IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 20, 2014, 11:59:03 AM (12 years ago)
Author:
eugene
Message:

typos

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tags/ipp-pv3-20140717/ippScripts/scripts/sc_remote_exec.pl

    r37203 r37269  
    1 #!/usr/bin/env perl 
     1#!/usr/bin/env perl
    22
    33use Carp;
     
    5454
    5555my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id);
    56 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files                                   
     56my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    5757
    5858# Phase 1: See if we can actually do anything.
     
    6969unless ($rt_success) {
    7070    $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 }
    74 my $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);
     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);
    7777my $rrData2 = parse_md_list($rrData);
    7878my $runData = ${ $rrData2 }[0]; # There should be only one
     
    8383# Copy command files
    8484    my @files = ();
    85    
     85
    8686    my $uri_command = $path_base . ".cmd";
    8787    my $uri_transfer= $path_base . ".transfer";
     
    9797    my $disk_generate= $ipprc->file_resolve($uri_generate);
    9898    my $disk_return  = $ipprc->file_resolve($uri_return);
    99    
     99
    100100    scp_put($disk_command,uri_local_to_remote($uri_command));
    101101    scp_put($disk_transfer,uri_local_to_remote($uri_transfer));
     
    104104    scp_put($disk_generate,uri_local_to_remote($uri_generate));
    105105    scp_put($disk_return, uri_local_to_remote($uri_return));
    106    
     106
    107107# Run check command
    108108    my (undef,$remote_check) = uri_convert($uri_check);
     
    112112    # We no longer need to parse this output, as it retrieves files itself.
    113113    foreach my $l (split /\n/, (join '', @$ssh_check_stdout)) {
    114         print "$l\n";
     114        print "$l\n";
    115115    }
    116116
     
    119119    my $ssh_exec_stdout = ssh_exec_command("msub -V $remote_command");
    120120    if ($#{ $ssh_exec_stdout } != -1) { # Parse the output
    121         $job_id = ${ $ssh_exec_stdout }[0];
    122         chomp($job_id);
    123         $job_id =~ s/\s+//g;
     121        $job_id = ${ $ssh_exec_stdout }[0];
     122        chomp($job_id);
     123        $job_id =~ s/\s+//g;
    124124    }
    125125
    126126    unless(defined($job_id)) { # If we don't have a job_id from this command, it didn't run correctly.
    127         &my_die("No job_id returned.  Sorry.",$remote_id,$PS_EXIT_PROG_ERROR);
     127        &my_die("No job_id returned.  Sorry.",$remote_id,$PS_EXIT_PROG_ERROR);
    128128    }
    129129
     
    133133    $command .= " -job_id $job_id ";
    134134    $command .= " -dbname $dbname " if defined $dbname;
    135    
     135
     136    print STDERR "$command\n";
    136137    system($command);
    137    
     138
    138139} # End of exec phase
    139140
     
    158159while (($poll_count < $poll_max)&&($poll_response != 1)&&($poll_response != -1)&&($force != 1)) {
    159160    if ($verbose) {
    160         print "Polling code.  Sleeping.  $poll_count of $poll_max $poll_response\n";
     161        print "Polling code.  Sleeping.  $poll_count of $poll_max $poll_response\n";
    161162    }
    162163    unless ($poll_count == 0) {
    163         sleep($poll_sleep);
     164        sleep($poll_sleep);
    164165    }
    165166    ($poll_response,$poll_word) = poll_job($job_id);
    166167
    167168    if ($poll_response == 1) { # This job has completed
    168         last;
     169        last;
    169170    }
    170171    elsif ($poll_response == -1) { # This job has an 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
     172        warn("The job exited incorrectly: $remote_id $job_id $poll_word.  Attempting to recover what we can.");
     173        $poll_response = 1; # To fool the check later into proceding
    173174    }
    174175    $poll_count++;
     
    201202    push @returned_files, $_;
    202203    if ($_ =~ /dbinfo/) {
    203         push @dbinfo_files, $_;
    204         push @dbindex, $iter;
     204        push @dbinfo_files, $_;
     205        push @dbindex, $iter;
    205206    }
    206207    $iter++;
     
    218219# Feed the return list into the transfer tool
    219220# If this fails, we should go to an auth wait point.
    220 if ($poll_word eq 'Completed') { 
     221if ($poll_word eq 'Completed') {
    221222    # We're complete.  All files should exist on disk
    222223    my $iter = 0;
    223224    my $transfer_success = 1;
    224225    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";
     226        $transfer_success = 1;
     227        $iter++;
     228        check_ssh_connection();
     229        my $return_push_output = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_return --offset $offset");
     230        my $return_push_output_print = join "\n", @{ $return_push_output };
     231        if ($return_push_output_print =~ /exited with value 255/) { $transfer_success = 0; }
     232        print "$return_push_output_print\n";
    232233    } while (($transfer_success != 1) &&  ($iter < 10));  # Try harder;
    233234}
     
    247248    $cmd =~ s/-/ -/g; # This is just a safety check for missing space.
    248249    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    249         run(command => $cmd, verbose => $verbose);
     250        run(command => $cmd, verbose => $verbose);
    250251    unless ($success) {
    251252
    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);
    258         }
     253        # This shouldn't fail, but we also can't suddenly abort if something does fail.
     254        # Now we're going to drop the component that owns this dbinfo, which should force a retry.
     255        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     256        warn("The command that shouldn't fail has failed: $file $cmd $remote_id $error_code");
     257        if ($poll_word ne 'Completed') {  # If the job claims it completed, then we're fighting the network.
     258            drop_component($remote_id,$cmd,$file);
     259        }
    259260    }
    260261
     
    272273
    273274    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    274         run(command => $cmd, verbose => $verbose);
     275        run(command => $cmd, verbose => $verbose);
    275276    unless ($success) {
    276         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    277         &my_die("Authorization check failed.",$remote_id,0,'auth');
     277        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     278        &my_die("Authorization check failed.",$remote_id,0,'auth');
    278279    }
    279280}
     
    288289
    289290    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    290         run(command => $cmd, verbose => $verbose);
     291        run(command => $cmd, verbose => $verbose);
    291292    unless ($success) {
    292         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    293         &my_die();
     293        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     294        &my_die();
    294295    }
    295296}
     
    302303
    303304    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    304         run(command => $cmd, verbose => $verbose);
     305        run(command => $cmd, verbose => $verbose);
    305306    unless ($success) {
    306         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    307         &my_die();
     307        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     308        &my_die();
    308309    }
    309310}
     
    314315    print "EXEC: $cmd\n";
    315316    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    316         run(command => $cmd, verbose => $verbose);
     317        run(command => $cmd, verbose => $verbose);
    317318    unless ($success) {
    318         $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();
    321         &my_die("Failed to execute command: >>$cmd<<");
     319        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     320        # If we failed, see if we failed due to authorization.
     321        check_ssh_connection();
     322        &my_die("Failed to execute command: >>$cmd<<");
    322323    }
    323324    return ($stdout_buf);
    324 }   
     325}
    325326
    326327sub poll_job {
     
    328329    my $response_array = ssh_exec_command("checkjob -v $job_id");
    329330    my $response = join "\n", @$response_array;
    330    
    331     if ($response =~ /State: Running/) { 
    332         return(0,"Running");
     331
     332    if ($response =~ /State: Running/) {
     333        return(0,"Running");
    333334    }
    334335    elsif ($response =~ /State: Completed/) {
    335         return(1,"Completed");
     336        return(1,"Completed");
    336337    }
    337338    elsif ($response =~ /State: Idle/) {
    338         return(-2,"Idle");
     339        return(-2,"Idle");
    339340    }
    340341    else {
    341         my $response_word = $response;
    342         $response_word =~ s/.*State: //;
    343         $response_word =~ s/\n.*//;
    344         return(-1,$response_word);
     342        my $response_word = $response;
     343        $response_word =~ s/.*State: //;
     344        $response_word =~ s/\n.*//;
     345        return(-1,$response_word);
    345346    }
    346347}
     
    351352    my $ipp_disk= $ipprc->file_resolve( $neb_uri );
    352353    my $remote_disk = $ipp_disk;
    353    
     354
    354355    unless(defined($ipp_disk)) {
    355         my_die();
     356        my_die();
    356357    }
    357358
     
    382383    return($remote_uri);
    383384}
    384  
     385
    385386sub uri_remote_to_local {
    386387    # This needs to replace the remote root directory with the nebulous tag.
     
    388389    $remote_uri =~ s%${remote_root}%%;
    389390    my $local_uri  = "neb:///" . $remote_uri;
    390    
     391
    391392    return($local_uri);
    392393}
     
    397398    my $file = shift;
    398399
    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);
     400    if ($cmd eq '') {
     401        # Zero byte file.  This dbinfo was never constructed properly.
     402
     403        # Steal the stage_id from the filename.  This isn't something I'm happy about.
     404        my $stage = $runData->{stage};
     405        my $stage_id = $file;
     406        if ($stage eq 'chip') {
     407            $stage_id =~ s/^.*ch\.//;
     408        }
     409        elsif ($stage eq 'camera') {
     410            $stage_id =~ s/^.*cm\.//;
     411        }
     412        elsif ($stage eq 'warp') {
     413            $stage_id =~ s/^.*wrp\.//;
     414        }
     415        elsif ($stage eq 'stack') {
     416            $stage_id =~ s/^.*stk\.//;
     417        }
     418        $stage_id =~ s/\..*$//;
     419
     420        # Drop this from the database
     421        my $drop_cmd = "$remotetool -dropcomponent -remote_id $remote_id -stage_id $stage_id ";
     422        $drop_cmd   .= " -dbname $dbname " if defined($dbname);
     423        system($drop_cmd);
    423424    }
    424425
     
    434435
    435436    carp($msg);
    436    
     437
    437438    if (defined $id and not $no_update) {
    438         my $command = "$remotetool -updaterun -remote_id $id";
    439         $command .= " -fault $exit_code " if defined $exit_code;
    440         $command .= " -job_id $job_id " if defined $jobid;
    441         $command .= " -set_state $exit_state " if defined $exit_state;
    442         $command .= " -dbname $dbname " if defined $dbname;
    443 
    444         system($command);
     439        my $command = "$remotetool -updaterun -remote_id $id";
     440        $command .= " -fault $exit_code " if defined $exit_code;
     441        $command .= " -job_id $job_id " if defined $jobid;
     442        $command .= " -set_state $exit_state " if defined $exit_state;
     443        $command .= " -dbname $dbname " if defined $dbname;
     444
     445        system($command);
    445446    }
    446447
Note: See TracChangeset for help on using the changeset viewer.