fixes and docs for testing crunch jobs locally
[arvados.git] / services / crunch / crunch-job
index 8ab0ea377bafca15a5e270b6ec796e54dd8bc43c..710fc0b0c8caa404eaa19dc865270f6ef6bd3e74 100755 (executable)
@@ -97,6 +97,7 @@ if (defined $job_api_token) {
 
 my $have_slurm = exists $ENV{SLURM_JOBID} && exists $ENV{SLURM_NODELIST};
 my $job_has_uuid = $jobspec =~ /^[-a-z\d]+$/;
+my $local_job = !$job_has_uuid;
 
 
 $SIG{'HUP'} = sub
@@ -119,7 +120,8 @@ my $metastream = Warehouse::Stream->new(whc => new Warehouse);
 $metastream->clear;
 $metastream->write_start('log.txt');
 
-my $User = {};
+my $User = $arv->{'users'}->{'current'}->execute;
+
 my $Job = {};
 my $job_id;
 my $dbh;
@@ -127,7 +129,6 @@ my $sth;
 if ($job_has_uuid)
 {
   $Job = $arv->{'jobs'}->{'get'}->execute('uuid' => $jobspec);
-  $User = $arv->{'users'}->{'current'}->execute;
   if (!$force_unlock) {
     if ($Job->{'is_locked_by'}) {
       croak("Job is locked: " . $Job->{'is_locked_by'});
@@ -153,11 +154,12 @@ else
     qw(script script_version script_parameters);
   }
 
-  if (!defined $Job->{'uuid'}) {
-    my $hostname = `hostname -s`;
-    chomp $hostname;
-    $Job->{'uuid'} = sprintf ("%s-t%d-p%d", $hostname, time, $$);
-  }
+  $Job->{'is_locked_by'} = $User->{'uuid'};
+  $Job->{'started_at'} = gmtime;
+
+  $Job = $arv->{'jobs'}->{'create'}->execute('job' => $Job);
+
+  $job_has_uuid = 1;
 }
 $job_id = $Job->{'uuid'};
 
@@ -314,22 +316,22 @@ else
 
 
 my $build_script;
-do {
-  local $/ = undef;
-  $build_script = <DATA>;
-};
 
 
-$ENV{"CRUNCH_SRC_COMMIT"} = $Job->{revision};
+$ENV{"CRUNCH_SRC_COMMIT"} = $Job->{script_version};
 
-my $skip_install = (!$have_slurm && $Job->{revision} =~ m{^/});
+my $skip_install = ($local_job && $Job->{script_version} =~ m{^/});
 if ($skip_install)
 {
-  $ENV{"CRUNCH_SRC"} = $Job->{revision};
+  $ENV{"CRUNCH_SRC"} = $Job->{script_version};
 }
 else
 {
-  Log (undef, "Install revision ".$Job->{revision});
+  do {
+    local $/ = undef;
+    $build_script = <DATA>;
+  };
+  Log (undef, "Install revision ".$Job->{script_version});
   my $nodelist = join(",", @node);
 
   # Clean out crunch_tmp/work and crunch_tmp/opt
@@ -384,7 +386,7 @@ else
     chomp $gitlog;
     if ($gitlog =~ /^[a-f0-9]{40}$/) {
       $commit = $gitlog;
-      Log (undef, "Using commit $commit for revision $treeish");
+      Log (undef, "Using commit $commit for script_version $treeish");
     }
   }
 
@@ -556,7 +558,7 @@ for (my $todo_ptr = 0; $todo_ptr <= $#jobstep_todo; $todo_ptr ++)
     my @execargs = qw(sh);
     my $build_script_to_send = "";
     my $command =
-       "mkdir -p $ENV{CRUNCH_TMP}/revision "
+       "mkdir -p $ENV{CRUNCH_WORK} $ENV{CRUNCH_TMP} "
        ."&& cd $ENV{CRUNCH_TMP} ";
     if ($build_script)
     {
@@ -564,18 +566,6 @@ for (my $todo_ptr = 0; $todo_ptr <= $#jobstep_todo; $todo_ptr ++)
       $command .=
          "&& perl -";
     }
-    elsif (!$skip_install)
-    {
-      $command .=
-         "&& "
-         ."( "
-         ."  [ -e '$ENV{CRUNCH_INSTALL}/.tested' ] "
-         ."|| "
-         ."  ( svn export --quiet '$ENV{INSTALL_REPOS}/installrevision' "
-         ."    && ./installrevision "
-         ."  ) "
-         .") ";
-    }
     $ENV{"PYTHONPATH"} = "$ENV{CRUNCH_SRC}/sdk/python"; # xxx hack
     $command .=
         "&& exec $ENV{CRUNCH_SRC}/crunch_scripts/" . $Job->{"script"};