From 16e37a45d55400a9650cbb70dd4ee17594662194 Mon Sep 17 00:00:00 2001 From: linggao Date: Thu, 29 May 2008 21:13:37 +0000 Subject: [PATCH] changed in nodeAdd/nodeRemove in monitoring infrastructure git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@1525 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- .../lib/xcat/monitoring/monitorctrl.pm | 215 ++---------------- .../xcat/monitoring/samples/templatemon.pm | 40 ++-- .../lib/xcat/monitoring/snmpmon.pm | 64 +++--- .../lib/xcat/monitoring/xcatmon.pm | 16 +- 4 files changed, 89 insertions(+), 246 deletions(-) diff --git a/xCAT-server-2.0/lib/xcat/monitoring/monitorctrl.pm b/xCAT-server-2.0/lib/xcat/monitoring/monitorctrl.pm index cfcef6aa7..3631e2d08 100644 --- a/xCAT-server-2.0/lib/xcat/monitoring/monitorctrl.pm +++ b/xCAT-server-2.0/lib/xcat/monitoring/monitorctrl.pm @@ -613,42 +613,15 @@ sub processNodelistTableChanges { if (@nodenames ==0) { return 0;} - my $hierarchy=getMonServerWithInfo(\@nodenames); - - #get all possible ip and hostname for the local host - my @hostinfo=xCAT::Utils->determinehostname(); - my %iphash=(); - foreach(@hostinfo) {$iphash{$_}=1;} - - foreach (keys(%$hierarchy)) { - my @server_pair=split(',', $_); - my $svname=$server_pair[0]; - my $mon_nodes=$hierarchy->{$_}; - if (($iphash{$svname}) || ($svname eq "noservicenode")) { #this is for ms - #call each plug-in to add the nodes into the monitoring domain - foreach(keys(%PRODUCT_LIST)) { - my $aRef=$PRODUCT_LIST{$_}; - my $module_name=$aRef->[1]; - #print "moduel_name=$module_name\n"; - if ($action eq "a") { ${$module_name."::"}{addNodes}->($mon_nodes);} - else { ${$module_name."::"}{removeNodes}->($mon_nodes);} } - } else { #this is for a service node - #call each service node to handle it - my @noderange=(); - foreach my $nodetemp (@$mon_nodes) { - push(@noderange, $nodetemp->[0]); - } - my $cmd; - if ($action eq "a") { $cmd="psh --nonodecheck $svname monaddnode --local " . join(',', @noderange); } - else { $cmd="psh --nonodecheck $svname monrmnode --local " . join(',', @noderange); } - #print "cmd=$cmd\n"; - my $result=`$cmd 2>&1`; - #print "result=$result\n"; - if ($?) { - xCAT::MsgUtils->message('S', "[mon]:$cmd result=$result\n"); - } - } + #call each plug-in to add the nodes into the monitoring domain + foreach(keys(%PRODUCT_LIST)) { + my $aRef=$PRODUCT_LIST{$_}; + my $module_name=$aRef->[1]; + #print "moduel_name=$module_name\n"; + if ($action eq "a") { ${$module_name."::"}{addNodes}->(\@nodenames, 1);} + else { ${$module_name."::"}{removeNodes}->(\@nodenames, 1);} } + return 0; } @@ -1177,7 +1150,7 @@ sub nodeStatMonName { } #-------------------------------------------------------------------------------- -=head3 pluginsAddNodes +=head3 addNodes This function informs all the local active monitoring plug-ins to add the given nodes to their monitoring domain. Arguments: @@ -1187,7 +1160,7 @@ sub nodeStatMonName { [return code, error message] as the values. =cut #-------------------------------------------------------------------------------- -sub pluginsAddNodes { +sub addNodes { my $noderef=shift; if ($noderef =~ /xCAT_monitoring::monitorctrl/) { $noderef=shift; @@ -1201,7 +1174,7 @@ sub pluginsAddNodes { foreach(keys(%PRODUCT_LIST)) { my $aRef=$PRODUCT_LIST{$_}; my $module_name=$aRef->[1]; - my @ret1=${$module_name."::"}{addNodes}->($noderef); + my @ret1=${$module_name."::"}{addNodes}->($noderef, 0); $ret{$_}=\@ret1; #for service node, the error may not be get shown, log it @@ -1213,7 +1186,7 @@ sub pluginsAddNodes { return %ret; } #-------------------------------------------------------------------------------- -=head3 pluginsRemoveNodes +=head3 removeNodes This function informs all the local active monitoring plug-ins to remove the given nodes to their monitoring domain. Arguments: @@ -1223,7 +1196,7 @@ sub pluginsAddNodes { [return code, error message] as the values. =cut #-------------------------------------------------------------------------------- -sub pluginsRemoveNodes { +sub removeNodes { my $noderef=shift; if ($noderef =~ /xCAT_monitoring::monitorctrl/) { $noderef=shift; @@ -1237,7 +1210,7 @@ sub pluginsRemoveNodes { foreach(keys(%PRODUCT_LIST)) { my $aRef=$PRODUCT_LIST{$_}; my $module_name=$aRef->[1]; - my @ret1=${$module_name."::"}{removeNodes}->($noderef); + my @ret1=${$module_name."::"}{removeNodes}->($noderef, 0); $ret{$_}=\@ret1; if (($ret1[0] >0)) { @@ -1248,166 +1221,6 @@ sub pluginsRemoveNodes { return %ret; } -#-------------------------------------------------------------------------------- -=head3 addNodes - This function informs all the active monitoring plug-ins to add the given - nodes to their monitoring domain. If the service node of the given nodes are - not the localhost, the request will be sent to the conresponding service nodes. - Arguments: - noderange a pointer to an array of node names - local 0 or 1, if set to 1, the nodes are only handled locally. No need - to find their service nodes. - Returns: - ret a hash with plug-in name as the keys and the an arry of - [return code, error message] as the values. -=cut -#-------------------------------------------------------------------------------- -sub addNodes { - my $p_input=shift; - if ($p_input =~ /xCAT_monitoring::monitorctrl/) { - $p_input=shift; - } - my $handle_local=shift; - - my %ret=(); - - - my @nodenames=@$p_input; - if (@nodenames == 0) { return %ret; } - #print "nodenames=@nodenames\n"; - - if ($handle_local) { - return pluginsAddNodes($p_input); - } - - my $isSV=xCAT::Utils->isServiceNode(); - my @hostinfo=xCAT::Utils->determinehostname(); - %iphash=(); - foreach(@hostinfo) {$iphash{$_}=1;} - - my $hierachy=xCAT_monitoring::monitorctrl->getMonServer(\@nodenames); - my @mon_servers=keys(%$hierachy); - - foreach (@mon_servers) { - #service node come in pairs, the first one is the monserver adapter that facing the mn, - # the second one is facing the cn. we use the first one here - my @server_pair=split(',', $_); - my $svname=$server_pair[0]; - my $mon_nodes=$hierachy->{$_}; - if ($iphash{$_}) { - #let all actvie modules to process it - my %ret1=pluginsAddNodes($mon_nodes); - my @ret2=(); - foreach(keys(%ret1)) { - push(@ret2, "$_ ".$ret1{$_}."\n"); - } - $ret{$svname}=\@ret2; - } elsif (!$isSV) { - if ($svname eq "noservicenode") { - my %ret1=pluginsAddNodes($mon_nodes); - my @ret2=(); - foreach(keys(%ret1)) { - push(@ret2, "$_ ".$ret1{$_}."\n"); - } - $ret{$svname}=\@ret2; - } else { - #forward them to the service nodes - my @noderange=(); - foreach my $nodetemp (@$mon_nodes) { - push(@noderange, $nodetemp->[0]); - } - my $cmd="psh --nonodecheck $svname monaddnode --local " . join(',', @noderange); - my $result=`$cmd 2>&1`; - #print "result=$result\n"; - if ($?) { - $ret{$svname}=[1, $result]; - } - } - } - } - - return %ret; -} - -#-------------------------------------------------------------------------------- -=head3 removeNodes - This function informs all the active monitoring plug-ins to remove the given - nodes to their monitoring domain. If the service node of the given nodes are - not the localhost, the request will be sent to the conresponding service nodes. - Arguments: - noderange a pointer to an array of node names - local 0 or 1, if set to 1, the nodes are only handled locally. No need - to find their service nodes. - Returns: - ret a hash with plug-in name as the keys and the an arry of - [return code, error message] as the values. -=cut -#-------------------------------------------------------------------------------- -sub removeNodes { - my $p_input=shift; - if ($p_input =~ /xCAT_monitoring::monitorctrl/) { - $p_input=shift; - } - my $handle_local=shift; - - my %ret=(); - - my @nodenames=@$p_input; - if (@nodenames == 0) { return %ret; } - #print "nodenames=@nodenames\n"; - - if ($handle_local) { - return pluginsRemoveNodes($p_input); - } - - - my $isSV=xCAT::Utils->isServiceNode(); - my @hostinfo=xCAT::Utils->determinehostname(); - %iphash=(); - foreach(@hostinfo) {$iphash{$_}=1;} - - my $hierachy=xCAT_monitoring::monitorctrl->getMonServer(\@nodenames); - my @mon_servers=keys(%$hierachy); - - foreach (@mon_servers) { - my @server_pair=split(',', $_); - my $svname=$server_pair[0]; - my $mon_nodes=$hierachy->{$_}; - if ($iphash{$_}) { - #let all actvie modules to process it - my %ret1=pluginsRemoveNodes($mon_nodes); - my @ret2=(); - foreach(keys(%ret1)) { - push(@ret2, "$_ ".$ret1{$_}."\n"); - } - $ret{$svname}=\@ret2; - } elsif (!$isSV) { - if ($svname eq "noservicenode") { - #let all actvie modules to process it - my %ret1=pluginsRemoveNodes($mon_nodes); - my @ret2=(); - foreach(keys(%ret1)) { - push(@ret2, "$_ ".$ret1{$_}."\n"); - } - $ret{$svname}=\@ret2; - } else { - #forward them to the service nodes - my @noderange=(); - foreach my $nodetemp (@$mon_nodes) { - push(@noderange, $nodetemp->[0]); - } - my $cmd="psh --nonodecheck $svname monrmnode --local " . join(',', @noderange); - my $result=`$cmd 2>&1`; - #print "result=$result\n"; - if ($?) { - $ret{$svname}=[1, $result]; - } - } - } - } - - return %ret; -} diff --git a/xCAT-server-2.0/lib/xcat/monitoring/samples/templatemon.pm b/xCAT-server-2.0/lib/xcat/monitoring/samples/templatemon.pm index 0f6832169..3beb64d28 100644 --- a/xCAT-server-2.0/lib/xcat/monitoring/samples/templatemon.pm +++ b/xCAT-server-2.0/lib/xcat/monitoring/samples/templatemon.pm @@ -155,9 +155,11 @@ sub stopNodeStatusMon { This function is called by the monitorctrl module when new nodes are added to the xCAT cluster. It should add the nodes into the product for monitoring. Arguments: - nodes --nodes to be added. It is a pointer to an array with each element - being a ref to an array of [nodes, nodetype, status]. For example: - [['node1', 'osi', 'active'], ['node2', 'switch', 'booting']..] + nodes --nodes to be added. It is a pointer to an array. If the next argument is + 1, each element is a ref to an array of [nodes, nodetype, status]. For example: + [['node1', 'active'], ['node2', 'booting']..]. + if the next argument is 0, each element is a node name to be added. + boolean -- 1, or 0. Returns: (error code, error message) =cut @@ -169,11 +171,16 @@ sub addNodes { } #demo how you can parse the input. you may commnet it out. - - foreach(@$noderef) { - my $node_info=$_; - print " node=$node_info->[0], nodetype=$node_info->[1], status=$node_info->[2]\n"; + my $info=shift; + if ($info) { + foreach(@$noderef) { + my $node_info=$_; + print " node=$node_info->[0], status=$node_info->[1]\n"; + } + } else { + print "noderef=@$noderef\n"; } + #TODO: include the nodes into the product for monitoring. return (0, "0k"); @@ -184,9 +191,11 @@ sub addNodes { This function is called by the monitorctrl module when nodes are removed from the xCAT cluster. It should remove the nodes from the product for monitoring. Arguments: - nodes --nodes to be removed. It is a pointer to an array with each element - being a ref to an array of [nodes, nodetype, status]. For example: - [['node1', 'osi', 'active'], ['node2', 'switch', 'booting']..] + nodes --nodes to be added. It is a pointer to an array. If the next argument is + 1, each element is a ref to an array of [nodes, nodetype, status]. For example: + [['node1', 'active'], ['node2', 'booting']..]. + if the next argument is 0, each element is a node name to be added. + boolean -- 1, or 0. Returns: (error code, error message) =cut @@ -198,9 +207,14 @@ sub removeNodes { } #demo how you can parse the input. you may commnet it out. - foreach(@$noderef) { - my $node_info=$_; - print " node=$node_info->[0], nodetype=$node_info->[1], status=$node_info->[2]\n"; + my $info=shift; + if ($info) { + foreach(@$noderef) { + my $node_info=$_; + print " node=$node_info->[0], status=$node_info->[1]\n"; + } + } else { + print "noderef=@$noderef\n"; } diff --git a/xCAT-server-2.0/lib/xcat/monitoring/snmpmon.pm b/xCAT-server-2.0/lib/xcat/monitoring/snmpmon.pm index a7852d22c..3d23ea511 100644 --- a/xCAT-server-2.0/lib/xcat/monitoring/snmpmon.pm +++ b/xCAT-server-2.0/lib/xcat/monitoring/snmpmon.pm @@ -529,24 +529,30 @@ sub stopNodeStatusMon { =head3 addNodes This function adds the nodes into the SNMP domain. Arguments: - nodes --nodes to be added. It is a pointer to an array with each element - being a ref to an array of [nodes, nodetype, status]. For example: - [['node1', 'osi', 'active'], ['node2', 'switch', 'booting']..] + nodes --nodes to be added. It is a pointer to an array. If the next argument is + 1, each element is a ref to an array of [nodes, nodetype, status]. For example: + [['node1', 'active'], ['node2', 'booting']..]. + if the next argument is 0, each element is a node name to be added. + boolean -- 1, or 0. Returns: (error code, error message) =cut #-------------------------------------------------------------------------------- sub addNodes { - #print "snmpmon::addNodes\n"; - $noderef=shift; - if ($noderef =~ /xCAT_monitoring::snmpmon/) { - $noderef=shift; - } - - foreach(@$noderef) { - my $node_info=$_; - print " node=$node_info->[0], nodetype=$node_info->[1], status=$node_info->[2]\n"; - } +# print "snmpmon::addNodes\n"; +# $noderef=shift; +# if ($noderef =~ /xCAT_monitoring::snmpmon/) { +# $noderef=shift; +# } +# my $info=shift; +# if ($info) { +# foreach(@$noderef) { +# my $node_info=$_; +# print " node=$node_info->[0], status=$node_info->[1]\n"; +# } +# } else { +# print "noderef=@$noderef\n"; +# } return (0, "ok"); } @@ -555,24 +561,30 @@ sub addNodes { =head3 removeNodes This function removes the nodes from the SNMP domain. Arguments: - nodes --nodes to be removed. It is a pointer to an array with each element - being a ref to an array of [nodes, nodetype, status]. For example: - [['node1', 'osi', 'active'], ['node2', 'switch', 'booting']..] + nodes --nodes to be added. It is a pointer to an array. If the next argument is + 1, each element is a ref to an array of [nodes, nodetype, status]. For example: + [['node1', 'active'], ['node2', 'booting']..]. + if the next argument is 0, each element is a node name to be added. + boolean -- 1, or 0. Returns: (error code, error message) =cut #-------------------------------------------------------------------------------- sub removeNodes { - print "snmpmon::removeNodes\n"; - $noderef=shift; - if ($noderef =~ /xCAT_monitoring::snmpmon/) { - $noderef=shift; - } - - foreach(@$noderef) { - my $node_info=$_; - print " node=$node_info->[0], nodetype=$node_info->[1], status=$node_info->[2]\n"; - } +# print "snmpmon::removeNodes\n"; +# $noderef=shift; +# if ($noderef =~ /xCAT_monitoring::snmpmon/) { +# $noderef=shift; +# } +# my $info=shift; +# if ($info) { +# foreach(@$noderef) { +# my $node_info=$_; +# print " node=$node_info->[0], status=$node_info->[1]\n"; +# } +# } else { +# print "noderef=@$noderef\n"; +# } return (0, "ok"); } diff --git a/xCAT-server-2.0/lib/xcat/monitoring/xcatmon.pm b/xCAT-server-2.0/lib/xcat/monitoring/xcatmon.pm index bf988ed3e..5602ae676 100644 --- a/xCAT-server-2.0/lib/xcat/monitoring/xcatmon.pm +++ b/xCAT-server-2.0/lib/xcat/monitoring/xcatmon.pm @@ -166,9 +166,11 @@ sub stopNodeStatusMon { This function is called by the monitorctrl module when new nodes are added to the xCAT cluster. It should add the nodes into the product for monitoring. Arguments: - nodes --nodes to be added. It is a pointer to an array with each element - being a ref to an array of [nodes, nodetype, status]. For example: - [['node1', 'osi', 'active'], ['node2', 'switch', 'booting']..] + nodes --nodes to be added. It is a pointer to an array. If the next argument is + 1, each element is a ref to an array of [nodes, nodetype, status]. For example: + [['node1', 'active'], ['node2', 'booting']..]. + if the next argument is 0, each element is a node name to be added. + boolean -- 1, or 0. Returns: (error code, error message) =cut @@ -185,9 +187,11 @@ sub addNodes { This function is called by the monitorctrl module when nodes are removed from the xCAT cluster. It should remove the nodes from the product for monitoring. Arguments: - nodes --nodes to be removed. It is a pointer to an array with each element - being a ref to an array of [nodes, nodetype, status]. For example: - [['node1', 'osi', 'active'], ['node2', 'switch', 'booting']..] + nodes --nodes to be added. It is a pointer to an array. If the next argument is + 1, each element is a ref to an array of [nodes, nodetype, status]. For example: + [['node1', 'active'], ['node2', 'booting']..]. + if the next argument is 0, each element is a node name to be added. + boolean -- 1, or 0. Returns: (error code, error message) =cut