]> granicus.if.org Git - icinga2/commitdiff
Added discovery component.
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 23 Apr 2012 14:49:02 +0000 (16:49 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 23 Apr 2012 14:49:02 +0000 (16:49 +0200)
components/configrpc/configrpccomponent.cpp
icinga/authenticationcomponent.cpp
icinga/discoverycomponent.cpp [new file with mode: 0644]
icinga/discoverycomponent.h [new file with mode: 0644]
icinga/endpoint.cpp
icinga/endpoint.h
icinga/i2-icinga.h
icinga/icinga.vcxproj

index 9fd60bec88a940c8039ad6f2c2992bc95edc3f53..062070f23a003b9581d4f7474890530a8cd19d9a 100644 (file)
@@ -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);
                }
        }
 
index 3adff23cf81b769774435bcef5c99f541e67fd66..f5b0ec21783eba505b358d3bfd85c147a1a119a2 100644 (file)
@@ -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;
 }
diff --git a/icinga/discoverycomponent.cpp b/icinga/discoverycomponent.cpp
new file mode 100644 (file)
index 0000000..31667bd
--- /dev/null
@@ -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;
+}
diff --git a/icinga/discoverycomponent.h b/icinga/discoverycomponent.h
new file mode 100644 (file)
index 0000000..20ec3b5
--- /dev/null
@@ -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 */
index 38f6f8148299c6d6caa92f713e94a324893dbef3..98165032980a147b7d9d9e0950ca62990aeaa45b 100644 (file)
@@ -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
index 317cbd956e6aa00203e8ca60d1d7248b08310711..1980fdd48e89744339cba7b9e9113b2c9fd12fb2 100644 (file)
@@ -64,6 +64,8 @@ public:
 
        int CountMethodSinks(void) const;
        int CountMethodSources(void) const;
+
+       Event<EventArgs> OnIdentityChanged;
 };
 
 }
index ed01699dc0b4f9fc9e8e2e67ee7ba2b83ad391ec..0cd6c511e3fb0ec9bc89e48e06b9cae253fadb6a 100644 (file)
@@ -20,5 +20,6 @@
 #include "subscriptionmessage.h"
 #include "authenticationcomponent.h"
 #include "identitymessage.h"
+#include "discoverycomponent.h"
 
 #endif /* I2ICINGA_H */
index e7f0406fb77dacff3c4f35725eafa4fa5d1c369b..829cc38ac16b790ef3a7ea02c007f7e8429e1d27 100644 (file)
@@ -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" />