From: Gunnar Beutner Date: Thu, 21 Jun 2012 15:39:16 +0000 (+0200) Subject: Bugfixes. X-Git-Tag: v0.0.1~380 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7ed19cd533576fa749ad5ad3542e2f99e006d167;p=icinga2 Bugfixes. --- diff --git a/base/timer.cpp b/base/timer.cpp index d7646c59d..6efe52aaf 100644 --- a/base/timer.cpp +++ b/base/timer.cpp @@ -110,7 +110,7 @@ void Timer::Call(void) if (et - st > 3) { stringstream msgbuf; msgbuf << "Timer call took " << et - st << " seconds."; - Application::Log(LogInformation, "base", msgbuf.str()); + Application::Log(LogWarning, "base", msgbuf.str()); } } diff --git a/components/configrpc/configrpccomponent.cpp b/components/configrpc/configrpccomponent.cpp index c93f67d00..4d9f017cb 100644 --- a/components/configrpc/configrpccomponent.cpp +++ b/components/configrpc/configrpccomponent.cpp @@ -66,6 +66,10 @@ void ConfigRpcComponent::Stop(void) void ConfigRpcComponent::NewEndpointHandler(const Endpoint::Ptr& endpoint) { + /* no need to sync the config with local endpoints */ + if (endpoint->IsLocal()) + return; + endpoint->OnSessionEstablished.connect(boost::bind(&ConfigRpcComponent::SessionEstablishedHandler, this, _1)); } diff --git a/components/delegation/delegationcomponent.cpp b/components/delegation/delegationcomponent.cpp index a499c7ac2..19f9c8626 100644 --- a/components/delegation/delegationcomponent.cpp +++ b/components/delegation/delegationcomponent.cpp @@ -30,9 +30,6 @@ string DelegationComponent::GetName(void) const void DelegationComponent::Start(void) { m_AllServices = boost::make_shared(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("service")); -/* m_AllServices->OnObjectAdded.connect(boost::bind(&DelegationComponent::NewServiceHandler, this, _2)); - m_AllServices->OnObjectCommitted.connect(boost::bind(&DelegationComponent::NewServiceHandler, this, _2)); - m_AllServices->OnObjectRemoved.connect(boost::bind(&DelegationComponent::RemovedServiceHandler, this, _2));*/ m_AllServices->Start(); m_DelegationTimer = boost::make_shared(); @@ -45,6 +42,8 @@ void DelegationComponent::Start(void) m_DelegationEndpoint->RegisterPublication("checker::AssignService"); m_DelegationEndpoint->RegisterPublication("checker::ClearServices"); GetEndpointManager()->RegisterEndpoint(m_DelegationEndpoint); + + GetEndpointManager()->OnNewEndpoint.connect(bind(&DelegationComponent::NewEndpointHandler, this, _2)); } void DelegationComponent::Stop(void) @@ -110,6 +109,29 @@ vector DelegationComponent::GetCheckerCandidates(const Service& s return candidates; } +void DelegationComponent::NewEndpointHandler(const Endpoint::Ptr& endpoint) +{ + endpoint->OnSessionEstablished.connect(bind(&DelegationComponent::SessionEstablishedHandler, this, _1)); +} +void DelegationComponent::SessionEstablishedHandler(const Endpoint::Ptr& endpoint) +{ + stringstream msgbuf; + msgbuf << "Clearing assigned services for endpoint '" << endpoint->GetIdentity() << "'"; + Application::Log(LogInformation, "delegation", msgbuf.str()); + + /* locally clear checker for all services that previously belonged to this endpoint */ + ConfigObject::Set::Iterator it; + for (it = m_AllServices->Begin(); it != m_AllServices->End(); it++) { + Service service = *it; + + if (service.GetChecker() == endpoint->GetIdentity()) + service.SetChecker(""); + } + + /* remotely clear services for this endpoint */ + ClearServices(endpoint); +} + void DelegationComponent::DelegationTimerHandler(void) { map histogram; @@ -208,9 +230,6 @@ void DelegationComponent::DelegationTimerHandler(void) } if (delegated > 0) { - // TODO: send clear message when session is established - // TODO: clear local assignments when session is lost - need_clear = true; /* remove this once clear messages are properly sent */ if (need_clear) { map::iterator hit; for (hit = histogram.begin(); hit != histogram.end(); hit++) { @@ -230,7 +249,7 @@ void DelegationComponent::DelegationTimerHandler(void) } stringstream msgbuf; - msgbuf << "Re-delegated " << delegated << " services"; + msgbuf << "Updated delegations for " << delegated << " services"; Application::Log(LogInformation, "delegation", msgbuf.str()); } diff --git a/components/delegation/delegationcomponent.h b/components/delegation/delegationcomponent.h index 44140deb4..1369f0425 100644 --- a/components/delegation/delegationcomponent.h +++ b/components/delegation/delegationcomponent.h @@ -38,6 +38,9 @@ private: ConfigObject::Set::Ptr m_AllServices; Timer::Ptr m_DelegationTimer; + void NewEndpointHandler(const Endpoint::Ptr& endpoint); + void SessionEstablishedHandler(const Endpoint::Ptr& endpoint); + void AssignServiceResponseHandler(Service& service, const Endpoint::Ptr& sender, bool timedOut); void DelegationTimerHandler(void); diff --git a/components/discovery/discoverycomponent.cpp b/components/discovery/discoverycomponent.cpp index daf433b2f..263827a38 100644 --- a/components/discovery/discoverycomponent.cpp +++ b/components/discovery/discoverycomponent.cpp @@ -105,9 +105,11 @@ void DiscoveryComponent::CheckExistingEndpoint(const Endpoint::Ptr& self, const */ void DiscoveryComponent::NewEndpointHandler(const Endpoint::Ptr& endpoint) { - /* ignore local endpoints */ - if (endpoint->IsLocal()) + /* immediately finish session setup for local endpoints */ + if (endpoint->IsLocal()) { + endpoint->OnSessionEstablished(endpoint); return; + } /* accept discovery::RegisterComponent messages from any endpoint */ endpoint->RegisterPublication("discovery::RegisterComponent"); @@ -414,8 +416,8 @@ void DiscoveryComponent::ProcessDiscoveryMessage(const string& identity, const D SendDiscoveryMessage("discovery::NewComponent", identity, Endpoint::Ptr()); - /* don't send a welcome message for discovery::RegisterComponent messages */ - if (endpoint && trusted) + /* don't send a welcome message for discovery::NewComponent messages */ + if (endpoint && !trusted) FinishDiscoverySetup(endpoint); } @@ -485,6 +487,12 @@ void DiscoveryComponent::DiscoveryTimerHandler(void) if (identity == GetEndpointManager()->GetIdentity()) continue; + /* for explicitly-configured upstream endpoints + * we prefer to use the node/service from the + * config object - which is what the for loop above does */ + if (ConfigObject::GetObject("endpoint", identity)) + continue; + curr = i; i++;