Author: jfthomps
Date: Mon Apr 2 19:53:51 2012
New Revision: 1308508
URL: http://svn.apache.org/viewvc?rev=1308508&view=rev
Log:
VCL-568
refresh current reservations page 15 minutes after a reservation becomes
available
requests.php:
-modified viewRequests - added a hidden element to most reservations that is
the next timeout value
-modified getViewRequestHTMLitem - added timeoutdata
-modified connectRequest - added call to addConnectTimeout if
getReservationConnectTimeout returns null; added hidden element that is the
next timeout value; added dijit dialog that says reservation has timed out
-added AJcheckConnectTimeout
-added getReservationNextTimeout
-added getReservationConnectTimeout
-added addConnectTimeout
utils.php:
-modified getComputers - (unrelated to this JIRA) fixed bug introduced when
changing how vmprofileid gets set; there needed to be 2 joins to the vmhost
table, one for vms and one for vm hosts
-modified getDojoHTML - added dijit.form.Button and dijit.Dialog to
connectRequest state; added dojo css, dojo requires and a timeout call for
checkConnectTimeout for connectRequest state; added timeout call for
checkTimeouts to viewRequests state
states.php: added AJcheckConnectTimeout
requests.js:
-added checkTimeouts
-added checkConnectTimeout
-added checkConnectTimeoutCB
Modified:
incubator/vcl/trunk/web/.ht-inc/requests.php
incubator/vcl/trunk/web/.ht-inc/states.php
incubator/vcl/trunk/web/.ht-inc/utils.php
incubator/vcl/trunk/web/js/requests.js
Modified: incubator/vcl/trunk/web/.ht-inc/requests.php
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/web/.ht-inc/requests.php?rev=1308508&r1=1308507&r2=1308508&view=diff
==============================================================================
--- incubator/vcl/trunk/web/.ht-inc/requests.php (original)
+++ incubator/vcl/trunk/web/.ht-inc/requests.php Mon Apr 2 19:53:51 2012
@@ -1001,10 +1001,14 @@ function viewRequests() {
}
$text .= " </div>\n";
$text .= " </div>\n";
+ $text .=
getViewRequestHTMLitem('timeoutdata', $requests[$i]['id'], $requests[$i]);
$text .= " </TD>\n";
}
- else
- $text .= " <TD></TD>\n";
+ else {
+ $text .= " <TD>";
+ $text .=
getViewRequestHTMLitem('timeoutdata', $requests[$i]['id'], $requests[$i]);
+ $text .= "</TD>\n";
+ }
}
else
$text .= " <TD></TD>\n";
@@ -1452,7 +1456,7 @@ function getViewRequestHTMLitem($item, $
$r .= " <TD>\n";
$r .= " <button dojoType=\"dijit.form.Button\">\n";
$r .= " Delete\n";
- $r .= " <script type=\"dojo/method\"
event=\"onClick\">\n";
+ $r .= " <script type=\"dojo/method\"
event=\"onClick\">\n";
$r .= " endReservation('$var1');\n";
$r .= " </script>\n";
$r .= " </button>\n";
@@ -1479,7 +1483,7 @@ function getViewRequestHTMLitem($item, $
$r .= " <TD>\n";
$r .= " <button dojoType=\"dijit.form.Button\">\n";
$r .= " Remove\n";
- $r .= " <script type=\"dojo/method\"
event=\"onClick\">\n";
+ $r .= " <script type=\"dojo/method\"
event=\"onClick\">\n";
$r .= " removeReservation('$var1');\n";
$r .= " </script>\n";
$r .= " </button>\n";
@@ -1565,7 +1569,7 @@ function getViewRequestHTMLitem($item, $
$r .= " <div dojoType=\"dijit.MenuItem\"\n";
$r .= " iconClass=\"noicon\"\n";
$r .= " label=\"Reboot\">\n";
- $r .= " <script type=\"dojo/method\"
event=\"onClick\">\n";
+ $r .= " <script type=\"dojo/method\"
event=\"onClick\">\n";
$r .= " rebootRequest('$var1');\n";
$r .= " </script>\n";
$r .= " </div>\n";
@@ -1582,7 +1586,7 @@ function getViewRequestHTMLitem($item, $
$r .= " <div dojoType=\"dijit.MenuItem\"\n";
$r .= " iconClass=\"noicon\"\n";
$r .= " label=\"Reinstall\">\n";
- $r .= " <script type=\"dojo/method\"
event=\"onClick\">\n";
+ $r .= " <script type=\"dojo/method\"
event=\"onClick\">\n";
$r .= " showReinstallRequest('$var1');\n";
$r .= " </script>\n";
$r .= " </div>\n";
@@ -1666,6 +1670,19 @@ function getViewRequestHTMLitem($item, $
$r .= "</TD>\n";
return $r;
}
+ if($item == 'timeoutdata') {
+ if($data['currstateid'] == 8 ||
+ ($data['currstateid'] == 14 && $data['laststateid'] == 8)) {
+ $end = datetimeToUnix($data['end']) + 15;
+ $r .= " <input type=\"hidden\"
class=\"timeoutvalue\" value=\"$end\">\n";
+ }
+ else {
+ $timeout = getReservationNextTimeout($data['resid']);
+ if(! is_null($timeout))
+ $r .= " <input type=\"hidden\"
class=\"timeoutvalue\" value=\"$timeout\">\n";
+ }
+ return $r;
+ }
}
////////////////////////////////////////////////////////////////////////////////
@@ -3285,8 +3302,13 @@ function connectRequest() {
print "is no longer available.<br>\n";
return;
}
+ $timeout =
getReservationConnectTimeout($requestData['reservations'][0]['reservationid']);
+ if(is_null($timeout))
+
addConnectTimeout($requestData['reservations'][0]['reservationid'],
+
$requestData['reservations'][0]['computerid']);
+ $now = time();
if($requestData['reservations'][0]['remoteIP'] != $remoteIP) {
- $setback = unixToDatetime(time() - 600);
+ $setback = unixToDatetime($now - 600);
$query = "UPDATE reservation "
. "SET remoteIP = '$remoteIP', "
. "lastcheck = '$setback' "
@@ -3296,6 +3318,9 @@ function connectRequest() {
addChangeLogEntry($requestData["logid"], $remoteIP);
}
+ if(! is_null($timeout))
+ print "<input type=\"hidden\" id=\"timeoutvalue\"
value=\"$timeout\">\n";
+
print "<H2 align=center>Connect!</H2>\n";
if($requestData['forimaging']) {
print "<font color=red><big><strong>NOTICE:</strong> Later in
this process, you must accept a
@@ -3364,7 +3389,7 @@ function connectRequest() {
print "<FORM action=\"" . BASEURL . SCRIPT .
"\" method=post>\n";
$cdata = array('requestid' => $requestid,
'resid' =>
$res['reservationid']);
- $expire = datetimeToUnix($requestData['end']) -
time() + 1800; # remaining reservation time plus 30 min
+ $expire = datetimeToUnix($requestData['end']) -
$now + 1800; # remaining reservation time plus 30 min
$cont = addContinuationsEntry('sendRDPfile',
$cdata, $expire);
print "<INPUT type=hidden name=continuation
value=\"$cont\">\n";
print "<INPUT type=submit value=\"Get RDP
File\">\n";
@@ -3375,6 +3400,52 @@ function connectRequest() {
if($cluster)
print "</fieldset><br>\n";
}
+ $cdata = array('requestid' => $requestid);
+ $cont = addContinuationsEntry('AJcheckConnectTimeout', $cdata,
SECINDAY);
+ print "<input type=\"hidden\" id=\"refreshcont\" value=\"$cont\">\n";
+ print "<div dojoType=dijit.Dialog\n";
+ print " id=\"timeoutdlg\"\n";
+ print " title=\"Reservation Timed Out\"\n";
+ print " duration=250\n";
+ print " draggable=false>\n";
+ print "This reservation has timed out<br>and is no longer
available.<br><br>\n";
+ print " <div align=\"center\">\n";
+ print " <button dojoType=\"dijit.form.Button\">\n";
+ print " Okay\n";
+ print " <script type=\"dojo/method\" event=\"onClick\">\n";
+ print " dijit.byId('timeoutdlg').hide();\n";
+ print " </script>\n";
+ print " </button>\n";
+ print " </div>\n";
+ print "</div>\n";
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn AJcheckConnectTimeout()
+///
+/// \brief checks to see if a reservation has timed out
+///
+////////////////////////////////////////////////////////////////////////////////
+function AJcheckConnectTimeout() {
+ $requestid = getContinuationVar('requestid');
+ $reqdata = getRequestInfo($requestid, 1);
+ $stateid = $reqdata['stateid'];
+ if($stateid == 14)
+ $stateid == $reqdata['laststateid'];
+ if(is_null($reqdata) ||
+ $stateid == 1 ||
+ $stateid == 11 ||
+ $stateid == 12 ||
+ $stateid == 16 ||
+ $stateid == 17) {
+ $data['status'] = 'timeout';
+ sendJSON($data);
+ return;
+ }
+ $data['status'] = 'inuse';
+ sendJSON($data);
+ return;
}
////////////////////////////////////////////////////////////////////////////////
@@ -3594,4 +3665,101 @@ function processRequestInput($checks=1)
$return["testjavascript"] = 0;
return $return;
}
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn getReservationNextTimeout($resid)
+///
+/// \param $resid - reservation id
+///
+/// \return unix timestamp
+///
+/// \brief determines the time at which the specified reservation will time out
+/// if not acknowledged or NULL if there is no entry
+///
+////////////////////////////////////////////////////////////////////////////////
+function getReservationNextTimeout($resid) {
+ $query = "SELECT UNIX_TIMESTAMP(cll.timestamp) AS timestamp, "
+ . "cll.loadstateid, "
+ . "v1.value AS acknowledgetimeout, "
+ . "v2.value AS connecttimeout "
+ . "FROM computerloadlog cll, "
+ . "variable v1, "
+ . "variable v2 "
+ . "WHERE cll.reservationid = $resid AND "
+ . "(cll.loadstateid = 18 OR "
+ . "cll.loadstateid = 55) AND "
+ . "v1.name = 'acknowledgetimeout' AND "
+ . "v2.name = 'connecttimeout' "
+ . "ORDER BY cll.timestamp DESC "
+ . "LIMIT 1";
+ #return $query; TODO debug
+ $qh = doQuery($query);
+ if($row = mysql_fetch_assoc($qh)) {
+ if(! is_numeric($row['timestamp']))
+ return NULL;
+ if($row['loadstateid'] == 18)
+ return $row['timestamp'] + $row['acknowledgetimeout'] +
15;
+ elseif($row['loadstateid'] == 55)
+ return $row['timestamp'] + $row['connecttimeout'] + 15;
+ else
+ return NULL;
+ }
+ else
+ return NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn getReservationConnectTimeout($resid)
+///
+/// \param $resid - reservation id
+///
+/// \return unix timestamp
+///
+/// \brief determines the time at which the specified reservation will time out
+/// if not connected or NULL if there is no entry
+///
+////////////////////////////////////////////////////////////////////////////////
+function getReservationConnectTimeout($resid) {
+ $query = "SELECT UNIX_TIMESTAMP(cll.timestamp) AS timestamp, "
+ . "v.value AS connecttimeout "
+ . "FROM computerloadlog cll, "
+ . "variable v "
+ . "WHERE cll.reservationid = $resid AND "
+ . "cll.loadstateid = 55 AND "
+ . "v.name = 'connecttimeout'";
+ $qh = doQuery($query);
+ if($row = mysql_fetch_assoc($qh)) {
+ if(! is_numeric($row['timestamp']))
+ return NULL;
+ return $row['timestamp'] + $row['connecttimeout'] + 15;
+ }
+ else
+ return NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn addConnectTimeout($resid, $compid)
+///
+/// \param $resid - reservation id
+/// \param $compid - computer id
+///
+/// \brief inserts a connecttimeout entry in computerloadlog for $resid/$compid
+///
+////////////////////////////////////////////////////////////////////////////////
+function addConnectTimeout($resid, $compid) {
+ $query = "INSERT INTO computerloadlog "
+ . "(reservationid, "
+ . "computerid, "
+ . "loadstateid, "
+ . "timestamp) "
+ . "VALUES "
+ . "($resid, "
+ . "$compid, "
+ . "55, "
+ . "NOW())";
+ doQuery($query);
+}
?>
Modified: incubator/vcl/trunk/web/.ht-inc/states.php
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/web/.ht-inc/states.php?rev=1308508&r1=1308507&r2=1308508&view=diff
==============================================================================
--- incubator/vcl/trunk/web/.ht-inc/states.php (original)
+++ incubator/vcl/trunk/web/.ht-inc/states.php Mon Apr 2 19:53:51 2012
@@ -169,6 +169,7 @@ $noHTMLwrappers = array('sendRDPfile',
'AJsubmitDeleteRequest',
'AJconfirmRemoveRequest',
'AJsubmitRemoveRequest',
+ 'AJcheckConnectTimeout',
'AJsetImageProduction',
'AJsubmitSetImageProduction',
'AJeditRequest',
@@ -214,6 +215,7 @@ $actions['mode']['AJconfirmRemoveRequest
$actions['mode']['AJsubmitRemoveRequest'] = "AJsubmitRemoveRequest";
$actions['mode']['connectRequest'] = "connectRequest";
$actions['mode']['sendRDPfile'] = "sendRDPfile";
+$actions['mode']['AJcheckConnectTimeout'] = "AJcheckConnectTimeout";
#$actions['mode']['connectMindterm'] = "connectMindterm";
#$actions['mode']['connectRDPapplet'] = "connectRDPapplet";
$actions['pages']['viewRequests'] = "currentReservations";
@@ -226,6 +228,7 @@ $actions['pages']['AJconfirmRemoveReques
$actions['pages']['AJsubmitRemoveRequest'] = "currentReservations";
$actions['pages']['connectRequest'] = "currentReservations";
$actions['pages']['sendRDPfile'] = "currentReservations";
+$actions['pages']['AJcheckConnectTimeout'] = "currentReservations";
#$actions['pages']['connectMindterm'] = "currentReservations";
#$actions['pages']['connectRDPapplet'] = "currentReservations";
Modified: incubator/vcl/trunk/web/.ht-inc/utils.php
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/web/.ht-inc/utils.php?rev=1308508&r1=1308507&r2=1308508&view=diff
==============================================================================
--- incubator/vcl/trunk/web/.ht-inc/utils.php (original)
+++ incubator/vcl/trunk/web/.ht-inc/utils.php Mon Apr 2 19:53:51 2012
@@ -7098,7 +7098,7 @@ function getComputers($sort=0, $included
. "c.location, "
. "c.provisioningid, "
. "pr.prettyname AS provisioning, "
- . "vh.vmprofileid "
+ . "vh2.vmprofileid "
. "FROM state st, "
. "platform p, "
. "schedule sc, "
@@ -7108,8 +7108,8 @@ function getComputers($sort=0, $included
. "user u, "
. "affiliation a, "
. "computer c "
- . "LEFT JOIN vmhost vh ON (c.id = vh.computerid) "
- . "LEFT JOIN vmtype vt ON (c.vmtypeid = vt.id) "
+ . "LEFT JOIN vmhost vh ON (c.vmhostid = vh.id) "
+ . "LEFT JOIN vmhost vh2 ON (c.id = vh2.computerid) "
. "LEFT JOIN computer c2 ON (c2.id = vh.computerid) "
. "LEFT JOIN image next ON (c.nextimageid = next.id) "
. "LEFT JOIN provisioning pr ON (c.provisioningid = pr.id) "
@@ -10369,7 +10369,9 @@ function getDojoHTML($refresh) {
'dijit.form.FilteringSelect');
break;
case 'connectRequest':
- $dojoRequires = array('dojo.parser');
+ $dojoRequires = array('dojo.parser',
+ 'dijit.form.Button',
+ 'dijit.Dialog');
break;
case 'viewRequestInfo':
$dojoRequires = array('dojo.parser',
@@ -10583,12 +10585,20 @@ function getDojoHTML($refresh) {
return '';
switch($mode) {
case "connectRequest":
+ $rt .= "<style type=\"text/css\">\n";
+ $rt .= " @import
\"themes/$skin/css/dojo/$skin.css\";\n";
+ $rt .= "</style>\n";
$rt .= "<script type=\"text/javascript\"
src=\"dojo/dojo/dojo.js\"\n";
$rt .= " djConfig=\"parseOnLoad: true\">\n";
$rt .= "</script>\n";
$rt .= "<script type=\"text/javascript\"
src=\"js/requests.js\"></script>\n";
$rt .= "<script type=\"text/javascript\">\n";
- $rt .= " dojo.addOnLoad(showRDPbutton);\n";
+ $rt .= " dojo.addOnLoad(function() {\n";
+ foreach($dojoRequires as $req)
+ $rt .= " dojo.require(\"$req\");\n";
+ $rt .= " showRDPbutton();\n";
+ $rt .= " setTimeout(checkConnectTimeout, 15000);\n";
+ $rt .= " });\n";
$rt .= "</script>\n";
return $rt;
@@ -10615,6 +10625,7 @@ function getDojoHTML($refresh) {
$rt .= " });\n";
if($refresh)
$rt .= " refresh_timer =
setTimeout(resRefresh, 12000);\n";
+ $rt .= " check_timeout_timer =
setTimeout(checkTimeouts, 15000);\n";
$rt .= "</script>\n";
return $rt;
Modified: incubator/vcl/trunk/web/js/requests.js
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/web/js/requests.js?rev=1308508&r1=1308507&r2=1308508&view=diff
==============================================================================
--- incubator/vcl/trunk/web/js/requests.js (original)
+++ incubator/vcl/trunk/web/js/requests.js Mon Apr 2 19:53:51 2012
@@ -265,6 +265,22 @@ function setMaxRequestLength(minutes) {
}
}
+function checkTimeouts() {
+ var nextcheck = 15;
+ var nodes = dojo.query('.timeoutvalue');
+ var tmp = new Date();
+ var now = (tmp.getTime() - tmp.getMilliseconds()) / 1000;
+ for(var i = 0; i < nodes.length; i++) {
+ if(nodes[i].value <= now) {
+ resRefresh();
+ break;
+ }
+ else if(nodes[i].value - now < nextcheck)
+ nextcheck = nodes[i].value - now;
+ }
+ check_timeout_timer = setTimeout(checkTimeouts, nextcheck * 1000);
+}
+
function resRefresh() {
if(! dojo.byId('resRefreshCont'))
return;
@@ -700,6 +716,34 @@ function submitReinstallReservationCB(da
}
}
+function checkConnectTimeout() {
+ var nextcheck = 15;
+ if(! dojo.byId('timeoutvalue'))
+ return;
+ var timeout = dojo.byId('timeoutvalue').value;
+ var tmp = new Date();
+ var now = (tmp.getTime() - tmp.getMilliseconds()) / 1000;
+ if(timeout <= now) {
+ var cont = dojo.byId('refreshcont').value;
+ RPCwrapper({continuation: cont}, checkConnectTimeoutCB, 1);
+ return;
+ }
+ else if(timeout - now < nextcheck) {
+ nextcheck = timeout - now;
+ }
+ setTimeout(checkConnectTimeout, nextcheck * 1000);
+}
+
+function checkConnectTimeoutCB(data, ioArgs) {
+ if(data.items.status == 'timeout') {
+ dijit.byId('timeoutdlg').show();
+ return;
+ }
+ else if(data.items.status == 'inuse') {
+ setTimeout(checkConnectTimeout, 300000);
+ }
+}
+
function showRDPbutton() {
// submitted by Gerhard Harti from ODU
if(! dojo.byId('counterdiv') || ! dojo.byId('connectdiv'))