From fe33d7d98f2aa9b8c37f2b12d0fa5c44d8edca95 Mon Sep 17 00:00:00 2001 From: cxhong Date: Mon, 29 Oct 2018 05:12:20 -0400 Subject: [PATCH] Log Number of Nodes for xCAT command to command.log (#5729) * Log Number of Nodes for chdef/mkdef/rmdef/lsdef/nodels command to command.log * Create a new tag for reponse object --- xCAT-server/lib/xcat/plugins/DBobjectdefs.pm | 4 ++++ xCAT-server/lib/xcat/plugins/tabutils.pm | 9 ++++++++- xCAT-server/sbin/xcatd | 13 +++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm b/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm index 748d07792..91e4a49e9 100755 --- a/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm +++ b/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm @@ -2080,6 +2080,7 @@ sub defmk $rsp->{data}->[0] = "$nodenum object definitions have been created or modified."; if ($nodenum > 0) { # Some objects were created, report as success + $rsp->{numofnodes}->[0] = $nodenum; xCAT::MsgUtils->message("I", $rsp, $::callback); } else { @@ -2962,6 +2963,7 @@ sub defch if ($nodenum) { $rsp->{data}->[0] = "$nodenum object definitions have been created or modified."; + $rsp->{numofnodes}->[0] = $nodenum; } else { $rsp->{data}->[0] = "No object definitions have been created or modified."; } @@ -4155,6 +4157,7 @@ sub defls # Display the definition of objects if (defined($rsp_info->{data}) && scalar(@{ $rsp_info->{data} }) > 0) { + $rsp_info->{numofnodes}->[0] = $numobjects; xCAT::MsgUtils->message("I", $rsp_info, $::callback); } @@ -4522,6 +4525,7 @@ sub defrm my $rsp; my $nodenum = scalar(keys %objhash); $rsp->{data}->[0] = "$nodenum object definitions have been removed."; + $rsp->{numofnodes}->[0] = $nodenum; xCAT::MsgUtils->message("I", $rsp, $::callback); } diff --git a/xCAT-server/lib/xcat/plugins/tabutils.pm b/xCAT-server/lib/xcat/plugins/tabutils.pm index 2bc3a5c14..0d428a5d9 100644 --- a/xCAT-server/lib/xcat/plugins/tabutils.pm +++ b/xCAT-server/lib/xcat/plugins/tabutils.pm @@ -1882,6 +1882,8 @@ sub nodels my $VERSION; my $HELP; + my $nodenum; + my $nodels_usage = sub { my $exitcode = shift @_; @@ -2154,6 +2156,7 @@ sub nodels } } $callback->($rsp); + $nodenum = scalar (@$nodes); } else { @@ -2205,8 +2208,12 @@ sub nodels #} } + $nodenum = scalar (@nodes); } } + my $rsp_info; + $rsp_info->{numofnodes}->[0] = $nodenum; + $callback->($rsp_info); return 0; } @@ -2328,7 +2335,7 @@ sub tabch { { my $tab = xCAT::Table->new($_, -create => 1, -autocommit => 0); unless ($tab) { - my %rsp; + my %rsp; $rsp{data}->[0] = "Table $_ does not exist."; $rsp{errorcode}->[0] = 1; $callback->(\%rsp); diff --git a/xCAT-server/sbin/xcatd b/xCAT-server/sbin/xcatd index b9729d12c..5ecc294de 100755 --- a/xCAT-server/sbin/xcatd +++ b/xCAT-server/sbin/xcatd @@ -30,6 +30,8 @@ my $udpctl; my $pid_UDP; my $pid_MON; +my $numofnodes=0; + # ----used for command log start--------- my $cmdlog_svrpid; @@ -2165,6 +2167,7 @@ sub plugin_command { } } } + } my $dispatch_parentfd; @@ -2661,6 +2664,9 @@ sub send_response { if ( (ref($rsp) eq 'ARRAY') && scalar(@$rsp) > 0 ) { foreach (@$rsp) { $_->{xcatdsource}->[0] = $MYXCATSERVER unless ($_->{xcatdsource}); + if ($_->{numofnodes}) { + $numofnodes = $_->{numofnodes}->[0]; + } } } } @@ -2803,6 +2809,12 @@ sub service_connection { if ($enable_perf) { xCAT::MsgUtils->perf_log_process('immediate', $req); } + + if (exists($req->{noderange}) && defined($req->{noderange}->[0])) { + my @nnodes = xCAT::NodeRange::noderange($req->{noderange}->[0]); + $numofnodes = (scalar(@nnodes)); + } + # ----used for command log start---------- $cmdlog_starttime = time(); my ($sec, $min, $hour, $mday, $mon, $year) = localtime($cmdlog_starttime); @@ -3018,6 +3030,7 @@ sub service_connection { } # ----used for command log start------- + $cmdlog_alllog .= "[NumberNodes] $numofnodes \n"; my $reqhandletime = sprintf("%.3f", time()-$cmdlog_starttime); $cmdlog_alllog .= "[ElapsedTime] $reqhandletime s\n"; cmdlog_submitlog();