IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20990


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

reverting to pre-distributed version code (distrib is on branch)

Location:
trunk/Nebulous-Server
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/MANIFEST

    r20965 r20990  
    3535t/00_distribution.t
    3636t/01_load.t
    37 t/02_config.t
    3837t/02_server_setup.t
    3938t/03_server_create_object.t
  • trunk/Nebulous-Server/lib/Nebulous/Server.pm

    r20972 r20990  
    11# Copyright (c) 2004-2008  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.95 2008-12-13 00:41:15 jhoblitt Exp $
     3# $Id: Server.pm,v 1.96 2008-12-14 22:54:25 eugene Exp $
    44
    55package Nebulous::Server;
     
    99no warnings qw( uninitialized );
    1010
    11 our $VERSION = '0.16';
     11our $VERSION = '0.15';
    1212
    1313use base qw( Class::Accessor::Fast );
     
    1919use File::Spec;
    2020use Log::Log4perl;
    21 use Nebulous::Keys qw( parse_neb_key parse_neb_volume );
    2221use Nebulous::Server::Config;
    2322use Nebulous::Server::Log;
    2423use Nebulous::Server::SQL;
     24use 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->new( @_ );
    39 
    40     return $class->new_from_config($config);
    41 }
    42 
    43 
    44 sub new_from_config
    45 {
    46     my ($class, $config) = @_;
     38    my $config = Nebulous::Server::Config->init( @_ );
    4739
    4840    # log4perl is not avaliable until we call init()
     
    5951    $self->config($config);
    6052
     53    # ask for the db handle as a means of validating the database parameters
     54    $self->db;
     55
    6156    $log->debug( "leaving" );
    62 
     57   
    6358    return $self;
    6459}
    6560
     61
    6662sub db
    6763{
    68     my ($self, $key) = @_;
     64    my $self = shift;
     65
     66    if (@_) {
     67        $self->{db} = $_[0];
     68        return $self;
     69    }
    6970
    7071    my $log     = $self->log;
     
    7273    my $config  = $self->config;
    7374
    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];
    8475    # if the dbh is still alive, return it
    85     if (defined $dbh and $dbh->ping) {
     76    if (defined $self->{db} and $self->{db}->ping) {
    8677        $log->debug("db handle is still alive");
    87         return $dbh;
     78        return $self->{db};
    8879    }
    8980    # otherwise create a new connection
    9081    $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;
    9682
    9783    # if we're running under mod_perl & Apache::DBI is loaded we want to
     
    10086    # processes and the database might have gone away on us.  Apache::DBI will
    10187    # take care of getting a valid dbh back.
    102     eval {
    103         $dbh = DBI->connect_cached(
    104             $db_config->dsn,
    105             $db_config->dbuser,
    106             $db_config->dbpasswd,
     88    my $db;
     89    eval {
     90        $db = DBI->connect_cached(
     91            $config->dsn,
     92            $config->dbuser,
     93            $config->dbpasswd,
    10794            {
    10895                RaiseError => 1,
     
    11299        );
    113100
    114         $dbh->do( $sql->set_transaction_model );
    115         $log->debug( "connected to database: ", sub { $dbh->data_sources; } );
    116         $dbh->commit;
     101        $db->do( $sql->set_transaction_model );
     102        $log->debug( "connected to database: ", sub { $db->data_sources; } );
     103        $db->commit;
    117104        $log->debug("commit");
    118105    };
    119106    if ( $@ ) {
    120         $dbh->rollback if $dbh;
     107        $db->rollback if $db;
    121108        $log->debug("rollback");
    122109        $log->logdie( "database error: $@" );
    123110    }
    124111
    125     $self->{dbs}[$db_index] = $dbh;
    126 
    127     return $dbh;
     112    $self->{db} = $db;
     113
     114    return $db;
    128115}
    129116
     
    152139    my $log = $self->log;
    153140    my $sql = $self->sql;
    154     my $db  = $self->db($key);
     141    my $db  =$self->db;
    155142
    156143    $log->debug( "entered - @_" );
     
    163150    # to check it after parsing the key
    164151    if (defined $vol_name
    165         and not $self->_is_valid_volume_name($key, $key->volume)) {
     152        and not $self->_is_valid_volume_name($key->volume)) {
    166153        if ($key->soft_volume) {
    167154            $log->warn( "$vol_name is not a known volume name" );
     
    173160       
    174161    my ($vol_id, $vol_host, $vol_path, $vol_xattr)
    175         = $self->_get_storage_volume($key, $vol_name, $key->soft_volume);
     162        = $self->_get_storage_volume($vol_name, $key->soft_volume);
    176163
    177164    my $uri;
     
    274261    my $log = $self->log;
    275262    my $sql = $self->sql;
    276     my $db  = $self->db($key);
     263    my $db  =$self->db;
    277264
    278265    $log->debug("entered - @_");
     
    309296
    310297
    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 # }
     298sub 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}
    464385
    465386
     
    499420    my $log = $self->log;
    500421    my $sql = $self->sql;
    501     my $db  = $self->db($key);
     422    my $db  =$self->db;
    502423
    503424    $log->debug("entered - @_");
     
    508429
    509430    if (defined $vol_name
    510         and not $self->_is_valid_volume_name($key, $key->volume)) {
     431        and not $self->_is_valid_volume_name($key->volume)) {
    511432        if ($key->soft_volume) {
    512433            $log->warn( "$vol_name is not a known volume name" );
     
    520441    if (defined $vol_name) {
    521442        ($vol_id, $vol_host, $vol_path, $vol_xattr)
    522             = $self->_get_storage_volume($key, $vol_name);
     443            = $self->_get_storage_volume($vol_name);
    523444    } else {
    524445        ($vol_id, $vol_host, $vol_path, $vol_xattr)
     
    613534    my $log = $self->log;
    614535    my $sql = $self->sql;
    615     my $db  = $self->db($key);
     536    my $db  =$self->db;
    616537
    617538    $log->debug( "entered - @_" );
     
    716637    my $log = $self->log;
    717638    my $sql = $self->sql;
    718     my $db  = $self->db($key);
     639    my $db  =$self->db;
    719640
    720641    $log->debug( "entered - @_" );
     
    828749    my $log = $self->log;
    829750    my $sql = $self->sql;
    830     my $db  = $self->db($key);
     751    my $db  =$self->db;
    831752
    832753    $log->debug("entered - @_");
     
    895816    my $log = $self->log;
    896817    my $sql = $self->sql;
    897     my $db  = $self->db($key);
     818    my $db  =$self->db;
    898819
    899820    $log->debug("entered - @_");
     
    948869    my $log = $self->log;
    949870    my $sql = $self->sql;
    950     my $db  = $self->db($key);
     871    my $db  =$self->db;
    951872
    952873    $log->debug("entered - @_");
     
    991912    my $log = $self->log;
    992913    my $sql = $self->sql;
    993     my $db  = $self->db($key);
     914    my $db  =$self->db;
    994915
    995916    $log->debug("entered - @_");
     
    1026947sub find_objects
    1027948{
    1028     # XXX: this will only search one db
    1029 
    1030     my $self = shift;
    1031 
    1032     my ($pattern) = validate_pos( @_,
     949    my $self = shift;
     950
     951    my ( $pattern ) = validate_pos( @_,
    1033952        {
    1034953            type        => SCALAR,
     
    1039958    my $log = $self->log;
    1040959    my $sql = $self->sql;
    1041     my $db  = $self->db;
     960    my $db  =$self->db;
    1042961
    1043962    $log->debug( "entered - @_" );
     
    10971016    my $log = $self->log;
    10981017    my $sql = $self->sql;
    1099     my $db  = $self->db($key);
     1018    my $db  =$self->db;
    11001019
    11011020    $log->debug("entered - @_");
     
    11081027    # to check it after parsing the key
    11091028    if (defined $vol_name
    1110         and not $self->_is_valid_volume_name($key, $key->volume)) {
     1029        and not $self->_is_valid_volume_name($key->volume)) {
    11111030        if ($key->soft_volume) {
    11121031            $log->warn( "$vol_name is not a known volume name" );
     
    11681087    my $self = shift;
    11691088
    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         },
     1089    my ( $uri ) = validate_pos( @_,
    11771090        {
    11781091            type => SCALAR|SCALARREF,
     
    11821095    my $log = $self->log;
    11831096    my $sql = $self->sql;
    1184     my $db  = $self->db($key);
     1097    my $db  =$self->db;
    11851098
    11861099    $log->debug( "entered - @_" );
     
    12691182    my $log = $self->log;
    12701183    my $sql = $self->sql;
    1271     my $db  = $self->db($key);
     1184    my $db  =$self->db;
    12721185
    12731186    $log->debug("entered - @_");
     
    12981211sub mounts
    12991212{
    1300     # XXX: this will only pull the mounts from one db
    13011213    my $self = shift;
    13021214
     
    13051217    my $log = $self->log;
    13061218    my $sql = $self->sql;
    1307     my $db  = $self->db;
     1219    my $db  =$self->db;
    13081220
    13091221    $log->debug("entered - @_");
     
    13341246    my $self = shift;
    13351247
    1336     my ($key, $name, $soft_volume) = @_;
    1337 
    1338     my $log = $self->log;
    1339     my $sql = $self->sql;
    1340     my $db  = $self->db($key);
     1248    my $log = $self->log;
     1249    my $sql = $self->sql;
     1250    my $db  = $self->db;
    13411251
    13421252    no warnings qw( uninitialized );
    13431253    $log->debug( "entered - @_" );
    13441254    use warnings;
     1255
     1256    my ($name, $soft_volume) = @_;
    13451257
    13461258    my ($vol_id, $vol_host, $vol_path, $xattr);
     
    13591271                # find it, fall back to any volume
    13601272                if ($soft_volume) {
    1361                     ($vol_id, $vol_host, $vol_path, $xattr) = $self->_get_storage_volume($key);
     1273                    ($vol_id, $vol_host, $vol_path, $xattr) = $self->_get_storage_volume;
    13621274                    return; # this just returns out of the eval not from the subroutine
    13631275                }
     
    13991311    my $self = shift;
    14001312
    1401     my $key = shift;
    1402 
    1403     my $log = $self->log;
    1404     my $sql = $self->sql;
    1405     my $db  = $self->db($key);
     1313    my $log = $self->log;
     1314    my $sql = $self->sql;
     1315    my $db  =$self->db;
    14061316
    14071317    no warnings qw( uninitialized );
     
    14091319    use warnings;
    14101320
     1321    my $key = shift;
    14111322
    14121323    $key = parse_neb_key($key);
     
    14501361    my $log = $self->log;
    14511362    my $sql = $self->sql;
    1452     my $db  = $self->db($key);
     1363    my $db  =$self->db;
    14531364
    14541365    $key = parse_neb_key($key);
     
    14771388sub _is_valid_volume_name
    14781389{
    1479     my ($self, $key, $vol_name) = @_;
    1480 
    1481     my $log = $self->log;
    1482     my $sql = $self->sql;
    1483     my $db  = $self->db($key);
     1390    my ($self, $vol_name) = @_;
     1391
     1392    my $log = $self->log;
     1393    my $sql = $self->sql;
     1394    my $db  =$self->db;
    14841395
    14851396    my $volume_info = parse_neb_volume($vol_name);
     
    15181429    my $log = $self->log;
    15191430    my $sql = $self->sql;
    1520     my $db  = $self->db($key);
     1431    my $db  = $self->db;
    15211432
    15221433    my $uri;
     
    16471558    my $log = $self->log;
    16481559    my $sql = $self->sql;
    1649 #    my $db  = $self->db;
     1560    my $db  =$self->db;
    16501561
    16511562    $log->debug( "entered" );
    16521563
    1653 #    $self->db->disconnect;       
    1654 
    1655 #    $log->debug( "disconnected from database: ", sub { $db->data_sources; } );
     1564    $self->db->disconnect;       
     1565
     1566    $log->debug( "disconnected from database: ", sub { $db->data_sources; } );
    16561567
    16571568    $log->debug( "leaving" );
  • trunk/Nebulous-Server/lib/Nebulous/Server/Config.pm

    r20965 r20990  
    11# Copyright (C) 2005  Joshua Hoblitt
    22#
    3 # $Id: Config.pm,v 1.4 2008-12-12 21:13:41 jhoblitt Exp $
     3# $Id: Config.pm,v 1.5 2008-12-14 22:54:25 eugene Exp $
    44
    55package Nebulous::Server::Config;
     
    88use warnings FATAL => qw( all );
    99
    10 our $VERSION = 0.03;
     10our $VERSION = 0.02;
    1111
    1212use base qw( Class::Accessor::Fast );
    1313
    1414use Log::Log4perl qw( :levels );
    15 use Params::Validate qw( validate validate_pos SCALAR );
     15use Params::Validate qw( validate SCALAR );
    1616
    1717our %LEVELS = (
     
    2525);
    2626
    27 my $db_validate = {
    28     dbindex       => {
    29         type => SCALAR,
    30         regex => qr/^\d+$/,
    31     },
     27my $new_validate = {
    3228    dsn         => { type => SCALAR },
    3329    dbuser      => { type => SCALAR },
    3430    dbpasswd    => { type => SCALAR },
    35 };
    36 
    37 my $new_validate = {
    3831    log_level   => {
    3932        type        => SCALAR,
     
    4639        },
    4740    },
    48     dsn         => { type => SCALAR, optional => 1 },
    49     dbuser      => { type => SCALAR, optional => 1 },
    50     dbpasswd    => { type => SCALAR, optional => 1 },
    5141};
    5242
    5343__PACKAGE__->mk_ro_accessors( keys %$new_validate );
    5444
    55 
    56 sub new
    57 {
     45sub init {
    5846    my $class = shift;
    5947
     
    6149
    6250    # normalize log levels to lower-case
    63     my $self ={ log_level => lc $p{ log_level } };
     51    $p{ log_level } = lc $p{ log_level };
     52
     53    my $self = \%p;
    6454
    6555    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     }
    7856
    7957    return $self;
    8058}
    8159
    82 
    83 sub 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 
    101 sub 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 
    114 sub n_db
    115 {
    116     my $self = shift;
    117 
    118     return scalar @{ $self->{dbs} };
    119 }
    120 
    121 
    122 package Nebulous::Server::Config::DB;
    123 
    124 use strict;
    125 use warnings FATAL => qw( all );
    126 
    127 our $VERSION = 0.01;
    128 
    129 use base qw( Class::Accessor::Fast );
    130 
    131 __PACKAGE__->mk_ro_accessors(qw( dsn dbuser dbpasswd ));
    132 
    133601;
    13461
  • trunk/Nebulous-Server/lib/Nebulous/Server/Log.pm

    r20965 r20990  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Log.pm,v 1.8 2008-12-12 21:13:41 jhoblitt Exp $
     3# $Id: Log.pm,v 1.9 2008-12-14 22:54:25 eugene Exp $
    44
    55package Nebulous::Server::Log;
     
    1616    my ($self, $config) = @_;
    1717
    18 #    my $dsn         = $config->db->dsn;
    19 #    my $dbuser      = $config->db->dbuser;
    20 #    my $dbpasswd    = $config->db->dbpasswd;
     18    my $dsn         = $config->dsn;
     19    my $dbuser      = $config->dbuser;
     20    my $dbpasswd    = $config->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.sql        = \
    34 #    log4perl.appender.SQLLOG.datasource =
    35 #    log4perl.appender.SQLLOG.username   =
    36 #    log4perl.appender.SQLLOG.password   =
     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        = \
    3737    INSERT INTO log (timestamp, hostname, level, sub, message) \
    3838    VALUES          (%d,        %H,       %p,    %M,  %m)
  • trunk/Nebulous-Server/lib/Nebulous/Server/SOAP.pm

    r20972 r20990  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SOAP.pm,v 1.5 2008-12-13 00:41:15 jhoblitt Exp $
     3# $Id: SOAP.pm,v 1.6 2008-12-14 22:54:25 eugene Exp $
    44
    55package Nebulous::Server::SOAP;
     
    1717our $AUTOLOAD;
    1818
    19 our $config;
     19our @args;
    2020our $neb;
    2121
    22 
    23 sub new_on_init
    24 {
     22sub new_on_init {
    2523    my $self = shift;
    2624
     
    2927    require Apache2::ServerUtil;
    3028
    31     $config = shift;
     29    @args = @_;
    3230
    3331    my $s = Apache2::ServerUtil->server;
     
    3735}
    3836
    39 
    40 sub init
    41 {
     37sub init {
    4238    my $self = shift;
    4339
    44     $neb = Nebulous::Server->new_from_config($config);       
     40    $neb = Nebulous::Server->new(@args);       
    4541
    4642    return Apache2::Const::OK;
    4743}
    4844
    49 
    50 sub AUTOLOAD
    51 {
     45sub AUTOLOAD {
    5246    my $self = shift;
    5347
     
    8276}
    8377
    84 
    85781;
  • trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm

    r20966 r20990  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SQL.pm,v 1.77 2008-12-12 21:41:07 jhoblitt Exp $
     3# $Id: SQL.pm,v 1.78 2008-12-14 22:54:25 eugene Exp $
    44
    55package Nebulous::Server::SQL;
     
    88use warnings FATAL => qw( all );
    99
    10 our $VERSION = '0.03';
     10our $VERSION = '0.02';
    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 = ?
    5349    },
    5450    get_object          => qq{
     
    328324        HAVING available_instances < instances OR instances < copies
    329325    },
    330     find_objects_with_extra_instances_by_xattr => qq{
    331         SELECT
    332             so.so_id,
    333             so.ext_id,
     326    find_objects_with_extra_instances => qq{
     327        SELECT
     328            storage_object.so_id,
     329            ext_id,
    334330            count(ins_id) as instances,
    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
     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
    346344            USING(vol_id)
    347345        WHERE
    348             mv.available = 1
     346            mymountedvol.available = 1
     347            AND storage_object_xattr.name = 'user.copies'
    349348        GROUP BY so_id
    350349        HAVING available_instances > copies
    351         limit 5;
    352350    },
    353351    get_mounted_volumes => qq{
  • trunk/Nebulous-Server/t/02_server_setup.t

    r20965 r20990  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 02_server_setup.t,v 1.7 2008-12-12 21:13:41 jhoblitt Exp $
     5# $Id: 02_server_setup.t,v 1.8 2008-12-14 22:54:25 eugene Exp $
    66
    77use strict;
    88use warnings;
    99
    10 use Test::More tests => 6;
     10use Test::More tests => 2;
    1111
    1212use lib qw( ./t ./lib );
     
    1717Test::Nebulous->setup;
    1818
    19 isa_ok(Nebulous::Server->new(), "Nebulous::Server");
     19isa_ok(
     20    Nebulous::Server->new(
     21        dsn         => $NEB_DB,
     22        dbuser      => $NEB_USER,
     23        dbpasswd    => $NEB_PASS,
     24    ),
     25    "Nebulous::Server"
     26);
    2027
    2128Test::Nebulous->setup;
    2229
    23 # ->new()
    24 {
    25     my $neb = Nebulous::Server->new( log_level => 'off' );
    26 
    27     ok($neb, "set log level");
    28 }
    29 
    30 Test::Nebulous->setup;
    31 
    32 {
    33     my $neb = Nebulous::Server->new(
     30eval {
     31    Nebulous::Server->new(
    3432        dsn         => "DBI:mysql:database=foobar:host=localhost",
    3533        dbuser      => "baz",
    3634        dbpasswd    =>"boo",
    3735    );
    38 
    39     ok($neb, "set database");
    40 }
    41 
    42 Test::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 }
     36};
     37like( $@, qr/DBI connect.*? failed/, "bad dsn/user/pass" );
    6438
    6539Test::Nebulous->cleanup;
  • trunk/Nebulous-Server/t/08_server_delete_instance.t

    r20965 r20990  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 08_server_delete_instance.t,v 1.11 2008-12-12 21:13:41 jhoblitt Exp $
     5# $Id: 08_server_delete_instance.t,v 1.12 2008-12-14 22:54:25 eugene Exp $
    66
    77use strict;
     
    2424
    2525{
    26     my $key = "foo";
    27     my $uri = $neb->create_object($key);
     26    my $uri = $neb->create_object("foo");
    2827
    29     ok($neb->delete_instance($key, $uri), "delete instance");
     28    ok($neb->delete_instance($uri), "delete instance");
    3029}
    3130
     
    3332
    3433{
    35     my $key = "foo";
    36     my $uri1 = $neb->create_object($key);
    37     my $uri2 = $neb->replicate_object($key);
     34    my $uri1 = $neb->create_object("foo");
     35    my $uri2 = $neb->replicate_object("foo");
    3836
    39     ok($neb->delete_instance($key, $uri1), "delete instance");
     37    ok($neb->delete_instance($uri1), "delete instance");
    4038
    41     my $locations = $neb->find_instances($key);
     39    my $locations = $neb->find_instances("foo");
    4240
    4341    is($locations->[0], $uri2, "instance remains");
    4442
    45     ok($neb->delete_instance($key, $uri2), "delete instance");
     43    ok($neb->delete_instance( $uri2 ), "delete instance");
    4644
    4745    eval {
    48         $neb->find_instances($key);
     46        $neb->find_instances("foo");
    4947    };
    5048    like($@, qr/is valid object key/, "storage object was deleted");
     
    5452
    5553eval {
    56     my $key = "foo";
    57     my $uri1 = $neb->create_object($key);
    58 
    59     $neb->delete_instance($key, "file:/foo");
     54    $neb->delete_instance("file:/foo");
    6055};
    6156like($@, qr/no instance is associated with uri/, "uri does not exist");
     
    6661    $neb->delete_instance();
    6762};
    68 like($@, qr/2 were expected/, "no params");
     63like($@, qr/1 was expected/, "no params");
    6964
    7065Test::Nebulous->setup;
    7166
    7267eval {
    73     my $key = "foo";
    74     my $uri1 = $neb->create_object($key);
    75 
    76     $neb->delete_instance("foo", 2, 3);
     68    $neb->delete_instance("foo", 2);
    7769};
    78 like($@, qr/2 were expected/, "too many params");
     70like($@, qr/1 was expected/, "too many params");
    7971
    8072Test::Nebulous->cleanup;
  • trunk/Nebulous-Server/t/10_server_is_valid_volume_name.t

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