Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add activation priority for config object types #6270

Merged
merged 1 commit into from
May 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/base/filelogger.ti
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace icinga

class FileLogger : StreamLogger
{
activation_priority -100;

[config, required] String path;
};

Expand Down
2 changes: 2 additions & 0 deletions lib/base/sysloglogger.ti
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace icinga

class SyslogLogger : Logger
{
activation_priority -100;

[config] String facility {
default {{{ return "LOG_USER"; }}}
};
Expand Down
5 changes: 5 additions & 0 deletions lib/base/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
1 change: 1 addition & 0 deletions lib/base/type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Type : public Object
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);
Expand Down
2 changes: 2 additions & 0 deletions lib/checker/checkercomponent.ti
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace icinga

class CheckerComponent : ConfigObject
{
activation_priority 100;

[config] int concurrent_checks {
get {{{
return Application::GetMaxConcurrentChecks();
Expand Down
2 changes: 2 additions & 0 deletions lib/compat/checkresultreader.ti
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace icinga

class CheckResultReader : ConfigObject
{
activation_priority 100;

[config] String spool_dir {
default {{{ return Application::GetLocalStateDir() + "/lib/icinga2/spool/checkresults/"; }}}
};
Expand Down
2 changes: 2 additions & 0 deletions lib/compat/compatlogger.ti
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace icinga

class CompatLogger : ConfigObject
{
activation_priority 100;

[config] String log_dir {
default {{{ return Application::GetLocalStateDir() + "/log/icinga2/compat"; }}}
};
Expand Down
2 changes: 2 additions & 0 deletions lib/compat/externalcommandlistener.ti
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace icinga

class ExternalCommandListener : ConfigObject
{
activation_priority 100;

[config] String command_path {
default {{{ return Application::GetRunDir() + "/icinga2/cmd/icinga2.cmd"; }}}
};
Expand Down
2 changes: 2 additions & 0 deletions lib/compat/statusdatawriter.ti
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace icinga

class StatusDataWriter : ConfigObject
{
activation_priority 100;

[config] String status_path {
default {{{ return Application::GetLocalStateDir() + "/cache/icinga2/status.dat"; }}}
};
Expand Down
31 changes: 24 additions & 7 deletions lib/config/configitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions lib/db_ido_mysql/idomysqlconnection.ti
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace icinga

class IdoMysqlConnection : DbConnection
{
activation_priority 100;

[config] String host {
default {{{ return "localhost"; }}}
};
Expand Down
2 changes: 2 additions & 0 deletions lib/db_ido_pgsql/idopgsqlconnection.ti
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace icinga

class IdoPgsqlConnection : DbConnection
{
activation_priority 100;

[config] String host {
default {{{ return "localhost"; }}}
};
Expand Down
2 changes: 2 additions & 0 deletions lib/livestatus/livestatuslistener.ti
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace icinga
{

class LivestatusListener : ConfigObject {
activation_priority 100;

[config] String socket_type {
default {{{ return "unix"; }}}
};
Expand Down
2 changes: 2 additions & 0 deletions lib/notification/notificationcomponent.ti
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace icinga

class NotificationComponent : ConfigObject
{
activation_priority 100;

[config] bool enable_ha (EnableHA) {
default {{{ return true; }}}
};
Expand Down
2 changes: 2 additions & 0 deletions lib/perfdata/elasticsearchwriter.ti
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace icinga

class ElasticsearchWriter : ConfigObject
{
activation_priority 100;

[config, required] String host {
default {{{ return "127.0.0.1"; }}}
};
Expand Down
2 changes: 2 additions & 0 deletions lib/perfdata/gelfwriter.ti
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace icinga

class GelfWriter : ConfigObject
{
activation_priority 100;

[config] String host {
default {{{ return "127.0.0.1"; }}}
};
Expand Down
2 changes: 2 additions & 0 deletions lib/perfdata/graphitewriter.ti
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace icinga

class GraphiteWriter : ConfigObject
{
activation_priority 100;

[config] String host {
default {{{ return "127.0.0.1"; }}}
};
Expand Down
2 changes: 2 additions & 0 deletions lib/perfdata/influxdbwriter.ti
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace icinga

class InfluxdbWriter : ConfigObject
{
activation_priority 100;

[config, required] String host {
default {{{ return "127.0.0.1"; }}}
};
Expand Down
2 changes: 2 additions & 0 deletions lib/perfdata/opentsdbwriter.ti
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace icinga

class OpenTsdbWriter : ConfigObject
{
activation_priority 100;

[config] String host {
default {{{ return "127.0.0.1"; }}}
};
Expand Down
2 changes: 2 additions & 0 deletions lib/perfdata/perfdatawriter.ti
Original file line number Diff line number Diff line change
Expand Up @@ -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"; }}}
};
Expand Down
2 changes: 2 additions & 0 deletions lib/remote/apilistener.ti
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions tools/mkclass/class_lexer.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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];

Expand Down
12 changes: 12 additions & 0 deletions tools/mkclass/class_parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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
Expand Down Expand Up @@ -106,6 +108,7 @@ using namespace icinga;
%type <rule> validator_rule
%type <rules> validator_rules
%type <validator> validator
%type <num> T_NUMBER

%{

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 */
Expand Down
8 changes: 8 additions & 0 deletions tools/mkclass/classcompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion tools/mkclass/classcompiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ enum FieldAttribute
FANoUserView = 2048,
FADeprecated = 4096,
FAGetVirtual = 8192,
FASetVirtual = 16384
FASetVirtual = 16384,
FAActivationPriority = 32768
};

struct FieldType
Expand Down Expand Up @@ -122,6 +123,7 @@ struct Field
std::string NavigationName;
std::string NavigateAccessor;
bool PureNavigateAccessor{false};
int Priority{0};

inline std::string GetFriendlyName() const
{
Expand Down Expand Up @@ -167,6 +169,7 @@ struct Klass
int Attributes;
std::vector<Field> Fields;
std::vector<std::string> LoadDependencies;
int ActivationPriority{0};
};

enum RuleAttribute
Expand Down