IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 12, 2014, 3:55:38 PM (12 years ago)
Author:
eugene
Message:

merge changes from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140717/ippScripts/scripts/sc_remote_exec.pl

    r36844 r37242  
    1616# Hard coded values
    1717my $DMZ_HOST = 'wtrw';
    18 my $SEC_HOST = 'mu-fe4';
     18my $SEC_HOST = 'mu-fe';
    1919my $IPP_PATH = '/turquoise/usr/projects/cosmo/mswarren/ipp/';
    2020my $remote_root  = '/scratch3/watersc1/';
     
    3131}
    3232
    33 
    3433# Options
    35 my ($remote_id,$path_base,$policy,$poll,$job_id,$dbname,$verbose,$no_update,$camera);
    36 
     34my ($remote_id,$path_base,$policy,$poll,$force,$job_id,$dbname,$verbose,$no_update,$camera);
     35$force = 0;
     36$verbose = 0;
    3737GetOptions(
    3838    'remote_id=s'   => \$remote_id,
     
    4141    'policy=s'      => \$policy,
    4242    'poll'          => \$poll,
     43    'force-poll'    => \$force,
    4344    'camera=s'      => \$camera,
    4445    'dbname=s'      => \$dbname,
     
    5354
    5455my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id);
    55 
    5656my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files                                   
    5757
     
    6161
    6262print "passed authentication challenge.\n";
     63
     64# Phase 1.5: Grab the information about this run;
     65my $rt_cmd = "$remotetool -listrun -remote_id $remote_id ";
     66$rt_cmd   .= " -dbname $dbname " if defined($dbname);
     67my ( $rt_success, $rt_error_code, $rt_full_buf, $rt_stdout_buf, $rt_stderr_buf ) =
     68    run(command => $rt_cmd, verbose => $verbose);
     69unless ($rt_success) {
     70    $rt_error_code = (($rt_error_code >> 8) or $PS_EXIT_PROG_ERROR);
     71    &my_die("UNable to run remotetool to determine remote run status",
     72            $remote_id,$rt_error_code);
     73}
     74my $rrData = $mdcParser->parse(join "", @$rt_stdout_buf) or
     75    &my_die("UNable to run remotetool to determine remote run status",
     76            $remote_id,$rt_error_code);
     77my $rrData2 = parse_md_list($rrData);
     78my $runData = ${ $rrData2 }[0]; # There should be only one
    6379
    6480# These are operations we only need to do on the first call, not on subsequent poll operations.
     
    92108    my (undef,$remote_check) = uri_convert($uri_check);
    93109    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");
     110
    95111    my $ssh_check_stdout = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_check --fetch $remote_transfer");
    96112    # We no longer need to parse this output, as it retrieves files itself.
     
    130146# Poll the job status?
    131147my $poll_count = 0;
    132 my $poll_max   = 5;
     148my $poll_max   = 1; # If it isn't finished now, it's unlikely to magically finish in the next five minutes.
    133149my $poll_sleep = 60;
    134150my $poll_response = 0;
    135 while (($poll_count < $poll_max)&&($poll_response != 1)&&($poll_response != -1)) {
     151my $poll_word  = "nothing";
     152
     153if ($force) {
     154    $poll_response = 1;
     155    $poll_word     = "Completed";
     156}
     157
     158while (($poll_count < $poll_max)&&($poll_response != 1)&&($poll_response != -1)&&($force != 1)) {
    136159    if ($verbose) {
    137160        print "Polling code.  Sleeping.  $poll_count of $poll_max $poll_response\n";
     
    140163        sleep($poll_sleep);
    141164    }
    142     $poll_response = poll_job($job_id);
     165    ($poll_response,$poll_word) = poll_job($job_id);
    143166
    144167    if ($poll_response == 1) { # This job has completed
     
    146169    }
    147170    elsif ($poll_response == -1) { # This job has an error
    148         &my_die("The job exited incorrectly.",$remote_id, $PS_EXIT_PROG_ERROR);
     171        warn("The job exited incorrectly: $remote_id $job_id $poll_word.  Attempting to recover what we can.");
     172        $poll_response = 1; # To fool the check later into proceding
    149173    }
    150174    $poll_count++;
     
    156180    &my_die("Job hasn't completed.  Ending polling.", $remote_id, 0, "run", $job_id);
    157181}
    158 # Retrieve validation summary
    159 my $fault = 0;
     182
    160183
    161184# Initialize the remote side to sync things
     
    165188my $uri_return  = $path_base . ".return";
    166189my ($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 
     190# We shouldn't need to get this file.  We made that file.
     191#scp_get($remote_return,$ipp_return);
     192
     193# Construct list of dbinfo files we'll need to execute.
     194my @returned_files = ();
     195my @dbinfo_files   = ();
     196my @dbindex        = ();
     197my $iter           = 0;
    173198open(RETURN,   "$ipp_return") || &my_die("Couldn't open file? $ipp_return", $remote_id,$PS_EXIT_SYS_ERROR);
    174 while(<RETURN>) {
     199while (<RETURN>) {
    175200    chomp;
     201    push @returned_files, $_;
    176202    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);
     203        push @dbinfo_files, $_;
     204        push @dbindex, $iter;
     205    }
     206    $iter++;
     207
     208}
     209close(RETURN);
     210print STDERR "Expect $#dbinfo_files dbinfo files\n";
     211
     212my $first = 0;
     213my $last  = $#dbinfo_files;
     214my $mid   = 0;
     215my $range = 20;  # How wide of a chunk to look through to catch threading drops
     216my $offset = 0;  # Offset to start from.
     217
     218# Feed the return list into the transfer tool
     219# If this fails, we should go to an auth wait point.
     220if ($poll_word eq 'Completed') { 
     221    # We're complete.  All files should exist on disk
     222    my $iter = 0;
     223    my $transfer_success = 1;
     224    do {
     225        $transfer_success = 1;
     226        $iter++;
     227        check_ssh_connection();
     228        my $return_push_output = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_return --offset $offset");
     229        my $return_push_output_print = join "\n", @{ $return_push_output };
     230        if ($return_push_output_print =~ /exited with value 255/) { $transfer_success = 0; }
     231        print "$return_push_output_print\n";
     232    } while (($transfer_success != 1) &&  ($iter < 10));  # Try harder;
     233}
     234else {
     235    # Just try and fetch things, because we didn't complete correctly, it seems.
     236    my $return_push_output = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_return --offset $offset");
     237    my $return_push_output_print = join "\n", @{ $return_push_output };
     238    print "$return_push_output_print\n";
     239}
     240
     241foreach my $file (@dbinfo_files) {
     242    open(DBF,"$file") || warn "Missing file $file\n";
     243    my $cmd = <DBF>;
     244    close(DBF);
     245    chomp($cmd);
     246#    print STDERR "$file $cmd\n";
     247    $cmd =~ s/-/ -/g; # This is just a safety check for missing space.
     248    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     249        run(command => $cmd, verbose => $verbose);
     250    unless ($success) {
     251
     252        # This shouldn't fail, but we also can't suddenly abort if something does fail. 
     253        # Now we're going to drop the component that owns this dbinfo, which should force a retry.
     254        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     255        warn("The command that shouldn't fail has failed: $file $cmd $remote_id $error_code");
     256        if ($poll_word ne 'Completed') {  # If the job claims it completed, then we're fighting the network.
     257            drop_component($remote_id,$cmd,$file);
    189258        }
    190         close(DBF);
    191     }
    192 }
    193 close(RETURN);
     259    }
     260
     261}
    194262
    195263# We're done, so set the state and exit.
    196264&my_die("Finished",$remote_id,0,"full");
    197 
    198265
    199266
     
    209276        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    210277        &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.
    217278    }
    218279}
     
    250311sub ssh_exec_command {
    251312    my $cmd = shift;
    252     $cmd = "$ssh $DMZ_HOST ssh ${SEC_HOST} $cmd";
     313    $cmd = "$ssh  $DMZ_HOST ssh  ${SEC_HOST} $cmd";
     314    print "EXEC: $cmd\n";
    253315    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    254316        run(command => $cmd, verbose => $verbose);
    255317    unless ($success) {
    256318        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     319        # If we failed, see if we failed due to authorization.
     320        check_ssh_connection();
    257321        &my_die("Failed to execute command: >>$cmd<<");
    258322    }
     
    266330   
    267331    if ($response =~ /State: Running/) {
    268         return(0);
     332        return(0,"Running");
    269333    }
    270334    elsif ($response =~ /State: Completed/) {
    271         return(1);
     335        return(1,"Completed");
    272336    }
    273337    elsif ($response =~ /State: Idle/) {
    274         return(-2);
     338        return(-2,"Idle");
    275339    }
    276340    else {
    277         return(-1);
     341        my $response_word = $response;
     342        $response_word =~ s/.*State: //;
     343        $response_word =~ s/\n.*//;
     344        return(-1,$response_word);
    278345    }
    279346}
     
    324391    return($local_uri);
    325392}
     393
     394sub drop_component {
     395    my $remote_id = shift;
     396    my $cmd = shift;
     397    my $file = shift;
     398
     399    if ($cmd eq '') {
     400        # Zero byte file.  This dbinfo was never constructed properly.
     401       
     402        # Steal the stage_id from the filename.  This isn't something I'm happy about.
     403        my $stage = $runData->{stage};
     404        my $stage_id = $file;
     405        if ($stage eq 'chip') {
     406            $stage_id =~ s/^.*ch\.//;
     407        }
     408        elsif ($stage eq 'camera') {
     409            $stage_id =~ s/^.*cm\.//;
     410        }
     411        elsif ($stage eq 'warp') {
     412            $stage_id =~ s/^.*wrp\.//;
     413        }
     414        elsif ($stage eq 'stack') {
     415            $stage_id =~ s/^.*stk\.//;
     416        }
     417        $stage_id =~ s/\..*$//;
     418       
     419        # Drop this from the database
     420        my $drop_cmd = "$remotetool -dropcomponent -remote_id $remote_id -stage_id $stage_id ";
     421        $drop_cmd   .= " -dbname $dbname " if defined($dbname);
     422        system($drop_cmd);
     423    }
     424
     425}
     426
    326427sub my_die {
    327428    my $msg = shift;
     
    347448}
    348449
    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.
    396450# Quick review:
    397451# new -> pending -> run -> full
Note: See TracChangeset for help on using the changeset viewer.