mirror of
https://github.com/Icinga/icinga2.git
synced 2025-04-08 17:05:25 +02:00
This commit removes a distinction in how dependency objects are checked for cycles in the resulting graph depending on whether they are part of the initially loaded configuration during process startup or as part of a runtime update. The DependencyCycleChecker helper class is extended with a mechanism that allows additional dependencies to be considered during the cycle search. This allows using it to check for cycles before actually registering the dependencies with the checkables. The aforementioned case-distinction for initial/runtime-update config is removed by making use of the newly added BeforeOnAllConfigLoaded signal to perform the cycle check at once for each batch of dependencies inside ConfigItem::CommitNewItems() for both cases now. During the initial config loading, there can be multiple batches of dependencies as objects from apply rules are created separately, so parts of the dependency graph might be visited multiple times now, however that is limited to a minimum as only parts of the graph that are reachable from the newly added dependencies are searched.
66 lines
1.6 KiB
C++
66 lines
1.6 KiB
C++
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
|
|
|
#ifndef DEPENDENCY_H
|
|
#define DEPENDENCY_H
|
|
|
|
#include "icinga/i2-icinga.hpp"
|
|
#include "icinga/dependency-ti.hpp"
|
|
#include "config/configitem.hpp"
|
|
|
|
namespace icinga
|
|
{
|
|
|
|
class ApplyRule;
|
|
struct ScriptFrame;
|
|
class Host;
|
|
class Service;
|
|
|
|
/**
|
|
* A service dependency..
|
|
*
|
|
* @ingroup icinga
|
|
*/
|
|
class Dependency final : public ObjectImpl<Dependency>
|
|
{
|
|
public:
|
|
static void StaticInitialize();
|
|
|
|
DECLARE_OBJECT(Dependency);
|
|
DECLARE_OBJECTNAME(Dependency);
|
|
|
|
intrusive_ptr<Checkable> GetParent() const;
|
|
intrusive_ptr<Checkable> GetChild() const;
|
|
|
|
TimePeriod::Ptr GetPeriod() const;
|
|
|
|
bool IsAvailable(DependencyType dt) const;
|
|
|
|
void ValidateStates(const Lazy<Array::Ptr>& lvalue, const ValidationUtils& utils) override;
|
|
|
|
static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
|
|
static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
|
|
|
|
/* Note: Only use them for unit test mocks. Prefer InitChildParentReferences(). */
|
|
void SetParent(intrusive_ptr<Checkable> parent);
|
|
void SetChild(intrusive_ptr<Checkable> child);
|
|
|
|
protected:
|
|
void OnConfigLoaded() override;
|
|
void OnAllConfigLoaded() override;
|
|
void Stop(bool runtimeRemoved) override;
|
|
void InitChildParentReferences();
|
|
|
|
private:
|
|
Checkable::Ptr m_Parent;
|
|
Checkable::Ptr m_Child;
|
|
|
|
static bool EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule, bool skipFilter);
|
|
static bool EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule, bool skipFilter = false);
|
|
|
|
static void BeforeOnAllConfigLoadedHandler(const ConfigItems& items);
|
|
};
|
|
|
|
}
|
|
|
|
#endif /* DEPENDENCY_H */
|