You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vcl.apache.org by jf...@apache.org on 2012/02/23 21:39:17 UTC

svn commit: r1292943 - in /incubator/vcl/trunk/web/.ht-inc: utils.php xmlrpcWrappers.php

Author: jfthomps
Date: Thu Feb 23 20:39:17 2012
New Revision: 1292943

URL: http://svn.apache.org/viewvc?rev=1292943&view=rev
Log:
VCL-383
make future reservations that would be part of a block allocation included in the block allocation

utils.php: modified isAvailable - added additional parameter that can be passed - $skipconcurrentcheck; if this is set to 1, it does not check the overlapping count for reservations of that image; when working with block allocations, it is often useful to call isAvailable for the block allocated time plus a leading reload amount, but then to only make the reservation for the leading reload time; this can cause an overlap for the check but not for the actual reservation

xmlrpcWrappers.php: modified XMLRPCprocessBlockTime - added code to look for any future reservations made by users in the user group associated with the block allocation for the same image; if so, try to include them in the block allocation to keep from tying up additional machines

Modified:
    incubator/vcl/trunk/web/.ht-inc/utils.php
    incubator/vcl/trunk/web/.ht-inc/xmlrpcWrappers.php

Modified: incubator/vcl/trunk/web/.ht-inc/utils.php
URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/web/.ht-inc/utils.php?rev=1292943&r1=1292942&r2=1292943&view=diff
==============================================================================
--- incubator/vcl/trunk/web/.ht-inc/utils.php (original)
+++ incubator/vcl/trunk/web/.ht-inc/utils.php Thu Feb 23 20:39:17 2012
@@ -3644,7 +3644,7 @@ function getBlockAllocationIDs($user) {
 ///
 /// \fn isAvailable($images, $imageid, $imagerevisionid, $start, $end,
 ///                 $requestid, $userid, $ignoreprivileges, $forimaging, $ip,
-///                 $mac)
+///                 $mac, $skipconcurrentcheck)
 ///
 /// \param $images - array as returned from getImages
 /// \param $imageid - imageid from the image table
@@ -3665,6 +3665,8 @@ function getBlockAllocationIDs($user) {
 /// be a server profile reservation if defined
 /// \param $mac - (optional, default='') mac address to be assigned; assumed to
 /// be a server profile reservation if defined
+/// \param $skipconcurrentcheck (optional, default=0) - set to 1 to skip check
+/// for concurrent use of image; useful for setting up reload reservations
 ///
 /// \return -3 if unavailable due to an ip/mac conflict
 ///         -2 if specified time period is during a maintenance window
@@ -3678,7 +3680,7 @@ function getBlockAllocationIDs($user) {
 ////////////////////////////////////////////////////////////////////////////////
 function isAvailable($images, $imageid, $imagerevisionid, $start, $end,
                      $requestid=0, $userid=0, $ignoreprivileges=0,
-                     $forimaging=0, $ip='', $mac='') {
+                     $forimaging=0, $ip='', $mac='', $skipconcurrentcheck=0) {
 	global $requestInfo;
 	$requestInfo["start"] = $start;
 	$requestInfo["end"] = $end;
@@ -3752,7 +3754,8 @@ function isAvailable($images, $imageid, 
 		$ignorestates .= ",'reloading','reload','timeout','inuse'";
 	foreach($requestInfo["images"] as $key => $imageid) {
 		# check for max concurrent usage of image
-		if($images[$imageid]['maxconcurrent'] != NULL) {
+		if(! $skipconcurrentcheck && 
+		   $images[$imageid]['maxconcurrent'] != NULL) {
 			$compids = array();
 			$reloadid = getUserlistID('vclreload@Local');
 			$query = "SELECT rs.computerid "

Modified: incubator/vcl/trunk/web/.ht-inc/xmlrpcWrappers.php
URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/web/.ht-inc/xmlrpcWrappers.php?rev=1292943&r1=1292942&r2=1292943&view=diff
==============================================================================
--- incubator/vcl/trunk/web/.ht-inc/xmlrpcWrappers.php (original)
+++ incubator/vcl/trunk/web/.ht-inc/xmlrpcWrappers.php Thu Feb 23 20:39:17 2012
@@ -1004,6 +1004,100 @@ function XMLRPCprocessBlockTime($blockTi
 		             'errormsg' => 'invalid image associated with block allocation');
 	}
 
+	$unixstart = datetimeToUnix($rqdata['start']);
+	$unixend = datetimeToUnix($rqdata['end']);
+	$revisionid = getProductionRevisionid($rqdata['imageid']);
+	$imgLoadTime = getImageLoadEstimate($rqdata['imageid']);
+	if($imgLoadTime == 0)
+		$imgLoadTime = $images[$rqdata['imageid']]['reloadtime'] * 60;
+	$vclreloadid = getUserlistID('vclreload@Local');
+	$groupmembers = getUserGroupMembers($rqdata['groupid']);
+	$userids = array_keys($groupmembers);
+
+	# add any computers from future reservations users in the group made
+	if(! empty($groupmembers)) {
+		## find reservations by users
+		$allids = implode(',', $userids);
+		$query = "SELECT rq.id AS reqid, "
+		       .        "UNIX_TIMESTAMP(rq.start) AS start, "
+		       .        "rq.userid "
+		       . "FROM request rq, "
+		       .      "reservation rs "
+		       . "WHERE rs.requestid = rq.id AND "
+		       .       "rq.userid IN ($allids) AND "
+		       .       "rq.start < '{$rqdata['end']}' AND "
+		       .       "rq.end > '{$rqdata['start']}' AND "
+		       .       "rs.imageid = {$rqdata['imageid']} AND "
+		       .       "rs.computerid NOT IN (SELECT computerid "
+		       .                             "FROM blockComputers "
+		       .                             "WHERE blockTimeid = $blockTimesid)";
+		$qh = doQuery($query);
+		$donereqids = array();
+		$blockCompVals = array();
+		$checkstartbase = $unixstart - $imgLoadTime - 300;
+		$reloadstartbase = unixToDatetime($checkstartbase);
+		$rows = mysql_num_rows($qh);
+		while($row = mysql_fetch_assoc($qh)) {
+			if(array_key_exists($row['reqid'], $donereqids))
+				continue;
+			$donereqids[$row['reqid']] = 1;
+			if($row['start'] < datetimeToUnix($rqdata['start'])) {
+				$checkstart = $row['start'] - $imgLoadTime - 300;
+				$reloadstart = unixToDatetime($checkstart);
+				$reloadend = unixToDatetime($row['start']);
+			}
+			else {
+				$checkstart = $checkstartbase;
+				$reloadstart = $reloadstartbase;
+				$reloadend = $rqdata['start'];
+			}
+			# check to see if computer is available for whole block
+			$rc = isAvailable($images, $rqdata['imageid'], $revisionid, $checkstart,
+			                  $unixend, $row['reqid'], $row['userid'],
+			                  $ignoreprivileges, 0, '', '', 1);
+			// if not available for whole block, just skip this one
+			if($rc < 1)
+				continue;
+			$compid = $requestInfo['computers'][0];
+			# create reload reservation
+			$reqid = simpleAddRequest($compid, $rqdata['imageid'], $revisionid,
+			                          $reloadstart, $reloadend, 19, $vclreloadid);
+			if($reqid == 0)
+				continue;
+			# add to blockComputers
+			$blockCompVals[] = "($blockTimesid, $compid, {$rqdata['imageid']}, $reqid)";
+			# process any subimages
+			for($key = 1; $key < count($requestInfo['computers']); $key++) {
+				$subimageid = $requestInfo['images'][$key];
+				$subrevid = getProductionRevisionid($subimageid);
+				$compid = $requestInfo['computers'][$key];
+				$mgmtnodeid = $requestInfo['mgmtnodes'][$key];
+				$blockCompVals[] = "($blockTimesid, $compid, $subimageid, $reqid)";
+
+				$query = "INSERT INTO reservation "
+						 .        "(requestid, "
+						 .        "computerid, "
+						 .        "imageid, "
+						 .        "imagerevisionid, "
+						 .        "managementnodeid) "
+						 . "VALUES "
+						 .       "($reqid, "
+						 .       "$compid, "
+						 .       "$subimageid, "
+						 .       "$subrevid, "
+						 .       "$mgmtnodeid)";
+				doQuery($query, 101);
+			}
+		}
+		if(count($blockCompVals)) {
+			$blockComps = implode(',', $blockCompVals);
+			$query = "INSERT INTO blockComputers "
+			       .        "(blockTimeid, computerid, imageid, reloadrequestid) "
+			       . "VALUES $blockComps";
+			doQuery($query);
+		}
+	}
+
 	# check to see if all computers have been allocated
 	$query = "SELECT COUNT(computerid) AS allocated "
 	       . "FROM blockComputers "
@@ -1020,19 +1114,23 @@ function XMLRPCprocessBlockTime($blockTi
 	else
 		$compsPerAlloc = 1;
 	$toallocate = ($rqdata['numMachines'] * $compsPerAlloc) - $compCompleted;
-	if($toallocate == 0)
+	if($toallocate == 0) {
+		if(count($blockCompVals)) {
+			return array('status' => 'success',
+			             'allocated' => $rqdata['numMachines'],
+			             'unallocated' => 0);
+		}
 		return array('status' => 'completed');
+	}
 	$reqToAlloc = $toallocate / $compsPerAlloc;
 
 	if(! $ignoreprivileges) {
 		# get userids in user group
-		$tmp = getUserGroupMembers($rqdata['groupid']);
-		if(empty($tmp)) {
+		if(empty($groupmembers)) {
 			return array('status' => 'error',
 			             'errorcode' => 11,
 			             'errormsg' => 'empty user group and ignoreprivileges set to 0');
 		}
-		$userids = array_keys($tmp);
 		# make length of $userids match $reqToAlloc by duplicating or trimming some users
 		while($reqToAlloc > count($userids))
 			$userids = array_merge($userids, $userids);
@@ -1046,23 +1144,16 @@ function XMLRPCprocessBlockTime($blockTi
 	$stagExtra = $reqToAlloc * 60;
 
 	# determine estimated load time
-	$imgLoadTime = getImageLoadEstimate($rqdata['imageid']);
-	if($imgLoadTime == 0)
-		$imgLoadTime = $images[$rqdata['imageid']]['reloadtime'] * 60;
 	$loadtime = $imgLoadTime + (10 * 60); # add 10 minute fudge factor
-	$unixstart = datetimeToUnix($rqdata['start']);
 	if((time() + $loadtime + $stagExtra) > $unixstart) {
 		$return['status'] = 'warning';
 		$return['warningcode'] = 13;
 		$return['warningmsg'] = 'possibly insufficient time to load machines';
 	}
 	$start = unixToDatetime($unixstart - $loadtime);
-	$unixend = datetimeToUnix($rqdata['end']);
 
 	$userid = 0;
 	$allocated = 0;
-	$vclreloadid = getUserlistID('vclreload@Local');
-	$revisionid = getProductionRevisionid($rqdata['imageid']);
 	$blockCompVals = array();
 	# FIXME (maybe) - if some subset of users in the user group have available
 	# computers, but others do not, $allocated will be less than the desired