IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 39581


Ignore:
Timestamp:
May 27, 2016, 10:21:16 AM (10 years ago)
Author:
bills
Message:

Added options to specify the age of filesets that should be preserved by cleanup.
The first is --retention-days. Filesets registered that many days ago or older will be
cleaned up.
A second option --use-configured-publish-retention is a flag tells the script to go find
the number of days in the siteConfig if it wasn't supplied in the arguments.
If it is not found in the siteConfig the script dies.

I also removed the hard coded value for data store url from the code and require
it to be found in the siteConfig.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/cleandsproduct.pl

    r35328 r39581  
    1919use PS::IPP::Metadata::List qw( parse_md_list );
    2020
     21use Date::Parse;
     22
    2123use PS::IPP::Config 1.01 qw( :standard );
    2224
     
    3739my ($product, $datastore, $last_fileset, $keep_files, $verbose);
    3840
     41# If supplied, retention_days is the number of days that filesets in a data store will be preserved.
     42# The use_configured_publish_retention_days option tells us to get retention_days from the site config.
     43# The later is only used if retention-days is not supplied in the options.
     44# NOTE: if last_fileset is also given, clean up will stop after that fileset irrespective of whether
     45# subsequent filesets are older than the retention time.
     46
     47my ($retention_days, $use_publish_retention_days);
     48
    3949# Parse the command-line arguments
    4050GetOptions(
    41            'product=s'      => \$product,      #product name
    42            'datastore=s'    => \$datastore,     #datastore uri
     51           'product=s'      => \$product,      # product name
     52           'datastore=s'    => \$datastore,    # datastore uri
    4353           'last_fileset=s' => \$last_fileset, # last fileset to delete
    44            'no_rm'          => \$keep_files, # last fileset to delete
    45            'verbose'        => \$verbose,    # Print stuff?
     54           'last-fileset=s' => \$last_fileset, # more modern spelling for last option
     55           'retention-days=s'   => \$retention_days, # see above
     56           'use-configured-publish-retention' => \$use_publish_retention_days, #see above
     57           'no_rm'          => \$keep_files,   # remove fileset but leave files in place
     58           'no-rm'          => \$keep_files,   # more modern spelling for last option
     59           'verbose'        => \$verbose,      # Print stuff?
    4660           ) or pod2usage( 2 );
    4761
     
    5266
    5367
    54 
    55 # since this needs to run on the MHPCC cluster there is no need to go to the
    56 # proxy to get the datastore listing
    57 $datastore = "http://ippc17/ds" if !$datastore;
    58 # $datastore = "http://datastore.ipp.ifa.hawaii.edu" if !$datastore;
     68if (!$datastore) {
     69    $datastore = metadataLookupStr($ipprc->{_siteConfig}, "DATA_STORE_ROOT_URL");
     70    die ("Unable to find DATA_STORE_ROOT_URL in siteConfig\n") unless $datastore;
     71}
    5972
    6073my $uri = "$datastore/$product/index.txt";
    6174
     75# XXX: I'm not sure why this bracket is here
    6276{
    6377    my $command = "$dsproductls --uri $uri --extra --timeout 150";
     
    7791    }
    7892
     93    # if retention_days is specified, use that. Otherwise if requested use the publish config value from the siteConfig
     94    if (!$retention_days and $use_publish_retention_days) {
     95        $retention_days = metadataLookupS32($ipprc->{_siteConfig}, "DATA_STORE_PUBLISH_RETENTION_DAYS");
     96        die ("required value DATA_STORE_PUBLISH_RETENTION_DAYS not found in siteConfig\n") unless defined $retention_days;
     97    }
     98
     99    # if $retention_days is set we are to clean only filesets registered before
     100    # that date/time. Convert the limit to seconds.
     101    my $clean_before;
     102    if ($retention_days) {
     103        $clean_before = time() - $retention_days * 86400;
     104    }
     105
    79106    foreach my $line (@lines) {
    80107        chomp $line;
     
    82109
    83110        my ($fsuri, $fs_name, $registered, $fs_type, $target_id, $stage, $stage_id) = split " ", $line;
     111
     112        if ($clean_before) {
     113            # registered is in the format YYYY-MM-DDTHH:MM:SSZ. Date::Parse::str2time handles this.
     114            my $ticks = str2time($registered);
     115            if ($ticks > $clean_before) {
     116                # This fileset and therefore subsequent ones in the list was registered after our end
     117                # date. We're done.
     118                last;
     119            }
     120        }
    84121
    85122        $command = "$dsreg --del $fs_name --product $product";
     
    96133        last if $last_fileset and ($fs_name eq $last_fileset);
    97134    }
    98 
    99 
    100135}
    101136
Note: See TracChangeset for help on using the changeset viewer.