From 780fbaaad823073355c0702c8d6c668fd226a69a Mon Sep 17 00:00:00 2001 From: lissav Date: Tue, 6 Aug 2013 12:15:26 -0400 Subject: [PATCH] use MAXMIN routine --- xCAT-server/lib/xcat/plugins/tabutils.pm | 110 ++++++++--------------- 1 file changed, 38 insertions(+), 72 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/tabutils.pm b/xCAT-server/lib/xcat/plugins/tabutils.pm index 9cf8b00fc..2596cab60 100644 --- a/xCAT-server/lib/xcat/plugins/tabutils.pm +++ b/xCAT-server/lib/xcat/plugins/tabutils.pm @@ -580,9 +580,10 @@ sub tabdump if ($args) { @ARGV = @{$args}; } - Getopt::Long::Configure("posix_default"); - Getopt::Long::Configure("no_gnu_compat"); - Getopt::Long::Configure("bundling"); + Getopt::Long::Configure("posix_default"); + Getopt::Long::Configure("no_gnu_compat"); + Getopt::Long::Configure("bundling"); + if (!GetOptions( 'h|?|help' => \$HELP, @@ -604,14 +605,15 @@ sub tabdump return; } if ($FILENAME and $FILENAME !~ /^\//) { $FILENAME =~ s/^/$request->{cwd}->[0]\//; } - + if ($HELP) { $tabdump_usage->(0); return; } + if (($NUMBERENTRIES) && ($DESC)) { $cb->({error => "You cannot use the -n and -d flag together. ",errorcode=>1}); return 1; } - + if (($NUMBERENTRIES) && ($OPTW)) { $cb->({error => "You cannot use the -n and -w flag together. ",errorcode=>1}); return 1; @@ -620,10 +622,8 @@ sub tabdump $cb->({error => "You cannot use the -n and -f flag together. ",errorcode=>1}); return 1; } - if (scalar(@ARGV)>1) { $tabdump_usage->(1); return; } - my %rsp; # If no arguments given, we display a list of the tables if (!scalar(@ARGV)) { @@ -647,15 +647,15 @@ sub tabdump } # get the table name $table = $ARGV[0]; - + # if -n can only be the auditlog or eventlog if ($NUMBERENTRIES) { if (!( $table =~ /^auditlog/ ) && (!($table =~ /^eventlog/))){ $cb->({error => "$table table is not supported in tabdump -n. You may only use this option on the auditlog or the eventlog.",errorcode=>1}); return 1; - } - } - + } + } + # do not allow teal tables if ( $table =~ /^x_teal/ ) { $cb->({error => "$table table is not supported in tabdump. Use Teal maintenance commands. ",errorcode=>1}); @@ -703,7 +703,6 @@ sub tabdump return $rc; } - my $recs; my @ents; my @attrarray; @@ -758,12 +757,12 @@ sub tabdump } # # display input number of records for the table requested tabdump -n +# note currently only supports auditlog and eventlog # sub tabdump_numberentries { my $table = shift; my $cb = shift; my $numberentries = shift; # either number of records to display - my $attrrecid="recid"; my $VERBOSE = shift; my $rc=0; @@ -772,38 +771,21 @@ sub tabdump_numberentries { $cb->({error => "Unable to open $table",errorcode=>4}); return 1; } - my $DBname = xCAT::Utils->get_DBName; - my @attribs = ($attrrecid); - my @ents=$tab->getAllAttribs(@attribs); - if (@ents) { # anything to process - # find smallest and largest recid, note table is not ordered by recid after - # a while - my $smallrid; - my $largerid; - foreach my $rid (@ents) { - if (!(defined $smallrid)) { - $smallrid=$rid; - } - if (!(defined $largerid)) { - $largerid=$rid; - } - if ($rid->{$attrrecid} < $smallrid->{$attrrecid}) { - $smallrid=$rid; - } - if ($rid->{$attrrecid} > $largerid->{$attrrecid}) { - $largerid=$rid; - } - } - my $RECID; - #determine recid to show all records after - $RECID= $largerid->{$attrrecid} - $numberentries ; - $rc=tabdump_recid($table,$cb,$RECID, $attrrecid); - } else { + #determine recid to show all records after + my $RECID; + my $attrrecid="recid"; + my $values = $tab->getMAXMINEntries($attrrecid); + my $max=$values->{"max"}; + if (defined($values->{"max"})){ + $RECID= $values->{"max"} - $numberentries ; + $rc=tabdump_recid($table,$cb,$RECID, $attrrecid); + + } else { my %rsp; push @{$rsp{data}}, "Nothing to display from $table."; $rsp{errorcode} = $rc; $cb->(\%rsp); - } + } return $rc; } # Display requested recored @@ -831,6 +813,7 @@ sub tabdump_recid { output_table($table,$cb,$tab,\@recs); return $rc; } + # Display information from the daemon. # sub lsxcatd @@ -1066,7 +1049,7 @@ sub tabprune if (($table eq "eventlog") || ($table eq "auditlog")) { $attrrecid="recid"; } else { - if ($table eq "isnm_perf") { # if ISNM These tables are really not supported in 2.8 or later + if ($table eq "isnm_perf") { # if ISNM These tables are really not supported in 2.8 or later $attrrecid="perfid"; } else { $attrrecid="period"; # isnm_perf_sum table @@ -1134,51 +1117,34 @@ sub tabprune_numberentries { $cb->({error => "Unable to open $table",errorcode=>4}); return 1; } - my $DBname = xCAT::Utils->get_DBName; - my @attribs = ("$attrrecid"); - my @ents=$tab->getAllAttribs(@attribs); - if (@ents) { # anything to process - # find smallest and largest recid, note table is not ordered by recid after - # a while - my $smallrid; - my $largerid; - foreach my $rid (@ents) { - if (!(defined $smallrid)) { - $smallrid=$rid; - } - if (!(defined $largerid)) { - $largerid=$rid; - } - if ($rid->{$attrrecid} < $smallrid->{$attrrecid}) { - $smallrid=$rid; - } - if ($rid->{$attrrecid} > $largerid->{$attrrecid}) { - $largerid=$rid; - } - } - my $RECID; + my $RECID; + my $values = $tab->getMAXMINEntries($attrrecid); + if ((defined($values->{"max"})) && (defined($values->{"min"}))) { + my $largerid = $values->{"max"}; + my $smallrid = $values->{"min"}; if ($flag eq "n") { # deleting number of records - #determine recid to delete all entries that come before like the -i flag - $RECID= $smallrid->{$attrrecid} + $numberentries ; + #get the smalled recid and add number to delete, that is where to start removing + $RECID= $smallrid + $numberentries ; } else { # flag must be percentage #take largest and smallest recid and percentage and determine the recid # that will remove the requested percentage. If some are missing in the # middle due to tabedit, we are not worried about it. - my $totalnumberrids = $largerid->{$attrrecid} - $smallrid->{$attrrecid} +1; + my $totalnumberrids = $largerid - $smallrid +1; my $percent = $numberentries / 100; my $percentage=$totalnumberrids * $percent ; my $cnt=sprintf( "%d", $percentage ); # round to whole number - $RECID=$smallrid->{$attrrecid} + $cnt; # get recid to remove all before + $RECID=$smallrid + $cnt; # get recid to remove all before } + # Now prune starting at $RECID $rc=tabprune_recid($table,$cb,$RECID, $attrrecid,$VERBOSE); - } else { + } else { my %rsp; push @{$rsp{data}}, "Nothing to prune from $table."; $rsp{errorcode} = $rc; $cb->(\%rsp); - } - return $rc; + } + return $rc; } # prune all entries up to the record id input