2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2012-06-14 11:23:25 +02:00
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "checker/checkercomponent.hpp"
|
2018-01-18 13:50:38 +01:00
|
|
|
#include "checker/checkercomponent-ti.cpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "icinga/icingaapplication.hpp"
|
|
|
|
#include "icinga/cib.hpp"
|
|
|
|
#include "remote/apilistener.hpp"
|
2019-04-15 16:56:30 +02:00
|
|
|
#include "base/configuration.hpp"
|
2015-08-15 20:28:05 +02:00
|
|
|
#include "base/configtype.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "base/objectlock.hpp"
|
|
|
|
#include "base/utility.hpp"
|
2017-05-15 15:51:39 +02:00
|
|
|
#include "base/perfdatavalue.hpp"
|
2014-10-19 14:21:12 +02:00
|
|
|
#include "base/logger.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "base/exception.hpp"
|
|
|
|
#include "base/convert.hpp"
|
|
|
|
#include "base/statsfunction.hpp"
|
2021-02-02 10:16:04 +01:00
|
|
|
#include <chrono>
|
2012-06-14 11:23:25 +02:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2013-03-12 13:45:54 +01:00
|
|
|
REGISTER_TYPE(CheckerComponent);
|
2014-02-18 10:53:44 +01:00
|
|
|
|
2015-09-21 11:44:58 +02:00
|
|
|
REGISTER_STATSFUNCTION(CheckerComponent, &CheckerComponent::StatsFunc);
|
2014-02-17 16:34:18 +01:00
|
|
|
|
2015-02-07 22:36:17 +01:00
|
|
|
void CheckerComponent::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
|
2014-02-17 16:34:18 +01:00
|
|
|
{
|
2018-01-11 11:17:38 +01:00
|
|
|
DictionaryData nodes;
|
2014-02-18 10:53:44 +01:00
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const CheckerComponent::Ptr& checker : ConfigType::GetObjectsByType<CheckerComponent>()) {
|
2014-04-03 15:36:13 +02:00
|
|
|
unsigned long idle = checker->GetIdleCheckables();
|
|
|
|
unsigned long pending = checker->GetPendingCheckables();
|
2014-02-18 10:53:44 +01:00
|
|
|
|
2018-01-11 11:17:38 +01:00
|
|
|
nodes.emplace_back(checker->GetName(), new Dictionary({
|
|
|
|
{ "idle", idle },
|
|
|
|
{ "pending", pending }
|
|
|
|
}));
|
2014-02-18 10:53:44 +01:00
|
|
|
|
|
|
|
String perfdata_prefix = "checkercomponent_" + checker->GetName() + "_";
|
2014-11-08 21:17:16 +01:00
|
|
|
perfdata->Add(new PerfdataValue(perfdata_prefix + "idle", Convert::ToDouble(idle)));
|
|
|
|
perfdata->Add(new PerfdataValue(perfdata_prefix + "pending", Convert::ToDouble(pending)));
|
2014-02-18 10:53:44 +01:00
|
|
|
}
|
|
|
|
|
2018-01-11 11:17:38 +01:00
|
|
|
status->Set("checkercomponent", new Dictionary(std::move(nodes)));
|
2014-02-17 16:34:18 +01:00
|
|
|
}
|
2013-03-12 13:45:54 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void CheckerComponent::OnConfigLoaded()
|
2012-06-14 11:23:25 +02:00
|
|
|
{
|
2021-01-18 14:29:05 +01:00
|
|
|
ConfigObject::OnActiveChanged.connect([this](const ConfigObject::Ptr& object, const Value&) {
|
|
|
|
ObjectHandler(object);
|
|
|
|
});
|
|
|
|
ConfigObject::OnPausedChanged.connect([this](const ConfigObject::Ptr& object, const Value&) {
|
|
|
|
ObjectHandler(object);
|
|
|
|
});
|
|
|
|
|
|
|
|
Checkable::OnNextCheckChanged.connect([this](const Checkable::Ptr& checkable, const Value&) {
|
|
|
|
NextCheckChangedHandler(checkable);
|
|
|
|
});
|
2013-11-28 20:56:21 +01:00
|
|
|
}
|
|
|
|
|
2015-08-20 17:18:48 +02:00
|
|
|
void CheckerComponent::Start(bool runtimeCreated)
|
2013-11-28 20:56:21 +01:00
|
|
|
{
|
2015-08-20 17:18:48 +02:00
|
|
|
ObjectImpl<CheckerComponent>::Start(runtimeCreated);
|
2012-08-03 23:03:58 +02:00
|
|
|
|
2017-02-08 14:53:52 +01:00
|
|
|
Log(LogInformation, "CheckerComponent")
|
2017-12-19 15:50:05 +01:00
|
|
|
<< "'" << GetName() << "' started.";
|
2017-02-08 14:53:52 +01:00
|
|
|
|
|
|
|
|
2021-01-18 14:29:05 +01:00
|
|
|
m_Thread = std::thread([this]() { CheckThreadProc(); });
|
2012-06-14 11:23:25 +02:00
|
|
|
|
2023-03-21 10:30:15 +01:00
|
|
|
m_ResultTimer = Timer::Create();
|
2012-06-17 23:10:03 +02:00
|
|
|
m_ResultTimer->SetInterval(5);
|
2021-01-18 14:29:05 +01:00
|
|
|
m_ResultTimer->OnTimerExpired.connect([this](const Timer * const&) { ResultTimerHandler(); });
|
2012-06-17 20:35:56 +02:00
|
|
|
m_ResultTimer->Start();
|
2012-06-14 11:23:25 +02:00
|
|
|
}
|
|
|
|
|
2015-08-20 17:18:48 +02:00
|
|
|
void CheckerComponent::Stop(bool runtimeRemoved)
|
2012-06-14 11:23:25 +02:00
|
|
|
{
|
2013-02-19 23:02:08 +01:00
|
|
|
{
|
2021-02-02 10:16:04 +01:00
|
|
|
std::unique_lock<std::mutex> lock(m_Mutex);
|
2013-02-19 23:02:08 +01:00
|
|
|
m_Stopped = true;
|
|
|
|
m_CV.notify_all();
|
|
|
|
}
|
|
|
|
|
2014-03-17 09:04:19 +01:00
|
|
|
m_ResultTimer->Stop();
|
2013-02-19 23:02:08 +01:00
|
|
|
m_Thread.join();
|
2014-04-16 15:01:31 +02:00
|
|
|
|
2019-01-24 13:55:17 +01:00
|
|
|
Log(LogInformation, "CheckerComponent")
|
|
|
|
<< "'" << GetName() << "' stopped.";
|
|
|
|
|
2015-08-20 17:18:48 +02:00
|
|
|
ObjectImpl<CheckerComponent>::Stop(runtimeRemoved);
|
2012-06-14 11:23:25 +02:00
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void CheckerComponent::CheckThreadProc()
|
2012-06-14 11:23:25 +02:00
|
|
|
{
|
2013-08-30 10:19:32 +02:00
|
|
|
Utility::SetThreadName("Check Scheduler");
|
2019-04-15 16:56:30 +02:00
|
|
|
IcingaApplication::Ptr icingaApp = IcingaApplication::GetInstance();
|
2013-08-30 10:19:32 +02:00
|
|
|
|
2021-02-02 10:16:04 +01:00
|
|
|
std::unique_lock<std::mutex> lock(m_Mutex);
|
2013-02-17 19:14:34 +01:00
|
|
|
|
2013-02-24 01:10:34 +01:00
|
|
|
for (;;) {
|
2014-04-03 15:36:13 +02:00
|
|
|
typedef boost::multi_index::nth_index<CheckableSet, 1>::type CheckTimeView;
|
|
|
|
CheckTimeView& idx = boost::get<1>(m_IdleCheckables);
|
2013-02-17 19:14:34 +01:00
|
|
|
|
2013-02-21 16:12:50 +01:00
|
|
|
while (idx.begin() == idx.end() && !m_Stopped)
|
|
|
|
m_CV.wait(lock);
|
2012-08-04 13:49:25 +02:00
|
|
|
|
2013-02-21 16:12:50 +01:00
|
|
|
if (m_Stopped)
|
|
|
|
break;
|
2013-02-19 23:02:08 +01:00
|
|
|
|
2016-08-27 19:56:12 +02:00
|
|
|
auto it = idx.begin();
|
2016-07-28 12:50:48 +02:00
|
|
|
CheckableScheduleInfo csi = *it;
|
2013-02-17 19:14:34 +01:00
|
|
|
|
2016-07-28 12:50:48 +02:00
|
|
|
double wait = csi.NextCheck - Utility::GetTime();
|
2013-02-11 13:05:08 +01:00
|
|
|
|
2019-04-15 16:56:30 +02:00
|
|
|
//#ifdef I2_DEBUG
|
|
|
|
// Log(LogDebug, "CheckerComponent")
|
|
|
|
// << "Pending checks " << Checkable::GetPendingChecks()
|
|
|
|
// << " vs. max concurrent checks " << icingaApp->GetMaxConcurrentChecks() << ".";
|
|
|
|
//#endif /* I2_DEBUG */
|
|
|
|
|
|
|
|
if (Checkable::GetPendingChecks() >= icingaApp->GetMaxConcurrentChecks())
|
2016-05-18 14:30:36 +02:00
|
|
|
wait = 0.5;
|
|
|
|
|
|
|
|
if (wait > 0) {
|
2013-02-18 14:40:24 +01:00
|
|
|
/* Wait for the next check. */
|
2021-02-02 10:16:04 +01:00
|
|
|
m_CV.wait_for(lock, std::chrono::duration<double>(wait));
|
2013-02-18 14:40:24 +01:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-07-28 12:50:48 +02:00
|
|
|
Checkable::Ptr checkable = csi.Object;
|
|
|
|
|
2014-04-05 19:02:45 +02:00
|
|
|
m_IdleCheckables.erase(checkable);
|
2012-06-17 22:46:40 +02:00
|
|
|
|
2014-04-05 19:02:45 +02:00
|
|
|
bool forced = checkable->GetForceNextCheck();
|
2013-03-13 16:04:53 +01:00
|
|
|
bool check = true;
|
2023-02-01 16:25:56 +01:00
|
|
|
bool notifyNextCheck = false;
|
2013-09-12 10:03:48 +02:00
|
|
|
|
2013-09-10 09:26:46 +02:00
|
|
|
if (!forced) {
|
2014-04-05 19:02:45 +02:00
|
|
|
if (!checkable->IsReachable(DependencyCheckExecution)) {
|
2014-10-20 10:09:57 +02:00
|
|
|
Log(LogNotice, "CheckerComponent")
|
2017-12-19 15:50:05 +01:00
|
|
|
<< "Skipping check for object '" << checkable->GetName() << "': Dependency failed.";
|
2023-02-01 16:25:56 +01:00
|
|
|
|
2014-02-27 11:05:55 +01:00
|
|
|
check = false;
|
2023-02-01 16:25:56 +01:00
|
|
|
notifyNextCheck = true;
|
2014-02-27 11:05:55 +01:00
|
|
|
}
|
|
|
|
|
2014-04-17 11:29:47 +02:00
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2019-04-15 16:56:30 +02:00
|
|
|
if (host && !service && (!checkable->GetEnableActiveChecks() || !icingaApp->GetEnableHostChecks())) {
|
2014-10-20 10:09:57 +02:00
|
|
|
Log(LogNotice, "CheckerComponent")
|
2017-12-19 15:50:05 +01:00
|
|
|
<< "Skipping check for host '" << host->GetName() << "': active host checks are disabled";
|
2014-04-17 11:29:47 +02:00
|
|
|
check = false;
|
|
|
|
}
|
2019-04-15 16:56:30 +02:00
|
|
|
if (host && service && (!checkable->GetEnableActiveChecks() || !icingaApp->GetEnableServiceChecks())) {
|
2014-10-20 10:09:57 +02:00
|
|
|
Log(LogNotice, "CheckerComponent")
|
2017-12-19 15:50:05 +01:00
|
|
|
<< "Skipping check for service '" << service->GetName() << "': active service checks are disabled";
|
2013-03-13 16:04:53 +01:00
|
|
|
check = false;
|
|
|
|
}
|
|
|
|
|
2014-04-05 19:02:45 +02:00
|
|
|
TimePeriod::Ptr tp = checkable->GetCheckPeriod();
|
2013-03-13 16:04:53 +01:00
|
|
|
|
|
|
|
if (tp && !tp->IsInside(Utility::GetTime())) {
|
2014-10-20 10:09:57 +02:00
|
|
|
Log(LogNotice, "CheckerComponent")
|
2017-12-19 15:50:05 +01:00
|
|
|
<< "Skipping check for object '" << checkable->GetName()
|
|
|
|
<< "': not in check period '" << tp->GetName() << "'";
|
2023-02-01 16:25:56 +01:00
|
|
|
|
2013-03-13 16:04:53 +01:00
|
|
|
check = false;
|
2023-02-01 16:25:56 +01:00
|
|
|
notifyNextCheck = true;
|
2013-03-13 16:04:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-05 19:02:45 +02:00
|
|
|
/* reschedule the checkable if checks are disabled */
|
2013-03-13 16:04:53 +01:00
|
|
|
if (!check) {
|
2016-07-28 12:50:48 +02:00
|
|
|
m_IdleCheckables.insert(GetCheckableScheduleInfo(checkable));
|
2013-11-28 20:55:10 +01:00
|
|
|
lock.unlock();
|
|
|
|
|
2018-07-02 16:17:33 +02:00
|
|
|
Log(LogDebug, "CheckerComponent")
|
|
|
|
<< "Checks for checkable '" << checkable->GetName() << "' are disabled. Rescheduling check.";
|
|
|
|
|
2014-04-05 19:02:45 +02:00
|
|
|
checkable->UpdateNextCheck();
|
2013-01-22 16:01:08 +01:00
|
|
|
|
2023-02-01 16:25:56 +01:00
|
|
|
if (notifyNextCheck) {
|
|
|
|
// Trigger update event for Icinga DB
|
|
|
|
Checkable::OnNextCheckUpdated(checkable);
|
|
|
|
}
|
|
|
|
|
2013-11-28 20:55:10 +01:00
|
|
|
lock.lock();
|
2013-01-22 16:01:08 +01:00
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
continue;
|
2013-01-22 16:01:08 +01:00
|
|
|
}
|
|
|
|
|
2018-07-02 16:17:33 +02:00
|
|
|
|
|
|
|
csi = GetCheckableScheduleInfo(checkable);
|
|
|
|
|
|
|
|
Log(LogDebug, "CheckerComponent")
|
|
|
|
<< "Scheduling info for checkable '" << checkable->GetName() << "' ("
|
|
|
|
<< Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", checkable->GetNextCheck()) << "): Object '"
|
|
|
|
<< csi.Object->GetName() << "', Next Check: "
|
|
|
|
<< Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", csi.NextCheck) << "(" << csi.NextCheck << ").";
|
|
|
|
|
|
|
|
m_PendingCheckables.insert(csi);
|
2013-03-06 13:01:51 +01:00
|
|
|
|
|
|
|
lock.unlock();
|
|
|
|
|
2013-09-10 09:26:46 +02:00
|
|
|
if (forced) {
|
2014-04-05 19:02:45 +02:00
|
|
|
ObjectLock olock(checkable);
|
|
|
|
checkable->SetForceNextCheck(false);
|
2013-03-04 15:52:42 +01:00
|
|
|
}
|
2013-01-23 15:25:00 +01:00
|
|
|
|
2014-10-20 10:09:57 +02:00
|
|
|
Log(LogDebug, "CheckerComponent")
|
2017-12-19 15:50:05 +01:00
|
|
|
<< "Executing check for '" << checkable->GetName() << "'";
|
2012-06-17 20:35:56 +02:00
|
|
|
|
2016-08-29 14:12:29 +02:00
|
|
|
Checkable::IncreasePendingChecks();
|
|
|
|
|
2021-01-18 14:29:05 +01:00
|
|
|
/*
|
|
|
|
* Explicitly use CheckerComponent::Ptr to keep the reference counted while the
|
|
|
|
* callback is active and making it crash safe
|
|
|
|
*/
|
|
|
|
CheckerComponent::Ptr checkComponent(this);
|
|
|
|
|
|
|
|
Utility::QueueAsyncCallback([this, checkComponent, checkable]() { ExecuteCheckHelper(checkable); });
|
2013-03-06 13:01:51 +01:00
|
|
|
|
|
|
|
lock.lock();
|
2012-10-15 08:52:31 +02:00
|
|
|
}
|
2012-06-14 11:23:25 +02:00
|
|
|
}
|
|
|
|
|
2014-04-05 19:02:45 +02:00
|
|
|
void CheckerComponent::ExecuteCheckHelper(const Checkable::Ptr& checkable)
|
2012-06-17 20:35:56 +02:00
|
|
|
{
|
2013-03-25 18:36:15 +01:00
|
|
|
try {
|
2014-04-05 19:02:45 +02:00
|
|
|
checkable->ExecuteCheck();
|
2013-03-25 18:36:15 +01:00
|
|
|
} catch (const std::exception& ex) {
|
2014-11-08 21:17:16 +01:00
|
|
|
CheckResult::Ptr cr = new CheckResult();
|
2014-04-22 19:02:45 +02:00
|
|
|
cr->SetState(ServiceUnknown);
|
|
|
|
|
2018-07-21 10:38:09 +02:00
|
|
|
String output = "Exception occurred while checking '" + checkable->GetName() + "': " + DiagnosticInformation(ex);
|
2014-04-22 19:02:45 +02:00
|
|
|
cr->SetOutput(output);
|
|
|
|
|
|
|
|
double now = Utility::GetTime();
|
|
|
|
cr->SetScheduleStart(now);
|
|
|
|
cr->SetScheduleEnd(now);
|
|
|
|
cr->SetExecutionStart(now);
|
|
|
|
cr->SetExecutionEnd(now);
|
|
|
|
|
|
|
|
checkable->ProcessCheckResult(cr);
|
|
|
|
|
|
|
|
Log(LogCritical, "checker", output);
|
2013-03-25 18:36:15 +01:00
|
|
|
}
|
2016-05-12 13:46:22 +02:00
|
|
|
|
2016-08-29 14:12:29 +02:00
|
|
|
Checkable::DecreasePendingChecks();
|
|
|
|
|
2016-05-12 13:46:22 +02:00
|
|
|
{
|
2021-02-02 10:16:04 +01:00
|
|
|
std::unique_lock<std::mutex> lock(m_Mutex);
|
2016-05-12 13:46:22 +02:00
|
|
|
|
|
|
|
/* remove the object from the list of pending objects; if it's not in the
|
|
|
|
* list this was a manual (i.e. forced) check and we must not re-add the
|
|
|
|
* object to the list because it's already there. */
|
2016-08-27 19:56:12 +02:00
|
|
|
auto it = m_PendingCheckables.find(checkable);
|
|
|
|
|
2016-05-12 13:46:22 +02:00
|
|
|
if (it != m_PendingCheckables.end()) {
|
|
|
|
m_PendingCheckables.erase(it);
|
|
|
|
|
|
|
|
if (checkable->IsActive())
|
2016-07-28 12:50:48 +02:00
|
|
|
m_IdleCheckables.insert(GetCheckableScheduleInfo(checkable));
|
2016-05-12 13:46:22 +02:00
|
|
|
|
|
|
|
m_CV.notify_all();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Log(LogDebug, "CheckerComponent")
|
2017-12-19 15:50:05 +01:00
|
|
|
<< "Check finished for object '" << checkable->GetName() << "'";
|
2012-07-13 21:00:54 +02:00
|
|
|
}
|
2012-06-20 15:23:31 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void CheckerComponent::ResultTimerHandler()
|
2012-07-13 21:00:54 +02:00
|
|
|
{
|
2013-03-16 21:18:53 +01:00
|
|
|
std::ostringstream msgbuf;
|
2013-02-17 19:14:34 +01:00
|
|
|
|
|
|
|
{
|
2021-02-02 10:16:04 +01:00
|
|
|
std::unique_lock<std::mutex> lock(m_Mutex);
|
2013-02-17 19:14:34 +01:00
|
|
|
|
2014-05-26 20:56:34 +02:00
|
|
|
msgbuf << "Pending checkables: " << m_PendingCheckables.size() << "; Idle checkables: " << m_IdleCheckables.size() << "; Checks/s: "
|
2017-12-19 15:50:05 +01:00
|
|
|
<< (CIB::GetActiveHostChecksStatistics(60) + CIB::GetActiveServiceChecksStatistics(60)) / 60.0;
|
2013-02-17 19:14:34 +01:00
|
|
|
}
|
|
|
|
|
2014-05-28 13:03:44 +02:00
|
|
|
Log(LogNotice, "CheckerComponent", msgbuf.str());
|
2012-06-17 20:35:56 +02:00
|
|
|
}
|
|
|
|
|
2015-08-15 20:28:05 +02:00
|
|
|
void CheckerComponent::ObjectHandler(const ConfigObject::Ptr& object)
|
2012-06-14 11:23:25 +02:00
|
|
|
{
|
2015-03-20 08:15:07 +01:00
|
|
|
Checkable::Ptr checkable = dynamic_pointer_cast<Checkable>(object);
|
2013-02-21 16:12:50 +01:00
|
|
|
|
2015-03-20 08:15:07 +01:00
|
|
|
if (!checkable)
|
|
|
|
return;
|
2013-08-20 11:06:04 +02:00
|
|
|
|
2015-02-09 08:50:17 +01:00
|
|
|
Zone::Ptr zone = Zone::GetByName(checkable->GetZoneName());
|
2014-05-03 20:02:22 +02:00
|
|
|
bool same_zone = (!zone || Zone::GetLocalZone() == zone);
|
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
{
|
2021-02-02 10:16:04 +01:00
|
|
|
std::unique_lock<std::mutex> lock(m_Mutex);
|
2012-06-14 16:09:04 +02:00
|
|
|
|
2014-05-09 11:32:24 +02:00
|
|
|
if (object->IsActive() && !object->IsPaused() && same_zone) {
|
2014-04-05 19:02:45 +02:00
|
|
|
if (m_PendingCheckables.find(checkable) != m_PendingCheckables.end())
|
2013-09-13 07:49:12 +02:00
|
|
|
return;
|
2012-06-14 16:09:04 +02:00
|
|
|
|
2016-07-28 12:50:48 +02:00
|
|
|
m_IdleCheckables.insert(GetCheckableScheduleInfo(checkable));
|
2013-09-13 07:49:12 +02:00
|
|
|
} else {
|
2014-04-05 19:02:45 +02:00
|
|
|
m_IdleCheckables.erase(checkable);
|
|
|
|
m_PendingCheckables.erase(checkable);
|
2013-09-13 07:49:12 +02:00
|
|
|
}
|
2013-08-20 11:06:04 +02:00
|
|
|
|
2013-02-18 14:40:24 +01:00
|
|
|
m_CV.notify_all();
|
2012-07-17 12:57:21 +02:00
|
|
|
}
|
2012-06-14 11:23:25 +02:00
|
|
|
}
|
|
|
|
|
2016-07-28 12:50:48 +02:00
|
|
|
CheckableScheduleInfo CheckerComponent::GetCheckableScheduleInfo(const Checkable::Ptr& checkable)
|
|
|
|
{
|
|
|
|
CheckableScheduleInfo csi;
|
|
|
|
csi.Object = checkable;
|
|
|
|
csi.NextCheck = checkable->GetNextCheck();
|
|
|
|
return csi;
|
|
|
|
}
|
|
|
|
|
2014-04-05 19:02:45 +02:00
|
|
|
void CheckerComponent::NextCheckChangedHandler(const Checkable::Ptr& checkable)
|
2013-01-22 12:44:23 +01:00
|
|
|
{
|
2021-02-02 10:16:04 +01:00
|
|
|
std::unique_lock<std::mutex> lock(m_Mutex);
|
2013-02-21 16:12:50 +01:00
|
|
|
|
2014-04-05 19:02:45 +02:00
|
|
|
/* remove and re-insert the object from the set in order to force an index update */
|
2014-04-03 15:36:13 +02:00
|
|
|
typedef boost::multi_index::nth_index<CheckableSet, 0>::type CheckableView;
|
|
|
|
CheckableView& idx = boost::get<0>(m_IdleCheckables);
|
2013-02-17 19:14:34 +01:00
|
|
|
|
2016-08-27 19:56:12 +02:00
|
|
|
auto it = idx.find(checkable);
|
|
|
|
|
2013-02-21 16:12:50 +01:00
|
|
|
if (it == idx.end())
|
|
|
|
return;
|
2013-01-22 12:44:23 +01:00
|
|
|
|
2014-04-05 19:02:45 +02:00
|
|
|
idx.erase(checkable);
|
2016-07-28 12:50:48 +02:00
|
|
|
|
|
|
|
CheckableScheduleInfo csi = GetCheckableScheduleInfo(checkable);
|
|
|
|
idx.insert(csi);
|
|
|
|
|
2013-02-21 16:12:50 +01:00
|
|
|
m_CV.notify_all();
|
2013-01-22 12:44:23 +01:00
|
|
|
}
|
2014-02-18 10:53:44 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
unsigned long CheckerComponent::GetIdleCheckables()
|
2014-02-18 10:53:44 +01:00
|
|
|
{
|
2021-02-02 10:16:04 +01:00
|
|
|
std::unique_lock<std::mutex> lock(m_Mutex);
|
2014-02-18 10:53:44 +01:00
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
return m_IdleCheckables.size();
|
2014-02-18 10:53:44 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
unsigned long CheckerComponent::GetPendingCheckables()
|
2014-02-18 10:53:44 +01:00
|
|
|
{
|
2021-02-02 10:16:04 +01:00
|
|
|
std::unique_lock<std::mutex> lock(m_Mutex);
|
2014-02-18 10:53:44 +01:00
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
return m_PendingCheckables.size();
|
2014-02-18 10:53:44 +01:00
|
|
|
}
|