mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 14:44:32 +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()) {
|
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")
|
Log(LogDebug, "Checkable")
|
||||||
<< "Dependency group '" << dependencyGroup->GetRedundancyGroupName() << "' have failed for checkable '"
|
<< "Dependency group '" << dependencyGroup->GetRedundancyGroupName() << "' have failed for checkable '"
|
||||||
<< GetName() << "': Marking as unreachable.";
|
<< GetName() << "': Marking as unreachable.";
|
||||||
|
@ -325,14 +325,24 @@ DependencyGroup::State DependencyGroup::GetState(const Checkable* child, Depende
|
|||||||
|
|
||||||
if (IsRedundancyGroup()) {
|
if (IsRedundancyGroup()) {
|
||||||
// The state of a redundancy group is determined by the best state of any parent. If any parent ist reachable,
|
// 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
|
// the redundancy group is reachable, analogously for availability.
|
||||||
// available as reachable = 0 implies available = 0.
|
if (reachable == 0) {
|
||||||
return {reachable > 0, available > 0};
|
return State::Unreachable;
|
||||||
|
} else if (available == 0) {
|
||||||
|
return State::Failed;
|
||||||
|
} else {
|
||||||
|
return State::Ok;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// For dependencies without a redundancy group, dependencies.size() will be 1 in almost all cases. It will only
|
// 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,
|
// 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
|
// all of them have to be reachable/available as they don't provide redundancy.
|
||||||
// unavailable here as well as only reachable parents count towards the number of available parents.
|
if (reachable < dependencies.size()) {
|
||||||
return {reachable == dependencies.size(), available == 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;
|
const String& GetRedundancyGroupName() const;
|
||||||
String GetCompositeKey();
|
String GetCompositeKey();
|
||||||
|
|
||||||
struct State
|
enum class State { Ok, Failed, Unreachable };
|
||||||
{
|
|
||||||
bool Reachable; // Whether the dependency group is reachable.
|
|
||||||
bool OK; // Whether the dependency group is reachable and OK.
|
|
||||||
};
|
|
||||||
|
|
||||||
State GetState(const Checkable* child, DependencyType dt = DependencyState, int rstack = 0) const;
|
State GetState(const Checkable* child, DependencyType dt = DependencyState, int rstack = 0) const;
|
||||||
|
|
||||||
static boost::signals2::signal<void(const Checkable::Ptr&, const DependencyGroup::Ptr&)> OnChildRegistered;
|
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()},
|
{"id", redundancyGroup->GetIcingaDBIdentifier()},
|
||||||
{"environment_id", m_EnvironmentId},
|
{"environment_id", m_EnvironmentId},
|
||||||
{"redundancy_group_id", redundancyGroup->GetIcingaDBIdentifier()},
|
{"redundancy_group_id", redundancyGroup->GetIcingaDBIdentifier()},
|
||||||
{"failed", !state.Reachable || !state.OK},
|
{"failed", state != DependencyGroup::State::Ok},
|
||||||
{"is_reachable", state.Reachable},
|
{"is_reachable", state != DependencyGroup::State::Unreachable},
|
||||||
{"last_state_change", TimestampToMilliseconds(Utility::GetTime())},
|
{"last_state_change", TimestampToMilliseconds(Utility::GetTime())},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user