From 8e61490530fa8a6dccf904912bc5798d95abd5bf Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 14 Jun 2012 16:09:04 +0200 Subject: [PATCH] Checker/delegation fixes. --- base/i2-base.h | 1 + base/object.cpp | 1 - base/object.h | 2 +- components/checker/checkercomponent.cpp | 18 ++++++++++++---- components/delegation/delegationcomponent.cpp | 21 +++++++++++-------- components/delegation/delegationcomponent.h | 2 +- 6 files changed, 29 insertions(+), 16 deletions(-) diff --git a/base/i2-base.h b/base/i2-base.h index 22d94f9c7..4dcc25e3e 100644 --- a/base/i2-base.h +++ b/base/i2-base.h @@ -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 */ diff --git a/base/object.cpp b/base/object.cpp index 477477f40..9e38f7e0f 100644 --- a/base/object.cpp +++ b/base/object.cpp @@ -52,7 +52,6 @@ void Object::Hold(void) */ void Object::ClearHeldObjects(void) { - cout << "Cleared " << m_HeldObjects.size() << " held objects." << endl; m_HeldObjects.clear(); } diff --git a/base/object.h b/base/object.h index cc8507cb7..273d86b6c 100644 --- a/base/object.h +++ b/base/object.h @@ -29,7 +29,7 @@ namespace icinga * * @ingroup base */ -class I2_BASE_API Object : public enable_shared_from_this, boost::signals::trackable +class I2_BASE_API Object : public enable_shared_from_this, public boost::signals::trackable { public: typedef shared_ptr Ptr; diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index e9281a246..3b451efca 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -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(¶ms)) + return 0; + + MessagePart serviceMsg; + if (!params.GetProperty("service", &serviceMsg)) + return 0; + + ConfigObject::Ptr object = make_shared(serviceMsg.GetDictionary()); + Service service(object); + m_Services.push(service); + + Application::Log("Accepted service '" + service.GetName() + "'"); + ResponseMessage rm; rm.SetID(id); diff --git a/components/delegation/delegationcomponent.cpp b/components/delegation/delegationcomponent.cpp index 8c6c50f26..4bb7cf2ab 100644 --- a/components/delegation/delegationcomponent.cpp +++ b/components/delegation/delegationcomponent.cpp @@ -29,19 +29,15 @@ string DelegationComponent::GetName(void) const void DelegationComponent::Start(void) { m_AllServices = make_shared(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(); 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; } diff --git a/components/delegation/delegationcomponent.h b/components/delegation/delegationcomponent.h index 7712ef9f3..ade9183b3 100644 --- a/components/delegation/delegationcomponent.h +++ b/components/delegation/delegationcomponent.h @@ -40,7 +40,7 @@ private: int NewServiceHandler(const ObjectSetEventArgs& ea); int RemovedServiceHandler(const ObjectSetEventArgs& 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);