Author: arkurth
Date: Tue Feb 10 23:54:39 2015
New Revision: 1658844

URL: http://svn.apache.org/r1658844
Log:
VCL-816
Added "-n" switch to the command in utils.pm::nmap_port. This causes the 
command to run much faster.

VCL-16
Changed utils.pm::get_request_info to use cached info by default. For large 
cluster requests, each reservation process was retrieving the same image and 
other information over and over - n-squared problem.

VCL-174
Removed section from utils.pm::get_request_info which populates the natport 
table. This was being done by every cluster reservation for all other cluster 
reservations. Moved to State.pm::initialize.

Updated utils.pm::get_computer_info to only call get_computer_nathost_info if a 
nathostcomputermap entry exists for the computer.

Modified:
    vcl/trunk/managementnode/lib/VCL/Module/State.pm
    vcl/trunk/managementnode/lib/VCL/utils.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=1658844&r1=1658843&r2=1658844&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/State.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/State.pm Tue Feb 10 23:54:39 2015
@@ -114,6 +114,16 @@ sub initialize {
                
$self->data->set_reservation_lastcheck_time($reservation_lastcheck);
        }
        
+       # Populate natport table for reservation
+       if ($nathost_id && $request_state_name =~ 
/(new|reserved|modified|test)/) {
+               if (!populate_reservation_natport($reservation_id)) {
+                       $self->reservation_failed("failed to populate natport 
table for reservation");
+               }
+               if (!update_reservation_natlog($reservation_id)) {
+                       notify($ERRORS{'CRITICAL'}, 0, "failed to populate 
natlog table for reservation");
+               }
+       }
+       
        # If this is a cluster request, wait for all reservations to begin 
before proceeding
        if ($reservation_count > 1) {
                if (!$self->wait_for_all_reservations_to_begin('begin', 300, 
30)) {

Modified: vcl/trunk/managementnode/lib/VCL/utils.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=1658844&r1=1658843&r2=1658844&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/utils.pm Tue Feb 10 23:54:39 2015
@@ -2182,8 +2182,9 @@ sub nmap_port {
        my $remote_connection_target = 
determine_remote_connection_target($hostname);
        my $hostname_string = $remote_connection_target;
        $hostname_string .= " ($hostname)" if ($hostname ne 
$remote_connection_target);
-       
-       my $command = "/usr/bin/nmap $remote_connection_target -P0 -p $port -T 
Aggressive";
+
+       my $command = "/usr/bin/nmap $remote_connection_target -P0 -p $port -T 
Aggressive -n";
+
        my ($exit_status, $output) = run_command($command, 1);
        if (!defined($output)) {
                notify($ERRORS{'WARNING'}, 0, "failed to run nmap command on 
management node: '$command'");
@@ -2973,9 +2974,9 @@ sub get_request_info {
                return;
        }
        
-       # Don't use cached info by default
-       if (!defined($no_cache)) {
-               $no_cache = 1;
+       # Use cached info by default
+       if (!$no_cache) {
+               $no_cache = 0;
        }
        
        # Get a hash ref containing the database column names
@@ -3086,21 +3087,6 @@ EOF
                my $computer_info = get_computer_info($computer_id, $no_cache);
                $request_info->{reservation}{$reservation_id}{computer} = 
$computer_info;
                
-               # Populate natport table for reservation
-               # Make sure this wasn't called from 
populate_reservation_natport or else recursive loop will occur
-               my $caller_trace = get_caller_trace(5);
-               if ($caller_trace !~ /populate_reservation_natport/) {
-                       my $request_state_name = $request_info->{state}{name};
-                       if ($request_state_name =~ 
/(new|reserved|modified|test)/) {
-                               if 
(!populate_reservation_natport($reservation_id)) {
-                                       notify($ERRORS{'CRITICAL'}, 0, "failed 
to populate natport table for reservation");
-                               }
-                               if 
(!update_reservation_natlog($reservation_id)) {
-                                       notify($ERRORS{'CRITICAL'}, 0, "failed 
to populate natlog table for reservation");
-                               }
-                       }
-               }
-               
                # Add the connect method info to the hash
                my $connect_method_info = 
get_connect_method_info($imagerevision_id, 0);
                $request_info->{reservation}{$reservation_id}{connect_methods} 
= $connect_method_info;
@@ -3981,7 +3967,7 @@ EOF
        
        # Get the vmhost computer info and add it to the hash
        my $computer_id = $vmhost_info->{computerid};
-       my $computer_info = get_computer_info($computer_id);
+       my $computer_info = get_computer_info($computer_id, $no_cache);
        if ($computer_info) {
                $vmhost_info->{computer} = $computer_info;
        }
@@ -6989,7 +6975,7 @@ sub get_computer_info {
        if (!$no_cache && defined($ENV{computer_info}{$computer_identifier})) {
                return $ENV{computer_info}{$computer_identifier};
        }
-       notify($ERRORS{'DEBUG'}, 0, "retrieving info for computer 
$computer_identifier");
+       #notify($ERRORS{'DEBUG'}, 0, "retrieving info for computer 
$computer_identifier");
        
        # Get a hash ref containing the database column names
        my $database_table_columns = get_database_table_columns();
@@ -7003,6 +6989,7 @@ sub get_computer_info {
                'platform',
                'resource',
                'resourcetype',
+               'nathostcomputermap'
        );
        
        # Construct the select statement
@@ -7051,6 +7038,7 @@ ON (
        AND resource.resourcetypeid = resourcetype.id
        AND resourcetype.name = 'computer'
 )
+LEFT JOIN (nathostcomputermap) ON (nathostcomputermap.computerid = computer.id)
 
 WHERE
 computer.deleted != '1'
@@ -7106,6 +7094,9 @@ EOF
                elsif ($table eq 'resourcetype') {
                        $computer_info->{resource}{$table}{$column} = $value;
                }
+               elsif ($table eq 'nathostcomputermap') {
+                       # Do not add, will retrieve later on
+               }
                else {
                        $computer_info->{$table}{$column} = $value;
                }
@@ -7171,9 +7162,15 @@ EOF
                }
        }
        
-       my $nathost_info = get_computer_nathost_info($computer_id, $no_cache);
-       if ($nathost_info) {
-               $computer_info->{nathost} = $nathost_info;
+       # Check if the computer associated with this reservation is assigned a 
NAT host
+       if (my $nathost_id = $computer_info->{'nathostcomputermap-nathostid'}) {
+               my $nathost_info = get_computer_nathost_info($computer_id, 
$no_cache);
+               if ($nathost_info) {
+                       $computer_info->{nathost} = $nathost_info;
+               }
+               else {
+                       notify($ERRORS{'WARNING'}, 0, "$computer_hostname is 
mapped to NAT host $nathost_id but NAT host info could not be retrieved");
+               }
        }
        
        notify($ERRORS{'DEBUG'}, 0, "retrieved info for computer: 
$computer_identifier");
@@ -7330,7 +7327,7 @@ EOF
                        $nathost_info->{HOSTNAME} = 
$nathost_info->{computer}{hostname};
                }
                else {
-                       my $computer_info = get_computer_info($resource_subid) 
|| {};
+                       my $computer_info = get_computer_info($resource_subid, 
$no_cache) || {};
                        $nathost_info->{HOSTNAME} = $computer_info->{hostname};
                }
        }


Reply via email to