Start of DB2 direct connection work

This commit is contained in:
Deon George 2011-09-01 07:36:33 +10:00
parent ef4b667277
commit 9eededa37a
18 changed files with 641 additions and 226 deletions

View File

@ -13,5 +13,6 @@
abstract class Database extends Kohana_Database { abstract class Database extends Kohana_Database {
// Enable TSM SHOW commands // Enable TSM SHOW commands
const SHOW = 5; const SHOW = 5;
const SET = 6;
} }
?> ?>

View File

@ -10,7 +10,7 @@
* @copyright (c) 2010 phpTSMadmin Development Team * @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html * @license http://phptsmadmin.sf.net/license.html
*/ */
class Database_TSM extends Database { abstract class Database_TSM extends Database {
// Database in use by each connection // Database in use by each connection
protected static $_current_databases = array(); protected static $_current_databases = array();
@ -24,25 +24,33 @@ class Database_TSM extends Database {
protected $_identifier = ''; protected $_identifier = '';
// Our TSM Message Format // Our TSM Message Format
private $msg_format = '[A-Z]{3}[0-9]{4}[I|E|W|S]'; protected $msg_format = '[A-Z]{3}[0-9]{4}[I|E|W|S]';
// Our Message Codes stored in the last query // Our Message Codes stored in the last query
private $_query_msg_codes = array(); protected $_query_msg_codes = array();
// Our return code error messages we can ignore // Our return code error messages we can ignore
private $ignore_codes = array( protected $ignore_codes = array(
'ANS8001I', // Return code %s. 'ANS8001I', // Return code %s.
); );
// Our return code error messages we can ignore // Our return code error messages we can ignore
private $nodata_codes = array( protected $nodata_codes = array(
'ANR2034E', // SELECT: No match found using this criteria. 'ANR2034E', // SELECT: No match found using this criteria.
); );
protected $execute_stdout = '';
protected $execute_stderr = '';
protected $execute_rc = NULL;
// Our required abstract methods // Our required abstract methods
public function begin($mode = NULL) {} public function begin($mode = NULL) {}
public function commit() {} public function commit() {}
public function rollback() {} public function rollback() {}
public function set_charset($charset) {} 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. * Return the caching defined in the current configuration.
@ -55,82 +63,6 @@ class Database_TSM extends Database {
return ($this->_config['caching'] AND isset($this->_config['cache'][$table])) ? $this->_config['cache'][$table] : FALSE; return ($this->_config['caching'] AND isset($this->_config['cache'][$table])) ? $this->_config['cache'][$table] : FALSE;
} }
public function connect() {
if ($this->_connection)
return;
// 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('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('config.client'))) {
system_message(array('title'=>'Cant find DSMADMC',
'body'=>sprintf('Unable to find the dsmadmc at <b>%s</b>',Kohana::config('client.config')),
'type'=>'error'));
return FALSE;
}
if (! $username OR ! $password)
Request::current()->redirect('/login?need_login=1');
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('config.client'),
$database ? '-server='.$database : '',
$username,
$password,
Kohana::config('config.client_errorlogname') ? sprintf('-errorlogname=%s',Kohana::config('config.client_errorlogname')) : '',
$database ? sprintf('-se=%s',$database) : ''
);
$result = $this->query(Database::SELECT,'SELECT server_name,platform,version,release,level,sublevel FROM status');
if ($result)
return TSM::instance()->set($username,$password,$result);
else
Request::current()->redirect(Request::detect_uri());
}
} 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());
}
// \xFF is a better delimiter, but the PHP driver uses underscore
$this->_connection_id = sha1($hostname.'_'.$username.'_'.$password);
if ( ! empty($this->_config['charset'])) {
// Set the character set
$this->set_charset($this->_config['charset']);
}
}
private function clear() { private function clear() {
$this->_query_msg_codes = array(); $this->_query_msg_codes = array();
} }
@ -144,35 +76,15 @@ class Database_TSM extends Database {
// Benchmark this query for the current instance // Benchmark this query for the current instance
$benchmark = Profiler::start("Database ({$this->_instance})", $sql); $benchmark = Profiler::start("Database ({$this->_instance})", $sql);
// 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);
// Execute the query // Execute the query
$stderr = exec($this->_connection.'"'.$sql.'"',$stdout,$rc); $result = $this->execute($sql);
// Work out our message codes if ($this->execute_stderr AND $this->execute_rc) {
$result = array();
foreach ($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();
$rc = 0;
}
if ($stderr AND $rc) {
if (isset($benchmark))
{
// This benchmark is worthless // This benchmark is worthless
if (isset($benchmark))
Profiler::delete($benchmark); Profiler::delete($benchmark);
}
SystemMessage::TSM_Error($stdout,$sql); SystemMessage::TSM_Error(sprintf('%s (%s)',$this->execute_stdout,$this->execute_stderr),$sql);
Request::current()->redirect('welcome'); Request::current()->redirect('welcome');
} }
@ -189,91 +101,8 @@ class Database_TSM extends Database {
throw new Kohana_Exception('Database INSERTS are not supported'); throw new Kohana_Exception('Database INSERTS are not supported');
elseif ($type === Database::SHOW) elseif ($type === Database::SHOW)
return new Database_TSM_Show($result, $sql, $as_object, $params); return new Database_TSM_Show($result, $sql, $as_object, $params);
} elseif ($type === Database::SET)
return new Database_TSM_Set($result, $sql, $as_object, $params);
public function list_tables($like = NULL) {
if (is_string($like))
// Search for table names
$result = $this->query(Database::SELECT, 'SHOW TABLES LIKE '.$this->quote($like), FALSE);
else
// Find all table names
$result = $this->query(Database::SELECT, 'SHOW TABLES', FALSE);
$tables = array();
foreach ($result as $row)
$tables[] = reset($row);
return $tables;
}
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
$result = $this->query(Database::SELECT, 'SHOW FULL COLUMNS FROM '.$table.' LIKE '.$this->quote($like), FALSE);
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;
} }
public function escape($value) { public function escape($value) {
@ -283,5 +112,5 @@ class Database_TSM extends Database {
// SQL standard is to use single-quotes for all values // SQL standard is to use single-quotes for all values
return "'$value'"; return "'$value'";
} }
}
} // End Database_TSM ?>

