Some more performance improvements and caching
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
* @copyright (c) 2010 phpTSMadmin Development Team
|
||||
* @license http://phptsmadmin.sf.net/license.html
|
||||
*/
|
||||
class Model_FILESPACE extends TSM_ORM {
|
||||
class Model_FILESPACE extends ORM_TSM {
|
||||
protected $_table_name = 'FILESPACES';
|
||||
protected $_primary_key = 'FILESPACE_NAME'; // We need a primary key to detect that the object is loaded.
|
||||
protected $_sorting = array(
|
||||
@@ -41,45 +41,176 @@ class Model_FILESPACE extends TSM_ORM {
|
||||
|
||||
protected $_display_filters = array(
|
||||
'BACKUP_END'=>array(
|
||||
array('TSM_ORM::date',array(':value','d-M-Y')),
|
||||
array('ORM_TSM::date',array(':value','d-M-Y')),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Get all the OCCUPANCY for this FILESYSTEM on this NODE
|
||||
*/
|
||||
private function _occupancy() {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s-%s',__METHOD__,$this->NODE_NAME,$this->FILESPACE_NAME);
|
||||
$c = Kohana::$config->load('config')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->NODE->occupancy() as $oo)
|
||||
if ($oo->FILESPACE_NAME == $this->FILESPACE_NAME)
|
||||
array_push($result,$oo);
|
||||
|
||||
// @todo Cache time should be configurble
|
||||
Cache::instance($c)->set($k,$result,300);
|
||||
}
|
||||
|
||||
Log::instance()->add(LOG::DEBUG,'EXIT :method',array(':method'=>__METHOD__));
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the VOLUEMUSAGE for this FILESYSTEM on this NODE
|
||||
*/
|
||||
private function _volumeusage() {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s-%s',__METHOD__,$this->NODE_NAME,$this->FILESPACE_NAME);
|
||||
$c = Kohana::$config->load('config')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->NODE->volumeusage() as $vuo)
|
||||
if ($vuo->FILESPACE_NAME == $this->FILESPACE_NAME)
|
||||
array_push($result,$vuo);
|
||||
|
||||
// @todo Cache time should be configurble
|
||||
Cache::instance($c)->set($k,$result,300);
|
||||
}
|
||||
|
||||
Log::instance()->add(LOG::DEBUG,'EXIT :method',array(':method'=>__METHOD__));
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the data that this FILESYSTEM 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) {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s-%s-%s-%s',__METHOD__,$this->NODE_NAME,$this->FILESPACE_NAME,$pool,$metric);
|
||||
$c = Kohana::$config->load('config')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = 0;
|
||||
|
||||
foreach ($this->_occupancy() as $oo)
|
||||
if ($oo->STGPOOL_NAME == $pool)
|
||||
$result += $oo->{$metric};
|
||||
|
||||
// @todo Cache time should be configurble
|
||||
Cache::instance($c)->set($k,$result,300);
|
||||
}
|
||||
|
||||
Log::instance()->add(LOG::DEBUG,'EXIT :method',array(':method'=>__METHOD__));
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the data that this FILESYSTEM has in a STORAGE POOL
|
||||
* @param $pool is STORAGE POOL NAME
|
||||
* @param $metric is metric of the storpage pool, eg: NUM_FILES
|
||||
* @param $type is Bkup/Arch/SpMg
|
||||
*/
|
||||
private function data_bypoolbybtype($pool,$metric,$type) {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s-%s-%s-%s-%s',__METHOD__,$this->NODE_NAME,$this->FILESPACE_NAME,$pool,$metric,$type);
|
||||
$c = Kohana::$config->load('config')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = 0;
|
||||
|
||||
foreach ($this->_occupancy() as $oo)
|
||||
if ($oo->STGPOOL_NAME == $pool AND $oo->TYPE == $type)
|
||||
$result += $oo->{$metric};
|
||||
|
||||
// @todo Cache time should be configurble
|
||||
Cache::instance($c)->set($k,$result,300);
|
||||
}
|
||||
|
||||
Log::instance()->add(LOG::DEBUG,'EXIT :method',array(':method'=>__METHOD__));
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the LOGICAL_MB that this FILESYSTEM has in a STORAGE POOL
|
||||
* @param $pool is STORAGE POOL NAME
|
||||
*/
|
||||
public function logmb_bypool($pool) {
|
||||
Log::instance()->add(LOG::DEBUG,'FLYBY :method',array(':method'=>__METHOD__));
|
||||
return $this->data_bypool($pool,'LOGICAL_MB');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the LOGICAL_MB that this FILESYSTEM has in a STORAGE POOL
|
||||
* @param $pool is STORAGE POOL NAME
|
||||
* @param $type is Bkup/Arch/SpMg
|
||||
*/
|
||||
public function logmb_bypoolbybtype($pool,$type) {
|
||||
Log::instance()->add(LOG::DEBUG,'FLYBY :method',array(':method'=>__METHOD__));
|
||||
return $this->data_bypoolbybtype($pool,'LOGICAL_MB',$type);
|
||||
}
|
||||
|
||||
public function utilsation() {
|
||||
return $this->CAPACITY*($this->PCT_UTIL/100);
|
||||
}
|
||||
|
||||
// $dtype must be Bkup or Arch
|
||||
public function storagepools($dtype) {
|
||||
$pool = array();
|
||||
|
||||
foreach ($this->NODE->OCC
|
||||
->select('STGPOOL_NAME')
|
||||
->where('TYPE','=',$dtype)
|
||||
->and_where('FILESPACE_NAME','=',$this->FILESPACE_NAME)
|
||||
->group_by('STGPOOL_NAME')
|
||||
->order_by('STGPOOL_NAME')
|
||||
->find_all() as $oo)
|
||||
|
||||
array_push($pool,$oo->STGPOOL);
|
||||
|
||||
return $pool;
|
||||
}
|
||||
|
||||
public function pool_logical_util($pool,$btype) {
|
||||
return $this->NODE->OCC
|
||||
->where('STGPOOL_NAME','=',$pool)
|
||||
->and_where('TYPE','=',$btype)
|
||||
->and_where('FILESPACE_NAME','=',$this->FILESPACE_NAME)
|
||||
->find()->LOGICAL_MB;
|
||||
/**
|
||||
* Return the VOLUMES that this FILESYSTEM uses for this NODE
|
||||
* @param $pool is STORAGE POOL NAME
|
||||
*/
|
||||
public function vols_bypool($pool) {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s-%s-%s',__METHOD__,$this->NODE_NAME,$this->FILESPACE_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);
|
||||
}
|
||||
|
||||
// @todo Cache time should be configurble
|
||||
Cache::instance($c)->set($k,$result,300);
|
||||
}
|
||||
|
||||
Log::instance()->add(LOG::DEBUG,'EXIT :method',array(':method'=>__METHOD__));
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function pool_numvols($pool,$ctype) {
|
||||
return $this->NODE->VOLUMEUSAGE
|
||||
->where('STGPOOL_NAME','=',$pool)
|
||||
->and_where('COPY_TYPE','=',$ctype)
|
||||
->and_where('FILESPACE_NAME','=',$this->FILESPACE_NAME)
|
||||
->find_all()->count();
|
||||
/**
|
||||
* Return the VOLUMES that this FILESYSTEM uses for this NODE 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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user