mirror of https://github.com/Icinga/icinga2.git
Split DynamicObject::OnConfigLoaded into two separate events
refs #7780
This commit is contained in:
parent
b22d3c099a
commit
334e61037a
|
@ -182,6 +182,11 @@ void DynamicObject::OnConfigLoaded(void)
|
||||||
/* Nothing to do here. */
|
/* Nothing to do here. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DynamicObject::OnAllConfigLoaded(void)
|
||||||
|
{
|
||||||
|
/* Nothing to do here. */
|
||||||
|
}
|
||||||
|
|
||||||
void DynamicObject::OnStateLoaded(void)
|
void DynamicObject::OnStateLoaded(void)
|
||||||
{
|
{
|
||||||
/* Nothing to do here. */
|
/* Nothing to do here. */
|
||||||
|
|
|
@ -77,6 +77,7 @@ public:
|
||||||
virtual void Resume(void);
|
virtual void Resume(void);
|
||||||
|
|
||||||
virtual void OnConfigLoaded(void);
|
virtual void OnConfigLoaded(void);
|
||||||
|
virtual void OnAllConfigLoaded(void);
|
||||||
virtual void OnStateLoaded(void);
|
virtual void OnStateLoaded(void);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -44,6 +44,7 @@ using namespace icinga;
|
||||||
boost::mutex ConfigItem::m_Mutex;
|
boost::mutex ConfigItem::m_Mutex;
|
||||||
ConfigItem::TypeMap ConfigItem::m_Items;
|
ConfigItem::TypeMap ConfigItem::m_Items;
|
||||||
ConfigItem::ItemList ConfigItem::m_UnnamedItems;
|
ConfigItem::ItemList ConfigItem::m_UnnamedItems;
|
||||||
|
ConfigItem::ItemList ConfigItem::m_CommittedItems;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for the ConfigItem class.
|
* Constructor for the ConfigItem class.
|
||||||
|
@ -198,6 +199,13 @@ DynamicObject::Ptr ConfigItem::Commit(bool discard)
|
||||||
dobj->SetShortName(m_Name);
|
dobj->SetShortName(m_Name);
|
||||||
|
|
||||||
dobj->SetName(name);
|
dobj->SetName(name);
|
||||||
|
dobj->OnConfigLoaded();
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_Mutex);
|
||||||
|
m_CommittedItems.push_back(this);
|
||||||
|
}
|
||||||
|
|
||||||
Dictionary::Ptr attrs = Serialize(dobj, FAConfig);
|
Dictionary::Ptr attrs = Serialize(dobj, FAConfig);
|
||||||
|
|
||||||
|
@ -315,8 +323,15 @@ bool ConfigItem::CommitNewItems(ParallelWorkQueue& upq)
|
||||||
if (ConfigCompilerContext::GetInstance()->HasErrors())
|
if (ConfigCompilerContext::GetInstance()->HasErrors())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
BOOST_FOREACH(const ItemPair& ip, items) {
|
std::vector<ConfigItem::Ptr> new_items;
|
||||||
upq.Enqueue(boost::bind(&DynamicObject::OnConfigLoaded, ip.first->m_Object));
|
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_Mutex);
|
||||||
|
new_items.swap(m_CommittedItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_FOREACH(const ConfigItem::Ptr& item, new_items) {
|
||||||
|
upq.Enqueue(boost::bind(&DynamicObject::OnAllConfigLoaded, item->m_Object));
|
||||||
}
|
}
|
||||||
|
|
||||||
upq.Join();
|
upq.Join();
|
||||||
|
|
|
@ -91,6 +91,7 @@ private:
|
||||||
|
|
||||||
typedef std::vector<ConfigItem::Ptr> ItemList;
|
typedef std::vector<ConfigItem::Ptr> ItemList;
|
||||||
static ItemList m_UnnamedItems;
|
static ItemList m_UnnamedItems;
|
||||||
|
static ItemList m_CommittedItems;
|
||||||
|
|
||||||
static ConfigItem::Ptr GetObjectUnlocked(const String& type,
|
static ConfigItem::Ptr GetObjectUnlocked(const String& type,
|
||||||
const String& name);
|
const String& name);
|
||||||
|
|
|
@ -1564,6 +1564,7 @@ Value ApiEvents::ExecuteCommandAPIHandler(const MessageOrigin& origin, const Dic
|
||||||
|
|
||||||
static_pointer_cast<DynamicObject>(host)->OnStateLoaded();
|
static_pointer_cast<DynamicObject>(host)->OnStateLoaded();
|
||||||
static_pointer_cast<DynamicObject>(host)->OnConfigLoaded();
|
static_pointer_cast<DynamicObject>(host)->OnConfigLoaded();
|
||||||
|
static_pointer_cast<DynamicObject>(host)->OnAllConfigLoaded();
|
||||||
|
|
||||||
Dictionary::Ptr macros = params->Get("macros");
|
Dictionary::Ptr macros = params->Get("macros");
|
||||||
|
|
||||||
|
|
|
@ -72,9 +72,7 @@ void Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, cons
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
ConfigItem::Ptr dependencyItem = builder->Compile();
|
ConfigItem::Ptr dependencyItem = builder->Compile();
|
||||||
DynamicObject::Ptr dobj = dependencyItem->Commit();
|
dependencyItem->Commit();
|
||||||
dobj->OnConfigLoaded();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule)
|
bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule)
|
||||||
|
|
|
@ -35,11 +35,11 @@ using namespace icinga;
|
||||||
|
|
||||||
REGISTER_TYPE(Host);
|
REGISTER_TYPE(Host);
|
||||||
|
|
||||||
void Host::OnConfigLoaded(void)
|
void Host::OnAllConfigLoaded(void)
|
||||||
{
|
{
|
||||||
Checkable::OnConfigLoaded();
|
Checkable::OnAllConfigLoaded();
|
||||||
|
|
||||||
ASSERT(!OwnsLock());
|
HostGroup::EvaluateObjectRules(this);
|
||||||
|
|
||||||
Array::Ptr groups = GetGroups();
|
Array::Ptr groups = GetGroups();
|
||||||
|
|
||||||
|
@ -56,7 +56,6 @@ void Host::OnConfigLoaded(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HostGroup::EvaluateObjectRules(this);
|
|
||||||
ScheduledDowntime::EvaluateApplyRules(this);
|
ScheduledDowntime::EvaluateApplyRules(this);
|
||||||
Notification::EvaluateApplyRules(this);
|
Notification::EvaluateApplyRules(this);
|
||||||
Dependency::EvaluateApplyRules(this);
|
Dependency::EvaluateApplyRules(this);
|
||||||
|
|
|
@ -68,7 +68,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual void Stop(void);
|
virtual void Stop(void);
|
||||||
|
|
||||||
virtual void OnConfigLoaded(void);
|
virtual void OnAllConfigLoaded(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable boost::mutex m_ServicesMutex;
|
mutable boost::mutex m_ServicesMutex;
|
||||||
|
|
|
@ -54,16 +54,8 @@ bool HostGroup::EvaluateObjectRule(const Host::Ptr& host, const ConfigItem::Ptr&
|
||||||
Log(LogDebug, "HostGroup")
|
Log(LogDebug, "HostGroup")
|
||||||
<< "Assigning membership for group '" << group_name << "' to host '" << host->GetName() << "'";
|
<< "Assigning membership for group '" << group_name << "' to host '" << host->GetName() << "'";
|
||||||
|
|
||||||
HostGroup::Ptr groupObject = HostGroup::GetByName(group_name);
|
Array::Ptr groups = host->GetGroups();
|
||||||
|
groups->Add(group_name);
|
||||||
if (!groupObject) {
|
|
||||||
Log(LogCritical, "HostGroup")
|
|
||||||
<< "Invalid membership assignment. Group '" << group_name << "' does not exist.";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* assign host group membership */
|
|
||||||
groupObject->ResolveGroupMembership(host, true);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,9 +71,7 @@ void Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, co
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
ConfigItem::Ptr notificationItem = builder->Compile();
|
ConfigItem::Ptr notificationItem = builder->Compile();
|
||||||
DynamicObject::Ptr dobj = notificationItem->Commit();
|
notificationItem->Commit();
|
||||||
dobj->OnConfigLoaded();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule)
|
bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule)
|
||||||
|
|
|
@ -71,8 +71,7 @@ void ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkabl
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
ConfigItem::Ptr downtimeItem = builder->Compile();
|
ConfigItem::Ptr downtimeItem = builder->Compile();
|
||||||
DynamicObject::Ptr dobj = downtimeItem->Commit();
|
downtimeItem->Commit();
|
||||||
dobj->OnConfigLoaded();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule)
|
bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule)
|
||||||
|
|
|
@ -64,8 +64,7 @@ void Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& nam
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
ConfigItem::Ptr serviceItem = builder->Compile();
|
ConfigItem::Ptr serviceItem = builder->Compile();
|
||||||
DynamicObject::Ptr dobj = serviceItem->Commit();
|
serviceItem->Commit();
|
||||||
dobj->OnConfigLoaded();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule)
|
bool Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule)
|
||||||
|
|
|
@ -41,8 +41,17 @@ String ServiceNameComposer::MakeName(const String& shortName, const Object::Ptr&
|
||||||
return service->GetHostName() + "!" + shortName;
|
return service->GetHostName() + "!" + shortName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service::OnConfigLoaded(void)
|
void Service::OnAllConfigLoaded(void)
|
||||||
{
|
{
|
||||||
|
Checkable::OnAllConfigLoaded();
|
||||||
|
|
||||||
|
m_Host = Host::GetByName(GetHostName());
|
||||||
|
|
||||||
|
if (m_Host)
|
||||||
|
m_Host->AddService(this);
|
||||||
|
|
||||||
|
ServiceGroup::EvaluateObjectRules(this);
|
||||||
|
|
||||||
Array::Ptr groups = GetGroups();
|
Array::Ptr groups = GetGroups();
|
||||||
|
|
||||||
if (groups) {
|
if (groups) {
|
||||||
|
@ -58,16 +67,6 @@ void Service::OnConfigLoaded(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Host = Host::GetByName(GetHostName());
|
|
||||||
|
|
||||||
if (m_Host)
|
|
||||||
m_Host->AddService(this);
|
|
||||||
|
|
||||||
SetSchedulingOffset(Utility::Random());
|
|
||||||
|
|
||||||
Checkable::OnConfigLoaded();
|
|
||||||
|
|
||||||
ServiceGroup::EvaluateObjectRules(this);
|
|
||||||
ScheduledDowntime::EvaluateApplyRules(this);
|
ScheduledDowntime::EvaluateApplyRules(this);
|
||||||
Notification::EvaluateApplyRules(this);
|
Notification::EvaluateApplyRules(this);
|
||||||
Dependency::EvaluateApplyRules(this);
|
Dependency::EvaluateApplyRules(this);
|
||||||
|
|
|
@ -56,7 +56,7 @@ public:
|
||||||
static void EvaluateApplyRules(const Host::Ptr& host);
|
static void EvaluateApplyRules(const Host::Ptr& host);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void OnConfigLoaded(void);
|
virtual void OnAllConfigLoaded(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Host::Ptr m_Host;
|
Host::Ptr m_Host;
|
||||||
|
|
|
@ -57,16 +57,8 @@ bool ServiceGroup::EvaluateObjectRule(const Service::Ptr& service, const ConfigI
|
||||||
Log(LogDebug, "ServiceGroup")
|
Log(LogDebug, "ServiceGroup")
|
||||||
<< "Assigning membership for group '" << group_name << "' to service '" << service->GetName() << "'";
|
<< "Assigning membership for group '" << group_name << "' to service '" << service->GetName() << "'";
|
||||||
|
|
||||||
ServiceGroup::Ptr groupObject = ServiceGroup::GetByName(group_name);
|
Array::Ptr groups = service->GetGroups();
|
||||||
|
groups->Add(group_name);
|
||||||
if (!groupObject) {
|
|
||||||
Log(LogCritical, "ServiceGroup")
|
|
||||||
<< "Invalid membership assignment. Group '" << group_name << "' does not exist.";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* assign service group membership */
|
|
||||||
groupObject->ResolveGroupMembership(service, true);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,17 @@ boost::signals2::signal<void (const User::Ptr&, bool, const MessageOrigin&)> Use
|
||||||
|
|
||||||
void User::OnConfigLoaded(void)
|
void User::OnConfigLoaded(void)
|
||||||
{
|
{
|
||||||
|
DynamicObject::OnConfigLoaded();
|
||||||
|
|
||||||
SetTypeFilter(FilterArrayToInt(GetTypes(), ~0));
|
SetTypeFilter(FilterArrayToInt(GetTypes(), ~0));
|
||||||
SetStateFilter(FilterArrayToInt(GetStates(), ~0));
|
SetStateFilter(FilterArrayToInt(GetStates(), ~0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void User::OnAllConfigLoaded(void)
|
||||||
|
{
|
||||||
|
DynamicObject::OnAllConfigLoaded();
|
||||||
|
|
||||||
|
UserGroup::EvaluateObjectRules(this);
|
||||||
|
|
||||||
Array::Ptr groups = GetGroups();
|
Array::Ptr groups = GetGroups();
|
||||||
|
|
||||||
|
@ -52,8 +61,6 @@ void User::OnConfigLoaded(void)
|
||||||
ug->ResolveGroupMembership(this, true);
|
ug->ResolveGroupMembership(this, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UserGroup::EvaluateObjectRules(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void User::Stop(void)
|
void User::Stop(void)
|
||||||
|
|
|
@ -58,6 +58,7 @@ protected:
|
||||||
virtual void Stop(void);
|
virtual void Stop(void);
|
||||||
|
|
||||||
virtual void OnConfigLoaded(void);
|
virtual void OnConfigLoaded(void);
|
||||||
|
virtual void OnAllConfigLoaded(void);
|
||||||
private:
|
private:
|
||||||
mutable boost::mutex m_UserMutex;
|
mutable boost::mutex m_UserMutex;
|
||||||
};
|
};
|
||||||
|
|
|
@ -54,16 +54,8 @@ bool UserGroup::EvaluateObjectRule(const User::Ptr& user, const ConfigItem::Ptr&
|
||||||
Log(LogDebug, "UserGroup")
|
Log(LogDebug, "UserGroup")
|
||||||
<< "Assigning membership for group '" << group_name << "' to user '" << user->GetName() << "'";
|
<< "Assigning membership for group '" << group_name << "' to user '" << user->GetName() << "'";
|
||||||
|
|
||||||
UserGroup::Ptr groupObject = UserGroup::GetByName(group_name);
|
Array::Ptr groups = user->GetGroups();
|
||||||
|
groups->Add(group_name);
|
||||||
if (!groupObject) {
|
|
||||||
Log(LogCritical, "UserGroup")
|
|
||||||
<< "Invalid membership assignment. Group '" << group_name << "' does not exist.";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* assign user group membership */
|
|
||||||
groupObject->ResolveGroupMembership(user, true);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue