You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vcl.apache.org by fa...@apache.org on 2009/07/15 21:15:34 UTC
svn commit: r794372 - in /incubator/vcl/trunk/managementnode:
bin/health_check.pl lib/VCL/healthcheck.pm
Author: fapeeler
Date: Wed Jul 15 19:15:34 2009
New Revision: 794372
URL: http://svn.apache.org/viewvc?rev=794372&view=rev
Log:
VCL-169
start of stage1 shutdown functionality, based on the machine type and
state
if machine is of blade type and state= available,failed,maintenance
healthcheck will proceed to shutdown blade using the xcat provisioning
module power_off routine
Modified:
incubator/vcl/trunk/managementnode/bin/health_check.pl
incubator/vcl/trunk/managementnode/lib/VCL/healthcheck.pm
Modified: incubator/vcl/trunk/managementnode/bin/health_check.pl
URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/bin/health_check.pl?rev=794372&r1=794371&r2=794372&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/bin/health_check.pl (original)
+++ incubator/vcl/trunk/managementnode/bin/health_check.pl Wed Jul 15 19:15:34 2009
@@ -55,7 +55,41 @@
use VCL::utils;
use VCL::healthcheck;
+use Getopt::Long;
+#------- Subroutine declarations -------
+sub main();
+sub help();
+sub print_usage();
+
+#----------GLOBALS--------------
+# Store the command line options in this hash
+our %OPTIONS;
+
+our $STAGE = 0;
+our $HELP = 0;
+
+
+GetOptions(\%OPTIONS, 'help', 'powerdown=s');
+
+
+# Get the remaining command line parameters
+$HELP = $OPTIONS{help} if (defined($OPTIONS{help} && $OPTIONS{help}));
+$STAGE = $OPTIONS{powerdown} if (defined($OPTIONS{powerdown} && $OPTIONS{powerdown}));
+
+if($STAGE){
+
+ unless($STAGE =~ /available|all/){
+ print "\nInvalid powerdown option\n\n";
+ help();
+ exit;
+ }
+
+}
+if($HELP){
+ help();
+ exit;
+}
##############################################################################
# now just do basic monitoring
@@ -68,21 +102,65 @@
=cut
-#----------GLOBALS--------------
-
-#------- Subroutine declarations -------
-sub main();
main();
sub main() {
my $check = new VCL::healthcheck();
- $check->process;
+ $check->process($STAGE);
#$check->send_report;
}
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 print_usage
+
+ Parameters :
+ Returns :
+ Description :
+
+=cut
+
+sub print_usage() {
+
+ my $text = sprintf(" %s \n", "Usage: healthcheck.pl [options]" );
+ $text .= sprintf(" %s \n"," ");
+ $text .= sprintf(" %s \n", "healthcheck.pl : without options scans nodes and" );
+ $text .= sprintf(" %s \n", "resets data in database if needed" );
+ $text .= sprintf(" %s \n"," ");
+ $text .= sprintf(" %s \n","Valid options:");
+ $text .= sprintf(" %s \n"," ");
+ $text .= sprintf(" %s \n","-powerdown=ARG : A power down argument can be one of");
+ $text .= sprintf(" %s \n","available shutdown available or idle blades");
+ $text .= sprintf(" %s \n","all shutdown all nodes, notify users of pending shutdown");
+
+ print "$text\n";
+
+} ## end sub help
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 help
+
+ Parameters :
+ Returns :
+ Description :
+
+=cut
+sub help() {
+ my $message = <<"END";
+--------------------------------------------
+
+health_check.pl is intented to as a cmdline script or via cron
+
+END
+
+ print $message;
+ print_usage();
+ exit;
+} ## end sub help
#/////////////////////////////////////////////////////////////////////////////
1;
Modified: incubator/vcl/trunk/managementnode/lib/VCL/healthcheck.pm
URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/healthcheck.pm?rev=794372&r1=794371&r2=794372&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/healthcheck.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/healthcheck.pm Wed Jul 15 19:15:34 2009
@@ -148,10 +148,21 @@
=cut
sub process {
- my ($info) = @_;
+ my ($info, $powerdownstage) = @_;
notify($ERRORS{'OK'}, $LOG, "in processing routine");
$info->{"globalmsg"}->{"body"} = "Summary of VCL node monitoring system:\n\n";
+ if($powerdownstage =~ /^(available|all)$/){
+ my $mn_hostname = $info->{managementnode}->{hostname};
+ notify($ERRORS{'OK'}, $LOG, "ALERT: powerdown stage triggered,placing MN $mn_hostname in maintenance");
+ if (set_managementnode_state($info->{managementnode}, "maintenance")) {
+ notify($ERRORS{'OK'}, $LOG, "Successfully set $mn_hostname into maintenance");
+ }
+ else{
+ notify($ERRORS{'WARNING'}, $LOG, "Failed to set $mn_hostname into maintenance");
+ }
+ }
+
foreach my $cid (keys %{$info->{computertable}}) {
#set some local variables
my $comp_hostname = $info->{computertable}->{$cid}->{computer}->{hostname};
@@ -180,6 +191,7 @@
# Collect current state of node - it could have changed since we started
if (my $comp_current_state = get_computer_current_state_name($cid)) {
+ $info->{computertable}->{$cid}->{computer}->{state}->{name} = $comp_current_state;
$comp_state = $comp_current_state;
}
else {
@@ -187,6 +199,21 @@
notify($ERRORS{'OK'}, $LOG, "could not retrieve current computer state cid= $cid, using old data");
}
+ #check for powerdownstages
+ if($powerdownstage =~ /^(available|all)$/){
+ $info->{computertable}->{$cid}->{"powerdownstage"} = $powerdownstage;
+ if(powerdown_event($info->{computertable}->{$cid})){
+ notify($ERRORS{'OK'}, $LOG, "Successfully powered down $comp_hostname");
+ }
+ else {
+ #notify($ERRORS{'OK'}, $LOG, "Could not powerdown $comp_hostname");
+ }
+ next;
+ }
+ else {
+ #proceed as normal
+ }
+
#Only preform actions on these available or failed computer states
#skip if is inuse, maintenance, tovmhost, etc.
if ($comp_state !~ /available|failed/) {
@@ -358,6 +385,63 @@
#////////////////////////////////////////////////////////////////////////////////
+=head2 powerdown_event
+
+ Parameters : hash
+ Returns : 1,0
+ Description :
+
+=cut
+
+sub powerdown_event {
+ my ($self) = @_;
+
+ my $management_node_keys = $self->{managementnode}->{keys};
+ my $computer_host_name = $self->{computer}->{hostname};
+ my $computer_short_name = 0;
+ my $computer_ip_address = $self->{computer}->{IPaddress};
+ my $image_os_name = $self->{image}->{OS}->{name};
+ my $image_name = $self->{imagerevision}->{imagename};
+ my $image_os_type = $self->{image}->{OS}->{type};
+ my $provisioning_perl_package = $self->{computer}->{provisioning}->{module}->{perlpackage};
+ my $comp_type = $self->{computer}->{type};
+ my $comp_state = $self->{computer}->{state}->{name};
+ my $computer_node_name = $self->{computer}->{hostname};
+ my $power_down_stage = $self->{powerdownstage};
+
+ $computer_short_name = $1 if ($computer_node_name =~ /([-_a-zA-Z0-9]*)(\.?)/);
+
+ #If blade or vm and available|failed|maintenance - simply power-off
+ #If blade and vmhostinuse - check vms, if available power-down all
+
+ if(($comp_type =~ /blade/) && ($comp_state =~ /^(available|failed|maintenance)/)){
+ notify($ERRORS{'OK'}, $LOG, "calling provision module $provisioning_perl_package power_off routine $computer_short_name");
+
+ eval "use $provisioning_perl_package";
+ if ($EVAL_ERROR) {
+ notify($ERRORS{'WARNING'}, $LOG, "$provisioning_perl_package module could not be loaded");
+ notify($ERRORS{'OK'}, $LOG, "returning 0");
+ return 0;
+ }
+ my $power_off_status = eval "&$provisioning_perl_package" . '::power_off($computer_short_name);';
+ notify($ERRORS{'OK'}, $LOG, "$power_off_status ");
+ if($power_off_status){
+ notify($ERRORS{'OK'}, $LOG, "SUCCESS powered_off $computer_short_name");
+ return 1;
+ }
+ return 0;
+ }
+ else{
+ notify($ERRORS{'OK'}, $LOG, "SKIPPING $computer_short_name comp_type= $comp_type in comp_state= $comp_state");
+ return 0;
+ }
+
+
+
+}
+
+#////////////////////////////////////////////////////////////////////////////////
+
=head2 virtualmachine_investigator
Parameters : hash