control: Change `addGroup()` to get all managed objects
The addGroup method is used to populate the cache with event groups
triggered by a timer when the "preload_groups" directive is used.
Instead of going out to dbus to refresh the cache for each group member,
use the ObjectManager interface to retrieve all the managed objects for
each unique service of the group members.
Change-Id: I61136409f035cd78a1762b4e22b00376e1cb4a43
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/manager.cpp b/control/json/manager.cpp
index 0acf706..def8d95 100644
--- a/control/json/manager.cpp
+++ b/control/json/manager.cpp
@@ -596,30 +596,59 @@
void Manager::addGroup(const Group& group)
{
- const auto& members = group.getMembers();
- for (const auto& member : members)
+ std::set<std::string> services;
+ for (const auto& member : group.getMembers())
{
try
{
- auto service = getService(member, group.getInterface());
+ const auto& service =
+ util::SDBusPlus::getService(member, group.getInterface());
- auto variant =
- util::SDBusPlus::getPropertyVariant<PropertyVariantType>(
- service, member, group.getInterface(), group.getProperty());
+ // TODO - Optimize to only retrieve the paths on this service
+ auto objMgrPaths =
+ getPaths(service, "org.freedesktop.DBus.ObjectManager");
- setProperty(member, group.getInterface(), group.getProperty(),
- variant);
- }
- catch (const std::exception& e)
- {
- try
+ // Look for the ObjectManager as an ancestor from the member.
+ auto hasObjMgr =
+ std::any_of(objMgrPaths.begin(), objMgrPaths.end(),
+ [&member](const auto& path) {
+ return member.find(path) != std::string::npos;
+ });
+
+ if (!hasObjMgr)
{
- _objects.at(member)
- .at(group.getInterface())
- .erase(group.getProperty());
+ // No object manager interface provided for group member
+ // Attempt to retrieve group member property directly
+ auto value =
+ util::SDBusPlus::getPropertyVariant<PropertyVariantType>(
+ _bus, service, member, group.getInterface(),
+ group.getProperty());
+
+ setProperty(member, group.getInterface(), group.getProperty(),
+ value);
+ continue;
}
- catch (const std::out_of_range&)
- {}
+
+ if (services.find(service) == services.end())
+ {
+ services.insert(service);
+ for (const auto& objMgrPath : objMgrPaths)
+ {
+ // Get all managed objects from the service
+ auto objects =
+ util::SDBusPlus::getManagedObjects<PropertyVariantType>(
+ _bus, service, objMgrPath);
+
+ // Insert objects into cache
+ insertFilteredObjects(objects);
+ }
+ }
+ }
+ catch (const util::DBusServiceError&)
+ {
+ // No service found for group member containing the group's
+ // configured interface
+ continue;
}
}
}