mirror of https://github.com/Icinga/icinga2.git
Make sure that Notification objects are activated after Host/Service objects
fixes #8517
This commit is contained in:
parent
dd6691537b
commit
4da3b1c5b3
|
@ -106,6 +106,11 @@ Value Type::GetField(int id) const
|
||||||
return Object::GetField(id);
|
return Object::GetField(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<String> Type::GetLoadDependencies(void) const
|
||||||
|
{
|
||||||
|
return std::vector<String>();
|
||||||
|
}
|
||||||
|
|
||||||
String TypeType::GetName(void) const
|
String TypeType::GetName(void) const
|
||||||
{
|
{
|
||||||
return "Type";
|
return "Type";
|
||||||
|
|
|
@ -84,6 +84,8 @@ public:
|
||||||
virtual void SetField(int id, const Value& value);
|
virtual void SetField(int id, const Value& value);
|
||||||
virtual Value GetField(int id) const;
|
virtual Value GetField(int id) const;
|
||||||
|
|
||||||
|
virtual std::vector<String> GetLoadDependencies(void) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ObjectFactory GetFactory(void) const = 0;
|
virtual ObjectFactory GetFactory(void) const = 0;
|
||||||
|
|
||||||
|
|
|
@ -326,11 +326,43 @@ bool ConfigItem::CommitNewItems(WorkQueue& upq)
|
||||||
new_items.swap(m_CommittedItems);
|
new_items.swap(m_CommittedItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::set<String> types;
|
||||||
|
|
||||||
BOOST_FOREACH(const ConfigItem::Ptr& item, new_items) {
|
BOOST_FOREACH(const ConfigItem::Ptr& item, new_items) {
|
||||||
|
types.insert(item->m_Type);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set<String> completed_types;
|
||||||
|
|
||||||
|
while (types.size() != completed_types.size()) {
|
||||||
|
std::set<String> current_types;
|
||||||
|
|
||||||
|
BOOST_FOREACH(const String& type, types) {
|
||||||
|
if (completed_types.find(type) != completed_types.end())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Type::Ptr ptype = Type::GetByName(type);
|
||||||
|
bool unresolved_dep = false;
|
||||||
|
|
||||||
|
BOOST_FOREACH(const String& loadDep, ptype->GetLoadDependencies()) {
|
||||||
|
if (types.find(loadDep) != types.end() && completed_types.find(loadDep) == completed_types.end()) {
|
||||||
|
unresolved_dep = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!unresolved_dep) {
|
||||||
|
BOOST_FOREACH(const ConfigItem::Ptr& item, new_items) {
|
||||||
|
if (item->m_Type == type)
|
||||||
upq.Enqueue(boost::bind(&DynamicObject::OnAllConfigLoaded, item->m_Object));
|
upq.Enqueue(boost::bind(&DynamicObject::OnAllConfigLoaded, item->m_Object));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
completed_types.insert(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
upq.Join();
|
upq.Join();
|
||||||
|
}
|
||||||
} while (!items.empty());
|
} while (!items.empty());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -33,6 +33,9 @@ public:
|
||||||
|
|
||||||
class Dependency : CustomVarObject < DependencyNameComposer
|
class Dependency : CustomVarObject < DependencyNameComposer
|
||||||
{
|
{
|
||||||
|
load_after Host;
|
||||||
|
load_after Service;
|
||||||
|
|
||||||
[config] String child_host_name;
|
[config] String child_host_name;
|
||||||
[config] String child_service_name;
|
[config] String child_service_name;
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,9 @@ public:
|
||||||
|
|
||||||
class Notification : CustomVarObject < NotificationNameComposer
|
class Notification : CustomVarObject < NotificationNameComposer
|
||||||
{
|
{
|
||||||
|
load_after Host;
|
||||||
|
load_after Service;
|
||||||
|
|
||||||
[config, protected] String command (CommandRaw);
|
[config, protected] String command (CommandRaw);
|
||||||
[config] double interval {
|
[config] double interval {
|
||||||
default {{{ return 1800; }}}
|
default {{{ return 1800; }}}
|
||||||
|
|
|
@ -32,6 +32,9 @@ public:
|
||||||
|
|
||||||
class ScheduledDowntime : CustomVarObject < ScheduledDowntimeNameComposer
|
class ScheduledDowntime : CustomVarObject < ScheduledDowntimeNameComposer
|
||||||
{
|
{
|
||||||
|
load_after Host;
|
||||||
|
load_after Service;
|
||||||
|
|
||||||
[config, protected] String host_name;
|
[config, protected] String host_name;
|
||||||
[config, protected] String service_name;
|
[config, protected] String service_name;
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,8 @@ public:
|
||||||
|
|
||||||
class Service : Checkable < ServiceNameComposer
|
class Service : Checkable < ServiceNameComposer
|
||||||
{
|
{
|
||||||
|
load_after Host;
|
||||||
|
|
||||||
[config] String display_name {
|
[config] String display_name {
|
||||||
get {{{
|
get {{{
|
||||||
if (m_DisplayName.IsEmpty())
|
if (m_DisplayName.IsEmpty())
|
||||||
|
|
|
@ -133,6 +133,7 @@ static char *lb_steal(lex_buf *lb)
|
||||||
class { return T_CLASS; }
|
class { return T_CLASS; }
|
||||||
namespace { return T_NAMESPACE; }
|
namespace { return T_NAMESPACE; }
|
||||||
code { return T_CODE; }
|
code { return T_CODE; }
|
||||||
|
load_after { return T_LOAD_AFTER; }
|
||||||
abstract { yylval->num = TAAbstract; return T_CLASS_ATTRIBUTE; }
|
abstract { yylval->num = TAAbstract; return T_CLASS_ATTRIBUTE; }
|
||||||
config { yylval->num = FAConfig; return T_FIELD_ATTRIBUTE; }
|
config { yylval->num = FAConfig; return T_FIELD_ATTRIBUTE; }
|
||||||
state { yylval->num = FAState; return T_FIELD_ATTRIBUTE; }
|
state { yylval->num = FAState; return T_FIELD_ATTRIBUTE; }
|
||||||
|
|
|
@ -55,6 +55,7 @@ using namespace icinga;
|
||||||
%token T_INCLUDE "include (T_INCLUDE)"
|
%token T_INCLUDE "include (T_INCLUDE)"
|
||||||
%token T_CLASS "class (T_CLASS)"
|
%token T_CLASS "class (T_CLASS)"
|
||||||
%token T_CODE "code (T_CODE)"
|
%token T_CODE "code (T_CODE)"
|
||||||
|
%token T_LOAD_AFTER "load_after (T_LOAD_AFTER)"
|
||||||
%token T_NAMESPACE "namespace (T_NAMESPACE)"
|
%token T_NAMESPACE "namespace (T_NAMESPACE)"
|
||||||
%token T_STRING "string (T_STRING)"
|
%token T_STRING "string (T_STRING)"
|
||||||
%token T_ANGLE_STRING "angle_string (T_ANGLE_STRING)"
|
%token T_ANGLE_STRING "angle_string (T_ANGLE_STRING)"
|
||||||
|
@ -192,7 +193,13 @@ class: class_attribute_list T_CLASS T_IDENTIFIER inherits_specifier type_base_sp
|
||||||
|
|
||||||
$$->Attributes = $1;
|
$$->Attributes = $1;
|
||||||
|
|
||||||
$$->Fields = *$7;
|
for (std::vector<Field>::iterator it = $7->begin(); it != $7->end(); it++) {
|
||||||
|
if (it->Attributes & FALoadDependency) {
|
||||||
|
$$->LoadDependencies.push_back(it->Name);
|
||||||
|
} else
|
||||||
|
$$->Fields.push_back(*it);
|
||||||
|
}
|
||||||
|
|
||||||
delete $7;
|
delete $7;
|
||||||
|
|
||||||
ClassCompiler::OptimizeStructLayout($$->Fields);
|
ClassCompiler::OptimizeStructLayout($$->Fields);
|
||||||
|
@ -281,6 +288,14 @@ class_field: field_attribute_list identifier identifier alternative_name_specifi
|
||||||
|
|
||||||
$$ = field;
|
$$ = field;
|
||||||
}
|
}
|
||||||
|
| T_LOAD_AFTER identifier ';'
|
||||||
|
{
|
||||||
|
Field *field = new Field();
|
||||||
|
field->Attributes = FALoadDependency;
|
||||||
|
field->Name = $2;
|
||||||
|
std::free($2);
|
||||||
|
$$ = field;
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
alternative_name_specifier: /* empty */
|
alternative_name_specifier: /* empty */
|
||||||
|
|
|
@ -349,6 +349,17 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
|
||||||
<< "\t\t" << "return TypeHelper<" << klass.Name << ">::GetFactory();" << std::endl
|
<< "\t\t" << "return TypeHelper<" << klass.Name << ">::GetFactory();" << std::endl
|
||||||
<< "\t" << "}" << std::endl << std::endl;
|
<< "\t" << "}" << std::endl << std::endl;
|
||||||
|
|
||||||
|
/* GetLoadDependencies */
|
||||||
|
std::cout << "\t" << "virtual std::vector<String> GetLoadDependencies(void) const" << std::endl
|
||||||
|
<< "\t" << "{" << std::endl
|
||||||
|
<< "\t\t" << "std::vector<String> deps;" << std::endl;
|
||||||
|
|
||||||
|
for (std::vector<std::string>::const_iterator itd = klass.LoadDependencies.begin(); itd != klass.LoadDependencies.end(); itd++)
|
||||||
|
std::cout << "\t\t" << "deps.push_back(\"" << *itd << "\");" << std::endl;
|
||||||
|
|
||||||
|
std::cout << "\t\t" << "return deps;" << std::endl
|
||||||
|
<< "\t" << "}" << std::endl;
|
||||||
|
|
||||||
std::cout << "};" << std::endl << std::endl;
|
std::cout << "};" << std::endl << std::endl;
|
||||||
|
|
||||||
/* ObjectImpl */
|
/* ObjectImpl */
|
||||||
|
|
|
@ -63,7 +63,8 @@ enum FieldAttribute
|
||||||
FAGetProtected = 8,
|
FAGetProtected = 8,
|
||||||
FASetProtected = 16,
|
FASetProtected = 16,
|
||||||
FAInternal = 32,
|
FAInternal = 32,
|
||||||
FANoStorage = 64
|
FANoStorage = 64,
|
||||||
|
FALoadDependency = 128
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Field
|
struct Field
|
||||||
|
@ -124,6 +125,7 @@ struct Klass
|
||||||
std::string TypeBase;
|
std::string TypeBase;
|
||||||
int Attributes;
|
int Attributes;
|
||||||
std::vector<Field> Fields;
|
std::vector<Field> Fields;
|
||||||
|
std::vector<std::string> LoadDependencies;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ClassCompiler
|
class ClassCompiler
|
||||||
|
|
Loading…
Reference in New Issue