IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 6, 2009, 5:44:55 PM (17 years ago)
Author:
bills
Message:

Create stamps in workdir area instead of the data store product directory
various changes to improve logging

File:
1 edited

Legend:

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

    r21385 r21410  
    1212use Sys::Hostname;
    1313use Getopt::Long qw( GetOptions );
    14 
     14use File::Basename qw( basename dirname);
     15
     16my $req_id;
     17my $uri;
     18my $redirect_output;
     19my $product;
    1520my $verbose;
    1621my $dbname;
    17 my $req_id;
    1822
    1923GetOptions(
    20     'verbose'   =>  \$verbose,
    21     'dbname=s'  =>  \$dbname,
    22     'req_id=s'  =>  \$req_id,
     24    'req_id=s'          =>  \$req_id,
     25    'uri=s'             =>  \$uri,
     26    'product=s'         =>  \$product,
     27    'redirect-output'   =>  \$redirect_output,
     28    'verbose'           =>  \$verbose,
     29    'dbname=s'          =>  \$dbname,
    2330);
    2431
     
    2936}
    3037
    31 die "req_id is required" if !defined($req_id);
     38die "--req_id --uri --product are required"
     39    if !defined($req_id) or
     40       !defined($uri) or
     41       !defined($product);
    3242
    3343use IPC::Cmd 0.36 qw( can_run run );
     
    6676}
    6777
     78if ($redirect_output) {
     79    my $logDest = "$workdir/psparse.$req_id.log";
     80    $ipprc->redirect_output($logDest);
     81}
     82
    6883my $defaultDSProduct = metadataLookupStr($ipprc->{_siteConfig}, 'PSTAMP_DATA_STORE_PRODUCT');
    6984exit ($PS_EXIT_CONFIG_ERROR) unless defined $defaultDSProduct;
     
    8398my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    8499
    85 my $psrequest;
    86 #Look up the uri for the given request
    87 {
    88     my $command = "$pstamptool -pendingreq -req_id $req_id";
    89     $command .= " -dbname $dbname" if $dbname;
     100
     101my $fn = basename($uri);
     102my $new_uri = "$workdir/$fn";
     103if ($uri =~ /^http:/) {
     104    # if the uri is an http uri download the file
     105    my $command = "$dsget --uri $uri --filename $new_uri";
    90106    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    91107        run(command => $command, verbose => $verbose);
     
    93109        die("Unable to perform $command error code: $error_code");
    94110    }
    95 
    96     if (@$stdout_buf == 0) {
    97         print STDERR "pending pstamp request id $req_id not found\n";
    98         exit 1;
    99     }
    100     my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    101         die("Unable to parse metdata config doc");
    102 
    103     my $requests = parse_md_list($metadata);
    104 
    105     my $num = @$requests;
    106     die "unexpected number of requests $num found" if $num > 1;
    107 
    108     $psrequest = $requests->[0];
    109 }
    110 
    111 if (!$psrequest) {
    112     print STDERR "pending postage stamp request $req_id not found\n";
    113     exit 1;
    114 }
    115 
    116 my $uri = $psrequest->{uri};
    117 
    118 # if the uri is from a data store, download it
    119 
    120 my $ds_id = $psrequest->{ds_id};
    121 
    122 my $new_uri;
    123 if ($ds_id && ($uri =~ /^http:/)) {
    124     {
    125         $new_uri = "$workdir/request.fits";
    126         my $command = "$dsget --uri $uri --filename $new_uri";
    127         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    128             run(command => $command, verbose => $verbose);
    129         unless ($success) {
    130             die("Unable to perform $command error code: $error_code");
    131         }
    132 
    133         $uri = $new_uri;
    134     }
    135 }
    136 
    137 #  find the name of the output directory
    138 my $product;
    139 if ($ds_id) {
    140     my $command = "$pstamptool -datastore -ds_id $ds_id";
    141     $command .= " -dbname $dbname" if $dbname;
    142     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    143         run(command => $command, verbose => $verbose);
    144     unless ($success) {
    145         die("Unable to perform $command error code: $error_code");
    146     }
    147 
    148     if (@$stdout_buf == 0) {
    149         print STDERR "data store with data store id $ds_id not found\n";
    150         exit 1;
    151     }
    152     my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    153         die("Unable to parse metdata config doc");
    154 
    155     my $dataStores = parse_md_list($metadata);
    156 
    157     my $dataStore = $dataStores->[0];
    158 
    159     $product = $dataStore->{outProduct};
    160 } else {
     111} elsif ($uri ne $new_uri) {
     112    # put a link to the file into the workdir
     113    if (-e $new_uri) {
     114        unlink $new_uri or die "failed to unlink $new_uri";
     115    }
     116    if (! symlink $uri, $new_uri) {
     117        die ("failed to link request file $uri to workdir $workdir");
     118    }
     119}
     120$uri = $new_uri;
     121
     122die "request file $uri not found" if ! -e $uri;
     123
     124#  if product was not defined (in database), use the default
     125if ($product eq "NULL") {
    161126    $product = $defaultDSProduct;
    162127}
    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 #
    168 my $outProductDir = "$outputDataStoreRoot/$product";
    169 
    170 die "output product directory $outProductDir does not exist" if (! -e $outProductDir) ;
    171 die "file with name of output product directory $outProductDir exists but is not a directory"
    172     if (! -d $outProductDir);
    173128
    174129my $parse_cmd;
     
    220175}
    221176
    222 $parse_cmd .= " --mode queue_job --req_id $req_id --product $product --out_dir $outProductDir --file $uri";
     177$parse_cmd .= " --mode queue_job --req_id $req_id --product $product --out_dir $workdir --file $uri";
    223178$parse_cmd .= " --dbname $dbname" if $dbname;
     179$parse_cmd .= " --verbose" if $verbose;
    224180
    225181my $newState = "run";
Note: See TracChangeset for help on using the changeset viewer.