IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28525


Ignore:
Timestamp:
Jun 28, 2010, 2:59:29 PM (16 years ago)
Author:
watersc1
Message:

Final update to nebulous for this iteration. Changes:

  • nebdiskd reads its configuration from a sane location.
  • neb-ls is useful.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/bin/nebdiskd

    r28492 r28525  
    5353# set the process name for easy pgrep-ability
    5454$0 = 'nebdiskd';
    55 my $rcfile = "$ENV{HOME}/.nebdiskrc";
     55#my $rcfile = "$ENV{HOME}/.nebdiskrc";
     56my $rcfile = $ENV{NEBDISKDRC};
     57unless (defined($rcfile)) {
     58    $rcfile = '/etc/nebdiskd.rc';
     59}
    5660$rcfile = File::Spec->canonpath($rcfile);
    5761
     
    7175my %host_removed = ();
    7276my $failure_limit = 5;
    73 
    74 
    7577
    7678#my $mounts = $c->get_mounts;
     
    143145$SIG{HUP}  = sub { $c = read_rcfile($rcfile) };
    144146
     147my $date = localtime();
     148$log->warn("BEGIN: $date with RCFILE: $rcfile");
    145149
    146150while (1) {
  • trunk/Nebulous-Server/lib/Nebulous/Server.pm

    r28446 r28525  
    99no warnings qw( uninitialized );
    1010
    11 our $VERSION = '0.17';
     11our $VERSION = '0.18';
    1212
    1313use base qw( Class::Accessor::Fast );
     
    15081508
    15091509    return \@keys;
     1510}
     1511
     1512sub find_objects_wildcard
     1513{
     1514    my $self = shift;
     1515
     1516    my $log = $self->log;
     1517    $log->debug( "entered - @_" );
     1518
     1519    my ($pattern) = validate_pos( @_,
     1520        {
     1521            type        => SCALAR,
     1522            optional    => 1,
     1523        },
     1524    );
     1525
     1526    my $sql = $self->sql;
     1527    my $db  = $self->_db_for_index(0);
     1528   
     1529    # validate that we have a key to deal with
     1530    eval {
     1531        $pattern = parse_neb_key($pattern) if defined $pattern;
     1532    };
     1533    $log->logdie("$@") if $@;
     1534
     1535    unless (defined $pattern) {
     1536        $log->debug( "leaving" );
     1537        $log->logdie("no keys found");
     1538    }
     1539
     1540    # parse out the directory we're working in, and decide if we are a directory
     1541    my $dir_id = $self->_resolve_dir_parent_id(key => $pattern, dir_id => 1);
     1542    my $work_dir;
     1543    my $file_pattern;
     1544    if (defined $dir_id) {
     1545        $work_dir = $pattern;
     1546        $file_pattern = '%';
     1547    }
     1548    else {
     1549        my $dir_plain = dirname($pattern);
     1550        if ($dir_plain eq 'neb:') {
     1551            $dir_plain = 'neb:///';
     1552        }
     1553        if ($dir_plain) {
     1554            $work_dir = parse_neb_key($dir_plain);
     1555        }
     1556        else {
     1557            $work_dir = parse_neb_key('/');
     1558        }
     1559        $log->warn("work dir: $work_dir " . $work_dir->path);
     1560        $file_pattern = basename $pattern;
     1561        unless ($file_pattern) {
     1562            $file_pattern = '%';
     1563        }
     1564       
     1565        $dir_id = $self->_resolve_dir_parent_id(key => $work_dir, dir_id => 1);
     1566        unless (defined $dir_id) {
     1567            $log->logdie("pattern $work_dir does not match any key or directory");
     1568        }
     1569    }
     1570   
     1571    # find dirs under dir
     1572    my @dir_keys;
     1573
     1574    eval {
     1575        $log->debug("looking for directories under dir: $dir_id");
     1576        $log->warn("dir_id: $dir_id pattern: $file_pattern");
     1577        my $query = $db->prepare_cached( $sql->find_dir_by_parent_id . " AND dirname LIKE ? ");
     1578        $query->execute( $dir_id, $file_pattern );
     1579
     1580        while ( my $row = $query->fetchrow_hashref ) {
     1581            next if $row->{'dir_id'} == 1;
     1582            my $dir = $row->{'dirname'};
     1583            if ($dir_id == 1) {
     1584                push @dir_keys, $dir . '/' if $dir;
     1585            } else {
     1586                push @dir_keys, $work_dir->path . '/' . $dir . '/' if $dir;
     1587            }
     1588            $log->debug( "matched $dir" ) if $dir;
     1589        }
     1590    };
     1591    $log->logdie("database error: $@") if $@;
     1592
     1593    # find files under dir
     1594    my @keys;
     1595    eval {
     1596        $log->debug("looking for objects under dir: $dir_id");
     1597        my $query = $db->prepare_cached( $sql->find_object_by_dir_id . " AND ext_id_basename LIKE ? ");
     1598        $query->execute( $dir_id , $file_pattern);
     1599
     1600        while ( my $row = $query->fetchrow_hashref ) {
     1601            my $key = $row->{ 'ext_id' };
     1602            push @keys, $key if $key;
     1603            $log->debug( "matched $key" ) if $key;
     1604        }
     1605    };
     1606    $log->logdie("database error: $@") if $@;
     1607
     1608    $log->debug( "leaving" );
     1609   
     1610    return [sort(@dir_keys), sort(@keys)];
     1611
    15101612}
    15111613
  • trunk/Nebulous/bin/neb-ls

    r24346 r28525  
    11#!/usr/bin/env perl
    22
    3 # Copyright (C) 2007-2009  Joshua Hoblitt
     3# Copyright (C) 2007-2009  Joshua Hoblitt, 2010 Chris Waters
    44
    55use strict;
     
    1616my (
    1717    $server,
    18     $long,
    19 #    $recursive,
     18    $path,
     19    $column,
    2020);
    2121
    2222$server = $ENV{'NEB_SERVER'} unless $server;
    2323
    24 # make --long the default
    25 $long = 1;
    2624
    2725GetOptions(
    2826    'server|s=s'    => \$server,
    29 #    'recursive|r'   => \$recursive,
    30     'l|1'           => \$long,
     27    'path|p'        => \$path,
     28    'column|c'      => \$column,
    3129) || pod2usage( 2 );
     30
     31# twiddle column so that it does it by default.
     32
     33$column = not $column;
    3234
    3335my $pattern = shift;
     
    4749$pattern ||= "/";
    4850
    49 #if ($recursive) {
    50 #    $pattern = "^" . $pattern . ".*";
    51 #} else {
    52 #    $pattern = "^" . $pattern . "\$";
    53 #}
     51my $keys = $neb->find_objects_wildcard($pattern);
    5452
    55 my $keys = $neb->find_objects($pattern);
    56 
     53if ($path) {
     54    my @files;
     55    foreach my $key (@{ $keys }) {
     56        my $uris = $neb->find_instances($key);
     57        if (defined $uris) {
     58            push @files, URI->new(@$uris[0])->file;
     59        }
     60    }
     61    @{ $keys } = @files;
     62}
    5763if ($keys) {
    58     if ($long) {
    59         print join("\n", @{ $keys }), "\n";
    60     } else {
    61         print join(" ", @{ $keys }), "\n";
     64    if ($column) {
     65        open(COLUMN,"|column") || die "Cannot open column command.";
     66        print COLUMN join("\n", @{ $keys }), "\n";
     67        close(COLUMN);
     68    }
     69    else {
     70        print join("\n", @{ $keys }), "\n";
    6271    }
    6372}
     73
    6474
    6575__END__
     
    7383=head1 SYNOPSIS
    7484
    75     neb-ls [--server <URL>] [-l|-1] [--recursive] <pattern>
     85    neb-ls [--server <URL>] [-c] [-p] <pattern>
    7686
    7787=head1 DESCRIPTION
    7888
    7989This program list Nebulous keys matched by C<<pattern>>.  Call it with no
    80 arguments is equivalanet to searching with the pattern C<.*>.  Where
    81 C<<pattern>> is a POSIX 1003.2 compatable regular repression.
     90arguments is equivalent to searching with the pattern C<neb://>.  SQL like
     91wildcards are supported to select out certain files.
    8292
    8393=head1 OPTIONS
     
    8595=over 4
    8696
    87 =item * -l|-1
     97=item * --path|-p
    8898
    89 Use a long listing format.
     99Find the disk files corresponding to the keys found.
     100
     101=item * --column|-c
     102
     103Disable column formatting, and output results one to a line.
    90104
    91105Optional
    92106
    93 =cut
    94 #=item * --recursive|-r
    95 #
    96 #By default C<neb-ls> will only try to match the exact string provided to it.
    97 #With this option set all keys which match C<<pattern>> as a REGEX or substring
    98 #will be returned.
    99 #
    100 #Optional
    101 #
    102107=item * --server|-s <URL>
    103108
     
    122127=back
    123128
    124 =head1 CREDITS
    125 
    126 Just me, myself, and I.
    127 
    128129=head1 SUPPORT
    129130
     
    132133=head1 AUTHOR
    133134
    134 Joshua Hoblitt <jhoblitt@cpan.org>
     135Joshua Hoblitt <jhoblitt@cpan.org>, Chris Waters
    135136
    136137=head1 COPYRIGHT
    137138
    138 Copyright (C) 2007-2009  Joshua Hoblitt.  All rights reserved.
     139Copyright (C) 2007-2010  Joshua Hoblitt / Chris Waters.  All rights reserved.
    139140
    140141This program is free software; you can redistribute it and/or modify it under
  • trunk/Nebulous/lib/Nebulous/Client.pm

    r28446 r28525  
    99no warnings qw( uninitialized );
    1010
    11 our $VERSION = '0.17';
     11our $VERSION = '0.18';
    1212
    1313use Digest::MD5;
     
    741741}
    742742
     743sub find_objects_wildcard
     744{
     745    my $self = shift;
     746
     747    my @args = validate_pos( @_,
     748        {
     749            type        => SCALAR,
     750            optional    => 1,
     751        },
     752    );
     753
     754    $log->debug( "entered - @_" );
     755
     756    my $response = $self->{ 'server' }->find_objects_wildcard( @args );
     757    if ( $response->fault ) {
     758        $self->set_err($response->faultstring);
     759
     760        if ($response->faultstring =~ /no keys found/) {
     761            $log->debug( "leaving" );
     762            return;
     763        }
     764        if ($response->faultstring =~ /does not match any key or directory/) {
     765            $log->debug( "leaving" );
     766            return;
     767        }
     768
     769        $log->logdie("unhandled fault - ", $self->err);
     770    }
     771
     772    my $keys = $response->result;
     773
     774    $log->debug( "server found: @$keys" );
     775
     776#    foreach my $path ( @{ $uris } ) {
     777#        $path = _get_file_path( $path );
     778#    }
     779
     780    $log->debug( "leaving" );
     781
     782    return $keys;
     783}
     784
    743785
    744786sub find_instances
Note: See TracChangeset for help on using the changeset viewer.