mirror of https://github.com/Icinga/icinga2.git
Integrate libdyn with the configfile component.
This commit is contained in:
parent
6c3b2a1348
commit
d45bcf99b1
|
@ -9,10 +9,6 @@ libbase_la_SOURCES = \
|
|||
application.h \
|
||||
component.cpp \
|
||||
component.h \
|
||||
configcollection.cpp \
|
||||
configcollection.h \
|
||||
confighive.cpp \
|
||||
confighive.h \
|
||||
configobject.cpp \
|
||||
configobject.h \
|
||||
cxx11-compat.h \
|
||||
|
@ -27,6 +23,10 @@ libbase_la_SOURCES = \
|
|||
i2-base.h \
|
||||
object.cpp \
|
||||
object.h \
|
||||
objectset.cpp \
|
||||
objectset.h \
|
||||
objectmap.cpp \
|
||||
objectmap.h \
|
||||
socket.cpp \
|
||||
socket.h \
|
||||
tcpclient.cpp \
|
||||
|
|
|
@ -49,8 +49,6 @@ Application::Application(void)
|
|||
if (IsDebuggerPresent())
|
||||
m_Debugging = true;
|
||||
#endif /* _WIN32 */
|
||||
|
||||
m_ConfigHive = make_shared<ConfigHive>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -197,16 +195,6 @@ void Application::Shutdown(void)
|
|||
m_ShuttingDown = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the application's configuration hive.
|
||||
*
|
||||
* @returns The config hive.
|
||||
*/
|
||||
ConfigHive::Ptr Application::GetConfigHive(void) const
|
||||
{
|
||||
return m_ConfigHive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a component from a shared library.
|
||||
*
|
||||
|
|
|
@ -47,8 +47,6 @@ public:
|
|||
|
||||
static void Log(string message);
|
||||
|
||||
ConfigHive::Ptr GetConfigHive(void) const;
|
||||
|
||||
shared_ptr<Component> LoadComponent(const string& path,
|
||||
const ConfigObject::Ptr& componentConfig);
|
||||
void RegisterComponent(shared_ptr<Component> component);
|
||||
|
@ -67,7 +65,6 @@ private:
|
|||
|
||||
static bool m_ShuttingDown; /**< Whether the application is in the process of
|
||||
shutting down. */
|
||||
ConfigHive::Ptr m_ConfigHive; /**< The application's configuration. */
|
||||
map< string, shared_ptr<Component> > m_Components; /**< Components that
|
||||
were loaded by the application. */
|
||||
vector<string> m_Arguments; /**< Command-line arguments */
|
||||
|
|
|
@ -13,13 +13,13 @@
|
|||
<ItemGroup>
|
||||
<ClCompile Include="application.cpp" />
|
||||
<ClCompile Include="component.cpp" />
|
||||
<ClCompile Include="configcollection.cpp" />
|
||||
<ClCompile Include="confighive.cpp" />
|
||||
<ClCompile Include="configobject.cpp" />
|
||||
<ClCompile Include="dictionary.cpp" />
|
||||
<ClCompile Include="exception.cpp" />
|
||||
<ClCompile Include="fifo.cpp" />
|
||||
<ClCompile Include="object.cpp" />
|
||||
<ClCompile Include="objectmap.cpp" />
|
||||
<ClCompile Include="objectset.cpp" />
|
||||
<ClCompile Include="socket.cpp" />
|
||||
<ClCompile Include="tcpclient.cpp" />
|
||||
<ClCompile Include="tcpserver.cpp" />
|
||||
|
@ -34,12 +34,12 @@
|
|||
<ItemGroup>
|
||||
<ClInclude Include="application.h" />
|
||||
<ClInclude Include="component.h" />
|
||||
<ClInclude Include="configcollection.h" />
|
||||
<ClInclude Include="confighive.h" />
|
||||
<ClInclude Include="configobject.h" />
|
||||
<ClInclude Include="cxx11-compat.h" />
|
||||
<ClInclude Include="delegate.h" />
|
||||
<ClInclude Include="dictionary.h" />
|
||||
<ClInclude Include="objectmap.h" />
|
||||
<ClInclude Include="objectset.h" />
|
||||
<ClInclude Include="observable.h" />
|
||||
<ClInclude Include="exception.h" />
|
||||
<ClInclude Include="fifo.h" />
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "i2-base.h"
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
/**
|
||||
* Sets the hive this collection belongs to.
|
||||
*
|
||||
* @param hive The hive.
|
||||
*/
|
||||
void ConfigCollection::SetHive(const ConfigHive::WeakPtr& hive)
|
||||
{
|
||||
m_Hive = hive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the hive this collection belongs to.
|
||||
*
|
||||
* @returns The hive.
|
||||
*/
|
||||
ConfigHive::WeakPtr ConfigCollection::GetHive(void) const
|
||||
{
|
||||
return m_Hive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new object to this collection.
|
||||
*
|
||||
* @param object The new object.
|
||||
*/
|
||||
void ConfigCollection::AddObject(const ConfigObject::Ptr& object)
|
||||
{
|
||||
RemoveObject(object);
|
||||
|
||||
Objects[object->GetName()] = object;
|
||||
object->Commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an object from this collection
|
||||
*
|
||||
* @param object The object that is to be removed.
|
||||
*/
|
||||
void ConfigCollection::RemoveObject(const ConfigObject::Ptr& object)
|
||||
{
|
||||
ObjectIterator oi = Objects.find(object->GetName());
|
||||
|
||||
if (oi != Objects.end()) {
|
||||
Objects.erase(oi);
|
||||
|
||||
EventArgs ea;
|
||||
ea.Source = object;
|
||||
OnObjectRemoved(ea);
|
||||
|
||||
ConfigHive::Ptr hive = m_Hive.lock();
|
||||
if (hive)
|
||||
hive->OnObjectRemoved(ea);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an object by name.
|
||||
*
|
||||
* @param name The name of the object.
|
||||
* @returns The object or a null pointer if the specified object
|
||||
* could not be found.
|
||||
*/
|
||||
ConfigObject::Ptr ConfigCollection::GetObject(const string& name) const
|
||||
{
|
||||
ObjectConstIterator oi = Objects.find(name);
|
||||
|
||||
if (oi == Objects.end())
|
||||
return ConfigObject::Ptr();
|
||||
|
||||
return oi->second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes the specified callback for each object contained in this collection.
|
||||
*
|
||||
* @param callback The callback.
|
||||
*/
|
||||
void ConfigCollection::ForEachObject(function<int (const EventArgs&)> callback)
|
||||
{
|
||||
EventArgs ea;
|
||||
|
||||
for (ObjectIterator oi = Objects.begin(); oi != Objects.end(); oi++) {
|
||||
ea.Source = oi->second;
|
||||
callback(ea);
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef CONFIGCOLLECTION_H
|
||||
#define CONFIGCOLLECTION_H
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
class ConfigHive;
|
||||
|
||||
/**
|
||||
* A collection of configuration objects that each have the same type.
|
||||
*
|
||||
* @ingroup base
|
||||
*/
|
||||
class I2_BASE_API ConfigCollection : public Object
|
||||
{
|
||||
public:
|
||||
typedef shared_ptr<ConfigCollection> Ptr;
|
||||
typedef weak_ptr<ConfigCollection> WeakPtr;
|
||||
|
||||
typedef map<string, ConfigObject::Ptr>::iterator ObjectIterator;
|
||||
typedef map<string, ConfigObject::Ptr>::const_iterator ObjectConstIterator;
|
||||
map<string, ConfigObject::Ptr> Objects;
|
||||
|
||||
void SetHive(const weak_ptr<ConfigHive>& hive);
|
||||
weak_ptr<ConfigHive> GetHive(void) const;
|
||||
|
||||
void AddObject(const ConfigObject::Ptr& object);
|
||||
void RemoveObject(const ConfigObject::Ptr& object);
|
||||
ConfigObject::Ptr GetObject(const string& name = string()) const;
|
||||
|
||||
void ForEachObject(function<int (const EventArgs&)> callback);
|
||||
|
||||
Observable<EventArgs> OnObjectCommitted;
|
||||
Observable<EventArgs> OnObjectRemoved;
|
||||
|
||||
private:
|
||||
weak_ptr<ConfigHive> m_Hive;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* CONFIGCOLLECTION_H */
|
|
@ -1,93 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "i2-base.h"
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
/**
|
||||
* Adds a new object to this hive.
|
||||
*
|
||||
* @param object The new object.
|
||||
*/
|
||||
void ConfigHive::AddObject(const ConfigObject::Ptr& object)
|
||||
{
|
||||
object->SetHive(static_pointer_cast<ConfigHive>(shared_from_this()));
|
||||
GetCollection(object->GetType())->AddObject(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an object from this hive.
|
||||
*
|
||||
* @param object The object that is to be removed.
|
||||
*/
|
||||
void ConfigHive::RemoveObject(const ConfigObject::Ptr& object)
|
||||
{
|
||||
GetCollection(object->GetType())->RemoveObject(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an object by type and name.
|
||||
*
|
||||
* @param type The type of the object.
|
||||
* @param name The name of the object.
|
||||
* @returns The object or a null pointer if the specified object
|
||||
* could not be found.
|
||||
*/
|
||||
ConfigObject::Ptr ConfigHive::GetObject(const string& type, const string& name)
|
||||
{
|
||||
return GetCollection(type)->GetObject(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a collection by name. Creates an empty collection
|
||||
* if the collection doesn't already exist.
|
||||
*
|
||||
* @param collection The name of the collection.
|
||||
* @returns The collection or a null pointer if the specified collection
|
||||
* could not be found.
|
||||
*/
|
||||
ConfigCollection::Ptr ConfigHive::GetCollection(const string& collection)
|
||||
{
|
||||
CollectionConstIterator ci = Collections.find(collection);
|
||||
|
||||
if (ci == Collections.end()) {
|
||||
Collections[collection] = make_shared<ConfigCollection>();
|
||||
ci = Collections.find(collection);
|
||||
}
|
||||
|
||||
return ci->second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes the specified callback for each object contained in this hive.
|
||||
*
|
||||
* @param type The config object type.
|
||||
* @param callback The callback.
|
||||
*/
|
||||
void ConfigHive::ForEachObject(const string& type,
|
||||
function<int (const EventArgs&)> callback)
|
||||
{
|
||||
CollectionIterator ci = Collections.find(type);
|
||||
|
||||
if (ci == Collections.end())
|
||||
return;
|
||||
|
||||
ci->second->ForEachObject(callback);
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef CONFIGHIVE_H
|
||||
#define CONFIGHIVE_H
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
/**
|
||||
* A collection of all configuration objects that belong to an application.
|
||||
*
|
||||
* @ingroup base
|
||||
*/
|
||||
class I2_BASE_API ConfigHive : public Object
|
||||
{
|
||||
public:
|
||||
typedef shared_ptr<ConfigHive> Ptr;
|
||||
typedef weak_ptr<ConfigHive> WeakPtr;
|
||||
|
||||
typedef map<string, ConfigCollection::Ptr>::iterator CollectionIterator;
|
||||
typedef map<string, ConfigCollection::Ptr>::const_iterator CollectionConstIterator;
|
||||
map<string, ConfigCollection::Ptr> Collections;
|
||||
|
||||
void AddObject(const ConfigObject::Ptr& object);
|
||||
void RemoveObject(const ConfigObject::Ptr& object);
|
||||
ConfigObject::Ptr GetObject(const string& type,
|
||||
const string& name = string());
|
||||
ConfigCollection::Ptr GetCollection(const string& type);
|
||||
|
||||
void ForEachObject(const string& type,
|
||||
function<int (const EventArgs&)> callback);
|
||||
|
||||
Observable<EventArgs> OnObjectCommitted;
|
||||
Observable<EventArgs> OnObjectRemoved;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* CONFIGHIVE_H */
|
|
@ -21,114 +21,157 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
/**
|
||||
* Constructor for the ConfigObject class.
|
||||
*
|
||||
* @param type The type of the object.
|
||||
* @param name The name of the object.
|
||||
*/
|
||||
ConfigObject::ConfigObject(const string& type, const string& name)
|
||||
ConfigObject::ConfigObject(Dictionary::Ptr properties)
|
||||
: m_Properties(properties), m_Tags(make_shared<Dictionary>())
|
||||
{ }
|
||||
|
||||
ConfigObject::ConfigObject(string type, string name)
|
||||
: m_Properties(make_shared<Dictionary>()), m_Tags(make_shared<Dictionary>())
|
||||
{
|
||||
m_Type = type;
|
||||
m_Name = name;
|
||||
m_Replicated = false;
|
||||
SetProperty("__type", type);
|
||||
SetProperty("__name", name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the hive this object belongs to.
|
||||
*
|
||||
* @param hive The hive.
|
||||
*/
|
||||
void ConfigObject::SetHive(const ConfigHive::WeakPtr& hive)
|
||||
void ConfigObject::SetProperties(Dictionary::Ptr properties)
|
||||
{
|
||||
if (m_Hive.lock())
|
||||
throw logic_error("Config object already has a parent hive.");
|
||||
|
||||
m_Hive = hive;
|
||||
m_Properties = properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the hive this object belongs to.
|
||||
*
|
||||
* @returns The hive.
|
||||
*/
|
||||
ConfigHive::WeakPtr ConfigObject::GetHive(void) const
|
||||
Dictionary::Ptr ConfigObject::GetProperties(void) const
|
||||
{
|
||||
return m_Hive;
|
||||
return m_Properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of this object.
|
||||
*
|
||||
* @param name The name.
|
||||
*/
|
||||
void ConfigObject::SetName(const string& name)
|
||||
Dictionary::Ptr ConfigObject::GetTags(void) const
|
||||
{
|
||||
m_Name = name;
|
||||
return m_Tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the name of this object.
|
||||
*
|
||||
* @returns The name.
|
||||
*/
|
||||
string ConfigObject::GetName(void) const
|
||||
{
|
||||
return m_Name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of this object.
|
||||
*
|
||||
* @param type The type.
|
||||
*/
|
||||
void ConfigObject::SetType(const string& type)
|
||||
{
|
||||
m_Type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the type of this object.
|
||||
*
|
||||
* @returns The type.
|
||||
*/
|
||||
string ConfigObject::GetType(void) const
|
||||
{
|
||||
return m_Type;
|
||||
string type;
|
||||
GetProperties()->GetProperty("__type", &type);
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this object was replicated.
|
||||
*
|
||||
* @param replicated Whether this object was replicated.
|
||||
*/
|
||||
void ConfigObject::SetReplicated(bool replicated)
|
||||
string ConfigObject::GetName(void) const
|
||||
{
|
||||
m_Replicated = replicated;
|
||||
string name;
|
||||
GetProperties()->GetProperty("__name", &name);
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves whether this object was replicated.
|
||||
*
|
||||
* @returns Whether this object was replicated.
|
||||
*/
|
||||
bool ConfigObject::IsReplicated(void) const
|
||||
void ConfigObject::SetLocal(bool value)
|
||||
{
|
||||
return m_Replicated;
|
||||
GetProperties()->SetProperty("__local", value ? 1 : 0);
|
||||
}
|
||||
|
||||
bool ConfigObject::IsLocal(void) const
|
||||
{
|
||||
bool value;
|
||||
GetProperties()->GetProperty("__local", &value);
|
||||
return (value != 0);
|
||||
}
|
||||
|
||||
void ConfigObject::SetAbstract(bool value)
|
||||
{
|
||||
GetProperties()->SetProperty("__abstract", value ? 1 : 0);
|
||||
}
|
||||
|
||||
bool ConfigObject::IsAbstract(void) const
|
||||
{
|
||||
long value;
|
||||
GetProperties()->GetProperty("__abstract", &value);
|
||||
return (value != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles changed properties by propagating them to the hive
|
||||
* and collection this object is contained in.
|
||||
*
|
||||
*/
|
||||
void ConfigObject::Commit(void)
|
||||
{
|
||||
ConfigHive::Ptr hive = m_Hive.lock();
|
||||
if (hive) {
|
||||
EventArgs ea;
|
||||
ea.Source = shared_from_this();
|
||||
hive->GetCollection(m_Type)->OnObjectCommitted(ea);
|
||||
hive->OnObjectCommitted(ea);
|
||||
}
|
||||
ConfigObject::Ptr dobj = GetObject(GetType(), GetName());
|
||||
ConfigObject::Ptr self = static_pointer_cast<ConfigObject>(shared_from_this());
|
||||
assert(!dobj || dobj == self);
|
||||
GetAllObjects()->CheckObject(self);
|
||||
}
|
||||
|
||||
void ConfigObject::Unregister(void)
|
||||
{
|
||||
ConfigObject::Ptr self = static_pointer_cast<ConfigObject>(shared_from_this());
|
||||
GetAllObjects()->RemoveObject(self);
|
||||
}
|
||||
|
||||
ObjectSet<ConfigObject::Ptr>::Ptr ConfigObject::GetAllObjects(void)
|
||||
{
|
||||
static ObjectSet<ConfigObject::Ptr>::Ptr allObjects;
|
||||
|
||||
if (!allObjects) {
|
||||
allObjects = make_shared<ObjectSet<ConfigObject::Ptr> >();
|
||||
allObjects->Start();
|
||||
}
|
||||
|
||||
return allObjects;
|
||||
}
|
||||
|
||||
ConfigObject::TNMap::Ptr ConfigObject::GetObjectsByTypeAndName(void)
|
||||
{
|
||||
static ConfigObject::TNMap::Ptr tnmap;
|
||||
|
||||
if (!tnmap) {
|
||||
tnmap = make_shared<ConfigObject::TNMap>(GetAllObjects(), &ConfigObject::TypeAndNameGetter);
|
||||
tnmap->Start();
|
||||
}
|
||||
|
||||
return tnmap;
|
||||
}
|
||||
|
||||
ConfigObject::Ptr ConfigObject::GetObject(string type, string name)
|
||||
{
|
||||
ConfigObject::TNMap::Range range;
|
||||
range = GetObjectsByTypeAndName()->GetRange(make_pair(type, name));
|
||||
|
||||
assert(distance(range.first, range.second) <= 1);
|
||||
|
||||
if (range.first == range.second)
|
||||
return ConfigObject::Ptr();
|
||||
else
|
||||
return range.first->second;
|
||||
}
|
||||
|
||||
bool ConfigObject::TypeAndNameGetter(const ConfigObject::Ptr& object, pair<string, string> *key)
|
||||
{
|
||||
*key = make_pair(object->GetType(), object->GetName());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function<bool (ConfigObject::Ptr)> ConfigObject::MakeTypePredicate(string type)
|
||||
{
|
||||
return bind(&ConfigObject::TypePredicate, _1, type);
|
||||
}
|
||||
|
||||
bool ConfigObject::TypePredicate(const ConfigObject::Ptr& object, string type)
|
||||
{
|
||||
return (object->GetType() == type);
|
||||
}
|
||||
|
||||
ConfigObject::TMap::Ptr ConfigObject::GetObjectsByType(void)
|
||||
{
|
||||
static ObjectMap<string, ConfigObject::Ptr>::Ptr tmap;
|
||||
|
||||
if (!tmap) {
|
||||
tmap = make_shared<ConfigObject::TMap>(GetAllObjects(), &ConfigObject::TypeGetter);
|
||||
tmap->Start();
|
||||
}
|
||||
|
||||
return tmap;
|
||||
}
|
||||
|
||||
bool ConfigObject::TypeGetter(const ConfigObject::Ptr& object, string *key)
|
||||
{
|
||||
*key = object->GetType();
|
||||
return true;
|
||||
}
|
||||
|
||||
ConfigObject::TMap::Range ConfigObject::GetObjects(string type)
|
||||
{
|
||||
return GetObjectsByType()->GetRange(type);
|
||||
}
|
|
@ -20,46 +20,82 @@
|
|||
#ifndef CONFIGOBJECT_H
|
||||
#define CONFIGOBJECT_H
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
class ConfigHive;
|
||||
|
||||
/**
|
||||
* A configuration object that has arbitrary properties.
|
||||
*
|
||||
* @ingroup base
|
||||
*/
|
||||
class I2_BASE_API ConfigObject : public Dictionary
|
||||
class I2_BASE_API ConfigObject : public Object
|
||||
{
|
||||
public:
|
||||
typedef shared_ptr<ConfigObject> Ptr;
|
||||
typedef weak_ptr<ConfigObject> WeakPtr;
|
||||
|
||||
ConfigObject(const string& type, const string& name);
|
||||
typedef ObjectMap<pair<string, string>, ConfigObject::Ptr> TNMap;
|
||||
typedef ObjectMap<string, ConfigObject::Ptr> TMap;
|
||||
typedef ObjectSet<ConfigObject::Ptr> Set;
|
||||
|
||||
void SetHive(const weak_ptr<ConfigHive>& hive);
|
||||
weak_ptr<ConfigHive> GetHive(void) const;
|
||||
ConfigObject(Dictionary::Ptr properties);
|
||||
ConfigObject(string type, string name);
|
||||
|
||||
void SetName(const string& name);
|
||||
void SetProperties(Dictionary::Ptr config);
|
||||
Dictionary::Ptr GetProperties(void) const;
|
||||
|
||||
template<typename T>
|
||||
void SetProperty(const string& key, const T& value)
|
||||
{
|
||||
GetProperties()->SetProperty(key, value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool GetProperty(const string& key, T *value) const
|
||||
{
|
||||
return GetProperties()->GetProperty(key, value);
|
||||
}
|
||||
|
||||
Dictionary::Ptr GetTags(void) const;
|
||||
|
||||
template<typename T>
|
||||
void SetTag(const string& key, const T& value)
|
||||
{
|
||||
GetTags()->SetProperty(key, value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool GetTag(const string& key, T *value) const
|
||||
{
|
||||
return GetTags()->GetProperty(key, value);
|
||||
}
|
||||
|
||||
string GetType(void) const;
|
||||
string GetName(void) const;
|
||||
|
||||
void SetType(const string& type);
|
||||
string GetType(void) const;
|
||||
void SetLocal(bool value);
|
||||
bool IsLocal(void) const;
|
||||
|
||||
void SetReplicated(bool replicated);
|
||||
bool IsReplicated(void) const;
|
||||
void SetAbstract(bool value);
|
||||
bool IsAbstract(void) const;
|
||||
|
||||
void Commit(void);
|
||||
void Unregister(void);
|
||||
|
||||
static ObjectSet<ConfigObject::Ptr>::Ptr GetAllObjects(void);
|
||||
|
||||
static TNMap::Ptr GetObjectsByTypeAndName(void);
|
||||
static TMap::Ptr GetObjectsByType(void);
|
||||
|
||||
static ConfigObject::Ptr GetObject(string type, string name);
|
||||
|
||||
static TMap::Range GetObjects(string type);
|
||||
|
||||
static function<bool (ConfigObject::Ptr)> MakeTypePredicate(string type);
|
||||
|
||||
private:
|
||||
weak_ptr<ConfigHive> m_Hive;
|
||||
Dictionary::Ptr m_Properties;
|
||||
Dictionary::Ptr m_Tags;
|
||||
|
||||
string m_Name;
|
||||
string m_Type;
|
||||
bool m_Replicated;
|
||||
static bool TypeAndNameGetter(const ConfigObject::Ptr& object, pair<string, string> *key);
|
||||
static bool TypePredicate(const ConfigObject::Ptr& object, string type);
|
||||
|
||||
static bool TypeGetter(const ConfigObject::Ptr& object, string *key);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -154,9 +154,9 @@ using namespace std::tr1::placeholders;
|
|||
#include "tcpclient.h"
|
||||
#include "tcpserver.h"
|
||||
#include "tlsclient.h"
|
||||
#include "objectset.h"
|
||||
#include "objectmap.h"
|
||||
#include "configobject.h"
|
||||
#include "configcollection.h"
|
||||
#include "confighive.h"
|
||||
#include "application.h"
|
||||
#include "component.h"
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "i2-dyn.h"
|
||||
#include "i2-base.h"
|
||||
|
||||
using namespace icinga;
|
||||
|
|
@ -24,7 +24,7 @@ namespace icinga
|
|||
{
|
||||
|
||||
template<typename TKey = string, typename TValue = Object::Ptr>
|
||||
class I2_DYN_API ObjectMap : public Object
|
||||
class ObjectMap : public Object
|
||||
{
|
||||
public:
|
||||
typedef shared_ptr<ObjectMap<TKey, TValue> > Ptr;
|
||||
|
@ -56,6 +56,19 @@ public:
|
|||
return m_Objects.equal_range(key);
|
||||
}
|
||||
|
||||
void ForeachObject(TKey key, function<int (const ObjectSetEventArgs<TValue>&)> callback)
|
||||
{
|
||||
ObjectSetEventArgs<TValue> ea;
|
||||
ea.Source = shared_from_this();
|
||||
|
||||
Range range = GetRange(key);
|
||||
|
||||
for (Iterator it = range.first; it != range.second; it++) {
|
||||
ea.Target(*it);
|
||||
callback(ea);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
multimap<TKey, TValue> m_Objects;
|
||||
typename ObjectSet<TValue>::Ptr m_Parent;
|
|
@ -17,7 +17,7 @@
|
|||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "i2-dyn.h"
|
||||
#include "i2-base.h"
|
||||
|
||||
using namespace icinga;
|
||||
|
|
@ -30,7 +30,7 @@ struct ObjectSetEventArgs : public EventArgs
|
|||
};
|
||||
|
||||
template<typename TValue>
|
||||
class I2_DYN_API ObjectSet : public Object
|
||||
class ObjectSet : public Object
|
||||
{
|
||||
public:
|
||||
typedef shared_ptr<ObjectSet<TValue> > Ptr;
|
||||
|
@ -121,6 +121,17 @@ public:
|
|||
return m_Objects.end();
|
||||
}
|
||||
|
||||
void ForeachObject(function<int (const ObjectSetEventArgs<TValue>&)> callback)
|
||||
{
|
||||
ObjectSetEventArgs<TValue> ea;
|
||||
ea.Source = shared_from_this();
|
||||
|
||||
for (Iterator it = Begin(); it != End(); it++) {
|
||||
ea.Target(*it);
|
||||
callback(ea);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
set<TValue> m_Objects;
|
||||
|
|
@ -11,9 +11,7 @@ configfile_la_SOURCES = \
|
|||
configfile_la_CPPFLAGS = \
|
||||
$(BOOST_CPPFLAGS) \
|
||||
-I${top_srcdir}/base \
|
||||
-I${top_srcdir}/icinga \
|
||||
-I${top_srcdir}/jsonrpc \
|
||||
-I${top_srcdir}/third-party/cJSON
|
||||
-I${top_srcdir}/dyn
|
||||
|
||||
configfile_la_LDFLAGS = \
|
||||
$(BOOST_LDFLAGS) \
|
||||
|
@ -24,5 +22,4 @@ configfile_la_LDFLAGS = \
|
|||
|
||||
configfile_la_LIBADD = \
|
||||
$(top_builddir)/base/libbase.la \
|
||||
$(top_builddir)/icinga/libicinga.la \
|
||||
$(top_builddir)/third-party/cJSON/libcJSON.la
|
||||
$(top_builddir)/dyn/libdyn.la
|
||||
|
|
|
@ -45,11 +45,11 @@
|
|||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(SolutionDir)\third-party\cJSON;$(IncludePath)</IncludePath>
|
||||
<IncludePath>$(SolutionDir)\base;$(SolutionDir)\icinga;$(SolutionDir)\dyn;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(SolutionDir)\third-party\cJSON;$(IncludePath)</IncludePath>
|
||||
<IncludePath>$(SolutionDir)\base;$(SolutionDir)\icinga;$(SolutionDir)\dyn;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
|
@ -63,7 +63,7 @@
|
|||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>base.lib;jsonrpc.lib;icinga.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>base.lib;dyn.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<Lib>
|
||||
<AdditionalDependencies>
|
||||
|
@ -86,7 +86,7 @@
|
|||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>base.lib;jsonrpc.lib;icinga.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>base.lib;dyn.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<Lib>
|
||||
<AdditionalDependencies>$(OutDir)\base.lib;$(OutDir)\jsonrpc.lib</AdditionalDependencies>
|
||||
|
|
|
@ -17,10 +17,7 @@
|
|||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "i2-configfile.h"
|
||||
#include "cJSON.h"
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
|
@ -38,66 +35,13 @@ void ConfigFileComponent::Start(void)
|
|||
if (!GetConfig()->GetProperty("configFilename", &filename))
|
||||
throw logic_error("Missing 'configFilename' property");
|
||||
|
||||
fp.open(filename.c_str(), ifstream::in);
|
||||
if (fp.fail())
|
||||
throw runtime_error("Could not open config file");
|
||||
Application::Log("Compiling config file: " + filename);
|
||||
|
||||
GetIcingaApplication()->Log("Reading config file: " + filename);
|
||||
vector<ConfigItem::Ptr> configItems = ConfigCompiler::CompileFile(filename);
|
||||
|
||||
while (!fp.eof()) {
|
||||
size_t bufferSize = 1024;
|
||||
char *buffer = (char *)fifo->GetWriteBuffer(&bufferSize);
|
||||
fp.read(buffer, bufferSize);
|
||||
if (fp.bad())
|
||||
throw runtime_error("Could not read from config file");
|
||||
fifo->Write(NULL, fp.gcount());
|
||||
}
|
||||
Application::Log("Executing config items...");
|
||||
|
||||
fp.close();
|
||||
|
||||
fifo->Write("\0", 1);
|
||||
|
||||
/* TODO: implement config parsing, for now we just use JSON */
|
||||
cJSON *jsonobj = cJSON_Parse((const char *)fifo->GetReadBuffer());
|
||||
fifo->Read(NULL, fifo->GetSize());
|
||||
|
||||
if (jsonobj == NULL)
|
||||
throw ConfigParserException("Could not parse config file.");
|
||||
|
||||
for (cJSON *typeobj = jsonobj->child; typeobj != NULL; typeobj = typeobj->next) {
|
||||
string type = typeobj->string;
|
||||
|
||||
for (cJSON *object = typeobj->child; object != NULL; object = object->next) {
|
||||
string name = object->string;
|
||||
|
||||
ConfigObject::Ptr cfgobj = make_shared<ConfigObject>(type, name);
|
||||
|
||||
for (cJSON *property = object->child; property != NULL; property = property->next) {
|
||||
string key = property->string;
|
||||
|
||||
if (property->type == cJSON_String) {
|
||||
string value = property->valuestring;
|
||||
|
||||
cfgobj->SetProperty(key, value);
|
||||
} else if (property->type == cJSON_Array) {
|
||||
Dictionary::Ptr items = make_shared<Dictionary>();
|
||||
|
||||
for (cJSON *item = property->child; item != NULL; item = item->next) {
|
||||
if (item->type != cJSON_String)
|
||||
continue;
|
||||
|
||||
items->AddUnnamedProperty(item->valuestring);
|
||||
}
|
||||
|
||||
cfgobj->SetProperty(key, items);
|
||||
}
|
||||
}
|
||||
|
||||
GetConfigHive()->AddObject(cfgobj);
|
||||
}
|
||||
}
|
||||
|
||||
cJSON_Delete(jsonobj);
|
||||
ConfigVM::ExecuteItems(configItems);
|
||||
}
|
||||
|
||||
void ConfigFileComponent::Stop(void)
|
||||
|
|
|
@ -33,7 +33,7 @@ DEFINE_EXCEPTION_CLASS(ConfigParserException);
|
|||
/**
|
||||
* @ingroup configfile
|
||||
*/
|
||||
class ConfigFileComponent : public IcingaComponent
|
||||
class ConfigFileComponent : public Component
|
||||
{
|
||||
public:
|
||||
typedef shared_ptr<ConfigFileComponent> Ptr;
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*/
|
||||
|
||||
#include <i2-base.h>
|
||||
#include <i2-icinga.h>
|
||||
#include <i2-dyn.h>
|
||||
|
||||
#include "configfilecomponent.h"
|
||||
|
||||
|
|
|
@ -46,12 +46,12 @@
|
|||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(IncludePath)</IncludePath>
|
||||
<IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(SolutionDir)\dyn;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(IncludePath)</IncludePath>
|
||||
<IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(SolutionDir)\dyn;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
|
|
|
@ -29,7 +29,6 @@ string ConfigRpcComponent::GetName(void) const
|
|||
void ConfigRpcComponent::Start(void)
|
||||
{
|
||||
EndpointManager::Ptr endpointManager = GetEndpointManager();
|
||||
ConfigHive::Ptr configHive = GetConfigHive();
|
||||
|
||||
m_ConfigRpcEndpoint = make_shared<VirtualEndpoint>();
|
||||
|
||||
|
@ -38,8 +37,9 @@ void ConfigRpcComponent::Start(void)
|
|||
m_ConfigRpcEndpoint->RegisterTopicHandler("config::FetchObjects",
|
||||
bind_weak(&ConfigRpcComponent::FetchObjectsHandler, shared_from_this()));
|
||||
|
||||
configHive->OnObjectCommitted += bind_weak(&ConfigRpcComponent::LocalObjectCommittedHandler, shared_from_this());
|
||||
configHive->OnObjectRemoved += bind_weak(&ConfigRpcComponent::LocalObjectRemovedHandler, shared_from_this());
|
||||
ConfigObject::GetAllObjects()->OnObjectAdded += bind_weak(&ConfigRpcComponent::LocalObjectCommittedHandler, shared_from_this());
|
||||
ConfigObject::GetAllObjects()->OnObjectCommitted += bind_weak(&ConfigRpcComponent::LocalObjectCommittedHandler, shared_from_this());
|
||||
ConfigObject::GetAllObjects()->OnObjectRemoved += bind_weak(&ConfigRpcComponent::LocalObjectRemovedHandler, shared_from_this());
|
||||
|
||||
m_ConfigRpcEndpoint->RegisterPublication("config::ObjectCommitted");
|
||||
m_ConfigRpcEndpoint->RegisterPublication("config::ObjectRemoved");
|
||||
|
@ -110,13 +110,10 @@ bool ConfigRpcComponent::ShouldReplicateObject(const ConfigObject::Ptr& object)
|
|||
int ConfigRpcComponent::FetchObjectsHandler(const NewRequestEventArgs& ea)
|
||||
{
|
||||
Endpoint::Ptr client = ea.Sender;
|
||||
ConfigHive::Ptr configHive = GetConfigHive();
|
||||
ConfigObject::Set::Ptr allObjects = ConfigObject::GetAllObjects();
|
||||
|
||||
for (ConfigHive::CollectionIterator ci = configHive->Collections.begin(); ci != configHive->Collections.end(); ci++) {
|
||||
ConfigCollection::Ptr collection = ci->second;
|
||||
|
||||
for (ConfigCollection::ObjectIterator oi = collection->Objects.begin(); oi != collection->Objects.end(); oi++) {
|
||||
ConfigObject::Ptr object = oi->second;
|
||||
for (ConfigObject::Set::Iterator ci = allObjects->Begin(); ci != allObjects->End(); ci++) {
|
||||
ConfigObject::Ptr object = *ci;
|
||||
|
||||
if (!ShouldReplicateObject(object))
|
||||
continue;
|
||||
|
@ -125,12 +122,11 @@ int ConfigRpcComponent::FetchObjectsHandler(const NewRequestEventArgs& ea)
|
|||
|
||||
GetEndpointManager()->SendUnicastMessage(m_ConfigRpcEndpoint, client, request);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ConfigRpcComponent::LocalObjectCommittedHandler(const EventArgs& ea)
|
||||
int ConfigRpcComponent::LocalObjectCommittedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
|
||||
{
|
||||
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
||||
|
||||
|
@ -143,7 +139,7 @@ int ConfigRpcComponent::LocalObjectCommittedHandler(const EventArgs& ea)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int ConfigRpcComponent::LocalObjectRemovedHandler(const EventArgs& ea)
|
||||
int ConfigRpcComponent::LocalObjectRemovedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
|
||||
{
|
||||
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
||||
|
||||
|
@ -159,7 +155,6 @@ int ConfigRpcComponent::LocalObjectRemovedHandler(const EventArgs& ea)
|
|||
int ConfigRpcComponent::RemoteObjectCommittedHandler(const NewRequestEventArgs& ea)
|
||||
{
|
||||
RequestMessage message = ea.Request;
|
||||
bool was_null = false;
|
||||
|
||||
MessagePart params;
|
||||
if (!message.GetParams(¶ms))
|
||||
|
@ -173,26 +168,18 @@ int ConfigRpcComponent::RemoteObjectCommittedHandler(const NewRequestEventArgs&
|
|||
if (!params.GetProperty("type", &type))
|
||||
return 0;
|
||||
|
||||
ConfigHive::Ptr configHive = GetConfigHive();
|
||||
ConfigObject::Ptr object = configHive->GetObject(type, name);
|
||||
|
||||
if (!object) {
|
||||
was_null = true;
|
||||
object = make_shared<ConfigObject>(type, name);
|
||||
}
|
||||
|
||||
MessagePart properties;
|
||||
if (!params.GetProperty("properties", &properties))
|
||||
return 0;
|
||||
|
||||
for (DictionaryIterator i = properties.Begin(); i != properties.End(); i++) {
|
||||
object->SetProperty(i->first, i->second);
|
||||
}
|
||||
ConfigObject::Ptr object = ConfigObject::GetObject(type, name);
|
||||
|
||||
if (was_null) {
|
||||
object->SetReplicated(true);
|
||||
configHive->AddObject(object);
|
||||
}
|
||||
if (!object)
|
||||
object = make_shared<ConfigObject>(properties.GetDictionary());
|
||||
else
|
||||
object->SetProperties(properties.GetDictionary());
|
||||
|
||||
object->Commit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -213,14 +200,13 @@ int ConfigRpcComponent::RemoteObjectRemovedHandler(const NewRequestEventArgs& ea
|
|||
if (!params.GetProperty("type", &type))
|
||||
return 0;
|
||||
|
||||
ConfigHive::Ptr configHive = GetConfigHive();
|
||||
ConfigObject::Ptr object = configHive->GetObject(type, name);
|
||||
ConfigObject::Ptr object = ConfigObject::GetObject(type, name);
|
||||
|
||||
if (!object)
|
||||
return 0;
|
||||
|
||||
if (object->IsReplicated())
|
||||
configHive->RemoveObject(object);
|
||||
if (!object->IsLocal())
|
||||
object->Unregister();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -28,14 +28,19 @@ namespace icinga
|
|||
*/
|
||||
class ConfigRpcComponent : public IcingaComponent
|
||||
{
|
||||
public:
|
||||
virtual string GetName(void) const;
|
||||
virtual void Start(void);
|
||||
virtual void Stop(void);
|
||||
|
||||
private:
|
||||
VirtualEndpoint::Ptr m_ConfigRpcEndpoint;
|
||||
|
||||
int NewEndpointHandler(const NewEndpointEventArgs& ea);
|
||||
int SessionEstablishedHandler(const EventArgs& ea);
|
||||
|
||||
int LocalObjectCommittedHandler(const EventArgs& ea);
|
||||
int LocalObjectRemovedHandler(const EventArgs& ea);
|
||||
int LocalObjectCommittedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
||||
int LocalObjectRemovedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
||||
|
||||
int FetchObjectsHandler(const NewRequestEventArgs& ea);
|
||||
int RemoteObjectCommittedHandler(const NewRequestEventArgs& ea);
|
||||
|
@ -45,10 +50,6 @@ private:
|
|||
string method, bool includeProperties);
|
||||
|
||||
static bool ShouldReplicateObject(const ConfigObject::Ptr& object);
|
||||
public:
|
||||
virtual string GetName(void) const;
|
||||
virtual void Start(void);
|
||||
virtual void Stop(void);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>base.lib;jsonrpc.lib;icinga.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>base.lib;jsonrpc.lib;icinga.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
|
@ -76,7 +76,7 @@
|
|||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>base.lib;jsonrpc.lib;icinga.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>base.lib;jsonrpc.lib;icinga.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -348,14 +348,10 @@ bool DiscoveryComponent::HasMessagePermission(Dictionary::Ptr roles, string mess
|
|||
if (!roles)
|
||||
return false;
|
||||
|
||||
ConfigHive::Ptr configHive = GetConfigHive();
|
||||
ConfigCollection::Ptr roleCollection = configHive->GetCollection("role");
|
||||
ConfigObject::TMap::Range range = ConfigObject::GetObjects("role");
|
||||
|
||||
for (DictionaryIterator ip = roles->Begin(); ip != roles->End(); ip++) {
|
||||
ConfigObject::Ptr role = roleCollection->GetObject(ip->second);
|
||||
|
||||
if (!role)
|
||||
continue;
|
||||
for (ConfigObject::TMap::Iterator ip = range.first; ip != range.second; ip++) {
|
||||
ConfigObject::Ptr role = ip->second;
|
||||
|
||||
Object::Ptr object;
|
||||
if (!role->GetProperty(messageType, &object))
|
||||
|
@ -395,10 +391,7 @@ void DiscoveryComponent::ProcessDiscoveryMessage(string identity, DiscoveryMessa
|
|||
message.GetNode(&info->Node);
|
||||
message.GetService(&info->Service);
|
||||
|
||||
ConfigHive::Ptr configHive = GetConfigHive();
|
||||
ConfigCollection::Ptr endpointCollection = configHive->GetCollection("endpoint");
|
||||
|
||||
ConfigObject::Ptr endpointConfig = endpointCollection->GetObject(identity);
|
||||
ConfigObject::Ptr endpointConfig = ConfigObject::GetObject("endpoint", identity);
|
||||
Dictionary::Ptr roles;
|
||||
if (endpointConfig) {
|
||||
Object::Ptr object;
|
||||
|
@ -485,31 +478,6 @@ int DiscoveryComponent::RegisterComponentMessageHandler(const NewRequestEventArg
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes "endpoint" config objects.
|
||||
*
|
||||
* @param ea Event arguments for the new config object.
|
||||
* @returns 0
|
||||
*/
|
||||
int DiscoveryComponent::EndpointConfigHandler(const EventArgs& ea)
|
||||
{
|
||||
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
||||
|
||||
EndpointManager::Ptr endpointManager = GetEndpointManager();
|
||||
|
||||
/* Check if we're already connected to this endpoint. */
|
||||
if (endpointManager->GetEndpointByIdentity(object->GetName()))
|
||||
return 0;
|
||||
|
||||
string node, service;
|
||||
if (object->GetProperty("node", &node) && object->GetProperty("service", &service)) {
|
||||
/* reconnect to this endpoint */
|
||||
endpointManager->AddConnection(node, service);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether we have to reconnect to other components and removes stale
|
||||
* components from the registry.
|
||||
|
@ -525,8 +493,21 @@ int DiscoveryComponent::DiscoveryTimerHandler(const TimerEventArgs& tea)
|
|||
time(&now);
|
||||
|
||||
/* check whether we have to reconnect to one of our upstream endpoints */
|
||||
ConfigCollection::Ptr endpointCollection = GetConfigHive()->GetCollection("endpoint");
|
||||
endpointCollection->ForEachObject(bind(&DiscoveryComponent::EndpointConfigHandler, this, _1));
|
||||
ConfigObject::TMap::Range range = ConfigObject::GetObjects("endpoint");
|
||||
|
||||
for (ConfigObject::TMap::Iterator it = range.first; it != range.second; it++) {
|
||||
ConfigObject::Ptr object = it->second;
|
||||
|
||||
/* Check if we're already connected to this endpoint. */
|
||||
if (endpointManager->GetEndpointByIdentity(object->GetName()))
|
||||
continue;
|
||||
|
||||
string node, service;
|
||||
if (object->GetProperty("node", &node) && object->GetProperty("service", &service)) {
|
||||
/* reconnect to this endpoint */
|
||||
endpointManager->AddConnection(node, service);
|
||||
}
|
||||
}
|
||||
|
||||
map<string, ComponentDiscoveryInfo::Ptr>::iterator curr, i;
|
||||
for (i = m_Components.begin(); i != m_Components.end(); ) {
|
||||
|
|
|
@ -76,8 +76,6 @@ private:
|
|||
|
||||
void FinishDiscoverySetup(Endpoint::Ptr endpoint);
|
||||
|
||||
int EndpointConfigHandler(const EventArgs& ea);
|
||||
|
||||
bool HasMessagePermission(Dictionary::Ptr roles, string messageType, string message);
|
||||
|
||||
static const int RegistrationTTL = 300;
|
||||
|
|
|
@ -21,13 +21,7 @@ libdyn_la_SOURCES = \
|
|||
expression.cpp \
|
||||
expression.h \
|
||||
expressionlist.cpp \
|
||||
expressionlist.h \
|
||||
dynamicobject.cpp \
|
||||
dynamicobject.h \
|
||||
objectset.cpp \
|
||||
objectset.h \
|
||||
objectmap.cpp \
|
||||
objectmap.h
|
||||
expressionlist.h
|
||||
|
||||
libdyn_la_CPPFLAGS = \
|
||||
-DI2_DYN_BUILD \
|
||||
|
|
|
@ -107,26 +107,27 @@ ConfigItem::TNMap::Ptr ConfigItem::GetObjectsByTypeAndName(void)
|
|||
|
||||
void ConfigItem::Commit(void)
|
||||
{
|
||||
DynamicObject::Ptr dobj = m_DynamicObject.lock();
|
||||
|
||||
if (!dobj) {
|
||||
dobj = DynamicObject::GetObject(GetType(), GetName());
|
||||
|
||||
if (!dobj)
|
||||
dobj = make_shared<DynamicObject>();
|
||||
|
||||
m_DynamicObject = dobj;
|
||||
}
|
||||
ConfigObject::Ptr dobj = m_ConfigObject.lock();
|
||||
|
||||
Dictionary::Ptr properties = make_shared<Dictionary>();
|
||||
CalculateProperties(properties);
|
||||
dobj->SetConfig(properties);
|
||||
|
||||
if (!dobj)
|
||||
dobj = ConfigObject::GetObject(GetType(), GetName());
|
||||
|
||||
if (!dobj)
|
||||
dobj = make_shared<ConfigObject>(properties);
|
||||
else
|
||||
dobj->SetProperties(properties);
|
||||
|
||||
m_ConfigObject = dobj;
|
||||
|
||||
dobj->Commit();
|
||||
|
||||
ConfigItem::Ptr ci = GetObject(GetType(), GetName());
|
||||
ConfigItem::Ptr self = static_pointer_cast<ConfigItem>(shared_from_this());
|
||||
if (ci && ci != self) {
|
||||
ci->m_DynamicObject.reset();
|
||||
ci->m_ConfigObject.reset();
|
||||
GetAllObjects()->RemoveObject(ci);
|
||||
}
|
||||
GetAllObjects()->CheckObject(self);
|
||||
|
@ -134,7 +135,7 @@ void ConfigItem::Commit(void)
|
|||
|
||||
void ConfigItem::Unregister(void)
|
||||
{
|
||||
// TODO: unregister associated DynamicObject
|
||||
// TODO: unregister associated ConfigObject
|
||||
|
||||
ConfigItem::Ptr self = static_pointer_cast<ConfigItem>(shared_from_this());
|
||||
GetAllObjects()->RemoveObject(self);
|
||||
|
|
|
@ -57,7 +57,7 @@ private:
|
|||
vector<string> m_Parents;
|
||||
ExpressionList::Ptr m_ExpressionList;
|
||||
|
||||
DynamicObject::WeakPtr m_DynamicObject;
|
||||
ConfigObject::WeakPtr m_ConfigObject;
|
||||
|
||||
static bool GetTypeAndName(const ConfigItem::Ptr& object, pair<string, string> *key);
|
||||
};
|
||||
|
|
|
@ -16,12 +16,9 @@
|
|||
<ClInclude Include="configvm.h" />
|
||||
<ClInclude Include="config_parser.h" />
|
||||
<ClInclude Include="debuginfo.h" />
|
||||
<ClInclude Include="dynamicobject.h" />
|
||||
<ClInclude Include="expression.h" />
|
||||
<ClInclude Include="expressionlist.h" />
|
||||
<ClInclude Include="i2-dyn.h" />
|
||||
<ClInclude Include="objectmap.h" />
|
||||
<ClInclude Include="objectset.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="configcompiler.cpp" />
|
||||
|
@ -29,11 +26,8 @@
|
|||
<ClCompile Include="configvm.cpp" />
|
||||
<ClCompile Include="config_lexer.cc" />
|
||||
<ClCompile Include="config_parser.cc" />
|
||||
<ClCompile Include="dynamicobject.cpp" />
|
||||
<ClCompile Include="expression.cpp" />
|
||||
<ClCompile Include="expressionlist.cpp" />
|
||||
<ClCompile Include="objectmap.cpp" />
|
||||
<ClCompile Include="objectset.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="config_lexer.ll">
|
||||
|
|
|
@ -1,118 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "i2-dyn.h"
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
DynamicObject::DynamicObject(void)
|
||||
: m_Config(make_shared<Dictionary>()), m_Tags(make_shared<Dictionary>())
|
||||
{
|
||||
}
|
||||
|
||||
void DynamicObject::SetConfig(Dictionary::Ptr config)
|
||||
{
|
||||
m_Config = config;
|
||||
}
|
||||
|
||||
Dictionary::Ptr DynamicObject::GetConfig(void) const
|
||||
{
|
||||
return m_Config;
|
||||
}
|
||||
|
||||
Dictionary::Ptr DynamicObject::GetTags(void)
|
||||
{
|
||||
if (!m_Tags)
|
||||
m_Tags = make_shared<Dictionary>();
|
||||
|
||||
return m_Tags;
|
||||
}
|
||||
|
||||
string DynamicObject::GetType(void) const
|
||||
{
|
||||
string type;
|
||||
GetConfig()->GetProperty("__type", &type);
|
||||
return type;
|
||||
}
|
||||
|
||||
string DynamicObject::GetName(void) const
|
||||
{
|
||||
string name;
|
||||
GetConfig()->GetProperty("__name", &name);
|
||||
return name;
|
||||
}
|
||||
|
||||
void DynamicObject::Commit(void)
|
||||
{
|
||||
DynamicObject::Ptr dobj = GetObject(GetType(), GetName());
|
||||
DynamicObject::Ptr self = static_pointer_cast<DynamicObject>(shared_from_this());
|
||||
assert(!dobj || dobj == self);
|
||||
GetAllObjects()->CheckObject(self);
|
||||
}
|
||||
|
||||
void DynamicObject::Unregister(void)
|
||||
{
|
||||
DynamicObject::Ptr self = static_pointer_cast<DynamicObject>(shared_from_this());
|
||||
GetAllObjects()->RemoveObject(self);
|
||||
}
|
||||
|
||||
ObjectSet<DynamicObject::Ptr>::Ptr DynamicObject::GetAllObjects(void)
|
||||
{
|
||||
static ObjectSet<DynamicObject::Ptr>::Ptr allObjects;
|
||||
|
||||
if (!allObjects) {
|
||||
allObjects = make_shared<ObjectSet<DynamicObject::Ptr> >();
|
||||
allObjects->Start();
|
||||
}
|
||||
|
||||
return allObjects;
|
||||
}
|
||||
|
||||
DynamicObject::TNMap::Ptr DynamicObject::GetObjectsByTypeAndName(void)
|
||||
{
|
||||
static DynamicObject::TNMap::Ptr tnmap;
|
||||
|
||||
if (!tnmap) {
|
||||
tnmap = make_shared<DynamicObject::TNMap>(GetAllObjects(), &DynamicObject::GetTypeAndName);
|
||||
tnmap->Start();
|
||||
}
|
||||
|
||||
return tnmap;
|
||||
}
|
||||
|
||||
DynamicObject::Ptr DynamicObject::GetObject(string type, string name)
|
||||
{
|
||||
DynamicObject::TNMap::Range range;
|
||||
range = GetObjectsByTypeAndName()->GetRange(make_pair(type, name));
|
||||
|
||||
assert(distance(range.first, range.second) <= 1);
|
||||
|
||||
if (range.first == range.second)
|
||||
return DynamicObject::Ptr();
|
||||
else
|
||||
return range.first->second;
|
||||
}
|
||||
|
||||
bool DynamicObject::GetTypeAndName(const DynamicObject::Ptr& object, pair<string, string> *key)
|
||||
{
|
||||
*key = make_pair(object->GetType(), object->GetName());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef DYNAMICOBJECT_H
|
||||
#define DYNAMICOBJECT_H
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
class I2_DYN_API DynamicObject : public Object
|
||||
{
|
||||
public:
|
||||
typedef shared_ptr<DynamicObject> Ptr;
|
||||
typedef weak_ptr<DynamicObject> WeakPtr;
|
||||
|
||||
typedef ObjectMap<pair<string, string>, DynamicObject::Ptr> TNMap;
|
||||
|
||||
DynamicObject(void);
|
||||
|
||||
void SetConfig(Dictionary::Ptr config);
|
||||
Dictionary::Ptr GetConfig(void) const;
|
||||
|
||||
Dictionary::Ptr GetTags(void);
|
||||
|
||||
string GetType(void) const;
|
||||
string GetName(void) const;
|
||||
|
||||
void Commit(void);
|
||||
void Unregister(void);
|
||||
|
||||
static ObjectSet<DynamicObject::Ptr>::Ptr GetAllObjects(void);
|
||||
static TNMap::Ptr GetObjectsByTypeAndName(void);
|
||||
static DynamicObject::Ptr GetObject(string type, string name);
|
||||
|
||||
private:
|
||||
Dictionary::Ptr m_Config;
|
||||
Dictionary::Ptr m_Tags;
|
||||
|
||||
static bool GetTypeAndName(const DynamicObject::Ptr& object, pair<string, string> *key);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* DYNAMICOBJECT_H */
|
|
@ -41,9 +41,6 @@
|
|||
#include "debuginfo.h"
|
||||
#include "expression.h"
|
||||
#include "expressionlist.h"
|
||||
#include "objectset.h"
|
||||
#include "objectmap.h"
|
||||
#include "dynamicobject.h"
|
||||
#include "configitem.h"
|
||||
#include "configcompiler.h"
|
||||
#include "configvm.h"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <i2-dyn.h>
|
||||
#include <i2-jsonrpc.h>
|
||||
//#include <i2-jsonrpc.h>
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
|
|
|
@ -52,25 +52,32 @@ int IcingaApplication::Main(const vector<string>& args)
|
|||
string componentDirectory = GetExeDirectory() + "/../lib/icinga2";
|
||||
AddComponentSearchDir(componentDirectory);
|
||||
|
||||
/* register handler for 'icinga' config objects */
|
||||
ConfigCollection::Ptr icingaCollection = GetConfigHive()->GetCollection("icinga");
|
||||
function<int (const EventArgs&)> NewIcingaConfigHandler = bind_weak(&IcingaApplication::NewIcingaConfigHandler, shared_from_this());
|
||||
icingaCollection->OnObjectCommitted += NewIcingaConfigHandler;
|
||||
icingaCollection->ForEachObject(NewIcingaConfigHandler);
|
||||
icingaCollection->OnObjectRemoved += bind_weak(&IcingaApplication::DeletedIcingaConfigHandler, shared_from_this());
|
||||
ConfigObject::Ptr icingaConfig = ConfigObject::GetObject("application", "icinga");
|
||||
|
||||
if (!icingaConfig)
|
||||
throw runtime_error("Configuration must contain an 'application' object named 'icinga'.");
|
||||
|
||||
if (!icingaConfig->IsLocal())
|
||||
throw runtime_error("'icinga' application object must be 'local'.");
|
||||
|
||||
icingaConfig->GetProperty("privkey", &m_PrivateKeyFile);
|
||||
icingaConfig->GetProperty("pubkey", &m_PublicKeyFile);
|
||||
icingaConfig->GetProperty("cakey", &m_CAKeyFile);
|
||||
icingaConfig->GetProperty("node", &m_Node);
|
||||
icingaConfig->GetProperty("service", &m_Service);
|
||||
|
||||
/* register handler for 'component' config objects */
|
||||
ConfigCollection::Ptr componentCollection = GetConfigHive()->GetCollection("component");
|
||||
function<int (const EventArgs&)> NewComponentHandler = bind_weak(&IcingaApplication::NewComponentHandler, shared_from_this());
|
||||
componentCollection->OnObjectCommitted += NewComponentHandler;
|
||||
componentCollection->ForEachObject(NewComponentHandler);
|
||||
componentCollection->OnObjectRemoved += bind_weak(&IcingaApplication::DeletedComponentHandler, shared_from_this());
|
||||
static ConfigObject::Set::Ptr componentObjects = make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("component"));
|
||||
function<int (const ObjectSetEventArgs<ConfigObject::Ptr>&)> NewComponentHandler = bind_weak(&IcingaApplication::NewComponentHandler, shared_from_this());
|
||||
componentObjects->OnObjectAdded += NewComponentHandler;
|
||||
componentObjects->OnObjectCommitted += NewComponentHandler;
|
||||
componentObjects->OnObjectRemoved += bind_weak(&IcingaApplication::DeletedComponentHandler, shared_from_this());
|
||||
componentObjects->Start();
|
||||
|
||||
/* load config file */
|
||||
ConfigObject::Ptr fileComponentConfig = make_shared<ConfigObject>("component", "configfile");
|
||||
fileComponentConfig->SetProperty("configFilename", args[1]);
|
||||
fileComponentConfig->SetProperty("replicate", 0);
|
||||
GetConfigHive()->AddObject(fileComponentConfig);
|
||||
fileComponentConfig->GetProperties()->SetProperty("configFilename", args[1]);
|
||||
fileComponentConfig->Commit();
|
||||
|
||||
if (!GetPrivateKeyFile().empty() && !GetPublicKeyFile().empty() && !GetCAKeyFile().empty()) {
|
||||
/* set up SSL context */
|
||||
|
@ -103,12 +110,12 @@ EndpointManager::Ptr IcingaApplication::GetEndpointManager(void)
|
|||
return m_EndpointManager;
|
||||
}
|
||||
|
||||
int IcingaApplication::NewComponentHandler(const EventArgs& ea)
|
||||
int IcingaApplication::NewComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
|
||||
{
|
||||
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
||||
ConfigObject::Ptr object = ea.Target;
|
||||
|
||||
/* don't allow replicated config objects */
|
||||
if (object->IsReplicated())
|
||||
if (!object->IsLocal())
|
||||
return 0;
|
||||
|
||||
string path;
|
||||
|
@ -125,9 +132,9 @@ int IcingaApplication::NewComponentHandler(const EventArgs& ea)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int IcingaApplication::DeletedComponentHandler(const EventArgs& ea)
|
||||
int IcingaApplication::DeletedComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
|
||||
{
|
||||
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
||||
ConfigObject::Ptr object = ea.Target;
|
||||
|
||||
Component::Ptr component = GetComponent(object->GetName());
|
||||
UnregisterComponent(component);
|
||||
|
@ -135,87 +142,26 @@ int IcingaApplication::DeletedComponentHandler(const EventArgs& ea)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int IcingaApplication::NewIcingaConfigHandler(const EventArgs& ea)
|
||||
{
|
||||
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
||||
|
||||
/* don't allow replicated config objects */
|
||||
if (object->IsReplicated())
|
||||
return 0;
|
||||
|
||||
string privkey;
|
||||
if (object->GetProperty("privkey", &privkey))
|
||||
SetPrivateKeyFile(privkey);
|
||||
|
||||
string pubkey;
|
||||
if (object->GetProperty("pubkey", &pubkey))
|
||||
SetPublicKeyFile(pubkey);
|
||||
|
||||
string cakey;
|
||||
if (object->GetProperty("cakey", &cakey))
|
||||
SetCAKeyFile(cakey);
|
||||
|
||||
string node;
|
||||
if (object->GetProperty("node", &node))
|
||||
SetNode(node);
|
||||
|
||||
string service;
|
||||
if (object->GetProperty("service", &service))
|
||||
SetService(service);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IcingaApplication::DeletedIcingaConfigHandler(const EventArgs&)
|
||||
{
|
||||
throw runtime_error("Unsupported operation.");
|
||||
}
|
||||
|
||||
void IcingaApplication::SetPrivateKeyFile(string privkey)
|
||||
{
|
||||
m_PrivateKeyFile = privkey;
|
||||
}
|
||||
|
||||
string IcingaApplication::GetPrivateKeyFile(void) const
|
||||
{
|
||||
return m_PrivateKeyFile;
|
||||
}
|
||||
|
||||
void IcingaApplication::SetPublicKeyFile(string pubkey)
|
||||
{
|
||||
m_PublicKeyFile = pubkey;
|
||||
}
|
||||
|
||||
string IcingaApplication::GetPublicKeyFile(void) const
|
||||
{
|
||||
return m_PublicKeyFile;
|
||||
}
|
||||
|
||||
void IcingaApplication::SetCAKeyFile(string cakey)
|
||||
{
|
||||
m_CAKeyFile = cakey;
|
||||
}
|
||||
|
||||
string IcingaApplication::GetCAKeyFile(void) const
|
||||
{
|
||||
return m_CAKeyFile;
|
||||
}
|
||||
|
||||
void IcingaApplication::SetNode(string node)
|
||||
{
|
||||
m_Node = node;
|
||||
}
|
||||
|
||||
string IcingaApplication::GetNode(void) const
|
||||
{
|
||||
return m_Node;
|
||||
}
|
||||
|
||||
void IcingaApplication::SetService(string service)
|
||||
{
|
||||
m_Service = service;
|
||||
}
|
||||
|
||||
string IcingaApplication::GetService(void) const
|
||||
{
|
||||
return m_Service;
|
||||
|
|
|
@ -38,19 +38,10 @@ public:
|
|||
|
||||
EndpointManager::Ptr GetEndpointManager(void);
|
||||
|
||||
void SetPrivateKeyFile(string privkey);
|
||||
string GetPrivateKeyFile(void) const;
|
||||
|
||||
void SetPublicKeyFile(string pubkey);
|
||||
string GetPublicKeyFile(void) const;
|
||||
|
||||
void SetCAKeyFile(string cakey);
|
||||
string GetCAKeyFile(void) const;
|
||||
|
||||
void SetNode(string node);
|
||||
string GetNode(void) const;
|
||||
|
||||
void SetService(string service);
|
||||
string GetService(void) const;
|
||||
|
||||
private:
|
||||
|
@ -62,11 +53,8 @@ private:
|
|||
string m_Node;
|
||||
string m_Service;
|
||||
|
||||
int NewComponentHandler(const EventArgs& ea);
|
||||
int DeletedComponentHandler(const EventArgs& ea);
|
||||
|
||||
int NewIcingaConfigHandler(const EventArgs& ea);
|
||||
int DeletedIcingaConfigHandler(const EventArgs& ea);
|
||||
int NewComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
||||
int DeletedComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
||||
|
||||
int NewRpcListenerHandler(const EventArgs& ea);
|
||||
int DeletedRpcListenerHandler(const EventArgs& ea);
|
||||
|
|
|
@ -36,13 +36,3 @@ EndpointManager::Ptr IcingaComponent::GetEndpointManager(void) const
|
|||
|
||||
return app->GetEndpointManager();
|
||||
}
|
||||
|
||||
ConfigHive::Ptr IcingaComponent::GetConfigHive(void) const
|
||||
{
|
||||
IcingaApplication::Ptr app = GetIcingaApplication();
|
||||
|
||||
if (!app)
|
||||
return ConfigHive::Ptr();
|
||||
|
||||
return app->GetConfigHive();
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ class I2_ICINGA_API IcingaComponent : public Component
|
|||
protected:
|
||||
IcingaApplication::Ptr GetIcingaApplication(void) const;
|
||||
EndpointManager::Ptr GetEndpointManager(void) const;
|
||||
ConfigHive::Ptr GetConfigHive(void) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue