From: Gunnar Beutner Date: Sat, 4 Aug 2012 12:13:04 +0000 (+0200) Subject: Bugfix for restoring objects from the retention.dat file. X-Git-Tag: v0.0.1~164 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d8be3f088fa8c32a41200a7bee1319c05452bebe;p=icinga2 Bugfix for restoring objects from the retention.dat file. --- diff --git a/base/dynamicobject.cpp b/base/dynamicobject.cpp index 78a4ea2ad..2320e6a55 100644 --- a/base/dynamicobject.cpp +++ b/base/dynamicobject.cpp @@ -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, 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 +{ } diff --git a/base/dynamicobject.h b/base/dynamicobject.h index d44d8316c..5a48965d1 100644 --- a/base/dynamicobject.h +++ b/base/dynamicobject.h @@ -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); diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index 6b4ab546e..33a41dff6 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -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);