View File

@ -0,0 +1,162 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* TSM database connection using DB2.
*
* @package PTA
* @subpackage TSM
* @category Drivers
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
class Database_TSM_DB2 extends Database_TSM {
public function connect() {
if ($this->_connection)
return;
// Extract the connection parameters, adding required variabels
extract($this->_config['connection'] + array(
'database' => '',
'hostname' => '',
'username' => '',
'port' => '',
'password' => '',
'persistent' => FALSE,
));
// Get user login details from user session - these are set by login
if (! $username)
$username = Session::instance()->get_once(Kohana::config('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 (! $username OR ! $password)
Request::current()->redirect('/login?need_login=1');
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
$constring = sprintf('DATABASE=%s;HOSTNAME=%s;PORT=%s;PROTOCOL=%s;UID=%s;PWD=%s',
$database,$hostname,$port,'TCPIP',$username,$password);
$this->_connection = db2_connect($constring,NULL,NULL);
if ($this->_connection) {
$result = DB::query(Database::SET,'SET SCHEMA='.$database)->execute(Kohana::config('config.client_type'));
$result = $this->query(Database::SELECT,'SELECT server_name,platform,version,release,level,sublevel FROM status');
return TSM::instance()->set($username,$password,$result);
} else
Request::current()->redirect(Request::detect_uri());
}
} 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());
}
// \xFF is a better delimiter, but the PHP driver uses underscore
$this->_connection_id = sha1($hostname.'_'.$username.'_'.$password);
if ( ! empty($this->_config['charset'])) {
// Set the character set
$this->set_charset($this->_config['charset']);
}
}
protected function execute($sql) {
$result = @db2_exec($this->_connection,$sql);
$this->execute_stderr = db2_stmt_errormsg();
$this->execute_rc = db2_stmt_error();
return $result;
}
public function list_columns($table, $like = NULL, $add_prefix = TRUE) {
// Make sure the database is connected
$this->_connection or $this->connect();
// 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 = db2_columns($this->_connection,NULL,NULL,$table);
$count = 0;
$columns = array();
while ($row = db2_fetch_assoc($result)) {
list($type, $length) = $this->_parse_type($row['TYPE_NAME']);
$column = $this->datatype($type);
$column['column_name'] = $row['COLUMN_NAME'];
$column['data_type'] = $type;
$column['is_nullable'] = ($row['IS_NULLABLE'] == 'YES');
$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['COLUMN_NAME']] = $column;
}
return $columns;
}
}
?>

