Read persistent triggers from storage
Read json storage file for persistent triggers.
Add trigger to telemetry service.
Cover code with UTs.
Tested:
- Passed unit tests
- Tested on QEMU
* starting app without configuration
* restart app with configuration stored
* restart app with configuration in incorrect version
* restart app with configuration malformed
Change-Id: I2cb9324abdb8323be8a7f0c932ed7f70c5bc2891
Signed-off-by: Cezary Zwolak <cezary.zwolak@intel.com>
Signed-off-by: Lukasz Kazmierczak <lukasz.kazmierczak@intel.com>
diff --git a/src/trigger.cpp b/src/trigger.cpp
index 2bba3ea..6289a05 100644
--- a/src/trigger.cpp
+++ b/src/trigger.cpp
@@ -1,34 +1,30 @@
#include "trigger.hpp"
+#include "interfaces/trigger_types.hpp"
#include "interfaces/types.hpp"
+#include "utils/conversion_trigger.hpp"
#include "utils/transform.hpp"
#include <phosphor-logging/log.hpp>
-template <class... Ts>
-struct overloaded : Ts...
-{
- using Ts::operator()...;
-};
-template <class... Ts>
-overloaded(Ts...) -> overloaded<Ts...>;
-
Trigger::Trigger(
boost::asio::io_context& ioc,
const std::shared_ptr<sdbusplus::asio::object_server>& objServer,
const std::string& nameIn, const bool isDiscreteIn,
const bool logToJournalIn, const bool logToRedfishIn,
- const bool updateReportIn, const TriggerSensors& sensorsIn,
- const std::vector<std::string>& reportNamesIn,
- const TriggerThresholdParams& thresholdParamsIn,
+ const bool updateReportIn, const std::vector<std::string>& reportNamesIn,
+ const std::vector<LabeledSensorInfo>& LabeledSensorsInfoIn,
+ const LabeledTriggerThresholdParams& labeledThresholdParamsIn,
std::vector<std::shared_ptr<interfaces::Threshold>>&& thresholdsIn,
interfaces::TriggerManager& triggerManager,
interfaces::JsonStorage& triggerStorageIn) :
name(nameIn),
isDiscrete(isDiscreteIn), logToJournal(logToJournalIn),
logToRedfish(logToRedfishIn), updateReport(updateReportIn),
- path(triggerDir + name), sensors(sensorsIn), reportNames(reportNamesIn),
- thresholdParams(thresholdParamsIn), thresholds(std::move(thresholdsIn)),
+ path(triggerDir + name), reportNames(reportNamesIn),
+ labeledSensorsInfo(LabeledSensorsInfoIn),
+ labeledThresholdParams(labeledThresholdParamsIn),
+ thresholds(std::move(thresholdsIn)),
fileName(std::to_string(std::hash<std::string>{}(name))),
triggerStorage(triggerStorageIn)
{
@@ -72,13 +68,23 @@
[this](const auto&) { return persistent; });
dbusIface.register_property_r(
- "Thresholds", thresholdParams,
+ "Thresholds", TriggerThresholdParams{},
sdbusplus::vtable::property_::emits_change,
- [](const auto& x) { return x; });
+ [this](const auto&) {
+ return std::visit(
+ utils::FromLabeledThresholdParamConversion(),
+ labeledThresholdParams);
+ });
+
dbusIface.register_property_r(
- "Sensors", sensors, sdbusplus::vtable::property_::emits_change,
- [](const auto& x) { return x; });
+ "Sensors", SensorsInfo{},
+ sdbusplus::vtable::property_::emits_change,
+ [this](const auto&) {
+ return utils::fromLabeledSensorsInfo(labeledSensorsInfo);
+ });
+
dbusIface.register_property_r(
+
"ReportNames", reportNames,
sdbusplus::vtable::property_::emits_change,
[](const auto& x) { return x; });
@@ -110,44 +116,15 @@
data["Version"] = triggerVersion;
data["Name"] = name;
- data["ThresholdParamsDiscriminator"] = thresholdParams.index();
- data["IsDiscrete"] = isDiscrete;
+ data["ThresholdParamsDiscriminator"] = labeledThresholdParams.index();
+ data["IsDiscrete"] = labeledThresholdParams.index() == 1;
data["LogToJournal"] = logToJournal;
data["LogToRedfish"] = logToRedfish;
data["UpdateReport"] = updateReport;
-
- std::visit(
- overloaded{
- [&](const std::vector<numeric::ThresholdParam>& arg) {
- data["ThresholdParams"] =
- utils::transform(arg, [](const auto& thresholdParam) {
- const auto& [type, dwellTime, direction,
- thresholdValue] = thresholdParam;
- return numeric::LabeledThresholdParam(
- numeric::stringToType(type), dwellTime,
- numeric::stringToDirection(direction),
- thresholdValue);
- });
- },
- [&](const std::vector<discrete::ThresholdParam>& arg) {
- data["ThresholdParams"] =
- utils::transform(arg, [](const auto& thresholdParam) {
- const auto& [userId, severity, dwellTime,
- thresholdValue] = thresholdParam;
- return discrete::LabeledThresholdParam(
- userId, discrete::stringToSeverity(severity),
- dwellTime, thresholdValue);
- });
- },
- },
- thresholdParams);
-
+ data["ThresholdParams"] =
+ utils::labeledThresholdParamsToJson(labeledThresholdParams);
data["ReportNames"] = reportNames;
-
- data["Sensors"] = utils::transform(sensors, [](const auto& sensor) {
- const auto& [sensorPath, sensorMetadata] = sensor;
- return LabeledTriggerSensor(sensorPath, sensorMetadata);
- });
+ data["Sensors"] = labeledSensorsInfo;
triggerStorage.store(fileName, data);
}
@@ -159,4 +136,4 @@
return false;
}
return true;
-}
\ No newline at end of file
+}