2009-03-04 17:24:08 +00:00
|
|
|
|
package Hydra::Controller::Job;
|
|
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
use warnings;
|
|
|
|
|
use base 'Hydra::Base::Controller::ListBuilds';
|
|
|
|
|
use Hydra::Helper::Nix;
|
|
|
|
|
use Hydra::Helper::CatalystUtils;
|
|
|
|
|
|
|
|
|
|
|
2009-03-12 23:46:17 +00:00
|
|
|
|
sub job : Chained('/') PathPart('job') CaptureArgs(3) {
|
|
|
|
|
my ($self, $c, $projectName, $jobsetName, $jobName) = @_;
|
|
|
|
|
|
2014-04-24 11:05:16 +02:00
|
|
|
|
$c->stash->{jobset} = $c->model('DB::Jobsets')->find({ project => $projectName, name => $jobsetName });
|
|
|
|
|
|
|
|
|
|
if (!$c->stash->{jobset}) {
|
|
|
|
|
my $rename = $c->model('DB::JobsetRenames')->find({ project => $projectName, from_ => $jobsetName });
|
|
|
|
|
notFound($c, "Jobset ‘$jobsetName’ doesn't exist.") unless defined $rename;
|
|
|
|
|
|
|
|
|
|
# Return a permanent redirect to the new jobset name.
|
|
|
|
|
my @captures = @{$c->req->captures};
|
|
|
|
|
$captures[1] = $rename->to_;
|
|
|
|
|
$c->res->redirect($c->uri_for($c->action, \@captures, $c->req->params), 301);
|
|
|
|
|
$c->detach;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$c->stash->{job} = $c->stash->{jobset}->jobs->find({ name => $jobName })
|
2009-03-13 15:41:19 +00:00
|
|
|
|
or notFound($c, "Job $projectName:$jobsetName:$jobName doesn't exist.");
|
|
|
|
|
$c->stash->{project} = $c->stash->{job}->project;
|
2009-03-04 17:24:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-04-02 16:15:57 +00:00
|
|
|
|
sub overview : Chained('job') PathPart('') Args(0) {
|
|
|
|
|
my ($self, $c) = @_;
|
2013-08-26 18:58:04 +02:00
|
|
|
|
my $job = $c->stash->{job};
|
2009-04-02 16:15:57 +00:00
|
|
|
|
|
|
|
|
|
$c->stash->{template} = 'job.tt';
|
|
|
|
|
|
2013-01-22 14:41:02 +01:00
|
|
|
|
$c->stash->{lastBuilds} =
|
2013-08-26 18:58:04 +02:00
|
|
|
|
[ $job->builds->search({ finished => 1 },
|
2013-05-23 10:45:49 -04:00
|
|
|
|
{ order_by => 'id DESC', rows => 10, columns => [@buildListColumns] }) ];
|
2010-04-23 08:17:15 +00:00
|
|
|
|
|
2013-02-22 12:51:00 +01:00
|
|
|
|
$c->stash->{queuedBuilds} = [
|
2013-08-26 18:58:04 +02:00
|
|
|
|
$job->builds->search(
|
2013-02-22 12:51:00 +01:00
|
|
|
|
{ finished => 0 },
|
2013-10-11 12:01:52 +02:00
|
|
|
|
{ order_by => ["priority DESC", "id"] }
|
2013-01-22 14:09:37 +01:00
|
|
|
|
) ];
|
2013-08-26 18:58:04 +02:00
|
|
|
|
|
|
|
|
|
# If this is an aggregate job, then get its constituents.
|
|
|
|
|
my @constituents = $c->model('DB::Builds')->search(
|
2013-10-03 15:00:28 +02:00
|
|
|
|
{ aggregate => { -in => $job->builds->search({}, { columns => ["id"], order_by => "id desc", rows => 15 })->as_query } },
|
|
|
|
|
{ join => 'aggregateconstituents_constituents',
|
|
|
|
|
columns => ['id', 'job', 'finished', 'buildstatus'],
|
|
|
|
|
+select => ['aggregateconstituents_constituents.aggregate'],
|
|
|
|
|
+as => ['aggregate']
|
|
|
|
|
});
|
2013-08-26 18:58:04 +02:00
|
|
|
|
|
|
|
|
|
my $aggregates = {};
|
|
|
|
|
my %constituentJobs;
|
|
|
|
|
foreach my $b (@constituents) {
|
2013-10-03 15:00:28 +02:00
|
|
|
|
my $jobName = $b->get_column('job');
|
|
|
|
|
$aggregates->{$b->get_column('aggregate')}->{constituents}->{$jobName} =
|
|
|
|
|
{ id => $b->id, finished => $b->finished, buildstatus => $b->buildstatus };
|
|
|
|
|
$constituentJobs{$jobName} = 1;
|
2013-08-26 18:58:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-27 13:45:27 +00:00
|
|
|
|
foreach my $agg (keys %$aggregates) {
|
2013-10-03 15:00:28 +02:00
|
|
|
|
# FIXME: could be done in one query.
|
|
|
|
|
$aggregates->{$agg}->{build} =
|
|
|
|
|
$c->model('DB::Builds')->find({id => $agg}, {columns => [@buildListColumns]}) or die;
|
2013-08-27 13:45:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-26 18:58:04 +02:00
|
|
|
|
$c->stash->{aggregates} = $aggregates;
|
|
|
|
|
$c->stash->{constituentJobs} = [sort (keys %constituentJobs)];
|
2013-10-14 20:07:26 +02:00
|
|
|
|
|
|
|
|
|
$c->stash->{starred} = $c->user->starredjobs(
|
|
|
|
|
{ project => $c->stash->{project}->name
|
|
|
|
|
, jobset => $c->stash->{jobset}->name
|
|
|
|
|
, job => $c->stash->{job}->name
|
|
|
|
|
})->count == 1 if $c->user_exists;
|
2015-07-31 00:57:30 +02:00
|
|
|
|
|
|
|
|
|
$c->stash->{metrics} = [ $job->buildmetrics->search(
|
|
|
|
|
{ }, { select => ["name"], distinct => 1, order_by => "timestamp desc", }) ];
|
2009-04-02 16:15:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-10-07 12:59:09 +02:00
|
|
|
|
sub build_times : Chained('job') PathPart('build-times') Args(0) {
|
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
my @res = $c->stash->{job}->builds->search(
|
|
|
|
|
{ finished => 1, buildstatus => 0, closuresize => { '!=', 0 } },
|
|
|
|
|
{ join => "actualBuildStep"
|
|
|
|
|
, "+select" => ["actualBuildStep.stoptime - actualBuildStep.starttime"]
|
|
|
|
|
, "+as" => ["actualBuildTime"],
|
|
|
|
|
, order_by => "id" });
|
|
|
|
|
$self->status_ok($c, entity => [ map { { id => $_->id, timestamp => $_ ->timestamp, value => $_->get_column('actualBuildTime') } } @res ]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-10-07 11:23:15 +02:00
|
|
|
|
sub closure_sizes : Chained('job') PathPart('closure-sizes') Args(0) {
|
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
my @res = $c->stash->{job}->builds->search(
|
|
|
|
|
{ finished => 1, buildstatus => 0, closuresize => { '!=', 0 } },
|
|
|
|
|
{ order_by => "id", columns => [ "id", "timestamp", "closuresize" ] });
|
|
|
|
|
$self->status_ok($c, entity => [ map { { id => $_->id, timestamp => $_ ->timestamp, value => $_->closuresize } } @res ]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-10-07 11:45:17 +02:00
|
|
|
|
sub output_sizes : Chained('job') PathPart('output-sizes') Args(0) {
|
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
my @res = $c->stash->{job}->builds->search(
|
|
|
|
|
{ finished => 1, buildstatus => 0, size => { '!=', 0 } },
|
|
|
|
|
{ order_by => "id", columns => [ "id", "timestamp", "size" ] });
|
|
|
|
|
$self->status_ok($c, entity => [ map { { id => $_->id, timestamp => $_ ->timestamp, value => $_->size } } @res ]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-07-31 00:57:30 +02:00
|
|
|
|
sub metric : Chained('job') PathPart('metric') Args(1) {
|
|
|
|
|
my ($self, $c, $metricName) = @_;
|
|
|
|
|
|
|
|
|
|
$c->stash->{template} = 'metric.tt';
|
|
|
|
|
$c->stash->{metricName} = $metricName;
|
|
|
|
|
|
|
|
|
|
my @res = $c->stash->{job}->buildmetrics->search(
|
|
|
|
|
{ name => $metricName },
|
|
|
|
|
{ order_by => "timestamp", columns => [ "build", "name", "timestamp", "value", "unit" ] });
|
|
|
|
|
|
|
|
|
|
$self->status_ok($c, entity => [ map { { id => $_->get_column("build"), timestamp => $_ ->timestamp, value => $_->value, unit => $_->unit } } @res ]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-03-04 17:24:08 +00:00
|
|
|
|
# Hydra::Base::Controller::ListBuilds needs this.
|
|
|
|
|
sub get_builds : Chained('job') PathPart('') CaptureArgs(0) {
|
|
|
|
|
my ($self, $c) = @_;
|
2009-03-13 15:41:19 +00:00
|
|
|
|
$c->stash->{allBuilds} = $c->stash->{job}->builds;
|
2009-04-03 15:37:21 +00:00
|
|
|
|
$c->stash->{latestSucceeded} = $c->model('DB')->resultset('LatestSucceededForJob')
|
|
|
|
|
->search({}, {bind => [$c->stash->{project}->name, $c->stash->{jobset}->name, $c->stash->{job}->name]});
|
2009-03-04 17:24:08 +00:00
|
|
|
|
$c->stash->{channelBaseName} =
|
2009-03-13 15:41:19 +00:00
|
|
|
|
$c->stash->{project}->name . "-" . $c->stash->{jobset}->name . "-" . $c->stash->{job}->name;
|
2009-03-04 17:24:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-10-14 20:07:26 +02:00
|
|
|
|
sub star : Chained('job') PathPart('star') Args(0) {
|
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
requirePost($c);
|
|
|
|
|
requireUser($c);
|
|
|
|
|
my $args =
|
|
|
|
|
{ project => $c->stash->{project}->name
|
|
|
|
|
, jobset => $c->stash->{jobset}->name
|
|
|
|
|
, job => $c->stash->{job}->name
|
|
|
|
|
};
|
|
|
|
|
if ($c->request->params->{star} eq "1") {
|
|
|
|
|
$c->user->starredjobs->update_or_create($args);
|
|
|
|
|
} else {
|
|
|
|
|
$c->user->starredjobs->find($args)->delete;
|
|
|
|
|
}
|
|
|
|
|
$c->stash->{resource}->{success} = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-03-04 17:24:08 +00:00
|
|
|
|
1;
|