diff --git a/module/Dashboard/src/Dashboard/Controller/DashboardController.php b/module/Dashboard/src/Dashboard/Controller/DashboardController.php index 211ef62cce8..14fa23d79aa 100644 --- a/module/Dashboard/src/Dashboard/Controller/DashboardController.php +++ b/module/Dashboard/src/Dashboard/Controller/DashboardController.php @@ -31,6 +31,8 @@ class DashboardController extends AbstractActionController { + protected $directorModel = null; + protected $jobModel = null; protected $dashboardModel = null; protected $bsock = null; @@ -70,23 +72,23 @@ private function getJobs($status=null, $days=1, $hours=null) if($status != null) { if($status == "running") { - $jobs_R = $this->getDashboardModel()->getJobs($this->bsock, 'R', $days, $hours); - $jobs_l = $this->getDashboardModel()->getJobs($this->bsock, 'l', $days, $hours); + $jobs_R = $this->getJobModel()->getJobsByStatus($this->bsock, 'R', $days, $hours); + $jobs_l = $this->getJobModel()->getJobsByStatus($this->bsock, 'l', $days, $hours); $num = count($jobs_R) + count($jobs_l); } elseif($status == "waiting") { - $jobs_F = $this->getDashboardModel()->getJobs($this->bsock, 'F', $days, $hours); - $jobs_S = $this->getDashboardModel()->getJobs($this->bsock, 'S', $days, $hours); - $jobs_s = $this->getDashboardModel()->getJobs($this->bsock, 's', $days, $hours); - $jobs_m = $this->getDashboardModel()->getJobs($this->bsock, 'm', $days, $hours); - $jobs_M = $this->getDashboardModel()->getJobs($this->bsock, 'M', $days, $hours); - $jobs_j = $this->getDashboardModel()->getJobs($this->bsock, 'j', $days, $hours); - $jobs_c = $this->getDashboardModel()->getJobs($this->bsock, 'c', $days, $hours); - $jobs_C = $this->getDashboardModel()->getJobs($this->bsock, 'C', $days, $hours); - $jobs_d = $this->getDashboardModel()->getJobs($this->bsock, 'd', $days, $hours); - $jobs_t = $this->getDashboardModel()->getJobs($this->bsock, 't', $days, $hours); - $jobs_p = $this->getDashboardModel()->getJobs($this->bsock, 'p', $days, $hours); - $jobs_q = $this->getDashboardModel()->getJobs($this->bsock, 'q', $days, $hours); + $jobs_F = $this->getJobModel()->getJobsByStatus($this->bsock, 'F', $days, $hours); + $jobs_S = $this->getJobModel()->getJobsByStatus($this->bsock, 'S', $days, $hours); + $jobs_s = $this->getJobModel()->getJobsByStatus($this->bsock, 's', $days, $hours); + $jobs_m = $this->getJobModel()->getJobsByStatus($this->bsock, 'm', $days, $hours); + $jobs_M = $this->getJobModel()->getJobsByStatus($this->bsock, 'M', $days, $hours); + $jobs_j = $this->getJobModel()->getJobsByStatus($this->bsock, 'j', $days, $hours); + $jobs_c = $this->getJobModel()->getJobsByStatus($this->bsock, 'c', $days, $hours); + $jobs_C = $this->getJobModel()->getJobsByStatus($this->bsock, 'C', $days, $hours); + $jobs_d = $this->getJobModel()->getJobsByStatus($this->bsock, 'd', $days, $hours); + $jobs_t = $this->getJobModel()->getJobsByStatus($this->bsock, 't', $days, $hours); + $jobs_p = $this->getJobModel()->getJobsByStatus($this->bsock, 'p', $days, $hours); + $jobs_q = $this->getJobModel()->getJobsByStatus($this->bsock, 'q', $days, $hours); $num = count($jobs_F) + count($jobs_S) + count($jobs_s) + count($jobs_m) + count($jobs_M) + count($jobs_j) + @@ -95,15 +97,15 @@ private function getJobs($status=null, $days=1, $hours=null) count($jobs_p) + count($jobs_q); } elseif($status == "successful") { - $jobs_T = $this->getDashboardModel()->getJobs($this->bsock, 'T', $days, $hours); - $jobs_W = $this->getDashboardModel()->getJobs($this->bsock, 'W', $days, $hours); + $jobs_T = $this->getJobModel()->getJobsByStatus($this->bsock, 'T', $days, $hours); + $jobs_W = $this->getJobModel()->getJobsByStatus($this->bsock, 'W', $days, $hours); $num = count($jobs_T) + count($jobs_W); } elseif($status == "unsuccessful") { - $jobs_A = $this->getDashboardModel()->getJobs($this->bsock, 'A', $days, $hours); - $jobs_E = $this->getDashboardModel()->getJobs($this->bsock, 'E', $days, $hours); - $jobs_e = $this->getDashboardModel()->getJobs($this->bsock, 'e', $days, $hours); - $jobs_f = $this->getDashboardModel()->getJobs($this->bsock, 'f', $days, $hours); + $jobs_A = $this->getJobModel()->getJobsByStatus($this->bsock, 'A', $days, $hours); + $jobs_E = $this->getJobModel()->getJobsByStatus($this->bsock, 'E', $days, $hours); + $jobs_e = $this->getJobModel()->getJobsByStatus($this->bsock, 'e', $days, $hours); + $jobs_f = $this->getJobModel()->getJobsByStatus($this->bsock, 'f', $days, $hours); $num = count($jobs_A) + count($jobs_E) + count($jobs_e) + count($jobs_f); } } @@ -126,7 +128,7 @@ public function getDataAction() if($data == "jobslaststatus") { try { $this->bsock = $this->getServiceLocator()->get('director'); - $result = $this->getDashboardModel()->getJobsLastStatus($this->bsock); + $result = $this->getJobModel()->getJobsLastStatus($this->bsock); $this->bsock->disconnect(); } catch(Exception $e) { @@ -136,7 +138,7 @@ public function getDataAction() elseif($data == "dirdmsg") { try { $this->bsock = $this->getServiceLocator()->get('director'); - $result = $this->getDashboardModel()->getLastDirectorMessages($this->bsock); + $result = $this->getDirectorModel()->getDirectorMessages($this->bsock, 50, null, false); $this->bsock->disconnect(); } catch(Exception $e) { @@ -155,6 +157,24 @@ public function getDataAction() } + public function getDirectorModel() + { + if(!$this->directorModel) { + $sm = $this->getServiceLocator(); + $this->directorModel = $sm->get('Director\Model\DirectorModel'); + } + return $this->directorModel; + } + + public function getJobModel() + { + if(!$this->jobModel) { + $sm = $this->getServiceLocator(); + $this->jobModel = $sm->get('Job\Model\JobModel'); + } + return $this->jobModel; + } + public function getDashboardModel() { if(!$this->dashboardModel) { diff --git a/module/Dashboard/src/Dashboard/Model/DashboardModel.php b/module/Dashboard/src/Dashboard/Model/DashboardModel.php index 0deb1b25cf1..2ed942f2559 100644 --- a/module/Dashboard/src/Dashboard/Model/DashboardModel.php +++ b/module/Dashboard/src/Dashboard/Model/DashboardModel.php @@ -25,56 +25,6 @@ namespace Dashboard\Model; -use Zend\Json\Json; - class DashboardModel { - - public function getJobs(&$bsock=null, $status=null, $days=null, $hours=null) - { - if(isset($bsock, $status)) { - if(isset($days)) { - $cmd = 'llist jobs jobstatus='.$status.' days='.$days.''; - } - elseif(isset($hours)) { - $cmd = 'llist jobs jobstatus='.$status.' hours='.$hours.''; - } - else { - $cmd = 'llist jobs jobstatus='.$status.''; - } - $result = $bsock->send_command($cmd, 2, null); - $jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $jobs['result']['jobs']; - } - else { - throw new \Exception('Missing argument.'); - } - } - - public function getJobsLastStatus(&$bsock=null) - { - if(isset($bsock)) { - $cmd = 'llist jobs last'; - $result = $bsock->send_command($cmd, 2, null); - $jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $jobs['result']['jobs']; - } - else { - throw new \Exception('Missing argument.'); - } - } - - public function getLastDirectorMessages(&$bsock=null) - { - if(isset($bsock)) { - $cmd = 'llist log limit=50'; - $result = $bsock->send_command($cmd, 2, null); - $msg = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $msg['result']['log']; - } - else { - throw new \Exception('Missing argument.'); - } - } - } diff --git a/module/Director/src/Director/Controller/DirectorController.php b/module/Director/src/Director/Controller/DirectorController.php index 1c870d74f15..91b1f804e06 100644 --- a/module/Director/src/Director/Controller/DirectorController.php +++ b/module/Director/src/Director/Controller/DirectorController.php @@ -97,7 +97,7 @@ public function getDataAction() if($data == "messages") { try { $this->bsock = $this->getServiceLocator()->get('director'); - $result = $this->getDirectorModel()->getDirectorMessages($this->bsock, $limit); + $result = $this->getDirectorModel()->getDirectorMessages($this->bsock, $limit, $offset, $reverse); $this->bsock->disconnect(); } catch(Exception $e) { diff --git a/module/Director/src/Director/Model/DirectorModel.php b/module/Director/src/Director/Model/DirectorModel.php index 0c6bbc43a6e..abb094c140b 100644 --- a/module/Director/src/Director/Model/DirectorModel.php +++ b/module/Director/src/Director/Model/DirectorModel.php @@ -55,7 +55,18 @@ public function getDirectorStatus(&$bsock=null) public function getDirectorMessages(&$bsock=null, $limit=null, $offset=null, $reverse=null) { if(isset($bsock, $limit)) { - $cmd = 'list log limit='.$limit.' reverse'; + if($reverse && $offset == null) { + $cmd = 'list log limit='.$limit.' reverse'; + } + else if($reverse && $offset != null) { + $cmd = 'list log limit='.$limit.' offset='.$offset.' reverse'; + } + else if(!$reverse && $offset != null) { + $cmd = 'list log limit='.$limit.' offset='.$offset; + } + else if(!$reverse && $offset == null) { + $cmd = 'list log limit='.$limit; + } $result = $bsock->send_command($cmd, 2, null); $messages = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); return $messages['result']['log']; diff --git a/module/Director/view/director/director/messages.phtml b/module/Director/view/director/director/messages.phtml index 8ce5ea03f52..9cf96a1a291 100644 --- a/module/Director/view/director/director/messages.phtml +++ b/module/Director/view/director/director/messages.phtml @@ -62,7 +62,7 @@ $this->headTitle($title); function getDirectorMessages() { $.ajax({ - url : 'url('director', array('action' => 'getData'), null) . '?data=messages&limit=500'; ?>', + url : 'url('director', array('action' => 'getData'), null) . '?data=messages&limit=500&offset=null&reverse=true'; ?>', dataType: 'json', timeout: 10000, success: function(data) { diff --git a/module/Job/src/Job/Model/JobModel.php b/module/Job/src/Job/Model/JobModel.php index f6941a8df89..1d9522671bb 100644 --- a/module/Job/src/Job/Model/JobModel.php +++ b/module/Job/src/Job/Model/JobModel.php @@ -128,6 +128,19 @@ public function getJobsByType(&$bsock=null, $type=null) } } + public function getJobsLastStatus(&$bsock=null) + { + if(isset($bsock)) { + $cmd = 'llist jobs last'; + $result = $bsock->send_command($cmd, 2, null); + $jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $jobs['result']['jobs']; + } + else { + throw new \Exception('Missing argument.'); + } + } + public function runJob(&$bsock=null, $name=null) { if(isset($bsock, $name)) {