Author: fapeeler
Date: Mon Aug 16 20:18:17 2010
New Revision: 986123

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

removed 4hr and 2hr window checks, now if a block allocation is within 6hrs it 
gets processed.
added get_group_name and get_user_info, to get information on sending a 
confirmation message to the owner


Modified:
    incubator/vcl/trunk/managementnode/lib/VCL/DataStructure.pm
    incubator/vcl/trunk/managementnode/lib/VCL/blockrequest.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=986123&r1=986122&r2=986123&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/DataStructure.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/DataStructure.pm Mon Aug 16 
20:18:17 2010
@@ -105,6 +105,7 @@ $SUBROUTINE_MAPPINGS{blockrequest_name} 
 $SUBROUTINE_MAPPINGS{blockrequest_image_id}           = 
'$self->blockrequest_data->{BLOCKREQUEST_ID}{imageid}';
 $SUBROUTINE_MAPPINGS{blockrequest_number_machines}    = 
'$self->blockrequest_data->{BLOCKREQUEST_ID}{numMachines}';
 $SUBROUTINE_MAPPINGS{blockrequest_group_id}           = 
'$self->blockrequest_data->{BLOCKREQUEST_ID}{groupid}';
+$SUBROUTINE_MAPPINGS{blockrequest_group_name}         = 
'$self->blockrequest_data->{BLOCKREQUEST_ID}{groupname}';
 $SUBROUTINE_MAPPINGS{blockrequest_repeating}          = 
'$self->blockrequest_data->{BLOCKREQUEST_ID}{repeating}';
 $SUBROUTINE_MAPPINGS{blockrequest_owner_id}           = 
'$self->blockrequest_data->{BLOCKREQUEST_ID}{ownerid}';
 $SUBROUTINE_MAPPINGS{blockrequest_admin_group_id}     = 
'$self->blockrequest_data->{BLOCKREQUEST_ID}{admingroupid}';

