IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 25146


Ignore:
Timestamp:
Aug 20, 2009, 11:14:18 AM (17 years ago)
Author:
watersc1
Message:
 
Location:
branches/czw_branch/cleanup/Nebulous
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/cleanup/Nebulous/bin/neb-cull

    r25051 r25146  
    1616use Pod::Usage qw( pod2usage );
    1717
    18 my ($server, $volume, $one_only);
     18my ($min_copies, $server, $volume, $one_only);
    1919
    2020$server = $ENV{'NEB_SERVER'} unless $server;
    2121
    2222GetOptions(
     23    'min_copies|m=i'=> \$min_copies,
    2324    'server|s=s'    => \$server,
    2425    'volume|v=s'    => \$volume,
     
    4142    unless defined $neb;
    4243
     44$volume ||= "any";
     45$min_copies ||= 2;
     46
    4347my @cull_args;   
    4448push @cull_args, $key;
    45 if (defined $volume) {
    46     push @cull_args, $volume;
    47 }
     49push @cull_args, $volume;
    4850
    4951if ($one_only) {
     
    5860    }
    5961} else {
     62    push @cull_args, $min_copies;
    6063    unless (defined $neb->cull(@cull_args)) {
    6164        die "failed to cull Nebulous key: $key - " . $neb->err;
  • branches/czw_branch/cleanup/Nebulous/lib/Nebulous/Client.pm

    r25051 r25146  
    275275    my $self = shift;
    276276
    277     my ($key, $vol_name) = validate_pos(@_,
     277    my ($key, $vol_name, $min_copies) = validate_pos(@_,
    278278        {
    279279            type => SCALAR,
     
    284284            optional    => 1,
    285285        },
    286     );
    287 
    288     $log->debug( "entered - @_" );
    289 
    290     my $locations;
     286        {
     287            # min copies
     288            type        => SCALAR,
     289            optional    => 1,
     290        },
     291    );
     292
     293    $min_copies ||= 1;
     294
     295    $log->debug( "entered - @_" );
     296
     297    my $stats = $self->stat($key);
     298    my $instances = $stats->[6];
     299    if ((not defined $instances) or ($instances == 0)) {
     300        $self->set_err("can not cull - no instances");
     301        $log->debug("leaving");
     302        return;
     303    }
     304    if ($instances < $min_copies) {
     305        $self->set_err("can not cull - not enough instances");
     306        $log->debug("leaving");
     307
     308        return;
     309    }
     310
    291311    # if vol_name is specified we need to stat the file to find out how many
    292312    # instances there are on all volumes.  Otherwise we wouldn't know if it's
    293313    # safe to remove the last instance on the specified volume.
    294314    # XXX We need some way to determine which is the best instance to remove
     315    my $locations;
    295316    if (defined $vol_name) {
    296         my @stats = $self->stat($key);
    297         my $instances = $stats[6];
    298         if (defined $instances and $instances < 2) {
    299             $self->set_err("can not cull - not enough instances");
    300             $log->debug("leaving");
    301 
    302             return;
    303         }
    304 
    305317        $locations = $self->find_instances($key, $vol_name);
    306         unless (defined $locations) {
    307             $self->set_err( "no instances" );
    308             $log->debug( "leaving" );
    309 
    310             return;
    311         }
    312318    } else {
    313319        $locations = $self->find_instances($key);
    314         unless ($locations) {
    315             $self->set_err( "no instances" );
    316             $log->debug("leaving");
    317 
    318             return;
    319         }
    320 
    321         if (scalar @{ $locations } < 2) {
    322             $self->set_err("can not cull - not enough instances");
    323             $log->debug("leaving");
    324 
    325             return;
    326         }
     320    }
     321
     322    unless (defined $locations) {
     323        $self->set_err( "no instances" );
     324        $log->debug( "leaving" );
     325
     326        return;
    327327    }
    328328
     
    393393            }
    394394            for (my $i = 1; $i < $stats->[6]; $i++) {
    395                 $self->cull($key);
     395                $self->cull($key, "any", 1);
    396396                $removed++;
    397397            }
  • branches/czw_branch/cleanup/Nebulous/t/53_client_cull.t

    r13180 r25146  
    114114    $neb->cull();
    115115};
    116 like( $@, qr/1 - 2 were expected/, "no params" );
     116like( $@, qr/1 - 3 were expected/, "no params" );
    117117
    118118Test::Nebulous->setup;
     
    122122        proxy => "http://$hostport/nebulous",
    123123    );
    124     $neb->cull( 1, 2, 3 );
     124    $neb->cull( 1, 2, 3, 4 );
    125125};
    126 like( $@, qr/1 - 2 were expected/, "too many params" );
     126like( $@, qr/1 - 3 were expected/, "too many params" );
    127127
    128128Test::Nebulous->cleanup;
  • branches/czw_branch/cleanup/Nebulous/t/72_neb-cull.t

    r25051 r25146  
    1717
    1818use Apache::Test qw( -withtestmore );
    19 plan tests => 29;
     19plan tests => 41;
    2020
    2121use lib qw( ./lib ./t );
     
    7171    is($? >> 8, 255, "exit code");
    7272    like($test->stdout, qr/^$/, "stdout");
     73    like($test->stderr, qr/failed to cull Nebulous key/, "stderr");
     74}
     75
     76Test::Nebulous->setup;
     77
     78{
     79    my $key = 'foo';
     80
     81    my $neb = Nebulous::Client->new(
     82        proxy => $neb_url,
     83    );
     84    $neb->create($key);
     85    $neb->replicate($key);
     86
     87    $test->run(args => $key);
     88
     89    is($neb->stat($key)->[6], 1, "correct # of instances");
     90    is($? >> 8, 0, "exit code");
     91    like($test->stdout, qr/^$/, "stdout");
     92    like($test->stderr, qr/^$/, "stderr");
     93}
     94
     95Test::Nebulous->setup;
     96
     97{
     98    my $key = 'foo';
     99
     100    my $neb = Nebulous::Client->new(
     101        proxy => $neb_url,
     102    );
     103    $neb->create($key);
     104    $neb->replicate($key);
     105    $neb->replicate($key);
     106
     107    $test->run(args => $key);
     108
     109    is($neb->stat($key)->[6], 2, "correct # of instances");
     110    is($? >> 8, 0, "exit code");
     111    like($test->stdout, qr/^$/, "stdout");
     112    like($test->stderr, qr/^$/, "stderr");
     113}
     114
     115Test::Nebulous->setup;
     116
     117{
     118    my $key = 'foo';
     119
     120    my $neb = Nebulous::Client->new(
     121        proxy => $neb_url,
     122    );
     123    $neb->create($key);
     124
     125    $test->run(args => "--one_only " . $key);
     126
     127    is($neb->stat($key)->[6], 1, "correct # of instances");
     128    is($? >> 8, 255, "exit code");
     129    like($test->stdout, qr/^$/, "stdout");
    73130    like($test->stderr, qr/not enough instances/, "stderr");
    74131}
     
    85142    $neb->replicate($key);
    86143
    87     $test->run(args => $key);
    88 
    89     is($neb->stat($key)->[6], 1, "correct # of instances");
    90     is($? >> 8, 0, "exit code");
    91     like($test->stdout, qr/^$/, "stdout");
    92     like($test->stderr, qr/^$/, "stderr");
    93 }
    94 
    95 Test::Nebulous->setup;
    96 
    97 {
    98     my $key = 'foo';
    99 
    100     my $neb = Nebulous::Client->new(
    101         proxy => $neb_url,
    102     );
    103     $neb->create($key);
    104     $neb->replicate($key);
    105     $neb->replicate($key);
    106 
    107     $test->run(args => $key);
    108 
    109     is($neb->stat($key)->[6], 2, "correct # of instances");
    110     is($? >> 8, 0, "exit code");
    111     like($test->stdout, qr/^$/, "stdout");
    112     like($test->stderr, qr/^$/, "stderr");
    113 }
    114 
    115 Test::Nebulous->setup;
    116 
    117 {
    118     my $key = 'foo';
    119 
    120     my $neb = Nebulous::Client->new(
    121         proxy => $neb_url,
    122     );
    123     $neb->create($key);
    124 
    125144    $test->run(args => "--one_only " . $key);
    126145
    127146    is($neb->stat($key)->[6], 1, "correct # of instances");
    128     is($? >> 8, 255, "exit code");
     147    is($? >> 8, 0, "exit code");
     148    like($test->stdout, qr/^$/, "stdout");
     149    like($test->stderr, qr/^$/, "stderr");
     150}
     151
     152Test::Nebulous->setup;
     153
     154{
     155    my $key = 'foo';
     156
     157    my $neb = Nebulous::Client->new(
     158        proxy => $neb_url,
     159    );
     160    $neb->create($key);
     161    $neb->replicate($key);
     162    $neb->replicate($key);
     163
     164    $test->run(args => "--one_only " . $key);
     165
     166    is($neb->stat($key)->[6], 1, "correct # of instances");
     167    is($? >> 8, 0, "exit code");
     168    like($test->stdout, qr/^$/, "stdout");
     169    like($test->stderr, qr/^$/, "stderr");
     170}
     171
     172Test::Nebulous->setup;
     173
     174{
     175    my $key = 'foo';
     176
     177    my $neb = Nebulous::Client->new(
     178        proxy => $neb_url,
     179    );
     180    $neb->create($key);
     181    $neb->replicate($key);
     182
     183    $test->run(args => "--min_copies 1 " . $key);
     184
     185    is($neb->stat($key)->[6], 1, "correct # of instances");
     186    is($? >> 8, 0, "exit code");
     187    like($test->stdout, qr/^$/, "stdout");
     188    like($test->stderr, qr/^$/, "stderr");
     189}
     190
     191Test::Nebulous->setup;
     192
     193{
     194    my $key = 'foo';
     195
     196    my $neb = Nebulous::Client->new(
     197        proxy => $neb_url,
     198    );
     199    $neb->create($key);
     200
     201    $test->run(args => "--min_copies 1 " . $key);
     202
     203    is($neb->stat($key)->[6], 1, "correct # of instances");
     204    is($? >> 8, 0, "exit code");
    129205    like($test->stdout, qr/^$/, "stdout");
    130206    like($test->stderr, qr/not enough instances/, "stderr");
     
    141217    $neb->create($key);
    142218    $neb->replicate($key);
    143 
    144     $test->run(args => "--one_only " . $key);
    145 
    146     is($neb->stat($key)->[6], 1, "correct # of instances");
    147     is($? >> 8, 0, "exit code");
    148     like($test->stdout, qr/^$/, "stdout");
    149     like($test->stderr, qr/^$/, "stderr");
    150 }
    151 
    152 Test::Nebulous->setup;
    153 
    154 {
    155     my $key = 'foo';
    156 
    157     my $neb = Nebulous::Client->new(
    158         proxy => $neb_url,
    159     );
    160     $neb->create($key);
    161     $neb->replicate($key);
    162     $neb->replicate($key);
    163 
    164     $test->run(args => "--one_only " . $key);
     219    $neb->replicate($key);
     220
     221    $test->run(args => "--min_copies 2 " . $key);
    165222
    166223    is($neb->stat($key)->[6], 1, "correct # of instances");
Note: See TracChangeset for help on using the changeset viewer.