asynctask.h \
component.cpp \
component.h \
- configobject.cpp \
- configobject.h \
dictionary.cpp \
dictionary.h \
+ dynamicobject.cpp \
+ dynamicobject.h \
event.cpp \
event.h \
exception.cpp \
<ItemGroup>
<ClCompile Include="application.cpp" />
<ClCompile Include="component.cpp" />
- <ClCompile Include="configobject.cpp" />
+ <ClCompile Include="dynamicobject.cpp" />
<ClCompile Include="dictionary.cpp" />
<ClCompile Include="event.cpp" />
<ClCompile Include="exception.cpp" />
<ClInclude Include="application.h" />
<ClInclude Include="asynctask.h" />
<ClInclude Include="component.h" />
- <ClInclude Include="configobject.h" />
+ <ClInclude Include="dynamicobject.h" />
<ClInclude Include="dictionary.h" />
<ClInclude Include="event.h" />
<ClInclude Include="fifo.h" />
<ClCompile Include="component.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
- <ClCompile Include="configobject.cpp">
- <Filter>Quelldateien</Filter>
- </ClCompile>
<ClCompile Include="dictionary.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="netstring.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
+ <ClCompile Include="dynamicobject.cpp">
+ <Filter>Quelldateien</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="application.h">
<ClInclude Include="component.h">
<Filter>Headerdateien</Filter>
</ClInclude>
- <ClInclude Include="configobject.h">
- <Filter>Headerdateien</Filter>
- </ClInclude>
<ClInclude Include="dictionary.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="netstring.h">
<Filter>Headerdateien</Filter>
</ClInclude>
+ <ClInclude Include="dynamicobject.h">
+ <Filter>Headerdateien</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Quelldateien">
* Constructor for the component class.
*/
Component::Component(const Dictionary::Ptr& properties)
- : ConfigObject(properties)
+ : DynamicObject(properties)
{
assert(Application::IsMainThread());
*
* @returns The configuration.
*/
-ConfigObject::Ptr IComponent::GetConfig(void) const
+DynamicObject::Ptr IComponent::GetConfig(void) const
{
return m_Config->GetSelf();
}
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;
};
*
* @ingroup base
*/
-class I2_BASE_API Component : public ConfigObject
+class I2_BASE_API Component : public DynamicObject
{
public:
typedef shared_ptr<Component> Ptr;
using namespace icinga;
-map<pair<string, string>, Dictionary::Ptr> ConfigObject::m_PersistentTags;
-boost::signal<void (const ConfigObject::Ptr&)> ConfigObject::OnCommitted;
-boost::signal<void (const ConfigObject::Ptr&)> ConfigObject::OnRemoved;
+map<pair<string, string>, Dictionary::Ptr> DynamicObject::m_PersistentTags;
+boost::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnCommitted;
+boost::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnRemoved;
-ConfigObject::ConfigObject(const Dictionary::Ptr& properties)
+DynamicObject::DynamicObject(const Dictionary::Ptr& properties)
: m_Properties(properties), m_Tags(boost::make_shared<Dictionary>())
{
/* restore the object's tags */
}
}
-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<ConfigObject::TypeMap::iterator, bool> ti;
- ti = GetAllObjects().insert(make_pair(GetType(), ConfigObject::NameMap()));
+ pair<DynamicObject::TypeMap::iterator, bool> ti;
+ ti = GetAllObjects().insert(make_pair(GetType(), DynamicObject::NameMap()));
ti.first->second.insert(make_pair(GetName(), GetSelf()));
SetCommitTimestamp(Utility::GetTime());
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;
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::TypeMap::iterator, ConfigObject::TypeMap::iterator> ConfigObject::GetTypes(void)
+pair<DynamicObject::TypeMap::iterator, DynamicObject::TypeMap::iterator> DynamicObject::GetTypes(void)
{
return make_pair(GetAllObjects().begin(), GetAllObjects().end());
}
-pair<ConfigObject::NameMap::iterator, ConfigObject::NameMap::iterator> ConfigObject::GetObjects(const string& type)
+pair<DynamicObject::NameMap::iterator, DynamicObject::NameMap::iterator> DynamicObject::GetObjects(const string& type)
{
- pair<ConfigObject::TypeMap::iterator, bool> ti;
- ti = GetAllObjects().insert(make_pair(type, ConfigObject::NameMap()));
+ pair<DynamicObject::TypeMap::iterator, bool> 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<Variant>& arguments, ScriptTask::CompletionCallback callback)
{
Dictionary::Ptr methods;
return task;
}
-void ConfigObject::DumpObjects(const string& filename)
+void DynamicObject::DumpObjects(const string& filename)
{
Logger::Write(LogInformation, "base", "Dumping program state to file '" + filename + "'");
FIFO::Ptr fifo = boost::make_shared<FIFO>();
- 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<Dictionary>();
}
}
-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;
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 {
}
}
-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<ConfigObject>(properties);
+ return boost::make_shared<DynamicObject>(properties);
}
-
* 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<ConfigObject> Ptr;
- typedef weak_ptr<ConfigObject> WeakPtr;
+ typedef shared_ptr<DynamicObject> Ptr;
+ typedef weak_ptr<DynamicObject> WeakPtr;
- typedef function<ConfigObject::Ptr (const Dictionary::Ptr&)> Factory;
+ typedef function<DynamicObject::Ptr (const Dictionary::Ptr&)> Factory;
typedef map<string, Factory> ClassMap;
- typedef map<string, ConfigObject::Ptr> NameMap;
+ typedef map<string, DynamicObject::Ptr> NameMap;
typedef map<string, NameMap> TypeMap;
- ConfigObject(const Dictionary::Ptr& properties);
+ DynamicObject(const Dictionary::Ptr& properties);
void SetProperties(const Dictionary::Ptr& config);
Dictionary::Ptr GetProperties(void) const;
void RemoveTag(const string& key);
- ScriptTask::Ptr InvokeMethod(const string& hook,
+ ScriptTask::Ptr InvokeMethod(const string& method,
const vector<Variant>& arguments, ScriptTask::CompletionCallback callback);
string GetType(void) const;
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<TypeMap::iterator, TypeMap::iterator> GetTypes(void);
static pair<NameMap::iterator, NameMap::iterator> GetObjects(const string& type);
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<void (const ConfigObject::Ptr&)> OnCommitted;
- static boost::signal<void (const ConfigObject::Ptr&)> OnRemoved;
+ static boost::signal<void (const DynamicObject::Ptr&)> OnCommitted;
+ static boost::signal<void (const DynamicObject::Ptr&)> OnRemoved;
private:
static ClassMap& GetClasses(void);
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);
}
};
}
-#endif /* CONFIGOBJECT_H */
+#endif /* DYNAMICOBJECT_H */
#include "process.h"
#include "scriptfunction.h"
#include "scripttask.h"
-#include "configobject.h"
+#include "dynamicobject.h"
#include "logger.h"
#include "application.h"
#include "component.h"
* to this logger.
*/
Logger::Logger(const Dictionary::Ptr& properties)
- : ConfigObject(properties)
+ : DynamicObject(properties)
{
if (!IsLocal())
throw_exception(runtime_error("Logger objects must be local."));
*/
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<Logger>(object);
if (entry.Severity >= logger->GetMinSeverity())
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<Logger> Ptr;
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."));
namespace icinga
{
-class I2_CIB_API Host : public ConfigObject
+class I2_CIB_API Host : public DynamicObject
{
public:
typedef shared_ptr<Host> Ptr;
typedef weak_ptr<Host> WeakPtr;
Host(const Dictionary::Ptr& properties)
- : ConfigObject(properties)
+ : DynamicObject(properties)
{ }
static bool Exists(const string& name);
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."));
namespace icinga
{
-class I2_CIB_API HostGroup : public ConfigObject
+class I2_CIB_API HostGroup : public DynamicObject
{
public:
typedef shared_ptr<HostGroup> Ptr;
typedef weak_ptr<HostGroup> WeakPtr;
HostGroup(const Dictionary::Ptr& properties)
- : ConfigObject(properties)
+ : DynamicObject(properties)
{ }
static bool Exists(const string& name);
throw_exception(invalid_argument("Missing argument: Service must be specified."));
Variant vservice = arguments[0];
- if (!vservice.IsObjectType<ConfigObject>())
+ if (!vservice.IsObjectType<DynamicObject>())
throw_exception(invalid_argument("Argument must be a config object."));
Service::Ptr service = static_cast<Service::Ptr>(vservice);
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."));
class CheckResultMessage;
class ServiceStatusMessage;
-class I2_CIB_API Service : public ConfigObject
+class I2_CIB_API Service : public DynamicObject
{
public:
typedef shared_ptr<Service> Ptr;
typedef weak_ptr<Service> WeakPtr;
Service(const Dictionary::Ptr& properties)
- : ConfigObject(properties)
+ : DynamicObject(properties)
{ }
static bool Exists(const string& name);
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."));
namespace icinga
{
-class I2_CIB_API ServiceGroup : public ConfigObject
+class I2_CIB_API ServiceGroup : public DynamicObject
{
public:
typedef shared_ptr<ServiceGroup> Ptr;
typedef weak_ptr<ServiceGroup> WeakPtr;
ServiceGroup(const Dictionary::Ptr& properties)
- : ConfigObject(properties)
+ : DynamicObject(properties)
{ }
static bool Exists(const string& name);
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);
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");
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);
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<ConfigObject::TypeMap::iterator, ConfigObject::TypeMap::iterator> trange;
- ConfigObject::TypeMap::iterator tt;
+ pair<DynamicObject::TypeMap::iterator, DynamicObject::TypeMap::iterator> 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;
}
}
-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)
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)
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<ConfigObject>(properties.GetDictionary());
+ object = boost::make_shared<DynamicObject>(properties.GetDictionary());
if (object->GetSource() == EndpointManager::GetInstance()->GetIdentity()) {
/* the peer sent us an object that was originally created by us -
return;
}
} else {
- ConfigObject::Ptr remoteObject = boost::make_shared<ConfigObject>(properties.GetDictionary());
+ DynamicObject::Ptr remoteObject = boost::make_shared<DynamicObject>(properties.GetDictionary());
if (object->GetCommitTimestamp() >= remoteObject->GetCommitTimestamp())
return;
if (!params.Get("type", &type))
return;
- ConfigObject::Ptr object = ConfigObject::GetObject(type, name);
+ DynamicObject::Ptr object = DynamicObject::GetObject(type, name);
if (!object)
return;
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);
};
}
map<string, vector<string> > 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<Host>(object);
Dictionary::Ptr dict;
map<string, vector<Service::Ptr> > 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<Service>(object);
Dictionary::Ptr dict;
if (item->GetType() != "host")
return;
- ConfigObject::Ptr host = item->GetConfigObject();
+ DynamicObject::Ptr host = item->GetDynamicObject();
if (!host)
return;
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<Timer>();
m_DelegationTimer->SetInterval(30);
mgr->UnregisterEndpoint(m_Endpoint);
}
-void DelegationComponent::ServiceCommittedHandler(const ConfigObject::Ptr& object)
+void DelegationComponent::ServiceCommittedHandler(const DynamicObject::Ptr& object)
{
Service::Ptr service = dynamic_pointer_cast<Service>(object);
}
}
-void DelegationComponent::ServiceRemovedHandler(const ConfigObject::Ptr& object)
+void DelegationComponent::ServiceRemovedHandler(const DynamicObject::Ptr& object)
{
Service::Ptr service = dynamic_pointer_cast<Service>(object);
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<Service>(object);
if (!service)
vector<Service::Ptr> 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<Service>(object);
if (!service)
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<Endpoint::Ptr> GetCheckerCandidates(const Service::Ptr& service) const;
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;
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);
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;
/* 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) {
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<Dictionary>();
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();
void ConfigItem::Unregister(void)
{
- ConfigObject::Ptr dobj = m_ConfigObject.lock();
+ DynamicObject::Ptr dobj = m_DynamicObject.lock();
if (dobj)
dobj->Unregister();
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)
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;
vector<string> m_Parents;
DebugInfo m_DebugInfo;
- ConfigObject::WeakPtr m_ConfigObject;
+ DynamicObject::WeakPtr m_DynamicObject;
typedef map<pair<string, string>, ConfigItem::Ptr> ItemMap;
static ItemMap m_Items;
*/
int IcingaApplication::Main(const vector<string>& args)
{
- /* restore the previous program state */
- ConfigObject::RestoreObjects("retention.dat");
-
- m_RetentionTimer = boost::make_shared<Timer>();
- 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<ConfigItemBuilder>();
consoleLogConfig->SetType("Logger");
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<Timer>();
+ 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 */
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'."));
}
void IcingaApplication::DumpProgramState(void) {
- ConfigObject::DumpObjects("retention.dat.tmp");
+ DynamicObject::DumpObjects("retention.dat.tmp");
rename("retention.dat.tmp", "retention.dat");
}