Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Dashboard: Native director connectivity
Browse files Browse the repository at this point in the history
Replaces database connection with native director connection.
  • Loading branch information
fbergkemper committed Sep 4, 2015
1 parent 68c707e commit 3fb1454
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 54 deletions.
87 changes: 75 additions & 12 deletions module/Dashboard/src/Dashboard/Controller/DashboardController.php
Expand Up @@ -31,18 +31,16 @@
class DashboardController extends AbstractActionController
{

protected $jobTable;

public function indexAction()
{
if($_SESSION['bareos']['authenticated'] && $this->SessionTimeoutPlugin()->timeout()) {

return new ViewModel(
array(
'runningJobs' => $this->getJobTable()->getJobCountLast24HoursByStatus("running"),
'waitingJobs' => $this->getJobTable()->getJobCountLast24HoursByStatus("waiting"),
'successfulJobs' => $this->getJobTable()->getJobCountLast24HoursByStatus("successful"),
'unsuccessfulJobs' => $this->getJobTable()->getJobCountLast24HoursByStatus("unsuccessful"),
'runningJobs' => $this->getJobCount("running", 1, null),
'waitingJobs' => $this->getJobCount("waiting", 1, null),
'successfulJobs' => $this->getJobCount("successful", 1, null),
'unsuccessfulJobs' => $this->getJobCount("unsuccessful", 1, null),
)
);
}
Expand All @@ -51,15 +49,80 @@ public function indexAction()
}
}

private function getJobTable()
private function getJobCount($status=null, $days=null, $hours=null)
{
if(!$this->jobTable)
{
$sm = $this->getServiceLocator();
$this->jobTable = $sm->get('Job\Model\JobTable');
if($status != null) {
$director = $this->getServiceLocator()->get('director');
if($status == "running") {
$jobs_R = $this->getJobsByStatus('R', 1, null);
$jobs_l = $this->getJobsByStatus('l', 1, null);
$num = count($jobs_R) + count($jobs_l);
return $num;
}
elseif($status == "waiting") {
$jobs_F = $this->getJobsByStatus('F', 1, null);
$jobs_S = $this->getJobsByStatus('S', 1, null);
$jobs_s = $this->getJobsByStatus('s', 1, null);
$jobs_m = $this->getJobsByStatus('m', 1, null);
$jobs_M = $this->getJobsByStatus('M', 1, null);
$jobs_j = $this->getJobsByStatus('j', 1, null);
$jobs_c = $this->getJobsByStatus('c', 1, null);
$jobs_C = $this->getJobsByStatus('C', 1, null);
$jobs_d = $this->getJobsByStatus('d', 1, null);
$jobs_t = $this->getJobsByStatus('t', 1, null);
$jobs_p = $this->getJobsByStatus('p', 1, null);
$jobs_q = $this->getJobsByStatus('q', 1, null);
$num = count($jobs_F) + count($jobs_S) +
count($jobs_s) + count($jobs_m) +
count($jobs_M) + count($jobs_j) +
count($jobs_c) + count($jobs_C) +
count($jobs_d) + count($jobs_t) +
count($jobs_p) + count($jobs_q);
return $num;
}
elseif($status == "successful") {
$jobs_T = $this->getJobsByStatus('T', 1, null);
$jobs_W = $this->getJobsByStatus('W', 1, null);
$num = count($jobs_T) + count($jobs_W);
return $num;
}
elseif($status == "unsuccessful") {
$jobs_A = $this->getJobsByStatus('A', 1, null);
$jobs_E = $this->getJobsByStatus('E', 1, null);
$jobs_e = $this->getJobsByStatus('e', 1, null);
$jobs_f = $this->getJobsByStatus('f', 1, null);
$num = count($jobs_A) + count($jobs_E) + count($jobs_e) + count($jobs_f);
return $num;
}
else {
return null;
}
}
else {
return null;
}
return $this->jobTable;
}

private function getJobsByStatus($status=null, $days=null, $hours=null)
{
if($status != null) {
$director = $this->getServiceLocator()->get('director');
if($days != null) {
$result = $director->send_command('llist jobs jobstatus="'.$status.'" days="'.$days.'"', 2, null);
}
elseif($hours != null) {
$result = $director->send_command('llist jobs jobstatus="'.$status.'" hours="'.$hours.'"', 2, null);
}
else {
$result = $director->send_command('llist jobs jobstatus="'.$status.'"', 2, null);
}
$jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $jobs['result']['jobs'];
}
else {
return null;
}
}

}

12 changes: 2 additions & 10 deletions module/Dashboard/src/Dashboard/Model/Dashboard.php
Expand Up @@ -3,7 +3,7 @@
/**
*
* bareos-webui - Bareos Web-Frontend
*
*
* @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2014 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
Expand All @@ -25,15 +25,7 @@

namespace Dashboard\Model;

class Dashboard
class Dashboard
{

public $dashboardid;

public function exchangeArray($data)
{
//$this->dashboardid = (!empty($data['dashboardid'])) ? $data['dashboardid'] : null;
}

}

29 changes: 1 addition & 28 deletions module/Dashboard/src/Dashboard/Model/DashboardTable.php
Expand Up @@ -3,7 +3,7 @@
/**
*
* bareos-webui - Bareos Web-Frontend
*
*
* @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2014 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
Expand All @@ -25,34 +25,7 @@

namespace Dashboard\Model;

use Zend\Db\TableGateway\TableGateway;

class DashboardTable
{

protected $tableGateway;

public function __construct(TableGateway $tableGateway)
{
$this->tableGateway = $tableGateway;
}

public function fetchAll()
{
$resultSet = $this->tableGateway->select();
return $resultSet;
}

public function getDashboard($id)
{
$id = (int) $id;
$rowset = $this->tableGateway->select(array('id' => $id));
$row = $rowset->current();
if(!$row) {
throw new \Exception("Could not find row $id");
}
return $row;
}

}

5 changes: 1 addition & 4 deletions module/Dashboard/view/dashboard/dashboard/index.phtml
Expand Up @@ -29,9 +29,6 @@ $this->headTitle($title);

?>

<h3 class="text-muted"><?php echo $this->translate($title); ?></h3>
<hr />

<div class="row">

<div class="col-md-8">
Expand All @@ -49,7 +46,7 @@ $this->headTitle($title);

<div class="col-md-4">

<table class="table" style="font-size: 9pt;">
<table class="table">
<tr>
<td><a href="<?php echo $this->url('job', array('action' => 'running')); ?>"><?php echo $this->translate("Running"); ?></a></td>
<td><a href="<?php echo $this->url('job', array('action' => 'running')); ?>"><?php echo $this->runningJobs; ?></a></td>
Expand Down

0 comments on commit 3fb1454

Please sign in to comment.