IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 23, 2007, 10:45:08 AM (19 years ago)
Author:
jhoblitt
Message:

change API to generally return true URIs instead of file paths
add support for some what intelligent volume allocations

File:
1 edited

Legend:

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

    r10627 r12961  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.22 2006-12-12 00:02:53 jhoblitt Exp $
     3# $Id: Server.pm,v 1.23 2007-04-23 20:45:08 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    1313
    1414use DBI;
    15 use Nebulous::Util qw( :standard );
     15use Log::Log4perl;
    1616use Nebulous::Server::Config;
    1717use Nebulous::Server::Log;
    1818use Nebulous::Server::SQL;
    19 use Log::Log4perl;
    20 use Params::Validate qw( validate_pos SCALAR );
     19use Nebulous::Util qw( :standard );
     20use Params::Validate qw( validate_pos SCALAR SCALARREF );
     21use URI::file;
    2122
    2223__PACKAGE__->mk_accessors(qw( log sql config ));
     
    159160    $log->debug( "entered - @_" );
    160161
    161     # TODO do some intelligent volume allocated
    162     # add hooks to make this decision based on avaiable space
    163162    $volume = $self->_get_storage_volume( $volume );
    164163
    165     my $uri;
    166164    my $object_id;
    167165    my $ins_id;
     
    210208    }
    211209
    212     $uri = "$volume/$key.$ins_id";
     210    my $uri = URI::file->new("$volume/$key.$ins_id");
    213211
    214212    $log->debug( "generated uri $uri");
    215213
    216     my $path = _get_file_path( $uri );
    217 
    218214    # TODO add some stuff here to retry if unsucessful
    219215    eval {
    220         _create_empty_file( $path );
     216        _create_empty_file($uri->file);
    221217    };
    222218    if ( $@ ) {
     
    237233    $log->debug( "leaving" );
    238234
    239     return $uri;
     235    return "$uri";
    240236}
    241237
     
    297293
    298294        {
    299             $uri = "$volume/$key.$ins_id";
    300             $log->debug( "generated uri $uri");
     295            $uri = URI::file->new("$volume/$key.$ins_id");
     296            $log->debug("generated uri $uri");
    301297
    302298            my $query = $db->prepare_cached( $sql->update_instance_uri );
     
    311307
    312308    eval {
    313         $path = _get_file_path( $uri );
    314         $path = _create_empty_file( $path );
     309        _create_empty_file($uri->file);
    315310    };
    316311    if ( $@ ) {
     
    323318    $log->debug( "leaving" );
    324319
    325     return $uri;
     320    return "$uri";
    326321}
    327322
     
    620615    my ( $uri ) = validate_pos( @_,
    621616        {
    622             type => SCALAR,
     617            type => SCALAR|SCALARREF,
    623618        },
    624619    );
     
    731726}
    732727
     728#  select *, total - used as free, (used / total) * 100 as perused from mount;
     729
    733730sub _get_storage_volume {
    734731    my $self = shift;
     
    751748        if ( $name ) {
    752749            $query = $db->prepare_cached( $sql->get_storage_volume_byname );
    753             $rows = $query->execute( $name );
     750            $rows = $query->execute(0.95, $name);
    754751        } else {
    755752            $query = $db->prepare_cached( $sql->get_storage_volume );
    756             $rows = $query->execute;
     753            $rows = $query->execute(0.95);
    757754        }
    758755
     
    762759        }
    763760
    764         $volume = $query->fetchrow_hashref->{ 'uri' };
     761        $volume = $query->fetchrow_hashref->{ 'mountpoint' };
    765762
    766763        $query->finish;
Note: See TracChangeset for help on using the changeset viewer.