Skip to content

Commit

Permalink
Adapt Icinga#7786 to the new ConfigItem::CommitNewItems() (credit Hen…
Browse files Browse the repository at this point in the history
…rik Triem)
  • Loading branch information
ymartin-ovh committed Oct 6, 2023
1 parent bba6a76 commit f6b9d53
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions lib/remote/apilistener-configsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,22 +443,51 @@ void ApiListener::SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient
Log(LogInformation, "ApiListener")
<< "Syncing runtime objects to endpoint '" << endpoint->GetName() << "'.";

std::set<Type::Ptr> types;
std::set<Type::Ptr> completed_types;

for (const Type::Ptr& type : Type::GetAllTypes()) {
auto *dtype = dynamic_cast<ConfigType *>(type.get());
if (ConfigObject::TypeInstance->IsAssignableFrom(type))
types.insert(type);
}

while (types.size() != completed_types.size()) {
for (const Type::Ptr& type : types) {
if (completed_types.find(type) != completed_types.end())
continue;

if (!dtype)
continue;
bool unresolved_dep = false;

for (const ConfigObject::Ptr& object : dtype->GetObjects()) {
/* don't sync objects for non-matching parent-child zones */
if (!azone->CanAccessObject(object))
/* skip this type (for now) if there are unresolved load dependencies */
for (auto pLoadDep : type->GetLoadDependencies()) {
if (types.find(pLoadDep) != types.end() && completed_types.find(pLoadDep) == completed_types.end()) {
unresolved_dep = true;
break;
}
}

if (unresolved_dep)
continue;

/* send the config object to the connected client */
UpdateConfigObject(object, nullptr, aclient);
auto *dtype = dynamic_cast<ConfigType *>(type.get());
if (!dtype)
continue;

for (const ConfigObject::Ptr& object : dtype->GetObjects()) {
/* don't sync objects for non-matching parent-child zones */
if (!azone->CanAccessObject(object))
continue;

/* send the config object to the connected client */
UpdateConfigObject(object, nullptr, aclient);
}

completed_types.insert(type);

}
}


Log(LogInformation, "ApiListener")
<< "Finished syncing runtime objects to endpoint '" << endpoint->GetName() << "'.";
}

0 comments on commit f6b9d53

Please sign in to comment.