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 2010/10/26 21:10:46 UTC
svn commit: r1027688 - in /incubator/vcl/trunk/web:
.ht-inc/blockallocations.php .ht-inc/states.php .ht-inc/utils.php
js/blockallocations.js
Author: jfthomps
Date: Tue Oct 26 19:10:45 2010
New Revision: 1027688
URL: http://svn.apache.org/viewvc?rev=1027688&view=rev
Log:
VCL-406
add some charts to see how machines are allocated to block allocations
utils.php: modified getDojoHTML - added case statements for viewBlockAllocatedMachines
blockallocations.php:
-modified blockAllocations - added link to page of allocated machines charts
-added viewBlockAllocatedMachines
-added getChartHTML
-added AJgetBlockAllocatedMachineData
states.php:
-added viewBlockAllocatedMachines
-added AJgetBlockAllocatedMachineData
js/blockallocations.js:
-added updateAllocatedMachines
-added updateAllocatedMachinesCB
-added timestampToTimeBare
-added timestampToTimeVirtual
Modified:
incubator/vcl/trunk/web/.ht-inc/blockallocations.php
incubator/vcl/trunk/web/.ht-inc/states.php
incubator/vcl/trunk/web/.ht-inc/utils.php
incubator/vcl/trunk/web/js/blockallocations.js
Modified: incubator/vcl/trunk/web/.ht-inc/blockallocations.php
URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/web/.ht-inc/blockallocations.php?rev=1027688&r1=1027687&r2=1027688&view=diff
==============================================================================
--- incubator/vcl/trunk/web/.ht-inc/blockallocations.php (original)
+++ incubator/vcl/trunk/web/.ht-inc/blockallocations.php Tue Oct 26 19:10:45 2010
@@ -44,6 +44,8 @@ function blockAllocations() {
}
else {
print "<h2>Manage Block Allocations</h2>\n";
+ $cont = addContinuationsEntry('viewBlockAllocatedMachines');
+ print "<a href=\"" . BASEURL . SCRIPT . "?continuation=$cont\">View Block Allocated Machines</a>\n";
print "<div id=\"blocklist\">\n";
print getCurrentBlockHTML();
print "</div>\n";
@@ -3440,4 +3442,201 @@ function AJpopulateBlockStore() {
}
}
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn viewBlockAllocatedMachines()
+///
+/// \brief prints a page that displays charts of machines allocated to block
+/// allocations
+///
+////////////////////////////////////////////////////////////////////////////////
+function viewBlockAllocatedMachines() {
+ print "<h2>Block Allocated Bare Machines</h2>\n";
+ print "Start time: \n";
+ $start = unixToDatetime(unixFloor15(time() - 3600));
+ list($sdate, $stime) = explode(' ', $start);
+ print "<div type=\"text\" id=\"chartstartdate\" dojoType=\"dijit.form.DateTextBox\" ";
+ print "required=\"true\" value=\"$sdate\"></div>\n";
+ print "<div type=\"text\" id=\"chartstarttime\" dojoType=\"dijit.form.TimeTextBox\" ";
+ print "required=\"true\" value=\"T$stime\" style=\"width: 78px\"></div>\n";
+ print "<button dojoType=\"dijit.form.Button\" type=\"button\" ";
+ print "id=\"updatechart\">\n";
+ print " Update Charts\n";
+ print " <script type=\"dojo/method\" event=\"onClick\">\n";
+ print " updateAllocatedMachines();\n";
+ print " </script>\n";
+ print "</button>\n";
+ print "<h3>Bare Machines</h3>\n";
+ print "<div id=\"totalbare\"></div>\n";
+ print getChartHTML('allocatedBareMachines');
+ print "<h3>Virtual Machines</h3>\n";
+ print "<div id=\"totalvirtual\"></div>\n";
+ print getChartHTML('allocatedVirtualMachines');
+ $cont = addContinuationsEntry('AJgetBlockAllocatedMachineData', array('val' => 0), SECINDAY, 1, 0);
+ print "<input type=\"hidden\" id=\"updatecont\" value=\"$cont\">\n";
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn getChartHTML($id)
+///
+/// \param $id = js id for the dojo chart
+///
+/// \return html to build a dojo chart
+///
+/// \brief creates the html needed to generate a dojo chart
+///
+////////////////////////////////////////////////////////////////////////////////
+function getChartHTML($id) {
+ $txt = "<div class=\"dashwidget\">\n";
+ $txt .= "<div dojoType=\"dojox.charting.widget.Chart2D\" id=\"$id\"\n";
+ $txt .= " theme=\"dojox.charting.themes.ThreeD\"\n";
+ $txt .= " style=\"width: 500px; height: 300px;\">\n";
+ $txt .= "<div class=\"axis\"\n";
+ $txt .= " name=\"x\"\n";
+ if($id == 'allocatedBareMachines')
+ $txt .= " labelFunc=\"timestampToTimeBare\"\n";
+ elseif($id == 'allocatedVirtualMachines')
+ $txt .= " labelFunc=\"timestampToTimeVirtual\"\n";
+ $txt .= " maxLabelSize=\"35\"\n";
+ $txt .= " rotation=\"-90\"\n";
+ $txt .= " majorTickStep=\"4\"\n";
+ $txt .= " minorTickStep=\"1\">\n";
+ $txt .= " </div>\n";
+ $txt .= "<div class=\"axis\" name=\"y\" vertical=\"true\" includeZero=\"true\"></div>\n";
+ $txt .= "<div class=\"plot\" name=\"default\" type=\"Columns\"></div>\n";
+ $txt .= "<div class=\"plot\" name=\"grid\" type=\"Grid\" vMajorLines=\"false\"></div>\n";
+ $txt .= "<div class=\"series\" name=\"Main\" data=\"0\"></div>\n";
+ $txt .= "<div class=\"action\" type=\"Tooltip\"></div>\n";
+ $txt .= "<div class=\"action\" type=\"Magnify\"></div>\n";
+ $txt .= "</div>\n";
+ $txt .= "</div>\n";
+ return $txt;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn AJgetBlockAllocatedMachineData()
+///
+/// \brief gets data about machines allocated to block allocations for the time
+/// period starting with submitted start and ending 12 hours later; sends data
+/// in JSON format
+///
+////////////////////////////////////////////////////////////////////////////////
+function AJgetBlockAllocatedMachineData() {
+ $start = processInputVar('start', ARG_STRING);
+ if(! preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/', $start)) {
+ $start = unixFloor15(time() - 3600);
+ $startdt = unixToDatetime($start);
+ }
+ else {
+ $startdt = "$start:00";
+ $start = datetimeToUnix($startdt);
+ }
+ $end = $start + (12 * 3600);
+ $enddt = unixToDatetime($end);
+ $alldata = array();
+
+ # bare
+ $data = array();
+ $query = "SELECT COUNT(id) "
+ . "FROM computer "
+ . "WHERE stateid IN (2, 3, 6, 8, 11) AND "
+ . "type = 'blade'";
+ $qh = doQuery($query, 101);
+ if($row = mysql_fetch_row($qh))
+ $data['total'] = $row[0];
+ for($time = $start, $i = 0; $time < $end; $time += 900, $i++) {
+ $fmttime = date('g:i a', $time);
+ $data["points"][$i] = array('x' => $i, 'y' => 0, 'value' => $i, 'text' => $fmttime);
+ }
+ $data['maxy'] = 0;
+ $query = "SELECT UNIX_TIMESTAMP(bt.start) as start, "
+ . "UNIX_TIMESTAMP(bt.end) as end, "
+ . "br.numMachines "
+ . "FROM blockTimes bt, "
+ . "blockRequest br, "
+ . "image i, "
+ . "OS o "
+ . "WHERE bt.blockRequestid = br.id AND "
+ . "bt.skip = 0 AND "
+ . "bt.start < '$enddt' AND "
+ . "bt.end > '$startdt' AND "
+ . "br.imageid = i.id AND "
+ . "i.OSid = o.id AND "
+ . "o.installtype != 'vmware'";
+ $qh = doQuery($query, 101);
+ while($row = mysql_fetch_assoc($qh)) {
+ for($binstart = $start, $binend = $start + 900, $binindex = 0;
+ $binend <= $end;
+ $binstart += 900, $binend += 900, $binindex++) {
+ if($binend <= $row['start'])
+ continue;
+ elseif($row['start'] < $binend && $row['end'] > $binstart)
+ $data["points"][$binindex]['y'] += $row['numMachines'];
+ elseif($binstart >= $row['end'])
+ break;
+ }
+ }
+ for($time = $start, $i = 0; $time < $end; $time += 900, $i++) {
+ if($data["points"][$i]['y'] > $data['maxy'])
+ $data['maxy'] = $data['points'][$i]['y'];
+ $data["points"][$i]['tooltip'] = "{$data['points'][$i]['text']}: {$data['points'][$i]['y']}";
+ }
+ $alldata['bare'] = $data;
+
+ # virtual
+ $data = array();
+ $query = "SELECT COUNT(id) "
+ . "FROM computer "
+ . "WHERE stateid IN (2, 3, 6, 8, 11) AND "
+ . "type = 'virtualmachine'";
+ $qh = doQuery($query, 101);
+ if($row = mysql_fetch_row($qh))
+ $data['total'] = $row[0];
+ for($time = $start, $i = 0; $time < $end; $time += 900, $i++) {
+ $fmttime = date('g:i a', $time);
+ $data["points"][$i] = array('x' => $i, 'y' => 0, 'value' => $i, 'text' => $fmttime);
+ }
+ $data['maxy'] = 0;
+ $query = "SELECT UNIX_TIMESTAMP(bt.start) as start, "
+ . "UNIX_TIMESTAMP(bt.end) as end, "
+ . "br.numMachines "
+ . "FROM blockTimes bt, "
+ . "blockRequest br, "
+ . "image i, "
+ . "OS o "
+ . "WHERE bt.blockRequestid = br.id AND "
+ . "bt.skip = 0 AND "
+ . "bt.start < '$enddt' AND "
+ . "bt.end > '$startdt' AND "
+ . "br.imageid = i.id AND "
+ . "i.OSid = o.id AND "
+ . "o.installtype = 'vmware'";
+ $qh = doQuery($query, 101);
+ while($row = mysql_fetch_assoc($qh)) {
+ for($binstart = $start, $binend = $start + 900, $binindex = 0;
+ $binend <= $end;
+ $binstart += 900, $binend += 900, $binindex++) {
+ if($binend <= $row['start'])
+ continue;
+ elseif($row['start'] < $binend && $row['end'] > $binstart)
+ $data["points"][$binindex]['y'] += $row['numMachines'];
+ elseif($binstart >= $row['end'])
+ break;
+ }
+ }
+ for($time = $start, $i = 0; $time < $end; $time += 900, $i++) {
+ if($data["points"][$i]['y'] > $data['maxy'])
+ $data['maxy'] = $data['points'][$i]['y'];
+ $data["points"][$i]['tooltip'] = "{$data['points'][$i]['text']}: {$data['points'][$i]['y']}";
+ }
+ $alldata['virtual'] = $data;
+
+ $val = getContinuationVar('val') + 1;
+ $cont = addContinuationsEntry('AJgetBlockAllocatedMachineData', array('val' => $val), SECINDAY, 1, 0);
+ $alldata['cont'] = $cont;
+ sendJSON($alldata);
+}
?>
Modified: incubator/vcl/trunk/web/.ht-inc/states.php
URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/web/.ht-inc/states.php?rev=1027688&r1=1027687&r2=1027688&view=diff
==============================================================================
--- incubator/vcl/trunk/web/.ht-inc/states.php (original)
+++ incubator/vcl/trunk/web/.ht-inc/states.php Tue Oct 26 19:10:45 2010
@@ -145,6 +145,7 @@ $noHTMLwrappers = array('sendRDPfile',
'AJvalidateUserid',
'AJupdateDashboard',
'AJgetStatData',
+ 'AJgetBlockAllocatedMachineData',
);
# main
@@ -207,6 +208,8 @@ $actions['mode']['AJupdateBlockStatus']
$actions['mode']['AJpopulateBlockStore'] = "AJpopulateBlockStore";
$actions['mode']['AJviewBlockAllocationTimes'] = "AJviewBlockAllocationTimes";
$actions['mode']['AJtoggleBlockTime'] = "AJtoggleBlockTime";
+$actions['mode']['viewBlockAllocatedMachines'] = "viewBlockAllocatedMachines";
+$actions['mode']['AJgetBlockAllocatedMachineData'] = "AJgetBlockAllocatedMachineData";
$actions['pages']['blockAllocations'] = "blockAllocations";
$actions['pages']['newBlockAllocation'] = "blockAllocations";
$actions['pages']['editBlockAllocation'] = "blockAllocations";
@@ -224,6 +227,8 @@ $actions['pages']['AJpopulateBlockStore'
$actions['pages']['AJviewBlockAllocationTimes'] = "blockAllocations";
$actions['pages']['AJtoggleBlockTime'] = "blockAllocations";
$actions['pages']['AJviewBlockAllocation'] = "blockAllocations";
+$actions['pages']['viewBlockAllocatedMachines'] = "blockAllocations";
+$actions['pages']['AJgetBlockAllocatedMachineData'] = "blockAllocations";
# user preferences
$actions['mode']['userpreferences'] = "userpreferences"; # entry
Modified: incubator/vcl/trunk/web/.ht-inc/utils.php
URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/web/.ht-inc/utils.php?rev=1027688&r1=1027687&r2=1027688&view=diff
==============================================================================
--- incubator/vcl/trunk/web/.ht-inc/utils.php (original)
+++ incubator/vcl/trunk/web/.ht-inc/utils.php Tue Oct 26 19:10:45 2010
@@ -8894,6 +8894,17 @@ function getDojoHTML($refresh) {
case 'viewBlockStatus':
$dojoRequires = array('dojo.parser');
break;
+ case 'viewBlockAllocatedMachines':
+ $dojoRequires = array('dojo.parser',
+ 'dojox.string.sprintf',
+ 'dijit.form.Button',
+ 'dijit.form.DateTextBox',
+ 'dijit.form.TimeTextBox',
+ 'dojox.charting.widget.Chart2D',
+ 'dojox.charting.action2d.Tooltip',
+ 'dojox.charting.action2d.Magnify',
+ 'dojox.charting.themes.ThreeD');
+ break;
case 'editSchedule':
case 'submitAddSchedule':
$dojoRequires = array('dojo.parser',
@@ -9107,6 +9118,24 @@ function getDojoHTML($refresh) {
$rt .= "</script>\n";
return $rt;
+ case 'viewBlockAllocatedMachines':
+ $rt .= "<style type=\"text/css\">\n";
+ $rt .= " @import \"themes/$skin/css/dojo/$skin.css\";\n";
+ $rt .= "</style>\n";
+ $rt .= "<script type=\"text/javascript\" src=\"js/blockallocations.js\"></script>\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\">\n";
+ foreach($dojoRequires as $req) {
+ $rt .= " dojo.require(\"$req\");\n";
+ }
+ $rt .= " dojo.addOnLoad(function() {\n";
+ $rt .= " updateAllocatedMachines();\n";
+ $rt .= " });\n";
+ $rt .= "</script>\n";
+ return $rt;
+
case "editSchedule":
case "submitAddSchedule":
$rt .= "<style type=\"text/css\">\n";
Modified: incubator/vcl/trunk/web/js/blockallocations.js
URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/web/js/blockallocations.js?rev=1027688&r1=1027687&r2=1027688&view=diff
==============================================================================
--- incubator/vcl/trunk/web/js/blockallocations.js (original)
+++ incubator/vcl/trunk/web/js/blockallocations.js Tue Oct 26 19:10:45 2010
@@ -1338,3 +1338,46 @@ function checkOwnerCB(data, ioArgs) {
ownervalid = true;
}
}
+
+function updateAllocatedMachines() {
+ var d = dijit.byId('chartstartdate').value;
+ var t = dijit.byId('chartstarttime').value;
+ var date1 = dojox.string.sprintf('%d-%02d-%02d %02d:%02d',
+ d.getFullYear(),
+ (d.getMonth() + 1),
+ d.getDate(),
+ t.getHours(),
+ t.getMinutes());
+ var cont = dojo.byId('updatecont').value;
+ RPCwrapper({continuation: cont, start: date1}, updateAllocatedMachinesCB, 1);
+}
+
+function updateAllocatedMachinesCB(data, ioArgs) {
+ dojo.byId('updatecont').value = data.items.cont;
+ var graph = dijit.byId('allocatedBareMachines').chart;
+ graph.updateSeries('Main', data.items.bare.points);
+ graph.labeldata = data.items.bare.points;
+ graph.render();
+ var graph = dijit.byId('allocatedVirtualMachines').chart;
+ graph.updateSeries('Main', data.items.virtual.points);
+ graph.labeldata = data.items.virtual.points;
+ graph.render();
+ dojo.byId('totalbare').innerHTML = 'Total online: ' + data.items.bare.total;
+ dojo.byId('totalvirtual').innerHTML = 'Total online: ' + data.items.virtual.total;
+}
+
+function timestampToTimeBare(val) {
+ if(! dijit.byId('allocatedBareMachines').chart.labeldata)
+ return '';
+ else
+ var data = dijit.byId('allocatedBareMachines').chart.labeldata;
+ return data[val]['text'];
+}
+
+function timestampToTimeVirtual(val) {
+ if(! dijit.byId('allocatedVirtualMachines').chart.labeldata)
+ return '';
+ else
+ var data = dijit.byId('allocatedVirtualMachines').chart.labeldata;
+ return data[val]['text'];
+}