Skip to content

Commit

Permalink
Fix object sync for objects in a global zone
Browse files Browse the repository at this point in the history
fixes #11541
  • Loading branch information
Michael Friedrich committed Nov 14, 2016
1 parent 1bfb91f commit 40d68fc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/remote/apilistener-configsync.cpp
Expand Up @@ -243,7 +243,7 @@ Value ApiListener::ConfigDeleteObjectAPIHandler(const MessageOrigin::Ptr& origin

if (!object) {
Log(LogNotice, "ApiListener")
<< "Could not delete non-existent object '" << params->Get("name") << "'.";
<< "Could not delete non-existent object '" << params->Get("name") << "' with type '" << params->Get("type") << "'.";
return Empty;
}

Expand Down
30 changes: 26 additions & 4 deletions lib/remote/apilistener.cpp
Expand Up @@ -689,7 +689,7 @@ void ApiListener::SyncSendMessage(const Endpoint::Ptr& endpoint, const Dictionar

if (!endpoint->GetSyncing()) {
Log(LogNotice, "ApiListener")
<< "Sending message to '" << endpoint->GetName() << "'";
<< "Sending message '" << message->Get("method") << "' to '" << endpoint->GetName() << "'";

double maxTs = 0;

Expand All @@ -713,17 +713,39 @@ bool ApiListener::RelayMessageOne(const Zone::Ptr& targetZone, const MessageOrig

Zone::Ptr myZone = Zone::GetLocalZone();

/* only relay the message to a) the same zone, b) the parent zone and c) direct child zones */
if (targetZone != myZone && targetZone != myZone->GetParent() && targetZone->GetParent() != myZone)
/* only relay the message to a) the same zone, b) the parent zone and c) direct child zones. Exception is a global zone. */
if (!targetZone->GetGlobal() &&
targetZone != myZone &&
targetZone != myZone->GetParent() &&
targetZone->GetParent() != myZone) {
Log(LogCritical, "ApiListener")
<< "Not relaying message '" << message->Get("method") << "'. Not in the same/parent/child zone.";
return true;
}

Endpoint::Ptr myEndpoint = GetLocalEndpoint();

std::vector<Endpoint::Ptr> skippedEndpoints;

bool relayed = false, log_needed = false, log_done = false;

for (const Endpoint::Ptr& endpoint : targetZone->GetEndpoints()) {
std::set<Endpoint::Ptr> targetEndpoints;

if (targetZone->GetGlobal()) {
targetEndpoints = myZone->GetEndpoints();

for (const Zone::Ptr& zone : ConfigType::GetObjectsByType<Zone>()) {
/* Fetch immediate child zone members */
if (zone->GetParent() == myZone) {
std::set<Endpoint::Ptr> endpoints = zone->GetEndpoints();
targetEndpoints.insert(endpoints.begin(), endpoints.end());
}
}
} else {
targetEndpoints = targetZone->GetEndpoints();
}

for (const Endpoint::Ptr& endpoint : targetEndpoints) {
/* don't relay messages to ourselves */
if (endpoint == GetLocalEndpoint())
continue;
Expand Down
3 changes: 3 additions & 0 deletions lib/remote/zone.cpp
Expand Up @@ -103,6 +103,9 @@ bool Zone::CanAccessObject(const ConfigObject::Ptr& object)
if (!object_zone)
object_zone = Zone::GetLocalZone();

if (object_zone->GetGlobal())
return true;

return object_zone->IsChildOf(this);
}

Expand Down

0 comments on commit 40d68fc

Please sign in to comment.