Changeset 13131
- Timestamp:
- May 2, 2007, 10:53:42 AM (19 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
-
Nebulous-Server/lib/Nebulous/Server.pm (modified) (4 diffs)
-
Nebulous-Server/lib/Nebulous/Server/SQL.pm (modified) (8 diffs)
-
Nebulous-Server/t/03_server_create_object.t (modified) (3 diffs)
-
Nebulous/lib/Nebulous/Server.pm (modified) (4 diffs)
-
Nebulous/lib/Nebulous/Server/SQL.pm (modified) (8 diffs)
-
Nebulous/t/03_server_create_object.t (modified) (3 diffs)
-
Nebulous/t/Test/Nebulous.pm (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/lib/Nebulous/Server.pm
r13130 r13131 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1.3 0 2007-05-02 20:14:45jhoblitt Exp $3 # $Id: Server.pm,v 1.31 2007-05-02 20:53:42 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 1022 1022 } 1023 1023 1024 # select *, total - used as free, (used / total) * 100 as perused from mount;1025 1024 1026 1025 sub _get_storage_volume … … 1051 1050 if ( $name ) { 1052 1051 $query = $db->prepare_cached( $sql->get_storage_volume_byname ); 1053 $rows = $query->execute(0.95, $name); 1052 # %free, name, avaiable, allocate 1053 $rows = $query->execute(0.95, $name, 1, 1); 1054 1054 unless ($rows > 0) { 1055 1055 $query->finish; … … 1063 1063 } else { 1064 1064 $query = $db->prepare_cached( $sql->get_storage_volume ); 1065 $rows = $query->execute(0.95); 1065 # %free, avaiable, allocate 1066 $rows = $query->execute(0.95, 1, 1); 1066 1067 # there has to be atleast one storage volume 1067 1068 unless ($rows > 0) { -
trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
r13130 r13131 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1.3 2 2007-05-02 20:14:46jhoblitt Exp $3 # $Id: SQL.pm,v 1.33 2007-05-02 20:53:42 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 161 161 used / total < ? 162 162 AND name = ? 163 AND available = ? 164 AND allocate = ? 163 165 ORDER BY free DESC 164 166 LIMIT 1 … … 172 174 WHERE 173 175 used / total < ? 176 AND available = ? 177 AND allocate = ? 174 178 ORDER BY free DESC 175 179 LIMIT 1 … … 177 181 new_volume => qq{ 178 182 INSERT INTO volume (name, path, allocate) 179 VALUES (?, ?, TRUE )183 VALUES (?, ?, TRUE, TRUE) 180 184 }, 181 185 get_volume_by_name => qq{ … … 304 308 path VARCHAR(255) NOT NULL, 305 309 allocate BOOLEAN DEFAULT FALSE, 310 available BOOLEAN DEFAULT FALSE, 306 311 PRIMARY KEY(vol_id), 307 312 KEY(name(16)), 308 KEY(allocate) 313 KEY(allocate), 314 KEY(available) 309 315 ) ENGINE=innodb; 310 316 … … 337 343 DECLARE namevar VARCHAR(255); 338 344 DECLARE pathvar VARCHAR(255); 339 DECLARE cur1 CURSOR FOR SELECT vol_id, name, path FROM volume 340 WHERE allocate = TRUE; 345 DECLARE allocatevar BOOLEAN; 346 DECLARE availablevar BOOLEAN; 347 DECLARE cur1 CURSOR FOR SELECT vol_id, name, path, allocate, available FROM volume; 341 348 DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE; 342 349 … … 353 360 vol_id INT NOT NULL, 354 361 name VARCHAR(255) NOT NULL, 355 path VARCHAR(255) NOT NULL 362 path VARCHAR(255) NOT NULL, 363 allocate BOOLEAN DEFAULT FALSE, 364 available BOOLEAN DEFAULT FALSE 356 365 ) ENGINE=MEMORY; 357 366 … … 363 372 364 373 myloop: LOOP 365 FETCH cur1 INTO vol_idvar, namevar, pathvar ;374 FETCH cur1 INTO vol_idvar, namevar, pathvar, allocatevar, availablevar; 366 375 IF `done` THEN LEAVE myloop; END IF; 367 376 INSERT INTO mountedvol 368 SELECT mountpoint, total, used, vol_idvar, namevar, pathvar 377 SELECT mountpoint, total, used, vol_idvar, namevar, pathvar, allocatevar, availablevar 369 378 FROM 370 379 (SELECT *, INSTR(pathvar, mountpoint) = 1 as substring -
trunk/Nebulous-Server/t/03_server_create_object.t
r13130 r13131 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 03_server_create_object.t,v 1.1 4 2007-05-02 20:14:46jhoblitt Exp $5 # $Id: 03_server_create_object.t,v 1.15 2007-05-02 20:53:42 jhoblitt Exp $ 6 6 7 7 use strict; 8 8 use warnings FATAL => qw( all ); 9 9 10 use Test::More tests => 1 0;10 use Test::More tests => 12; 11 11 12 12 use lib qw( ./t ./lib ); … … 59 59 $neb->create_object("foo", 'node03'); 60 60 }; 61 like($@, qr/node03 is not available/, "request volume with allocate = FALSE");61 like($@, qr/node03 is not available/, "request volume this is full"); 62 62 63 63 Test::Nebulous->setup; … … 66 66 $neb->create_object("foo", 'node04'); 67 67 }; 68 like($@, qr/node04 is not available/, "request volume this is full"); 68 like($@, qr/node04 is not available/, "request volume with allocate = FALSE, available = FALSE"); 69 70 Test::Nebulous->setup; 71 72 eval { 73 $neb->create_object("foo", 'node05'); 74 }; 75 like($@, qr/node05 is not available/, "request volume with allocate = FALSE , available = TRUE"); 76 77 Test::Nebulous->setup; 78 79 eval { 80 $neb->create_object("foo", 'node06'); 81 }; 82 like($@, qr/node06 is not available/, "request volume with allocate = TRUE, available = FALSE"); 69 83 70 84 Test::Nebulous->setup; -
trunk/Nebulous/lib/Nebulous/Server.pm
r13130 r13131 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1.3 0 2007-05-02 20:14:45jhoblitt Exp $3 # $Id: Server.pm,v 1.31 2007-05-02 20:53:42 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 1022 1022 } 1023 1023 1024 # select *, total - used as free, (used / total) * 100 as perused from mount;1025 1024 1026 1025 sub _get_storage_volume … … 1051 1050 if ( $name ) { 1052 1051 $query = $db->prepare_cached( $sql->get_storage_volume_byname ); 1053 $rows = $query->execute(0.95, $name); 1052 # %free, name, avaiable, allocate 1053 $rows = $query->execute(0.95, $name, 1, 1); 1054 1054 unless ($rows > 0) { 1055 1055 $query->finish; … … 1063 1063 } else { 1064 1064 $query = $db->prepare_cached( $sql->get_storage_volume ); 1065 $rows = $query->execute(0.95); 1065 # %free, avaiable, allocate 1066 $rows = $query->execute(0.95, 1, 1); 1066 1067 # there has to be atleast one storage volume 1067 1068 unless ($rows > 0) { -
trunk/Nebulous/lib/Nebulous/Server/SQL.pm
r13130 r13131 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1.3 2 2007-05-02 20:14:46jhoblitt Exp $3 # $Id: SQL.pm,v 1.33 2007-05-02 20:53:42 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 161 161 used / total < ? 162 162 AND name = ? 163 AND available = ? 164 AND allocate = ? 163 165 ORDER BY free DESC 164 166 LIMIT 1 … … 172 174 WHERE 173 175 used / total < ? 176 AND available = ? 177 AND allocate = ? 174 178 ORDER BY free DESC 175 179 LIMIT 1 … … 177 181 new_volume => qq{ 178 182 INSERT INTO volume (name, path, allocate) 179 VALUES (?, ?, TRUE )183 VALUES (?, ?, TRUE, TRUE) 180 184 }, 181 185 get_volume_by_name => qq{ … … 304 308 path VARCHAR(255) NOT NULL, 305 309 allocate BOOLEAN DEFAULT FALSE, 310 available BOOLEAN DEFAULT FALSE, 306 311 PRIMARY KEY(vol_id), 307 312 KEY(name(16)), 308 KEY(allocate) 313 KEY(allocate), 314 KEY(available) 309 315 ) ENGINE=innodb; 310 316 … … 337 343 DECLARE namevar VARCHAR(255); 338 344 DECLARE pathvar VARCHAR(255); 339 DECLARE cur1 CURSOR FOR SELECT vol_id, name, path FROM volume 340 WHERE allocate = TRUE; 345 DECLARE allocatevar BOOLEAN; 346 DECLARE availablevar BOOLEAN; 347 DECLARE cur1 CURSOR FOR SELECT vol_id, name, path, allocate, available FROM volume; 341 348 DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE; 342 349 … … 353 360 vol_id INT NOT NULL, 354 361 name VARCHAR(255) NOT NULL, 355 path VARCHAR(255) NOT NULL 362 path VARCHAR(255) NOT NULL, 363 allocate BOOLEAN DEFAULT FALSE, 364 available BOOLEAN DEFAULT FALSE 356 365 ) ENGINE=MEMORY; 357 366 … … 363 372 364 373 myloop: LOOP 365 FETCH cur1 INTO vol_idvar, namevar, pathvar ;374 FETCH cur1 INTO vol_idvar, namevar, pathvar, allocatevar, availablevar; 366 375 IF `done` THEN LEAVE myloop; END IF; 367 376 INSERT INTO mountedvol 368 SELECT mountpoint, total, used, vol_idvar, namevar, pathvar 377 SELECT mountpoint, total, used, vol_idvar, namevar, pathvar, allocatevar, availablevar 369 378 FROM 370 379 (SELECT *, INSTR(pathvar, mountpoint) = 1 as substring -
trunk/Nebulous/t/03_server_create_object.t
r13130 r13131 3 3 # Copryight (C) 2004-2005 Joshua Hoblitt 4 4 # 5 # $Id: 03_server_create_object.t,v 1.1 4 2007-05-02 20:14:46jhoblitt Exp $5 # $Id: 03_server_create_object.t,v 1.15 2007-05-02 20:53:42 jhoblitt Exp $ 6 6 7 7 use strict; 8 8 use warnings FATAL => qw( all ); 9 9 10 use Test::More tests => 1 0;10 use Test::More tests => 12; 11 11 12 12 use lib qw( ./t ./lib ); … … 59 59 $neb->create_object("foo", 'node03'); 60 60 }; 61 like($@, qr/node03 is not available/, "request volume with allocate = FALSE");61 like($@, qr/node03 is not available/, "request volume this is full"); 62 62 63 63 Test::Nebulous->setup; … … 66 66 $neb->create_object("foo", 'node04'); 67 67 }; 68 like($@, qr/node04 is not available/, "request volume this is full"); 68 like($@, qr/node04 is not available/, "request volume with allocate = FALSE, available = FALSE"); 69 70 Test::Nebulous->setup; 71 72 eval { 73 $neb->create_object("foo", 'node05'); 74 }; 75 like($@, qr/node05 is not available/, "request volume with allocate = FALSE , available = TRUE"); 76 77 Test::Nebulous->setup; 78 79 eval { 80 $neb->create_object("foo", 'node06'); 81 }; 82 like($@, qr/node06 is not available/, "request volume with allocate = TRUE, available = FALSE"); 69 83 70 84 Test::Nebulous->setup; -
trunk/Nebulous/t/Test/Nebulous.pm
r13130 r13131 1 1 # Copyright (C) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Nebulous.pm,v 1.1 3 2007-05-02 20:14:46jhoblitt Exp $3 # $Id: Nebulous.pm,v 1.14 2007-05-02 20:53:42 jhoblitt Exp $ 4 4 5 5 package Test::Nebulous; … … 24 24 my $dir3 = ""; 25 25 my $dir4 = ""; 26 my $dir5 = ""; 27 my $dir6 = ""; 26 28 27 29 sub setup { … … 35 37 $dir3 = tempdir( CLEANUP => 0 ); 36 38 $dir4 = tempdir( CLEANUP => 0 ); 39 $dir5 = tempdir( CLEANUP => 0 ); 40 $dir6 = tempdir( CLEANUP => 0 ); 37 41 38 42 foreach my $statement (@{ $sql->get_db_schema }) { … … 41 45 42 46 # node01/node02: allocate = TRUE 43 $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate ) VALUES (1, 'node01', ?, TRUE) }, undef, $dir1);47 $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate, available) VALUES (1, 'node01', ?, TRUE, TRUE) }, undef, $dir1); 44 48 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir1); 45 49 46 $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate ) VALUES (2, 'node02', ?, TRUE) }, undef, $dir2);50 $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate, available) VALUES (2, 'node02', ?, TRUE, TRUE) }, undef, $dir2); 47 51 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e8) }, undef, $dir2); 48 52 49 # node03: allocate = FALSE50 $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate ) VALUES (3, 'node03', ?, FALSE) }, undef, $dir3);51 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e 8) }, undef, $dir3);53 # node03: allocate = TRUE, volume full 54 $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate, available) VALUES (3, 'node03', ?, TRUE, TRUE) }, undef, $dir3); 55 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e10) }, undef, $dir3); 52 56 53 # node04: allocate = TRUE, volume full 54 $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate) VALUES (4, 'node04', ?, TRUE) }, undef, $dir4); 55 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e10) }, undef, $dir4); 57 # node04: allocate = FALSE, available = FALSE 58 $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate, available) VALUES (4, 'node04', ?, FALSE, FALSE) }, undef, $dir4); 59 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir4); 60 61 # node05: allocate = FALSE, available = TRUE 62 $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate, available) VALUES (5, 'node05', ?, FALSE, TRUE) }, undef, $dir5); 63 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir5); 64 65 # node06: allocate = TRUE, available = FALSE 66 $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate, available) VALUES (6, 'node06', ?, TRUE, FALSE) }, undef, $dir4); 67 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir6); 56 68 } 57 69 … … 66 78 rmtree([$dir3], 0, 1) if -e $dir3; 67 79 rmtree([$dir4], 0, 1) if -e $dir4; 80 rmtree([$dir5], 0, 1) if -e $dir5; 81 rmtree([$dir6], 0, 1) if -e $dir6; 68 82 } 69 83
Note:
See TracChangeset
for help on using the changeset viewer.
