Author: arkurth
Date: Thu May 11 18:58:08 2017
New Revision: 1794871

URL: http://svn.apache.org/viewvc?rev=1794871&view=rev
Log:
VCL-919
Removed all custom $substitution_hashref parameters in calls to 
get_admin_message and get_user_message. The previous values have been added to 
DataStructure.pm so all replacements are consistent.

Replaced substitution code in Module.pm::_get_message_variable with calls to 
DataStructure.pm::substitute_string_variables. This code was mostly duplicated 
and improved in DataStructure.pm.

Added the following keys to DataStructure.pm %SUBROUTINE_MAPPINGS. These allow 
the backend code to update the values in $self->data and have them available to 
be substituted in user and admin values:
* image_capture_type
* notice_interval

Added calls to set_notice_interval in inuse.pm::notify_user_future_endtime and 
notify_user_endtime_imminent so that [notice_interval] is properly replaced in 
messages.

Renamed keys in DataStructure.pm %SUBROUTINE_MAPPINGS:
* request_pid --> process_pid
* request_ppid --> process_ppid

Updated State.pm::initialize to call set_process_pid/ppid rather than passing 
DataStructure object to clunky utils.pm::set_hash_process_id. Removed 
utils.pm::set_hash_process_id.

Removed keys from DataStructure.pm %SUBROUTINE_MAPPINGS:
* request_is_cluster_parent (redundant, replaced calls with 
is_parent_reservation)
* request_is_cluster_child (was not called)


Modified:
    vcl/trunk/managementnode/lib/VCL/DataStructure.pm
    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/image.pm
    vcl/trunk/managementnode/lib/VCL/inuse.pm
    vcl/trunk/managementnode/lib/VCL/utils.pm

Modified: vcl/trunk/managementnode/lib/VCL/DataStructure.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/DataStructure.pm?rev=1794871&r1=1794870&r2=1794871&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/DataStructure.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/DataStructure.pm Thu May 11 18:58:08 2017
@@ -101,6 +101,12 @@ use VCL::utils;
 
 my %SUBROUTINE_MAPPINGS;
 
+# TODO: Move all keys which don't come straight from the database to the top
+$SUBROUTINE_MAPPINGS{process_pid} = '$self->request_data->{PID}';
+$SUBROUTINE_MAPPINGS{process_ppid} = '$self->request_data->{PPID}';
+$SUBROUTINE_MAPPINGS{image_capture_type} = 
'$self->request_data->{IMAGE_CAPTURE_TYPE}';
+$SUBROUTINE_MAPPINGS{notice_interval} = 
'$self->request_data->{NOTICE_INTERVAL}';
+
 $SUBROUTINE_MAPPINGS{blockrequest_id} = 
'$self->blockrequest_data->{BLOCKREQUEST_ID}{id}';
 $SUBROUTINE_MAPPINGS{blockrequest_name} = 
'$self->blockrequest_data->{BLOCKREQUEST_ID}{name}';
 $SUBROUTINE_MAPPINGS{blockrequest_image_id} = 
'$self->blockrequest_data->{BLOCKREQUEST_ID}{imageid}';
@@ -136,9 +142,6 @@ $SUBROUTINE_MAPPINGS{request_id} = '$sel
 $SUBROUTINE_MAPPINGS{request_laststate_id} = 
'$self->request_data->{laststateid}';
 $SUBROUTINE_MAPPINGS{request_log_id} = '$self->request_data->{logid}';
 $SUBROUTINE_MAPPINGS{request_notice_interval} = 
'$self->request_data->{NOTICEINTERVAL}';
-$SUBROUTINE_MAPPINGS{request_is_cluster_parent} = 
'$self->request_data->{PARENTIMAGE}';
-$SUBROUTINE_MAPPINGS{request_pid} = '$self->request_data->{PID}';
-$SUBROUTINE_MAPPINGS{request_ppid} = '$self->request_data->{PPID}';
 $SUBROUTINE_MAPPINGS{request_preload} = '$self->request_data->{preload}';
 $SUBROUTINE_MAPPINGS{request_preload_only} = 
'$self->request_data->{PRELOADONLY}';
 $SUBROUTINE_MAPPINGS{request_reservation_count} = 
'$self->request_data->{RESERVATIONCOUNT}';
@@ -146,7 +149,6 @@ $SUBROUTINE_MAPPINGS{request_start_time}
 $SUBROUTINE_MAPPINGS{request_duration_epoch} = 
