Runtime objects: send config::HaveObjects to v2.13+ on connect

refs #8210
This commit is contained in:
Alexander A. Klimov 2020-09-04 15:48:05 +02:00
parent 8c6998b66d
commit ee211daf76
3 changed files with 65 additions and 2 deletions

View File

@ -427,7 +427,7 @@ void ApiListener::DeleteConfigObject(const ConfigObject::Ptr& object, const Mess
} }
} }
/* Initial sync on connect for new endpoints */ /* Initial sync on connect for new endpoints < v2.13 */
void ApiListener::SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient) void ApiListener::SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient)
{ {
Endpoint::Ptr endpoint = aclient->GetEndpoint(); Endpoint::Ptr endpoint = aclient->GetEndpoint();
@ -457,3 +457,59 @@ void ApiListener::SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient
Log(LogInformation, "ApiListener") Log(LogInformation, "ApiListener")
<< "Finished syncing runtime objects to endpoint '" << endpoint->GetName() << "'."; << "Finished syncing runtime objects to endpoint '" << endpoint->GetName() << "'.";
} }
/* Initial sync on connect for new endpoints >= v2.13 */
void ApiListener::DeclareRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient)
{
Endpoint::Ptr endpoint = aclient->GetEndpoint();
ASSERT(endpoint);
Zone::Ptr azone = endpoint->GetZone();
Log(LogInformation, "ApiListener")
<< "Informing endpoint '" << endpoint->GetName() << "' about runtime objects.";
Dictionary::Ptr versions = new Dictionary();
for (auto& type : Type::GetAllTypes()) {
auto ctype (dynamic_cast<ConfigType*>(type.get()));
if (!ctype) {
continue;
}
for (auto& object : ctype->GetObjects()) {
if (object->GetPackage() != "_api" && object->GetVersion() == 0) {
continue;
}
/* don't sync objects for non-matching parent-child zones */
if (!azone->CanAccessObject(object)) {
continue;
}
auto type (object->GetReflectionType()->GetName());
Dictionary::Ptr perType = versions->Get(type);
if (!perType) {
perType = new Dictionary();
versions->Set(type, perType);
}
perType->Set(object->GetName(), object->GetVersion());
}
}
if (versions->GetLength()) {
aclient->SendMessage(new Dictionary({
{ "jsonrpc", "2.0" },
{ "method", "config::HaveObjects" },
{ "params", new Dictionary({
{ "versions", versions }
}) }
}));
}
Log(LogInformation, "ApiListener")
<< "Finished informing endpoint '" << endpoint->GetName() << "' about runtime objects.";
}

View File

@ -787,6 +787,8 @@ void ApiListener::SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoi
Log(LogInformation, "ApiListener") Log(LogInformation, "ApiListener")
<< "Sending config updates for endpoint '" << endpoint->GetName() << "' in zone '" << eZone->GetName() << "'."; << "Sending config updates for endpoint '" << endpoint->GetName() << "' in zone '" << eZone->GetName() << "'.";
bool negotiate = endpoint->GetVersion() >= 21300;
/* sync zone file config */ /* sync zone file config */
SendConfigUpdate(aclient); SendConfigUpdate(aclient);
@ -794,7 +796,11 @@ void ApiListener::SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoi
<< "Finished sending config file updates for endpoint '" << endpoint->GetName() << "' in zone '" << eZone->GetName() << "'."; << "Finished sending config file updates for endpoint '" << endpoint->GetName() << "' in zone '" << eZone->GetName() << "'.";
/* sync runtime config */ /* sync runtime config */
SendRuntimeConfigObjects(aclient); if (negotiate) {
DeclareRuntimeConfigObjects(aclient);
} else {
SendRuntimeConfigObjects(aclient);
}
Log(LogInformation, "ApiListener") Log(LogInformation, "ApiListener")
<< "Finished sending runtime config updates for endpoint '" << endpoint->GetName() << "' in zone '" << eZone->GetName() << "'."; << "Finished sending runtime config updates for endpoint '" << endpoint->GetName() << "' in zone '" << eZone->GetName() << "'.";

View File

@ -214,6 +214,7 @@ private:
void DeleteConfigObject(const ConfigObject::Ptr& object, const MessageOrigin::Ptr& origin, void DeleteConfigObject(const ConfigObject::Ptr& object, const MessageOrigin::Ptr& origin,
const JsonRpcConnection::Ptr& client = nullptr); const JsonRpcConnection::Ptr& client = nullptr);
void SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient); void SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient);
void DeclareRuntimeConfigObjects(const JsonRpcConnection::Ptr& client);
void SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoint::Ptr& endpoint, bool needSync); void SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoint::Ptr& endpoint, bool needSync);