[icinga-checkins] icinga.org: icinga2/fix/api-sync-repl-11684: wip

git at icinga.org git at icinga.org
Wed Jun 15 17:50:20 CEST 2016


Module: icinga2
Branch: fix/api-sync-repl-11684
Commit: e26b27d49d45f3a056f2db9732a9fc1cddaf8fec
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=e26b27d49d45f3a056f2db9732a9fc1cddaf8fec

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Sat May 21 15:52:04 2016 +0200

wip

---

 lib/icinga/comment.cpp                |    2 +-
 lib/icinga/downtime.cpp               |    2 +-
 lib/remote/apilistener-configsync.cpp |    4 ++--
 lib/remote/configobjectutility.cpp    |   16 +++++++++++-----
 lib/remote/configobjectutility.hpp    |    5 +++--
 lib/remote/createobjecthandler.cpp    |    3 ++-
 6 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/lib/icinga/comment.cpp b/lib/icinga/comment.cpp
index 7b91653..4719f8c 100644
--- a/lib/icinga/comment.cpp
+++ b/lib/icinga/comment.cpp
@@ -185,7 +185,7 @@ String Comment::AddComment(const Checkable::Ptr& checkable, CommentType entryTyp
 
 	Array::Ptr errors = new Array();
 
-	if (!ConfigObjectUtility::CreateObject(Comment::TypeInstance, fullName, config, errors)) {
+	if (!ConfigObjectUtility::CreateObject(Comment::TypeInstance, fullName, config, zone, errors)) {
 		ObjectLock olock(errors);
 		BOOST_FOREACH(const String& error, errors) {
 			Log(LogCritical, "Comment", error);
diff --git a/lib/icinga/downtime.cpp b/lib/icinga/downtime.cpp
index ee916c2..c013d15 100644
--- a/lib/icinga/downtime.cpp
+++ b/lib/icinga/downtime.cpp
@@ -233,7 +233,7 @@ String Downtime::AddDowntime(const Checkable::Ptr& checkable, const String& auth
 
 	Array::Ptr errors = new Array();
 
-	if (!ConfigObjectUtility::CreateObject(Downtime::TypeInstance, fullName, config, errors)) {
+	if (!ConfigObjectUtility::CreateObject(Downtime::TypeInstance, fullName, config, zone, errors)) {
 		ObjectLock olock(errors);
 		BOOST_FOREACH(const String& error, errors) {
 			Log(LogCritical, "Downtime", error);
diff --git a/lib/remote/apilistener-configsync.cpp b/lib/remote/apilistener-configsync.cpp
index 189f705..a379342 100644
--- a/lib/remote/apilistener-configsync.cpp
+++ b/lib/remote/apilistener-configsync.cpp
@@ -116,7 +116,7 @@ Value ApiListener::ConfigUpdateObjectAPIHandler(const MessageOrigin::Ptr& origin
 		Array::Ptr errors = new Array();
 
 		if (!ConfigObjectUtility::CreateObject(Type::GetByName(objType),
-		    objName, config, errors)) {
+		    objName, config, endpoint->GetZone()->GetName(), errors)) {
 			Log(LogCritical, "ApiListener")
 			    << "Could not create object '" << objName << "':";
 
@@ -295,7 +295,7 @@ void ApiListener::UpdateConfigObject(const ConfigObject::Ptr& object, const Mess
 	params->Set("version", object->GetVersion());
 
 	if (object->GetPackage() == "_api") {
-		String file = ConfigObjectUtility::GetObjectConfigPath(object->GetReflectionType(), object->GetName());
+		String file = ConfigObjectUtility::GetObjectConfigPath(object->GetReflectionType(), object->GetName(), object->GetZoneName());
 
 		std::ifstream fp(file.CStr(), std::ifstream::binary);
 		if (!fp)
diff --git a/lib/remote/configobjectutility.cpp b/lib/remote/configobjectutility.cpp
index 107caa4..a19bf3f 100644
--- a/lib/remote/configobjectutility.cpp
+++ b/lib/remote/configobjectutility.cpp
@@ -38,12 +38,18 @@ String ConfigObjectUtility::GetConfigDir(void)
 	    ConfigPackageUtility::GetActiveStage("_api");
 }
 
-String ConfigObjectUtility::GetObjectConfigPath(const Type::Ptr& type, const String& fullName)
+String ConfigObjectUtility::GetObjectConfigPath(const Type::Ptr& type,
+    const String& fullName, const String& zoneName)
 {
 	String typeDir = type->GetPluralName();
 	boost::algorithm::to_lower(typeDir);
 
-	return GetConfigDir() + "/conf.d/" + typeDir +
+	String configDir = "conf.d";
+
+	if (!zoneName.IsEmpty())
+		configDir = "zones.d/" + zoneName;
+
+	return GetConfigDir() + "/" + configDir + "/" + typeDir +
 	    "/" + EscapeName(fullName) + ".conf";
 }
 
@@ -100,7 +106,7 @@ String ConfigObjectUtility::CreateObjectConfig(const Type::Ptr& type, const Stri
 }
 
 bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& fullName,
-    const String& config, const Array::Ptr& errors)
+    const String& config, const String& zoneName, const Array::Ptr& errors)
 {
 	if (!ConfigPackageUtility::PackageExists("_api")) {
 		ConfigPackageUtility::CreatePackage("_api");
@@ -109,7 +115,7 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full
 		ConfigPackageUtility::ActivateStage("_api", stage);
 	}
 
-	String path = GetObjectConfigPath(type, fullName);
+	String path = GetObjectConfigPath(type, fullName, zoneName);
 	Utility::MkDirP(Utility::DirName(path), 0700);
 
 	if (Utility::PathExists(path)) {
@@ -214,7 +220,7 @@ bool ConfigObjectUtility::DeleteObjectHelper(const ConfigObject::Ptr& object, bo
 		return false;
 	}
 
-	String path = GetObjectConfigPath(object->GetReflectionType(), object->GetName());
+	String path = GetObjectConfigPath(object->GetReflectionType(), object->GetName(), object->GetZoneName());
 
 	if (Utility::PathExists(path)) {
 		if (unlink(path.CStr()) < 0) {
diff --git a/lib/remote/configobjectutility.hpp b/lib/remote/configobjectutility.hpp
index 2b6d474..bf1c38f 100644
--- a/lib/remote/configobjectutility.hpp
+++ b/lib/remote/configobjectutility.hpp
@@ -39,13 +39,14 @@ class I2_REMOTE_API ConfigObjectUtility
 
 public:
 	static String GetConfigDir(void);
-	static String GetObjectConfigPath(const Type::Ptr& type, const String& fullName);
+	static String GetObjectConfigPath(const Type::Ptr& type, const String& fullName,
+	    const String& zoneName);
 
 	static String CreateObjectConfig(const Type::Ptr& type, const String& fullName,
 	     bool ignoreOnError, const Array::Ptr& templates, const Dictionary::Ptr& attrs);
 
 	static bool CreateObject(const Type::Ptr& type, const String& fullName,
-	     const String& config, const Array::Ptr& errors);
+	     const String& config, const String& zoneName, const Array::Ptr& errors);
 
 	static bool DeleteObject(const ConfigObject::Ptr& object, bool cascade, const Array::Ptr& errors);
 
diff --git a/lib/remote/createobjecthandler.cpp b/lib/remote/createobjecthandler.cpp
index 84c60f7..41a6497 100644
--- a/lib/remote/createobjecthandler.cpp
+++ b/lib/remote/createobjecthandler.cpp
@@ -97,7 +97,8 @@ bool CreateObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
 		return true;
 	}
 
-	if (!ConfigObjectUtility::CreateObject(type, name, config, errors)) {
+	/* Pass the zone name to ensure the object is created in zones.d package directory. */
+	if (!ConfigObjectUtility::CreateObject(type, name, config, localZoneName, errors)) {
 		result1->Set("errors", errors);
 		result1->Set("code", 500);
 		result1->Set("status", "Object could not be created.");



More information about the icinga-checkins mailing list