Merge pull request #6270 from Icinga/feature/activation-priority

Add activation priority for config object types
This commit is contained in:
Michael Friedrich 2018-05-04 11:41:57 +02:00 committed by GitHub
commit 40dfd82d65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 92 additions and 8 deletions

View File

@ -26,6 +26,8 @@ namespace icinga
class FileLogger : StreamLogger
{
activation_priority -100;
[config, required] String path;
};

View File

@ -26,6 +26,8 @@ namespace icinga
class SyslogLogger : Logger
{
activation_priority -100;
[config] String facility {
default {{{ return "LOG_USER"; }}}
};

View File

@ -154,6 +154,11 @@ std::vector<String> Type::GetLoadDependencies() const
return std::vector<String>();
}
int Type::GetActivationPriority() const
{
return 0;
}
void Type::RegisterAttributeHandler(int fieldId, const AttributeHandler& callback)
{
throw std::runtime_error("Invalid field ID.");

View File

@ -103,6 +103,7 @@ public:
Value GetField(int id) const override;
virtual std::vector<String> GetLoadDependencies() const;
virtual int GetActivationPriority() const;
typedef std::function<void (const Object::Ptr&, const Value&)> AttributeHandler;
virtual void RegisterAttributeHandler(int fieldId, const AttributeHandler& callback);

View File

@ -26,6 +26,8 @@ namespace icinga
class CheckerComponent : ConfigObject
{
activation_priority 100;
[config] int concurrent_checks {
get {{{
return Application::GetMaxConcurrentChecks();

View File

@ -27,6 +27,8 @@ namespace icinga
class CheckResultReader : ConfigObject
{
activation_priority 100;
[config] String spool_dir {
default {{{ return Application::GetLocalStateDir() + "/lib/icinga2/spool/checkresults/"; }}}
};

View File

@ -27,6 +27,8 @@ namespace icinga
class CompatLogger : ConfigObject
{
activation_priority 100;
[config] String log_dir {
default {{{ return Application::GetLocalStateDir() + "/log/icinga2/compat"; }}}
};

View File

@ -27,6 +27,8 @@ namespace icinga
class ExternalCommandListener : ConfigObject
{
activation_priority 100;
[config] String command_path {
default {{{ return Application::GetRunDir() + "/icinga2/cmd/icinga2.cmd"; }}}
};

View File

@ -27,6 +27,8 @@ namespace icinga
class StatusDataWriter : ConfigObject
{
activation_priority 100;
[config] String status_path {
default {{{ return Application::GetLocalStateDir() + "/cache/icinga2/status.dat"; }}}
};

View File

@ -602,18 +602,35 @@ bool ConfigItem::ActivateItems(WorkQueue& upq, const std::vector<ConfigItem::Ptr
if (!silent)
Log(LogInformation, "ConfigItem", "Triggering Start signal for config items");
for (const ConfigItem::Ptr& item : newItems) {
if (!item->m_Object)
continue;
/* Activate objects in priority order. */
std::vector<Type::Ptr> types = Type::GetAllTypes();
ConfigObject::Ptr object = item->m_Object;
std::sort(types.begin(), types.end(), [](const Type::Ptr& a, const Type::Ptr& b) {
if (a->GetActivationPriority() < b->GetActivationPriority())
return true;
return false;
});
for (const Type::Ptr& type : types) {
for (const ConfigItem::Ptr& item : newItems) {
if (!item->m_Object)
continue;
ConfigObject::Ptr object = item->m_Object;
Type::Ptr objectType = object->GetReflectionType();
if (objectType != type)
continue;
#ifdef I2_DEBUG
Log(LogDebug, "ConfigItem")
<< "Activating object '" << object->GetName() << "' of type '" << object->GetReflectionType()->GetName() << "'";
Log(LogDebug, "ConfigItem")
<< "Activating object '" << object->GetName() << "' of type '"
<< objectType->GetName() << "' with priority '"
<< objectType->GetActivationPriority();
#endif /* I2_DEBUG */
object->Activate(runtimeCreated);
object->Activate(runtimeCreated);
}
}
upq.Join();

View File

@ -26,6 +26,8 @@ namespace icinga
class IdoMysqlConnection : DbConnection
{
activation_priority 100;
[config] String host {
default {{{ return "localhost"; }}}
};

View File

@ -26,6 +26,8 @@ namespace icinga
class IdoPgsqlConnection : DbConnection
{
activation_priority 100;
[config] String host {
default {{{ return "localhost"; }}}
};

View File

@ -26,6 +26,8 @@ namespace icinga
{
class LivestatusListener : ConfigObject {
activation_priority 100;
[config] String socket_type {
default {{{ return "unix"; }}}
};

View File

@ -26,6 +26,8 @@ namespace icinga
class NotificationComponent : ConfigObject
{
activation_priority 100;
[config] bool enable_ha (EnableHA) {
default {{{ return true; }}}
};

View File

@ -7,6 +7,8 @@ namespace icinga
class ElasticsearchWriter : ConfigObject
{
activation_priority 100;
[config, required] String host {
default {{{ return "127.0.0.1"; }}}
};

View File

@ -26,6 +26,8 @@ namespace icinga
class GelfWriter : ConfigObject
{
activation_priority 100;
[config] String host {
default {{{ return "127.0.0.1"; }}}
};

View File

@ -26,6 +26,8 @@ namespace icinga
class GraphiteWriter : ConfigObject
{
activation_priority 100;
[config] String host {
default {{{ return "127.0.0.1"; }}}
};

View File

@ -26,6 +26,8 @@ namespace icinga
class InfluxdbWriter : ConfigObject
{
activation_priority 100;
[config, required] String host {
default {{{ return "127.0.0.1"; }}}
};

View File

@ -26,6 +26,8 @@ namespace icinga
class OpenTsdbWriter : ConfigObject
{
activation_priority 100;
[config] String host {
default {{{ return "127.0.0.1"; }}}
};

View File

@ -27,6 +27,8 @@ namespace icinga
class PerfdataWriter : ConfigObject
{
activation_priority 100;
[config] String host_perfdata_path {
default {{{ return Application::GetLocalStateDir() + "/spool/icinga2/perfdata/host-perfdata"; }}}
};

View File

@ -28,6 +28,8 @@ namespace icinga
class ApiListener : ConfigObject
{
activation_priority 50;
[config, deprecated] String cert_path;
[config, deprecated] String key_path;
[config, deprecated] String ca_path;

View File

@ -135,6 +135,7 @@ class { return T_CLASS; }
namespace { return T_NAMESPACE; }
code { return T_CODE; }
load_after { return T_LOAD_AFTER; }
activation_priority { return T_ACTIVATION_PRIORITY; }
library { return T_LIBRARY; }
abstract { yylval->num = TAAbstract; return T_CLASS_ATTRIBUTE; }
vararg_constructor { yylval->num = TAVarArgConstructor; return T_CLASS_ATTRIBUTE; }
@ -164,6 +165,7 @@ navigate { yylval->num = FTNavigate; return T_FIELD_ACCESSOR_TYPE; }
\"[^\"]+\" { yylval->text = strdup(yytext + 1); yylval->text[strlen(yylval->text) - 1] = '\0'; return T_STRING; }
\<[^ \>]*\> { yylval->text = strdup(yytext + 1); yylval->text[strlen(yylval->text) - 1] = '\0'; return T_ANGLE_STRING; }
[a-zA-Z_][:a-zA-Z0-9\-_]* { yylval->text = strdup(yytext); return T_IDENTIFIER; }
-?[0-9]+(\.[0-9]+)? { yylval->num = strtod(yytext, NULL); return T_NUMBER; }
. return yytext[0];

View File

@ -61,6 +61,7 @@ using namespace icinga;
%token T_CLASS "class (T_CLASS)"
%token T_CODE "code (T_CODE)"
%token T_LOAD_AFTER "load_after (T_LOAD_AFTER)"
%token T_ACTIVATION_PRIORITY "activation_priority (T_ACTIVATION_PRIORITY)"
%token T_LIBRARY "library (T_LIBRARY)"
%token T_NAMESPACE "namespace (T_NAMESPACE)"
%token T_VALIDATOR "validator (T_VALIDATOR)"
@ -77,6 +78,7 @@ using namespace icinga;
%token T_SET "set (T_SET)"
%token T_DEFAULT "default (T_DEFAULT)"
%token T_FIELD_ACCESSOR_TYPE "field_accessor_type (T_FIELD_ACCESSOR_TYPE)"
%token T_NUMBER "number (T_NUMBER)"
%type <text> T_IDENTIFIER
%type <text> T_STRING
%type <text> T_ANGLE_STRING
@ -106,6 +108,7 @@ using namespace icinga;
%type <rule> validator_rule
%type <rules> validator_rules
%type <validator> validator
%type <num> T_NUMBER
%{
@ -250,6 +253,8 @@ class: class_attribute_list T_CLASS T_IDENTIFIER inherits_specifier type_base_sp
for (const Field& field : *$7) {
if (field.Attributes & FALoadDependency) {
$$->LoadDependencies.push_back(field.Name);
} else if (field.Attributes & FAActivationPriority) {
$$->ActivationPriority = field.Priority;
} else
$$->Fields.push_back(field);
}
@ -380,6 +385,13 @@ class_field: field_attribute_list field_type identifier alternative_name_specifi
std::free($2);
$$ = field;
}
| T_ACTIVATION_PRIORITY T_NUMBER ';'
{
auto *field = new Field();
field->Attributes = FAActivationPriority;
field->Priority = $2;
$$ = field;
}
;
alternative_name_specifier: /* empty */

View File

@ -408,6 +408,14 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
m_Impl << "\t" << "return deps;" << std::endl
<< "}" << std::endl << std::endl;
/* GetActivationPriority */
m_Header << "\t" << "int GetActivationPriority() const override;" << std::endl;
m_Impl << "int TypeImpl<" << klass.Name << ">::GetActivationPriority() const" << std::endl
<< "{" << std::endl
<< "\t" << "return " << klass.ActivationPriority << ";" << std::endl
<< "}" << std::endl << std::endl;
/* RegisterAttributeHandler */
m_Header << "public:" << std::endl
<< "\t" << "void RegisterAttributeHandler(int fieldId, const Type::AttributeHandler& callback) override;" << std::endl;

View File

@ -76,7 +76,8 @@ enum FieldAttribute
FANoUserView = 2048,
FADeprecated = 4096,
FAGetVirtual = 8192,
FASetVirtual = 16384
FASetVirtual = 16384,
FAActivationPriority = 32768
};
struct FieldType
@ -122,6 +123,7 @@ struct Field
std::string NavigationName;
std::string NavigateAccessor;
bool PureNavigateAccessor{false};
int Priority{0};
inline std::string GetFriendlyName() const
{
@ -167,6 +169,7 @@ struct Klass
int Attributes;
std::vector<Field> Fields;
std::vector<std::string> LoadDependencies;
int ActivationPriority{0};
};
enum RuleAttribute