IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20989


Ignore:
Timestamp:
Dec 14, 2008, 12:52:37 PM (17 years ago)
Author:
eugene
Message:

moving distributed verion code to a branch

Location:
branches/neb_distrib_20081210/Nebulous-Server
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • branches/neb_distrib_20081210/Nebulous-Server/MANIFEST

    r20091 r20989  
    3535t/00_distribution.t
    3636t/01_load.t
     37t/02_config.t
    3738t/02_server_setup.t
    3839t/03_server_create_object.t
  • branches/neb_distrib_20081210/Nebulous-Server/lib/Nebulous/Server.pm

    r20091 r20989  
    11# Copyright (c) 2004-2008  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.93 2008-10-13 20:41:17 jhoblitt Exp $
     3# $Id: Server.pm,v 1.93.6.1 2008-12-14 22:52:37 eugene Exp $
    44
    55package Nebulous::Server;
     
    99no warnings qw( uninitialized );
    1010
    11 our $VERSION = '0.15';
     11our $VERSION = '0.16';
    1212
    1313use base qw( Class::Accessor::Fast );
     
    1919use File::Spec;
    2020use Log::Log4perl;
     21use Nebulous::Keys qw( parse_neb_key parse_neb_volume );
    2122use Nebulous::Server::Config;
    2223use Nebulous::Server::Log;
    2324use Nebulous::Server::SQL;
    24 use Nebulous::Keys qw( parse_neb_key parse_neb_volume );
    2525use Params::Validate qw( validate_pos SCALAR SCALARREF UNDEF );
    2626use URI::file;
     
    3636
    3737    # let Nebulous::Server::Config validate our params
    38     my $config = Nebulous::Server::Config->init( @_ );
     38    my $config = Nebulous::Server::Config->new( @_ );
     39
     40    return $class->new_from_config($config);
     41}
     42
     43
     44sub new_from_config
     45{
     46    my ($class, $config) = @_;
    3947
    4048    # log4perl is not avaliable until we call init()
     
    5159    $self->config($config);
    5260
    53     # ask for the db handle as a means of validating the database parameters
    54     $self->db;
    55 
    5661    $log->debug( "leaving" );
    57    
     62
    5863    return $self;
    5964}
    6065
    61 
    6266sub db
    6367{
    64     my $self = shift;
    65 
    66     if (@_) {
    67         $self->{db} = $_[0];
    68         return $self;
    69     }
     68    my ($self, $key) = @_;
    7069
    7170    my $log     = $self->log;
     
    7372    my $config  = $self->config;
    7473
     74    my $db_index = 0;
     75    if (defined $key) {
     76        # hash the key to select the correct database instance
     77        # only use the first 8 hex chars... have to be careful to avoid an int
     78        # overflow here
     79        $db_index = unpack("h8", sha1_hex("$key")) % $config->n_db;
     80    }
     81
     82    # lookup to see if we have a stored dbh for this database
     83    my $dbh = $self->{dbs}[$db_index];
    7584    # if the dbh is still alive, return it
    76     if (defined $self->{db} and $self->{db}->ping) {
     85    if (defined $dbh and $dbh->ping) {
    7786        $log->debug("db handle is still alive");
    78         return $self->{db};
     87        return $dbh;
    7988    }
    8089    # otherwise create a new connection
    8190    $log->debug("db handle is dead/unopened");
     91
     92    # lookup database info
     93    my $db_config = $config->db($db_index);
     94    die "can't find database configuration info for database # $db_index"
     95        unless $db_config;
    8296
    8397    # if we're running under mod_perl & Apache::DBI is loaded we want to
     
    86100    # processes and the database might have gone away on us.  Apache::DBI will
    87101    # take care of getting a valid dbh back.
    88     my $db;
    89     eval {
    90         $db = DBI->connect_cached(
    91             $config->dsn,
    92             $config->dbuser,
    93             $config->dbpasswd,
     102    eval {
     103        $dbh = DBI->connect_cached(
     104            $db_config->dsn,
     105            $db_config->dbuser,
     106            $db_config->dbpasswd,
    94107            {
    95108                RaiseError => 1,
     
    99112        );
    100113
    101         $db->do( $sql->set_transaction_model );
    102         $log->debug( "connected to database: ", sub { $db->data_sources; } );
    103         $db->commit;
     114        $dbh->do( $sql->set_transaction_model );
     115        $log->debug( "connected to database: ", sub { $dbh->data_sources; } );
     116        $dbh->commit;
    104117        $log->debug("commit");
    105118    };
    106119    if ( $@ ) {
    107         $db->rollback if $db;
     120        $dbh->rollback if $dbh;
    108121        $log->debug("rollback");
    109122        $log->logdie( "database error: $@" );
    110123    }
    111124
    112     $self->{db} = $db;
    113 
    114     return $db;
     125    $self->{dbs}[$db_index] = $dbh;
     126
     127    return $dbh;
    115128}
    116129
     
    139152    my $log = $self->log;
    140153    my $sql = $self->sql;
    141     my $db  =$self->db;
     154    my $db  = $self->db($key);
    142155
    143156    $log->debug( "entered - @_" );
     
    150163    # to check it after parsing the key
    151164    if (defined $vol_name
    152         and not $self->_is_valid_volume_name($key->volume)) {
     165        and not $self->_is_valid_volume_name($key, $key->volume)) {
    153166        if ($key->soft_volume) {
    154167            $log->warn( "$vol_name is not a known volume name" );
     
    160173       
    161174    my ($vol_id, $vol_host, $vol_path, $vol_xattr)
    162         = $self->_get_storage_volume($vol_name, $key->soft_volume);
     175        = $self->_get_storage_volume($key, $vol_name, $key->soft_volume);
    163176
    164177    my $uri;
     
    261274    my $log = $self->log;
    262275    my $sql = $self->sql;
    263     my $db  =$self->db;
     276    my $db  = $self->db($key);
    264277
    265278    $log->debug("entered - @_");
     
    296309
    297310
    298 sub swap_objects
    299 {
    300     my $self = shift;
    301 
    302     my ($key1, $key2) = validate_pos(@_,
    303         {
    304             type        => SCALAR,
    305             callbacks   => {
    306                 'is valid object key' => sub { $self->_is_valid_object_key($_[0]) },
    307             },
    308         },
    309         {
    310             type        => SCALAR,
    311             callbacks   => {
    312                 'is valid object key' => sub { $self->_is_valid_object_key($_[0]) },
    313             },
    314         },
    315     );
    316 
    317     my $log = $self->log;
    318     my $sql = $self->sql;
    319     my $db  =$self->db;
    320 
    321     $log->debug("entered - @_");
    322 
    323     # ignore volumes
    324     $key1 = parse_neb_key($key1);
    325     $key2 = parse_neb_key($key2);
    326 
    327     # order of operations for the swap:
    328     # key1 -> key1.swap
    329     # key2 -> key1
    330     # key1.swap -> key2
    331 
    332     eval {
    333         {
    334             # key1 -> key1.swap
    335             my $query = $db->prepare_cached($sql->rename_object);
    336             # this SQL statment takes the new key name as the first param
    337             my $rows = $query->execute($key1->path . ".swap", $key1->path);
    338 
    339             # if we affected more then one row something very bad has happened.
    340             unless ($rows == 1) {
    341                 $query->finish;
    342                 $log->logdie("affected row count is $rows instead of 1");
    343             }
    344         }
    345 
    346         {
    347             # key2 -> key1
    348             my $query = $db->prepare_cached($sql->rename_object);
    349             # this SQL statment takes the new key name as the first param
    350             my $rows = $query->execute($key1->path, $key2->path);
    351 
    352             # if we affected more then one row something very bad has happened.
    353             unless ($rows == 1) {
    354                 $query->finish;
    355                 $log->logdie("affected row count is $rows instead of 1");
    356             }
    357         }
    358 
    359         {
    360             # key1.swap -> key2
    361             my $query = $db->prepare_cached($sql->rename_object);
    362             # this SQL statment takes the new key name as the first param
    363             my $rows = $query->execute($key2->path, $key1->path . ".swap");
    364 
    365             # if we affected more then one row something very bad has happened.
    366             unless ($rows == 1) {
    367                 $query->finish;
    368                 $log->logdie("affected row count is $rows instead of 1");
    369             }
    370         }
    371 
    372         $db->commit;
    373         $log->debug("commit");
    374     };
    375     if ($@) {
    376         $db->rollback;
    377         $log->debug("rollback");
    378         $log->logdie("database error: $@");
    379     }
    380 
    381     $log->debug("leaving");
    382 
    383     return 1;
    384 }
     311# sub swap_objects
     312# {
     313#     my $self = shift;
     314#
     315#     my ($key1, $key2) = validate_pos(@_,
     316#         {
     317#             type        => SCALAR,
     318#             callbacks   => {
     319#                 'is valid object key' => sub { $self->_is_valid_object_key($_[0]) },
     320#             },
     321#         },
     322#         {
     323#             type        => SCALAR,
     324#             callbacks   => {
     325#                 'is valid object key' => sub { $self->_is_valid_object_key($_[0]) },
     326#             },
     327#         },
     328#     );
     329#
     330#     my $log  = $self->log;
     331#     my $sql  = $self->sql;
     332#     my $dbh1 = $self->db($key1);
     333#     my $dbh2 = $self->db($key2);
     334#
     335#     $log->debug("entered - @_");
     336#
     337#     # ignore volumes
     338#     $key1 = parse_neb_key($key1);
     339#     $key2 = parse_neb_key($key2);
     340#
     341#     # order of operations for the swap with a single db is:
     342#     # key1 -> key1.swap
     343#     # key2 -> key1
     344#     # key1.swap -> key2
     345#
     346#     # XXX this cmp will only work if ->db() returns the same exact (cached) dbh
     347#     if ($dbh1 == $dbh2) {
     348#         my $dbh = $dbh1;
     349#         eval {
     350#             {
     351#                 # key1 -> key1.swap
     352#                 my $query = $dbh->prepare_cached($sql->rename_object);
     353#                 # this SQL statment takes the new key name as the first param
     354#                 my $rows = $query->execute($key1->path . ".swap", $key1->path);
     355#
     356#                 # if we affected more then one row something very bad has happened.
     357#                 unless ($rows == 1) {
     358#                     $query->finish;
     359#                     $log->logdie("affected row count is $rows instead of 1");
     360#                 }
     361#             }
     362#
     363#             {
     364#                 # key2 -> key1
     365#                 my $query = $dbh->prepare_cached($sql->rename_object);
     366#                 # this SQL statment takes the new key name as the first param
     367#                 my $rows = $query->execute($key1->path, $key2->path);
     368#
     369#                 # if we affected more then one row something very bad has happened.
     370#                 unless ($rows == 1) {
     371#                     $query->finish;
     372#                     $log->logdie("affected row count is $rows instead of 1");
     373#                 }
     374#             }
     375#
     376#             {
     377#                 # key1.swap -> key2
     378#                 my $query = $dbh->prepare_cached($sql->rename_object);
     379#                 # this SQL statment takes the new key name as the first param
     380#                 my $rows = $query->execute($key2->path, $key1->path . ".swap");
     381#
     382#                 # if we affected more then one row something very bad has happened.
     383#                 unless ($rows == 1) {
     384#                     $query->finish;
     385#                     $log->logdie("affected row count is $rows instead of 1");
     386#                 }
     387#             }
     388#
     389#             $dbn->commit;
     390#             $log->debug("commit");
     391#         };
     392#         if ($@) {
     393#             $dbh->rollback;
     394#             $log->debug("rollback");
     395#             $log->logdie("database error: $@");
     396#         }
     397#     }
     398#
     399#     # order of operations for the swap between two dbs is:
     400#     # key1 start transaction
     401#     # key1 -> read all instances
     402#     # key1 -> remove all instances
     403#     # key2 start transaction
     404#     # key2 -> read all instances
     405#     # key2 -> remove all instances
     406#     # key1 -> insert key 2 instances
     407#     # key2 -> insert key 1 instances
     408#     # key1,2 commit
     409#
     410#     eval {
     411#         {
     412#             # key1 -> read all instances
     413#             my $query = $dbh->prepare_cached($sql->rename_object);
     414#             # this SQL statment takes the new key name as the first param
     415#             my $rows = $query->execute($key1->path . ".swap", $key1->path);
     416#
     417#             # if we affected more then one row something very bad has happened.
     418#             unless ($rows == 1) {
     419#                 $query->finish;
     420#                 $log->logdie("affected row count is $rows instead of 1");
     421#             }
     422#         }
     423#
     424#         {
     425#             # key2 -> key1
     426#             my $query = $db->prepare_cached($sql->rename_object);
     427#             # this SQL statment takes the new key name as the first param
     428#             my $rows = $query->execute($key1->path, $key2->path);
     429#
     430#             # if we affected more then one row something very bad has happened.
     431#             unless ($rows == 1) {
     432#                 $query->finish;
     433#                 $log->logdie("affected row count is $rows instead of 1");
     434#             }
     435#         }
     436#
     437#         {
     438#             # key1.swap -> key2
     439#             my $query = $db->prepare_cached($sql->rename_object);
     440#             # this SQL statment takes the new key name as the first param
     441#             my $rows = $query->execute($key2->path, $key1->path . ".swap");
     442#
     443#             # if we affected more then one row something very bad has happened.
     444#             unless ($rows == 1) {
     445#                 $query->finish;
     446#                 $log->logdie("affected row count is $rows instead of 1");
     447#             }
     448#         }
     449#
     450#         $db->commit;
     451#         $log->debug("commit");
     452#     };
     453#         if ($@) {
     454#             $db->rollback;
     455#             $log->debug("rollback");
     456#             $log->logdie("database error: $@");
     457#         }
     458#
     459#
     460#     $log->debug("leaving");
     461#
     462#     return 1;
     463# }
    385464
    386465
     
    420499    my $log = $self->log;
    421500    my $sql = $self->sql;
    422     my $db  =$self->db;
     501    my $db  = $self->db($key);
    423502
    424503    $log->debug("entered - @_");
     
    429508
    430509    if (defined $vol_name
    431         and not $self->_is_valid_volume_name($key->volume)) {
     510        and not $self->_is_valid_volume_name($key, $key->volume)) {
    432511        if ($key->soft_volume) {
    433512            $log->warn( "$vol_name is not a known volume name" );
     
    441520    if (defined $vol_name) {
    442521        ($vol_id, $vol_host, $vol_path, $vol_xattr)
    443             = $self->_get_storage_volume($vol_name);
     522            = $self->_get_storage_volume($key, $vol_name);
    444523    } else {
    445524        ($vol_id, $vol_host, $vol_path, $vol_xattr)
     
    534613    my $log = $self->log;
    535614    my $sql = $self->sql;
    536     my $db  =$self->db;
     615    my $db  = $self->db($key);
    537616
    538617    $log->debug( "entered - @_" );
     
    637716    my $log = $self->log;
    638717    my $sql = $self->sql;
    639     my $db  =$self->db;
     718    my $db  = $self->db($key);
    640719
    641720    $log->debug( "entered - @_" );
     
    749828    my $log = $self->log;
    750829    my $sql = $self->sql;
    751     my $db  =$self->db;
     830    my $db  = $self->db($key);
    752831
    753832    $log->debug("entered - @_");
     
    816895    my $log = $self->log;
    817896    my $sql = $self->sql;
    818     my $db  =$self->db;
     897    my $db  = $self->db($key);
    819898
    820899    $log->debug("entered - @_");
     
    869948    my $log = $self->log;
    870949    my $sql = $self->sql;
    871     my $db  =$self->db;
     950    my $db  = $self->db($key);
    872951
    873952    $log->debug("entered - @_");
     
    912991    my $log = $self->log;
    913992    my $sql = $self->sql;
    914     my $db  =$self->db;
     993    my $db  = $self->db($key);
    915994
    916995    $log->debug("entered - @_");
     
    9471026sub find_objects
    9481027{
    949     my $self = shift;
    950 
    951     my ( $pattern ) = validate_pos( @_,
     1028    # XXX: this will only search one db
     1029
     1030    my $self = shift;
     1031
     1032    my ($pattern) = validate_pos( @_,
    9521033        {
    9531034            type        => SCALAR,
     
    9581039    my $log = $self->log;
    9591040    my $sql = $self->sql;
    960     my $db  =$self->db;
     1041    my $db  = $self->db;
    9611042
    9621043    $log->debug( "entered - @_" );
     
    10161097    my $log = $self->log;
    10171098    my $sql = $self->sql;
    1018     my $db  =$self->db;
     1099    my $db  = $self->db($key);
    10191100
    10201101    $log->debug("entered - @_");
     
    10271108    # to check it after parsing the key
    10281109    if (defined $vol_name
    1029         and not $self->_is_valid_volume_name($key->volume)) {
     1110        and not $self->_is_valid_volume_name($key, $key->volume)) {
    10301111        if ($key->soft_volume) {
    10311112            $log->warn( "$vol_name is not a known volume name" );
     
    10871168    my $self = shift;
    10881169
    1089     my ( $uri ) = validate_pos( @_,
     1170    my ($key, $uri) = validate_pos( @_,
     1171        {
     1172            type        => SCALAR,
     1173            callbacks   => {
     1174                'is valid object key' => sub { $self->_is_valid_object_key($_[0]) },
     1175            },
     1176        },
    10901177        {
    10911178            type => SCALAR|SCALARREF,
     
    10951182    my $log = $self->log;
    10961183    my $sql = $self->sql;
    1097     my $db  =$self->db;
     1184    my $db  = $self->db($key);
    10981185
    10991186    $log->debug( "entered - @_" );
     
    11821269    my $log = $self->log;
    11831270    my $sql = $self->sql;
    1184     my $db  =$self->db;
     1271    my $db  = $self->db($key);
    11851272
    11861273    $log->debug("entered - @_");
     
    12111298sub mounts
    12121299{
     1300    # XXX: this will only pull the mounts from one db
    12131301    my $self = shift;
    12141302
     
    12171305    my $log = $self->log;
    12181306    my $sql = $self->sql;
    1219     my $db  =$self->db;
     1307    my $db  = $self->db;
    12201308
    12211309    $log->debug("entered - @_");
     
    12461334    my $self = shift;
    12471335
    1248     my $log = $self->log;
    1249     my $sql = $self->sql;
    1250     my $db  = $self->db;
     1336    my ($key, $name, $soft_volume) = @_;
     1337
     1338    my $log = $self->log;
     1339    my $sql = $self->sql;
     1340    my $db  = $self->db($key);
    12511341
    12521342    no warnings qw( uninitialized );
    12531343    $log->debug( "entered - @_" );
    12541344    use warnings;
    1255 
    1256     my ($name, $soft_volume) = @_;
    12571345
    12581346    my ($vol_id, $vol_host, $vol_path, $xattr);
     
    12711359                # find it, fall back to any volume
    12721360                if ($soft_volume) {
    1273                     ($vol_id, $vol_host, $vol_path, $xattr) = $self->_get_storage_volume;
     1361                    ($vol_id, $vol_host, $vol_path, $xattr) = $self->_get_storage_volume($key);
    12741362                    return; # this just returns out of the eval not from the subroutine
    12751363                }
     
    13111399    my $self = shift;
    13121400
    1313     my $log = $self->log;
    1314     my $sql = $self->sql;
    1315     my $db  =$self->db;
     1401    my $key = shift;
     1402
     1403    my $log = $self->log;
     1404    my $sql = $self->sql;
     1405    my $db  = $self->db($key);
    13161406
    13171407    no warnings qw( uninitialized );
     
    13191409    use warnings;
    13201410
    1321     my $key = shift;
    13221411
    13231412    $key = parse_neb_key($key);
     
    13611450    my $log = $self->log;
    13621451    my $sql = $self->sql;
    1363     my $db  =$self->db;
     1452    my $db  = $self->db($key);
    13641453
    13651454    $key = parse_neb_key($key);
     
    13881477sub _is_valid_volume_name
    13891478{
    1390     my ($self, $vol_name) = @_;
    1391 
    1392     my $log = $self->log;
    1393     my $sql = $self->sql;
    1394     my $db  =$self->db;
     1479    my ($self, $key, $vol_name) = @_;
     1480
     1481    my $log = $self->log;
     1482    my $sql = $self->sql;
     1483    my $db  = $self->db($key);
    13951484
    13961485    my $volume_info = parse_neb_volume($vol_name);
     
    14291518    my $log = $self->log;
    14301519    my $sql = $self->sql;
    1431     my $db  = $self->db;
     1520    my $db  = $self->db($key);
    14321521
    14331522    my $uri;
     
    15581647    my $log = $self->log;
    15591648    my $sql = $self->sql;
    1560     my $db  =$self->db;
     1649#    my $db  = $self->db;
    15611650
    15621651    $log->debug( "entered" );
    15631652
    1564     $self->db->disconnect;       
    1565 
    1566     $log->debug( "disconnected from database: ", sub { $db->data_sources; } );
     1653#    $self->db->disconnect;       
     1654
     1655#    $log->debug( "disconnected from database: ", sub { $db->data_sources; } );
    15671656
    15681657    $log->debug( "leaving" );
  • branches/neb_distrib_20081210/Nebulous-Server/lib/Nebulous/Server/Config.pm

    r17072 r20989  
    11# Copyright (C) 2005  Joshua Hoblitt
    22#
    3 # $Id: Config.pm,v 1.3 2008-03-20 21:10:57 jhoblitt Exp $
     3# $Id: Config.pm,v 1.3.22.1 2008-12-14 22:52:37 eugene Exp $
    44
    55package Nebulous::Server::Config;
     
    88use warnings FATAL => qw( all );
    99
    10 our $VERSION = 0.02;
     10our $VERSION = 0.03;
    1111
    1212use base qw( Class::Accessor::Fast );
    1313
    1414use Log::Log4perl qw( :levels );
    15 use Params::Validate qw( validate SCALAR );
     15use Params::Validate qw( validate validate_pos SCALAR );
    1616
    1717our %LEVELS = (
     
    2525);
    2626
    27 my $new_validate = {
     27my $db_validate = {
     28    dbindex       => {
     29        type => SCALAR,
     30        regex => qr/^\d+$/,
     31    },
    2832    dsn         => { type => SCALAR },
    2933    dbuser      => { type => SCALAR },
    3034    dbpasswd    => { type => SCALAR },
     35};
     36
     37my $new_validate = {
    3138    log_level   => {
    3239        type        => SCALAR,
     
    3946        },
    4047    },
     48    dsn         => { type => SCALAR, optional => 1 },
     49    dbuser      => { type => SCALAR, optional => 1 },
     50    dbpasswd    => { type => SCALAR, optional => 1 },
    4151};
    4252
    4353__PACKAGE__->mk_ro_accessors( keys %$new_validate );
    4454
    45 sub init {
     55
     56sub new
     57{
    4658    my $class = shift;
    4759
     
    4961
    5062    # normalize log levels to lower-case
    51     $p{ log_level } = lc $p{ log_level };
    52 
    53     my $self = \%p;
     63    my $self ={ log_level => lc $p{ log_level } };
    5464
    5565    bless $self, $class || ref $class;
     66
     67    my @dbs;
     68    $self->{dbs} = \@dbs;
     69
     70    if (defined $p{dsn} or defined $p{dbuser} or defined $p{dbpasswd}) {
     71        $self->add_db(
     72            dbindex     => 0,
     73            dsn         => $p{dsn},
     74            dbuser      => $p{dbuser},
     75            dbpasswd    => $p{dbpasswd},
     76        );
     77    }
    5678
    5779    return $self;
    5880}
    5981
     82
     83sub add_db
     84{
     85    my $self = shift;
     86   
     87    my %p = validate( @_, $db_validate );
     88
     89    my $config_db = Nebulous::Server::Config::DB->new({
     90        dsn         => $p{dsn},
     91        dbuser      => $p{dbuser},
     92        dbpasswd    => $p{dbpasswd},
     93    });
     94
     95    $self->{dbs}->[$p{dbindex}] = $config_db;
     96
     97    return $self;
     98}
     99
     100
     101sub db
     102{
     103    my $self = shift;
     104
     105    my ($db_index) = validate_pos( @_, { type => SCALAR, optional => 1, });
     106
     107    # default to 0
     108    $db_index ||= 0;
     109
     110    return $self->{dbs}->[$db_index];
     111}
     112
     113
     114sub n_db
     115{
     116    my $self = shift;
     117
     118    return scalar @{ $self->{dbs} };
     119}
     120
     121
     122package Nebulous::Server::Config::DB;
     123
     124use strict;
     125use warnings FATAL => qw( all );
     126
     127our $VERSION = 0.01;
     128
     129use base qw( Class::Accessor::Fast );
     130
     131__PACKAGE__->mk_ro_accessors(qw( dsn dbuser dbpasswd ));
     132
    601331;
    61134
  • branches/neb_distrib_20081210/Nebulous-Server/lib/Nebulous/Server/Log.pm

    r17546 r20989  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Log.pm,v 1.7 2008-05-07 00:02:10 jhoblitt Exp $
     3# $Id: Log.pm,v 1.7.22.1 2008-12-14 22:52:37 eugene Exp $
    44
    55package Nebulous::Server::Log;
     
    1616    my ($self, $config) = @_;
    1717
    18     my $dsn         = $config->dsn;
    19     my $dbuser      = $config->dbuser;
    20     my $dbpasswd    = $config->dbpasswd;
     18#    my $dsn         = $config->db->dsn;
     19#    my $dbuser      = $config->db->dbuser;
     20#    my $dbpasswd    = $config->db->dbpasswd;
    2121
    2222    my $conf = <<END;
     
    3030#   date | hostname | priority | method/sub - message\n
    3131
    32     log4perl.appender.SQLLOG            = Log::Log4perl::Appender::DBI
    33     log4perl.appender.SQLLOG.datasource = $dsn
    34     log4perl.appender.SQLLOG.username   = $dbuser
    35     log4perl.appender.SQLLOG.password   = $dbpasswd
    36     log4perl.appender.SQLLOG.sql        = \
     32#    log4perl.appender.SQLLOG            = Log::Log4perl::Appender::DBI
     33#    log4perl.appender.SQLLOG.sql        = \
     34#    log4perl.appender.SQLLOG.datasource =
     35#    log4perl.appender.SQLLOG.username   =
     36#    log4perl.appender.SQLLOG.password   =
    3737    INSERT INTO log (timestamp, hostname, level, sub, message) \
    3838    VALUES          (%d,        %H,       %p,    %M,  %m)
  • branches/neb_distrib_20081210/Nebulous-Server/lib/Nebulous/Server/SOAP.pm

    r13111 r20989  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SOAP.pm,v 1.4 2007-05-02 00:42:52 jhoblitt Exp $
     3# $Id: SOAP.pm,v 1.4.32.1 2008-12-14 22:52:37 eugene Exp $
    44
    55package Nebulous::Server::SOAP;
     
    1717our $AUTOLOAD;
    1818
    19 our @args;
     19our $config;
    2020our $neb;
    2121
    22 sub new_on_init {
     22
     23sub new_on_init
     24{
    2325    my $self = shift;
    2426
     
    2729    require Apache2::ServerUtil;
    2830
    29     @args = @_;
     31    $config = shift;
    3032
    3133    my $s = Apache2::ServerUtil->server;
     
    3537}
    3638
    37 sub init {
     39
     40sub init
     41{
    3842    my $self = shift;
    3943
    40     $neb = Nebulous::Server->new(@args);       
     44    $neb = Nebulous::Server->new_from_config($config);       
    4145
    4246    return Apache2::Const::OK;
    4347}
    4448
    45 sub AUTOLOAD {
     49
     50sub AUTOLOAD
     51{
    4652    my $self = shift;
    4753
     
    7682}
    7783
     84
    78851;
  • branches/neb_distrib_20081210/Nebulous-Server/lib/Nebulous/Server/SQL.pm

    r20175 r20989  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SQL.pm,v 1.75 2008-10-15 20:45:51 jhoblitt Exp $
     3# $Id: SQL.pm,v 1.75.6.1 2008-12-14 22:52:37 eugene Exp $
    44
    55package Nebulous::Server::SQL;
     
    88use warnings FATAL => qw( all );
    99
    10 our $VERSION = '0.02';
     10our $VERSION = '0.03';
    1111
    1212use base qw( Class::Accessor::Fast );
     
    4747        (so_id, vol_id, uri)
    4848        VALUES (?, ?, 'error')
     49    },
     50    get_all_instances   => qq{
     51        SELECT * FROM INSTANCE
     52        WHERE so_id = ?
    4953    },
    5054    get_object          => qq{
     
    324328        HAVING available_instances < instances OR instances < copies
    325329    },
    326     find_objects_with_extra_instances => qq{
    327         SELECT
    328             storage_object.so_id,
    329             ext_id,
     330    find_objects_with_extra_instances_by_xattr => qq{
     331        SELECT
     332            so.so_id,
     333            so.ext_id,
    330334            count(ins_id) as instances,
    331             volume.name as volume_name,
    332             volume.host as volume_host,
    333             count(mymountedvol.vol_id) as available_instances,
    334             count(mymountedvol.vol_id) > 0 as recoverable,
    335             storage_object_xattr.value as copies
    336         FROM storage_object
    337         JOIN instance
    338             USING(so_id)
    339         JOIN volume
    340             USING(vol_id)
    341         LEFT JOIN storage_object_xattr
    342             ON storage_object.so_id = storage_object_xattr.so_id
    343         JOIN mymountedvol
     335            mv.name as volume_name,
     336            mv.host as volume_host,
     337            count(mv.vol_id) as available_instances,
     338            xattr.value as copies
     339        FROM storage_object AS so
     340        JOIN storage_object_xattr as xattr
     341            ON so.so_id = xattr.so_id
     342            AND xattr.name = 'user.copies'
     343        JOIN instance AS i
     344            ON so.so_id = i.so_id
     345        JOIN mountedvol AS mv
    344346            USING(vol_id)
    345347        WHERE
    346             mymountedvol.available = 1
    347             AND storage_object_xattr.name = 'user.copies'
     348            mv.available = 1
    348349        GROUP BY so_id
    349350        HAVING available_instances > copies
     351        limit 5;
    350352    },
    351353    get_mounted_volumes => qq{
  • branches/neb_distrib_20081210/Nebulous-Server/t/02_server_setup.t

    r16281 r20989  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 02_server_setup.t,v 1.6 2008-02-02 01:51:29 jhoblitt Exp $
     5# $Id: 02_server_setup.t,v 1.6.22.1 2008-12-14 22:52:37 eugene Exp $
    66
    77use strict;
    88use warnings;
    99
    10 use Test::More tests => 2;
     10use Test::More tests => 6;
    1111
    1212use lib qw( ./t ./lib );
     
    1717Test::Nebulous->setup;
    1818
    19 isa_ok(
    20     Nebulous::Server->new(
    21         dsn         => $NEB_DB,
    22         dbuser      => $NEB_USER,
    23         dbpasswd    => $NEB_PASS,
    24     ),
    25     "Nebulous::Server"
    26 );
     19isa_ok(Nebulous::Server->new(), "Nebulous::Server");
    2720
    2821Test::Nebulous->setup;
    2922
    30 eval {
    31     Nebulous::Server->new(
     23# ->new()
     24{
     25    my $neb = Nebulous::Server->new( log_level => 'off' );
     26
     27    ok($neb, "set log level");
     28}
     29
     30Test::Nebulous->setup;
     31
     32{
     33    my $neb = Nebulous::Server->new(
    3234        dsn         => "DBI:mysql:database=foobar:host=localhost",
    3335        dbuser      => "baz",
    3436        dbpasswd    =>"boo",
    3537    );
    36 };
    37 like( $@, qr/DBI connect.*? failed/, "bad dsn/user/pass" );
     38
     39    ok($neb, "set database");
     40}
     41
     42Test::Nebulous->setup;
     43
     44# add dbs after ->new()
     45{
     46    my $neb = Nebulous::Server->new;
     47
     48    ok($neb->config->add_db(
     49        dbindex    => 0,
     50        dsn         => "DBI:mysql:database=foobar:host=localhost",
     51        dbuser      => "baz",
     52        dbpasswd    =>"boo",
     53    ), "add db");
     54   
     55    ok($neb->config->add_db(
     56        dbindex    => 1,
     57        dsn         => "DBI:mysql:database=foobar:host=localhost",
     58        dbuser      => "baz",
     59        dbpasswd    =>"boo",
     60    ), "add dbs");
     61
     62    is($neb->config->n_db, 2, "n dbs")
     63}
    3864
    3965Test::Nebulous->cleanup;
  • branches/neb_distrib_20081210/Nebulous-Server/t/08_server_delete_instance.t

    r17072 r20989  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 08_server_delete_instance.t,v 1.10 2008-03-20 21:10:14 jhoblitt Exp $
     5# $Id: 08_server_delete_instance.t,v 1.10.22.1 2008-12-14 22:52:37 eugene Exp $
    66
    77use strict;
     
    2424
    2525{
    26     my $uri = $neb->create_object("foo");
     26    my $key = "foo";
     27    my $uri = $neb->create_object($key);
    2728
    28     ok($neb->delete_instance($uri), "delete instance");
     29    ok($neb->delete_instance($key, $uri), "delete instance");
    2930}
    3031
     
    3233
    3334{
    34     my $uri1 = $neb->create_object("foo");
    35     my $uri2 = $neb->replicate_object("foo");
     35    my $key = "foo";
     36    my $uri1 = $neb->create_object($key);
     37    my $uri2 = $neb->replicate_object($key);
    3638
    37     ok($neb->delete_instance($uri1), "delete instance");
     39    ok($neb->delete_instance($key, $uri1), "delete instance");
    3840
    39     my $locations = $neb->find_instances("foo");
     41    my $locations = $neb->find_instances($key);
    4042
    4143    is($locations->[0], $uri2, "instance remains");
    4244
    43     ok($neb->delete_instance( $uri2 ), "delete instance");
     45    ok($neb->delete_instance($key, $uri2), "delete instance");
    4446
    4547    eval {
    46         $neb->find_instances("foo");
     48        $neb->find_instances($key);
    4749    };
    4850    like($@, qr/is valid object key/, "storage object was deleted");
     
    5254
    5355eval {
    54     $neb->delete_instance("file:/foo");
     56    my $key = "foo";
     57    my $uri1 = $neb->create_object($key);
     58
     59    $neb->delete_instance($key, "file:/foo");
    5560};
    5661like($@, qr/no instance is associated with uri/, "uri does not exist");
     
    6166    $neb->delete_instance();
    6267};
    63 like($@, qr/1 was expected/, "no params");
     68like($@, qr/2 were expected/, "no params");
    6469
    6570Test::Nebulous->setup;
    6671
    6772eval {
    68     $neb->delete_instance("foo", 2);
     73    my $key = "foo";
     74    my $uri1 = $neb->create_object($key);
     75
     76    $neb->delete_instance("foo", 2, 3);
    6977};
    70 like($@, qr/1 was expected/, "too many params");
     78like($@, qr/2 were expected/, "too many params");
    7179
    7280Test::Nebulous->cleanup;
  • branches/neb_distrib_20081210/Nebulous-Server/t/10_server_is_valid_volume_name.t

    r17072 r20989  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 10_server_is_valid_volume_name.t,v 1.5 2008-03-20 21:10:14 jhoblitt Exp $
     5# $Id: 10_server_is_valid_volume_name.t,v 1.5.22.1 2008-12-14 22:52:37 eugene Exp $
    66
    77use strict;
     
    2323Test::Nebulous->setup;
    2424
    25 ok($neb->_is_valid_volume_name('node01'), "valid volume name");
     25ok($neb->_is_valid_volume_name('foo', 'node01'), "valid volume name");
    2626
    2727Test::Nebulous->setup;
    2828
    29 ok($neb->_is_valid_volume_name('node02'), "valid volume name");
     29ok($neb->_is_valid_volume_name('foo', 'node02'), "valid volume name");
    3030
    3131Test::Nebulous->setup;
    3232
    33 is($neb->_is_valid_volume_name('node99'), undef, "invalid volume name");
     33is($neb->_is_valid_volume_name('foo', 'node99'), undef, "invalid volume name");
    3434
    3535Test::Nebulous->cleanup;
Note: See TracChangeset for help on using the changeset viewer.