Make sure that Notification objects are activated after Host/Service objects

fixes #8517
This commit is contained in:
Gunnar Beutner 2015-02-25 12:43:03 +01:00
parent dd6691537b
commit 4da3b1c5b3
11 changed files with 83 additions and 4 deletions

View File

@ -106,6 +106,11 @@ Value Type::GetField(int id) const
return Object::GetField(id);
}
std::vector<String> Type::GetLoadDependencies(void) const
{
return std::vector<String>();
}
String TypeType::GetName(void) const
{
return "Type";

View File

@ -84,6 +84,8 @@ public:
virtual void SetField(int id, const Value& value);
virtual Value GetField(int id) const;
virtual std::vector<String> GetLoadDependencies(void) const;
protected:
virtual ObjectFactory GetFactory(void) const = 0;

View File

@ -326,11 +326,43 @@ bool ConfigItem::CommitNewItems(WorkQueue& upq)
new_items.swap(m_CommittedItems);
}
std::set<String> types;
BOOST_FOREACH(const ConfigItem::Ptr& item, new_items) {
upq.Enqueue(boost::bind(&DynamicObject::OnAllConfigLoaded, item->m_Object));
types.insert(item->m_Type);
}
upq.Join();
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));
}
completed_types.insert(type);
}
}
upq.Join();
}
} while (!items.empty());
return true;

View File

@ -33,6 +33,9 @@ public:
class Dependency : CustomVarObject < DependencyNameComposer
{
load_after Host;
load_after Service;
[config] String child_host_name;
[config] String child_service_name;

View File

@ -32,6 +32,9 @@ public:
class Notification : CustomVarObject < NotificationNameComposer
{
load_after Host;
load_after Service;
[config, protected] String command (CommandRaw);
[config] double interval {
default {{{ return 1800; }}}

View File

@ -32,6 +32,9 @@ public:
class ScheduledDowntime : CustomVarObject < ScheduledDowntimeNameComposer
{
load_after Host;
load_after Service;
[config, protected] String host_name;
[config, protected] String service_name;

View File

@ -35,6 +35,8 @@ public:
class Service : Checkable < ServiceNameComposer
{
load_after Host;
[config] String display_name {
get {{{
if (m_DisplayName.IsEmpty())

View File

@ -133,6 +133,7 @@ static char *lb_steal(lex_buf *lb)
class { return T_CLASS; }
namespace { return T_NAMESPACE; }
code { return T_CODE; }
load_after { return T_LOAD_AFTER; }
abstract { yylval->num = TAAbstract; return T_CLASS_ATTRIBUTE; }
config { yylval->num = FAConfig; return T_FIELD_ATTRIBUTE; }
state { yylval->num = FAState; return T_FIELD_ATTRIBUTE; }

View File

@ -55,6 +55,7 @@ using namespace icinga;
%token T_INCLUDE "include (T_INCLUDE)"
%token T_CLASS "class (T_CLASS)"
%token T_CODE "code (T_CODE)"
%token T_LOAD_AFTER "load_after (T_LOAD_AFTER)"
%token T_NAMESPACE "namespace (T_NAMESPACE)"
%token T_STRING "string (T_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;
$$->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;
ClassCompiler::OptimizeStructLayout($$->Fields);
@ -281,6 +288,14 @@ class_field: field_attribute_list identifier identifier alternative_name_specifi
$$ = field;
}
| T_LOAD_AFTER identifier ';'
{
Field *field = new Field();
field->Attributes = FALoadDependency;
field->Name = $2;
std::free($2);
$$ = field;
}
;
alternative_name_specifier: /* empty */

View File

@ -349,6 +349,17 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
<< "\t\t" << "return TypeHelper<" << klass.Name << ">::GetFactory();" << 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;
/* ObjectImpl */

View File

@ -63,7 +63,8 @@ enum FieldAttribute
FAGetProtected = 8,
FASetProtected = 16,
FAInternal = 32,
FANoStorage = 64
FANoStorage = 64,
FALoadDependency = 128
};
struct Field
@ -124,6 +125,7 @@ struct Klass
std::string TypeBase;
int Attributes;
std::vector<Field> Fields;
std::vector<std::string> LoadDependencies;
};
class ClassCompiler