mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-24 06:05:01 +02:00
Make DependencyGroup::State an enum
The previous struct used two bools to represent three useful states. Make this more explicit by having these three states as an enum.
This commit is contained in:
parent
864e2aaae0
commit
065118bc22
@ -206,7 +206,7 @@ bool Checkable::IsReachable(DependencyType dt, int rstack) const
|
||||
}
|
||||
|
||||
for (auto& dependencyGroup : GetDependencyGroups()) {
|
||||
if (auto state(dependencyGroup->GetState(this, dt, rstack + 1)); !state.Reachable || !state.OK) {
|
||||
if (auto state(dependencyGroup->GetState(this, dt, rstack + 1)); state != DependencyGroup::State::Ok) {
|
||||
Log(LogDebug, "Checkable")
|
||||
<< "Dependency group '" << dependencyGroup->GetRedundancyGroupName() << "' have failed for checkable '"
|
||||
<< GetName() << "': Marking as unreachable.";
|
||||
|
@ -325,14 +325,24 @@ DependencyGroup::State DependencyGroup::GetState(const Checkable* child, Depende
|
||||
|
||||
if (IsRedundancyGroup()) {
|
||||
// The state of a redundancy group is determined by the best state of any parent. If any parent ist reachable,
|
||||
// the redundancy group is reachable, analogously for availability. Note that an unreachable group cannot be
|
||||
// available as reachable = 0 implies available = 0.
|
||||
return {reachable > 0, available > 0};
|
||||
// the redundancy group is reachable, analogously for availability.
|
||||
if (reachable == 0) {
|
||||
return State::Unreachable;
|
||||
} else if (available == 0) {
|
||||
return State::Failed;
|
||||
} else {
|
||||
return State::Ok;
|
||||
}
|
||||
} else {
|
||||
// For dependencies without a redundancy group, dependencies.size() will be 1 in almost all cases. It will only
|
||||
// contain more elements if there are duplicate dependency config objects between two checkables. In this case,
|
||||
// all of them have to be reachable or available as they don't provide redundancy. Note that unreachable implies
|
||||
// unavailable here as well as only reachable parents count towards the number of available parents.
|
||||
return {reachable == dependencies.size(), available == dependencies.size()};
|
||||
// all of them have to be reachable/available as they don't provide redundancy.
|
||||
if (reachable < dependencies.size()) {
|
||||
return State::Unreachable;
|
||||
} else if (available < dependencies.size()) {
|
||||
return State::Failed;
|
||||
} else {
|
||||
return State::Ok;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -163,12 +163,7 @@ public:
|
||||
const String& GetRedundancyGroupName() const;
|
||||
String GetCompositeKey();
|
||||
|
||||
struct State
|
||||
{
|
||||
bool Reachable; // Whether the dependency group is reachable.
|
||||
bool OK; // Whether the dependency group is reachable and OK.
|
||||
};
|
||||
|
||||
enum class State { Ok, Failed, Unreachable };
|
||||
State GetState(const Checkable* child, DependencyType dt = DependencyState, int rstack = 0) const;
|
||||
|
||||
static boost::signals2::signal<void(const Checkable::Ptr&, const DependencyGroup::Ptr&)> OnChildRegistered;
|
||||
|
@ -213,8 +213,8 @@ Dictionary::Ptr IcingaDB::SerializeRedundancyGroupState(const Checkable::Ptr& ch
|
||||
{"id", redundancyGroup->GetIcingaDBIdentifier()},
|
||||
{"environment_id", m_EnvironmentId},
|
||||
{"redundancy_group_id", redundancyGroup->GetIcingaDBIdentifier()},
|
||||
{"failed", !state.Reachable || !state.OK},
|
||||
{"is_reachable", state.Reachable},
|
||||
{"failed", state != DependencyGroup::State::Ok},
|
||||
{"is_reachable", state != DependencyGroup::State::Unreachable},
|
||||
{"last_state_change", TimestampToMilliseconds(Utility::GetTime())},
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user