IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 7, 2009, 4:08:25 PM (17 years ago)
Author:
Paul Price
Message:

Merging trunk (r25026) to get up-to-date on old branch.

Location:
branches/pap
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/Nebulous

    • Property svn:mergeinfo deleted
  • branches/pap/Nebulous/lib

    • Property svn:mergeinfo deleted
  • branches/pap/Nebulous/lib/Nebulous/Client.pm

    r23934 r25027  
    99no warnings qw( uninitialized );
    1010
    11 our $VERSION = '0.09';
     11our $VERSION = '0.17';
    1212
    1313use Digest::MD5;
     
    1616use Nebulous::Client::Log;
    1717use Nebulous::Util qw( :standard );
    18 use Params::Validate qw( validate validate_pos SCALAR UNDEF );
     18use Params::Validate qw( validate validate_pos SCALAR UNDEF BOOLEAN );
    1919#use SOAP::Lite +trace => [qw( debug )];
    2020use SOAP::Lite;
     
    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
     
    329329    my $uri = $self->delete_instance($key, @$locations[0]);
    330330
     331    eval {
     332        _nuke_file(_get_file_path(@$locations[0]));
     333    };
     334    if ($@) {
     335        $log->logdie($@);
     336    }
     337
    331338    $log->debug("leaving");
    332339
    333340    return $uri;
     341}
     342
     343
     344sub there_can_be_only_one
     345{
     346    my $self = shift;
     347
     348    my ($key, $vol_name) = validate_pos(@_,
     349        {
     350            type => SCALAR,
     351        },
     352        {
     353            # volume
     354            type        => SCALAR,
     355            optional    => 1,
     356        },
     357    );
     358
     359    $log->debug( "entered - @_" );
     360
     361    my $locations;
     362    my $removed = 0;
     363    eval {
     364        # first - strip off any inaccesible instances
     365        if (not defined $self->prune($key)) {
     366            # use the prune() method to also determine if $key is valid
     367            die "invalid key: $key";
     368        }
     369
     370        # check to see if there is an instance on $vol_name that should be the
     371        # sole survivor
     372        if (defined $vol_name) {
     373            $locations = $self->find_instances($key, $vol_name);
     374        }
     375
     376        if (defined $locations) {
     377            my $instances = $self->find_instances($key);
     378            if (scalar @$instances < 2) {
     379                die "not enough instances";
     380            }
     381            foreach my $victim (@$instances) {
     382                next if $victim eq $locations->[0];
     383                $self->delete_instance($key, $victim);
     384                $removed++;
     385            }
     386        } else {
     387            # nuke whatever
     388            my $stats = $self->stat($key);
     389            # start at one so cull() is called one less time then the # of
     390            # instances
     391            if ($stats->[6] < 2) {
     392                die "not enough instances";
     393            }
     394            for (my $i = 1; $i < $stats->[6]; $i++) {
     395                $self->cull($key);
     396                $removed++;
     397            }
     398        }
     399
     400    };
     401    if ($@) {
     402        if ($@ =~ qr/invalid key/) {
     403            $self->set_err($@);
     404            return;
     405        }
     406        $log->logdie($@);
     407    }
     408
     409    $log->debug("leaving");
     410
     411    return $removed;
    334412}
    335413
     
    803881    my $self = shift;
    804882
    805     my ( $key ) = validate_pos( @_,
    806         {
    807             type => SCALAR,
     883    my ($key, $force) = validate_pos( @_,
     884        {
     885            type        => SCALAR,
     886        },
     887        {
     888            type        => BOOLEAN,
     889            optional    => 1,
     890            default     => undef,
     891            callbacks   => {
     892                'is boolean' => sub {
     893                    $_[0] == 0 or $_[0] == 1 or $_[0] == undef;
     894                },
     895            },
    808896        },
    809897    );
     
    817905    # a lock is implicitly removed when the last storage object is deleted
    818906    foreach my $uri ( @$locations ) {
     907        # it is being assumed here that it is better to have files on disk and
     908        # not in the database then the inverse.
     909        my $path;
     910        eval {
     911            $path = _get_file_path( $uri );
     912        };
     913        if ($@) {
     914            if ($force) {
     915                $log->warn($@);
     916                $log->warn("exception ignored because force is in effect");
     917            } else {
     918                $log->logdie($@);
     919            }
     920        }
     921
    819922        $self->delete_instance($key, $uri) or return undef;
     923
     924        eval {
     925            _nuke_file( $path );
     926        };
     927        if ($@) {
     928            if ($force) {
     929                $log->warn($@);
     930                $log->warn("exception ignored because force is in effect");
     931            } else {
     932                $log->logdie($@);
     933            }
     934        }
    820935    }
    821936
     
    9591074    $log->debug( "entered - @_" );
    9601075
    961     # it is being assumed here that it is better to have files on disk and not in
    962     # the database then the inverse.
    963 
    964     my $path;
    965     eval {
    966         $path = _get_file_path( $uri );
    967     };
    968     $log->logdie( $@ ) if $@;
    969 
    9701076    my $response = $self->{ 'server' }->delete_instance($key, $uri);
    9711077    if ( $response->fault ) {
     
    9821088    $log->debug( "server deleted instance" );
    9831089
    984     eval {
    985         _nuke_file( $path );
    986     };
    987     $log->logdie( $@ ) if $@;
    988 
    9891090    $log->debug( "leaving" );
    9901091
     
    10451146
    10461147    return $stats;
     1148}
     1149
     1150
     1151sub chmod
     1152{
     1153    my $self = shift;
     1154
     1155    my ($key, $mode) = validate_pos( @_,
     1156        {
     1157            type => SCALAR,
     1158        },
     1159        {
     1160            type => SCALAR,
     1161            regex       => qr/\d{3,4}/,
     1162        },
     1163    );
     1164
     1165    $log->debug( "entered - @_" );
     1166
     1167    my $response = $self->{ 'server' }->chmod_object($key, $mode);
     1168    if ( $response->fault ) {
     1169        $self->set_err($response->faultstring);
     1170        if ($response->faultstring =~ /is valid object key/) {
     1171            $log->debug( "leaving" );
     1172            return;
     1173        }
     1174        if ($response->faultstring =~ /is allowable mode/) {
     1175            $log->debug( "leaving" );
     1176            return;
     1177        }
     1178
     1179        $log->logdie("unhandled fault - ", $self->err);
     1180    }
     1181
     1182    my $response_mode = $response->result;
     1183
     1184    $log->debug( "leaving" );
     1185
     1186    return $response_mode;
     1187}
     1188
     1189
     1190sub prune
     1191{
     1192    my $self = shift;
     1193
     1194    my ( $key ) = validate_pos( @_,
     1195        {
     1196            type => SCALAR,
     1197        },
     1198    );
     1199
     1200    $log->debug( "entered - @_" );
     1201
     1202    my $response = $self->{ 'server' }->prune_object( $key );
     1203    if ( $response->fault ) {
     1204        $self->set_err($response->faultstring);
     1205        if ($response->faultstring =~ /is valid object key/) {
     1206            $log->debug( "leaving" );
     1207            return;
     1208        }
     1209
     1210        $log->logdie("unhandled fault - ", $self->err);
     1211    }
     1212
     1213    $log->debug( "server returned a stat" );
     1214
     1215    my $n_removed = $response->result;
     1216
     1217    $log->debug( "leaving" );
     1218
     1219    return $n_removed;
    10471220}
    10481221
  • branches/pap/Nebulous/lib/Nebulous/Client.pod

    r20094 r25027  
    1313    );
    1414
    15     my $uri = $neb->create( "key", "node01" );
    16     my $fh = $neb->open_create( "key", "node01" );
    17     $neb->replicate( "key", "node01" );
    18     $neb->cull( "key", "node01" );
    19     $neb->lock( "key", 'write' );
    20     $neb->unlock( "key", 'write' );
     15    my $uri = $neb->create( $key, $vol );
     16    my $fh = $neb->open_create( $key, $vol );
     17    $neb->replicate( $key, $vol );
     18    $neb->cull( $key, $vol );
     19    $neb->lock( $key, 'write' );
     20    $neb->unlock( $key, 'write' );
    2121    $neb->setxattr( $key, $name, $value, $flags );
    2222    $neb->getxattr( $key, $name );
     
    2424    $neb->removexattr( $key, $name );
    2525    my $uris = $neb->find_objects( $pattern );
    26     my $uris = $neb->find_instances( "key", "node01" );
    27     my $path = $neb->find( "key" );
    28     my $fh = $neb->open( "key", 'read' );
    29     $neb->delete( "key" );
    30     $neb->copy( "key", "new_key", "node01" );
    31     $neb->move( "key", "new_key" );
    32     $neb->swap( "key1", "key2" );
     26    my $uris = $neb->find_instances( $key, $vol );
     27    my $path = $neb->find( $key );
     28    my $fh = $neb->open( $key, 'read' );
     29    $neb->delete( $key );
     30    $neb->copy( $key, $new_key, $vol );
     31    $neb->move( $key, $new_key );
     32    $neb->swap( $key1, $key2 );
    3333    $neb->delete_instance( $uri );
    34     my $stats = $neb->stat( "key" );
     34    my $stats = $neb->stat( $key );
    3535    my $mounts = $neb->mounts();
     36    my $mode = $neb->chmod( $key, $mode );
     37    my $n_dead = $neb->prune( $key );
     38    my $n_dead = $neb->there_can_be_only_one( $key, $vol );
    3639
    3740=head1 DESCRIPTION
     
    404407
    405408Returns an arrayref of scalars.
     409
     410=item * prune($key)
     411
     412Removes all of the inaccessible instances from an object.
     413
     414=over 4
     415
     416=item * key
     417
     418The storage object key (name).
     419
     420=back
     421
     422The number of instances removed.
     423
     424=item * there_can_be_only_one($key, $vol)
     425
     426Removes all but one instance of an object and automatically removes any
     427inaccessible instances.
     428
     429=over 4
     430
     431=item * key
     432
     433The storage object key (name).
     434
     435=item * vol
     436
     437If specified, the only remaining instance will be left on this volume (if an
     438instance already exists there).
     439
     440=back
     441
     442The number of avaiable instances removed.
    406443
    407444=item * mounts()
     
    425462    ]
    426463
     464=item * chmod( $key, $mode );
     465
     466Accepts 2 parameters, both mandatory.  C<$key> is the nebulous key to operate
     467on and C<$mode> are the POSIX like file permissions to set on all instances of
     468C<$key>.  C<$mode> must be specified in oct.  Returns C<$mode> or sucess or an
     469exception on failure.
     470
    427471=back
    428472
     
    456500=head1 COPYRIGHT
    457501
    458 Copyright (C) 2004-2008  Joshua Hoblitt.  All rights reserved.
     502Copyright (C) 2004-2009  Joshua Hoblitt.  All rights reserved.
    459503
    460504This program is free software; you can redistribute it and/or modify it under
Note: See TracChangeset for help on using the changeset viewer.