Changeset 20965
- Timestamp:
- Dec 12, 2008, 11:13:41 AM (17 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 18 edited
-
Nebulous-Server/MANIFEST (modified) (1 diff)
-
Nebulous-Server/lib/Nebulous/Server.pm (modified) (40 diffs)
-
Nebulous-Server/lib/Nebulous/Server/Config.pm (modified) (5 diffs)
-
Nebulous-Server/lib/Nebulous/Server/Log.pm (modified) (3 diffs)
-
Nebulous-Server/lib/Nebulous/Server/SQL.pm (modified) (3 diffs)
-
Nebulous-Server/t/02_config.t (added)
-
Nebulous-Server/t/02_server_setup.t (modified) (2 diffs)
-
Nebulous-Server/t/08_server_delete_instance.t (modified) (5 diffs)
-
Nebulous-Server/t/10_server_is_valid_volume_name.t (modified) (2 diffs)
-
Nebulous/lib/Nebulous/Client.pm (modified) (7 diffs)
-
Nebulous/nebclient/nebulous.wsdl (modified) (1 diff)
-
Nebulous/nebclient/src/nebclient.c (modified) (5 diffs)
-
Nebulous/nebclient/src/nebclient.h (modified) (2 diffs)
-
Nebulous/nebclient/src/nebulous.h (modified) (4 diffs)
-
Nebulous/nebclient/src/soapC.c (modified) (6 diffs)
-
Nebulous/nebclient/src/soapClient.c (modified) (3 diffs)
-
Nebulous/nebclient/src/soapServer.c (modified) (2 diffs)
-
Nebulous/nebclient/src/soapStub.h (modified) (3 diffs)
-
Nebulous/t/62_client_delete_instance.t (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/MANIFEST
r20091 r20965 35 35 t/00_distribution.t 36 36 t/01_load.t 37 t/02_config.t 37 38 t/02_server_setup.t 38 39 t/03_server_create_object.t -
trunk/Nebulous-Server/lib/Nebulous/Server.pm
r20091 r20965 1 1 # Copyright (c) 2004-2008 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1.9 3 2008-10-13 20:41:17jhoblitt Exp $3 # $Id: Server.pm,v 1.94 2008-12-12 21:13:41 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 9 9 no warnings qw( uninitialized ); 10 10 11 our $VERSION = '0.1 5';11 our $VERSION = '0.16'; 12 12 13 13 use base qw( Class::Accessor::Fast ); … … 19 19 use File::Spec; 20 20 use Log::Log4perl; 21 use Nebulous::Keys qw( parse_neb_key parse_neb_volume ); 21 22 use Nebulous::Server::Config; 22 23 use Nebulous::Server::Log; 23 24 use Nebulous::Server::SQL; 24 use Nebulous::Keys qw( parse_neb_key parse_neb_volume );25 25 use Params::Validate qw( validate_pos SCALAR SCALARREF UNDEF ); 26 26 use URI::file; … … 36 36 37 37 # let Nebulous::Server::Config validate our params 38 my $config = Nebulous::Server::Config-> init( @_ );38 my $config = Nebulous::Server::Config->new( @_ ); 39 39 40 40 # log4perl is not avaliable until we call init() … … 51 51 $self->config($config); 52 52 53 # ask for the db handle as a means of validating the database parameters54 $self->db;55 56 53 $log->debug( "leaving" ); 57 54 … … 62 59 sub db 63 60 { 64 my $self = shift; 65 66 if (@_) { 67 $self->{db} = $_[0]; 68 return $self; 69 } 61 my ($self, $key) = @_; 70 62 71 63 my $log = $self->log; … … 73 65 my $config = $self->config; 74 66 67 my $db_index = 0; 68 if (defined $key) { 69 # hash the key to select the correct database instance 70 $db_index = unpack("%20h", sha1_hex("$key")) % $config->n_db; 71 } 72 73 # lookup to see if we have a stored dbh for this database 74 my $dbh = $self->{dbs}[$db_index]; 75 75 # if the dbh is still alive, return it 76 if (defined $ self->{db} and $self->{db}->ping) {76 if (defined $dbh and $dbh->ping) { 77 77 $log->debug("db handle is still alive"); 78 return $ self->{db};78 return $dbh; 79 79 } 80 80 # otherwise create a new connection 81 81 $log->debug("db handle is dead/unopened"); 82 83 # lookup database info 84 my $db_config = $config->db($db_index); 85 die "can't find database configuration info for database # $db_index" 86 unless $db_config; 82 87 83 88 # if we're running under mod_perl & Apache::DBI is loaded we want to … … 86 91 # processes and the database might have gone away on us. Apache::DBI will 87 92 # 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, 93 eval { 94 $dbh = DBI->connect_cached( 95 $db_config->dsn, 96 $db_config->dbuser, 97 $db_config->dbpasswd, 94 98 { 95 99 RaiseError => 1, … … 99 103 ); 100 104 101 $db ->do( $sql->set_transaction_model );102 $log->debug( "connected to database: ", sub { $db ->data_sources; } );103 $db ->commit;105 $dbh->do( $sql->set_transaction_model ); 106 $log->debug( "connected to database: ", sub { $dbh->data_sources; } ); 107 $dbh->commit; 104 108 $log->debug("commit"); 105 109 }; 106 110 if ( $@ ) { 107 $db ->rollback if $db;111 $dbh->rollback if $dbh; 108 112 $log->debug("rollback"); 109 113 $log->logdie( "database error: $@" ); 110 114 } 111 115 112 $self->{db } = $db;113 114 return $db ;116 $self->{dbs}[$db_index] = $dbh; 117 118 return $dbh; 115 119 } 116 120 … … 139 143 my $log = $self->log; 140 144 my $sql = $self->sql; 141 my $db = $self->db;145 my $db = $self->db($key); 142 146 143 147 $log->debug( "entered - @_" ); … … 150 154 # to check it after parsing the key 151 155 if (defined $vol_name 152 and not $self->_is_valid_volume_name($key ->volume)) {156 and not $self->_is_valid_volume_name($key, $key->volume)) { 153 157 if ($key->soft_volume) { 154 158 $log->warn( "$vol_name is not a known volume name" ); … … 160 164 161 165 my ($vol_id, $vol_host, $vol_path, $vol_xattr) 162 = $self->_get_storage_volume($ vol_name, $key->soft_volume);166 = $self->_get_storage_volume($key, $vol_name, $key->soft_volume); 163 167 164 168 my $uri; … … 261 265 my $log = $self->log; 262 266 my $sql = $self->sql; 263 my $db = $self->db;267 my $db = $self->db($key); 264 268 265 269 $log->debug("entered - @_"); … … 296 300 297 301 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 } 302 # sub swap_objects 303 # { 304 # my $self = shift; 305 # 306 # my ($key1, $key2) = validate_pos(@_, 307 # { 308 # type => SCALAR, 309 # callbacks => { 310 # 'is valid object key' => sub { $self->_is_valid_object_key($_[0]) }, 311 # }, 312 # }, 313 # { 314 # type => SCALAR, 315 # callbacks => { 316 # 'is valid object key' => sub { $self->_is_valid_object_key($_[0]) }, 317 # }, 318 # }, 319 # ); 320 # 321 # my $log = $self->log; 322 # my $sql = $self->sql; 323 # my $dbh1 = $self->db($key1); 324 # my $dbh2 = $self->db($key2); 325 # 326 # $log->debug("entered - @_"); 327 # 328 # # ignore volumes 329 # $key1 = parse_neb_key($key1); 330 # $key2 = parse_neb_key($key2); 331 # 332 # # order of operations for the swap with a single db is: 333 # # key1 -> key1.swap 334 # # key2 -> key1 335 # # key1.swap -> key2 336 # 337 # # XXX this cmp will only work if ->db() returns the same exact (cached) dbh 338 # if ($dbh1 == $dbh2) { 339 # my $dbh = $dbh1; 340 # eval { 341 # { 342 # # key1 -> key1.swap 343 # my $query = $dbh->prepare_cached($sql->rename_object); 344 # # this SQL statment takes the new key name as the first param 345 # my $rows = $query->execute($key1->path . ".swap", $key1->path); 346 # 347 # # if we affected more then one row something very bad has happened. 348 # unless ($rows == 1) { 349 # $query->finish; 350 # $log->logdie("affected row count is $rows instead of 1"); 351 # } 352 # } 353 # 354 # { 355 # # key2 -> key1 356 # my $query = $dbh->prepare_cached($sql->rename_object); 357 # # this SQL statment takes the new key name as the first param 358 # my $rows = $query->execute($key1->path, $key2->path); 359 # 360 # # if we affected more then one row something very bad has happened. 361 # unless ($rows == 1) { 362 # $query->finish; 363 # $log->logdie("affected row count is $rows instead of 1"); 364 # } 365 # } 366 # 367 # { 368 # # key1.swap -> key2 369 # my $query = $dbh->prepare_cached($sql->rename_object); 370 # # this SQL statment takes the new key name as the first param 371 # my $rows = $query->execute($key2->path, $key1->path . ".swap"); 372 # 373 # # if we affected more then one row something very bad has happened. 374 # unless ($rows == 1) { 375 # $query->finish; 376 # $log->logdie("affected row count is $rows instead of 1"); 377 # } 378 # } 379 # 380 # $dbn->commit; 381 # $log->debug("commit"); 382 # }; 383 # if ($@) { 384 # $dbh->rollback; 385 # $log->debug("rollback"); 386 # $log->logdie("database error: $@"); 387 # } 388 # } 389 # 390 # # order of operations for the swap between two dbs is: 391 # # key1 start transaction 392 # # key1 -> read all instances 393 # # key1 -> remove all instances 394 # # key2 start transaction 395 # # key2 -> read all instances 396 # # key2 -> remove all instances 397 # # key1 -> insert key 2 instances 398 # # key2 -> insert key 1 instances 399 # # key1,2 commit 400 # 401 # eval { 402 # { 403 # # key1 -> read all instances 404 # my $query = $dbh->prepare_cached($sql->rename_object); 405 # # this SQL statment takes the new key name as the first param 406 # my $rows = $query->execute($key1->path . ".swap", $key1->path); 407 # 408 # # if we affected more then one row something very bad has happened. 409 # unless ($rows == 1) { 410 # $query->finish; 411 # $log->logdie("affected row count is $rows instead of 1"); 412 # } 413 # } 414 # 415 # { 416 # # key2 -> key1 417 # my $query = $db->prepare_cached($sql->rename_object); 418 # # this SQL statment takes the new key name as the first param 419 # my $rows = $query->execute($key1->path, $key2->path); 420 # 421 # # if we affected more then one row something very bad has happened. 422 # unless ($rows == 1) { 423 # $query->finish; 424 # $log->logdie("affected row count is $rows instead of 1"); 425 # } 426 # } 427 # 428 # { 429 # # key1.swap -> key2 430 # my $query = $db->prepare_cached($sql->rename_object); 431 # # this SQL statment takes the new key name as the first param 432 # my $rows = $query->execute($key2->path, $key1->path . ".swap"); 433 # 434 # # if we affected more then one row something very bad has happened. 435 # unless ($rows == 1) { 436 # $query->finish; 437 # $log->logdie("affected row count is $rows instead of 1"); 438 # } 439 # } 440 # 441 # $db->commit; 442 # $log->debug("commit"); 443 # }; 444 # if ($@) { 445 # $db->rollback; 446 # $log->debug("rollback"); 447 # $log->logdie("database error: $@"); 448 # } 449 # 450 # 451 # $log->debug("leaving"); 452 # 453 # return 1; 454 # } 385 455 386 456 … … 420 490 my $log = $self->log; 421 491 my $sql = $self->sql; 422 my $db = $self->db;492 my $db = $self->db($key); 423 493 424 494 $log->debug("entered - @_"); … … 429 499 430 500 if (defined $vol_name 431 and not $self->_is_valid_volume_name($key ->volume)) {501 and not $self->_is_valid_volume_name($key, $key->volume)) { 432 502 if ($key->soft_volume) { 433 503 $log->warn( "$vol_name is not a known volume name" ); … … 441 511 if (defined $vol_name) { 442 512 ($vol_id, $vol_host, $vol_path, $vol_xattr) 443 = $self->_get_storage_volume($ vol_name);513 = $self->_get_storage_volume($key, $vol_name); 444 514 } else { 445 515 ($vol_id, $vol_host, $vol_path, $vol_xattr) … … 534 604 my $log = $self->log; 535 605 my $sql = $self->sql; 536 my $db = $self->db;606 my $db = $self->db($key); 537 607 538 608 $log->debug( "entered - @_" ); … … 637 707 my $log = $self->log; 638 708 my $sql = $self->sql; 639 my $db = $self->db;709 my $db = $self->db($key); 640 710 641 711 $log->debug( "entered - @_" ); … … 749 819 my $log = $self->log; 750 820 my $sql = $self->sql; 751 my $db = $self->db;821 my $db = $self->db($key); 752 822 753 823 $log->debug("entered - @_"); … … 816 886 my $log = $self->log; 817 887 my $sql = $self->sql; 818 my $db = $self->db;888 my $db = $self->db($key); 819 889 820 890 $log->debug("entered - @_"); … … 869 939 my $log = $self->log; 870 940 my $sql = $self->sql; 871 my $db = $self->db;941 my $db = $self->db($key); 872 942 873 943 $log->debug("entered - @_"); … … 912 982 my $log = $self->log; 913 983 my $sql = $self->sql; 914 my $db = $self->db;984 my $db = $self->db($key); 915 985 916 986 $log->debug("entered - @_"); … … 947 1017 sub find_objects 948 1018 { 949 my $self = shift; 950 951 my ( $pattern ) = validate_pos( @_, 1019 # XXX: this will only search one db 1020 1021 my $self = shift; 1022 1023 my ($pattern) = validate_pos( @_, 952 1024 { 953 1025 type => SCALAR, … … 958 1030 my $log = $self->log; 959 1031 my $sql = $self->sql; 960 my $db = $self->db;1032 my $db = $self->db; 961 1033 962 1034 $log->debug( "entered - @_" ); … … 1016 1088 my $log = $self->log; 1017 1089 my $sql = $self->sql; 1018 my $db = $self->db;1090 my $db = $self->db($key); 1019 1091 1020 1092 $log->debug("entered - @_"); … … 1027 1099 # to check it after parsing the key 1028 1100 if (defined $vol_name 1029 and not $self->_is_valid_volume_name($key ->volume)) {1101 and not $self->_is_valid_volume_name($key, $key->volume)) { 1030 1102 if ($key->soft_volume) { 1031 1103 $log->warn( "$vol_name is not a known volume name" ); … … 1087 1159 my $self = shift; 1088 1160 1089 my ( $uri ) = validate_pos( @_, 1161 my ($key, $uri) = validate_pos( @_, 1162 { 1163 type => SCALAR, 1164 callbacks => { 1165 'is valid object key' => sub { $self->_is_valid_object_key($_[0]) }, 1166 }, 1167 }, 1090 1168 { 1091 1169 type => SCALAR|SCALARREF, … … 1095 1173 my $log = $self->log; 1096 1174 my $sql = $self->sql; 1097 my $db = $self->db;1175 my $db = $self->db($key); 1098 1176 1099 1177 $log->debug( "entered - @_" ); … … 1182 1260 my $log = $self->log; 1183 1261 my $sql = $self->sql; 1184 my $db = $self->db;1262 my $db = $self->db($key); 1185 1263 1186 1264 $log->debug("entered - @_"); … … 1211 1289 sub mounts 1212 1290 { 1291 # XXX: this will only pull the mounts from one db 1213 1292 my $self = shift; 1214 1293 … … 1217 1296 my $log = $self->log; 1218 1297 my $sql = $self->sql; 1219 my $db = $self->db;1298 my $db = $self->db; 1220 1299 1221 1300 $log->debug("entered - @_"); … … 1246 1325 my $self = shift; 1247 1326 1248 my $log = $self->log; 1249 my $sql = $self->sql; 1250 my $db = $self->db; 1327 my ($key, $name, $soft_volume) = @_; 1328 1329 my $log = $self->log; 1330 my $sql = $self->sql; 1331 my $db = $self->db($key); 1251 1332 1252 1333 no warnings qw( uninitialized ); 1253 1334 $log->debug( "entered - @_" ); 1254 1335 use warnings; 1255 1256 my ($name, $soft_volume) = @_;1257 1336 1258 1337 my ($vol_id, $vol_host, $vol_path, $xattr); … … 1271 1350 # find it, fall back to any volume 1272 1351 if ($soft_volume) { 1273 ($vol_id, $vol_host, $vol_path, $xattr) = $self->_get_storage_volume ;1352 ($vol_id, $vol_host, $vol_path, $xattr) = $self->_get_storage_volume($key); 1274 1353 return; # this just returns out of the eval not from the subroutine 1275 1354 } … … 1311 1390 my $self = shift; 1312 1391 1313 my $log = $self->log; 1314 my $sql = $self->sql; 1315 my $db =$self->db; 1392 my $key = shift; 1393 1394 my $log = $self->log; 1395 my $sql = $self->sql; 1396 my $db = $self->db($key); 1316 1397 1317 1398 no warnings qw( uninitialized ); … … 1319 1400 use warnings; 1320 1401 1321 my $key = shift;1322 1402 1323 1403 $key = parse_neb_key($key); … … 1361 1441 my $log = $self->log; 1362 1442 my $sql = $self->sql; 1363 my $db = $self->db;1443 my $db = $self->db($key); 1364 1444 1365 1445 $key = parse_neb_key($key); … … 1388 1468 sub _is_valid_volume_name 1389 1469 { 1390 my ($self, $ vol_name) = @_;1391 1392 my $log = $self->log; 1393 my $sql = $self->sql; 1394 my $db = $self->db;1470 my ($self, $key, $vol_name) = @_; 1471 1472 my $log = $self->log; 1473 my $sql = $self->sql; 1474 my $db = $self->db($key); 1395 1475 1396 1476 my $volume_info = parse_neb_volume($vol_name); … … 1429 1509 my $log = $self->log; 1430 1510 my $sql = $self->sql; 1431 my $db = $self->db ;1511 my $db = $self->db($key); 1432 1512 1433 1513 my $uri; … … 1558 1638 my $log = $self->log; 1559 1639 my $sql = $self->sql; 1560 my $db =$self->db;1640 # my $db = $self->db; 1561 1641 1562 1642 $log->debug( "entered" ); 1563 1643 1564 $self->db->disconnect;1565 1566 $log->debug( "disconnected from database: ", sub { $db->data_sources; } );1644 # $self->db->disconnect; 1645 1646 # $log->debug( "disconnected from database: ", sub { $db->data_sources; } ); 1567 1647 1568 1648 $log->debug( "leaving" ); -
trunk/Nebulous-Server/lib/Nebulous/Server/Config.pm
r17072 r20965 1 1 # Copyright (C) 2005 Joshua Hoblitt 2 2 # 3 # $Id: Config.pm,v 1. 3 2008-03-20 21:10:57jhoblitt Exp $3 # $Id: Config.pm,v 1.4 2008-12-12 21:13:41 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::Config; … … 8 8 use warnings FATAL => qw( all ); 9 9 10 our $VERSION = 0.0 2;10 our $VERSION = 0.03; 11 11 12 12 use base qw( Class::Accessor::Fast ); 13 13 14 14 use Log::Log4perl qw( :levels ); 15 use Params::Validate qw( validate SCALAR );15 use Params::Validate qw( validate validate_pos SCALAR ); 16 16 17 17 our %LEVELS = ( … … 25 25 ); 26 26 27 my $new_validate = { 27 my $db_validate = { 28 dbindex => { 29 type => SCALAR, 30 regex => qr/^\d+$/, 31 }, 28 32 dsn => { type => SCALAR }, 29 33 dbuser => { type => SCALAR }, 30 34 dbpasswd => { type => SCALAR }, 35 }; 36 37 my $new_validate = { 31 38 log_level => { 32 39 type => SCALAR, … … 39 46 }, 40 47 }, 48 dsn => { type => SCALAR, optional => 1 }, 49 dbuser => { type => SCALAR, optional => 1 }, 50 dbpasswd => { type => SCALAR, optional => 1 }, 41 51 }; 42 52 43 53 __PACKAGE__->mk_ro_accessors( keys %$new_validate ); 44 54 45 sub init { 55 56 sub new 57 { 46 58 my $class = shift; 47 59 … … 49 61 50 62 # 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 } }; 54 64 55 65 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 } 56 78 57 79 return $self; 58 80 } 59 81 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 60 133 1; 61 134 -
trunk/Nebulous-Server/lib/Nebulous/Server/Log.pm
r17546 r20965 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Log.pm,v 1. 7 2008-05-07 00:02:10jhoblitt Exp $3 # $Id: Log.pm,v 1.8 2008-12-12 21:13:41 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::Log; … … 16 16 my ($self, $config) = @_; 17 17 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; 21 21 22 22 my $conf = <<END; … … 30 30 # date | hostname | priority | method/sub - message\n 31 31 32 log4perl.appender.SQLLOG = Log::Log4perl::Appender::DBI33 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 = 37 37 INSERT INTO log (timestamp, hostname, level, sub, message) \ 38 38 VALUES (%d, %H, %p, %M, %m) -
trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
r20175 r20965 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1.7 5 2008-10-15 20:45:51 jhoblitt Exp $3 # $Id: SQL.pm,v 1.76 2008-12-12 21:13:41 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 8 8 use warnings FATAL => qw( all ); 9 9 10 our $VERSION = '0.0 2';10 our $VERSION = '0.03'; 11 11 12 12 use base qw( Class::Accessor::Fast ); … … 47 47 (so_id, vol_id, uri) 48 48 VALUES (?, ?, 'error') 49 }, 50 get_all_instances => qq{ 51 SELECT * FROM INSTANCE 52 WHERE so_id = ? 49 53 }, 50 54 get_object => qq{ -
trunk/Nebulous-Server/t/02_server_setup.t
r16281 r20965 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 02_server_setup.t,v 1. 6 2008-02-02 01:51:29jhoblitt Exp $5 # $Id: 02_server_setup.t,v 1.7 2008-12-12 21:13:41 jhoblitt Exp $ 6 6 7 7 use strict; 8 8 use warnings; 9 9 10 use Test::More tests => 2;10 use Test::More tests => 6; 11 11 12 12 use lib qw( ./t ./lib ); … … 17 17 Test::Nebulous->setup; 18 18 19 isa_ok( 20 Nebulous::Server->new( 21 dsn => $NEB_DB, 22 dbuser => $NEB_USER, 23 dbpasswd => $NEB_PASS, 24 ), 25 "Nebulous::Server" 26 ); 19 isa_ok(Nebulous::Server->new(), "Nebulous::Server"); 27 20 28 21 Test::Nebulous->setup; 29 22 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 30 Test::Nebulous->setup; 31 32 { 33 my $neb = Nebulous::Server->new( 32 34 dsn => "DBI:mysql:database=foobar:host=localhost", 33 35 dbuser => "baz", 34 36 dbpasswd =>"boo", 35 37 ); 36 }; 37 like( $@, qr/DBI connect.*? failed/, "bad dsn/user/pass" ); 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 } 38 64 39 65 Test::Nebulous->cleanup; -
trunk/Nebulous-Server/t/08_server_delete_instance.t
r17072 r20965 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 08_server_delete_instance.t,v 1.1 0 2008-03-20 21:10:14jhoblitt Exp $5 # $Id: 08_server_delete_instance.t,v 1.11 2008-12-12 21:13:41 jhoblitt Exp $ 6 6 7 7 use strict; … … 24 24 25 25 { 26 my $uri = $neb->create_object("foo"); 26 my $key = "foo"; 27 my $uri = $neb->create_object($key); 27 28 28 ok($neb->delete_instance($ uri), "delete instance");29 ok($neb->delete_instance($key, $uri), "delete instance"); 29 30 } 30 31 … … 32 33 33 34 { 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); 36 38 37 ok($neb->delete_instance($ uri1), "delete instance");39 ok($neb->delete_instance($key, $uri1), "delete instance"); 38 40 39 my $locations = $neb->find_instances( "foo");41 my $locations = $neb->find_instances($key); 40 42 41 43 is($locations->[0], $uri2, "instance remains"); 42 44 43 ok($neb->delete_instance( $uri2), "delete instance");45 ok($neb->delete_instance($key, $uri2), "delete instance"); 44 46 45 47 eval { 46 $neb->find_instances( "foo");48 $neb->find_instances($key); 47 49 }; 48 50 like($@, qr/is valid object key/, "storage object was deleted"); … … 52 54 53 55 eval { 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"); 55 60 }; 56 61 like($@, qr/no instance is associated with uri/, "uri does not exist"); … … 61 66 $neb->delete_instance(); 62 67 }; 63 like($@, qr/ 1 wasexpected/, "no params");68 like($@, qr/2 were expected/, "no params"); 64 69 65 70 Test::Nebulous->setup; 66 71 67 72 eval { 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); 69 77 }; 70 like($@, qr/ 1 wasexpected/, "too many params");78 like($@, qr/2 were expected/, "too many params"); 71 79 72 80 Test::Nebulous->cleanup; -
trunk/Nebulous-Server/t/10_server_is_valid_volume_name.t
r17072 r20965 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 10_server_is_valid_volume_name.t,v 1. 5 2008-03-20 21:10:14jhoblitt Exp $5 # $Id: 10_server_is_valid_volume_name.t,v 1.6 2008-12-12 21:13:41 jhoblitt Exp $ 6 6 7 7 use strict; … … 23 23 Test::Nebulous->setup; 24 24 25 ok($neb->_is_valid_volume_name(' node01'), "valid volume name");25 ok($neb->_is_valid_volume_name('foo', 'node01'), "valid volume name"); 26 26 27 27 Test::Nebulous->setup; 28 28 29 ok($neb->_is_valid_volume_name(' node02'), "valid volume name");29 ok($neb->_is_valid_volume_name('foo', 'node02'), "valid volume name"); 30 30 31 31 Test::Nebulous->setup; 32 32 33 is($neb->_is_valid_volume_name(' node99'), undef, "invalid volume name");33 is($neb->_is_valid_volume_name('foo', 'node99'), undef, "invalid volume name"); 34 34 35 35 Test::Nebulous->cleanup; -
trunk/Nebulous/lib/Nebulous/Client.pm
r20094 r20965 1 1 # Copyright (c) 2004-2008 Joshua Hoblitt 2 2 # 3 # $Id: Client.pm,v 1.6 2 2008-10-13 21:20:33jhoblitt Exp $3 # $Id: Client.pm,v 1.63 2008-12-12 21:13:41 jhoblitt Exp $ 4 4 5 5 package Nebulous::Client; … … 243 243 # if the copy failed we now have a zero length instances floating 244 244 # around that must be removed 245 unless ($self->delete_instance( "$uri")) {245 unless ($self->delete_instance($key, "$uri")) { 246 246 $log->logdie( "can not copy instance $uri AND FAILED TO CLEANUP EMPTY INSTANCE" ); 247 247 } … … 256 256 257 257 unless ($src_md5 eq $dst_md5) { 258 $self->delete_instance( "$uri");258 $self->delete_instance($key, "$uri"); 259 259 $log->logdie( "md5sum mismatch" ); 260 260 } … … 327 327 } 328 328 329 my $uri = $self->delete_instance( @$locations[0]);329 my $uri = $self->delete_instance($key, @$locations[0]); 330 330 331 331 $log->debug("leaving"); … … 813 813 # a lock is implicitly removed when the last storage object is deleted 814 814 foreach my $uri ( @$locations ) { 815 $self->delete_instance( $uri) or return undef;815 $self->delete_instance($key, $uri) or return undef; 816 816 } 817 817 … … 944 944 my $self = shift; 945 945 946 my ($uri) = validate_pos(@_, 946 my ($key, $uri) = validate_pos(@_, 947 { 948 type => SCALAR, 949 }, 947 950 { 948 951 type => SCALAR, … … 961 964 $log->logdie( $@ ) if $@; 962 965 963 my $response = $self->{ 'server' }->delete_instance( $uri);966 my $response = $self->{ 'server' }->delete_instance($key, $uri); 964 967 if ( $response->fault ) { 965 968 $self->set_err($response->faultstring); -
trunk/Nebulous/nebclient/nebulous.wsdl
r20208 r20965 125 125 126 126 <message name="delete_instanceRequest"> 127 <part name="key" type="xsd:string" /> 127 128 <part name="uri" type="xsd:string" /> 128 129 </message> -
trunk/Nebulous/nebclient/src/nebclient.c
r20344 r20965 4 4 * Copyright (C) 2005 Joshua Hoblitt 5 5 * 6 * $Id: nebclient.c,v 1.5 4 2008-10-23 22:30:44 billsExp $6 * $Id: nebclient.c,v 1.55 2008-12-12 21:13:41 jhoblitt Exp $ 7 7 */ 8 8 … … 253 253 } 254 254 255 if (!nebDeleteInstance(server, locations->URI[0])) {255 if (!nebDeleteInstance(server, key, locations->URI[0])) { 256 256 nebObjectInstancesFree(locations); 257 257 … … 539 539 540 540 for (int i = 0; i < locations->n; i++) { 541 if (!nebDeleteInstance(server, locations->URI[i])) {541 if (!nebDeleteInstance(server, key, locations->URI[i])) { 542 542 nebSetErr(server, "can not delete instance"); 543 543 nebObjectInstancesFree(locations); … … 655 655 } 656 656 657 bool nebDeleteInstance(nebServer *server, const char * URI)657 bool nebDeleteInstance(nebServer *server, const char *key, const char *URI) 658 658 { 659 659 int response; … … 676 676 677 677 if (soap_call_ns1__delete_USCOREinstance(server->soap, server->endpoint, 678 NULL, (char *) URI, &response) != SOAP_OK) {678 NULL, (char *)key, (char *)URI, &response) != SOAP_OK) { 679 679 nebFree(filename); 680 680 -
trunk/Nebulous/nebclient/src/nebclient.h
r20344 r20965 4 4 * Copyright (C) 2005 Joshua Hoblitt 5 5 * 6 * $Id: nebclient.h,v 1.3 6 2008-10-23 22:30:44 billsExp $6 * $Id: nebclient.h,v 1.37 2008-12-12 21:13:41 jhoblitt Exp $ 7 7 */ 8 8 … … 248 248 bool nebDeleteInstance( 249 249 nebServer *server, ///< nebServer object 250 const char *key, ///< storage object key (name) 250 251 const char *URI ///< URL of instance to remove 251 252 ); -
trunk/Nebulous/nebclient/src/nebulous.h
r20208 r20965 1 1 /* src/nebulous.h 2 2 Generated by wsdl2h 1.2.11 from nebulous.wsdl and typemap.dat 3 2008-1 0-16 23:26:37GMT3 2008-12-11 21:42:13 GMT 4 4 Copyright (C) 2001-2008 Robert van Engelen, Genivia Inc. All Rights Reserved. 5 5 This part of the software is released under one of the following licenses: … … 808 808 NULL, // char *action = NULL selects default action for this operation 809 809 // request parameters: 810 char* key, 810 811 char* uri, 811 812 // response parameters: … … 819 820 struct soap *soap, 820 821 // request parameters: 822 char* key, 821 823 char* uri, 822 824 // response parameters: … … 831 833 //gsoap ns1 service method-action: delete_USCOREinstance urn:Nebulous/Server/SOAP#delete_instance 832 834 int ns1__delete_USCOREinstance( 835 char* key, ///< Request parameter 833 836 char* uri, ///< Request parameter 834 837 int *result ///< Response parameter -
trunk/Nebulous/nebclient/src/soapC.c
r20208 r20965 12 12 #endif 13 13 14 SOAP_SOURCE_STAMP("@(#) soapC.c ver 2.7.11 2008-1 0-16 23:26:39GMT")14 SOAP_SOURCE_STAMP("@(#) soapC.c ver 2.7.11 2008-12-11 21:42:14 GMT") 15 15 16 16 … … 1342 1342 { 1343 1343 (void)soap; (void)a; /* appease -Wall -Werror */ 1344 soap_default_string(soap, &a->key); 1344 1345 soap_default_string(soap, &a->uri); 1345 1346 } … … 1348 1349 { 1349 1350 (void)soap; (void)a; /* appease -Wall -Werror */ 1351 soap_serialize_string(soap, &a->key); 1350 1352 soap_serialize_string(soap, &a->uri); 1351 1353 } … … 1363 1365 if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, SOAP_TYPE_ns1__delete_USCOREinstance), type)) 1364 1366 return soap->error; 1367 if (soap_out_string(soap, "key", -1, &a->key, "")) 1368 return soap->error; 1365 1369 if (soap_out_string(soap, "uri", -1, &a->uri, "")) 1366 1370 return soap->error; … … 1378 1382 SOAP_FMAC3 struct ns1__delete_USCOREinstance * SOAP_FMAC4 soap_in_ns1__delete_USCOREinstance(struct soap *soap, const char *tag, struct ns1__delete_USCOREinstance *a, const char *type) 1379 1383 { 1384 size_t soap_flag_key = 1; 1380 1385 size_t soap_flag_uri = 1; 1381 1386 if (soap_element_begin_in(soap, tag, 0, type)) … … 1389 1394 for (;;) 1390 1395 { soap->error = SOAP_TAG_MISMATCH; 1396 if (soap_flag_key && (soap->error == SOAP_TAG_MISMATCH || soap->error == SOAP_NO_TAG)) 1397 if (soap_in_string(soap, "key", &a->key, "xsd:string")) 1398 { soap_flag_key--; 1399 continue; 1400 } 1391 1401 if (soap_flag_uri && (soap->error == SOAP_TAG_MISMATCH || soap->error == SOAP_NO_TAG)) 1392 1402 if (soap_in_string(soap, "uri", &a->uri, "xsd:string")) -
trunk/Nebulous/nebclient/src/soapClient.c
r20208 r20965 10 10 #endif 11 11 12 SOAP_SOURCE_STAMP("@(#) soapClient.c ver 2.7.11 2008-1 0-16 23:26:38GMT")12 SOAP_SOURCE_STAMP("@(#) soapClient.c ver 2.7.11 2008-12-11 21:42:13 GMT") 13 13 14 14 … … 700 700 } 701 701 702 SOAP_FMAC5 int SOAP_FMAC6 soap_call_ns1__delete_USCOREinstance(struct soap *soap, const char *soap_endpoint, const char *soap_action, char * uri, int *result)702 SOAP_FMAC5 int SOAP_FMAC6 soap_call_ns1__delete_USCOREinstance(struct soap *soap, const char *soap_endpoint, const char *soap_action, char *key, char *uri, int *result) 703 703 { struct ns1__delete_USCOREinstance soap_tmp_ns1__delete_USCOREinstance; 704 704 struct ns1__delete_USCOREinstanceResponse *soap_tmp_ns1__delete_USCOREinstanceResponse; … … 708 708 soap_action = "urn:Nebulous/Server/SOAP#delete_instance"; 709 709 soap->encodingStyle = "http://schemas.xmlsoap.org/soap/encoding/"; 710 soap_tmp_ns1__delete_USCOREinstance.key = key; 710 711 soap_tmp_ns1__delete_USCOREinstance.uri = uri; 711 712 soap_begin(soap); -
trunk/Nebulous/nebclient/src/soapServer.c
r20208 r20965 10 10 #endif 11 11 12 SOAP_SOURCE_STAMP("@(#) soapServer.c ver 2.7.11 2008-1 0-16 23:26:38GMT")12 SOAP_SOURCE_STAMP("@(#) soapServer.c ver 2.7.11 2008-12-11 21:42:13 GMT") 13 13 14 14 … … 643 643 || soap_end_recv(soap)) 644 644 return soap->error; 645 soap->error = ns1__delete_USCOREinstance(soap, soap_tmp_ns1__delete_USCOREinstance. uri, &soap_tmp_int);645 soap->error = ns1__delete_USCOREinstance(soap, soap_tmp_ns1__delete_USCOREinstance.key, soap_tmp_ns1__delete_USCOREinstance.uri, &soap_tmp_int); 646 646 if (soap->error) 647 647 return soap->error; -
trunk/Nebulous/nebclient/src/soapStub.h
r20208 r20965 283 283 struct ns1__delete_USCOREinstance 284 284 { 285 char *key; /* optional element of type xsd:string */ 285 286 char *uri; /* optional element of type xsd:string */ 286 287 }; … … 432 433 SOAP_FMAC5 int SOAP_FMAC6 ns1__find_USCOREinstances(struct soap*, char *key, char *volume, struct ns1__find_USCOREinstancesResponse *_param_3); 433 434 434 SOAP_FMAC5 int SOAP_FMAC6 ns1__delete_USCOREinstance(struct soap*, char * uri, int *result);435 SOAP_FMAC5 int SOAP_FMAC6 ns1__delete_USCOREinstance(struct soap*, char *key, char *uri, int *result); 435 436 436 437 SOAP_FMAC5 int SOAP_FMAC6 ns1__stat_USCOREobject(struct soap*, char *key, struct ns1__stat_USCOREobjectResponse *_param_4); … … 467 468 SOAP_FMAC5 int SOAP_FMAC6 soap_call_ns1__find_USCOREinstances(struct soap *soap, const char *soap_endpoint, const char *soap_action, char *key, char *volume, struct ns1__find_USCOREinstancesResponse *_param_3); 468 469 469 SOAP_FMAC5 int SOAP_FMAC6 soap_call_ns1__delete_USCOREinstance(struct soap *soap, const char *soap_endpoint, const char *soap_action, char * uri, int *result);470 SOAP_FMAC5 int SOAP_FMAC6 soap_call_ns1__delete_USCOREinstance(struct soap *soap, const char *soap_endpoint, const char *soap_action, char *key, char *uri, int *result); 470 471 471 472 SOAP_FMAC5 int SOAP_FMAC6 soap_call_ns1__stat_USCOREobject(struct soap *soap, const char *soap_endpoint, const char *soap_action, char *key, struct ns1__stat_USCOREobjectResponse *_param_4); -
trunk/Nebulous/t/62_client_delete_instance.t
r5667 r20965 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 62_client_delete_instance.t,v 1. 1 2005-12-03 02:52:31 jhoblitt Exp $5 # $Id: 62_client_delete_instance.t,v 1.2 2008-12-12 21:13:41 jhoblitt Exp $ 6 6 7 7 use strict; … … 10 10 use Apache::Test qw( -withtestmore ); 11 11 12 plan tests => 9;12 plan tests => 11; 13 13 14 14 use lib qw( ./t ./lib ); … … 26 26 proxy => "http://$hostport/nebulous", 27 27 ); 28 $neb->create( "foo" );29 28 30 my $locations = $neb->find_instances( "foo" ); 29 my $key = "foo"; 30 $neb->create($key); 31 31 32 my $uri = $neb->delete_instance( @$locations[0] ); 32 my $locations = $neb->find_instances($key); 33 34 my $uri = $neb->delete_instance($key, @$locations[0]); 33 35 34 36 is( $uri, @$locations[0], "delete instance" ); … … 43 45 proxy => "http://$hostport/nebulous", 44 46 ); 45 $neb->create( "foo" ); 46 $neb->replicate( "foo" ); 47 my $key = "foo"; 48 $neb->create($key); 49 $neb->replicate($key); 47 50 48 51 my $uri1 = $neb->find_instances( "foo" )->[0]; 49 52 50 ok( $neb->delete_instance( $uri1), "delete instance" );53 ok( $neb->delete_instance($key, $uri1), "delete instance" ); 51 54 52 55 my $uri2 = $neb->find_instances( "foo" )->[0]; … … 54 57 isnt( $uri1, $uri2, "other instance remains" ); 55 58 56 ok( $neb->delete_instance( $uri2), "delete instance" );59 ok( $neb->delete_instance($key, $uri2), "delete instance" ); 57 60 58 61 my $locations = $neb->find_instances( "foo" ); 59 62 60 is( $locations, undef, "no rema ning instances" );63 is( $locations, undef, "no remaining instances" ); 61 64 } 65 66 Test::Nebulous->setup; 62 67 63 68 { … … 65 70 proxy => "http://$hostport/nebulous", 66 71 ); 67 my $uri = $neb->delete_instance( "file:/foo" ); 72 my $key = "foo"; 73 $neb->create($key); 74 my $uri = $neb->delete_instance($key, "file:/foo" ); 68 75 69 76 is( $uri, undef, "uri does not exist" ); … … 76 83 proxy => "http://$hostport/nebulous", 77 84 ); 78 $neb->delete_instance();85 my $uri = $neb->delete_instance("foo", "file:/foo" ); 79 86 }; 80 like( $@, qr/ 1 was expected/, "no params" );87 like( $@, qr/is valid object key/, "bad object key" ); 81 88 82 89 Test::Nebulous->setup; … … 86 93 proxy => "http://$hostport/nebulous", 87 94 ); 88 $neb->delete_instance( "foo", 2);95 my $uri = $neb->delete_instance("foo"); 89 96 }; 90 like( $@, qr/1 was expected/, "too many params" ); 97 like( $@, qr/2 were expected/, "missing second param" ); 98 99 Test::Nebulous->setup; 100 101 eval { 102 my $neb = Nebulous::Client->new( 103 proxy => "http://$hostport/nebulous", 104 ); 105 $neb->delete_instance(); 106 }; 107 like( $@, qr/2 were expected/, "no params" ); 108 109 Test::Nebulous->setup; 110 111 eval { 112 my $neb = Nebulous::Client->new( 113 proxy => "http://$hostport/nebulous", 114 ); 115 $neb->delete_instance("foo", 2, 3); 116 }; 117 like( $@, qr/2 were expected/, "too many params" ); 91 118 92 119 Test::Nebulous->cleanup;
Note:
See TracChangeset
for help on using the changeset viewer.
