Initial commit
This commit is contained in:
62
modules/tsm/classes/lnApp/Database/Result.php
Normal file
62
modules/tsm/classes/lnApp/Database/Result.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* TSM database show result. See [Results](/database/results) for usage and examples.
|
||||
*
|
||||
* @package TSM Database Module
|
||||
* @category Database
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010-2014 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class lnApp_Database_Result extends Kohana_Database_Result {
|
||||
protected $_internal_row = 0;
|
||||
protected $_rows;
|
||||
|
||||
// Required Abstract Classes
|
||||
public function __destruct() {}
|
||||
|
||||
public function seek($offset) {
|
||||
if ($this->offsetExists($offset)) {
|
||||
// Set the current row to the offset
|
||||
$this->_current_row = $this->_internal_row = $offset;
|
||||
|
||||
return TRUE;
|
||||
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
public function current() {
|
||||
if ($this->_current_row !== $this->_internal_row AND ! $this->seek($this->_current_row))
|
||||
return FALSE;
|
||||
|
||||
// Return an stdClass
|
||||
if ($this->_as_object === TRUE) {
|
||||
return $this;
|
||||
|
||||
} elseif (is_string($this->_as_object)) {
|
||||
// Return an object of given class name
|
||||
$o = new $this->_as_object;
|
||||
|
||||
return $o->load_object($this->_rows[$this->_current_row]);
|
||||
|
||||
// Return an array of the row
|
||||
} else {
|
||||
return $this->_rows[$this->_current_row];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a row value from the query
|
||||
*
|
||||
* TSM returns all columns in upper case
|
||||
*/
|
||||
public function get($name, $default = NULL) {
|
||||
$name = strtoupper($name);
|
||||
|
||||
return parent::get($name,$default);
|
||||
}
|
||||
}
|
||||
?>
|
113
modules/tsm/classes/lnApp/Database/TSM.php
Normal file
113
modules/tsm/classes/lnApp/Database/TSM.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* TSM database connection.
|
||||
*
|
||||
* @package TSM Database Module
|
||||
* @category Drivers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010-2014 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class lnApp_Database_TSM extends Database {
|
||||
// Database in use by each connection
|
||||
protected static $_current_databases = array();
|
||||
|
||||
// Use SET NAMES to set the character set
|
||||
protected static $_set_names;
|
||||
|
||||
// Identifier for this connection within the PHP driver
|
||||
protected $_connection_id;
|
||||
|
||||
// TSM does not use a backtick for identifiers
|
||||
protected $_identifier = '';
|
||||
|
||||
// Our TSM Message Format
|
||||
protected $msg_format = '[A-Z]{3}[0-9]{4}[I|E|W|S]';
|
||||
|
||||
// Our Message Codes stored in the last query
|
||||
protected $_query_msg_codes = array();
|
||||
|
||||
// Our return code error messages we can ignore
|
||||
protected $ignore_codes = array(
|
||||
'ANS8001I', // Return code %s.
|
||||
);
|
||||
// Our return code error messages we can ignore
|
||||
protected $nodata_codes = array(
|
||||
'ANR2034E', // SELECT: No match found using this criteria.
|
||||
);
|
||||
|
||||
protected $execute_stdout = '';
|
||||
protected $execute_stderr = '';
|
||||
protected $execute_rc = NULL;
|
||||
|
||||
// Our required abstract methods
|
||||
public function begin($mode = NULL) {}
|
||||
public function commit() {}
|
||||
public function rollback() {}
|
||||
public function set_charset($charset) {}
|
||||
public function list_tables($like = NULL) {}
|
||||
|
||||
// Required methods
|
||||
abstract protected function execute($sql);
|
||||
|
||||
/**
|
||||
* Return the caching defined in the current configuration.
|
||||
*
|
||||
* $cache_time = $db->caching("table");
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function caching($table) {
|
||||
return (array_key_exists('cache',Kohana::modules()) AND $this->_config['caching'] AND isset($this->_config['cache'][$table])) ? $this->_config['cache'][$table] : FALSE;
|
||||
}
|
||||
|
||||
private function clear() {
|
||||
$this->_query_msg_codes = array();
|
||||
}
|
||||
|
||||
public function escape($value) {
|
||||
// SQL standard is to use single-quotes for all values
|
||||
return "'$value'";
|
||||
}
|
||||
|
||||
public function query($type, $sql, $as_object = FALSE, array $params = NULL) {
|
||||
// Make sure the database is connected
|
||||
if (! $this->_connection && ! $this->connect())
|
||||
return new Database_TSM_Result(array(),'',$as_object,$params);
|
||||
|
||||
$this->clear();
|
||||
|
||||
if ( ! empty($this->_config['profiling']))
|
||||
// Benchmark this query for the current instance
|
||||
$benchmark = Profiler::start("Database ({$this->_instance})", $sql);
|
||||
|
||||
// Execute the query
|
||||
$result = $this->execute($sql);
|
||||
|
||||
if ($this->execute_stderr AND $this->execute_rc) {
|
||||
// This benchmark is worthless
|
||||
if (isset($benchmark))
|
||||
Profiler::delete($benchmark);
|
||||
|
||||
SystemMessage::TSM('error',sprintf('%s (%s)',$this->execute_stdout,$this->execute_stderr),$sql);
|
||||
}
|
||||
|
||||
if (isset($benchmark))
|
||||
Profiler::stop($benchmark);
|
||||
|
||||
// Set the last query
|
||||
$this->last_query = $sql;
|
||||
|
||||
if ($type === Database::SELECT)
|
||||
// Return an iterator of results
|
||||
return new Database_TSM_Result($result, $sql, $as_object, $params);
|
||||
elseif ($type === Database::INSERT)
|
||||
throw new Kohana_Exception('Database INSERTS are not supported');
|
||||
elseif ($type === Database::SHOW)
|
||||
return new Database_TSM_Show($result, $sql, $as_object, $params);
|
||||
elseif ($type === Database::SET)
|
||||
return new Database_TSM_Set($result, $sql, $as_object, $params);
|
||||
}
|
||||
}
|
||||
?>
|
48
modules/tsm/classes/lnApp/Database/TSM/Result.php
Normal file
48
modules/tsm/classes/lnApp/Database/TSM/Result.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* TSM database result. See [Results](/database/results) for usage and examples.
|
||||
*
|
||||
* @package TSM Database Module
|
||||
* @category Database
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010-2014 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class lnApp_Database_TSM_Result extends Database_Result {
|
||||
public function __construct($result, $sql, $as_object = FALSE, array $params = NULL) {
|
||||
parent::__construct($result, $sql, $as_object, $params);
|
||||
|
||||
$start = FALSE;
|
||||
// Is this a DB2 result?
|
||||
if (is_resource($result) AND function_exists('db2_fetch_object')) {
|
||||
// If we are running a DB2 set command, we can return
|
||||
if (preg_match('/^SET/',$sql))
|
||||
return;
|
||||
|
||||
while ($r = db2_fetch_object($result))
|
||||
$this->_rows[$this->_internal_row++] = (array)$r;
|
||||
|
||||
// Is this an DSMADMC result?
|
||||
} elseif (is_array($result))
|
||||
foreach ($result as $line) {
|
||||
if (! trim($line)) {
|
||||
if ($start)
|
||||
$this->_internal_row++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
list($k,$v) = explode(':',$line,2);
|
||||
|
||||
$this->_rows[$this->_internal_row][trim($k)] = trim($v);
|
||||
$start = TRUE;
|
||||
}
|
||||
else
|
||||
throw new Kohana_Exception('Unknown result :result',array(':result'=>$result));
|
||||
|
||||
$this->_total_rows = $this->_internal_row;
|
||||
$this->_internal_row = 0;
|
||||
}
|
||||
}
|
||||
?>
|
185
modules/tsm/classes/lnApp/Database/Tsm/dsmadmc.php
Normal file
185
modules/tsm/classes/lnApp/Database/Tsm/dsmadmc.php
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* TSM database connection using DSMADMC.
|
||||
*
|
||||
* @package TSM Database Module
|
||||
* @category Drivers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010-2014 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class lnApp_Database_Tsm_dsmadmc extends Database_TSM {
|
||||
public function connect() {
|
||||
// Extract the connection parameters, adding required variabels
|
||||
extract($this->_config['connection'] + array(
|
||||
'database' => '',
|
||||
'hostname' => '',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'persistent' => FALSE,
|
||||
));
|
||||
|
||||
// Get user login details from user session - these are set by login
|
||||
if (! $username)
|
||||
$username = Session::instance()->get_once(Kohana::$config->load('auth')->session_key);
|
||||
if (! $password)
|
||||
$password = Session::instance()->get_once('password');
|
||||
|
||||
// Prevent this information from showing up in traces
|
||||
unset($this->_config['connection']['username'], $this->_config['connection']['password']);
|
||||
|
||||
if (! file_exists(Kohana::$config->load('tsm')->client)) {
|
||||
SystemMessage::TSM('error',sprintf('Unable to find the dsmadmc at <b>%s</b>',Kohana::$config->load('tsm')->client),'');
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (! $username OR ! $password)
|
||||
HTTP::redirect('login');
|
||||
|
||||
try {
|
||||
if ($persistent) {
|
||||
// Create a persistent connection
|
||||
throw new Kohana_Exception('Cant do persistant connections');
|
||||
|
||||
} else {
|
||||
// Create a connection and force it to be a new link
|
||||
$this->_connection = sprintf('%s %s -id=%s -password=%s -displ=list -editor=no -dataonly=YES %s %s ',
|
||||
Kohana::$config->load('tsm')->client,
|
||||
$database ? '-server='.$database : '',
|
||||
$username,
|
||||
$password,
|
||||
Kohana::$config->load('tsm')->client_errorlogname ? sprintf('-errorlogname=%s',Kohana::$config->load('tsm')->client_errorlogname) : '',
|
||||
$database ? sprintf('-se=%s',$database) : ''
|
||||
);
|
||||
|
||||
$result = $this->query(Database::SELECT,'SELECT server_name,platform,version,release,level,sublevel FROM status');
|
||||
|
||||
if ($result->count()) {
|
||||
return TSM::instance()->set($username,$password,$result);
|
||||
|
||||
} else {
|
||||
$this->_connection = FALSE;
|
||||
|
||||
// @todo Get ANS8034E (ID not recognised), or ??????E (invalid password)
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Login Failed'),
|
||||
'type'=>'error',
|
||||
'body'=>_('Invalid Username and/or Password.')
|
||||
));
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (ErrorException $e) {
|
||||
// No connection exists
|
||||
$this->_connection = NULL;
|
||||
|
||||
throw new Database_Exception(':error', array(
|
||||
':error' => sprintf('%s error in %s (%s)',$e->getMessage(),$e->getFile(),$e->getLine()),
|
||||
),
|
||||
$e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
protected function execute($sql) {
|
||||
$this->execute_stdout = '';
|
||||
|
||||
// We need to escape any back slashes, since the exec will transpose them
|
||||
// @todo Is there a better way of doing this?
|
||||
$sql = str_replace('\\','\\\\',$sql);
|
||||
|
||||
$this->execute_stderr = exec($this->_connection.'"'.$sql.'"',$this->execute_stdout,$this->execute_rc);
|
||||
if (Kohana::$config->load('config.site.mode') == Kohana::DEVELOPMENT)
|
||||
SystemMessage::TSM('info',sprintf('%s (%s) [%s]',$this->_connection.'"'.$sql.'"',join("\n",$this->execute_stdout),$this->execute_rc),$sql);
|
||||
|
||||
// Work out our message codes
|
||||
$result = array();
|
||||
foreach ($this->execute_stdout as $line)
|
||||
if (! preg_match('/^('.$this->msg_format.')\s+/',$line,$matches))
|
||||
array_push($result,$line);
|
||||
elseif (! in_array($matches[1],$this->ignore_codes))
|
||||
array_push($this->_query_msg_codes,$matches[1]);
|
||||
|
||||
// If we got a no data code
|
||||
if (array_intersect($this->_query_msg_codes,$this->nodata_codes)) {
|
||||
$result = array();
|
||||
$this->execute_rc = 0;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function list_columns($table, $like = NULL, $add_prefix = TRUE) {
|
||||
// Quote the table name
|
||||
$table = ($add_prefix === TRUE) ? $this->quote_table($table) : $table;
|
||||
|
||||
if (is_string($like))
|
||||
// Search for column names
|
||||
throw new Kohana_Exception('Like queries not implemented');
|
||||
else
|
||||
// Find all column names
|
||||
$result = $this->query(Database::SELECT, sprintf('SELECT * FROM SYSCAT.COLUMNS WHERE TABNAME=\'%s\'',$table), FALSE);
|
||||
|
||||
$count = 0;
|
||||
$columns = array();
|
||||
foreach ($result as $row) {
|
||||
list($type, $length) = $this->_parse_type($row['TYPENAME']);
|
||||
|
||||
$column = $this->datatype($type);
|
||||
|
||||
$column['column_name'] = $row['COLNAME'];
|
||||
$column['data_type'] = $type;
|
||||
$column['is_nullable'] = ($row['NULLS'] == 'TRUE');
|
||||
$column['ordinal_position'] = ++$count;
|
||||
|
||||
switch (strtolower($column['data_type'])) {
|
||||
case 'float':
|
||||
if (isset($length))
|
||||
list($column['numeric_precision'], $column['numeric_scale']) = explode(',', $length);
|
||||
break;
|
||||
|
||||
case 'int':
|
||||
if (isset($length))
|
||||
// MySQL attribute
|
||||
$column['display'] = $length;
|
||||
break;
|
||||
|
||||
case 'string':
|
||||
switch ($column['data_type']) {
|
||||
case 'binary':
|
||||
case 'varbinary':
|
||||
$column['character_maximum_length'] = $length;
|
||||
break;
|
||||
|
||||
case 'char':
|
||||
case 'varchar':
|
||||
$column['character_maximum_length'] = $length;
|
||||
case 'text':
|
||||
case 'tinytext':
|
||||
case 'mediumtext':
|
||||
case 'longtext':
|
||||
$column['collation_name'] = $row['Collation'];
|
||||
break;
|
||||
|
||||
case 'enum':
|
||||
case 'set':
|
||||
$column['collation_name'] = $row['Collation'];
|
||||
$column['options'] = explode('\',\'', substr($length, 1, -1));
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// TSM attributes
|
||||
$column['comment'] = $row['REMARKS'];
|
||||
$columns[$row['COLNAME']] = $column;
|
||||
}
|
||||
|
||||
return $columns ? $columns : array('');
|
||||
}
|
||||
}
|
||||
?>
|
32
modules/tsm/classes/lnApp/Model/ADMIN.php
Normal file
32
modules/tsm/classes/lnApp/Model/ADMIN.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* TSM Administrator Model
|
||||
*
|
||||
* @package TSM Database Module
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010-2014 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class lnApp_Model_ADMIN extends ORM_TSM {
|
||||
protected $_table_name = 'ADMINS';
|
||||
protected $_primary_key = 'ADMIN_NAME';
|
||||
|
||||
protected $_display_filters = array(
|
||||
'LASTACC_TIME'=>array(
|
||||
array('ORM_TSM::Date',array(':value','d-M-Y')),
|
||||
),
|
||||
'PWSET_TIME'=>array(
|
||||
array('ORM_TSM::Date',array(':value','d-M-Y')),
|
||||
),
|
||||
'REG_TIME'=>array(
|
||||
array('ORM_TSM::Date',array(':value','d-M-Y')),
|
||||
),
|
||||
);
|
||||
|
||||
public function name() {
|
||||
return $this->ADMIN_NAME;
|
||||
}
|
||||
}
|
||||
?>
|
798
modules/tsm/classes/lnApp/Model/NODE.php
Normal file
798
modules/tsm/classes/lnApp/Model/NODE.php
Normal file
@@ -0,0 +1,798 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* Obtain TSM details on NODES
|
||||
*
|
||||
* @package TSM Database Module
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010-2014 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class lnApp_Model_NODE extends ORM_TSM {
|
||||
protected $_table_name = 'NODES';
|
||||
protected $_primary_key = 'NODE_NAME';
|
||||
protected $_sorting = array(
|
||||
'NODE_NAME'=>'ASC',
|
||||
);
|
||||
|
||||
protected $_has_one = array(
|
||||
'DOMAIN'=>array('foreign_key'=>'DOMAIN_NAME','far_key'=>'DOMAIN_NAME'),
|
||||
);
|
||||
protected $_has_many = array(
|
||||
'ACTLOG'=>array('foreign_key'=>'NODENAME','far_key'=>'NODE_NAME'),
|
||||
'FILESPACE'=>array('foreign_key'=>'NODE_NAME','far_key'=>'NODE_NAME'),
|
||||
'VOLUMEUSAGE'=>array('foreign_key'=>'NODE_NAME','far_key'=>'NODE_NAME'),
|
||||
'ASSOCIATION'=>array('foreign_key'=>'NODE_NAME','far_key'=>'NODE_NAME'),
|
||||
'MGMTCLASS'=>array('foreign_key'=>'DOMAIN_NAME','far_key'=>'DOMAIN_NAME'),
|
||||
'CLIENTOPT'=>array('foreign_key'=>'OPTIONSET_NAME','far_key'=>'OPTION_SET'),
|
||||
'SUMMARY'=>array('foreign_key'=>'ENTITY','far_key'=>'NODE_NAME'),
|
||||
'EVENT'=>array('foreign_key'=>'NODE_NAME','far_key'=>'NODE_NAME'),
|
||||
'OCC'=>array('foreign_key'=>'NODE_NAME','far_key'=>'NODE_NAME'),
|
||||
);
|
||||
|
||||
protected $_display_filters = array(
|
||||
'REG_TIME'=>array(
|
||||
array('ORM_TSM::Date',array(':value','d-M-Y')),
|
||||
),
|
||||
'PWSET_TIME'=>array(
|
||||
array('ORM_TSM::Date',array(':value','d-M-Y')),
|
||||
),
|
||||
'LASTACC_TIME'=>array(
|
||||
array('ORM_TSM::Date',array(':value','d-M-Y')),
|
||||
),
|
||||
'LASTSESS_SENT'=>array(
|
||||
array('number_format',array(':value',0)),
|
||||
),
|
||||
'LASTSESS_RECVD'=>array(
|
||||
array('number_format',array(':value',0)),
|
||||
),
|
||||
'LASTSESS_DURATION'=>array(
|
||||
array('number_format',array(':value',2)),
|
||||
),
|
||||
'LASTSESS_IDLEWAIT'=>array(
|
||||
array('number_format',array(':value',2)),
|
||||
),
|
||||
'LASTSESS_COMMWAIT'=>array(
|
||||
array('number_format',array(':value',2)),
|
||||
),
|
||||
'LASTSESS_MEDIAWAIT'=>array(
|
||||
array('number_format',array(':value',2)),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Get all the ACTIVITIY LOG for this NODE
|
||||
*/
|
||||
private function _actlog() {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s',__METHOD__,$this->NODE_NAME);
|
||||
$c = Kohana::$config->load('tsm')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
// We cant load all records here, like we do with the others, there is too much data!
|
||||
$result = $this->ACTLOG->find_all();
|
||||
|
||||
// @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 ACTIVITY SUMMARY for this NODE
|
||||
*/
|
||||
private function _actsum() {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s',__METHOD__,$this->NODE_NAME);
|
||||
$c = Kohana::$config->load('tsm')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$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('ACTSUM')->find_all() as $o)
|
||||
if ($o->ENTITY == $this->NODE_NAME)
|
||||
array_push($result,$o);
|
||||
|
||||
// @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 FILESPACES for this NODE
|
||||
*/
|
||||
private function _filespaces() {
|
||||
$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('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() {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s',__METHOD__,$this->NODE_NAME);
|
||||
$c = Kohana::$config->load('tsm')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$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);
|
||||
|
||||
// @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 VOLUMES for this NODE
|
||||
*/
|
||||
private function _volumeusage() {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s',__METHOD__,$this->NODE_NAME);
|
||||
$c = Kohana::$config->load('tsm')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$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);
|
||||
|
||||
// @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 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.')' : '');
|
||||
}
|
||||
|
||||
// @todo This needs to return the global configuration.
|
||||
public function passexp() {
|
||||
if ($this->PASSEXP)
|
||||
return 'TBA';
|
||||
else
|
||||
return _('No Set');
|
||||
}
|
||||
|
||||
// @todo This needs to be validated as a correct calculation
|
||||
public function lasttransferpercent() {
|
||||
$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);
|
||||
else
|
||||
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;
|
||||
else
|
||||
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;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The last sent aggregate performance
|
||||
*/
|
||||
public function lastsendaggperformance() {
|
||||
if ((real)$this->LASTSESS_DURATION)
|
||||
return $this->LASTSESS_SENT/$this->LASTSESS_DURATION/1024/1024;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The last receive aggregate performance
|
||||
*/
|
||||
public function lastreceiveaggperformance() {
|
||||
if ((real)$this->LASTSESS_DURATION)
|
||||
return $this->LASTSESS_RECVD/$this->LASTSESS_DURATION/1024/1024;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
// @todo This should return the system setting (cloptset), if the node setting is not configured.
|
||||
public function txngroupmax() {
|
||||
return $this->TXNGROUPMAX;
|
||||
}
|
||||
|
||||
// Test to see if a node has any data of type
|
||||
// @param $type is BACKUP/ARCHIVE/SPACE MANAGED
|
||||
public function hasData($type) {
|
||||
return $this->vols_byctype($type) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
public function activity() {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s',__METHOD__,$this->NODE_NAME);
|
||||
$c = Kohana::$config->load('tsm')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = array();
|
||||
|
||||
$result = $this->ACTLOG->ExcludeBA()->find_all();
|
||||
|
||||
// @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 ACTIVITY LOG information for a SESSION
|
||||
* @param $sid Session ID
|
||||
* @param $start Session Start Time (to illiminate any duplication session data)
|
||||
*/
|
||||
public function actlog_session($sid,$start) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->_actlog() as $alo)
|
||||
if ($alo->SESSION == $sid AND $alo->start() >= $start)
|
||||
array_push($result,$alo);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the ACTIVITY of this NODE
|
||||
* @param $type is Bkup/Arch/SpMg
|
||||
*/
|
||||
public function act_bybtype($type) {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s-%s',__METHOD__,$this->NODE_NAME,$type);
|
||||
$c = Kohana::$config->load('tsm')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->_actsum() as $aso)
|
||||
if ($aso->ACTIVITY == $this->datatypemap($type))
|
||||
array_push($result,$aso);
|
||||
|
||||
Sort::MASort($result,'SCHEDULE_NAME,START_TIME');
|
||||
// @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 Schedules used for all activites of type
|
||||
* @param $type is Bkup/Arch/SpMg
|
||||
*/
|
||||
public function act_schedules($type) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->act_bybtype($type) as $ao)
|
||||
if (! in_array($ao->SCHEDULE_NAME,$result))
|
||||
array_push($result,$ao->SCHEDULE_NAME);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the BACKUP TYPES used by this NODE
|
||||
* ie: Bkup/Arch/SpMg
|
||||
*/
|
||||
public function btypes() {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s',__METHOD__,$this->NODE_NAME);
|
||||
$c = Kohana::$config->load('tsm')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->_occupancy() as $oo)
|
||||
if (! in_array($oo->TYPE,$result))
|
||||
array_push($result,$oo->TYPE);
|
||||
|
||||
// @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 total of a field for this NODE has by backup TYPE
|
||||
* @param $field the field to check
|
||||
* @param $data the value of that field to match
|
||||
* @param $metric is metric of the storpage pool, eg: NUM_FILES
|
||||
*/
|
||||
private function _data_int($field,$data,$metric) {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s-%s-%s-%s',__METHOD__,$this->NODE_NAME,$field,$data,$metric);
|
||||
$c = Kohana::$config->load('tsm')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = 0;
|
||||
|
||||
foreach ($this->_occupancy() as $oo)
|
||||
if ($oo->{$field} == $data)
|
||||
$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 NODE has in a STORAGE POOL by backup TYPE
|
||||
* @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',__METHOD__,$this->NODE_NAME,$pool,$metric,$type);
|
||||
$c = Kohana::$config->load('tsm')->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 FILES that this NODE has by backup TYPE
|
||||
* @param $type is Bkup/Arch/SpMg
|
||||
*/
|
||||
public function file_bybtype($type) {
|
||||
Log::instance()->add(LOG::DEBUG,'FLYBY :method',array(':method'=>__METHOD__));
|
||||
return $this->_data_int('TYPE',$type,'NUM_FILES');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the FILES that this NODE has in a STORAGE POOL
|
||||
* @param $pool is STORAGE POOL NAME
|
||||
*/
|
||||
public function file_bypool($pool) {
|
||||
Log::instance()->add(LOG::DEBUG,'FLYBY :method',array(':method'=>__METHOD__));
|
||||
return $this->_data_int('STGPOOL_NAME',$pool,'NUM_FILES');
|
||||
}
|
||||
|
||||
public function file_bypoolbybtype($pool,$type) {
|
||||
Log::instance()->add(LOG::DEBUG,'FLYBY :method',array(':method'=>__METHOD__));
|
||||
return $this->_data_bypoolbybtype($pool,'NUM_FILES',$type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the FILES that this NODE has in a STORAGE POOL TYPE
|
||||
* @param $type is ACTIVEDATA/PRIMARY/COPY
|
||||
*/
|
||||
public function file_byptype($type) {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$result = 0;
|
||||
|
||||
foreach ($this->stgpools_byptype($type) as $spo)
|
||||
$result += $this->file_bypool($spo);
|
||||
|
||||
Log::instance()->add(LOG::DEBUG,'EXIT :method',array(':method'=>__METHOD__));
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function file_active() {
|
||||
return $this->file_byptype('ACTIVE') == 0 ? 'Unknown' : (int)$this->file_byptype('ACTIVE')/(int)$this->file_byptype('PRIMARY');
|
||||
}
|
||||
|
||||
public function file_mediaprotection() {
|
||||
return number_format((int)$this->file_byptype('COPY')/(int)$this->file_byptype('PRIMARY')*100,2);
|
||||
}
|
||||
|
||||
public function fs() {
|
||||
return $this->_filespaces();
|
||||
}
|
||||
|
||||
public function fs_capacity() {
|
||||
$result = 0;
|
||||
|
||||
foreach ($this->_filespaces() as $fso)
|
||||
$result += $fso->CAPACITY;
|
||||
|
||||
return (int)$result;
|
||||
}
|
||||
|
||||
public function fs_data() {
|
||||
$result = 0;
|
||||
|
||||
foreach ($this->_filespaces() as $fso)
|
||||
$result += $fso->utilsation();
|
||||
|
||||
return (int)$result;
|
||||
}
|
||||
|
||||
public function fs_logical() {
|
||||
$result = 0;
|
||||
|
||||
foreach ($this->_filespaces() as $fso)
|
||||
$result += $fso->data_logical();
|
||||
|
||||
return (int)$result;
|
||||
}
|
||||
|
||||
public function fs_utilisation() {
|
||||
return round($this->fs_data()/$this->fs_capacity()*100,2);
|
||||
}
|
||||
|
||||
public function fs_vol($vol) {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s-%s',__METHOD__,$this->NODE_NAME,$vol);
|
||||
$c = Kohana::$config->load('tsm')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->_volumeusage() as $vuo)
|
||||
if ($vuo->VOLUME_NAME == $vol AND ! in_array($vuo->FILESPACE_NAME,$result))
|
||||
array_push($result,$vuo->FILESPACE);
|
||||
|
||||
Sort::MASort($result,'FILESPACE_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Graph of the BA Client Sessions
|
||||
* @param $type is Bkup/Arch/SpMg
|
||||
* @see [node/ajaxjson_basessions]
|
||||
*/
|
||||
public function graph_basessions($type='Bkup',$schedule='') {
|
||||
$chart = 'ComboChart';
|
||||
|
||||
$google = GoogleChart::factory($chart)
|
||||
->div(sprintf('bas_%s_%s',$type,$schedule))
|
||||
->dataurl(URL::site(sprintf('node/ajaxjson_basessions/%s?c=%s&s=%s&t=%s',$this->NODE_NAME,$chart,$schedule,$type)));
|
||||
|
||||
return (string)$google;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Graph of the Schedule Backup Activity
|
||||
* @param $type is Bkup/Arch/SpMg
|
||||
* @see [node/ajaxjson_schedules]
|
||||
*/
|
||||
public function graph_schedules($type='Bkup',$schedule='') {
|
||||
$chart = 'ComboChart';
|
||||
|
||||
$google = GoogleChart::factory($chart)
|
||||
->div(sprintf('sch_%s_%s',$type,$schedule))
|
||||
->dataurl(URL::site(sprintf('node/ajaxjson_schedules/%s?c=%s&s=%s&t=%s',$this->NODE_NAME,$chart,$schedule,$type)));
|
||||
|
||||
return (string)$google;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the LOGICAL_MB that this NODE has by backup TYPE
|
||||
* @param $type is Bkup/Arch/SpMg
|
||||
*/
|
||||
public function logmb_bybtype($type) {
|
||||
Log::instance()->add(LOG::DEBUG,'FLYBY :method',array(':method'=>__METHOD__));
|
||||
return $this->_data_int('TYPE',$type,'LOGICAL_MB');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the LOGICAL_MB that this NODE 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_int('STGPOOL_NAME',$pool,'LOGICAL_MB');
|
||||
}
|
||||
|
||||
public function logmb_bypoolbybtype($pool,$type) {
|
||||
Log::instance()->add(LOG::DEBUG,'FLYBY :method',array(':method'=>__METHOD__));
|
||||
return $this->_data_bypoolbybtype($pool,'LOGICAL_MB',$type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the FILES that this NODE has in a STORAGE POOL TYPE
|
||||
* @param $type is ACTIVEDATA/PRIMARY/COPY
|
||||
*/
|
||||
public function logmb_byptype($type) {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$result = 0;
|
||||
|
||||
foreach ($this->stgpools_byptype($type) as $spo)
|
||||
$result += $this->logmb_bypool($spo);
|
||||
|
||||
Log::instance()->add(LOG::DEBUG,'EXIT :method',array(':method'=>__METHOD__));
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function occupancy() {
|
||||
return $this->_occupancy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the STORAGE POOLS this NODE has data in
|
||||
*/
|
||||
public function stgpools() {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s',__METHOD__,$this->NODE_NAME);
|
||||
$c = Kohana::$config->load('tsm')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$x = $result = array();
|
||||
|
||||
foreach ($this->_occupancy() as $oo)
|
||||
if (! in_array($oo->STGPOOL_NAME,$x)) {
|
||||
array_push($result,$oo->STGPOOL);
|
||||
array_push($x,$oo->STGPOOL_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s',__METHOD__,$this->NODE_NAME);
|
||||
$c = Kohana::$config->load('tsm')->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);
|
||||
}
|
||||
|
||||
Log::instance()->add(LOG::DEBUG,'EXIT :method',array(':method'=>__METHOD__));
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the STORAGE POOLS that this NODE uses by BACKUP TYPE
|
||||
* @param $type is Bkup/Arch/SpMg
|
||||
*/
|
||||
public function stgpools_bybtype($type) {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s-%s',__METHOD__,$this->NODE_NAME,$type);
|
||||
$c = Kohana::$config->load('tsm')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$x = $result = array();
|
||||
|
||||
foreach ($this->_occupancy() as $oo)
|
||||
if ($oo->TYPE == $type AND ! in_array($oo->STGPOOL_NAME,$x)) {
|
||||
array_push($result,$oo->STGPOOL);
|
||||
array_push($x,$oo->STGPOOL_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the STORAGE POOLS that this NODE uses by BACKUP TYPE
|
||||
* @param $type is ACTIVEDATA/PRIMARY/COPY
|
||||
*/
|
||||
public function stgpools_byptype($type) {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s-%s',__METHOD__,$this->NODE_NAME,$type);
|
||||
$c = Kohana::$config->load('tsm')->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);
|
||||
}
|
||||
|
||||
Log::instance()->add(LOG::DEBUG,'EXIT :method',array(':method'=>__METHOD__));
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function vols_bybtype($type) {
|
||||
return $this->vols_byctype($this->datatypemap($type));
|
||||
}
|
||||
|
||||
private function _vols_metric($metric,$data) {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s-%s-%s',__METHOD__,$this->NODE_NAME,$metric,$data);
|
||||
$c = Kohana::$config->load('tsm')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$x = $result = array();
|
||||
|
||||
foreach ($this->_volumeusage() as $vuo)
|
||||
if ($vuo->{$metric} == $data 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);
|
||||
}
|
||||
|
||||
Log::instance()->add(LOG::DEBUG,'EXIT :method',array(':method'=>__METHOD__));
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the VOLUMES that this NODE uses by BACKUP TYPE
|
||||
* @param $type is BACKUP/ARCHIVE/SPACE MANAGED
|
||||
*/
|
||||
public function vols_byctype($type) {
|
||||
return $this->_vols_metric('COPY_TYPE',$type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the VOLUMES that this NODE uses
|
||||
* @param $pool is STORAGE POOL NAME
|
||||
*/
|
||||
public function vols_bypool($pool) {
|
||||
return $this->_vols_metric('STGPOOL_NAME',$pool);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the VOLUMES that this NODE has in a STORAGE POOL TYPE
|
||||
* @param $type is ACTIVEDATA/PRIMARY/COPY
|
||||
*/
|
||||
public function vols_byptype($type) {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$result = array();
|
||||
|
||||
foreach ($this->stgpools_byptype($type) as $spo)
|
||||
$result = array_merge($result,$this->vols_bypool($spo));
|
||||
|
||||
Log::instance()->add(LOG::DEBUG,'EXIT :method',array(':method'=>__METHOD__));
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the VOLUMES that this NODE uses by POOL and BACKUP TYPE
|
||||
* @param $pool is STORAGE POOL NAME
|
||||
* @param $type is Bkup/Arch/SpMg
|
||||
*/
|
||||
public function vols_bypoolbybtype($pool,$type) {
|
||||
return $this->vols_bypoolbyctype($pool,$this->datatypemap($type));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_bypoolbyctype($pool,$type) {
|
||||
Log::instance()->add(LOG::DEBUG,'ENTER :method',array(':method'=>__METHOD__));
|
||||
|
||||
$k = sprintf('%s-%s-%s-%s',__METHOD__,$this->NODE_NAME,$pool,$type);
|
||||
$c = Kohana::$config->load('tsm')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->_volumeusage() as $vuo)
|
||||
if ($vuo->STGPOOL_NAME == $pool AND $vuo->COPY_TYPE == $type AND ! in_array($vuo->VOLUME_NAME,$result))
|
||||
array_push($result,$vuo->VOLUME);
|
||||
|
||||
Sort::MASort($result,'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 volumeusage() {
|
||||
return $this->_volumeusage();
|
||||
}
|
||||
}
|
||||
?>
|
38
modules/tsm/classes/lnApp/TSM.php
Normal file
38
modules/tsm/classes/lnApp/TSM.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class contains our TSM information
|
||||
*
|
||||
* @package TSM Database Module
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010-2014 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class lnApp_TSM {
|
||||
static $_online = FALSE;
|
||||
|
||||
public function set($username,$password,Database_TSM_Result $server) {
|
||||
return TSM::$_online = TRUE;
|
||||
}
|
||||
|
||||
public static function online() {
|
||||
return TSM::$_online;
|
||||
}
|
||||
|
||||
public static function instance() {
|
||||
return new TSM;
|
||||
}
|
||||
|
||||
public static function name() {
|
||||
return Session::instance()->get('SERVER')->get('SERVER_NAME');
|
||||
}
|
||||
|
||||
public static function version() {
|
||||
$s = Session::instance()->get('SERVER')->rewind()->as_array();
|
||||
$s = array_pop($s);
|
||||
|
||||
return sprintf('%s.%s.%s.%s',$s['VERSION'],$s['RELEASE'],$s['LEVEL'],$s['SUBLEVEL']);
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user