IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 20, 2009, 11:15:20 AM (17 years ago)
Author:
jhoblitt
Message:

merge neb_distrib_20081210

Location:
trunk/Nebulous-Server
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server

  • trunk/Nebulous-Server/lib/Nebulous/Server/Config.pm

    r20990 r23932  
    88use warnings FATAL => qw( all );
    99
    10 our $VERSION = 0.02;
     10our $VERSION = 0.03;
    1111
    1212use base qw( Class::Accessor::Fast );
    1313
    1414use Log::Log4perl qw( :levels );
    15 use Params::Validate qw( validate SCALAR );
     15use Params::Validate qw( validate validate_pos SCALAR );
    1616
    1717our %LEVELS = (
     
    2525);
    2626
    27 my $new_validate = {
     27my $db_validate = {
     28    dbindex       => {
     29        type => SCALAR,
     30        regex => qr/^\d+$/,
     31    },
    2832    dsn         => { type => SCALAR },
    2933    dbuser      => { type => SCALAR },
    3034    dbpasswd    => { type => SCALAR },
    31     log_level   => {
     35};
     36
     37my $new_validate = {
     38    trace       => {
    3239        type        => SCALAR,
    3340        optional    => 1,
    34         default     => 'all',
     41        default     => 'fatal',
    3542        callbacks   => {
    3643            'is valid level' => sub {
     
    3946        },
    4047    },
     48    dsn         => { type => SCALAR, optional => 1 },
     49    dbuser      => { type => SCALAR, optional => 1 },
     50    dbpasswd    => { type => SCALAR, optional => 1 },
    4151};
    4252
    4353__PACKAGE__->mk_ro_accessors( keys %$new_validate );
    4454
    45 sub init {
     55
     56sub new
     57{
    4658    my $class = shift;
    4759
     
    4961
    5062    # normalize log levels to lower-case
    51     $p{ log_level } = lc $p{ log_level };
    52 
    53     my $self = \%p;
     63    my $self = { trace => $LEVELS{lc($p{trace})} };
    5464
    5565    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    }
    5678
    5779    return $self;
    5880}
    5981
     82
     83sub 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
     101sub 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
     114sub n_db
     115{
     116    my $self = shift;
     117
     118    return scalar @{ $self->{dbs} };
     119}
     120
     121
     122package Nebulous::Server::Config::DB;
     123
     124use strict;
     125use warnings FATAL => qw( all );
     126
     127our $VERSION = 0.01;
     128
     129use base qw( Class::Accessor::Fast );
     130
     131__PACKAGE__->mk_ro_accessors(qw( dsn dbuser dbpasswd ));
     132
    601331;
    61134
  • trunk/Nebulous-Server/lib/Nebulous/Server/Log.pm

    r20990 r23932  
    1616    my ($self, $config) = @_;
    1717
    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;
    2121
    2222    my $conf = <<END;
     
    3030#   date | hostname | priority | method/sub - message\n
    3131
    32     log4perl.appender.SQLLOG            = Log::Log4perl::Appender::DBI
    33     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   =
    3737    INSERT INTO log (timestamp, hostname, level, sub, message) \
    3838    VALUES          (%d,        %H,       %p,    %M,  %m)
  • trunk/Nebulous-Server/lib/Nebulous/Server/SOAP.pm

    r20990 r23932  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SOAP.pm,v 1.6 2008-12-14 22:54:25 eugene Exp $
     3# $Id: SOAP.pm,v 1.4.32.1 2008-12-14 22:52:37 eugene Exp $
    44
    55package Nebulous::Server::SOAP;
     
    1717our $AUTOLOAD;
    1818
    19 our @args;
     19our $config;
    2020our $neb;
    2121
    22 sub new_on_init {
     22
     23sub new_on_init
     24{
    2325    my $self = shift;
    2426
     
    2729    require Apache2::ServerUtil;
    2830
    29     @args = @_;
     31    $config = shift;
    3032
    3133    my $s = Apache2::ServerUtil->server;
     
    3537}
    3638
    37 sub init {
     39
     40sub init
     41{
    3842    my $self = shift;
    3943
    40     $neb = Nebulous::Server->new(@args);       
     44    $neb = Nebulous::Server->new_from_config($config);       
    4145
    4246    return Apache2::Const::OK;
    4347}
    4448
    45 sub AUTOLOAD {
     49
     50sub AUTOLOAD
     51{
    4652    my $self = shift;
    4753
     
    7682}
    7783
     84
    78851;
  • trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm

    r23699 r23932  
    88use warnings FATAL => qw( all );
    99
    10 our $VERSION = '0.02';
     10our $VERSION = '0.04';
    1111
    1212use base qw( Class::Accessor::Fast );
     
    2626    new_object          => qq{
    2727        INSERT INTO storage_object
    28         (so_id, ext_id, type)
    29         VALUES (?, ?, 'REG_FILE')
     28        (so_id, ext_id, ext_id_basename, type, dir_id)
     29        VALUES (?, ?, ?, 'REG_FILE', ?)
    3030    },
    3131    new_object_attr  => qq{
     
    6060        USING (so_id)
    6161        WHERE ext_id = ?
     62    },
     63    get_directory       => qq{
     64        SELECT
     65            dir_id
     66        FROM directory
     67        WHERE parent_id = ?
     68            AND dirname = ?
     69    },
     70    new_directory       => qq{
     71        INSERT INTO directory
     72        (dirname, parent_id)
     73        VALUES (?, ?)
    6274    },
    6375    check_object_name => qq{
     
    297309            USING(vol_id)
    298310    },
    299     find_objects => qq{
    300         SELECT *
    301         FROM storage_object
    302         WHERE ext_id REGEXP ?
     311    find_object_by_ext_id => qq{
     312        SELECT ext_id, ext_id_basename
     313        FROM storage_object
     314        WHERE ext_id = ?
     315    },
     316    find_object_by_dir_id => qq{
     317        SELECT ext_id, ext_id_basename
     318        FROM storage_object
     319        WHERE dir_id = ?
    303320    },
    304321    rename_object => qq{
    305322        UPDATE storage_object
    306         SET ext_id = ?
     323        SET ext_id = ?, ext_id_basename = ?, dir_id = ?
    307324        WHERE ext_id = ?
    308325    },
     
    330347        GROUP BY so_id
    331348        HAVING available_instances < instances OR instances < copies
     349    },
     350    find_objects_with_extra_instances_by_xattr => qq{
     351        SELECT
     352            so.so_id,
     353            so.ext_id,
     354            count(ins_id) as instances,
     355            mv.name as volume_name,
     356            mv.host as volume_host,
     357            count(mv.vol_id) as available_instances,
     358            xattr.value as copies
     359        FROM storage_object AS so
     360        JOIN storage_object_xattr as xattr
     361            ON so.so_id = xattr.so_id
     362            AND xattr.name = 'user.copies'
     363        JOIN instance AS i
     364            ON so.so_id = i.so_id
     365        JOIN mountedvol AS mv
     366            USING(vol_id)
     367        WHERE
     368            mv.available = 1
     369        GROUP BY so_id
     370        HAVING available_instances > copies
     371        limit 5;
    332372    },
    333373    find_objects_with_extra_instances => qq{
     
    387427DROP TABLE IF EXISTS log;
    388428DROP TABLE IF EXISTS mountedvol;
     429DROP TABLE IF EXISTS directory;
    389430DROP PROCEDURE IF EXISTS getmountedvol;
    390431SET FOREIGN_KEY_CHECKS=1
     
    408449
    409450__DATA__
     451CREATE TABLE directory (
     452    dir_id BIGINT NOT NULL AUTO_INCREMENT,
     453    dirname CHAR(255) NOT NULL,
     454    parent_id BIGINT NOT NULL,
     455    FOREIGN KEY(parent_id) REFERENCES directory(dir_id),
     456    PRIMARY KEY(dir_id),
     457    KEY(parent_id)
     458) ENGINE=innodb DEFAULT CHARSET=latin1;
     459
     460###
     461
     462INSERT INTO directory (dir_id, dirname, parent_id) VALUES (1, '/', 1);
     463
     464###
     465
    410466CREATE TABLE storage_object (
    411467    so_id BIGINT NOT NULL AUTO_INCREMENT,
    412468    ext_id VARCHAR(255) NOT NULL UNIQUE,
     469    ext_id_basename VARCHAR(255) NOT NULL,
     470    dir_id BIGINT NOT NULL,
     471    FOREIGN KEY(dir_id) REFERENCES directory(dir_id),
    413472    type enum('REG_FILE'),
    414473    PRIMARY KEY(so_id),
Note: See TracChangeset for help on using the changeset viewer.