This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
phptsmadmin/application/classes/Model/FILESPACE.php

260 lines
7.4 KiB
PHP
Raw Normal View History

2011-04-07 05:03:05 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
*
* @package PTA
* @subpackage File Spaces
* @category Models
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
class Model_FILESPACE extends ORM_TSM {
2011-04-07 05:03:05 +00:00
protected $_table_name = 'FILESPACES';
protected $_primary_key = 'FILESPACE_NAME'; // We need a primary key to detect that the object is loaded.
protected $_sorting = array(
'NODE_NAME'=>'ASC',
'FILESPACE_NAME'=>'ASC',
);
2011-08-31 21:36:33 +00:00
protected $_has_one = array(
'NODE'=>array('foreign_key'=>'NODE_NAME','far_key'=>'NODE_NAME'),
);
protected $_tsm = array(
'db2'=>array(
'_primary_key'=>'FSNAME',
'_sorting'=>array(
'NODEID'=>'ASC',
'FSNAME'=>'ASC',
),
'_has_one'=>array(
'NODE'=>array('foreign_key'=>'NODEID','far_key'=>'NODEID'),
),
'translate'=>array(
'FILESPACE_NAME'=>'FSNAME',
'BACKUP_END'=>'BACKSTART',
'PCT_UTIL'=>NULL,
),
),
2011-04-07 05:03:05 +00:00
);
protected $_display_filters = array(
'BACKUP_END'=>array(
array('ORM_TSM::date',array(':value','d-M-Y')),
),
2011-04-07 05:03:05 +00:00
);
/**
* 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;
}
/**
2012-12-13 04:46:25 +00:00
* Return the physical space that has been given to TSM to store
*/
public function data_physical() {
$result = 0;
foreach ($this->_occupancy() as $oo) {
// Quick Sanity Check
if ((int)$oo->PHYSICAL_MB == 0 AND $oo->LOGICAL_MB > $oo->REPORTING_MB)
SystemMessage::add(array(
'title'=>_('TSM Data Integrity ?'),
'body'=>sprintf('While [%s] PHYSICAL_MB is (%s), LOGICAL_MB (%s) > REPORTING_MB(%s) [%s]?',$oo->FILESPACE_NAME,$oo->PHYSICAL_MB,$oo->LOGICAL_MB,$oo->REPORTING_MB,$oo->STGPOOL_NAME),
'type'=>'error',
));
elseif ((int)$oo->PHYSICAL_MB > 0 AND $oo->LOGICAL_MB > $oo->PHYSICAL_MB)
SystemMessage::add(array(
'title'=>_('TSM Data Integrity ?'),
'body'=>sprintf('While [%s] PHYSICAL_MB is (%s), LOGICAL_MB (%s) is greater [%s]?',$oo->FILESPACE_NAME,$oo->PHYSICAL_MB,$oo->LOGICAL_MB,$oo->STGPOOL_NAME),
'type'=>'error',
));
if ((int)$oo->PHYSICAL_MB > 0)
$result += $oo->PHYSICAL_MB;
else
$result += $oo->REPORTING_MB;
}
return $result;
}
/**
* Return the space that TSM is using to store this data
*/
public function data_logical() {
$result = 0;
foreach ($this->_occupancy() as $oo)
$result += $oo->LOGICAL_MB;
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);
}
2011-04-07 05:03:05 +00:00
public function utilsation() {
2011-08-31 21:36:33 +00:00
return $this->CAPACITY*($this->PCT_UTIL/100);
}
2011-04-07 05:03:05 +00:00
/**
* 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__));
2011-04-07 05:03:05 +00:00
$k = sprintf('%s-%s-%s-%s',__METHOD__,$this->NODE_NAME,$this->FILESPACE_NAME,$pool);
$c = Kohana::$config->load('config')->cache;
2011-04-07 05:03:05 +00:00
if (is_null($result = Cache::instance($c)->get($k))) {
$x = $result = array();
2011-04-07 05:03:05 +00:00
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);
}
2011-04-07 05:03:05 +00:00
Log::instance()->add(LOG::DEBUG,'EXIT :method',array(':method'=>__METHOD__));
return $result;
2011-04-07 05:03:05 +00:00
}
/**
* 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
*/
2012-12-06 05:19:30 +00:00
public function vols_bypoolbyctype($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;
2011-04-07 05:03:05 +00:00
}
}
?>