IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18539


Ignore:
Timestamp:
Jul 15, 2008, 10:02:24 AM (18 years ago)
Author:
bills
Message:

Significant changes to how requests flow through the system. Improved
fault handling and reporting.

File:
1 edited

Legend:

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

    r18380 r18539  
    22###
    33### pstampparser_run.pl
    4 ###     Run the postage stamp request parser for a given request id
     4###     Run the request parser for a given request id
    55###
    66
     
    1515my $verbose;
    1616my $dbname;
    17 my $request_id;
     17my $req_id;
    1818
    1919GetOptions(
    2020    'verbose'   =>  \$verbose,
    21     'dbname=s'    =>  \$dbname,
    22     'req_id=s'  =>  \$request_id,
     21    'dbname=s'  =>  \$dbname,
     22    'req_id=s'  =>  \$req_id,
    2323);
    2424
     
    2929}
    3030
    31 die "req_id is required" if !defined($request_id);
     31die "req_id is required" if !defined($req_id);
    3232
    3333use IPC::Cmd 0.36 qw( can_run run );
     
    5151my $ipprc = PS::IPP::Config->new(); # IPP Configuration
    5252
    53 #my $outputDataStoreRoot = "/var/www/html/ds/dsroot";
    54 
    55 my $outputDataStoreRoot = metadataLookupStr($ipprc->{_siteConfig}, 'PSTAMP_DATA_STORE_ROOT');
    56 exit ($PS_EXIT_CONFIG_ERROR) unless defined $outputDataStoreRoot;
     53my $outputDataStoreRoot = metadataLookupStr($ipprc->{_siteConfig}, 'DATA_STORE_ROOT');
     54exit ($PS_EXIT_CONFIG_ERROR) unless defined $outputDataStoreRoot; # lookup failure outputs a message
    5755my $defaultOutputRoot = $outputDataStoreRoot;
    5856
    59 
    60 #my $inputWorkdir = "/export/data1/bills/pstamp/work/$request_id";
    61 
    62 my $inputWorkdir = metadataLookupStr($ipprc->{_siteConfig}, 'PSTAMP_WORKDIR');
    63 exit ($PS_EXIT_CONFIG_ERROR) unless defined $inputWorkdir;
    64 $inputWorkdir .= "/$request_id";
     57my $pstamp_workdir = metadataLookupStr($ipprc->{_siteConfig}, 'PSTAMP_WORKDIR');
     58exit ($PS_EXIT_CONFIG_ERROR) unless defined $pstamp_workdir; # lookup failure outputs a message
     59
     60# workdir is where we download request files to and place any error output from the parser
     61# NOTE: this location needs to be kept in sync with the web interface ( request.php )
     62my $workdir = "$pstamp_workdir/$req_id";
     63
     64if (! -e $workdir ) {
     65    mkdir $workdir or die "failed to create working directory $workdir for request id $req_id";
     66}
     67
     68my $defaultDSProduct = metadataLookupStr($ipprc->{_siteConfig}, 'PSTAMP_DATA_STORE_PRODUCT');
     69exit ($PS_EXIT_CONFIG_ERROR) unless defined $defaultDSProduct;
    6570   
    6671my $missing_tools;
     
    8186#Look up the uri for the given request
    8287{
    83     my $command = "$pstamptool -pendingreq -req_id $request_id";
     88    my $command = "$pstamptool -pendingreq -req_id $req_id";
    8489    $command .= " -dbname $dbname" if $dbname;
    8590    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    9095
    9196    if (@$stdout_buf == 0) {
    92         print STDERR "pending pstamp request id $request_id not found\n";
     97        print STDERR "pending pstamp request id $req_id not found\n";
    9398        exit 1;
    9499    }
     
    98103    my $requests = parse_md_list($metadata);
    99104
    100     # TODO: We are assuming that we get an array of length 1 (or zero)
    101     # should we fail if we get more?
    102     #$psrequest = ${@$requests}[0];
     105    my $num = @$requests;
     106    die "unexpected number of requests $num found" if $num > 1;
     107
    103108    $psrequest = $requests->[0];
    104109}
    105110
    106111if (!$psrequest) {
    107     print STDERR "postage stamp request $request_id not found\n";
    108     # TODO: is this always an error, what if the request is no longer pending?
     112    print STDERR "pending postage stamp request $req_id not found\n";
    109113    exit 1;
    110114}
     
    112116my $uri = $psrequest->{uri};
    113117
    114 # if the uri is remote, download it
    115 # XXX how can we tell?
    116 # perhaps assume remote if the uri begins with http:
    117 # or perhaps assume it is remote if it doesn't begin with '/' or path://
    118 # actually since we're using dsget which is an http program the former is the
    119 # way to go. Now it's easier than that, we can assume that dsget is needed if
    120 # request->{ds_id} != 0
     118# if the uri is from a data store, download it
    121119
    122120my $ds_id = $psrequest->{ds_id};
    123121
     122my $new_uri;
    124123if ($ds_id) {
    125     mkdir $inputWorkdir;
    126124    {
    127         my $new_uri = "$inputWorkdir/request.fits";
     125        $new_uri = "$workdir/request.fits";
    128126        my $command = "$dsget --uri $uri --filename $new_uri";
    129127        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    138136
    139137#  find the name of the output directory
    140 my $outdir;
     138my $product;
    141139if ($ds_id) {
    142140    my $command = "$pstamptool -datastore -ds_id $ds_id";
     
    159157    my $dataStore = $dataStores->[0];
    160158
    161     $outdir = "$outputDataStoreRoot/$psrequest->{outFileset}";
     159    $product = $dataStore->{outProduct};
    162160} else {
    163     $outdir = "$defaultOutputRoot/$psrequest->{outFileset}";
    164 }
    165 
    166 #  create the output directory
    167 if (! -e $outdir ) {
    168     mkdir $outdir or die("unable to create output directory $outdir");
    169 } elsif (! -d $outdir) {
    170     die("file with name of output directory $outdir exists but is not a directory");
    171 }
     161    $product = $defaultDSProduct;
     162}
     163
     164#
     165# Here is one of the places that we assume that the output for a request goes directly into
     166# the output fileset directory in the data store.
     167#
     168my $outProductDir = "$outputDataStoreRoot/$product";
     169
     170die "output product directory $outProductDir does not exist" if (! -e $outProductDir) ;
     171die "file with name of output product directory $outProductDir exists but is not a directory"
     172    if (! -d $outProductDir);
     173
    172174
    173175# run the appropriate parse command to parse the queue the jobs for this request
     
    175177my $request_type = find_request_type($uri);
    176178
    177 print STDERR "request_type is $request_type\n" if $verbose;
     179print STDERR "request_type for $req_id is $request_type\n" if $verbose;
    178180
    179181my $parse_cmd;
     182my $reqType;    # for the database
    180183if ($request_type eq "PS1_PS_REQUEST") {
    181     $parse_cmd = $pstampparse . " -mode queue_job -req_id $request_id -out_dir $outdir -file $uri";
    182     $parse_cmd .= " -dbname $dbname" if $dbname;
     184    $reqType = 'pstamp';
     185    $parse_cmd = $pstampparse . " --mode queue_job --req_id $req_id --product $product --out_dir $outProductDir --file $uri";
     186    $parse_cmd .= " --dbname $dbname" if $dbname;
    183187} elsif ($request_type eq "MOPS_DETECTABILITY_QUERY") {
    184     $parse_cmd = $dqueryparse  . " --mode queue_job --req_id $request_id --out_dir $outdir --uri $uri";
     188    $reqType = 'dquery';
     189    $parse_cmd = $dqueryparse  . " --mode queue_job --req_id $req_id --out_dir $outProductDir --uri $uri";
    185190}
    186191
     
    191196}
    192197
     198my $fault;
    193199{
     200    my $error_file_name = "$workdir/parse_error.txt";
     201    # get rid of any error file from previous run
     202    unlink $error_file_name if (-e $error_file_name);
     203
    194204    my $command = "$parse_cmd";
    195205    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    196206        run(command => $command, verbose => $verbose);
    197     unless ($success) {
    198         if (!open OUT, ">$outdir/parse_error") {
    199             die("unable to open parse_error file $outdir/parse_error");
     207
     208    # save the contents of stderr (if any) to a file. This is relevant if
     209    # the file parsed properl but one of the rows in the request file generated an error
     210    my $errbuf = join "", @$stderr_buf;
     211    if ($errbuf) {
     212        if (!open OUT, ">$error_file_name") {
     213            die("unable to open parse_error file $error_file_name");
    200214        }
    201         print OUT "@$stderr_buf";
     215        print OUT "$errbuf";
    202216        close(OUT);
    203     }
    204 }
    205 
    206 # XXX make sure that a job got actually got queued.
    207 # If not set the request result and set state to
    208 # run so that the "request finisher" can build the results file.
    209 
    210 #
    211 # update the state of this request from 'new' to 'run'
     217        print STDERR $errbuf if $verbose;
     218    }
     219
     220    unless ($success) {
     221        $fault = $error_code >> 8;
     222    }
     223}
     224
     225#
     226# update the state of this request from 'new' to 'run' and set the uri to the downloaded location
    212227#
    213228{
    214     my $command = "$pstamptool -processedreq -req_id $request_id -state run";
    215     $command .= " -dbname $dbname" if $dbname;
     229    my $command = "$pstamptool -processedreq -req_id $req_id -state run";
     230    $command   .= " -reqType $reqType" if $reqType;
     231    $command   .= " -uri $new_uri" if $new_uri;
     232    $command   .= " -fault $fault" if $fault;
     233    $command   .= " -dbname $dbname" if $dbname;
    216234    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    217235        run(command => $command, verbose => $verbose);
     
    220238    }
    221239}
     240
     241# Note: We do not return $fault here. If there was a fatal error we've already exited.
     242# If we got a fault it's due to bad input from the user we've set things up for this to be
     243# handled by the pstamp.request.finish
    222244
    223245exit 0;
Note: See TracChangeset for help on using the changeset viewer.