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 2013/06/13 16:40:45 UTC

svn commit: r1492689 - in /vcl/trunk/managementnode/lib/VCL: Module.pm Module/OS.pm Module/State.pm inuse.pm new.pm reserved.pm utils.pm

Author: arkurth
Date: Thu Jun 13 14:40:45 2013
New Revision: 1492689

URL: http://svn.apache.org/r1492689
Log:
VCL-678
Removed and/or commented out several unnecessary notify messages in Module.pm to reduce vcld.log output.

VCL-707
Changed how vcld.log lines are deliminated. All fields are now separated by a pipe character. If a field is blank, a pipe character is added. This allows output to be pasted into a spreadsheet and text to columns results in the fields in the correct column for all lines.

VCL-16
Moved initial user connection check from reserved.pm to inuse.pm. This removed duplicate code.

Updated reserved.pm so that the parent reservation waits for all child reservations' reserved processes to terminate before changing the request state to inuse. This fixes a problem where the state would change before the child's reserved process ended. The child's inuse process would fail to launch because vcld detected the other process still running.

Moved user connection check loop from OS.pm::is_user_connected to inuse.pm. Updated inuse.pm to update reservation.lastcheck for all reservations in a cluster when a user connection is detected. While looping waiting for a connection, the current reservation.lastcheck is retrieved from the database. If it changed it means some other reservation in the cluster detected a connection and the loop terminates. 

Reworked and simplified much of inuse.pm::process. It was still using goto calls.

Modified:
    vcl/trunk/managementnode/lib/VCL/Module.pm
    vcl/trunk/managementnode/lib/VCL/Module/OS.pm
    vcl/trunk/managementnode/lib/VCL/Module/State.pm
    vcl/trunk/managementnode/lib/VCL/inuse.pm
    vcl/trunk/managementnode/lib/VCL/new.pm
    vcl/trunk/managementnode/lib/VCL/reserved.pm
    vcl/trunk/managementnode/lib/VCL/utils.pm

Modified: vcl/trunk/managementnode/lib/VCL/Module.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module.pm?rev=1492689&r1=1492688&r2=1492689&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module.pm Thu Jun 13 14:40:45 2013
@@ -169,16 +169,14 @@ sub new {
 		next if ($arg_key eq 'data_structure');
 		
 		$self->{$arg_key} = $args->{$arg_key};
-		notify($ERRORS{'DEBUG'}, 0, "set '$arg_key' key for $class object from arguments");
+		#notify($ERRORS{'DEBUG'}, 0, "set '$arg_key' key for $class object from arguments");
 	}
 
 	# Bless the object as the class which new was called with
-	notify($ERRORS{'DEBUG'}, 0, "blessing new $class object");
 	bless $self, $class;
 	
 	# Get the memory address of this newly created object - useful for debugging object creation problems
 	my $address = sprintf('%x', $self);
