mirror of https://github.com/Icinga/icinga2.git
ido: Implement servicegroup members.
This commit is contained in:
parent
e73f34ad02
commit
5d09af0a6e
|
@ -33,6 +33,7 @@ static boost::mutex l_Mutex;
|
|||
static std::map<String, std::vector<Service::WeakPtr> > l_MembersCache;
|
||||
static bool l_MembersCacheNeedsUpdate = false;
|
||||
static Timer::Ptr l_MembersCacheTimer;
|
||||
boost::signals2::signal<void (void)> ServiceGroup::OnMembersChanged;
|
||||
|
||||
REGISTER_TYPE(ServiceGroup);
|
||||
|
||||
|
@ -137,6 +138,10 @@ void ServiceGroup::RefreshMembersCache(void)
|
|||
}
|
||||
}
|
||||
|
||||
boost::mutex::scoped_lock lock(l_Mutex);
|
||||
l_MembersCache.swap(newMembersCache);
|
||||
{
|
||||
boost::mutex::scoped_lock lock(l_Mutex);
|
||||
l_MembersCache.swap(newMembersCache);
|
||||
}
|
||||
|
||||
OnMembersChanged();
|
||||
}
|
||||
|
|
|
@ -49,6 +49,8 @@ public:
|
|||
|
||||
static void InvalidateMembersCache(void);
|
||||
|
||||
static boost::signals2::signal<void (void)> OnMembersChanged;
|
||||
|
||||
protected:
|
||||
virtual void OnRegistrationCompleted(void);
|
||||
|
||||
|
|
|
@ -73,8 +73,6 @@ void HostGroupDbObject::MembersChangedHandler(void)
|
|||
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("HostGroup")) {
|
||||
HostGroup::Ptr hg = static_pointer_cast<HostGroup>(object);
|
||||
|
||||
Log(LogWarning, "ido", "HG: " + hg->GetName());
|
||||
|
||||
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
|
||||
DbQuery query2;
|
||||
query2.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
|
||||
|
|
|
@ -22,22 +22,29 @@
|
|||
#include "ido/dbvalue.h"
|
||||
#include "icinga/servicegroup.h"
|
||||
#include "base/objectlock.h"
|
||||
#include "base/initialize.h"
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_DBTYPE(ServiceGroup, "servicegroup", DbObjectTypeServiceGroup, "servicegroup_object_id", ServiceGroupDbObject);
|
||||
INITIALIZE_ONCE(ServiceGroupDbObject, &ServiceGroupDbObject::StaticInitialize);
|
||||
|
||||
ServiceGroupDbObject::ServiceGroupDbObject(const DbType::Ptr& type, const String& name1, const String& name2)
|
||||
: DbObject(type, name1, name2)
|
||||
{ }
|
||||
|
||||
void ServiceGroupDbObject::StaticInitialize(void)
|
||||
{
|
||||
ServiceGroup::OnMembersChanged.connect(&ServiceGroupDbObject::MembersChangedHandler);
|
||||
}
|
||||
|
||||
Dictionary::Ptr ServiceGroupDbObject::GetConfigFields(void) const
|
||||
{
|
||||
Dictionary::Ptr fields = boost::make_shared<Dictionary>();
|
||||
ServiceGroup::Ptr group = static_pointer_cast<ServiceGroup>(GetObject());
|
||||
|
||||
fields->Set("alias", Empty);
|
||||
fields->Set("alias", group->GetDisplayName());
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
@ -46,3 +53,34 @@ Dictionary::Ptr ServiceGroupDbObject::GetStatusFields(void) const
|
|||
{
|
||||
return Empty;
|
||||
}
|
||||
|
||||
|
||||
void ServiceGroupDbObject::OnConfigUpdate(void)
|
||||
{
|
||||
MembersChangedHandler();
|
||||
}
|
||||
|
||||
void ServiceGroupDbObject::MembersChangedHandler(void)
|
||||
{
|
||||
DbQuery query1;
|
||||
query1.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
|
||||
query1.Type = DbQueryDelete;
|
||||
query1.WhereCriteria = boost::make_shared<Dictionary>();
|
||||
query1.WhereCriteria->Set("instance_id", 0);
|
||||
OnQuery(query1);
|
||||
|
||||
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("ServiceGroup")) {
|
||||
ServiceGroup::Ptr sg = static_pointer_cast<ServiceGroup>(object);
|
||||
|
||||
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
|
||||
DbQuery query2;
|
||||
query2.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
|
||||
query2.Type = DbQueryInsert;
|
||||
query2.Fields = boost::make_shared<Dictionary>();
|
||||
query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
query2.Fields->Set("servicegroup_id", DbValue::FromObjectInsertID(sg));
|
||||
query2.Fields->Set("service_object_id", service);
|
||||
OnQuery(query2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,8 +38,16 @@ public:
|
|||
|
||||
ServiceGroupDbObject(const DbType::Ptr& type, const String& name1, const String& name2);
|
||||
|
||||
static void StaticInitialize(void);
|
||||
|
||||
virtual Dictionary::Ptr GetConfigFields(void) const;
|
||||
virtual Dictionary::Ptr GetStatusFields(void) const;
|
||||
|
||||
protected:
|
||||
virtual void OnConfigUpdate(void);
|
||||
|
||||
private:
|
||||
static void MembersChangedHandler(void);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue