2012-04-02 16:11:22 +02:00
|
|
|
|
package Hydra::Controller::JobsetEval;
|
|
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
use warnings;
|
2012-04-02 23:25:07 +02:00
|
|
|
|
use base 'Hydra::Base::Controller::NixChannel';
|
2012-04-02 16:11:22 +02:00
|
|
|
|
use Hydra::Helper::Nix;
|
|
|
|
|
use Hydra::Helper::CatalystUtils;
|
|
|
|
|
|
|
|
|
|
|
2015-09-02 13:13:55 +02:00
|
|
|
|
sub evalChain : Chained('/') PathPart('eval') CaptureArgs(1) {
|
2012-04-02 16:11:22 +02:00
|
|
|
|
my ($self, $c, $evalId) = @_;
|
2013-01-22 14:41:02 +01:00
|
|
|
|
|
2012-04-02 16:11:22 +02:00
|
|
|
|
my $eval = $c->model('DB::JobsetEvals')->find($evalId)
|
2013-01-22 14:09:37 +01:00
|
|
|
|
or notFound($c, "Evaluation $evalId doesn't exist.");
|
2012-04-02 16:11:22 +02:00
|
|
|
|
|
|
|
|
|
$c->stash->{eval} = $eval;
|
|
|
|
|
$c->stash->{project} = $eval->project;
|
|
|
|
|
$c->stash->{jobset} = $eval->jobset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-09-02 13:13:55 +02:00
|
|
|
|
sub view :Chained('evalChain') :PathPart('') :Args(0) :ActionClass('REST') { }
|
|
|
|
|
|
|
|
|
|
sub view_GET {
|
2012-04-02 16:11:22 +02:00
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
|
|
|
|
|
$c->stash->{template} = 'jobset-eval.tt';
|
|
|
|
|
|
|
|
|
|
my $eval = $c->stash->{eval};
|
|
|
|
|
|
2013-08-28 16:07:24 +02:00
|
|
|
|
$c->stash->{filter} = $c->request->params->{filter} // "";
|
|
|
|
|
my $filter = $c->stash->{filter} eq "" ? {} : { job => { ilike => "%" . $c->stash->{filter} . "%" } };
|
|
|
|
|
|
2012-04-02 20:40:59 +02:00
|
|
|
|
my $compare = $c->req->params->{compare};
|
|
|
|
|
my $eval2;
|
2012-04-02 16:11:22 +02:00
|
|
|
|
|
2012-04-02 20:40:59 +02:00
|
|
|
|
# Allow comparing this evaluation against the previous evaluation
|
|
|
|
|
# (default), an arbitrary evaluation, or the latest completed
|
|
|
|
|
# evaluation of another jobset.
|
2012-04-17 08:53:00 +00:00
|
|
|
|
if (defined $compare) {
|
|
|
|
|
if ($compare =~ /^\d+$/) {
|
|
|
|
|
$eval2 = $c->model('DB::JobsetEvals')->find($compare)
|
|
|
|
|
or notFound($c, "Evaluation $compare doesn't exist.");
|
2013-10-03 01:54:42 +02:00
|
|
|
|
} elsif ($compare =~ /^-(\d+)$/) {
|
|
|
|
|
my $t = int($1);
|
2013-08-28 15:46:08 +02:00
|
|
|
|
$eval2 = $c->stash->{jobset}->jobsetevals->find(
|
2013-10-03 01:54:42 +02:00
|
|
|
|
{ hasnewbuilds => 1, timestamp => {'<=', $eval->timestamp - $t} },
|
|
|
|
|
{ order_by => "timestamp desc", rows => 1});
|
2012-04-17 08:53:00 +00:00
|
|
|
|
} elsif (defined $compare && $compare =~ /^($jobsetNameRE)$/) {
|
|
|
|
|
my $j = $c->stash->{project}->jobsets->find({name => $compare})
|
|
|
|
|
or notFound($c, "Jobset $compare doesn't exist.");
|
2013-11-11 21:17:22 +00:00
|
|
|
|
$eval2 = getLatestFinishedEval($j);
|
2012-04-17 08:53:00 +00:00
|
|
|
|
} else {
|
|
|
|
|
notFound($c, "Unknown comparison source ‘$compare’.");
|
|
|
|
|
}
|
2012-04-02 20:40:59 +02:00
|
|
|
|
} else {
|
|
|
|
|
($eval2) = $eval->jobset->jobsetevals->search(
|
|
|
|
|
{ hasnewbuilds => 1, id => { '<', $eval->id } },
|
|
|
|
|
{ order_by => "id DESC", rows => 1 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$c->stash->{otherEval} = $eval2 if defined $eval2;
|
2013-01-22 14:41:02 +01:00
|
|
|
|
|
2013-08-28 13:04:14 +00:00
|
|
|
|
sub cmpBuilds {
|
|
|
|
|
my ($a, $b) = @_;
|
|
|
|
|
return $a->get_column('job') cmp $b->get_column('job')
|
|
|
|
|
|| $a->get_column('system') cmp $b->get_column('system')
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-28 16:07:24 +02:00
|
|
|
|
my @builds = $eval->builds->search($filter, { columns => [@buildListColumns] });
|
|
|
|
|
my @builds2 = defined $eval2 ? $eval2->builds->search($filter, { columns => [@buildListColumns] }) : ();
|
2013-08-28 13:04:14 +00:00
|
|
|
|
|
|
|
|
|
@builds = sort { cmpBuilds($a, $b) } @builds;
|
|
|
|
|
@builds2 = sort { cmpBuilds($a, $b) } @builds2;
|
2012-04-02 16:11:22 +02:00
|
|
|
|
|
|
|
|
|
$c->stash->{stillSucceed} = [];
|
|
|
|
|
$c->stash->{stillFail} = [];
|
|
|
|
|
$c->stash->{nowSucceed} = [];
|
|
|
|
|
$c->stash->{nowFail} = [];
|
2012-04-02 16:45:05 +02:00
|
|
|
|
$c->stash->{new} = [];
|
|
|
|
|
$c->stash->{removed} = [];
|
2012-04-02 15:23:42 +00:00
|
|
|
|
$c->stash->{unfinished} = [];
|
2013-10-03 01:54:42 +02:00
|
|
|
|
$c->stash->{aborted} = [];
|
2012-04-02 16:11:22 +02:00
|
|
|
|
|
|
|
|
|
my $n = 0;
|
|
|
|
|
foreach my $build (@builds) {
|
2014-01-15 16:06:47 +01:00
|
|
|
|
my $aborted = $build->finished != 0 && ($build->buildstatus == 3 || $build->buildstatus == 4);
|
2012-04-02 16:11:22 +02:00
|
|
|
|
my $d;
|
2012-04-02 20:40:59 +02:00
|
|
|
|
my $found = 0;
|
2012-04-02 16:11:22 +02:00
|
|
|
|
while ($n < scalar(@builds2)) {
|
|
|
|
|
my $build2 = $builds2[$n];
|
2013-08-28 13:04:14 +00:00
|
|
|
|
my $d = cmpBuilds($build, $build2);
|
2012-04-02 20:40:59 +02:00
|
|
|
|
last if $d == -1;
|
2012-04-02 16:11:22 +02:00
|
|
|
|
if ($d == 0) {
|
2012-04-02 16:45:05 +02:00
|
|
|
|
$n++;
|
2012-04-02 20:40:59 +02:00
|
|
|
|
$found = 1;
|
2014-01-15 16:06:47 +01:00
|
|
|
|
if ($aborted) {
|
|
|
|
|
# do nothing
|
|
|
|
|
} elsif ($build->finished == 0 || $build2->finished == 0) {
|
2012-04-02 15:23:42 +00:00
|
|
|
|
push @{$c->stash->{unfinished}}, $build;
|
|
|
|
|
} elsif ($build->buildstatus == 0 && $build2->buildstatus == 0) {
|
2012-04-02 16:11:22 +02:00
|
|
|
|
push @{$c->stash->{stillSucceed}}, $build;
|
|
|
|
|
} elsif ($build->buildstatus != 0 && $build2->buildstatus != 0) {
|
|
|
|
|
push @{$c->stash->{stillFail}}, $build;
|
|
|
|
|
} elsif ($build->buildstatus == 0 && $build2->buildstatus != 0) {
|
|
|
|
|
push @{$c->stash->{nowSucceed}}, $build;
|
|
|
|
|
} elsif ($build->buildstatus != 0 && $build2->buildstatus == 0) {
|
|
|
|
|
push @{$c->stash->{nowFail}}, $build;
|
2012-04-02 16:45:05 +02:00
|
|
|
|
} else { die; }
|
|
|
|
|
last;
|
2012-04-02 16:11:22 +02:00
|
|
|
|
}
|
2012-04-02 16:45:05 +02:00
|
|
|
|
push @{$c->stash->{removed}}, { job => $build2->get_column('job'), system => $build2->get_column('system') };
|
2012-04-02 16:11:22 +02:00
|
|
|
|
$n++;
|
|
|
|
|
}
|
2014-01-15 16:06:47 +01:00
|
|
|
|
if ($aborted) {
|
|
|
|
|
push @{$c->stash->{aborted}}, $build;
|
|
|
|
|
} else {
|
|
|
|
|
push @{$c->stash->{new}}, $build if !$found;
|
|
|
|
|
}
|
2012-04-02 16:11:22 +02:00
|
|
|
|
}
|
2013-01-22 14:41:02 +01:00
|
|
|
|
|
2012-04-02 16:11:22 +02:00
|
|
|
|
$c->stash->{full} = ($c->req->params->{full} || "0") eq "1";
|
2015-09-02 13:13:55 +02:00
|
|
|
|
|
|
|
|
|
$self->status_ok(
|
|
|
|
|
$c,
|
|
|
|
|
entity => $eval
|
|
|
|
|
);
|
2012-04-02 16:11:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-09-02 13:13:55 +02:00
|
|
|
|
sub release : Chained('evalChain') PathPart('release') Args(0) {
|
2012-07-18 23:46:41 +02:00
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
my $eval = $c->stash->{eval};
|
|
|
|
|
|
|
|
|
|
requireProjectOwner($c, $c->stash->{project});
|
2013-01-22 14:41:02 +01:00
|
|
|
|
|
2012-07-18 23:46:41 +02:00
|
|
|
|
my @builds = $eval->builds;
|
|
|
|
|
|
|
|
|
|
my $releaseName;
|
|
|
|
|
$releaseName ||= $_->releasename foreach @builds;
|
|
|
|
|
|
2014-08-23 16:20:58 +02:00
|
|
|
|
# If no release name has been defined by any of the builds, compose one of the project name and evaluation id
|
|
|
|
|
$releaseName = $eval->project->name."-".$eval->id unless defined $releaseName;
|
2012-07-18 23:46:41 +02:00
|
|
|
|
|
|
|
|
|
my $release;
|
|
|
|
|
|
|
|
|
|
txn_do($c->model('DB')->schema, sub {
|
|
|
|
|
|
|
|
|
|
$release = $c->stash->{project}->releases->create(
|
|
|
|
|
{ name => $releaseName
|
|
|
|
|
, timestamp => time
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
foreach my $build (@builds) {
|
|
|
|
|
$release->releasemembers->create(
|
|
|
|
|
{ build => $build->id
|
|
|
|
|
, description => $build->description
|
|
|
|
|
}) if $build->buildstatus == 0;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$c->res->redirect($c->uri_for($c->controller('Release')->action_for('view'),
|
|
|
|
|
[$c->stash->{project}->name, $release->name]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-09-02 13:13:55 +02:00
|
|
|
|
sub create_jobset : Chained('evalChain') PathPart('create-jobset') Args(0) {
|
2015-07-06 15:17:35 +02:00
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
my $eval = $c->stash->{eval};
|
|
|
|
|
|
|
|
|
|
requireProjectOwner($c, $c->stash->{project});
|
|
|
|
|
|
|
|
|
|
$c->stash->{template} = 'edit-jobset.tt';
|
|
|
|
|
$c->stash->{createFromEval} = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-09-02 13:13:55 +02:00
|
|
|
|
sub cancel : Chained('evalChain') PathPart('cancel') Args(0) {
|
2013-10-04 15:40:43 +02:00
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
requireProjectOwner($c, $c->stash->{eval}->project);
|
|
|
|
|
my $n = cancelBuilds($c->model('DB')->schema, $c->stash->{eval}->builds);
|
|
|
|
|
$c->flash->{successMsg} = "$n builds have been cancelled.";
|
|
|
|
|
$c->res->redirect($c->uri_for($c->controller('JobsetEval')->action_for('view'), $c->req->captures));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-10-28 15:04:12 +01:00
|
|
|
|
sub restart {
|
|
|
|
|
my ($self, $c, $condition) = @_;
|
2013-10-04 17:01:47 +02:00
|
|
|
|
requireProjectOwner($c, $c->stash->{eval}->project);
|
2015-10-28 15:04:12 +01:00
|
|
|
|
my $builds = $c->stash->{eval}->builds->search({ finished => 1, buildstatus => $condition });
|
2013-10-04 17:01:47 +02:00
|
|
|
|
my $n = restartBuilds($c->model('DB')->schema, $builds);
|
|
|
|
|
$c->flash->{successMsg} = "$n builds have been restarted.";
|
|
|
|
|
$c->res->redirect($c->uri_for($c->controller('JobsetEval')->action_for('view'), $c->req->captures));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-10-28 15:04:12 +01:00
|
|
|
|
sub restart_aborted : Chained('evalChain') PathPart('restart-aborted') Args(0) {
|
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
restart($self, $c, { -in => [3, 4, 9] });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub restart_failed : Chained('evalChain') PathPart('restart-failed') Args(0) {
|
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
restart($self, $c, { 'not in' => [0] });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-09-02 13:13:55 +02:00
|
|
|
|
sub bump : Chained('evalChain') PathPart('bump') Args(0) {
|
2015-08-10 18:56:19 +02:00
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
requireProjectOwner($c, $c->stash->{eval}->project); # FIXME: require admin?
|
|
|
|
|
my $builds = $c->stash->{eval}->builds->search({ finished => 0 });
|
|
|
|
|
my $n = $builds->count();
|
|
|
|
|
$c->model('DB')->schema->txn_do(sub {
|
|
|
|
|
$builds->update({globalpriority => time()});
|
|
|
|
|
});
|
|
|
|
|
$c->flash->{successMsg} = "$n builds have been bumped to the front of the queue.";
|
|
|
|
|
$c->res->redirect($c->uri_for($c->controller('JobsetEval')->action_for('view'), $c->req->captures));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-04-02 23:25:07 +02:00
|
|
|
|
# Hydra::Base::Controller::NixChannel needs this.
|
2015-09-02 13:13:55 +02:00
|
|
|
|
sub nix : Chained('evalChain') PathPart('channel') CaptureArgs(0) {
|
2012-04-02 23:25:07 +02:00
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
$c->stash->{channelName} = $c->stash->{project}->name . "-" . $c->stash->{jobset}->name . "-latest";
|
|
|
|
|
$c->stash->{channelBuilds} = $c->stash->{eval}->builds
|
|
|
|
|
->search_literal("exists (select 1 from buildproducts where build = build.id and type = 'nix-build')")
|
2013-02-13 16:49:28 +00:00
|
|
|
|
->search({ finished => 1, buildstatus => 0 },
|
|
|
|
|
{ columns => [@buildListColumns, 'drvpath', 'description', 'homepage']
|
|
|
|
|
, join => ["buildoutputs"]
|
2013-10-07 17:06:17 +02:00
|
|
|
|
, order_by => ["build.id", "buildoutputs.name"]
|
2013-02-13 16:49:28 +00:00
|
|
|
|
, '+select' => ['buildoutputs.path', 'buildoutputs.name'], '+as' => ['outpath', 'outname'] });
|
2012-04-02 23:25:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-09-02 13:13:55 +02:00
|
|
|
|
sub job : Chained('evalChain') PathPart('job') {
|
2013-08-13 01:56:45 +02:00
|
|
|
|
my ($self, $c, $job, @rest) = @_;
|
|
|
|
|
|
|
|
|
|
my $build = $c->stash->{eval}->builds->find({job => $job});
|
|
|
|
|
|
|
|
|
|
notFound($c, "This evaluation has no job with the specified name.") unless defined $build;
|
|
|
|
|
|
|
|
|
|
$c->res->redirect($c->uri_for($c->controller('Build')->action_for("build"), [$build->id], @rest));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-04-02 16:11:22 +02:00
|
|
|
|
1;
|