Author: fapeeler
Date: Tue Apr 12 14:09:50 2011
New Revision: 1091419

URL: http://svn.apache.org/viewvc?rev=1091419&view=rev
Log:
VCL-432

Added support to automatically capture an imaging reservation when time has 
expired.
This only applies to reservations that have the imaging flag set on the request.

It calls the xmlrpc api to start the imaging request.

VCL-446

inuse.pm, 
for reservations greater than 24hr. At certain time intervals notify user their 
reservation will end


Modified:
    incubator/vcl/trunk/managementnode/lib/VCL/DataStructure.pm
    incubator/vcl/trunk/managementnode/lib/VCL/inuse.pm
    incubator/vcl/trunk/managementnode/lib/VCL/utils.pm

Modified: incubator/vcl/trunk/managementnode/lib/VCL/DataStructure.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/DataStructure.pm?rev=1091419&r1=1091418&r2=1091419&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/DataStructure.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/DataStructure.pm Tue Apr 12 
14:09:50 2011
@@ -136,6 +136,7 @@ $SUBROUTINE_MAPPINGS{request_preload}   
 $SUBROUTINE_MAPPINGS{request_preload_only}      = 
'$self->request_data->{PRELOADONLY}';
 $SUBROUTINE_MAPPINGS{request_reservation_count} = 
'$self->request_data->{RESERVATIONCOUNT}';
 $SUBROUTINE_MAPPINGS{request_start_time}        = 
'$self->request_data->{start}';
+$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}';

