[icinga-checkins] icinga.org: icinga2/feature/incremental-ido-updates-12435: Replace GetType ()->GetName() calls with GetReflectionType()->GetName()

git at icinga.org git at icinga.org
Mon Aug 15 14:39:03 CEST 2016


Module: icinga2
Branch: feature/incremental-ido-updates-12435
Commit: 41f19983ff6be343ce0e683c0dd4e3a227c65d58
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=41f19983ff6be343ce0e683c0dd4e3a227c65d58

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Mon Aug 15 14:38:49 2016 +0200

Replace GetType()->GetName() calls with GetReflectionType()->GetName()

fixes #12438

---

 lib/base/configobject.cpp             |    4 ++--
 lib/db_ido/dbconnection.cpp           |   15 ++++++++++-----
 lib/db_ido/dbobject.cpp               |   11 +++++++----
 lib/db_ido/servicedbobject.cpp        |    1 -
 lib/icinga/compatutility.cpp          |    7 ++++---
 lib/remote/apilistener-configsync.cpp |    4 ++--
 lib/remote/apilistener.cpp            |    2 +-
 7 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/lib/base/configobject.cpp b/lib/base/configobject.cpp
index 520e4b2..f52eee3 100644
--- a/lib/base/configobject.cpp
+++ b/lib/base/configobject.cpp
@@ -384,7 +384,7 @@ void ConfigObject::Start(bool runtimeCreated)
 
 void ConfigObject::Activate(bool runtimeCreated)
 {
-	CONTEXT("Activating object '" + GetName() + "' of type '" + GetType()->GetName() + "'");
+	CONTEXT("Activating object '" + GetName() + "' of type '" + GetReflectionType()->GetName() + "'");
 
 	{
 		ObjectLock olock(this);
@@ -413,7 +413,7 @@ void ConfigObject::Stop(bool runtimeRemoved)
 
 void ConfigObject::Deactivate(bool runtimeRemoved)
 {
-	CONTEXT("Deactivating object '" + GetName() + "' of type '" + GetType()->GetName() + "'");
+	CONTEXT("Deactivating object '" + GetName() + "' of type '" + GetReflectionType()->GetName() + "'");
 
 	{
 		ObjectLock olock(this);
diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp
index bef8cd3..3ffcaf3 100644
--- a/lib/db_ido/dbconnection.cpp
+++ b/lib/db_ido/dbconnection.cpp
@@ -449,12 +449,12 @@ void DbConnection::UpdateObject(const ConfigObject::Ptr& object)
 
 			String cachedHash = GetConfigHash(dbobj);
 
-			if (cachedHash != configHash) {
-				dbobj->SendConfigUpdateHeavy(configFields);
-				dbobj->SendStatusUpdate();
-			} else {
+			//if (cachedHash != configHash) {
+			//	dbobj->SendConfigUpdateHeavy(configFields);
+			//	dbobj->SendStatusUpdate();
+			//} else {
 				dbobj->SendConfigUpdateLight();
-			}
+			//}
 		} else if (!active) {
 			/* Deactivate the deleted object no matter
 			 * which state it had in the database.
@@ -466,12 +466,17 @@ void DbConnection::UpdateObject(const ConfigObject::Ptr& object)
 
 void DbConnection::UpdateAllObjects(void)
 {
+	double st = Utility::GetTime();
+
 	ConfigType::Ptr type;
 	BOOST_FOREACH(const ConfigType::Ptr& dt, ConfigType::GetTypes()) {
 		BOOST_FOREACH(const ConfigObject::Ptr& object, dt->GetObjects()) {
 			UpdateObject(object);
 		}
 	}
+
+	Log(LogInformation, "DbConnection")
+	    << "UpdateAllObjects took " << std::setw(2) << Utility::GetTime() - st << " seconds";
 }
 
 void DbConnection::PrepareDatabase(void)
diff --git a/lib/db_ido/dbobject.cpp b/lib/db_ido/dbobject.cpp
index ab2e558..4516a10 100644
--- a/lib/db_ido/dbobject.cpp
+++ b/lib/db_ido/dbobject.cpp
@@ -23,6 +23,9 @@
 #include "icinga/customvarobject.hpp"
 #include "icinga/service.hpp"
 #include "icinga/compatutility.hpp"
+#include "icinga/checkcommand.hpp"
+#include "icinga/eventcommand.hpp"
+#include "icinga/notificationcommand.hpp"
 #include "remote/endpoint.hpp"
 #include "base/configobject.hpp"
 #include "base/configtype.hpp"
@@ -359,7 +362,7 @@ DbObject::Ptr DbObject::GetOrCreateByObject(const ConfigObject::Ptr& object)
 	if (dbobj)
 		return dbobj;
 
-	DbType::Ptr dbtype = DbType::GetByName(object->GetType()->GetName());
+	DbType::Ptr dbtype = DbType::GetByName(object->GetReflectionType()->GetName());
 
 	if (!dbtype)
 		return DbObject::Ptr();
@@ -375,9 +378,9 @@ DbObject::Ptr DbObject::GetOrCreateByObject(const ConfigObject::Ptr& object)
 		name1 = service->GetHost()->GetName();
 		name2 = service->GetShortName();
 	} else {
-		if (object->GetType() == ConfigType::GetByName("CheckCommand") ||
-		    object->GetType() == ConfigType::GetByName("EventCommand") ||
-		    object->GetType() == ConfigType::GetByName("NotificationCommand")) {
+		if (object->GetReflectionType() == CheckCommand::TypeInstance ||
+		    object->GetReflectionType() == EventCommand::TypeInstance ||
+		    object->GetReflectionType() == NotificationCommand::TypeInstance) {
 			Command::Ptr command = dynamic_pointer_cast<Command>(object);
 			name1 = CompatUtility::GetCommandName(command);
 		}
diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp
index afa0245..921e159 100644
--- a/lib/db_ido/servicedbobject.cpp
+++ b/lib/db_ido/servicedbobject.cpp
@@ -354,7 +354,6 @@ void ServiceDbObject::DoCommonConfigUpdate(void)
 String ServiceDbObject::CalculateConfigHash(const Dictionary::Ptr& configFields) const
 {
 	String hashData = DbObject::CalculateConfigHash(configFields);
-	return hashData;
 
 	Service::Ptr service = static_pointer_cast<Service>(GetObject());
 
diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp
index e2aeeb3..20c1f6f 100644
--- a/lib/icinga/compatutility.cpp
+++ b/lib/icinga/compatutility.cpp
@@ -20,6 +20,7 @@
 #include "icinga/compatutility.hpp"
 #include "icinga/checkcommand.hpp"
 #include "icinga/eventcommand.hpp"
+#include "icinga/notificationcommand.hpp"
 #include "icinga/pluginutility.hpp"
 #include "icinga/service.hpp"
 #include "base/utility.hpp"
@@ -62,11 +63,11 @@ String CompatUtility::GetCommandNamePrefix(const Command::Ptr command)
 		return Empty;
 
 	String prefix;
-	if (command->GetType() == ConfigType::GetByName("CheckCommand"))
+	if (command->GetReflectionType() == CheckCommand::TypeInstance)
 		prefix = "check_";
-	else if (command->GetType() == ConfigType::GetByName("NotificationCommand"))
+	else if (command->GetReflectionType() == NotificationCommand::TypeInstance)
 		prefix = "notification_";
-	else if (command->GetType() == ConfigType::GetByName("EventCommand"))
+	else if (command->GetReflectionType() == EventCommand::TypeInstance)
 		prefix = "event_";
 
 	return prefix;
diff --git a/lib/remote/apilistener-configsync.cpp b/lib/remote/apilistener-configsync.cpp
index 189f705..aaee8d9 100644
--- a/lib/remote/apilistener-configsync.cpp
+++ b/lib/remote/apilistener-configsync.cpp
@@ -291,7 +291,7 @@ void ApiListener::UpdateConfigObject(const ConfigObject::Ptr& object, const Mess
 
 	Dictionary::Ptr params = new Dictionary();
 	params->Set("name", object->GetName());
-	params->Set("type", object->GetType()->GetName());
+	params->Set("type", object->GetReflectionType()->GetName());
 	params->Set("version", object->GetVersion());
 
 	if (object->GetPackage() == "_api") {
@@ -370,7 +370,7 @@ void ApiListener::DeleteConfigObject(const ConfigObject::Ptr& object, const Mess
 
 	Dictionary::Ptr params = new Dictionary();
 	params->Set("name", object->GetName());
-	params->Set("type", object->GetType()->GetName());
+	params->Set("type", object->GetReflectionType()->GetName());
 	params->Set("version", object->GetVersion());
 
 	message->Set("params", params);
diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp
index 5103235..227fe50 100644
--- a/lib/remote/apilistener.cpp
+++ b/lib/remote/apilistener.cpp
@@ -651,7 +651,7 @@ void ApiListener::PersistMessage(const Dictionary::Ptr& message, const ConfigObj
 
 	if (secobj) {
 		Dictionary::Ptr secname = new Dictionary();
-		secname->Set("type", secobj->GetType()->GetName());
+		secname->Set("type", secobj->GetReflectionType()->GetName());
 		secname->Set("name", secobj->GetName());
 		pmessage->Set("secobj", secname);
 	}



More information about the icinga-checkins mailing list