control: Load JSON configured groups and events
Load the JSON configured groups and events, removing the remaining
references to the YAML based groups, triggers, and actions types. JSON
configured groups are loaded and provided to each event so that they can
eventually be copied and updated for the specifics of the event.
Change-Id: If713809b2865b5fe84b7bbb5a086cd49ba7fe55c
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/event.cpp b/control/json/event.cpp
index d19c9c1..7fec581 100644
--- a/control/json/event.cpp
+++ b/control/json/event.cpp
@@ -16,7 +16,6 @@
#include "event.hpp"
#include "group.hpp"
-#include "json_parser.hpp"
#include <nlohmann/json.hpp>
#include <phosphor-logging/log.hpp>
@@ -31,27 +30,18 @@
using json = nlohmann::json;
using namespace phosphor::logging;
-const std::map<configKey, std::unique_ptr<Group>> Event::_availGrps =
- getConfig<Group>(true);
-
-Event::Event(sdbusplus::bus::bus& bus, const json& jsonObj) :
- ConfigBase(jsonObj), _bus(bus)
+Event::Event(const json& jsonObj, sdbusplus::bus::bus& bus,
+ std::map<configKey, std::unique_ptr<Group>>& groups) :
+ ConfigBase(jsonObj),
+ _bus(bus)
{
- if (jsonObj.contains("profiles"))
- {
- for (const auto& profile : jsonObj["profiles"])
- {
- _profiles.emplace_back(profile.get<std::string>());
- }
- }
-
// Event could have a precondition
if (!jsonObj.contains("precondition"))
{
// Event groups are optional
if (jsonObj.contains("groups"))
{
- setGroups(jsonObj);
+ setGroups(jsonObj, groups);
}
setTriggers(jsonObj);
// Event actions are optional
@@ -62,11 +52,12 @@
}
else
{
- setPrecond(jsonObj);
+ setPrecond(jsonObj, groups);
}
}
-void Event::setPrecond(const json& jsonObj)
+void Event::setPrecond(const json& jsonObj,
+ std::map<configKey, std::unique_ptr<Group>>& groups)
{
const auto& precond = jsonObj["precondition"];
if (!precond.contains("name") || !precond.contains("groups") ||
@@ -77,11 +68,12 @@
throw std::runtime_error(
"Missing required event precondition attributes");
}
- setGroups(precond);
+ setGroups(precond, groups);
setTriggers(precond);
}
-void Event::setGroups(const json& jsonObj)
+void Event::setGroups(const json& jsonObj,
+ std::map<configKey, std::unique_ptr<Group>>& groups)
{
for (const auto& group : jsonObj["groups"])
{
@@ -110,8 +102,8 @@
// Groups with the same profiles as the event can be used
configKey key =
std::make_pair(group["name"].get<std::string>(), _profiles);
- auto grpEntry = _availGrps.find(key);
- if (grpEntry != _availGrps.end())
+ auto grpEntry = groups.find(key);
+ if (grpEntry != groups.end())
{
eGroup grp;
for (const auto& member : grpEntry->second->getMembers())
@@ -127,8 +119,8 @@
// Groups with no profiles specified can be used in any event
key = std::make_pair(group["name"].get<std::string>(),
std::vector<std::string>{});
- grpEntry = _availGrps.find(key);
- if (grpEntry != _availGrps.end())
+ grpEntry = groups.find(key);
+ if (grpEntry != groups.end())
{
eGroup grp;
for (const auto& member : grpEntry->second->getMembers())