Changeset 21410 for trunk/pstamp/scripts/pstamp_parser_run.pl
- Timestamp:
- Feb 6, 2009, 5:44:55 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/pstamp/scripts/pstamp_parser_run.pl (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pstamp/scripts/pstamp_parser_run.pl
r21385 r21410 12 12 use Sys::Hostname; 13 13 use Getopt::Long qw( GetOptions ); 14 14 use File::Basename qw( basename dirname); 15 16 my $req_id; 17 my $uri; 18 my $redirect_output; 19 my $product; 15 20 my $verbose; 16 21 my $dbname; 17 my $req_id;18 22 19 23 GetOptions( 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, 23 30 ); 24 31 … … 29 36 } 30 37 31 die "req_id is required" if !defined($req_id); 38 die "--req_id --uri --product are required" 39 if !defined($req_id) or 40 !defined($uri) or 41 !defined($product); 32 42 33 43 use IPC::Cmd 0.36 qw( can_run run ); … … 66 76 } 67 77 78 if ($redirect_output) { 79 my $logDest = "$workdir/psparse.$req_id.log"; 80 $ipprc->redirect_output($logDest); 81 } 82 68 83 my $defaultDSProduct = metadataLookupStr($ipprc->{_siteConfig}, 'PSTAMP_DATA_STORE_PRODUCT'); 69 84 exit ($PS_EXIT_CONFIG_ERROR) unless defined $defaultDSProduct; … … 83 98 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 84 99 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 101 my $fn = basename($uri); 102 my $new_uri = "$workdir/$fn"; 103 if ($uri =~ /^http:/) { 104 # if the uri is an http uri download the file 105 my $command = "$dsget --uri $uri --filename $new_uri"; 90 106 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 91 107 run(command => $command, verbose => $verbose); … … 93 109 die("Unable to perform $command error code: $error_code"); 94 110 } 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 122 die "request file $uri not found" if ! -e $uri; 123 124 # if product was not defined (in database), use the default 125 if ($product eq "NULL") { 161 126 $product = $defaultDSProduct; 162 127 } 163 164 #165 # Here is one of the places that we assume that the output for a request goes directly into166 # 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 128 174 129 my $parse_cmd; … … 220 175 } 221 176 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"; 223 178 $parse_cmd .= " --dbname $dbname" if $dbname; 179 $parse_cmd .= " --verbose" if $verbose; 224 180 225 181 my $newState = "run";
Note:
See TracChangeset
for help on using the changeset viewer.
