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

Commit

Permalink
Pool: 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 Aug 26, 2015
1 parent 5a09907 commit cb45270
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 308 deletions.
13 changes: 6 additions & 7 deletions module/Application/view/partial/paginator.phtml
@@ -1,18 +1,17 @@

<?php if($this->pageCount): ?>

<div>
<ul class="pagination pagination-centered">

<ul class="pagination">

<!-- previous page link -->
<?php if(isset($this->previous)): ?>
<li>
<a href="<?php echo $this->url($this->route, array(), null, true); ?>?page=<?php echo $this->previous; ?>">previous</a>
<a href="<?php echo $this->url($this->route, array(), null, true); ?>?page=<?php echo $this->previous; ?>"><span aria-hidden="true">&laquo;</span></a>
</li>
<?php else: ?>
<li class="disabled">
<a href="#">previous</a>
<a href="#"><span aria-hidden="true">&laquo;</span></a>
</li>
<?php endif; ?>

Expand Down Expand Up @@ -46,11 +45,11 @@
<!-- next page link -->
<?php if(isset($this->next)): ?>
<li>
<a href="<?php echo $this->url($this->route, array(), null, true); ?>?page=<?php echo $this->next; ?>">next</a>
<a href="<?php echo $this->url($this->route, array(), null, true); ?>?page=<?php echo $this->next; ?>"><span aria-hidden="true">&raquo;</span></a>
</li>
<?php else: ?>
<li class="disabled">
<a href="#">next</a>
<a href="#"><span aria-hidden="true">&raquo;</span></a>
</li>
<?php endif; ?>

Expand Down
1 change: 0 additions & 1 deletion module/Media/config/module.config.php
Expand Up @@ -53,7 +53,6 @@
'action' => 'index',
),
),

),
),
),
Expand Down
9 changes: 5 additions & 4 deletions module/Pool/config/module.config.php
Expand Up @@ -40,20 +40,21 @@
'pool' => array(
'type' => 'segment',
'options' => array(
'route' => '/pool[/][:action][/:id][order_by/:order_by][/:order][/][limit/:limit]',
'route' => '/pool[/][:action/][:id][/][limit/:limit]',
'constraints' => array(
'action' => '(?!\blimit\b)(?!\border_by\b)[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
'action' => '(?!\blimit\b)[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[a-zA-Z][a-zA-Z0-9_-]*',
'order_by' => '[a-zA-Z][a-zA-Z0-9_-]*',
'order' => 'ASC|DESC',
'limit' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Pool\Controller\Pool',
'action' => 'index',
'limit' => '[0-9]+'
),
),

),
),
),
Expand Down
76 changes: 46 additions & 30 deletions module/Pool/src/Pool/Controller/PoolController.php
Expand Up @@ -5,7 +5,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/)
* @copyright Copyright (c) 2013-2015 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -27,32 +27,32 @@

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Paginator\Adapter\ArrayAdapter;
use Zend\Paginator\Paginator;

class PoolController extends AbstractActionController
{

protected $poolTable;
protected $mediaTable;

public function indexAction()
{
if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) {
$order_by = $this->params()->fromRoute('order_by') ? $this->params()->fromRoute('order_by') : 'PoolId';
$order = $this->params()->fromRoute('order') ? $this->params()->fromRoute('order') : 'DESC';

$pools = $this->getPools();
$page = (int) $this->params()->fromQuery('page');
$limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25';
$paginator = $this->getPoolTable()->fetchAll(true, $order_by, $order);
$paginator->setCurrentPageNumber( (int) $this->params()->fromQuery('page', 1) );

$paginator = new Paginator(new ArrayAdapter($pools));
$paginator->setCurrentPageNumber($page);
$paginator->setItemCountPerPage($limit);

return new ViewModel(
array(
'limit' => $limit,
//'pools' => $pools,
'paginator' => $paginator,
'order_by' => $order_by,
'order' => $order,
'limit' => $limit,
'pools' => $this->getPoolTable()->fetchAll(),
)
);

}
else {
return $this->redirect()->toRoute('auth', array('action' => 'login'));
Expand All @@ -62,16 +62,26 @@ public function indexAction()
public function detailsAction()
{
if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) {
$id = (int) $this->params()->fromRoute('id', 0);

if (!$id) {
return $this->redirect()->toRoute('pool');
}

$poolname = $this->params()->fromRoute('id');
$page = $this->params()->fromQuery('page');
$limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25';

$pool = $this->getPool($poolname);
$media = $this->getPoolMedia($poolname);

$paginator = new Paginator(new ArrayAdapter($media));
$paginator->setCurrentPageNumber($page);
$paginator->setItemCountPerPage($limit);

return new ViewModel(
array(
'pool' => $this->getPoolTable()->getPool($id),
'media' => $this->getMediaTable()->getPoolVolumes($id),
'poolname' => $poolname,
'limit' => $limit,
'pool' => $pool,
//'media' => $media,
'paginator' => $paginator,
)
);
}
Expand All @@ -80,22 +90,28 @@ public function detailsAction()
}
}

