Merge the BuildResultInfo table into the Builds table
This commit is contained in:
@ -15,11 +15,13 @@ use File::Slurp;
|
||||
|
||||
# !!! Rewrite this to use View::JSON.
|
||||
|
||||
|
||||
sub api : Chained('/') PathPart('api') CaptureArgs(0) {
|
||||
my ($self, $c) = @_;
|
||||
$c->response->content_type('application/json');
|
||||
}
|
||||
|
||||
|
||||
sub projectToHash {
|
||||
my ($project) = @_;
|
||||
return {
|
||||
@ -28,14 +30,15 @@ sub projectToHash {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
sub projects : Chained('api') PathPart('projects') Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
my @projects = $c->model('DB::Projects')->search({hidden => 0}, {order_by => 'name'}) ;
|
||||
my @projects = $c->model('DB::Projects')->search({hidden => 0}, {order_by => 'name'});
|
||||
|
||||
my @list ;
|
||||
my @list;
|
||||
foreach my $p (@projects) {
|
||||
push @list, projectToHash($p) ;
|
||||
push @list, projectToHash($p);
|
||||
}
|
||||
|
||||
$c->stash->{'plain'} = {
|
||||
@ -44,6 +47,7 @@ sub projects : Chained('api') PathPart('projects') Args(0) {
|
||||
$c->forward('Hydra::View::Plain');
|
||||
}
|
||||
|
||||
|
||||
sub buildToHash {
|
||||
my ($build) = @_;
|
||||
my $result = {
|
||||
@ -58,7 +62,7 @@ sub buildToHash {
|
||||
};
|
||||
|
||||
if($build->finished) {
|
||||
$result->{'buildstatus'} = $build->get_column("buildstatus") ;
|
||||
$result->{'buildstatus'} = $build->get_column("buildstatus");
|
||||
} else {
|
||||
$result->{'busy'} = $build->get_column("busy");
|
||||
$result->{'priority'} = $build->get_column("priority");
|
||||
@ -67,28 +71,27 @@ sub buildToHash {
|
||||
return $result;
|
||||
};
|
||||
|
||||
|
||||
sub latestbuilds : Chained('api') PathPart('latestbuilds') Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
my $nr = $c->request->params->{nr} ;
|
||||
my $nr = $c->request->params->{nr};
|
||||
error($c, "Parameter not defined!") if !defined $nr;
|
||||
|
||||
my $project = $c->request->params->{project} ;
|
||||
my $jobset = $c->request->params->{jobset} ;
|
||||
my $job = $c->request->params->{job} ;
|
||||
my $system = $c->request->params->{system} ;
|
||||
my $project = $c->request->params->{project};
|
||||
my $jobset = $c->request->params->{jobset};
|
||||
my $job = $c->request->params->{job};
|
||||
my $system = $c->request->params->{system};
|
||||
|
||||
my $filter = {finished => 1} ;
|
||||
my $filter = {finished => 1};
|
||||
$filter->{project} = $project if ! $project eq "";
|
||||
$filter->{jobset} = $jobset if ! $jobset eq "";
|
||||
$filter->{job} = $job if !$job eq "";
|
||||
$filter->{system} = $system if !$system eq "";
|
||||
|
||||
my @latest = joinWithResultInfo($c, $c->model('DB::Builds'))->search($filter, {rows => $nr, order_by => ["timestamp DESC"] });
|
||||
my @latest = $c->model('DB::Builds')->search($filter, {rows => $nr, order_by => ["timestamp DESC"] });
|
||||
|
||||
my @list ;
|
||||
foreach my $b (@latest) {
|
||||
push @list, buildToHash($b) ;
|
||||
}
|
||||
my @list;
|
||||
push @list, buildToHash($_) foreach @latest;
|
||||
|
||||
$c->stash->{'plain'} = {
|
||||
data => scalar (JSON::Any->objToJson(\@list))
|
||||
@ -96,6 +99,7 @@ sub latestbuilds : Chained('api') PathPart('latestbuilds') Args(0) {
|
||||
$c->forward('Hydra::View::Plain');
|
||||
}
|
||||
|
||||
|
||||
sub jobsetToHash {
|
||||
my ($jobset) = @_;
|
||||
return {
|
||||
@ -108,10 +112,11 @@ sub jobsetToHash {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
sub jobsets : Chained('api') PathPart('jobsets') Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
my $projectName = $c->request->params->{project} ;
|
||||
my $projectName = $c->request->params->{project};
|
||||
error($c, "Parameter 'project' not defined!") if !defined $projectName;
|
||||
|
||||
my $project = $c->model('DB::Projects')->find($projectName)
|
||||
@ -119,10 +124,8 @@ sub jobsets : Chained('api') PathPart('jobsets') Args(0) {
|
||||
|
||||
my @jobsets = jobsetOverview($c, $project);
|
||||
|
||||
my @list ;
|
||||
foreach my $j (@jobsets) {
|
||||
push @list, jobsetToHash($j) ;
|
||||
}
|
||||
my @list;
|
||||
push @list, jobsetToHash($_) foreach @jobsets;
|
||||
|
||||
$c->stash->{'plain'} = {
|
||||
data => scalar (JSON::Any->objToJson(\@list))
|
||||
@ -130,10 +133,11 @@ sub jobsets : Chained('api') PathPart('jobsets') Args(0) {
|
||||
$c->forward('Hydra::View::Plain');
|
||||
}
|
||||
|
||||
|
||||
sub queue : Chained('api') PathPart('queue') Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
my $nr = $c->request->params->{nr} ;
|
||||
my $nr = $c->request->params->{nr};
|
||||
error($c, "Parameter not defined!") if !defined $nr;
|
||||
|
||||
my @builds = $c->model('DB::Builds')->search({finished => 0}, {rows => $nr, order_by => ["busy DESC", "priority DESC", "timestamp"]});
|
||||
@ -147,6 +151,7 @@ sub queue : Chained('api') PathPart('queue') Args(0) {
|
||||
$c->forward('Hydra::View::Plain');
|
||||
}
|
||||
|
||||
|
||||
sub nrqueue : Chained('api') PathPart('nrqueue') Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
my $nrQueuedBuilds = $c->model('DB::Builds')->search({finished => 0})->count();
|
||||
@ -156,6 +161,7 @@ sub nrqueue : Chained('api') PathPart('nrqueue') Args(0) {
|
||||
$c->forward('Hydra::View::Plain');
|
||||
}
|
||||
|
||||
|
||||
sub nrrunning : Chained('api') PathPart('nrrunning') Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
my $nrRunningBuilds = $c->model('DB::Builds')->search({finished => 0, busy => 1 })->count();
|
||||
@ -165,20 +171,21 @@ sub nrrunning : Chained('api') PathPart('nrrunning') Args(0) {
|
||||
$c->forward('Hydra::View::Plain');
|
||||
}
|
||||
|
||||
|
||||
sub nrbuilds : Chained('api') PathPart('nrbuilds') Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
my $nr = $c->request->params->{nr} ;
|
||||
my $period = $c->request->params->{period} ;
|
||||
my $nr = $c->request->params->{nr};
|
||||
my $period = $c->request->params->{period};
|
||||
|
||||
error($c, "Parameter not defined!") if !defined $nr || !defined $period;
|
||||
my $base;
|
||||
|
||||
my $project = $c->request->params->{project} ;
|
||||
my $jobset = $c->request->params->{jobset} ;
|
||||
my $job = $c->request->params->{job} ;
|
||||
my $system = $c->request->params->{system} ;
|
||||
my $project = $c->request->params->{project};
|
||||
my $jobset = $c->request->params->{jobset};
|
||||
my $job = $c->request->params->{job};
|
||||
my $system = $c->request->params->{system};
|
||||
|
||||
my $filter = {finished => 1} ;
|
||||
my $filter = {finished => 1};
|
||||
$filter->{project} = $project if ! $project eq "";
|
||||
$filter->{jobset} = $jobset if ! $jobset eq "";
|
||||
$filter->{job} = $job if !$job eq "";
|
||||
@ -187,11 +194,9 @@ sub nrbuilds : Chained('api') PathPart('nrbuilds') Args(0) {
|
||||
$base = 60*60 if($period eq "hour");
|
||||
$base = 24*60*60 if($period eq "day");
|
||||
|
||||
my @stats = $c->model('DB::Builds')->search($filter, {select => [{ count => "*" }], as => ["nr"], group_by => ["timestamp - timestamp % $base"], order_by => "timestamp - timestamp % $base DESC", rows => $nr}) ;
|
||||
my @arr ;
|
||||
foreach my $d (@stats) {
|
||||
push @arr, int($d->get_column("nr"));
|
||||
}
|
||||
my @stats = $c->model('DB::Builds')->search($filter, {select => [{ count => "*" }], as => ["nr"], group_by => ["timestamp - timestamp % $base"], order_by => "timestamp - timestamp % $base DESC", rows => $nr});
|
||||
my @arr;
|
||||
push @arr, int($_->get_column("nr")) foreach @stats;
|
||||
@arr = reverse(@arr);
|
||||
|
||||
$c->stash->{'plain'} = {
|
||||
@ -200,38 +205,40 @@ sub nrbuilds : Chained('api') PathPart('nrbuilds') Args(0) {
|
||||
$c->forward('Hydra::View::Plain');
|
||||
}
|
||||
|
||||
|
||||
sub scmdiff : Chained('api') PathPart('scmdiff') Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
my $uri = $c->request->params->{uri} ;
|
||||
my $type = $c->request->params->{type} ;
|
||||
my $rev1 = $c->request->params->{rev1} ;
|
||||
my $rev2 = $c->request->params->{rev2} ;
|
||||
my $uri = $c->request->params->{uri};
|
||||
my $type = $c->request->params->{type};
|
||||
my $rev1 = $c->request->params->{rev1};
|
||||
my $rev2 = $c->request->params->{rev2};
|
||||
my $branch;
|
||||
|
||||
die("invalid revisions: [$rev1] [$rev2]") if $rev1 !~ m/^[a-zA-Z0-9_.]+$/ || $rev2 !~ m/^[a-zA-Z0-9_.]+$/ ;
|
||||
die("invalid revisions: [$rev1] [$rev2]") if $rev1 !~ m/^[a-zA-Z0-9_.]+$/ || $rev2 !~ m/^[a-zA-Z0-9_.]+$/;
|
||||
|
||||
my $diff = "";
|
||||
if($type eq "hg") {
|
||||
if ($type eq "hg") {
|
||||
my $clonePath = scmPath . "/" . sha256_hex($uri);
|
||||
die if ! -d $clonePath;
|
||||
$branch = `(cd $clonePath ; hg log --template '{branch}' -r $rev2)`;
|
||||
$diff .= `(cd $clonePath ; hg log -r $rev1 -r $rev2 -b $branch)`;
|
||||
$diff .= `(cd $clonePath ; hg diff -r $rev1:$rev2)`;
|
||||
$branch = `(cd $clonePath; hg log --template '{branch}' -r $rev2)`;
|
||||
$diff .= `(cd $clonePath; hg log -r $rev1 -r $rev2 -b $branch)`;
|
||||
$diff .= `(cd $clonePath; hg diff -r $rev1:$rev2)`;
|
||||
} elsif ($type eq "git") {
|
||||
my $clonePath = scmPath . "/" . sha256_hex($uri);
|
||||
die if ! -d $clonePath;
|
||||
$diff .= `(cd $clonePath ; git log $rev1..$rev2)`;
|
||||
$diff .= `(cd $clonePath ; git diff $rev1..$rev2)`;
|
||||
$diff .= `(cd $clonePath; git log $rev1..$rev2)`;
|
||||
$diff .= `(cd $clonePath; git diff $rev1..$rev2)`;
|
||||
}
|
||||
|
||||
$c->stash->{'plain'} = { data => (scalar $diff) || " " };
|
||||
$c->forward('Hydra::View::Plain');
|
||||
}
|
||||
|
||||
|
||||
sub readNormalizedLog {
|
||||
my ($file) = @_;
|
||||
my $pipe = (-f "$file.bz2" ? "cat $file.bz2 | bzip2 -d" : "cat $file") ;
|
||||
my $pipe = (-f "$file.bz2" ? "cat $file.bz2 | bzip2 -d" : "cat $file");
|
||||
my $res = `$pipe`;
|
||||
|
||||
$res =~ s/\/nix\/store\/[a-z0-9]*-/\/nix\/store\/...-/g;
|
||||
@ -240,6 +247,7 @@ sub readNormalizedLog {
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
sub logdiff : Chained('api') PathPart('logdiff') Args(2) {
|
||||
my ($self, $c, $buildid1, $buildid2) = @_;
|
||||
|
||||
@ -252,9 +260,9 @@ sub logdiff : Chained('api') PathPart('logdiff') Args(2) {
|
||||
notFound($c, "Build with ID $buildid2 doesn't exist.")
|
||||
if !defined $build2;
|
||||
|
||||
if (-f $build1->resultInfo->logfile && -f $build2->resultInfo->logfile) {
|
||||
my $logtext1 = readNormalizedLog($build1->resultInfo->logfile);
|
||||
my $logtext2 = readNormalizedLog($build2->resultInfo->logfile);
|
||||
if (-f $build1->logfile && -f $build2->logfile) {
|
||||
my $logtext1 = readNormalizedLog($build1->logfile);
|
||||
my $logtext2 = readNormalizedLog($build2->logfile);
|
||||
$diff = diff \$logtext1, \$logtext2;
|
||||
} else {
|
||||
$c->response->status(404);
|
||||
@ -265,4 +273,5 @@ sub logdiff : Chained('api') PathPart('logdiff') Args(2) {
|
||||
$c->forward('Hydra::View::Plain');
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
@ -48,20 +48,20 @@ sub view_build : Chained('build') PathPart('') Args(0) {
|
||||
$c->stash->{logtext} = `cat $logfile` if defined $logfile && -e $logfile;
|
||||
}
|
||||
|
||||
if (defined $build->resultInfo && $build->resultInfo->iscachedbuild) {
|
||||
if ($build->finished && $build->iscachedbuild) {
|
||||
(my $cachedBuildStep) = $c->model('DB::BuildSteps')->search({ outpath => $build->outpath }, {}) ;
|
||||
$c->stash->{cachedBuild} = $cachedBuildStep->build if defined $cachedBuildStep;
|
||||
}
|
||||
|
||||
(my $lastBuildStep) = $build->buildsteps->search({},{order_by => "stepnr DESC", rows => 1});
|
||||
my $path = defined $lastBuildStep ? $lastBuildStep->logfile : "" ;
|
||||
if (defined $build->resultInfo && ($build->resultInfo->buildstatus == 1 || $build->resultInfo->buildstatus == 6) && !($path eq "") && -f $lastBuildStep->logfile) {
|
||||
if ($build->finished && ($build->buildstatus == 1 || $build->buildstatus == 6) && !($path eq "") && -f $lastBuildStep->logfile) {
|
||||
my $logtext = `tail -n 50 $path`;
|
||||
$c->stash->{logtext} = removeAsciiEscapes($logtext);
|
||||
}
|
||||
|
||||
if($build->finished) {
|
||||
$c->stash->{prevBuilds} = [joinWithResultInfo($c, $c->model('DB::Builds'))->search(
|
||||
if ($build->finished) {
|
||||
$c->stash->{prevBuilds} = [$c->model('DB::Builds')->search(
|
||||
{ project => $c->stash->{project}->name
|
||||
, jobset => $c->stash->{build}->jobset->name
|
||||
, job => $c->stash->{build}->job->name
|
||||
@ -105,9 +105,9 @@ sub view_nixlog : Chained('build') PathPart('nixlog') {
|
||||
sub view_log : Chained('build') PathPart('log') {
|
||||
my ($self, $c, $mode) = @_;
|
||||
|
||||
error($c, "Build didn't produce a log.") if !defined $c->stash->{build}->resultInfo->logfile;
|
||||
error($c, "Build didn't produce a log.") if !defined $c->stash->{build}->logfile;
|
||||
|
||||
showLog($c, $c->stash->{build}->resultInfo->logfile, $mode);
|
||||
showLog($c, $c->stash->{build}->logfile, $mode);
|
||||
}
|
||||
|
||||
|
||||
@ -438,7 +438,7 @@ sub keep : Chained('build') PathPart Args(1) {
|
||||
registerRoot $build->outpath if $newStatus == 1;
|
||||
|
||||
txn_do($c->model('DB')->schema, sub {
|
||||
$build->resultInfo->update({keep => int $newStatus});
|
||||
$build->update({keep => int $newStatus});
|
||||
});
|
||||
|
||||
$c->flash->{buildMsg} =
|
||||
|
@ -25,16 +25,11 @@ sub overview : Chained('job') PathPart('') Args(0) {
|
||||
|
||||
#getBuildStats($c, scalar $c->stash->{job}->builds);
|
||||
|
||||
$c->stash->{currentBuilds} = [$c->stash->{job}->builds->search({iscurrent => 1}, { join => 'resultInfo', '+select' => ["resultInfo.releasename", "resultInfo.buildStatus"]
|
||||
, '+as' => ["releasename", "buildStatus"], order_by => 'system' })];
|
||||
$c->stash->{currentBuilds} = [$c->stash->{job}->builds->search({finished => 1, iscurrent => 1}, { order_by => 'system' })];
|
||||
|
||||
$c->stash->{lastBuilds} =
|
||||
[ $c->stash->{job}->builds->search({ finished => 1 },
|
||||
{ join => 'resultInfo',
|
||||
, '+select' => ["resultInfo.releasename", "resultInfo.buildStatus"]
|
||||
, '+as' => ["releasename", "buildStatus"]
|
||||
, order_by => 'timestamp DESC', rows => 10
|
||||
}) ];
|
||||
{ order_by => 'timestamp DESC', rows => 10 }) ];
|
||||
|
||||
$c->stash->{runningBuilds} = [
|
||||
$c->stash->{job}->builds->search(
|
||||
|
@ -65,9 +65,9 @@ sub jobsetIndex {
|
||||
my @as = ();
|
||||
push(@select, "job"); push(@as, "job");
|
||||
foreach my $system (@systems) {
|
||||
push(@select, "(select buildstatus from BuildResultInfo bri join Builds b using (id) where b.id = (select max(id) from Builds t where t.project = me.project and t.jobset = me.jobset and t.job = me.job and t.system = '$system' and t.iscurrent = 1 ))");
|
||||
push(@select, "(select buildstatus from Builds b where b.id = (select max(id) from Builds t where t.project = me.project and t.jobset = me.jobset and t.job = me.job and t.system = '$system' and t.iscurrent = 1 ))");
|
||||
push(@as, $system);
|
||||
push(@select, "(select b.id from BuildResultInfo bri join Builds b using (id) where b.id = (select max(id) from Builds t where t.project = me.project and t.jobset = me.jobset and t.job = me.job and t.system = '$system' and t.iscurrent = 1 ))");
|
||||
push(@select, "(select b.id from Builds b where b.id = (select max(id) from Builds t where t.project = me.project and t.jobset = me.jobset and t.job = me.job and t.system = '$system' and t.iscurrent = 1 ))");
|
||||
push(@as, "$system-build");
|
||||
}
|
||||
$c->stash->{activeJobsStatus} =
|
||||
@ -81,13 +81,9 @@ sub jobsetIndex {
|
||||
}
|
||||
|
||||
# Last builds for jobset.
|
||||
my $tmp = $c->stash->{jobset}->builds;
|
||||
$c->stash->{lastBuilds} =
|
||||
[ joinWithResultInfo($c, $tmp)->search({ finished => 1 },
|
||||
{ order_by => "timestamp DESC", rows => 5
|
||||
, '+select' => ["resultInfo.buildStatus"]
|
||||
, '+as' => ["buildStatus"]
|
||||
}) ];
|
||||
[ $c->stash->{jobset}->builds->search({ finished => 1 },
|
||||
{ order_by => "timestamp DESC", rows => 5 }) ];
|
||||
}
|
||||
|
||||
|
||||
|
@ -86,13 +86,10 @@ sub timeline :Local {
|
||||
$pit = $pit-(24*60*60)-1;
|
||||
|
||||
$c->stash->{template} = 'timeline.tt';
|
||||
$c->stash->{builds} = [$c->model('DB::Builds')->search(
|
||||
{finished => 1, stoptime => { '>' => $pit } }
|
||||
, { join => 'resultInfo'
|
||||
, order_by => ["starttime"]
|
||||
, '+select' => [ 'resultInfo.starttime', 'resultInfo.stoptime', 'resultInfo.buildstatus' ]
|
||||
, '+as' => [ 'starttime', 'stoptime', 'buildstatus' ]
|
||||
})];
|
||||
$c->stash->{builds} = [ $c->model('DB::Builds')->search
|
||||
( { finished => 1, stoptime => { '>' => $pit } }
|
||||
, { order_by => ["starttime"] }
|
||||
) ];
|
||||
}
|
||||
|
||||
|
||||
|
@ -153,10 +153,7 @@ sub result : Chained('view') PathPart('') {
|
||||
|
||||
# Note: we don't actually check whether $id is a primary build,
|
||||
# but who cares?
|
||||
my $primaryBuild = $c->stash->{project}->builds->find($id,
|
||||
{ join => 'resultInfo',
|
||||
, '+select' => ["resultInfo.releasename", "resultInfo.buildstatus"]
|
||||
, '+as' => ["releasename", "buildstatus"] })
|
||||
my $primaryBuild = $c->stash->{project}->builds->find($id)
|
||||
or error($c, "Build $id doesn't exist.");
|
||||
|
||||
my $result = getViewResult($primaryBuild, $c->stash->{jobs});
|
||||
|
Reference in New Issue
Block a user