IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37298


Ignore:
Timestamp:
Aug 24, 2014, 1:15:51 PM (12 years ago)
Author:
eugene
Message:

testing for sc_ scripts: prepare chip & camera are good; remote_exec is good; remote_poll is good

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

Legend:

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

    r37284 r37298  
    143143        scripts/sc_prepare_run.pl
    144144        scripts/sc_remote_exec.pl
     145        scripts/sc_remote_poll.pl
    145146        scripts/sc_retry_return.pl
    146147        scripts/sc_transfer_tool.pl
  • tags/ipp-pv3-20140717/ippScripts/scripts/sc_prepare_camera.pl

    r37291 r37298  
    2020# Hard coded values
    2121# my $remote_root   = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location
    22 my $remote_root   = '/scratch3/watersc1/';  # Far side destination base location
    23 my $threads_req   = 0;                      # How many threads are we going to use?
     22my $remote_root     = '/scratch3/watersc1/';  # Far side destination base location
     23my $remote_hostname = "LANL/Mustang";         # Name of the remote node.
     24my $threads_req     = 0;                      # How many threads are we going to use?
    2425
    2526my $fail_state = "prep_fail";
     
    3839GetOptions(
    3940    'remote_id=s'    => \$remote_id,
    40     'cam_d=s'        => \$cam_id,
     41    'cam_id=s'       => \$cam_id,
    4142    'camera|c=s'     => \$camera,
    4243    'dbname|d=s'     => \$dbname,
     
    8586
    8687# STEP 1: Get exposure level information for this camRun
    87 my ($workdir,$exp_tag);
    88 {   
     88my ($workdir,$exp_tag,$reduction);
     89{
    8990    my $command = "$camtool -pendingexp -cam_id $cam_id ";
    9091    $command   .= " -dbname $dbname " if defined($dbname);
    91    
     92
    9293    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    9394        run(command => $command, verbose => 0);
    9495    unless ($success) {
    9596        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    96        
     97
    9798        &my_die("Unable to run camtool to determine stage parameters.", $remote_id, $cam_id, $error_code, $fail_state);
    9899    }
    99    
     100
    100101    my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
    101         &my_die("Unable to determine cam component information.", $remote_id, $cam_id, $PS_EXIT_PROG_ERROR, $fail_state);
     102        &my_die("Unable to determine cam component information.", $remote_id, $cam_id, $PS_EXIT_PROG_ERROR, $fail_state);
    102103    my $metadata = parse_md_list($MDlist);
    103104    my $camEntry = $metadata->[0];
    104    
    105     $workdir = $camEntry->{workdir};
    106     $exp_tag = $camEntry->{exp_tag};
     105
     106    $workdir   = $camEntry->{workdir};
     107    $exp_tag   = $camEntry->{exp_tag};
     108    $reduction = $camEntry->{reduction};
     109    $reduction = 'DEFAULT' unless defined $reduction;
    107110    unless (defined($workdir)) {
    108         while( my ($k, $v) = each %$camEntry ) {
    109             print "key: $k, value: $v.\n";
    110         }
    111         print "%{ $camEntry }\n";
    112         die;
     111        while( my ($k, $v) = each %$camEntry ) {
     112            print "key: $k, value: $v.\n";
     113        }
     114        print "%{ $camEntry }\n";
     115        die;
    113116    }
    114117}
     
    122125    $command   .= " -dbname $dbname " if defined($dbname);
    123126
    124     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    125         run(command => $command, verbose => 0);
     127    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     128        run(command => $command, verbose => 0);
    126129    unless ($success) {
    127         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     130        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    128131        &my_die("Unable to run camtool -pendingimfile ", $remote_id, $cam_id, $error_code, $fail_state);
    129132    }
     
    131134    # We don't actually care about the input cam data other than to know which mask files to instantiate.
    132135    my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
    133         &my_die("Unable to determine cam component information.", $remote_id, $cam_id, $PS_EXIT_PROG_ERROR, $fail_state);
     136        &my_die("Unable to determine cam component information.", $remote_id, $cam_id, $PS_EXIT_PROG_ERROR, $fail_state);
    134137
    135138    my $metadata = parse_md_list($MDlist);
     
    140143    my $pre_cmd_masks= "ls -1 ${remote_chip_path}*.mk.fits > ${remote_outroot}.masklist";
    141144
    142     my $reduction = 'DEFAULT' unless defined $camEntry->{reduction};
    143     my $recipe_psastro = $ipprc->reduction($reduction, 'PSASTRO'); # Recipe to use                                                                         
     145    my $recipe_psastro = $ipprc->reduction($reduction, 'PSASTRO'); # Recipe to use
     146    if ($recipe_psastro eq "") {
     147        &my_die("Unable to determine PSASTRO recipe", $cam_id, $PS_EXIT_PROG_ERROR);
     148    }
    144149
    145150    my $psastro_command = " psastro -list ${remote_outroot}.cmflist ";
    146151    $psastro_command   .= " -masklist ${remote_outroot}.masklist ${remote_outroot} ";
    147 #   $psastro_command   .= " -refmasklist ${remote_outroot}.masklist ${remote_outroot} ";
    148 # This is used to do edge calculations.  It should probably be smart enough to know that it can just use the masks I just specified, but it's not.
    149     # Uncomment when remote psastro supports this
     152#   $psastro_command   .= " -refmasklist ${remote_outroot}.masklist ${remote_outroot} ";
     153    $psastro_command   .= " -refmasklist /turquoise/usr/projects/ps1/watersc1/references/gpc1.refmask.list ";
    150154    $psastro_command   .= " -kh-correct /turquoise/usr/projects/ps1/watersc1/references/khcorrect.20140606.v0.fits ";
    151     $psastro_command   .= " -refmasklist /turquoise/usr/projects/ps1/watersc1/references/gpc1.refmask.list ";
    152155#   $psastro_command   .= " -astrommodel /turquoise/usr/projects/ps1/watersc1/references/gpc1.20080909.asm ";
    153156    $psastro_command   .= " -astrommodel /turquoise/usr/projects/ps1/watersc1/references/gpc1.20140505.asm ";
     
    156159    $psastro_command   .= " -dumpconfig ${remote_outroot}.psastro.mdc -stats ${remote_outroot}.stats ";
    157160    $psastro_command   .= " -recipe PPSTATS CAMSTATS ";
    158    
     161
    159162    my $camtool_post_cmd = "camtool -cam_id $cam_id -addprocessedexp -uri UNKNOWN ";
    160     $camtool_post_cmd  .=  " -dbname $dbname " if defined $dbname; 
     163    $camtool_post_cmd  .=  " -dbname $dbname " if defined $dbname;
    161164    $camtool_post_cmd  .=  " -path_base $ipp_outroot -hostname $remote_hostname -dtime_script 0 ";
    162165    my $post_cmd_echo = " echo -n \"$camtool_post_cmd\" > ${remote_outroot}.dbinfo ";
     
    168171    # Determine which output files need to be returned
    169172    foreach my $component(@return_component_list) {
    170         my $filename = $ipprc->filename($component,$ipp_outroot);
    171         my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename);
    172         my $remote_outroot_dir = dirname($ipp_disk);
    173         print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
     173        my $filename = $ipprc->filename($component,$ipp_outroot);
     174        my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename);
     175        my $remote_outroot_dir = dirname($ipp_disk);
     176        print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
    174177    }
    175178    foreach my $chipInfo (@{ $metadata }) {
    176         my $filename = $ipprc->filename("PSASTRO.OUTPUT.MASK",$ipp_outroot,$chipInfo->{class_id});
    177         my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename);
    178         my $remote_outroot_dir = dirname($ipp_disk);
    179         print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
     179        my $filename = $ipprc->filename("PSASTRO.OUTPUT.MASK",$ipp_outroot,$chipInfo->{class_id});
     180        my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename);
     181        my $remote_outroot_dir = dirname($ipp_disk);
     182        print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
    180183    }
    181184    print CONFIG "\n";
     
    204207    my $ipp_disk= $ipprc->file_resolve( $neb_uri );
    205208    my $remote_disk = $ipp_disk;
    206    
     209
    207210    unless(defined($ipp_disk)) {
    208211        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state);
     
    220223    my $ipp_disk= $ipprc->file_resolve( $neb_uri , 1);
    221224    my $remote_disk = $ipp_disk;
    222    
     225
    223226    unless(defined($ipp_disk)) {
    224227        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state);
     
    235238    my $neb_uri = shift;
    236239    my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri );
    237    
     240
    238241    unless (exists($file_filter{$neb_uri})) {
    239242        $file_filter{$neb_uri} = 1;
     
    265268    return($remote_uri);
    266269}
    267  
     270
    268271sub uri_remote_to_local { #(local_neb_uri) = uri_remote_to_local(remote_uri);
    269272    # This needs to replace the remote root directory with the nebulous tag.
     
    271274    $remote_uri =~ s%${remote_root}%%;
    272275    my $local_uri  = "neb:///" . $remote_uri;
    273    
     276
    274277    return($local_uri);
    275278}
     
    286289
    287290    carp($msg);
    288    
     291
    289292    if (defined $remote_id and defined $stage_id and not $no_update) {
    290         my $command = "remotetool -updatecomponent -remote_id $id -stage_id $stage_id";
     293        my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $stage_id";
    291294        $command .= " -set_state $exit_state " if defined $exit_state;
    292295        $command .= " -dbname $dbname " if defined $dbname;
  • tags/ipp-pv3-20140717/ippScripts/scripts/sc_prepare_chip.pl

    r37291 r37298  
    2020# Hard coded values
    2121# my $remote_root   = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location
    22 my $remote_root   = '/scratch3/watersc1/';  # Far side destination base location
    23 my $remote_raw    = "${remote_root}/raw/";  # Directory to find raw data in.
    24 my $threads_req   = 4;
     22my $remote_root     = '/scratch3/watersc1/';  # Far side destination base location
     23my $remote_hostname = "LANL/Mustang";         # Name of the remote node.
     24my $remote_raw      = "${remote_root}/raw/";  # Directory to find raw data in.
     25my $threads_req     = 4;
    2526
    2627my $fail_state = "prep_fail";
     
    264265        my $post_commandA = "chiptool -addprocessedimfile -exp_id $exp_id -chip_id $chip_id -class_id $class_id ";
    265266        $post_commandA   .= " -uri ${ipp_outroot}.ch.${class_id}.ch.fits -path_base $ipp_outroot ";
    266         $post_commandA   .= " -magicked 0 -hostname REMOTE -dtime_script 0 ";
     267        $post_commandA   .= " -magicked 0 -hostname $remote_hostname -dtime_script 0 ";
    267268        $post_commandA   .= " -dbname $dbname " if defined $dbname;
    268269
  • tags/ipp-pv3-20140717/ippScripts/scripts/sc_prepare_run.pl

    r37291 r37298  
    3232# Estimate of how long a job runs, in hours (depends on stage)
    3333my %job_cost = ();
    34 $job_cost{"camera"} = 1700 / 60 / 60; 
     34$job_cost{"camera"} = 1700 / 60 / 60;
    3535$job_cost{"chip"}   = 150 / 60 / 60;
    3636$job_cost{"warp"}   = 110 / 60 / 60;
     
    4242my $min_time      = 1;                      # shortest allocation to ask for
    4343my $max_time      = 8;                      # longest allocation to ask for
    44 my $remote_hostname= "LANL/Mustang";         # Name of the remote node.
    4544
    4645# We need to ensure we only ever try to transfer a file once.
  • tags/ipp-pv3-20140717/ippScripts/scripts/sc_prepare_stack.pl

    r37291 r37298  
    2020# Hard coded values
    2121# my $remote_root   = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location
    22 my $remote_root   = '/scratch3/watersc1/';  # Far side destination base location
    23 my $threads_req   = 4;                      # How many threads are we going to use?
     22my $remote_root     = '/scratch3/watersc1/';  # Far side destination base location
     23my $remote_hostname = "LANL/Mustang";         # Name of the remote node.
     24my $threads_req     = 4;                      # How many threads are we going to use?
    2425
    2526my $fail_state = "prep_fail";
     
    5960
    6061my @return_component_list = ("DBINFO.EXP", "PPSTACK.UNCONV","PPSTACK.UNCONV.MASK","PPSTACK.UNCONV.VARIANCE",
    61                              "PPSTACK.UNCONV.EXP","PPSTACK.UNCONV.EXPWT","PPSTACK.UNCONV.EXPNUM","PSPHOT.OUTPUT",
    62                              "LOG.EXP", "PSASTRO.STATS",
    63                              "PPSTACK.CONFIG","PPSTACK.TARGET.PSF","PSPHOT.STACK.PSF.SAVE");
     62                             "PPSTACK.UNCONV.EXP","PPSTACK.UNCONV.EXPWT","PPSTACK.UNCONV.EXPNUM","PSPHOT.OUTPUT",
     63                             "LOG.EXP", "PSASTRO.STATS",
     64                             "PPSTACK.CONFIG","PPSTACK.TARGET.PSF","PSPHOT.STACK.PSF.SAVE");
    6465#,"PPSTACK.CONV.KERNEL");
    6566
     
    9394    $command .= " -dbname $dbname " if defined($dbname);
    9495    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    95         run(command => $command, verbose => 0);
     96        run(command => $command, verbose => 0);
    9697    unless ($success) {
    97         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    98         &my_die("Unable to run stacktool -tosum ", $remote_id, $stack_id, $error_code, $fail_state);
     98        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     99        &my_die("Unable to run stacktool -tosum ", $remote_id, $stack_id, $error_code, $fail_state);
    99100    }
    100101
    101102    my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
    102         &my_die("Unable to determine stack component information.", $remote_id, $stack_id, $PS_EXIT_PROG_ERROR, $fail_state);
     103        &my_die("Unable to determine stack component information.", $remote_id, $stack_id, $PS_EXIT_PROG_ERROR, $fail_state);
    103104    my $metadata = parse_md_list($MDlist);
    104105
     
    111112    $skycell_id= $stack->{skycell_id};
    112113}
    113 my $ipp_outroot    = "${workdir}/${tess_id}/${skycell_id}/${tess_id}.${skycell_id}.stk.${stack_id}";   
    114 my $remote_outroot = uri_local_to_remote($ipp_outroot);   
     114my $ipp_outroot    = "${workdir}/${tess_id}/${skycell_id}/${tess_id}.${skycell_id}.stk.${stack_id}";
     115my $remote_outroot = uri_local_to_remote($ipp_outroot);
    115116my $remote_outdir  = uri_local_to_remote("${workdir}/${tess_id}/${skycell_id}");
    116117
     
    122123    $command .= " -dbname $dbname " if defined($dbname);
    123124    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    124         run(command => $command, verbose => 0);
     125        run(command => $command, verbose => 0);
    125126    unless ($success) {
    126         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    127         &my_die("Unable to run stacktool -inputskyfile ", $remote_id, $stack_id, $error_code, $fail_state);
     127        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     128        &my_die("Unable to run stacktool -inputskyfile ", $remote_id, $stack_id, $error_code, $fail_state);
    128129    }
    129130
    130131    my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
    131         &my_die("Unable to determine stack component information.", $remote_id, $stack_id, $PS_EXIT_PROG_ERROR, $fail_state);
     132        &my_die("Unable to determine stack component information.", $remote_id, $stack_id, $PS_EXIT_PROG_ERROR, $fail_state);
    132133    my $warpData = parse_md_list($MDlist);
    133134}
     
    137138    my $warp_path_base_string = "";
    138139    foreach my $warpEntry ( @{ $warpData } ) {
    139         my $warp_path_base = $warpEntry->{path_base};
    140         my $remote_path_base = uri_local_to_remote($warp_path_base);
    141         $warp_path_base_string .= " $remote_path_base ";
    142 
    143         # Append file names to transfer lists so we can recover if warps are deleted.
    144         uri_to_outputs($warp_path_base . ".fits");
    145         uri_to_outputs($warp_path_base . ".wt.fits");
    146         uri_to_outputs($warp_path_base . ".mask.fits");
    147         uri_to_outputs($warp_path_base . ".cmf");
    148 #       uri_to_outputs($warp_path_base . ".psf");
     140        my $warp_path_base = $warpEntry->{path_base};
     141        my $remote_path_base = uri_local_to_remote($warp_path_base);
     142        $warp_path_base_string .= " $remote_path_base ";
     143
     144        # Append file names to transfer lists so we can recover if warps are deleted.
     145        uri_to_outputs($warp_path_base . ".fits");
     146        uri_to_outputs($warp_path_base . ".wt.fits");
     147        uri_to_outputs($warp_path_base . ".mask.fits");
     148        uri_to_outputs($warp_path_base . ".cmf");
     149#       uri_to_outputs($warp_path_base . ".psf");
    149150    }
    150151    my $mk_mdc_command = "mkdir -p $remote_outdir && sc_mk_stack_mdc.pl $warp_path_base_string > ${remote_outroot}.in.mdc";
    151     my $recipe_ppstack = $ipprc->reduction($reduction, 'STACK_PPSTACK'); # Recipe to use                                                                         
     152    my $recipe_ppstack = $ipprc->reduction($reduction, 'STACK_PPSTACK'); # Recipe to use
    152153    my $ppstack_command  = " ppStack -input ${remote_outroot}.in.mdc ";
    153154    $ppstack_command    .= " ${remote_outroot} -stats ${remote_outroot}.stats ";
     
    169170    $post_cmd_echo   .=  " -dbname $dbname " if defined $dbname;
    170171    $post_cmd_echo   .= " -hostname $remote_hostname -dtime_script 0 \" > ${remote_outroot}.dbinfo ";
    171        
     172
    172173    my $post_cmd_SfM  = " ppStatsFromMetadata ${remote_outroot}.stats - STACK_SKYCELL >> ${remote_outroot}.dbinfo ";
    173174
     
    177178    # Determine which output files need to be returned
    178179    foreach my $component(@return_component_list) {
    179         my $filename = $ipprc->filename($component,$ipp_outroot);
    180         my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename);
    181         my $remote_outroot_dir = dirname($ipp_disk);
    182         print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
     180        my $filename = $ipprc->filename($component,$ipp_outroot);
     181        my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename);
     182        my $remote_outroot_dir = dirname($ipp_disk);
     183        print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
    183184    }
    184185    print CONFIG "\n";
     
    206207    my $ipp_disk= $ipprc->file_resolve( $neb_uri );
    207208    my $remote_disk = $ipp_disk;
    208    
     209
    209210    unless(defined($ipp_disk)) {
    210211        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $stack_id, $PS_EXIT_SYS_ERROR, $fail_state);
     
    222223    my $ipp_disk= $ipprc->file_resolve( $neb_uri , 1);
    223224    my $remote_disk = $ipp_disk;
    224    
     225
    225226    unless(defined($ipp_disk)) {
    226227        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $stack_id, $PS_EXIT_SYS_ERROR, $fail_state);
     
    237238    my $neb_uri = shift;
    238239    my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri );
    239    
     240
    240241    unless (exists($file_filter{$neb_uri})) {
    241242        $file_filter{$neb_uri} = 1;
     
    267268    return($remote_uri);
    268269}
    269  
     270
    270271sub uri_remote_to_local { #(local_neb_uri) = uri_remote_to_local(remote_uri);
    271272    # This needs to replace the remote root directory with the nebulous tag.
     
    273274    $remote_uri =~ s%${remote_root}%%;
    274275    my $local_uri  = "neb:///" . $remote_uri;
    275    
     276
    276277    return($local_uri);
    277278}
     
    288289
    289290    carp($msg);
    290    
     291
    291292    if (defined $remote_id and defined $stage_id and not $no_update) {
    292293        my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $stage_id";
  • tags/ipp-pv3-20140717/ippScripts/scripts/sc_prepare_warp.pl

    r37291 r37298  
    2020# Hard coded values
    2121# my $remote_root = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location
    22 my $remote_root   = '/scratch3/watersc1/'; 
    23 my $threads_req   = 4;                      # How many threads are we going to use?
     22my $remote_root     = '/scratch3/watersc1/';
     23my $remote_hostname = "LANL/Mustang";         # Name of the remote node.
     24my $threads_req     = 4;                      # How many threads are we going to use?
    2425
    2526my $fail_state = "prep_fail";
     
    9091    $command   .= " -dbname $dbname " if defined($dbname);
    9192    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    92         run(command => $command, verbose => 0);
     93        run(command => $command, verbose => 0);
    9394    unless ($success) {
    94         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    95         &my_die("Unable to run warptool -pendingimfile ", $remote_id, $warp_id, $error_code, $fail_state);
     95        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     96        &my_die("Unable to run warptool -pendingimfile ", $remote_id, $warp_id, $error_code, $fail_state);
    9697    }
    9798    my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
    98         &my_die("Unable to determine warp component information.", $remote_id, $warp_id, $PS_EXIT_PROG_ERROR, $fail_state);
     99        &my_die("Unable to determine warp component information.", $remote_id, $warp_id, $PS_EXIT_PROG_ERROR, $fail_state);
    99100    $warpData = parse_md_list($MDlist);
    100101}
     
    103104{
    104105    foreach my $warpEntry ( @{ $warpData } ) {
    105         my $workdir = $warpEntry->{workdir};
    106         my $exp_tag = $warpEntry->{exp_tag};
    107         my $skycell_id = $warpEntry->{skycell_id};
    108         my $tess_id = $warpEntry->{tess_id};
    109         my $reduction = 'DEFAULT' unless defined $warpEntry->{reduction};
    110         my $recipe_pswarp = $ipprc->reduction($reduction, 'WARP_PSWARP'); # Recipe to use                                                                         
    111         my $ipp_outroot = "${workdir}/${exp_tag}/${exp_tag}.wrp.${warp_id}.${skycell_id}";
    112         print "$ipp_outroot\n";
    113         my $remote_outroot = uri_local_to_remote($ipp_outroot);
    114 
    115         my $command = "$warptool -scmap -warp_id $warp_id -skycell_id ${skycell_id}";
    116         $command   .= " -dbname $dbname " if defined($dbname);
    117        
    118         ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    119             run(command => $command, verbose => 0);
    120         unless ($success) {
    121             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    122             &my_die("Unable to run warptool -pendingimfile: $command ", $remote_id, $warp_id, $error_code, $fail_state);
    123         }
    124    
    125         my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
    126             &my_die("Unable to determine warp component information.", $remote_id, $warp_id, $PS_EXIT_PROG_ERROR, $fail_state);
    127         my $inData = parse_md_list($MDlist);
    128        
    129         my $pre_cmd_ims = "ls -1 ";
    130         my $pre_cmd_masks= "ls -1 ";
    131         my $pre_cmd_vars = "ls -1 ";
    132         my $pre_cmd_astrom = "";
    133 
    134         foreach my $imfile (@{ $inData2 }) {
    135             my $image = $ipprc->filename("PPIMAGE.CHIP", $imfile->{chip_path_base}, $imfile->{class_id});
    136             my $mask  = $ipprc->filename("PSASTRO.OUTPUT.MASK", $imfile->{cam_path_base}, $imfile->{class_id});
    137             my $var   = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $imfile->{chip_path_base}, $imfile->{class_id});
    138 
    139             my $astrom= $ipprc->filename("PSASTRO.OUTPUT", $imfile->{cam_path_base});
    140            
    141             my $remote_image = uri_local_to_remote($image);
    142             my $remote_mask  = uri_local_to_remote($mask);
    143             my $remote_var   = uri_local_to_remote($var);
    144             my $remote_astrom= uri_local_to_remote($astrom);
    145 
    146             $pre_cmd_ims     .= " $remote_image ";
    147             $pre_cmd_masks   .= " $remote_mask  ";
    148             $pre_cmd_vars    .= " $remote_var   ";
    149             $pre_cmd_astrom   = "echo $remote_astrom > ${remote_outroot}.astrom ";
    150         }
    151         $pre_cmd_ims   .= "  > ${remote_outroot}.imlist ";
    152         $pre_cmd_masks .= "  > ${remote_outroot}.masklist ";
    153         $pre_cmd_vars  .= "  > ${remote_outroot}.varlist ";
    154 
    155         my $skycell_command = " dvoImageExtract -D CATDIR /turquoise/usr/projects/ps1/watersc1/tess/${tess_id} $skycell_id -o ${remote_outroot}.skyfile ";
    156 
    157         my $pswarp_command  = " pswarp -list ${remote_outroot}.imlist ";
    158         $pswarp_command    .= " -masklist ${remote_outroot}.masklist -variancelist ${remote_outroot}.varlist ";
    159         $pswarp_command    .= " -astromlist ${remote_outroot}.astrom ";
    160         $pswarp_command    .= " ${remote_outroot} ${remote_outroot}.skyfile ";
    161         $pswarp_command    .= " -F PSPHOT.PSF.SAVE PSPHOT.PSF.SKY.SAVE ";
    162         $pswarp_command    .= " -F PSPHOT.OUTPUT PSPHOT.OUT.CMF.MEF ";
    163         $pswarp_command    .= " -F PSPHOT.BACKMDL PSPHOT.BACKMDL.MEF ";
    164         $pswarp_command    .= " -F SOURCE.PLOT.MOMENTS SOURCE.PLOT.SKY.MOMENTS ";
    165         $pswarp_command    .= " -F SOURCE.PLOT.PSFMODEL SOURCE.PLOT.SKY.PSFMODEL ";
    166         $pswarp_command    .= " -F SOURCE.PLOT.APRESID SOURCE.PLOT.SKY.APRESID ";
    167         $pswarp_command    .= " -recipe PSWARP $recipe_pswarp ";
    168         $pswarp_command    .= " -tracedest ${remote_outroot}.trace -log ${remote_outroot}.log ";
    169         $pswarp_command    .= " -threads $threads_req "; # -image_id ${image_id} -source_id ${source_id} ";
    170         $pswarp_command    .= " -recipe PPSTATS WARPSTATS ";
    171         $pswarp_command    .= " -dumpconfig ${remote_outroot}.pswarp.mdc -stats ${remote_outroot}.stats ";
    172 
    173 #       print "$pswarp_command \n";
    174        
    175         my $post_cmd_echo = " echo -n \"warptool  -addwarped -warp_id $warp_id -skycell_id $skycell_id -tess_id $tess_id ";
    176         $post_cmd_echo   .= " -path_base $remote_outroot -uri UNKNOWN ";
    177         $post_cmd_echo   .=  " -dbname $dbname " if defined $dbname;
    178         $post_cmd_echo   .= " -path_base $ipp_outroot -hostname $remote_hostname -dtime_script 0 \" > ${remote_outroot}.dbinfo ";
    179        
    180         my $post_cmd_SfM  = " ppStatsFromMetadata ${remote_outroot}.stats - WARP_SKYCELL >> ${remote_outroot}.dbinfo ";
    181 
    182         print CONFIG "${pre_cmd_ims} && ${pre_cmd_masks} && ${pre_cmd_vars} && ${pre_cmd_astrom} && ${skycell_command} && ${pswarp_command} && ${post_cmd_echo} && ${post_cmd_SfM} ";
    183         $job_index++;
    184 
    185         # Determine which output files need to be returned
    186         foreach my $component(@return_component_list) {
    187             my $filename = $ipprc->filename($component,$ipp_outroot,$skycell_id);
    188             my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename);
    189             my $remote_outroot_dir = dirname($ipp_disk);
    190             print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
    191         }
    192         print CONFIG "\n";
    193 #       die();
     106        my $workdir = $warpEntry->{workdir};
     107        my $exp_tag = $warpEntry->{exp_tag};
     108        my $skycell_id = $warpEntry->{skycell_id};
     109        my $tess_id = $warpEntry->{tess_id};
     110        my $reduction = 'DEFAULT' unless defined $warpEntry->{reduction};
     111        my $recipe_pswarp = $ipprc->reduction($reduction, 'WARP_PSWARP'); # Recipe to use
     112        my $ipp_outroot = "${workdir}/${exp_tag}/${exp_tag}.wrp.${warp_id}.${skycell_id}";
     113        print "$ipp_outroot\n";
     114        my $remote_outroot = uri_local_to_remote($ipp_outroot);
     115
     116        my $command = "$warptool -scmap -warp_id $warp_id -skycell_id ${skycell_id}";
     117        $command   .= " -dbname $dbname " if defined($dbname);
     118
     119        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     120            run(command => $command, verbose => 0);
     121        unless ($success) {
     122            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     123            &my_die("Unable to run warptool -pendingimfile: $command ", $remote_id, $warp_id, $error_code, $fail_state);
     124        }
     125
     126        my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
     127            &my_die("Unable to determine warp component information.", $remote_id, $warp_id, $PS_EXIT_PROG_ERROR, $fail_state);
     128        my $inData = parse_md_list($MDlist);
     129
     130        my $pre_cmd_ims = "ls -1 ";
     131        my $pre_cmd_masks= "ls -1 ";
     132        my $pre_cmd_vars = "ls -1 ";
     133        my $pre_cmd_astrom = "";
     134
     135        foreach my $imfile (@{ $inData2 }) {
     136            my $image = $ipprc->filename("PPIMAGE.CHIP", $imfile->{chip_path_base}, $imfile->{class_id});
     137            my $mask  = $ipprc->filename("PSASTRO.OUTPUT.MASK", $imfile->{cam_path_base}, $imfile->{class_id});
     138            my $var   = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $imfile->{chip_path_base}, $imfile->{class_id});
     139
     140            my $astrom= $ipprc->filename("PSASTRO.OUTPUT", $imfile->{cam_path_base});
     141
     142            my $remote_image = uri_local_to_remote($image);
     143            my $remote_mask  = uri_local_to_remote($mask);
     144            my $remote_var   = uri_local_to_remote($var);
     145            my $remote_astrom= uri_local_to_remote($astrom);
     146
     147            $pre_cmd_ims     .= " $remote_image ";
     148            $pre_cmd_masks   .= " $remote_mask  ";
     149            $pre_cmd_vars    .= " $remote_var   ";
     150            $pre_cmd_astrom   = "echo $remote_astrom > ${remote_outroot}.astrom ";
     151        }
     152        $pre_cmd_ims   .= "  > ${remote_outroot}.imlist ";
     153        $pre_cmd_masks .= "  > ${remote_outroot}.masklist ";
     154        $pre_cmd_vars  .= "  > ${remote_outroot}.varlist ";
     155
     156        my $skycell_command = " dvoImageExtract -D CATDIR /turquoise/usr/projects/ps1/watersc1/tess/${tess_id} $skycell_id -o ${remote_outroot}.skyfile ";
     157
     158        my $pswarp_command  = " pswarp -list ${remote_outroot}.imlist ";
     159        $pswarp_command    .= " -masklist ${remote_outroot}.masklist -variancelist ${remote_outroot}.varlist ";
     160        $pswarp_command    .= " -astromlist ${remote_outroot}.astrom ";
     161        $pswarp_command    .= " ${remote_outroot} ${remote_outroot}.skyfile ";
     162        $pswarp_command    .= " -F PSPHOT.PSF.SAVE PSPHOT.PSF.SKY.SAVE ";
     163        $pswarp_command    .= " -F PSPHOT.OUTPUT PSPHOT.OUT.CMF.MEF ";
     164        $pswarp_command    .= " -F PSPHOT.BACKMDL PSPHOT.BACKMDL.MEF ";
     165        $pswarp_command    .= " -F SOURCE.PLOT.MOMENTS SOURCE.PLOT.SKY.MOMENTS ";
     166        $pswarp_command    .= " -F SOURCE.PLOT.PSFMODEL SOURCE.PLOT.SKY.PSFMODEL ";
     167        $pswarp_command    .= " -F SOURCE.PLOT.APRESID SOURCE.PLOT.SKY.APRESID ";
     168        $pswarp_command    .= " -recipe PSWARP $recipe_pswarp ";
     169        $pswarp_command    .= " -tracedest ${remote_outroot}.trace -log ${remote_outroot}.log ";
     170        $pswarp_command    .= " -threads $threads_req "; # -image_id ${image_id} -source_id ${source_id} ";
     171        $pswarp_command    .= " -recipe PPSTATS WARPSTATS ";
     172        $pswarp_command    .= " -dumpconfig ${remote_outroot}.pswarp.mdc -stats ${remote_outroot}.stats ";
     173
     174#       print "$pswarp_command \n";
     175
     176        my $post_cmd_echo = " echo -n \"warptool  -addwarped -warp_id $warp_id -skycell_id $skycell_id -tess_id $tess_id ";
     177        $post_cmd_echo   .= " -path_base $remote_outroot -uri UNKNOWN ";
     178        $post_cmd_echo   .=  " -dbname $dbname " if defined $dbname;
     179        $post_cmd_echo   .= " -path_base $ipp_outroot -hostname $remote_hostname -dtime_script 0 \" > ${remote_outroot}.dbinfo ";
     180
     181        my $post_cmd_SfM  = " ppStatsFromMetadata ${remote_outroot}.stats - WARP_SKYCELL >> ${remote_outroot}.dbinfo ";
     182
     183        print CONFIG "${pre_cmd_ims} && ${pre_cmd_masks} && ${pre_cmd_vars} && ${pre_cmd_astrom} && ${skycell_command} && ${pswarp_command} && ${post_cmd_echo} && ${post_cmd_SfM} ";
     184        $job_index++;
     185
     186        # Determine which output files need to be returned
     187        foreach my $component(@return_component_list) {
     188            my $filename = $ipprc->filename($component,$ipp_outroot,$skycell_id);
     189            my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename);
     190            my $remote_outroot_dir = dirname($ipp_disk);
     191            print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
     192        }
     193        print CONFIG "\n";
     194#       die();
    194195    }
    195196}
     
    217218    my $ipp_disk= $ipprc->file_resolve( $neb_uri );
    218219    my $remote_disk = $ipp_disk;
    219    
     220
    220221    unless(defined($ipp_disk)) {
    221222        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state);
     
    233234    my $ipp_disk= $ipprc->file_resolve( $neb_uri , 1);
    234235    my $remote_disk = $ipp_disk;
    235    
     236
    236237    unless(defined($ipp_disk)) {
    237238        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $warp_id, $PS_EXIT_SYS_ERROR, $fail_state);
     
    248249    my $neb_uri = shift;
    249250    my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri );
    250    
     251
    251252    unless (exists($file_filter{$neb_uri})) {
    252253        $file_filter{$neb_uri} = 1;
     
    278279    return($remote_uri);
    279280}
    280  
     281
    281282sub uri_remote_to_local { #(local_neb_uri) = uri_remote_to_local(remote_uri);
    282283    # This needs to replace the remote root directory with the nebulous tag.
     
    284285    $remote_uri =~ s%${remote_root}%%;
    285286    my $local_uri  = "neb:///" . $remote_uri;
    286    
     287
    287288    return($local_uri);
    288289}
     
    299300
    300301    carp($msg);
    301    
     302
    302303    if (defined $remote_id and defined $stage_id and not $no_update) {
    303304        my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $stage_id";
  • tags/ipp-pv3-20140717/ippScripts/scripts/sc_remote_exec.pl

    r37289 r37298  
    3232
    3333# Options
    34 my ($remote_id,$path_base,$dbname,$verbose,$no_update,$camera);
     34my ($remote_id,$job_id,$path_base,$dbname,$verbose,$no_update,$camera);
    3535$verbose = 0;
    3636GetOptions(
     
    6464unless ($rt_success) {
    6565    $rt_error_code = (($rt_error_code >> 8) or $PS_EXIT_PROG_ERROR);
    66     &my_die("Unable to run remotetool to determine remote run status",
    67             $remote_id,$rt_error_code);
     66    &my_die("Unable to run remotetool to determine remote run status", $remote_id, $rt_error_code);
    6867}
    6968my $rrData = $mdcParser->parse(join "", @$rt_stdout_buf) or
    70     &my_die("Unable to run remotetool to determine remote run status",
    71             $remote_id,$rt_error_code);
     69    &my_die("Unable to run remotetool to determine remote run status", $remote_id, $rt_error_code);
    7270my $rrData2 = parse_md_list($rrData);
    7371my $runData = ${ $rrData2 }[0]; # There should be only one
    7472
    75 my ($remote_path) = uri_convert($path_base);
     73my ($remote_path) = &uri_local_to_remote($path_base);
    7674print "REMOTE PATH: $remote_path\n";
    7775
     
    9492my $disk_return  = $ipprc->file_resolve($uri_return);
    9593
    96 scp_put($disk_command,uri_local_to_remote($uri_command));
    97 scp_put($disk_transfer,uri_local_to_remote($uri_transfer));
    98 scp_put($disk_check,uri_local_to_remote($uri_check));
    99 scp_put($disk_config,uri_local_to_remote($uri_config));
    100 scp_put($disk_generate,uri_local_to_remote($uri_generate));
    101 scp_put($disk_return, uri_local_to_remote($uri_return));
    102 
    103 # Run check command
    104 # my (undef,$remote_check) = uri_convert($uri_check);
    105 # my (undef,$remote_transfer)= uri_convert($uri_transfer);
    106 
    107 my $ssh_check_stdout = ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_path --fetch");
     94&scp_put($disk_command,  &uri_local_to_remote($uri_command));
     95&scp_put($disk_transfer, &uri_local_to_remote($uri_transfer));
     96&scp_put($disk_check,    &uri_local_to_remote($uri_check));
     97&scp_put($disk_config,   &uri_local_to_remote($uri_config));
     98&scp_put($disk_generate, &uri_local_to_remote($uri_generate));
     99&scp_put($disk_return,   &uri_local_to_remote($uri_return));
     100
     101my $ssh_check_stdout = &ssh_exec_command("${remote_root}/sc_transfer_tool.pl --input $remote_path --fetch");
    108102
    109103# We no longer need to parse this output, as it retrieves files itself.
     
    113107
    114108# Run real command
    115 my (undef,$remote_command) = uri_convert($uri_command);
    116 my $ssh_exec_stdout = ssh_exec_command("msub -V $remote_command");
     109my (undef,$remote_command) = &uri_convert($uri_command);
     110my $ssh_exec_stdout = &ssh_exec_command("msub -V $remote_command");
    117111if ($#{ $ssh_exec_stdout } != -1) { # Parse the output
    118112    $job_id = ${ $ssh_exec_stdout }[0];
     
    122116
    123117unless(defined($job_id)) { # If we don't have a job_id from this command, it didn't run correctly.
    124     &my_die("No job_id returned.  Sorry.",$remote_id,$PS_EXIT_PROG_ERROR);
     118    &my_die("No job_id returned.  Sorry.", $remote_id, $PS_EXIT_PROG_ERROR);
    125119}
    126120
    127121# Notify the database that this entry is currently running.
    128 &my_die("Finished",$remote_id,0,"run",$job_id);
     122&my_die("Finished", $remote_id, 0, "run", $job_id);
    129123
    130124# END PROGRAM
     
    137131    unless ($success) {
    138132        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    139         &my_die("Authorization check failed.",$remote_id,0,'auth');
     133        &my_die("Authorization check failed.", $remote_id, 0, 'auth');
    140134    }
    141135}
     
    147141
    148142    my $directory = dirname($destination);
    149     ssh_exec_command("mkdir -p $directory");
    150 
    151     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    152         run(command => $cmd, verbose => $verbose);
    153     unless ($success) {
    154         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    155         &my_die();
     143    &ssh_exec_command("mkdir -p $directory");
     144
     145    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     146        run(command => $cmd, verbose => $verbose);
     147    unless ($success) {
     148        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     149        &my_die("failed to send file $file to LANL", $remote_id, $error_code);
    156150    }
    157151}
     
    167161    unless ($success) {
    168162        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    169         &my_die();
     163        &my_die("failed to get file $file from LANL", $remote_id, $error_code);
    170164    }
    171165}
     
    173167sub ssh_exec_command {
    174168    my $cmd = shift;
    175     $cmd = "$ssh $DMZ_HOST ssh  ${SEC_HOST} $cmd";
     169    $cmd = "$ssh -n $DMZ_HOST ssh  ${SEC_HOST} $cmd";
    176170    print "EXEC: $cmd\n";
    177171    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    181175        # If we failed, see if we failed due to authorization.
    182176        check_ssh_connection();
    183         &my_die("Failed to execute command: >>$cmd<<");
     177        &my_die("Failed to execute remote command: >>$cmd<<", $remote_id, $error_code);
    184178    }
    185179    return ($stdout_buf);
    186180}
    187181
    188 sub poll_job {
    189     my $job_id = shift;
    190     my $response_array = ssh_exec_command("checkjob -v $job_id");
    191     my $response = join "\n", @$response_array;
    192 
    193     if ($response =~ /State: Running/) {
    194         return(0,"Running");
    195     }
    196     elsif ($response =~ /State: Completed/) {
    197         return(1,"Completed");
    198     }
    199     elsif ($response =~ /State: Idle/) {
    200         return(-2,"Idle");
    201     }
    202     else {
    203         my $response_word = $response;
    204         $response_word =~ s/.*State: //;
    205         $response_word =~ s/\n.*//;
    206         return(-1,$response_word);
    207     }
    208 }
    209 
    210 
     182# neb URI to (ipp_disk,remote_disk)
    211183sub uri_convert {
    212184    my $neb_uri = shift;
     
    215187
    216188    unless(defined($ipp_disk)) {
    217         my_die();
     189        &my_die("Failed to generate or find uri $neb_uri", $remote_id, $PS_EXIT_SYS_ERROR);
    218190    }
    219191
     
    225197}
    226198
    227 sub uri_to_outputs {
    228     my $neb_uri = shift;
    229     my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri );
    230 
    231 #    print TRANSFER "$ipp_disk\n";
    232 #    print CHECK    "$remote_disk\n";
    233     return($ipp_disk,$remote_disk);
    234 }
    235 
     199# neb URI to remote URI-on-disk
    236200sub uri_local_to_remote {
    237201    # This needs to replace the nebulous tag with the remote root.
     
    245209}
    246210
    247 sub uri_remote_to_local {
    248     # This needs to replace the remote root directory with the nebulous tag.
    249     my $remote_uri = shift;
    250     $remote_uri =~ s%${remote_root}%%;
    251     my $local_uri  = "neb:///" . $remote_uri;
    252 
    253     return($local_uri);
    254 }
    255 
    256 sub drop_component {
    257     my $remote_id = shift;
    258     my $cmd = shift;
    259     my $file = shift;
    260 
    261     if ($cmd eq '') {
    262         # Zero byte file.  This dbinfo was never constructed properly.
    263 
    264         # Steal the stage_id from the filename.  This isn't something I'm happy about.
    265         my $stage = $runData->{stage};
    266         my $stage_id = $file;
    267         if ($stage eq 'chip') {
    268             $stage_id =~ s/^.*ch\.//;
    269         }
    270         elsif ($stage eq 'camera') {
    271             $stage_id =~ s/^.*cm\.//;
    272         }
    273         elsif ($stage eq 'warp') {
    274             $stage_id =~ s/^.*wrp\.//;
    275         }
    276         elsif ($stage eq 'stack') {
    277             $stage_id =~ s/^.*stk\.//;
    278         }
    279         $stage_id =~ s/\..*$//;
    280 
    281         # Drop this from the database
    282         my $drop_cmd = "$remotetool -dropcomponent -remote_id $remote_id -stage_id $stage_id ";
    283         $drop_cmd   .= " -dbname $dbname " if defined($dbname);
    284         system($drop_cmd);
    285     }
    286 
    287 }
    288 
    289211sub my_die {
    290212    my $msg = shift;
  • tags/ipp-pv3-20140717/ippScripts/scripts/sc_remote_poll.pl

    r37288 r37298  
    3535# tools
    3636my $missing_tools;
    37 my $ssh        = can_run('ssh')  or (warn "Can't find ssh" and $missing_tools = 1);
    38 my $scp        = can_run('scp')  or (warn "Can't find scp" and $missing_tools = 1);
     37my $ssh        = can_run('ssh')        or (warn "Can't find ssh" and $missing_tools = 1);
     38my $scp        = can_run('scp')        or (warn "Can't find scp" and $missing_tools = 1);
    3939my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1);
     40my $chiptool   = can_run('chiptool')   or (warn "Can't find chiptool" and $missing_tools = 1);
    4041
    4142if ($missing_tools) {
     
    4546
    4647# Options
    47 my ($remote_id,$path_base,$policy,$poll,$force,$job_id,$dbname,$verbose,$no_update,$camera);
    48 $force = 0;
     48my ($remote_id,$path_base,$skip_poll,$skip_transfer,$job_id,$dbname,$retry,$verbose,$no_update,$camera);
    4949$verbose = 0;
    5050GetOptions(
     
    5252    'job_id=s'      => \$job_id,
    5353    'path_base=s'   => \$path_base,
    54     'policy=s'      => \$policy,
    55     'poll'          => \$poll,
    56     'force-poll'    => \$force,
     54    'skip_poll'     => \$skip_poll,
     55    'skip_transfer' => \$skip_transfer,
    5756    'camera=s'      => \$camera,
    5857    'dbname=s'      => \$dbname,
     58    'retry'         => \$retry,
    5959    'verbose'       => \$verbose,
    6060    'no_update'     => \$no_update,
     
    7878# STEP 2: Grab the information about this run;
    7979my $runData;
    80 { 
     80{
    8181    my $command = "$remotetool -listrun -remote_id $remote_id ";
    8282    $command   .= " -dbname $dbname " if defined($dbname);
    8383
    8484    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    85         run(command => $command, verbose => $verbose);
     85        run(command => $command, verbose => $verbose);
    8686
    8787    unless ($success) {
    88         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    89         &my_die("Unable to run remotetool to determine remote run status", $remote_id, $error_code);
     88        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     89        &my_die("Unable to run remotetool to determine remote run status", $remote_id, $error_code);
    9090    }
    9191
     
    101101my $poll_word  = "nothing";
    102102
    103 ($poll_response,$poll_word) = poll_job($job_id);
    104 
    105 if ($poll_response == -1) { # This job has an error
    106     print "The job exited incorrectly: $remote_id $job_id $poll_word $poll_response.\n";
    107     # warn("The job exited incorrectly: $remote_id $job_id $poll_word.");
    108     exit (2);
    109 }
    110 
    111 if ($poll_response != 1) { # This job has NOT completed
    112     print "The job has not exited at LANL: $remote_id $job_id $poll_word $poll_response.\n";
    113     exit (2);
     103if ($skip_poll) {
     104    $poll_word  = "Completed";
     105} else {
     106    ($poll_response,$poll_word) = poll_job($job_id);
     107
     108    if ($poll_response == -1) { # This job has an error
     109        print "The job exited incorrectly: $remote_id $job_id $poll_word $poll_response.\n";
     110        # warn("The job exited incorrectly: $remote_id $job_id $poll_word.");
     111        exit (2);
     112    }
     113
     114    if ($poll_response != 1) { # This job has NOT completed
     115        print "The job has not exited at LANL: $remote_id $job_id $poll_word $poll_response.\n";
     116        exit (2);
     117    }
    114118}
    115119
    116120my $remote_path = uri_local_to_remote($path_base);
    117121
    118 # transfer tool should check the existence of files on the remote end
    119 # and only return those that exist
    120 {
     122# STEP 4: transfer back the files.  Transfer tool should check the
     123# existence of files on the remote end and only return those that
     124# exist
     125unless ($skip_transfer) {
    121126    my $offset = 0;  # Offset to start from.
    122127    my $iter = 0;
     
    136141print STDERR "rsync of all files is complete, checking the results\n";
    137142
    138 # grab the .stats file
    139 
    140 my $uri_stats    = $path_base . ".stats";
    141 my $disk_stats   = $ipprc->file_resolve($uri_stats);
     143# STEP 5: grab the .stat file from LANL (this file is first constructed at LANL)
     144
     145my $uri_stats    = $path_base . ".stat";
     146my $disk_stats   = $ipprc->file_resolve($uri_stats, 1);
    142147my $remote_stats = uri_local_to_remote($uri_stats);
    143148
    144149scp_get($remote_stats,$disk_stats);
    145150
    146 # check for PASS / PART / FAIL : if dbinfo is PASS, go ahead and execute that. 
     151# STEP 6: check dbinfo files for PASS / PART / FAIL
     152
     153my %stage_pass = ();
     154my %stage_fail = ();
     155my %stage_part = ();
    147156
    148157my $Npass = 0;
     
    151160my @dbinfo_files   = ();
    152161open (STATFILE, "$disk_stats") || &my_die("Couldn't open file? $disk_stats", $remote_id, $PS_EXIT_SYS_ERROR);
    153 while (my $line = <RETURN>) {
     162while (my $line = <STATFILE>) {
    154163    chomp $line;
    155     unless ($_ =~ /dbinfo/) { next; }
     164    unless ($line =~ /dbinfo/) { next; }
    156165
    157166    my @words = split (" ", $line);
     167
     168    my ($stage_id, $class_id) = get_stage_id_from_dbinfo ($words[0]);
     169
    158170    if ($words[1] eq "PASS") {
    159171        push @dbinfo_files, $words[0];
    160         $Npass ++;
     172        $stage_pass{$stage_id} = 1;
     173        $Npass ++;
    161174    } elsif ($words[1] eq "FAIL") {
    162         $Nfail ++;
     175        $stage_fail{$stage_id} = 1;
     176        $Nfail ++;
    163177    } elsif ($words[1] eq "PART") {
    164         $Npart ++;
    165     }
    166 }
    167 close(RETURN);
     178        $stage_part{$stage_id} = 1;
     179        $Npart ++;
     180    }
     181}
     182close (STATFILE);
    168183print STDERR "dbinfo files: $Npass PASS, $Nfail FAIL, $Npart PART\n";
    169184
     185# STEP 7: if dbinfo is PASS, execute it (fail ones that are not PASS?).
    170186foreach my $file (@dbinfo_files) {
    171187    open(DBF,"$file") || warn "Missing file $file\n";
     
    176192    $cmd =~ s/-/ -/g; # This is just a safety check for missing space.
    177193
    178     if ($cmd == "") {
    179         print STDERR "problem: empty dbinfo file\n";
    180         next;
    181     }
    182 
    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.
    187         # Now we're going to drop the component that owns this dbinfo, which should force a retry.
    188         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    189         warn("The command that shouldn't fail has failed: $file $cmd $remote_id $error_code");
    190         if ($poll_word ne 'Completed') {  # If the job claims it completed, then we're fighting the network.
    191             fail_component($remote_id, $cmd, $file);
    192         }
    193     }
    194 
     194    if ($cmd eq "") {
     195        print STDERR "problem: empty dbinfo file\n";
     196        exit (1);
     197        next;
     198    }
     199
     200    print "dbinfo: $file\n";
     201
     202    if ($retry) {
     203        # use the dbinfo filename to get stage id, check if we have already updated this entry:
     204        my ($stage_id, $class_id) = get_stage_id_from_dbinfo ($file);
     205
     206        # we just need to check for the existence of an entry:
     207        if ($runData->{stage} eq "chip") {
     208            my $cmd1 = "$chiptool -simple -processedimfile -chip_id $stage_id -class_id $class_id";
     209            $cmd1   .= " -dbname $dbname " if defined($dbname);
     210
     211            my ( $success1, $error_code1, $full_buf1, $stdout_buf1, $stderr_buf1 ) =
     212                run(command => $cmd1, verbose => 0);
     213
     214            unless ($success1) {
     215                $error_code1 = (($error_code1 >> 8) or $PS_EXIT_PROG_ERROR);
     216                &my_die("Unable to run chiptool to check on results", $remote_id, $error_code1);
     217            }
     218
     219            my $Nrows = @$stdout_buf1;
     220            if ($Nrows > 0) {
     221                print STDERR "already updated: $stage_id, $class_id\n";
     222                next;
     223            }
     224        } else {
     225            print STDERR "do not know how to handle stage $runData->{stage}\n";
     226            exit (3);
     227        }
     228    }
     229
     230    unless ($no_update) {
     231        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     232            run(command => $cmd, verbose => $verbose);
     233        unless ($success) {
     234            # This shouldn't fail, but we also can't suddenly abort if something does fail.
     235            # Now we're going to drop the component that owns this dbinfo, which should force a retry.
     236            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     237            warn("The command that shouldn't fail has failed: $file $cmd $remote_id $error_code");
     238            my ($stage_id, $class_id) = get_stage_id_from_dbinfo ($file);
     239            $stage_fail{$stage_id} = 1;
     240        }
     241    }
     242}
     243print STDERR "dbinfo files all run (or skipped)\n";
     244
     245# STEP 8: unify the stage states and update the remoteComponent entries
     246foreach my $entry (keys (%stage_fail)) {
     247    $stage_pass{$entry} = 0;
     248}
     249foreach my $entry (keys (%stage_part)) {
     250    $stage_pass{$entry} = 0;
     251}
     252foreach my $entry (keys (%stage_pass)) {
     253    my $cmd = "remotetool -updatecomponent -remote_id $remote_id -stage_id $entry";
     254    $cmd   .= " -dbname $dbname " if defined($dbname);
     255    if ($stage_pass{$entry}) {
     256        $cmd .= " -set_state pass";
     257    } else {
     258        $cmd .= " -set_state fail";
     259    }
     260
     261    unless ($no_update) {
     262        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     263            run(command => $cmd, verbose => $verbose);
     264        unless ($success) {
     265            &my_die("Unable to run remotetool to determine remote run status", $remote_id);
     266        }
     267    } else {
     268        print STDERR "no_update: $cmd\n";
     269    }
    195270}
    196271
     
    223298    unless ($success) {
    224299        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    225         &my_die();
     300        &my_die("Failed to send file $file to LANL", $remote_id, $PS_EXIT_SYS_ERROR);
    226301    }
    227302}
     
    237312    unless ($success) {
    238313        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    239         &my_die();
     314        &my_die("Failed to get file $file from LANL", $remote_id, $PS_EXIT_SYS_ERROR);
    240315    }
    241316}
     
    243318sub ssh_exec_command {
    244319    my $cmd = shift;
    245     $cmd = "$ssh $DMZ_HOST ssh  ${SEC_HOST} $cmd";
     320    $cmd = "$ssh -n $DMZ_HOST ssh  ${SEC_HOST} $cmd";
    246321    print "EXEC: $cmd\n";
    247322    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    251326        # If we failed, see if we failed due to authorization.
    252327        check_ssh_connection();
    253         &my_die("Failed to execute command: >>$cmd<<");
     328        &my_die("Failed to execute command: >>$cmd<<", $remote_id, $PS_EXIT_SYS_ERROR);
    254329    }
    255330    return ($stdout_buf);
     
    285360
    286361    unless(defined($ipp_disk)) {
    287         my_die();
     362        &my_die("Failed to generate or find uri $neb_uri", $remote_id, $PS_EXIT_SYS_ERROR);
    288363    }
    289364
     
    324399}
    325400
     401# assumes $runData->{stage} exists
     402sub get_stage_id_from_dbinfo {
     403    my $file = shift;
     404
     405    my $stage_id = 0;
     406    my $class_id = 0;
     407
     408    # Steal the stage_id from the filename.  This isn't something I'm happy about.
     409    my $stage = $runData->{stage};
     410    if ($stage eq 'chip') {
     411        ($stage_id, $class_id) = $file =~ /ch\.(\d*).(XY\d\d).dbinfo/;
     412    }
     413    elsif ($stage eq 'camera') {
     414        $stage_id =~ s/^.*cm\.//;
     415        $class_id = 0;
     416    }
     417    elsif ($stage eq 'warp') {
     418        $stage_id =~ s/^.*wrp\.//;
     419        $class_id = 0;
     420    }
     421    elsif ($stage eq 'stack') {
     422        $stage_id =~ s/^.*stk\.//;
     423        $class_id = 0;
     424    }
     425
     426    return ($stage_id, $class_id);
     427}
     428
    326429sub fail_component {
    327430    my $remote_id = shift;
     
    333436    my $stage_id = $file;
    334437    if ($stage eq 'chip') {
    335         $stage_id =~ s/^.*ch\.//;
     438        $stage_id =~ s/^.*ch\.//;
    336439    }
    337440    elsif ($stage eq 'camera') {
    338         $stage_id =~ s/^.*cm\.//;
     441        $stage_id =~ s/^.*cm\.//;
    339442    }
    340443    elsif ($stage eq 'warp') {
    341         $stage_id =~ s/^.*wrp\.//;
     444        $stage_id =~ s/^.*wrp\.//;
    342445    }
    343446    elsif ($stage eq 'stack') {
    344         $stage_id =~ s/^.*stk\.//;
     447        $stage_id =~ s/^.*stk\.//;
    345448    }
    346449    $stage_id =~ s/\..*$//;
    347    
     450
    348451    print STDERR "failed component: $remote_id, $stage_id\n";
    349    
     452
    350453    # Drop this from the database
    351454    ## my $drop_cmd = "$remotetool -dropcomponent -remote_id $remote_id -stage_id $stage_id ";
     
    400503        my $command = "$remotetool -updaterun -remote_id $id";
    401504        $command .= " -fault $exit_code " if defined $exit_code;
    402         $command .= " -job_id $job_id " if defined $jobid;
    403505        $command .= " -set_state $exit_state " if defined $exit_state;
    404506        $command .= " -dbname $dbname " if defined $dbname;
  • tags/ipp-pv3-20140717/ippScripts/scripts/sc_transfer_tool.pl

    r37287 r37298  
    102102}
    103103
    104 my $stat_file = "$input_path.stat";
    105 print "STATFILE: $stat_file\n";
    106 open (STATFILE, ">$stat_file");
     104unless ($fetch) {
     105    my $stat_file = "$input_path.stat";
     106    print "STATFILE: $stat_file\n";
     107    open (STATFILE, ">$stat_file");
     108}
    107109
    108110$i = 0;
     
    116118    if ($line < $offset) { next; } # I think this is off-by-one in a safe direction
    117119
    118     if ($line % 250 == 0)  { print "line $line : $Lname\n"; }
     120    if ($line % 250 == 0)  { print STDERR "line $line : $Lname\n"; }
    119121
    120122    $i = int(rand($#filehandles + 1));
    121    
     123    if ($i >= $threads) {
     124        print STDERR "HUH: impossible file handle?\n";
     125        die;
     126    }
     127
    122128    # if we are fetching, and 'quickfetch' is requested, skip file if it exists
    123129    # NOTE: this does not check that the transfer was complete or the file is current
     
    129135    } else {
    130136        # We are pushing, but only send back files we actually have
    131         if (-e $Lname) {
     137        # we cannot have the remote file unless the local file exists
     138        # (it is a link to the local file and is generated after the local file)
     139        my $haveRemote = -e "$local_tmp/$Rname";
     140        if ($haveRemote) {
    132141            print { $filehandles[$i] } "$Rname\n";
    133142            print STATFILE "$Rname PASS\n";
    134143        } else {
    135             print STATFILE "$Rname FAIL\n";
     144            my $haveLocal = -e $Lname;
     145            if ($haveLocal) {
     146                print STATFILE "$Rname PART\n";
     147            } else {
     148                print STATFILE "$Rname FAIL\n";
     149            }
    136150        }
    137151    }
     
    139153close(LOCAL);
    140154close(REMOTE);
    141 close(STATFILE);
     155unless ($fetch) { close(STATFILE); }
    142156
    143157for ($i = 0; $i < $threads; $i++) {
Note: See TracChangeset for help on using the changeset viewer.