IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 23, 2010, 11:33:14 AM (16 years ago)
Author:
bills
Message:

Enable the postage stamp server to generate stamps from cleaned up data.
"Works" for chip and warp stages. diff and maybe stack to do.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/scripts/pstamp_checkdependent.pl

    r27703 r27751  
    4848my $warptool = can_run('warptool') or (warn "Can't find warptool" and $missing_tools = 1);
    4949my $difftool = can_run('difftool') or (warn "Can't find difftool" and $missing_tools = 1);
     50my $stacktool = can_run('stacktool') or (warn "Can't find stacktool" and $missing_tools = 1);
    5051my $magicdstool = can_run('magicdstool') or (warn "Can't find magicdstool" and $missing_tools = 1);
    5152my $pstamptool = can_run('pstamptool') or (warn "Can't find pstamptool" and $missing_tools = 1);
     
    8687} else {
    8788    if ($stage eq "chip") {
    88         $cmd = "$chiptool -processedimfile -chip_id $stage_id -class_id $component";
     89        $cmd = "$chiptool -processedimfile -allfiles -chip_id $stage_id -class_id $component";
    8990    } elsif ($stage eq "warp") {
    9091        $cmd = "$warptool -warped -warp_id $stage_id -skycell_id $component";
     
    9697}
    9798
    98 my $components = runToolAndParse($cmd, $verbose);
    99 
    100 my $n = scalar @$components;
    101 my_die("Unexpected number of components found $n", $PS_EXIT_PROG_ERROR) if ($n != 1);
     99my $it = runToolAndParseExpectOne($cmd, $verbose);
     100
     101my_die("no components found", $PS_EXIT_PROG_ERROR) if ( !$it);
    102102
    103103# Got "it"
    104 my $it = $components->[0];
    105104
    106105my $status = 0;
     
    130129    # need to queue the updates
    131130    if ($stage eq 'chip') {
    132         # queue_update_chip takes an array so that queue_update_warp can pass a set of
    133         # chips to it
     131        # queue_update_chip takes an array so that queue_update_warp can pass it set of chips
    134132        my $chips = [$it];
    135133        $status = queue_update_chip($it->{chip_id}, $whole_run, $chips, $rlabel, $need_magic);
     
    145143
    146144    # detect states that cannot be updated and update the job state
    147     # XXX: we should be more assertive here and check for the specific states where we can continue
     145    # XXX: Perhaps I should be more assertive here and check for the specific states that we know
     146    # that we can continue.
     147
    148148    my $state = $it->{state};
    149149    my $job_fault = 0;
    150     if (($state =~ /scrub/) or ($state =~ /purge/)) {
     150
     151    # temporary hack to deal with data with old burntool tables. This check is now done by pstampparse.pl
     152    # so runs in this state will not get queued
     153    if ($stage eq 'chip') {
     154        my $burntool_state = $it->{burntool_state};
     155        if ($burntool_state and (abs($burntool_state) < 14)) {
     156            print STDERR "chip $it->{chip_id} $it->{class_id} has burntool_state $burntool_state. Not avaiable.\n";
     157            $job_fault = $PSTAMP_NOT_AVAILABLE;
     158        }
     159    }
     160    if ($state eq 'error_cleaned') {
     161        $job_fault = $PSTAMP_NOT_AVAILABLE;
     162    } elsif (($state =~ /scrub/) or ($state =~ /purge/)) {
    151163        # jobs must have changed state since depenency was made
    152164        print STDERR "Dependency cannot be satisfied\n";
     
    155167        # Dependency never should have been inserted
    156168        my_die ("Unexpected state for ${stage}Run $stage_id $state", $PS_EXIT_PROG_ERROR);
     169    }
     170    if (!$job_fault and ($stage eq 'chip')) {
     171        $job_fault = queue_update_magicDSRun($stage, $stage_id, $rlabel, $it->{raw_magicked}, $it->{dsRun_state});
    157172    }
    158173    if ($job_fault) {
     
    213228    }
    214229
     230    my $status = queue_update_magicDSRun('chip', $chip_id, $rlabel, $raw_all_magicked, $dsRun_state);
     231
     232    return $status;
     233}
     234
     235sub queue_update_warp {
     236    # check status of input chips. If state is not updatable set error code for job
     237
     238    # if chipProcessedImfile.state is cleaned call queue_update_chip
     239
     240    # need to code warptool -setskyfiletoupdate
     241    my $metadata = shift;
     242    my $whole_run = shift;  # if true queue entire run for update
     243    my $rlabel = shift;     # if defined a new label for the chipRun
     244    my $need_magic = shift;
     245
     246    my $raw_all_magicked = 1; # this gets cleared if any of the inputs aren't destreaked
     247
     248    my $warp_id = $metadata->{warp_id};
     249    if (!$whole_run) {
     250        my $skycell = $metadata;
     251        my $skycell_id = $skycell->{skycell_id};
     252
     253        my $command = "$warptool -scmap -warp_id $warp_id -skycell_id $skycell_id";
     254        my $data = runToolAndParse($command, $verbose);
     255        my_die("failed to find warpSkyCelllMap for warpRun $warp_id skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR)
     256            if !$data or scalar @$data == 0;
     257
     258        my $good_to_go = 1;
     259        my @chipsToUpdate;
     260        my $chip_id;
     261        foreach my $chip (@$data) {
     262            $chip_id = $chip->{chip_id};
     263            if (($chip->{data_state} ne 'full') or ($need_magic and ($chip->{magicked} <= 0))) {
     264                $good_to_go = 0;
     265                push @chipsToUpdate, $chip;
     266            } else {
     267                # this chip is good to go
     268            }
     269        }
     270
     271        if ($good_to_go) {
     272            my $command = "$warptool -setskyfiletoupdate -warp_id $warp_id -skycell_id $skycell->{skycell_id}";
     273            $command .= " -set_label $rlabel" if $rlabel;
     274
     275            if (!$no_update) {
     276                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     277                            run(command => $command, verbose => $verbose);
     278                unless ($success) {
     279                    my_die("failed to queue ${stage}Run $stage_id $component for update", $PS_EXIT_UNKNOWN_ERROR);
     280                }
     281            } else {
     282                print "skipping $command\n";
     283            }
     284        } elsif (scalar @chipsToUpdate > 0) {
     285            return queue_update_chip($chip_id, 0, \@chipsToUpdate, $rlabel, $need_magic);
     286        }
     287    } else {
     288        my $warpRun = $metadata;
     289        my $command = "$chiptool -listrun -chip_id $warpRun->{chip_id}";
     290        my $data = runToolAndParse($command, $verbose);
     291        my_die("failed to find chipRun $warpRun->{chip_id} for warpRun $warp_id", $PS_EXIT_UNKNOWN_ERROR)
     292            if !$data or scalar @$data != 1;
     293
     294        my $chipRun = $data->[0];
     295
     296        my $chipRunState = $chipRun->{state};
     297        if (($chipRunState =~ /purge/) or ($chipRunState =~ /scrub/)) {
     298            print STDERR "warpRun $warp_id depends on chipRun $chipRun->{chip_id} which is in state $chipRunState\n";
     299            faultJobs('stop', 'warp', $warp_id, $PSTAMP_GONE);
     300            return 0;
     301        }
     302        my $warpRunState = $warpRun->{state};
     303        if (($chipRunState eq 'full') and (! $need_magic or ($chipRun->{magicked} > 0)) and ($warpRunState eq 'cleaned')) {
     304            # The inputs and outputs are ready. Queue the warpRun for update.
     305
     306            # providing no -skycell_id arguments changes all skyfiles with data_state = 'cleaned' to 'update'
     307            my $command = "$warptool -setskyfiletoupdate -warp_id $warp_id";
     308            $command .= " -set_label $rlabel" if $rlabel;
     309
     310            if (!$no_update) {
     311                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     312                            run(command => $command, verbose => $verbose);
     313                unless ($success) {
     314                    my_die("failed to queue ${stage}Run $stage_id $component for update", $PS_EXIT_UNKNOWN_ERROR);
     315                }
     316            } else {
     317                print "skipping $command\n";
     318            }
     319        } elsif ($chipRunState eq 'cleaned' or
     320            (($chipRun->{state} eq 'full') and ($need_magic and ($chipRun->{magicked} < 0) and ($chipRun->{dsRun_state} ne 'new')))) {
     321            my $data = [$chipRun];
     322            return queue_update_chip($chipRun->{chip_id}, 1, $data, $rlabel, $need_magic);
     323        }
     324    }
     325
     326    # return value may be the return status of script so zero is good
     327    return 0;
     328}
     329sub queue_update_diff {
     330    my $metadata = shift;
     331    my $whole_run = shift;  # if true queue entire run for update
     332    my $rlabel = shift;     # if defined a new label for the chipRun
     333    my $need_magic = shift;
     334
     335# XXXX This is not ready to go yet XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxx
     336
     337    my $diff_id   = $metadata->{diff_id};
     338    my $diff_mode = $metadata->{diff_mode};
     339    if (!$whole_run) {
     340        my $skycell = $metadata;
     341        my $skycell_id = $skycell->{skycell_id};
     342
     343        # put this in a module somewhere
     344        my $IPP_DIFF_MODE_WARP_WARP   = 1;
     345        my $IPP_DIFF_MODE_WARP_STACK  = 2;
     346        my $IPP_DIFF_MODE_STACK_WARP  = 2;
     347        my $IPP_DIFF_MODE_STACK_STACK = 4;
     348        if ($diff_mode == $IPP_DIFF_MODE_WARP_STACK ) {
     349            # check the state of the stack
     350            my $command = "$stacktool -sumkskyfile -stack_id $skycell->{stack2}";
     351            my $stack = runToolAndParseExpectOne($command, $verbose);
     352            my_die("failed to find stackSumSkyfile for stack_id $skycell->{stack2}", $PS_EXIT_UNKNOWN_ERROR) if !$stack;
     353
     354            if ($stack->{state} ne 'full') {
     355                print STDERR "template stack for diffRun $diff_id $skycell_id is not in full state faulting jobs\n";
     356                # this faults all jobs depending on this dep_id
     357                faultJobs('stop', 'diff', $diff_id, $PSTAMP_GONE);
     358                return $PSTAMP_GONE;
     359            }
     360
     361            # now check the warp
     362            $command = "$warptool -warped -warp_id $skycell->{warp1} -skycell_id $skycell_id";
     363            my $warp = runToolAndExpectOne($command, $verbose);
     364            my_die("failed to find warpSkyfile for warpRun $skycell->{warp_id} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR)
     365                if !$warp;
     366        }
     367
     368        my $good_to_go = 1;
     369        my @chipsToUpdate;
     370        my $chip_id;
     371        my $warp_id;
     372        my $data ;  #XXXX
     373        foreach my $chip (@$data) {
     374            $chip_id = $chip->{chip_id};
     375            if (($chip->{data_state} ne 'full') or ($need_magic and ($chip->{magicked} <= 0))) {
     376                $good_to_go = 0;
     377                push @chipsToUpdate, $chip;
     378            } else {
     379                # this chip is good to go
     380            }
     381        }
     382
     383        if ($good_to_go) {
     384            my $command = "$warptool -setskyfiletoupdate -warp_id $warp_id -skycell_id $skycell->{skycell_id}";
     385            $command .= " -set_label $rlabel" if $rlabel;
     386
     387            if (!$no_update) {
     388                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     389                            run(command => $command, verbose => $verbose);
     390                unless ($success) {
     391                    my_die("failed to queue ${stage}Run $stage_id $component for update", $PS_EXIT_UNKNOWN_ERROR);
     392                }
     393            } else {
     394                print "skipping $command\n";
     395            }
     396        } elsif (scalar @chipsToUpdate > 0) {
     397            return queue_update_chip($chip_id, 0, \@chipsToUpdate, $rlabel, $need_magic);
     398        }
     399    } else {
     400        my $warpRun = $metadata;
     401        my $warp_id = $warpRun->{warp_id};
     402        my $command = "$chiptool -listrun -chip_id $warpRun->{chip_id}";
     403        my $data = runToolAndParse($command, $verbose);
     404        my_die("failed to find chipRun $warpRun->{chip_id} for warpRun $warp_id", $PS_EXIT_UNKNOWN_ERROR)
     405            if !$data or scalar @$data != 1;
     406
     407        my $chipRun = $data->[0];
     408
     409        my $chipRunState = $chipRun->{state};
     410        if (($chipRunState =~ /purge/) or ($chipRunState =~ /scrub/)) {
     411            print STDERR "warpRun $warp_id depends on chipRun $chipRun->{chip_id} which is in state $chipRunState\n";
     412            faultJobs('stop', 'warp', $warp_id, $PSTAMP_GONE);
     413            return 0;
     414        }
     415        my $warpRunState = $warpRun->{state};
     416        if (($chipRunState eq 'full') and (! $need_magic or ($chipRun->{magicked} > 0)) and ($warpRunState eq 'cleaned')) {
     417            # The inputs and outputs are ready. Queue the warpRun for update.
     418
     419            # providing no -skycell_id arguments changes all skyfiles with data_state = 'cleaned' to 'update'
     420            my $command = "$warptool -setskyfiletoupdate -warp_id $warp_id";
     421            $command .= " -set_label $rlabel" if $rlabel;
     422
     423            if (!$no_update) {
     424                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     425                            run(command => $command, verbose => $verbose);
     426                unless ($success) {
     427                    my_die("failed to queue ${stage}Run $stage_id $component for update", $PS_EXIT_UNKNOWN_ERROR);
     428                }
     429            } else {
     430                print "skipping $command\n";
     431            }
     432        } elsif ($chipRunState eq 'cleaned' or
     433            (($chipRun->{state} eq 'full') and ($need_magic and ($chipRun->{magicked} < 0) and ($chipRun->{dsRun_state} ne 'new')))) {
     434            my $data = [$chipRun];
     435            return queue_update_chip($chipRun->{chip_id}, 1, $data, $rlabel, $need_magic);
     436        }
     437    }
     438
     439    # return value may be the return status of script so zero is good
     440    return 0;
     441}
     442
     443
     444# run a command that produces metadata output and parse the results into an array of objects
     445sub runToolAndParse {
     446    my $command = shift;
     447    my $verbose = shift;
     448
     449    my ($program) = split " ", $command;
     450    $program = basename($program);
     451
     452    print "Running $command\n" if !$verbose;
     453    my $start_tool = DateTime->now->mjd;
     454    # run the command and parse the output
     455    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     456                run(command => $command, verbose => $verbose);
     457    unless ($success) {
     458        print STDERR @$stderr_buf if !$verbose;
     459        return undef;
     460    }
     461
     462    my $now = DateTime->now->mjd;
     463    my $dtime_tool = (DateTime->now->mjd - $start_tool) * 86400.;
     464    print "Time to run $program: $dtime_tool\n";
     465
     466    my $buf = join "", @$stdout_buf;
     467    if (!$buf) {
     468        return undef;
     469    }
     470
     471    my $start_parse = DateTime->now->mjd;
     472
     473    my $mdcParser = PS::IPP::Metadata::Config->new;
     474    my $results = parse_md_fast($mdcParser, $buf)
     475        or my_die ("Unable to parse metadata config doc", $PS_EXIT_UNKNOWN_ERROR);
     476
     477    my $dtime_parse = (DateTime->now->mjd - $start_parse) * 86400.;
     478    print "Time to parse results from $program: $dtime_parse\n";
     479
     480    return $results;
     481}
     482
     483# run an command returning metadata where we expect 1 entry
     484sub runToolAndParseExpectOne {
     485    my $command = shift;
     486    my $verbose = shift;
     487
     488    my $data = runToolAndParse($command, $verbose);
     489
     490    if (!$data) {
     491        return undef;
     492    }
     493
     494    my $n = scalar @$data;
     495    if ($n > 1) {
     496        my_die("Unexpected number of components $n returned by $command", $PS_EXIT_PROG_ERROR);
     497    }
     498
     499    return $data->[0];
     500}
     501
     502# splits meta data config input stream into single units to work around the pathalogically
     503# slow parser. This is similar to and adapted from code in various ippScripts.
     504sub parse_md_fast {
     505    my $mdcParser = shift;
     506    my $input = shift;
     507    my $output = ();
     508
     509    my @whole = split /\n/, $input;
     510    my @single = ();
     511
     512    my $n;
     513    while ( ($n = @whole) > 0) {
     514        my $value = shift @whole;
     515        push @single, $value;
     516        if ($value =~ /^\s*END\s*$/) {
     517            push @single, "\n";
     518
     519            my $list = parse_md_list( $mdcParser->parse( join("\n", @single ) ) ) or
     520                print STDERR "Unable to parse metdata config doc" and return undef;
     521            push @$output, $list->[0];
     522
     523            @single = ();
     524        }
     525    }
     526    return $output;
     527}
     528
     529sub faultJobs {
     530    my ($state, $stage, $stage_id, $job_fault) = @_;
     531
     532    my $command = "$pstamptool -updatejob -state stop -fault $job_fault -dep_id $dep_id";
     533    $command .= " -dbname $dbname" if $dbname;
     534    $command .= " -dbserver $dbserver" if $dbserver;
     535    if (!$no_update) {
     536        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     537                    run(command => $command, verbose => $verbose);
     538        unless ($success) {
     539            my_die("failed to set pstampJob.fault for dep_id: $dep_id",
     540                $PS_EXIT_UNKNOWN_ERROR);
     541        }
     542    } else {
     543        print "skipping $command\n";
     544    }
     545}
     546
     547sub queue_update_magicDSRun {
     548    my $stage = shift;
     549    my $stage_id = shift;
     550    my $rlabel  = shift;
     551    my $input_magicked = shift;
     552    my $dsRun_state = shift;
     553
     554    # XXX: this code is only fully coded and tested for chip stage
     555    my_die ("queue_update_magicDSRun only works for stage chip", $PS_EXIT_PROG_ERROR) if $stage ne 'chip';
     556
    215557    # if called from queue_update_warp dsRun_state is unknown. Go find it.
    216558    if (!$dsRun_state) {
    217         my $command = "$chiptool -listrun -chip_id $chip_id";
     559        my $command = "$chiptool -listrun -chip_id $stage_id";
    218560        my $data = runToolAndParse($command, $verbose);
    219561        my $chipRun = $data->[0];
     
    222564
    223565    # if the input file is already magicked no need to queue destreaking for this chipRun
    224     if ($need_magic and !$raw_all_magicked) {
     566    if ($need_magic and !$input_magicked) {
    225567        if ($dsRun_state eq 'cleaned') {
    226568            my $command = "$magicdstool -updaterun -set_state new -stage $stage -stage_id $stage_id";
     
    242584        }
    243585    }
    244 
    245     # return value may be the return status of script so zero is good
    246586    return 0;
    247587}
    248588
    249 sub queue_update_warp {
    250     # check status of input chips. If state is not updatable set error code for job
    251 
    252     # if chipProcessedImfile.state is cleaned call queue_update_chip
    253 
    254     # need to code warptool -setskyfiletoupdate
    255     my $metadata = shift;
    256     my $whole_run = shift;  # if true queue entire run for update
    257     my $rlabel = shift;     # if defined a new label for the chipRun
    258     my $need_magic = shift;
    259 
    260     my $raw_all_magicked = 1; # this gets cleared if any of the inputs aren't destreaked
    261 
    262     my $warp_id = $metadata->{warp_id};
    263     if (!$whole_run) {
    264         my $skycell = $metadata;
    265         my $skycell_id = $skycell->{skycell_id};
    266 
    267         my $command = "$warptool -scmap -warp_id $warp_id -skycell_id $skycell_id";
    268         my $data = runToolAndParse($command, $verbose);
    269         my_die("failed to find warpSkyCelllMap for warpRun $warp_id skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR)
    270             if !$data or scalar @$data == 0;
    271 
    272         my $good_to_go = 1;
    273         my @chipsToUpdate;
    274         my $chip_id;
    275         foreach my $chip (@$data) {
    276             $chip_id = $chip->{chip_id};
    277             if (($chip->{data_state} ne 'full') or ($need_magic and ($chip->{magicked} <= 0))) {
    278                 $good_to_go = 0;
    279                 push @chipsToUpdate, $chip;
    280             } else {
    281                 # this chip is good to go
    282             }
    283         }
    284 
    285         if ($good_to_go) {
    286             my $command = "$warptool -setskyfiletoupdate -warp_id $warp_id -skycell_id $skycell->{skycell_id}";
    287             $command .= " -set_label $rlabel" if $rlabel;
    288 
    289             if (!$no_update) {
    290                 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    291                             run(command => $command, verbose => $verbose);
    292                 unless ($success) {
    293                     my_die("failed to queue ${stage}Run $stage_id $component for update", $PS_EXIT_UNKNOWN_ERROR);
    294                 }
    295             } else {
    296                 print "skipping $command\n";
    297             }
    298         } elsif (scalar @chipsToUpdate > 0) {
    299             return queue_update_chip($chip_id, 0, \@chipsToUpdate, $rlabel, $need_magic);
    300         }
    301     } else {
    302         my $warpRun = $metadata;
    303         my $command = "$chiptool -listrun -chip_id $warpRun->{chip_id}";
    304         my $data = runToolAndParse($command, $verbose);
    305         my_die("failed to find chipRun $warpRun->{chip_id} for warpRun $warp_id", $PS_EXIT_UNKNOWN_ERROR)
    306             if !$data or scalar @$data != 1;
    307 
    308         my $chipRun = $data->[0];
    309 
    310         my $chipRunState = $chipRun->{state};
    311         if (($chipRunState =~ /purge/) or ($chipRunState =~ /scrub/)) {
    312             print STDERR "warpRun $warp_id depends on chipRun $chipRun->{chip_id} which is in state $chipRunState\n";
    313             faultJobs('stop', 'warp', $warp_id, $PSTAMP_GONE);
    314             return 0;
    315         }
    316         my $warpRunState = $warpRun->{state};
    317         if (($chipRunState eq 'full') and (! $need_magic or ($chipRun->{magicked} > 0)) and ($warpRunState eq 'cleaned')) {
    318             # The inputs and outputs are ready. Queue the warpRun for update.
    319 
    320             # providing no -skycell_id arguments changes all skyfiles with data_state = 'cleaned' to 'update'
    321             my $command = "$warptool -setskyfiletoupdate -warp_id $warp_id";
    322             $command .= " -set_label $rlabel" if $rlabel;
    323 
    324             if (!$no_update) {
    325                 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    326                             run(command => $command, verbose => $verbose);
    327                 unless ($success) {
    328                     my_die("failed to queue ${stage}Run $stage_id $component for update", $PS_EXIT_UNKNOWN_ERROR);
    329                 }
    330             } else {
    331                 print "skipping $command\n";
    332             }
    333         } elsif ($chipRunState eq 'cleaned' or
    334             (($chipRun->{state} eq 'full') and ($need_magic and ($chipRun->{magicked} < 0) and ($chipRun->{dsRun_state} ne 'new')))) {
    335             my $data = [$chipRun];
    336             return queue_update_chip($chipRun->{chip_id}, 1, $data, $rlabel, $need_magic);
    337         }
    338     }
    339 
    340     # return value may be the return status of script so zero is good
    341     return 0;
    342 }
    343 sub queue_update_diff {
    344     return 0;
    345 }
    346 
    347 
    348 # run a command that produces metadata output and parse the results into an array of objects
    349 sub runToolAndParse {
    350     my $command = shift;
    351     my $verbose = shift;
    352 
    353     my ($program) = split " ", $command;
    354     $program = basename($program);
    355 
    356     print "Running $command\n" if !$verbose;
    357     my $start_tool = DateTime->now->mjd;
    358     # run the command and parse the output
    359     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    360                 run(command => $command, verbose => $verbose);
    361     unless ($success) {
    362         print STDERR @$stderr_buf if !$verbose;
    363         return undef;
    364     }
    365 
    366     my $now = DateTime->now->mjd;
    367     my $dtime_tool = (DateTime->now->mjd - $start_tool) * 86400.;
    368     print "Time to run $program: $dtime_tool\n";
    369 
    370     my $buf = join "", @$stdout_buf;
    371     if (!$buf) {
    372         return undef;
    373     }
    374 
    375     my $start_parse = DateTime->now->mjd;
    376 
    377     my $mdcParser = PS::IPP::Metadata::Config->new;
    378     my $results = parse_md_fast($mdcParser, $buf)
    379         or my_die ("Unable to parse metadata config doc", $PS_EXIT_UNKNOWN_ERROR);
    380 
    381     my $dtime_parse = (DateTime->now->mjd - $start_parse) * 86400.;
    382     print "Time to parse results from $program: $dtime_parse\n";
    383 
    384     return $results;
    385 }
    386 
    387 # splits meta data config input stream into single units to work around the pathalogically
    388 # slow parser. This is similar to and adapted from code in various ippScripts.
    389 sub parse_md_fast {
    390     my $mdcParser = shift;
    391     my $input = shift;
    392     my $output = ();
    393 
    394     my @whole = split /\n/, $input;
    395     my @single = ();
    396 
    397     my $n;
    398     while ( ($n = @whole) > 0) {
    399         my $value = shift @whole;
    400         push @single, $value;
    401         if ($value =~ /^\s*END\s*$/) {
    402             push @single, "\n";
    403 
    404             my $list = parse_md_list( $mdcParser->parse( join("\n", @single ) ) ) or
    405                 print STDERR "Unable to parse metdata config doc" and return undef;
    406             push @$output, $list->[0];
    407 
    408             @single = ();
    409         }
    410     }
    411     return $output;
    412 }
    413 sub faultJobs {
    414     my ($state, $stage, $stage_id, $job_fault) = @_;
    415 
    416     my $command = "$pstamptool -updatejob -state stop -fault $job_fault -dep_id $dep_id";
     589sub my_die
     590{
     591    my $msg = shift;
     592    my $fault = shift;
     593    carp $msg;
     594
     595    my $command = "$pstamptool -updatedepedent -fault $fault -dep_id $dep_id";
    417596    $command .= " -dbname $dbname" if $dbname;
    418597    $command .= " -dbserver $dbserver" if $dbserver;
     
    421600                    run(command => $command, verbose => $verbose);
    422601        unless ($success) {
    423             my_die("failed to set pstamJob.fault for dep_id: $dep_id",
     602            my_die("failed to set pstampDependent.fault for dep_id: $dep_id",
    424603                $PS_EXIT_UNKNOWN_ERROR);
    425604        }
     
    427606        print "skipping $command\n";
    428607    }
    429 }
    430 
    431 sub my_die
    432 {
    433     my $msg = shift;
    434     my $fault = shift;
    435 
    436     carp $msg;
    437 
    438     return $fault;
    439 }
     608
     609    exit $fault;
     610}
Note: See TracChangeset for help on using the changeset viewer.