More library display enhancements

This commit is contained in:
Deon George 2011-06-26 22:20:12 +10:00
parent 214bc39648
commit 9cfd1dc3df
11 changed files with 313 additions and 28 deletions

View File

@ -61,12 +61,11 @@ class Controller_LIBRARY extends Controller_TemplateDefault {
Request::current()->redirect('library');
}
$slots = DB::query(Database::SHOW,'SHOW SLOTS '.$lo)->execute();
Block::add(array(
'title'=>sprintf(_('Library Information for %s'),$lo->LIBRARY_NAME),
'body'=>View::factory('library/detail')
->set('lo',$lo)
->set('slots',$slots)
->set('slots',$lo->slots())
));
}
}

View File

@ -34,7 +34,7 @@ class Database_TSM_Show extends Database_Result {
$slot = array();
foreach ((preg_split('/,\s*/',$line,-1)) as $slotkey => $val)
if (preg_match('/^element number\s+/',$val))
$slot['element'] = preg_replace('/^element number\s+/','',$val);
$slot['element'] = (int)preg_replace('/^element number\s+/','',$val);
elseif (preg_match('/^Slot\s+/',$val))
$slot['slot'] = preg_replace('/^Slot\s+/','',$val);
elseif (preg_match('/^status\s+/',$val))
@ -72,7 +72,6 @@ class Database_TSM_Show extends Database_Result {
list($k,$v) = explode(':',$line,2);
$this->data[$k] = $v;
} else {
}
}
}

View File

@ -3,12 +3,12 @@
/**
*
* @package PTA
* @subpackage Volume
* @subpackage Device Classes
* @category Models
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
* @node This is model is using the plural name, as storage pools have an attribute with the singular name
* @note This is model is using the plural name, as storage pools have an attribute with the singular name
*/
class Model_DEVCLASSES extends ORMTSM {
protected $_table_name = 'DEVCLASSES';
@ -17,5 +17,9 @@ class Model_DEVCLASSES extends ORMTSM {
'DEVTYPE'=>'ASC',
'DEVCLASS_NAME'=>'ASC',
);
protected $_has_many = array(
'STGPOOL'=>array('foreign_key'=>'DEVCLASS','far_key'=>'DEVCLASS_NAME'),
);
}
?>

View File