View File

@ -0,0 +1,186 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* TSM database connection using DSMADMC.
*
* @package PTA
* @subpackage TSM
* @category Drivers
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
class Database_TSM_DSMADMC extends Database_TSM {
public function connect() {
if ($this->_connection)
return;
// 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('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('config.client'))) {
system_message(array('title'=>'Cant find DSMADMC',
'body'=>sprintf('Unable to find the dsmadmc at <b>%s</b>',Kohana::config('client.config')),
'type'=>'error'));
return FALSE;
}
if (! $username OR ! $password)
Request::current()->redirect('/login?need_login=1');
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('config.client'),
$database ? '-server='.$database : '',
$username,
$password,
Kohana::config('config.client_errorlogname') ? sprintf('-errorlogname=%s',Kohana::config('config.client_errorlogname')) : '',
$database ? sprintf('-se=%s',$database) : ''
);
$result = $this->query(Database::SELECT,'SELECT server_name,platform,version,release,level,sublevel FROM status');
if ($result)
return TSM::instance()->set($username,$password,$result);
else
Request::current()->redirect(Request::detect_uri());
}
} 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());
}
// \xFF is a better delimiter, but the PHP driver uses underscore
$this->_connection_id = sha1($hostname.'_'.$username.'_'.$password);
if ( ! empty($this->_config['charset'])) {
// Set the character set
$this->set_charset($this->_config['charset']);
}
}
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);
// 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;
}
}
?>

View File

