IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37265


Ignore:
Timestamp:
Aug 19, 2014, 8:00:38 AM (12 years ago)
Author:
eugene
Message:

sc_retry_return.pl ready for testing

Location:
tags/ipp-pv3-20140717/ippScripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tags/ipp-pv3-20140717/ippScripts/Build.PL

    r37124 r37265  
    142142        scripts/sc_prepare_warp.pl
    143143        scripts/sc_remote_exec.pl
     144        scripts/sc_retry_return.pl
    144145        scripts/sc_transfer_tool.pl
    145146    )],
  • tags/ipp-pv3-20140717/ippScripts/scripts/sc_retry_return.pl

    r37264 r37265  
    2525my $scp        = can_run('scp')  or (warn "Can't find scp" and $missing_tools = 1);
    2626my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1);
     27my $chiptool   = can_run('chiptool') or (warn "Can't find chiptool" and $missing_tools = 1);
    2728
    2829if ($missing_tools) {
     
    3233
    3334# Options
    34 my ($remote_id,$path_base,$policy,$poll,$force,$job_id,$dbname,$verbose,$no_update,$camera);
     35my ($remote_id,$path_base,$job_id,$dbname,$verbose,$no_update,$camera);
    3536$force = 0;
    3637$verbose = 0;
     
    3940    'job_id=s'      => \$job_id,
    4041    'path_base=s'   => \$path_base,
    41     'policy=s'      => \$policy,
    42     'poll'          => \$poll,
    43     'force-poll'    => \$force,
    4442    'camera=s'      => \$camera,
    4543    'dbname=s'      => \$dbname,
     
    8078my $rrData2 = parse_md_list($rrData);
    8179my $runData = ${ $rrData2 }[0]; # There should be only one
    82 
    83 # keep this for reference for the moment, but this block should not be in this function
    84 if (0) {
    85 # Phase 2: Ensure files are in place:
    86 # Copy command files
    87     my @files = ();
    88 
    89     my $uri_command = $path_base . ".cmd";
    90     my $uri_transfer= $path_base . ".transfer";
    91     my $uri_check   = $path_base . ".check";
    92     my $uri_config  = $path_base . ".config";
    93     my $uri_generate= $path_base . ".generate";
    94     my $uri_return  = $path_base . ".return";
    95 
    96     my $disk_command = $ipprc->file_resolve($uri_command);
    97     my $disk_transfer= $ipprc->file_resolve($uri_transfer);
    98     my $disk_check   = $ipprc->file_resolve($uri_check);
    99     my $disk_config  = $ipprc->file_resolve($uri_config);
    100     my $disk_generate= $ipprc->file_resolve($uri_generate);
    101     my $disk_return  = $ipprc->file_resolve($uri_return);
    102 
    103     scp_put($disk_command,uri_local_to_remote($uri_command));
    104     scp_put($disk_transfer,uri_local_to_remote($uri_transfer));
    105     scp_put($disk_check,uri_local_to_remote($uri_check));
    106     scp_put($disk_config,uri_local_to_remote($uri_config));
    107     scp_put($disk_generate,uri_local_to_remote($uri_generate));
    108     scp_put($disk_return, uri_local_to_remote($uri_return));
    109 
    110 # Run check command
    111     my (undef,$remote_check) = uri_convert($uri_check);
    112     my (undef,$remote_transfer)= uri_convert($uri_transfer);
    113 
    114     my $ssh_check_stdout = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_check --fetch $remote_transfer");
    115     # We no longer need to parse this output, as it retrieves files itself.
    116     foreach my $l (split /\n/, (join '', @$ssh_check_stdout)) {
    117         print "$l\n";
    118     }
    119 
    120 # Run real command
    121     my (undef,$remote_command) = uri_convert($uri_command);
    122     my $ssh_exec_stdout = ssh_exec_command("msub -V $remote_command");
    123     if ($#{ $ssh_exec_stdout } != -1) { # Parse the output
    124         $job_id = ${ $ssh_exec_stdout }[0];
    125         chomp($job_id);
    126         $job_id =~ s/\s+//g;
    127     }
    128 
    129     unless(defined($job_id)) { # If we don't have a job_id from this command, it didn't run correctly.
    130         &my_die("No job_id returned.  Sorry.",$remote_id,$PS_EXIT_PROG_ERROR);
    131     }
    132 
    133     # Notify the database that this entry is currently running.
    134     my $command = "$remotetool -updaterun -remote_id $remote_id ";
    135     $command .= " -set_state run ";
    136     $command .= " -job_id $job_id ";
    137     $command .= " -dbname $dbname " if defined $dbname;
    138 
    139     print STDERR "$command\n";
    140     system($command);
    141 
    142 } # End of exec phase
    14380
    14481# Poll the job status?
     
    203140        print "$return_push_output_print\n";
    204141    } while (($transfer_success != 1) &&  ($iter < 10));  # Try harder;
     142
     143    if (!$transfer_success) &my_die ("failed to get all return files");
    205144}
    206145
    207146foreach my $file (@dbinfo_files) {
    208     # use the filename to get the stage id, check if we have already updated this entry:
    209 
    210 
     147
     148    # use the dbinfo filename to get stage id, check if we have already updated this entry:
     149    my ($stage_id, $class_id) = get_stage_id_from_dbinfo ($file);
     150
     151    # chiptool -dbname -chip_id $stage_id -class_id $class_id
     152
     153    # we just need to check for the existence of an entry:
     154    if ($runData->{stage} == "chip") {
     155        my $cmd = "$chiptool -simple -processedimfile -chip_id $stage_id -class_id $class_id";
     156        $cmd   .= " -dbname $dbname " if defined($dbname);
     157       
     158        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     159            run(command => $cmd, verbose => $verbose);
     160
     161        unless ($success) {
     162            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     163            &my_die("Unable to run chiptool to check on results", $remote_id,$error_code);
     164        }
     165
     166        my $Nrows = @$stdout_buff;
     167        if ($Nrows > 0) {
     168            print STDERR "skip this entry: $stage_id, $class_id\n";
     169            next;
     170        }
     171    }
    211172
    212173    open(DBF,"$file") || warn "Missing file $file\n";
    213174    my $cmd = <DBF>;
    214175    close(DBF);
     176
    215177    chomp($cmd);
    216 #    print STDERR "$file $cmd\n";
     178
    217179    $cmd =~ s/-/ -/g; # This is just a safety check for missing space.
     180    if ($cmd == "") {
     181        print STDERR "empty dbinfo file for $stage_id, $class_id, skipping\n";
     182        next;
     183    }
     184
    218185    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    219186        run(command => $cmd, verbose => $verbose);
    220187    unless ($success) {
    221 
    222188        # This shouldn't fail, but we also can't suddenly abort if something does fail.
    223189        # Now we're going to drop the component that owns this dbinfo, which should force a retry.
     
    228194        }
    229195    }
    230 
    231196}
    232197
     
    234199&my_die("Finished",$remote_id,0,"full");
    235200
    236 
    237201# END PROGRAM
    238202
    239 
     203# yes
    240204sub check_ssh_connection {
    241205    my $cmd = "$ssh -O check $DMZ_HOST";
     
    245209    unless ($success) {
    246210        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    247         &my_die("Authorization check failed.",$remote_id,0,'auth');
    248     }
    249 }
    250 
    251 sub scp_put {
    252     my $file = shift;
    253     my $destination = shift;
    254     my $cmd = "$scp $file ${DMZ_HOST}:${SEC_HOST}:${destination}";
    255 
    256     my $directory = dirname($destination);
    257     ssh_exec_command("mkdir -p $directory");
    258 
    259     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    260         run(command => $cmd, verbose => $verbose);
    261     unless ($success) {
    262         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    263         &my_die();
    264     }
    265 }
    266 
    267 sub scp_get {
    268     my $destination = shift;
    269     my $file = shift;
    270 
    271     my $cmd = "$scp ${DMZ_HOST}:${SEC_HOST}:${destination} $file ";
    272 
    273     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    274         run(command => $cmd, verbose => $verbose);
    275     unless ($success) {
    276         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    277         &my_die();
     211        &my_die("Authorization check failed", $remote_id, 0, 'auth');
    278212    }
    279213}
     
    294228}
    295229
     230sub uri_convert {
     231    my $neb_uri = shift;
     232    my $ipp_disk= $ipprc->file_resolve( $neb_uri );
     233    my $remote_disk = $ipp_disk;
     234
     235    unless(defined($ipp_disk)) {
     236        my_die();
     237    }
     238
     239    $remote_disk =~ s%^.*/%%;   # Remove nebulous path
     240    $remote_disk =~ s%^\d+\.%%; # Remove ins_id
     241    $remote_disk =~ s%:%/%g;    # Replace colons with directories
     242    $remote_disk = "${remote_root}/${remote_disk}";
     243    return($ipp_disk, $remote_disk);
     244}
     245
    296246sub poll_job {
    297247    my $job_id = shift;
    298248    my $response_array = ssh_exec_command("checkjob -v $job_id");
    299249    my $response = join "\n", @$response_array;
    300 
    301     if ($response =~ /State: Running/) {
    302         return(0,"Running");
     250   
     251    if ($response =~ /State: Running/) { 
     252        return(0,"Running");
    303253    }
    304254    elsif ($response =~ /State: Completed/) {
    305         return(1,"Completed");
     255        return(1,"Completed");
    306256    }
    307257    elsif ($response =~ /State: Idle/) {
    308         return(-2,"Idle");
     258        return(-2,"Idle");
    309259    }
    310260    else {
    311         my $response_word = $response;
    312         $response_word =~ s/.*State: //;
    313         $response_word =~ s/\n.*//;
    314         return(-1,$response_word);
    315     }
    316 }
    317 
    318 
    319 sub uri_convert {
    320     my $neb_uri = shift;
    321     my $ipp_disk= $ipprc->file_resolve( $neb_uri );
    322     my $remote_disk = $ipp_disk;
    323 
    324     unless(defined($ipp_disk)) {
    325         my_die();
    326     }
    327 
    328     $remote_disk =~ s%^.*/%%;   # Remove nebulous path
    329     $remote_disk =~ s%^\d+\.%%; # Remove ins_id
    330     $remote_disk =~ s%:%/%g;    # Replace colons with directories
    331     $remote_disk = "${remote_root}/${remote_disk}";
    332     return($ipp_disk,$remote_disk);
    333 }
    334 
    335 sub uri_to_outputs {
    336     my $neb_uri = shift;
    337     my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri );
    338 
    339 #    print TRANSFER "$ipp_disk\n";
    340 #    print CHECK    "$remote_disk\n";
    341     return($ipp_disk,$remote_disk);
    342 }
    343 
    344 sub uri_local_to_remote {
    345     # This needs to replace the nebulous tag with the remote root.
    346     my $local_uri = shift;
    347     $local_uri =~ s%^.*?/%%; # neb:/
    348     $local_uri =~ s%^.*?/%%; # /
    349     $local_uri =~ s%^.*?/%%; # @HOST@.0/
    350     my $remote_uri = "${remote_root}/" . $local_uri;
    351 
    352     return($remote_uri);
    353 }
    354 
    355 sub uri_remote_to_local {
    356     # This needs to replace the remote root directory with the nebulous tag.
    357     my $remote_uri = shift;
    358     $remote_uri =~ s%${remote_root}%%;
    359     my $local_uri  = "neb:///" . $remote_uri;
    360 
    361     return($local_uri);
    362 }
     261        my $response_word = $response;
     262        $response_word =~ s/.*State: //;
     263        $response_word =~ s/\n.*//;
     264        return(-1,$response_word);
     265    }
     266}
     267
    363268
    364269# assumes $runData->{stage} exists
    365270sub get_stage_id_from_dbinfo {
    366271    my $file = shift;
     272
     273    my $stage_id = 0;
     274    my $class_id = 0;
    367275
    368276    # Steal the stage_id from the filename.  This isn't something I'm happy about.
     
    373281    elsif ($stage eq 'camera') {
    374282        $stage_id =~ s/^.*cm\.//;
     283        $class_id = 0;
    375284    }
    376285    elsif ($stage eq 'warp') {
    377286        $stage_id =~ s/^.*wrp\.//;
     287        $class_id = 0;
    378288    }
    379289    elsif ($stage eq 'stack') {
    380290        $stage_id =~ s/^.*stk\.//;
     291        $class_id = 0;
    381292    }
    382293
     
    439350    exit($exit_code);
    440351}
    441 
    442 # Quick review:
    443 # new -> pending -> run -> full
    444 # auth
Note: See TracChangeset for help on using the changeset viewer.