Author: arkurth
Date: Thu May 25 18:52:54 2017
New Revision: 1796182

URL: http://svn.apache.org/viewvc?rev=1796182&view=rev
Log:
VCL-1051
Added checks in State.pm::state_exit for checkpoint state.

Removed condition that prevented the request state from being updated to 
'complete' if current request state is 'deleted' and the new request state is 
anything other than 'complete'. If state_exit got called during the 'deleted' 
state with arguments set to 'failed', the request state would be left in 
'pending' when the process ended.

VCL-887
Changed call in new.pm::process from switch_state to state_exit.

Removed no longer used utils.pm::switch_state subroutine.

Removed unused $self->data->get_* variables from new.pm.

Other
Removed unreachable call to exit; in reclaim.pm.

Modified:
    vcl/trunk/managementnode/lib/VCL/Module/State.pm
    vcl/trunk/managementnode/lib/VCL/new.pm
    vcl/trunk/managementnode/lib/VCL/reclaim.pm

Modified: vcl/trunk/managementnode/lib/VCL/Module/State.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/State.pm?rev=1796182&r1=1796181&r2=1796182&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/State.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/State.pm Thu May 25 18:52:54 2017
@@ -945,7 +945,7 @@ sub state_exit {
                
                if ($request_state_name_new) {
                        # Never set request state to failed if previous state 
is image
-                       if ($request_state_name_old eq 'image' && 
$request_state_name_new !~ /(complete|maintenance)/) {
+                       if ($request_state_name_old =~ /(image|checkpoint)/ && 
$request_state_name_new !~ /(complete|maintenance)/) {
                                notify($ERRORS{'CRITICAL'}, 0, "previous 
request state is $request_state_name_old, not setting request state to 
$request_state_name_new, setting request and computer state to maintenance");
                                $request_state_name_new = 'maintenance';
                                $computer_state_name_new = 'maintenance';
@@ -973,18 +973,7 @@ sub state_exit {
                }
                
                if ($nat_sanitize_needed) {
-                       if (!$self->nathost_os(0)) {
-                               notify($ERRORS{'WARNING'}, 0, "unable to 
sanitize firewall rules from NAT host $nathost_hostname, NAT host OS object is 
not available");
-                       }
-                       elsif (!$self->nathost_os->firewall()) {
-                               notify($ERRORS{'WARNING'}, 0, "unable to 
sanitize firewall rules from NAT host $nathost_hostname, NAT host OS object's 
firewall method returned false");
-                       }
-                       elsif 
(!$self->nathost_os->firewall->can('nat_sanitize_reservation')) {
-                               notify($ERRORS{'WARNING'}, 0, "unable to 
sanitize firewall rules from NAT host $nathost_hostname, NAT host OS firewall 
object does not implement a 'nat_sanitize_reservation' method");
-                       }
-                       else {
-                               
$self->nathost_os->firewall->nat_sanitize_reservation();
-                       }
+                       $self->nathost_os->firewall->nat_sanitize_reservation();
                }
        }
        
@@ -1058,14 +1047,9 @@ sub state_exit {
                        }
                }
                else {
-                       # Current request state = 'deleted'
-                       if ($request_state_name_new =~ /(complete)/) {
-                               if (!update_request_state($request_id, 
$request_state_name_new, $request_state_name_old)) {
-                                       notify($ERRORS{'WARNING'}, 0, "failed 
to change request state: $request_state_name_old/$request_laststate_name_old 
--> $request_state_name_new/$request_state_name_old");
-                               }
-                       }
-                       else {
-                               notify($ERRORS{'WARNING'}, 0, "request state 
not updated: $request_state_name_old --> $request_state_name_new");
+                       # Current request state = 'deleted', always set the 
request state to 'complete'
+                       if (!update_request_state($request_id, 'complete', 
$request_state_name_old)) {
+                               notify($ERRORS{'WARNING'}, 0, "failed to change 
request state: $request_state_name_old/$request_laststate_name_old --> 
$request_state_name_new/$request_state_name_old");
                        }
                }
        }

Modified: vcl/trunk/managementnode/lib/VCL/new.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/new.pm?rev=1796182&r1=1796181&r2=1796182&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/new.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/new.pm Thu May 25 18:52:54 2017
@@ -88,7 +88,6 @@ use VCL::utils;
 sub process {
        my $self = shift;
        
-       my $request_data                    = $self->data->get_request_data();
        my $request_id                      = $self->data->get_request_id();
        my $request_state_name              = 
$self->data->get_request_state_name();
        my $request_preload_only            = 
$self->data->get_request_preload_only();
@@ -103,7 +102,6 @@ sub process {
        my $image_id                        = $self->data->get_image_id();
        my $image_name                      = $self->data->get_image_name();
        my $imagerevision_id                = 
$self->data->get_imagerevision_id();
-       my $user_standalone                 = 
$self->data->get_user_standalone();
        
        # If reload state is reload and computer is part of block allocation 
confirm imagerevisionid is the production image.
        if ($request_state_name eq 'reload' && is_inblockrequest($computer_id)) 
{
@@ -350,7 +348,7 @@ sub process {
                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');
+               $self->state_exit(undef, 'available');
        }
        
        my $next_computer_state;
@@ -461,7 +459,6 @@ sub reload_image {
        my $computer_state_name             = 
$self->data->get_computer_state_name();
        my $image_id                        = $self->data->get_image_id();
        my $image_name                      = $self->data->get_image_name();
-       my $image_os_install_type           = 
$self->data->get_image_os_install_type();
        my $imagerevision_id                = 
$self->data->get_imagerevision_id();
        my $server_request_id               = 
$self->data->get_server_request_id();
        my $server_request_fixed_ip         = 
$self->data->get_server_request_fixed_ip();
@@ -648,9 +645,14 @@ sub computer_not_being_used {
        my $image_reloadtime                = 
$self->data->get_image_reload_time();
        my $request_state_name              = 
$self->data->get_request_state_name();
        
-       my $attempt_limit = 5;
+       my $attempt_limit = 10;
        ATTEMPT: for (my $attempt = 1; $attempt <= $attempt_limit; $attempt++) {
-               notify($ERRORS{'OK'}, 0, "attempt $attempt/$attempt_limit: 
checking for competing reservations assigned to $computer_short_name");
+               if ($attempt > 2) {
+                       notify($ERRORS{'OK'}, 0, "attempt 
$attempt/$attempt_limit: sleeping 5 seconds before checking if 
$computer_short_name is not being used");
+                       sleep_uninterrupted(5);
+               }
+               
+               notify($ERRORS{'OK'}, 0, "attempt $attempt/$attempt_limit: 
checking if $computer_short_name is not being used");
                my $computer_state_name = 
$self->data->get_computer_state_name();
                
                # Return 0 if computer state is deleted, vmhostinuse
@@ -668,7 +670,7 @@ sub computer_not_being_used {
                
                # Warn if computer state isn't available or reload - except for 
reinstall requests
                if ($request_state_name !~ /^(reinstall)$/ && 
$computer_state_name !~ /^(available|reload)$/) {
-                       notify($ERRORS{'WARNING'}, 0, "$computer_short_name 
state is $computer_state_name, checking if any conflicting reservations are 
active");
+                       notify($ERRORS{'WARNING'}, 0, "$computer_short_name 
state is $computer_state_name, checking if any competing reservations are 
active");
                }
                
                # Check if there is another request using this machine
@@ -677,20 +679,15 @@ sub computer_not_being_used {
                
                # There should be at least 1 request -- the one being processed
                if (!$competing_request_info) {
-                       notify($ERRORS{'WARNING'}, 0, "failed to retrieve any 
requests for computer id=$computer_id, there should be at least 1");
-                       return;
-               }
-               
-               # Remove the request currently being processed from the hash
-               delete $competing_request_info->{$request_id};
-               
-               if (!keys(%$competing_request_info)) {
-                       notify($ERRORS{'OK'}, 0, "$computer_short_name is not 
assigned to any other reservations");
-                       return 1;
+                       notify($ERRORS{'WARNING'}, 0, "failed to retrieve any 
requests for computer $computer_id, there should probably be at least 1");
+                       next ATTEMPT;
                }
                
                # Loop through the competing requests
                COMPETING_REQUESTS: for my $competing_request_id (sort keys 
%$competing_request_info) {
+                       # Ignore the request currently being processed
+                       next if $competing_request_id == $request_id;
+                       
                        my $competing_reservation_id    = 
$competing_request_info->{$competing_request_id}{data}->get_reservation_id();
                        my $competing_request_state     = 
$competing_request_info->{$competing_request_id}{data}->get_request_state_name();
                        my $competing_request_laststate = 
$competing_request_info->{$competing_request_id}{data}->get_request_laststate_name();
@@ -714,7 +711,7 @@ sub computer_not_being_used {
                        # Check for existing image creation requests
                        if ($competing_request_state =~ /^(image|checkpoint)$/ 
|| $competing_request_laststate =~ /^(image|checkpoint)$/) {
                                notify($ERRORS{'WARNING'}, 0, 
"$computer_short_name is NOT available, it is assigned to an existing imaging 
reservation:\n$competing_request_info_string");
-                               return 0;
+                               next ATTEMPT;
                        }
                        
                        # Check for any requests in the maintenance state
@@ -817,7 +814,7 @@ sub computer_not_being_used {
                                        }
                                        
                                        # Wait for competing process to end 
before verifying that it was successfully killed
-                                       sleep 2;
+                                       sleep_uninterrupted(2);
                                        
                                        # Verify that the competing reservation 
process was killed
                                        if 
(reservation_being_processed($competing_reservation_id)) {
@@ -834,11 +831,11 @@ sub computer_not_being_used {
                        }
                        elsif 
(reservation_being_processed($competing_reservation_id)) {
                                notify($ERRORS{'WARNING'}, 0, "computer 
$computer_short_name is NOT available, assigned overlapping reservations, 
competing reservation is currently being 
processed:\n$competing_request_info_string");
-                               return 0;
+                               next ATTEMPT;
                        }
                        else {
                                notify($ERRORS{'WARNING'}, 0, "computer 
$computer_short_name is NOT available, assigned overlapping reservations, 
competing reservation is NOT currently being 
processed:\n$competing_request_info_string");
-                               return 0;
+                               next ATTEMPT;
                        }
                }
                
@@ -924,7 +921,7 @@ sub reserve_computer {
 
 sub wait_for_child_reservations {
        my $self              = shift;
-       my $request_data      = $self->data->get_request_data();
+       
        my $request_id        = $self->data->get_request_id();
        my @reservation_ids   = $self->data->get_reservation_ids();
        my $reservation_count = $self->data->get_reservation_count();

Modified: vcl/trunk/managementnode/lib/VCL/reclaim.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/reclaim.pm?rev=1796182&r1=1796181&r2=1796182&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/reclaim.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/reclaim.pm Thu May 25 18:52:54 2017
@@ -204,10 +204,6 @@ sub process {
        else {
                $self->state_exit('complete', 'available');
        }
-       
-       notify($ERRORS{'DEBUG'}, 0, "exiting");
-       exit;
-
 } ## end sub process
 
 #//////////////////////////////////////////////////////////////////////////////


Reply via email to