Changeset 18539
- Timestamp:
- Jul 15, 2008, 10:02:24 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/pstamp/scripts/pstamp_parser_run.pl (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pstamp/scripts/pstamp_parser_run.pl
r18380 r18539 2 2 ### 3 3 ### pstampparser_run.pl 4 ### Run the postage stamprequest parser for a given request id4 ### Run the request parser for a given request id 5 5 ### 6 6 … … 15 15 my $verbose; 16 16 my $dbname; 17 my $req uest_id;17 my $req_id; 18 18 19 19 GetOptions( 20 20 'verbose' => \$verbose, 21 'dbname=s' => \$dbname,22 'req_id=s' => \$req uest_id,21 'dbname=s' => \$dbname, 22 'req_id=s' => \$req_id, 23 23 ); 24 24 … … 29 29 } 30 30 31 die "req_id is required" if !defined($req uest_id);31 die "req_id is required" if !defined($req_id); 32 32 33 33 use IPC::Cmd 0.36 qw( can_run run ); … … 51 51 my $ipprc = PS::IPP::Config->new(); # IPP Configuration 52 52 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; 53 my $outputDataStoreRoot = metadataLookupStr($ipprc->{_siteConfig}, 'DATA_STORE_ROOT'); 54 exit ($PS_EXIT_CONFIG_ERROR) unless defined $outputDataStoreRoot; # lookup failure outputs a message 57 55 my $defaultOutputRoot = $outputDataStoreRoot; 58 56 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"; 57 my $pstamp_workdir = metadataLookupStr($ipprc->{_siteConfig}, 'PSTAMP_WORKDIR'); 58 exit ($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 ) 62 my $workdir = "$pstamp_workdir/$req_id"; 63 64 if (! -e $workdir ) { 65 mkdir $workdir or die "failed to create working directory $workdir for request id $req_id"; 66 } 67 68 my $defaultDSProduct = metadataLookupStr($ipprc->{_siteConfig}, 'PSTAMP_DATA_STORE_PRODUCT'); 69 exit ($PS_EXIT_CONFIG_ERROR) unless defined $defaultDSProduct; 65 70 66 71 my $missing_tools; … … 81 86 #Look up the uri for the given request 82 87 { 83 my $command = "$pstamptool -pendingreq -req_id $req uest_id";88 my $command = "$pstamptool -pendingreq -req_id $req_id"; 84 89 $command .= " -dbname $dbname" if $dbname; 85 90 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 90 95 91 96 if (@$stdout_buf == 0) { 92 print STDERR "pending pstamp request id $req uest_id not found\n";97 print STDERR "pending pstamp request id $req_id not found\n"; 93 98 exit 1; 94 99 } … … 98 103 my $requests = parse_md_list($metadata); 99 104 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 103 108 $psrequest = $requests->[0]; 104 109 } 105 110 106 111 if (!$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"; 109 113 exit 1; 110 114 } … … 112 116 my $uri = $psrequest->{uri}; 113 117 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 121 119 122 120 my $ds_id = $psrequest->{ds_id}; 123 121 122 my $new_uri; 124 123 if ($ds_id) { 125 mkdir $inputWorkdir;126 124 { 127 my $new_uri = "$inputWorkdir/request.fits";125 $new_uri = "$workdir/request.fits"; 128 126 my $command = "$dsget --uri $uri --filename $new_uri"; 129 127 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 138 136 139 137 # find the name of the output directory 140 my $ outdir;138 my $product; 141 139 if ($ds_id) { 142 140 my $command = "$pstamptool -datastore -ds_id $ds_id"; … … 159 157 my $dataStore = $dataStores->[0]; 160 158 161 $ outdir = "$outputDataStoreRoot/$psrequest->{outFileset}";159 $product = $dataStore->{outProduct}; 162 160 } 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 # 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); 173 172 174 173 175 # run the appropriate parse command to parse the queue the jobs for this request … … 175 177 my $request_type = find_request_type($uri); 176 178 177 print STDERR "request_type is $request_type\n" if $verbose;179 print STDERR "request_type for $req_id is $request_type\n" if $verbose; 178 180 179 181 my $parse_cmd; 182 my $reqType; # for the database 180 183 if ($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; 183 187 } 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"; 185 190 } 186 191 … … 191 196 } 192 197 198 my $fault; 193 199 { 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 194 204 my $command = "$parse_cmd"; 195 205 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 196 206 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"); 200 214 } 201 print OUT " @$stderr_buf";215 print OUT "$errbuf"; 202 216 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 212 227 # 213 228 { 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; 216 234 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 217 235 run(command => $command, verbose => $verbose); … … 220 238 } 221 239 } 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 222 244 223 245 exit 0;
Note:
See TracChangeset
for help on using the changeset viewer.
