IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36844 for trunk/ippScripts


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

These have been tested and seem to work correctly.

Location:
trunk/ippScripts/scripts
Files:
4 added
2 edited

Legend:

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

    r36596 r36844  
    1919# Hard coded values
    2020my $remote_root   = '/scratch3/watersc1/';  # Far side destination base location
     21my $remote_raw    = "${remote_root}/raw/";  # Directory to find raw data in.
    2122my $threads       = 2;                      # How many threads are we going to use?
    2223my $job_cost      = 150 / 60 / 60;          # Estimate of how long a job runs, in hours.
     
    150151#print Dumper(%detrends);
    151152
     153my @return_component_list = ("DBINFO.IMFILE","PPIMAGE.STATS","LOG.IMFILE","TRACE.IMFILE","PPIMAGE.BACKMDL","PPIMAGE.PATTERN");
    152154
    153155#
     
    157159my $uri_check   = $path_base . ".check";
    158160my $uri_config  = $path_base . ".config";
     161my $uri_generate= $path_base . ".generate";
     162my $uri_return  = $path_base . ".return";
    159163
    160164my $disk_command = $ipprc->file_resolve($uri_command,1);
     
    162166my $disk_check   = $ipprc->file_resolve($uri_check,1);
    163167my $disk_config  = $ipprc->file_resolve($uri_config,1);
     168my $disk_generate= $ipprc->file_resolve($uri_generate,1);
     169my $disk_return  = $ipprc->file_resolve($uri_return,1);
    164170
    165171my (undef, $remote_config) = uri_convert($uri_config); # Needs to be done after we've created it.
     
    168174open(CHECK,    ">$disk_check")  || &my_die("Couldn't open file? $disk_check",$chip_id,$PS_EXIT_SYS_ERROR);
    169175open(CONFIG,   ">$disk_config")  || &my_die("Couldn't open file? $disk_config",$chip_id,$PS_EXIT_SYS_ERROR);
     176open(GENERATE, ">$disk_generate") || &my_die("Couldn't open file? $disk_generate",$chip_id,$PS_EXIT_SYS_ERROR);
     177open(RETURN,   ">$disk_return") || &my_die("Couldn't open file? $disk_return", $chip_id, $PS_EXIT_SYS_ERROR);
     178
    170179
    171180#
     
    185194   
    186195    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    187         run(command => $command, verbose => $verbose);
     196        run(command => $command, verbose => 0);
    188197    unless ($success) {
    189198        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     
    254263   
    255264    my $chipData = $mdcParser->parse(join "", @$stdout_buf) or
    256         &my_die("Unable to parse chiptool -pendingimfile information.",
    257                 $chip_id,$error_code);
     265        next;
     266#       &my_die("Unable to parse chiptool -pendingimfile information.",
     267#               $chip_id,$error_code);
    258268    my $chipData2= parse_md_list($chipData);
    259269
     
    270280       
    271281        # Process the image and burntool table
    272         my (undef,$remote_uri) = uri_to_outputs($uri);
     282        my ($ipp_uri,$remote_uri) = uri_to_outputs_raw($uri);
    273283        my $btt = $uri;
    274284        $btt =~ s/fits$/burn.tbl/;
    275         my (undef,$remote_btt) = uri_to_outputs($btt);
     285        my ($ipp_btt,$remote_btt) = uri_to_outputs_raw($btt);
    276286       
    277287        # Initialize the ppI command
     
    287297            my $det_code = $det_types{$det};
    288298            my $duri = $detrends_to_use{$det}->{$class_id};
    289             my (undef, $remote_det_uri) = uri_to_outputs($duri);
     299            my ($ipp_det_uri, $remote_det_uri) = uri_to_outputs_raw($duri);
    290300            $ppImage_command .= " $det_code $remote_det_uri ";
    291301        }
     
    310320        $ppImage_command .= " -log ${remote_outroot}.${class_id}.log ";
    311321
    312         push @main_commands, $ppImage_command;
     322#       push @main_commands, $ppImage_command;
    313323
    314324        # Calculate pre and post commands
    315325        my $remote_outroot_dir = dirname($remote_outroot);
    316         push @pre_commands, "mkdir -p $remote_outroot_dir";
     326        my $pre_command = "mkdir -p $remote_outroot_dir";
    317327       
    318328        my $post_commandA = "chiptool -addprocessedimfile -exp_id $exp_id -chip_id $chip_id -class_id $class_id ";
     
    321331        $post_commandA   .= " -dbname $dbname " if defined $dbname;
    322332
    323         my $post_commandB = "echo -n $post_commandA > ${remote_outroot}.${class_id}.dbinfo && ";
     333        my $post_commandB = "echo -n \"$post_commandA\" > ${remote_outroot}.${class_id}.dbinfo ";
    324334        my $post_commandC = "ppStatsFromMetadata ${remote_outroot}.${class_id}.stats - CHIP_IMFILE >> ${remote_outroot}.${class_id}.dbinfo";
    325335       
    326         push @post_commands, "$post_commandB $post_commandC";
     336#       push @post_commands, "$post_commandB $post_commandC";
    327337
    328338        $job_index++;
     339
     340        print CONFIG "${pre_command} && ${ppImage_command} && ${post_commandB} && ${post_commandC}";
     341
     342
     343        # Determine which output files need to be returned.
     344        foreach my $component (@return_component_list) {
     345#           uri_convert_and_create( $ipprc->filename($component, $ipp_outroot, $class_id) );
     346            my $filename = $ipprc->filename($component, $ipp_outroot, $class_id);
     347            my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename );
     348            my $remote_outroot_dir = dirname($ipp_disk);
     349            print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} ";
     350#           print "  $filename $ipp_disk $remote_disk\n";
     351#           die;
     352        }
     353
     354        print CONFIG "\n";
    329355    }
    330356}
    331357
    332358# Actually put the commands into the output file.
    333 my %unique_cmds = ();
    334 foreach my $cmd (@pre_commands) {
    335     unless(exists($unique_cmds{$cmd})) {
    336         print CONFIG $cmd . "\n";
    337         $unique_cmds{$cmd} = 1;
    338     }
    339 }
    340 foreach my $cmd (@main_commands) {
    341     unless(exists($unique_cmds{$cmd})) {
    342         print CONFIG $cmd . "\n";
    343         $unique_cmds{$cmd} = 1;
    344     }
    345 }
    346 foreach my $cmd (@post_commands) {
    347     unless(exists($unique_cmds{$cmd})) {
    348         print CONFIG $cmd . "\n";
    349         $unique_cmds{$cmd} = 1;
    350     }
    351 }
     359# my %unique_cmds = ();
     360# foreach my $cmd (@pre_commands) {
     361#     unless(exists($unique_cmds{$cmd})) {
     362#       print CONFIG $cmd . "\n";
     363#       $unique_cmds{$cmd} = 1;
     364#     }
     365# }
     366# foreach my $cmd (@main_commands) {
     367#     unless(exists($unique_cmds{$cmd})) {
     368#       print CONFIG $cmd . "\n";
     369#       $unique_cmds{$cmd} = 1;
     370#     }
     371# }
     372# foreach my $cmd (@post_commands) {
     373#     unless(exists($unique_cmds{$cmd})) {
     374#       print CONFIG $cmd . "\n";
     375#       $unique_cmds{$cmd} = 1;
     376#     }
     377# }
    352378
    353379close(CONFIG);
    354380close(TRANSFER);
    355381close(CHECK);
     382close(RETURN);
     383close(GENERATE);
    356384
    357385#
     
    425453}
    426454
     455sub uri_convert_and_create {
     456    my $neb_uri = shift;
     457    my $ipp_disk= $ipprc->file_resolve( $neb_uri , 1);
     458    my $remote_disk = $ipp_disk;
     459   
     460    unless(defined($ipp_disk)) {
     461        my_die();
     462    }
     463
     464    $remote_disk =~ s%^.*/%%;   # Remove nebulous path
     465    $remote_disk =~ s%^\d+\.%%; # Remove ins_id
     466    $remote_disk =~ s%:%/%g;    # Replace colons with directories
     467    $remote_disk = "${remote_root}/${remote_disk}";
     468    return($ipp_disk,$remote_disk);
     469}
     470
    427471sub uri_to_outputs {
    428472    my $neb_uri = shift;
     
    433477        print TRANSFER "$ipp_disk\n";
    434478        print CHECK    "$remote_disk\n";
     479    }
     480    return($ipp_disk,$remote_disk);
     481}
     482
     483sub uri_to_outputs_raw {
     484    my $neb_uri = shift;
     485    my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri );
     486    $remote_disk = $remote_raw . $ipp_disk;
     487    unless (exists($file_filter{$neb_uri})) {
     488        $file_filter{$neb_uri} = 1;
     489        print TRANSFER "$ipp_disk\n";
     490        print CHECK    "$remote_disk\n";
     491    }
     492    return($ipp_disk,$remote_disk);
     493}
     494
     495sub uri_to_outputs_for_return {
     496    my $neb_uri = shift;
     497    my ($ipp_disk, $remote_disk) = uri_convert_and_create( $neb_uri );
     498    unless (exists($file_filter{$neb_uri})) {
     499        $file_filter{$neb_uri} = 1;
     500        print RETURN "$ipp_disk\n";
     501        print GENERATE "$remote_disk\n";
    435502    }
    436503    return($ipp_disk,$remote_disk);
  • 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.