report_manager.cpp (dcc4e1936173a93251a02066432bc2bcbc386240) | report_manager.cpp (7e098e93ef0974739459d296f99ddfab54722c23) |
---|---|
1#include "report_manager.hpp" 2 3#include "report.hpp" 4#include "types/report_types.hpp" 5#include "utils/conversion.hpp" 6#include "utils/transform.hpp" 7 8#include <phosphor-logging/log.hpp> --- 42 unchanged lines hidden (view full) --- 51 dbusIface.register_method( 52 "AddReport", [this](boost::asio::yield_context& yield, 53 const std::string& reportName, 54 const std::string& reportingType, 55 const bool emitsReadingsUpdate, 56 const bool logToMetricReportsCollection, 57 const uint64_t interval, 58 ReadingParametersPastVersion metricParams) { | 1#include "report_manager.hpp" 2 3#include "report.hpp" 4#include "types/report_types.hpp" 5#include "utils/conversion.hpp" 6#include "utils/transform.hpp" 7 8#include <phosphor-logging/log.hpp> --- 42 unchanged lines hidden (view full) --- 51 dbusIface.register_method( 52 "AddReport", [this](boost::asio::yield_context& yield, 53 const std::string& reportName, 54 const std::string& reportingType, 55 const bool emitsReadingsUpdate, 56 const bool logToMetricReportsCollection, 57 const uint64_t interval, 58 ReadingParametersPastVersion metricParams) { |
59 constexpr auto enabledDefault = true; |
|
59 return addReport(yield, reportName, reportingType, 60 emitsReadingsUpdate, 61 logToMetricReportsCollection, 62 Milliseconds(interval), 63 convertToReadingParameters( | 60 return addReport(yield, reportName, reportingType, 61 emitsReadingsUpdate, 62 logToMetricReportsCollection, 63 Milliseconds(interval), 64 convertToReadingParameters( |
64 std::move(metricParams))) | 65 std::move(metricParams)), 66 enabledDefault) |
65 .getPath(); 66 }); 67 68 dbusIface.register_method( 69 "AddReportFutureVersion", 70 [this](boost::asio::yield_context& yield, 71 const std::string& reportName, 72 const std::string& reportingType, 73 const bool emitsReadingsUpdate, 74 const bool logToMetricReportsCollection, 75 const uint64_t interval, 76 ReadingParameters metricParams) { | 67 .getPath(); 68 }); 69 70 dbusIface.register_method( 71 "AddReportFutureVersion", 72 [this](boost::asio::yield_context& yield, 73 const std::string& reportName, 74 const std::string& reportingType, 75 const bool emitsReadingsUpdate, 76 const bool logToMetricReportsCollection, 77 const uint64_t interval, 78 ReadingParameters metricParams) { |
79 constexpr auto enabledDefault = true; |
|
77 return addReport(yield, reportName, reportingType, 78 emitsReadingsUpdate, 79 logToMetricReportsCollection, 80 Milliseconds(interval), | 80 return addReport(yield, reportName, reportingType, 81 emitsReadingsUpdate, 82 logToMetricReportsCollection, 83 Milliseconds(interval), |
81 std::move(metricParams)) | 84 std::move(metricParams), enabledDefault) |
82 .getPath(); 83 }); 84 }); 85} 86 87void ReportManager::removeReport(const interfaces::Report* report) 88{ 89 reports.erase( --- 74 unchanged lines hidden (view full) --- 164 static_cast<int>(std::errc::invalid_argument), e.what()); 165 } 166} 167 168interfaces::Report& ReportManager::addReport( 169 boost::asio::yield_context& yield, const std::string& reportName, 170 const std::string& reportingType, const bool emitsReadingsUpdate, 171 const bool logToMetricReportsCollection, Milliseconds interval, | 85 .getPath(); 86 }); 87 }); 88} 89 90void ReportManager::removeReport(const interfaces::Report* report) 91{ 92 reports.erase( --- 74 unchanged lines hidden (view full) --- 167 static_cast<int>(std::errc::invalid_argument), e.what()); 168 } 169} 170 171interfaces::Report& ReportManager::addReport( 172 boost::asio::yield_context& yield, const std::string& reportName, 173 const std::string& reportingType, const bool emitsReadingsUpdate, 174 const bool logToMetricReportsCollection, Milliseconds interval, |
172 ReadingParameters metricParams) | 175 ReadingParameters metricParams, const bool enabled) |
173{ 174 auto labeledMetricParams = 175 reportFactory->convertMetricParams(yield, metricParams); 176 177 return addReport(reportName, reportingType, emitsReadingsUpdate, 178 logToMetricReportsCollection, interval, | 176{ 177 auto labeledMetricParams = 178 reportFactory->convertMetricParams(yield, metricParams); 179 180 return addReport(reportName, reportingType, emitsReadingsUpdate, 181 logToMetricReportsCollection, interval, |
179 std::move(labeledMetricParams)); | 182 std::move(labeledMetricParams), enabled); |
180} 181 182interfaces::Report& ReportManager::addReport( 183 const std::string& reportName, const std::string& reportingType, 184 const bool emitsReadingsUpdate, const bool logToMetricReportsCollection, 185 Milliseconds interval, | 183} 184 185interfaces::Report& ReportManager::addReport( 186 const std::string& reportName, const std::string& reportingType, 187 const bool emitsReadingsUpdate, const bool logToMetricReportsCollection, 188 Milliseconds interval, |
186 std::vector<LabeledMetricParameters> labeledMetricParams) | 189 std::vector<LabeledMetricParameters> labeledMetricParams, 190 const bool enabled) |
187{ 188 verifyAddReport(reportName, reportingType, interval, labeledMetricParams); 189 190 reports.emplace_back( 191 reportFactory->make(reportName, reportingType, emitsReadingsUpdate, 192 logToMetricReportsCollection, interval, *this, | 191{ 192 verifyAddReport(reportName, reportingType, interval, labeledMetricParams); 193 194 reports.emplace_back( 195 reportFactory->make(reportName, reportingType, emitsReadingsUpdate, 196 logToMetricReportsCollection, interval, *this, |
193 *reportStorage, labeledMetricParams)); | 197 *reportStorage, labeledMetricParams, enabled)); |
194 return *reports.back(); 195} 196 197void ReportManager::loadFromPersistent() 198{ 199 std::vector<interfaces::JsonStorage::FilePath> paths = 200 reportStorage->list(); 201 202 for (const auto& path : paths) 203 { 204 std::optional<nlohmann::json> data = reportStorage->load(path); 205 try 206 { | 198 return *reports.back(); 199} 200 201void ReportManager::loadFromPersistent() 202{ 203 std::vector<interfaces::JsonStorage::FilePath> paths = 204 reportStorage->list(); 205 206 for (const auto& path : paths) 207 { 208 std::optional<nlohmann::json> data = reportStorage->load(path); 209 try 210 { |
211 bool enabled = data->at("Enabled").get<bool>(); |
|
207 size_t version = data->at("Version").get<size_t>(); 208 if (version != Report::reportVersion) 209 { 210 throw std::logic_error("Invalid version"); 211 } 212 std::string& name = data->at("Name").get_ref<std::string&>(); 213 std::string& reportingType = 214 data->at("ReportingType").get_ref<std::string&>(); 215 bool emitsReadingsSignal = 216 data->at("EmitsReadingsUpdate").get<bool>(); 217 bool logToMetricReportsCollection = 218 data->at("LogToMetricReportsCollection").get<bool>(); 219 uint64_t interval = data->at("Interval").get<uint64_t>(); 220 auto readingParameters = 221 data->at("ReadingParameters") 222 .get<std::vector<LabeledMetricParameters>>(); 223 224 addReport(name, reportingType, emitsReadingsSignal, 225 logToMetricReportsCollection, Milliseconds(interval), | 212 size_t version = data->at("Version").get<size_t>(); 213 if (version != Report::reportVersion) 214 { 215 throw std::logic_error("Invalid version"); 216 } 217 std::string& name = data->at("Name").get_ref<std::string&>(); 218 std::string& reportingType = 219 data->at("ReportingType").get_ref<std::string&>(); 220 bool emitsReadingsSignal = 221 data->at("EmitsReadingsUpdate").get<bool>(); 222 bool logToMetricReportsCollection = 223 data->at("LogToMetricReportsCollection").get<bool>(); 224 uint64_t interval = data->at("Interval").get<uint64_t>(); 225 auto readingParameters = 226 data->at("ReadingParameters") 227 .get<std::vector<LabeledMetricParameters>>(); 228 229 addReport(name, reportingType, emitsReadingsSignal, 230 logToMetricReportsCollection, Milliseconds(interval), |
226 std::move(readingParameters)); | 231 std::move(readingParameters), enabled); |
227 } 228 catch (const std::exception& e) 229 { 230 phosphor::logging::log<phosphor::logging::level::ERR>( 231 "Failed to load report from storage", 232 phosphor::logging::entry( 233 "FILENAME=%s", 234 static_cast<std::filesystem::path>(path).c_str()), --- 17 unchanged lines hidden --- | 232 } 233 catch (const std::exception& e) 234 { 235 phosphor::logging::log<phosphor::logging::level::ERR>( 236 "Failed to load report from storage", 237 phosphor::logging::entry( 238 "FILENAME=%s", 239 static_cast<std::filesystem::path>(path).c_str()), --- 17 unchanged lines hidden --- |