IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 3, 2008, 9:37:51 AM (18 years ago)
Author:
bills
Message:

Various changes to allow processing of detectability query requests
by the postage stamp server request processor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/scripts/pstamp_parser_run.pl

    r16975 r17893  
    55###
    66
     7#XXX TODO: accept dbname save-temps and verbose as command line parameters
     8#XXX see notes about error handling
     9
    710use warnings;
    811use strict;
    912
    1013use Sys::Hostname;
    11 my $host = hostname();
    12 print "\n\n";
    13 print "Starting script $0 on $host\n\n";
     14
     15my $verbose = 1;
     16if ($verbose) {
     17    my $host = hostname();
     18    print "\n\n";
     19    print "Starting script $0 on $host\n\n";
     20}
    1421
    1522if (@ARGV != 1) {
     
    1825
    1926my $request_id = $ARGV[0];
    20 
    2127
    2228use IPC::Cmd 0.36 qw( can_run run );
     
    5763my $pstamptool  = can_run('pstamptool')  or (warn "Can't find pstamptool"  and $missing_tools = 1);
    5864my $pstampparse = can_run('pstampparse') or (warn "Can't find pstampparse" and $missing_tools = 1);
     65my $dqueryparse = can_run('dqueryparse.pl') or (warn "Can't find dqueryparse.pl" and $missing_tools = 1);
    5966my $dsget = can_run('dsget') or (warn "Can't find dsget" and $missing_tools = 1);
    6067
     
    7178    my $command = "$pstamptool -pendingreq -req_id $request_id";
    7279    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    73         run(command => $command, verbose => 1);
     80        run(command => $command, verbose => $verbose);
    7481    unless ($success) {
    7582        die("Unable to perform $command error code: $error_code");
     
    8592    my $requests = parse_md_list($metadata);
    8693
    87     $psrequest = ${@$requests}[0];
     94    # TODO: We are assuming that we get an array of length 1 (or zero)
     95    # should we fail if we get more?
     96    #$psrequest = ${@$requests}[0];
     97    $psrequest = $requests->[0];
    8898}
    8999
     
    112122        my $command = "$dsget --uri $uri --filename $new_uri";
    113123        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    114             run(command => $command, verbose => 1);
     124            run(command => $command, verbose => $verbose);
    115125        unless ($success) {
    116126            die("Unable to perform $command error code: $error_code");
     
    121131}
    122132
    123 create the output diredtory
     133find the name of the output directory
    124134my $outdir;
    125135if ($ds_id) {
    126136    my $command = "$pstamptool -datastore -ds_id $ds_id";
    127137    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    128         run(command => $command, verbose => 1);
     138        run(command => $command, verbose => $verbose);
    129139    unless ($success) {
    130140        die("Unable to perform $command error code: $error_code");
     
    140150    my $dataStores = parse_md_list($metadata);
    141151
    142     my $dataStore = ${@$dataStores}[0];
     152    my $dataStore = $dataStores->[0];
    143153
    144154    $outdir = "$outputDataStoreRoot/$psrequest->{outFileset}";
     
    147157}
    148158
     159#  create the output directory
    149160if (! -e $outdir ) {
    150161    mkdir $outdir or die("unable to create output directory $outdir");
     
    153164}
    154165
    155 # run pstampparse to parse the queue the jobs for this request
     166# run the appropriate parse command to parse the queue the jobs for this request
     167# first check the extension header to find the EXTNAME
     168my $request_type = find_request_type($uri);
     169
     170print STDERR "request_type is $request_type\n" if $verbose;
     171
     172my $parse_cmd;
     173if ($request_type eq "PS1_PS_REQUEST") {
     174    $parse_cmd = $pstampparse . " -mode queue_job -req_id $request_id -out_dir $outdir $uri";
     175} elsif ($request_type eq "MOPS_DETECTABILITY_QUERY") {
     176    $parse_cmd = $dqueryparse  . " --mode queue_job --req_id $request_id --out_dir $outdir --uri $uri";
     177}
     178
     179if (!$parse_cmd) {
     180    # XXX TODO mark the error state for the job and set it to stop
     181    die "null request type found in $uri" if !$request_type;
     182    die "unknown request type $request_type found in $uri";
     183}
     184
    156185{
    157     my $command = "$pstampparse -mode queue_job -req_id $request_id -out_dir $outdir $uri";
    158     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    159         run(command => $command, verbose => 1);
    160     unless ($success) {
    161 #        die("Unable to perform $command error code: $error_code");
     186    my $command = "$parse_cmd";
     187    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     188        run(command => $command, verbose => $verbose);
     189    unless ($success) {
    162190        if (!open OUT, ">$outdir/parse_error") {
    163191            die("unable to open parse_error file $outdir/parse_error");
     
    167195    }
    168196}
    169 
    170197# XXX make sure that a job got actually got queued. If not set the request result and set state to
    171198# run so that the "request finisher" can build the results file.
     
    177204    my $command = "$pstamptool -processedreq -req_id $request_id -state run";
    178205    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    179         run(command => $command, verbose => 1);
     206        run(command => $command, verbose => $verbose);
    180207    unless ($success) {
    181208        die("Unable to perform $command error code: $error_code");
     
    184211
    185212exit 0;
     213
     214sub find_request_type {
     215    # find the EXTNAME in the input fits table
     216    # TODO: do this right handling errors etc.
     217    my $file_name = shift;
     218    my $out = `echo $file_name | fields -x 0 EXTNAME`;
     219
     220    # output from fields is filename value
     221    my ($dummy, $extname) = split " ", $out;
     222
     223    return $extname;
     224}
Note: See TracChangeset for help on using the changeset viewer.