From 9b7fb6398d2974b649c3505ddb19e44a933c3e44 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Tue, 17 Nov 2009 15:55:17 +0000 Subject: [PATCH] using as many as one php object per node was killing the UI --- planetlab/includes/plc_objects.php | 45 +++++++++++++++++++----------- planetlab/nodes/interface.php | 2 +- planetlab/nodes/nodes.php | 6 ++-- planetlab/slices/slice.php | 8 ++---- 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/planetlab/includes/plc_objects.php b/planetlab/includes/plc_objects.php index e4d3801..c3c23c5 100644 --- a/planetlab/includes/plc_objects.php +++ b/planetlab/includes/plc_objects.php @@ -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 { diff --git a/planetlab/nodes/interface.php b/planetlab/nodes/interface.php index b5150ba..f9676ac 100644 --- a/planetlab/nodes/interface.php +++ b/planetlab/nodes/interface.php @@ -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(); diff --git a/planetlab/nodes/nodes.php b/planetlab/nodes/nodes.php index 59df3d9..b609813 100644 --- a/planetlab/nodes/nodes.php +++ b/planetlab/nodes/nodes.php @@ -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]); diff --git a/planetlab/slices/slice.php b/planetlab/slices/slice.php index eae7b9a..0d587ef 100644 --- a/planetlab/slices/slice.php +++ b/planetlab/slices/slice.php @@ -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(); -- 2.43.0