IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 27, 2008, 11:59:53 AM (18 years ago)
Author:
jhoblitt
Message:

add neb-admin util

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/bin/neb-admin

    r17771 r17815  
    33# Copyright (C) 2005-2008  Joshua Hoblitt
    44#
    5 # $Id: neb-admin,v 1.1 2008-05-22 04:08:29 jhoblitt Exp $
     5# $Id: neb-admin,v 1.2 2008-05-27 21:59:53 jhoblitt Exp $
    66
    77use strict;
     
    1919use Pod::Usage qw( pod2usage );
    2020
    21 my ($db, $dbuser, $dbpass, $server);
     21my ($db, $dbuser, $dbpass, $server, $limit);
    2222
    2323$db     = $ENV{'NEB_DB'} unless $db;
     
    3131    'pass=s'        => \$dbpass,
    3232    'server|s=s'    => \$server,
     33    'limit|l=i'     => \$limit,
    3334) || pod2usage( 2 );
    3435
     
    3839pod2usage( -msg => "Required options: --db --user --pass", -exitval => 2 )
    3940    unless $db && $dbuser && $dbpass;
     41
     42# set default limit to 5
     43$limit ||= 5;
    4044
    4145my $neb = Nebulous::Client->new(
     
    6064
    6165# so_id, ext_id, instances, available_instances, need_recovery, recoverable
    62 my $query = $dbh->prepare( $sql->find_objects_with_unavailable_instances );
     66my $query = $dbh->prepare( $sql->find_objects_with_unavailable_instances
     67        . " LIMIT $limit" );
    6368$query->execute;
    6469
     
    6873}
    6974$query->finish;
     75   
     76print "replciate MULTI\n\n";
    7077
    7178foreach my $obj (@rows) {
     
    7582    my $key = $obj->{ext_id};
    7683    my $has = $obj->{instances};
     84    my $vol_name = $obj->{volume_name};
    7785    my $available = $obj->{available_instances} || 0;
    7886    my $need_recovery = $obj->{need_recovery};
     
    8492    # objects with only a single instance that are offline are unrecoverable so
    8593    # we don't need to handle that special case
    86     next unless $need_recovery;
     94#    next unless $need_recovery;
    8795    unless ($recoverable) {
    8896        warn "so_id: $so_id key: \'$key\' ",
     
    96104    next unless $need;
    97105
    98     for (; $need > 0; $need--) {
    99         warn "so_id: $so_id key: \'$key\' ",
    100             "has $available available instances, target $copies -- replicating"
    101             or warn "so_id: $so_id key: \'$key\' replication failed";
    102 
    103         $need++;
     106    my %md = (
     107        key         => $key,
     108        need_copies => $need,
     109        volume_name => $vol_name,
     110    );
     111
     112    print_metadata("replicate", \%md);
     113    print "\n";
     114}
     115
     116sub print_metadata
     117{
     118    my ($name, $pairs) = @_;
     119
     120    print "$name METADATA\n";
     121
     122    # format from formatMetadataItem() in pzMetadataConfig.c
     123    foreach my $key (keys %$pairs) {
     124        my $value = $pairs->{$key};
     125        if (looks_like_number($value)) {
     126            printf("   " . "%-15s  %-8s  %-15s\n", $key, "S32", $value);
     127        } else {
     128            printf("   " . "%-15s  %-8s  %-15s\n", $key, "STR", $value);
     129        }
    104130    }
     131   
     132    print "END\n";
     133}
     134
     135# looks_like_number() was stolen from Scalar::Util
     136#
     137# Copyright (c) 1997-2006 Graham Barr <gbarr@pobox.com>. All rights reserved.
     138# This program is free software; you can redistribute it and/or modify it
     139# under the same terms as Perl itself.
     140
     141sub looks_like_number {
     142  local $_ = shift;
     143
     144  # checks from perlfaq4
     145  return 0 if !defined($_) or ref($_);
     146  return 1 if (/^[+-]?\d+$/); # is a +/- integer
     147  return 1 if (/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/); # a C float
     148  return 1 if ($] >= 5.008 and /^(Inf(inity)?|NaN)$/i) or ($] >= 5.006001 and /^Inf$/i);
     149
     150  0;
    105151}
    106152
Note: See TracChangeset for help on using the changeset viewer.