@ -15,6 +15,17 @@ class Database_TSM_Result extends Database_Result {
parent::__construct($result, $sql, $as_object, $params); parent::__construct($result, $sql, $as_object, $params);
$start = FALSE; $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) { foreach ($result as $line) {
if (! trim($line)) { if (! trim($line)) {
if ($start) if ($start)
@ -28,6 +39,8 @@ class Database_TSM_Result extends Database_Result {
$this->_rows[$this->_internal_row][trim($k)] = trim($v); $this->_rows[$this->_internal_row][trim($k)] = trim($v);
$start = TRUE; $start = TRUE;
} }
else
throw new Kohana_Exception('Unknown result :result',array(':result'=>$result));
$this->_total_rows = $this->_internal_row; $this->_total_rows = $this->_internal_row;
$this->_internal_row = 0; $this->_internal_row = 0;

View File

@ -0,0 +1,15 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* TSM database set result.
*
* @package PTA
* @subpackage TSM
* @category Query/Set
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
class Database_TSM_Set extends Database_Result {
}
?>

View File

@ -13,5 +13,12 @@ class Model_Auth_UserDefault extends Model_Auth_User {
protected $_disable_wild_select = TRUE; protected $_disable_wild_select = TRUE;
protected $_disable_join_table_name = TRUE; protected $_disable_join_table_name = TRUE;
protected $_disable_limit = TRUE; protected $_disable_limit = TRUE;
protected function _initialize() {
// Set out DB connection configuration.
$this->_db_group = Kohana::config('config.client_type');
parent::_initialize();
}
} }
?> ?>

View File

@ -22,6 +22,16 @@ class Model_DOMAIN extends ORMTSM {
'SCHEDULE_CLIENT'=>array('foreign_key'=>'DOMAIN_NAME','far_key'=>'DOMAIN_NAME') 'SCHEDULE_CLIENT'=>array('foreign_key'=>'DOMAIN_NAME','far_key'=>'DOMAIN_NAME')
); );
protected $_tsm = array(
'db2'=>array(
'_has_many'=>array(
'MGMTCLASS'=>array('foreign_key'=>'DOMAIN_NAME','far_key'=>'DOMAIN_NAME'),
'NODE'=>array('foreign_key'=>'DOMAINNAME','far_key'=>'DOMAIN_NAME'),
'SCHEDULE_CLIENT'=>array('foreign_key'=>'DOMAIN_NAME','far_key'=>'DOMAIN_NAME')
),
),
);
// Pools used by a domain. // Pools used by a domain.
private $pools = array(); private $pools = array();

View File

@ -17,9 +17,29 @@ class Model_FILESPACE extends ORMTSM {
'FILESPACE_NAME'=>'ASC', 'FILESPACE_NAME'=>'ASC',
); );
protected $_has_one = array(
'NODE'=>array('foreign_key'=>'NODE_NAME','far_key'=>'NODE_NAME'),
);
protected $_has_many = array( protected $_has_many = array(
'VOLUMEUSAGE'=>array('foreign_key'=>array('NODE_NAME'=>'NODE_NAME','FILESPACE_NAME'=>'FILESPACE_NAME')), );
'OCCUPANCY'=>array('foreign_key'=>array('NODE_NAME'=>'NODE_NAME','FILESPACE_NAME'=>'FILESPACE_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,
),
),
); );
protected $_display_filters = array( protected $_display_filters = array(
@ -29,16 +49,17 @@ class Model_FILESPACE extends ORMTSM {
); );
public function utilsation() { public function utilsation() {
return $this->CAPACITY * ($this->PCT_UTIL/100); return $this->CAPACITY*($this->PCT_UTIL/100);
} }
// $dtype must be Bkup or Arch // $dtype must be Bkup or Arch
public function storagepools($dtype) { public function storagepools($dtype) {
$pool = array(); $pool = array();
foreach ($this->OCCUPANCY foreach ($this->NODE->OCC
->select('STGPOOL_NAME') ->select('STGPOOL_NAME')
->where('TYPE','=',$dtype) ->where('TYPE','=',$dtype)
->and_where('FILESPACE_NAME','=',$this->FILESPACE_NAME)
->group_by('STGPOOL_NAME') ->group_by('STGPOOL_NAME')
->order_by('STGPOOL_NAME') ->order_by('STGPOOL_NAME')
->find_all() as $oo) ->find_all() as $oo)
@ -49,11 +70,19 @@ class Model_FILESPACE extends ORMTSM {
} }
public function pool_logical_util($pool,$btype) { public function pool_logical_util($pool,$btype) {
return $this->OCCUPANCY->where('STGPOOL_NAME','=',$pool)->where('TYPE','=',$btype)->find()->LOGICAL_MB; return $this->NODE->OCC
->where('STGPOOL_NAME','=',$pool)
->and_where('TYPE','=',$btype)
->and_where('FILESPACE_NAME','=',$this->FILESPACE_NAME)
->find()->LOGICAL_MB;
} }
public function pool_numvols($pool,$ctype) { public function pool_numvols($pool,$ctype) {
return $this->VOLUMEUSAGE->where('STGPOOL_NAME','=',$pool)->where('COPY_TYPE','=',$ctype)->find_all()->count(); return $this->NODE->VOLUMEUSAGE
->where('STGPOOL_NAME','=',$pool)
->and_where('COPY_TYPE','=',$ctype)
->and_where('FILESPACE_NAME','=',$this->FILESPACE_NAME)
->find_all()->count();
} }
} }
?> ?>

View File

