control: Use event groups on `init` triggers
Use the provided event groups when enabling any `init` triggers instead
of the action groups. Event groups is what's used with setting up event
triggers and may or may not be a different set of groups than what's
used when actions are run depending on event configuration.
Change-Id: I804e798e169598080583965e6922fc5fb1cfa2be
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/triggers/init.cpp b/control/json/triggers/init.cpp
index a060853..1ce272c 100644
--- a/control/json/triggers/init.cpp
+++ b/control/json/triggers/init.cpp
@@ -132,12 +132,14 @@
handler = methods.find(method);
}
- for (auto& action : actions)
- {
- // Groups are optional, so a method is only required if there are groups
- // i.e.) An init triggered event without any groups results in just
- // running the actions
- if (!action->getGroups().empty() && handler == methods.end())
+ return [handler = std::move(handler)](
+ const std::string& eventName, Manager* mgr,
+ const std::vector<Group>& groups,
+ std::vector<std::unique_ptr<ActionBase>>& actions) {
+ // Event groups are optional, so a method is only required if there
+ // are event groups i.e.) An init triggered event without any event
+ // groups results in just running the actions
+ if (!groups.empty() && handler == methods.end())
{
// Construct list of available methods
auto availMethods = std::accumulate(
@@ -152,20 +154,15 @@
log<level::ERR>(msg.c_str());
throw std::runtime_error(msg.c_str());
}
- }
- return [handler = std::move(handler)](
- const std::string& eventName, Manager* mgr,
- const std::vector<Group>& groups,
- std::vector<std::unique_ptr<ActionBase>>& actions) {
+ for (const auto& group : groups)
+ {
+ // Call method handler for each group to populate cache
+ handler->second(mgr, group);
+ }
for (auto& action : actions)
{
- for (const auto& group : action->getGroups())
- {
- // Call method handler for each group in the actions
- handler->second(mgr, group);
- }
- // Run the action
+ // Run each action after initializing all the groups
action->run();
}
};