[icinga-checkins] icinga.org: icinga2/master: Fix: Endpoints were not properly marked as local.

git at icinga.org git at icinga.org
Fri Jan 18 09:37:34 CET 2013


Module: icinga2
Branch: master
Commit: 5a7aeb1f19262be266bd3afc5236b6e178b0360a
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=5a7aeb1f19262be266bd3afc5236b6e178b0360a

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Fri Jan 18 09:36:28 2013 +0100

Fix: Endpoints were not properly marked as local.

---

 components/checker/checkercomponent.cpp         |    2 +-
 components/demo/democomponent.cpp               |    2 +-
 components/replication/replicationcomponent.cpp |    2 +-
 lib/remoting/endpoint.cpp                       |    5 +++--
 lib/remoting/endpoint.h                         |    2 +-
 lib/remoting/endpointmanager.cpp                |   12 +++++++-----
 6 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp
index 8e16d87..928289a 100644
--- a/components/checker/checkercomponent.cpp
+++ b/components/checker/checkercomponent.cpp
@@ -23,7 +23,7 @@ using namespace icinga;
 
 void CheckerComponent::Start(void)
 {
-	m_Endpoint = Endpoint::MakeEndpoint("checker", true);
+	m_Endpoint = Endpoint::MakeEndpoint("checker", false);
 
 	/* dummy registration so the delegation module knows this is a checker
 	   TODO: figure out a better way for this */
diff --git a/components/demo/democomponent.cpp b/components/demo/democomponent.cpp
index 17c3d4d..b72b02f 100644
--- a/components/demo/democomponent.cpp
+++ b/components/demo/democomponent.cpp
@@ -26,7 +26,7 @@ using namespace icinga;
  */
 void DemoComponent::Start(void)
 {
-	m_Endpoint = Endpoint::MakeEndpoint("demo", true);
+	m_Endpoint = Endpoint::MakeEndpoint("demo", false);
 	m_Endpoint->RegisterTopicHandler("demo::HelloWorld",
 	    boost::bind(&DemoComponent::HelloWorldRequestHandler, this, _2,
 	    _3));
diff --git a/components/replication/replicationcomponent.cpp b/components/replication/replicationcomponent.cpp
index f8ee5c6..ec71756 100644
--- a/components/replication/replicationcomponent.cpp
+++ b/components/replication/replicationcomponent.cpp
@@ -26,7 +26,7 @@ using namespace icinga;
  */
 void ReplicationComponent::Start(void)
 {
-	m_Endpoint = Endpoint::MakeEndpoint("replication", true);
+	m_Endpoint = Endpoint::MakeEndpoint("replication", false);
 
 	DynamicObject::OnRegistered.connect(boost::bind(&ReplicationComponent::LocalObjectRegisteredHandler, this, _1));
 	DynamicObject::OnUnregistered.connect(boost::bind(&ReplicationComponent::LocalObjectUnregisteredHandler, this, _1));
diff --git a/lib/remoting/endpoint.cpp b/lib/remoting/endpoint.cpp
index 99d2684..b6e89f1 100644
--- a/lib/remoting/endpoint.cpp
+++ b/lib/remoting/endpoint.cpp
@@ -76,15 +76,16 @@ Endpoint::Ptr Endpoint::GetByName(const String& name)
  * Helper function for creating new endpoint objects.
  *
  * @param name The name of the new endpoint.
+ * @param replicated Whether replication is enabled for the endpoint object.
  * @param local Whether the new endpoint should be local.
  * @returns The new endpoint.
  */
-Endpoint::Ptr Endpoint::MakeEndpoint(const String& name, bool local)
+Endpoint::Ptr Endpoint::MakeEndpoint(const String& name, bool replicated, bool local)
 {
 	ConfigItemBuilder::Ptr endpointConfig = boost::make_shared<ConfigItemBuilder>();
 	endpointConfig->SetType("Endpoint");
 	endpointConfig->SetName(local ? "local:" + name : name);
-	endpointConfig->SetLocal(local ? 1 : 0);
+	endpointConfig->SetLocal(!replicated);
 	endpointConfig->AddExpression("local", OperatorSet, local);
 
 	DynamicObject::Ptr object = endpointConfig->Compile()->Commit();
diff --git a/lib/remoting/endpoint.h b/lib/remoting/endpoint.h
index 7444697..9b8e22e 100644
--- a/lib/remoting/endpoint.h
+++ b/lib/remoting/endpoint.h
@@ -69,7 +69,7 @@ public:
 	String GetNode(void) const;
 	String GetService(void) const;
 
-	static Endpoint::Ptr MakeEndpoint(const String& name, bool local);
+	static Endpoint::Ptr MakeEndpoint(const String& name, bool replicated, bool local = true);
 
 	static boost::signal<void (const Endpoint::Ptr&)> OnConnected;
 	static boost::signal<void (const Endpoint::Ptr&)> OnDisconnected;
diff --git a/lib/remoting/endpointmanager.cpp b/lib/remoting/endpointmanager.cpp
index 299e24a..799f3c2 100644
--- a/lib/remoting/endpointmanager.cpp
+++ b/lib/remoting/endpointmanager.cpp
@@ -81,7 +81,7 @@ void EndpointManager::SetIdentity(const String& identity)
 	if (object)
 		m_Endpoint = dynamic_pointer_cast<Endpoint>(object);
 	else
-		m_Endpoint = Endpoint::MakeEndpoint(identity, false);
+		m_Endpoint = Endpoint::MakeEndpoint(identity, true, true);
 }
 
 /**
@@ -173,7 +173,7 @@ void EndpointManager::ClientConnectedHandler(const Stream::Ptr& client, const St
 	if (Endpoint::Exists(identity))
 		endpoint = Endpoint::GetByName(identity);
 	else
-		endpoint = Endpoint::MakeEndpoint(identity, false);
+		endpoint = Endpoint::MakeEndpoint(identity, true);
 
 	endpoint->SetClient(jclient);
 }
@@ -310,9 +310,11 @@ void EndpointManager::SubscriptionTimerHandler(void)
 		if (!endpoint->IsLocalEndpoint())
 			continue;
 
-		String topic;
-		BOOST_FOREACH(tie(tuples::ignore, topic), endpoint->GetSubscriptions()) {
-			subscriptions->Set(topic, topic);
+		if (endpoint->GetSubscriptions()) {
+			String topic;
+			BOOST_FOREACH(tie(tuples::ignore, topic), endpoint->GetSubscriptions()) {
+				subscriptions->Set(topic, topic);
+			}
 		}
 	}
 





More information about the icinga-checkins mailing list