@ -16,10 +16,119 @@ class Model_LIBRARY extends ORMTSM {
'LIBRARY_NAME'=>'ASC',
);
// Store our show slots data
private $slots;
private $storagepools = array();
protected $_has_one = array(
);
protected $_has_many = array(
'DRIVE'=>array('foreign_key'=>'LIBRARY_NAME','far_key'=>'LIBRARY_NAME'),
'PATH'=>array('foreign_key'=>'DESTINATION_NAME','far_key'=>'LIBRARY_NAME'),
'DEVCLASSES'=>array('foreign_key'=>'LIBRARY_NAME','far_key'=>'LIBRARY_NAME'),
);
public function slots() {
return $this->slots ? $this->slots : $this->slots = DB::query(Database::SHOW,'SHOW SLOTS '.$this)->execute();
}
// Return a list of scratch volumes
public function scratch() {
$return = array();
foreach ($this->slots() as $slot)
if ($slot->status == 'Allocated' AND $slot->LIBVOLUME->usage() == 'scratch')
array_push($return,$slot->LIBVOLUME->VOLUME);
return $return;
}
// Return a list of volumes that are readonly
public function readonly() {
$return = array();
foreach ($this->slots() as $slot)
if ($slot->LIBVOLUME->VOLUME->ACCESS == 'READONLY')
array_push($return,$slot->LIBVOLUME->VOLUME);
return $return;
}
// Return the number of slots that are empty.
public function numemptyslot() {
return $this->slots->Slots-$this->slots->Changers-count($this->slots);
}
// Return the slots that are used, but not checked in.
public function notcheckedin() {
$return = array();
foreach ($this->slots() as $slot)
if ($slot->status == 'Full')
array_push($return,$slot);
return $return;
}
// Return the device classes that use this library.
public function devclasses() {
return $this->DEVCLASSES->where('LIBRARY_NAME','=',$this)->find_all();
}
// Return a list of storage pools that potentially use this library.
public function storagepools() {
if (! $this->storagepools)
foreach ($this->devclasses() as $dco)
foreach ($dco->STGPOOL->find_all() as $spo)
array_push($this->storagepools,$spo);
return $this->storagepools;
}
public function storagepoolstype($type) {
$result = array();
foreach ($this->storagepools() as $spo)
if ($spo->POOLTYPE == $type)
array_push($result,$spo);
return $result;
}
// Return a list of volumes
// $ptype is pool type (PRIMARY,ACTIVE,COPY)
// @param $inout IN|OUT of the library
// @param $status volume status FULL|FILLING|PENDING|EMPTY
// @note This is an intensive method that needs caching.
public function volstype($type,$inout,$status) {
static $CACHE = array();
$ainout = array('in','out');
$astatus = array('FULL','FILLING','PENDING','EMPTY');
if (! isset($CACHE[__METHOD__][$type]))
foreach ($this->storagepoolstype($type) as $spo)
foreach ($ainout as $cinout)
foreach ($astatus as $cstatus) {
if (! isset($CACHE[__METHOD__][$spo->POOLTYPE][$cinout][$cstatus]))
$CACHE[__METHOD__][$spo->POOLTYPE][$cinout][$cstatus] = array();
$CACHE[__METHOD__][$spo->POOLTYPE][$cinout][$cstatus] =
array_merge($CACHE[__METHOD__][$spo->POOLTYPE][$cinout][$cstatus],$spo->libvolstype($cinout,$cstatus));
}
return isset($CACHE[__METHOD__][$type][$inout][$status]) ? $CACHE[__METHOD__][$type][$inout][$status] : array();
}
public function volsnotinlib() {
$result = array();
foreach ($this->storagepools() as $spo)
foreach ($spo->VOLUME->find_all() as $vo)
if ($vo->MEDIA->STATUS != 'MOUNTABLEINLIB')
array_push($result,$vo);
Sort::masort($result,'VOLUME_NAME');
return $result;
}
}
?>

View File

