diff --git a/lib/remote/apilistener-configsync.cpp b/lib/remote/apilistener-configsync.cpp index f244938ae..a0e992971 100644 --- a/lib/remote/apilistener-configsync.cpp +++ b/lib/remote/apilistener-configsync.cpp @@ -36,6 +36,7 @@ REGISTER_APIFUNCTION(DeleteObject, config, &ApiListener::ConfigDeleteObjectAPIHa void ApiListener::StaticInitialize(void) { + //TODO: Figure out how to delete objects during runtime, but not on shutdown (object inactive) ConfigObject::OnActiveChanged.connect(&ApiListener::ConfigUpdateObjectHandler); ConfigObject::OnVersionChanged.connect(&ApiListener::ConfigUpdateObjectHandler); } @@ -293,3 +294,35 @@ void ApiListener::DeleteConfigObject(const ConfigObject::Ptr& object, const Mess else RelayMessage(origin, object, message, false); } + +void ApiListener::SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient) +{ + Endpoint::Ptr endpoint = aclient->GetEndpoint(); + ASSERT(endpoint); + + Zone::Ptr azone = endpoint->GetZone(); + Zone::Ptr lzone = Zone::GetLocalZone(); + + /* only sync objects in the same zone for now */ + if (azone->GetName() != lzone->GetName()) { + Log(LogWarning, "ApiListener") + << "Skipping object sync to endpoint '" << endpoint->GetName() + << "' in zone '" << azone->GetName() << "'. Not in the same zone '" + << lzone->GetName() << "'."; + return; + } + + Log(LogInformation, "ApiListener") + << "Syncing runtime objects to endpoint '" << endpoint->GetName() << "'."; + + //TODO get the active stage for "_api" and all objects instead of fetching all objects in memory? + BOOST_FOREACH(const ConfigType::Ptr& dt, ConfigType::GetTypes()) { + BOOST_FOREACH(const ConfigObject::Ptr& object, dt->GetObjects()) { + if (object->GetPackage() != "_api") + continue; + + /* send the config object to the connected client */ + UpdateConfigObject(object, MessageOrigin::Ptr(), aclient); + } + } +} diff --git a/lib/remote/apilistener-filesync.cpp b/lib/remote/apilistener-filesync.cpp index 7a998be48..74b55e020 100644 --- a/lib/remote/apilistener-filesync.cpp +++ b/lib/remote/apilistener-filesync.cpp @@ -188,9 +188,9 @@ void ApiListener::SendConfigUpdate(const JsonRpcConnection::Ptr& aclient) continue; } - if (zone->IsGlobal()) - Log(LogInformation, "ApiListener") - << "Syncing global zone '" << zone->GetName() << "'."; + Log(LogInformation, "ApiListener") + << "Syncing " << (zone->IsGlobal() ? "global " : "") + << "zone '" << zone->GetName() << "' to endpoint '" << endpoint->GetName() << "'."; configUpdate->Set(zone->GetName(), LoadConfigDir(zonesDir + "/" + zone->GetName())); } diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 78db25756..e25983332 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -380,7 +380,10 @@ void ApiListener::NewClientHandlerInternal(const Socket::Ptr& client, const Stri ReplayLog(aclient); } + /* sync zone file config */ SendConfigUpdate(aclient); + /* sync runtime config */ + SendRuntimeConfigObjects(aclient); } else AddAnonymousClient(aclient); } else { diff --git a/lib/remote/apilistener.hpp b/lib/remote/apilistener.hpp index 88943a18f..786714b5a 100644 --- a/lib/remote/apilistener.hpp +++ b/lib/remote/apilistener.hpp @@ -136,6 +136,7 @@ private: const JsonRpcConnection::Ptr& client = JsonRpcConnection::Ptr()); void DeleteConfigObject(const ConfigObject::Ptr& object, const MessageOrigin::Ptr& origin, const JsonRpcConnection::Ptr& client = JsonRpcConnection::Ptr()); + void SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient); }; }