From 8c185a38b0292b4f83f7ed1f2dab6a9c1754ccaa Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 30 Jul 2012 10:17:29 +0200 Subject: [PATCH] Renamed ConfigObject to DynamicObject. --- base/Makefile.am | 4 +- base/base.vcxproj | 4 +- base/base.vcxproj.filters | 12 +- base/component.cpp | 4 +- base/component.h | 6 +- base/{configobject.cpp => dynamicobject.cpp} | 103 +++++++++--------- base/{configobject.h => dynamicobject.h} | 34 +++--- base/i2-base.h | 2 +- base/logger.cpp | 6 +- base/logger.h | 6 +- cib/host.cpp | 4 +- cib/host.h | 4 +- cib/hostgroup.cpp | 4 +- cib/hostgroup.h | 4 +- cib/nagioschecktask.cpp | 2 +- cib/service.cpp | 4 +- cib/service.h | 4 +- cib/servicegroup.cpp | 4 +- cib/servicegroup.h | 4 +- components/checker/checkercomponent.cpp | 2 +- components/cibsync/cibsynccomponent.cpp | 26 ++--- components/cibsync/cibsynccomponent.h | 8 +- components/compat/compatcomponent.cpp | 6 +- .../convenience/conveniencecomponent.cpp | 2 +- components/delegation/delegationcomponent.cpp | 16 +-- components/delegation/delegationcomponent.h | 4 +- components/discovery/discoverycomponent.cpp | 12 +- dyn/configitem.cpp | 16 +-- dyn/configitem.h | 6 +- icinga/icingaapplication.cpp | 21 ++-- 30 files changed, 167 insertions(+), 167 deletions(-) rename base/{configobject.cpp => dynamicobject.cpp} (69%) rename base/{configobject.h => dynamicobject.h} (77%) diff --git a/base/Makefile.am b/base/Makefile.am index 2b64ffcfd..9b5d72b57 100644 --- a/base/Makefile.am +++ b/base/Makefile.am @@ -10,10 +10,10 @@ libbase_la_SOURCES = \ asynctask.h \ component.cpp \ component.h \ - configobject.cpp \ - configobject.h \ dictionary.cpp \ dictionary.h \ + dynamicobject.cpp \ + dynamicobject.h \ event.cpp \ event.h \ exception.cpp \ diff --git a/base/base.vcxproj b/base/base.vcxproj index ed034480a..8545cbd00 100644 --- a/base/base.vcxproj +++ b/base/base.vcxproj @@ -13,7 +13,7 @@ - + @@ -47,7 +47,7 @@ - + diff --git a/base/base.vcxproj.filters b/base/base.vcxproj.filters index 0a152dbdf..2fd084fd5 100644 --- a/base/base.vcxproj.filters +++ b/base/base.vcxproj.filters @@ -7,9 +7,6 @@ Quelldateien - - Quelldateien - Quelldateien @@ -85,6 +82,9 @@ Quelldateien + + Quelldateien + @@ -96,9 +96,6 @@ Headerdateien - - Headerdateien - Headerdateien @@ -177,6 +174,9 @@ Headerdateien + + Headerdateien + diff --git a/base/component.cpp b/base/component.cpp index 304ea2084..55c1c26f4 100644 --- a/base/component.cpp +++ b/base/component.cpp @@ -27,7 +27,7 @@ REGISTER_CLASS(Component); * Constructor for the component class. */ Component::Component(const Dictionary::Ptr& properties) - : ConfigObject(properties) + : DynamicObject(properties) { assert(Application::IsMainThread()); @@ -136,7 +136,7 @@ void Component::AddSearchDir(const string& componentDirectory) * * @returns The configuration. */ -ConfigObject::Ptr IComponent::GetConfig(void) const +DynamicObject::Ptr IComponent::GetConfig(void) const { return m_Config->GetSelf(); } diff --git a/base/component.h b/base/component.h index 9f106a6ca..2f7f9c25f 100644 --- a/base/component.h +++ b/base/component.h @@ -33,10 +33,10 @@ public: virtual void Stop(void); protected: - ConfigObject::Ptr GetConfig(void) const; + DynamicObject::Ptr GetConfig(void) const; private: - ConfigObject *m_Config; + DynamicObject *m_Config; friend class Component; }; @@ -47,7 +47,7 @@ private: * * @ingroup base */ -class I2_BASE_API Component : public ConfigObject +class I2_BASE_API Component : public DynamicObject { public: typedef shared_ptr Ptr; diff --git a/base/configobject.cpp b/base/dynamicobject.cpp similarity index 69% rename from base/configobject.cpp rename to base/dynamicobject.cpp index 5303b7a3e..44adff2e6 100644 --- a/base/configobject.cpp +++ b/base/dynamicobject.cpp @@ -21,11 +21,11 @@ using namespace icinga; -map, Dictionary::Ptr> ConfigObject::m_PersistentTags; -boost::signal ConfigObject::OnCommitted; -boost::signal ConfigObject::OnRemoved; +map, Dictionary::Ptr> DynamicObject::m_PersistentTags; +boost::signal DynamicObject::OnCommitted; +boost::signal DynamicObject::OnRemoved; -ConfigObject::ConfigObject(const Dictionary::Ptr& properties) +DynamicObject::DynamicObject(const Dictionary::Ptr& properties) : m_Properties(properties), m_Tags(boost::make_shared()) { /* restore the object's tags */ @@ -37,88 +37,88 @@ ConfigObject::ConfigObject(const Dictionary::Ptr& properties) } } -void ConfigObject::SetProperties(const Dictionary::Ptr& properties) +void DynamicObject::SetProperties(const Dictionary::Ptr& properties) { m_Properties = properties; } -Dictionary::Ptr ConfigObject::GetProperties(void) const +Dictionary::Ptr DynamicObject::GetProperties(void) const { return m_Properties; } -void ConfigObject::SetTags(const Dictionary::Ptr& tags) +void DynamicObject::SetTags(const Dictionary::Ptr& tags) { m_Tags = tags; } -Dictionary::Ptr ConfigObject::GetTags(void) const +Dictionary::Ptr DynamicObject::GetTags(void) const { return m_Tags; } -string ConfigObject::GetType(void) const +string DynamicObject::GetType(void) const { string type; GetProperties()->Get("__type", &type); return type; } -string ConfigObject::GetName(void) const +string DynamicObject::GetName(void) const { string name; GetProperties()->Get("__name", &name); return name; } -bool ConfigObject::IsLocal(void) const +bool DynamicObject::IsLocal(void) const { bool value = false; GetProperties()->Get("__local", &value); return value; } -bool ConfigObject::IsAbstract(void) const +bool DynamicObject::IsAbstract(void) const { bool value = false; GetProperties()->Get("__abstract", &value); return value; } -void ConfigObject::SetSource(const string& value) +void DynamicObject::SetSource(const string& value) { GetProperties()->Set("__source", value); } -string ConfigObject::GetSource(void) const +string DynamicObject::GetSource(void) const { string value; GetProperties()->Get("__source", &value); return value; } -void ConfigObject::SetCommitTimestamp(double ts) +void DynamicObject::SetCommitTimestamp(double ts) { GetProperties()->Set("__tx", ts); } -double ConfigObject::GetCommitTimestamp(void) const +double DynamicObject::GetCommitTimestamp(void) const { double value = 0; GetProperties()->Get("__tx", &value); return value; } -void ConfigObject::Commit(void) +void DynamicObject::Commit(void) { assert(Application::IsMainThread()); - ConfigObject::Ptr dobj = GetObject(GetType(), GetName()); - ConfigObject::Ptr self = GetSelf(); + DynamicObject::Ptr dobj = GetObject(GetType(), GetName()); + DynamicObject::Ptr self = GetSelf(); assert(!dobj || dobj == self); - pair ti; - ti = GetAllObjects().insert(make_pair(GetType(), ConfigObject::NameMap())); + pair ti; + ti = GetAllObjects().insert(make_pair(GetType(), DynamicObject::NameMap())); ti.first->second.insert(make_pair(GetName(), GetSelf())); SetCommitTimestamp(Utility::GetTime()); @@ -126,17 +126,17 @@ void ConfigObject::Commit(void) OnCommitted(GetSelf()); } -void ConfigObject::Unregister(void) +void DynamicObject::Unregister(void) { assert(Application::IsMainThread()); - ConfigObject::TypeMap::iterator tt; + DynamicObject::TypeMap::iterator tt; tt = GetAllObjects().find(GetType()); if (tt == GetAllObjects().end()) return; - ConfigObject::NameMap::iterator nt = tt->second.find(GetName()); + DynamicObject::NameMap::iterator nt = tt->second.find(GetName()); if (nt == tt->second.end()) return; @@ -146,41 +146,41 @@ void ConfigObject::Unregister(void) OnRemoved(GetSelf()); } -ConfigObject::Ptr ConfigObject::GetObject(const string& type, const string& name) +DynamicObject::Ptr DynamicObject::GetObject(const string& type, const string& name) { - ConfigObject::TypeMap::iterator tt; + DynamicObject::TypeMap::iterator tt; tt = GetAllObjects().find(type); if (tt == GetAllObjects().end()) - return ConfigObject::Ptr(); + return DynamicObject::Ptr(); - ConfigObject::NameMap::iterator nt = tt->second.find(name); + DynamicObject::NameMap::iterator nt = tt->second.find(name); if (nt == tt->second.end()) - return ConfigObject::Ptr(); + return DynamicObject::Ptr(); return nt->second; } -pair ConfigObject::GetTypes(void) +pair DynamicObject::GetTypes(void) { return make_pair(GetAllObjects().begin(), GetAllObjects().end()); } -pair ConfigObject::GetObjects(const string& type) +pair DynamicObject::GetObjects(const string& type) { - pair ti; - ti = GetAllObjects().insert(make_pair(type, ConfigObject::NameMap())); + pair ti; + ti = GetAllObjects().insert(make_pair(type, DynamicObject::NameMap())); return make_pair(ti.first->second.begin(), ti.first->second.end()); } -void ConfigObject::RemoveTag(const string& key) +void DynamicObject::RemoveTag(const string& key) { GetTags()->Remove(key); } -ScriptTask::Ptr ConfigObject::InvokeMethod(const string& method, +ScriptTask::Ptr DynamicObject::InvokeMethod(const string& method, const vector& arguments, ScriptTask::CompletionCallback callback) { Dictionary::Ptr methods; @@ -199,7 +199,7 @@ ScriptTask::Ptr ConfigObject::InvokeMethod(const string& method, return task; } -void ConfigObject::DumpObjects(const string& filename) +void DynamicObject::DumpObjects(const string& filename) { Logger::Write(LogInformation, "base", "Dumping program state to file '" + filename + "'"); @@ -211,11 +211,11 @@ void ConfigObject::DumpObjects(const string& filename) FIFO::Ptr fifo = boost::make_shared(); - ConfigObject::TypeMap::iterator tt; + DynamicObject::TypeMap::iterator tt; for (tt = GetAllObjects().begin(); tt != GetAllObjects().end(); tt++) { - ConfigObject::NameMap::iterator nt; + DynamicObject::NameMap::iterator nt; for (nt = tt->second.begin(); nt != tt->second.end(); nt++) { - ConfigObject::Ptr object = nt->second; + DynamicObject::Ptr object = nt->second; Dictionary::Ptr persistentObject = boost::make_shared(); @@ -249,10 +249,8 @@ void ConfigObject::DumpObjects(const string& filename) } } -void ConfigObject::RestoreObjects(const string& filename) +void DynamicObject::RestoreObjects(const string& filename) { - assert(GetAllObjects().empty()); - Logger::Write(LogInformation, "base", "Restoring program state from file '" + filename + "'"); std::ifstream fp; @@ -290,7 +288,7 @@ void ConfigObject::RestoreObjects(const string& filename) Dictionary::Ptr properties; if (persistentObject->Get("properties", &properties)) { - ConfigObject::Ptr object = Create(type, properties); + DynamicObject::Ptr object = Create(type, properties); object->SetTags(tags); object->Commit(); } else { @@ -301,33 +299,34 @@ void ConfigObject::RestoreObjects(const string& filename) } } -ConfigObject::TypeMap& ConfigObject::GetAllObjects(void) +DynamicObject::TypeMap& DynamicObject::GetAllObjects(void) { static TypeMap objects; return objects; } -ConfigObject::ClassMap& ConfigObject::GetClasses(void) +DynamicObject::ClassMap& DynamicObject::GetClasses(void) { static ClassMap classes; return classes; } -void ConfigObject::RegisterClass(const string& type, ConfigObject::Factory factory) +void DynamicObject::RegisterClass(const string& type, DynamicObject::Factory factory) { - GetClasses()[type] = factory; + if (GetObjects(type).first != GetObjects(type).second) + throw_exception(runtime_error("Cannot register class for type '" + + type + "': Objects of this type already exist.")); - /* TODO: upgrade existing objects */ + GetClasses()[type] = factory; } -ConfigObject::Ptr ConfigObject::Create(const string& type, const Dictionary::Ptr& properties) +DynamicObject::Ptr DynamicObject::Create(const string& type, const Dictionary::Ptr& properties) { - ConfigObject::ClassMap::iterator it; + DynamicObject::ClassMap::iterator it; it = GetClasses().find(type); if (it != GetClasses().end()) return it->second(properties); else - return boost::make_shared(properties); + return boost::make_shared(properties); } - diff --git a/base/configobject.h b/base/dynamicobject.h similarity index 77% rename from base/configobject.h rename to base/dynamicobject.h index 16b4be97f..f61f08f08 100644 --- a/base/configobject.h +++ b/base/dynamicobject.h @@ -17,30 +17,30 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#ifndef CONFIGOBJECT_H -#define CONFIGOBJECT_H +#ifndef DYNAMICOBJECT_H +#define DYNAMICOBJECT_H namespace icinga { /** - * A configuration object. + * A dynamic object that can be instantiated from the configuration file. * * @ingroup base */ -class I2_BASE_API ConfigObject : public Object +class I2_BASE_API DynamicObject : public Object { public: - typedef shared_ptr Ptr; - typedef weak_ptr WeakPtr; + typedef shared_ptr Ptr; + typedef weak_ptr WeakPtr; - typedef function Factory; + typedef function Factory; typedef map ClassMap; - typedef map NameMap; + typedef map NameMap; typedef map TypeMap; - ConfigObject(const Dictionary::Ptr& properties); + DynamicObject(const Dictionary::Ptr& properties); void SetProperties(const Dictionary::Ptr& config); Dictionary::Ptr GetProperties(void) const; @@ -68,7 +68,7 @@ public: void RemoveTag(const string& key); - ScriptTask::Ptr InvokeMethod(const string& hook, + ScriptTask::Ptr InvokeMethod(const string& method, const vector& arguments, ScriptTask::CompletionCallback callback); string GetType(void) const; @@ -85,7 +85,7 @@ public: void Commit(void); void Unregister(void); - static ConfigObject::Ptr GetObject(const string& type, const string& name); + static DynamicObject::Ptr GetObject(const string& type, const string& name); static pair GetTypes(void); static pair GetObjects(const string& type); @@ -93,10 +93,10 @@ public: static void RestoreObjects(const string& filename); static void RegisterClass(const string& type, Factory factory); - static ConfigObject::Ptr Create(const string& type, const Dictionary::Ptr& properties); + static DynamicObject::Ptr Create(const string& type, const Dictionary::Ptr& properties); - static boost::signal OnCommitted; - static boost::signal OnRemoved; + static boost::signal OnCommitted; + static boost::signal OnRemoved; private: static ClassMap& GetClasses(void); @@ -113,9 +113,9 @@ private: class RegisterClassHelper { public: - RegisterClassHelper(const string& name, ConfigObject::Factory factory) + RegisterClassHelper(const string& name, DynamicObject::Factory factory) { - ConfigObject::RegisterClass(name, factory); + DynamicObject::RegisterClass(name, factory); } }; @@ -124,4 +124,4 @@ public: } -#endif /* CONFIGOBJECT_H */ +#endif /* DYNAMICOBJECT_H */ diff --git a/base/i2-base.h b/base/i2-base.h index fb236bd60..62b96d935 100644 --- a/base/i2-base.h +++ b/base/i2-base.h @@ -184,7 +184,7 @@ namespace tuples = boost::tuples; #include "process.h" #include "scriptfunction.h" #include "scripttask.h" -#include "configobject.h" +#include "dynamicobject.h" #include "logger.h" #include "application.h" #include "component.h" diff --git a/base/logger.cpp b/base/logger.cpp index 28bc0d8a2..56718b9f6 100644 --- a/base/logger.cpp +++ b/base/logger.cpp @@ -30,7 +30,7 @@ REGISTER_CLASS(Logger); * to this logger. */ Logger::Logger(const Dictionary::Ptr& properties) - : ConfigObject(properties) + : DynamicObject(properties) { if (!IsLocal()) throw_exception(runtime_error("Logger objects must be local.")); @@ -107,8 +107,8 @@ LogSeverity Logger::GetMinSeverity(void) const */ void Logger::ForwardLogEntry(const LogEntry& entry) { - ConfigObject::Ptr object; - BOOST_FOREACH(tie(tuples::ignore, object), ConfigObject::GetObjects("Logger")) { + DynamicObject::Ptr object; + BOOST_FOREACH(tie(tuples::ignore, object), DynamicObject::GetObjects("Logger")) { Logger::Ptr logger = dynamic_pointer_cast(object); if (entry.Severity >= logger->GetMinSeverity()) diff --git a/base/logger.h b/base/logger.h index 7b3f3d496..524bc8d21 100644 --- a/base/logger.h +++ b/base/logger.h @@ -60,15 +60,15 @@ public: virtual void ProcessLogEntry(const LogEntry& entry) = 0; protected: - ConfigObject::Ptr GetConfig(void) const; + DynamicObject::Ptr GetConfig(void) const; private: - ConfigObject *m_Config; + DynamicObject *m_Config; friend class Logger; }; -class I2_BASE_API Logger : public ConfigObject +class I2_BASE_API Logger : public DynamicObject { public: typedef shared_ptr Ptr; diff --git a/cib/host.cpp b/cib/host.cpp index 2d69f36f4..c2b4c592d 100644 --- a/cib/host.cpp +++ b/cib/host.cpp @@ -35,12 +35,12 @@ string Host::GetAlias(void) const bool Host::Exists(const string& name) { - return (ConfigObject::GetObject("Host", name)); + return (DynamicObject::GetObject("Host", name)); } Host::Ptr Host::GetByName(const string& name) { - ConfigObject::Ptr configObject = ConfigObject::GetObject("Host", name); + DynamicObject::Ptr configObject = DynamicObject::GetObject("Host", name); if (!configObject) throw_exception(invalid_argument("Host '" + name + "' does not exist.")); diff --git a/cib/host.h b/cib/host.h index 95101a096..ae327fbdc 100644 --- a/cib/host.h +++ b/cib/host.h @@ -23,14 +23,14 @@ namespace icinga { -class I2_CIB_API Host : public ConfigObject +class I2_CIB_API Host : public DynamicObject { public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; Host(const Dictionary::Ptr& properties) - : ConfigObject(properties) + : DynamicObject(properties) { } static bool Exists(const string& name); diff --git a/cib/hostgroup.cpp b/cib/hostgroup.cpp index bbae75254..58ddaf3d2 100644 --- a/cib/hostgroup.cpp +++ b/cib/hostgroup.cpp @@ -49,12 +49,12 @@ string HostGroup::GetActionUrl(void) const bool HostGroup::Exists(const string& name) { - return (ConfigObject::GetObject("HostGroup", name)); + return (DynamicObject::GetObject("HostGroup", name)); } HostGroup::Ptr HostGroup::GetByName(const string& name) { - ConfigObject::Ptr configObject = ConfigObject::GetObject("HostGroup", name); + DynamicObject::Ptr configObject = DynamicObject::GetObject("HostGroup", name); if (!configObject) throw_exception(invalid_argument("HostGroup '" + name + "' does not exist.")); diff --git a/cib/hostgroup.h b/cib/hostgroup.h index 820bdbb0f..f283e0da9 100644 --- a/cib/hostgroup.h +++ b/cib/hostgroup.h @@ -23,14 +23,14 @@ namespace icinga { -class I2_CIB_API HostGroup : public ConfigObject +class I2_CIB_API HostGroup : public DynamicObject { public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; HostGroup(const Dictionary::Ptr& properties) - : ConfigObject(properties) + : DynamicObject(properties) { } static bool Exists(const string& name); diff --git a/cib/nagioschecktask.cpp b/cib/nagioschecktask.cpp index 9209c0e30..e7568ac18 100644 --- a/cib/nagioschecktask.cpp +++ b/cib/nagioschecktask.cpp @@ -31,7 +31,7 @@ void NagiosCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector()) + if (!vservice.IsObjectType()) throw_exception(invalid_argument("Argument must be a config object.")); Service::Ptr service = static_cast(vservice); diff --git a/cib/service.cpp b/cib/service.cpp index 5e8d95910..6d410aeb9 100644 --- a/cib/service.cpp +++ b/cib/service.cpp @@ -37,12 +37,12 @@ string Service::GetAlias(void) const bool Service::Exists(const string& name) { - return (ConfigObject::GetObject("Service", name)); + return (DynamicObject::GetObject("Service", name)); } Service::Ptr Service::GetByName(const string& name) { - ConfigObject::Ptr configObject = ConfigObject::GetObject("Service", name); + DynamicObject::Ptr configObject = DynamicObject::GetObject("Service", name); if (!configObject) throw_exception(invalid_argument("Service '" + name + "' does not exist.")); diff --git a/cib/service.h b/cib/service.h index fa9fda51d..dcfa7fae2 100644 --- a/cib/service.h +++ b/cib/service.h @@ -42,14 +42,14 @@ class CheckResult; class CheckResultMessage; class ServiceStatusMessage; -class I2_CIB_API Service : public ConfigObject +class I2_CIB_API Service : public DynamicObject { public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; Service(const Dictionary::Ptr& properties) - : ConfigObject(properties) + : DynamicObject(properties) { } static bool Exists(const string& name); diff --git a/cib/servicegroup.cpp b/cib/servicegroup.cpp index e19b08bda..daca48aab 100644 --- a/cib/servicegroup.cpp +++ b/cib/servicegroup.cpp @@ -49,12 +49,12 @@ string ServiceGroup::GetActionUrl(void) const bool ServiceGroup::Exists(const string& name) { - return (ConfigObject::GetObject("ServiceGroup", name)); + return (DynamicObject::GetObject("ServiceGroup", name)); } ServiceGroup::Ptr ServiceGroup::GetByName(const string& name) { - ConfigObject::Ptr configObject = ConfigObject::GetObject("ServiceGroup", name); + DynamicObject::Ptr configObject = DynamicObject::GetObject("ServiceGroup", name); if (!configObject) throw_exception(invalid_argument("ServiceGroup '" + name + "' does not exist.")); diff --git a/cib/servicegroup.h b/cib/servicegroup.h index 9666f15da..d43b5a671 100644 --- a/cib/servicegroup.h +++ b/cib/servicegroup.h @@ -23,14 +23,14 @@ namespace icinga { -class I2_CIB_API ServiceGroup : public ConfigObject +class I2_CIB_API ServiceGroup : public DynamicObject { public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; ServiceGroup(const Dictionary::Ptr& properties) - : ConfigObject(properties) + : DynamicObject(properties) { } static bool Exists(const string& name); diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index e05549fb8..bf0944bbc 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -76,7 +76,7 @@ void CheckerComponent::CheckTimerHandler(void) arguments.push_back(service); ScriptTask::Ptr task; task = service->InvokeMethod("check", arguments, boost::bind(&CheckerComponent::CheckCompletedHandler, this, service, _1)); - assert(task); /* TODO: gracefully handle missing hooks */ + assert(task); /* TODO: gracefully handle missing methods */ service->SetTag("current_task", task); diff --git a/components/cibsync/cibsynccomponent.cpp b/components/cibsync/cibsynccomponent.cpp index 376090c0b..7516e1879 100644 --- a/components/cibsync/cibsynccomponent.cpp +++ b/components/cibsync/cibsynccomponent.cpp @@ -34,8 +34,8 @@ void CIBSyncComponent::Start(void) m_Endpoint->RegisterTopicHandler("config::FetchObjects", boost::bind(&CIBSyncComponent::FetchObjectsHandler, this, _2)); - ConfigObject::OnCommitted.connect(boost::bind(&CIBSyncComponent::LocalObjectCommittedHandler, this, _1)); - ConfigObject::OnRemoved.connect(boost::bind(&CIBSyncComponent::LocalObjectRemovedHandler, this, _1)); + DynamicObject::OnCommitted.connect(boost::bind(&CIBSyncComponent::LocalObjectCommittedHandler, this, _1)); + DynamicObject::OnRemoved.connect(boost::bind(&CIBSyncComponent::LocalObjectRemovedHandler, this, _1)); m_Endpoint->RegisterPublication("config::ObjectCommitted"); m_Endpoint->RegisterPublication("config::ObjectRemoved"); @@ -106,7 +106,7 @@ void CIBSyncComponent::SessionEstablishedHandler(const Endpoint::Ptr& endpoint) EndpointManager::GetInstance()->SendUnicastMessage(m_Endpoint, endpoint, request); } -RequestMessage CIBSyncComponent::MakeObjectMessage(const ConfigObject::Ptr& object, string method, bool includeProperties) +RequestMessage CIBSyncComponent::MakeObjectMessage(const DynamicObject::Ptr& object, string method, bool includeProperties) { RequestMessage msg; msg.SetMethod(method); @@ -123,17 +123,17 @@ RequestMessage CIBSyncComponent::MakeObjectMessage(const ConfigObject::Ptr& obje return msg; } -bool CIBSyncComponent::ShouldReplicateObject(const ConfigObject::Ptr& object) +bool CIBSyncComponent::ShouldReplicateObject(const DynamicObject::Ptr& object) { return (!object->IsLocal()); } void CIBSyncComponent::FetchObjectsHandler(const Endpoint::Ptr& sender) { - pair trange; - ConfigObject::TypeMap::iterator tt; + pair trange; + DynamicObject::TypeMap::iterator tt; for (tt = trange.first; tt != trange.second; tt++) { - ConfigObject::Ptr object; + DynamicObject::Ptr object; BOOST_FOREACH(tie(tuples::ignore, object), tt->second) { if (!ShouldReplicateObject(object)) continue; @@ -145,7 +145,7 @@ void CIBSyncComponent::FetchObjectsHandler(const Endpoint::Ptr& sender) } } -void CIBSyncComponent::LocalObjectCommittedHandler(const ConfigObject::Ptr& object) +void CIBSyncComponent::LocalObjectCommittedHandler(const DynamicObject::Ptr& object) { /* don't send messages when we're currently processing a remote update */ if (m_SyncingConfig) @@ -158,7 +158,7 @@ void CIBSyncComponent::LocalObjectCommittedHandler(const ConfigObject::Ptr& obje MakeObjectMessage(object, "config::ObjectCommitted", true)); } -void CIBSyncComponent::LocalObjectRemovedHandler(const ConfigObject::Ptr& object) +void CIBSyncComponent::LocalObjectRemovedHandler(const DynamicObject::Ptr& object) { /* don't send messages when we're currently processing a remote update */ if (m_SyncingConfig) @@ -189,10 +189,10 @@ void CIBSyncComponent::RemoteObjectCommittedHandler(const Endpoint::Ptr& sender, if (!params.Get("properties", &properties)) return; - ConfigObject::Ptr object = ConfigObject::GetObject(type, name); + DynamicObject::Ptr object = DynamicObject::GetObject(type, name); if (!object) { - object = boost::make_shared(properties.GetDictionary()); + object = boost::make_shared(properties.GetDictionary()); if (object->GetSource() == EndpointManager::GetInstance()->GetIdentity()) { /* the peer sent us an object that was originally created by us - @@ -204,7 +204,7 @@ void CIBSyncComponent::RemoteObjectCommittedHandler(const Endpoint::Ptr& sender, return; } } else { - ConfigObject::Ptr remoteObject = boost::make_shared(properties.GetDictionary()); + DynamicObject::Ptr remoteObject = boost::make_shared(properties.GetDictionary()); if (object->GetCommitTimestamp() >= remoteObject->GetCommitTimestamp()) return; @@ -245,7 +245,7 @@ void CIBSyncComponent::RemoteObjectRemovedHandler(const RequestMessage& request) if (!params.Get("type", &type)) return; - ConfigObject::Ptr object = ConfigObject::GetObject(type, name); + DynamicObject::Ptr object = DynamicObject::GetObject(type, name); if (!object) return; diff --git a/components/cibsync/cibsynccomponent.h b/components/cibsync/cibsynccomponent.h index 8a5cbfd17..3bc46945b 100644 --- a/components/cibsync/cibsynccomponent.h +++ b/components/cibsync/cibsynccomponent.h @@ -41,17 +41,17 @@ private: void NewEndpointHandler(const Endpoint::Ptr& endpoint); void SessionEstablishedHandler(const Endpoint::Ptr& endpoint); - void LocalObjectCommittedHandler(const ConfigObject::Ptr& object); - void LocalObjectRemovedHandler(const ConfigObject::Ptr& object); + void LocalObjectCommittedHandler(const DynamicObject::Ptr& object); + void LocalObjectRemovedHandler(const DynamicObject::Ptr& object); void FetchObjectsHandler(const Endpoint::Ptr& sender); void RemoteObjectCommittedHandler(const Endpoint::Ptr& sender, const RequestMessage& request); void RemoteObjectRemovedHandler(const RequestMessage& request); - static RequestMessage MakeObjectMessage(const ConfigObject::Ptr& object, + static RequestMessage MakeObjectMessage(const DynamicObject::Ptr& object, string method, bool includeProperties); - static bool ShouldReplicateObject(const ConfigObject::Ptr& object); + static bool ShouldReplicateObject(const DynamicObject::Ptr& object); }; } diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp index 2deb7e3a6..ae288f535 100644 --- a/components/compat/compatcomponent.cpp +++ b/components/compat/compatcomponent.cpp @@ -222,8 +222,8 @@ void CompatComponent::StatusTimerHandler(void) map > hostgroups; - ConfigObject::Ptr object; - BOOST_FOREACH(tie(tuples::ignore, object), ConfigObject::GetObjects("Host")) { + DynamicObject::Ptr object; + BOOST_FOREACH(tie(tuples::ignore, object), DynamicObject::GetObjects("Host")) { const Host::Ptr& host = static_pointer_cast(object); Dictionary::Ptr dict; @@ -265,7 +265,7 @@ void CompatComponent::StatusTimerHandler(void) map > servicegroups; - BOOST_FOREACH(tie(tuples::ignore, object), ConfigObject::GetObjects("Service")) { + BOOST_FOREACH(tie(tuples::ignore, object), DynamicObject::GetObjects("Service")) { Service::Ptr service = static_pointer_cast(object); Dictionary::Ptr dict; diff --git a/components/convenience/conveniencecomponent.cpp b/components/convenience/conveniencecomponent.cpp index 9bf399d45..7d700fafb 100644 --- a/components/convenience/conveniencecomponent.cpp +++ b/components/convenience/conveniencecomponent.cpp @@ -144,7 +144,7 @@ void ConvenienceComponent::HostRemovedHandler(const ConfigItem::Ptr& item) if (item->GetType() != "host") return; - ConfigObject::Ptr host = item->GetConfigObject(); + DynamicObject::Ptr host = item->GetDynamicObject(); if (!host) return; diff --git a/components/delegation/delegationcomponent.cpp b/components/delegation/delegationcomponent.cpp index c1dda1310..161412bab 100644 --- a/components/delegation/delegationcomponent.cpp +++ b/components/delegation/delegationcomponent.cpp @@ -24,8 +24,8 @@ using namespace icinga; void DelegationComponent::Start(void) { - ConfigObject::OnCommitted.connect(boost::bind(&DelegationComponent::ServiceCommittedHandler, this, _1)); - ConfigObject::OnRemoved.connect(boost::bind(&DelegationComponent::ServiceRemovedHandler, this, _1)); + DynamicObject::OnCommitted.connect(boost::bind(&DelegationComponent::ServiceCommittedHandler, this, _1)); + DynamicObject::OnRemoved.connect(boost::bind(&DelegationComponent::ServiceRemovedHandler, this, _1)); m_DelegationTimer = boost::make_shared(); m_DelegationTimer->SetInterval(30); @@ -50,7 +50,7 @@ void DelegationComponent::Stop(void) mgr->UnregisterEndpoint(m_Endpoint); } -void DelegationComponent::ServiceCommittedHandler(const ConfigObject::Ptr& object) +void DelegationComponent::ServiceCommittedHandler(const DynamicObject::Ptr& object) { Service::Ptr service = dynamic_pointer_cast(object); @@ -71,7 +71,7 @@ void DelegationComponent::ServiceCommittedHandler(const ConfigObject::Ptr& objec } } -void DelegationComponent::ServiceRemovedHandler(const ConfigObject::Ptr& object) +void DelegationComponent::ServiceRemovedHandler(const DynamicObject::Ptr& object) { Service::Ptr service = dynamic_pointer_cast(object); @@ -160,8 +160,8 @@ void DelegationComponent::SessionEstablishedHandler(const Endpoint::Ptr& endpoin return; /* locally clear checker for all services that previously belonged to this endpoint */ - ConfigObject::Ptr object; - BOOST_FOREACH(tie(tuples::ignore, object), ConfigObject::GetObjects("Service")) { + DynamicObject::Ptr object; + BOOST_FOREACH(tie(tuples::ignore, object), DynamicObject::GetObjects("Service")) { Service::Ptr service = dynamic_pointer_cast(object); if (!service) @@ -186,8 +186,8 @@ void DelegationComponent::DelegationTimerHandler(void) vector services; /* build "checker -> service count" histogram */ - ConfigObject::Ptr object; - BOOST_FOREACH(tie(tuples::ignore, object), ConfigObject::GetObjects("Service")) { + DynamicObject::Ptr object; + BOOST_FOREACH(tie(tuples::ignore, object), DynamicObject::GetObjects("Service")) { Service::Ptr service = dynamic_pointer_cast(object); if (!service) diff --git a/components/delegation/delegationcomponent.h b/components/delegation/delegationcomponent.h index 6a067f01c..4ace3fe35 100644 --- a/components/delegation/delegationcomponent.h +++ b/components/delegation/delegationcomponent.h @@ -39,8 +39,8 @@ private: void NewEndpointHandler(const Endpoint::Ptr& endpoint); void SessionEstablishedHandler(const Endpoint::Ptr& endpoint); - void ServiceCommittedHandler(const ConfigObject::Ptr& object); - void ServiceRemovedHandler(const ConfigObject::Ptr& object); + void ServiceCommittedHandler(const DynamicObject::Ptr& object); + void ServiceRemovedHandler(const DynamicObject::Ptr& object); void DelegationTimerHandler(void); vector GetCheckerCandidates(const Service::Ptr& service) const; diff --git a/components/discovery/discoverycomponent.cpp b/components/discovery/discoverycomponent.cpp index fe1f50d84..44326fdd2 100644 --- a/components/discovery/discoverycomponent.cpp +++ b/components/discovery/discoverycomponent.cpp @@ -313,8 +313,8 @@ bool DiscoveryComponent::HasMessagePermission(const Dictionary::Ptr& roles, cons if (!roles) return false; - ConfigObject::Ptr role; - BOOST_FOREACH(tie(tuples::ignore, role), ConfigObject::GetObjects("Role")) { + DynamicObject::Ptr role; + BOOST_FOREACH(tie(tuples::ignore, role), DynamicObject::GetObjects("Role")) { Dictionary::Ptr permissions; if (!role->GetProperty(messageType, &permissions)) continue; @@ -355,7 +355,7 @@ void DiscoveryComponent::ProcessDiscoveryMessage(const string& identity, const D if (message.GetService(&service) && !service.empty()) info->Service = service; - ConfigObject::Ptr endpointConfig = ConfigObject::GetObject("endpoint", identity); + DynamicObject::Ptr endpointConfig = DynamicObject::GetObject("endpoint", identity); Dictionary::Ptr roles; if (endpointConfig) endpointConfig->GetProperty("roles", &roles); @@ -442,8 +442,8 @@ void DiscoveryComponent::DiscoveryTimerHandler(void) double now = Utility::GetTime(); /* check whether we have to reconnect to one of our upstream endpoints */ - ConfigObject::Ptr object; - BOOST_FOREACH(tie(tuples::ignore, object), ConfigObject::GetObjects("Endpoint")) { + DynamicObject::Ptr object; + BOOST_FOREACH(tie(tuples::ignore, object), DynamicObject::GetObjects("Endpoint")) { /* Check if we're already connected to this endpoint. */ if (endpointManager->GetEndpointByIdentity(object->GetName())) continue; @@ -470,7 +470,7 @@ void DiscoveryComponent::DiscoveryTimerHandler(void) /* for explicitly-configured upstream endpoints * we prefer to use the node/service from the * config object - which is what the for loop above does */ - if (ConfigObject::GetObject("endpoint", identity)) + if (DynamicObject::GetObject("endpoint", identity)) continue; if (info->LastSeen < now - DiscoveryComponent::RegistrationTTL) { diff --git a/dyn/configitem.cpp b/dyn/configitem.cpp index 1a46d9a23..f445eefa5 100644 --- a/dyn/configitem.cpp +++ b/dyn/configitem.cpp @@ -75,22 +75,22 @@ void ConfigItem::CalculateProperties(Dictionary::Ptr dictionary) const m_ExpressionList->Execute(dictionary); } -ConfigObject::Ptr ConfigItem::Commit(void) +DynamicObject::Ptr ConfigItem::Commit(void) { - ConfigObject::Ptr dobj = m_ConfigObject.lock(); + DynamicObject::Ptr dobj = m_DynamicObject.lock(); Dictionary::Ptr properties = boost::make_shared(); CalculateProperties(properties); if (!dobj) - dobj = ConfigObject::GetObject(GetType(), GetName()); + dobj = DynamicObject::GetObject(GetType(), GetName()); if (!dobj) - dobj = ConfigObject::Create(GetType(), properties); + dobj = DynamicObject::Create(GetType(), properties); else dobj->SetProperties(properties); - m_ConfigObject = dobj; + m_DynamicObject = dobj; if (dobj->IsAbstract()) dobj->Unregister(); @@ -109,7 +109,7 @@ ConfigObject::Ptr ConfigItem::Commit(void) void ConfigItem::Unregister(void) { - ConfigObject::Ptr dobj = m_ConfigObject.lock(); + DynamicObject::Ptr dobj = m_DynamicObject.lock(); if (dobj) dobj->Unregister(); @@ -123,9 +123,9 @@ void ConfigItem::Unregister(void) OnRemoved(GetSelf()); } -ConfigObject::Ptr ConfigItem::GetConfigObject(void) const +DynamicObject::Ptr ConfigItem::GetDynamicObject(void) const { - return m_ConfigObject.lock(); + return m_DynamicObject.lock(); } ConfigItem::Ptr ConfigItem::GetObject(const string& type, const string& name) diff --git a/dyn/configitem.h b/dyn/configitem.h index ddc479082..8df8edb77 100644 --- a/dyn/configitem.h +++ b/dyn/configitem.h @@ -41,10 +41,10 @@ public: void CalculateProperties(Dictionary::Ptr dictionary) const; - ConfigObject::Ptr Commit(void); + DynamicObject::Ptr Commit(void); void Unregister(void); - ConfigObject::Ptr GetConfigObject(void) const; + DynamicObject::Ptr GetDynamicObject(void) const; DebugInfo GetDebugInfo(void) const; @@ -61,7 +61,7 @@ private: vector m_Parents; DebugInfo m_DebugInfo; - ConfigObject::WeakPtr m_ConfigObject; + DynamicObject::WeakPtr m_DynamicObject; typedef map, ConfigItem::Ptr> ItemMap; static ItemMap m_Items; diff --git a/icinga/icingaapplication.cpp b/icinga/icingaapplication.cpp index e5388207a..cfd8cd9b6 100644 --- a/icinga/icingaapplication.cpp +++ b/icinga/icingaapplication.cpp @@ -42,14 +42,6 @@ IcingaApplication::IcingaApplication(void) */ int IcingaApplication::Main(const vector& args) { - /* restore the previous program state */ - ConfigObject::RestoreObjects("retention.dat"); - - m_RetentionTimer = boost::make_shared(); - m_RetentionTimer->SetInterval(60); - m_RetentionTimer->OnTimerExpired.connect(boost::bind(&IcingaApplication::DumpProgramState, this)); - m_RetentionTimer->Start(); - /* create console logger */ ConfigItemBuilder::Ptr consoleLogConfig = boost::make_shared(); consoleLogConfig->SetType("Logger"); @@ -58,6 +50,15 @@ int IcingaApplication::Main(const vector& args) consoleLogConfig->AddExpression("type", OperatorSet, "console"); consoleLogConfig->Compile()->Commit(); + /* restore the previous program state */ + DynamicObject::RestoreObjects("retention.dat"); + + /* periodically dump the program state */ + m_RetentionTimer = boost::make_shared(); + m_RetentionTimer->SetInterval(60); + m_RetentionTimer->OnTimerExpired.connect(boost::bind(&IcingaApplication::DumpProgramState, this)); + m_RetentionTimer->Start(); + #ifdef _WIN32 Logger::Write(LogInformation, "icinga", "Icinga component loader"); #else /* _WIN32 */ @@ -135,7 +136,7 @@ int IcingaApplication::Main(const vector& args) item->Commit(); } - ConfigObject::Ptr icingaConfig = ConfigObject::GetObject("Application", "icinga"); + DynamicObject::Ptr icingaConfig = DynamicObject::GetObject("Application", "icinga"); if (!icingaConfig) throw_exception(runtime_error("Configuration must contain an 'Application' object named 'icinga'.")); @@ -196,7 +197,7 @@ int IcingaApplication::Main(const vector& args) } void IcingaApplication::DumpProgramState(void) { - ConfigObject::DumpObjects("retention.dat.tmp"); + DynamicObject::DumpObjects("retention.dat.tmp"); rename("retention.dat.tmp", "retention.dat"); }