require_once 'plc_session.php';
global $plc, $api;
-$sliceid=$_POST['sliceid'];
+$slice_id=$_POST['slice_id'];
$slicename=$_POST['slicename'];
-$leases_grain=$_POST['leases_grain'];
+$leases_granularity=$_POST['leases_granularity'];
$leases_offset=$_POST['leases_offset'];
$leases_slots=$_POST['leases_slots'];
$leases_w=$_POST['leases_w'];
// need to recompute reservable nodes for this slice
$node_columns=array('hostname','node_id');
-$reservable_nodes=$api->GetNodes(array('|slice_ids'=>intval($sliceid), 'node_type'=>'reservable'),$node_columns);
+$reservable_nodes=$api->GetNodes(array('|slice_ids'=>intval($slice_id), 'node_type'=>'reservable'),$node_columns);
// where to start from, expressed as an offset in hours from now
$rough_start=time()+$leases_offset*3600;
// show the next 36 grains
-$duration=$leases_slots*$leases_grain;
-$steps=$duration/$leases_grain;
-$start=intval($rough_start/$leases_grain)*$leases_grain;
+$duration=$leases_slots*$leases_granularity;
+$steps=$duration/$leases_granularity;
+$start=intval($rough_start/$leases_granularity)*$leases_granularity;
$end=$rough_start+$duration;
$lease_columns=array('lease_id','name','t_from','t_until','hostname','name');
$leases=$api->GetLeases(array(']t_until'=>$rough_start,'[t_from'=>$end,'-SORT'=>'t_from'),$lease_columns);
$host_hash[$hostname]=array();
}
// resync within the table
- $lease['nfrom']=($lease['t_from']-$start)/$leases_grain;
- $lease['nuntil']=($lease['t_until']-$start)/$leases_grain;
+ $lease['nfrom']=($lease['t_from']-$start)/$leases_granularity;
+ $lease['nuntil']=($lease['t_until']-$start)/$leases_granularity;
$host_hash[$hostname] []= $lease;
}
// leases_data is the name used by leases.js to locate this table
// the timeslot headers read (timestamp,label)
$day_names=array('Su','M','Tu','W','Th','F','Sa');
for ($i=0; $i<$steps; $i++) {
- $timestamp=($start+$i*$leases_grain);
+ $timestamp=($start+$i*$leases_granularity);
$day=$day_names[intval(strftime("%w",$timestamp))];
$label=$day . strftime(" %H:%M",$timestamp);
// expose in each header cell the full timestamp, and how to display it - use & as a separator*/
var y_sep = 10;
// 1-grain leases attributes
-// w_grain is configurable from $_GET
-//var w_grain = 20;
+// leases_w is configurable from html
+//var leases_w = 20;
var y_node = 15;
var radius= 6;
////////////////////////////////////////////////////////////
// the scheduler object
-function Scheduler (sliceid, slicename, w_grain) {
+function Scheduler () {
// xxx-hacky dunno how to retrieve this object from an ajax callback
Scheduler.scheduler=this;
// the data contains slice names, and lease_id, we need this to find our own leases (mine)
- this.sliceid=sliceid;
- this.slicename=slicename;
this.paper=null;
- this.w_grain = parseInt(w_grain);
- // the path for the triangle-shaped buttons
- this.timebutton_path="M1,0L"+(this.w_grain-1)+",0L"+(this.w_grain/2)+","+y_header+"L1,0";
-
- // how many time slots
- this.nb_grains = function () { return this.axisx.length;}
-
////////////////////
// store the result of an ajax request in the leases_data table
this.set_html = function (html_data) {
// the names of the hidden fields that hold the input to this class
// are hard-wired for now
this.parse_html = function () {
- this.sliceid=getInnerText($$("span#leases_sliceid")[0]).strip();
- this.slicename=getInnerText($$("span#leases_slicename")[0]).strip();
- this.leases_grain=getInnerText($$("span#leases_grain")[0]).strip();
- this.leases_offset=getInnerText($$("span#leases_offset")[0]).strip();
- this.leases_slots=getInnerText($$("span#leases_slots")[0]).strip();
- this.leases_w=getInnerText($$("span#leases_w")[0]).strip();
+ window.console.log('in parse_html');
var table = $$("table#leases_data")[0];
// no reservable nodes - no data
- if ( ! table) return false;
- // check for the body too xxx
+ if ( ! table) {
+ window.console.log('no table');
+ return false;
+ }
// the nodelabels
var data = [], axisx = [], axisy = [];
table.getElementsBySelector("tbody>tr>th").each(function (cell) {
axisy.push(getInnerText(cell));
});
+ // test for at least one entry; other wise this means we haven't retrieved
+ // the html dta yet
+ if (axisy.length <1) {
+ window.console.log('no axisy');
+ window.console.log('have retrieved html text as'+getInnerText(table));
+ return false;
+ }
// the timeslot labels
table.getElementsBySelector("thead>tr>th").each(function (cell) {
});
this.axisx=axisx;
+ window.console.log('in parse_html, set axisx to'+axisx.length);
this.axisy=axisy;
this.data=data;
return true;
}
+ // how many time slots
+ this.nb_grains = function () { return this.axisx.length;}
+
////////////////////
// draw
this.draw_area = function (canvas_id) {
- this.total_width = x_nodelabel + this.nb_grains()*this.w_grain;
+ window.console.log('in draw_area');
+ this.total_width = x_nodelabel + this.nb_grains()*this.leases_w;
this.total_height = 2*y_header /* the timelabels */
+ 2*y_sep /* extra space */
+ y_node /* all-nodes & timebuttons row */
}
this.paper=paper;
+ // the path for the triangle-shaped buttons
+ this.timebutton_path="M1,0L"+(this.leases_w-1)+",0L"+(this.leases_w/2)+","+y_header+"L1,0";
+
var axisx=this.axisx;
+ window.console.log('in draw_area, retrieved axisx' + axisx.length);
+
var axisy=this.axisy;
// maintain the list of nodelabels for the 'all nodes' button
this.nodelabels=[];
} else if ( (timestamp%(12*3600))==0) {
paper.path(half_daymarker_path).attr({'translation':left+','+top}).attr(attr_daymarker);
}
- left+=(this.w_grain);
+ left+=(this.leases_w);
}
////////// the row with the timeslot buttons (the one labeled 'All nodes')
timebutton.from_time=axisx[i][0];
timebutton.scheduler=this;
timebutton.click(timebutton_methods.click);
- left+=(this.w_grain);
+ left+=(this.leases_w);
}
//////// the body of the scheduler : loop on nodes
lease_id=this.data[data_index][0];
slicename=this.data[data_index][1];
duration=this.data[data_index][2];
- var lease=paper.rect (left,top,this.w_grain*duration,y_node,radius);
+ var lease=paper.rect (left,top,this.leases_w*duration,y_node,radius);
lease.lease_id=lease_id;
lease.nodename=nodename;
lease.nodelabel=nodelabel;
// and vice versa
this.leases.push(lease);
// move on with the loop
- left += this.w_grain*duration;
+ left += this.leases_w*duration;
data_index +=1;
}
top += y_node + y_sep;
}
}
}
- sliceid=this.sliceid;
+ slice_id=this.slice_id;
// Ajax.Request comes with prototype
var ajax=new Ajax.Request('/planetlab/common/actions.php',
{method:'post',
}
}
+ // re-read settings from the html, ajax-aquire the html text for the leases_data table
+ // store it in the html tree, parse it, and refresh graphic
this.refresh = function () {
+ window.console.log('in refresh');
+ this.slice_id=getInnerText($$("span#leases_slice_id")[0]).strip();
+ this.slicename=getInnerText($$("span#leases_slicename")[0]).strip();
+ this.leases_granularity=getInnerText($$("span#leases_granularity")[0]).strip();
+ this.leases_offset=getInnerText($$("span#leases_offset")[0]).strip();
+ this.leases_slots=getInnerText($$("span#leases_slots")[0]).strip();
+ this.leases_w=parseInt(getInnerText($$("span#leases_w")[0]).strip());
+
document.body.style.cursor = "wait";
var ajax=new Ajax.Request('/planetlab/slices/leases-data.php',
{method:'post',
- parameters:{'sliceid':this.sliceid,
+ parameters:{'slice_id':this.slice_id,
'slicename':this.slicename,
- 'leases_grain':this.leases_grain,
+ 'leases_granularity':this.leases_granularity,
'leases_offset':this.leases_offset,
'leases_slots':this.leases_slots,
'leases_w':this.leases_w},
onSuccess: function (transport) {
var response = transport.responseText || "no response text";
-// window.console.log("received from ajax=[["+response+"]]");
+ window.console.log("received from ajax=[["+response+"]]");
var scheduler=Scheduler.scheduler;
if ( ! scheduler.set_html (response))
alert ("Something wrong .. Could not store ajax result..");
function init_scheduler () {
// Grab the data
- var data = [], axisx = [], axisy = [];
- var sliceid = getInnerText($$("span#leases_sliceid")[0]).strip();
- var slicename = getInnerText($$("span#leases_slicename")[0]).strip();
- var w_grain = getInnerText($$("span#leases_w")[0]).strip();
- var scheduler = new Scheduler (sliceid,slicename,w_grain);
+ var scheduler = new Scheduler ();
// parse the table with data, and if not empty, draw the scheduler
- if (scheduler.parse_html ()) {
- scheduler.draw_area("leases_area");
- }
+ window.console.log('in init_scheduler');
+ scheduler.refresh();
// attach behaviour to buttons
var refresh=$$("button#leases_refresh")[0];
var submit=$$("button#leases_submit")[0];
submit.onclick = function () { scheduler.submit(); }
- scheduler.refresh();
-
}
Event.observe(window, 'load', init_scheduler);
if ( ! $leases_w) $leases_w=20;
// number of timeslots to display
- $grain=$api->GetLeaseGranularity();
+ $granularity=$api->GetLeaseGranularity();
// these elements are for passing data to the javascript layer
echo "<span class='hidden' id='leases_slicename'>" . $slice['name'] . "</span>";
- echo "<span class='hidden' id='leases_sliceid'>" . $slice['slice_id']. "</span>";
- echo "<span class='hidden' id='leases_grain'>" . $grain . "</span>";
+ echo "<span class='hidden' id='leases_slice_id'>" . $slice['slice_id']. "</span>";
+ echo "<span class='hidden' id='leases_granularity'>" . $granularity . "</span>";
echo "<span class='hidden' id='leases_offset'>" . $leases_offset . "</span>";
echo "<span class='hidden' id='leases_slots'>" . $leases_slots . "</span>";
echo "<span class='hidden' id='leases_w'>" . $leases_w . "</span>";
- // cut off
- if ($profiling) plc_debug_prof('6 granul',$grain);
- // where to start from, expressed as an offset in hours from now
- $rough_start=time()+$leases_offset*3600;
- // show the next 36 grains
- $duration=$leases_slots*$grain;
- $steps=$duration/$grain;
- $start=intval($rough_start/$grain)*$grain;
- $end=$rough_start+$duration;
- $lease_columns=array('lease_id','name','t_from','t_until','hostname','name');
- $leases=$api->GetLeases(array(']t_until'=>$rough_start,'[t_from'=>$end,'-SORT'=>'t_from'),$lease_columns);
- if ($profiling) plc_debug_prof('7 leases',count($leases));
- // hash nodes -> leases
- $host_hash=array();
- foreach ($leases as $lease) {
- $hostname=$lease['hostname'];
- if ( ! $host_hash[$hostname] ) {
- $host_hash[$hostname]=array();
- }
- // resync within the table
- $lease['nfrom']=($lease['t_from']-$start)/$grain;
- $lease['nuntil']=($lease['t_until']-$start)/$grain;
- $host_hash[$hostname] []= $lease;
- }
- // leases_data is the name used by leases.js to locate this table
- echo "<table id='leases_data' class='hidden'>";
- // pass (slice_id,slicename,x_grain) in the upper-left cell, as thead>tr>td
- echo "<thead><tr><td>" . $slice['slice_id'] . '&' . $slice['name'] . '&' . $leases_w . "</td>";
- // the timeslot headers read (timestamp,label)
- $day_names=array('Su','M','Tu','W','Th','F','Sa');
- for ($i=0; $i<$steps; $i++) {
- $timestamp=($start+$i*$grain);
- $day=$day_names[intval(strftime("%w",$timestamp))];
- $label=$day . strftime(" %H:%M",$timestamp);
- // expose in each header cell the full timestamp, and how to display it - use & as a separator*/
- echo "<th>" . implode("&",array($timestamp,$label)) . "</th>";
- }
- echo "</tr></thead><tbody>";
- // todo - sort on hostnames
- function sort_hostname ($a,$b) { return ($a['hostname']<$b['hostname'])?-1:1;}
- usort($reservable_nodes,sort_hostname);
- foreach ($reservable_nodes as $node) {
- echo "<tr><th scope='row'>". $node['hostname'] . "</th>";
- $hostname=$node['hostname'];
- $leases=$host_hash[$hostname];
- $counter=0;
- while ($counter<$steps) {
- if ($leases && ($leases[0]['nfrom']<=$counter)) {
- $lease=array_shift($leases);
- /* nicer display, merge two consecutive leases for the same slice
- avoid doing that for now, as it might makes things confusing */
- /* while ($leases && ($leases[0]['name']==$lease['name']) && ($leases[0]['nfrom']==$lease['nuntil'])) {
- $lease['nuntil']=$leases[0]['nuntil'];
- array_shift($leases);
- }*/
- $duration=$lease['nuntil']-$counter;
- echo "<td colspan='$duration'>" . $lease['lease_id'] . '&' . $lease['name'] . "</td>";
- $counter=$lease['nuntil'];
- } else {
- echo "<td></td>";
- $counter+=1;
- }
- }
- echo "</tr>";
- }
- echo "</tbody></table>\n";
+ // leases_data is the name used by leases.js to locate this place
+ // first population will be triggered by init_scheduler from leases.js
+ echo "<table id='leases_data' class='hidden'></table>";
// the general layout for the scheduler
echo <<< EOF