using as many as one php object per node was killing the UI
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 17 Nov 2009 15:55:17 +0000 (15:55 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 17 Nov 2009 15:55:17 +0000 (15:55 +0000)
planetlab/includes/plc_objects.php
planetlab/nodes/interface.php
planetlab/nodes/nodes.php
planetlab/slices/slice.php

index e4d3801..c3c23c5 100644 (file)
@@ -272,34 +272,45 @@ class Node extends PlcObject {
   function lastContact() {
     return $this->timeaway($this->last_contact);
   }
-  // returns a tuple ( label, class) 
-  // $node needs at least 'run_level' 'boot_state' 
-  function status_label_class () {
-    $label= $this->run_level ? $this->run_level : ( $this->boot_state . '*' ) ;
-    if ($this->stale()) $label .= '...';
+
+  function timeaway($val) {
+    if ( $val != NULL ) {
+      $ret = timeDiff(intval($val));
+    } else {
+      $ret = "Never";
+    }
+    return $ret;
+  }
+
+  // code needs to be accessible from outside an object too 
+  // b/c of the performance overhead of creating as many objects as nodes
+  static function status_label_class__ ($boot_state, $run_level, $last_contact, $peer_id) {
+    $label= $run_level ? $run_level : ( $boot_state . '*' ) ;
+    if (Node::stale_($last_contact,$peer_id)) $label .= '...';
     $class=($label=="boot") ? 'node-ok' : 'node-ko';
     return array($label,$class);
   }
-
+  static function status_label_class_ ($node) {
+    return Node::status_label_class__ ($node['boot_state'],$node['run_level'],$node['last_contact'], $node['peer_id']);
+  }
+  function status_label_class () {
+    return Node::status_label_class__ ($this->boot_state,$this->run_level,$this->last_contact, $this->peer_id);
+  }
   static function status_footnote () {
     return "state; * if node doesn't have an observed state; ... if status is stale (" . Node::stale_text() . ")";
   }
-
-  function stale() {
+  
+  // ditto
+  static function stale_ ($last_contact, $peer_id) {
+    // remote nodes don't have a last_contact
+    if ( $peer_id) return false;
     $STALE_LENGTH = 2*60*60;   /* TODO: set by some policy */
     $now = time();
-    return ( $this->last_contact + $STALE_LENGTH < $now );
+    return ( $last_contact + $STALE_LENGTH < $now );
   }
+  function stale() { return Node::stale_ ($this->last_contact,$this->peer_id); }
   static function stale_text() { return "2 hours"; }
 
-  function timeaway($val) {
-    if ( $val != NULL ) {
-      $ret = timeDiff(intval($val));
-    } else {
-      $ret = "Never";
-    }
-    return $ret;
-  }
 }
 
 class Slice {
index b5150ba..f9676ac 100644 (file)
@@ -141,7 +141,7 @@ if ($mode == 'add') return;
 
 //////////////////////////////////////// tags
 $tags=$api->GetInterfaceTags (array('interface_id'=>$interface_id));
-$toggle=new PlekitToggle ('tags',count_english($tags,'tags'),
+$toggle=new PlekitToggle ('tags',count_english($tags,'tag'),
                          array('visible'=>get_arg('show_tags',false)));
 $toggle->start();
 
index 59df3d9..b609813 100644 (file)
@@ -185,13 +185,13 @@ $short="?"; $long="extra status info"; $type='string';
        $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
 
 # initial sort on hostnames
-$table=new PlekitTable ("nodes",$headers,4+$offset);
+$table=new PlekitTable ("nodes",$headers,3+$offset);
 $table->start();
 
 $peers = new Peers ($api);
 // write rows
 foreach ($nodes as $node) {
-  $node_obj = new Node ($node);
+  //$node_obj = new Node ($node);
   $hostname=$node['hostname'];
   $node_id=$node['node_id'];
   $site_id=$node['site_id'];
@@ -208,7 +208,7 @@ foreach ($nodes as $node) {
   $table->cell (l_site_t($site_id,$login_base));
   $table->cell (l_node_t($node_id,$hostname));
   $table->cell (l_interface_t($interface_id,$ip),array('only-if'=> !$peer_id));
-  list($label,$class) = $node_obj->status_label_class();
+  list($label,$class) = Node::status_label_class_($node);
   $table->cell ($label,array('class'=>$class));
   $table->cell (count($node['slice_ids']));
   foreach ($visiblecolumns as $tagname) $table->cell($node[$tagname]);
index eae7b9a..0d587ef 100644 (file)
@@ -428,12 +428,11 @@ $form=new PlekitForm(l_actions(),array('slice_id'=>$slice['slice_id']));
 $form->start();
 $table->start();
 if ($nodes) foreach ($nodes as $node) {
-  $node_obj=new Node($node);
   $table->row_start();
   $peers->cell($table,$node['peer_id']);
   $table->cell(l_node_obj($node));
   $run_level=$node['run_level'];
-  list($label,$class) = $node_obj->status_label_class();
+  list($label,$class) = Node::status_label_class_($node);
   $table->cell ($label,array('class'=>$class));
   foreach ($visiblecolumns as $tagname) $table->cell($node[$tagname]);
 
@@ -492,14 +491,11 @@ if ($privileges) {
     $form->start();
     $table->start();
     if ($potential_nodes) foreach ($potential_nodes as $node) {
-       $node_obj=new Node($node);
        $table->row_start();
        $peers->cell($table,$node['peer_id']);
        $table->cell(l_node_obj($node));
-       list($label,$class) = $node_obj->status_label_class();
+       list($label,$class) = Node::status_label_class_($node);
        $table->cell ($label,array('class'=>$class));
-       $class=($run_level == 'boot') ? 'node-ok' : 'node-ko';
-       $table->cell($run_level,array('class'=>$class));
        foreach ($visiblecolumns as $tagname) $table->cell($node[$tagname]);
        $table->cell ($form->checkbox_html('node_ids[]',$node['node_id']));
        $table->row_end();