Fix: Endpoints were not properly marked as local.

This commit is contained in:
Gunnar Beutner 2013-01-18 09:36:28 +01:00
parent 70c66fa542
commit 5a7aeb1f19
6 changed files with 14 additions and 11 deletions

View File

@ -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 */

View File

@ -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));

View File

@ -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));

View File

@ -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();

View File

@ -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;

View File

@ -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);
}
}
}