-	notify($ERRORS{'DEBUG'}, 0, "blessed new $class object, address: $address");
 	
 	# Display a message based on the type of object created
 	if ($self->isa('VCL::Module::State')) {
@@ -281,7 +279,7 @@ sub create_os_object {
 	
 	if ($os) {
 		my $os_address = sprintf('%x', $os);
-		notify($ERRORS{'OK'}, 0, "$os_perl_package OS object created, address: $os_address");
+		notify($ERRORS{'DEBUG'}, 0, "$os_perl_package OS object created, address: $os_address");
 		return $os;
 	}
 	else {
@@ -340,7 +338,7 @@ sub create_mn_os_object {
 	# 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");
+		notify($ERRORS{'DEBUG'}, 0, "$mn_os_perl_package OS object created, address: $address");
 		
 		# Allow $mn_os->data to access $mn_os
 		$mn_data->set_mn_os($mn_os);
@@ -435,8 +433,7 @@ sub create_vmhost_os_object {
 	
 	if ($vmhost_os) {
 		my $address = sprintf('%x', $vmhost_os);
-		notify($ERRORS{'OK'}, 0, "$vmhost_os_perl_package OS object created, address: $address");
-		$self->set_vmhost_os($vmhost_os);
+		notify($ERRORS{'DEBUG'}, 0, "$vmhost_os_perl_package OS object created, address: $address");
 		return $vmhost_os;
 	}
 	else {
@@ -502,7 +499,7 @@ sub create_provisioning_object {
 	if ($provisioner) {
 		my $provisioner_address = sprintf('%x', $provisioner);
 		my $provisioner_computer_name = $provisioner->data->get_computer_short_name();
-		notify($ERRORS{'OK'}, 0, "$provisioning_perl_package provisioning object created for $provisioner_computer_name, address: $provisioner_address");
+		notify($ERRORS{'DEBUG'}, 0, "$provisioning_perl_package provisioning object created for $provisioner_computer_name, address: $provisioner_address");
 		return $provisioner;
 	}
 	else {
@@ -803,6 +800,13 @@ sub set_vmhost_os {
 	my $vmhost_os_address = sprintf('%x', $vmhost_os);
 	notify($ERRORS{'DEBUG'}, 0, "storing reference to VM host OS object (address: $vmhost_os_address) in this $type object (address: $address)");
 	$self->{vmhost_os} = $vmhost_os;
+	
+	
+	#my $address = sprintf('%x', $self);
+	#my $vmhost_os_address = sprintf('%x', $vmhost_os);
+	#my $type = ref($self);
+	#notify($ERRORS{'DEBUG'}, 0, "storing reference to VM host OS object (address: $vmhost_os_address) in this $type object (address: $address)");
+	#$self->{vmhost_os} = $vmhost_os;
 }
 
 #/////////////////////////////////////////////////////////////////////////////
@@ -1053,8 +1057,11 @@ sub code_loop_timeout {
 		my $seconds_remaining = ($end_time > $current_time) ? ($end_time - $current_time) : 0;
 		my $sleep_seconds = ($seconds_remaining < $attempt_delay_seconds) ? $seconds_remaining : $attempt_delay_seconds;
 		
-		if (!$message_interval_seconds || ($attempt == 1 || ($seconds_remaining <= $attempt_delay_seconds) || ($seconds_elapsed % $message_interval_seconds) < $attempt_delay_seconds)) {
-			notify($ERRORS{'DEBUG'}, 0, "attempt $attempt: $message ($seconds_elapsed/$seconds_remaining elapsed/remaining seconds), sleeping for $sleep_seconds seconds");
+		if (!$message_interval_seconds) {
+			notify($ERRORS{'OK'}, 0, "attempt $attempt: $message ($seconds_elapsed/$seconds_remaining elapsed/remaining seconds), sleeping for $sleep_seconds seconds");
+		}
+		elsif ($attempt == 1 || ($seconds_remaining <= $attempt_delay_seconds) || ($seconds_elapsed % $message_interval_seconds) < $attempt_delay_seconds) {
+			notify($ERRORS{'OK'}, 0, "attempt $attempt: $message ($seconds_elapsed/$seconds_remaining elapsed/remaining seconds)");
 		}
 		
 		if (!$sleep_seconds) {

Modified: vcl/trunk/managementnode/lib/VCL/Module/OS.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS.pm?rev=1492689&r1=1492688&r2=1492689&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS.pm Thu Jun 13 14:40:45 2013
@@ -754,7 +754,6 @@ sub wait_for_response {
 	}
 	
 	# Wait for SSH to respond, loop until timeout is reached
-	notify($ERRORS{'OK'}, 0, "waiting for $computer_node_name to respond to SSH, maximum of $ssh_response_timeout_seconds seconds");
 	if (!$self->wait_for_ssh($ssh_response_timeout_seconds, $ssh_attempt_delay_seconds)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to connect to $computer_node_name via SSH after $ssh_response_timeout_seconds seconds");
 		return;
@@ -2092,7 +2091,7 @@ sub execute {
 	# Check the argument type
 	if (ref($argument)) {
 		if (ref($argument) eq 'HASH') {
-			#notify($ERRORS{'DEBUG'}, 0, "first argument is a hash reference:\n" . format_data($argument));
+			notify($ERRORS{'DEBUG'}, 0, "first argument is a hash reference:\n" . format_data($argument));
 			
 			$computer_name = $argument->{node} if (!$computer_name);
 			$command = $argument->{command};
@@ -2782,96 +2781,39 @@ sub process_connect_methods {
 =cut
 
 sub is_user_connected {
-	
 	my $self = shift;
 	if (ref($self) !~ /VCL::Module/i) {
 		notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it must be called as a class method");
 		return;
 	}
-	my $time_limit = shift;
-	if ( !$time_limit ) {
-		notify($ERRORS{'WARNING'}, 0, "time_limit variable not passed as an argument");
-		return "failed";
-	}
-
-	my $request_id             = $self->data->get_request_id();	
-	my $computer_node_name     = $self->data->get_computer_node_name();
-	my $request_state_name	   = $self->data->get_request_state_name();
-	my $request_laststate_name = $self->data->get_request_state_name();
-	my $user_unityid           = $self->data->get_user_login_id();
-	my $connect_methods        = $self->data->get_connect_methods();
-	
-	my $start_time    = time();
-	my $timeout_time  = ($start_time + ($time_limit * 60));
-	my $time_exceeded = 0;
-	my $break         = 0;
-	my $ret_val       = "no";
-
-	# Figure out number of loops for log messages
-	while (!$break) {
-		notify($ERRORS{'OK'}, 0, "checking for connection by $user_unityid on $computer_node_name");
-		
-		if (is_request_deleted($request_id)) {
-			notify($ERRORS{'OK'}, 0, "user has deleted request");
-			$break   = 1;
-			$ret_val = "deleted";
-			return $ret_val;
-		}
-		
-		# Check if the request state changed
-		# This will occur with cluster requests while the child reservations are checking for a connection
-		my ($request_current_state_name, $request_current_laststate_name) = get_request_current_state_name($request_id);
-		if (($request_current_state_name eq 'pending' && $request_current_laststate_name ne $request_state_name) ||
-			 ($request_current_state_name ne 'pending' && $request_current_state_name ne $request_state_name)) {
-			notify($ERRORS{'OK'}, 0, "request state changed: $request_state_name/$request_laststate_name --> $request_current_state_name/$request_current_laststate_name, returning 'connected'");
-			return 'connected';
-		}
-		else {
-			notify($ERRORS{'OK'}, 0, "request state NOT changed: $request_state_name/$request_laststate_name --> $request_current_state_name/$request_current_laststate_name");
-		}
+
+	my $computer_node_name = $self->data->get_computer_node_name();
+	my $user_login_id      = $self->data->get_user_login_id();
+	my $connect_methods    = $self->data->get_connect_methods();
+	
+	notify($ERRORS{'OK'}, 0, "checking for connection by $user_login_id on $computer_node_name");
+	
+	foreach my $connect_method_id (keys %$connect_methods) {
+		my $name = $connect_methods->{$connect_method_id}{name};
+		my $port = $connect_methods->{$connect_method_id}{port};
+		my $protocol = $connect_methods->{$connect_method_id}{protocol} || 'TCP';
 		
-		$time_exceeded = time_exceeded($start_time, $time_limit);
-		if ($time_exceeded) {
-			notify($ERRORS{'OK'}, 0, "$time_limit minute time limit exceeded begin cleanup process");
-			# time_exceeded, begin cleanup process
-			$break = 1;
-			if ($request_state_name =~ /reserved/) {
-				notify($ERRORS{'OK'}, 0, "user never logged in returning nologin");
-				$ret_val = "nologin";
-			}
-			else {
-				$ret_val = "timeout";
-			}
-			return $ret_val;
-		} ## end if ($time_exceeded)
-		else {    # time not exceeded check for connection
-			foreach my $CMid (sort keys %{$connect_methods} ) {
-				if($self->can("check_connection_on_port")) {
-					if(defined($$connect_methods{$CMid}{port}) && $$connect_methods{$CMid}{port}) {
-						my $connect_state = $self->check_connection_on_port($$connect_methods{$CMid}{port});
-						if($connect_state =~ /(connected|conn_wrong_ip|timeout|failed)/i){
-						 	return $connect_state	
-						}
-					}
-					else {
-						notify($ERRORS{'WARNING'}, 0, "port not defined for connectMethod id $CMid");
-					}
-				}
-				else {
-					notify($ERRORS{'CRITICAL'}, 0, "OS module does not support check_connection_on_port: " . ref($self));
-					return;
-				}
-			}
-		}
+		notify($ERRORS{'DEBUG'}, 0, "checking '$name' connect method, protocol: $protocol, port: $port");
 		
-		my $current_time = time();
-		my $seconds_elapsed = ($current_time - $start_time);
-		my $seconds_until_timeout = ($timeout_time - $current_time);
+		if (!$self->can("check_connection_on_port")) {
+			notify($ERRORS{'CRITICAL'}, 0, ref($self) . " OS module does not implement check_connection_on_port subroutine");
+			return;
+		}
 		
-		notify($ERRORS{'DEBUG'}, 0, "$user_unityid has not connected to $computer_node_name ($seconds_elapsed/$seconds_until_timeout seconds elapsed/remaining), sleeping for 15 seconds");
-		sleep 15;
+		my $result = $self->check_connection_on_port($port);
+		if ($result && $result !~ /no/i) {
+			notify($ERRORS{'OK'}, 0, "$user_login_id is connected to $computer_node_name using $name connect method, result: $result");
+			return 1;
+		}
 	}
-	return $ret_val;
+	
+	notify($ERRORS{'OK'}, 0, "$user_login_id is not connected to $computer_node_name");
+	return 0;
 }
 
 #/////////////////////////////////////////////////////////////////////////////

Modified: vcl/trunk/managementnode/lib/VCL/Module/State.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/State.pm?rev=1492689&r1=1492688&r2=1492689&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/State.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/State.pm Thu Jun 13 14:40:45 2013
@@ -96,7 +96,10 @@ sub initialize {
 	}
 	
 	# Update reservation lastcheck value to prevent processes from being forked over and over if a problem occurs
-	update_reservation_lastcheck($reservation_id);
+	my $reservation_lastcheck = update_reservation_lastcheck($reservation_id);
+	if ($reservation_lastcheck) {
+		$self->data->set_reservation_lastcheck_time($reservation_lastcheck);
+	}
 	
 	# Check the image OS before creating OS object
 	if (!$self->check_image_os()) {

Modified: vcl/trunk/managementnode/lib/VCL/inuse.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/inuse.pm?rev=1492689&r1=1492688&r2=1492689&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/inuse.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/inuse.pm Thu Jun 13 14:40:45 2013
@@ -79,6 +79,7 @@ use strict;
 use warnings;
 use diagnostics;
 
+use POSIX;
 use VCL::utils;
 
 ##############################################################################
@@ -91,554 +92,298 @@ use VCL::utils;
 
 =head2 process
 
- Parameters  : $request_data_hash_reference
- Returns     : 1 if successful, 0 otherwise
- Description : Processes a reservation in the inuse state. You must pass this
-               method a reference to a hash containing request data.
+ Parameters  : 
+ Returns     : boolean
+ Description : Processes a reservation in the inuse state.
 
 =cut
 
 sub process {
 	my $self = shift;
 	
-	my $request_id            = $self->data->get_request_id();
-	my $reservation_id        = $self->data->get_reservation_id();
-	my $request_end           = $self->data->get_request_end_time();
-	my $request_duration      = $self->data->get_request_duration_epoch();
-	my $request_logid         = $self->data->get_request_log_id();
-	my $request_checktime     = $self->data->get_request_check_time();
-	my $request_checkuser     = $self->data->get_request_checkuser();
-	my $reservation_remoteip  = $self->data->get_reservation_remote_ip();
-	my $computer_id           = $self->data->get_computer_id();
-	my $computer_short_name   = $self->data->get_computer_short_name();
-	my $computer_type         = $self->data->get_computer_type();
-	my $computer_hostname     = $self->data->get_computer_hostname();
-	my $computer_nodename     = $self->data->get_computer_node_name();
-	my $computer_ip_address   = $self->data->get_computer_ip_address();
-	my $image_os_name         = $self->data->get_image_os_name();
-	my $imagemeta_checkuser   = $self->data->get_imagemeta_checkuser();
-	my $user_login_id         = $self->data->get_user_login_id();
-	my $request_forimaging    = $self->data->get_request_forimaging();
-	my $image_os_type         = $self->data->get_image_os_type();
-	my $reservation_count     = $self->data->get_reservation_count();
+	my $request_id = $self->data->get_request_id();
+	my $request_state_name = $self->data->get_request_state_name();
+	my $request_laststate_name = $self->data->get_request_laststate_name();
+	my $request_start = $self->data->get_request_start_time();
+	my $request_end = $self->data->get_request_end_time();
+	my $request_data = $self->data->get_request_data();
+	my $request_forimaging = $self->data->get_request_forimaging();
+	my $request_checkuser = $self->data->get_request_checkuser();
+	my $reservation_id = $self->data->get_reservation_id();
+	my $reservation_count = $self->data->get_reservation_count();
+	my $server_request_id = $self->data->get_server_request_id();
+	my $imagemeta_checkuser = $self->data->get_imagemeta_checkuser();
 	my $is_parent_reservation = $self->data->is_parent_reservation();
-	my $request_state_name    = $self->data->get_request_state_name();
+	my $computer_id = $self->data->get_computer_id();
+	my $computer_short_name   = $self->data->get_computer_short_name();
+	my $connect_timeout_minutes = $self->data->get_variable('connect_timeout_minutes') || 15;
 	
-	if ($request_state_name =~ /reboot|rebootsoft|reboothard/) {
-		notify($ERRORS{'OK'}, 0, "this is a '$request_state_name' request");
+	# Make sure connect timeout is long enough
+	# It has to be a bit longer than the ~5 minute period between inuse checks due to cluster reservations
+	# If too short, a user may be connected to one computer in a cluster and another inuse process times out before the connected computer is checked
+	if ($connect_timeout_minutes < 10) {
+		notify($ERRORS{'WARNING'}, 0, "connect timeout is set to $connect_timeout_minutes minutes, it must be 10 minutes or more");
+		$connect_timeout_minutes = 10;
+	}
+	
+	# Check if reboot operation was requested
+	if ($request_state_name =~ /reboot/) {
 		if ($self->os->can('reboot')) {
-			if ($self->os->reboot()) {
-				notify($ERRORS{'OK'}, 0, "successfuly rebooted $computer_nodename");
-			}
-			else {
-				notify($ERRORS{'WARNING'}, 0, "failed to reboot $computer_nodename");
-				# Do not fail request or machine
+			if (!$self->os->reboot()) {
+				notify($ERRORS{'CRITICAL'}, 0, "user requested reboot of $computer_short_name failed");
 			}
 		}
 		else {
 			notify($ERRORS{'CRITICAL'}, 0, "'$request_state_name' operation requested, " . ref($self->os) . " does not implement a 'reboot' subroutine");
 		}
-		
-		# Put this request back into the inuse state
-		if (update_request_state($request_id, "inuse", "inuse")) {
-			notify($ERRORS{'OK'}, 0, "request state set back to inuse");
-		}
-		else {
-			notify($ERRORS{'WARNING'}, 0, "unable to set request state back to inuse");
-		}
-		
+		update_request_state($request_id, "inuse", "inuse");
 		notify($ERRORS{'OK'}, 0, "exiting");
 		exit;
 	}
 	
-	# Server modified
+	# Check if server reservation has been modified
 	if ($request_state_name =~ /servermodified/) {
-      notify($ERRORS{'OK'}, 0, "this is a '$request_state_name' request");
-
-		#FIXME - a cmd queue is needed to tell vcld what to do
-		#for now we assume a user has been added/removed from a user group
-		
 		if (!$self->os->manage_server_access()) {
 			notify($ERRORS{'CRITICAL'}, 0, "failed to update server access");
       }
-		
-		# Put this request back into the inuse state
-		if (update_request_state($request_id, "inuse", "inuse")) {
-			notify($ERRORS{'OK'}, 0, "request state set back to inuse");
-      }
-      else {
-         notify($ERRORS{'WARNING'}, 0, "unable to set request state back to inuse");
-      }
-      
-      notify($ERRORS{'OK'}, 0, "exiting");
+		update_request_state($request_id, "inuse", "inuse");
       exit;
-	
 	}
 	
-	# Set the user connection timeout limit in minutes
-	my $connect_timeout_limit = 15;
-	
-	# Check if request imaging status has changed
-	# Check if this is an imaging request, causes process to exit if state or laststate = image
-	$request_forimaging = $self->_check_imaging_request();
-	
 	# Remove rows from computerloadlog for this reservation, don't remove the loadstate=begin row
-	if (delete_computerloadlog_reservation($reservation_id, '!begin')) {
-		notify($ERRORS{'OK'}, 0, "rows removed from computerloadlog table for reservation $reservation_id");
-	}
-	else {
-		notify($ERRORS{'OK'}, 0, "unable to remove rows from computerloadlog table for reservation $reservation_id");
-	}
+	delete_computerloadlog_reservation($reservation_id, '!begin');
 	
-	# Update the lastcheck value for this reservation to now
-	if (update_reservation_lastcheck($reservation_id)) {
-		notify($ERRORS{'OK'}, 0, "updated lastcheck time for reservation $reservation_id");
-	}
-	else {
-		notify($ERRORS{'CRITICAL'}, 0, "unable to update lastcheck time for reservation $reservation_id");
-	}
-
-	# For inuse state, check_time should return 'end', 'poll', or 'nothing'
-	# Is this a poll or end time
-	if ($request_checktime eq "poll") {
-		notify($ERRORS{'OK'}, 0, "beginning to poll");
-		
-		# Check if the computer is responding to SSH before attempting to poll it or do any other checks done on the computer
-		# This is done to prevent unnecessary looping and to reduce log file output
-		my $is_ssh_responding = $self->os->is_ssh_responding();
+	my $now_epoch_seconds = time;
+	my $request_start_epoch_seconds = convert_to_epoch_seconds($request_start);
+	my $request_end_epoch_seconds = convert_to_epoch_seconds($request_end);
+	my $request_remaining_seconds = ($request_end_epoch_seconds - $now_epoch_seconds);
+	my $request_remaining_minutes = floor($request_remaining_seconds / 60);
+	my $request_duration_seconds = ($request_end_epoch_seconds - $request_start_epoch_seconds);
+	my $request_duration_hours = floor($request_duration_seconds / 60 / 60);
+	
+	my $end_time_notify_minutes = 10;
+	my $end_time_notify_seconds = ($end_time_notify_minutes * 60);
+	
+	# Check if near the end time
+	if ($request_remaining_minutes <= ($end_time_notify_minutes + 6)) {
+		# Only 1 reservation needs to handle the end time countdown
+		if (!$is_parent_reservation) {
+			notify($ERRORS{'OK'}, 0, "request end time countdown handled by parent reservation, exiting");
+			exit;
+		}
 		
-		if ($is_ssh_responding) {
-			notify($ERRORS{'DEBUG'}, 0, "checking if firewall needs to be updated");
-			if ($self->os->can('firewall_compare_update')) {
-				if ($self->os->firewall_compare_update()) {
-					notify($ERRORS{'DEBUG'}, 0, "confirmed firewall scope has been updated");
-				}
-			}	
-			else {
-				notify($ERRORS{'DEBUG'}, 0, ref($self->os) . " OS module does not implement a 'firewall_compare_update' subroutine");
-			}
+		my $now_string               = strftime('%H:%M:%S', localtime($now_epoch_seconds));
+		my $request_end_string       = strftime('%H:%M:%S', localtime($request_end_epoch_seconds));
+		my $request_remaining_string = strftime('%H:%M:%S', gmtime($request_remaining_seconds));
+		my $end_time_notify_string   = strftime('%H:%M:%S', gmtime($end_time_notify_seconds));
+		
+		my $sleep_seconds = ($request_remaining_seconds - $end_time_notify_seconds);
+		if ($sleep_seconds > 0) {
+			my $sleep_string = strftime('%H:%M:%S', gmtime($sleep_seconds));
+			notify($ERRORS{'OK'}, 0, "request end time is near, sleeping for $sleep_seconds seconds:\n" .
+				"current time     : $now_string\n" .
+				"request end time : $request_end_string\n" .
+				"remaining time   : $request_remaining_string\n" .
+				"notify time      : $end_time_notify_string\n" .
+				"sleep time       : $sleep_string"
+			);
+			sleep $sleep_seconds;
 		}
 		else {
-			notify($ERRORS{'DEBUG'}, 0, "unable to check if firewall needs to be updated, $computer_short_name is not responding to SSH");
-		}
-		
-		# Check the imagemeta checkuser flag, request forimaging flag, and if cluster request
-		if (!$request_checkuser || !$imagemeta_checkuser || $request_forimaging || ($reservation_count > 1) || !$is_ssh_responding) {
-			# Either imagemeta checkuser flag = 0, forimaging = 1, or cluster request
-			if (!$request_checkuser) {
-				notify($ERRORS{'OK'}, 0, "request checkuser flag not set, skipping user connection check");
-			}
-			if (!$imagemeta_checkuser) {
-				notify($ERRORS{'OK'}, 0, "imagemeta checkuser flag not set, skipping user connection check");
-			}
-			if ($request_forimaging) {
-				notify($ERRORS{'OK'}, 0, "forimaging flag is set to 1, skipping user connection check");
-			}
-			if ($reservation_count > 1) {
-				notify($ERRORS{'OK'}, 0, "reservation count is $reservation_count, skipping user connection check");
-			}
-			if (!$is_ssh_responding) {
-				notify($ERRORS{'OK'}, 0, "$computer_short_name is not responding to SSH, skipping user connection check");
-			}
-			
-			# Check if the user deleted the request
-			if (is_request_deleted($request_id)) {
-				# User deleted request, exit
-				notify($ERRORS{'OK'}, 0, "user deleted request, exiting");
-				exit;
-			}
-			
-			# If duration is greater than 24 hours and 5 minutes perform end time notice checks
-			if ($request_duration > (24 * 60 * 60 + 5 * 60)) {
-				notify($ERRORS{'DEBUG'}, 0, "request duration greater than 24 hours ($request_duration seconds), checking if endtime notice should be sent to user");
-				
-				# Check end time for a notice interval
-				# This returns 0 if no notice is to be given
-				my $notice_interval = check_endtimenotice_interval($request_end);
-				
-				if ($notice_interval && $is_parent_reservation) {
-					notify($ERRORS{'OK'}, 0, "notice interval is set to $notice_interval");
-					
-					# Notify the user of the end time
-					$self->_notify_user_endtime($notice_interval);
-				}
-			}
-			else {
-				notify($ERRORS{'DEBUG'}, 0, "request duration less than 24 hours ($request_duration seconds), skipping endtime notice check");
-			}
-			
-			# Check if the user deleted the request
-			if (is_request_deleted($request_id)) {
-				# User deleted request, exit
-				notify($ERRORS{'OK'}, 0, "user deleted request, exiting");
-				exit;
-			}
-			
-			# Check if request imaging status has changed
-			# Check if this is an imaging request, causes process to exit if state or laststate = image
-			$request_forimaging = $self->_check_imaging_request();
-			
-			# Update the lastcheck time for this reservation
-			if (update_reservation_lastcheck($reservation_id)) {
-				my $dstring = convert_to_datetime();
-				notify($ERRORS{'OK'}, 0, "updated reservation lastcheck time to now");
-			}
-			else {
-				notify($ERRORS{'WARNING'}, 0, "failed to update reservation lastcheck time to now");
-			}
-			
-			# Put this request back into the inuse state
-			if ($is_parent_reservation) {
-				if (update_request_state($request_id, "inuse", "inuse")) {
-					notify($ERRORS{'OK'}, 0, "request state set back to inuse");
-				}
-				else {
-					notify($ERRORS{'CRITICAL'}, 0, "unable to set request state back to inuse");
-				}
-			}
-			else {
-				notify($ERRORS{'OK'}, 0, "child reservation, request state NOT set back to inuse");
-			}
-			
-			notify($ERRORS{'OK'}, 0, "exiting");
-			exit;
-		}    # if (!$imagemeta_checkuser || $request_forimaging.......
-		
-		
-		# Poll:
-		# Simply check for user connection
-		# If not connected:
-		#   Loop; check end time, continue to check for connection
-		#   If not connected within 15 minutes -- timeout
-		#   If end time is near prepare
-		notify($ERRORS{'OK'}, 0, "proceeding to check for user connection");
-		
-		# Get epoch seconds for current and end time, calculate difference
-		my $now_epoch       = convert_to_epoch_seconds();
-		my $end_epoch       = convert_to_epoch_seconds($request_end);
-		my $time_difference = $end_epoch - $now_epoch;
-		
-		# If end time is 10-15 minutes from now:
-		#    Sleep difference
-		#    Go to end mode
-		if ($time_difference >= (10 * 60) && $time_difference <= (15 * 60)) {
-			notify($ERRORS{'OK'}, 0, "end time ($time_difference seconds) is 10-15 minutes from now");
+			notify($ERRORS{'WARNING'}, 0, "request notify end time has passed:\n" .
+				"current time           : $now_string\n" .
+				"request end time       : $request_end_string\n" .
+				"remaining time         : $request_remaining_string\n" .
+				"notify time            : $end_time_notify_string"
+			);
+		}
+		
+		# Loop for $end_time_notify_minutes regardless of how much time is actually left
+		# The time until request.end may be short if vcld wasn't running
+		# This gives the user notice that the request is ending
+		for (my $iteration = 0; $iteration <= $end_time_notify_minutes; ++$iteration) {
+			$request_remaining_minutes = ($end_time_notify_minutes - $iteration);
+			notify($ERRORS{'OK'}, 0, "minutes until end of end of request: $request_remaining_minutes");
 			
-			# Calculate the sleep time = time until the request end - 10 minutes
-			# User will have 10 minutes after this sleep call before disconnected
-			my $sleep_time = $time_difference - (10 * 60);
-			notify($ERRORS{'OK'}, 0, "sleeping for $sleep_time seconds");
-			sleep $sleep_time;
-			$request_checktime = "end";
-			goto ENDTIME;
-		}  # Close if poll, checkuser=1, and end time is 10-15 minutes away
-		
-		notify($ERRORS{'OK'}, 0, "end time not yet reached, polling machine for user connection");
-		
-		my $check_connection = $self->os->is_user_connected($connect_timeout_limit);
-		
-		# FOR TESTING
-		#$check_connection = 'timeout';
-		
-		# Proceed based on status of check_connection
-		if ($check_connection eq "connected" || $check_connection eq "conn_wrong_ip") {
-			notify($ERRORS{'OK'}, 0, "user connected");
+			# Check if user deleted the request
+			exit if is_request_deleted($request_id);
 			
-			# Check if request imaging status has changed
 			# Check if this is an imaging request, causes process to exit if state or laststate = image
-			$request_forimaging = $self->_check_imaging_request();
-			
-			# Put this request back into the inuse state
-			if (update_request_state($request_id, "inuse", "inuse")) {
-				notify($ERRORS{'OK'}, 0, "request state set back to inuse");
-			}
-			else {
-				notify($ERRORS{'WARNING'}, 0, "unable to set request state back to inuse");
-			}
-			
-			# Update the lastcheck time for this reservation
-			if (update_reservation_lastcheck($reservation_id)) {
-				notify($ERRORS{'OK'}, 0, "updated lastcheck time for this reservation to now");
-			}
-			else {
-				notify($ERRORS{'WARNING'}, 0, "unable to update lastcheck time for this reservation to now");
-			}
-			
-			notify($ERRORS{'OK'}, 0, "exiting");
-			exit;
-		} # Close check_connection is connected
-		
-		elsif (!$request_forimaging && $check_connection eq "timeout") {
-			notify($ERRORS{'OK'}, 0, "user did not reconnect within $connect_timeout_limit minute time limit");
-			
-			# Check if request imaging status has changed
-			# Check if this is an imaging request, causes process to exit if state or laststate = image
-			$request_forimaging = $self->_check_imaging_request();
-			
-			notify($ERRORS{'OK'}, 0, "notifying user that request timed out");
-			$self->_notify_user_timeout();
-			
-			# Put this request into the timeout state
-			if (update_request_state($request_id, "timeout", "inuse")) {
-				notify($ERRORS{'OK'}, 0, "request state set to timeout");
-			}
-			else {
-				notify($ERRORS{'WARNING'}, 0, "unable to set request state to timeout");
-			}
+			$self->_check_imaging_request();
 			
-			# Get the current computer state directly from the database
-			my $computer_state;
-			if ($computer_state = get_computer_current_state_name($computer_id)) {
-				notify($ERRORS{'OK'}, 0, "computer $computer_id state retrieved from database: $computer_state");
-			}
-			else {
-				notify($ERRORS{'WARNING'}, 0, "unable to retrieve computer $computer_id state from database");
+			# Get the current request end time from the database
+			my $current_request_end = get_request_end($request_id);
+			my $current_request_end_epoch_seconds = convert_to_epoch_seconds($current_request_end);
+			
+			# Check if the user extended the request
+			if ($current_request_end_epoch_seconds > $request_end_epoch_seconds) {
+				notify($ERRORS{'OK'}, 0, "user extended request, end time: $request_end --> $current_request_end, returning request to inuse state");
+				update_request_state($request_id, "inuse", "inuse");
+				exit;
 			}
 			
-			# Check if computer is in maintenance state
-			if ($computer_state =~ /maintenance/) {
-				notify($ERRORS{'OK'}, 0, "computer $computer_short_name in maintenance state, skipping update");
-			}
-			else {
-				# Computer is not in maintenance state, set its state to timeout
-				if (update_computer_state($computer_id, "timeout")) {
-					notify($ERRORS{'OK'}, 0, "computer $computer_id set to timeout state");
-				}
-				else {
-					notify($ERRORS{'WARNING'}, 0, "unable to set computer $computer_id to the timeout state");
-				}
+			# Notify user when 5 or 10 minutes remain
+			if ($request_remaining_minutes == 5 || $request_remaining_minutes == 10) {
+				$self->_notify_user_disconnect($request_remaining_minutes);
 			}
 			
-			# Update the entry in the log table with the current finalend time and ending set to timeout
-			if (update_log_ending($request_logid, "timeout")) {
-				notify($ERRORS{'OK'}, 0, "log id $request_logid finalend was updated to now and ending set to timeout");
-			}
-			else {
-				notify($ERRORS{'WARNING'}, 0, "log id $request_logid finalend could not be updated to now and ending set to timeout");
+			if ($iteration < $end_time_notify_minutes) {
+				notify($ERRORS{'OK'}, 0, "sleeping for 60 seconds");
+				sleep 60;
 			}
-			
-			notify($ERRORS{'OK'}, 0, "exiting");
-			exit;
-		} ## end elsif ($check_connection eq "timeout")  [ if ($check_connection eq "connected")
-		
-		elsif ($check_connection eq "deleted") {
-			# Exit quietly
-			notify($ERRORS{'OK'}, 0, "user has deleted the request, quietly exiting");
-			exit;
 		}
 		
-		else {
-			notify($ERRORS{'CRITICAL'}, 0, "unexpected return value from check_connection: $check_connection, treating request as connected");
-			
-			# Check if request imaging status has changed
-			# Check if this is an imaging request, causes process to exit if state or laststate = image
-			$request_forimaging = $self->_check_imaging_request();
-			
-			# Put this request back into the inuse state
-			if (update_request_state($request_id, "inuse", "inuse")) {
-				notify($ERRORS{'OK'}, 0, "request state set back to inuse");
-			}
-			else {
-				notify($ERRORS{'WARNING'}, 0, "unable to set request state back to inuse");
-			}
-			
-			# Update the lastcheck time for this reservation
-			if (update_reservation_lastcheck($reservation_id)) {
-				notify($ERRORS{'OK'}, 0, "updated lastcheck time for this reservation to now");
-			}
-			else {
-				notify($ERRORS{'WARNING'}, 0, "unable to update lastcheck time for this reservation to now");
-			}
-			
-			notify($ERRORS{'OK'}, 0, "exiting");
-			exit;
-		} ## end else [ if ($check_connection eq "connected")  [... [elsif ($check_connection eq "deleted")
-	}    # Close if checktime is poll
-	
-	elsif ($request_checktime eq "end") {
-		# Time has ended
-		# Notify user to save work and exit within 10 minutes
-		
-		ENDTIME:
-		my $notified        = 0;
-		my $disconnect_time = 10;
-		
-		# Loop until disconnect time = 0
-		while ($disconnect_time != 0) {
-			notify($ERRORS{'OK'}, 0, "minutes left until user is disconnected: $disconnect_time");
-			
-			# Notify user at 10 minutes until disconnect
-			if ($disconnect_time == 10) {
-				$self->_notify_user_disconnect($disconnect_time);
-				insertloadlog($reservation_id, $computer_id, "inuseend10", "notifying user of disconnect");
-			}
-			
-			# Sleep one minute and decrement disconnect time by a minute
-			sleep 60;
-			$disconnect_time--;
-		
-			# Check if the user deleted the request
-			if (is_request_deleted($request_id)) {
-				# User deleted request, exit queitly
-				notify($ERRORS{'OK'}, 0, "user has deleted the request, quietly exiting");
-				exit;
-			}
-			
-			# Perform some actions at 5 minutes until end of request
-			if ($disconnect_time == 5) {
-				# Check for connection
-				if (isconnected($computer_hostname, $computer_type, $reservation_remoteip, $image_os_name, $computer_ip_address,$image_os_type)) {
-					insertloadlog($reservation_id, $computer_id, "inuseend5", "notifying user of endtime");
-					$self->_notify_user_disconnect($disconnect_time);
-				}
-				else {
-					insertloadlog($reservation_id, $computer_id, "inuseend5", "user is not connected, notification skipped");
-					notify($ERRORS{'OK'}, 0, "user has disconnected from $computer_short_name, skipping additional notices");
-				}
-			}    # Close if disconnect time = 5
-			
-			# Check to see if the end time was extended
-			my $new_request_end;
-			if ($new_request_end = get_request_end($request_id)) {
-				notify($ERRORS{'OK'}, 0, "request end value in database: $new_request_end");
-			}
-			else {
-				notify($ERRORS{'WARNING'}, 0, "unable to retrieve updated request end value from database");
-			}
-			
-			# Convert the current and new end times to epoch seconds
-			my $new_request_end_epoch = convert_to_epoch_seconds($new_request_end);
-			my $request_end_epoch     = convert_to_epoch_seconds($request_end);
-			
-			# Check if request imaging status has changed
-			# Check if this is an imaging request, causes process to exit if state or laststate = image
-			$request_forimaging = $self->_check_imaging_request();
-			
-			# Check if request end is later than the original (user extended time)
-			if ($new_request_end_epoch > $request_end_epoch) {
-				notify($ERRORS{'OK'}, 0, "user extended end time, returning request to inuse state");
-				
-				# Put this request back into the inuse state
-				if ($is_parent_reservation && update_request_state($request_id, "inuse", "inuse")) {
-					notify($ERRORS{'OK'}, 0, "request state set back to inuse");
-				}
-				elsif (!$is_parent_reservation) {
-					notify($ERRORS{'OK'}, 0, "child reservation, request state NOT set back to inuse");
-				}
-				else {
-					notify($ERRORS{'WARNING'}, 0, "unable to set request state back to inuse");
-				}
-				
-				notify($ERRORS{'OK'}, 0, "exiting");
-				exit;
-			} ## end if ($new_request_end_epoch > $request_end_epoch)
-		}    # Close while disconnect time is not 0
-		
-		# Check if this is an imaging request, causes process to exit if state or laststate = image
-		$request_forimaging = $self->_check_imaging_request();
+		# Notify user - endtime and image capture has started
+		$self->_notify_user_request_ended();
 		
-		# Automatically capture image
-		# If forimaging and not a cluster reservation - initiate capture process
-		if($request_forimaging && ($reservation_count < 2) ){
-			# Check if the user deleted the request
-			if (is_request_deleted($request_id)) {
-				# User deleted request, exit queitly
-				notify($ERRORS{'OK'}, 0, "user has deleted the request, quietly exiting");
-				exit;
-			}
-			if ($self->_start_imaging_request){
-				notify($ERRORS{'OK'}, 0, "Started image capture process. This process is Exiting.");
-				#notify user - endtime and image capture has started
-				$self->_notify_user_request_ended();
-				exit;
-			}	
-			else {
-				notify($ERRORS{'CRITICAL'}, 0, "_start_imaging_request xmlrpc call failed putting request and node into maintenance");
-				# Update the request state to maintenance, laststate to inuse
-				if (update_request_state($request_id, "maintenance", "inuse")) {
-					notify($ERRORS{'OK'}, 0, "request state set to maintenance, laststate to inuse");
-				}
-				else {
-					notify($ERRORS{'CRITICAL'}, 0, "unable to set request state to maintenance, laststate to inuse");
-				}
-				
-				# Update the computer state to maintenance
-				if (update_computer_state($computer_id, "maintenance")) {
-					notify($ERRORS{'OK'}, 0, "$computer_short_name state set to maintenance");
-				}
-				else {
-					notify($ERRORS{'CRITICAL'}, 0, "unable to set $computer_short_name state to maintenance");
-				}
+		# Initiate auto-capture process if this is an imaging request and not a cluster reservation
+		if ($request_forimaging && $reservation_count == 1) {
+			notify($ERRORS{'OK'}, 0, "initiating image auto-capture process");
+			if (!$self->_start_imaging_request()) {
+				notify($ERRORS{'CRITICAL'}, 0, "failed to initiate image auto-capture process, changing request and computer state to maintenance");
+				update_request_state($request_id, 'maintenance', 'maintenance');
 				exit;
 			}
 		}
 		
-		# Insert an entry into the load log
-		insertloadlog($reservation_id, $computer_id, "timeout", "endtime reached moving to timeout");
-		notify($ERRORS{'OK'}, 0, "end time reached, setting request to timeout state");
-		
-		# Put this request into the timeout state
-		if ($is_parent_reservation && update_request_state($request_id, "timeout", "inuse")) {
-			notify($ERRORS{'OK'}, 0, "request state set to timeout");
-		}
-		elsif (!$is_parent_reservation) {
-			notify($ERRORS{'OK'}, 0, "child reservation, request state NOT set back to timeout");
+		switch_state($request_data, 'timeout', 'timeout', 'EOR', 1);
+		exit;
+	}
+	
+	# If duration is greater than 24 hours perform end time notice checks
+	if ($is_parent_reservation && $request_duration_hours >= 24) {
+		notify($ERRORS{'DEBUG'}, 0, "checking end time notice interval, request duration: $request_duration_hours hours, parent reservation: $is_parent_reservation");
+		# Check end time for a notice interval - returns 0 if no notice is to be given
+		my $notice_interval = check_endtimenotice_interval($request_end);
+		if ($notice_interval) {
+			$self->_notify_user_endtime($notice_interval);
 		}
-		else {
-			notify($ERRORS{'WARNING'}, 0, "unable to set request state to timout");
+	}
+	else {
+		notify($ERRORS{'DEBUG'}, 0, "skipping end time notice interval check, request duration: $request_duration_hours hours, parent reservation: $is_parent_reservation");
+	}
+	
+	# Check if the computer is responding to SSH
+	if (!$self->os->is_ssh_responding()) {
+		notify($ERRORS{'OK'}, 0, "$computer_short_name is not responding to SSH, skipping user connection check");
+		update_request_state($request_id, "inuse", "inuse");
+		exit;
+	}
+	
+	# Update the firewall if necessary - this is what allows a user to click Connect from different locations
+	# Not necessary first time inuse state is processed after reserved
+	if ($request_laststate_name ne 'reserved' && $self->os->can('firewall_compare_update')) {
+		$self->os->firewall_compare_update();
+	}
+
+	# Skip connection checks if the computer is not responding to SSH
+	# This prevents a reservatino from timing out if the user is actually connected but SSH from the management node isn't working
+	# Wait for the user to acknowledge the request by clicking Connect button or from API
+	if (!$self->code_loop_timeout(sub{$self->user_connected()}, [], "waiting for user to connect to $computer_short_name", ($connect_timeout_minutes*60), 15)) {
+		if (!$imagemeta_checkuser || !$request_checkuser) {
+			notify($ERRORS{'OK'}, 0, "never detected user connection, skipping timeout, imagemeta checkuser: $imagemeta_checkuser, request checkuser: $request_checkuser");
+		}
+		elsif ($server_request_id) {
+			notify($ERRORS{'OK'}, 0, "never detected user connection, skipping timeout, server reservation");
 		}
-		
-		# Get the current computer state directly from the database
-		my $computer_state;
-		if ($computer_state = get_computer_current_state_name($computer_id)) {
-			notify($ERRORS{'OK'}, 0, "computer $computer_id state retrieved from database: $computer_state");
+		elsif ($request_forimaging && $request_laststate_name ne 'reserved') {
+			notify($ERRORS{'OK'}, 0, "never detected user connection, skipping timeout, imaging reservation");
 		}
-		else {
-			notify($ERRORS{'WARNING'}, 0, "unable to retrieve computer $computer_id state from database");
+		elsif ($reservation_count > 1 && $request_laststate_name ne 'reserved') {
+			notify($ERRORS{'OK'}, 0, "never detected user connection, skipping timeout, cluster reservation");
 		}
-		
-		# Check if computer is in maintenance state
-		if ($computer_state =~ /maintenance/) {
-			notify($ERRORS{'OK'}, 0, "computer $computer_short_name in maintenance state, skipping computer state update");
+		elsif ($request_duration_hours > 24) {
+			notify($ERRORS{'OK'}, 0, "never detected user connection, skipping timeout, request duration: $request_duration_hours hours");
 		}
 		else {
-			notify($ERRORS{'OK'}, 0, "computer not in maintenance, setting computer to timeout state");
-			# Computer is not in maintenance state, set its state to timeout
-			if (update_computer_state($computer_id, "timeout")) {
-				notify($ERRORS{'OK'}, 0, "computer $computer_id set to timeout state");
+			exit if is_request_deleted($request_id);
+			
+			# Update reservation lastcheck, otherwise request will be processed immediately again
+			update_reservation_lastcheck($reservation_id);
+			
+			if ($request_laststate_name eq 'reserved') {
+				$self->_notify_user_no_login();
+				switch_state($request_data, 'timeout', 'timeout', 'nologin', 1);
 			}
 			else {
-				notify($ERRORS{'WARNING'}, 0, "unable to set computer $computer_id to the timeout state");
+				$self->_notify_user_timeout();
+				switch_state($request_data, 'timeout', 'timeout', 'timeout', 1);
 			}
-		} ## end else [ if ($computer_state =~ /maintenance/)
-		
-		# Notify user about ending request
-		$self->_notify_user_request_ended();
-		
-		# Update the entry in the log table with the current finalend time and ending set to timeout
-		if ($is_parent_reservation && update_log_ending($request_logid, "EOR")) {
-			notify($ERRORS{'OK'}, 0, "log id $request_logid finalend was updated to now and ending set to EOR");
 		}
-		elsif (!$is_parent_reservation) {
-			notify($ERRORS{'OK'}, 0, "child reservation, log id $request_logid finalend was NOT updated");
+	}
+	
+	# If this is the first time the inuse state is being processed, tighten up the firewall
+	if ($request_laststate_name eq 'reserved') {
+		# Process the connect methods again, lock the firewall down to the address the user connected from
+		my $remote_ip = $self->data->get_reservation_remote_ip();
+		if (!$self->os->process_connect_methods($remote_ip, 1)) {
+			notify($ERRORS{'CRITICAL'}, 0, "failed to process connect methods after user connected to computer");
 		}
-		else {
-			notify($ERRORS{'WARNING'}, 0, "log id $request_logid finalend could not be updated to now and ending set to EOR");
+	}
+	
+	update_request_state($request_id, "inuse", "inuse");
+	exit;
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 user_connected
+
+ Parameters  : none
+ Returns     : boolean
+ Description : Checks if the user is connected to the computer. If the user
+					isn't connected and this is a cluster request, checks if a
+					computerloadlog 'connected' entry exists for any of the other
+					reservations in cluster.
+
+=cut
+
+sub user_connected {
+	my $self = shift;
+	if (ref($self) !~ /VCL::/) {
+		notify($ERRORS{'CRITICAL'}, 0, "subroutine can only be called as a class method of a VCL object");
+		return;
+	}
+	
+	my $request_id = $self->data->get_request_id();
+	my @reservation_ids = $self->data->get_reservation_ids();
+	my $reservation_id = $self->data->get_reservation_id();
+	my $reservation_lastcheck = $self->data->get_reservation_lastcheck_time();
+	my $reservation_count = $self->data->get_request_reservation_count();
+	my $computer_id = $self->data->get_computer_id();
+	my $computer_short_name = $self->data->get_computer_short_name();
+	
+	# Check if user deleted the request
+	exit if is_request_deleted($request_id);
+	
+	# Check if this is an imaging request, causes process to exit if state or laststate = image
+	$self->_check_imaging_request();
+	
+	# Check if the user has connected to the reservation being processed
+	if ($self->os->is_user_connected()) {
+		insertloadlog($reservation_id, $computer_id, "connected", "user connected to $computer_short_name");
+		
+		# If this is a cluster request, update the lastcheck value for all reservations
+		# This signals the other reservation inuse processes that a connection was detected on another computer
+		if ($reservation_count > 1) {
+			update_reservation_lastcheck(@reservation_ids);
 		}
-		
-		notify($ERRORS{'OK'}, 0, "exiting");
-		exit;
-	}    # Close if request checktime is end
+		return 1;
+	}
 	
-	# Not poll or end
-	else {
-		notify($ERRORS{'OK'}, 0, "returning \'$request_checktime\', exiting");
-		exit;
+	if ($reservation_count > 1) {
+		my $current_reservation_lastcheck = get_current_reservation_lastcheck($reservation_id);
+		if ($current_reservation_lastcheck ne $reservation_lastcheck) {
+			notify($ERRORS{'DEBUG'}, 0, "user connected to another computer in the cluster, reservation lastcheck updated since this process began: $reservation_lastcheck --> $current_reservation_lastcheck");
+			return 1;
+		}
+		else {
+			notify($ERRORS{'DEBUG'}, 0, "no connection to another computer in the cluster detected, reservation lastcheck has not been updated since this process began: $reservation_lastcheck");
+		}
 	}
 	
-	notify($ERRORS{'OK'}, 0, "exiting");
-	exit;
-} ## end sub process
+	return 0;
+}
 
 #/////////////////////////////////////////////////////////////////////////////
 
@@ -1079,6 +824,69 @@ EOF
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 _notify_user_nologin
+
+ Parameters  : none
+ Returns     : boolean
+ Description : Notifies the user that the request has timed out becuase no
+               initial connection was made. An e-mail and/or IM message will
+               be sent to the user.
+
+=cut
+
+sub _notify_user_nologin {
+	my $self = shift;
+	
+	my $request_id                 = $self->data->get_request_id();
+	my $reservation_id             = $self->data->get_reservation_id();
+	my $user_email                 = $self->data->get_user_email();
+	my $user_emailnotices          = $self->data->get_user_emailnotices();
+	my $user_im_name               = $self->data->get_user_imtype_name();
+	my $user_im_id                 = $self->data->get_user_im_id();
+	my $affiliation_sitewwwaddress = $self->data->get_user_affiliation_sitewwwaddress();
+	my $affiliation_helpaddress    = $self->data->get_user_affiliation_helpaddress();
+	my $image_prettyname           = $self->data->get_image_prettyname();
+	my $computer_ip_address        = $self->data->get_computer_ip_address();
+	my $is_parent_reservation      = $self->data->is_parent_reservation();
+
+	my $message = <<"EOF";
+
+Your reservation has timed out for image $image_prettyname at address $computer_ip_address because no initial connection was made.
+
+To make another reservation, please revisit $affiliation_sitewwwaddress.
+
+Thank You,
+VCL Team
+
+
+******************************************************************
+This is an automated notice. If you need assistance
+please respond with detailed information on the issue
+and a help ticket will be generated.
+
+To disable email notices
+-Visit $affiliation_sitewwwaddress
+-Select User Preferences
+-Select General Preferences
+******************************************************************
+EOF
+
+	my $subject = "VCL -- Reservation Timeout";
+
+	if ($is_parent_reservation && $user_emailnotices) {
+		#if  "0" user does not care to get additional notices
+		mail($user_email, $subject, $message, $affiliation_helpaddress);
+		notify($ERRORS{'OK'}, 0, "sent reservation timeout e-mail to $user_email");
+	}
+	if ($user_im_name ne "none") {
+		notify_via_IM($user_im_name, $user_im_id, $message);
+		notify($ERRORS{'OK'}, 0, "sent reservation timeout IM to $user_im_name");
+	}
+	return 1;
+} ## end sub _notify_user_timeout
+
+#/////////////////////////////////////////////////////////////////////////////
+
 =head2 _check_imaging_request
 
  Parameters  : 
@@ -1090,45 +898,12 @@ EOF
 sub _check_imaging_request {
 	my $self               = shift;
 	my $request_id         = $self->data->get_request_id();
-	my $reservation_id     = $self->data->get_reservation_id();
-	my $request_forimaging = $self->data->get_request_forimaging();
-	
-	notify($ERRORS{'DEBUG'}, 0, "checking if request is imaging or if forimaging flag has changed");
 	
-	# Call is_request_imaging
-	# -returns 'image' if request state or laststate = image
-	# -returns 'forimaging' if request state and laststate != image, and forimaging = 1
-	# -returns 0 if request state and laststate != image, and forimaging = 0
-	# -returns undefined if an error occurred
 	my $imaging_result = is_request_imaging($request_id);
-	
 	if ($imaging_result eq 'image') {
 		notify($ERRORS{'OK'}, 0, "image creation process has begun, exiting");
 		exit;
 	}
-	elsif ($imaging_result eq 'forimaging') {
-		if ($request_forimaging != 1) {
-			notify($ERRORS{'OK'}, 0, "request forimaging flag has changed to 1, updating data structure");
-			$self->data->set_request_forimaging(1);
-		}
-		return 1;
-	}
-	elsif ($imaging_result == 0) {
-		if ($request_forimaging != 0) {
-			notify($ERRORS{'OK'}, 0, "request forimaging flag has changed to 0, updating data structure");
-			$self->data->set_request_forimaging(0);
-		}
-		return 0;
-	}
-	elsif (!defined($imaging_result)) {
-		notify($ERRORS{'WARNING'}, 0, "failed to retrieve request imaging values from database");
-		return;
-	}
-	else {
-		notify($ERRORS{'WARNING'}, 0, "unexpected result returned from is_request_imaging: $imaging_result");
-		return;
-	}
-	
 }
 #/////////////////////////////////////////////////////////////////////////////
 

Modified: vcl/trunk/managementnode/lib/VCL/new.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/new.pm?rev=1492689&r1=1492688&r2=1492689&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/new.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/new.pm Thu Jun 13 14:40:45 2013
@@ -292,11 +292,9 @@ sub process {
 	
 	if ($request_state_name eq 'tovmhostinuse' && ($image_name =~ /noimage/i || $computer_provisioning_name =~ /none/i)) {
 		notify($ERRORS{'OK'}, 0, "$computer_short_name will not be reloaded, image: $image_name, provisioning name: $computer_provisioning_name");
-		insertloadlog($reservation_id, $computer_id, "nodeready", "VM host $computer_short_name is not configured to be automatically loaded");
 	}
 	elsif ($self->reload_image()) {
 		notify($ERRORS{'OK'}, 0, "$computer_short_name is loaded with $image_name");
-		insertloadlog($reservation_id, $computer_id, "nodeready", "$computer_short_name is loaded with $image_name");
 	}
 	elsif ($request_preload_only) {
 		# Load failed preload only = true
@@ -351,8 +349,8 @@ sub process {
 
 	# Parent only checks and waits for any other images to complete and checkin
 	if ($reservation_is_parent && $reservation_count > 1) {
-		insertloadlog($reservation_id, $computer_id, "info", "cluster based reservation");
-
+		insertloadlog($reservation_id, $computer_id, "nodeready", "$computer_short_name is loaded with $image_name (cluster parent)");
+		
 		# Wait on child reservations
 		if ($self->wait_for_child_reservations()) {
 			notify($ERRORS{'OK'}, 0, "done waiting for child reservations, they are all ready");
@@ -421,15 +419,7 @@ sub process {
 				# Call reservation_failed, problem computer not opened for reservation
 				$self->reservation_failed("process failed after attempting to reserve the computer");
 			}
-
-			# Insert a row into the computerloadlog table
-			if (insertloadlog($reservation_id, $computer_id, "reserved", "$computer_short_name successfully reserved with $image_name")) {
-				notify($ERRORS{'OK'}, 0, "inserted computerloadlog entry, load state=reserved");
-			}
-			else {
-				notify($ERRORS{'WARNING'}, 0, "failed to insert computerloadlog entry, load state=reserved");
-			}
-
+			
 			# Set variables for the next states
 			# Don't change state of computer to reserved yet, reserved.pm will do this after it initializes
 			# This is done to reduce the delay between when Connect is shown to the user and the firewall is prepared
@@ -471,15 +461,10 @@ sub process {
 	else {
 		notify($ERRORS{'OK'}, 0, "this is a child image, request state NOT changed to '$next_request_state'");
 	}
-
-	# Insert a row into the computerloadlog table
-	if (insertloadlog($reservation_id, $computer_id, "info", "$computer_short_name successfully set to $next_computer_state with $image_name")) {
-		notify($ERRORS{'OK'}, 0, "inserted computerloadlog entry: $computer_short_name successfully set to $next_computer_state with $image_name");
-	}
-	else {
-		notify($ERRORS{'WARNING'}, 0, "failed to insert computerloadlog entry: $computer_short_name successfully set to $next_computer_state with $image_name");
-	}
-
+	
+	# Add nodeready last before process exits, this is used by the cluster parent to determine when child reservations are ready
+	insertloadlog($reservation_id, $computer_id, "nodeready", "$computer_short_name is loaded with $image_name");
+	
 	notify($ERRORS{'OK'}, 0, "exiting");
 	exit;
 
@@ -1209,15 +1194,15 @@ sub wait_for_child_reservations {
 			notify($ERRORS{'OK'}, 0, "waiting for $loop_iteration_delay seconds");
 			sleep $loop_iteration_delay;
 		}
-
+		
 		# Check if request has been deleted
 		if (is_request_deleted($request_id)) {
 			notify($ERRORS{'OK'}, 0, "request has been deleted, setting computer state to 'available' and exiting");
-
+			
 			# Update state of computer and exit
 			switch_state($request_data, '', 'available', '', '1');
 		}
-
+		
 		# Check if all of the reservations are ready according to the computerloadlog table
 		my $computerloadlog_reservations_ready = reservations_ready($request_id);
 		if ($computerloadlog_reservations_ready) {
@@ -1238,45 +1223,20 @@ sub wait_for_child_reservations {
 			if ($child_reservation_id == $reservation_id) {
 				next RESERVATION_LOOP;
 			}
-
+			
 			# Get the computer ID of the child reservation
 			my $child_computer_id = $request_data->{reservation}{$child_reservation_id}{computer}{id};
 			notify($ERRORS{'DEBUG'}, 0, "checking reservation $child_reservation_id: computer ID=$child_computer_id");
-
+			
 			# Get the child reservation's current computer state
 			my $child_computer_state = get_computer_current_state_name($child_computer_id);
 			notify($ERRORS{'DEBUG'}, 0, "reservation $child_reservation_id: computer state=$child_computer_state");
-
-			# Check child reservation's computer state, is it reserved?
-			if ($child_computer_state eq "reserved") {
-				notify($ERRORS{'OK'}, 0, "ready: reservation $child_reservation_id computer state is reserved");
-			}
-			elsif ($child_computer_state eq "reloading") {
-				notify($ERRORS{'OK'}, 0, "not ready: reservation $child_reservation_id is still reloading");
-				next WAITING_LOOP;
-			}
-			elsif ($child_computer_state eq "available" && $loop_iteration > 2) {
-				# Child computer may still be in the available state if the request start is recent
-				# Warn if still in available state after this subroutine has iterated a couple times
-				notify($ERRORS{'WARNING'}, 0, "not ready: reservation $child_reservation_id: computer state is still $child_computer_state");
-				next WAITING_LOOP;
-			}
-			elsif ($child_computer_state eq "available") {
-				notify($ERRORS{'OK'}, 0, "not ready: reservation $child_reservation_id: reloading has not begun yet");
-				next WAITING_LOOP;
-			}
-			elsif ($child_computer_state =~ /^(failed|maintenance|deleted)$/) {
-				notify($ERRORS{'WARNING'}, 0, "abort: reservation $child_reservation_id: computer was put into maintenance, returning");
+			
+			if ($child_computer_state =~ /^(failed|maintenance)$/) {
+				notify($ERRORS{'WARNING'}, 0, "aborting, child reservation $child_reservation_id computer state: $child_computer_state");
 				return;
 			}
-			else {
-				notify($ERRORS{'WARNING'}, 0, "unexpected: reservation $child_reservation_id: computer in unexpected state: $child_computer_state");
-				next WAITING_LOOP;
-			}
 		} ## end foreach my $child_reservation_id (@reservation_ids)
-
-		notify($ERRORS{'OK'}, 0, "all child reservations are ready, returning 1");
-		return 1;
 	} ## end for (my $loop_iteration = 1; $loop_iteration...
 
 	# If out of main loop, waited maximum amount of time

Modified: vcl/trunk/managementnode/lib/VCL/reserved.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/reserved.pm?rev=1492689&r1=1492688&r2=1492689&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/reserved.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/reserved.pm Thu Jun 13 14:40:45 2013
@@ -106,16 +106,19 @@ sub process {
 	my $server_request_id	        = $self->data->get_server_request_id();
 	my $acknowledge_timeout_seconds = $self->data->get_variable('acknowledgetimeout') || 900;
 	my $connect_timeout_seconds     = $self->data->get_variable('connecttimeout') || 900;
+	my $is_parent_reservation       = $self->data->is_parent_reservation();
 	
 	# Update the log loaded time to now for this request
 	update_log_loaded_time($request_logid);
 	
+	insertloadlog($reservation_id, $computer_id, "reserved", "$computer_short_name successfully reserved");
+	
 	# Update the computer state to reserved
 	# This causes pending to change to the Connect button on the Current Reservations page
 	update_computer_state($computer_id, 'reserved');
 	
 	# Wait for the user to acknowledge the request by clicking Connect button or from API
-	if (!$self->code_loop_timeout(sub{$self->has_user_acknowledged()}, [], 'waiting for user acknowledgement', $acknowledge_timeout_seconds, 1, 10)) {
+	if (!$self->code_loop_timeout(sub{$self->user_acknowledged()}, [], 'waiting for user acknowledgement', $acknowledge_timeout_seconds, 1, 10)) {
 		$self->_notify_user_timeout($request_data);
 		switch_state($request_data, 'timeout', 'timeout', 'noack', 1);
 	}
@@ -142,48 +145,14 @@ sub process {
 		$self->reservation_failed("OS module post_reserve failed");
 	}
 	
-	# Wait for the user to connect to the computer
-	# This calls process_connect_methods
-	my $connected_result = $self->os->is_user_connected(($connect_timeout_seconds / 60));
-	
-	# Check once more if request has been deleted
-	if ($connected_result =~ /deleted/ || is_request_deleted($request_id)) {
-		notify($ERRORS{'OK'}, 0, "request deleted, exiting");
-		exit;
-	}
-	elsif ($connected_result =~ /(nologin)/) {
-		# Check if user connection check should be ignored
-		if (!$imagemeta_checkuser) {
-			notify($ERRORS{'OK'}, 0, "ignoring user connection check, imagemeta checkuser flag is false");
-		}
-		elsif ($reservation_count > 1) {
-			notify($ERRORS{'OK'}, 0, "ignoring user connection check, cluster reservation");
-		}
-		elsif ($request_forimaging){
-			notify($ERRORS{'OK'}, 0, "ignoring user connection check, image creation reservation");
-		}
-		elsif ($server_request_id) {
-			notify($ERRORS{'OK'}, 0, "ignoring user connection check, server reservation");
-		}
-		else {
-			# Default case, user never connected, timeout
-			$self->_notify_user_timeout($request_data);
-			switch_state($request_data, 'timeout', 'timeout', 'nologin', 1);
+	# For cluster reservations, the parent must wait until all child reserved processes have exited
+	# Otherwise, the state will change to inuse while the child processes are still finishing up the reserved state
+	# vcld will then fail to fork inuse processes for the child reservations
+	if ($reservation_count > 1 && $is_parent_reservation) {
+		if (!$self->code_loop_timeout(sub{$self->is_child_process_running()}, [], 'waiting for child reserved processes to exit', 3*60, 5)) {
+			$self->reservation_failed('child reservation reserved processes did not exit');
 		}
 	}
-	else {
-		insertloadlog($reservation_id, $computer_id, "connected", "reserved: user connected to $computer_short_name");
-	}
-	
-	# Process the connect methods again, lock the firewall down to the address the user connected from
-	my $remote_ip = $self->data->get_reservation_remote_ip();
-	if (!$self->os->process_connect_methods($remote_ip, 1)) {
-		notify($ERRORS{'CRITICAL'}, 0, "failed to process connect methods after user connected to computer");
-	}
-	
-	# Update the lastcheck value for this reservation to now so that inuse does not begin checking immediately
-	# If this is a cluster request, update lastcheck for all reservations so they also don't attempt to process the inuse state immediately
-	update_reservation_lastcheck(@reservation_ids);
 	
 	# Change the request and computer state to inuse then exit
 	switch_state($request_data, 'inuse', 'inuse', '', 1);
@@ -191,7 +160,41 @@ sub process {
 
 #/////////////////////////////////////////////////////////////////////////////
 
-=head2 has_user_acknowledged
+=head2 is_child_process_running
+
+ Parameters  : none
+ Returns     : boolean
+ Description : 
+
+=cut
+
+sub is_child_process_running {
+	my $self = shift;
+	if (ref($self) !~ /VCL::reserved/) {
+		notify($ERRORS{'CRITICAL'}, 0, "subroutine can only be called as a class method of a VCL::reserved object");
+		return;
+	}
+	
+	my $request_id = $self->data->get_request_id();
+	my $reservation_id = $self->data->get_reservation_id();
+	
+	my @reservation_ids = $self->data->get_reservation_ids();
+	@reservation_ids = grep { $_ ne $reservation_id} @reservation_ids;
+	
+	my $pattern = "$request_id:(" . join('|', @reservation_ids) . ")";
+	if (my @pids = is_management_node_process_running($pattern)) {
+		notify($ERRORS{'DEBUG'}, 0, "child processes are running: " . join(", ", @pids));
+		return 0;
+	}
+	else {
+		notify($ERRORS{'DEBUG'}, 0, "no child processes running");
+		return 1;
+	}
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 user_acknowledged
 
  Parameters  : none
  Returns     : boolean
@@ -203,7 +206,7 @@ sub process {
 
 =cut
 
-sub has_user_acknowledged {
+sub user_acknowledged {
 	my $self = shift;
 	if (ref($self) !~ /VCL::reserved/) {
 		notify($ERRORS{'CRITICAL'}, 0, "subroutine can only be called as a class method of a VCL::reserved object");
@@ -253,6 +256,7 @@ sub _notify_user_timeout {
 	my $affiliation_helpaddress    = $self->data->get_user_affiliation_helpaddress();
 	my $image_prettyname           = $self->data->get_image_prettyname();
 	my $computer_ip_address        = $self->data->get_computer_ip_address();
+	my $is_parent_reservation      = $self->data->is_parent_reservation();
 
 	my $message = <<"EOF";
 
@@ -278,7 +282,7 @@ EOF
 
 	my $subject = "VCL -- Reservation Timeout";
 
-	if ($user_emailnotices) {
+	if ($is_parent_reservation && $user_emailnotices) {
 		#if  "0" user does not care to get additional notices
 		mail($user_email, $subject, $message, $affiliation_helpaddress);
 		notify($ERRORS{'OK'}, 0, "sent reservation timeout e-mail to $user_email");

Modified: vcl/trunk/managementnode/lib/VCL/utils.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=1492689&r1=1492688&r2=1492689&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/utils.pm Thu Jun 13 14:40:45 2013
@@ -77,8 +77,6 @@ use XML::Simple;
 use Time::HiRes qw(gettimeofday tv_interval);
 use Crypt::OpenSSL::RSA;
 
-#use Date::Calc qw(Delta_DHMS Time_to_Date Date_to_Time);
-
 require Exporter;
 our @ISA = qw(Exporter);
 
@@ -131,6 +129,7 @@ our @EXPORT = qw(
   get_imagemeta_info
   get_imagerevision_info
   get_current_image_contents_noDS
+  get_current_reservation_lastcheck
   get_local_user_info
   get_management_node_blockrequests
   get_management_node_computer_ids
@@ -145,6 +144,7 @@ our @EXPORT = qw(
   get_production_imagerevision_info
   get_random_mac_address
   get_request_by_computerid
+  get_request_computerloadstate_names
   get_request_current_state_name
   get_request_end
   get_request_info
@@ -658,17 +658,22 @@ sub notify {
 	$string =~ s/\s*\n\s*/\n/gs;
 	
 	# Replace consecutive spaces with a single space to keep log file concise as long as string doesn't contain a quote
-	if ($string !~ /[\'\"]/gs) {
+	if ($string !~ /[\'\"]/gs && $string !~ /\s:\s/gs) {
 		$string =~ s/[ \t]+/ /gs;
 	}
 
 	# Assemble the process identifier string
-	my $process_identifier = $PID;
-	$process_identifier .= "|$ENV{request_id}:$ENV{reservation_id}" if (defined $ENV{request_id} && defined $ENV{reservation_id});
-	$process_identifier .= "|$ENV{state}" if (defined $ENV{state});
+	my $process_identifier;
+	$process_identifier .= "|$PID|";
+	$process_identifier .= $ENV{request_id} if defined $ENV{request_id};
+	$process_identifier .= "|";
+	$process_identifier .= $ENV{reservation_id} if defined $ENV{reservation_id};
+	$process_identifier .= "|";
+	$process_identifier .= $ENV{state} || 'vcld';
+	$process_identifier .= "|$filename:$sub|$line";
 
 	# Assemble the log message
-	my $log_message = "$currenttime|$process_identifier|$caller_info|$string";
+	my $log_message = "$currenttime$process_identifier|$string";
 
 	# Format the data if WARNING or CRITICAL, and @data was passed
 	my $formatted_data;
@@ -794,7 +799,7 @@ END
 
 	# Add the process identifier to every line of the log message
 	chomp $log_message;
-	$log_message =~ s/\n([^\n])/\n|$process_identifier| $1/g;
+	$log_message =~ s/\n([^\n])/\n$process_identifier| $1/g;
 	
 	# Check if the logfile path has been set and not running in daemon mode and redirect output to log file
 	# No need to redirect in daemon mode because STDOUT is redirected by vcld
@@ -897,34 +902,34 @@ sub convert_to_epoch_seconds {
 
 sub check_endtimenotice_interval {
 	my $end = $_[0];
-	my ($package, $filename, $line, $sub) = caller(0);
 	notify($ERRORS{'WARNING'}, 0, "endtime not set") if (!defined($end));
+	
 	my $now      = convert_to_epoch_seconds();
 	my $epochend = convert_to_epoch_seconds($end);
 	my $epoch_until_end = $epochend - $now;
-
+	
 	notify($ERRORS{'OK'}, 0, "endtime= $end epoch_until_end= $epoch_until_end");
-
+	
 	my $diff_seconds = $epoch_until_end;
 	
 	my $diff_weeks = int($epoch_until_end/604800);
 	$diff_seconds -= $diff_weeks * 604800;
 	
 	my $diff_days = int($diff_seconds/86400);
-        my $Total_days = int($epoch_until_end/86400);
+	my $Total_days = int($epoch_until_end/86400);
 	$diff_seconds -= $diff_days * 86400;
-        
+	
 	my $diff_hours = int($diff_seconds/3600);
-        $diff_seconds -= $diff_hours * 3600;
-
-        my $diff_minutes = int($diff_seconds/60);
-        $diff_seconds -= $diff_minutes * 60;
+	$diff_seconds -= $diff_hours * 3600;
+	
+	my $diff_minutes = int($diff_seconds/60);
+	$diff_seconds -= $diff_minutes * 60;
 	
 	notify($ERRORS{'OK'}, 0, "End Time is in: $diff_weeks week\(s\) $diff_days day\(s\) $diff_hours hour\(s\) $diff_minutes min\(s\) and $diff_seconds sec\(s\)");
-
+	
 	#flag on: 2 & 1 week; 2,1 day, 1 hour, 30,15,10,5 minutes
 	#ignore over 2weeks away
-	if($diff_weeks >= 2){ 
+	if($diff_weeks >= 2){
 		return 0;
 	}
 	#2 week: between 14 days and a 14 day -6 minutes window
@@ -936,25 +941,23 @@ sub check_endtimenotice_interval {
 		return 0;
 	}
 	# 1 week notice: between 7 days and a 7 day -6 minute window
-        elsif ($Total_days >= 6 && $diff_hours >= 23 && $diff_minutes >= 55) {
-           return "1 week";
-        }
-       	# Ignore: between 2 days and 7 day - 15 minute window
-       	elsif ($Total_days >= 2) {
-               return 0;
-       	}
-       	# 2 day notice: between 2 days and a 2 day -6 minute window
-       	elsif($Total_days >= 1 && $diff_hours >= 23 && $diff_minutes >= 55) {
-           return "2 days";
-       	}
-	 # 1 day notice: between 1 days and a 1 day -6 minute window
+	elsif ($Total_days >= 6 && $diff_hours >= 23 && $diff_minutes >= 55) {
+		return "1 week";
+	}
+	# Ignore: between 2 days and 7 day - 15 minute window
+	elsif ($Total_days >= 2) {
+		return 0;
+	}
+	# 2 day notice: between 2 days and a 2 day -6 minute window
+	elsif($Total_days >= 1 && $diff_hours >= 23 && $diff_minutes >= 55) {
+		return "2 days";
+	}
+	# 1 day notice: between 1 days and a 1 day -6 minute window
 	elsif($Total_days >= 0 && $diff_hours >= 23 && $diff_minutes >= 55) {
-    		return "24 hours";
+		return "24 hours";
 	}
-
-	return 0; 
-	
 	
+	return 0;
 } ## end sub check_endtimenotice_interval
 
 #/////////////////////////////////////////////////////////////////////////////
@@ -2079,6 +2082,48 @@ sub get_reservation_accounts {
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 get_current_reservation_lastcheck
+
+ Parameters  : $reservation_id
+ Returns     : string
+ Description : Retrieves the current value of reservation.lastcheck from the
+               database.
+
+=cut
+
+sub get_current_reservation_lastcheck {
+	my ($reservation_id) = @_;
+
+	# Check the passed parameter
+	if (!defined($reservation_id)) {
+		notify($ERRORS{'WARNING'}, 0, "reservation ID was not specified");
+		return;
+	}
+
+	# Create the select statement
+	my $select_statement = <<EOF;
+SELECT
+reservation.lastcheck
+FROM
+reservation
+WHERE
+reservation.id = $reservation_id
+EOF
+
+	my @selected_rows = database_select($select_statement);
+
+	# Check to make sure 1 row was returned
+	if (!@selected_rows) {
+		notify($ERRORS{'WARNING'}, 0, "failed to retrieve current reservation lastcheck for reservation $reservation_id");
+		return;
+	}
+	
+	my $row = $selected_rows[0];
+	return $row->{lastcheck};
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
 =head2 update_reservation_accounts
 
  Parameters  : $reservation_id, $userid, $password, $mode
@@ -4494,8 +4539,7 @@ sub get_default_imagemeta_info {
 	$ENV{imagemeta_info}{default} = $default_imagemeta_info;
 	
 	my %default_imagemeta_info_copy = %{$ENV{imagemeta_info}{default}};
-	
-	notify($ERRORS{'DEBUG'}, 0, "retrieved default imagemeta info:\n" . format_data(\%default_imagemeta_info_copy));
+	#notify($ERRORS{'DEBUG'}, 0, "retrieved default imagemeta info:\n" . format_data(\%default_imagemeta_info_copy));
 	return \%default_imagemeta_info_copy;
 }
 
@@ -4802,10 +4846,10 @@ sub run_ssh_command {
 
 		# Print the SSH command, only display the attempt # if > 1
 		if ($attempts == 1) {
-			notify($ERRORS{'DEBUG'}, 0, "executing SSH command on $node:\n$ssh_command") if $output_level;
+			notify($ERRORS{'DEBUG'}, 0, "executing SSH command on $node: '$command'") if $output_level;
 		}
 		else {
-			notify($ERRORS{'DEBUG'}, 0, "attempt $attempts/$max_attempts: executing SSH command on $node:\n$ssh_command") if $output_level;
+			notify($ERRORS{'DEBUG'}, 0, "attempt $attempts/$max_attempts: executing SSH command on $node: '$ssh_command'") if $output_level;
 		}
 		
 		# Enclose SSH command in an eval block and use alarm to eventually timeout the SSH command if it hangs
@@ -4919,22 +4963,7 @@ sub run_ssh_command {
 			my @output_lines = split(/[\r\n]+/, $ssh_output);
 			
 			# Print the output unless no_output is set
-			notify($ERRORS{'DEBUG'}, 0, "run_ssh_command output:\n" . join("\n", @output_lines)) if $output_level > 1;
-			
-			# Print the command and exit status
-			(my $ssh_output_summary = $ssh_output) =~ s/\s+/ /gs;
-			if (length($ssh_output_summary) > 30) {
-				$ssh_output_summary = substr($ssh_output_summary, 0, 30);
-				$ssh_output_summary .= "...";
-			}
-			
-			# Display the full ssh command if the exit status is not 0
-			if ($exit_status) {
-				notify($ERRORS{'OK'}, 0, "SSH command executed on $node, command:\n$ssh_command\nreturning ($exit_status, \"$ssh_output_summary\")") if $output_level > 1;
-			}
-			else {
-				notify($ERRORS{'DEBUG'}, 0, "SSH command executed on $node, returning ($exit_status, \"$ssh_output_summary\")") if $output_level > 1;
-			}
+			notify($ERRORS{'DEBUG'}, 0, "command: '$command', output:\n" . join("\n", @output_lines)) if $output_level > 1;
 			
 			# Return the exit status and output
 			return ($exit_status, \@output_lines);
@@ -6148,8 +6177,10 @@ sub update_log_ending {
 =head2 update_reservation_lastcheck
 
  Parameters  : $reservation_id or @reservation_ids
- Returns     : boolean
- Description :
+ Returns     : string
+ Description : Updates reservation.lastcheck to the current time. The argument
+               may be a single reservation ID or an array of IDs. The timestamp
+               which lastcheck was set to is returned.
 
 =cut
 
@@ -6161,26 +6192,28 @@ sub update_reservation_lastcheck {
 		notify($ERRORS{'WARNING'}, 0, "reservation ID was not specified");
 		return;
 	}
-
 	my $reservation_id_string = join(', ', @reservation_ids);
 	
+	# Must use an explicit timestamp, can't use NOW() because calling subroutine may need the exact value this is set to
+	my $lastcheck = makedatestring();
+	
 	# Construct the update statement
 	my $update_statement = <<EOF;
 UPDATE
 reservation
 SET
-reservation.lastcheck = NOW()
+reservation.lastcheck = '$lastcheck'
 WHERE
 reservation.id IN ($reservation_id_string)
 EOF
 
 	# Call the database execute subroutine
 	if (database_execute($update_statement)) {
-		notify($ERRORS{'DEBUG'}, 0, "updated reservation.lastcheck to now for reservation IDs: $reservation_id_string");
-		return 1;
+		notify($ERRORS{'DEBUG'}, 0, "updated reservation.lastcheck to '$lastcheck' for reservation IDs: $reservation_id_string");
+		return $lastcheck;
 	}
 	else {
-		notify($ERRORS{'WARNING'}, 0, "failed to update reservation.lastcheck to now for reservation IDs: $reservation_id_string");
+		notify($ERRORS{'WARNING'}, 0, "failed to update reservation.lastcheck to '$lastcheck' for reservation IDs: $reservation_id_string");
 		return;
 	}
 } ## end sub update_reservation_lastcheck
@@ -8564,6 +8597,58 @@ sub reservations_ready {
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 get_request_computerloadstate_names
+
+ Parameters  :  $request_id
+ Returns     :  hash reference
+ Description : Retrieves the computerloadlog entries for all reservations
+               belonging to the request. A hash is constructed with keys set to
+               the reservation IDs. The data of each key is a reference to an
+               array containing the computerloadstate names, sorted from newest
+               computerloadlog entry to oldest.
+
+=cut
+
+sub get_request_computerloadstate_names {
+	my ($request_id) = @_;
+	if (!$request_id) {
+		notify($ERRORS{'WARNING'}, 0, "request ID argument was not passed");
+		return;
+	}
+
+	my $select_statement = <<EOF;
+SELECT
+computerloadlog.reservationid,
+computerloadstate.loadstatename
+
+FROM
+request,
+reservation
+
+LEFT JOIN (computerloadlog, computerloadstate) ON (
+computerloadlog.reservationid = reservation.id
+AND computerloadlog.loadstateid = computerloadstate.id
+)
+
+WHERE
+request.id = $request_id
+AND reservation.requestid = request.id
+ORDER BY computerloadlog.timestamp DESC
+EOF
+
+	my @rows = database_select($select_statement);
+	
+	my $computerloadlog_info = {};
+	for my $row (@rows) {
+		push @{$computerloadlog_info->{$row->{reservationid}}}, $row->{loadstatename};
+	}
+	
+	notify($ERRORS{'DEBUG'}, 0, "retrieved computerloadlog info for request:\n" . format_data($computerloadlog_info));
+	return $computerloadlog_info;
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
 =head2 reservation_being_processed
 
  Parameters  :  reservation ID
@@ -10554,19 +10639,19 @@ sub stopwatch {
 	
 	$ENV{'current'} = [$seconds, $microseconds];
 	
-	my $message = "stopwatch - $ENV{'stopwatch_count'}: ";
+	my $message = "[stopwatch] $ENV{'stopwatch_count'}: ";
 	$message .= "$title " if defined($title);
 	$title = '<none>' if !defined($title);
 	
-	my $previous_delta = tv_interval($ENV{'previous'}, $ENV{'current'});
-	my $start_delta = tv_interval($ENV{'start'}, $ENV{'current'});
+	my $previous_delta = sprintf("%.2f", tv_interval($ENV{'previous'}, $ENV{'current'}));
+	my $start_delta = sprintf("%.2f", tv_interval($ENV{'start'}, $ENV{'current'}));
 	
 	$start_delta = 0 if $start_delta =~ /e/;
 	$previous_delta = 0 if $previous_delta =~ /e/;
 	
-	$message .= "+$previous_delta ($start_delta)";
+	$message .= "(previous/start: +$previous_delta/+$start_delta)";
 	
-	print "$message\n";
+	print "\n$message\n\n";
 	
 	my $info = {
 		current => $ENV{'current'},