[icinga-checkins] icinga.org: icinga2/master: Bugfix: some legacy_id changes didn' t cause the cache to get updated.

git at icinga.org git at icinga.org
Wed Jan 30 15:24:06 CET 2013


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

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Wed Jan 30 15:10:51 2013 +0100

Bugfix: some legacy_id changes didn't cause the cache to get updated.

---

 components/compat/compatcomponent.cpp |   10 ----------
 lib/icinga/commentprocessor.cpp       |   15 ++++-----------
 lib/icinga/downtimeprocessor.cpp      |   15 ++++-----------
 3 files changed, 8 insertions(+), 32 deletions(-)

diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp
index 0e82e13..da2209b 100644
--- a/components/compat/compatcomponent.cpp
+++ b/components/compat/compatcomponent.cpp
@@ -184,11 +184,6 @@ void CompatComponent::DumpComments(ofstream& fp, const DynamicObject::Ptr& owner
 		if (CommentProcessor::IsCommentExpired(comment))
 			continue;
 
-		/* There's no way for us to dump comments that haven't been
-		 * assigned a legacy ID yet. */
-		if (!comment->Contains("legacy_id"))
-			continue;
-
 		if (!service)
 			fp << "hostcomment {" << "\n";
 		else
@@ -234,11 +229,6 @@ void CompatComponent::DumpDowntimes(ofstream& fp, const DynamicObject::Ptr& owne
 		if (DowntimeProcessor::IsDowntimeExpired(downtime))
 			continue;
 
-		/* There's no way for us to dump downtimes that haven't been
-		 * assigned a legacy ID yet. */
-		if (!downtime->Contains("legacy_id"))
-			continue;
-
 		if (!service)
 			fp << "hostdowntime {" << "\n";
 		else
diff --git a/lib/icinga/commentprocessor.cpp b/lib/icinga/commentprocessor.cpp
index 5703c2c..33423b9 100644
--- a/lib/icinga/commentprocessor.cpp
+++ b/lib/icinga/commentprocessor.cpp
@@ -42,6 +42,7 @@ String CommentProcessor::AddComment(const DynamicObject::Ptr& owner,
 	comment->Set("author", author);
 	comment->Set("text", text);
 	comment->Set("expire_time", expireTime);
+	comment->Set("legacy_id", m_NextCommentID++);
 
 	Dictionary::Ptr comments = owner->Get("comments");
 
@@ -133,15 +134,7 @@ void CommentProcessor::AddCommentsToCache(const DynamicObject::Ptr& owner)
 	String id;
 	Dictionary::Ptr comment;
 	BOOST_FOREACH(tie(id, comment), comments) {
-		int legacy_id;
-
-		if (!comment->Contains("legacy_id")) {
-			legacy_id = m_NextCommentID;
-			m_NextCommentID++;
-			comment->Set("legacy_id", legacy_id);
-		} else {
-			legacy_id = comment->Get("legacy_id");
-		}
+		int legacy_id = comment->Get("legacy_id");
 
 		if (legacy_id >= m_NextCommentID)
 			m_NextCommentID = legacy_id + 1;
@@ -150,9 +143,9 @@ void CommentProcessor::AddCommentsToCache(const DynamicObject::Ptr& owner)
 			/* The legacy_id is already in use by another comment;
 			 * this shouldn't usually happen - assign it a new ID */
 
-			legacy_id = m_NextCommentID;
-			m_NextCommentID++;
+			legacy_id = m_NextCommentID++;
 			comment->Set("legacy_id", legacy_id);
+			owner->Touch("comments");
 		}
 
 		m_LegacyCommentCache[legacy_id] = id;
diff --git a/lib/icinga/downtimeprocessor.cpp b/lib/icinga/downtimeprocessor.cpp
index 9799957..17b2939 100644
--- a/lib/icinga/downtimeprocessor.cpp
+++ b/lib/icinga/downtimeprocessor.cpp
@@ -47,6 +47,7 @@ String DowntimeProcessor::AddDowntime(const DynamicObject::Ptr& owner,
 	downtime->Set("duration", duration);
 	downtime->Set("triggered_by", triggeredBy);
 	downtime->Set("trigger_time", 0);
+	downtime->Set("legacy_id", m_NextDowntimeID++);
 
 	Dictionary::Ptr downtimes = owner->Get("downtimes");
 
@@ -149,15 +150,7 @@ void DowntimeProcessor::AddDowntimesToCache(const DynamicObject::Ptr& owner)
 	BOOST_FOREACH(tie(id, downtime), downtimes) {
 		double end_time = downtime->Get("end_time");
 
-		int legacy_id;
-
-		if (!downtime->Contains("legacy_id")) {
-			legacy_id = m_NextDowntimeID;
-			m_NextDowntimeID++;
-			downtime->Set("legacy_id", legacy_id);
-		} else {
-			legacy_id = downtime->Get("legacy_id");
-		}
+		int legacy_id = downtime->Get("legacy_id");
 
 		if (legacy_id >= m_NextDowntimeID)
 			m_NextDowntimeID = legacy_id + 1;
@@ -165,9 +158,9 @@ void DowntimeProcessor::AddDowntimesToCache(const DynamicObject::Ptr& owner)
 		if (m_LegacyDowntimeCache.find(legacy_id) != m_LegacyDowntimeCache.end()) {
 			/* The legacy_id is already in use by another downtime;
 			 * this shouldn't usually happen - assign it a new ID. */
-			legacy_id = m_NextDowntimeID;
-			m_NextDowntimeID++;
+			legacy_id = m_NextDowntimeID++;
 			downtime->Set("legacy_id", legacy_id);
+			owner->Touch("downtimes");
 		}
 
 		m_LegacyDowntimeCache[legacy_id] = id;





More information about the icinga-checkins mailing list