mirror of https://github.com/Icinga/icinga2.git
Implement initial api object sync for newly connected endpoints
TODO: Figure out how to deal with Shutdown() deactivating and therefore deleting all api created objects. refs #9927
This commit is contained in:
parent
a6d8cea5c2
commit
4955c28b0c
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -188,9 +188,9 @@ void ApiListener::SendConfigUpdate(const JsonRpcConnection::Ptr& aclient)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (zone->IsGlobal())
|
||||
Log(LogInformation, "ApiListener")
|
||||
<< "Syncing global zone '" << zone->GetName() << "'.";
|
||||
<< "Syncing " << (zone->IsGlobal() ? "global " : "")
|
||||
<< "zone '" << zone->GetName() << "' to endpoint '" << endpoint->GetName() << "'.";
|
||||
|
||||
configUpdate->Set(zone->GetName(), LoadConfigDir(zonesDir + "/" + zone->GetName()));
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue