machine-status: Read /etc/nix.machines instead of using the BuildMachines table

This commit is contained in:
Shea Levy 2013-03-04 15:37:20 -05:00
parent a77161e40a
commit f9426f365b
3 changed files with 47 additions and 13 deletions

View file

@ -74,12 +74,14 @@ sub status :Local {
sub machines :Local Args(0) { sub machines :Local Args(0) {
my ($self, $c) = @_; my ($self, $c) = @_;
$c->stash->{machines} = [$c->model('DB::BuildMachines')->search( my $machines = getMachines;
{}, my $idles = $c->model('DB::BuildSteps')->search(
{ order_by => ["enabled DESC", "hostname"] { stoptime => { '!=', undef } },
, '+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)"] { select => [ 'machine', { max => 'stoptime', -as => 'max_stoptime' }], group_by => "machine" });
, '+as' => ['idle'] while (my $idle = $idles->next) {
})]; ${$machines}{$idle->machine}{'idle'} = $idle->max_stoptime;
}
$c->stash->{machines} = $machines;
$c->stash->{steps} = [ $c->model('DB::BuildSteps')->search( $c->stash->{steps} = [ $c->model('DB::BuildSteps')->search(
{ finished => 0, 'me.busy' => 1, 'build.busy' => 1, }, { finished => 0, 'me.busy' => 1, 'build.busy' => 1, },
{ join => [ 'build' ] { join => [ 'build' ]

View file

@ -16,7 +16,7 @@ our @EXPORT = qw(
getViewResult getLatestSuccessfulViewResult getViewResult getLatestSuccessfulViewResult
jobsetOverview removeAsciiEscapes getDrvLogPath logContents jobsetOverview removeAsciiEscapes getDrvLogPath logContents
getMainOutput getMainOutput
getEvals); getEvals getMachines);
sub getHydraHome { sub getHydraHome {
@ -373,5 +373,33 @@ sub getEvals {
return [@res]; 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 (<CONF>) {
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; 1;

View file

@ -6,18 +6,18 @@
<thead> <thead>
<tr> <tr>
<th colspan="5"> <th colspan="5">
[% IF m.enabled == 1 %] [% IF m.value.maxJobs > 0 %]
<a class="btn btn-success btn-mini" href="[% c.uri_for('/admin/machine' m.hostname 'disable' ) %]">Running</a> Running
[% ELSE %] [% ELSE %]
<a class="btn btn-danger btn-mini" href="[% c.uri_for('/admin/machine' m.hostname 'enable' ) %]">Stopped</a> Stopped
[% END %] <tt>[% m.hostname %]</tt> (<tt>[% comma=0; FOREACH ms IN m.buildmachinesystemtypes %][% IF comma; %], [% ELSE; comma = 1; END; ms.system; END %])</tt> [% END %] <tt>[% m.key %]</tt> (<tt>[% comma=0; FOREACH system IN m.value.systemTypes %][% IF comma; %], [% ELSE; comma = 1; END; system; END %])</tt>
</th> </th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
[% idle = 1 %] [% idle = 1 %]
[% FOREACH step IN steps %] [% FOREACH step IN steps %]
[% IF step.machine.match('@(.*)').0 == m.hostname %] [% IF step.machine.match('@(.*)').0 == m.key %]
[% idle = 0 %] [% idle = 0 %]
<tr> <tr>
<td><tt>[% INCLUDE renderFullJobName project = step.build.project.name jobset = step.build.jobset.name job = step.build.job.name %]</tt></td> <td><tt>[% INCLUDE renderFullJobName project = step.build.project.name jobset = step.build.jobset.name job = step.build.job.name %]</tt></td>
@ -29,7 +29,11 @@
[% END %] [% END %]
[% END %] [% END %]
[% IF idle == 1 %] [% IF idle == 1 %]
<tr><td colspan="5">Idle since [% INCLUDE renderDuration duration = curTime - m.get_column('idle') %]</td></tr> [% IF m.value.idle %]
<tr><td colspan="5">Idle since [% INCLUDE renderDuration duration = curTime - m.value.idle %]</td></tr>
[% ELSE %]
<tr><td colspan="5">Never built</td></tr>
[% END %]
[% END %] [% END %]
</tbody> </tbody>
[% END %] [% END %]