Changeset 30587 for branches/czw_branch/20101203/pstamp/scripts
- Timestamp:
- Feb 11, 2011, 4:42:29 PM (15 years ago)
- Location:
- branches/czw_branch/20101203
- Files:
-
- 6 edited
-
. (modified) (1 prop)
-
pstamp/scripts/psstatus (modified) (7 diffs)
-
pstamp/scripts/pstamp_checkdependent.pl (modified) (23 diffs)
-
pstamp/scripts/pstamp_job_run.pl (modified) (6 diffs)
-
pstamp/scripts/pstamp_server_status (modified) (3 diffs)
-
pstamp/scripts/pstampparse.pl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20101203
-
branches/czw_branch/20101203/pstamp/scripts/psstatus
r30586 r30587 13 13 my $running; 14 14 my $finished; 15 my $ req_faulted;16 my $ job_faulted;15 my $finishing; 16 my $totals; 17 17 my $dbname; 18 18 my $dbserver; … … 20 20 my $dbpassword; 21 21 my $verbose; 22 my $finishing;23 22 24 23 GetOptions( … … 26 25 'finished|f', \$finished, 27 26 'finishing', \$finishing, 28 'req_faulted', \$req_faulted, 29 'job_faulted', \$job_faulted, 27 'totals|t', \$totals, 30 28 'limit|l=i', \$limit, 31 29 'dbname=s', \$dbname, … … 35 33 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV ; 36 34 37 $running = 1 if (!$finished and !$finishing and !$running );38 39 my $no_args = ! (defined $running or defined $finished or defined $ req_faulted or defined $job_faulted);35 $running = 1 if (!$finished and !$finishing and !$running and !$totals); 36 37 my $no_args = ! (defined $running or defined $finished or defined $finishing or defined $totals ); 40 38 41 39 die "cannot supply --running and --finished\n" if ($running and $finished); … … 44 42 my $ipprc = PS::IPP::Config->new(); 45 43 my $dbh = getDBHandle(); 44 45 my $totals_query = " 46 SELECT label, count(job_id) AS 'Unfinished Jobs', priority 47 FROM pstampRequest join pstampJob USING(req_id) 48 JOIN Label USING(label) 49 WHERE pstampJob.state ='run' and pstampRequest.state ='run' 50 GROUP by label"; 46 51 47 52 my $running_query = " … … 51 56 label, 52 57 reqType, 53 priority,58 -- priority, 54 59 state, 55 60 fault, … … 233 238 234 239 my $sql; 235 if ($finished) { 240 if ($totals) { 241 $sql = $totals_query; 242 } elsif ($finished) { 236 243 $sql = $finished_query; 237 244 } elsif ($running) { -
branches/czw_branch/20101203/pstamp/scripts/pstamp_checkdependent.pl
r30586 r30587 4 4 # 5 5 # Check the status of a pending pstampDependent insuring that 6 # the dependent processing has been queued and whether it is7 # finished or not6 # the any update processing that is needed has been queued and determine check 7 # whether the processing has finished or not 8 8 9 9 use warnings; … … 27 27 my $IPP_DIFF_MODE_STACK_STACK = 4; 28 28 29 my ($dep_id, $stage, $stage_id, $component, $imagedb, $rlabel, $need_magic );30 my ($dbname, $ dbserver, $verbose, $save_temps, $no_update);29 my ($dep_id, $stage, $stage_id, $component, $imagedb, $rlabel, $need_magic, $fault_count, $max_fault_count); 30 my ($dbname, $ps_dbserver, $verbose, $save_temps, $no_update); 31 31 32 32 GetOptions( … … 35 35 'stage_id=i' => \$stage_id, 36 36 'component=s' => \$component, 37 'imagedb=s' => \$imagedb, # dbname for images .37 'imagedb=s' => \$imagedb, # dbname for images lookups. 38 38 'rlabel=s' => \$rlabel, 39 39 'need_magic' => \$need_magic, 40 'fault_count=i' => \$fault_count, 41 'max_fault_count=i' => \$max_fault_count, 40 42 'dbname=s' => \$dbname, # postage stamp server dbname 41 'dbserver=s' => \$ dbserver,# postage stamp server dbserver43 'dbserver=s' => \$ps_dbserver, # postage stamp server dbserver 42 44 'verbose' => \$verbose, 43 45 'save-temps' => \$save_temps, … … 48 50 if !(defined $dep_id and defined $stage and defined $stage_id and 49 51 defined $component and defined $imagedb); 52 53 $max_fault_count = 5 if !$max_fault_count; 54 $fault_count = 0 if !defined $fault_count; 50 55 51 56 my $missing_tools; … … 61 66 } 62 67 68 my $ipprc = PS::IPP::Config->new(); 69 70 if (!$ps_dbserver) { 71 $ps_dbserver = metadataLookupStr($ipprc->{_siteConfig}, 'PS_DBSERVER'); 72 } 73 $pstamptool .= " -dbname $dbname" if $dbname; 74 $pstamptool .= " -dbserver $ps_dbserver"; 75 63 76 # Append imagedb to the ippTools 77 # Note: configured DBSERVER is used for this server 64 78 $chiptool .= " -dbname $imagedb"; 65 79 $warptool .= " -dbname $imagedb"; … … 68 82 $magicdstool .= " -dbname $imagedb"; 69 83 70 my $ipprc = PS::IPP::Config->new();71 72 if (!$dbserver) {73 $dbserver = metadataLookupStr($ipprc->{_siteConfig}, 'PS_DBSERVER');74 }75 76 84 77 85 my $tool; 78 86 my $cmd; 79 87 my $dsRun_state = ""; 80 my $whole_run = ($component eq 'all'); 81 82 # XXX: whole_run was a concept that isn't practical. Having one dependent for 83 # a whole run makes finding errors too hard. We always have a dependent for each 84 # component. 85 # XXX: remove the unneeded code 86 my_die("component = 'all' not supported", $PS_EXIT_PROG_ERROR) if $whole_run;; 87 88 if ($whole_run) { 89 if ($stage eq "chip") { 90 $cmd = "$chiptool -listrun -chip_id $stage_id"; 91 } elsif ($stage eq "warp") { 92 $cmd = "$warptool -listrun -warp_id $stage_id"; 93 } elsif ($stage eq "diff") { 94 $cmd = "$difftool -listrun -diff_id $stage_id"; 95 } else { 96 my_die("unexpected stage $stage found", $PS_EXIT_PROG_ERROR); 97 } 88 89 if ($stage eq "chip") { 90 $cmd = "$chiptool -processedimfile -allfiles -chip_id $stage_id -class_id $component"; 91 } elsif ($stage eq "warp") { 92 $cmd = "$warptool -warped -warp_id $stage_id -skycell_id $component"; 93 } elsif ($stage eq "diff") { 94 $cmd = "$difftool -diffskyfile -diff_id $stage_id -skycell_id $component"; 98 95 } else { 99 if ($stage eq "chip") { 100 $cmd = "$chiptool -processedimfile -allfiles -chip_id $stage_id -class_id $component"; 101 } elsif ($stage eq "warp") { 102 $cmd = "$warptool -warped -warp_id $stage_id -skycell_id $component"; 103 } elsif ($stage eq "diff") { 104 $cmd = "$difftool -diffskyfile -diff_id $stage_id -skycell_id $component"; 105 } else { 106 my_die("unexpected stage $stage found", $PS_EXIT_PROG_ERROR); 107 } 96 my_die("unexpected stage $stage found", $PS_EXIT_PROG_ERROR); 108 97 } 109 98 … … 124 113 } 125 114 my $status = 0; 126 if (( $it->{state} eq 'full') or ($it->{state} eq 'update') and ($whole_run or ($it->{data_state} eq 'full'))115 if ((($it->{state} eq 'full') or ($it->{state} eq 'update')) and ($it->{data_state} eq 'full') 127 116 and (!$need_magic or $magic_ok or $it->{magicked} > 0)) { 128 117 129 # This Dependency is satisfied. All done! 118 # This Dependency is satisfied. All done. Release the pstampJobs 119 # 130 120 my $command = "$pstamptool -updatedependent -set_state full -dep_id $dep_id"; 131 $command .= " -dbname $dbname" if $dbname;132 $command .= " -dbserver $dbserver" if $dbserver;133 121 if (!$no_update) { 134 122 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 143 131 } elsif (($it->{state} eq 'cleaned') or ($it->{state} eq 'update')) { 144 132 # For warp and diff stages we need to call the 'queue_update' subroutines even if the 145 # data_state is update in order to check the earlier stages in the pipeline 146 # For example if warpSkyfile is in update state but the chip run that it depends on hasn't 147 # been updated we need to go and queue it. 148 149 if (($it->{state} ne 'cleaned') and $it->{fault}) { 150 my_die("Component faulted on update dep_id: $dep_id", 151 $PS_EXIT_SYS_ERROR); 133 # data_state is update in order to check the state of inputs in earlier stages in the pipeline 134 # For example if warpSkyfile is in update state but the chipRun that it depends on hasn't 135 # been updated we need to go and queue the chips for processing. 136 137 my $fault = $it->{fault}; 138 if (($fault eq $PSTAMP_GONE) or (($it->{state} eq 'update') and $fault)) { 139 $fault_count++; 140 print "$stage $stage_id $component has fault $fault\n"; 141 if ($it->{fault} eq $PSTAMP_GONE) { 142 faultJobs($PSTAMP_GONE); 143 exit 0; 144 } elsif ($fault_count >= $max_fault_count) { 145 print "$stage $stage_id $component has faulted $fault_count times. Giving up\n"; 146 147 faultComponent($stage, $stage_id, $component, $PSTAMP_GONE); 148 149 # fault the jobs 150 faultJobs($PSTAMP_GONE); 151 exit 0; 152 } 153 154 # assume the fault is transient. 155 my_die("Component faulted on update dep_id: $dep_id", $PS_EXIT_SYS_ERROR); 152 156 } 153 157 154 158 if ($stage eq 'chip') { 155 # check_states_chip takes an array so that check_states_warp can pass it set of chips159 # check_states_chip takes an array so that check_states_warp can pass it a set of chips 156 160 my $chips = [$it]; 157 $status = check_states_chip($it->{chip_id}, $ whole_run, $chips, $rlabel, $need_magic);161 $status = check_states_chip($it->{chip_id}, $chips, $rlabel, $need_magic); 158 162 } elsif ($stage eq 'warp') { 159 $status = check_states_warp($it, $ whole_run, $rlabel, $need_magic);163 $status = check_states_warp($it, $rlabel, $need_magic); 160 164 } elsif ($stage eq 'diff') { 161 $status = check_states_diff($it, $ whole_run, $rlabel, $need_magic);165 $status = check_states_diff($it, $rlabel, $need_magic); 162 166 } else { 163 167 my_die("Unexpected stage found $stage", $PS_EXIT_PROG_ERROR); 168 } 169 if ($status >= $PSTAMP_FIRST_ERROR_CODE) { 170 faultJobs($status); 164 171 } 165 172 } else { … … 173 180 my $job_fault = 0; 174 181 175 if (0) {176 if ($stage eq 'chip') {177 # XXX: There is no need to check this anymore. All magicked chipRuns have abs(burntool_state) >= 13178 # If something changes that causes an error, we will figure that out from the chip failure179 my $burntool_state = $it->{burntool_state};180 # XXX: get the value of 13 from the ppImage recipe181 if ($burntool_state and (abs($burntool_state) < 13)) {182 print STDERR "chip $it->{chip_id} $it->{class_id} has burntool_state $burntool_state. Not avaiable.\n";183 $job_fault = $PSTAMP_NOT_AVAILABLE;184 }185 }186 }187 182 if ($state eq 'error_cleaned') { 188 183 $job_fault = $PSTAMP_NOT_AVAILABLE; 189 } elsif (($state =~ /scrub/) or ($state =~ /purge/) ) {190 # jobs must have changed state since depenency was made184 } elsif (($state =~ /scrub/) or ($state =~ /purge/) or ($state eq 'drop')) { 185 # Component state must have been changed state since dependency was inserted. 191 186 print STDERR "Dependency cannot be satisfied\n"; 192 187 $job_fault = $PSTAMP_GONE; … … 195 190 my_die ("Unexpected state for ${stage}Run $stage_id $state", $PS_EXIT_PROG_ERROR); 196 191 } 192 197 193 if (!$job_fault and ($stage eq 'chip')) { 194 # should only get here with data_state 'full' and perhaps destreaking not done 195 my_die ("Unexpected state for ${stage}Run $stage_id $state", $PS_EXIT_PROG_ERROR) 196 if $it->{data_state} ne 'full'; 197 198 198 # chip processing is done, start destreaking. 199 199 my @chips; … … 201 201 $job_fault = check_states_magicDSRun($stage, $stage_id, \@chips, $rlabel, $need_magic, $it->{raw_magicked}, $it->{magic_ds_id}, $it->{dsRun_state}); 202 202 } 203 if ($job_fault) { 204 faultJobs($state, $stage, $stage_id, $job_fault); 203 204 if ($job_fault >= $PSTAMP_FIRST_ERROR_CODE) { 205 faultJobs($job_fault); 205 206 } 206 207 } … … 211 212 sub check_states_chip { 212 213 my $chip_id = shift; 213 my $whole_run = shift; # if true queue entire run for update 214 my $metadatas = shift; # an array of hashes, either from -processedimfile or -listrun 214 my $metadatas = shift; # an array of hashes, either from chiptool -processedimfile or warptool -scmap 215 215 my $rlabel = shift; # if defined a new label for the chipRun 216 216 my $need_magic = shift; 217 218 217 219 218 my $dsRun_state; … … 221 220 my @chips; 222 221 my $magic_ds_id; 223 if (!$whole_run) { 224 foreach my $chip (@$metadatas) { 225 $dsRun_state = $chip->{dsRun_state}; 226 $raw_all_magicked &= ($chip->{raw_magicked} > 0); 227 $magic_ds_id = $chip->{magic_ds_id}; 228 229 push @chips, $chip->{class_id}; 230 231 my $state = $chip->{state}; 232 my $data_state = $chip->{data_state}; 233 if (($state =~ /error/) or ($state =~ /purged/) or ($state =~ /scrubbed/) or ($state eq 'drop') or 234 ($data_state =~ /error/) or ($data_state =~ /purged/) or ($data_state =~ /scrubbed/)) { 235 236 print "chipRun state is $chip->{chip_id} has state: $state data_state: $data_state cannot update\n"; 237 faultJobs('stop', undef, undef, $PSTAMP_GONE); 238 239 return 0; 240 } elsif (($chip->{data_state} ne 'update') and ($chip->{data_state} ne 'full')) { 241 242 my $command = "$chiptool -setimfiletoupdate -chip_id $chip_id -class_id $chip->{class_id}"; 243 $command .= " -set_label $rlabel" if $rlabel; 244 245 if (!$no_update) { 246 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 247 run(command => $command, verbose => $verbose); 248 unless ($success) { 249 my_die("failed to queue ${stage}Run $stage_id $component for update", $PS_EXIT_UNKNOWN_ERROR); 250 } 251 } else { 252 print "skipping $command\n"; 253 } 254 } elsif ($chip->{fault}) { 255 # fault the dependent 256 my_die("chip $chip->{chip_id} $chip->{class_id} faulted: $chip->{fault}", $chip->{fault}); 257 } elsif ($chip->{dsFile_fault}) { 258 # fault the dependent 259 my_die("magicDSFile $chip->{magic_ds_id} $chip->{chip_id} $chip->{class_id} faulted: $chip->{dsFile_fault}", $chip->{dsFile_fault}); 260 } 261 } 262 } else { 263 my $run = $metadatas->[0]; 264 $dsRun_state = $run->{dsRun_state}; 265 $raw_all_magicked = ($run->{raw_magicked} > 0); 266 my $state = $run->{state}; 267 if (($state =~ /error/) or ($state =~ /purged/) or ($state =~ /scrubbed/)) { 268 print "chipRun state is $run->{chip_id} is in state $state cannot update\n"; 269 faultJobs('stop', undef, undef, $PSTAMP_GONE); 270 return 0; 271 } 272 273 # providing no -class_id arguments changes all imfiles with data_state = 'cleaned' to 'update' 274 my $command = "$chiptool -setimfiletoupdate -chip_id $chip_id"; 275 $command .= " -set_label $rlabel" if $rlabel; 276 277 if (!$no_update) { 278 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 279 run(command => $command, verbose => $verbose); 280 unless ($success) { 281 my_die("failed to queue ${stage}Run $stage_id $component for update", $PS_EXIT_UNKNOWN_ERROR); 282 } 283 } else { 284 print "skipping $command\n"; 285 } 286 } 287 288 my $status = check_states_magicDSRun('chip', $chip_id, \@chips, $rlabel, $need_magic, $raw_all_magicked, $magic_ds_id, $dsRun_state); 289 290 return $status; 291 } 292 293 sub check_states_warp { 294 # check status of input chips. If state is not updatable set error code for job 295 296 # if chipProcessedImfile.state is cleaned call check_states_chip 297 298 my $metadata = shift; 299 my $whole_run = shift; # if true queue entire run for update 300 my $rlabel = shift; # if defined a new label for the chipRun 301 my $need_magic = shift; 302 303 my $raw_all_magicked = 1; # this gets cleared if any of the inputs aren't destreaked 304 305 my $warp_id = $metadata->{warp_id}; 306 my $skycell_id = $metadata->{skycell_id}; 307 my $state = $metadata->{state}; 308 my $data_state = $metadata->{data_state}; 309 if (($state =~ /error/) or ($state =~ /purged/) or ($state =~ /scrubbed/) or ($state eq 'drop') or 310 ($data_state =~ /error/) or ($data_state =~ /purged/) or ($data_state =~ /scrubbed/)) { 311 print STDERR "warpRun $warp_id $skycell_id has state $state $data_state faulting jobs\n"; 312 faultJobs('stop', undef, undef, $PSTAMP_GONE); 313 exit 0; 314 } 315 if (($state eq 'update') and ($metadata->{fault})) { 316 # fault dependent. 317 my $fault = $metadata->{fault}; 318 my_die("warp $warp_id $skycell_id faulted: $fault", $fault); 319 } 320 321 if (!$whole_run) { 322 my $skycell = $metadata; 323 my $skycell_id = $skycell->{skycell_id}; 324 325 my $command = "$warptool -scmap -warp_id $warp_id -skycell_id $skycell_id"; 326 my $data = runToolAndParse($command, $verbose); 327 if (!$data or scalar @$data == 0) { 328 # This happens if the chipProcessedImfile disappears which happened when earlier 329 # versions of chiptool -revertprocessedimfile didn't check the chipRun.state before 330 # deleing the row. 331 # Fault the jobs so that the Request can finish ... 332 faultJobs('stop', undef, undef, $PSTAMP_GONE); 333 # ... and fault the dependent so that we have a record of the error 334 my_die("failed to find warpSkyCelllMap for warpRun $warp_id skycell_id $skycell_id", 335 $PSTAMP_GONE); 336 } 337 338 339 my $chips_ready = 1; 340 my @chipsToUpdate; 341 my $chip_id; 342 foreach my $chip (@$data) { 343 $chip_id = $chip->{chip_id}; 344 if (($chip->{data_state} ne 'full') or ($need_magic and ($chip->{magicked} <= 0))) { 345 $chips_ready = 0; 346 $chip->{fault} = $chip->{chip_fault}; 347 push @chipsToUpdate, $chip; 222 223 my $queued_update = 0; 224 foreach my $chip (@$metadatas) { 225 $dsRun_state = $chip->{dsRun_state}; 226 $raw_all_magicked &= ($chip->{raw_magicked} > 0); 227 $magic_ds_id = $chip->{magic_ds_id}; 228 229 push @chips, $chip->{class_id}; 230 231 my $state = $chip->{state}; 232 my $data_state = $chip->{data_state}; 233 if (($state =~ /error/) or ($state =~ /purged/) or ($state =~ /scrubbed/) or ($state eq 'drop') or 234 ($data_state =~ /error/) or ($data_state =~ /purged/) or ($data_state =~ /scrubbed/) or ($data_state eq 'drop')) { 235 236 print "chipRun state is $chip->{chip_id} has state: $state data_state: $data_state cannot update\n"; 237 my $error_code; 238 if (($state eq 'error_cleaned') or ($data_state ='error_cleaned')) { 239 $error_code = $PSTAMP_NOT_AVAILABLE; 348 240 } else { 349 # this chip is good to go 350 } 351 } 352 353 if ($chips_ready and $skycell->{data_state} ne 'update') { 354 # the reason we defer setting the warp to update is so that we can handle error conditions at previous 355 # stages more easily. 356 my $command = "$warptool -setskyfiletoupdate -warp_id $warp_id -skycell_id $skycell->{skycell_id}"; 241 $error_code = $PSTAMP_GONE; 242 } 243 244 # caller will fault the jobs 245 return $error_code; 246 } elsif (($chip->{data_state} ne 'update') and ($chip->{data_state} ne 'full')) { 247 248 # chiptool does more state checking to insure this isn't done prematurely. 249 my $command = "$chiptool -setimfiletoupdate -chip_id $chip_id -class_id $chip->{class_id}"; 357 250 $command .= " -set_label $rlabel" if $rlabel; 358 251 … … 366 259 print "skipping $command\n"; 367 260 } 368 } elsif (scalar @chipsToUpdate > 0) { 369 return check_states_chip($chip_id, 0, \@chipsToUpdate, $rlabel, $need_magic); 370 } 371 } else { 372 my $warpRun = $metadata; 373 my $command = "$chiptool -listrun -chip_id $warpRun->{chip_id}"; 374 my $data = runToolAndParse($command, $verbose); 375 my_die("failed to find chipRun $warpRun->{chip_id} for warpRun $warp_id", $PS_EXIT_UNKNOWN_ERROR) 376 if !$data or scalar @$data != 1; 377 378 my $chipRun = $data->[0]; 379 380 my $chipRunState = $chipRun->{state}; 381 if (($chipRunState =~ /purge/) or ($chipRunState =~ /scrub/)) { 382 print STDERR "warpRun $warp_id depends on chipRun $chipRun->{chip_id} which is in state $chipRunState\n"; 383 faultJobs('stop', 'warp', $warp_id, $PSTAMP_GONE); 384 return 0; 385 } 386 my $warpRunState = $warpRun->{state}; 387 if (($chipRunState eq 'full') and (! $need_magic or ($chipRun->{magicked} > 0)) and ($warpRunState eq 'cleaned')) { 388 # The inputs and outputs are ready. Queue the warpRun for update. 389 390 # providing no -skycell_id arguments changes all skyfiles with data_state = 'cleaned' to 'update' 391 my $command = "$warptool -setskyfiletoupdate -warp_id $warp_id"; 392 $command .= " -set_label $rlabel" if $rlabel; 393 394 if (!$no_update) { 395 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 396 run(command => $command, verbose => $verbose); 397 unless ($success) { 398 my_die("failed to queue ${stage}Run $stage_id $component for update", $PS_EXIT_UNKNOWN_ERROR); 399 } 400 } else { 401 print "skipping $command\n"; 402 } 403 } elsif ($chipRunState eq 'cleaned' or 404 (($chipRun->{state} eq 'full') and ($need_magic and ($chipRun->{magicked} < 0) and ($chipRun->{dsRun_state} ne 'new')))) { 405 my $data = [$chipRun]; 406 return check_states_chip($chipRun->{chip_id}, 1, $data, $rlabel, $need_magic); 407 } 408 } 409 410 # return value may be the return status of script so zero is good 411 return 0; 412 } 261 $queued_update = 1; 262 } elsif ($chip->{fault}) { 263 $fault_count++; 264 my $fault = $chip->{fault}; 265 266 if ($fault eq $PSTAMP_GONE) { 267 # caller will fault jobs 268 return $PSTAMP_GONE; 269 } elsif ($fault_count > $max_fault_count) { 270 print "$stage $stage_id has faulted $fault_count times. Giving up\n"; 271 $fault = $PSTAMP_GONE; 272 faultComponent('chip', $chip->{chip_id}, $chip->{class_id}, $PSTAMP_GONE); 273 return $PSTAMP_GONE; 274 } 275 # fault the dependent 276 my_die("chip $chip->{chip_id} $chip->{class_id} faulted: $chip->{fault}", $chip->{fault}); 277 } elsif ($chip->{dsFile_fault} eq $PSTAMP_GONE) { 278 print STDERR "magicDSFile $chip->{magic_ds_id} $chip->{chip_id} $chip->{class_id} is GONE"; 279 return $PSTAMP_GONE; 280 } elsif ($chip->{dsFile_fault} and ($chip->{dsFile_data_state} eq 'update')) { 281 # fault the dependent 282 my_die("magicDSFile $chip->{magic_ds_id} $chip->{chip_id} $chip->{class_id} faulted: $chip->{dsFile_fault}", $chip->{dsFile_fault}); 283 } 284 } 285 286 my $status = 0; 287 if (!$queued_update) { 288 $status = check_states_magicDSRun('chip', $chip_id, \@chips, $rlabel, $need_magic, $raw_all_magicked, $magic_ds_id, $dsRun_state); 289 } 290 291 return $status; 292 } 293 294 sub check_states_warp { 295 my $metadata = shift; 296 my $rlabel = shift; # if defined a new label for the chipRun 297 my $need_magic = shift; 298 299 my $exit_status = 0; 300 301 my $raw_all_magicked = 1; # this gets cleared if any of the inputs aren't destreaked 302 303 my $warp_id = $metadata->{warp_id}; 304 my $skycell_id = $metadata->{skycell_id}; 305 my $state = $metadata->{state}; 306 my $data_state = $metadata->{data_state}; 307 308 if (($state =~ /error/) or ($state =~ /purged/) or ($state =~ /scrubbed/) or ($state eq 'drop') or 309 ($data_state =~ /error/) or ($data_state =~ /purged/) or ($data_state =~ /scrubbed/) or ($data_state eq 'drop')) { 310 print STDERR "warpRun $warp_id $skycell_id has state $state $data_state faulting jobs\n"; 311 my $error_code; 312 if (($state eq 'error_cleaned') or ($data_state eq 'error_cleaned')) { 313 $error_code = $PSTAMP_NOT_AVAILABLE; 314 } else { 315 $error_code = $PSTAMP_GONE; 316 } 317 return $error_code 318 } 319 if (($state eq 'update') and ($metadata->{fault})) { 320 # fault dependent. 321 my $fault = $metadata->{fault}; 322 print STDERR "warp $warp_id $skycell_id faulted: $fault"; 323 return $fault; 324 } 325 326 my $skycell = $metadata; 327 328 # get the list of input chips for this skycell 329 my $command = "$warptool -scmap -warp_id $warp_id -skycell_id $skycell_id"; 330 my $data = runToolAndParse($command, $verbose); 331 if (!$data or scalar @$data == 0) { 332 # This happens if the chipProcessedImfile disappears which happened when earlier 333 # versions of chiptool -revertprocessedimfile didn't check the chipRun.state before 334 # deleting the row. 335 print STDERR "failed to find warpSkyCelllMap for warpRun $warp_id skycell_id $skycell_id"; 336 return $PSTAMP_GONE; 337 } 338 339 my $chips_ready = 1; 340 my @chipsToUpdate; 341 my $chip_id; 342 foreach my $chip (@$data) { 343 $chip_id = $chip->{chip_id}; 344 if (($chip->{data_state} ne 'full') or ($need_magic and ($chip->{magicked} <= 0))) { 345 $chips_ready = 0; 346 $chip->{fault} = $chip->{chip_fault}; 347 push @chipsToUpdate, $chip; 348 } else { 349 # this chip is done 350 } 351 } 352 353 if ($chips_ready and $skycell->{data_state} ne 'update') { 354 # the reason we defer setting the warp to update is so that we can handle error conditions at previous 355 # stages more easily. 356 my $command = "$warptool -setskyfiletoupdate -warp_id $warp_id -skycell_id $skycell->{skycell_id}"; 357 $command .= " -set_label $rlabel" if $rlabel; 358 359 if (!$no_update) { 360 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 361 run(command => $command, verbose => $verbose); 362 unless ($success) { 363 my_die("failed to queue ${stage}Run $stage_id $component for update", $PS_EXIT_UNKNOWN_ERROR); 364 } 365 } else { 366 print "skipping $command\n"; 367 } 368 } elsif (scalar @chipsToUpdate > 0) { 369 my $fault = check_states_chip($chip_id, \@chipsToUpdate, $rlabel, $need_magic); 370 if ($fault) { 371 if ($fault eq $PSTAMP_GONE) { 372 # chip or dsfile that this skycell depends on has faulted in a way that is not recoverable 373 # fault the skycell 374 faultComponent('warp', $warp_id, $skycell->{skycell_id}, $PSTAMP_GONE); 375 } 376 $exit_status = $fault; 377 } 378 } 379 380 # return value may be used as the return status of script so we use zero as success 381 return $exit_status; 382 } 383 413 384 sub check_states_diff { 414 385 my $metadata = shift; 415 my $whole_run = shift; # if true queue entire run for update416 386 my $rlabel = shift; # if defined a new label for the chipRun 417 387 my $need_magic = shift; … … 419 389 my $diff_id = $metadata->{diff_id}; 420 390 my $diff_mode = $metadata->{diff_mode}; 421 if (!$whole_run) { 422 my $skycell = $metadata; 423 my $skycell_id = $skycell->{skycell_id}; 424 425 if ($diff_mode == $IPP_DIFF_MODE_WARP_STACK ) { 426 # check the state of the template stack 427 my $command = "$stacktool -sumskyfile -stack_id $skycell->{stack2}"; 428 my $stack = runToolAndParseExpectOne($command, $verbose); 429 my_die("failed to find stackSumSkyfile for stack_id $skycell->{stack2}", $PS_EXIT_UNKNOWN_ERROR) if !$stack; 430 431 if ($stack->{state} ne 'full') { 432 print STDERR "template stack for diffRun $diff_id $skycell_id is not in full state faulting jobs\n"; 433 # this faults all jobs depending on this dep_id 434 faultJobs('stop', 'diff', $diff_id, $PSTAMP_GONE); 435 return $PSTAMP_GONE; 436 } 437 438 # now check the warp 439 $command = "$warptool -warped -warp_id $skycell->{warp1} -skycell_id $skycell_id"; 440 my $warp = runToolAndParseExpectOne($command, $verbose); 441 my_die("failed to find warpSkyfile for warpRun $skycell->{warp1} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR) if !$warp; 442 443 if ($warp->{data_state} ne 'full') { 444 return check_states_warp($warp, 0, $rlabel, $need_magic); 445 } 446 # warps are ready fall through and queue the diff update 447 } elsif ($diff_mode eq $IPP_DIFF_MODE_WARP_WARP) { 448 my $command = "$warptool -warped -warp_id $skycell->{warp1} -skycell_id $skycell_id"; 449 my $warp1 = runToolAndParseExpectOne($command, $verbose); 450 my_die("failed to find warpSkyfile for warpRun $skycell->{warp1} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR) if !$warp1; 451 452 my $warps_ready = 1; 453 my $status = 0; 454 if ($warp1->{data_state} ne 'full') { 455 $warps_ready = 0; 456 $status = check_states_warp($warp1, 0, $rlabel, $need_magic); 457 if ($status) { 458 return $status; 391 my $skycell = $metadata; 392 my $skycell_id = $skycell->{skycell_id}; 393 394 if ($diff_mode == $IPP_DIFF_MODE_WARP_STACK ) { 395 # check the state of the template stack 396 my $command = "$stacktool -sumskyfile -stack_id $skycell->{stack2}"; 397 my $stack = runToolAndParseExpectOne($command, $verbose); 398 my_die("failed to find stackSumSkyfile for stack_id $skycell->{stack2}", $PS_EXIT_UNKNOWN_ERROR) if !$stack; 399 400 if ($stack->{state} ne 'full') { 401 print STDERR "template stack for diffRun $diff_id $skycell_id is not in full state faulting jobs\n"; 402 faultComponent('diff', $diff_id, $skycell_id, $PSTAMP_GONE); 403 return $PSTAMP_GONE; 404 } 405 406 # now check the warp 407 $command = "$warptool -warped -warp_id $skycell->{warp1} -skycell_id $skycell_id"; 408 my $warp = runToolAndParseExpectOne($command, $verbose); 409 my_die("failed to find warpSkyfile for warpRun $skycell->{warp1} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR) if !$warp; 410 411 if ($warp->{data_state} ne 'full') { 412 my $warp_status = check_states_warp($warp, 0, $rlabel, $need_magic); 413 if ($warp_status eq $PSTAMP_GONE) { 414 faultComponent('diff', $diff_id, $skycell_id, $PSTAMP_GONE); 415 } 416 return $warp_status; 417 } 418 # warps are ready fall through and queue the diff update 419 } elsif ($diff_mode eq $IPP_DIFF_MODE_WARP_WARP) { 420 my $command = "$warptool -warped -warp_id $skycell->{warp1} -skycell_id $skycell_id"; 421 my $warp1 = runToolAndParseExpectOne($command, $verbose); 422 my_die("failed to find warpSkyfile for warpRun $skycell->{warp1} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR) if !$warp1; 423 424 my $warps_ready = 1; 425 my $warp_status = 0; 426 if ($warp1->{data_state} ne 'full') { 427 $warps_ready = 0; 428 $warp_status = check_states_warp($warp1, 0, $rlabel, $need_magic); 429 if ($warp_status) { 430 if ($warp_status eq $PSTAMP_GONE) { 431 faultComponent('diff', $diff_id, $skycell_id, $PSTAMP_GONE); 459 432 } 460 } 461 $command = "$warptool -warped -warp_id $skycell->{warp2} -skycell_id $skycell_id"; 462 my $warp2 = runToolAndParseExpectOne($command, $verbose); 463 my_die("failed to find warpSkyfile for warpRun $skycell->{warp2} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR) if !$warp2; 464 465 if ($warp2->{data_state} ne 'full') { 466 $warps_ready = 0; 467 $status = check_states_warp($warp2, 0, $rlabel, $need_magic); 468 } 469 470 if (!$warps_ready) { 471 # don't queue the diff update yet 472 return $status; 473 } 474 475 } elsif ($diff_mode == $IPP_DIFF_MODE_STACK_STACK ) { 476 # check the state of the input stack 477 my $command = "$stacktool -sumskyfile -stack_id $skycell->{stack2}"; 478 my $stack1 = runToolAndParseExpectOne($command, $verbose); 479 my_die("failed to find stackSumSkyfile for stack_id $skycell->{stack2}", $PS_EXIT_UNKNOWN_ERROR) if !$stack1; 480 481 if ($stack1->{state} ne 'full') { 482 print STDERR "input stack for diffRun $diff_id $skycell_id is not in full state faulting jobs\n"; 483 # this faults all jobs depending on this dep_id 484 faultJobs('stop', 'diff', $diff_id, $PSTAMP_GONE); 485 return $PSTAMP_GONE; 486 } 487 # check the state of the template stack 488 $command = "$stacktool -sumskyfile -stack_id $skycell->{stack2}"; 489 my $stack2 = runToolAndParseExpectOne($command, $verbose); 490 my_die("failed to find stackSumSkyfile for stack_id $skycell->{stack2}", $PS_EXIT_UNKNOWN_ERROR) if !$stack2; 491 492 if ($stack2->{state} ne 'full') { 493 print STDERR "template stack for diffRun $diff_id $skycell_id is not in full state faulting jobs\n"; 494 # this faults all jobs depending on this dep_id 495 faultJobs('stop', 'diff', $diff_id, $PSTAMP_GONE); 496 return $PSTAMP_GONE; 497 } 498 499 # inputs are ready fall through and queue the diff update 500 } elsif ($diff_mode == $IPP_DIFF_MODE_STACK_WARP ) { 501 # check the state of the input stack 502 my $command = "$stacktool -sumskyfile -stack_id $skycell->{stack1}"; 503 my $stack = runToolAndParseExpectOne($command, $verbose); 504 my_die("failed to find stackSumSkyfile for stack_id $skycell->{stack1}", $PS_EXIT_UNKNOWN_ERROR) if !$stack; 505 506 if ($stack->{state} ne 'full') { 507 print STDERR "input stack for diffRun $diff_id $skycell_id is not in full state faulting jobs\n"; 508 # this faults all jobs depending on this dep_id 509 faultJobs('stop', 'diff', $diff_id, $PSTAMP_GONE); 510 return $PSTAMP_GONE; 511 } 512 513 # now check the template warp 514 $command = "$warptool -warped -warp_id $skycell->{warp2} -skycell_id $skycell_id"; 515 my $warp = runToolAndParseExpectOne($command, $verbose); 516 my_die("failed to find warpSkyfile for warpRun $skycell->{warp2} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR) if !$warp; 517 518 if ($warp->{data_state} ne 'full') { 519 return check_states_warp($warp, 0, $rlabel, $need_magic); 520 } 521 # warps are ready fall through and queue the diff update 433 return $warp_status; 434 } 435 } 436 $command = "$warptool -warped -warp_id $skycell->{warp2} -skycell_id $skycell_id"; 437 my $warp2 = runToolAndParseExpectOne($command, $verbose); 438 my_die("failed to find warpSkyfile for warpRun $skycell->{warp2} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR) if !$warp2; 439 440 if ($warp2->{data_state} ne 'full') { 441 $warps_ready = 0; 442 $warp_status = check_states_warp($warp2, 0, $rlabel, $need_magic); 443 if ($warp_status eq $PSTAMP_GONE) { 444 faultComponent('diff', $diff_id, $skycell_id, $PSTAMP_GONE); 445 } 446 } 447 448 if (!$warps_ready) { 449 # don't queue the diff update yet 450 return $warp_status; 451 } 452 # inputs are ready fall through and queue the diff update 453 454 } elsif ($diff_mode == $IPP_DIFF_MODE_STACK_STACK ) { 455 # check the state of the input stack 456 my $command = "$stacktool -sumskyfile -stack_id $skycell->{stack2}"; 457 my $stack1 = runToolAndParseExpectOne($command, $verbose); 458 my_die("failed to find stackSumSkyfile for stack_id $skycell->{stack2}", $PS_EXIT_UNKNOWN_ERROR) if !$stack1; 459 460 if ($stack1->{state} ne 'full') { 461 print STDERR "input stack for diffRun $diff_id $skycell_id is not in full state faulting jobs\n"; 462 faultComponent('diff', $diff_id, $skycell_id, $PSTAMP_GONE); 463 return $PSTAMP_GONE; 464 } 465 # check the state of the template stack 466 $command = "$stacktool -sumskyfile -stack_id $skycell->{stack2}"; 467 my $stack2 = runToolAndParseExpectOne($command, $verbose); 468 my_die("failed to find stackSumSkyfile for stack_id $skycell->{stack2}", $PS_EXIT_UNKNOWN_ERROR) if !$stack2; 469 470 if ($stack2->{state} ne 'full') { 471 print STDERR "template stack for diffRun $diff_id $skycell_id is not in full state faulting jobs\n"; 472 faultComponent('diff', $diff_id, $skycell_id, $PSTAMP_GONE); 473 return $PSTAMP_GONE; 474 } 475 476 # inputs are ready fall through and queue the diff update 477 } elsif ($diff_mode == $IPP_DIFF_MODE_STACK_WARP ) { 478 # check the state of the input stack 479 my $command = "$stacktool -sumskyfile -stack_id $skycell->{stack1}"; 480 my $stack = runToolAndParseExpectOne($command, $verbose); 481 my_die("failed to find stackSumSkyfile for stack_id $skycell->{stack1}", $PS_EXIT_UNKNOWN_ERROR) if !$stack; 482 483 if ($stack->{state} ne 'full') { 484 print STDERR "input stack for diffRun $diff_id $skycell_id is not in full state faulting jobs\n"; 485 faultComponent('diff', $diff_id, $skycell_id, $PSTAMP_GONE); 486 return $PSTAMP_GONE; 487 } 488 489 # now check the template warp 490 $command = "$warptool -warped -warp_id $skycell->{warp2} -skycell_id $skycell_id"; 491 my $warp = runToolAndParseExpectOne($command, $verbose); 492 my_die("failed to find warpSkyfile for warpRun $skycell->{warp2} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR) if !$warp; 493 494 if ($warp->{data_state} ne 'full') { 495 my $warp_status = check_states_warp($warp, 0, $rlabel, $need_magic); 496 if ($warp_status eq $PSTAMP_GONE) { 497 faultComponent('diff', $diff_id, $skycell_id, $PSTAMP_GONE); 498 } 499 return $warp_status; 500 } 501 # warps are ready fall through and queue the diff update 502 } else { 503 my_die("unexpected diff_mode found: $diff_mode", $PS_EXIT_PROG_ERROR); 504 } 505 506 if ($skycell->{data_state} ne 'update') { 507 my $command = "$difftool -setskyfiletoupdate -diff_id $diff_id -skycell_id $skycell_id"; 508 $command .= " -set_label $rlabel" if $rlabel; 509 510 if (!$no_update) { 511 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 512 run(command => $command, verbose => $verbose); 513 unless ($success) { 514 my_die("failed to queue ${stage}Run $stage_id $component for update", $PS_EXIT_UNKNOWN_ERROR); 515 } 522 516 } else { 523 my_die("unexpected diff_mode found: $diff_mode", $PS_EXIT_PROG_ERROR); 524 } 525 526 if ($skycell->{data_state} ne 'update') { 527 my $command = "$difftool -setskyfiletoupdate -diff_id $diff_id -skycell_id $skycell_id"; 528 $command .= " -set_label $rlabel" if $rlabel; 529 530 if (!$no_update) { 531 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 532 run(command => $command, verbose => $verbose); 533 unless ($success) { 534 my_die("failed to queue ${stage}Run $stage_id $component for update", $PS_EXIT_UNKNOWN_ERROR); 535 } 536 } else { 537 print "skipping $command\n"; 538 } 539 } 540 } else { 541 # XXX todo whole_run 542 return $PS_EXIT_PROG_ERROR; 517 print "skipping $command\n"; 518 } 543 519 } 544 520 … … 633 609 } 634 610 635 sub faultJobs { 636 my ($state, $stage, $stage_id, $job_fault) = @_; 637 638 my $command = "$pstamptool -updatejob -set_state stop -set_fault $job_fault -dep_id $dep_id"; 639 $command .= " -dbname $dbname" if $dbname; 640 $command .= " -dbserver $dbserver" if $dbserver; 641 if (!$no_update) { 642 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 643 run(command => $command, verbose => $verbose); 644 unless ($success) { 645 my_die("failed to set pstampJob.fault for dep_id: $dep_id", 646 $PS_EXIT_UNKNOWN_ERROR); 647 } 648 } else { 649 print "skipping $command\n"; 650 } 651 } 652 611 # Check the data_state of the magicDSFile associated with this component (currently only chip stage is supported) 612 # Returns zero on success. 613 # returns the PSTAMP fault code to use for the jobs if an unrecoverable error is detected 614 # And faults the dependent if transient errors occur 653 615 sub check_states_magicDSRun { 654 616 my $stage = shift; … … 661 623 my $dsRun_state = shift; 662 624 663 # XXX: this code assumes that destreaking is handled at thechip stage625 # XXX: this code assumes that for update destreaking is only performed for chip stage 664 626 my_die ("check_states_magicDSRun only implemented for chip stage", $PS_EXIT_PROG_ERROR) if $stage ne 'chip'; 665 627 … … 675 637 if ($need_magic and !$input_magicked) { 676 638 if (!defined($dsRun_state) or ($dsRun_state eq 'NULL')) { 639 # it is arguably a programming error if we get here 677 640 print "No magicDSRun for chipRun $stage_id and magic is required\n"; 678 faultJobs('stop', undef, undef, $PSTAMP_NOT_DESTREAKED);641 return $PSTAMP_NOT_DESTREAKED; 679 642 } elsif (($dsRun_state eq 'cleaned') or ($dsRun_state eq 'update')) { 680 643 foreach my $c (@$components) { … … 684 647 my_die("failed to find magicDSFile for ${stage}Run $stage_id $c", $PS_EXIT_UNKNOWN_ERROR); 685 648 } 686 if ($dsfile->{fault} > 0) { 649 if ($dsfile->{fault} eq $PSTAMP_GONE) { 650 print "magicDSFile has fault $PSTAMP_GONE\n"; 651 return $PSTAMP_GONE; 652 } 653 # destreak faults get cleared when the component is set to be updated 654 if (($dsfile->{data_state} eq 'update') and ($dsfile->{fault} > 0)) { 655 $fault_count++; 656 if ($fault_count > $max_fault_count) { 657 print "Destreak file $magic_ds_id $component for $stage $stage_id has faulted $fault_count times. Giving up\n"; 658 faultComponent('destreak', $magic_ds_id, $component, $PSTAMP_GONE); 659 return $PSTAMP_GONE; 660 } 661 # Assume fault is transient 687 662 my_die("faulted magicDSFile for ${stage}Run $stage_id $c fault: $dsfile->{fault}", 688 663 $PS_EXIT_UNKNOWN_ERROR); … … 690 665 if ($dsfile->{data_state} eq 'cleaned') { 691 666 $command = "$magicdstool -setfiletoupdate -magic_ds_id $magic_ds_id -component $c"; 692 # XXX: get the recoveryroot from a config file (it isn't actually used except to check whether it is in nebulous) 667 # XXX: get the recoveryroot from a config file 668 # (It isn't actually used except to check whether it is a nebulous path) 693 669 $command .= " -set_recoveryroot neb://any/gpc1/destreak/recover"; 694 670 $command .= " -set_label $rlabel" if $rlabel; … … 708 684 } 709 685 } elsif ($dsRun_state eq 'failed_revert') { 686 # XXX: revert failures are rarely fixed. give up but say it's just not available not GONE 710 687 print "magicDSRun.state = $dsRun_state for chipRun $stage_id is in state failed_revert cannot update\n"; 711 faultJobs('stop', undef, undef, $PSTAMP_NOT_AVAILABLE);688 return $PSTAMP_NOT_AVAILABLE; 712 689 } else { 713 690 print "magicDSRun.state = $dsRun_state for chipRun $stage_id"; … … 716 693 } 717 694 } 695 718 696 return 0; 697 } 698 699 sub faultJobs { 700 my ($job_fault) = @_; 701 702 my $command = "$pstamptool -updatejob -set_state stop -set_fault $job_fault -dep_id $dep_id"; 703 if (!$no_update) { 704 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 705 run(command => $command, verbose => $verbose); 706 unless ($success) { 707 my_die("failed to set pstampJob.fault for dep_id: $dep_id", 708 $PS_EXIT_UNKNOWN_ERROR); 709 } 710 } else { 711 print "skipping $command\n"; 712 } 713 } 714 715 sub faultComponent { 716 my ($stage, $stage_id, $component, $fault) = @_; 717 718 my $command; 719 if ($stage eq 'chip') { 720 $command = "$chiptool -updateprocessedimfile -chip_id $stage_id -class_id $component"; 721 } elsif ($stage eq 'warp') { 722 $command = "$warptool -updateskyfile -warp_id $stage_id -skycell_id $component"; 723 } elsif ($stage eq 'diff') { 724 $command = "$difftool -updatediffskyfile -diff_id $stage_id -skycell_id $component"; 725 } elsif ($stage eq 'destreak') { 726 $command = "$magicdstool -updatedestreakedfile -magic_ds_id $stage_id -component $component"; 727 } else { 728 my_die("unexpected stage $stage found", $PS_EXIT_PROG_ERROR); 729 } 730 731 $command .= " -fault $fault"; 732 733 if (!$no_update) { 734 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 735 run(command => $command, verbose => $verbose); 736 unless ($success) { 737 carp "$cmd failed"; 738 } 739 } else { 740 print "skipping $command\n"; 741 } 719 742 } 720 743 … … 726 749 727 750 my $command = "$pstamptool -updatedependent -set_fault $fault -dep_id $dep_id"; 728 $command .= " -dbname $dbname" if $dbname;729 $command .= " -dbserver $dbserver" if $dbserver;730 751 if (!$no_update) { 731 752 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = -
branches/czw_branch/20101203/pstamp/scripts/pstamp_job_run.pl
r30586 r30587 14 14 use File::Basename; 15 15 use File::Copy; 16 use File::Temp qw(tempfile );16 use File::Temp qw(tempfile tempdir); 17 17 use Digest::MD5::File qw( file_md5_hex ); 18 18 use PS::IPP::PStamp::RequestFile qw( :standard ); … … 144 144 } elsif (($options & $PSTAMP_REQUIRE_UNCENSORED) and ($stage ne 'chip')) { 145 145 # user required uncensored but since stage isn't chip we can't rebuild them 146 my_die("uncensored inputs not available for job $job_id", $job_id, $PSTAMP_NOT_AVAILABLE); 147 } elsif (($options & $PSTAMP_REQUEST_UNCENSORED) and ($stage ne 'chip')) { 146 my_die("uncensored inputs not available for job $job_id", $job_id, $PSTAMP_NOT_AVAILABLE, 'stop'); 147 } elsif (($options & $PSTAMP_REQUEST_UNCENSORED) and ($params->{state} eq 'update') and ($stage ne 'chip')) { 148 # we can only restore pixels for chip stage images if the data has been updated. 149 # XXX: this test is not quite good enough. If all components have been updated then the 150 # state will be 'full' But this will get us going. 151 print "Run state is update: will make stamps from destreaked $stage images.\n"; 148 152 # make stamps from uncensored images 149 153 $muggle = 0; … … 151 155 # Try and replace the streaks from the recovery images 152 156 153 @file_list = (); 154 $tmproot = "$outdir/$job_id"; 155 mkdir $tmproot or 156 my_die( "failed to create temporary directory $tmproot", $job_id, $PS_EXIT_UNKNOWN_ERROR); 157 my $temp_dir = metadataLookupStr($ipprc->{_siteConfig}, "TEMP.DIR") or &my_die("Unable to find temporary directory in site configuration", $job_id, $PS_EXIT_CONFIG_ERROR); 158 $tmproot = tempdir("$temp_dir/psjob.$job_id.XXXX", CLEANUP => !$save_temps); 157 159 my $muggle_command = "$streaksreplace -stage $stage -tmproot $tmproot"; 158 160 # find the "directory" of the input path_base … … 160 162 my $base = basename($image); 161 163 $tmpImage = "$tmproot/$base"; 164 165 @file_list = (); 162 166 163 167 # XXX: We should get the recovery_path_base from the magicDSFile but that requires a bunch of file rule and … … 180 184 $base = basename($variance); 181 185 $tmpVariance = "$tmproot/$base"; 182 $newFileArgs .= " - weight$tmpVariance";186 $newFileArgs .= " -variance $tmpVariance"; 183 187 my $recVariance = "$inputdir/REC_$base"; 184 188 $muggle_command .= " -weight $variance -recweight $recVariance"; … … 225 229 } 226 230 227 if (!$save_temps) {228 unlink $tmpImage if $tmpImage;229 unlink $tmpMask if $tmpMask;230 unlink $tmpVariance if $tmpVariance;231 rmdir $tmproot if $tmproot;232 }233 234 231 if ($exitStatus == 0) { 235 232 my $reglist = "$outdir/reglist$job_id"; -
branches/czw_branch/20101203/pstamp/scripts/pstamp_server_status
r30586 r30587 46 46 47 47 48 my $down = 0;49 if ($down) {50 print "Postage Stamp Server will be down for maintenance it will back at approximately 00:00 2010-12-11 UTC\n";51 exit 0;52 }53 48 54 49 my $now = `date -u`; … … 56 51 print "<b>Status updated: </b> $now<br /><br />\n"; 57 52 58 my ($pts, $pantasks_script) = tempfile ('/tmp/pts.XXXX', UNLINK => !$save_temps); 53 my $down = 0; 54 if ($down) { 55 print "Postage Stamp Server will be down for maintenance it will back at approximately 00:00 2010-12-11 UTC\n"; 56 # exit 0; 57 } else { 58 # talk to pantasks_server and get the status 59 59 60 print $pts "status\n"; 61 print $pts "quit\n"; 62 close $pts; 60 my ($pts, $pantasks_script) = tempfile ('/tmp/pts.XXXX', UNLINK => !$save_temps); 63 61 64 my $command = "$pantasks_client < $pantasks_script"; 65 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 66 run(command => $command, verbose => $verbose); 67 unless ($success) { 68 $error_code = (($error_code >> 8) or 1); 69 if ($error_code == 12) { 70 #print "Postage Stamp Server is not running\n"; 71 print "Postage Stamp Server will be down for maintenance it will back shortly.\n"; 72 exit 0; 62 print $pts "status\n"; 63 print $pts "quit\n"; 64 close $pts; 65 66 67 my $command = "$pantasks_client < $pantasks_script"; 68 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 69 run(command => $command, verbose => $verbose); 70 unless ($success) { 71 $error_code = (($error_code >> 8) or 1); 72 if ($error_code == 12) { 73 #print "Postage Stamp Server is not running\n"; 74 print "Postage Stamp Server will be down for maintenance it will back shortly.\n"; 75 exit 0; 76 } else { 77 warn("$command failed. exit status: $error_code"); 78 exit $error_code; 79 } 73 80 } 74 warn("$command failed. exit status: $error_code");75 exit $error_code;76 }77 81 78 my $output = join "", @$stdout_buf;82 my $output = join "", @$stdout_buf; 79 83 80 print "$output" if $verbose;84 print "$output" if $verbose; 81 85 82 my @lines = split "\n", $output;86 my @lines = split "\n", $output; 83 87 84 my ($scheduler_state, $controller_state);85 my $got_state = 0;86 my %tasks;87 foreach my $line (@lines) {88 chomp $line;89 next if !$line;90 my ($first, $second, $third);88 my ($scheduler_state, $controller_state); 89 my $got_state = 0; 90 my %tasks; 91 foreach my $line (@lines) { 92 chomp $line; 93 next if !$line; 94 my ($first, $second, $third); 91 95 92 if ($line =~ /Scheduler is/) {93 ($first, $second, $scheduler_state) = split " ", $line;94 $got_state = 1;95 # print "$first $second $third $scheduler_state\n";96 } elsif ($line =~ /Controller is/) {97 ($first, $second, $controller_state) = split " ", $line;98 # print "$first $second $third $controller_state\n";99 } elsif ($got_state == 1 and $line =~ /\+|\-/) {100 # print "$line\n";101 my ($task_state, $task, $nrun, $njobs, $ngood, $nfail, $ntime, $cmd) = split " ", $line;102 # print "$task $task_state\n";103 my %this_task = ( name => $task, nrun=> $nrun, njobs => $njobs, ngood => $ngood, nfail => $nfail, ntime => $ntime, cmd => $cmd );96 if ($line =~ /Scheduler is/) { 97 ($first, $second, $scheduler_state) = split " ", $line; 98 $got_state = 1; 99 # print "$first $second $third $scheduler_state\n"; 100 } elsif ($line =~ /Controller is/) { 101 ($first, $second, $controller_state) = split " ", $line; 102 # print "$first $second $third $controller_state\n"; 103 } elsif ($got_state == 1 and $line =~ /\+|\-/) { 104 # print "$line\n"; 105 my ($task_state, $task, $nrun, $njobs, $ngood, $nfail, $ntime, $cmd) = split " ", $line; 106 # print "$task $task_state\n"; 107 my %this_task = ( name => $task, nrun=> $nrun, njobs => $njobs, ngood => $ngood, nfail => $nfail, ntime => $ntime, cmd => $cmd ); 104 108 105 # change '.' in task name to '_' so we have a valid hash key 106 $task =~ s/\./\_/g; 107 $tasks{$task} = \%this_task; 109 # change '.' in task name to '_' so we have a valid hash key 110 $task =~ s/\./\_/g; 111 $tasks{$task} = \%this_task; 112 } 113 } 114 115 if ($scheduler_state) { 116 print "Pantasks Scheduler $scheduler_state.\n"; 117 if ($controller_state) { 118 print $br . "Pantasks Controller $controller_state.\n"; 119 } else { 120 print STDERR "Controller state not found"; 121 exit 1; 122 } 123 print "$br$br\n"; 124 } else { 125 print STDERR "Scheduler state not found"; 126 exit 1; 127 } 128 129 my $request_run = $tasks{'pstamp_request_run'}; 130 my $request_fin = $tasks{'request_finish_run'}; 131 my $job_run = $tasks{'pstamp_job_run'}; 132 133 134 if ($request_run) { 135 # print "<br >\n"; 136 print "<b>Parser Status:</b> $request_run->{nrun} running. $request_run->{ngood} parsed successfully. $request_run->{nfail} failed to parse."; 137 if ($request_fin) { 138 print " $request_fin->{ngood} Requests finished."; 139 } else { 140 print "Task request.finish.run not found.\n"; 141 } 142 print "\n"; 143 print "\n"; 144 if ($job_run) { 145 print "<br /><b>Job Status:</b> $job_run->{nrun} running. $job_run->{ngood} completed successfully. $job_run->{nfail} failed"; 146 print "<br />\n"; 147 } else { 148 print "Task pstamp.job.run not found.<br />\n"; 149 } 150 } else { 151 print "Task pstamp.request.run not found.\n"; 108 152 } 109 153 } 110 154 111 if ($scheduler_state) { 112 print "Pantasks Scheduler $scheduler_state.\n"; 113 if ($controller_state) { 114 print $br . "Pantasks Controller $controller_state.\n"; 115 } else { 116 print STDERR "Controller state not found"; 117 exit 1; 118 } 119 print "$br$br\n"; 120 } else { 121 print STDERR "Scheduler state not found"; 122 exit 1; 123 } 155 # now run the script psstatus to check the status of running requests and finished requests 156 print "<br /><b>Unfinished Requests</b><br />\n"; 157 print "<pre>\n"; 158 system "$status_cmd --totals"; 159 print "</pre>\n"; 124 160 125 my $request_run = $tasks{'pstamp_request_run'}; 126 my $request_fin = $tasks{'request_finish_run'}; 127 my $job_run = $tasks{'pstamp_job_run'}; 161 #print "<br />\n"; 128 162 129 163 130 if ($request_run) { 131 print "<br /><b>Parser Status:</b> $request_run->{nrun} running. $request_run->{ngood} parsed successfully. $request_run->{nfail} failed to parse."; 132 if ($request_fin) { 133 print " $request_fin->{ngood} Requests finished."; 134 } else { 135 print "Task request.finish.run not found.\n"; 136 } 137 print "\n"; 138 print "\n"; 139 if ($job_run) { 140 print "<br /><b>Job Status:</b> $job_run->{nrun} running. $job_run->{ngood} completed successfully. $job_run->{nfail} failed"; 141 print "<br />\n"; 142 } else { 143 print "Task pstamp.job.run not found.<br />\n"; 144 } 145 146 # now run the script psstatus to check the status of running requests and finished requests 147 print "<br /><b>Unfinished Requests</b><br />\n"; 148 print "<pre>\n"; 149 system "$status_cmd --running"; 150 print "</pre>\n"; 164 # print "<br /><b>Unfinished Requests</b><br />\n"; 165 print "<pre>\n"; 166 system "$status_cmd --running"; 167 print "</pre>\n"; 151 168 152 169 if (0) { … … 158 175 } 159 176 160 print "<br /><b>Requests completed in last 24 hours (most recently completed first)</b><br />\n"; 161 print "<pre>\n"; 162 system "$status_cmd --finished"; 163 print "</pre>\n"; 164 165 } else { 166 print "Task pstamp.request.run not found.\n"; 167 } 168 177 print "<br /><b>Requests completed in last 24 hours (most recently completed first)</b><br />\n"; 178 print "<pre>\n"; 179 system "$status_cmd --finished"; 180 print "</pre>\n"; 169 181 170 182 -
branches/czw_branch/20101203/pstamp/scripts/pstampparse.pl
r30586 r30587 932 932 my $data_state = $image->{data_state}; 933 933 $data_state = $run_state if $stage eq 'stack'; 934 if (($run_state =~ /purged/) or ($run_state =~ /scrubbed/) or ($run_state eq 'drop')) { 934 my $component_fault = $image->{fault}; 935 my $stage_id = $image->{stage_id}; 936 my $component = $image->{component}; 937 938 if ($component_fault eq $PSTAMP_GONE) { 935 939 # image is gone and it's not coming back 940 print STDERR "$stage $stage_id $component is gone\n"; 941 $$r_newState = 'stop'; 942 $$r_fault = $PSTAMP_GONE; 943 } elsif (($run_state =~ /purged/) or ($run_state =~ /scrubbed/) or ($run_state eq 'drop')) { 944 # image is gone and it's not coming back 945 print STDERR "$stage $stage_id $component has state: $run_state data_state: $data_state\n"; 936 946 $$r_newState = 'stop'; 937 947 $$r_fault = $PSTAMP_GONE; 938 948 } elsif (($run_state eq "error_cleaned") or ($data_state eq 'error_cleaned')) { 939 949 # if cleanup had an error don't get the user's hopes up set fault to gone 950 print STDERR "$stage $stage_id $component has state: $run_state data_state: $data_state\n"; 940 951 $$r_newState = 'stop'; 941 952 $$r_fault = $PSTAMP_GONE;
Note:
See TracChangeset
for help on using the changeset viewer.