Modified: incubator/vcl/trunk/managementnode/lib/VCL/inuse.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/inuse.pm?rev=1091419&r1=1091418&r2=1091419&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/inuse.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/inuse.pm Tue Apr 12 14:09:50 2011
@@ -104,6 +104,7 @@ sub process {
        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 $reservation_remoteip  = $self->data->get_reservation_remote_ip();
@@ -172,28 +173,29 @@ sub process {
 
                        # Get a date string for the current time
                        my $date_string;
-
-                       # 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) {
-                               notify($ERRORS{'OK'}, 0, "notice interval is 
set to $notice_interval");
-
-                               # Notify the user of the end time
-                               $self->_notify_user_endtime($notice_interval);
-
-                               # Set lastcheck time ahead by 16 minutes for 
all notices except the last (30 minute) notice
-                               if ($notice_interval ne "30 minutes") {
-                                       my $epoch_now = 
convert_to_epoch_seconds();
-                                       $date_string = 
convert_to_datetime(($epoch_now + (16 * 60)));
-                               }
-                               else {
-                                       my $epoch_now = 
convert_to_epoch_seconds();
-                                       $date_string = 
convert_to_datetime($epoch_now);
-                               }
-                       } ## end if ($notice_interval)
-
+                       # If duration is greater than 24hrs 5minutes then 
perform end time notice checks
+                       if($request_duration >= 86640 ){
+                               # 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);
+
+                                       # Set lastcheck time ahead by 16 
minutes for all notices except the last (30 minute) notice
+                                       if ($notice_interval ne "30 minutes") {
+                                               my $epoch_now = 
convert_to_epoch_seconds();
+                                               $date_string = 
convert_to_datetime(($epoch_now + (16 * 60)));
+                                       }
+                                       else {
+                                               my $epoch_now = 
convert_to_epoch_seconds();
+                                               $date_string = 
convert_to_datetime($epoch_now);
+                                       }
+                               } ## end if ($notice_interval)
+                       }
                        # Check if the user deleted the request
                        if (is_request_deleted($request_id)) {
                                # User deleted request, exit queitly
@@ -227,7 +229,7 @@ sub process {
 
                        notify($ERRORS{'OK'}, 0, "exiting");
                        exit;
-               }    # Close if poll and checkuser = 0
+               }    # if (!$imagemeta_checkuser || $request_forimaging.......
 
 
                # Poll:
@@ -464,6 +466,42 @@ sub process {
 
                # Check if this is an imaging request, causes process to exit 
if state or laststate = image
                $request_forimaging = $self->_check_imaging_request();
+               
+               # 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 image
+                               if (update_request_state($request_id, 
"maintenance", "image")) {
+                                       notify($ERRORS{'OK'}, 0, "request state 
set to maintenance, laststate to image");
+                               }
+                               else {
+                                       notify($ERRORS{'CRITICAL'}, 0, "unable 
to set request state to maintenance, laststate to image");
+                               }
+
+                               # 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");
+                                       }
+                               exit;
+                       }
+               }
 
                # Insert an entry into the load log
                insertloadlog($reservation_id, $computer_id, "timeout", 
"endtime reached moving to timeout");
@@ -576,10 +614,16 @@ sub _notify_user_endtime {
        my $user_emailnotices               = 
$self->data->get_user_emailnotices();
        my $user_imtype_name                = 
$self->data->get_user_imtype_name();
        my $user_im_id                      = $self->data->get_user_im_id();
+       my $request_forimaging              = $self->_check_imaging_request();  
+       my $request_id                      = $self->data->get_request_id();
 
-       my $message = <<"EOF";
+       my $message;
+       my $subject;
+       my $short_message = "You have $notice_interval until the scheduled end 
time of your reservation. VCL Team";
+
+       $message  = <<"EOF";
 
-You have $notice_interval until the end of your reservation for image 
$image_prettyname.
+You have $notice_interval until the scheduled end time of your reservation for 
image $image_prettyname.
 
 Reservation extensions are available if the machine you are on does not have a 
reservation immediately following.
 
@@ -604,7 +648,7 @@ To disable email notices
 ******************************************************************
 EOF
 
-       my $subject = "VCL -- $notice_interval until end of reservation";
+       $subject = "VCL -- $notice_interval until end of reservation for 
$image_prettyname";
 
        # Send mail
        if ($user_emailnotices) {
@@ -614,6 +658,23 @@ EOF
        else {
                notify($ERRORS{'DEBUG'}, 0, "user $user_login_id email notices 
disabled - not notifying user of endtime");
        }
+        # Send message to machine
+        if ($computer_type =~ /blade|virtualmachine/) {
+                if ($image_os_type =~ /windows/) {
+                        # Notify via windows msg cmd
+                        $user_login_id= "administrator" 
if($request_forimaging);
+                        notify_via_msg($computer_short_name, $user_login_id, 
$short_message);
+                }
+                elsif ($image_os_type =~ /linux/){
+                        # Notify via wall
+                        notify_via_wall($computer_short_name, $user_login_id, 
$short_message, $image_os_name, $computer_type);
+                }
+        } ## end if ($computer_type =~ /blade|virtualmachine/)
+        elsif ($computer_type eq "lab") {
+                # Notify via wall
+                notify_via_wall($computer_ip_address, $user_login_id, 
$short_message, $image_os_name, $computer_type);
+        }
+
 
        # Send IM
        if ($user_imtype_name ne "none") {
@@ -649,22 +710,23 @@ sub _notify_user_disconnect {
                notify($ERRORS{'WARNING'}, 0, "disconnect time message not set, 
disconnect time was not passed");
                return 0;
        }
-       
+
        my $computer_short_name             = 
$self->data->get_computer_short_name();
-       my $computer_type                   = $self->data->get_computer_type();
-       my $computer_ip_address             = 
$self->data->get_computer_ip_address();
-       my $image_os_name                   = $self->data->get_image_os_name();
-       my $image_prettyname                = 
$self->data->get_image_prettyname();
-       my $image_os_type                   = $self->data->get_image_os_type();
-       my $user_affiliation_sitewwwaddress = 
$self->data->get_user_affiliation_sitewwwaddress();
-       my $user_affiliation_helpaddress    = 
$self->data->get_user_affiliation_helpaddress();
-       my $user_login_id                   = $self->data->get_user_login_id();
-       my $user_email                      = $self->data->get_user_email();
-       my $user_emailnotices               = 
$self->data->get_user_emailnotices();
-       my $user_imtype_name                = 
$self->data->get_user_imtype_name();
-       my $user_im_id                      = $self->data->get_user_im_id();
-       my $is_parent_reservation           = 
$self->data->is_parent_reservation();
-       
+        my $computer_type                   = $self->data->get_computer_type();
+        my $computer_ip_address             = 
$self->data->get_computer_ip_address();
+        my $image_os_name                   = $self->data->get_image_os_name();
+        my $image_prettyname                = 
$self->data->get_image_prettyname();
+        my $image_os_type                   = $self->data->get_image_os_type();
+        my $user_affiliation_sitewwwaddress = 
$self->data->get_user_affiliation_sitewwwaddress();
+        my $user_affiliation_helpaddress    = 
$self->data->get_user_affiliation_helpaddress();
+        my $user_login_id                   = $self->data->get_user_login_id();
+        my $user_email                      = $self->data->get_user_email();
+        my $user_emailnotices               = 
$self->data->get_user_emailnotices();
+        my $user_imtype_name                = 
$self->data->get_user_imtype_name();
+        my $user_im_id                      = $self->data->get_user_im_id();
+        my $is_parent_reservation           = 
$self->data->is_parent_reservation();
+       my $request_forimaging              = $self->_check_imaging_request();
+
        my $disconnect_string;
        if ($disconnect_time == 0) {
                $disconnect_string = "0 minutes";
@@ -676,7 +738,14 @@ sub _notify_user_disconnect {
                $disconnect_string = "$disconnect_time minutes";
        }
 
-       my $message = <<"EOF";
+       my $short_message;
+       my $subject;
+       my $message;
+
+       if(!$request_forimaging){
+               
+
+       $message = <<"EOF";
 
 You have $disconnect_string until the end of your reservation for image 
$image_prettyname, please save all work and prepare to exit.
 
@@ -701,10 +770,45 @@ To disable email notices
 ******************************************************************
 EOF
 
-       my $short_message = "You have $disconnect_string until the end of your 
reservation. Please save all work and prepare to log off.";
+               $short_message = "You have $disconnect_string until the end of 
your reservation. Please save all work and prepare to log off.";
 
-       my $subject = "VCL -- $disconnect_string until end of reservation";
+               $subject = "VCL -- $disconnect_string until end of reservation";
+       
+       }
+       else {
+               $short_message = "You have $disconnect_string until the auto 
capture process is started.";
+
+               $subject = "VCL Imaging Reservation -- $disconnect_string until 
starting auto capture";
+               
+               $message = <<"EOF";
+
+You have $disconnect_string until the end of your reservation for image 
$image_prettyname. 
+
+At the scheduled end time your imaging reservation will be automatically 
captured. 
 
+To prevent this auto capture, visit the VCL site 
$user_affiliation_sitewwwaddress manually start the image creation process.
+
+Please note this auto capture feature is intended to prevent destorying any 
work you have done to the image.
+
+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 $user_affiliation_sitewwwaddress
+-Select User Preferences
+-Select General Preferences
+
+******************************************************************
+EOF
+               
+       
+       }
        # Send mail
        if ($is_parent_reservation && $user_emailnotices) {
                mail($user_email, $subject, $message, 
$user_affiliation_helpaddress);
@@ -719,6 +823,7 @@ EOF
        if ($computer_type =~ /blade|virtualmachine/) {
                if ($image_os_type =~ /windows/) {
                        # Notify via windows msg cmd
+                       $user_login_id= "administrator" if($request_forimaging);
                        notify_via_msg($computer_short_name, $user_login_id, 
$short_message);
                }
                elsif ($image_os_type =~ /linux/){
@@ -837,10 +942,13 @@ sub _notify_user_request_ended {
        my $user_imtype_name                = 
$self->data->get_user_imtype_name();
        my $user_im_id                      = $self->data->get_user_im_id();
        my $is_parent_reservation           = 
$self->data->is_parent_reservation();
+       my $subject;
+       my $message;
 
-       my $subject = "VCL -- End of reservation";
+       if(!$request_forimaging) {
+       $subject = "VCL -- End of reservation";
 
-       my $message = <<"EOF";
+       $message = <<"EOF";
 
 Your reservation of $image_prettyname has ended. Thank you for using 
$user_affiliation_sitewwwaddress.
 
@@ -860,6 +968,35 @@ To disable email notices
 
 ******************************************************************
 EOF
+       }
+       else {
+               $subject = "VCL Image Reservation - Auto capture started";
+               
+               $message = <<"EOF";
+
+Your imaging reservation of $image_prettyname has reached it's scheduled end 
time.
+
+To avoid losing your work we have started an automatic capture of this image. 
Upon completion of the 
+image capture. You will be notified about the completion of the image capture.
+
+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 $user_affiliation_sitewwwaddress
+-Select User Preferences
+-Select General Preferences
+
+******************************************************************
+EOF
+
+       }       
 
        # Send mail
        if ($is_parent_reservation && $user_emailnotices) {
@@ -927,6 +1064,37 @@ sub _check_imaging_request {
        }
        
 }
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 _start_imaging_request
+
+ Parameters  :   
+ Returns     : 1 if successfully inserted image capture, undefined if an error 
occurred, exits otherwise
+ Description : If request is forimaging and timesout, this inserts a imaging 
reservation. 
+
+=cut
+
+sub _start_imaging_request {
+
+       my $self            = shift;
+       my $request_id = $self->data->get_request_id();
+
+       my $method = "XMLRPCautoCapture";
+       my @argument_string = ($method,$request_id);
+       my $xml_ret = xmlrpc_call(@argument_string);
+
+       if($xml_ret->value->{status} =~ /success/ ){
+               return 1;
+       }
+       
+       notify($ERRORS{'WARNING'}, 0, "$xml_ret->value->{status}");
+       if($xml_ret->value->{status} =~ /error/i){
+               notify($ERRORS{'WARNING'}, 0, "errorcode= 
$xml_ret->value->{errorcode} errormsg= $xml_ret->value->{errormsg}");
+       }
+
+       return 0;
+
+}
 
 #/////////////////////////////////////////////////////////////////////////////
 

Modified: incubator/vcl/trunk/managementnode/lib/VCL/utils.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=1091419&r1=1091418&r2=1091419&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/utils.pm Tue Apr 12 14:09:50 2011
@@ -860,106 +860,63 @@ 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      = time();
+       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);
+       $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;
+       
+       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
-       #2 week: between 14 days and a 14 day -15 minutes window
-       if ($epochend <= (14 * 60 * 60 * 24) && $epochend >= (14 * 60 * 60 * 24 
- 15 * 60)) {
-               return (1, "2week");
-       }
-       #1 week: between 7 days and a 14 day -15 minute window
-       elsif ($epochend <= (7 * 60 * 60 * 24) && $epochend >= (7 * 60 * 60 * 
24 - 15 * 60)) {
-               return (1, "1week");
-       }
-       #2 day: between 2 days and a 2 day -15 minute window
-       if ($epochend <= (2 * 60 * 60 * 24) && $epochend >= (2 * 60 * 60 * 24 - 
15 * 60)) {
-               return (1, "2day");
-       }
-       #1 day: between 1 days and a 1 day -15 minute window
-       if ($epochend <= (1 * 60 * 60 * 24) && $epochend >= (1 * 60 * 60 * 24 - 
15 * 60)) {
-               return (1, "1day");
-       }
-       #30-25 minutes
-       if ($epochend <= (30 * 60) && $epochend >= (25 * 60)) {
-               return (1, "30min");
+       #ignore over 2weeks away
+       if($diff_weeks >= 2){ 
+               return 0;
+       }
+       #2 week: between 14 days and a 14 day -6 minutes window
+       elsif($Total_days >= 13 && $diff_hours >= 23 && $diff_minutes >= 55){
+               return "2 weeks";
        }
+       #Ignore: between 7 days and 14 day - 6 minute window
+       elsif($Total_days >=7) {
+               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 >= 0 && $diff_hours >= 23 && $diff_minutes >= 55) {
+               return "24 hours";
+       }
+
+       return 0; 
+       
+       
 } ## end sub check_endtimenotice_interval
-#sub new_check_endtimenotice_interval {
-#       my ($request_end, $base_time) = @_;
-#       my ($package, $filename, $line, $sub) = caller(0);
-#
-#      # Check the parameter
-#      if (!defined($request_end)) {
-#              notify($ERRORS{'WARNING'}, 0, "request end time was not 
specified"");
-#              return 0;
-#       }
-#      elsif (!$request_end) {
-#              notify($ERRORS{'WARNING'}, 0, "request end time was specified 
but is blank"");
-#              return 0;
-#       }
-#
-#      # Convert the request end time to epoch seconds
-#       my $end_epoch_seconds = convert_to_epoch_seconds($request_end);
-#
-#      # This is only used for testing
-#      my @now;
-#      if ($base_time) {
-#              my $base_epoch_seconds = convert_to_epoch_seconds($base_time);
-#              @now = Time_to_Date($base_epoch_seconds);
-#       }
-#      else {
-#              @now = Time_to_Date();
-#       }
-#
-#      # Get arrays from the Date::Calc::Time_to_Date functions for now and 
the end time
-#      my @end = Time_to_Date($end_epoch_seconds);
-#
-#      # Calculate the difference
-#      my ($days, $hours, $minutes, $seconds) = Delta_DHMS(@now, @end);
-#
-#       # Return a value on: 2 & 1 week; 2,1 day, 1 hour, 30,15,10,5 minutes
-#      my $return_value = 0;
-#
-#      # Ignore: over 14 days away
-#       if ($days >= 14){
-#          $return_value = 0;
-#       }
-#      # 2 week notice: between 14 days and a 14 day - 15 minute window
-#      elsif ($days >= 13 && $hours >= 23 && $minutes >= 45){
-#          $return_value = "2 weeks";
-#       }
-#      # Ignore: between 7 days and 14 day - 15 minute window
-#      elsif ($days >= 7) {
-#              $return_value = 0;
-#      }
-#       # 1 week notice: between 7 days and a 7 day -15 minute window
-#       elsif ($days >= 6 && $hours >= 23 && $minutes >= 45) {
-#          $return_value = "1 week";
-#       }
-#      # Ignore: between 2 days and 7 day - 15 minute window
-#      elsif ($days >= 2) {
-#              $return_value = 0;
-#      }
-#       # 2 day notice: between 2 days and a 2 day -15 minute window
-#       elsif($days >= 1 && $hours >= 23 && $minutes >= 45) {
-#          $return_value = "2 days";
-#       }
-#      # Ignore: between 1 days and 2 day - 15 minute window
-#      elsif ($days >= 1) {
-#              $return_value = 0;
-#      }
-#       # 1 day notice: between 1 days and a 1 day -15 minute window
-#       elsif($days >= 0 && $hours >= 23 && $minutes >= 45) {
-#          $return_value = "1 day";
-#       }
-#       #30-25 minutes
-#       elsif ($minutes >= 25 && $minutes <= 30) {
-#          $return_value = "30 minutes";
-#       }
-
-#      notify($ERRORS{'OK'}, 0, "days: time difference is days:$days 
hours:$hours minutes:$minutes, returning $return_value");
-#      return $return_value;
-#}
 
 #/////////////////////////////////////////////////////////////////////////////
 


Reply via email to