From: Gunnar Beutner Date: Thu, 29 Aug 2013 14:53:57 +0000 (+0200) Subject: Fix: State file doesn't work for generated service objects. X-Git-Tag: v0.0.3~650 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=91724814d8dc99a62cd13f419b6222a8356176b8;p=icinga2 Fix: State file doesn't work for generated service objects. --- diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index 983dbab6d..406cbff4d 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -68,9 +68,17 @@ Dictionary::Ptr DynamicObject::Serialize(int attributeTypes) const void DynamicObject::Deserialize(const Dictionary::Ptr& update, int attributeTypes) { ASSERT(!OwnsLock()); - ObjectLock olock(this); - InternalDeserialize(update, attributeTypes); + { + ObjectLock olock(this); + InternalDeserialize(update, attributeTypes); + } + + if (attributeTypes & Attribute_Config) + OnConfigLoaded(); + + if (attributeTypes & Attribute_State) + OnStateLoaded(); } void DynamicObject::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const @@ -176,6 +184,16 @@ void DynamicObject::Stop(void) OnStopped(GetSelf()); } +void DynamicObject::OnConfigLoaded(void) +{ + /* Nothing to do here. */ +} + +void DynamicObject::OnStateLoaded(void) +{ + /* Nothing to do here. */ +} + Value DynamicObject::InvokeMethod(const String& method, const std::vector& arguments) { diff --git a/lib/base/dynamicobject.h b/lib/base/dynamicobject.h index 048fd5deb..204e0c0e3 100644 --- a/lib/base/dynamicobject.h +++ b/lib/base/dynamicobject.h @@ -102,6 +102,9 @@ protected: virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const; virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes); + virtual void OnConfigLoaded(void); + virtual void OnStateLoaded(void); + private: String m_Name; String m_Type; diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 8e67483fa..b886504e7 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -56,7 +56,10 @@ void Host::Start(void) hg->AddMember(GetSelf()); } } +} +void Host::OnConfigLoaded(void) +{ UpdateSlaveServices(); } diff --git a/lib/icinga/host.h b/lib/icinga/host.h index c73cacfbb..68011d1f5 100644 --- a/lib/icinga/host.h +++ b/lib/icinga/host.h @@ -127,6 +127,8 @@ protected: virtual void Start(void); virtual void Stop(void); + virtual void OnConfigLoaded(void); + virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const; virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes); diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index 75c195bf5..2f5a068f9 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -44,6 +44,12 @@ void Service::Start(void) SetSchedulingOffset(rand()); UpdateNextCheck(); + AddDowntimesToCache(); + AddCommentsToCache(); +} + +void Service::OnConfigLoaded(void) +{ Array::Ptr groups = GetGroups(); if (groups) { @@ -55,12 +61,11 @@ void Service::Start(void) } } - AddDowntimesToCache(); - AddCommentsToCache(); - Host::Ptr host = GetHost(); if (host) host->AddService(GetSelf()); + + UpdateSlaveNotifications(); } String Service::GetDisplayName(void) const diff --git a/lib/icinga/service.h b/lib/icinga/service.h index 428455b85..c38a537be 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -332,6 +332,8 @@ public: protected: virtual void Start(void); + virtual void OnConfigLoaded(void); + virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const; virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes); diff --git a/lib/icinga/user.cpp b/lib/icinga/user.cpp index b4dcb24d5..649792422 100644 --- a/lib/icinga/user.cpp +++ b/lib/icinga/user.cpp @@ -27,10 +27,8 @@ using namespace icinga; REGISTER_TYPE(User); -void User::Start(void) +void User::OnConfigLoaded(void) { - DynamicObject::Start(); - Array::Ptr groups = GetGroups(); if (groups) { diff --git a/lib/icinga/user.h b/lib/icinga/user.h index 26e65427c..ed25f2a83 100644 --- a/lib/icinga/user.h +++ b/lib/icinga/user.h @@ -57,9 +57,10 @@ public: virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const; protected: - virtual void Start(void); virtual void Stop(void); + virtual void OnConfigLoaded(void); + virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const; virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);