2015-08-17 14:18:07 +02:00
|
|
|
|
#! /usr/bin/env perl
|
2008-10-10 16:05:05 +00:00
|
|
|
|
|
|
|
|
|
use strict;
|
2013-09-25 15:51:03 +02:00
|
|
|
|
use utf8;
|
2017-02-21 16:17:31 +01:00
|
|
|
|
use Config::General;
|
|
|
|
|
use Data::Dump qw(dump);
|
|
|
|
|
use Digest::SHA qw(sha256_hex);
|
|
|
|
|
use Encode;
|
|
|
|
|
use File::Slurp;
|
2009-10-26 15:39:14 +00:00
|
|
|
|
use Hydra::Helper::AddBuilds;
|
2017-02-21 16:17:31 +01:00
|
|
|
|
use Hydra::Helper::CatalystUtils;
|
2014-11-19 14:44:04 +01:00
|
|
|
|
use Hydra::Helper::Email;
|
2017-02-21 16:17:31 +01:00
|
|
|
|
use Hydra::Helper::Nix;
|
2012-03-13 12:10:19 +01:00
|
|
|
|
use Hydra::Model::DB;
|
2017-02-21 16:17:31 +01:00
|
|
|
|
use Hydra::Plugin;
|
|
|
|
|
use Hydra::Schema;
|
|
|
|
|
use JSON;
|
2015-07-10 16:40:50 +02:00
|
|
|
|
use Net::Statsd;
|
2017-02-21 16:17:31 +01:00
|
|
|
|
use Nix::Store;
|
2017-02-21 15:49:01 +01:00
|
|
|
|
use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC);
|
2017-02-21 16:17:31 +01:00
|
|
|
|
use Try::Tiny;
|
2008-10-28 10:18:03 +00:00
|
|
|
|
|
2009-04-22 22:59:54 +00:00
|
|
|
|
STDOUT->autoflush();
|
2014-11-19 14:44:04 +01:00
|
|
|
|
STDERR->autoflush(1);
|
|
|
|
|
binmode STDERR, ":encoding(utf8)";
|
2009-04-22 22:59:54 +00:00
|
|
|
|
|
2012-03-13 12:10:19 +01:00
|
|
|
|
my $db = Hydra::Model::DB->new();
|
2017-07-21 14:25:33 +02:00
|
|
|
|
my $notifyAdded = $db->storage->dbh->prepare("notify builds_added, ?");
|
|
|
|
|
|
2013-01-22 13:19:28 +01:00
|
|
|
|
my $config = getHydraConfig();
|
2008-11-05 04:52:52 +00:00
|
|
|
|
|
2013-07-02 13:54:18 +02:00
|
|
|
|
my $plugins = [Hydra::Plugin->instantiate(db => $db, config => $config)];
|
2013-05-25 15:36:58 -04:00
|
|
|
|
|
2015-04-09 17:35:04 +02:00
|
|
|
|
my $dryRun = defined $ENV{'HYDRA_DRY_RUN'};
|
2013-02-25 18:47:54 +01:00
|
|
|
|
|
2017-03-13 15:11:13 +01:00
|
|
|
|
alarm 3600; # FIXME: make configurable
|
|
|
|
|
|
2010-03-05 15:41:10 +00:00
|
|
|
|
|
2017-02-21 16:17:31 +01:00
|
|
|
|
sub parseJobName {
|
|
|
|
|
# Parse a job specification of the form `<project>:<jobset>:<job>
|
|
|
|
|
# [attrs]'. The project, jobset and attrs may be omitted. The
|
|
|
|
|
# attrs have the form `name = "value"'.
|
|
|
|
|
my ($s) = @_;
|
|
|
|
|
our $key;
|
|
|
|
|
our %attrs = ();
|
|
|
|
|
# hm, maybe I should stop programming Perl before it's too late...
|
|
|
|
|
$s =~ / ^ (?: (?: ($projectNameRE) : )? ($jobsetNameRE) : )? ($jobNameRE) \s*
|
|
|
|
|
(\[ \s* (
|
|
|
|
|
([\w]+) (?{ $key = $^N; }) \s* = \s* \"
|
|
|
|
|
([\w\-]+) (?{ $attrs{$key} = $^N; }) \"
|
|
|
|
|
\s* )* \])? $
|
|
|
|
|
/x
|
|
|
|
|
or die "invalid job specifier `$s'";
|
|
|
|
|
return ($1, $2, $3, \%attrs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub attrsToSQL {
|
|
|
|
|
my ($attrs, $id) = @_;
|
|
|
|
|
|
|
|
|
|
my $query = "1 = 1";
|
|
|
|
|
|
|
|
|
|
foreach my $name (keys %{$attrs}) {
|
|
|
|
|
my $value = $attrs->{$name};
|
|
|
|
|
$name =~ /^[\w\-]+$/ or die;
|
|
|
|
|
$value =~ /^[\w\-]+$/ or die;
|
|
|
|
|
# !!! Yes, this is horribly injection-prone... (though
|
|
|
|
|
# name/value are filtered above). Should use SQL::Abstract,
|
|
|
|
|
# but it can't deal with subqueries. At least we should use
|
|
|
|
|
# placeholders.
|
|
|
|
|
$query .= " and exists (select 1 from buildinputs where build = $id and name = '$name' and value = '$value')";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-11-20 16:12:20 +01:00
|
|
|
|
# Fetch a store path from 'eval_substituter' if not already present.
|
|
|
|
|
sub getPath {
|
|
|
|
|
my ($path) = @_;
|
|
|
|
|
return 1 if isValidPath($path);
|
|
|
|
|
|
|
|
|
|
my $substituter = $config->{eval_substituter};
|
|
|
|
|
|
|
|
|
|
system("nix", "copy", "--from", $substituter, "--", $path)
|
|
|
|
|
if defined $substituter;
|
|
|
|
|
|
|
|
|
|
return isValidPath($path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-02-21 16:17:31 +01:00
|
|
|
|
sub fetchInputBuild {
|
|
|
|
|
my ($db, $project, $jobset, $name, $value) = @_;
|
|
|
|
|
|
|
|
|
|
my $prevBuild;
|
|
|
|
|
|
|
|
|
|
if ($value =~ /^\d+$/) {
|
|
|
|
|
$prevBuild = $db->resultset('Builds')->find({ id => int($value) });
|
|
|
|
|
} else {
|
|
|
|
|
my ($projectName, $jobsetName, $jobName, $attrs) = parseJobName($value);
|
|
|
|
|
$projectName ||= $project->name;
|
|
|
|
|
$jobsetName ||= $jobset->name;
|
|
|
|
|
|
|
|
|
|
# Pick the most recent successful build of the specified job.
|
|
|
|
|
$prevBuild = $db->resultset('Builds')->search(
|
|
|
|
|
{ finished => 1, project => $projectName, jobset => $jobsetName
|
|
|
|
|
, job => $jobName, buildStatus => 0 },
|
|
|
|
|
{ order_by => "me.id DESC", rows => 1
|
|
|
|
|
, where => \ attrsToSQL($attrs, "me.id") })->single;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-20 16:12:20 +01:00
|
|
|
|
return () if !defined $prevBuild || !getPath(getMainOutput($prevBuild)->path);
|
2017-02-21 16:17:31 +01:00
|
|
|
|
|
|
|
|
|
#print STDERR "input `", $name, "': using build ", $prevBuild->id, "\n";
|
|
|
|
|
|
|
|
|
|
my $pkgNameRE = "(?:(?:[A-Za-z0-9]|(?:-[^0-9]))+)";
|
|
|
|
|
my $versionRE = "(?:[A-Za-z0-9\.\-]+)";
|
|
|
|
|
|
|
|
|
|
my $relName = ($prevBuild->releasename or $prevBuild->nixname);
|
|
|
|
|
my $version = $2 if $relName =~ /^($pkgNameRE)-($versionRE)$/;
|
|
|
|
|
|
|
|
|
|
my $mainOutput = getMainOutput($prevBuild);
|
|
|
|
|
|
|
|
|
|
my $result =
|
|
|
|
|
{ storePath => $mainOutput->path
|
|
|
|
|
, id => $prevBuild->id
|
|
|
|
|
, version => $version
|
|
|
|
|
, outputName => $mainOutput->name
|
|
|
|
|
};
|
|
|
|
|
if (isValidPath($prevBuild->drvpath)) {
|
|
|
|
|
$result->{drvPath} = $prevBuild->drvpath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub fetchInputSystemBuild {
|
|
|
|
|
my ($db, $project, $jobset, $name, $value) = @_;
|
|
|
|
|
|
|
|
|
|
my ($projectName, $jobsetName, $jobName, $attrs) = parseJobName($value);
|
|
|
|
|
$projectName ||= $project->name;
|
|
|
|
|
$jobsetName ||= $jobset->name;
|
|
|
|
|
|
|
|
|
|
my @latestBuilds = $db->resultset('LatestSucceededForJob')
|
|
|
|
|
->search({}, {bind => [$projectName, $jobsetName, $jobName]});
|
|
|
|
|
|
|
|
|
|
my @validBuilds = ();
|
|
|
|
|
foreach my $build (@latestBuilds) {
|
2017-11-20 16:12:20 +01:00
|
|
|
|
push(@validBuilds, $build) if getPath(getMainOutput($build)->path);
|
2017-02-21 16:17:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (scalar(@validBuilds) == 0) {
|
|
|
|
|
print STDERR "input `", $name, "': no previous build available\n";
|
|
|
|
|
return ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my @inputs = ();
|
|
|
|
|
|
|
|
|
|
foreach my $prevBuild (@validBuilds) {
|
|
|
|
|
my $pkgNameRE = "(?:(?:[A-Za-z0-9]|(?:-[^0-9]))+)";
|
|
|
|
|
my $versionRE = "(?:[A-Za-z0-9\.\-]+)";
|
|
|
|
|
|
|
|
|
|
my $relName = ($prevBuild->releasename or $prevBuild->nixname);
|
|
|
|
|
my $version = $2 if $relName =~ /^($pkgNameRE)-($versionRE)$/;
|
|
|
|
|
|
|
|
|
|
my $input =
|
|
|
|
|
{ storePath => getMainOutput($prevBuild)->path
|
|
|
|
|
, id => $prevBuild->id
|
|
|
|
|
, version => $version
|
|
|
|
|
, system => $prevBuild->system
|
|
|
|
|
};
|
|
|
|
|
push(@inputs, $input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return @inputs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub fetchInputEval {
|
|
|
|
|
my ($db, $project, $jobset, $name, $value) = @_;
|
|
|
|
|
|
|
|
|
|
my $eval;
|
|
|
|
|
|
|
|
|
|
if ($value =~ /^\d+$/) {
|
|
|
|
|
$eval = $db->resultset('JobsetEvals')->find({ id => int($value) });
|
|
|
|
|
die "evaluation $eval->{id} does not exist\n" unless defined $eval;
|
|
|
|
|
} elsif ($value =~ /^($projectNameRE):($jobsetNameRE)$/) {
|
|
|
|
|
my $jobset = $db->resultset('Jobsets')->find({ project => $1, name => $2 });
|
|
|
|
|
die "jobset ‘$value’ does not exist\n" unless defined $jobset;
|
|
|
|
|
$eval = getLatestFinishedEval($jobset);
|
|
|
|
|
die "jobset ‘$value’ does not have a finished evaluation\n" unless defined $eval;
|
|
|
|
|
} elsif ($value =~ /^($projectNameRE):($jobsetNameRE):($jobNameRE)$/) {
|
|
|
|
|
$eval = $db->resultset('JobsetEvals')->find(
|
|
|
|
|
{ project => $1, jobset => $2, hasnewbuilds => 1 },
|
|
|
|
|
{ order_by => "id DESC", rows => 1
|
|
|
|
|
, where =>
|
|
|
|
|
\ [ # All builds in this jobset should be finished...
|
|
|
|
|
"not exists (select 1 from JobsetEvalMembers m join Builds b on m.build = b.id where m.eval = me.id and b.finished = 0) "
|
|
|
|
|
# ...and the specified build must have succeeded.
|
|
|
|
|
. "and exists (select 1 from JobsetEvalMembers m join Builds b on m.build = b.id where m.eval = me.id and b.job = ? and b.buildstatus = 0)"
|
|
|
|
|
, [ 'name', $3 ] ]
|
|
|
|
|
});
|
|
|
|
|
die "there is no successful build of ‘$value’ in a finished evaluation\n" unless defined $eval;
|
|
|
|
|
} else {
|
|
|
|
|
die;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $jobs = {};
|
|
|
|
|
foreach my $build ($eval->builds) {
|
|
|
|
|
next unless $build->finished == 1 && $build->buildstatus == 0;
|
|
|
|
|
# FIXME: Handle multiple outputs.
|
|
|
|
|
my $out = $build->buildoutputs->find({ name => "out" });
|
|
|
|
|
next unless defined $out;
|
|
|
|
|
# FIXME: Should we fail if the path is not valid?
|
|
|
|
|
next unless isValidPath($out->path);
|
|
|
|
|
$jobs->{$build->get_column('job')} = $out->path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { jobs => $jobs };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub fetchInput {
|
|
|
|
|
my ($plugins, $db, $project, $jobset, $name, $type, $value, $emailresponsible) = @_;
|
|
|
|
|
my @inputs;
|
|
|
|
|
|
|
|
|
|
if ($type eq "build") {
|
|
|
|
|
@inputs = fetchInputBuild($db, $project, $jobset, $name, $value);
|
|
|
|
|
}
|
|
|
|
|
elsif ($type eq "sysbuild") {
|
|
|
|
|
@inputs = fetchInputSystemBuild($db, $project, $jobset, $name, $value);
|
|
|
|
|
}
|
|
|
|
|
elsif ($type eq "eval") {
|
|
|
|
|
@inputs = fetchInputEval($db, $project, $jobset, $name, $value);
|
|
|
|
|
}
|
|
|
|
|
elsif ($type eq "string" || $type eq "nix") {
|
|
|
|
|
die unless defined $value;
|
|
|
|
|
@inputs = { value => $value };
|
|
|
|
|
}
|
|
|
|
|
elsif ($type eq "boolean") {
|
|
|
|
|
die unless defined $value && ($value eq "true" || $value eq "false");
|
|
|
|
|
@inputs = { value => $value };
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
my $found = 0;
|
|
|
|
|
foreach my $plugin (@{$plugins}) {
|
|
|
|
|
@inputs = $plugin->fetchInput($type, $name, $value, $project, $jobset);
|
|
|
|
|
if (defined $inputs[0]) {
|
|
|
|
|
$found = 1;
|
|
|
|
|
last;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
die "input `$name' has unknown type `$type'." unless $found;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach my $input (@inputs) {
|
|
|
|
|
$input->{type} = $type;
|
|
|
|
|
$input->{emailresponsible} = $emailresponsible;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return @inputs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub booleanToString {
|
|
|
|
|
my ($exprType, $value) = @_;
|
|
|
|
|
my $result;
|
|
|
|
|
if ($exprType eq "guile") {
|
|
|
|
|
if ($value eq "true") {
|
|
|
|
|
$result = "#t";
|
|
|
|
|
} else {
|
|
|
|
|
$result = "#f";
|
|
|
|
|
}
|
|
|
|
|
$result = $value;
|
|
|
|
|
} else {
|
|
|
|
|
$result = $value;
|
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub buildInputToString {
|
|
|
|
|
my ($exprType, $input) = @_;
|
|
|
|
|
my $result;
|
|
|
|
|
if ($exprType eq "guile") {
|
|
|
|
|
$result = "'((file-name . \"" . ${input}->{storePath} . "\")" .
|
|
|
|
|
(defined $input->{revision} ? "(revision . \"" . $input->{revision} . "\")" : "") .
|
|
|
|
|
(defined $input->{revCount} ? "(revision-count . " . $input->{revCount} . ")" : "") .
|
|
|
|
|
(defined $input->{gitTag} ? "(git-tag . \"" . $input->{gitTag} . "\")" : "") .
|
|
|
|
|
(defined $input->{shortRev} ? "(short-revision . \"" . $input->{shortRev} . "\")" : "") .
|
|
|
|
|
(defined $input->{version} ? "(version . \"" . $input->{version} . "\")" : "") .
|
|
|
|
|
")";
|
|
|
|
|
} else {
|
|
|
|
|
$result = "{ outPath = builtins.storePath " . $input->{storePath} . "" .
|
|
|
|
|
"; inputType = \"" . $input->{type} . "\"" .
|
|
|
|
|
(defined $input->{uri} ? "; uri = \"" . $input->{uri} . "\"" : "") .
|
|
|
|
|
(defined $input->{revNumber} ? "; rev = " . $input->{revNumber} . "" : "") .
|
|
|
|
|
(defined $input->{revision} ? "; rev = \"" . $input->{revision} . "\"" : "") .
|
|
|
|
|
(defined $input->{revCount} ? "; revCount = " . $input->{revCount} . "" : "") .
|
|
|
|
|
(defined $input->{gitTag} ? "; gitTag = \"" . $input->{gitTag} . "\"" : "") .
|
|
|
|
|
(defined $input->{shortRev} ? "; shortRev = \"" . $input->{shortRev} . "\"" : "") .
|
|
|
|
|
(defined $input->{version} ? "; version = \"" . $input->{version} . "\"" : "") .
|
|
|
|
|
(defined $input->{outputName} ? "; outputName = \"" . $input->{outputName} . "\"" : "") .
|
|
|
|
|
(defined $input->{drvPath} ? "; drvPath = builtins.storePath " . $input->{drvPath} . "" : "") .
|
|
|
|
|
";}";
|
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub inputsToArgs {
|
|
|
|
|
my ($inputInfo, $exprType) = @_;
|
|
|
|
|
my @res = ();
|
|
|
|
|
|
|
|
|
|
foreach my $input (sort keys %{$inputInfo}) {
|
|
|
|
|
push @res, "-I", "$input=$inputInfo->{$input}->[0]->{storePath}"
|
|
|
|
|
if scalar @{$inputInfo->{$input}} == 1
|
|
|
|
|
&& defined $inputInfo->{$input}->[0]->{storePath};
|
2017-10-26 13:10:14 +02:00
|
|
|
|
|
|
|
|
|
die "multiple jobset input alternatives are no longer supported"
|
|
|
|
|
if scalar @{$inputInfo->{$input}} != 1;
|
|
|
|
|
|
|
|
|
|
my $alt = $inputInfo->{$input}->[0];
|
|
|
|
|
|
|
|
|
|
if ($alt->{type} eq "string") {
|
|
|
|
|
push @res, "--argstr", $input, $alt->{value};
|
|
|
|
|
}
|
|
|
|
|
elsif ($alt->{type} eq "boolean") {
|
|
|
|
|
push @res, "--arg", $input, booleanToString($exprType, $alt->{value});
|
|
|
|
|
}
|
|
|
|
|
elsif ($alt->{type} eq "nix") {
|
|
|
|
|
die "input type ‘nix’ only supported for Nix-based jobsets\n" unless $exprType eq "nix";
|
|
|
|
|
push @res, "--arg", $input, $alt->{value};
|
|
|
|
|
}
|
|
|
|
|
elsif ($alt->{type} eq "eval") {
|
|
|
|
|
die "input type ‘eval’ only supported for Nix-based jobsets\n" unless $exprType eq "nix";
|
|
|
|
|
my $s = "{ ";
|
|
|
|
|
# FIXME: escape $_. But dots should not be escaped.
|
|
|
|
|
$s .= "$_ = builtins.storePath ${\$alt->{jobs}->{$_}}; "
|
|
|
|
|
foreach keys %{$alt->{jobs}};
|
|
|
|
|
$s .= "}";
|
|
|
|
|
push @res, "--arg", $input, $s;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
push @res, "--arg", $input, buildInputToString($exprType, $alt);
|
2017-02-21 16:17:31 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return @res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub evalJobs {
|
|
|
|
|
my ($inputInfo, $exprType, $nixExprInputName, $nixExprPath) = @_;
|
|
|
|
|
|
|
|
|
|
my $nixExprInput = $inputInfo->{$nixExprInputName}->[0]
|
|
|
|
|
or die "cannot find the input containing the job expression\n";
|
|
|
|
|
|
|
|
|
|
my $evaluator = ($exprType eq "guile") ? "hydra-eval-guile-jobs" : "hydra-eval-jobs";
|
|
|
|
|
|
2017-11-28 16:51:00 +01:00
|
|
|
|
my @cmd = ($evaluator,
|
|
|
|
|
"<" . $nixExprInputName . "/" . $nixExprPath . ">",
|
|
|
|
|
"--gc-roots-dir", getGCRootsDir,
|
|
|
|
|
"-j", 1,
|
|
|
|
|
inputsToArgs($inputInfo, $exprType));
|
2017-02-21 16:17:31 +01:00
|
|
|
|
|
|
|
|
|
if (defined $ENV{'HYDRA_DEBUG'}) {
|
|
|
|
|
sub escape {
|
|
|
|
|
my $s = $_;
|
|
|
|
|
$s =~ s/'/'\\''/g;
|
|
|
|
|
return "'" . $s . "'";
|
|
|
|
|
}
|
|
|
|
|
my @escaped = map escape, @cmd;
|
|
|
|
|
print STDERR "evaluator: @escaped\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(my $res, my $jobsJSON, my $stderr) = captureStdoutStderr(21600, @cmd);
|
|
|
|
|
die "$evaluator returned " . ($res & 127 ? "signal $res" : "exit code " . ($res >> 8))
|
|
|
|
|
. ":\n" . ($stderr ? decode("utf-8", $stderr) : "(no output)\n")
|
|
|
|
|
if $res;
|
|
|
|
|
|
|
|
|
|
print STDERR "$stderr";
|
|
|
|
|
|
|
|
|
|
return (decode_json($jobsJSON), $nixExprInput);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Return the most recent evaluation of the given jobset (that
|
|
|
|
|
# optionally had new builds), or undefined if no such evaluation
|
|
|
|
|
# exists.
|
|
|
|
|
sub getPrevJobsetEval {
|
|
|
|
|
my ($db, $jobset, $hasNewBuilds) = @_;
|
|
|
|
|
my ($prevEval) = $jobset->jobsetevals(
|
|
|
|
|
($hasNewBuilds ? { hasnewbuilds => 1 } : { }),
|
|
|
|
|
{ order_by => "id DESC", rows => 1 });
|
|
|
|
|
return $prevEval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Check whether to add the build described by $buildInfo.
|
|
|
|
|
sub checkBuild {
|
|
|
|
|
my ($db, $jobset, $inputInfo, $nixExprInput, $buildInfo, $buildMap, $prevEval, $jobOutPathMap, $plugins) = @_;
|
|
|
|
|
|
|
|
|
|
my @outputNames = sort keys %{$buildInfo->{outputs}};
|
|
|
|
|
die unless scalar @outputNames;
|
|
|
|
|
|
|
|
|
|
# In various checks we can use an arbitrary output (the first)
|
|
|
|
|
# rather than all outputs, since if one output is the same, the
|
|
|
|
|
# others will be as well.
|
|
|
|
|
my $firstOutputName = $outputNames[0];
|
|
|
|
|
my $firstOutputPath = $buildInfo->{outputs}->{$firstOutputName};
|
|
|
|
|
|
|
|
|
|
my $jobName = $buildInfo->{jobName} or die;
|
|
|
|
|
my $drvPath = $buildInfo->{drvPath} or die;
|
|
|
|
|
|
|
|
|
|
my $build;
|
|
|
|
|
|
|
|
|
|
txn_do($db, sub {
|
|
|
|
|
my $job = $jobset->jobs->update_or_create({ name => $jobName });
|
|
|
|
|
|
|
|
|
|
# Don't add a build that has already been scheduled for this
|
|
|
|
|
# job, or has been built but is still a "current" build for
|
|
|
|
|
# this job. Note that this means that if the sources of a job
|
|
|
|
|
# are changed from A to B and then reverted to A, three builds
|
|
|
|
|
# will be performed (though the last one will probably use the
|
|
|
|
|
# cached result from the first). This ensures that the builds
|
|
|
|
|
# with the highest ID will always be the ones that we want in
|
|
|
|
|
# the channels. FIXME: Checking the output paths doesn't take
|
|
|
|
|
# meta-attributes into account. For instance, do we want a
|
|
|
|
|
# new build to be scheduled if the meta.maintainers field is
|
|
|
|
|
# changed?
|
|
|
|
|
if (defined $prevEval) {
|
|
|
|
|
# Only check one output: if it's the same, the other will be as well.
|
|
|
|
|
my $firstOutput = $outputNames[0];
|
|
|
|
|
my ($prevBuild) = $prevEval->builds->search(
|
|
|
|
|
# The "project" and "jobset" constraints are
|
|
|
|
|
# semantically unnecessary (because they're implied by
|
|
|
|
|
# the eval), but they give a factor 1000 speedup on
|
|
|
|
|
# the Nixpkgs jobset with PostgreSQL.
|
|
|
|
|
{ project => $jobset->project->name, jobset => $jobset->name, job => $jobName,
|
|
|
|
|
name => $firstOutputName, path => $firstOutputPath },
|
|
|
|
|
{ rows => 1, columns => ['id'], join => ['buildoutputs'] });
|
|
|
|
|
if (defined $prevBuild) {
|
|
|
|
|
#print STDERR " already scheduled/built as build ", $prevBuild->id, "\n";
|
|
|
|
|
$buildMap->{$prevBuild->id} = { id => $prevBuild->id, jobName => $jobName, new => 0, drvPath => $drvPath };
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Prevent multiple builds with the same (job, outPath) from
|
|
|
|
|
# being added.
|
|
|
|
|
my $prev = $$jobOutPathMap{$jobName . "\t" . $firstOutputPath};
|
|
|
|
|
if (defined $prev) {
|
|
|
|
|
#print STDERR " already scheduled as build ", $prev, "\n";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $time = time();
|
|
|
|
|
|
|
|
|
|
sub null {
|
|
|
|
|
my ($s) = @_;
|
|
|
|
|
return $s eq "" ? undef : $s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Add the build to the database.
|
|
|
|
|
$build = $job->builds->create(
|
|
|
|
|
{ timestamp => $time
|
|
|
|
|
, description => null($buildInfo->{description})
|
|
|
|
|
, license => null($buildInfo->{license})
|
|
|
|
|
, homepage => null($buildInfo->{homepage})
|
|
|
|
|
, maintainers => null($buildInfo->{maintainers})
|
|
|
|
|
, maxsilent => $buildInfo->{maxSilent}
|
|
|
|
|
, timeout => $buildInfo->{timeout}
|
|
|
|
|
, nixname => $buildInfo->{nixName}
|
|
|
|
|
, drvpath => $drvPath
|
|
|
|
|
, system => $buildInfo->{system}
|
|
|
|
|
, nixexprinput => $jobset->nixexprinput
|
|
|
|
|
, nixexprpath => $jobset->nixexprpath
|
|
|
|
|
, priority => $buildInfo->{schedulingPriority}
|
|
|
|
|
, finished => 0
|
|
|
|
|
, iscurrent => 1
|
|
|
|
|
, ischannel => $buildInfo->{isChannel}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$build->buildoutputs->create({ name => $_, path => $buildInfo->{outputs}->{$_} })
|
|
|
|
|
foreach @outputNames;
|
|
|
|
|
|
|
|
|
|
$buildMap->{$build->id} = { id => $build->id, jobName => $jobName, new => 1, drvPath => $drvPath };
|
|
|
|
|
$$jobOutPathMap{$jobName . "\t" . $firstOutputPath} = $build->id;
|
|
|
|
|
|
|
|
|
|
print STDERR "added build ${\$build->id} (${\$jobset->project->name}:${\$jobset->name}:$jobName)\n";
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return $build;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2009-03-09 13:04:46 +00:00
|
|
|
|
sub fetchInputs {
|
2009-03-09 13:58:43 +00:00
|
|
|
|
my ($project, $jobset, $inputInfo) = @_;
|
2009-03-09 13:04:46 +00:00
|
|
|
|
foreach my $input ($jobset->jobsetinputs->all) {
|
|
|
|
|
foreach my $alt ($input->jobsetinputalts->all) {
|
2013-05-25 15:36:58 -04:00
|
|
|
|
push @{$$inputInfo{$input->name}}, $_
|
2013-10-08 14:47:24 -04:00
|
|
|
|
foreach fetchInput($plugins, $db, $project, $jobset, $input->name, $input->type, $alt->value, $input->emailresponsible);
|
2009-03-09 13:04:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-11-25 13:27:57 +00:00
|
|
|
|
sub setJobsetError {
|
|
|
|
|
my ($jobset, $errorMsg) = @_;
|
2013-09-24 12:01:40 -04:00
|
|
|
|
my $prevError = $jobset->errormsg;
|
|
|
|
|
|
2008-11-25 13:27:57 +00:00
|
|
|
|
eval {
|
2009-04-22 22:43:04 +00:00
|
|
|
|
txn_do($db, sub {
|
2013-09-25 16:21:16 +02:00
|
|
|
|
$jobset->update({ errormsg => $errorMsg, errortime => time, fetcherrormsg => undef });
|
2008-11-25 13:27:57 +00:00
|
|
|
|
});
|
|
|
|
|
};
|
2014-11-19 14:44:04 +01:00
|
|
|
|
if (defined $errorMsg && $errorMsg ne ($prevError // "") || $ENV{'HYDRA_MAIL_TEST'}) {
|
2013-09-24 12:01:40 -04:00
|
|
|
|
sendJobsetErrorNotification($jobset, $errorMsg);
|
|
|
|
|
}
|
2008-11-25 13:27:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-03 10:10:45 +00:00
|
|
|
|
|
2009-12-18 12:07:45 +00:00
|
|
|
|
sub sendJobsetErrorNotification() {
|
|
|
|
|
my ($jobset, $errorMsg) = @_;
|
|
|
|
|
|
2014-11-19 14:44:04 +01:00
|
|
|
|
chomp $errorMsg;
|
|
|
|
|
|
2018-08-01 16:56:53 +02:00
|
|
|
|
return unless $config->{email_notification} // 0;
|
2009-12-18 12:07:45 +00:00
|
|
|
|
return if $jobset->project->owner->emailonerror == 0;
|
2013-01-22 13:19:28 +01:00
|
|
|
|
return if $errorMsg eq "";
|
2009-12-18 12:07:45 +00:00
|
|
|
|
|
|
|
|
|
my $projectName = $jobset->project->name;
|
|
|
|
|
my $jobsetName = $jobset->name;
|
|
|
|
|
my $body = "Hi,\n"
|
|
|
|
|
. "\n"
|
2014-11-19 14:44:04 +01:00
|
|
|
|
. "This is to let you know that evaluation of the Hydra jobset ‘$projectName:$jobsetName’\n"
|
2009-12-18 12:07:45 +00:00
|
|
|
|
. "resulted in the following error:\n"
|
|
|
|
|
. "\n"
|
|
|
|
|
. "$errorMsg"
|
|
|
|
|
. "\n"
|
|
|
|
|
. "Regards,\n\nThe Hydra build daemon.\n";
|
|
|
|
|
|
2014-11-19 14:44:04 +01:00
|
|
|
|
try {
|
|
|
|
|
sendEmail(
|
|
|
|
|
$config,
|
|
|
|
|
$jobset->project->owner->emailaddress,
|
|
|
|
|
"Hydra $projectName:$jobsetName evaluation error",
|
|
|
|
|
$body,
|
|
|
|
|
[ 'X-Hydra-Project' => $projectName
|
|
|
|
|
, 'X-Hydra-Jobset' => $jobsetName
|
|
|
|
|
]);
|
|
|
|
|
} catch {
|
|
|
|
|
warn "error sending email: $_\n";
|
|
|
|
|
};
|
2009-12-18 12:07:45 +00:00
|
|
|
|
}
|
2008-11-25 13:27:57 +00:00
|
|
|
|
|
2012-03-07 18:48:10 +01:00
|
|
|
|
|
2009-04-23 15:40:36 +00:00
|
|
|
|
sub permute {
|
|
|
|
|
my @list = @_;
|
|
|
|
|
for (my $n = scalar @list - 1; $n > 0; $n--) {
|
2013-01-22 13:19:28 +01:00
|
|
|
|
my $k = int(rand($n + 1)); # 0 <= $k <= $n
|
2009-04-23 15:40:36 +00:00
|
|
|
|
@list[$n, $k] = @list[$k, $n];
|
|
|
|
|
}
|
|
|
|
|
return @list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-02-25 18:47:54 +01:00
|
|
|
|
sub checkJobsetWrapped {
|
|
|
|
|
my ($jobset) = @_;
|
|
|
|
|
my $project = $jobset->project;
|
Enable declarative projects.
This allows fully declarative project specifications. This is best
illustrated by example:
* I create a new project, setting the declarative spec file to
"spec.json" and the declarative input to a git repo pointing
at git://github.com/shlevy/declarative-hydra-example.git
* hydra creates a special ".jobsets" jobset alongside the project
* Just before evaluating the ".jobsets" jobset, hydra fetches
declarative-hydra-example.git, reads spec.json as a jobset spec,
and updates the jobset's configuration accordingly:
{
"enabled": 1,
"hidden": false,
"description": "Jobsets",
"nixexprinput": "src",
"nixexprpath": "default.nix",
"checkinterval": 300,
"schedulingshares": 100,
"enableemail": false,
"emailoverride": "",
"keepnr": 3,
"inputs": {
"src": { "type": "git", "value": "git://github.com/shlevy/declarative-hydra-example.git", "emailresponsible": false },
"nixpkgs": { "type": "git", "value": "git://github.com/NixOS/nixpkgs.git release-16.03", "emailresponsible": false }
}
}
* When the "jobsets" job of the ".jobsets" jobset completes, hydra
reads its output as a JSON representation of a dictionary of
jobset specs and creates a jobset named "master" configured
accordingly (In this example, this is the same configuration as
.jobsets itself, except using release.nix instead of default.nix):
{
"enabled": 1,
"hidden": false,
"description": "js",
"nixexprinput": "src",
"nixexprpath": "release.nix",
"checkinterval": 300,
"schedulingshares": 100,
"enableemail": false,
"emailoverride": "",
"keepnr": 3,
"inputs": {
"src": { "type": "git", "value": "git://github.com/shlevy/declarative-hydra-example.git", "emailresponsible": false },
"nixpkgs": { "type": "git", "value": "git://github.com/NixOS/nixpkgs.git release-16.03", "emailresponsible": false }
}
}
2016-03-11 18:14:58 -05:00
|
|
|
|
my $jobsetsJobset = length($project->declfile) && $jobset->name eq ".jobsets";
|
2016-04-12 14:35:57 -04:00
|
|
|
|
my $inputInfo = {};
|
Enable declarative projects.
This allows fully declarative project specifications. This is best
illustrated by example:
* I create a new project, setting the declarative spec file to
"spec.json" and the declarative input to a git repo pointing
at git://github.com/shlevy/declarative-hydra-example.git
* hydra creates a special ".jobsets" jobset alongside the project
* Just before evaluating the ".jobsets" jobset, hydra fetches
declarative-hydra-example.git, reads spec.json as a jobset spec,
and updates the jobset's configuration accordingly:
{
"enabled": 1,
"hidden": false,
"description": "Jobsets",
"nixexprinput": "src",
"nixexprpath": "default.nix",
"checkinterval": 300,
"schedulingshares": 100,
"enableemail": false,
"emailoverride": "",
"keepnr": 3,
"inputs": {
"src": { "type": "git", "value": "git://github.com/shlevy/declarative-hydra-example.git", "emailresponsible": false },
"nixpkgs": { "type": "git", "value": "git://github.com/NixOS/nixpkgs.git release-16.03", "emailresponsible": false }
}
}
* When the "jobsets" job of the ".jobsets" jobset completes, hydra
reads its output as a JSON representation of a dictionary of
jobset specs and creates a jobset named "master" configured
accordingly (In this example, this is the same configuration as
.jobsets itself, except using release.nix instead of default.nix):
{
"enabled": 1,
"hidden": false,
"description": "js",
"nixexprinput": "src",
"nixexprpath": "release.nix",
"checkinterval": 300,
"schedulingshares": 100,
"enableemail": false,
"emailoverride": "",
"keepnr": 3,
"inputs": {
"src": { "type": "git", "value": "git://github.com/shlevy/declarative-hydra-example.git", "emailresponsible": false },
"nixpkgs": { "type": "git", "value": "git://github.com/NixOS/nixpkgs.git release-16.03", "emailresponsible": false }
}
}
2016-03-11 18:14:58 -05:00
|
|
|
|
if ($jobsetsJobset) {
|
|
|
|
|
my @declInputs = fetchInput($plugins, $db, $project, $jobset, "decl", $project->decltype, $project->declvalue, 0);
|
|
|
|
|
my $declInput = @declInputs[0] or die "cannot find the input containing the declarative project specification\n";
|
|
|
|
|
die "multiple alternatives for the input containing the declarative project specificaiton are not supported\n"
|
|
|
|
|
if scalar @declInputs != 1;
|
|
|
|
|
my $declFile = $declInput->{storePath} . "/" . $project->declfile;
|
|
|
|
|
my $declText = read_file($declFile)
|
|
|
|
|
or die "Couldn't read declarative specification file $declFile: $!\n";
|
|
|
|
|
my $declSpec;
|
|
|
|
|
eval {
|
|
|
|
|
$declSpec = decode_json($declText);
|
|
|
|
|
};
|
|
|
|
|
die "Declarative specification file $declFile not valid JSON: $@\n" if $@;
|
|
|
|
|
updateDeclarativeJobset($db, $project, ".jobsets", $declSpec);
|
|
|
|
|
$jobset->discard_changes;
|
2016-04-12 14:35:57 -04:00
|
|
|
|
$inputInfo->{"declInput"} = [ $declInput ];
|
Enable declarative projects.
This allows fully declarative project specifications. This is best
illustrated by example:
* I create a new project, setting the declarative spec file to
"spec.json" and the declarative input to a git repo pointing
at git://github.com/shlevy/declarative-hydra-example.git
* hydra creates a special ".jobsets" jobset alongside the project
* Just before evaluating the ".jobsets" jobset, hydra fetches
declarative-hydra-example.git, reads spec.json as a jobset spec,
and updates the jobset's configuration accordingly:
{
"enabled": 1,
"hidden": false,
"description": "Jobsets",
"nixexprinput": "src",
"nixexprpath": "default.nix",
"checkinterval": 300,
"schedulingshares": 100,
"enableemail": false,
"emailoverride": "",
"keepnr": 3,
"inputs": {
"src": { "type": "git", "value": "git://github.com/shlevy/declarative-hydra-example.git", "emailresponsible": false },
"nixpkgs": { "type": "git", "value": "git://github.com/NixOS/nixpkgs.git release-16.03", "emailresponsible": false }
}
}
* When the "jobsets" job of the ".jobsets" jobset completes, hydra
reads its output as a JSON representation of a dictionary of
jobset specs and creates a jobset named "master" configured
accordingly (In this example, this is the same configuration as
.jobsets itself, except using release.nix instead of default.nix):
{
"enabled": 1,
"hidden": false,
"description": "js",
"nixexprinput": "src",
"nixexprpath": "release.nix",
"checkinterval": 300,
"schedulingshares": 100,
"enableemail": false,
"emailoverride": "",
"keepnr": 3,
"inputs": {
"src": { "type": "git", "value": "git://github.com/shlevy/declarative-hydra-example.git", "emailresponsible": false },
"nixpkgs": { "type": "git", "value": "git://github.com/NixOS/nixpkgs.git release-16.03", "emailresponsible": false }
}
}
2016-03-11 18:14:58 -05:00
|
|
|
|
}
|
2012-08-16 19:07:04 +02:00
|
|
|
|
my $exprType = $jobset->nixexprpath =~ /.scm$/ ? "guile" : "nix";
|
2013-01-22 13:19:28 +01:00
|
|
|
|
|
2009-03-09 13:04:46 +00:00
|
|
|
|
# Fetch all values for all inputs.
|
2017-02-21 15:49:01 +01:00
|
|
|
|
my $checkoutStart = clock_gettime(CLOCK_MONOTONIC);
|
2013-09-25 16:21:16 +02:00
|
|
|
|
eval {
|
|
|
|
|
fetchInputs($project, $jobset, $inputInfo);
|
|
|
|
|
};
|
2015-09-11 13:49:46 +02:00
|
|
|
|
my $fetchError = $@;
|
2015-07-10 16:40:50 +02:00
|
|
|
|
|
|
|
|
|
Net::Statsd::increment("hydra.evaluator.checkouts");
|
2017-02-21 15:49:01 +01:00
|
|
|
|
my $checkoutStop = clock_gettime(CLOCK_MONOTONIC);
|
2015-07-10 16:40:50 +02:00
|
|
|
|
Net::Statsd::timing("hydra.evaluator.checkout_time", int(($checkoutStop - $checkoutStart) * 1000));
|
|
|
|
|
|
2015-09-11 13:49:46 +02:00
|
|
|
|
if ($fetchError) {
|
2015-07-10 16:40:50 +02:00
|
|
|
|
Net::Statsd::increment("hydra.evaluator.failed_checkouts");
|
2015-09-11 13:49:46 +02:00
|
|
|
|
print STDERR $fetchError;
|
2013-09-25 16:21:16 +02:00
|
|
|
|
txn_do($db, sub {
|
2015-09-11 13:49:46 +02:00
|
|
|
|
$jobset->update({ lastcheckedtime => time, fetcherrormsg => $fetchError }) if !$dryRun;
|
2013-09-25 16:21:16 +02:00
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-11-07 14:51:44 +00:00
|
|
|
|
|
2011-11-30 18:13:35 +01:00
|
|
|
|
# Hash the arguments to hydra-eval-jobs and check the
|
2012-03-07 18:48:10 +01:00
|
|
|
|
# JobsetInputHashes to see if the previous evaluation had the same
|
2009-11-17 13:55:22 +00:00
|
|
|
|
# inputs. If so, bail out.
|
2012-08-16 19:07:04 +02:00
|
|
|
|
my @args = ($jobset->nixexprinput, $jobset->nixexprpath, inputsToArgs($inputInfo, $exprType));
|
2009-11-17 13:55:22 +00:00
|
|
|
|
my $argsHash = sha256_hex("@args");
|
2012-03-12 21:13:28 +01:00
|
|
|
|
my $prevEval = getPrevJobsetEval($db, $jobset, 0);
|
2016-10-24 20:20:20 +02:00
|
|
|
|
if (defined $prevEval && $prevEval->hash eq $argsHash && !$dryRun && !$jobset->forceeval) {
|
2012-03-07 18:48:10 +01:00
|
|
|
|
print STDERR " jobset is unchanged, skipping\n";
|
2015-07-10 16:40:50 +02:00
|
|
|
|
Net::Statsd::increment("hydra.evaluator.unchanged_checkouts");
|
2009-11-17 13:55:22 +00:00
|
|
|
|
txn_do($db, sub {
|
2013-09-25 16:21:16 +02:00
|
|
|
|
$jobset->update({ lastcheckedtime => time, fetcherrormsg => undef });
|
2009-11-17 13:55:22 +00:00
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-01-22 13:19:28 +01:00
|
|
|
|
|
2009-03-09 13:04:46 +00:00
|
|
|
|
# Evaluate the job expression.
|
2017-02-21 15:49:01 +01:00
|
|
|
|
my $evalStart = clock_gettime(CLOCK_MONOTONIC);
|
2014-09-30 00:20:54 +02:00
|
|
|
|
my ($jobs, $nixExprInput) = evalJobs($inputInfo, $exprType, $jobset->nixexprinput, $jobset->nixexprpath);
|
2017-02-21 15:49:01 +01:00
|
|
|
|
my $evalStop = clock_gettime(CLOCK_MONOTONIC);
|
2015-07-10 16:40:50 +02:00
|
|
|
|
|
Enable declarative projects.
This allows fully declarative project specifications. This is best
illustrated by example:
* I create a new project, setting the declarative spec file to
"spec.json" and the declarative input to a git repo pointing
at git://github.com/shlevy/declarative-hydra-example.git
* hydra creates a special ".jobsets" jobset alongside the project
* Just before evaluating the ".jobsets" jobset, hydra fetches
declarative-hydra-example.git, reads spec.json as a jobset spec,
and updates the jobset's configuration accordingly:
{
"enabled": 1,
"hidden": false,
"description": "Jobsets",
"nixexprinput": "src",
"nixexprpath": "default.nix",
"checkinterval": 300,
"schedulingshares": 100,
"enableemail": false,
"emailoverride": "",
"keepnr": 3,
"inputs": {
"src": { "type": "git", "value": "git://github.com/shlevy/declarative-hydra-example.git", "emailresponsible": false },
"nixpkgs": { "type": "git", "value": "git://github.com/NixOS/nixpkgs.git release-16.03", "emailresponsible": false }
}
}
* When the "jobsets" job of the ".jobsets" jobset completes, hydra
reads its output as a JSON representation of a dictionary of
jobset specs and creates a jobset named "master" configured
accordingly (In this example, this is the same configuration as
.jobsets itself, except using release.nix instead of default.nix):
{
"enabled": 1,
"hidden": false,
"description": "js",
"nixexprinput": "src",
"nixexprpath": "release.nix",
"checkinterval": 300,
"schedulingshares": 100,
"enableemail": false,
"emailoverride": "",
"keepnr": 3,
"inputs": {
"src": { "type": "git", "value": "git://github.com/shlevy/declarative-hydra-example.git", "emailresponsible": false },
"nixpkgs": { "type": "git", "value": "git://github.com/NixOS/nixpkgs.git release-16.03", "emailresponsible": false }
}
}
2016-03-11 18:14:58 -05:00
|
|
|
|
if ($jobsetsJobset) {
|
|
|
|
|
my @keys = keys %$jobs;
|
|
|
|
|
die "The .jobsets jobset must only have a single job named 'jobsets'"
|
|
|
|
|
unless (scalar @keys) == 1 && $keys[0] eq "jobsets";
|
|
|
|
|
}
|
2015-07-10 16:40:50 +02:00
|
|
|
|
Net::Statsd::timing("hydra.evaluator.eval_time", int(($evalStop - $evalStart) * 1000));
|
2009-03-09 15:16:11 +00:00
|
|
|
|
|
2015-04-09 17:35:04 +02:00
|
|
|
|
if ($dryRun) {
|
|
|
|
|
foreach my $name (keys %{$jobs}) {
|
|
|
|
|
my $job = $jobs->{$name};
|
|
|
|
|
if (defined $job->{drvPath}) {
|
|
|
|
|
print STDERR "good job $name: $job->{drvPath}\n";
|
|
|
|
|
} else {
|
|
|
|
|
print STDERR "failed job $name: $job->{error}\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-11 13:01:15 +02:00
|
|
|
|
die "Jobset contains a job with an empty name. Make sure the jobset evaluates to an attrset of jobs.\n"
|
|
|
|
|
if defined $jobs->{""};
|
|
|
|
|
|
2014-09-30 00:20:54 +02:00
|
|
|
|
$jobs->{$_}->{jobName} = $_ for keys %{$jobs};
|
|
|
|
|
|
2012-04-02 15:56:29 +00:00
|
|
|
|
my $jobOutPathMap = {};
|
2015-07-10 16:40:50 +02:00
|
|
|
|
my $jobsetChanged = 0;
|
2017-02-21 15:49:01 +01:00
|
|
|
|
my $dbStart = clock_gettime(CLOCK_MONOTONIC);
|
2012-04-02 15:56:29 +00:00
|
|
|
|
|
2017-05-24 10:38:29 -04:00
|
|
|
|
my %buildMap;
|
2009-04-22 22:43:04 +00:00
|
|
|
|
txn_do($db, sub {
|
2013-01-22 13:19:28 +01:00
|
|
|
|
|
2012-03-12 20:28:44 +01:00
|
|
|
|
my $prevEval = getPrevJobsetEval($db, $jobset, 1);
|
|
|
|
|
|
2012-03-07 18:48:10 +01:00
|
|
|
|
# Clear the "current" flag on all builds. Since we're in a
|
|
|
|
|
# transaction this will only become visible after the new
|
|
|
|
|
# current builds have been added.
|
|
|
|
|
$jobset->builds->search({iscurrent => 1})->update({iscurrent => 0});
|
|
|
|
|
|
2010-03-05 15:41:10 +00:00
|
|
|
|
# Schedule each successfully evaluated job.
|
2014-09-30 00:20:54 +02:00
|
|
|
|
foreach my $job (permute(values %{$jobs})) {
|
|
|
|
|
next if defined $job->{error};
|
2014-09-30 00:29:36 +02:00
|
|
|
|
#print STDERR "considering job " . $project->name, ":", $jobset->name, ":", $job->{jobName} . "\n";
|
2013-08-14 01:59:29 +02:00
|
|
|
|
checkBuild($db, $jobset, $inputInfo, $nixExprInput, $job, \%buildMap, $prevEval, $jobOutPathMap, $plugins);
|
2010-03-05 15:41:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-01 19:24:52 +01:00
|
|
|
|
# Have any builds been added or removed since last time?
|
2015-07-10 16:40:50 +02:00
|
|
|
|
$jobsetChanged =
|
2013-11-01 19:24:52 +01:00
|
|
|
|
(scalar(grep { $_->{new} } values(%buildMap)) > 0)
|
|
|
|
|
|| (defined $prevEval && $prevEval->jobsetevalmembers->count != scalar(keys %buildMap));
|
2010-03-05 15:41:10 +00:00
|
|
|
|
|
|
|
|
|
my $ev = $jobset->jobsetevals->create(
|
|
|
|
|
{ hash => $argsHash
|
|
|
|
|
, timestamp => time
|
2015-07-10 16:40:50 +02:00
|
|
|
|
, checkouttime => abs(int($checkoutStop - $checkoutStart))
|
|
|
|
|
, evaltime => abs(int($evalStop - $evalStart))
|
2013-11-01 19:24:52 +01:00
|
|
|
|
, hasnewbuilds => $jobsetChanged ? 1 : 0
|
|
|
|
|
, nrbuilds => $jobsetChanged ? scalar(keys %buildMap) : undef
|
2010-03-05 15:41:10 +00:00
|
|
|
|
});
|
|
|
|
|
|
2013-11-01 19:24:52 +01:00
|
|
|
|
if ($jobsetChanged) {
|
2013-08-14 01:59:29 +02:00
|
|
|
|
# Create JobsetEvalMembers mappings.
|
|
|
|
|
while (my ($id, $x) = each %buildMap) {
|
|
|
|
|
$ev->jobsetevalmembers->create({ build => $id, isnew => $x->{new} });
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-27 11:48:02 +02:00
|
|
|
|
# Create AggregateConstituents mappings. Since there can
|
|
|
|
|
# be jobs that alias each other, if there are multiple
|
|
|
|
|
# builds for the same derivation, pick the one with the
|
|
|
|
|
# shortest name.
|
|
|
|
|
my %drvPathToId;
|
|
|
|
|
while (my ($id, $x) = each %buildMap) {
|
|
|
|
|
my $y = $drvPathToId{$x->{drvPath}};
|
|
|
|
|
if (defined $y) {
|
|
|
|
|
next if length $x->{jobName} > length $y->{jobName};
|
|
|
|
|
next if length $x->{jobName} == length $y->{jobName} && $x->{jobName} ge $y->{jobName};
|
|
|
|
|
}
|
|
|
|
|
$drvPathToId{$x->{drvPath}} = $x;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-01 15:34:05 +02:00
|
|
|
|
foreach my $job (values %{$jobs}) {
|
2013-08-15 02:33:10 +02:00
|
|
|
|
next unless $job->{constituents};
|
2013-08-27 11:48:02 +02:00
|
|
|
|
my $x = $drvPathToId{$job->{drvPath}} or die;
|
2013-08-15 02:33:10 +02:00
|
|
|
|
foreach my $drvPath (split / /, $job->{constituents}) {
|
|
|
|
|
my $constituent = $drvPathToId{$drvPath};
|
|
|
|
|
if (defined $constituent) {
|
2013-08-27 11:48:02 +02:00
|
|
|
|
$db->resultset('AggregateConstituents')->update_or_create({aggregate => $x->{id}, constituent => $constituent->{id}});
|
2013-08-14 01:59:29 +02:00
|
|
|
|
} else {
|
2013-08-15 02:33:10 +02:00
|
|
|
|
warn "aggregate job ‘$job->{jobName}’ has a constituent ‘$drvPath’ that doesn't correspond to a Hydra build\n";
|
2013-08-14 01:59:29 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-05 15:41:10 +00:00
|
|
|
|
}
|
2013-01-22 13:19:28 +01:00
|
|
|
|
|
2012-04-15 18:36:36 +00:00
|
|
|
|
foreach my $name (keys %{$inputInfo}) {
|
|
|
|
|
for (my $n = 0; $n < scalar(@{$inputInfo->{$name}}); $n++) {
|
|
|
|
|
my $input = $inputInfo->{$name}->[$n];
|
|
|
|
|
$ev->jobsetevalinputs->create(
|
|
|
|
|
{ name => $name
|
|
|
|
|
, altnr => $n
|
|
|
|
|
, type => $input->{type}
|
|
|
|
|
, uri => $input->{uri}
|
|
|
|
|
, revision => $input->{revision}
|
|
|
|
|
, value => $input->{value}
|
|
|
|
|
, dependency => $input->{id}
|
|
|
|
|
, path => $input->{storePath} || "" # !!! temporary hack
|
|
|
|
|
, sha256hash => $input->{sha256hash}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-01-22 13:19:28 +01:00
|
|
|
|
|
2012-03-12 20:28:44 +01:00
|
|
|
|
print STDERR " created new eval ", $ev->id, "\n";
|
2012-03-13 13:09:10 +01:00
|
|
|
|
$ev->builds->update({iscurrent => 1});
|
2017-07-21 14:25:33 +02:00
|
|
|
|
|
|
|
|
|
# Wake up hydra-queue-runner.
|
|
|
|
|
my $lowestId;
|
|
|
|
|
while (my ($id, $x) = each %buildMap) {
|
|
|
|
|
$lowestId = $id if $x->{new} && (!defined $lowestId || $id < $lowestId);
|
|
|
|
|
}
|
|
|
|
|
$notifyAdded->execute($lowestId) if defined $lowestId;
|
|
|
|
|
|
2012-03-12 20:28:44 +01:00
|
|
|
|
} else {
|
|
|
|
|
print STDERR " created cached eval ", $ev->id, "\n";
|
2012-04-17 12:32:44 +02:00
|
|
|
|
$prevEval->builds->update({iscurrent => 1}) if defined $prevEval;
|
2010-03-05 15:41:10 +00:00
|
|
|
|
}
|
2013-10-11 12:01:52 +02:00
|
|
|
|
|
|
|
|
|
# If this is a one-shot jobset, disable it now.
|
|
|
|
|
$jobset->update({ enabled => 0 }) if $jobset->enabled == 2;
|
2014-09-29 19:46:11 +02:00
|
|
|
|
|
2016-10-24 20:20:20 +02:00
|
|
|
|
$jobset->update({ lastcheckedtime => time, forceeval => undef });
|
2009-10-02 16:06:28 +00:00
|
|
|
|
});
|
2013-01-22 13:19:28 +01:00
|
|
|
|
|
2017-02-21 15:49:01 +01:00
|
|
|
|
my $dbStop = clock_gettime(CLOCK_MONOTONIC);
|
2015-07-10 16:40:50 +02:00
|
|
|
|
|
|
|
|
|
Net::Statsd::timing("hydra.evaluator.db_time", int(($dbStop - $dbStart) * 1000));
|
|
|
|
|
Net::Statsd::increment("hydra.evaluator.evals");
|
|
|
|
|
Net::Statsd::increment("hydra.evaluator.cached_evals") unless $jobsetChanged;
|
|
|
|
|
|
2017-06-22 15:07:05 +02:00
|
|
|
|
#while (my ($id, $x) = each %buildMap) {
|
|
|
|
|
# system("hydra-notify build-queued $id") if $x->{new};
|
|
|
|
|
#}
|
2017-05-24 10:38:29 -04:00
|
|
|
|
|
2012-03-07 18:48:10 +01:00
|
|
|
|
# Store the error messages for jobs that failed to evaluate.
|
2014-09-30 00:20:54 +02:00
|
|
|
|
my $msg = "";
|
|
|
|
|
foreach my $job (values %{$jobs}) {
|
|
|
|
|
next unless defined $job->{error};
|
2013-09-25 15:51:03 +02:00
|
|
|
|
$msg .=
|
2014-09-30 00:20:54 +02:00
|
|
|
|
($job->{jobName} ne "" ? "in job ‘$job->{jobName}’" : "at top-level") .
|
|
|
|
|
":\n" . $job->{error} . "\n\n";
|
2009-03-09 15:16:11 +00:00
|
|
|
|
}
|
2010-01-12 08:39:30 +00:00
|
|
|
|
setJobsetError($jobset, $msg);
|
2008-11-04 18:23:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-02-25 18:47:54 +01:00
|
|
|
|
sub checkJobset {
|
|
|
|
|
my ($jobset) = @_;
|
2013-01-22 13:19:28 +01:00
|
|
|
|
|
2017-02-21 15:49:01 +01:00
|
|
|
|
my $startTime = clock_gettime(CLOCK_MONOTONIC);
|
2015-07-10 16:40:50 +02:00
|
|
|
|
|
2009-03-20 14:50:09 +00:00
|
|
|
|
eval {
|
2013-02-25 18:47:54 +01:00
|
|
|
|
checkJobsetWrapped($jobset);
|
2009-03-20 14:50:09 +00:00
|
|
|
|
};
|
2015-09-11 13:49:46 +02:00
|
|
|
|
my $checkError = $@;
|
2013-01-22 13:19:28 +01:00
|
|
|
|
|
2017-02-21 15:49:01 +01:00
|
|
|
|
my $stopTime = clock_gettime(CLOCK_MONOTONIC);
|
2015-07-10 16:40:50 +02:00
|
|
|
|
Net::Statsd::timing("hydra.evaluator.total_time", int(($stopTime - $startTime) * 1000));
|
|
|
|
|
|
2013-11-27 14:29:05 -05:00
|
|
|
|
my $failed = 0;
|
2015-09-11 13:49:46 +02:00
|
|
|
|
if ($checkError) {
|
|
|
|
|
print STDERR $checkError;
|
2009-04-22 22:43:04 +00:00
|
|
|
|
txn_do($db, sub {
|
2009-03-20 14:50:09 +00:00
|
|
|
|
$jobset->update({lastcheckedtime => time});
|
2015-09-11 13:49:46 +02:00
|
|
|
|
setJobsetError($jobset, $checkError);
|
2015-04-09 17:35:04 +02:00
|
|
|
|
}) if !$dryRun;
|
2013-11-27 14:29:05 -05:00
|
|
|
|
$failed = 1;
|
2009-03-20 14:50:09 +00:00
|
|
|
|
}
|
2013-02-25 21:04:10 +01:00
|
|
|
|
|
2013-11-27 14:29:05 -05:00
|
|
|
|
return $failed;
|
2009-03-20 14:50:09 +00:00
|
|
|
|
}
|
2008-11-04 18:23:28 +00:00
|
|
|
|
|
2009-03-20 14:50:09 +00:00
|
|
|
|
|
2016-10-13 15:53:05 +02:00
|
|
|
|
die "syntax: $0 <PROJECT> <JOBSET>\n" unless @ARGV == 2;
|
2009-03-05 12:32:14 +00:00
|
|
|
|
|
2016-10-13 15:53:05 +02:00
|
|
|
|
my $projectName = $ARGV[0];
|
|
|
|
|
my $jobsetName = $ARGV[1];
|
|
|
|
|
my $jobset = $db->resultset('Jobsets')->find($projectName, $jobsetName) or
|
|
|
|
|
die "$0: specified jobset \"$projectName:$jobsetName\" does not exist\n";
|
|
|
|
|
exit checkJobset($jobset);
|