IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24996


Ignore:
Timestamp:
Aug 4, 2009, 11:42:45 AM (17 years ago)
Author:
jhoblitt
Message:

add neb-cull --one_only flag

Location:
trunk/Nebulous
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous/Changes

    r24930 r24996  
    88    - add Nebulous::Client->prune() method
    99    - add Nebulous::Client->there_can_be_only_one() method
     10    - add neb-cull --one_only flag
    1011
    11120.10
  • trunk/Nebulous/MANIFEST

    r24930 r24996  
    102102t/70_neb-ls.t
    103103t/71_client_there_can_be_only_one.t
     104t/72_neb-cull.t
    104105t/90_nebclient.t
    105106t/TEST.PL
  • trunk/Nebulous/bin/neb-cull

    r16183 r24996  
    1616use Pod::Usage qw( pod2usage );
    1717
    18 my ($server, $volume);
     18my ($server, $volume, $one_only);
    1919
    2020$server = $ENV{'NEB_SERVER'} unless $server;
     
    2323    'server|s=s'    => \$server,
    2424    'volume|v=s'    => \$volume,
     25    'one_only|o'    => \$one_only,
    2526) || pod2usage( 2 );
    2627
     
    4041    unless defined $neb;
    4142
     43my @cull_args;   
     44push @cull_args, $key;
    4245if (defined $volume) {
    43     $neb->cull($key, $volume)
    44         or die "failed to replicate Nebulous key: $key";
     46    push @cull_args, $volume;
     47}
     48
     49if ($one_only) {
     50    my $status = $neb->there_can_be_only_one(@cull_args);
     51    if ($status == 0) {
     52        die "not enough instances of Nebulous key: $key";
     53    }
     54    if (not defined $status or $status < 1) {
     55        die "failed to cull Nebulous key: $key - " . $neb->err
     56            if defined $neb->err;
     57        die "failed to cull Nebulous key: $key";
     58    }
    4559} else {
    46     $neb->cull($key)
    47         or die "failed to replicate Nebulous key: $key";
     60    unless (defined $neb->cull(@cull_args)) {
     61        die "failed to cull Nebulous key: $key - " . $neb->err;
     62    }
    4863}
    4964
     
    5873=head1 SYNOPSIS
    5974
    60     neb-cull [--server <URL>] [--volume <volume name>] <key>
     75    neb-cull [--server <URL>] [--volume <volume name>] [--one_only] <key>
    6176
    6277=head1 DESCRIPTION
     
    7792
    7893Symbolic name of the volume to create the new instance on.
     94
     95Optional.
     96
     97=item * --one_only|-o
     98
     99Removes all but one instances of an object.  Any inaccessible instances are
     100removed.  If C<--volume> is specified, and an instance exists on that volume,
     101all instances but the one on that volume are removed.
    79102
    80103Optional.
     
    110133=head1 COPYRIGHT
    111134
    112 Copyright (C) 2007-2008  Joshua Hoblitt.  All rights reserved.
     135Copyright (C) 2007-2009  Joshua Hoblitt.  All rights reserved.
    113136
    114137This program is free software; you can redistribute it and/or modify it under
  • trunk/Nebulous/lib/Nebulous/Client.pm

    r24930 r24996  
    297297        my $instances = $stats[6];
    298298        if (defined $instances and $instances < 2) {
    299             $log->debug("can not cull - not enough instances");
     299            $self->set_err("can not cull - not enough instances");
    300300            $log->debug("leaving");
    301301
     
    305305        $locations = $self->find_instances($key, $vol_name);
    306306        unless (defined $locations) {
    307             $log->debug( "no instances" );
     307            $self->set_err( "no instances" );
    308308            $log->debug( "leaving" );
    309309
     
    313313        $locations = $self->find_instances($key);
    314314        unless ($locations) {
    315             $log->debug("no instances");
     315            $self->set_err( "no instances" );
    316316            $log->debug("leaving");
    317317
     
    320320
    321321        if (scalar @{ $locations } < 2) {
    322             $log->debug("can not cull - not enough instances");
     322            $self->set_err("can not cull - not enough instances");
    323323            $log->debug("leaving");
    324324
     
    365365        if (not defined $self->prune($key)) {
    366366            # use the prune() method to also determine if $key is valid
    367             $removed = undef;
    368             return;
     367            die "invalid key: $key";
    369368        }
    370369
     
    377376        if (defined $locations) {
    378377            my $instances = $self->find_instances($key);
     378            if (scalar @$instances < 2) {
     379                die "not enough instances";
     380            }
    379381            foreach my $victim (@$instances) {
    380382                next if $victim eq $locations->[0];
     
    387389            # start at one so cull() is called one less time then the # of
    388390            # instances
     391            if ($stats->[6] < 2) {
     392                die "not enough instances";
     393            }
    389394            for (my $i = 1; $i < $stats->[6]; $i++) {
    390395                $self->cull($key);
     
    395400    };
    396401    if ($@) {
     402        if ($@ =~ qr/invalid key/) {
     403            $self->set_err($@);
     404            return;
     405        }
    397406        $log->logdie($@);
    398407    }
Note: See TracChangeset for help on using the changeset viewer.