]> granicus.if.org Git - icinga2/commitdiff
Checker/delegation fixes.
authorGunnar Beutner <gunnar@beutner.name>
Thu, 14 Jun 2012 14:09:04 +0000 (16:09 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Thu, 14 Jun 2012 14:09:04 +0000 (16:09 +0200)
base/i2-base.h
base/object.cpp
base/object.h
components/checker/checkercomponent.cpp
components/delegation/delegationcomponent.cpp
components/delegation/delegationcomponent.h

index 22d94f9c75a6a52e458cf76b8700d447d29a91b1..4dcc25e3ef9027c74bf2b189404c6dc012655f8f 100644 (file)
@@ -55,6 +55,7 @@
 #ifdef _MSC_VER
 #      define HAVE_STDCXX_0X
 #      pragma warning(disable:4251)
+#      pragma warning(disable:4275)
 #      define _CRT_SECURE_NO_DEPRECATE
 #      define _CRT_SECURE_NO_WARNINGS
 #else /* _MSC_VER */
index 477477f40fb82aecb167b658bf00fbb68d11cc1a..9e38f7e0f77d0d2e784caa3732b1e89f90ae2df8 100644 (file)
@@ -52,7 +52,6 @@ void Object::Hold(void)
  */
 void Object::ClearHeldObjects(void)
 {
-       cout << "Cleared " << m_HeldObjects.size() << " held objects." << endl;
        m_HeldObjects.clear();
 }
 
index cc8507cb7a3100ee712637599519419474e456f2..273d86b6c3e124c17338cbcfb17e8d7fb6e23f31 100644 (file)
@@ -29,7 +29,7 @@ namespace icinga
  *
  * @ingroup base
  */
-class I2_BASE_API Object : public enable_shared_from_this<Object>, boost::signals::trackable
+class I2_BASE_API Object : public enable_shared_from_this<Object>, public boost::signals::trackable
 {
 public:
        typedef shared_ptr<Object> Ptr;
index e9281a246c3de716876a04a21eaf44ecc9574da5..3b451efcaca7a11cebb43db726b61f0e62be4cd5 100644 (file)
@@ -36,10 +36,6 @@ void CheckerComponent::Start(void)
        m_CheckerEndpoint->RegisterPublication("checker::CheckResult");
        GetEndpointManager()->RegisterEndpoint(m_CheckerEndpoint);
 
-       RequestMessage rm;
-       rm.SetMethod("checker::AssignService");
-       GetEndpointManager()->SendAPIMessage(m_CheckerEndpoint, rm, bind(&CheckerComponent::TestResponseHandler, this, _1));
-
        // TODO: get rid of this
        ConfigObject::GetAllObjects()->OnObjectAdded.connect(bind(&CheckerComponent::NewServiceHandler, this, _1));
 
@@ -111,6 +107,20 @@ int CheckerComponent::AssignServiceRequestHandler(const NewRequestEventArgs& nre
        if (!nrea.Request.GetID(&id))
                return 0;
 
+       MessagePart params;
+       if (!nrea.Request.GetParams(&params))
+               return 0;
+
+       MessagePart serviceMsg;
+       if (!params.GetProperty("service", &serviceMsg))
+               return 0;
+
+       ConfigObject::Ptr object = make_shared<ConfigObject>(serviceMsg.GetDictionary());
+       Service service(object);
+       m_Services.push(service);
+
+       Application::Log("Accepted service '" + service.GetName() + "'");
+
        ResponseMessage rm;
        rm.SetID(id);
 
index 8c6c50f2675981869e48a81a14d79af14ddf07d0..4bb7cf2abcfbc05dadf9f435de004c41879f5550 100644 (file)
@@ -29,19 +29,15 @@ string DelegationComponent::GetName(void) const
 void DelegationComponent::Start(void)
 {
        m_AllServices = make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("service"));
-       m_AllServices->OnObjectAdded += bind_weak(&DelegationComponent::NewServiceHandler, shared_from_this());
-       m_AllServices->OnObjectCommitted += bind_weak(&DelegationComponent::NewServiceHandler, shared_from_this());
-       m_AllServices->OnObjectRemoved += bind_weak(&DelegationComponent::RemovedServiceHandler, shared_from_this());
+       m_AllServices->OnObjectAdded.connect(bind(&DelegationComponent::NewServiceHandler, this, _1));
+       m_AllServices->OnObjectCommitted.connect(bind(&DelegationComponent::NewServiceHandler, this, _1));
+       m_AllServices->OnObjectRemoved.connect(bind(&DelegationComponent::RemovedServiceHandler, this, _1));
        m_AllServices->Start();
 
        m_DelegationEndpoint = make_shared<VirtualEndpoint>();
        m_DelegationEndpoint->RegisterPublication("checker::AssignService");
        m_DelegationEndpoint->RegisterPublication("checker::RevokeService");
        GetEndpointManager()->RegisterEndpoint(m_DelegationEndpoint);
-
-       RequestMessage rm;
-       rm.SetMethod("checker::AssignService");
-       GetEndpointManager()->SendAPIMessage(m_DelegationEndpoint, rm, bind(&DelegationComponent::TestResponseHandler, this, _1));
 }
 
 void DelegationComponent::Stop(void)
@@ -73,12 +69,19 @@ void DelegationComponent::AssignService(const ConfigObject::Ptr& service)
        params.SetProperty("service", service->GetProperties());
        request.SetParams(params);
 
+       Application::Log("Trying to delegate service '" + service->GetName() + "'");
+
        GetEndpointManager()->SendAPIMessage(m_DelegationEndpoint, request,
-           bind_weak(&DelegationComponent::AssignServiceResponseHandler, shared_from_this()));
+           bind(&DelegationComponent::AssignServiceResponseHandler, this, service, _1));
 }
 
-int DelegationComponent::AssignServiceResponseHandler(const NewResponseEventArgs& nrea)
+int DelegationComponent::AssignServiceResponseHandler(const ConfigObject::Ptr& service, const NewResponseEventArgs& nrea)
 {
+       if (nrea.TimedOut)
+               Application::Log("Service delegation for service '" + service->GetName() + "' timed out.");
+       else
+               Application::Log("Service delegation for service '" + service->GetName() + "'was successful.");
+
        return 0;
 }
 
index 7712ef9f3e4a5d858c7cc5c060e328c5cb00d8ac..ade9183b3577fdc80ea0783ac65ad946fca9037a 100644 (file)
@@ -40,7 +40,7 @@ private:
        int NewServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
        int RemovedServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
 
-       int AssignServiceResponseHandler(const NewResponseEventArgs& nrea);
+       int AssignServiceResponseHandler(const ConfigObject::Ptr& service, const NewResponseEventArgs& nrea);
        int RevokeServiceResponseHandler(const NewResponseEventArgs& nrea);
 
        void AssignService(const ConfigObject::Ptr& service);