[icinga-checkins] icinga.org: icinga2/support/2.4: Make sure the dependency graph is properly updated when adding and removing objects

git at icinga.org git at icinga.org
Thu May 12 11:50:27 CEST 2016


Module: icinga2
Branch: support/2.4
Commit: d82db2ae6cf03f461748218f78f81dafc3307a47
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=d82db2ae6cf03f461748218f78f81dafc3307a47

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Mon May  9 13:48:30 2016 +0200

Make sure the dependency graph is properly updated when adding and removing objects

fixes #11686
fixes #11374

---

 lib/base/dependencygraph.cpp    |   15 ++++++++++++++-
 lib/icinga/comment.ti           |    2 +-
 lib/icinga/dependency.ti        |    4 ++--
 lib/icinga/downtime.ti          |    2 +-
 lib/icinga/notification.ti      |    2 +-
 lib/icinga/scheduleddowntime.ti |    2 +-
 tools/mkclass/classcompiler.cpp |    4 ++--
 7 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/lib/base/dependencygraph.cpp b/lib/base/dependencygraph.cpp
index 6f1053c..037830d 100644
--- a/lib/base/dependencygraph.cpp
+++ b/lib/base/dependencygraph.cpp
@@ -34,7 +34,20 @@ void DependencyGraph::AddDependency(Object *parent, Object *child)
 void DependencyGraph::RemoveDependency(Object *parent, Object *child)
 {
 	boost::mutex::scoped_lock lock(m_Mutex);
-	m_Dependencies[child][parent]--;
+
+	std::map<Object *, int>& refs = m_Dependencies[child];
+	std::map<Object *, int>::iterator it = refs.find(parent);
+
+	if (it == refs.end())
+		return;
+
+	it->second--;
+
+	if (it->second == 0)
+		refs.erase(it);
+
+	if (refs.empty())
+		m_Dependencies.erase(child);
 }
 
 std::vector<Object::Ptr> DependencyGraph::GetParents(const Object::Ptr& child)
diff --git a/lib/icinga/comment.ti b/lib/icinga/comment.ti
index 8ac497a..94ad48e 100644
--- a/lib/icinga/comment.ti
+++ b/lib/icinga/comment.ti
@@ -67,7 +67,7 @@ class Comment : ConfigObject < CommentNameComposer
 
 			if (!newValue.IsEmpty()) {
 				Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
-				DependencyGraph::RemoveDependency(this, service.get());
+				DependencyGraph::AddDependency(this, service.get());
 			}
 		}}}
 		navigate {{{
diff --git a/lib/icinga/dependency.ti b/lib/icinga/dependency.ti
index aeb943f..fbbb824 100644
--- a/lib/icinga/dependency.ti
+++ b/lib/icinga/dependency.ti
@@ -55,7 +55,7 @@ class Dependency : CustomVarObject < DependencyNameComposer
 
 			if (!newValue.IsEmpty()) {
 				Service::Ptr service = Service::GetByNamePair(GetParentHostName(), newValue);
-				DependencyGraph::RemoveDependency(this, service.get());
+				DependencyGraph::AddDependency(this, service.get());
 			}
 		}}}
 		navigate {{{
@@ -82,7 +82,7 @@ class Dependency : CustomVarObject < DependencyNameComposer
 
 			if (!newValue.IsEmpty()) {
 				Service::Ptr service = Service::GetByNamePair(GetParentHostName(), newValue);
-				DependencyGraph::RemoveDependency(this, service.get());
+				DependencyGraph::AddDependency(this, service.get());
 			}
 		}}}
 		navigate {{{
diff --git a/lib/icinga/downtime.ti b/lib/icinga/downtime.ti
index d5a1698..5c7a19b 100644
--- a/lib/icinga/downtime.ti
+++ b/lib/icinga/downtime.ti
@@ -54,7 +54,7 @@ class Downtime : ConfigObject < DowntimeNameComposer
 
 			if (!newValue.IsEmpty()) {
 				Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
-				DependencyGraph::RemoveDependency(this, service.get());
+				DependencyGraph::AddDependency(this, service.get());
 			}
 		}}}
 		navigate {{{
diff --git a/lib/icinga/notification.ti b/lib/icinga/notification.ti
index c8825b3..18604e2 100644
--- a/lib/icinga/notification.ti
+++ b/lib/icinga/notification.ti
@@ -74,7 +74,7 @@ class Notification : CustomVarObject < NotificationNameComposer
 
 			if (!newValue.IsEmpty()) {
 				Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
-				DependencyGraph::RemoveDependency(this, service.get());
+				DependencyGraph::AddDependency(this, service.get());
 			}
 		}}}
 		navigate {{{
diff --git a/lib/icinga/scheduleddowntime.ti b/lib/icinga/scheduleddowntime.ti
index 4b95ae6..92b5e46 100644
--- a/lib/icinga/scheduleddowntime.ti
+++ b/lib/icinga/scheduleddowntime.ti
@@ -53,7 +53,7 @@ class ScheduledDowntime : CustomVarObject < ScheduledDowntimeNameComposer
 
 			if (!newValue.IsEmpty()) {
 				Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
-				DependencyGraph::RemoveDependency(this, service.get());
+				DependencyGraph::AddDependency(this, service.get());
 			}
 		}}}
 		navigate {{{
diff --git a/tools/mkclass/classcompiler.cpp b/tools/mkclass/classcompiler.cpp
index 60ae196..b72cd76 100644
--- a/tools/mkclass/classcompiler.cpp
+++ b/tools/mkclass/classcompiler.cpp
@@ -901,7 +901,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
 			       << "\t" << klass.Parent << "::Start(runtimeCreated);" << std::endl << std::endl;
 
 			for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
-				if (!(it->Type.IsName))
+				if (!it->Type.IsName && it->TrackAccessor.empty())
 					continue;
 
 				m_Impl << "\t" << "Track" << it->GetFriendlyName() << "(Empty, Get" << it->GetFriendlyName() << "());" << std::endl;
@@ -913,7 +913,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
 			       << "\t" << klass.Parent << "::Stop(runtimeRemoved);" << std::endl << std::endl;
 
 			for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
-				if (!(it->Type.IsName))
+				if (!it->Type.IsName && it->TrackAccessor.empty())
 					continue;
 
 				m_Impl << "\t" << "Track" << it->GetFriendlyName() << "(Get" << it->GetFriendlyName() << "(), Empty);" << std::endl;



More information about the icinga-checkins mailing list