Modified: incubator/vcl/trunk/managementnode/lib/VCL/blockrequest.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/blockrequest.pm?rev=986123&r1=986122&r2=986123&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/blockrequest.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/blockrequest.pm Mon Aug 16 
20:18:17 2010
@@ -133,8 +133,21 @@ sub process {
        my $blocktime_end                = $self->data->get_blocktime_end();
        my $blockrequest_name            = $self->data->get_blockrequest_name();
        my $blockrequest_owner_id        = 
$self->data->get_blockrequest_owner_id();
+       my $block_group_id               = 
$self->data->get_blockrequest_group_id();
+       my $block_group_name             = 
$self->data->get_blockrequest_group_name();
 
-
+       # Get user info 
+       my %info;
+       my $owner_affiliation_sitewwwaddress;
+       my $owner_affiliation_helpaddress;
+       my $owner_email;
+
+       if( %info = get_user_info($blockrequest_owner_id)){
+               $owner_email = $info{email};
+               $owner_affiliation_helpaddress = $info{helpaddress};
+               $owner_affiliation_sitewwwaddress = $info{sitewwwaddress};
+       }
+               
        #Set local timer
        my $localtimer = convert_to_epoch_seconds();
 
@@ -146,7 +159,9 @@ sub process {
        notify($ERRORS{'DEBUG'}, 0, "blocktime id: $blocktime_id");
        notify($ERRORS{'DEBUG'}, 0, "blocktime processed: 
$blocktime_processed");
        notify($ERRORS{'DEBUG'}, 0, "blocktime start: $blocktime_start");
-       notify($ERRORS{'DEBUG'}, 0, "blocktime end: $blocktime_end");
+       notify($ERRORS{'DEBUG'}, 0, "owner email: $owner_email");
+       notify($ERRORS{'DEBUG'}, 0, "help address: $owner_email");
+       notify($ERRORS{'DEBUG'}, 0, "owner www addr: 
$owner_affiliation_sitewwwaddress");
 
        if ($blockrequest_mode eq "start") {
 
@@ -217,14 +232,41 @@ sub process {
                
                }
 
-               #pause
-               if (pauseprocessing($localtimer)) {
-                       notify($ERRORS{'OK'}, 0, "past check window for this 
request, -- ok to proceed");
+               # Notify block request owner for given time slot has been 
processed.
+       
+               if($completed){
+                       
+                       my $subject = "VCL Block allocation results for 
$blockrequest_name";
+                       my $mailstring .= <<"EOF";
+The block allocation for $blockrequest_name was processed with the following 
results:
+
+Block allocation name  = $blockrequest_name
+Machines allocated     = $allocated
+Machines requested     = $blockrequest_number_machines
+Block Start time       = $blocktime_start
+Block End time         = $blocktime_end
+User Group             = $block_group_name
+
+The machines for this block allocation will be loaded up to an hour before the 
actual start time. 
+Once loaded the users listed in the user group $block_group_name will be able 
to login up to 15 minutes 
+before the start time.
+
+To make changes or to view the status of this block allocation. Please visit,
+$owner_affiliation_sitewwwaddress/scheduling/index.php?mode=blockAllocations
+
+EOF
+                       if(defined($owner_email)){
+                               mail($owner_email, $subject, $mailstring, 
$owner_affiliation_helpaddress);
+                       }       
+               
                }
+       
+               sleep 10;
 
                if (update_blockrequest_processing($blockrequest_id, 0)) {
                        notify($ERRORS{'OK'}, 0, "Removed processing flag on 
blockrequest_id $blockrequest_id");
                }
+               
 
        } ## end if ($blockrequest_mode eq "start")
        elsif ($blockrequest_mode eq "end") {
@@ -241,7 +283,7 @@ sub process {
                if ($status eq "expire") {
                        #fork start processing
                        notify($ERRORS{'OK'}, 0, "Block Request 
$blockrequest_id has expired");
-                       
if(udpate_block_request_status($blockrequest_id,"completed"){
+                       
if(udpate_block_request_status($blockrequest_id,"completed")){
                                notify($ERRORS{'OK'}, 0, "Updated status of 
blockRequest id $blockrequest_id to completed");
                        }
                        return 1;

Modified: incubator/vcl/trunk/managementnode/lib/VCL/utils.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=986123&r1=986122&r2=986123&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/utils.pm Mon Aug 16 20:18:17 2010
@@ -115,6 +115,7 @@ our @EXPORT = qw(
   get_current_file_name
   get_current_package_name
   get_current_subroutine_name
+  get_group_name
   get_highest_imagerevision_info
   get_image_info
   get_imagemeta_info
@@ -133,6 +134,7 @@ our @EXPORT = qw(
   get_resource_groups
   get_managable_resource_groups
   get_vmhost_info
+  get_user_info
   getdynamicaddress
   getimagesize
   getnewdbh
@@ -996,15 +998,8 @@ sub check_blockrequest_time {
        #notify($ERRORS{'DEBUG'}, 0, "start:  $start_datetime,  epoch: 
$start_time_epoch_seconds,  delta: $start_delta_minutes minutes");
        #notify($ERRORS{'DEBUG'}, 0, "end:    $end_datetime,    epoch: 
$end_time_epoch_seconds,    delta: $end_delta_minutes minutes");
 
-       # 4:00 to 4:15 hours in advance: start assigning resources
-       if ($start_delta_minutes >= (4 * 60) && $start_delta_minutes <= (4 * 60 
+ 10)) {
-               # Block request within start window
-               notify($ERRORS{'OK'}, 0, "block request start time is within 
start window ($start_delta_minutes minutes from now), returning 'start'");
-               return "start";
-       }
-
-       # 2:00 to 2:15 hours in advance: start assigning resources
-       if ($start_delta_minutes >= (2 * 60) && $start_delta_minutes <= (2 * 60 
+ 10)) {
+       # if 30min to 6 hrs in advance: start assigning resources
+       if ($start_delta_minutes >= (30) && $start_delta_minutes <= (6 * 60)) {
                # Block request within start window
                notify($ERRORS{'OK'}, 0, "block request start time is within 
start window ($start_delta_minutes minutes from now), returning 'start'");
                return "start";
@@ -4877,6 +4872,7 @@ sub get_management_node_requests {
        return %requests;
 } ## end sub get_management_node_requests
 
+
 #/////////////////////////////////////////////////////////////////////////////
 
 =head2  get_image_info
@@ -7595,6 +7591,7 @@ sub get_management_node_blockrequests {
        WHERE
        blockRequest.managementnodeid = $managementnode_id AND
         blockRequest.status = 'accepted' AND
+       blockTimes.processed = '0' AND
        (blockTimes.skip = '0' AND blockTimes.start < (NOW() + INTERVAL 360 
MINUTE )) OR
         blockTimes.end < NOW() 
    ";
@@ -7631,6 +7628,9 @@ sub get_management_node_blockrequests {
 
                        if ($key =~ /blockRequest_/) {
                                $blockrequests{$blockrequest_id}{$original_key} 
= $value;
+                               if($key =~ /_groupid/){
+                                       
$blockrequests{$blockrequest_id}{groupname} = get_group_name($value);
+                               }
                        }
                        elsif ($key =~ /blockTimes_/) {
                                
$blockrequests{$blockrequest_id}{blockTimes}{$blocktimes_id}{$original_key} = 
$value;
@@ -7875,6 +7875,115 @@ sub get_computer_grp_members {
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 get_user_info
+
+ Parameters  : $user_id
+ Returns     : scalar - group name
+ Description :
+
+=cut
+
+sub get_user_info {
+        my ($user_id) = @_;
+
+
+        if(!defined($user_id)){
+                notify($ERRORS{'WARNING'}, $LOGFILE, "user_id was not 
supplied");
+                return 0;
+        }
+
+        my $select_statement = <<EOF;
+SELECT DISTINCT
+user.*,
+affiliation.sitewwwaddress AS sitewwwaddress,
+affiliation.helpaddress AS helpaddress
+FROM
+user,
+affiliation
+WHERE
+user.id = $user_id AND
+affiliation.id = user.affiliationid
+EOF
+
+       # Call the database select subroutine
+        # This will return an array of one or more rows based on the select 
statement
+        my @selected_rows = database_select($select_statement);
+       
+       # Check to make sure 1 row was returned
+        if (scalar @selected_rows == 0) {
+                notify($ERRORS{'OK'}, 0, "user id $user_id was not found in 
the database, 0 rows were returned");
+                return ();
+        }
+        elsif (scalar @selected_rows > 1) {
+                notify($ERRORS{'WARNING'}, 0, "" . scalar @selected_rows . " 
rows were returned from database select");
+                return ();
+        }
+
+        # A single row was returned (good)
+        # Return the hash
+        return %{$selected_rows[0]};
+
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 get_group_name
+
+ Parameters  : $group_id
+ Returns     : scalar - group name
+ Description :
+
+=cut
+
+sub get_group_name {
+       my ($group_id) = @_;
+       
+       
+       if(!defined($group_id)){
+               notify($ERRORS{'WARNING'}, $LOGFILE, "group_id was not 
supplied");
+               return 0;
+       }
+
+       my $select_statement = <<EOF;
+SELECT DISTINCT
+usergroup.name
+FROM
+usergroup
+WHERE
+usergroup.id = $group_id
+EOF
+
+
+ # Call the database select subroutine
+        # This will return an array of one or more rows based on the select 
statement
+        my @selected_rows = database_select($select_statement);
+
+        # Check to make sure 1 row was returned
+        if (scalar @selected_rows == 0) {
+                notify($ERRORS{'WARNING'}, 0, "zero rows were returned from 
database select");
+                return ();
+        }
+        elsif (scalar @selected_rows > 1) {
+                notify($ERRORS{'WARNING'}, 0, "" . scalar @selected_rows . " 
rows were returned from database select");
+                return ();
+        }
+
+        # Get the single returned row
+        # It contains a hash
+        my $end;
+
+        # Make sure we return undef if the column wasn't found
+        if (defined $selected_rows[0]{name}) {
+                my $groupname = $selected_rows[0]{name};
+                return $groupname;
+        }
+        else {
+                return undef;
+        }
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
 =head2 get_computer_info
 
  Parameters  : $computer_id


Reply via email to