- Timestamp:
- May 3, 2010, 8:45:22 AM (16 years ago)
- Location:
- branches/simmosaic_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
pstamp/scripts/pstamp_parser_run.pl (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simmosaic_branches
- Property svn:mergeinfo changed
-
branches/simmosaic_branches/pstamp/scripts/pstamp_parser_run.pl
r24831 r27839 13 13 use Getopt::Long qw( GetOptions ); 14 14 use File::Basename qw( basename dirname); 15 use File::Copy; 16 use POSIX qw( strftime ); 17 use Carp; 18 use IPC::Cmd 0.36 qw( can_run run ); 19 20 use PS::IPP::Metadata::Config; 21 use PS::IPP::Metadata::Stats; 22 use PS::IPP::Metadata::List qw( parse_md_list ); 23 24 use PS::IPP::Config qw( :standard ); 15 25 16 26 my $req_id; … … 18 28 my $redirect_output; 19 29 my $product; 30 my $label; 20 31 my $verbose; 21 32 my $dbname; … … 26 37 'uri=s' => \$uri, 27 38 'product=s' => \$product, 39 'label=s' => \$label, 28 40 'redirect-output' => \$redirect_output, 29 41 'verbose' => \$verbose, … … 38 50 } 39 51 40 die "--req_id --uri --product are required"41 if !defined($req_id) or42 !defined($uri) or43 !defined($product);44 45 use IPC::Cmd 0.36 qw( can_run run );46 47 use PS::IPP::Metadata::Config;48 use PS::IPP::Metadata::Stats;49 use PS::IPP::Metadata::List qw( parse_md_list );50 51 use PS::IPP::Config qw($PS_EXIT_SUCCESS52 $PS_EXIT_UNKNOWN_ERROR53 $PS_EXIT_SYS_ERROR54 $PS_EXIT_CONFIG_ERROR55 $PS_EXIT_PROG_ERROR56 $PS_EXIT_DATA_ERROR57 $PS_EXIT_TIMEOUT_ERROR58 metadataLookupStr59 metadataLookupBool60 caturi61 );62 63 my $ipprc = PS::IPP::Config->new(); # IPP Configuration64 65 my $outputDataStoreRoot = metadataLookupStr($ipprc->{_siteConfig}, 'DATA_STORE_ROOT');66 exit ($PS_EXIT_CONFIG_ERROR) unless defined $outputDataStoreRoot; # lookup failure outputs a message67 my $defaultOutputRoot = $outputDataStoreRoot;68 69 my $pstamp_workdir = metadataLookupStr($ipprc->{_siteConfig}, 'PSTAMP_WORKDIR');70 exit ($PS_EXIT_CONFIG_ERROR) unless defined $pstamp_workdir; # lookup failure outputs a message71 72 if (!$dbserver) {73 $dbserver = metadataLookupStr($ipprc->{_siteConfig}, 'PS_DBSERVER');74 }75 76 # workdir is where we download request files to and place any error output from the parser77 # NOTE: this location needs to be kept in sync with the web interface ( request.php )78 my $workdir = "$pstamp_workdir/$req_id";79 80 if (! -e $workdir ) {81 mkdir $workdir or die "failed to create working directory $workdir for request id $req_id";82 }83 84 if ($redirect_output) {85 my $logDest = "$workdir/psparse.$req_id.log";86 $ipprc->redirect_output($logDest);87 }88 89 my $defaultDSProduct = metadataLookupStr($ipprc->{_siteConfig}, 'PSTAMP_DATA_STORE_PRODUCT');90 exit ($PS_EXIT_CONFIG_ERROR) unless defined $defaultDSProduct;91 92 52 my $missing_tools; 93 53 … … 102 62 } 103 63 64 65 my_die("--req_id --uri --product are required", $req_id, $PS_EXIT_CONFIG_ERROR) 66 if !defined($req_id) or 67 !defined($uri) or 68 !defined($product); 69 70 my $ipprc = PS::IPP::Config->new(); # IPP Configuration 71 72 my $outputDataStoreRoot = metadataLookupStr($ipprc->{_siteConfig}, 'DATA_STORE_ROOT'); 73 exit ($PS_EXIT_CONFIG_ERROR) unless defined $outputDataStoreRoot; # lookup failure outputs a message 74 my $defaultOutputRoot = $outputDataStoreRoot; 75 76 my $pstamp_workdir = metadataLookupStr($ipprc->{_siteConfig}, 'PSTAMP_WORKDIR'); 77 exit ($PS_EXIT_CONFIG_ERROR) unless defined $pstamp_workdir; # lookup failure outputs a message 78 79 if (!$dbserver) { 80 $dbserver = metadataLookupStr($ipprc->{_siteConfig}, 'PS_DBSERVER'); 81 } 82 83 # workdir is where all of the files generated for this request are placed 84 # NOTE: this location needs to be kept in sync with the web interface ( request.php ) 85 my $datestr = strftime "%Y%m%d", gmtime; 86 my $datedir = "$pstamp_workdir/$datestr"; 87 if (! -e $datedir ) { 88 mkdir $datedir or my_die( "failed to create working directory $datedir for request id $req_id", $req_id, 89 $PS_EXIT_CONFIG_ERROR); 90 } 91 92 my $workdir = "$datedir/$req_id"; 93 if (! -e $workdir ) { 94 mkdir $workdir or my_die("failed to create working directory $workdir for request id $req_id", $req_id, 95 $PS_EXIT_CONFIG_ERROR); 96 } 97 98 if ($redirect_output) { 99 my $logDest = "$workdir/psparse.$req_id.log"; 100 $ipprc->redirect_output($logDest); 101 } 102 103 my $defaultDSProduct = metadataLookupStr($ipprc->{_siteConfig}, 'PSTAMP_DATA_STORE_PRODUCT'); 104 exit ($PS_EXIT_CONFIG_ERROR) unless defined $defaultDSProduct; 105 104 106 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 105 107 … … 113 115 run(command => $command, verbose => $verbose); 114 116 unless ($success) { 115 die("Unable to perform $command error code: $error_code");117 my_die("Unable to perform $command error code: $error_code", $req_id, $error_code >> 8); 116 118 } 117 119 } elsif ($uri ne $new_uri) { 118 120 # put a link to the file into the workdir 119 121 if (-e $new_uri) { 120 unlink $new_uri or die "failed to unlink $new_uri";121 } 122 if (! symlink$uri, $new_uri) {123 die ("failed to link request file $uri to workdir $workdir");122 unlink $new_uri or my_die("failed to unlink $new_uri", $req_id, $PS_EXIT_UNKNOWN_ERROR); 123 } 124 if (! copy $uri, $new_uri) { 125 my_die ("failed to copy request file $uri to workdir $workdir", $req_id, $PS_EXIT_UNKNOWN_ERROR); 124 126 } 125 127 } 126 128 $uri = $new_uri; 127 129 128 die "request file $uri not found"if ! -e $uri;130 my_die("request file $uri not found", $req_id, $PS_EXIT_UNKNOWN_ERROR) if ! -e $uri; 129 131 130 132 # if product was not defined (in database), use the default … … 146 148 if ($request_type eq "PS1_PS_REQUEST") { 147 149 $reqType = 'pstamp'; 148 $parse_cmd = $pstampparse; 150 $parse_cmd = "$pstampparse"; 151 $parse_cmd .= " --label $label" if $label; 149 152 } elsif ($request_type eq "MOPS_DETECTABILITY_QUERY") { 150 153 $reqType = 'dquery'; … … 193 196 # get rid of any error file from previous attempt to parse this request 194 197 unlink $error_file_name if (-e $error_file_name); 198 199 # Run the parser 195 200 196 201 my $command = "$parse_cmd"; … … 255 260 } 256 261 } 262 263 sub my_die { 264 my $msg = shift; 265 my $req_id = shift; 266 my $fault = shift; 267 268 carp($msg); 269 270 my $command = "$pstamptool -updatereq -req_id $req_id -fault $fault"; 271 $command .= " -dbname $dbname" if $dbname; 272 $command .= " -dbserver $dbserver" if $dbserver; 273 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 274 run(command => $command, verbose => $verbose); 275 unless ($success) { 276 die("Unable to perform $command error code: $error_code"); 277 } 278 exit $fault; 279 }
Note:
See TracChangeset
for help on using the changeset viewer.
