IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13131


Ignore:
Timestamp:
May 2, 2007, 10:53:42 AM (19 years ago)
Author:
jhoblitt
Message:

add volume.available field and logic to use it

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/lib/Nebulous/Server.pm

    r13130 r13131  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.30 2007-05-02 20:14:45 jhoblitt Exp $
     3# $Id: Server.pm,v 1.31 2007-05-02 20:53:42 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    10221022}
    10231023
    1024 #  select *, total - used as free, (used / total) * 100 as perused from mount;
    10251024
    10261025sub _get_storage_volume
     
    10511050        if ( $name ) {
    10521051            $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);
    10541054            unless ($rows > 0) {
    10551055                $query->finish;
     
    10631063        } else {
    10641064            $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);
    10661067            # there has to be atleast one storage volume
    10671068            unless ($rows > 0) {
  • trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm

    r13130 r13131  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SQL.pm,v 1.32 2007-05-02 20:14:46 jhoblitt Exp $
     3# $Id: SQL.pm,v 1.33 2007-05-02 20:53:42 jhoblitt Exp $
    44
    55package Nebulous::Server::SQL;
     
    161161            used / total < ?
    162162            AND name = ?
     163            AND available = ?
     164            AND allocate = ?
    163165        ORDER BY free DESC
    164166        LIMIT 1
     
    172174        WHERE
    173175            used / total < ?
     176            AND available = ?
     177            AND allocate = ?
    174178        ORDER BY free DESC
    175179        LIMIT 1
     
    177181    new_volume          => qq{
    178182        INSERT INTO volume (name, path, allocate)
    179         VALUES (?, ?, TRUE)
     183        VALUES (?, ?, TRUE, TRUE)
    180184    },
    181185    get_volume_by_name => qq{
     
    304308    path VARCHAR(255) NOT NULL,
    305309    allocate BOOLEAN DEFAULT FALSE,
     310    available BOOLEAN DEFAULT FALSE,
    306311    PRIMARY KEY(vol_id),
    307312    KEY(name(16)),
    308     KEY(allocate)
     313    KEY(allocate),
     314    KEY(available)
    309315) ENGINE=innodb;
    310316
     
    337343    DECLARE namevar VARCHAR(255);
    338344    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;
    341348    DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE;
    342349
     
    353360        vol_id INT NOT NULL,
    354361        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
    356365    ) ENGINE=MEMORY;
    357366
     
    363372
    364373    myloop: LOOP
    365         FETCH cur1 INTO vol_idvar, namevar, pathvar;
     374        FETCH cur1 INTO vol_idvar, namevar, pathvar, allocatevar, availablevar;
    366375        IF `done` THEN LEAVE myloop; END IF;
    367376        INSERT INTO mountedvol
    368             SELECT mountpoint, total, used, vol_idvar, namevar, pathvar
     377            SELECT mountpoint, total, used, vol_idvar, namevar, pathvar, allocatevar, availablevar
    369378            FROM
    370379                (SELECT *, INSTR(pathvar, mountpoint) = 1 as substring
  • trunk/Nebulous-Server/t/03_server_create_object.t

    r13130 r13131  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 03_server_create_object.t,v 1.14 2007-05-02 20:14:46 jhoblitt Exp $
     5# $Id: 03_server_create_object.t,v 1.15 2007-05-02 20:53:42 jhoblitt Exp $
    66
    77use strict;
    88use warnings FATAL => qw( all );
    99
    10 use Test::More tests => 10;
     10use Test::More tests => 12;
    1111
    1212use lib qw( ./t ./lib );
     
    5959    $neb->create_object("foo", 'node03');
    6060};
    61 like($@, qr/node03 is not available/, "request volume with allocate = FALSE");
     61like($@, qr/node03 is not available/, "request volume this is full");
    6262
    6363Test::Nebulous->setup;
     
    6666    $neb->create_object("foo", 'node04');
    6767};
    68 like($@, qr/node04 is not available/, "request volume this is full");
     68like($@, qr/node04 is not available/, "request volume with allocate = FALSE, available = FALSE");
     69
     70Test::Nebulous->setup;
     71
     72eval {
     73    $neb->create_object("foo", 'node05');
     74};
     75like($@, qr/node05 is not available/, "request volume with allocate = FALSE , available = TRUE");
     76
     77Test::Nebulous->setup;
     78
     79eval {
     80    $neb->create_object("foo", 'node06');
     81};
     82like($@, qr/node06 is not available/, "request volume with allocate = TRUE, available = FALSE");
    6983
    7084Test::Nebulous->setup;
  • trunk/Nebulous/lib/Nebulous/Server.pm

    r13130 r13131  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.30 2007-05-02 20:14:45 jhoblitt Exp $
     3# $Id: Server.pm,v 1.31 2007-05-02 20:53:42 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    10221022}
    10231023
    1024 #  select *, total - used as free, (used / total) * 100 as perused from mount;
    10251024
    10261025sub _get_storage_volume
     
    10511050        if ( $name ) {
    10521051            $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);
    10541054            unless ($rows > 0) {
    10551055                $query->finish;
     
    10631063        } else {
    10641064            $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);
    10661067            # there has to be atleast one storage volume
    10671068            unless ($rows > 0) {
  • trunk/Nebulous/lib/Nebulous/Server/SQL.pm

    r13130 r13131  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SQL.pm,v 1.32 2007-05-02 20:14:46 jhoblitt Exp $
     3# $Id: SQL.pm,v 1.33 2007-05-02 20:53:42 jhoblitt Exp $
    44
    55package Nebulous::Server::SQL;
     
    161161            used / total < ?
    162162            AND name = ?
     163            AND available = ?
     164            AND allocate = ?
    163165        ORDER BY free DESC
    164166        LIMIT 1
     
    172174        WHERE
    173175            used / total < ?
     176            AND available = ?
     177            AND allocate = ?
    174178        ORDER BY free DESC
    175179        LIMIT 1
     
    177181    new_volume          => qq{
    178182        INSERT INTO volume (name, path, allocate)
    179         VALUES (?, ?, TRUE)
     183        VALUES (?, ?, TRUE, TRUE)
    180184    },
    181185    get_volume_by_name => qq{
     
    304308    path VARCHAR(255) NOT NULL,
    305309    allocate BOOLEAN DEFAULT FALSE,
     310    available BOOLEAN DEFAULT FALSE,
    306311    PRIMARY KEY(vol_id),
    307312    KEY(name(16)),
    308     KEY(allocate)
     313    KEY(allocate),
     314    KEY(available)
    309315) ENGINE=innodb;
    310316
     
    337343    DECLARE namevar VARCHAR(255);
    338344    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;
    341348    DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE;
    342349
     
    353360        vol_id INT NOT NULL,
    354361        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
    356365    ) ENGINE=MEMORY;
    357366
     
    363372
    364373    myloop: LOOP
    365         FETCH cur1 INTO vol_idvar, namevar, pathvar;
     374        FETCH cur1 INTO vol_idvar, namevar, pathvar, allocatevar, availablevar;
    366375        IF `done` THEN LEAVE myloop; END IF;
    367376        INSERT INTO mountedvol
    368             SELECT mountpoint, total, used, vol_idvar, namevar, pathvar
     377            SELECT mountpoint, total, used, vol_idvar, namevar, pathvar, allocatevar, availablevar
    369378            FROM
    370379                (SELECT *, INSTR(pathvar, mountpoint) = 1 as substring
  • trunk/Nebulous/t/03_server_create_object.t

    r13130 r13131  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 03_server_create_object.t,v 1.14 2007-05-02 20:14:46 jhoblitt Exp $
     5# $Id: 03_server_create_object.t,v 1.15 2007-05-02 20:53:42 jhoblitt Exp $
    66
    77use strict;
    88use warnings FATAL => qw( all );
    99
    10 use Test::More tests => 10;
     10use Test::More tests => 12;
    1111
    1212use lib qw( ./t ./lib );
     
    5959    $neb->create_object("foo", 'node03');
    6060};
    61 like($@, qr/node03 is not available/, "request volume with allocate = FALSE");
     61like($@, qr/node03 is not available/, "request volume this is full");
    6262
    6363Test::Nebulous->setup;
     
    6666    $neb->create_object("foo", 'node04');
    6767};
    68 like($@, qr/node04 is not available/, "request volume this is full");
     68like($@, qr/node04 is not available/, "request volume with allocate = FALSE, available = FALSE");
     69
     70Test::Nebulous->setup;
     71
     72eval {
     73    $neb->create_object("foo", 'node05');
     74};
     75like($@, qr/node05 is not available/, "request volume with allocate = FALSE , available = TRUE");
     76
     77Test::Nebulous->setup;
     78
     79eval {
     80    $neb->create_object("foo", 'node06');
     81};
     82like($@, qr/node06 is not available/, "request volume with allocate = TRUE, available = FALSE");
    6983
    7084Test::Nebulous->setup;
  • trunk/Nebulous/t/Test/Nebulous.pm

    r13130 r13131  
    11# Copyright (C) 2004  Joshua Hoblitt
    22#
    3 # $Id: Nebulous.pm,v 1.13 2007-05-02 20:14:46 jhoblitt Exp $
     3# $Id: Nebulous.pm,v 1.14 2007-05-02 20:53:42 jhoblitt Exp $
    44
    55package Test::Nebulous;
     
    2424my $dir3 = "";
    2525my $dir4 = "";
     26my $dir5 = "";
     27my $dir6 = "";
    2628
    2729sub setup {
     
    3537    $dir3 = tempdir( CLEANUP => 0 );
    3638    $dir4 = tempdir( CLEANUP => 0 );
     39    $dir5 = tempdir( CLEANUP => 0 );
     40    $dir6 = tempdir( CLEANUP => 0 );
    3741
    3842    foreach my $statement (@{ $sql->get_db_schema }) {
     
    4145
    4246    # 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);
    4448    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir1);
    4549
    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);
    4751    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e8) }, undef, $dir2);
    4852
    49     # node03: allocate = FALSE
    50     $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, 10e8) }, 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);
    5256
    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);
    5668}
    5769
     
    6678    rmtree([$dir3], 0, 1) if -e $dir3;
    6779    rmtree([$dir4], 0, 1) if -e $dir4;
     80    rmtree([$dir5], 0, 1) if -e $dir5;
     81    rmtree([$dir6], 0, 1) if -e $dir6;
    6882}
    6983
Note: See TracChangeset for help on using the changeset viewer.