IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 26, 2009, 1:59:32 PM (17 years ago)
Author:
beaumont
Message:

merged with trunk

Location:
branches/cnb_branches/cnb_branch_20090301
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/cnb_branches/cnb_branch_20090301

  • branches/cnb_branches/cnb_branch_20090301/DataStoreServer/scripts/dsreg

    r20293 r24244  
    3131my $fileset;
    3232my $filelist;
     33my $empty;
    3334
    3435my $fstype;
     
    6465        'product=s'     =>      \$product,
    6566        'list=s'        =>      \$filelist,
     67        'empty'         =>      \$empty,
    6668        'type=s'        =>      \$fstype,
    6769        'datapath=s'    =>      \$datapath,
     
    9597    $fileset = $add;
    9698    $err .= "--type is required\n" unless defined $fstype;
    97     $err .= "--list is required\n" unless defined $filelist;
     99    $err .= "--list is required\n" unless defined $filelist or $empty;
    98100    if ($linkfiles and $copyfiles) {
    99101        $err .= "only one of --link and --copy is allowed\n";
    100102    }
    101103    if (($linkfiles or $copyfiles) and !$datapath and !$abspath) {
    102         $err .= "need to specify datapath with --link or --copy\n";
    103     }
    104     if ($linkfiles && (substr($datapath, 0, 1) ne "/")) {
     104        $err .= "need to specify datapath or abspath with --link and --copy\n";
     105    }
     106    if (!$abspath && $linkfiles && (substr($datapath, 0, 1) ne "/")) {
    105107        $err .= "datapath must begin with / when using --link\n";
    106108    }
     
    135137    unless defined stat("$dsroot/$product/index.txt");
    136138
    137 $dbname      = metadataLookupStr($siteConfig, 'DBNAME') unless defined $dbname;
    138 my $dbserver = metadataLookupStr($siteConfig, 'DBSERVER');
    139 my $dbuser   = metadataLookupStr($siteConfig, 'DBUSER');
    140 my $dbpass   = metadataLookupStr($siteConfig, 'DBPASSWORD');
     139$dbname      = metadataLookupStr($siteConfig, 'DS_DBNAME') unless defined $dbname;
     140my $dbserver = metadataLookupStr($siteConfig, 'DS_DBSERVER');
     141my $dbuser   = metadataLookupStr($siteConfig, 'DS_DBUSER');
     142my $dbpass   = metadataLookupStr($siteConfig, 'DS_DBPASSWORD');
    141143exit ($PS_EXIT_CONFIG_ERROR) unless defined $dbserver and $dbname and $dbuser and $dbpass;
    142144
    143145my $dsn = "DBI:mysql:host=$dbserver;database=$dbname";
    144 my %conn_attrs = (PrintError => 1, RaiseError => 1, AutoCommit => 0);
     146# mysql cookbook says 'PrintError can interfere with failure detection in some cases'
     147my %conn_attrs = (PrintError => 0, RaiseError => 1, AutoCommit => 0);
    145148
    146149my $dbh = DBI->connect_cached($dsn, $dbuser, $dbpass, \%conn_attrs)
     
    209212    if ($@) { # an error occured
    210213        print STDERR "transaction failed, rolling back error was:\n$@\n";
     214        # roll back within eval to prevent rollback failure from terminating the script
    211215        eval {$dbh->rollback();};
    212216        cleanup();
     
    251255    }
    252256
     257
    253258    # Note: There is a race condition here. Somebody could sneak in now and add a fileset with
    254259    # fileset_name = $fileset. So later we'll check again that only one fileset with the name exists
    255260
    256 
    257     my $in;
    258     if ($filelist eq "-") {
    259         $in = *STDIN;
    260     } else {
    261         open $in, "<$filelist" or die  "cannot open filelist file $filelist\n";
    262     }
    263 
    264     my $lineno = 0;
     261    ## create the fileset directory
     262    if (! -e $fileset_dir) {
     263        if (!mkdir $fileset_dir) {
     264            die("failed trying to create fileset directory $fileset_dir");
     265        }
     266    }
     267
    265268    my @files;
    266     while (<$in>) {
    267         chomp;
    268         $lineno++;
    269 
    270         my $filename;
    271         my $bytes;
    272         my $md5sum;
    273         my $filetype;
    274 
    275         my @fields = split /\|/;
    276         if (@fields < 4) {
    277             die "malformed input line at $filelist line $lineno: $_\n";
    278         }
    279         $filename = shift @fields;
    280         $bytes    = shift @fields;  # if this is null it will be calculated below
    281         $md5sum   = shift @fields;  # if this is null it will be calculated below
    282         $filetype = shift @fields;
    283 
    284         # make sure the length of the type specific columns is 8
    285         while (@fields < 8) {
    286             push @fields, undef;
    287         }
    288         my $ts_cols = [@fields];
    289 
    290         my $hashref = {
    291             'file'      => $filename,
    292             'bytes'     => $bytes,
    293             'md5sum'    => $md5sum,
    294             'type'      => $filetype,
    295             'ts_cols'   => $ts_cols,
    296         };
    297 
    298         push @files, $hashref;
    299     }
    300 
    301     die("empty filelist\n") if (@files == 0);
    302 
    303     # Prepare the fileset directory
    304     if ($linkfiles or $copyfiles) {
    305         ## create the fileset directory
    306         if (! -e $fileset_dir) {
    307             if (!mkdir $fileset_dir) {
    308                 die("failed trying to create fileset directory $fileset_dir");
    309             }
    310         }
    311         eval {
    312             ## then copy or symlink the files into place
    313             foreach my $ref (@files) {
    314                 my $src = (defined $abspath ? '' : "$datapath/") . "$ref->{file}";
    315                 my $filename = fileparse($ref->{file}, ());
    316                 my $dest = "$fileset_dir/$filename";
    317 
    318                 if ($linkfiles) {
    319                     if (! symlink $src, $dest) {
    320                         die("failed trying to link $src to $dest");
    321                     }
    322                 } else {
    323                     if (!copy($src, $dest)) {
    324                         die("copy($src, $dest) failed");
     269    if (!$empty) {
     270        my $in;
     271        if ($filelist eq "-") {
     272            $in = *STDIN;
     273        } else {
     274            open $in, "<$filelist" or die  "cannot open filelist file $filelist\n";
     275        }
     276
     277        my $lineno = 0;
     278        while (<$in>) {
     279            chomp;
     280            $lineno++;
     281
     282            my $filename;
     283            my $bytes;
     284            my $md5sum;
     285            my $filetype;
     286
     287            my @fields = split /\|/;
     288            if (@fields < 4) {
     289                die "malformed input line at $filelist line $lineno: $_\n";
     290            }
     291            $filename = shift @fields;
     292            $bytes    = shift @fields;  # if this is null it will be calculated below
     293            $md5sum   = shift @fields;  # if this is null it will be calculated below
     294            $filetype = shift @fields;
     295
     296            # make sure the length of the type specific columns is 8
     297            while (@fields < 8) {
     298                push @fields, undef;
     299            }
     300            my $ts_cols = [@fields];
     301
     302            my $hashref = {
     303                'file'      => $filename,
     304                'bytes'     => $bytes,
     305                'md5sum'    => $md5sum,
     306                'type'      => $filetype,
     307                'ts_cols'   => $ts_cols,
     308            };
     309
     310            push @files, $hashref;
     311        }
     312
     313        die("empty filelist\n") if (@files == 0);
     314
     315        # Prepare the fileset directory
     316        if ($linkfiles or $copyfiles) {
     317            eval {
     318                ## then copy or symlink the files into place
     319                foreach my $ref (@files) {
     320                    my $src = (defined $abspath ? '' : "$datapath/") . "$ref->{file}";
     321                    my $filename = fileparse($ref->{file}, ());
     322                    my $dest = "$fileset_dir/$filename";
     323
     324                    if ($linkfiles) {
     325                        if (! symlink $src, $dest) {
     326                            die("failed trying to link $src to $dest");
     327                        }
     328                    } else {
     329                        if (!copy($src, $dest)) {
     330                            die("copy($src, $dest) failed");
     331                        }
    325332                    }
    326333                }
    327             }
    328         };
    329         if ($@) { # an error occured
    330             print STDERR "error preparing the fileset directory: $@\n";
    331 
    332             if (!$no_cleanup && system "rm -r $fileset_dir") {
    333                 die("failed to remove $fileset_dir");
    334             }
    335             exit $PS_EXIT_UNKNOWN_ERROR;
    336         }
    337     }
    338 
    339     # now calculate the md5sum and file size if they weren't provided
    340     foreach my $file (@files) {
    341         my $filename = fileparse($file->{file}, ());
    342         my $path = "$fileset_dir/$filename";
    343         if (! -e $path ) {
    344             die "file $path not found";
    345         }
    346         if (!$file->{bytes}) {
    347             my @finfo = stat($path);
    348             unless (@finfo) {
    349                 die ("can't stat $path");
    350             }
    351             $file->{bytes}  = $finfo[7];
    352         }
    353         if (!$file->{md5sum}) {
    354             # Get MD5 sum
    355             $file->{md5sum} = file_md5_hex($path);
     334            };
     335            if ($@) { # an error occured
     336                print STDERR "error preparing the fileset directory: $@\n";
     337
     338                if (!$no_cleanup && system "rm -r $fileset_dir") {
     339                    die("failed to remove $fileset_dir");
     340                }
     341                exit $PS_EXIT_UNKNOWN_ERROR;
     342            }
     343        }
     344
     345        # now calculate the md5sum and file size if they weren't provided
     346        foreach my $file (@files) {
     347            my $filename = fileparse($file->{file}, ());
     348            my $path = "$fileset_dir/$filename";
     349            if (! -e $path ) {
     350                die "file $path not found";
     351            }
     352            if (!$file->{bytes}) {
     353                my @finfo = stat($path);
     354                unless (@finfo) {
     355                    die ("can't stat $path");
     356                }
     357                $file->{bytes}  = $finfo[7];
     358            }
     359            if (!$file->{md5sum}) {
     360                # Get MD5 sum
     361                $file->{md5sum} = file_md5_hex($path);
     362            }
    356363        }
    357364    }
     
    471478    --copy      Copy files from datapath to Data Store
    472479    --datapath  path to source files for --copy or --link
     480    --abspath   path to source files is absoloute (--datapath not needed)
    473481    --ps0 - ps7 Optional product specific data
    474482    --rm        with --del remove the fileset directory from the Data Store
Note: See TracChangeset for help on using the changeset viewer.