Work on performance improvements with caching

This commit is contained in:
Deon George
2012-12-04 11:52:10 +11:00
parent eafb80f7fc
commit 1bf8a520e2
30 changed files with 877 additions and 495 deletions

View File

@@ -32,80 +32,238 @@ class Model_DOMAIN extends TSM_ORM {
),
);
// Pools used by a domain.
private $pools = array();
// Work out all the storage pools used by a domain.
// $dtype is BACKUP (Bkup) or ARCHIVE (Arch)
public function getStoragePools($dtype) {
return isset($this->pools[$dtype]) ? $this->pools[$dtype] : $this->_getpools($dtype);
}
private function _getpools($dtype) {
$this->pools[$dtype] = array();
foreach ($this->NODE->find_all() as $no)
foreach ($no->getStoragePools($dtype) as $ptype => $stgpools)
foreach ($stgpools as $spo)
if (! isset($this->pools[$dtype][$ptype]) OR ! in_array($spo,$this->pools[$dtype][$ptype]))
$this->pools[$dtype][$ptype][] = $spo;
return $this->pools[$dtype];
}
// Return the storage pools used for a domain by backup type
// $dtype is BACKUP (Bkup) or ARCHIVE (Arch)
// $ptype is pool type (PRIMARY,ACTIVE,COPY)
public function getStoragePoolsType($dtype,$ptype) {
if (! isset($this->pools[$dtype]))
$this->_getpools($dtype);
return isset($this->pools[$dtype][$ptype]) ? $this->pools[$dtype][$ptype] : array();
}
// $dtype is BACKUP or ARCHIVE
// $ptype is pool type (PRIMARY,ACTIVE,COPY)
public function getStorageModeVols($dtype,$ptype,$spo='') {
/**
* Get all the NODES in this DOMAIN
*/
private function _nodes() {
$result = array();
foreach ($this->NODE->find_all() as $no)
$result = array_merge($result,$no->getStorageModeVols($dtype,$ptype,$spo));
// In the interest of performance, we load all the records and get PHP to process it.
// Our ORM caching we reduce the hit on TSM.
foreach (ORM::factory('NODE')->find_all() as $o)
if ($o->DOMAIN_NAME == $this->DOMAIN_NAME)
array_push($result,$o);
return $result;
}
// $dtype is BACKUP (Bkup) or ARCHIVE (Arch)
// $ptype is pool type (PRIMARY,ACTIVE,COPY)
public function getStorageModeFiles($dtype,$ptype,$spo='') {
$count = 0;
foreach ($this->NODE->find_all() as $no)
$count += $no->getStorageModeFiles($dtype,$ptype,$spo);
return $count;
public function nodes() {
return $this->_nodes();
}
// $dtype is BACKUP or ARCHIVE
// $ptype is pool type (PRIMARY,ACTIVE,COPY)
public function getStorageModeData($dtype,$ptype,$spo='') {
$count = 0;
/**
* Return the FILES that NODES in this DOMAIN has in a STORAGE POOL
* @param $pool is STORAGE POOL NAME
*/
public function file_bypool($pool) {
$k = sprintf('%s-%s-%s',__METHOD__,$this->DOMAIN_NAME,$pool);
$c = Kohana::$config->load('config')->cache;
foreach ($this->NODE->find_all() as $no)
$count += $no->getStorageModeData($dtype,$ptype,$spo);
if (is_null($result = Cache::instance($c)->get($k))) {
$result = 0;
return $count;
foreach ($this->_nodes() as $no)
$result += $no->file_bypool($pool);
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
// $dtype is BACKUP or ARCHIVE
// $ptype is pool type (PRIMARY,ACTIVE,COPY)
public function getStorageModeNodes($dtype,$ptype,$spo='') {
/**
* Return the LOGICAL_MB that NODES in this DOMAIN has in a STORAGE POOL
* @param $pool is STORAGE POOL NAME
*/
public function logmb_bypool($pool) {
$k = sprintf('%s-%s-%s',__METHOD__,$this->DOMAIN_NAME,$pool);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$result = 0;
foreach ($this->_nodes() as $no)
$result += $no->logmb_bypool($pool);
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the NODES in this DOMAIN that have data in this STORAGE POOL
* @param $pool is STORAGE POOL NAME
*/
public function nodes_bypool(ORM $spo) {
$result = array();
foreach ($this->NODE->find_all() as $no)
if ($no->getStorageModeData($dtype,$ptype,$spo))
foreach ($spo->nodes() as $no)
if (in_array($no,$this->_nodes()))
array_push($result,$no);
return $result;
}
/**
* Return the STORAGE POOLS used by NODES in this DOMAIN
*/
public function stgpools() {
$k = sprintf('%s-%s',__METHOD__,$this->DOMAIN_NAME);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$result = array();
foreach ($this->nodes() as $no)
foreach ($no->stgpools() as $spo)
if (! in_array($spo,$result))
array_push($result,$spo);
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the STORAGE POOL TYPES used by NODES in this DOMAIN
* ie: ACTIVE/PRIMARY/COPY
* @todo This should be sorted by PRIMARY/ACTIVE/COPY
*/
public function stgpooltypes() {
$k = sprintf('%s-%s',__METHOD__,$this->DOMAIN_NAME);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$result = array();
foreach ($this->stgpools() as $spo)
if (! in_array($spo->POOLTYPE,$result))
array_push($result,$spo->POOLTYPE);
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the STORAGE POOLS that NODES in this DOMAIN uses by BACKUP TYPE
* @param $type is BACKUP/ARCHIVE/SPACE MANAGED
*/
public function stgpools_bybtype($type) {
$k = sprintf('%s-%s-%s',__METHOD__,$this->DOMAIN_NAME,$type);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$x = $result = array();
foreach ($this->_nodes() as $no)
foreach ($no->stgpools_bybtype($type) as $spo)
if (! in_array($spo->STGPOOL_NAME,$result))
array_push($result,$spo);
Sort::MASort($result,'STGPOOL_NAME');
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the STORAGE POOLS that NODES in this DOMAIN uses by BACKUP TYPE
* @param $type is ACTIVEDATA/PRIMARY/COPY
*/
public function stgpools_byptype($type) {
$k = sprintf('%s-%s-%s',__METHOD__,$this->DOMAIN_NAME,$type);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$result = array();
foreach ($this->stgpools() as $spo)
if ($spo->POOLTYPE == $type)
array_push($result,$spo);
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the VOLUMES that NODES in this DOMAIN use
* @param $pool is STORAGE POOL NAME
*/
public function vols_bypool($pool) {
$k = sprintf('%s-%s-%s',__METHOD__,$this->DOMAIN_NAME,$pool);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$x = $result = array();
foreach ($this->_nodes() as $no)
foreach ($no->vols_bypool($pool) as $vuo)
if (! in_array($vuo->VOLUME_NAME,$x)) {
array_push($result,$vuo);
array_push($x,$vuo->VOLUME_NAME);
}
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the VOLUMES that NODES in this DOMAIN uses by BACKUP TYPE
* @param $type is BACKUP/ARCHIVE/SPACE MANAGED
*/
public function vols_bybtype($type) {
$k = sprintf('%s-%s-%s',__METHOD__,$this->DOMAIN_NAME,$type);
$c = Kohana::$config->load('config')->cache;
if (TRUE OR is_null($result = Cache::instance($c)->get($k))) {
$x = $result = array();
foreach ($this->_nodes() as $no)
foreach ($no->vols_bybtype($type) as $vuo)
if (! in_array($vuo->VOLUME_NAME,$x)) {
array_push($result,$vuo);
array_push($x,$vuo->VOLUME_NAME);
}
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the VOLUMES that this NODE uses by pool and BACKUP TYPE
* @param $pool is STORAGE POOL NAME
* @param $type is BACKUP/ARCHIVE/SPACE MANAGED
*/
public function vols_bypoolbybtype($pool,$type) {
$x = $result = array();
foreach ($this->vols_bypool($pool) as $vuo)
if ($vuo->COPY_TYPE == $type AND ! in_array($vuo->VOLUME_NAME,$x)) {
array_push($result,$vuo);
array_push($x,$vuo->VOLUME_NAME);
}
return $result;
}
}
?>

View File

@@ -16,8 +16,6 @@ class Model_DRIVE extends TSM_ORM {
'DRIVE_NAME'=>'ASC',
);
protected $_has_one = array(
);
protected $_has_many = array(
'PATH'=>array('foreign_key'=>array('LIBRARY_NAME'=>'LIBRARY_NAME','DRIVE_NAME'=>'DESTINATION_NAME')),
);

View File

@@ -21,9 +21,6 @@ class Model_FILESPACE extends TSM_ORM {
'NODE'=>array('foreign_key'=>'NODE_NAME','far_key'=>'NODE_NAME'),
);
protected $_has_many = array(
);
protected $_tsm = array(
'db2'=>array(
'_primary_key'=>'FSNAME',

View File

@@ -20,14 +20,13 @@ class Model_LIBRARY extends TSM_ORM {
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'),
);
#zz
public function slots() {
return $this->slots ? $this->slots : $this->slots = DB::query(Database::SHOW,'SHOW SLOTS '.$this)->execute(Kohana::$config->load('config')->client_type);
}

View File

@@ -16,11 +16,6 @@ class Model_MEDIA extends TSM_ORM {
'VOLUME_NAME'=>'ASC',
);
protected $_has_one = array(
);
protected $_has_many = array(
);
public function inlib() {
return in_array($this->STATE,array('MOUNTABLEINLIB','Mountable in library'));
}

View File

@@ -114,16 +114,68 @@ class Model_NODE extends TSM_ORM {
),
);
// Pools used by a node.
private $pools = array();
/**
* Get all the FILESPACES for this NODE
*/
private function _filespaces() {
$result = array();
public function tsmclientversion() {
// In the interest of performance, we load all the records and get PHP to process it.
// Our ORM caching we reduce the hit on TSM.
foreach (ORM::factory('FILESPACE')->find_all() as $o)
if ($o->NODE_NAME == $this->NODE_NAME)
array_push($result,$o);
return $result;
}
/**
* Get all the OCCUPANCY for this NODE
*/
private function _occupancy() {
$result = array();
// In the interest of performance, we load all the records and get PHP to process it.
// Our ORM caching we reduce the hit on TSM.
foreach (ORM::factory('OCC')->find_all() as $o)
if ($o->NODE_NAME == $this->NODE_NAME)
array_push($result,$o);
return $result;
}
/**
* Get all the VOLUMES for this NODE
*/
private function _volumeusage() {
$result = array();
// In the interest of performance, we load all the records and get PHP to process it.
// Our ORM caching we reduce the hit on TSM.
foreach (ORM::factory('VOLUMEUSAGE')->find_all() as $o)
if ($o->NODE_NAME == $this->NODE_NAME)
array_push($result,$o);
return $result;
}
public function fs() {
return $this->_filespaces();
}
/**
* Return the version of the TSM client
*/
public function version() {
if ($this->CLIENT_VERSION)
return sprintf('%s.%s.%s.%s',$this->CLIENT_VERSION,$this->CLIENT_RELEASE,$this->CLIENT_LEVEL,$this->CLIENT_SUBLEVEL);
else
return '';
}
/**
* Return the OS version for the TSM client
*/
public function platform() {
return sprintf('%s %s',$this->PLATFORM_NAME,$this->CLIENT_OS_LEVEL ? '('.$this->CLIENT_OS_LEVEL.')' : '');
}
@@ -136,10 +188,13 @@ class Model_NODE extends TSM_ORM {
return _('No Set');
}
// @todo This needs to be validated as a correct calculation
public function lasttransferpercent() {
return 100-($this->LASTSESS_IDLEWAIT+$this->LASTSESS_COMMWAIT+$this->LASTSESS_MEDIAWAIT);
$x = 100-($this->LASTSESS_IDLEWAIT+$this->LASTSESS_COMMWAIT+$this->LASTSESS_MEDIAWAIT);
return $x < 0 ? 0 : $x;
}
// @todo This needs to be validated as a correct calculation
public function lasttransfertime() {
if ($this->LASTSESS_DURATION)
return $this->LASTSESS_DURATION*($this->lasttransferpercent()/100);
@@ -147,6 +202,7 @@ class Model_NODE extends TSM_ORM {
return 0;
}
// @todo This needs to be validated as a correct calculation
public function lastsendperformance() {
if ($this->lasttransfertime())
return $this->LASTSESS_SENT/$this->lasttransfertime()/1024/1024;
@@ -154,6 +210,7 @@ class Model_NODE extends TSM_ORM {
return 0;
}
// @todo This needs to be validated as a correct calculation
public function lastreceiveperformance() {
if ($this->lasttransfertime())
return $this->LASTSESS_RECVD/$this->lasttransfertime()/1024/1024;
@@ -161,6 +218,9 @@ class Model_NODE extends TSM_ORM {
return 0;
}
/**
* The last sent aggregate performance
*/
public function lastsendaggperformance() {
if ((real)$this->LASTSESS_DURATION)
return $this->LASTSESS_SENT/$this->LASTSESS_DURATION/1024/1024;
@@ -168,6 +228,9 @@ class Model_NODE extends TSM_ORM {
return 0;
}
/**
* The last receive aggregate performance
*/
public function lastreceiveaggperformance() {
if ((real)$this->LASTSESS_DURATION)
return $this->LASTSESS_RECVD/$this->LASTSESS_DURATION/1024/1024;
@@ -180,56 +243,20 @@ class Model_NODE extends TSM_ORM {
return $this->TXNGROUPMAX;
}
// Work out all the storage pools used by a node.
// $dtype is BACKUP (Bkup) or ARCHIVE (Arch)
public function getStoragePools($dtype) {
return isset($this->pools[$dtype]) ? $this->pools[$dtype] : $this->_getpools($dtype);
}
// $dtype is BACKUP (Bkup) or ARCHIVE (Arch)
private function _getpools($dtype) {
$this->pools[$dtype] = array();
foreach ($this->FILESPACE->find_all() as $fso)
foreach ($fso->storagepools($dtype) as $po)
if (! isset($this->pools[$dtype][$po->POOLTYPE][$po->STGPOOL_NAME]))
$this->pools[$dtype][$po->POOLTYPE][$po->STGPOOL_NAME] = $po;
return $this->pools[$dtype];
}
// Test to see if a node has any data of type
// $dtype is BACKUP (Bkup) or ARCHIVE (Arch)
public function hasData($dtype) {
return $this->getStoragePools($dtype) ? TRUE : FALSE;
}
public function getAllStoragePoolsType($ptype) {
$result = array();
foreach (Kohana::$config->load('config')->tsmdatatypes as $btype => $ctype)
$result = array_merge($result,$this->getStoragePoolsType($btype,$ptype));
return $result;
}
// Return the storage pools used for a backup type
// $dtype is BACKUP (Bkup) or ARCHIVE (Arch)
// $ptype is pool type (PRIMARY,ACTIVE,COPY)
public function getStoragePoolsType($dtype,$ptype) {
if (! isset($this->pools[$dtype]))
$this->_getpools($dtype);
return isset($this->pools[$dtype][$ptype]) ? $this->pools[$dtype][$ptype] : array();
// @param $type is BACKUP/ARCHIVE/SPACE MANAGED
public function hasData($type) {
return $this->vols_bybtype($type) ? TRUE : FALSE;
}
// $dtype is BACKUP or ARCHIVE
// $ptype is pool type (PRIMARY,ACTIVE,COPY)
#zz
public function getStorageModeVols($dtype,$ptype,$spo='') {
$result = array();
foreach ($this->VOLUMEUSAGE->where('COPY_TYPE','=',$dtype)->find_all() as $vo)
if ((! $spo OR $vo->STGPOOL_NAME == $spo) AND $vo->STGPOOL->POOLTYPE == $ptype)
foreach ($this->_volumeusage() as $vo)
if ($vo->COPY_TYPE == $dtype AND (! $spo OR $vo->STGPOOL_NAME == $spo) AND $vo->STGPOOL->POOLTYPE == $ptype)
if (! isset($result[$vo->VOLUME_NAME]))
$result[$vo->VOLUME_NAME] = $vo;
@@ -237,6 +264,7 @@ class Model_NODE extends TSM_ORM {
}
// $ptype is pool type (PRIMARY,ACTIVE,COPY)
#zz
public function getStorageTypeVols($ptype,$spo='') {
$result = array();
@@ -246,74 +274,243 @@ class Model_NODE extends TSM_ORM {
return $result;
}
// $dtype is BACKUP (Bkup) or ARCHIVE (Arch)
// $ptype is pool type (PRIMARY,ACTIVE,COPY)
public function getStorageModeFiles($dtype,$ptype,$spo='') {
$count = 0;
/**
* Return the data that this NODE has in a STORAGE POOL
* @param $pool is STORAGE POOL NAME
* @param $metric is metric of the storpage pool, eg: NUM_FILES
*/
private function data_bypool($pool,$metric) {
$k = sprintf('%s-%s-%s-%s',__METHOD__,$this->NODE_NAME,$pool,$metric);
$c = Kohana::$config->load('config')->cache;
foreach ($this->OCC->where('TYPE','=',$dtype)->find_all() as $oa)
if ((! $spo OR $oa->STGPOOL_NAME == $spo) AND $oa->STGPOOL->POOLTYPE == $ptype)
$count += $oa->NUM_FILES;
if (is_null($result = Cache::instance($c)->get($k))) {
$result = 0;
return $count;
}
foreach ($this->_occupancy() as $oo)
if ($oo->STGPOOL_NAME == $pool)
$result += $oo->{$metric};
// $ptype is pool type (PRIMARY,ACTIVE,COPY)
public function getStorageTypeFiles($ptype,$spo='') {
$count = 0;
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
foreach (Kohana::$config->load('config')->tsmdatatypes as $btype => $ctype)
$count += $this->getStorageModeFiles($btype,$ptype,$spo);
return $count;
}
// $dtype is BACKUP (Bkup) or ARCHIVE (Arch)
// $ptype is pool type (PRIMARY,ACTIVE,COPY)
public function getStorageModeData($dtype,$ptype,$spo='') {
$count = 0;
foreach ($this->OCC->where('TYPE','=',$dtype)->find_all() as $oa)
if ((! $spo OR $oa->STGPOOL_NAME == $spo) AND $oa->STGPOOL->POOLTYPE == $ptype)
$count += $oa->LOGICAL_MB;
return $count;
}
// $ptype is pool type (PRIMARY,ACTIVE,COPY)
public function getStorageTypeData($ptype,$spo='') {
$count = 0;
foreach (Kohana::$config->load('config')->tsmdatatypes as $btype => $ctype)
$count += $this->getStorageModeData($btype,$ptype,$spo);
return $count;
}
// Return the volumes that this node uses
// $dtype is BACKUP or ARCHIVE
public function volumes($dtype) {
$volumes = array();
$v = array();
foreach ($this->VOLUMEUSAGE->where('COPY_TYPE','=',$dtype)->order_by('STGPOOL_NAME,FILESPACE_NAME')->find_all() as $vol)
if (! in_array($vol->VOLUME->VOLUME_NAME,$v)) {
$volumes[$vol->STGPOOL_NAME][] = $vol->VOLUME;
array_push($v,$vol->VOLUME->VOLUME_NAME);
}
return $volumes;
return $result;
}
/**
* Get all the nodes by OS
* Return the FILES that this NODE has in a STORAGE POOL
* @param $pool is STORAGE POOL NAME
*/
public function byos() {
$a = $this->select('count(*) AS node_name,platform_name')
->group_by('platform_name')
->order_by('platform_name');
public function file_bypool($pool) {
return $this->data_bypool($pool,'NUM_FILES');
}
return $a->find_all();
/**
* Return the FILES that this NODE has in a STORAGE POOL TYPE
* @param $type is ACTIVEDATA/PRIMARY/COPY
*/
public function file_byptype($type) {
$result = 0;
foreach ($this->stgpools_byptype($type) as $spo)
$result += $this->file_bypool($spo);
return $result;
}
/**
* Return the LOGICAL_MB that this NODE has in a STORAGE POOL
* @param $pool is STORAGE POOL NAME
*/
public function logmb_bypool($pool) {
return $this->data_bypool($pool,'LOGICAL_MB');
}
/**
* Return the FILES that this NODE has in a STORAGE POOL TYPE
* @param $type is ACTIVEDATA/PRIMARY/COPY
*/
public function logmb_byptype($type) {
$result = 0;
foreach ($this->stgpools_byptype($type) as $spo)
$result += $this->logmb_bypool($spo);
return $result;
}
/**
* Return the STORAGE POOLS this NODE has data in
*/
public function stgpools() {
$k = sprintf('%s-%s',__METHOD__,$this->NODE_NAME);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$x = $result = array();
foreach ($this->_volumeusage() as $vuo)
if (! in_array($vuo->STGPOOL_NAME,$x)) {
array_push($result,$vuo->STGPOOL);
array_push($x,$vuo->STGPOOL_NAME);
}
Sort::MASort($result,'STGPOOL_NAME');
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the STORAGE POOL TYPES used by this NODE
* ie: ACTIVE/PRIMARY/COPY
* @todo This should be sorted by PRIMARY/ACTIVE/COPY
*/
public function stgpooltypes() {
$k = sprintf('%s-%s',__METHOD__,$this->NODE_NAME);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$result = array();
foreach ($this->stgpools() as $spo)
if (! in_array($spo->POOLTYPE,$result))
array_push($result,$spo->POOLTYPE);
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the STORAGE POOLS that this NODE uses by BACKUP TYPE
* @param $type is BACKUP/ARCHIVE/SPACE MANAGED
*/
public function stgpools_bybtype($type) {
$k = sprintf('%s-%s-%s',__METHOD__,$this->NODE_NAME,$type);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$x = $result = array();
foreach ($this->_volumeusage() as $vuo)
if ($vuo->COPY_TYPE == $type AND ! in_array($vuo->STGPOOL_NAME,$x)) {
array_push($result,$vuo->STGPOOL);
array_push($x,$vuo->STGPOOL_NAME);
}
Sort::MASort($result,'STGPOOL_NAME');
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the STORAGE POOLS that this NODE uses by BACKUP TYPE
* @param $type is ACTIVEDATA/PRIMARY/COPY
*/
public function stgpools_byptype($type) {
$k = sprintf('%s-%s-%s',__METHOD__,$this->NODE_NAME,$type);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$result = array();
foreach ($this->stgpools() as $spo)
if ($spo->POOLTYPE == $type)
array_push($result,$spo);
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the VOLUMES that this NODE uses by BACKUP TYPE
* @param $type is BACKUP/ARCHIVE/SPACE MANAGED
*/
public function vols_bybtype($type) {
$k = sprintf('%s-%s-%s',__METHOD__,$this->NODE_NAME,$type);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$x = $result = array();
foreach ($this->_volumeusage() as $vuo)
if ($vuo->COPY_TYPE == $type AND ! in_array($vuo->VOLUME_NAME,$x)) {
array_push($result,$vuo->VOLUME);
array_push($x,$vuo->VOLUME_NAME);
}
Sort::MASort($result,'VOLUME_NAME');
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the VOLUMES that this NODE uses
* @param $pool is STORAGE POOL NAME
*/
public function vols_bypool($pool) {
$k = sprintf('%s-%s-%s',__METHOD__,$this->NODE_NAME,$pool);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$x = $result = array();
foreach ($this->_volumeusage() as $vuo) {
if ($vuo->STGPOOL_NAME == $pool AND ! in_array($vuo->VOLUME_NAME,$x))
array_push($result,$vuo);
array_push($x,$vuo->VOLUME_NAME);
}
Sort::MASort($result,'VOLUME_NAME');
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the VOLUMES that this NODE has in a STORAGE POOL TYPE
* @param $type is ACTIVEDATA/PRIMARY/COPY
*/
public function vols_byptype($type) {
$result = array();
foreach ($this->stgpools_byptype($type) as $spo)
$result = array_merge($result,$this->vols_bypool($spo));
return $result;
}
/**
* Return the VOLUMES that this NODE uses by pool and BACKUP TYPE
* @param $pool is STORAGE POOL NAME
* @param $type is BACKUP/ARCHIVE/SPACE MANAGED
*/
public function vols_bypoolbybtype($pool,$type) {
$x = $result = array();
foreach ($this->vols_bypool($pool) as $vuo)
if ($vuo->COPY_TYPE == $type AND ! in_array($vuo->VOLUME_NAME,$x)) {
array_push($result,$vuo);
array_push($x,$vuo->VOLUME_NAME);
}
return $result;
}
}
?>

View File

@@ -20,6 +20,7 @@ class Model_OCC extends TSM_ORM {
);
protected $_has_one = array(
'NODE'=>array('foreign_key'=>'NODE_NAME','far_key'=>'NODE_NAME'),
'STGPOOL'=>array('foreign_key'=>'STGPOOL_NAME','far_key'=>'STGPOOL_NAME'),
);
}

View File

@@ -15,10 +15,5 @@ class Model_PATH extends TSM_ORM {
protected $_sorting = array(
'DESTINATION_NAME'=>'ASC',
);
protected $_has_one = array(
);
protected $_has_many = array(
);
}
?>

View File

@@ -27,6 +27,43 @@ class Model_STGPOOL extends TSM_ORM {
'OCC'=>array('foreign_key'=>'STGPOOL_NAME','far_key'=>'STGPOOL_NAME'),
);
/**
* Get all the OCCUPANCY for this STORAGE POOL
*/
private function _occupancy() {
$result = array();
// In the interest of performance, we load all the records and get PHP to process it.
// Our ORM caching we reduce the hit on TSM.
foreach (ORM::factory('OCC')->find_all() as $o)
if ($o->STGPOOL_NAME == $this->STGPOOL_NAME)
array_push($result,$o);
return $result;
}
/**
* Get all the NODES for this STORAGE POOL
*/
public function nodes() {
$k = sprintf('%s-%s',__METHOD__,$this->STGPOOL_NAME);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$result = array();
// @todo This might want to return the NODE object.
foreach ($this->_occupancy() as $oo)
if (! in_array($oo->NODE_NAME,$result))
array_push($result,$oo->NODE_NAME);
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
// Return a list of volumes
// @param $inout IN|OUT of the library
// @param $status volume status FULL|FILLING|PENDING|EMPTY

View File

@@ -20,8 +20,6 @@ class Model_VOLHISTORY extends TSM_ORM {
'LIBVOLUME'=>array('foreign_key'=>'VOLUME_NAME','far_key'=>'VOLUME_NAME'),
'VOLUME'=>array('foreign_key'=>'VOLUME_NAME','far_key'=>'VOLUME_NAME'),
);
protected $_has_many = array(
);
protected $_display_filters = array(
'DATE_TIME'=>array(

View File

@@ -34,26 +34,72 @@ class Model_VOLUME extends TSM_ORM {
),
);
// Show the number of filespaces on a volume
// $dtype is BACKUP or ARCHIVE
public function getFSOnVol($dtype) {
return $this->VOLUMEUSAGE->where('COPY_TYPE','=',$dtype)->find_all()->count();
/**
* Get all the VOLUMEUSAGE for this VOLUME
*/
private function _volumeusage() {
$result = array();
// In the interest of performance, we load all the records and get PHP to process it.
// Our ORM caching we reduce the hit on TSM.
foreach (ORM::factory('VOLUMEUSAGE')->find_all() as $o)
if ($o->VOLUME_NAME == $this->VOLUME_NAME)
array_push($result,$o);
return $result;
}
// Show the number of nodes on a volume
// $dtype is BACKUP or ARCHIVE
public function getNodesOnVol($dtype) {
return $this->VOLUMEUSAGE->select('NODE_NAME')->distinct(TRUE)->where('COPY_TYPE','=',$dtype)->find_all()->count();
/**
* Get FILESYSTEMS on a VOLUME
* @param $type is BACKUP/ARCHIVE/SPACE MANAGED
*/
public function fs_bybtype($type) {
$k = sprintf('%s-%s-%s',__METHOD__,$this->VOLUME_NAME,$type);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$result = array();
foreach ($this->_volumeusage() as $vuo)
if ($vuo->COPY_TYPE == $type)
array_push($result,$vuo);
Sort::MASort($result,'VOLUME_NAME');
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Get NODES on a VOLUME
* @param $type is BACKUP/ARCHIVE/SPACE MANAGED
*/
public function nodes_bybtype($type) {
$k = sprintf('%s-%s-%s',__METHOD__,$this->VOLUME_NAME,$type);
$c = Kohana::$config->load('config')->cache;
if (TRUE OR is_null($result = Cache::instance($c)->get($k))) {
$x = $result = array();
foreach ($this->_volumeusage() as $vuo)
if ($vuo->COPY_TYPE == $type AND ! in_array($vuo->NODE_NAME,$x)) {
array_push($result,$vuo);
array_push($x,$vuo->NODE_NAME);
}
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
public function isScratch() {
return $this->SCRATCH === 'YES' ? TRUE : FALSE;
}
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) OR $this->STATUS == 'EMPTY')

View File

@@ -14,8 +14,6 @@ class Model_VOLUMEUSAGE extends TSM_ORM {
protected $_primary_key = 'NODE_NAME'; // We need a primary key to detect that the object is loaded.
protected $_sorting = array(
'NODE_NAME'=>'ASC',
# 'FILESPACE_NAME'=>'ASC', // @todo Disabled, as we were getting some SQL errors, when the query returned no records
# 'VOLUME_NAME'=>'ASC',
);
protected $_has_one = array(