From f9426f365b210655c7bf255dd0269358c2fb30ee Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 4 Mar 2013 15:37:20 -0500 Subject: [PATCH] machine-status: Read /etc/nix.machines instead of using the BuildMachines table --- src/lib/Hydra/Controller/Root.pm | 14 ++++++++------ src/lib/Hydra/Helper/Nix.pm | 30 +++++++++++++++++++++++++++++- src/root/machine-status.tt | 16 ++++++++++------ 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 6a2af005..f8e9cc38 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -74,12 +74,14 @@ sub status :Local { sub machines :Local Args(0) { my ($self, $c) = @_; - $c->stash->{machines} = [$c->model('DB::BuildMachines')->search( - {}, - { order_by => ["enabled DESC", "hostname"] - , '+select' => ["(select bs.stoptime from buildsteps as bs where bs.machine = (me.username || '\@' || me.hostname) and not bs.stoptime is null order by bs.stoptime desc limit 1)"] - , '+as' => ['idle'] - })]; + my $machines = getMachines; + my $idles = $c->model('DB::BuildSteps')->search( + { stoptime => { '!=', undef } }, + { select => [ 'machine', { max => 'stoptime', -as => 'max_stoptime' }], group_by => "machine" }); + while (my $idle = $idles->next) { + ${$machines}{$idle->machine}{'idle'} = $idle->max_stoptime; + } + $c->stash->{machines} = $machines; $c->stash->{steps} = [ $c->model('DB::BuildSteps')->search( { finished => 0, 'me.busy' => 1, 'build.busy' => 1, }, { join => [ 'build' ] diff --git a/src/lib/Hydra/Helper/Nix.pm b/src/lib/Hydra/Helper/Nix.pm index 88bb1575..e93aff4b 100644 --- a/src/lib/Hydra/Helper/Nix.pm +++ b/src/lib/Hydra/Helper/Nix.pm @@ -16,7 +16,7 @@ our @EXPORT = qw( getViewResult getLatestSuccessfulViewResult jobsetOverview removeAsciiEscapes getDrvLogPath logContents getMainOutput - getEvals); + getEvals getMachines); sub getHydraHome { @@ -373,5 +373,33 @@ sub getEvals { return [@res]; } +sub getMachines { + my $machinesConf = $ENV{"NIX_REMOTE_SYSTEMS"} || "/etc/nix.machines"; + + # Read the list of machines. + my %machines = (); + if (-e $machinesConf) { + open CONF, "<$machinesConf" or die; + while () { + chomp; + s/\#.*$//g; + next if /^\s*$/; + my @tokens = split /\s/, $_; + my @supportedFeatures = split(/,/, $tokens[5] || ""); + my @mandatoryFeatures = split(/,/, $tokens[6] || ""); + $machines{$tokens[0]} = + { systemTypes => [ split(/,/, $tokens[1]) ] + , sshKeys => $tokens[2] + , maxJobs => int($tokens[3]) + , speedFactor => 1.0 * (defined $tokens[4] ? int($tokens[4]) : 1) + , supportedFeatures => [ @supportedFeatures, @mandatoryFeatures ] + , mandatoryFeatures => [ @mandatoryFeatures ] + }; + } + close CONF; + } + return \%machines; +} + 1; diff --git a/src/root/machine-status.tt b/src/root/machine-status.tt index d8db95fa..8a015e03 100644 --- a/src/root/machine-status.tt +++ b/src/root/machine-status.tt @@ -6,18 +6,18 @@ - [% IF m.enabled == 1 %] - Running + [% IF m.value.maxJobs > 0 %] + Running [% ELSE %] - Stopped - [% END %] [% m.hostname %] ([% comma=0; FOREACH ms IN m.buildmachinesystemtypes %][% IF comma; %], [% ELSE; comma = 1; END; ms.system; END %]) + Stopped + [% END %] [% m.key %] ([% comma=0; FOREACH system IN m.value.systemTypes %][% IF comma; %], [% ELSE; comma = 1; END; system; END %]) [% idle = 1 %] [% FOREACH step IN steps %] - [% IF step.machine.match('@(.*)').0 == m.hostname %] + [% IF step.machine.match('@(.*)').0 == m.key %] [% idle = 0 %] [% INCLUDE renderFullJobName project = step.build.project.name jobset = step.build.jobset.name job = step.build.job.name %] @@ -29,7 +29,11 @@ [% END %] [% END %] [% IF idle == 1 %] - Idle since [% INCLUDE renderDuration duration = curTime - m.get_column('idle') %] + [% IF m.value.idle %] + Idle since [% INCLUDE renderDuration duration = curTime - m.value.idle %] + [% ELSE %] + Never built + [% END %] [% END %] [% END %]