Author: jfthomps
Date: Tue Dec 21 19:25:26 2010
New Revision: 1051622

URL: http://svn.apache.org/viewvc?rev=1051622&view=rev
Log:
VCL-426
modify scheduler to not give user same computer if user had very recent, short 
reservation and other computers are available

added getPossibleRecentFailures that checks for recent, short reservations by 
the user for the requested image
modified isAvailable: added call to getPossibleRecentFailures; if it returns 
computers, we remove them from available machines unless that would result in 
no machines

Modified:
    incubator/vcl/trunk/web/.ht-inc/utils.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=1051622&r1=1051621&r2=1051622&view=diff
==============================================================================
--- incubator/vcl/trunk/web/.ht-inc/utils.php (original)
+++ incubator/vcl/trunk/web/.ht-inc/utils.php Tue Dec 21 19:25:26 2010
@@ -3713,6 +3713,25 @@ function isAvailable($images, $imageid, 
                        $computerids = $newcompids;
                }
 
+               # remove any recently reserved computers that could have been an
+               #   undetected failure
+               $failedids = getPossibleRecentFailures($userid, $imageid);
+               if(! empty($failedids)) {
+                       if(! empty($computerids)) {
+                               $testids = array_diff($computerids, $failedids);
+                               if(! empty($testids)) {
+                                       $computerids = $testids;
+                                       $currentids = array_diff($currentids, 
$failedids);
+                               }
+                       }
+                       if(! empty($blockids)) {
+                               $testids = array_diff($blockids, $failedids);
+                               if(! empty($testids))
+                                       $blockids = $testids;
+                       }
+               }
+
+               # allocate a computer
                $comparr = allocComputer($blockids, $currentids, $computerids,
                                         $startstamp, $nowfuture);
                if(empty($comparr)) {
@@ -3817,6 +3836,42 @@ function allocComputer($blockids, $curre
 
 
////////////////////////////////////////////////////////////////////////////////
 ///
+/// \fn getPossibleRecentFailures($userid, $imageid)
+///
+/// \param $userid - check log data for this user; if $userid = 0, check for
+///                  currently logged in user
+/// \param $imageid - check log data for this image
+///
+/// \return array of computerids that may have recently given the user a 
problem
+///
+/// \brief checks for recent reservations by the user that were very short and
+/// within a recent time frame in case there was a computer that gave a problem
+/// that the backend did not pick up
+///
+////////////////////////////////////////////////////////////////////////////////
+function getPossibleRecentFailures($userid, $imageid) {
+       if($userid == 0) {
+               global $user;
+               $userid = $user['id'];
+       }
+       $comps = array();
+       $query = "SELECT s.computerid "
+              . "FROM log l "
+              . "LEFT JOIN sublog s ON (s.logid = l.id) "
+              . "WHERE l.start > (NOW() - INTERVAL 90 MINUTE) AND "
+              .       "l.finalend < NOW() AND "
+              .       "l.userid = $userid AND "
+              .       "l.imageid = $imageid AND "
+              .       "l.wasavailable = 1 AND "
+              .       "l.ending != 'failed'";
+       $qh = doQuery($query, 101);
+       while($row = mysql_fetch_assoc($qh))
+               $comps[] = $row['computerid'];
+       return $comps;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
 /// \fn getMappedResources($resourcesubid, $resourcetype1,
 ///                                 $resourcetype2)
 ///


Reply via email to