IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 22, 2014, 3:50:46 PM (12 years ago)
Author:
watersc1
Message:

path change, trace drop, config typo fix, stack psf fix, exec force poll addition, exec drop/fails (likely needs further tuning), transfer shift to rsync return handler.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/sc_remote_exec.pl

    r36844 r37102  
    1818my $SEC_HOST = 'mu-fe4';
    1919my $IPP_PATH = '/turquoise/usr/projects/cosmo/mswarren/ipp/';
    20 my $remote_root  = '/scratch3/watersc1/';
    21 
     20#my $remote_root  = '/scratch3/watersc1/';
     21my $remote_root = '/lustre/scratch1/turquoise/watersc1/ps1/';
    2222# tools
    2323my $missing_tools;
     
    3333
    3434# Options
    35 my ($remote_id,$path_base,$policy,$poll,$job_id,$dbname,$verbose,$no_update,$camera);
    36 
     35my ($remote_id,$path_base,$policy,$poll,$force,$job_id,$dbname,$verbose,$no_update,$camera);
     36$force = 0;
     37$verbose = 0;
    3738GetOptions(
    3839    'remote_id=s'   => \$remote_id,
     
    4142    'policy=s'      => \$policy,
    4243    'poll'          => \$poll,
     44    'force-poll'    => \$force,
    4345    'camera=s'      => \$camera,
    4446    'dbname=s'      => \$dbname,
     
    6163
    6264print "passed authentication challenge.\n";
     65
     66# Phase 1.5: Grab the information about this run;
     67my $rt_cmd = "$remotetool -listrun -remote_id $remote_id ";
     68$rt_cmd   .= " -dbname $dbname " if defined($dbname);
     69my ( $rt_success, $rt_error_code, $rt_full_buf, $rt_stdout_buf, $rt_stderr_buf ) =
     70    run(command => $rt_cmd, verbose => $verbose);
     71unless ($rt_success) {
     72    $rt_error_code = (($rt_error_code >> 8) or $PS_EXIT_PROG_ERROR);
     73    &my_die("UNable to run remotetool to determine remote run status",
     74            $remote_id,$rt_error_code);
     75}
     76my $rrData = $mdcParser->parse(join "", @$rt_stdout_buf) or
     77    &my_die("UNable to run remotetool to determine remote run status",
     78            $remote_id,$rt_error_code);
     79my $rrData2 = parse_md_list($rrData);
     80my $runData = ${ $rrData2 }[0]; # There should be only one
    6381
    6482# These are operations we only need to do on the first call, not on subsequent poll operations.
     
    92110    my (undef,$remote_check) = uri_convert($uri_check);
    93111    my (undef,$remote_transfer)= uri_convert($uri_transfer);
    94 #    my $ssh_check_stdout = ssh_exec_command("${remote_root}/sc_validate_files.pl --check_list $remote_check --transfer_list $remote_transfer");
     112
    95113    my $ssh_check_stdout = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_check --fetch $remote_transfer");
    96114    # We no longer need to parse this output, as it retrieves files itself.
     
    130148# Poll the job status?
    131149my $poll_count = 0;
    132 my $poll_max   = 5;
     150my $poll_max   = 1; # If it isn't finished now, it's unlikely to magically finish in the next five minutes.
    133151my $poll_sleep = 60;
    134152my $poll_response = 0;
    135 while (($poll_count < $poll_max)&&($poll_response != 1)&&($poll_response != -1)) {
     153if ($force) {
     154    $poll_response = 1;
     155}
     156my $poll_word  = "nothing";
     157while (($poll_count < $poll_max)&&($poll_response != 1)&&($poll_response != -1)&&($force != 1)) {
    136158    if ($verbose) {
    137159        print "Polling code.  Sleeping.  $poll_count of $poll_max $poll_response\n";
     
    140162        sleep($poll_sleep);
    141163    }
    142     $poll_response = poll_job($job_id);
     164    ($poll_response,$poll_word) = poll_job($job_id);
    143165
    144166    if ($poll_response == 1) { # This job has completed
     
    146168    }
    147169    elsif ($poll_response == -1) { # This job has an error
    148         &my_die("The job exited incorrectly.",$remote_id, $PS_EXIT_PROG_ERROR);
     170        warn("The job exited incorrectly: $remote_id $job_id $poll_word.  Attempting to recover what we can.");
     171        $poll_response = 1; # To fool the check later into proceding
     172#       &my_die("The job exited incorrectly.",$remote_id, $PS_EXIT_PROG_ERROR);
    149173    }
    150174    $poll_count++;
     
    165189my $uri_return  = $path_base . ".return";
    166190my ($ipp_return,$remote_return) = uri_convert($uri_return);
    167 scp_get($remote_return,$ipp_return);
    168 # Feed teh return list into the
    169 my $return_push_output = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_return");
    170 print "$return_push_output\n";
    171 
    172 
     191# We shouldn't need to get this file.  We made that file.
     192#scp_get($remote_return,$ipp_return);
     193
     194# Check to see if we can resume.  Pack the files into an array
     195my @returned_files = ();
     196my @dbinfo_files   = ();
     197my @dbindex        = ();
     198my $iter           = 0;
    173199open(RETURN,   "$ipp_return") || &my_die("Couldn't open file? $ipp_return", $remote_id,$PS_EXIT_SYS_ERROR);
    174 while(<RETURN>) {
     200while (<RETURN>) {
    175201    chomp;
     202    push @returned_files, $_;
    176203    if ($_ =~ /dbinfo/) {
    177         my $file = $_;
    178 #       $file =~ s/${remote_root}.tmp//; THis shouldn't be needed, as the transfer tool munges the files on that side.
    179         open(DBF,"$file") || warn "Missing file $file\n";
    180         my $cmd = <DBF>;
    181         chomp($cmd);
    182         $cmd =~ s/-/ -/g; # This is just a safety check for missing space.
    183         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    184             run(command => $cmd, verbose => $verbose);
    185         unless ($success) {
    186             # This shouldn't fail, but we also can't suddenly abort if something does fail.  Maybe retry if this looks to be a continuing issue?
    187             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    188             warn("The command that shouldn't fail has failed: $cmd $remote_id $error_code");##,$remote_id,$error_code);
    189         }
    190         close(DBF);
    191     }
     204        push @dbinfo_files, $_;
     205        push @dbindex, $iter;
     206    }
     207    $iter++;
     208
    192209}
    193210close(RETURN);
     211
     212# Binary search it.  BUT: We're binary searching binary values.  So,
     213# this has to be far more careful than a fully sorted case would be.
     214# Only scan the dbinfo files as those are the things that are
     215# generated after the processing, and so must be the last things to
     216# exist.
     217
     218my $first = 0;
     219my $last  = $#dbinfo_files;
     220my $mid   = 0;
     221my $range = 20;  # How wide of a chunk to look through to catch threading drops
     222my $offset = 0;  # Offset to start from.
     223if (( stat($dbinfo_files[$last]) )[7] != 0) { $offset = $#dbinfo_files;}
     224else {
     225    my $count = 0;
     226    while ($first < $last - $range) {
     227
     228        $mid = int(($last + $first)/2);
     229        for (my $i = 0; $i <= $range; $i++) {
     230            my $size = (stat($dbinfo_files[$mid + $i]))[7];
     231#           print STDERR "$first $last $mid $i $size $dbinfo_files[$mid + $i]\n";
     232            if ($size == 0) {
     233                if ($last == $mid + $i) {
     234                    $first = $last - 1;
     235                }
     236                $last = $mid + $i;
     237                $i = $range + 10;
     238            }
     239        }
     240        if ($last > $mid + $range) { $first = $mid + $range; }
     241        $count++;
     242        if ($count > 200) {
     243            &my_die("The iteration loop couldn't converge after 200 rounds, suggesting something has gone wrong.",
     244                    $remote_id,4,"error_run");
     245        }
     246    }
     247    $offset = $mid - $range; # Because I want to make sure I get to the beginning of the thread group.
     248    $offset = $dbindex[$offset]; # Because we need to convert from dbinfo space to returned file space.
     249}
     250
     251# Feed teh return list into the transfer tool
     252# If this fails, we should go to an auth wait point.
     253my $return_push_output = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_return --offset $offset");
     254my $return_push_output_print = join "\n", @{ $return_push_output };
     255print "$return_push_output_print\n";
     256
     257#die();
     258
     259foreach my $file (@dbinfo_files) {
     260    open(DBF,"$file") || warn "Missing file $file\n";
     261    my $cmd = <DBF>;
     262    close(DBF);
     263    chomp($cmd);
     264    $cmd =~ s/-/ -/g; # This is just a safety check for missing space.
     265    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     266        run(command => $cmd, verbose => $verbose);
     267    unless ($success) {
     268        # This shouldn't fail, but we also can't suddenly abort if something does fail. 
     269        # Now we're going to drop the component that owns this dbinfo, which should force a retry.
     270        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     271        warn("The command that shouldn't fail has failed: $cmd $remote_id $error_code");
     272        drop_component($remote_id,$cmd,$file);
     273    }
     274
     275}
    194276
    195277# We're done, so set the state and exit.
    196278&my_die("Finished",$remote_id,0,"full");
    197 
    198279
    199280
     
    209290        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    210291        &my_die("Authorization check failed.",$remote_id,0,'auth');
    211 
    212 #       my $update_command = "$remotetool -updaterun -remote_id $remote_id ";
    213 #       $update_command .= " -set_state auth ";
    214 #       $update_command .= " -dbname $dbname " if defined $dbname;
    215 #       system($update_command);
    216 #       exit(0);  # This isn't an error.  It's a state we monitor and move to automatically.
    217292    }
    218293}
     
    250325sub ssh_exec_command {
    251326    my $cmd = shift;
    252     $cmd = "$ssh $DMZ_HOST ssh ${SEC_HOST} $cmd";
     327    $cmd = "$ssh  $DMZ_HOST ssh ${SEC_HOST} $cmd";
    253328    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    254329        run(command => $cmd, verbose => $verbose);
    255330    unless ($success) {
    256331        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     332        # If we failed, see if we failed due to authorization.
     333        check_ssh_connection();
    257334        &my_die("Failed to execute command: >>$cmd<<");
    258335    }
     
    266343   
    267344    if ($response =~ /State: Running/) {
    268         return(0);
     345        return(0,"Running");
    269346    }
    270347    elsif ($response =~ /State: Completed/) {
    271         return(1);
     348        return(1,"Completed");
    272349    }
    273350    elsif ($response =~ /State: Idle/) {
    274         return(-2);
     351        return(-2,"Idle");
    275352    }
    276353    else {
    277         return(-1);
     354        my $response_word = $response;
     355        $response_word =~ s/.*State: //;
     356        $response_word =~ s/\n.*//;
     357        return(-1,$response_word);
    278358    }
    279359}
     
    324404    return($local_uri);
    325405}
     406
     407sub drop_component {
     408    my $remote_id = shift;
     409    my $cmd = shift;
     410    my $file = shift;
     411
     412    if ($cmd eq '') {
     413        # Zero byte file.  This dbinfo was never constructed properly.
     414       
     415        # Steal the stage_id from the filename.  This isn't something I'm happy about.
     416        my $stage = $runData->{stage};
     417        my $stage_id = $file;
     418        if ($stage eq 'chip') {
     419            $stage_id =~ s/^.*ch\.//;
     420        }
     421        elsif ($stage eq 'camera') {
     422            $stage_id =~ s/^.*cm\.//;
     423        }
     424        elsif ($stage eq 'warp') {
     425            $stage_id =~ s/^.*wrp\.//;
     426        }
     427        elsif ($stage eq 'stack') {
     428            $stage_id =~ s/^.*stk\.//;
     429        }
     430        $stage_id =~ s/\..*$//;
     431       
     432        # Drop this from the database
     433        my $drop_cmd = "$remotetool -dropcomponent -remote_id $remote_id -stage_id $stage_id ";
     434        $drop_cmd   .= " -dbname $dbname " if defined($dbname);
     435        system($drop_cmd);
     436    }
     437
     438}
     439
    326440sub my_die {
    327441    my $msg = shift;
     
    347461}
    348462
    349 # I don't think I need this anymore, but I don't want to burn it until I"m sure.
    350 
    351 # exit(1);
    352 # # Read this as a metadata object
    353 # my $ssh_exec_stdout = ssh_exec_command("sc_validate_processing.pl ${path_base}.out");
    354 # my $retrieveData = $mdcParser->parse(join "", @$ssh_exec_stdout);
    355 # my $retrieveData2= parse_md_list($retrieveData);
    356 
    357 # foreach my $retrieveEntry (@$retrieveData2) {
    358 #     my $process_fault = $retrieveEntry->{fault};
    359 #     my $dbcommand = $retrieveEntry->{dbcommand};
    360 #     my $filelist  = $retrieveEntry->{filelist};
    361 
    362 #     scp_get("${filelist}",${filelist});
    363 #     open(FL,${filelist});
    364 #     while(<FL>) {
    365 #       chomp;
    366 #       my $f = $_;
    367 #       scp_get("${f}",$f);
    368 #     }
    369 #     close(FL);
    370 
    371 #     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    372 #       run(command => $dbcommand, verbose => $verbose);
    373 #     unless ($success) {
    374 #       $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    375 #       &my_die("The database command returned did not execute correctly. $dbcommand $process_fault",
    376 #               $remote_id,$error_code);
    377 #     }
    378 
    379 #     if ($process_fault != 0) {
    380 #       $fault = 1;
    381 #     }
    382 # }
    383 
    384 # if (($policy ne 'ignore')&&($fault != 0)) {
    385 #     &my_die("This job exited without all components finishing successfully.  Halting.",
    386 #           $remote_id,$fault,"halt");
    387 # }
    388 # else {
    389 #     print "This job exited without all components finishing successfully. $fault\n" if $fault;
    390 #     &my_die("This job finished.  Setting remote job to full.",
    391 #           $remote_id,0,"full");
    392 # }
    393 
    394 # Promote to finished.
    395 #&my_die(); # Not really, but I don't have the tool interface finished, so these are all just placeholders.
    396463# Quick review:
    397464# new -> pending -> run -> full
Note: See TracChangeset for help on using the changeset viewer.