Improve performance for Endpoint config validation

fixes #12450
This commit is contained in:
Gunnar Beutner 2016-08-16 13:53:45 +02:00
parent 832b5bed2a
commit 81974adf65
4 changed files with 21 additions and 15 deletions

View File

@ -39,26 +39,20 @@ void Endpoint::OnAllConfigLoaded(void)
{
ObjectImpl<Endpoint>::OnAllConfigLoaded();
BOOST_FOREACH(const Zone::Ptr& zone, ConfigType::GetObjectsByType<Zone>()) {
const std::set<Endpoint::Ptr> members = zone->GetEndpoints();
if (members.empty())
continue;
if (members.find(this) != members.end()) {
if (m_Zone)
BOOST_THROW_EXCEPTION(ScriptError("Endpoint '" + GetName()
+ "' is in more than one zone.", GetDebugInfo()));
m_Zone = zone;
}
}
if (!m_Zone)
BOOST_THROW_EXCEPTION(ScriptError("Endpoint '" + GetName() +
"' does not belong to a zone.", GetDebugInfo()));
}
void Endpoint::SetCachedZone(const Zone::Ptr& zone)
{
if (m_Zone)
BOOST_THROW_EXCEPTION(ScriptError("Endpoint '" + GetName()
+ "' is in more than one zone.", GetDebugInfo()));
m_Zone = zone;
}
void Endpoint::AddClient(const JsonRpcConnection::Ptr& client)
{
bool was_master = ApiListener::GetInstance()->IsMaster();

View File

@ -54,6 +54,8 @@ public:
static Endpoint::Ptr GetLocalEndpoint(void);
void SetCachedZone(const intrusive_ptr<Zone>& zone);
protected:
virtual void OnAllConfigLoaded(void) override;

View File

@ -26,6 +26,8 @@ namespace icinga
class Endpoint : ConfigObject
{
load_after Zone;
[config] String host;
[config, required] String port {
default {{{ return "5665"; }}}

View File

@ -37,6 +37,14 @@ void Zone::OnAllConfigLoaded(void)
Zone::Ptr zone = m_Parent;
int levels = 0;
Array::Ptr endpoints = GetEndpointsRaw();
if (endpoints) {
BOOST_FOREACH(const String& endpoint, endpoints) {
Endpoint::GetByName(endpoint)->SetCachedZone(this);
}
}
while (zone) {
m_AllParents.push_back(zone);