]> granicus.if.org Git - icinga2/commitdiff
Bugfix: some legacy_id changes didn't cause the cache to get updated.
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 30 Jan 2013 14:10:51 +0000 (15:10 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 30 Jan 2013 14:24:02 +0000 (15:24 +0100)
components/compat/compatcomponent.cpp
lib/icinga/commentprocessor.cpp
lib/icinga/downtimeprocessor.cpp

index 0e82e13ef77edc81710962984887b0d913877c18..da2209bccc53c834c1c74ff01f1a076d89482bff 100644 (file)
@@ -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
index 5703c2c9a2e84c68a5eeaa33b9eb751612af6536..33423b94c0b05a3c378f8153299f0f807e1adebd 100644 (file)
@@ -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;
index 97999572260f045e0fdb0f8c1182c6d47c8511a1..17b2939903096f6976c42248b778f83eb3a909a2 100644 (file)
@@ -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;