You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vcl.apache.org by ar...@apache.org on 2010/11/24 15:47:50 UTC

svn commit: r1038632 - in /incubator/vcl/trunk/managementnode/lib/VCL: Module.pm Module/OS/Linux.pm Module/OS/Windows.pm Module/State.pm utils.pm

Author: arkurth
Date: Wed Nov 24 14:47:49 2010
New Revision: 1038632

URL: http://svn.apache.org/viewvc?rev=1038632&view=rev
Log:
VCL-413
Added subroutines to Module.pm: create_mn_os_object, mn_os, set_mn_os.  Added code to State.pm::initialize to create a management node OS object.  This allows for an OS object to be created representing the management node's OS, allowing the Linux code to be used to perform operations on the management node.  This should reduce duplicated code.  Other modules created can access the management node OS object via $self->mn_os.

Other
Added utils.pm::get_file_size_info_string which accepts a byte integer argument and returns a formatted string displaying the file size in bytes, MB, and GB.

Fixed bug in utils.pm::string_to_ascii if the string argument is 0.  It had been returning an empty string instead of 0.

Fixed bug in Windows.pm::reg_query.  It was adding extra spaces to key names.

Modified:
    incubator/vcl/trunk/managementnode/lib/VCL/Module.pm
    incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm
    incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm
    incubator/vcl/trunk/managementnode/lib/VCL/Module/State.pm
    incubator/vcl/trunk/managementnode/lib/VCL/utils.pm

Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module.pm
URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module.pm?rev=1038632&r1=1038631&r2=1038632&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module.pm Wed Nov 24 14:47:49 2010
@@ -282,6 +282,68 @@ sub create_os_object {
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 create_mn_os_object
+
+ Parameters  : None
+ Returns     : boolean
+ Description : Creates a management node OS object if one has not already been
+               created for the calling object.
+
+=cut
+
+sub create_mn_os_object {
+	my $self = shift;
+	unless (ref($self) && $self->isa('VCL::Module')) {
+		notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it must be called as a class method");
+		return;
+	}
+	
+	# Make sure calling object isn't an OS module to avoid an infinite loop
+	if ($self->isa('VCL::Module::OS')) {
+		notify($ERRORS{'WARNING'}, 0, "this subroutine cannot be called from an existing OS module");
+		return;
+	}
+	
+	# Check if an OS object has already been stored in the calling object
+	if ($self->{mn_os}) {
+		my $address = sprintf('%x', $self->{mn_os});
+		notify($ERRORS{'DEBUG'}, 0, "management node OS object has already been created, address: $address, returning 1");
+		return 1;
+	}
+	
+	my $request_data = $self->data->get_request_data();
+	my $reservation_id = $self->data->get_reservation_id();
+	
+	# Create a DataStructure object containing computer data for the management node
+	my $mn_data;
+	eval {
+		$mn_data = new VCL::DataStructure();
+	};
+	
+	# Attempt to load the OS module
+	my $mn_os_perl_package = 'VCL::Module::OS::Linux::ManagementNode';
+	eval "use $mn_os_perl_package";
+	if ($EVAL_ERROR) {
+		notify($ERRORS{'WARNING'}, 0, "$mn_os_perl_package module could not be loaded, returning 0");
+		return 0;
+	}
+	notify($ERRORS{'DEBUG'}, 0, "$mn_os_perl_package module loaded");
+	
+	# Attempt to create the object
+	if (my $mn_os = ($mn_os_perl_package)->new({data_structure => $mn_data})) {
+		my $address = sprintf('%x', $mn_os);
+		notify($ERRORS{'OK'}, 0, "$mn_os_perl_package OS object created, address: $address");
+		$self->set_mn_os($mn_os);
+		return 1;
+	}
+	else {
+		notify($ERRORS{'WARNING'}, 0, "failed to create management node OS object");
+		return;
+	}
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
 =head2 create_provisioning_object
 
  Parameters  : None
@@ -346,8 +408,7 @@ sub create_provisioning_object {
 
  Parameters  : None
  Returns     : Process's OS object
- Description : Allows provisioning modules to access the reservation's OS
-               object.
+ Description : Allows modules to access the reservation's OS object.
 
 =cut
 
@@ -365,6 +426,28 @@ sub os {
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 mn_os
+
+ Parameters  : None
+ Returns     : Management node's OS object
+ Description : Allows modules to access the management node's OS object.
+
+=cut
+
+sub mn_os {
+	my $self = shift;
+	
+	if (!$self->{mn_os}) {
+		notify($ERRORS{'WARNING'}, 0, "unable to return management node OS object, \$self->{mn_os} is not set");
+		return;
+	}
+	else {
+		return $self->{mn_os};
+	}
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
 =head2 provisioner
 
  Parameters  : None
@@ -391,7 +474,7 @@ sub provisioner {
 =head2 set_os
 
  Parameters  : None
- Returns     : Process's OS object
+ Returns     : 
  Description : Sets the OS object for the module to access.
 
 =cut
@@ -404,6 +487,22 @@ sub set_os {
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 set_mn_os
+
+ Parameters  : None
+ Returns     : 
+ Description : Sets the management node OS object for the module to access.
+
+=cut
+
+sub set_mn_os {
+	my $self = shift;
+	my $mn_os = shift;
+	$self->{mn_os} = $mn_os;
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
 =head2 set_provisioner
 
  Parameters  : None

Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm
URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm?rev=1038632&r1=1038631&r2=1038632&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm Wed Nov 24 14:47:49 2010
@@ -1676,7 +1676,7 @@ sub get_available_space {
 	my $mb_available = format_number(($bytes_available / 1024 / 1024), 2);
 	my $gb_available = format_number(($bytes_available / 1024 / 1024 / 1024), 1);
 	
-	notify($ERRORS{'DEBUG'}, 0, "bytes available in '$path' on $computer_short_name: " . format_number($bytes_available) . " bytes ($mb_available MB, $gb_available GB)");
+	notify($ERRORS{'DEBUG'}, 0, "space available on volume on $computer_short_name containing '$path': " . get_file_size_info_string($bytes_available));
 	return $bytes_available;
 }
 
@@ -1745,7 +1745,7 @@ sub get_total_space {
 	my $mb_total = format_number(($bytes_total / 1024 / 1024), 2);
 	my $gb_total = format_number(($bytes_total / 1024 / 1024 / 1024), 1);
 	
-	notify($ERRORS{'DEBUG'}, 0, "total bytes of volume where '$path' resides on $computer_short_name: " . format_number($bytes_total) . " bytes ($mb_total MB, $gb_total GB)");
+	notify($ERRORS{'DEBUG'}, 0, "total size of volume on $computer_short_name containing '$path': " . get_file_size_info_string($bytes_total));
 	return $bytes_total;
 }
 

Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm
URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm?rev=1038632&r1=1038631&r2=1038632&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm Wed Nov 24 14:47:49 2010
@@ -2448,13 +2448,18 @@ sub reg_query {
 		return;
 	}
 	
-	#notify($ERRORS{'DEBUG'}, 0, "reg.exe QUERY output:\n" . join("\n", @$output));
+	notify($ERRORS{'DEBUG'}, 0, "reg.exe QUERY output:\n" . join("\n", @$output));
 	
 	# If value argument was specified, parse and return the data
 	if (defined($value_argument)) {
 		# Find the line containing the value information and parse it
-		my ($value, $type, $data) = map { $_ =~ /^\s*([^\t]+)\s*(REG_\w+)\s*(.*)/ } @$output;
-		$value = '(Default)' if $value eq '<NO NAME>';
+		my ($value, $type, $data) = map { $_ =~ /^\s*(.*)\s+(REG_\w+)\s+(.*)/ } @$output;
+		$value =~ s/(^\s+|\s+$)//g;
+		$type =~ s/(^\s+|\s+$)//g;
+		$data =~ s/(^\s+|\s+$)//g;
+		
+		$value = '(Default)' if $value =~ /NO NAME/;
+		
 		if ($type && defined($data)) {
 			$data = $self->reg_query_convert_data($type, $data);
 			notify($ERRORS{'DEBUG'}, 0, "retrieved registry data:\nkey: '$key_argument'\nvalue: '$value'\ntype: $type\ndata: '$data'");
@@ -2471,16 +2476,27 @@ sub reg_query {
 		
 		my $key;
 		for my $line (@$output) {
+			
 			if ($line =~ /^HKEY/) {
 				$key = $line;
 				$registry_hash{$key} = {};
 				next;
 			}
-			elsif ($line =~ /^\s*([^\t]+)\s*(REG_\w+)\s*(.*)/) {
+			elsif ($line =~ /^\s*(.*)\s+(REG_\w+)\s+(.*)/) {
 				my ($value, $type, $data) = ($1, $2, $3);
-				$value = '(Default)' if $value eq '<NO NAME>';
+				$value =~ s/(^\s+|\s+$)//g;
+				$type =~ s/(^\s+|\s+$)//g;
+				$data =~ s/(^\s+|\s+$)//g;
+				
+				$value = '(Default)' if $value =~ /NO NAME/;
+				
 				$data = $self->reg_query_convert_data($type, $data);
 				
+				#notify($ERRORS{'DEBUG'}, 0, "line: " . string_to_ascii($line) . "\n" .
+						 #"value: " . string_to_ascii($value) . "\n" .
+						 #"data: " . string_to_ascii($data)
+						 #);
+				
 				#$registry_hash{$key}{$value}{type} = $type;
 				$registry_hash{$key}{$value} = $data;
 			}
@@ -10123,14 +10139,14 @@ sub fix_default_profile {
 		return;
 	}
 	notify($ERRORS{'DEBUG'}, 0, "determined default profile path from the registry on $computer_node_name: '$default_profile_path'");
-
+	
 	# Load the default profile hive file into the registry
 	my $hive_file_path = "$default_profile_path\\ntuser.dat";
 	if (!$self->reg_load($root_key, $hive_file_path)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to load the default profile hive into the registry on $computer_node_name");
 		return;
 	}
-return;
+	
 	# Fix registry values known to cause problems
 	# The "Shell Folders" key may contain paths pointing to a specific user's profile
 	# Any paths under "Shell Folders" can be deleted

Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/State.pm
URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/State.pm?rev=1038632&r1=1038631&r2=1038632&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/State.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/State.pm Wed Nov 24 14:47:49 2010
@@ -111,6 +111,12 @@ sub initialize {
 		return;
 	}
 	
+	# Create a management node OS object
+	if (!$self->create_mn_os_object()) {
+		notify($ERRORS{'WARNING'}, 0, "failed to create management node OS object");
+		return;
+	}
+	
 	# Create a provisioning object
 	if (!$self->create_provisioning_object()) {
 		notify($ERRORS{'WARNING'}, 0, "failed to create provisioning object");
@@ -121,6 +127,10 @@ sub initialize {
 	$self->{provisioner}->set_os($self->{os});
 	$self->{os}->set_provisioner($self->{provisioner});
 	
+	# Allow the provisioning and OS objects to access the management node OS object
+	$self->{provisioner}->set_mn_os($self->{mn_os});
+	$self->{os}->set_mn_os($self->{mn_os});
+	
 	notify($ERRORS{'DEBUG'}, 0, "returning 1");
 	return 1;
 

Modified: incubator/vcl/trunk/managementnode/lib/VCL/utils.pm
URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=1038632&r1=1038631&r2=1038632&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/utils.pm Wed Nov 24 14:47:49 2010
@@ -118,6 +118,7 @@ our @EXPORT = qw(
   get_current_file_name
   get_current_package_name
   get_current_subroutine_name
+  get_file_size_info_string
   get_group_name
   get_highest_imagerevision_info
   get_image_info
@@ -606,7 +607,7 @@ sub notify {
 	
 	# Get info about the subroutine which called this subroutine
 	my ($package, $filename, $line, $sub) = caller(0);
-
+	
 	# Assemble the caller information
 	my $caller_info;
 	if (caller(1)) {
@@ -6372,7 +6373,7 @@ sub get_request_by_computerid {
 
 	# Check to make sure 1 row was returned
 	if (scalar @selected_rows == 0) {
-		notify($ERRORS{'WARNING'}, 0, "zero rows were returned from database select $computer_id");
+		notify($ERRORS{'OK'}, 0, "zero rows were returned from database select $computer_id");
 		return ();
 	}
 
@@ -9082,7 +9083,12 @@ sub string_to_ascii {
 		}
 	}
 	
-	return $ascii_value_string || '';
+	if (defined($ascii_value_string)) {
+		return $ascii_value_string;
+	}
+	else {
+		return '';
+	}
 }
 
 #/////////////////////////////////////////////////////////////////////////////
@@ -9769,6 +9775,30 @@ sub format_number {
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 get_file_size_info_string
+
+ Parameters  : $bytes
+ Returns     : string
+ Description : 
+
+=cut
+
+sub get_file_size_info_string {
+	my ($size_bytes, $separator) = @_;
+	$separator = ", " if !$separator;
+	
+	my $size_mb = format_number(($size_bytes / 1024 / 1024), 1);
+	my $size_gb = format_number(($size_bytes / 1024 / 1024 / 1024), 2);
+	
+	my $size_info;
+	$size_info .= format_number($size_bytes) . " bytes$separator";
+	$size_info .= "$size_mb MB$separator";
+	$size_info .=  "$size_gb GB";
+	return $size_info;
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
 =head2 create_management_node_directory
 
  Parameters  : $directory_path