'$self->request_data->{DURATION}';
 $SUBROUTINE_MAPPINGS{request_checkuser} = '$self->request_data->{checkuser}';
 #$SUBROUTINE_MAPPINGS{request_stateid} = '$self->request_data->{stateid}';
-$SUBROUTINE_MAPPINGS{request_is_cluster_child} = 
'$self->request_data->{SUBIMAGE}';
 $SUBROUTINE_MAPPINGS{request_test} = '$self->request_data->{test}';
 $SUBROUTINE_MAPPINGS{request_updated} = '$self->request_data->{UPDATED}';
 #$SUBROUTINE_MAPPINGS{request_userid} = '$self->request_data->{userid}';
@@ -819,7 +821,7 @@ sub _automethod : Automethod {
        }
        
        my $calling_subroutine = get_calling_subroutine();
-       
+
        # Check if the sub name is defined in the subroutine mappings hash
        # Return if it isn't
        if (!defined $SUBROUTINE_MAPPINGS{$data_identifier}) {
@@ -2140,7 +2142,7 @@ sub get_reservation_info_string {
                if (defined($reservation_count) && $reservation_count > 1) {
                        $string .= "cluster reservation: yes\n";
                        $string .= "reservation count: $reservation_count\n";
-                       $string .= "parent reservation: " . (defined($_ = 
$self->get_request_is_cluster_parent(0)) ? ($_ ? 'yes' : 'no') : '<undefined>') 
. "\n";
+                       $string .= "parent reservation: " . (defined($_ = 
$self->is_parent_reservation(0)) ? ($_ ? 'yes' : 'no') : '<undefined>') . "\n";
                }
        }
        

Modified: vcl/trunk/managementnode/lib/VCL/Module.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module.pm?rev=1794871&r1=1794870&r2=1794871&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module.pm Thu May 11 18:58:08 2017
@@ -1643,7 +1643,7 @@ sub get_semaphore {
 
 =head2 set_admin_message_variable
 
- Parameters  : $admin_message_key, $subject, $message, $substitution_hashref 
(optional)
+ Parameters  : $admin_message_key, $subject, $message
  Returns     : boolean
  Description : Sets an administrative message variable in the database.
 
@@ -1656,7 +1656,7 @@ sub set_admin_message_variable {
                return;
        }
        
-       my ($admin_message_key, $subject, $message, $substitution_hashref) = @_;
+       my ($admin_message_key, $subject, $message) = @_;
        if (!defined($admin_message_key)) {
                notify($ERRORS{'WARNING'}, 0, "message key argument was not 
supplied");
                return;
@@ -1675,7 +1675,6 @@ sub set_admin_message_variable {
        my $variable_value = {
                subject => $subject,
                message => $message,
-               substitutions => $substitution_hashref,
        };
        
        if (!set_variable($variable_name, $variable_value)) {
@@ -1683,14 +1682,14 @@ sub set_admin_message_variable {
        }
        
        # Test retrieving the variable
-       return $self->get_admin_message($admin_message_key, 
$substitution_hashref);
+       return $self->get_admin_message($admin_message_key);
 }
 
 #//////////////////////////////////////////////////////////////////////////////
 
 =head2 set_user_message_variable
 
- Parameters  : $user_message_key, $affiliation_identifier, $subject, $message, 
$short_message (optional), $substitution_hashref (optional)
+ Parameters  : $user_message_key, $affiliation_identifier, $subject, $message, 
$short_message (optional)
  Returns     : boolean
  Description : Sets a user message variable in the database.
 
@@ -1703,7 +1702,7 @@ sub set_user_message_variable {
                return;
        }
        
-       my ($user_message_key, $affiliation_identifier, $subject, $message, 
$short_message, $substitution_hashref) = @_;
+       my ($user_message_key, $affiliation_identifier, $subject, $message, 
$short_message) = @_;
        if (!defined($user_message_key)) {
                notify($ERRORS{'WARNING'}, 0, "key argument was not supplied");
                return;
@@ -1736,7 +1735,6 @@ sub set_user_message_variable {
                subject => $subject,
                message => $message,
                short_message => $short_message,
-               substitutions => $substitution_hashref,
        };
        
        if (!set_variable($variable_name, $variable_value)) {
@@ -1744,14 +1742,14 @@ sub set_user_message_variable {
        }
        
        # Test retrieving the variable
-       return $self->_get_message_variable($user_message_key, 
$substitution_hashref);
+       return $self->_get_message_variable($user_message_key);
 }
 
 #//////////////////////////////////////////////////////////////////////////////
 
 =head2 _get_message_variable
 
- Parameters  : $message_key, $substitution_hashref (optional), 
$return_short_message (optional), $admin_message (optional)
+ Parameters  : $message_key, $return_short_message (optional), $admin_message 
(optional)
  Returns     : array context, array: ($subject, $message)
                scalar context, string: $message
  Description : Retrieves message components from the variable table in the
@@ -1795,37 +1793,11 @@ sub set_user_message_variable {
                * subject (required)
                * message (required)
                * short_message (optional)
-               * substitutions (optional)
                
                The subject and message values will be used when sending email
                messages. The short_message key is optional and will be used 
when
                sending console, desktop, or IM messages to users.
                
-               The substitutions key is optional and is intended to only be 
used
-               to verify when message variables added or modified in the
-               database. Ideally, every variable entry which has custom
-               (uppercase) substitution strings in subject, message, or
-               short_message should have corresponding substitutions hash keys
-               and values:
-               variable.name: 'usermessage|TestKey|Global'
-               variable.value:
-               {
-                  'message' => "[MY_USERNAME]'s reservation will timeout in 
[NOTICE_INTERVAL]",
-                  'substitutions' => {
-                     'MY_USERNAME' => 'some-default-username',
-                     'NOTICE_INTERVAL' => 'xxx minutes',
-                  },
-               }
-               
-               The $substitution_hashref argument must be provided if subject,
-               message, or short_message contains custom strings to be 
replaced.
-               There must be a $substitution_hashref key for every custom,
-               upper-case replacement string. For example:
-               my $message = $self->_get_message_variable('TestKey', { 
'MY_USERNAME' => 'slappy', NOTICE_INTERVAL' => '5 minutes' });
-               
-               ...would return the string:
-               "slappy's reservation will timeout in 5 minutes"
-               
                The $return_short_message argument controls whether to return 
the
                value of message (default) or short_message.
                
@@ -1842,30 +1814,12 @@ sub _get_message_variable {
                return;
        }
        
-       my ($message_key, $substitution_hashref, $return_short_message, 
$admin_message) = @_;
+       my ($message_key, $return_short_message, $admin_message) = @_;
        if (!defined($message_key)) {
                notify($ERRORS{'WARNING'}, 0, "key argument was not supplied");
                return;
        }
        
-       # Initialize hash reference if argument was not supplied
-       if (defined($substitution_hashref)) {
-               my $type = ref($substitution_hashref);
-               if (!$type || $type ne 'HASH') {
-                       notify($ERRORS{'WARNING'}, 0, "substitution argument is 
not a hash reference:\n" . format_data($substitution_hashref));
-                       return;
-               }
-               elsif (keys(%$substitution_hashref)) {
-                       notify($ERRORS{'DEBUG'}, 0, "substitution hash 
reference was specified:\n" . format_data($substitution_hashref));
-               }
-       }
-       else {
-               $substitution_hashref = {};
-       }
-       
-       # Set common substitution values
-       $substitution_hashref->{PID} = $$;
-       
        my $message_type = ($admin_message ? 'admin' : 'user');
        
        # Assemble the variable name
@@ -1896,7 +1850,7 @@ sub _get_message_variable {
        # Make sure the variable contains subject key
        my $subject = $variable->{subject};
        if (!defined($subject)) {
-               notify($ERRORS{'WARNING'}, 0, "unable to retrieve $message_type 
message variable, '$variable_name' variable stored in database does not contain 
a {subject} key:\n" . format_data($variable));
+               notify($ERRORS{'WARNING'}, 0, "unable to retrieve $message_type 
message variable: '$variable_name', variable stored in database does not 
contain a {subject} key:\n" . format_data($variable));
                return;
        }
        
@@ -1914,74 +1868,30 @@ sub _get_message_variable {
        
        # Make sure message was determined
        if (!defined($message)) {
-               notify($ERRORS{'WARNING'}, 0, "unable to retrieve $message_type 
message variable, '$variable_name' variable stored in database does not contain 
a {message} key:\n" . format_data($variable));
+               notify($ERRORS{'WARNING'}, 0, "unable to retrieve $message_type 
message variable: '$variable_name', variable stored in database does not 
contain a {message} key:\n" . format_data($variable));
                return;
        }
        
-       # Extract all substitution string sections from the subject and message 
in the form: [foo]
-       my @substitution_strings = "$subject $message" =~ /\[([\w_]+)\]/g;
-       @substitution_strings = remove_array_duplicates(@substitution_strings);
-       
-       for my $substitution_string (@substitution_strings) {
-               my $substitution_value;
-               
-               # Check if the string matches a key in the optional 
substitution hash reference
-               if (defined($substitution_hashref->{$substitution_string})) {
-                       $substitution_value = 
$substitution_hashref->{$substitution_string};
-                       notify($ERRORS{'DEBUG'}, 0, "determined substitution 
value from supplied hash reference for '$variable_name' $message_type variable: 
$substitution_string --> $substitution_value");
-               }
-               elsif 
(defined($variable->{substitutions}{$substitution_string})) {
-                       $substitution_value = 
$variable->{substitutions}{$substitution_string};
-                       notify($ERRORS{'DEBUG'}, 0, "determined substitution 
value from variable definition substitutions for '$variable_name' $message_type 
variable: $substitution_string --> $substitution_value");
-               }
-               else {
-                       #notify($ERRORS{'DEBUG'}, 0, "substitution hash 
reference does not contain a '$substitution_string' key:\n" . 
format_data($substitution_hashref));
-                       
-                       # Attempt to retrieve the substitution value from the 
DataStructure
-                       # String in subject or message must be in a form such 
as: [image_name]
-                       # Brackets were removed in earlier regex, so 
$substitution_string would now contain: image_name
-                       
-                       # Check if DataStructure.pm implements get_ function
-                       if (!$self->data->can("get_$substitution_string")) {
-                               notify($ERRORS{'CRITICAL'}, 0, "$message_type 
variable: '$variable_name', failed to determine substitution value for 
substitution string: $substitution_string, DataStructure does not implement a 
get_$substitution_string function\n" .
-                                       "substitution hash reference 
argument:\n" . format_data($substitution_hashref) . "\n" .
-                                       "variable definition substitution hash 
reference:\n" . format_data($variable->{substitutions})
-                               );
-                               return;
-                       }
-                       
-                       # Assemble a code string to retrieve the value from the 
DataStructure:
-                       my $eval_string = 
"\$self->data->get_$substitution_string(0)";
-                       
-                       # Evaluate the code string:
-                       $substitution_value = eval $eval_string;
-                       if (defined($substitution_value)) {
-                               #notify($ERRORS{'DEBUG'}, 0, "determined 
DataStructure substitution value: $eval_string --> $substitution_value");
-                       }
-                       else {
-                               $substitution_value = '<undefined>';
-                       }
-               }
-               
-               # Replace the substitution strings in the subject and message
-               $subject =~ s/\[$substitution_string\]/$substitution_value/g;
-               $message =~ s/\[$substitution_string\]/$substitution_value/g;   
+       my $subject_substituted = 
$self->data->substitute_string_variables($subject);
+       my $message_substituted = 
$self->data->substitute_string_variables($message);
+       if (!defined($subject_substituted) || !defined($message_substituted)) {
+               notify($ERRORS{'WARNING'}, 0, "retrieved $message_type message 
variable '$variable_name' but failed to substitute text");
+               return;
        }
        
        # Remove leading and trailing newlines from message
-       $message =~ s/^\n+//g;
-       $message =~ s/\n+$//g;
+       $message_substituted =~ s/(^\n+|\n+$)//g;
        
        if (wantarray) {
-               notify($ERRORS{'DEBUG'}, 0, "retrieved '$variable_name' 
$message_type message variable and substituted text, returning array:\n" .
-                       "subject: $subject\n" .
-                       "message:\n$message"
+               notify($ERRORS{'DEBUG'}, 0, "retrieved $message_type message 
variable: $variable_name, returning array:\n" .
+                       "subject: $subject_substituted\n" .
+                       "message:\n$message_substituted"
                );
-               return ($subject, $message);
+               return ($subject_substituted, $message_substituted);
        }
        else {
-               notify($ERRORS{'DEBUG'}, 0, "retrieved '$variable_name' 
$message_type message variable and substituted text, returning message 
string:\n$message");
-               return $message;
+               notify($ERRORS{'DEBUG'}, 0, "retrieved $message_type message 
variable: '$variable_name', returning message string:\n$message_substituted");
+               return $message_substituted;
        }
 }
 
@@ -1989,7 +1899,7 @@ sub _get_message_variable {
 
 =head2 get_user_message
 
- Parameters  : $user_message_key, $substitution_hashref (optional)
+ Parameters  : $user_message_key
  Returns     : array context, array: ($subject, $message)
                scalar context, string: $message
  Description : Retrieves user messages.
@@ -2003,15 +1913,15 @@ sub get_user_message {
                return;
        }
        
-       my ($user_message_key, $substitution_hashref) = @_;
-       return $self->_get_message_variable($user_message_key, 
$substitution_hashref);
+       my ($user_message_key) = @_;
+       return $self->_get_message_variable($user_message_key);
 }
 
 #//////////////////////////////////////////////////////////////////////////////
 
 =head2 get_user_short_message
 
- Parameters  : $user_message_key, $substitution_hashref (optional)
+ Parameters  : $user_message_key
  Returns     : array context, array: ($subject, $short_message)
                scalar context, string: $short_message
  Description : Retrieves user short messages.
@@ -2025,15 +1935,15 @@ sub get_user_short_message {
                return;
        }
        
-       my ($user_message_key, $substitution_hashref) = @_;
-       return $self->_get_message_variable($user_message_key, 
$substitution_hashref, 1);
+       my ($user_message_key) = @_;
+       return $self->_get_message_variable($user_message_key, 1);
 }
 
 #//////////////////////////////////////////////////////////////////////////////
 
 =head2 get_admin_message
 
- Parameters  : $admin_message_key, $substitution_hashref (optional)
+ Parameters  : $admin_message_key
  Returns     : array context, array: ($subject, $message)
                scalar context, string: $message
  Description : Retrieves administrative messages.
@@ -2047,8 +1957,8 @@ sub get_admin_message {
                return;
        }
        
-       my ($admin_message_key, $substitution_hashref) = @_;
-       return $self->_get_message_variable($admin_message_key, 
$substitution_hashref, 0, 1);
+       my ($admin_message_key) = @_;
+       return $self->_get_message_variable($admin_message_key, 0, 1);
 }
 
 #//////////////////////////////////////////////////////////////////////////////

Modified: vcl/trunk/managementnode/lib/VCL/Module/OS.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS.pm?rev=1794871&r1=1794870&r2=1794871&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS.pm Thu May 11 18:58:08 2017
@@ -4410,8 +4410,6 @@ sub update_fixed_ip_info {
 
 =cut
 
-#//////////////////////////////////////////////////////////////////////////////
-
 sub get_timings {
        my $self = shift;
        my $variable = shift;
@@ -4651,7 +4649,7 @@ sub get_connect_method_remote_ip_address
        my $mn_public_ip_address = $self->mn_os->get_public_ip_address();
        
        # Get the ignored remote IP address variable from the database if it is 
configured
-       my $ignored_remote_ip_address_string = 
$self->data->get_variable('ignored_remote_ip_addresses') || '';
+       my $ignored_remote_ip_address_string = 
get_variable('ignored_remote_ip_addresses') || '';
        my @ignored_remote_ip_addresses = split(/[,; ]+/, 
$ignored_remote_ip_address_string);
        notify($ERRORS{'DEBUG'}, 0, "connections to $computer_node_name from 
any of the following IP addresses will be ignored: " . join(', ', 
@ignored_remote_ip_addresses)) if (@ignored_remote_ip_addresses);
        

Modified: vcl/trunk/managementnode/lib/VCL/Module/State.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/State.pm?rev=1794871&r1=1794870&r2=1794871&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/State.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/State.pm Thu May 11 18:58:08 2017
@@ -157,13 +157,10 @@ sub initialize {
                notify($ERRORS{'DEBUG'}, 0, "child reservation, not updating 
request state to 'pending'");
        }
        
-       # Set the PARENTIMAGE and SUBIMAGE keys in the request data hash
-       # These are deprecated, DataStructure's is_parent_reservation function 
should be used
-       $self->data->get_request_data->{PARENTIMAGE} = 
($self->data->is_parent_reservation() + 0);
-       $self->data->get_request_data->{SUBIMAGE}    = 
(!$self->data->is_parent_reservation() + 0);
-       
-       # Set the parent PID and this process's PID in the hash
-       set_hash_process_id($self->data->get_request_data);
+       # Set the PID and PPID in the DataStructure
+       # These will be wrong if set in get_request_info before the state 
process is forked
+       $self->data->set_process_pid($PID);
+       $self->data->set_process_ppid(getppid() || '<unknown>');
        
        # Create an OS object
        if (my $os = $self->create_os_object()) {

Modified: vcl/trunk/managementnode/lib/VCL/image.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/image.pm?rev=1794871&r1=1794870&r2=1794871&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/image.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/image.pm Thu May 11 18:58:08 2017
@@ -260,16 +260,12 @@ sub reservation_successful {
        my $computer_id                = $self->data->get_computer_id();
        my $sysadmin_mail_address      = 
$self->data->get_management_node_sysadmin_email(0);
        
-       my $image_capture_type;
-       
        # Send a capture completed message to the image owner
        my ($user_subject, $user_message);
        if ($request_state_name =~ /(checkpoint)/i) {
-               $image_capture_type = 'Checkpoint';
                ($user_subject, $user_message) = 
$self->get_user_message('image_checkpoint_success');
        }
        else {
-               $image_capture_type = 'Capture';
                ($user_subject, $user_message) = 
$self->get_user_message('image_creation_success');
        }
        if (defined($user_subject) && defined($user_message)) {
@@ -279,8 +275,7 @@ sub reservation_successful {
        # Send mail to administrators
        if ($sysadmin_mail_address) {
                # Get the administrator email subject and message
-               # Pass a hash containing an IMAGE_CAPTURE_TYPE key - this gets 
replaced in the subject of the message
-               my ($admin_subject, $admin_message) = 
$self->get_admin_message('image_creation_complete', { 'IMAGE_CAPTURE_TYPE' => 
$image_capture_type, IMAGE_SIZE_OLD => $image_size_old });
+               my ($admin_subject, $admin_message) = 
$self->get_admin_message('image_creation_complete');
                if (defined($admin_subject) && defined($admin_message)) {
                        mail($sysadmin_mail_address, $admin_subject, 
$admin_message, $affiliation_helpaddress);
                }
@@ -326,18 +321,10 @@ sub reservation_failed {
        my $computer_id                = $self->data->get_computer_id();
        my $computer_shortname         = $self->data->get_computer_short_name();
        my $sysadmin_mail_address      = 
$self->data->get_management_node_sysadmin_email(0);
-       
-       my $message = shift;
-       
-       my $image_capture_type;
-       if ($request_state_name =~ /(checkpoint)/i) {
-               $image_capture_type = 'Checkpoint';
-       }
-       else {
-               $image_capture_type = 'Creation';
-       }
+       my $image_capture_type         = $self->data->get_image_capture_type();
        
        # Image process failed
+       my $message = shift;
        if ($message) {
                notify($ERRORS{'CRITICAL'}, 0, "$image_name Image 
$image_capture_type Failed - $message");
        }
@@ -357,7 +344,7 @@ sub reservation_failed {
                # Get the administrator email subject and message
                # Pass a hash containing an IMAGE_CAPTURE_TYPE key - this gets 
replaced in the subject of the message
                my $admin_message_key = 'image_creation_failed';
-               my ($admin_subject, $admin_message) = 
$self->get_admin_message($admin_message_key, { 'IMAGE_CAPTURE_TYPE' => 
$image_capture_type });
+               my ($admin_subject, $admin_message) = 
$self->get_admin_message($admin_message_key);
                if (defined($admin_subject) && defined($admin_message)) {
                        mail($sysadmin_mail_address, $admin_subject, 
$admin_message, $affiliation_helpaddress);
                }

Modified: vcl/trunk/managementnode/lib/VCL/inuse.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/inuse.pm?rev=1794871&r1=1794870&r2=1794871&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/inuse.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/inuse.pm Thu May 11 18:58:08 2017
@@ -354,13 +354,15 @@ sub process {
 
 sub notify_user_future_endtime {
        my $self = shift;
-       my $notice_interval = shift;
        
        # Check to make sure notice interval is set
+       my $notice_interval = shift;
        if (!defined($notice_interval)) {
                notify($ERRORS{'WARNING'}, 0, "end time message not set, notice 
interval was not passed");
                return 0;
        }
+       # Set the notice interval in the DataStructure object so that the text 
can contain [notice_interval]
+       $self->data->set_notice_interval($notice_interval);
        
        my $is_parent_reservation        = $self->data->is_parent_reservation();
        my $computer_short_name          = 
$self->data->get_computer_short_name();
@@ -376,13 +378,13 @@ sub notify_user_future_endtime {
        
        # Send a message to the user notifying them the reservation end time is 
coming up
        if ($is_parent_reservation && $user_emailnotices) {
-               my ($user_subject, $user_message) = 
$self->get_user_message($user_message_key, { NOTICE_INTERVAL => 
$notice_interval});
+               my ($user_subject, $user_message) = 
$self->get_user_message($user_message_key);
                if (defined($user_subject) && defined($user_message)) {
                        mail($user_email, $user_subject, $user_message, 
$user_affiliation_helpaddress);
                }
        }
        
-       my $user_short_message = 
$self->get_user_short_message($user_message_key, { NOTICE_INTERVAL => 
$notice_interval});
+       my $user_short_message = 
$self->get_user_short_message($user_message_key);
        if ($user_short_message) {
                # Display a message on the console or desktop if the OS module 
supports it
                if ($self->os->can('notify_user_console')) {
@@ -419,13 +421,15 @@ sub notify_user_future_endtime {
 
 sub notify_user_endtime_imminent {
        my $self = shift;
-       my $notice_interval = shift;
        
-       # Check to make sure disconnect time was passed
+       # Check to make sure notice interval is set
+       my $notice_interval = shift;
        if (!defined($notice_interval)) {
-               notify($ERRORS{'WARNING'}, 0, "disconnect time message not set, 
disconnect time was not passed");
+               notify($ERRORS{'WARNING'}, 0, "disconnect time message not set, 
notice interval was not passed");
                return 0;
        }
+       # Set the notice interval in the DataStructure object so that the text 
can contain [notice_interval]
+       $self->data->set_notice_interval($notice_interval);
        
        my $computer_short_name          = 
$self->data->get_computer_short_name();
        my $image_os_type                = $self->data->get_image_os_type();
@@ -449,13 +453,13 @@ sub notify_user_endtime_imminent {
        
        # Send a message to the user notifying them the reservation end time is 
close
        if ($is_parent_reservation && $user_emailnotices) {
-               my ($user_subject, $user_message) = 
$self->get_user_message($user_message_key, { NOTICE_INTERVAL => 
$notice_interval});
+               my ($user_subject, $user_message) = 
$self->get_user_message($user_message_key);
                if (defined($user_subject) && defined($user_message)) {
                        mail($user_email, $user_subject, $user_message, 
$user_affiliation_helpaddress);
                }
        }
        
-       my $user_short_message = 
$self->get_user_short_message($user_message_key, { NOTICE_INTERVAL => 
$notice_interval});
+       my $user_short_message = 
$self->get_user_short_message($user_message_key);
        if ($user_short_message) {
                # Display a message on the console or desktop if the OS module 
supports it
                if ($self->os->can('notify_user_console')) {

Modified: vcl/trunk/managementnode/lib/VCL/utils.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=1794871&r1=1794870&r2=1794871&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/utils.pm Thu May 11 18:58:08 2017
@@ -243,7 +243,6 @@ our @EXPORT = qw(
        run_command
        run_scp_command
        run_ssh_command
-       set_hash_process_id
        set_logfile_path
        set_managementnode_state
        set_reservation_lastcheck
@@ -3017,7 +3016,8 @@ EOF
 
        # Build the hash
        my $request_info;
-
+       my $request_state_name;
+       
        for my $reservation_row (@selected_rows) {
                my $reservation_id = $reservation_row->{'reservation-id'};
                if (!$reservation_id) {
@@ -3047,6 +3047,8 @@ EOF
                        }
                }
                
+               $request_state_name = $request_info->{state}{name};
+               
                # Store duration in epoch seconds format
                my $request_start_epoch = 
convert_to_epoch_seconds($request_info->{start});
                my $request_end_epoch = 
convert_to_epoch_seconds($request_info->{end});
@@ -3072,7 +3074,6 @@ EOF
                if (defined $ENV{reservation_id} && $ENV{reservation_id} eq 
$reservation_id) {
                        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");
@@ -3159,15 +3160,24 @@ EOF
        
        # Set some default non-database values for the entire request
        # All data ever added to the hash should be initialized here
-       $request_info->{PID}              = '';
-       $request_info->{PPID}             = '';
-       $request_info->{PARENTIMAGE}      = '';
+       $request_info->{PID}              = $PID;
+       $request_info->{PPID}             = getppid();
        $request_info->{PRELOADONLY}      = '0';
-       $request_info->{SUBIMAGE}         = '';
        $request_info->{CHECKTIME}        = '';
        $request_info->{NOTICEINTERVAL}   = '';
        $request_info->{RESERVATIONCOUNT} = scalar keys 
%{$request_info->{reservation}};
        $request_info->{UPDATED}          = '0';
+       $request_info->{NOTICE_INTERVAL}  = '';
+       
+       if ($request_state_name eq 'image') {
+               $request_info->{IMAGE_CAPTURE_TYPE} = 'Capture';
+       }
+       elsif ($request_state_name eq 'checkpoint') {
+               $request_info->{IMAGE_CAPTURE_TYPE} = 'Checkpoint';
+       }
+       else {
+               $request_info->{IMAGE_CAPTURE_TYPE} = '';
+       }
        
        #notify($ERRORS{'DEBUG'}, 0, "retrieved request info:\n" . 
format_data($request_info));
        return $request_info;
@@ -6121,55 +6131,12 @@ EOF
 
 #//////////////////////////////////////////////////////////////////////////////
 
-=head2 set_hash_process_id
-
- Parameters  : Reference to a hash
- Returns     : 0 or 1
- Description : Sets the process ID of the current process and parent process ID
-               in a hash, to which a reference was passed.
-               $hash{PID} = process ID
-               $hash{PPID} = parent process ID
-
-=cut
-
-sub set_hash_process_id {
-       my ($hash_ref) = @_;
-
-       my ($package, $filename, $line, $sub) = caller(0);
-
-       # Check the passed parameter
-       if (!(defined($hash_ref))) {
-               notify($ERRORS{'WARNING'}, 0, "hash reference was not 
specified");
-               return 0;
-       }
-
-       # Make sure it's a hash reference
-       if (ref($hash_ref) ne "HASH") {
-               notify($ERRORS{'WARNING'}, 0, "passed parameter is not a hash 
reference");
-               return 0;
-       }
-
-       # Get the parent PID and this process's PID
-       # getppid() doesn't work under Windows so just set it to 0
-       my $ppid = 0;
-       $ppid = getppid() if ($^O !~ /win/i);
-       $hash_ref->{PPID} = $ppid;
-       my $pid = $$;
-       $hash_ref->{PID} = $pid;
-
-       return 1;
-} ## end sub set_hash_process_id
-
-#//////////////////////////////////////////////////////////////////////////////
-
 =head2 rename_vcld_process
 
  Parameters  : hash - Reference to hash containing request data
  Returns     : boolean
  Description : Renames running process based on request information. Appends 
the
                state name, request ID, and reservation ID to the process name.
-               Sets PARENTIMAGE and SUBIMAGE in the hash depending on whether 
or
-               reservation ID is the lowest for a request.
 
 =cut
 
@@ -6239,29 +6206,18 @@ sub rename_vcld_process {
 
                        if ($reservation_count > 1) {
                                if ($reservation_is_parent) {
-                                       
$data_structure->get_request_data->{PARENTIMAGE} = 1;
-                                       
$data_structure->get_request_data->{SUBIMAGE}    = 0;
                                        $new_process_name .= " 
(cluster=parent)";
                                }
                                else {
-                                       
$data_structure->get_request_data->{PARENTIMAGE} = 0;
-                                       
$data_structure->get_request_data->{SUBIMAGE}    = 1;
                                        $new_process_name .= " (cluster=child)";
                                }
                        } ## end if ($reservation_count > 1)
-                       else {
-                               
$data_structure->get_request_data->{PARENTIMAGE} = 1;
-                               $data_structure->get_request_data->{SUBIMAGE}   
 = 0;
-                       }
-
-                       notify($ERRORS{'DEBUG'}, 0, "PARENTIMAGE: " . 
$data_structure->get_request_data->{PARENTIMAGE});
-                       notify($ERRORS{'DEBUG'}, 0, "SUBIMAGE: " . 
$data_structure->get_request_data->{SUBIMAGE});
                } ## end if ($state_name ne 'blockrequest')
                else {
                        my $blockrequest_id   = 
$data_structure->get_blockrequest_id();
                        my $blockrequest_name = 
$data_structure->get_blockrequest_name();
                        my $blocktime_id      = 
$data_structure->get_blocktime_id();
-
+                       
                        # Append the IDs if they are set
                        $new_process_name .= " $blockrequest_id:$blocktime_id";
                        $new_process_name .= " '$blockrequest_name'";


Reply via email to