public function getPoolTable()
private function getPool($pool)
{
if(!$this->poolTable) {
$sm = $this->getServiceLocator();
$this->poolTable = $sm->get('Pool\Model\PoolTable');
}
return $this->poolTable;
$director = $this->getServiceLocator()->get('director');
$result = $director->send_command("llist pool=".$pool, 2, null);
$pools = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $pools['result']['pools'][0];
}

public function getMediaTable()
private function getPools()
{
if(!$this->mediaTable) {
$sm = $this->getServiceLocator();
$this->mediaTable = $sm->get('Media\Model\MediaTable');
}
return $this->mediaTable;
$director = $this->getServiceLocator()->get('director');
$result = $director->send_command("llist pools", 2, null);
$pools = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $pools['result']['pools'];
}

private function getPoolMedia($pool)
{
$director = $this->getServiceLocator()->get('director');
$result = $director->send_command("llist media pool=".$pool, 2, null);
$media = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $media['result']['media'];
}

}
Expand Down
65 changes: 3 additions & 62 deletions module/Pool/src/Pool/Model/Pool.php
Expand Up @@ -3,9 +3,9 @@
/**
*
* 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/)
* @copyright Copyright (c) 2013-2015 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -25,65 +25,6 @@

namespace Pool\Model;

class Pool
class Pool
{

public $poolid;
public $name;
public $numvols;
public $maxvols;
public $useonce;
public $usecatalog;
public $acceptanyvolume;
public $volretention;
public $voluseduration;
public $maxvoljobs;
public $maxvolfiles;
public $maxvolbytes;
public $autoprune;
public $recycle;
public $actiononpurge;
public $pooltype;
public $labeltype;
public $labelformat;
public $enabled;
public $scratchpoolid;
public $recyclepoolid;
public $nextpoolid;
public $migrationhighbytes;
public $migrationlowbytes;
public $migrationtime;

public function exchangeArray($data)
{
$data = array_change_key_case($data, CASE_LOWER);

$this->poolid = (!empty($data['poolid'])) ? $data['poolid'] : null;
$this->name = (!empty($data['name'])) ? $data['name'] : null;
$this->numvols = (!empty($data['numvols'])) ? $data['numvols'] : null;
$this->maxvols = (!empty($data['maxvols'])) ? $data['maxvols'] : null;
$this->useonce = (!empty($data['useonce'])) ? $data['useonce'] : null;
$this->usecatalog = (!empty($data['usecatalog'])) ? $data['usecatalog'] : null;
$this->acceptanyvolume = (!empty($data['acceptanyvolume'])) ? $data['acceptanyvolume'] : null;
$this->volretention = (!empty($data['volretention'])) ? $data['volretention'] : null;
$this->voluseduration = (!empty($data['voluseduration'])) ? $data['voluseduration'] : null;
$this->maxvoljobs = (!empty($data['maxvoljobs'])) ? $data['maxvoljobs'] : null;
$this->maxvolfiles = (!empty($data['maxvolfiles'])) ? $data['maxvolfiles'] : null;
$this->maxvolbytes = (!empty($data['maxvolbytes'])) ? $data['maxvolbytes'] : null;
$this->autoprune = (!empty($data['autoprune'])) ? $data['autoprune'] : null;
$this->recycle = (!empty($data['recycle'])) ? $data['recycle'] : null;
$this->actiononpurge = (!empty($data['actiononpurge'])) ? $data['actiononpurge'] : null;
$this->pooltype = (!empty($data['pooltype'])) ? $data['pooltype'] : null;
$this->labeltype = (!empty($data['labeltype'])) ? $data['labeltype'] : null;
$this->labelformat = (!empty($data['labelformat'])) ? $data['labelformat'] : null;
$this->enabled = (!empty($data['enabled'])) ? $data['enabled'] : null;
$this->scratchpoolid = (!empty($data['scratchpoolid'])) ? $data['scratchpoolid'] : null;
$this->recyclepoolid = (!empty($data['recyclepoolid'])) ? $data['recyclepoolid'] : null;
$this->nextpoolid = (!empty($data['nextpoolid'])) ? $data['nextpoolid'] : null;
$this->migrationhighbytes = (!empty($data['migrationhighbytes'])) ? $data['migrationhighbytes'] : null;
$this->migrationlowbytes = (!empty($data['migrationlowbytes'])) ? $data['migrationlowbytes'] : null;
$this->migrationtime = (!empty($data['migrationtime'])) ? $data['migrationtime'] : null;
}

}

98 changes: 2 additions & 96 deletions module/Pool/src/Pool/Model/PoolTable.php
Expand Up @@ -5,7 +5,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/)
* @copyright Copyright (c) 2013-2015 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -25,100 +25,6 @@

namespace Pool\Model;

use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql\Select;
use Zend\Paginator\Adapter\DbSelect;
use Zend\Paginator\Paginator;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Bareos\Db\Sql\BareosSqlCompatHelper;

class PoolTable implements ServiceLocatorAwareInterface
class PoolTable
{

protected $tableGateway;
protected $serviceLocator;

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

public function setServiceLocator(ServiceLocatorInterface $serviceLocator) {
$this->serviceLocator = $serviceLocator;
}

public function getServiceLocator() {
return $this->serviceLocator;
}

public function getDbDriverConfig() {
$config = $this->getServiceLocator()->get('Config');
return $config['db']['adapters'][$_SESSION['bareos']['director']]['driver'];
}

public function fetchAll($paginated=false, $order_by=null, $order=null)
{
$bsqlch = new BareosSqlCompatHelper($this->getDbDriverConfig());
$select = new Select();
$select->from($bsqlch->strdbcompat("Pool"));

if($order_by != null && $order != null) {
$select->order($bsqlch->strdbcompat($order_by) . " " . $order);
}
else {
$select->order($bsqlch->strdbcompat("PoolId") . " DESC");
}

if($paginated) {
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Pool());
$paginatorAdapter = new DbSelect(
$select,
$this->tableGateway->getAdapter(),
$resultSetPrototype
);
$paginator = new Paginator($paginatorAdapter);
return $paginator;
}
else {
$resultSet = $this->tableGateway->selectWith($select);
return $resultSet;
}
}

public function getPool($id)
{
$id = (int) $id;
$bsqlch = new BareosSqlCompatHelper($this->getDbDriverConfig());
$rowset = $this->tableGateway->select(
array(
$bsqlch->strdbcompat("PoolId") => $id
)
);
$row = $rowset->current();
if(!$row) {
throw new \Exception("Could not find row $id");
}
return $row;
}

public function getPoolNum()
{
$bsqlch = new BareosSqlCompatHelper($this->getDbDriverConfig());
$select = new Select();
$select->from($bsqlch->strdbcompat("Pool"));
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Pool());
$rowset = new DbSelect(
$select,
$this->tableGateway->getAdapter(),
$resultSetPrototype
);
$num = $rowset->count();
return $num;
}

}

0 comments on commit cb45270

Please sign in to comment.