Changeset 10546 for trunk/Nebulous-Server
- Timestamp:
- Dec 7, 2006, 5:29:19 PM (20 years ago)
- Location:
- trunk/Nebulous-Server
- Files:
-
- 13 edited
-
Changes (modified) (1 diff)
-
lib/Nebulous/Server.pm (modified) (18 diffs)
-
t/02_server_setup.t (modified) (3 diffs)
-
t/03_server_create_object.t (modified) (2 diffs)
-
t/04_server_replicate_object.t (modified) (2 diffs)
-
t/05_server_lock_object.t (modified) (2 diffs)
-
t/06_server_unlock_object.t (modified) (2 diffs)
-
t/07_server_find_instances.t (modified) (2 diffs)
-
t/08_server_delete_instance.t (modified) (2 diffs)
-
t/09_server_is_valid_class_id.t (modified) (3 diffs)
-
t/09_server_stat_object.t (modified) (2 diffs)
-
t/10_server_is_valid_volume_name.t (modified) (3 diffs)
-
t/11_server_is_valid_class_id.t (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/Changes
r5671 r10546 1 1 Revision history for Perl module Poi::PixelData 2 3 0.03 4 - change Nebulous::Server instantiate objects (init -> new) instead of 5 working with class data 6 - add a DESTROY method to Nebulous::Server to tear down the database 7 connection 2 8 3 9 0.02 Fri Dec 2 17:36:59 HST 2005 -
trunk/Nebulous-Server/lib/Nebulous/Server.pm
r5664 r10546 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1. 19 2005-12-03 02:32:56jhoblitt Exp $3 # $Id: Server.pm,v 1.20 2006-12-08 03:29:19 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 8 8 use warnings FATAL => qw( all ); 9 9 10 our $VERSION = '0.02'; 10 our $VERSION = '0.03'; 11 12 use base qw( Class::Accessor::Fast ); 11 13 12 14 use DBI; … … 18 20 use Params::Validate qw( validate_pos SCALAR ); 19 21 20 my $log; 21 my $sql; 22 my $db; 23 24 sub init { 25 my $self = shift; 22 __PACKAGE__->mk_accessors(qw( log sql db )); 23 24 sub new { 25 my $class = shift; 26 26 27 27 # let Nebulous::Server::Config validate our params … … 31 31 Nebulous::Server::Log->init; 32 32 33 $log = Log::Log4perl::get_logger( "Nebulous::Server" ); 34 $sql = Nebulous::Server::SQL->new; 35 36 $log->debug( "entered - @_" ); 37 33 my $log = Log::Log4perl::get_logger( "Nebulous::Server" ); 34 my $sql = Nebulous::Server::SQL->new; 35 36 $log->debug( "entered - @_" ); 37 38 my $db; 38 39 eval { 39 40 $db = DBI->connect( … … 61 62 $log->debug( "leaving" ); 62 63 63 return 1; 64 my $self = bless {}, ref $class || $class; 65 $self->log($log); 66 $self->sql($sql); 67 $self->db($db); 68 69 return $self; 64 70 } 65 71 … … 76 82 'is + integer' => sub { $_[0] =~ /^\d+$/ }, 77 83 # check that the class requested is valid 78 'is valid class id' => sub { _is_valid_class_id( $_[0] ) },84 'is valid class id' => sub { $self->_is_valid_class_id( $_[0] ) }, 79 85 }, 80 86 default => 0, … … 84 90 callbacks => { 85 91 # check that the volume requested is valid 86 'is valid volume name' => sub { _is_valid_volume_name($_[0]) },92 'is valid volume name' => sub { $self->_is_valid_volume_name($_[0]) }, 87 93 }, 88 94 optional => 1, … … 98 104 ); 99 105 106 my $log = $self->log; 107 my $sql = $self->sql; 108 my $db =$self->db; 109 100 110 $log->debug( "entered - @_" ); 101 111 102 112 # TODO do some intelligent volume allocated 103 113 # add hooks to make this decision based on avaiable space 104 $volume = _get_storage_volume( $volume );114 $volume = $self->_get_storage_volume( $volume ); 105 115 106 116 my $uri; … … 194 204 ); 195 205 206 my $log = $self->log; 207 my $sql = $self->sql; 208 my $db =$self->db; 209 196 210 $log->debug( "entered - @_" ); 197 211 198 212 # TODO 199 $volume = _get_storage_volume();213 $volume = $self->_get_storage_volume(); 200 214 201 215 my $path; … … 277 291 }, 278 292 ); 293 294 my $log = $self->log; 295 my $sql = $self->sql; 296 my $db =$self->db; 279 297 280 298 $log->debug( "entered - @_" ); … … 393 411 ); 394 412 413 my $log = $self->log; 414 my $sql = $self->sql; 415 my $db =$self->db; 416 395 417 $log->debug( "entered - @_" ); 396 418 … … 514 536 ); 515 537 538 my $log = $self->log; 539 my $sql = $self->sql; 540 my $db =$self->db; 541 516 542 $log->debug( "entered - @_" ); 517 543 … … 548 574 }, 549 575 ); 576 577 my $log = $self->log; 578 my $sql = $self->sql; 579 my $db =$self->db; 550 580 551 581 $log->debug( "entered - @_" ); … … 622 652 ); 623 653 654 my $log = $self->log; 655 my $sql = $self->sql; 656 my $db =$self->db; 657 624 658 $log->debug( "entered - @_" ); 625 659 … … 649 683 650 684 sub _get_storage_volume { 685 my $self = shift; 686 687 my $log = $self->log; 688 my $sql = $self->sql; 689 my $db =$self->db; 690 651 691 no warnings qw( uninitialized ); 652 692 $log->debug( "entered - @_" ); … … 690 730 691 731 sub _is_valid_class_id { 692 my $class_id = shift; 732 my ($self, $class_id) = @_; 733 734 my $log = $self->log; 735 my $sql = $self->sql; 736 my $db = $self->db; 693 737 694 738 my $class; … … 709 753 710 754 sub _is_valid_volume_name { 711 my $vol_name = shift; 755 my ($self, $vol_name) = @_; 756 757 my $log = $self->log; 758 my $sql = $self->sql; 759 my $db =$self->db; 712 760 713 761 my $volume; 714 762 eval { 715 my $query = $db->prepare_cached( $sql->get_volume_by_name );763 my $query = $db->prepare_cached( $sql->get_volume_by_name ); 716 764 $query->execute( $vol_name ); 717 765 ( $volume ) = $query->fetchrow_array; … … 727 775 } 728 776 777 sub DESTROY { 778 my $self = shift; 779 780 my $log = $self->log; 781 my $sql = $self->sql; 782 my $db =$self->db; 783 784 $log->debug( "entered" ); 785 786 $self->db->disconnect; 787 788 $log->debug( "disconnected from database: ", sub { $db->data_sources; } ); 789 790 $log->debug( "leaving" ); 791 } 792 729 793 1; 730 794 -
trunk/Nebulous-Server/t/02_server_setup.t
r4873 r10546 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 02_server_setup.t,v 1. 4 2005-08-25 01:40:04jhoblitt Exp $5 # $Id: 02_server_setup.t,v 1.5 2006-12-08 03:29:19 jhoblitt Exp $ 6 6 7 7 use strict; … … 17 17 Test::Nebulous->setup; 18 18 19 ok(20 Nebulous::Server-> init(19 isa_ok( 20 Nebulous::Server->new( 21 21 dsn => "DBI:mysql:database=test:host=localhost", 22 22 dbuser => "test", 23 23 dbpasswd => "", 24 24 ), 25 " connect",25 "Nebulous::Server" 26 26 ); 27 27 … … 29 29 30 30 eval { 31 Nebulous::Server-> init(31 Nebulous::Server->new( 32 32 dsn => "DBI:mysql:database=foobar:host=localhost", 33 33 dbuser => "baz", -
trunk/Nebulous-Server/t/03_server_create_object.t
r5504 r10546 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 03_server_create_object.t,v 1.1 0 2005-11-10 22:07:53jhoblitt Exp $5 # $Id: 03_server_create_object.t,v 1.11 2006-12-08 03:29:19 jhoblitt Exp $ 6 6 7 7 use strict; … … 16 16 use Test::Nebulous; 17 17 18 my $neb = "Nebulous::Server"; 19 20 $neb->init( 18 my $neb = Nebulous::Server->new( 21 19 dsn => "DBI:mysql:database=test:host=localhost", 22 20 dbuser => "test", -
trunk/Nebulous-Server/t/04_server_replicate_object.t
r4873 r10546 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 04_server_replicate_object.t,v 1. 5 2005-08-25 01:40:04jhoblitt Exp $5 # $Id: 04_server_replicate_object.t,v 1.6 2006-12-08 03:29:19 jhoblitt Exp $ 6 6 7 7 use strict; … … 16 16 use Test::Nebulous; 17 17 18 my $neb = "Nebulous::Server"; 19 20 $neb->init( 18 my $neb = Nebulous::Server->new( 21 19 dsn => "DBI:mysql:database=test:host=localhost", 22 20 dbuser => "test", -
trunk/Nebulous-Server/t/05_server_lock_object.t
r4873 r10546 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 05_server_lock_object.t,v 1. 5 2005-08-25 01:40:04jhoblitt Exp $5 # $Id: 05_server_lock_object.t,v 1.6 2006-12-08 03:29:19 jhoblitt Exp $ 6 6 7 7 use strict; … … 16 16 use Test::Nebulous; 17 17 18 my $neb = "Nebulous::Server"; 19 20 $neb->init( 18 my $neb = Nebulous::Server->new( 21 19 dsn => "DBI:mysql:database=test:host=localhost", 22 20 dbuser => "test", -
trunk/Nebulous-Server/t/06_server_unlock_object.t
r4873 r10546 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 06_server_unlock_object.t,v 1. 5 2005-08-25 01:40:04jhoblitt Exp $5 # $Id: 06_server_unlock_object.t,v 1.6 2006-12-08 03:29:19 jhoblitt Exp $ 6 6 7 7 use strict; … … 16 16 use Test::Nebulous; 17 17 18 my $neb = "Nebulous::Server"; 19 20 $neb->init( 18 my $neb = Nebulous::Server->new( 21 19 dsn => "DBI:mysql:database=test:host=localhost", 22 20 dbuser => "test", -
trunk/Nebulous-Server/t/07_server_find_instances.t
r4873 r10546 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 07_server_find_instances.t,v 1. 5 2005-08-25 01:40:04jhoblitt Exp $5 # $Id: 07_server_find_instances.t,v 1.6 2006-12-08 03:29:19 jhoblitt Exp $ 6 6 7 7 use strict; … … 16 16 use Test::Nebulous; 17 17 18 my $neb = "Nebulous::Server"; 19 20 $neb->init( 18 my $neb = Nebulous::Server->new( 21 19 dsn => "DBI:mysql:database=test:host=localhost", 22 20 dbuser => "test", -
trunk/Nebulous-Server/t/08_server_delete_instance.t
r4873 r10546 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 08_server_delete_instance.t,v 1. 5 2005-08-25 01:40:04jhoblitt Exp $5 # $Id: 08_server_delete_instance.t,v 1.6 2006-12-08 03:29:19 jhoblitt Exp $ 6 6 7 7 use strict; … … 16 16 use Test::Nebulous; 17 17 18 my $neb = "Nebulous::Server"; 19 20 $neb->init( 18 my $neb = Nebulous::Server->new( 21 19 dsn => "DBI:mysql:database=test:host=localhost", 22 20 dbuser => "test", -
trunk/Nebulous-Server/t/09_server_is_valid_class_id.t
r5498 r10546 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 09_server_is_valid_class_id.t,v 1. 1 2005-11-10 21:31:26jhoblitt Exp $5 # $Id: 09_server_is_valid_class_id.t,v 1.2 2006-12-08 03:29:19 jhoblitt Exp $ 6 6 7 7 use strict; … … 16 16 use Test::Nebulous; 17 17 18 my $neb = "Nebulous::Server"; 19 20 $neb->init( 18 my $neb = Nebulous::Server->new( 21 19 dsn => "DBI:mysql:database=test:host=localhost", 22 20 dbuser => "test", … … 24 22 ); 25 23 26 *_is_valid_class_id = \&Nebulous::Server::_is_valid_class_id;27 28 24 Test::Nebulous->setup; 29 25 30 26 # 0 is the default and is guarenteed to exist 31 ok( _is_valid_class_id( 0 ), "default class id");27 ok( $neb->_is_valid_class_id( 0 ), "default class id"); 32 28 33 29 Test::Nebulous->setup; 34 30 35 31 # the test setup adds class id 1 36 ok( _is_valid_class_id( 1 ), "custom class id");32 ok( $neb->_is_valid_class_id( 1 ), "custom class id"); 37 33 38 34 Test::Nebulous->setup; 39 35 40 is( _is_valid_class_id( 99 ), undef, "invalid class id");36 is( $neb->_is_valid_class_id( 99 ), undef, "invalid class id"); 41 37 42 38 Test::Nebulous->cleanup; -
trunk/Nebulous-Server/t/09_server_stat_object.t
r5492 r10546 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 09_server_stat_object.t,v 1. 7 2005-11-09 01:35:59 jhoblitt Exp $5 # $Id: 09_server_stat_object.t,v 1.8 2006-12-08 03:29:19 jhoblitt Exp $ 6 6 7 7 use strict; … … 16 16 use Test::Nebulous; 17 17 18 my $neb = "Nebulous::Server"; 19 20 $neb->init( 18 my $neb = Nebulous::Server->new( 21 19 dsn => "DBI:mysql:database=test:host=localhost", 22 20 dbuser => "test", -
trunk/Nebulous-Server/t/10_server_is_valid_volume_name.t
r5667 r10546 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 10_server_is_valid_volume_name.t,v 1. 1 2005-12-03 02:52:31jhoblitt Exp $5 # $Id: 10_server_is_valid_volume_name.t,v 1.2 2006-12-08 03:29:19 jhoblitt Exp $ 6 6 7 7 use strict; … … 16 16 use Test::Nebulous; 17 17 18 my $neb = "Nebulous::Server"; 19 20 $neb->init( 18 my $neb = Nebulous::Server->new( 21 19 dsn => "DBI:mysql:database=test:host=localhost", 22 20 dbuser => "test", … … 24 22 ); 25 23 26 *_is_valid_volume_name = \&Nebulous::Server::_is_valid_volume_name; 24 Test::Nebulous->setup; 25 26 ok( $neb->_is_valid_volume_name( 'node01' ), "valid volume name" ); 27 27 28 28 Test::Nebulous->setup; 29 29 30 ok( _is_valid_volume_name( 'node01' ), "valid volume name" );30 ok( $neb->_is_valid_volume_name( 'node02' ), "valid volume name" ); 31 31 32 32 Test::Nebulous->setup; 33 33 34 ok( _is_valid_volume_name( 'node02' ), "valid volume name" ); 35 36 Test::Nebulous->setup; 37 38 is( _is_valid_volume_name( 'node99' ), undef, "invalid volume name" ); 34 is( $neb->_is_valid_volume_name( 'node99' ), undef, "invalid volume name" ); 39 35 40 36 Test::Nebulous->cleanup; -
trunk/Nebulous-Server/t/11_server_is_valid_class_id.t
r5667 r10546 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 11_server_is_valid_class_id.t,v 1. 1 2005-12-03 02:52:31jhoblitt Exp $5 # $Id: 11_server_is_valid_class_id.t,v 1.2 2006-12-08 03:29:19 jhoblitt Exp $ 6 6 7 7 use strict; … … 16 16 use Test::Nebulous; 17 17 18 my $neb = "Nebulous::Server"; 19 20 $neb->init( 18 my $neb = Nebulous::Server->new( 21 19 dsn => "DBI:mysql:database=test:host=localhost", 22 20 dbuser => "test", … … 24 22 ); 25 23 26 *_is_valid_class_id = \&Nebulous::Server::_is_valid_class_id;27 28 24 Test::Nebulous->setup; 29 25 30 26 # 0 is the default and is guarenteed to exist 31 ok( _is_valid_class_id( 0 ), "default class id");27 ok( $neb->_is_valid_class_id( 0 ), "default class id"); 32 28 33 29 Test::Nebulous->setup; 34 30 35 31 # the test setup adds class id 1 36 ok( _is_valid_class_id( 1 ), "custom class id");32 ok( $neb->_is_valid_class_id( 1 ), "custom class id"); 37 33 38 34 Test::Nebulous->setup; 39 35 40 is( _is_valid_class_id( 99 ), undef, "invalid class id");36 is( $neb->_is_valid_class_id( 99 ), undef, "invalid class id"); 41 37 42 38 Test::Nebulous->cleanup;
Note:
See TracChangeset
for help on using the changeset viewer.
