summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Grobelny <krzysztof.grobelny@intel.com>2022-09-06 17:30:38 +0300
committerEd Tanous <ed@tanous.net>2022-09-06 18:06:45 +0300
commit894744945e8f40a93fbcd6c100c92e0cf5b0ef67 (patch)
treeea8f3b0ce5f7273b6574b51f4252107c3279b3b6
parent07ffa4e8ce8bdf6822df702872eade16d1bb5184 (diff)
downloadbmcweb-894744945e8f40a93fbcd6c100c92e0cf5b0ef67.tar.xz
used sdbusplus::unpackPropertiesNoThrow part 7
used sdbusplus::unpackPropertiesNoThrow in cable.hpp, metric_report_definition.hpp, telemetry_service.hpp and trigger.hpp, also replaced all usages of "GetAll" with sdbusplus::asio::getAllProperties bmcweb size: 2697624 -> 2693528 (-4096) compressed size: 1129037 -> 1129322 (+285) Tested: Performed get on one of the: - /redfish/v1/Cables - /redfish/v1/TelemetryService/MetricReportDefinitions - /redfish/v1/TelemetryService/Triggers (trigger was added using Dbus API) Get result before and after the change was in same format. Change-Id: I24f001b4f52d8eb5f529b08de278a611f8fa22b2 Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
-rw-r--r--redfish-core/lib/cable.hpp62
-rw-r--r--redfish-core/lib/metric_report_definition.hpp85
-rw-r--r--redfish-core/lib/telemetry_service.hpp47
-rw-r--r--redfish-core/lib/trigger.hpp152
4 files changed, 170 insertions, 176 deletions
diff --git a/redfish-core/lib/cable.hpp b/redfish-core/lib/cable.hpp
index e55368282b..0b8cd0fb8f 100644
--- a/redfish-core/lib/cable.hpp
+++ b/redfish-core/lib/cable.hpp
@@ -1,6 +1,9 @@
#pragma once
#include <dbus_utility.hpp>
#include <query.hpp>
+#include <sdbusplus/asio/property.hpp>
+#include <sdbusplus/unpack_properties.hpp>
+#include <utils/dbus_utils.hpp>
#include <utils/json_utils.hpp>
namespace redfish
@@ -23,40 +26,37 @@ inline void
return;
}
- for (const auto& [propKey, propVariant] : properties)
+ const std::string* cableTypeDescription = nullptr;
+ const double* length = nullptr;
+
+ const bool success = sdbusplus::unpackPropertiesNoThrow(
+ dbus_utils::UnpackErrorPrinter(), properties, "CableTypeDescription",
+ cableTypeDescription, "Length", length);
+
+ if (!success)
+ {
+ messages::internalError(resp);
+ return;
+ }
+
+ if (cableTypeDescription != nullptr)
+ {
+ resp.jsonValue["CableType"] = *cableTypeDescription;
+ }
+
+ if (length != nullptr)
{
- if (propKey == "CableTypeDescription")
+ if (!std::isfinite(*length))
{
- const std::string* cableTypeDescription =
- std::get_if<std::string>(&propVariant);
- if (cableTypeDescription == nullptr)
+ if (std::isnan(*length))
{
- messages::internalError(resp);
return;
}
- resp.jsonValue["CableType"] = *cableTypeDescription;
+ messages::internalError(resp);
+ return;
}
- else if (propKey == "Length")
- {
- const double* cableLength = std::get_if<double>(&propVariant);
- if (cableLength == nullptr)
- {
- messages::internalError(resp);
- return;
- }
- if (!std::isfinite(*cableLength))
- {
- if (std::isnan(*cableLength))
- {
- continue;
- }
- messages::internalError(resp);
- return;
- }
-
- resp.jsonValue["LengthMeters"] = *cableLength;
- }
+ resp.jsonValue["LengthMeters"] = *length;
}
}
@@ -83,14 +83,14 @@ inline void
continue;
}
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getAllProperties(
+ *crow::connections::systemBus, service, cableObjectPath,
+ interface,
[asyncResp](
const boost::system::error_code ec,
const dbus::utility::DBusPropertiesMap& properties) {
fillCableProperties(asyncResp->res, ec, properties);
- },
- service, cableObjectPath, "org.freedesktop.DBus.Properties",
- "GetAll", interface);
+ });
}
}
}
diff --git a/redfish-core/lib/metric_report_definition.hpp b/redfish-core/lib/metric_report_definition.hpp
index 88333fc0ff..37e903173c 100644
--- a/redfish-core/lib/metric_report_definition.hpp
+++ b/redfish-core/lib/metric_report_definition.hpp
@@ -9,6 +9,9 @@
#include <dbus_utility.hpp>
#include <query.hpp>
#include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
+#include <sdbusplus/unpack_properties.hpp>
+#include <utils/dbus_utils.hpp>
#include <map>
#include <tuple>
@@ -49,66 +52,61 @@ inline void
const bool* emitsReadingsUpdate = nullptr;
const bool* logToMetricReportsCollection = nullptr;
- const ReadingParameters* readingParams = nullptr;
+ const ReadingParameters* readingParameters = nullptr;
const std::string* reportingType = nullptr;
const uint64_t* interval = nullptr;
- for (const auto& [key, var] : ret)
- {
- if (key == "EmitsReadingsUpdate")
- {
- emitsReadingsUpdate = std::get_if<bool>(&var);
- }
- else if (key == "LogToMetricReportsCollection")
- {
- logToMetricReportsCollection = std::get_if<bool>(&var);
- }
- else if (key == "ReadingParameters")
- {
- readingParams = std::get_if<ReadingParameters>(&var);
- }
- else if (key == "ReportingType")
- {
- reportingType = std::get_if<std::string>(&var);
- }
- else if (key == "Interval")
- {
- interval = std::get_if<uint64_t>(&var);
- }
- }
- if (emitsReadingsUpdate == nullptr ||
- logToMetricReportsCollection == nullptr || readingParams == nullptr ||
- reportingType == nullptr || interval == nullptr)
+
+ const bool success = sdbusplus::unpackPropertiesNoThrow(
+ dbus_utils::UnpackErrorPrinter(), ret, "EmitsReadingsUpdate",
+ emitsReadingsUpdate, "LogToMetricReportsCollection",
+ logToMetricReportsCollection, "ReadingParameters", readingParameters,
+ "ReportingType", reportingType, "Interval", interval);
+
+ if (!success)
{
- BMCWEB_LOG_ERROR << "Property type mismatch or property is missing";
messages::internalError(asyncResp->res);
return;
}
std::vector<std::string> redfishReportActions;
redfishReportActions.reserve(2);
- if (*emitsReadingsUpdate)
+ if (emitsReadingsUpdate != nullptr && *emitsReadingsUpdate)
{
redfishReportActions.emplace_back("RedfishEvent");
}
- if (*logToMetricReportsCollection)
+
+ if (logToMetricReportsCollection != nullptr &&
+ *logToMetricReportsCollection)
{
redfishReportActions.emplace_back("LogToMetricReportsCollection");
}
nlohmann::json metrics = nlohmann::json::array();
- for (const auto& [sensorPath, operationType, metricId, metadata] :
- *readingParams)
+ if (readingParameters != nullptr)
{
- metrics.push_back({
- {"MetricId", metricId},
- {"MetricProperties", {metadata}},
- });
+ for (const auto& [sensorPath, operationType, metricId, metadata] :
+ *readingParameters)
+ {
+ metrics.push_back({
+ {"MetricId", metricId},
+ {"MetricProperties", {metadata}},
+ });
+ }
+ }
+
+ if (reportingType != nullptr)
+ {
+ asyncResp->res.jsonValue["MetricReportDefinitionType"] = *reportingType;
}
+
+ if (interval != nullptr)
+ {
+ asyncResp->res.jsonValue["Schedule"]["RecurrenceInterval"] =
+ time_utils::toDurationString(std::chrono::milliseconds(*interval));
+ }
+
asyncResp->res.jsonValue["Metrics"] = metrics;
- asyncResp->res.jsonValue["MetricReportDefinitionType"] = *reportingType;
asyncResp->res.jsonValue["ReportActions"] = redfishReportActions;
- asyncResp->res.jsonValue["Schedule"]["RecurrenceInterval"] =
- time_utils::toDurationString(std::chrono::milliseconds(*interval));
}
struct AddReportArgs
@@ -433,7 +431,9 @@ inline void requestRoutesMetricReportDefinition(App& app)
return;
}
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getAllProperties(
+ *crow::connections::systemBus, telemetry::service,
+ telemetry::getDbusReportPath(id), telemetry::reportInterface,
[asyncResp,
id](const boost::system::error_code ec,
const std::vector<std::pair<
@@ -453,10 +453,7 @@ inline void requestRoutesMetricReportDefinition(App& app)
}
telemetry::fillReportDefinition(asyncResp, id, ret);
- },
- telemetry::service, telemetry::getDbusReportPath(id),
- "org.freedesktop.DBus.Properties", "GetAll",
- telemetry::reportInterface);
+ });
});
BMCWEB_ROUTE(app,
"/redfish/v1/TelemetryService/MetricReportDefinitions/<str>/")
diff --git a/redfish-core/lib/telemetry_service.hpp b/redfish-core/lib/telemetry_service.hpp
index 72a1e1d0b8..afedbc636a 100644
--- a/redfish-core/lib/telemetry_service.hpp
+++ b/redfish-core/lib/telemetry_service.hpp
@@ -6,6 +6,9 @@
#include <dbus_utility.hpp>
#include <query.hpp>
#include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
+#include <sdbusplus/unpack_properties.hpp>
+#include <utils/dbus_utils.hpp>
namespace redfish
{
@@ -31,7 +34,10 @@ inline void handleTelemetryServiceGet(
asyncResp->res.jsonValue["Triggers"]["@odata.id"] =
"/redfish/v1/TelemetryService/Triggers";
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getAllProperties(
+ *crow::connections::systemBus, telemetry::service,
+ "/xyz/openbmc_project/Telemetry/Reports",
+ "xyz.openbmc_project.Telemetry.ReportManager",
[asyncResp](const boost::system::error_code ec,
const dbus::utility::DBusPropertiesMap& ret) {
if (ec == boost::system::errc::host_unreachable)
@@ -50,32 +56,29 @@ inline void handleTelemetryServiceGet(
const size_t* maxReports = nullptr;
const uint64_t* minInterval = nullptr;
- for (const auto& [key, var] : ret)
- {
- if (key == "MaxReports")
- {
- maxReports = std::get_if<size_t>(&var);
- }
- else if (key == "MinInterval")
- {
- minInterval = std::get_if<uint64_t>(&var);
- }
- }
- if (maxReports == nullptr || minInterval == nullptr)
+
+ const bool success = sdbusplus::unpackPropertiesNoThrow(
+ dbus_utils::UnpackErrorPrinter(), ret, "MaxReports", maxReports,
+ "MinInterval", minInterval);
+
+ if (!success)
{
- BMCWEB_LOG_ERROR << "Property type mismatch or property is missing";
messages::internalError(asyncResp->res);
return;
}
- asyncResp->res.jsonValue["MaxReports"] = *maxReports;
- asyncResp->res.jsonValue["MinCollectionInterval"] =
- time_utils::toDurationString(
- std::chrono::milliseconds(static_cast<time_t>(*minInterval)));
- },
- telemetry::service, "/xyz/openbmc_project/Telemetry/Reports",
- "org.freedesktop.DBus.Properties", "GetAll",
- "xyz.openbmc_project.Telemetry.ReportManager");
+ if (maxReports != nullptr)
+ {
+ asyncResp->res.jsonValue["MaxReports"] = *maxReports;
+ }
+
+ if (minInterval != nullptr)
+ {
+ asyncResp->res.jsonValue["MinCollectionInterval"] =
+ time_utils::toDurationString(std::chrono::milliseconds(
+ static_cast<time_t>(*minInterval)));
+ }
+ });
}
inline void requestRoutesTelemetryService(App& app)
diff --git a/redfish-core/lib/trigger.hpp b/redfish-core/lib/trigger.hpp
index 920a8c30c6..5e2f05003a 100644
--- a/redfish-core/lib/trigger.hpp
+++ b/redfish-core/lib/trigger.hpp
@@ -6,6 +6,9 @@
#include <app.hpp>
#include <query.hpp>
#include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
+#include <sdbusplus/unpack_properties.hpp>
+#include <utils/dbus_utils.hpp>
#include <tuple>
#include <variant>
@@ -188,107 +191,99 @@ inline bool fillTrigger(
const bool* discrete = nullptr;
const TriggerSensorsParams* sensors = nullptr;
const std::vector<sdbusplus::message::object_path>* reports = nullptr;
- const std::vector<std::string>* actions = nullptr;
+ const std::vector<std::string>* triggerActions = nullptr;
const TriggerThresholdParamsExt* thresholds = nullptr;
- for (const auto& [key, var] : properties)
- {
- if (key == "Name")
- {
- name = std::get_if<std::string>(&var);
- }
- else if (key == "Discrete")
- {
- discrete = std::get_if<bool>(&var);
- }
- else if (key == "Sensors")
- {
- sensors = std::get_if<TriggerSensorsParams>(&var);
- }
- else if (key == "Reports")
- {
- reports =
- std::get_if<std::vector<sdbusplus::message::object_path>>(&var);
- }
- else if (key == "TriggerActions")
- {
- actions = std::get_if<std::vector<std::string>>(&var);
- }
- else if (key == "Thresholds")
- {
- thresholds = std::get_if<TriggerThresholdParamsExt>(&var);
- }
- }
+ const bool success = sdbusplus::unpackPropertiesNoThrow(
+ dbus_utils::UnpackErrorPrinter(), properties, "Name", name, "Discrete",
+ discrete, "Sensors", sensors, "Reports", reports, "TriggerActions",
+ triggerActions, "Thresholds", thresholds);
- if (name == nullptr || discrete == nullptr || sensors == nullptr ||
- reports == nullptr || actions == nullptr || thresholds == nullptr)
+ if (!success)
{
- BMCWEB_LOG_ERROR
- << "Property type mismatch or property is missing in Trigger: "
- << id;
return false;
}
- std::optional<std::vector<std::string>> triggerActions =
- getTriggerActions(*actions);
- if (!triggerActions)
+ if (triggerActions != nullptr)
{
- BMCWEB_LOG_ERROR << "Property TriggerActions is invalid in Trigger: "
- << id;
- return false;
- }
-
- std::optional<nlohmann::json> linkedReports =
- getMetricReportDefinitions(*reports);
- if (!linkedReports)
- {
- BMCWEB_LOG_ERROR << "Property Reports is invalid in Trigger: " << id;
- return false;
+ std::optional<std::vector<std::string>> redfishTriggerActions =
+ getTriggerActions(*triggerActions);
+ if (!redfishTriggerActions)
+ {
+ BMCWEB_LOG_ERROR
+ << "Property TriggerActions is invalid in Trigger: " << id;
+ return false;
+ }
+ json["TriggerActions"] = *triggerActions;
}
- if (*discrete)
+ if (reports != nullptr)
{
- std::optional<nlohmann::json::array_t> discreteTriggers =
- getDiscreteTriggers(*thresholds);
-
- if (!discreteTriggers)
+ std::optional<nlohmann::json> linkedReports =
+ getMetricReportDefinitions(*reports);
+ if (!linkedReports)
{
- BMCWEB_LOG_ERROR << "Property Thresholds is invalid for discrete "
- "triggers in Trigger: "
+ BMCWEB_LOG_ERROR << "Property Reports is invalid in Trigger: "
<< id;
return false;
}
-
- json["DiscreteTriggers"] = *discreteTriggers;
- json["DiscreteTriggerCondition"] =
- discreteTriggers->empty() ? "Changed" : "Specified";
- json["MetricType"] = "Discrete";
+ json["Links"]["MetricReportDefinitions"] = *linkedReports;
}
- else
+
+ if (discrete != nullptr)
{
- std::optional<nlohmann::json> numericThresholds =
- getNumericThresholds(*thresholds);
+ if (*discrete)
+ {
+ std::optional<nlohmann::json::array_t> discreteTriggers =
+ getDiscreteTriggers(*thresholds);
- if (!numericThresholds)
+ if (!discreteTriggers)
+ {
+ BMCWEB_LOG_ERROR
+ << "Property Thresholds is invalid for discrete "
+ "triggers in Trigger: "
+ << id;
+ return false;
+ }
+
+ json["DiscreteTriggers"] = *discreteTriggers;
+ json["DiscreteTriggerCondition"] =
+ discreteTriggers->empty() ? "Changed" : "Specified";
+ json["MetricType"] = "Discrete";
+ }
+ else
{
- BMCWEB_LOG_ERROR << "Property Thresholds is invalid for numeric "
- "thresholds in Trigger: "
- << id;
- return false;
+ std::optional<nlohmann::json> numericThresholds =
+ getNumericThresholds(*thresholds);
+
+ if (!numericThresholds)
+ {
+ BMCWEB_LOG_ERROR
+ << "Property Thresholds is invalid for numeric "
+ "thresholds in Trigger: "
+ << id;
+ return false;
+ }
+
+ json["NumericThresholds"] = *numericThresholds;
+ json["MetricType"] = "Numeric";
}
+ }
+
+ if (name != nullptr)
+ {
+ json["Name"] = *name;
+ }
- json["NumericThresholds"] = *numericThresholds;
- json["MetricType"] = "Numeric";
+ if (sensors != nullptr)
+ {
+ json["MetricProperties"] = getMetricProperties(*sensors);
}
json["@odata.type"] = "#Triggers.v1_2_0.Triggers";
json["@odata.id"] = crow::utility::urlFromPieces(
"redfish", "v1", "TelemetryService", "Triggers", id);
json["Id"] = id;
- json["Name"] = *name;
- json["TriggerActions"] = *triggerActions;
- json["MetricProperties"] = getMetricProperties(*sensors);
- json["Links"]["MetricReportDefinitions"] = *linkedReports;
return true;
}
@@ -329,7 +324,9 @@ inline void requestRoutesTrigger(App& app)
{
return;
}
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getAllProperties(
+ *crow::connections::systemBus, telemetry::service,
+ telemetry::getDbusTriggerPath(id), telemetry::triggerInterface,
[asyncResp,
id](const boost::system::error_code ec,
const std::vector<std::pair<
@@ -351,10 +348,7 @@ inline void requestRoutesTrigger(App& app)
{
messages::internalError(asyncResp->res);
}
- },
- telemetry::service, telemetry::getDbusTriggerPath(id),
- "org.freedesktop.DBus.Properties", "GetAll",
- telemetry::triggerInterface);
+ });
});
BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/Triggers/<str>/")