IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 9, 2014, 6:17:18 PM (12 years ago)
Author:
watersc1
Message:

These have been tested and seem to work correctly.

File:
1 edited

Legend:

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

    r36583 r36844  
    1616# Hard coded values
    1717my $DMZ_HOST = 'wtrw';
    18 my $SEC_HOST = 'mu-fe';
     18my $SEC_HOST = 'mu-fe4';
    1919my $IPP_PATH = '/turquoise/usr/projects/cosmo/mswarren/ipp/';
    2020my $remote_root  = '/scratch3/watersc1/';
     
    2424my $ssh        = can_run('ssh')  or (warn "Can't find ssh" and $missing_tools = 1);
    2525my $scp        = can_run('scp')  or (warn "Can't find scp" and $missing_tools = 1);
    26 my $remotetool = can_run('echo') or (warn "Can't find remotetool" and $missing_tools = 1);
     26my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1);
    2727
    2828if ($missing_tools) {
     
    7272    my $uri_check   = $path_base . ".check";
    7373    my $uri_config  = $path_base . ".config";
     74    my $uri_generate= $path_base . ".generate";
     75    my $uri_return  = $path_base . ".return";
    7476
    7577    my $disk_command = $ipprc->file_resolve($uri_command);
     
    7779    my $disk_check   = $ipprc->file_resolve($uri_check);
    7880    my $disk_config  = $ipprc->file_resolve($uri_config);
     81    my $disk_generate= $ipprc->file_resolve($uri_generate);
     82    my $disk_return  = $ipprc->file_resolve($uri_return);
    7983   
    8084    scp_put($disk_command,uri_local_to_remote($uri_command));
     
    8286    scp_put($disk_check,uri_local_to_remote($uri_check));
    8387    scp_put($disk_config,uri_local_to_remote($uri_config));
     88    scp_put($disk_generate,uri_local_to_remote($uri_generate));
     89    scp_put($disk_return, uri_local_to_remote($uri_return));
    8490   
    8591# Run check command
    8692    my (undef,$remote_check) = uri_convert($uri_check);
    87     my $ssh_check_stdout = ssh_exec_command("${remote_root}/sc_validate_files.pl --check_list $remote_check");
    88    
    89 # Parse stdout for files to transfer.
    90     if ($#{ $ssh_check_stdout } != -1) { # There were files not found.
    91         # Someone was missing.  Use the check and transfer lists to identify the local version, and send it.
    92         # What was missing?
    93         my %missing_files = ();
    94         foreach my $l (split /\n/, (join '', @$ssh_check_stdout)) {
    95             print "Missing!: $l\n";
    96             $missing_files{$l} = 1;
    97         }
    98        
    99         # Do we have that file?
    100         my @check_files = ();
    101         open(CHECK,$disk_check);
    102         while(<CHECK>) {
    103             chomp;
    104             push @check_files, $_;
    105         }
    106         close(CHECK);
    107        
    108         my @trans_files = ();
    109         open(TRANS,$disk_transfer);
    110         while(<TRANS>) {
    111             chomp;
    112             push @trans_files, $_;
    113         }
    114         close(TRANS);
    115        
    116         if ($#trans_files != $#check_files) { &my_die("The transfer file list and check file list are different sizes",
    117                                                       $remote_id,$PS_EXIT_DATA_ERROR); }
    118        
    119         for (my $i = 0; $i <= $#check_files; $i++) {
    120             if (exists($missing_files{$check_files[$i]})) {
    121                 if ($trans_files[$i] ne "REMOTE_ONLY") {
    122                     scp_put($trans_files[$i],"$check_files[$i]");
    123                 }
    124                 else {
    125                     &my_die("There is a file that should be there, but the file isn't there, and I don't have a copy of that file here.  The file is: $check_files[$i]",
    126                         $remote_id,$PS_EXIT_DATA_ERROR); # This seems a bit harsh.
    127                 }
    128             }
    129         }
    130     }
    131 
     93    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");
     95    my $ssh_check_stdout = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_check --fetch $remote_transfer");
     96    # We no longer need to parse this output, as it retrieves files itself.
     97    foreach my $l (split /\n/, (join '', @$ssh_check_stdout)) {
     98        print "$l\n";
     99    }
    132100
    133101# Run real command
     
    147115    my $command = "$remotetool -updaterun -remote_id $remote_id ";
    148116    $command .= " -set_state run ";
    149     $command .= " -set_job_id $job_id ";
     117    $command .= " -job_id $job_id ";
    150118    $command .= " -dbname $dbname " if defined $dbname;
    151119   
    152120    system($command);
    153121   
    154 }
     122} # End of exec phase
    155123
    156124# Check that we have a valid job_id, either from the command line, or from the msub command.
     
    185153    print "Stopped Polling code.  $poll_count of $poll_max $poll_response\n";
    186154}
     155if ($poll_response != 1) {
     156    &my_die("Job hasn't completed.  Ending polling.", $remote_id, 0, "run", $job_id);
     157}
    187158# Retrieve validation summary
    188159my $fault = 0;
    189160
    190 exit(1);
    191 # Read this as a metadata object
    192 my $ssh_exec_stdout = ssh_exec_command("sc_validate_processing.pl ${path_base}.out");
    193 my $retrieveData = $mdcParser->parse(join "", @$ssh_exec_stdout);
    194 my $retrieveData2= parse_md_list($retrieveData);
    195 
    196 foreach my $retrieveEntry (@$retrieveData2) {
    197     my $process_fault = $retrieveEntry->{fault};
    198     my $dbcommand = $retrieveEntry->{dbcommand};
    199     my $filelist  = $retrieveEntry->{filelist};
    200 
    201     scp_get("${filelist}",${filelist});
    202     open(FL,${filelist});
    203     while(<FL>) {
    204         chomp;
    205         my $f = $_;
    206         scp_get("${f}",$f);
    207     }
    208     close(FL);
    209 
    210     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    211         run(command => $dbcommand, verbose => $verbose);
    212     unless ($success) {
    213         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    214         &my_die("The database command returned did not execute correctly. $dbcommand $process_fault",
    215                 $remote_id,$error_code);
    216     }
    217 
    218     if ($process_fault != 0) {
    219         $fault = 1;
    220     }
    221 }
    222 
    223 if (($policy ne 'ignore')&&($fault != 0)) {
    224     &my_die("This job exited without all components finishing successfully.  Halting.",
    225             $remote_id,$fault,"halt");
    226 }
    227 else {
    228     print "This job exited without all components finishing successfully. $fault\n" if $fault;
    229     &my_die("This job finished.  Setting remote job to full.",
    230             $remote_id,0,"full");
    231 }
    232 
    233 # Promote to finished.
    234 &my_die(); # Not really, but I don't have the tool interface finished, so these are all just placeholders.
    235 # Quick review:
    236 # new -> pending -> run -> full
    237 # auth
     161# Initialize the remote side to sync things
     162
     163# Once sync completes, execute all the database commands
     164# Grab the return list
     165my $uri_return  = $path_base . ".return";
     166my ($ipp_return,$remote_return) = uri_convert($uri_return);
     167scp_get($remote_return,$ipp_return);
     168# Feed teh return list into the
     169my $return_push_output = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_return");
     170print "$return_push_output\n";
     171
     172
     173open(RETURN,   "$ipp_return") || &my_die("Couldn't open file? $ipp_return", $remote_id,$PS_EXIT_SYS_ERROR);
     174while(<RETURN>) {
     175    chomp;
     176    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    }
     192}
     193close(RETURN);
     194
     195# We're done, so set the state and exit.
     196&my_die("Finished",$remote_id,0,"full");
     197
     198
    238199
    239200# END PROGRAM
     
    294255    unless ($success) {
    295256        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    296         &my_die();
     257        &my_die("Failed to execute command: >>$cmd<<");
    297258    }
    298259    return ($stdout_buf);
     
    368329    my $exit_code = shift;
    369330    my $exit_state = shift;
    370 
     331    my $jobid = shift;
    371332    $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code;
    372333
     
    374335   
    375336    if (defined $id and not $no_update) {
    376         my $command = "$remotetool -updaterun -stage_id $id";
     337        my $command = "$remotetool -updaterun -remote_id $id";
    377338        $command .= " -fault $exit_code " if defined $exit_code;
     339        $command .= " -job_id $job_id " if defined $jobid;
    378340        $command .= " -set_state $exit_state " if defined $exit_state;
    379341        $command .= " -dbname $dbname " if defined $dbname;
     
    384346    exit($exit_code);
    385347}
     348
     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.
     396# Quick review:
     397# new -> pending -> run -> full
     398# auth
Note: See TracChangeset for help on using the changeset viewer.