IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 18, 2010, 11:44:34 AM (16 years ago)
Author:
bills
Message:

Fix dsreg error reporting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DataStoreServer/scripts/dsreg

    r28800 r29478  
    4242
    4343my $dbname;         # Database name
     44my $dbserver;       # Database host
    4445my $dsroot;         # root directory of the data store
    4546
     
    8283        'ps7=s'         =>      \$ps7,
    8384        'dbname=s'      =>      \$dbname,
     85        'dbserver=s'    =>      \$dbserver,
     86        'ds_dbname=s'   =>      \$dbname,       # some scripts use these names
     87        'ds_dbserver=s' =>      \$dbserver,
    8488        'dsroot=s'      =>      \$dsroot,
    8589        'verbose'       =>      \$verbose,
    8690) or pod2usage(2);
    8791
     92pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
     93
     94# collect all command line argument errors and only fail once below.
    8895my $err = "";
    8996
     
    121128    $dsroot = metadataLookupStr($ipprc->{_siteConfig}, 'DATA_STORE_ROOT');
    122129    if (!$dsroot) {
    123         die("Data Store root directory not set");
    124     }
    125 }
    126 
     130        &my_die("Data Store root directory not set", $PS_EXIT_CONFIG_ERROR);
     131    }
     132}
    127133
    128134if (!stat("$dsroot/index.txt")) {
     
    131137
    132138# bail if any errors above
    133 show_usage($err)
    134     if ($err);
    135 
    136 show_usage("Invalid product '$product'.")
     139show_usage($err) if ($err);
     140
     141show_usage("Invalid data store product '$product'.")
    137142    unless defined stat("$dsroot/$product/index.txt");
    138143
    139144$dbname      = metadataLookupStr($siteConfig, 'DS_DBNAME') unless defined $dbname;
    140 my $dbserver = metadataLookupStr($siteConfig, 'DS_DBSERVER');
     145$dbserver    = metadataLookupStr($siteConfig, 'DS_DBSERVER') unless defined $dbserver;
    141146my $dbuser   = metadataLookupStr($siteConfig, 'DS_DBUSER');
    142147my $dbpass   = metadataLookupStr($siteConfig, 'DS_DBPASSWORD');
     
    148153
    149154my $dbh = DBI->connect_cached($dsn, $dbuser, $dbpass, \%conn_attrs)
    150         or die "Cannot connect to DB server\n";
     155        or &my_die("Cannot connect to DB server\n", $PS_EXIT_SYS_ERROR);
    151156
    152157print STDERR "dbh: $dbh\n" if $verbose;
     
    161166
    162167    my $stmt = $dbh->prepare("SELECT prod_id, last_fs FROM dsProduct WHERE prod_name = ?");
    163     $stmt->execute($product);
     168    my $execute_status = $stmt->execute($product);
     169    if (!$execute_status) {
     170        print STDERR "failed to execute product lookup\n";
     171        exit 2;
     172    }
    164173
    165174    my $prod_row = $stmt->fetchrow_hashref();
     
    228237        my $rc;
    229238        if (($rc = system "rm -r $fileset_dir")) {
    230             die("failed to remove $fileset_dir error code: $rc");
     239            &my_die("failed to remove $fileset_dir error code: $rc", $PS_EXIT_UNKNOWN_ERROR);
    231240        }
    232241    } else  {
     
    252261
    253262    if (!$prod_id) {
    254         die("product $product not found");
     263        &my_die("product $product not found", $PS_EXIT_UNKNOWN_ERROR);
    255264    }
    256265    my $count = $dbh->do("SELECT fileset_id FROM dsFileset WHERE fileset_name = ?" .
     
    268277    if (! -e $fileset_dir) {
    269278        if (!mkdir $fileset_dir) {
    270             die("failed trying to create fileset directory $fileset_dir");
     279            &my_die("failed trying to create fileset directory $fileset_dir", $PS_EXIT_SYS_ERROR);
    271280        }
    272281        if (! -d $fileset_dir ) {
    273             die("cannot access just created fileset directory $fileset_dir");
     282            &my_die("cannot access just created fileset directory $fileset_dir", $PS_EXIT_SYS_ERROR);
    274283        }
    275284    }
     
    281290            $in = *STDIN;
    282291        } else {
    283             open $in, "<$filelist" or die  "cannot open filelist file $filelist\n";
     292            open $in, "<$filelist" or &my_die("cannot open filelist file $filelist\n", $PS_EXIT_UNKNOWN_ERROR);
    284293        }
    285294
     
    296305            my @fields = split /\|/;
    297306            if (@fields < 4) {
    298                 die "malformed input line at $filelist line $lineno: $_\n";
     307                &my_die("malformed input line at $filelist line $lineno: $_\n", $PS_EXIT_PROG_ERROR);
    299308            }
    300309            $filename = shift @fields;
     
    320329        }
    321330
    322         die("empty filelist\n") if (@files == 0);
     331        &my_die("empty filelist\n", $PS_EXIT_PROG_ERROR) if (@files == 0);
    323332
    324333        # Prepare the fileset directory
     
    350359                    } else {
    351360                        if (!copy($src, $dest)) {
    352                             die("copy($src, $dest) failed");
     361                            &my_die("copy($src, $dest) failed", $PS_EXIT_UNKNOWN_ERROR);
    353362                        }
    354363                    }
     
    359368
    360369                if (!$no_cleanup && system "rm -r $fileset_dir") {
    361                     die("failed to remove $fileset_dir");
     370                    &my_die("failed to remove $fileset_dir", $PS_EXIT_UNKNOWN_ERROR);
    362371                }
    363372                exit $PS_EXIT_UNKNOWN_ERROR;
     
    370379            my $path = "$fileset_dir/$filename";
    371380            if (! -e $path ) {
    372                 die "file $path not found";
     381                &my_die("file $path not found", , $PS_EXIT_UNKNOWN_ERROR);
    373382            }
    374383            # get the size of the file
    375384            my @finfo = stat($path);
    376385            unless (@finfo) {
    377                 die ("can't stat $path");
     386                &my_die ("can't stat $path", $PS_EXIT_UNKNOWN_ERROR);
    378387            }
    379388            # if size was supplied make sure that it matches the actual
     
    382391                my $current_size = $finfo[7];
    383392                if ($file->{bytes} != $current_size) {
    384                     die "size on disk: $current_size does not match supplied"
    385                     . " size: $file->{bytes} for $path";
     393                    &my_die("size on disk: $current_size does not match supplied"
     394                    . " size: $file->{bytes} for $path", $PS_EXIT_PROG_ERROR);
    386395                }
    387396            } else {
     
    391400                # Get MD5 sum
    392401                $file->{md5sum} = file_md5_hex($path);
    393                 die("failed to compute valid md5sum for $path") if !$file->{md5sum};
     402                &my_die("failed to compute valid md5sum for $path", $PS_EXIT_UNKNOWN_ERROR) if !$file->{md5sum};
    394403            }
    395404        }
     
    401410        $dbh->disconnect();
    402411        $dbh = DBI->connect_cached($dsn, $dbuser, $dbpass, \%conn_attrs)
    403             or die "Cannot connect to server\n";
     412            or &my_die("Cannot connect to server\n", $PS_EXIT_SYS_ERROR);
    404413        print STDERR "ping failed new dbh: $dbh\n" if $verbose;
    405414    }
     
    415424                            $ps0, $ps1, $ps2, $ps3, $ps4, $ps5, $ps6, $ps7));
    416425
    417         die("failed to insert $fileset") if (!defined($count) or ($count == 0E0));
     426        &my_die("failed to insert $fileset", $PS_EXIT_UNKNOWN_ERROR) if (!defined($count) or ($count == 0E0));
    418427
    419428        # I don't use last_insert_id() because I've seen some problems with it and
     
    423432        my $nfs = @fsids;
    424433        if (!$nfs) {
    425             die("fileset '$fileset' missing even though we just added it");
     434            &my_die("fileset '$fileset' missing even though we just added it", $PS_EXIT_UNKNOWN_ERROR);
    426435        } elsif ($nfs > 1) {
    427             die("Fileset '$fileset' already exists under $product.");
     436            &my_die("Fileset '$fileset' already exists under $product.", $PS_EXIT_PROG_ERROR);
    428437        }
    429438        my $fileset_id = $fsids[0];
     
    443452
    444453            if ($count == 0E0) {
    445                 die("failed to insert $filename into $fileset");
     454                &my_die("failed to insert $filename into $fileset", $PS_EXIT_UNKNOWN_ERROR);
    446455            }
    447456        }
     
    450459                                . " WHERE prod_id = $prod_id");
    451460        if ($count == 0E0) {
    452             die("failed to update dsProduct $prod_id");
     461            &my_die("failed to update dsProduct $prod_id", $PS_EXIT_UNKNOWN_ERROR);
    453462        }
    454463
     
    457466        # create the cgi script index.txt by making a copy of its parent's
    458467        if (!copy("$dsroot/$product/index.txt", $index_script_name)) {
    459             die("failed to copy index script to file set");
     468            &my_die("failed to copy index script to file set", $PS_EXIT_UNKNOWN_ERROR);
    460469        }
    461470    };
     
    531540    }
    532541}
     542
     543sub my_die {
     544    my $msg = shift;
     545    my $fault = shift;
     546    carp $msg;
     547    exit $fault;
     548}
Note: See TracChangeset for help on using the changeset viewer.