]> granicus.if.org Git - icinga2/commitdiff
Bugfix for restoring objects from the retention.dat file.
authorGunnar Beutner <gunnar.beutner@netways.de>
Sat, 4 Aug 2012 12:13:04 +0000 (14:13 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sat, 4 Aug 2012 12:13:04 +0000 (14:13 +0200)
base/dynamicobject.cpp
base/dynamicobject.h
components/checker/checkercomponent.cpp

index 78a4ea2adfbae1b1c22db3bc360088aca133d35f..2320e6a55561f6856c893c775b9f725b92c600a4 100644 (file)
@@ -436,7 +436,7 @@ void DynamicObject::RestoreObjects(const String& filename)
                bool hasConfig = persistentObject->Contains("configTx");
                Dictionary::Ptr update = persistentObject->Get("update");
 
-               if (hasConfig) {
+               if (hasConfig && ClassExists(type)) {
                        DynamicObject::Ptr object = Create(type, update);
                        object->Register();
                } else {
@@ -466,6 +466,37 @@ void DynamicObject::RegisterClass(const String& type, DynamicObject::Factory fac
                    type + "': Objects of this type already exist."));
 
        GetClasses()[type] = factory;
+
+       /* restore persistent objects that match the newly-registered class */
+       map<pair<String, String>, Dictionary::Ptr>::iterator prev, st;
+       for (st = m_PersistentUpdates.begin(); st != m_PersistentUpdates.end(); st++)
+       {
+               /* check type of the update */
+               if (st->first.first != type) {
+                       st++;
+                       continue;
+               }
+
+               Dictionary::Ptr update = st->second;
+               bool hasConfig = update->Contains("configTx");
+               if (!hasConfig) {
+                       st++;
+                       continue;
+               }
+
+               DynamicObject::Ptr object = Create(type, update);
+               object->Register();
+
+               prev = st;
+               st++;
+               m_PersistentUpdates.erase(prev);
+       }
+
+}
+
+bool DynamicObject::ClassExists(const String& type)
+{
+       return (GetClasses().find(type) != GetClasses().end());
 }
 
 DynamicObject::Ptr DynamicObject::Create(const String& type, const Dictionary::Ptr& serializedUpdate)
@@ -521,4 +552,4 @@ void DynamicObject::FinishTx(void)
 }
 
 void DynamicObject::OnAttributeChanged(const String& name, const Value& oldValue)
-{ }
\ No newline at end of file
+{ }
index d44d8316c2872f2118d3ac09b4bdb72ee7d4574d..5a48965d1e90d61007810ea4fd7c9b4b16e87c6a 100644 (file)
@@ -118,6 +118,7 @@ public:
        static void RestoreObjects(const String& filename);
 
        static void RegisterClass(const String& type, Factory factory);
+       static bool ClassExists(const String& type);
        static DynamicObject::Ptr Create(const String& type, const Dictionary::Ptr& serializedUpdate);
 
        static double GetCurrentTx(void);
index 6b4ab546eec5379299b9854352b2e4498f25a9ec..33a41dff6ff568ee47880dd95b37c1e3f426fc60 100644 (file)
@@ -160,8 +160,6 @@ void CheckerComponent::CheckerChangedHandler(const Service::Ptr& service)
                if (m_PendingServices.find(service) != m_PendingServices.end())
                        return;
 
-               service->UpdateNextCheck();
-
                m_IdleServices.insert(service);
        } else {
                m_IdleServices.erase(service);