mirror of https://github.com/Icinga/icinga2.git
Checker/delegation fixes.
This commit is contained in:
parent
e66285ddc5
commit
8e61490530
|
@ -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 */
|
||||
|
|
|
@ -52,7 +52,6 @@ void Object::Hold(void)
|
|||
*/
|
||||
void Object::ClearHeldObjects(void)
|
||||
{
|
||||
cout << "Cleared " << m_HeldObjects.size() << " held objects." << endl;
|
||||
m_HeldObjects.clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<ConfigObject>(serviceMsg.GetDictionary());
|
||||
Service service(object);
|
||||
m_Services.push(service);
|
||||
|
||||
Application::Log("Accepted service '" + service.GetName() + "'");
|
||||
|
||||
ResponseMessage rm;
|
||||
rm.SetID(id);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue