From 7e954aff03aa3ee9fba13fc403a27489b4c78a15 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 2 Sep 2015 13:31:47 +0200 Subject: [PATCH] Keep machine stats even when a machine is removed from the machines file This is important for the Hydra provisioner, since it needs to be able to see whether a disabled machine still has jobs running on it. --- src/hydra-queue-runner/dispatcher.cc | 1 + src/hydra-queue-runner/hydra-queue-runner.cc | 9 ++++++++- src/hydra-queue-runner/state.hh | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/hydra-queue-runner/dispatcher.cc b/src/hydra-queue-runner/dispatcher.cc index b5f65a78..2b03cc88 100644 --- a/src/hydra-queue-runner/dispatcher.cc +++ b/src/hydra-queue-runner/dispatcher.cc @@ -89,6 +89,7 @@ system_time State::doDispatch() auto machines_(machines.lock()); for (auto & m : *machines_) { auto info(m.second->state->connectInfo.lock()); + if (!m.second->enabled) continue; if (info->consecutiveFailures && info->disabledUntil > now) { if (info->disabledUntil < sleepUntil) sleepUntil = info->disabledUntil; diff --git a/src/hydra-queue-runner/hydra-queue-runner.cc b/src/hydra-queue-runner/hydra-queue-runner.cc index 553c80de..66bdb855 100644 --- a/src/hydra-queue-runner/hydra-queue-runner.cc +++ b/src/hydra-queue-runner/hydra-queue-runner.cc @@ -74,8 +74,14 @@ void State::parseMachines(const std::string & contents) } for (auto & m : oldMachines) - if (newMachines.find(m.first) == newMachines.end()) + if (newMachines.find(m.first) == newMachines.end()) { printMsg(lvlInfo, format("removing machine ‘%1%’") % m.first); + /* Add a disabled Machine object to make sure stats are + maintained. */ + auto machine = std::make_shared(*(m.second)); + machine->enabled = false; + newMachines[m.first] = machine; + } auto machines_(machines.lock()); *machines_ = newMachines; @@ -489,6 +495,7 @@ void State::dumpStatus(Connection & conn, bool log) auto & s(m->state); nested.attr(m->sshName); JSONObject nested2(out); + nested2.attr("enabled", m->enabled); nested2.attr("currentJobs", s->currentJobs); if (s->currentJobs == 0) nested2.attr("idleSince", s->idleSince); diff --git a/src/hydra-queue-runner/state.hh b/src/hydra-queue-runner/state.hh index 5e1bcd0b..29350bd9 100644 --- a/src/hydra-queue-runner/state.hh +++ b/src/hydra-queue-runner/state.hh @@ -201,6 +201,8 @@ struct Machine { typedef std::shared_ptr ptr; + bool enabled{true}; + std::string sshName, sshKey; std::set systemTypes, supportedFeatures, mandatoryFeatures; unsigned int maxJobs = 1;