IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 11036


Ignore:
Timestamp:
Jan 11, 2007, 12:13:36 PM (19 years ago)
Author:
eugene
Message:

add exit codes, fault code setting

Location:
trunk/ippScripts/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/phase0_exp.pl

    r10625 r11036  
    1414use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    1515use Pod::Usage qw( pod2usage );
     16
     17use PS::IPP::Config qw(
     18    $PS_EXIT_SUCCESS
     19    $PS_EXIT_UNKNOWN_ERROR
     20    $PS_EXIT_SYS_ERROR
     21    $PS_EXIT_CONFIG_ERROR
     22    $PS_EXIT_PROG_ERROR
     23    $PS_EXIT_DATA_ERROR
     24    $PS_EXIT_TIMEOUT_ERROR
     25    );
    1626
    1727my ($cache, $exptag, $no_update);
     
    6777my $ppStats = can_run('ppStats')
    6878    or (warn "can't find ppStats" and $missing_tools = 1);
    69 die "Can't find required tools.\n" if $missing_tools;
     79if ($missing_tools) {
     80    warn ("Can't find required tools");
     81    &my_die ("", $PS_EXIT_CONFIG_ERROR);
     82}
    7083
    7184# setup cache interface
     
    8497    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    8598        cache_run(command => $command, verbose => 1);
    86     die "Unable to perform p0tool on exposure id $exptag: $error_code\n" if not $success;
    87     my $metadata = $mdcParser->parse(join "", @$stdout_buf)
    88             or die "unable to parse metadata config doc";
     99    unless ($success) {
     100        warn ("Unable to perform p0tool on exposure id $exptag: $error_code");
     101        &my_die ($exptag, $error_code);
     102    }
     103
     104    my $metadata = $mdcParser->parse(join "", @$stdout_buf);
     105    unless ($metadata) {
     106        warn ("Unable to parse metadata config doc");
     107        &my_die ($exptag, $PS_EXIT_PROG_ERROR);
     108    }
    89109    $imfiles = parse_md_list($metadata); # Data for imfiles
    90110}
     
    104124        if (not defined $values{$constant}) {
    105125            $values{$constant} = $value;
    106         } elsif ($values{$constant} ne $value) {
    107             die "Value of $constant for " . $imfile->{PHASE0_CLASSID} .
    108                 " doesn't match previous value.\n";
     126        }
     127        if ($values{$constant} ne $value) {
     128            warn ("Value of $constant for $imfile->{PHASE0_CLASSID} doesn't match previous value");
     129            &my_die ($exptag, $PS_EXIT_PROG_ERROR);
    109130        }
    110131    }
     
    121142    my $stdev = get_value($imfile, PHASE0_BG_MEAN_STDEV());
    122143    push @variances, $stdev**2;
     144}
     145
     146# XXX for a test, randomly declare a failure and return to pantasks
     147my $rnd = rand(1);
     148if ($rnd > 0.5) {
     149    warn ("random failure");
     150    &my_die ($exptag, $PS_EXIT_DATA_ERROR);
    123151}
    124152
     
    169197    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    170198        cache_run(command => \@command, verbose => 1);
    171     die "Unable to run phase0 update for $exptag: $error_code\n" if not $success;
     199    unless ($success) {
     200        warn ("Unable to run phase0 update for $exptag: $error_code");
     201        &my_die ($exptag, $error_code);
     202    }
    172203}
    173204
    174205### Pau.
    175 
    176206
    177207# Get the value for a particular imfile, along with a strong check for its existence
     
    181211
    182212    my $source = $imfile->{PHASE0_CLASSID()}; # Where it comes from
    183     die "Couldn't find value of $name for class_id=$source\n" if not defined $imfile->{$name};
     213
     214    unless (defined $imfile->{$name}) {
     215        warn ("Couldn't find value of $name for class_id=$source");
     216        &my_die ($exptag, $PS_EXIT_PROG_ERROR);
     217    }
    184218    return $imfile->{$name};
    185219}
     
    199233}
    200234
     235sub my_die
     236{
     237    my $exp_tag = $_[0];
     238    my $exit_code = $_[1];
     239    if ($exp_tag) {
     240        system ("$p0tool -faultexp -exp_tag $exp_tag -code $exit_code");
     241    }
     242    exit $exit_code;
     243}
     244
    201245END {
    202246    my $exit = $?;
     
    204248    $? = $exit;
    205249}
    206 
  • trunk/ippScripts/scripts/phase0_imfile.pl

    r10625 r11036  
    1515use Data::Dumper;
    1616
    17 use PS::IPP::Config;
     17use PS::IPP::Config qw(
     18    $PS_EXIT_SUCCESS
     19    $PS_EXIT_UNKNOWN_ERROR
     20    $PS_EXIT_SYS_ERROR
     21    $PS_EXIT_CONFIG_ERROR
     22    $PS_EXIT_PROG_ERROR
     23    $PS_EXIT_DATA_ERROR
     24    $PS_EXIT_TIMEOUT_ERROR
     25    );
     26
    1827my $ipprc = PS::IPP::Config->new(); # IPP configuration
    1928use File::Spec;
     
    4049    and defined $uri;
    4150
    42 use constant RECIPE => "PPSTATS_PHASE0"; # Recipe to use for ppStats
     51my $RECIPE = "PPSTATS_PHASE0"; # Recipe to use for ppStats
     52# use constant RECIPE => "PPSTATS_PHASE0"; # Recipe to use for ppStats
    4353
    4454# These values should be constant for all components
     
    7787my $p0tool = can_run('p0tool') or (warn "Can't find p0tool" and $missing_tools = 1);
    7888my $ppStats = can_run('ppStats') or (warn "Can't find ppStats" and $missing_tools = 1);
    79 die "Can't find required tools.\n" if $missing_tools;
     89
     90if ($missing_tools) {
     91    warn ("Can't find required tools");
     92    &my_die ("", "", $PS_EXIT_CONFIG_ERROR);
     93}
    8094
    8195# setup cache interface
     
    92106my $stats;
    93107{
    94     my $command = "$ppStats $uri -recipe PPSTATS " . RECIPE; # Command to run ppStats
     108    my $command = "$ppStats $uri -recipe PPSTATS $RECIPE"; # Command to run ppStats
    95109    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    96110        cache_run(command => $command, verbose => 1);
    97     die "Unable to perform ppStats on exposure id $exp_tag: $error_code\n"
    98         if not $success;
     111    unless ($success) {
     112        warn ("Unable to perform ppStats on exposure id $exp_tag: $error_code");
     113        &my_die ($exp_tag, $class_id, $error_code);
     114    }
    99115   
    100116    # Parse the output
    101117    my $mdcParser = PS::IPP::Metadata::Config->new;        # Parser for metadata config files
    102     my $metadata = $mdcParser->parse(join "", @$stdout_buf)
    103             or die "unable to parse metadata config doc";
     118    my $metadata = $mdcParser->parse(join "", @$stdout_buf); # XXX is this join necessary?
     119    unless ($metadata) {
     120        warn ("Unable to parse metadata config doc");
     121        &my_die ($exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
     122    }
    104123    my @constants = keys %{CONSTANTS()}; # List of constants to parse out
    105124    my @variables = keys %{VARIABLES()}; # List of variables to parse out
    106125    $stats = PS::IPP::Metadata::Stats->new(\@constants, \@variables); # Stats parser
    107     $stats->parse($metadata) or die "Unable to find all values.\n";
     126    unless ($stats->parse($metadata)) {
     127        warn ("Unable to find all values");
     128        &my_die ($exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
     129        # XXX is this a programming or a config error?
     130    }
     131 
     132    # XXX for a test, randomly declare a failure and return to pantasks
     133    my $rnd = rand(1);
     134    if ($rnd > 0.5) {
     135        warn ("random failure");
     136        &my_die ($exp_tag, $class_id, $PS_EXIT_DATA_ERROR);
     137    }
    108138}
    109139
     
    151181    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    152182        run(command => \@command, verbose => 1);
    153     die "Unable to perform p0tool -updateimfile: $error_code\n" if not $success;
     183
     184    unless ($success) {
     185        # XXX this is tricky: if we can't run -updateimfile, can we actually set the error code?
     186        # XXX if this is not a database error, it is probably a programming error (in p0tool or the passed args)
     187        warn ("Unable to perform p0tool -updateimfile: $error_code");
     188        &my_die ($exp_tag, $class_id, $error_code);
     189    }
    154190}
    155191
     
    166202        return @output;
    167203    }
     204}
     205
     206sub my_die
     207{
     208    my $exp_tag = $_[0];
     209    my $class_id = $_[1];
     210    my $exit_code = $_[2];
     211    if ($exp_tag && $class_id) {
     212        system ("$p0tool -faultimfile -exp_tag $exp_tag -class_id $class_id -code $exit_code");
     213    }
     214    exit $exit_code;
    168215}
    169216
Note: See TracChangeset for help on using the changeset viewer.