control: No longer append action groups to event groups
Prior to this change, groups configured on any event action would get
appended to the configured event groups resulting in the set of groups
that would trigger the event action. Instead, event groups are used to
trigger event actions(and used within the actions) if-and-only-if there
are no groups configured on the event actions. When groups are
configured on an event action, only those groups are used within the
event action and the event groups are what's used to trigger the
actions.
So now, an event may be configured to be triggered by a set of groups
separately from which groups are used within the actions. To have the
event groups that trigger the event also included in the processing of
its actions, the same group can be listed along with additional groups
directly on the action within the event. Of course, if the event groups
that trigger the event are also what should be used in the event
actions, then no groups should be given on the actions.
Change-Id: I857e1ec0996999d990ce370ede3d4e51b1f56314
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/event.cpp b/control/json/event.cpp
index 02f2ed5..d4aee96 100644
--- a/control/json/event.cpp
+++ b/control/json/event.cpp
@@ -149,19 +149,6 @@
throw std::runtime_error("Missing required event action name");
}
- // Append action specific groups to the list of event groups for each
- // action in the event
- auto actionGroups = _groups;
- setGroups(jsonAct, _profiles, actionGroups);
- if (actionGroups.empty())
- {
- log<level::DEBUG>(
- fmt::format("No groups configured for event {}'s action {} "
- "based on the active profile(s)",
- getName(), jsonAct["name"].get<std::string>())
- .c_str());
- }
-
// Determine list of zones action should be run against
std::vector<std::reference_wrapper<Zone>> actionZones;
if (!jsonAct.contains("zones"))
@@ -211,13 +198,40 @@
.c_str());
}
- // Create the action for the event
- auto actObj = ActionFactory::getAction(
- jsonAct["name"].get<std::string>(), jsonAct,
- std::move(actionGroups), std::move(actionZones));
- if (actObj)
+ // Action specific groups, if any given, will override the use of event
+ // groups in the action(s)
+ std::vector<Group> actionGroups;
+ setGroups(jsonAct, _profiles, actionGroups);
+ if (!actionGroups.empty())
{
- _actions.emplace_back(std::move(actObj));
+ // Create the action for the event using the action's groups
+ auto actObj = ActionFactory::getAction(
+ jsonAct["name"].get<std::string>(), jsonAct,
+ std::move(actionGroups), std::move(actionZones));
+ if (actObj)
+ {
+ _actions.emplace_back(std::move(actObj));
+ }
+ }
+ else
+ {
+ // Create the action for the event using the event's groups
+ auto actObj = ActionFactory::getAction(
+ jsonAct["name"].get<std::string>(), jsonAct, _groups,
+ std::move(actionZones));
+ if (actObj)
+ {
+ _actions.emplace_back(std::move(actObj));
+ }
+ }
+
+ if (actionGroups.empty() && _groups.empty())
+ {
+ log<level::DEBUG>(
+ fmt::format("No groups configured for event {}'s action {} "
+ "based on the active profile(s)",
+ getName(), jsonAct["name"].get<std::string>())
+ .c_str());
}
}
}