blob: 3dbed66388aeea35e2da6ac0d0088ee7f8550b65 [file]
#ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_REDFISH_AGGREGATED_BATCH_H_
#define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_REDFISH_AGGREGATED_BATCH_H_
#include <memory>
#include <string>
#include <vector>
#include "absl/functional/any_invocable.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "redfish_aggregated_batch_config.pb.h"
#include "tlbmc/http/http_client_interface.h"
#include "sensor.pb.h"
#include "tlbmc/sensors/redfish_aggregated_sensor.h"
namespace milotic_tlbmc {
// RedfishAggregatedBatch is an object that represents a batch of
// RedfishAggregatedSensors. It is responsible for refreshing all of the managed
// sensors and updating their states and timestamps.
// RedfishAggregatedBatch supports two major Redfish JSON schemas:
// * MetricReports
// * ProcessorMetrics
class RedfishAggregatedBatch
: public std::enable_shared_from_this<RedfishAggregatedBatch> {
private:
class Token;
public:
static absl::StatusOr<std::shared_ptr<RedfishAggregatedBatch>> Create(
const RedfishAggregatedBatchConfig& config,
const std::shared_ptr<boost::asio::io_context>& io_context,
std::unique_ptr<HttpClientInterface> http_client,
std::vector<std::shared_ptr<RedfishAggregatedSensor>>&& sensors);
RedfishAggregatedBatch(
const RedfishAggregatedBatchConfig& config,
const std::shared_ptr<boost::asio::io_context>& io_context,
std::unique_ptr<HttpClientInterface> http_client,
std::vector<std::shared_ptr<RedfishAggregatedSensor>>&& sensors);
~RedfishAggregatedBatch() = default;
void RefreshOnceAsync(absl::AnyInvocable<void()> callback);
// Returns the redfish location of the sensor.
absl::string_view GetRedfishLocation() const { return redfish_location_; }
// Returns the list of managed sensors of the batch sensor.
const std::vector<std::shared_ptr<RedfishAggregatedSensor>>&
GetManagedSensors() const {
return managed_sensors_;
}
// Returns the name of the batch sensor.
const std::string& GetBatchName() const { return config_.name(); }
protected:
static absl::Status ProcessResponseStatus(
boost::beast::error_code ec,
boost::beast::http::response<boost::beast::http::string_body> res);
private:
// Internal handler for the HTTP response.
void HandleBatchResponse(
boost::beast::error_code ec,
boost::beast::http::response<boost::beast::http::string_body> res,
absl::AnyInvocable<void()> callback);
const std::shared_ptr<boost::asio::io_context> io_context_;
const RedfishAggregatedBatchConfig config_;
std::unique_ptr<HttpClientInterface> http_client_;
const std::string redfish_location_;
const std::vector<std::shared_ptr<RedfishAggregatedSensor>> managed_sensors_;
};
} // namespace milotic_tlbmc
#endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_REDFISH_AGGREGATED_BATCH_H_