]> granicus.if.org Git - icinga2/commitdiff
Bugfixes.
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 21 Jun 2012 15:39:16 +0000 (17:39 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 21 Jun 2012 15:39:16 +0000 (17:39 +0200)
base/timer.cpp
components/configrpc/configrpccomponent.cpp
components/delegation/delegationcomponent.cpp
components/delegation/delegationcomponent.h
components/discovery/discoverycomponent.cpp

index d7646c59d8222e89f452f5c1822910b693769ff4..6efe52aaf423d7ccc666ffda6f81e6d68164c7ee 100644 (file)
@@ -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());
        }
 }
 
index c93f67d0047a15b42b3d7b0b5bd26d61beb1f91c..4d9f017cb2b65d1ba17cff36db5ffa68aa978400 100644 (file)
@@ -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));
 }
 
index a499c7ac29f02503257d0c8f36526d70a5743adc..19f9c86262cd3c7646873363f5af07c4e662abf8 100644 (file)
@@ -30,9 +30,6 @@ string DelegationComponent::GetName(void) const
 void DelegationComponent::Start(void)
 {
        m_AllServices = boost::make_shared<ConfigObject::Set>(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<Timer>();
@@ -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<Endpoint::Ptr> 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<Endpoint::Ptr, int> 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<Endpoint::Ptr, int>::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());
 }
 
index 44140deb4fe10db71ef4d471c32f599064a899e9..1369f04253a41b5e14955b1cc0d5848137870dcf 100644 (file)
@@ -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);
index daf433b2fba1cd3aa74ae93a9ae008e03c23c4b0..263827a38655360651ddd98b703392d2e6eafa9e 100644 (file)
@@ -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++;