2008-10-28 10:19:31 +00:00
|
|
|
package HydraFrontend::Controller::Root;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use parent 'Catalyst::Controller';
|
|
|
|
|
|
|
|
#
|
|
|
|
# Sets the actions in this controller to be registered with no prefix
|
|
|
|
# so they function identically to actions created in MyApp.pm
|
|
|
|
#
|
|
|
|
__PACKAGE__->config->{namespace} = '';
|
|
|
|
|
|
|
|
|
|
|
|
sub error {
|
|
|
|
my ($c, $msg) = @_;
|
|
|
|
$c->stash->{template} = 'error.tt';
|
|
|
|
$c->stash->{error} = $msg;
|
|
|
|
$c->response->status(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub getBuild {
|
|
|
|
my ($c, $id) = @_;
|
|
|
|
(my $build) = $c->model('DB::Builds')->search({ id => $id });
|
|
|
|
return $build;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub index :Path :Args(0) {
|
|
|
|
my ( $self, $c ) = @_;
|
|
|
|
$c->stash->{template} = 'index.tt';
|
2008-11-09 00:48:36 +00:00
|
|
|
$c->stash->{projects} = [$c->model('DB::Projects')->all];
|
2008-11-11 12:54:37 +00:00
|
|
|
$c->stash->{scheduled} = [$c->model('DB::Builds')->search(
|
|
|
|
{finished => 0}, {join => 'schedulingInfo'})]; # !!!
|
|
|
|
$c->stash->{allBuilds} = [$c->model('DB::Builds')->search(
|
|
|
|
{finished => 1}, {order_by => "timestamp DESC"})];
|
|
|
|
# Get the latest finished build for each unique job.
|
|
|
|
$c->stash->{latestBuilds} = [$c->model('DB::Builds')->search(undef,
|
|
|
|
{ join => 'resultInfo'
|
2008-11-11 17:49:50 +00:00
|
|
|
, where => "finished != 0 and timestamp = (select max(timestamp) from Builds where project == me.project and attrName == me.attrName and finished != 0)"
|
2008-11-11 12:54:37 +00:00
|
|
|
, order_by => "project, attrname"
|
|
|
|
})];
|
2008-10-28 10:19:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-06 23:17:46 +00:00
|
|
|
sub project :Local {
|
|
|
|
my ( $self, $c, $projectName ) = @_;
|
|
|
|
$c->stash->{template} = 'project.tt';
|
|
|
|
(my $project) = $c->model('DB::Projects')->search({ name => $projectName });
|
|
|
|
return error($c, "Project <tt>$projectName</tt> doesn't exist.") if !defined $project;
|
|
|
|
$c->stash->{project} = $project;
|
|
|
|
$c->stash->{jobNames} =
|
|
|
|
[$c->model('DB::Builds')->search({project => $projectName}, {select => [{distinct => 'attrname'}], as => ['attrname']})];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-28 15:34:29 +00:00
|
|
|
sub job :Local {
|
2008-11-05 03:25:48 +00:00
|
|
|
my ( $self, $c, $project, $jobName ) = @_;
|
2008-10-28 15:34:29 +00:00
|
|
|
$c->stash->{template} = 'job.tt';
|
2008-11-06 23:17:46 +00:00
|
|
|
$c->stash->{projectName} = $project;
|
2008-10-28 15:34:29 +00:00
|
|
|
$c->stash->{jobName} = $jobName;
|
2008-11-11 12:54:37 +00:00
|
|
|
$c->stash->{builds} = [$c->model('DB::Builds')->search(
|
|
|
|
{finished => 1, project => $project, attrName => $jobName},
|
|
|
|
{order_by => "timestamp DESC"})];
|
2008-10-28 15:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-28 10:19:31 +00:00
|
|
|
sub default :Path {
|
|
|
|
my ( $self, $c ) = @_;
|
|
|
|
error($c, "Page not found.");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub build :Local {
|
|
|
|
my ( $self, $c, $id ) = @_;
|
|
|
|
|
|
|
|
my $build = getBuild($c, $id);
|
|
|
|
return error($c, "Build with ID $id doesn't exist.") if !defined $build;
|
2008-10-28 12:44:36 +00:00
|
|
|
|
2008-10-28 10:19:31 +00:00
|
|
|
$c->stash->{template} = 'build.tt';
|
|
|
|
$c->stash->{build} = $build;
|
|
|
|
$c->stash->{id} = $id;
|
2008-11-11 14:45:33 +00:00
|
|
|
|
|
|
|
if (!$build->finished && $build->schedulingInfo->busy) {
|
|
|
|
my $logfile = $build->schedulingInfo->logfile;
|
|
|
|
$c->stash->{logtext} = `cat $logfile`;
|
|
|
|
}
|
2008-10-28 10:19:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub log :Local {
|
|
|
|
my ( $self, $c, $id, $logPhase ) = @_;
|
|
|
|
|
|
|
|
my $build = getBuild($c, $id);
|
|
|
|
return error($c, "Build with ID $id doesn't exist.") if !defined $build;
|
|
|
|
|
|
|
|
my $log = $build->buildlogs->find({logphase => $logPhase});
|
|
|
|
return error($c, "Build $id doesn't have a log phase named <tt>$logPhase</tt>.") if !defined $log;
|
|
|
|
|
|
|
|
$c->stash->{template} = 'log.tt';
|
|
|
|
$c->stash->{id} = $id;
|
|
|
|
$c->stash->{log} = $log;
|
|
|
|
|
|
|
|
# !!! should be done in the view (as a TT plugin).
|
|
|
|
$c->stash->{logtext} = loadLog($log->path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-11 17:49:50 +00:00
|
|
|
sub nixlog :Local {
|
|
|
|
my ( $self, $c, $id, $stepnr ) = @_;
|
|
|
|
|
|
|
|
my $build = getBuild($c, $id);
|
|
|
|
return error($c, "Build with ID $id doesn't exist.") if !defined $build;
|
|
|
|
|
|
|
|
my $step = $build->buildsteps->find({stepnr => $stepnr});
|
|
|
|
return error($c, "Build $id doesn't have a build step $stepnr.") if !defined $step;
|
|
|
|
|
|
|
|
$c->stash->{template} = 'log.tt';
|
|
|
|
$c->stash->{id} = $id;
|
|
|
|
$c->stash->{step} = $step;
|
|
|
|
|
|
|
|
# !!! should be done in the view (as a TT plugin).
|
|
|
|
$c->stash->{logtext} = loadLog($step->logfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-28 10:19:31 +00:00
|
|
|
sub loadLog {
|
|
|
|
my ($path) = @_;
|
|
|
|
# !!! all a quick hack
|
|
|
|
if ($path =~ /.bz2$/) {
|
|
|
|
return `cat $path | bzip2 -d`;
|
|
|
|
} else {
|
|
|
|
return `cat $path`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub end : ActionClass('RenderView') {}
|
|
|
|
|
|
|
|
|
|
|
|
1;
|