Author: jfthomps
Date: Tue Feb 21 20:25:53 2012
New Revision: 1291988

URL: http://svn.apache.org/viewvc?rev=1291988&view=rev
Log:
VCL-234
give error when block reservations requests more resources than concurrent use 
of image

blockallocations.php: modified processBlockAllocationInput - flag an error if 
the number of seats is greater than the maxconcurrent number of reservations 
for the image



VCL-398
make block allocations tie up concurrent usage of image

utils.php: modified isAvailable - changed section that checks for max 
concurrent usage to count reservations and machines allocated to block 
allocations

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

Modified: incubator/vcl/trunk/web/.ht-inc/blockallocations.php
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/web/.ht-inc/blockallocations.php?rev=1291988&r1=1291987&r2=1291988&view=diff
==============================================================================
--- incubator/vcl/trunk/web/.ht-inc/blockallocations.php (original)
+++ incubator/vcl/trunk/web/.ht-inc/blockallocations.php Tue Feb 21 20:25:53 
2012
@@ -2915,6 +2915,16 @@ function processBlockAllocationInput() {
                        . ' and ' . MAX_BLOCK_MACHINES . '.';
                $err = 1;
        }
+       if(! $err) {
+               $imgdata = getImages(0, $return['imageid']);
+               $concur = $imgdata[$return['imageid']]['maxconcurrent'];
+               if($return['seats'] > $concur) {
+                       $errmsg = "The selected image can only have $concur 
concurrent "
+                               . "reservations. Please reduce the number of 
requested "
+                               . "seats to $concur or less.";
+                       $err = 1;
+               }
+       }
        if(! $err && $type != 'weekly' && $type != 'monthly' && $type != 
'list') {
                $errmsg = 'You must select one of "Repeating Weekly", 
"Repeating Monthly", '
                        . 'or "List of Dates/Times".';

Modified: incubator/vcl/trunk/web/.ht-inc/utils.php
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/web/.ht-inc/utils.php?rev=1291988&r1=1291987&r2=1291988&view=diff
==============================================================================
--- incubator/vcl/trunk/web/.ht-inc/utils.php (original)
+++ incubator/vcl/trunk/web/.ht-inc/utils.php Tue Feb 21 20:25:53 2012
@@ -3753,20 +3753,40 @@ function isAvailable($images, $imageid, 
        foreach($requestInfo["images"] as $key => $imageid) {
                # check for max concurrent usage of image
                if($images[$imageid]['maxconcurrent'] != NULL) {
-                       $query = "SELECT COUNT(rs.imageid) AS currentusage "
+                       $compids = array();
+                       $reloadid = getUserlistID('vclreload@Local');
+                       $query = "SELECT rs.computerid "
                               . "FROM reservation rs, "
                               .      "request rq "
                               . "WHERE '$startstamp' < (rq.end + INTERVAL 900 
SECOND) AND "
                               .       "'$endstamp' > rq.start AND "
                               .       "rs.requestid = rq.id AND "
                               .       "rs.imageid = $imageid AND "
-                              .       "rq.stateid NOT IN (1,5,11,12,16,17)";
+                              .       "rq.stateid NOT IN (1,5,11,12,16,17) AND 
"
+                              .       "rq.userid != $reloadid";
                        $qh = doQuery($query, 101);
+                       while($row = mysql_fetch_assoc($qh))
+                               $compids[] = $row['computerid'];
+                       $usagecnt = count($compids);
+                       $allids = implode("','", $compids);
+                       $query = "SELECT COUNT(bc.imageid) AS currentusage "
+                              . "FROM blockComputers bc, "
+                              .      "blockRequest br, "
+                              .      "blockTimes bt "
+                              . "WHERE bc.blockTimeid = bt.id AND "
+                              .       "bt.blockRequestid = br.id AND "
+                              .       "bc.imageid = $imageid AND "
+                              .       "bc.computerid NOT IN ('$allids') AND "
+                              .       "'$startstamp' < (bt.end + INTERVAL 900 
SECOND) AND "
+                              .       "'$endstamp' > bt.start AND "
+                              .       "bt.skip != 1 AND "
+                              .       "br.status != 'deleted'";
+                       $qh = doQuery($query);
                        if(! $row = mysql_fetch_assoc($qh)) {
                                semUnlock();
                                return 0;
                        }
-                       if($row['currentusage'] >= 
$images[$imageid]['maxconcurrent']) {
+                       if(($usagecnt + $row['currentusage']) >= 
$images[$imageid]['maxconcurrent']) {
                                semUnlock();
                                return -1;
                        }


Reply via email to