mirror of https://github.com/Icinga/icinga2.git
Added discovery component.
This commit is contained in:
parent
5fa34a3e3d
commit
885f1834f1
|
@ -56,7 +56,9 @@ int ConfigRpcComponent::NewEndpointHandler(const NewEndpointEventArgs& ea)
|
|||
if (ea.Endpoint->HasIdentity()) {
|
||||
JsonRpcRequest request;
|
||||
request.SetMethod("config::FetchObjects");
|
||||
ea.Endpoint->ProcessRequest(m_ConfigRpcEndpoint, request);
|
||||
|
||||
EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
|
||||
endpointManager->SendUnicastRequest(m_ConfigRpcEndpoint, ea.Endpoint, request);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -111,7 +113,10 @@ int ConfigRpcComponent::FetchObjectsHandler(const NewRequestEventArgs& ea)
|
|||
if (!ShouldReplicateObject(object))
|
||||
continue;
|
||||
|
||||
client->ProcessRequest(m_ConfigRpcEndpoint, MakeObjectMessage(object, "config::ObjectCreated", true));
|
||||
JsonRpcRequest request = MakeObjectMessage(object, "config::ObjectCreated", true);
|
||||
|
||||
EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
|
||||
endpointManager->SendUnicastRequest(m_ConfigRpcEndpoint, client, request);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ void AuthenticationComponent::Start(void)
|
|||
{
|
||||
m_AuthenticationEndpoint = make_shared<VirtualEndpoint>();
|
||||
m_AuthenticationEndpoint->RegisterMethodHandler("auth::SetIdentity", bind_weak(&AuthenticationComponent::IdentityMessageHandler, shared_from_this()));
|
||||
m_AuthenticationEndpoint->RegisterMethodSource("auth::Welcome");
|
||||
|
||||
EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
|
||||
mgr->OnNewEndpoint += bind_weak(&AuthenticationComponent::NewEndpointHandler, shared_from_this());
|
||||
|
@ -48,7 +49,8 @@ int AuthenticationComponent::NewEndpointHandler(const NewEndpointEventArgs& neea
|
|||
params.SetIdentity("keks");
|
||||
request.SetParams(params);
|
||||
|
||||
neea.Endpoint->ProcessRequest(m_AuthenticationEndpoint, request);
|
||||
EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
|
||||
endpointManager->SendUnicastRequest(m_AuthenticationEndpoint, neea.Endpoint, request);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -70,7 +72,9 @@ int AuthenticationComponent::IdentityMessageHandler(const NewRequestEventArgs& n
|
|||
/* there's no authentication for now, just tell them it's ok to send messages */
|
||||
JsonRpcRequest request;
|
||||
request.SetMethod("auth::Welcome");
|
||||
nrea.Sender->ProcessRequest(m_AuthenticationEndpoint, request);
|
||||
|
||||
EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
|
||||
endpointManager->SendUnicastRequest(m_AuthenticationEndpoint, nrea.Sender, request);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
#include "i2-icinga.h"
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
IcingaApplication::Ptr DiscoveryComponent::GetIcingaApplication(void) const
|
||||
{
|
||||
return static_pointer_cast<IcingaApplication>(GetApplication());
|
||||
}
|
||||
|
||||
string DiscoveryComponent::GetName(void) const
|
||||
{
|
||||
return "discoverycomponent";
|
||||
}
|
||||
|
||||
void DiscoveryComponent::Start(void)
|
||||
{
|
||||
m_DiscoveryEndpoint = make_shared<VirtualEndpoint>();
|
||||
m_DiscoveryEndpoint->RegisterMethodSource("discovery::PeerAvailable");
|
||||
m_DiscoveryEndpoint->RegisterMethodHandler("auth::Welcome",
|
||||
bind_weak(&DiscoveryComponent::WelcomeMessageHandler, shared_from_this()));
|
||||
m_DiscoveryEndpoint->RegisterMethodHandler("discovery::GetPeers",
|
||||
bind_weak(&DiscoveryComponent::GetPeersMessageHandler, shared_from_this()));
|
||||
|
||||
EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
|
||||
mgr->RegisterEndpoint(m_DiscoveryEndpoint);
|
||||
}
|
||||
|
||||
void DiscoveryComponent::Stop(void)
|
||||
{
|
||||
IcingaApplication::Ptr app = GetIcingaApplication();
|
||||
|
||||
if (app) {
|
||||
EndpointManager::Ptr mgr = app->GetEndpointManager();
|
||||
mgr->UnregisterEndpoint(m_DiscoveryEndpoint);
|
||||
}
|
||||
}
|
||||
|
||||
int DiscoveryComponent::NewEndpointHandler(const NewEndpointEventArgs& neea)
|
||||
{
|
||||
neea.Endpoint->OnIdentityChanged += bind_weak(&DiscoveryComponent::IdentityChangedHandler, shared_from_this());
|
||||
|
||||
/* TODO: register handler for new sink/source */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DiscoveryComponent::IdentityChangedHandler(const EventArgs& neea)
|
||||
{
|
||||
/* TODO: send information about this client to all other clients */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& nrea)
|
||||
{
|
||||
JsonRpcRequest request;
|
||||
request.SetMethod("discovery::GetPeers");
|
||||
|
||||
EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
|
||||
endpointManager->SendUnicastRequest(m_DiscoveryEndpoint, nrea.Sender, request);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DiscoveryComponent::GetPeersMessageHandler(const NewRequestEventArgs& nrea)
|
||||
{
|
||||
/* TODO: send information about all available clients to this client */
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef DISCOVERYCOMPONENT_H
|
||||
#define DISCOVERYCOMPONENT_H
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
class DiscoveryComponent : public Component
|
||||
{
|
||||
private:
|
||||
VirtualEndpoint::Ptr m_DiscoveryEndpoint;
|
||||
|
||||
IcingaApplication::Ptr GetIcingaApplication(void) const;
|
||||
|
||||
int NewEndpointHandler(const NewEndpointEventArgs& neea);
|
||||
int IdentityChangedHandler(const EventArgs& neea);
|
||||
int WelcomeMessageHandler(const NewRequestEventArgs& nrea);
|
||||
int GetPeersMessageHandler(const NewRequestEventArgs& nrea);
|
||||
|
||||
public:
|
||||
virtual string GetName(void) const;
|
||||
virtual void Start(void);
|
||||
virtual void Stop(void);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* DISCOVERYCOMPONENT_H */
|
|
@ -10,6 +10,10 @@ string Endpoint::GetIdentity(void) const
|
|||
void Endpoint::SetIdentity(string identity)
|
||||
{
|
||||
m_Identity = identity;
|
||||
|
||||
EventArgs ea;
|
||||
ea.Source = shared_from_this();
|
||||
OnIdentityChanged(ea);
|
||||
}
|
||||
|
||||
bool Endpoint::HasIdentity(void) const
|
||||
|
|
|
@ -64,6 +64,8 @@ public:
|
|||
|
||||
int CountMethodSinks(void) const;
|
||||
int CountMethodSources(void) const;
|
||||
|
||||
Event<EventArgs> OnIdentityChanged;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -20,5 +20,6 @@
|
|||
#include "subscriptionmessage.h"
|
||||
#include "authenticationcomponent.h"
|
||||
#include "identitymessage.h"
|
||||
#include "discoverycomponent.h"
|
||||
|
||||
#endif /* I2ICINGA_H */
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="authenticationcomponent.cpp" />
|
||||
<ClCompile Include="discoverycomponent.cpp" />
|
||||
<ClCompile Include="endpoint.cpp" />
|
||||
<ClCompile Include="endpointmanager.cpp" />
|
||||
<ClCompile Include="icingaapplication.cpp" />
|
||||
|
@ -23,6 +24,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="authenticationcomponent.h" />
|
||||
<ClInclude Include="discoverycomponent.h" />
|
||||
<ClInclude Include="endpoint.h" />
|
||||
<ClInclude Include="endpointmanager.h" />
|
||||
<ClInclude Include="i2-icinga.h" />
|
||||
|
|
Loading…
Reference in New Issue