@ -11,7 +11,7 @@
*/
class Model_LIBVOLUME extends ORMTSM {
protected $_table_name = 'LIBVOLUMES';
protected $_primary_key = 'VOLUME_NAME';
protected $_primary_key = 'HOME_ELEMENT';
protected $_sorting = array(
'VOLUME_NAME'=>'ASC',
);
@ -32,16 +32,19 @@ class Model_LIBVOLUME extends ORMTSM {
case 'data':
return strtolower($this->LAST_USE);
default: return 'unknown';
default: return ($this->VOLUME->STATUS == 'EMPTY') ? 'empty' : 'unknown';
}
default: return 'notcheckedin';
}
}
public function volusage() {
switch ($this->usage()) {
case 'scratch': return _('Scratch');
case 'data':
case 'empty': return $this->VOLUME->STGPOOL_NAME;
case 'dbbackup': return $this->VOLHISTORY->lastuse()->TYPE;
case 'data': return $this->VOLUME->STGPOOL_NAME;
case 'notcheckedin': return _('Not Checked In');
case 'scratch': return _('Scratch');
default: return _('Unknown');
}
@ -51,27 +54,26 @@ class Model_LIBVOLUME extends ORMTSM {
switch ($this->usage()) {
case 'data': return sprintf('%s/%s',$this->VOLUME->display('STATUS'),$this->VOLUME->display('ACCESS'));
case 'dbbackup': return $this->VOLHISTORY->lastuse()->backupid();
case 'empty': return _('Empty');
default: return '';
}
}
public function access() {
switch ($this->usage()) {
case 'data':
case 'dbbackup':
return sprintf('%s/%s',$this->display('STATUS'),$this->display('OWNER'));
default: return '';
}
if ($this->usage() == 'scratch')
return '';
elseif ($this->STATUS)
return sprintf('%s/%s',$this->display('STATUS'),$this->display('OWNER'));
else
return '';
}
public function lastwrite() {
switch ($this->usage()) {
case 'data':
return $this->VOLUME->display('LAST_WRITE_DATE');
case 'dbbackup':
return $this->VOLHISTORY->lastuse()->display('DATE_TIME');
case 'empty': return $this->VOLUME->display('LAST_WRITE_DATE');
case 'dbbackup': return $this->VOLHISTORY->lastuse()->display('DATE_TIME');
default: return '';
}

View File

@ -0,0 +1,24 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
*
* @package PTA
* @subpackage Media
* @category Models
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
class Model_MEDIA extends ORMTSM {
protected $_table_name = 'MEDIA';
protected $_primary_key = 'VOLUME_NAME';
protected $_sorting = array(
'VOLUME_NAME'=>'ASC',
);
protected $_has_one = array(
);
protected $_has_many = array(
);
}
?>

View File

@ -22,5 +22,23 @@ class Model_STGPOOL extends ORMTSM {
protected $_has_many = array(
'VOLUME'=>array('foreign_key'=>'STGPOOL_NAME','far_key'=>'STGPOOL_NAME'),
);
// Return a list of volumes
// @param $inout IN|OUT of the library
// @param $status volume status FULL|FILLING|PENDING|EMPTY
public function libvolstype($inout,$status) {
$inout = strtolower($inout);
$status = strtoupper($status);
$result = array();
if (! isset($result[$inout]))
foreach ($this->VOLUME->find_all() as $vo) {
$state = ($vo->MEDIA->STATE == 'MOUNTABLEINLIB') ? 'in' : 'out';
$result[$state][$vo->STATUS][] = $vo;
}
return isset($result[$inout][$status]) ? $result[$inout][$status] : array();
}
}
?>

View File

@ -17,6 +17,9 @@ class Model_VOLUME extends ORMTSM {
'STGPOOL_NAME'=>'ASC',
);
protected $_has_one = array(
'MEDIA'=>array('foreign_key'=>'VOLUME_NAME','far_key'=>'VOLUME_NAME'),
);
protected $_has_many = array(
'VOLUMEUSAGE'=>array('foreign_key'=>'VOLUME_NAME','far_key'=>'VOLUME_NAME'),
);

View File

@ -12,6 +12,7 @@
*/
class ORM extends Kohana_ORM {
protected $_table_names_plural = false;
protected $_model_names_plural = false;
private $_object_formated = array();
private $_formated = FALSE;
// Our filters used to display values in a friendly format

View File

@ -14,7 +14,7 @@ class Slot {
private $data = array();
private $objects = array(
'VOLUME'=>'barcodelabel',
'LIBVOLUME'=>'barcodelabel',
'LIBVOLUME'=>'element',
);
public function __construct(array $slot) {
@ -36,7 +36,9 @@ class Slot {
}
public function barcodelabel() {
if ($this->status == 'Allocated' AND $this->barcode == 'not present')
if ($this->LIBVOLUME->VOLUME_NAME)
return $this->LIBVOLUME->VOLUME_NAME;
elseif ($this->status == 'Allocated' AND $this->barcode == 'not present')
return _('No Label');
elseif ($this->status == 'Unallocated')
return _('Slot Empty');

View File

@ -3,7 +3,7 @@
<td style="width: 50%; vertical-align: top;">
<table class="box-full">
<tr>
<td class="head" colspan="5">Information for this Library</td>
<td class="head" colspan="2">Information for this Library</td>
</tr>
<tr>
<td class="spacer">&nbsp;</td>
@ -26,7 +26,7 @@
</tr>
<tr>
<td>Slots/Changers</td>
<td class="data"><?php printf('%s/%s',$slots->Slots,$slots->Changers); ?></td>
<td class="data"><?php printf('%s/%s',$slots->Slots-$slots->Changers,$slots->Changers); ?></td>
</tr>
<tr>
<td>Shared</td>
@ -40,8 +40,98 @@
<td>Auto Label</td>
<td class="data"><?php echo $lo->display('AUTOLABEL'); ?></td>
</tr>
<tr>
<td>Paths</td>
<td>
<table style="width: 100%;">
<?php $i=0; foreach ($lo->PATH->find_all() as $po) { ?>
<tr class="<?php echo $i++%2 ? 'odd' : 'even'; ?>">
<td><?php echo $po->display('SOURCE_NAME'); ?></td>
<td><?php echo $po->display('SOURCE_TYPE'); ?></td>
<td><?php echo $po->display('DESTINATION_TYPE'); ?></td>
<td><?php echo $po->display('DEVICE'); ?></td>
</tr>
</table>
</td>
</tr>
<?php } ?>
</table>
</td>
<td style="width: 100%; vertical-align: top;" rowspan="2">
<table class="box-full">
<tr>
<td class="head" colspan="10">Library Volume Summary</td>
</tr>
<tr>
<td class="spacer">&nbsp;</td>
</tr>
<tr>
<td style="width: 40%;" colspan="2">Empty Slots</td>
<td style="width: 60%;" class="data" colspan="8"><?php echo $lo->numemptyslot(); ?></td>
</tr>
<tr>
<td colspan="2">Not Checked In</td>
<td class="data" colspan="8"><?php echo count($lo->notcheckedin()); ?></td>
</tr>
<tr>
<td colspan="2">Scratch</td>
<td class="data" colspan="8"><?php echo count($lo->scratch()); ?></td>
</tr>
<tr>
<td colspan="2">Read Only</td>
<td class="data" colspan="8"><?php echo count($lo->readonly()); ?></td>
</tr>
<tr>
<td class="spacer">&nbsp;</td>
</tr>
<tr>
<td class="head" colspan="10">Storage Pool Volumes for this Library</td>
</tr>
<tr>
<td class="spacer">&nbsp;</td>
</tr>
<tr>
<td colspan="2">Storage Type</td>
<td class="right">IN: FULL</td>
<td class="right">IN: FILLING</td>
<td class="right">IN: PENDING</td>
<td class="right">IN: EMPTY</td>
<td class="right">OUT: FULL</td>
<td class="right">OUT: FILLING</td>
<td class="right">OUT: PENDING</td>
<td class="right">OUT: EMPTY</td>
</tr>
<?php $i=0; foreach (Kohana::config('config.tsmpooltypes') as $type) { ?>
<tr class="<?php echo $i++%2 ? 'odd' : 'even'; ?>">
<td class="data" colspan="2"><?php echo $type; ?></td>
<td class="data-right"><?php echo count($lo->volstype($type,'in','FULL')); ?></td>
<td class="data-right"><?php echo count($lo->volstype($type,'in','FILLING')); ?></td>
<td class="data-right"><?php echo count($lo->volstype($type,'in','PENDING')); ?></td>
<td class="data-right"><?php echo count($lo->volstype($type,'in','EMPTY')); ?></td>
<td class="data-right"><?php echo count($lo->volstype($type,'out','FULL')); ?></td>
<td class="data-right"><?php echo count($lo->volstype($type,'out','FILLING')); ?></td>
<td class="data-right"><?php echo count($lo->volstype($type,'out','PENDING')); ?></td>
<td class="data-right"><?php echo count($lo->volstype($type,'out','EMPTY')); ?></td>
</tr>
<?php foreach ($lo->storagepoolstype($type) as $spo) { ?>
<tr class="<?php echo $i++%2 ? 'odd' : 'even'; ?>">
<td>&nbsp;</td>
<td><?php echo $spo; ?></td>
<td class="right"><?php echo count($spo->libvolstype('in','FULL')); ?></td>
<td class="right"><?php echo count($spo->libvolstype('in','FILLING')); ?></td>
<td class="right"><?php echo count($spo->libvolstype('in','PENDING')); ?></td>
<td class="right"><?php echo count($spo->libvolstype('in','EMPTY')); ?></td>
<td class="right"><?php echo count($spo->libvolstype('out','FULL')); ?></td>
<td class="right"><?php echo count($spo->libvolstype('out','FILLING')); ?></td>
<td class="right"><?php echo count($spo->libvolstype('out','PENDING')); ?></td>
<td class="right"><?php echo count($spo->libvolstype('out','EMPTY')); ?></td>
</tr>
<?php } ?>
<?php } ?>
</table>
</td>
</tr>
<tr>
<td style="width: 50%; vertical-align: top;">
<table class="box-full">
<tr>
@ -88,27 +178,61 @@
<td class="spacer">&nbsp;</td>
</tr>
<tr>
<td>Slot</td>
<td>Barcode</td>
<td>Usage</td>
<td>Status/Access</td>
<td>Library Access</td>
<td>Utilisation</td>
<td>Reclaim</td>
<td>Last Read</td>
<td>Last Write</td>
<td>Slot</td>
<td>Library Access</td>
</tr>
<?php $i=0; foreach ($slots as $slot) { ?>
<tr class="<?php echo $i++%2 ? 'odd' : 'even'; ?>">
<td class="data"><acronym title="<?php printf('%s: %s',_('Element'),$slot->element); ?>"><?php echo $slot; ?></acronym></td>
<td class="data"><?php echo HTML::nbsp($slot->barcodelabel()); ?></td>
<td class="data"><?php echo $slot->LIBVOLUME->volusage(); ?></td>
<td class="data"><?php echo HTML::nbsp($slot->LIBVOLUME->status()); ?></td>
<td class="data"><?php echo HTML::nbsp($slot->LIBVOLUME->access()); ?></td>
<td class="data"><?php echo $slot->LIBVOLUME->VOLUME->display('PCT_UTILIZED'); ?></td>
<td class="data"><?php echo $slot->LIBVOLUME->VOLUME->display('PCT_RECLAIM'); ?></td>
<td class="data"><?php echo $slot->LIBVOLUME->VOLUME->display('LAST_READ_DATE'); ?></td>
<td class="data"><?php echo HTML::nbsp($slot->LIBVOLUME->lastwrite()); ?></td>
<td class="data"><acronym title="<?php printf('%s: %s',_('Element'),$slot->element); ?>"><?php echo $slot; ?></acronym></td>
<td class="data"><?php echo HTML::nbsp($slot->LIBVOLUME->access()); ?></td>
</tr>
<?php } ?>
</table>
</td>
</tr>
<tr>
<td style="width: 100%; vertical-align: top;" colspan="2">
<table class="box-full">
<tr>
<td class="head" colspan="5">Volumes out of this Library</td>
</tr>
<tr>
<td class="spacer">&nbsp;</td>
</tr>
<tr>
<td>Volume</td>
<td>Usage</td>
<td>Status/Access</td>
<td>Utilisation</td>
<td>Reclaim</td>
<td>Last Read</td>
<td>Last Write</td>
<td>Location</td>
</tr>
<?php $i=0; foreach ($lo->volsnotinlib() as $vo) { ?>
<tr class="<?php echo $i++%2 ? 'odd' : 'even'; ?>">
<td class="data"><?php echo $vo; ?></td>
<td class="data"><?php echo $vo->STGPOOL_NAME; ?></td>
<td class="data"><?php printf('%s/%s',$vo->display('STATUS'),$vo->display('ACCESS')); ?></td>
<td class="data"><?php echo $vo->display('PCT_UTILIZED'); ?></td>
<td class="data"><?php echo $vo->display('PCT_RECLAIM'); ?></td>
<td class="data"><?php echo $vo->display('LAST_READ_DATE'); ?></td>
<td class="data"><?php echo $vo->display('LAST_WRITE_DATE'); ?></td>
<td class="data"><?php echo $vo->display('LOCATION'); ?></td>
</tr>
<?php } ?>
</table>