More work on library display

This commit is contained in:
Deon George
2011-06-27 14:37:11 +10:00
parent b2c250c319
commit c4ef5e2275
11 changed files with 136 additions and 666 deletions

View File

@@ -33,7 +33,7 @@ class Model_LIBRARY extends ORMTSM {
}
// Return a list of scratch volumes
public function scratch() {
public function scratchvol() {
$return = array();
foreach ($this->slots() as $slot)
@@ -44,7 +44,7 @@ class Model_LIBRARY extends ORMTSM {
}
// Return a list of volumes that are readonly
public function readonly() {
public function readonlyvol() {
$return = array();
foreach ($this->slots() as $slot)
@@ -60,7 +60,7 @@ class Model_LIBRARY extends ORMTSM {
}
// Return the slots that are used, but not checked in.
public function notcheckedin() {
public function notcheckedinvol() {
$return = array();
foreach ($this->slots() as $slot)
@@ -95,20 +95,22 @@ class Model_LIBRARY extends ORMTSM {
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) {
/**
* Return a list of volumes
*
* @param $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($ptype,$inout,$status) {
static $CACHE = array();
$ainout = array('in','out');
$astatus = array('FULL','FILLING','PENDING','EMPTY');
$ainout = array('IN','OUT');
if (! isset($CACHE[__METHOD__][$type]))
foreach ($this->storagepoolstype($type) as $spo)
if (! isset($CACHE[__METHOD__][$ptype]))
foreach ($this->storagepoolstype($ptype) as $spo)
foreach ($ainout as $cinout)
foreach ($astatus as $cstatus) {
foreach (Kohana::config('config.tsmvolstatus') as $cstatus) {
if (! isset($CACHE[__METHOD__][$spo->POOLTYPE][$cinout][$cstatus]))
$CACHE[__METHOD__][$spo->POOLTYPE][$cinout][$cstatus] = array();
@@ -116,7 +118,36 @@ class Model_LIBRARY extends ORMTSM {
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();
return isset($CACHE[__METHOD__][$ptype][$inout][$status]) ? $CACHE[__METHOD__][$ptype][$inout][$status] : array();
}
/**
* Return a list of DB volumes
*
* @param $inout IN|OUT of the library
* @note This is an intensive method that needs caching.
*/
public function dbvolsloc($inout) {
static $CACHE = array();
if (! isset($CACHE[__METHOD__]))
foreach (ORM::factory('volhistory')->where('TYPE','IN',Kohana::config('config.tsmdbtypes'))->find_all() as $vho)
$CACHE[__METHOD__][$vho->LIBVOLUME ? 'IN' : 'OUT'][] = $vho;
return isset($CACHE[__METHOD__][$inout]) ? $CACHE[__METHOD__][$inout] : array();
}
// Return a list of DB volumes by type
// @param $inout IN|OUT of the library
// @param $dtype is DB vole type (BACKUPFULL,BACKUPINCR,DBSNAPSHOT)
public function dbvolstype($inout,$dtype) {
$result = array();
foreach ($this->dbvolsloc($inout) as $vho)
if ($vho->TYPE ==$dtype)
array_push($result,$vho);
return $result;
}
public function volsnotinlib() {
@@ -130,5 +161,28 @@ class Model_LIBRARY extends ORMTSM {
Sort::masort($result,'VOLUME_NAME');
return $result;
}
// Volumes that are stale
public function stalevol() {
$result = array();
foreach ($this->storagepools() as $spo)
foreach ($spo->VOLUME->find_all() as $vo)
if ($vo->recycle())
array_push($result,$vo);
Sort::masort($result,'VOLUME_NAME');
return $result;
}
public function removablelibvol() {
$result = array();
foreach ($this->slots() as $slot)
if ($slot->LIBVOLUME->removable())
array_push($result,$slot->LIBVOLUME);
return $result;
}
}
?>

View File

@@ -79,5 +79,8 @@ class Model_LIBVOLUME extends ORMTSM {
}
}
public function removable() {
return ($this->usage() == 'dbbackup' OR ($this->usage() != 'scratch' AND $this->VOLUME->STGPOOL->POOLTYPE != 'PRIMARY')) ? TRUE : FALSE;
}
}
?>

View File

@@ -17,6 +17,7 @@ class Model_VOLHISTORY extends ORMTSM {
);
protected $_has_one = array(
'LIBVOLUME'=>array('foreign_key'=>'VOLUME_NAME','far_key'=>'VOLUME_NAME'),
'VOLUME'=>array('foreign_key'=>'VOLUME_NAME','far_key'=>'VOLUME_NAME'),
);
protected $_has_many = array(

View File

@@ -19,6 +19,7 @@ class Model_VOLUME extends ORMTSM {
protected $_has_one = array(
'MEDIA'=>array('foreign_key'=>'VOLUME_NAME','far_key'=>'VOLUME_NAME'),
'STGPOOL'=>array('foreign_key'=>'STGPOOL_NAME','far_key'=>'STGPOOL_NAME'),
);
protected $_has_many = array(
'VOLUMEUSAGE'=>array('foreign_key'=>'VOLUME_NAME','far_key'=>'VOLUME_NAME'),
@@ -52,5 +53,17 @@ class Model_VOLUME extends ORMTSM {
public function location() {
return $this->display('LOCATION');
}
// Age of a volume, based on last read/write access.
public function age() {
if (! $this->LAST_READ_DATE AND ! $this->LAST_WRITE_DATE)
return 0;
else
return (int)((time()-(strtotime(strtotime($this->LAST_READ_DATE) > strtotime($this->LAST_WRITE_DATE) ? $this->LAST_WRITE_DATE : $this->LAST_READ_DATE)))/86400);
}
public function recycle() {
return Kohana::config('config.tsmtapeage') < $this->age() ? TRUE : FALSE;
}
}
?>