IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17756


Ignore:
Timestamp:
May 19, 2008, 5:46:11 PM (18 years ago)
Author:
jhoblitt
Message:

change Nebulous::Client->find() to handle a volume param and to fall back to searching on the ':any' volume if the first search fails

Location:
trunk/Nebulous
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous/Changes

    r17725 r17756  
    22
    330.09
     4    - change Nebulous::Client->find() to handle a volume param and to fall back
     5      to searching on the ':any' volume if the first search fails
    46    - change open_create() to attempt to open the instance file 10 times before
    57      failing
  • trunk/Nebulous/lib/Nebulous/Client.pm

    r17737 r17756  
    11# Copyright (c) 2004-2008  Joshua Hoblitt
    22#
    3 # $Id: Client.pm,v 1.51 2008-05-19 20:52:37 jhoblitt Exp $
     3# $Id: Client.pm,v 1.52 2008-05-20 03:46:11 jhoblitt Exp $
    44
    55package Nebulous::Client;
     
    671671    my $self = shift;
    672672
    673     my ( $key ) = validate_pos( @_,
     673    my ( $key, @params ) = validate_pos( @_,
    674674        {
    675675            type        => SCALAR,
     
    684684    $log->debug( "entered - @_" );
    685685
    686     my $locations = $self->find_instances( $key, undef );
     686    my $locations = $self->find_instances( $key, @params );
     687    unless (defined $locations) {
     688        unless ($self->err =~ /no instances on storage volume/) {
     689            return;
     690        }
     691
     692        # then fall back to looking for isntances on any volume
     693        $locations = $self->find_instances( $key, ':any');
     694        unless (defined $locations) {
     695            return;
     696        }
     697    }
    687698
    688699    my $path;
  • trunk/Nebulous/t/56_client_find_instances.t

    r5667 r17756  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 56_client_find_instances.t,v 1.1 2005-12-03 02:52:31 jhoblitt Exp $
     5# $Id: 56_client_find_instances.t,v 1.2 2008-05-20 03:46:11 jhoblitt Exp $
    66
    77use strict;
     
    1010use Apache::Test qw( -withtestmore );
    1111
    12 plan tests => 19;
     12plan tests => 29;
    1313
    1414use lib qw( ./t ./lib );
     
    7474
    7575{
     76    # key, volume == undef
     77    my $neb = Nebulous::Client->new(
     78        proxy => "http://$hostport/nebulous",
     79    );
     80    $neb->create( "foo" );
     81
     82    my $locations = $neb->find_instances( "foo", undef );
     83
     84    is( scalar @$locations, 1, "found 1" );
     85    like( @$locations[0], qr/file:/, "URIs match" );
     86    ok( -e _get_file_path( @$locations[0] ), "URI matches file" );
     87}
     88
     89Test::Nebulous->setup;
     90
     91{
     92    # volume/key
     93    my $neb = Nebulous::Client->new(
     94        proxy => "http://$hostport/nebulous",
     95    );
     96    $neb->create( "foo" );
     97
     98    my $locations = $neb->find_instances( "neb://node01/foo");
     99
     100    is( scalar @$locations, 1, "found 1" );
     101    like( @$locations[0], qr/file:/, "URIs match" );
     102    ok( -e _get_file_path( @$locations[0] ), "URI matches file" );
     103}
     104
     105Test::Nebulous->setup;
     106
     107{
     108    # volume/key, volume override
     109    my $neb = Nebulous::Client->new(
     110        proxy => "http://$hostport/nebulous",
     111    );
     112    $neb->create( "foo", "node01" );
     113
     114    my $locations = $neb->find_instances( "neb://node01/foo", "node02" );
     115
     116    is($locations, undef, "no instances on specified volume" );
     117}
     118
     119Test::Nebulous->setup;
     120
     121{
     122    # volume/key, volume override
     123    my $neb = Nebulous::Client->new(
     124        proxy => "http://$hostport/nebulous",
     125    );
     126    $neb->create( "foo", "node01" );
     127
     128    my $locations = $neb->find_instances( "neb://node02/foo", ":any" );
     129
     130    is( scalar @$locations, 1, "found 1" );
     131    like( @$locations[0], qr/file:/, "URIs match" );
     132    ok( -e _get_file_path( @$locations[0] ), "URI matches file" );
     133}
     134
     135Test::Nebulous->setup;
     136
     137{
    76138    # key
    77139    my $neb = Nebulous::Client->new(
  • trunk/Nebulous/t/57_client_find.t

    r5667 r17756  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 57_client_find.t,v 1.1 2005-12-03 02:52:31 jhoblitt Exp $
     5# $Id: 57_client_find.t,v 1.2 2008-05-20 03:46:11 jhoblitt Exp $
    66
    77use strict;
     
    1010use Apache::Test qw( -withtestmore );
    1111
    12 plan tests => 4;
     12plan tests => 7;
    1313
    1414use lib qw( ./t ./lib );
     
    3737
    3838{
     39    # key, volume
     40    my $neb = Nebulous::Client->new(
     41        proxy => "http://$hostport/nebulous",
     42    );
     43    my $uri = $neb->create( "foo", "node01" );
     44
     45    my $path = $neb->find( "foo", "node01" );
     46
     47    ok( -e $path, "file exists" );
     48}
     49
     50Test::Nebulous->setup;
     51
     52{
     53    # key, volume does not hold key but this works anyways ans find will fall
     54    # back to looking for ":any"
     55    my $neb = Nebulous::Client->new(
     56        proxy => "http://$hostport/nebulous",
     57    );
     58    my $uri = $neb->create( "foo", "node01" );
     59
     60    my $path = $neb->find( "foo", "node02" );
     61
     62    ok( -e $path, "file exists" );
     63}
     64
     65Test::Nebulous->setup;
     66
     67{
     68    # key, volume :any
     69    my $neb = Nebulous::Client->new(
     70        proxy => "http://$hostport/nebulous",
     71    );
     72    my $uri = $neb->create( "foo", "node01" );
     73
     74    my $path = $neb->find( "foo", ":any" );
     75
     76    ok( -e $path, "file exists" );
     77}
     78
     79Test::Nebulous->setup;
     80
     81{
    3982    my $neb = Nebulous::Client->new(
    4083        proxy => "http://$hostport/nebulous",
     
    4386    my $path = $neb->find( "foo" );
    4487
    45     ok( ! -e $path, "file doesn't exist" );
     88    is($path, undef, "file doesn't exist" );
    4689}
    4790
     
    5598    $neb->find();
    5699};
    57 like( $@, qr/1 was expected/, "no params" );
     100like( $@, qr/1 - 2 were expected/, "no params" );
    58101
    59102Test::Nebulous->setup;
     
    64107    );
    65108
    66     $neb->find( "foo", "bar" );
     109    $neb->find( "foo", "bar", "bong" );
    67110};
    68 like( $@, qr/1 was expected/, "too many params" );
     111like( $@, qr/1 - 2 were expected/, "too many params" );
    69112
    70113Test::Nebulous->cleanup;
Note: See TracChangeset for help on using the changeset viewer.