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

Downtime#HasValidConfigOwner(): wait for ScheduledDowntimes #6826

Merged
merged 2 commits into from
Dec 18, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/icinga/downtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ bool Downtime::IsExpired() const

bool Downtime::HasValidConfigOwner() const
{
if (!ScheduledDowntime::AllConfigIsLoaded()) {
return true;
}

String configOwner = GetConfigOwner();
return configOwner.IsEmpty() || GetObject<ScheduledDowntime>(configOwner);
}
Expand Down
9 changes: 9 additions & 0 deletions lib/icinga/scheduleddowntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ void ScheduledDowntime::OnAllConfigLoaded()

if (!GetCheckable())
BOOST_THROW_EXCEPTION(ScriptError("ScheduledDowntime '" + GetName() + "' references a host/service which doesn't exist.", GetDebugInfo()));

m_AllConfigLoaded.store(true);
}

void ScheduledDowntime::Start(bool runtimeCreated)
Expand Down Expand Up @@ -331,3 +333,10 @@ void ScheduledDowntime::ValidateChildOptions(const Lazy<Value>& lvalue, const Va
BOOST_THROW_EXCEPTION(ValidationError(this, { "child_options" }, "Invalid child_options specified"));
}
}

bool ScheduledDowntime::AllConfigIsLoaded()
{
return m_AllConfigLoaded.load();
}

std::atomic<bool> ScheduledDowntime::m_AllConfigLoaded (false);
4 changes: 4 additions & 0 deletions lib/icinga/scheduleddowntime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "icinga/i2-icinga.hpp"
#include "icinga/scheduleddowntime-ti.hpp"
#include "icinga/checkable.hpp"
#include <atomic>

namespace icinga
{
Expand All @@ -47,6 +48,7 @@ class ScheduledDowntime final : public ObjectImpl<ScheduledDowntime>

static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
static bool AllConfigIsLoaded();

void ValidateRanges(const Lazy<Dictionary::Ptr>& lvalue, const ValidationUtils& utils) override;
void ValidateChildOptions(const Lazy<Value>& lvalue, const ValidationUtils& utils) override;
Expand All @@ -62,6 +64,8 @@ class ScheduledDowntime final : public ObjectImpl<ScheduledDowntime>
std::pair<double, double> FindNextSegment();
void CreateNextDowntime();

static std::atomic<bool> m_AllConfigLoaded;

static bool EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule);
static bool EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule);
};
Expand Down