[icinga-checkins] icinga.org: icinga2/master: Fix object resync issues

git at icinga.org git at icinga.org
Tue Oct 11 10:55:18 CEST 2016


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

Author: Gunnar Beutner <gunnar.beutner at icinga.com>
Date:   Tue Oct 11 10:53:51 2016 +0200

Fix object resync issues

refs #11684

---

 lib/remote/apilistener-configsync.cpp |   26 +++++++++++++++++++++-----
 lib/remote/apilistener.cpp            |    6 ++++++
 lib/remote/apilistener.hpp            |    1 +
 3 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/lib/remote/apilistener-configsync.cpp b/lib/remote/apilistener-configsync.cpp
index d72fd71..beeedb8 100644
--- a/lib/remote/apilistener-configsync.cpp
+++ b/lib/remote/apilistener-configsync.cpp
@@ -107,7 +107,11 @@ Value ApiListener::ConfigUpdateObjectAPIHandler(const MessageOrigin::Ptr& origin
 
 	String config = params->Get("config");
 
+	bool newObject = false;
+
 	if (!object && !config.IsEmpty()) {
+		newObject = true;
+
 		/* object does not exist, create it through the API */
 		Array::Ptr errors = new Array();
 
@@ -136,8 +140,8 @@ Value ApiListener::ConfigUpdateObjectAPIHandler(const MessageOrigin::Ptr& origin
 	if (!object)
 		return Empty;
 
-	/* update object attributes if version was changed */
-	if (objVersion <= object->GetVersion()) {
+	/* update object attributes if version was changed or if this is a new object */
+	if (newObject || objVersion <= object->GetVersion()) {
 		Log(LogNotice, "ApiListener")
 		    << "Discarding config update for object '" << object->GetName()
 		    << "': Object version " << std::fixed << object->GetVersion()
@@ -337,8 +341,14 @@ void ApiListener::UpdateConfigObject(const ConfigObject::Ptr& object, const Mess
 
 	if (client)
 		JsonRpc::SendMessage(client->GetStream(), message);
-	else
+	else {
+		Zone::Ptr target = static_pointer_cast<Zone>(object->GetZone());
+
+		if (!target)
+			target = Zone::GetLocalZone();
+
 		RelayMessage(origin, object, message, false);
+	}
 }
 
 
@@ -379,8 +389,14 @@ void ApiListener::DeleteConfigObject(const ConfigObject::Ptr& object, const Mess
 
 	if (client)
 		JsonRpc::SendMessage(client->GetStream(), message);
-	else
-		RelayMessage(origin, object, message, false);
+	else {
+		Zone::Ptr target = static_pointer_cast<Zone>(object->GetZone());
+
+		if (!target)
+			target = Zone::GetLocalZone();
+
+		RelayMessage(origin, target, message, false);
+	}
 }
 
 /* Initial sync on connect for new endpoints */
diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp
index 8ade19f..c76f63e 100644
--- a/lib/remote/apilistener.cpp
+++ b/lib/remote/apilistener.cpp
@@ -164,6 +164,12 @@ void ApiListener::Start(bool runtimeCreated)
 	OnMasterChanged(true);
 }
 
+void ApiListener::Stop(bool runtimeDeleted)
+{
+	boost::mutex::scoped_lock lock(m_LogLock);
+	CloseLogFile();
+}
+
 ApiListener::Ptr ApiListener::GetInstance(void)
 {
 	return m_Instance;
diff --git a/lib/remote/apilistener.hpp b/lib/remote/apilistener.hpp
index cbfbbd1..2b2df11 100644
--- a/lib/remote/apilistener.hpp
+++ b/lib/remote/apilistener.hpp
@@ -104,6 +104,7 @@ protected:
 	virtual void OnConfigLoaded(void) override;
 	virtual void OnAllConfigLoaded(void) override;
 	virtual void Start(bool runtimeCreated) override;
+	virtual void Stop(bool runtimeDeleted) override;
 
 	virtual void ValidateTlsProtocolmin(const String& value, const ValidationUtils& utils) override;
 



More information about the icinga-checkins mailing list