profiling - truncate_and_popup - reservable constants
[plewww.git] / planetlab / slices / slice.php
index fb0faa1..c28eeac 100644 (file)
@@ -40,8 +40,10 @@ $slice_id=intval($_GET['id']);
 if ( ! $slice_id ) { plc_error('Malformed URL - id not set'); return; }
 
 ////////////////////
-// Get all columns as we focus on only one entry
-$slices= $api->GetSlices( array($slice_id));
+// have to name columns b/c we need the non-native 'omf_control' column
+$slice_columns=array('slice_id','name','peer_id','site_id','person_ids','node_ids','expires',
+                    'url','description','instantiation','omf_control');
+$slices= $api->GetSlices( array($slice_id), $slice_columns);
 
 if (empty($slices)) {
   drupal_set_message ("Slice " . $slice_id . " not found");
@@ -147,10 +149,15 @@ EOF;
      } else {
       print <<< EOF
 <div class='my-slice-renewal'>
-<p>You must provide a short description as well as a link to a project website before renewing it.
-Do <span class='bold'>not</span> provide bogus information; if a complaint is lodged against your slice 
-and PlanetLab Operations is unable to determine what the normal behavior of your slice is, 
-your slice may be deleted to resolve the complaint.</p>
+<p>You <span class='bold'>must</span> provide a short description, 
+as well as a link to a project website, before renewing it.
+
+<br/> Please make sure to provide reasonable details on <span class='bold'>
+the kind of traffic</span>, and <span class='bold'>copyrights</span> if relevant. 
+Do <span class='bold'>not</span> provide bogus information; if a complaint is lodged against 
+your slice  and your PlanetLab Operations Center is unable to determine what the normal behavior 
+of your slice is, your slice may be deleted to resolve the complaint.</p>
+
 <p><span class='bold'>NOTE:</span> 
 Slices cannot be renewed beyond another $max_renewal_weeks week(s) ($max_renewal_date).
 </p>
@@ -253,6 +260,7 @@ $details->th_td('URL',$slice['url'],'url',array('width'=>50));
 $details->tr_submit("submit","Update Slice");
 $details->th_td('Expires',$expires);
 $details->th_td('Instantiation',$slice['instantiation']);
+$details->th_td("OMF-friendly", ($slice['omf_control'] ? 'Yes' : 'No') . " [to change: see 'omf_control' in the tags section below]");
 $details->th_td('Site',l_site_obj($site));
 // xxx show the PIs here
 //$details->th_td('PIs',...);
@@ -387,7 +395,8 @@ $toggle->end();
 //     (.) type is passed to the javascript table, for sorting (default is 'string')
 
 // minimal list as a start
-$node_fixed_columns = array('hostname','node_id','peer_id','slice_ids_whitelist','run_level','boot_state','last_contact','node_type');
+$node_fixed_columns = array('hostname','node_id','peer_id','slice_ids_whitelist',
+                           'run_level','boot_state','last_contact','node_type');
 // create a VisibleTags object : basically the list of tag columns to show
 $visibletags = new VisibleTags ($api, 'node');
 $visiblecolumns = $visibletags->column_names();
@@ -398,9 +407,14 @@ $potential_nodes=$api->GetNodes(array('~node_id'=>$slice['node_ids']),$node_colu
 $reservable_nodes=array();
 foreach ($nodes as $node) { if ($node['node_type']=='reservable') $reservable_nodes[]=$node; }
 
+$reservable_mark="-R-";
+$reservable_legend="reservable nodes are marked with " . $reservable_mark;
+
 ////////////////////
-$count=count($nodes);
-$toggle=new PlekitToggle ('my-slice-nodes',"$count Nodes",
+// outline the number of reservable nodes
+$nodes_message=count_english($nodes,"node");
+if (count($reservable_nodes)) $nodes_message .= " (" . count($reservable_nodes) . " reservable)";
+$toggle=new PlekitToggle ('my-slice-nodes',$nodes_message,
                          array('bubble'=>
                                'Manage nodes attached to this slice',
                                'visible'=>get_arg('show_nodes',false)));
@@ -418,7 +432,7 @@ $headers['peer']='string';
 $headers['hostname']='string';
 $short="ST"; $long=Node::status_footnote(); $type='string'; 
        $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
-$short="R"; $long="reservable nodes"; $type='string';
+$short="R"; $long=$reservable_legend; $type='string';
        $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
 // the extra tags, configured for the UI
 $headers=array_merge($headers,$visibletags->headers());
@@ -441,7 +455,7 @@ if ($nodes) foreach ($nodes as $node) {
   $run_level=$node['run_level'];
   list($label,$class) = Node::status_label_class_($node);
   $table->cell ($label,array('class'=>$class));
-  $table->cell( ($node['node_type']=='reservable')?"-R-":"" );
+  $table->cell( ($node['node_type']=='reservable')?$reservable_mark:"" );
   foreach ($visiblecolumns as $tagname) $table->cell($node[$tagname]);
 
   if ($privileges) $table->cell ($form->checkbox_html('node_ids[]',$node['node_id']));
@@ -485,7 +499,7 @@ if ($privileges) {
     $headers['hostname']='string';
     $short="ST"; $long=Node::status_footnote(); $type='string'; 
        $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
-    $short="R"; $long="reservable nodes"; $type='string';
+    $short="R"; $long=$reservable_legend; $type='string';
        $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
     // the extra tags, configured for the UI
     $headers=array_merge($headers,$visibletags->headers());
@@ -503,7 +517,7 @@ if ($privileges) {
        $table->cell(l_node_obj($node));
        list($label,$class) = Node::status_label_class_($node);
        $table->cell ($label,array('class'=>$class));
-       $table->cell( ($node['node_type']=='reservable')?"-R-":"" );
+       $table->cell( ($node['node_type']=='reservable')?$reservable_mark:"" );
        foreach ($visiblecolumns as $tagname) $table->cell($node[$tagname]);
        $table->cell ($form->checkbox_html('node_ids[]',$node['node_id']));
        $table->row_end();
@@ -529,15 +543,20 @@ if ($count && $privileges) {
                                 array('visible'=>get_arg('show_nodes_resa',false)));
   $toggle_nodes->start();
   $grain=$api->GetLeaseGranularity();
+  // where to start from, expressed as an offset in hours from now
+  $resa_offset=$_GET['resa_offset'];
+  if ( ! $resa_offset ) $resa_offset=0;
+  $rough_start=time()+$resa_offset*3600;
   // xxx should be configurable
-  $now=time(); 
-  // xxx ditto, for now, show the next 48 hours, or 96 grains, which ever is smaller
-  $duration=min(24*3600,24*$grain);
+  $resa_slots=$_GET['resa_slots'];
+  if ( ! $resa_slots ) $resa_slots = 36;
+  // for now, show the next 72 hours, or 72 grains, which ever is smaller
+  $duration=$resa_slots*$grain;
   $steps=$duration/$grain;
-  $start=intval($now/$grain)*$grain;
-  $end=$now+$duration;
-  $lease_columns=array('name','t_from','t_until','hostname','name');
-  $leases=$api->GetLeases(array(']t_until'=>$now,'[t_from'=>$end,'-SORT'=>'t_from'),$lease_columns);
+  $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);
   // hash nodes -> leases
   $host_hash=array();
   foreach ($leases as $lease) {
@@ -552,11 +571,17 @@ if ($count && $privileges) {
   }
   # leases_data is the name used by leases.js to locate this table
   echo "<table id='leases_data'>";
-  # pass the slicename as the [0,0] coordinate as thead>tr>td
-  echo "<thead><tr><td>" . $slice['name'] . "</td>";
-  for ($i=0; $i<$steps; $i++) 
+  # pass (slice_id,slicename) as the [0,0] coordinate as thead>tr>td
+  echo "<thead><tr><td>" . $slice['slice_id'] . '&' . $slice['name'] . "</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>" . ($start+$i*$grain) . "&" . strftime("%H:%M",$start+$i*$grain). "</th>";
+    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;}
@@ -570,13 +595,13 @@ if ($count && $privileges) {
       if ($leases && ($leases[0]['nfrom']<=$counter)) {
        $lease=array_shift($leases);
        /* nicer display, merge two consecutive leases for the same slice 
-        -*- tmp -*- avoid doing that for now, as it might makes things confusing */
+          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['name'] . "</td>";
+       echo "<td colspan='$duration'>" . $lease['lease_id'] . '&' . $lease['name'] . "</td>";
        $counter=$lease['nuntil']; 
       } else {
        echo "<td></td>";
@@ -589,13 +614,6 @@ if ($count && $privileges) {
 
   // the general layout for the scheduler
   echo <<< EOF
-<div id='leases_modes'><form>
-  <span id='leases_selection_mode'> Selection mode:
-  <input id='leases_mode_node'     type='radio' name='mode' value="node" />Node
-  <input id='leases_mode_timeslot' type='radio' name='mode' value="timeslot" checked />Timeslot
-  </span>
-</form></div>
-
 <div id='leases_area'></div>
 
 <div id='leases_buttons'>