- Timestamp:
- Aug 11, 2009, 3:54:00 PM (17 years ago)
- Location:
- branches/czw_branch/cleanup
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
pstamp/scripts/pstamp_job_run.pl (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/cleanup
- Property svn:mergeinfo changed
/trunk merged: 24940-24950,24953-24971,24973-24977,24986-24989,24993-25017,25019,25021,25023-25024,25026,25029-25031,25036-25049
- Property svn:mergeinfo changed
-
branches/czw_branch/cleanup/pstamp/scripts/pstamp_job_run.pl
r24951 r25051 14 14 use Digest::MD5::File qw( file_md5_hex ); 15 15 use PS::IPP::PStamp::RequestFile qw( :standard ); 16 17 my $verbose; 18 my $dbname;19 my $dbserver;20 my $job_id;21 my $redirect_output; 22 my $output_base;23 24 my $host = hostname();25 16 use IPC::Cmd 0.36 qw( can_run run ); 17 18 use PS::IPP::Metadata::Config; 19 #use PS::IPP::Metadata::Stats; 20 #use PS::IPP::Metadata::List qw( parse_md_list ); 21 22 use PS::IPP::Config qw( :standard ); 23 24 my ($job_id, $redirect_output, $outputBase, $rownum, $jobType); 25 my ($verbose, $dbname, $dbserver, $no_update); 26 26 27 27 GetOptions( 28 28 'job_id=s' => \$job_id, 29 'output_base=s' => \$output_base, 30 'redirect-output' => \$redirect_output, 29 'job_type=s' => \$jobType, 30 'rownum=s' => \$rownum, 31 'output_base=s' => \$outputBase, 32 'redirect-output' => \$redirect_output, 31 33 'dbname=s' => \$dbname, 32 34 'dbserver=s' => \$dbserver, 33 35 'verbose' => \$verbose, 36 'no-update' => \$no_update, 34 37 ); 35 38 36 39 40 my $host = hostname(); 37 41 if ($verbose) { 38 42 print "\n\n"; … … 41 45 42 46 die "job_id is required" if !$job_id; 43 die "output_base is required" if !$output_base; 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_SUCCESS 52 $PS_EXIT_UNKNOWN_ERROR 53 $PS_EXIT_SYS_ERROR 54 $PS_EXIT_CONFIG_ERROR 55 $PS_EXIT_PROG_ERROR 56 $PS_EXIT_DATA_ERROR 57 $PS_EXIT_TIMEOUT_ERROR 58 metadataLookupStr 59 metadataLookupBool 60 caturi 61 ); 47 48 my_die( "job_type is required", $job_id, $PS_EXIT_PROG_ERROR) if !$jobType; 49 my_die("rownum is required", $job_id, $PS_EXIT_PROG_ERROR) if !$rownum; 50 my_die("output_base is required", $job_id, $PS_EXIT_PROG_ERROR) if !$outputBase; 51 52 62 53 my $ipprc = PS::IPP::Config->new(); # IPP Configuration 63 64 54 if ($redirect_output) { 65 my $logDest = "$output_base.log"; 66 $ipprc->redirect_output($logDest); 67 } 55 my $logDest = "$outputBase.log"; 56 $ipprc->redirect_output($logDest) 57 or my_die ("unable to redirect output to $logDest", $job_id, $PS_EXIT_UNKNOWN_ERROR); 58 } 59 68 60 69 61 if (!$dbserver) { … … 78 70 79 71 if ($missing_tools) { 80 warn("Can't find required tools."); 81 exit ($PS_EXIT_CONFIG_ERROR); 72 my_die("Can't find required tools", $job_id, $PS_EXIT_CONFIG_ERROR); 82 73 } 83 74 84 75 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 85 76 86 my $psjob; 87 #Look up the uri for the given job 88 { 89 my $command = "$pstamptool -pendingjob -job_id $job_id"; 77 my $jobStatus; 78 if ($jobType eq "stamp") { 79 my $argslist = "$outputBase.args"; 80 open ARGSLIST, "<$argslist" or my_die("failed to open argslist file $argslist", $job_id, $PS_EXIT_UNKNOWN_ERROR); 81 my $argString = <ARGSLIST>; 82 close ARGSLIST; 83 chomp $argString; 84 85 # XXX: should we do any other sanity checking? 86 my_die("arglist file $argslist is empty", $job_id, $PS_EXIT_DATA_ERROR) if !$argString; 87 88 my $command = "$ppstamp $outputBase $argString"; 90 89 $command .= " -dbname $dbname" if $dbname; 91 90 $command .= " -dbserver $dbserver" if $dbserver; 92 91 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 93 92 run(command => $command, verbose => $verbose); 94 unless ($success) {95 die("Unable to perform pstamptool -pendingjob: $error_code");96 }97 98 if (@$stdout_buf == 0) {99 print STDERR "pending pstamp job id $job_id not found\n";100 exit 0;101 }102 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or103 die("Unable to parse metdata config doc");104 105 my $jobs = parse_md_list($metadata);106 my $num = @$jobs;107 die "unexpected number of jobs $num found for job: $job_id" if $num > 1;108 109 $psjob = $jobs->[0];110 }111 112 if (!$psjob) {113 print STDERR "postage stamp job $job_id not found\n";114 exit 1;115 }116 117 my $rownum = $psjob->{rownum};118 my $uri = $psjob->{uri};119 my $outputBase = $psjob->{outputBase};120 my $argString = $psjob->{args};121 my $jobType = $psjob->{jobType};122 123 my $jobStatus;124 if ($jobType eq "stamp") {125 my $command = "$ppstamp -file $uri $outputBase $argString";126 $command .= " -dbname $dbname" if $dbname;127 $command .= " -dbserver $dbserver" if $dbserver;128 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =129 run(command => $command, verbose => $verbose);130 93 131 94 if ($success) { 132 # XXX shouldn't need to do this, review schema`133 95 my $dir = dirname($outputBase); 134 96 135 97 my $reglist = "$dir/reglist$job_id"; 136 98 137 open F, ">$reglist" or die "can't open $reglist for output"; 138 139 # figure out what output images we should expect 140 141 # Note: we are assuming the contents of the filerules here. 142 my @extensions = ( "fits", "mk.fits", "wt.fits"); 143 144 # we always require an image 99 open F, ">$reglist" or my_die( "can't open $reglist for output", $job_id, $PS_EXIT_UNKNOWN_ERROR); 100 101 # Figure out what output images were produced 102 103 # Note: we are assuming the contents of the PSTAMP filerules here. 104 my %extensions = ( $PSTAMP_SELECT_IMAGE => "fits", 105 $PSTAMP_SELECT_MASK => "mk.fits", 106 $PSTAMP_SELECT_WEIGHT => "wt.fits"); 107 108 # we always create a stamp of the image 145 109 my $output_mask = $PSTAMP_SELECT_IMAGE; 146 110 147 # we search the argString for -mask and - weight.111 # we search the argString for -mask and -variance. 148 112 # searching the arg string allows us to avoid adding a column in pstampJob 149 # XXX yeah but does this make us susceptible to user input fouling us up? 150 # For example, what if somebody sets the output base to file-mask-weight 151 # TODO: clean this up 152 $output_mask |= $PSTAMP_SELECT_MASK if ($argString =~ /-mask/); 153 $output_mask |= $PSTAMP_SELECT_WEIGHT if ($argString =~ /-weight/); 154 155 # XXX we're getting a bit intimate with the bit field definitions here. 156 # do better use a hash 157 158 my $m = 1; 159 foreach my $extension (@extensions) { 160 my $do_this_one = $m & $output_mask; 161 $m = $m << 1; 113 $output_mask |= $PSTAMP_SELECT_MASK if ($argString =~ /-mask/); 114 $output_mask |= $PSTAMP_SELECT_WEIGHT if ($argString =~ /-variance/); 115 116 foreach my $key (keys (%extensions)) { 117 my $do_this_one = $key & $output_mask; 118 162 119 next if (! $do_this_one); 120 121 my $extension = $extensions{$key}; 163 122 164 123 my $basename = basename($outputBase); … … 175 134 } else { 176 135 $jobStatus = $error_code >> 8; 177 print STDERR "ppstamp failed with error code: $jobStatus\n";136 my_die( "ppstamp failed with error code: $jobStatus", $job_id, $jobStatus); 178 137 } 179 138 } elsif ($jobType eq "get_image") { 139 my_die( "get_image jobs not working right now", $job_id, $PS_EXIT_CONFIG_ERROR); 140 141 my $uri = ""; 180 142 my $command = "$pstamp_get_image_job --job_id $job_id --uri $uri --out_dir $outputBase --rownum $rownum"; 181 143 $command .= " --dbname $dbname" if $dbname; … … 188 150 } else { 189 151 $jobStatus = $error_code >> 8; 190 print STDERR "ppstamp failed with error code: $jobStatus\n";152 my_die( "pstamp_get_image_job failed with error code: $jobStatus", $job_id, $jobStatus); 191 153 } 192 154 } elsif ($jobType eq "detect_query") { 193 die("multiple detect_query jobs not supported yet");155 my_die("detect_query jobs not supported yet", $job_id,$PS_EXIT_CONFIG_ERROR); 194 156 } else { 195 die("unknown jobType $jobType found");196 } 197 198 # stop the job and set the result value157 my_die("unknown jobType $jobType found", $job_id, $PS_EXIT_PROG_ERROR); 158 } 159 160 # mark the job stopped in the database 199 161 { 200 my $command = "$pstamptool -updatejob -job_id $job_id -state stop -fault $jobStatus";162 my $command = "$pstamptool -updatejob -job_id $job_id -state stop"; 201 163 $command .= " -dbname $dbname" if $dbname; 202 164 $command .= " -dbserver $dbserver" if $dbserver; 203 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 204 run(command => $command, verbose => $verbose); 205 unless ($success) { 206 die("Unable to perform $command: $error_code"); 207 } 208 } 209 210 exit $jobStatus; 165 if (!$no_update) { 166 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 167 run(command => $command, verbose => $verbose); 168 unless ($success) { 169 die("Unable to perform $command: $error_code"); 170 } 171 } else { 172 print STDERR "skipping command: $command\n" 173 } 174 } 175 176 exit 0; 211 177 212 178 # create a string to be passed as input to dsreg when registering this file in a fileset … … 219 185 if (-e $path) { 220 186 my @finfo = stat($path); 221 die "failed to stat $path" unless (@finfo); # XXX clean up187 my_die("failed to stat $path", $job_id, $PS_EXIT_UNKNOWN_ERROR) unless (@finfo); 222 188 my $bytes = $finfo[7]; 223 189 my $md5sum = file_md5_hex($path); … … 225 191 return "$filename|$bytes|$md5sum|$filetype|"; 226 192 } else { 227 die "$filename not found at $path"; 228 } 229 } 193 my_die("$filename not found at $path", $job_id, $PS_EXIT_UNKNOWN_ERROR); 194 } 195 } 196 197 sub my_die 198 { 199 my $msg = shift; # Warning message on die 200 my $job_id = shift; # job identifier 201 my $exit_code = shift; # Exit code to add 202 203 $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code; 204 205 carp($msg); 206 if (defined $job_id and not $no_update) { 207 my $command = "$pstamptool -updatejob"; 208 $command .= " -job_id $job_id"; 209 $command .= " -fault $exit_code"; 210 $command .= " -dbname $dbname" if defined $dbname; 211 $command .= " -dbserver $dbserver" if defined $dbserver; 212 system($command); 213 } 214 exit $exit_code; 215 } 216
Note:
See TracChangeset
for help on using the changeset viewer.
