From cf7f5256ae9c7b18393c7ec23453deb3677129ba Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 12 Dec 2012 15:00:03 +1100 Subject: [PATCH] Added Node Session --- application/bootstrap.php | 2 +- application/classes/Controller/Node.php | 36 +++++++++++++++++++ application/classes/Model/ACTLOG.php | 19 +++++++++- application/classes/Model/ACTSUM.php | 17 +++++++++ application/classes/Model/NODE.php | 45 ++++++++++++++++++++++-- application/views/node/clientsession.php | 19 ++++++++++ application/views/node/sessions.php | 30 ++++++++-------- 7 files changed, 149 insertions(+), 19 deletions(-) create mode 100644 application/views/node/clientsession.php diff --git a/application/bootstrap.php b/application/bootstrap.php index 73ea5f6..d719266 100644 --- a/application/bootstrap.php +++ b/application/bootstrap.php @@ -146,7 +146,7 @@ Route::set('default/media', 'media(/)', array('file' => '.+')) * Set the routes. Each route must have a minimum of a name, a URI and a set of * defaults for the URI. */ -Route::set('default', '((/(/)))', array('id'=>'[a-zA-Z0-9_.\-=]+')) +Route::set('default', '((/(/)))', array('id'=>'[a-zA-Z0-9_.\-=,]+')) ->defaults(array( 'controller' => 'welcome', 'action' => 'index', diff --git a/application/classes/Controller/Node.php b/application/classes/Controller/Node.php index 5586208..cd513f7 100644 --- a/application/classes/Controller/Node.php +++ b/application/classes/Controller/Node.php @@ -52,5 +52,41 @@ class Controller_Node extends Controller_TemplateDefault_View { $this->response->headers('Content-Type','application/json'); $this->response->body($google->json()); } + + /** + * Return details of a specific node SESSION in the ACTIVITY LOG + * @param $id NODE,SESSION_ID,SESSION_START_DATE + */ + public function action_session() { + $id = $this->request->param('id'); + + if (substr_count($id,',') != 2) { + SystemMessage::add(array( + 'title'=>_('Invalid ID'), + 'body'=>sprintf(_('The session ID %s is invalid'),$id), + 'type'=>'error', + )); + + return; + } + + list($nid,$sid,$start) = explode(',',$id,3); + + $no = ORM::factory('NODE',$nid); + if (! $no->loaded()) { + SystemMessage::add(array( + 'title'=>_('Invalid Node'), + 'body'=>sprintf(_('The Node ID %s is invalid'),$nid), + 'type'=>'error', + )); + + return; + } + + Block::add(array( + 'title'=>sprintf(_('Session %s Detail for Node %s'),$sid,$no->display('NODE_NAME')), + 'body'=>View::factory(sprintf('%s/clientsession',strtolower($this->request->controller())))->set('o',$no->actlog_session($sid,$start)), + )); + } } ?> diff --git a/application/classes/Model/ACTLOG.php b/application/classes/Model/ACTLOG.php index 1506b7a..5a426f5 100644 --- a/application/classes/Model/ACTLOG.php +++ b/application/classes/Model/ACTLOG.php @@ -27,8 +27,25 @@ class Model_ACTLOG extends ORM_TSM { private $_msgno_ba_transfer = array(4963,4966,4967,4964); private $_msgno_ba_reduction = array(4968,4981,4976); - public function exclude_ba() { + /** + * Return the timestamp of the record in the ACTLOG + */ + public function FirstRec() { + return DB::query(Database::SELECT,'SELECT min(DATE_TIME) as DATE_TIME from ACTLOG')->cached(86400)->execute()->get('DATE_TIME'); + } + + /** + * Where class to exclude NODE backup messages + */ + public function ExcludeBA() { return $this->where('MSGNO','NOT IN',array_merge($this->_msgno_ba_objects,$this->_msgno_ba_bytes,$this->_msgno_ba_transfer,$this->_msgno_ba_reduction)); } + + /** + * Return this ACTIVITY LOG start time in seconds since epoch + */ + public function start() { + return ORM_TSM::date($this->DATE_TIME,'U'); + } } ?> diff --git a/application/classes/Model/ACTSUM.php b/application/classes/Model/ACTSUM.php index 8fa05c2..8c45cb8 100644 --- a/application/classes/Model/ACTSUM.php +++ b/application/classes/Model/ACTSUM.php @@ -25,8 +25,25 @@ class Model_ACTSUM extends ORM_TSM { ), ); + /** + * Return if this ACTIVITY SUMMARY would be still in the ACTIVITY LOG + */ + public function inActLog() { + return ORM_TSM::date(ORM::factory('ACTLOG')->FirstRec(),'U') <= $this->start(); + } + + /** + * Return this ACTIVITY SUMMARY in GB + */ public function bytes() { return (real)number_format($this->BYTES/1024/1024,0,'',''); } + + /** + * Return this ACTIVITY SUMMARY start time in seconds since epoch + */ + public function start() { + return ORM_TSM::date($this->START_TIME,'U'); + } } ?> diff --git a/application/classes/Model/NODE.php b/application/classes/Model/NODE.php index b8c3803..3abf742 100644 --- a/application/classes/Model/NODE.php +++ b/application/classes/Model/NODE.php @@ -115,6 +115,32 @@ class Model_NODE extends ORM_TSM { ), ); + /** + * Get all the ACTIVITIY LOG for this NODE + */ + private function _actlog() { + Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__)); + + $k = sprintf('%s-%s',__METHOD__,$this->NODE_NAME); + $c = Kohana::$config->load('config')->cache; + + if (is_null($result = Cache::instance($c)->get($k))) { + $result = array(); + + // In the interest of performance, we load all the records and get PHP to process it. + // Our ORM caching we reduce the hit on TSM. + foreach (ORM::factory('ACTLOG')->find_all() as $o) + if ($o->NODENAME == $this->NODE_NAME) + array_push($result,$o); + + // @todo Cache time should be configurble + Cache::instance($c)->set($k,$result,300); + } + + Log::instance()->add(LOG::DEBUG,'EXIT :method',array(':method'=>__METHOD__)); + return $result; + } + /** * Get all the ACTIVITY SUMMARY for this NODE */ @@ -303,7 +329,7 @@ class Model_NODE extends ORM_TSM { if (is_null($result = Cache::instance($c)->get($k))) { $result = array(); - $result = $this->ACTLOG->exclude_ba()->find_all(); + $result = $this->ACTLOG->ExcludeBA()->find_all(); // @todo Cache time should be configurble Cache::instance($c)->set($k,$result,300); @@ -313,6 +339,21 @@ class Model_NODE extends ORM_TSM { return $result; } + /** + * Get all the ACTIVITY LOG information for a SESSION + * @param $sid Session ID + * @param $start Session Start Time (to illiminate any duplication session data) + */ + public function actlog_session($sid,$start) { + $result = array(); + + foreach ($this->_actlog() as $alo) + if ($alo->SESSION == $sid AND $alo->start() >= $start) + array_push($result,$alo); + + return $result; + } + /** * Return the ACTIVITY of this NODE * @param $type is Bkup/Arch/SpMg @@ -340,7 +381,7 @@ class Model_NODE extends ORM_TSM { } /** - * Return the Schedules for all activites of type + * Return the Schedules used for all activites of type * @param $type is Bkup/Arch/SpMg */ public function act_schedules($type) { diff --git a/application/views/node/clientsession.php b/application/views/node/clientsession.php new file mode 100644 index 0000000..cd7e552 --- /dev/null +++ b/application/views/node/clientsession.php @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + +
Client Session Detail
 
StartMessage
display('DATE_TIME'); ?>display('MESSAGE'); ?>
diff --git a/application/views/node/sessions.php b/application/views/node/sessions.php index 0f88d01..e55da6c 100644 --- a/application/views/node/sessions.php +++ b/application/views/node/sessions.php @@ -27,22 +27,22 @@ Process Success - act_bybtype($btype) as $ao) { ?> + act_bybtype($btype) as $aso) { ?> - display('START_TIME'); ?> - display('END_TIME'); ?> - display('COMMMETH'); ?> - display('SCHEDULE_NAME'); ?> - display('NUMBER'); ?> - display('EXAMINED'); ?> - display('AFFECTED'); ?> - display('FAILED'); ?> - bytes(); ?> - display('IDLE'); ?> - display('MEDIAW'); ?> - display('COMM_WAIT'); ?> - display('PROCESSES'); ?> - display('SUCCESSFUL'); ?> + display('START_TIME'); ?> + display('END_TIME'); ?> + display('COMMMETH'); ?> + display('SCHEDULE_NAME'); ?> + inActLog() ? HTML::anchor(sprintf('node/session/%s,%s,%s',$o->NODE_NAME,$aso->NUMBER,$aso->start()),$aso->display('NUMBER')) : $aso->display('NUMBER'); ?> + display('EXAMINED'); ?> + display('AFFECTED'); ?> + display('FAILED'); ?> + bytes(); ?> + display('IDLE'); ?> + display('MEDIAW'); ?> + display('COMM_WAIT'); ?> + display('PROCESSES'); ?> + display('SUCCESSFUL'); ?>