Skip to content

Commit

Permalink
Refactoring: Dashboard Model
Browse files Browse the repository at this point in the history
- Removes getLastDirectorMessages() from the Dashboard Model. The Dashboard Controller
  uses the getDirectorMessages() method of the Director Model now. getDirectorMessages()
  is extended to be more flexible.

- Moves the getJobsLastStatus() method into its context, the Job Model.

- Removes getJobs() from the Dashboard Model. The Dashboard Controller uses the getJobsByStatus()
  method of the Job Model now.
  • Loading branch information
fbergkemper committed Aug 3, 2016
1 parent c348542 commit 791c670
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 75 deletions.
64 changes: 42 additions & 22 deletions module/Dashboard/src/Dashboard/Controller/DashboardController.php
Expand Up @@ -31,6 +31,8 @@

class DashboardController extends AbstractActionController
{
protected $directorModel = null;
protected $jobModel = null;
protected $dashboardModel = null;
protected $bsock = null;

Expand Down Expand Up @@ -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) +
Expand All @@ -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);
}
}
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
50 changes: 0 additions & 50 deletions module/Dashboard/src/Dashboard/Model/DashboardModel.php
Expand Up @@ -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.');
}
}

}
Expand Up @@ -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) {
Expand Down
13 changes: 12 additions & 1 deletion module/Director/src/Director/Model/DirectorModel.php
Expand Up @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion module/Director/view/director/director/messages.phtml
Expand Up @@ -62,7 +62,7 @@ $this->headTitle($title);

function getDirectorMessages() {
$.ajax({
url : '<?php echo $this->url('director', array('action' => 'getData'), null) . '?data=messages&limit=500'; ?>',
url : '<?php echo $this->url('director', array('action' => 'getData'), null) . '?data=messages&limit=500&offset=null&reverse=true'; ?>',
dataType: 'json',
timeout: 10000,
success: function(data) {
Expand Down
13 changes: 13 additions & 0 deletions module/Job/src/Job/Model/JobModel.php
Expand Up @@ -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)) {
Expand Down

0 comments on commit 791c670

Please sign in to comment.