@ -27,6 +27,61 @@ class Model_NODE extends ORMTSM {
'CLIENTOPT'=>array('foreign_key'=>'OPTIONSET_NAME','far_key'=>'OPTION_SET'), 'CLIENTOPT'=>array('foreign_key'=>'OPTIONSET_NAME','far_key'=>'OPTION_SET'),
'SUMMARY'=>array('foreign_key'=>'ENTITY','far_key'=>'NODE_NAME'), 'SUMMARY'=>array('foreign_key'=>'ENTITY','far_key'=>'NODE_NAME'),
'EVENT'=>array('foreign_key'=>'NODE_NAME','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 $_tsm = array(
'db2'=>array(
'_primary_key'=>'NODENAME',
'_sorting'=>array(
'NODENAME'=>'ASC',
),
'_has_one'=>array(
'DOMAIN'=>array('foreign_key'=>'DOMAIN_NAME','far_key'=>'DOMAINNAME'),
),
'_has_many'=>array(
'FILESPACE'=>array('foreign_key'=>'NODEID','far_key'=>'NODEID'),
'VOLUMEUSAGE'=>array('foreign_key'=>'NODE_NAME','far_key'=>'NODENAME'),
'ASSOCIATION'=>array('foreign_key'=>'NODE_NAME','far_key'=>'NODENAME'),
'MGMTCLASS'=>array('foreign_key'=>'DOMAIN_NAME','far_key'=>'DOMAIN_NAME'),
'CLIENTOPT'=>array('foreign_key'=>'OPTIONSET_NAME','far_key'=>'OPTIONSET'),
'SUMMARY'=>array('foreign_key'=>'ENTITY','far_key'=>'NODENAME'),
'EVENT'=>array('foreign_key'=>'NODE_NAME','far_key'=>'NODENAME'),
'OCC'=>array('foreign_key'=>'NODE_NAME','far_key'=>'NODENAME'),
),
'translate'=>array(
'NODE_NAME'=>'NODENAME',
'CLIENT_VERSION'=>'CLNTVERSION',
'CLIENT_RELEASE'=>'CLNTRELEASE',
'CLIENT_LEVEL'=>'CLNTLEVEL',
'CLIENT_SUBLEVEL'=>'CLNTSUBLEVEL',
'PLATFORM_NAME'=>'OSNAME',
'CLIENT_OS_LEVEL'=>'CLNTOSLEVEL',
'LASTACC_TIME'=>'LACDATE',
'REG_TIME'=>'REGDATE',
'PWSET_TIME'=>'PWSETDATE',
'LASTSESS_SENT'=>'SESSSENT',
'LASTSESS_RECVD'=>'SESSRECVD',
'LASTSESS_DURATION'=>'SESSDURATION',
'LASTSESS_IDLEWAIT'=>'SESSIDLEWAIT',
'LASTSESS_COMMWAIT'=>'SESSCOMMWAIT',
'LASTSESS_MEDIAWAIT'=>'SESSMEDIAWAIT',
'TCP_ADDRESS'=>NULL,
'EMAIL_ADDRESS'=>NULL,
'REG_ADMIN'=>'REGISTRAR',
'PASSEXP'=>NULL,
'INVALID_PW_COUNT'=>'INVPWCOUNT',
'LOCKED'=>'LOCKSTATE',
'DOMAIN_NAME'=>'DOMAINNAME',
'OPTION_SET'=>'OPTIONSET',
'COLLOCGROUP_NAME'=>NULL,
'COMPRESSION'=>'COMPRESS',
'ARCHDELETE'=>'ARCHDEL',
'BACKDELETE'=>'BACKDEL',
'KEEP_MP'=>NULL,
'MAX_MP_ALLOWED'=>'MAXNUMMP',
),
),
); );
protected $_display_filters = array( protected $_display_filters = array(
@ -196,8 +251,7 @@ class Model_NODE extends ORMTSM {
public function getStorageModeFiles($dtype,$ptype,$spo='') { public function getStorageModeFiles($dtype,$ptype,$spo='') {
$count = 0; $count = 0;
foreach ($this->FILESPACE->find_all() as $fo) foreach ($this->OCC->where('TYPE','=',$dtype)->find_all() as $oa)
foreach ($fo->OCCUPANCY->where('TYPE','=',$dtype)->find_all() as $oa)
if ((! $spo OR $oa->STGPOOL_NAME == $spo) AND $oa->STGPOOL->POOLTYPE == $ptype) if ((! $spo OR $oa->STGPOOL_NAME == $spo) AND $oa->STGPOOL->POOLTYPE == $ptype)
$count += $oa->NUM_FILES; $count += $oa->NUM_FILES;
@ -219,8 +273,7 @@ class Model_NODE extends ORMTSM {
public function getStorageModeData($dtype,$ptype,$spo='') { public function getStorageModeData($dtype,$ptype,$spo='') {
$count = 0; $count = 0;
foreach ($this->FILESPACE->find_all() as $fo) foreach ($this->OCC->where('TYPE','=',$dtype)->find_all() as $oa)
foreach ($fo->OCCUPANCY->where('TYPE','=',$dtype)->find_all() as $oa)
if ((! $spo OR $oa->STGPOOL_NAME == $spo) AND $oa->STGPOOL->POOLTYPE == $ptype) if ((! $spo OR $oa->STGPOOL_NAME == $spo) AND $oa->STGPOOL->POOLTYPE == $ptype)
$count += $oa->LOGICAL_MB; $count += $oa->LOGICAL_MB;

View File

@ -8,8 +8,9 @@
* @author Deon George * @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team * @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html * @license http://phptsmadmin.sf.net/license.html
* @node This has been renamed to OCC from OCCUPANCY, as DB2/FILESPACES has an OCCUPANCY column
*/ */
class Model_OCCUPANCY extends ORMTSM { class Model_OCC extends ORMTSM {
protected $_table_name = 'OCCUPANCY'; protected $_table_name = 'OCCUPANCY';
protected $_primary_key = 'NODE_NAME'; // We need a primary key to detect that the object is loaded. protected $_primary_key = 'NODE_NAME'; // We need a primary key to detect that the object is loaded.
protected $_sorting = array( protected $_sorting = array(

View File

@ -25,6 +25,39 @@ class ORMTSM extends ORM {
protected $_formated = FALSE; protected $_formated = FALSE;
protected $_formats = array(); protected $_formats = array();
protected $_tsm = array();
/**
*
* Configuration to enable PLA to work with DSMADMC & DB2 connections
* This is required, because the schema is different between each
* connection?
*/
protected function _initialize() {
// Set out DB connection configuration.
$this->_db_group = Kohana::config('config.client_type');
// Adjustments for DSMADMC or DB2 connections
if (array_key_exists(Kohana::config('config.client_type'),$this->_tsm))
foreach ($this->_tsm[Kohana::config('config.client_type')] as $k => $v)
if (preg_match('/^_/',$k))
$this->{$k} = $v;
if ($this->_db_group == 'db2')
$this->_disable_join_table_name = FALSE;
parent::_initialize();
}
public function __get($column) {
// Get a substited column name - need for DB2/DSMADMC schema differences
if (isset($this->_tsm[Kohana::config('config.client_type')]['translate']) AND array_key_exists($column,$this->_tsm[Kohana::config('config.client_type')]['translate'])) {
return is_null($c=$this->_tsm[Kohana::config('config.client_type')]['translate'][$column]) ? NULL : parent::__get($c);
}
else
return parent::__get($column);
}
public function find() { public function find() {
// Check if we can preload our data and havent already done it // Check if we can preload our data and havent already done it
if ($time = $this->isCacheable() AND is_null(Cache::instance()->get($cache_key = 'PRELOAD:'.$this->_table_name))) { if ($time = $this->isCacheable() AND is_null(Cache::instance()->get($cache_key = 'PRELOAD:'.$this->_table_name))) {

View File

@ -14,7 +14,7 @@ class SystemMessage extends lnApp_SystemMessage {
static public function TSM_Error($error,$sql) { static public function TSM_Error($error,$sql) {
SystemMessage::add(array( SystemMessage::add(array(
'title'=>_('Error while talking to TSM'), 'title'=>_('Error while talking to TSM'),
'body'=>_('Running SQL').': <b>'.$sql.'</b><br/><br/>'.implode('<br/>',$error), 'body'=>_('Running SQL').': <b>'.$sql.'</b><br/><br/>'.(is_array($error) ? implode('<br/>',$error) : $error),
'type'=>'error', 'type'=>'error',
)); ));
} }

View File

@ -13,6 +13,7 @@
return array( return array(
'cache_type' => 'file', 'cache_type' => 'file',
'client' => '/opt/tivoli/tsm/client/ba/bin/dsmadmc', 'client' => '/opt/tivoli/tsm/client/ba/bin/dsmadmc',
'client_type' => 'db2',
'client_errorlogname' => '/tmp/pta-tsm-errorlog.log', 'client_errorlogname' => '/tmp/pta-tsm-errorlog.log',
'date_format' => 'd-m-Y', 'date_format' => 'd-m-Y',
'tsmdatatypes' => array('Bkup'=>'BACKUP','Arch'=>'ARCHIVE'), 'tsmdatatypes' => array('Bkup'=>'BACKUP','Arch'=>'ARCHIVE'),

View File

@ -13,9 +13,9 @@
return array return array
( (
'default' => array 'dsmadmc' => array
( (
'type' => 'tsm', 'type' => 'tsm_dsmadmc',
'connection' => array( 'connection' => array(
/** /**
* The following options are available for MySQL: * The following options are available for MySQL:
@ -32,7 +32,71 @@ return array
'username' => FALSE, 'username' => FALSE,
'password' => FALSE, 'password' => FALSE,
//'persistent' => FALSE, // Unused //'persistent' => FALSE, // Unused
'database' => 'local', ),
'table_prefix' => '',
'charset' => 'utf8',
'caching' => TRUE,
'cache' => array(
'ASSOCIATIONS' => 1200,
'AR_COPYGROUPS' => 1200,
'BU_COPYGROUPS' => 1200,
'CLIENT_SCHEDULES' => 1200,
'CLIENTOPTS' => 1200,
'DEVCLASSES' => 1200,
'DOMAINS' => 1200,
'DRIVES' => 1200,
'EVENTS' => 1200,
'FILESPACES' => 1200,
'LIBRARIES' => 1200,
'LIBVOLUMES' => 1200,
'MEDIA' => 1200,
'MGMTCLASSES' => 1200,
'NODES' => 1200,
'OCCUPANCY' => 1200,
'PATHS' => 1200,
'SCHEMA' => 604800,
'STGPOOLS' => 1200,
'SUMMARY' => 180,
'VOLHISTORY' => 1200,
'VOLUMES' => 1200,
'VOLUMEUSAGE' => 1200,
),
'cachepreload' => array(
'DEVCLASSES' => 1200,
'DOMAINS' => 1200,
'DRIVES' => 1200,
'LIBVOLUMES' => 1200,
'LIBRARIES' => 1200,
'MEDIA' => 1200,
'NODES' => 1200,
'STGPOOLS' => 1200,
'VOLHISTORY' => 1200,
'VOLUMES' => 1200,
),
'profiling' => TRUE,
),
'db2' => array
(
'type' => 'tsm_db2',
'connection' => array(
/**
* The following options are available for DB2:
*
* string hostname server hostname, or socket
* string database database name
* string username database username
* string password database password
* boolean persistent use persistent connections?
*
* Ports and sockets may be appended to the hostname.
*/
'hostname' => 'localhost',
'port' => '60000',
'username' => FALSE,
'password' => FALSE,
'persistent' => FALSE,
'database' => 'TSMDB1',
), ),
'table_prefix' => '', 'table_prefix' => '',
'charset' => 'utf8', 'charset' => 'utf8',

View File

@ -20,16 +20,16 @@ return array(
'copyright' => '&copy; 20082011 phpTSMadmin Development Team', 'copyright' => '&copy; 20082011 phpTSMadmin Development Team',
), ),
'cache' => array( 'cache' => array(
'enabled' => FALSE, 'enabled' => TRUE,
), ),
'database' => array( 'database' => array(
'enabled' => FALSE, 'enabled' => TRUE,
), ),
'kohana' => array( 'kohana' => array(
'enabled' => FALSE, 'enabled' => TRUE,
), ),
'orm' => array( 'orm' => array(
'enabled' => FALSE, 'enabled' => TRUE,
), ),
'userguide' => array( 'userguide' => array(
'enabled' => FALSE, 'enabled' => FALSE,

View File

@ -0,0 +1,10 @@
-1. extract /.../COI/PackageSteps/DB2/FILES/ese/db2/linuxamd64/FILES/BASE_CLIENT_9.7.0.2_linuxamd64_x86_64.tar.gz
1. extract /.../COI/PackageSteps/DB2/FILES/ese/db2/linuxamd64/FILES/APPLICATION_DEVELOPMENT_TOOLS_9.7.0.2_linuxamd64_x86_64.tar.gz
2. link /opt/tivoli/tsm/db2/includes to extracted developer files
3. yum install gcc --enabler=updates
4. install php-pear (from webtatic)
5. install php-devel (from webtatic)
6. pecl install ibm_db2 (as root)
7. create php.d/db2.ini
8. run db2set DB2COMM=tcpip as tsminst1
9. open TCP port to enable remote connections db2 UPDATE DBM CFG USING SVCENAME DB2_tsminst1

View File

@ -1,2 +1,3 @@
## [PTA]() ## [PTA]()
- [Installation](install) - [Installation](install)
- [DB2](db2)