|
|
Datasrc
Action : was.datasrc (Category : was, Name : datasrc, By : kikonf)
Complete Name : was.datasrc.by.kikonf
Version : 5.0 License : Modified BSD License
Purpose of the was category :
Easy to customize. This category use in background the wsadmin command in jython mode (through AdminConfig, AdminControl
and AdminTask), to drive WebSphere Application Server ® configuration.
You can use it to manage the whole WebSphere ® architecture.
Purpose of this datasrc plugin : Creates a new DataSource
The following shows the main Source Code File for the Action : was.datasrc
Toggle lines
## Copyright (c) 2008, Patrick Germain Placidoux
## All rights reserved.
##
## This file is part of Kikonf Public Software.
##
## Kikonf Public Software is released under the modified BSD License,
## which should accompany it or any part of it in the file "COPYING".
## If you do not have this file you can access the license
## through the WWW at http://www.kikonf.org/license/bsd/license.txt.
##
## Home: http://www.kikonf.org
## Contact: kikonf@gmx.com
from actions.was.tools import *
class Datasrc(wasAction):
DATASRC=\
{
'db2': {
'notxa': 'DB2 Universal JDBC Driver DataSource(templates/system|jdbc-resource-provider-templates.xml#DataSource_DB2_UNI_1)',
'xa': 'DB2 Universal JDBC Driver XA DataSource(templates/system|jdbc-resource-provider-templates.xml#DataSource_DB2_UNI_2)',
},
'oracle_5': {
'notxa': 'Oracle JDBC Driver DataSource(templates/system|jdbc-resource-provider-templates.xml#DataSource_ora_5)',
},
'oracle_6': {
'xa': 'Oracle JDBC Driver XA DataSource(templates/system|jdbc-resource-provider-templates.xml#DataSource_ora_6)',
},
'msql': {
'notxa': 'WebSphere embedded ConnectJDBC for SQL Server DataSource(templates/system|jdbc-resource-provider-templates.xml#DataSource_DD_3)',
'xa': 'WebSphere embedded ConnectJDBC for SQL Server XA DataSource(templates/system|jdbc-resource-provider-templates.xml#DataSource_DD_4)',
}
}
def extract(self, scope_attrs, name=None, prefix=None, doRaise=True, **keywords):
self_funct='extract'
from actions.was.jdbc.by.kikonf import jdbc
self.verbose(scope_attrs, name=name, prefix=prefix)
scope_id, scope_attrs, scope=self.getScope(scope_attrs=scope_attrs, indent=self.getIndent())
indent=self.getIndent() + 3*' '
verbose('DataSource retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
ds=split( AdminConfig.getid(self.getScopeCP() + '/JDBCProvider:/DataSource:/') )
for d in ds:
datasrcs=getShowAsDict(AdminConfig.show(d))
dname=datasrcs['name']
if not (prefix!=None and name!=None and dname==prefix + '_' + name \
or prefix==None and name!=None and name==dname \
or prefix!=None and name==None and dname.startswith(prefix) \
or prefix==None and name==None):continue
verbose('DataSource:' + dname + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
if datasrcs.has_key('description') and datasrcs['description']!=None:desc=datasrcs['description']
else:desc=None
if desc==DESIGN_NOTICE:desc=None
jndi_name=datasrcs['jndiName']
provider=AdminConfig.showAttribute(datasrcs['provider'], 'name')
try:
ptype=jdbc.getProviderType(datasrcs['provider'], self)
if ptype==None:raise
if ptype.startswith('oracle'):ptype='oracle'
except:
verbose('DataSource:' + dname + ', not managed provider: ' + AdminConfig.showAttribute(datasrcs['provider'], 'name') + '. Skipped !', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
continue
verbose('JDBCProvider:' + provider + ' with type:' + ptype + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
statement_cache_size=datasrcs['statementCacheSize']
datasrc_node=self.newTop() #-- because in extract mode, each call returns a new blank top node.
_name=dname
if prefix!=None:_name=dname.split(prefix + '_')[1]
datasrc_node.setAttrs(name=_name, desc=desc, jndi_name=jndi_name, provider=provider, dbtype=ptype, statement_cache_size=statement_cache_size, prefix=prefix)
mkNodeScope(datasrc_node, scope_attrs, isUnique=True) #-- creates a scope node.
jaas_name=datasrcs['authDataAlias']
propset=datasrcs['propertySet']
jaas=None
verbose('JAASAuthData listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
as=split( AdminConfig.list("JAASAuthData") )
for a in as:
aname=AdminConfig.showAttribute(a, "alias")
if jaas_name==aname:
jaas=a
break
if jaas==None:
if doRaise:raise xception.kikonfActionSystemException(self, self_funct, 'Tag: jaas, Unable to retreive JAAS Alias named:' + jaas_name + ' !')
else:verbose('Tag: jaas, Unable to retreive JAAS Alias named:' + jaas_name + ' !', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
user=password='?'
else:
user = AdminConfig.showAttribute(jaas, 'userId')
verbose('JAASAuthData:' + aname + ' with user:' + user + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
try:
password=self.getPwdFromJAAS(aname)
except:password='???'
_name=aname
if prefix!=None:_name=aname.split(prefix + '_')[1]
desc=AdminConfig.showAttribute(jaas, 'description')
if desc!=None:desc=desc[1:-1]
if desc==DESIGN_NOTICE:desc=None
jaas_node=datasrc_node.newNode('jaas', name=_name, user=user, password=password, create='true', desc=desc)
connection_pool_node=datasrc_node.newNode('connection_pool') # Tag: connection_pool
indent=self.getIndent() + 3*' '
getConnectionPoolAttrs(datasrcs['connectionPool'], connection_pool_node, level=self.getVerbose(), indent=indent, logFile=self.getLogFile())
rps = split( AdminConfig.showAttribute(datasrcs['propertySet'], 'resourceProperties') ) # Tag: properties
properties_node=datasrc_node.newNode('properties')
properties=jdbc.Jdbc.DRIVERS[ptype]['pset']
for rp in rps:
for property in properties:
if rp.startswith(property):
value=AdminConfig.showAttribute(rp, 'value');
properties_node.newNode('property', name=property, value=value)
def remove(self, no_name, no_name_no_prefix):
datasrc_node=self.getTop()
datasrc_attrs = datasrc_node.getAttrs()
scope_id, scope_attrs, scope=self.getScope(parent_node=datasrc_node, indent=self.getIndent()) #-- Retreives scope
self.verbose(scope_attrs, name=datasrc_attrs.name, prefix=datasrc_attrs.prefix)
indent=self.getIndent() + 3*' '
# no_name/no_name_no_prefix
prefix=datasrc_attrs.prefix
name=datasrc_attrs.name
if no_name or no_name_no_prefix:name=None
if no_name_no_prefix:prefix=None
# remove all at prefix if present.
self.rmvDatasrc(name=name, prefix=prefix, indent=indent)
if datasrc_node.hasNode('jaas'):
jaas_node=datasrc_node.getNode('jaas')[0]
jaas_attrs = jaas_node.getAttrs()
if jaas_attrs.create == 'true':self.rmvJaas(name=jaas_attrs.name, prefix=datasrc_attrs.prefix, indent=indent) # not allowed to destroy all.
def inject(self):
self_funct='inject'
datasrc_node = self.getTop()
datasrc_attrs = datasrc_node.getAttrs()
scope_id, scope_attrs, scope=self.getScope(parent_node=datasrc_node, indent=self.getIndent()) #-- Retreives scope
from actions.was.jdbc.by.kikonf import jdbc
indent=self.getIndent() + 3*' '
self.rmvDatasrc(name=datasrc_attrs.name, prefix=datasrc_attrs.prefix, indent=indent) #-- Destroy all first
#-- name
if datasrc_attrs.prefix==None:name=datasrc_attrs.name
else:name=datasrc_attrs.prefix + '_' + datasrc_attrs.name
self.verbose(scope_attrs, name=name, prefix=datasrc_attrs.prefix)
if datasrc_node.hasNode('jaas'):
jaas_node=datasrc_node.getNode('jaas')[0]
jaas_attrs = jaas_node.getAttrs()
jaas_name=self.inJaas(jaas_attrs, datasrc_attrs.prefix, indent=indent)
else:raise xception.kikonfActionSystemException(self, self_funct, 'Tag: jaas, is required !')
verbose('JDBCProvider retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
provider = AdminConfig.getid(self.getScopeCP()+'/JDBCProvider:' + datasrc_attrs.provider)
if provider in ('', None):raise xception.kikonfActionSystemException(self, self_funct, 'Unable to retreive provider:' + datasrc_attrs.provider + '!')
verbose('JDBCProvider:' + provider + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
dbtype=datasrc_attrs.dbtype
if AdminConfig.showAttribute(provider, 'xa')=='true':
isxa='xa'
if dbtype=='oracle':dbtype+='_6'
else:
isxa='notxa'
if dbtype=='oracle':dbtype+='_5'
if not Datasrc.DATASRC[dbtype].has_key(isxa):raise xception.kikonfActionSystemException(self, self_funct, 'This dbtype:' + datasrc_attrs.dbtype + 'do not support this xa mode:' + iswa + ' !')
dtmpl=Datasrc.DATASRC[dbtype][isxa]
cmdvalues=[]
cmdvalues.append(['name', name])
cmdvalues.append(['jndiName', datasrc_attrs.jndi_name])
if datasrc_attrs.desc!=None:cmdvalues.append(['description', datasrc_attrs.desc])
else:cmdvalues.append(['description', DESIGN_NOTICE])
cmdvalues.append(['authDataAlias', jaas_name])
cmdvalues.append(['statementCacheSize', datasrc_attrs.statement_cache_size])
if datasrc_node.hasNode('connection_pool'):
conpool_node=datasrc_node.getNode('connection_pool')[0]
cmdvalues.append(['connectionPool', getConnectionPoolCfgs(conpool_node, level=self.getVerbose(), indent=indent, logFile=self.getLogFile())])
if isxa=='xa':cmdvalues.append(['xaRecoveryAuthAlias', jaas_name])
# creates
verbose('DataSource template listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
verbose('DataSource' + datasrc_attrs.name + ' creating using template.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
ds = AdminConfig.createUsingTemplate('DataSource', provider, 'name', datasrc_attrs.name, dtmpl)
AdminConfig.modify(ds, cmdvalues)
verbose('DataSource:' + datasrc_attrs.name + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
if datasrc_node.hasNode('properties'):self.inProps(datasrc_node.getNode('properties')[0], datasrc_attrs.provider, name, indent=indent + 3*' ')
def rmvDatasrc(self, name=None, prefix=None, indent=None):
scope_id, scope_attrs, scope=self.getScope()
verbose('DataSource listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
ds=getStartByNameAsDict(split( AdminConfig.list('DataSource', scope_id) ))
for dname in ds.keys():
if prefix!=None and dname.startswith(prefix) \
or prefix==None and name!=None and name==dname \
or prefix==None and name==None:
verbose('DataSource:' + dname + ' removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
AdminConfig.remove(ds[dname])
verbose('DataSource:' + dname + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
def inJaas(self, jaas_attrs, prefix=None, indent=None):
self_funct='inJaas'
if prefix==None:name=jaas_attrs.name
else:name=prefix + '_' + jaas_attrs.name
if jaas_attrs.create == 'false':return name
self.rmvJaas(name=jaas_attrs.name, prefix=prefix, indent=indent)
if jaas_attrs.user==None or jaas_attrs.password==None:raise xception.kikonfActionSystemException(self, self_funct, 'Tag: jaas, because Attribute "create" is false, Attributes user and password must be guiven !')
cmdvalues=[]
cmdvalues.append(['alias', name])
if jaas_attrs.desc!=None:description=['description', jaas_attrs.desc]
else:description=['description', DESIGN_NOTICE]
cmdvalues.append(['userId', jaas_attrs.user])
cmdvalues.append(['password', jaas_attrs.password])
verbose('Security retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
security = AdminConfig.getid('/Cell:' + self.getCell() + '/Security:/')
verbose('JAASAuthData:' + name + ' creating.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
jaasAlias = AdminConfig.create('JAASAuthData', security, cmdvalues)
verbose('JAASAuthData:' + name + ' with name:' + jaas_attrs.user + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
return name
def rmvJaas(self, name=None, prefix=None, indent=None):
verbose('JAASAuthData listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
as=split(AdminConfig.list("JAASAuthData"))
for a in as:
aname=AdminConfig.showAttribute(a, "alias")
if prefix!=None and aname.startswith(prefix) \
or prefix==None and name!=None and name==aname:
# or prefix==None and name==None: not allowed to destroy all
verbose('JAASAuthData:' + aname + ' removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
AdminConfig.remove(a)
verbose('JAASAuthData:' + aname + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
def inProps(self, node, provider, datasrc, indent=None):
props={}
for prop_node in node.getNodes():
dct=prop_node.getdAttrs()
props[dct['name']]=dct['value']
if len(props)!=0:
self.rmvProps(provider, datasrc, upds=props.keys(), indent=indent) #-- destroy first
verbose('JDBCProvider retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
pset=AdminConfig.getid(self.getScopeCP() + '/JDBCProvider:' + provider + '/DataSource:' + datasrc + '/J2EEResourcePropertySet:/')
for prop in props.keys():
verbose('J2EEResourceProperty:' + prop + ' creating.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
AdminConfig.create('J2EEResourceProperty', pset, [['name', prop],['value', props[prop]]])
verbose('J2EEResourceProperty:' + prop + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
def rmvProps(self, provider, datasrc, upds=None, indent=None):
if upds==None:return
verbose('J2EEResourceProperty retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
ps = getStartByNameAsDict(split( AdminConfig.getid(self.getScopeCP() + '/JDBCProvider:' + provider + '/DataSource:' + datasrc + '/J2EEResourcePropertySet:/J2EEResourceProperty:/') ))
for pname in ps.keys():
if pname in upds:
verbose('J2EEResourceProperty:' + pname + ' removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
AdminConfig.remove(ps[pname])
verbose('J2EEResourceProperty:' + pname + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
def verbose(self, scope_attrs, name=None, prefix=None):
scope=str(scope_attrs).replace("'", '')[1:-1]
if name!=None and prefix!=None:verbose('DataSource:' + name + ', under prefix:' + prefix+ ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
elif name!=None:verbose('DataSource:' + name + ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
elif prefix!=None:verbose('DataSources under prefix:' + prefix + ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
else:verbose('DataSources at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
## Copyright (c) 2008, Patrick Germain Placidoux
## All rights reserved.
##
## This file is part of Kikonf Public Software.
##
## Kikonf Public Software is released under the modified BSD License,
## which should accompany it or any part of it in the file "COPYING".
## If you do not have this file you can access the license
## through the WWW at http://www.kikonf.org/license/bsd/license.txt.
##
## Home: http://www.kikonf.org
## Contact: kikonf@gmx.com
from actions.was.tools import *
class Datasrc(wasAction):
DATASRC=\
{
'db2': {
'notxa': 'DB2 Universal JDBC Driver DataSource(templates/system|jdbc-resource-provider-templates.xml#DataSource_DB2_UNI_1)',
'xa': 'DB2 Universal JDBC Driver XA DataSource(templates/system|jdbc-resource-provider-templates.xml#DataSource_DB2_UNI_2)',
},
'oracle_5': {
'notxa': 'Oracle JDBC Driver DataSource(templates/system|jdbc-resource-provider-templates.xml#DataSource_ora_5)',
},
'oracle_6': {
'xa': 'Oracle JDBC Driver XA DataSource(templates/system|jdbc-resource-provider-templates.xml#DataSource_ora_6)',
},
'msql': {
'notxa': 'WebSphere embedded ConnectJDBC for SQL Server DataSource(templates/system|jdbc-resource-provider-templates.xml#DataSource_DD_3)',
'xa': 'WebSphere embedded ConnectJDBC for SQL Server XA DataSource(templates/system|jdbc-resource-provider-templates.xml#DataSource_DD_4)',
}
}
def extract(self, scope_attrs, name=None, prefix=None, doRaise=True, **keywords):
self_funct='extract'
from actions.was.jdbc.by.kikonf import jdbc
self.verbose(scope_attrs, name=name, prefix=prefix)
scope_id, scope_attrs, scope=self.getScope(scope_attrs=scope_attrs, indent=self.getIndent())
indent=self.getIndent() + 3*' '
verbose('DataSource retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
ds=split( AdminConfig.getid(self.getScopeCP() + '/JDBCProvider:/DataSource:/') )
for d in ds:
datasrcs=getShowAsDict(AdminConfig.show(d))
dname=datasrcs['name']
if not (prefix!=None and name!=None and dname==prefix + '_' + name \
or prefix==None and name!=None and name==dname \
or prefix!=None and name==None and dname.startswith(prefix) \
or prefix==None and name==None):continue
verbose('DataSource:' + dname + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
if datasrcs.has_key('description') and datasrcs['description']!=None:desc=datasrcs['description']
else:desc=None
if desc==DESIGN_NOTICE:desc=None
jndi_name=datasrcs['jndiName']
provider=AdminConfig.showAttribute(datasrcs['provider'], 'name')
try:
ptype=jdbc.getProviderType(datasrcs['provider'], self)
if ptype==None:raise
if ptype.startswith('oracle'):ptype='oracle'
except:
verbose('DataSource:' + dname + ', not managed provider: ' + AdminConfig.showAttribute(datasrcs['provider'], 'name') + '. Skipped !', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
continue
verbose('JDBCProvider:' + provider + ' with type:' + ptype + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
statement_cache_size=datasrcs['statementCacheSize']
datasrc_node=self.newTop() #-- because in extract mode, each call returns a new blank top node.
_name=dname
if prefix!=None:_name=dname.split(prefix + '_')[1]
datasrc_node.setAttrs(name=_name, desc=desc, jndi_name=jndi_name, provider=provider, dbtype=ptype, statement_cache_size=statement_cache_size, prefix=prefix)
mkNodeScope(datasrc_node, scope_attrs, isUnique=True) #-- creates a scope node.
jaas_name=datasrcs['authDataAlias']
propset=datasrcs['propertySet']
jaas=None
verbose('JAASAuthData listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
as=split( AdminConfig.list("JAASAuthData") )
for a in as:
aname=AdminConfig.showAttribute(a, "alias")
if jaas_name==aname:
jaas=a
break
if jaas==None:
if doRaise:raise xception.kikonfActionSystemException(self, self_funct, 'Tag: jaas, Unable to retreive JAAS Alias named:' + jaas_name + ' !')
else:verbose('Tag: jaas, Unable to retreive JAAS Alias named:' + jaas_name + ' !', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
user=password='?'
else:
user = AdminConfig.showAttribute(jaas, 'userId')
verbose('JAASAuthData:' + aname + ' with user:' + user + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
try:
password=self.getPwdFromJAAS(aname)
except:password='???'
_name=aname
if prefix!=None:_name=aname.split(prefix + '_')[1]
desc=AdminConfig.showAttribute(jaas, 'description')
if desc!=None:desc=desc[1:-1]
if desc==DESIGN_NOTICE:desc=None
jaas_node=datasrc_node.newNode('jaas', name=_name, user=user, password=password, create='true', desc=desc)
connection_pool_node=datasrc_node.newNode('connection_pool') # Tag: connection_pool
indent=self.getIndent() + 3*' '
getConnectionPoolAttrs(datasrcs['connectionPool'], connection_pool_node, level=self.getVerbose(), indent=indent, logFile=self.getLogFile())
rps = split( AdminConfig.showAttribute(datasrcs['propertySet'], 'resourceProperties') ) # Tag: properties
properties_node=datasrc_node.newNode('properties')
properties=jdbc.Jdbc.DRIVERS[ptype]['pset']
for rp in rps:
for property in properties:
if rp.startswith(property):
value=AdminConfig.showAttribute(rp, 'value');
properties_node.newNode('property', name=property, value=value)
def remove(self, no_name, no_name_no_prefix):
datasrc_node=self.getTop()
datasrc_attrs = datasrc_node.getAttrs()
scope_id, scope_attrs, scope=self.getScope(parent_node=datasrc_node, indent=self.getIndent()) #-- Retreives scope
self.verbose(scope_attrs, name=datasrc_attrs.name, prefix=datasrc_attrs.prefix)
indent=self.getIndent() + 3*' '
# no_name/no_name_no_prefix
prefix=datasrc_attrs.prefix
name=datasrc_attrs.name
if no_name or no_name_no_prefix:name=None
if no_name_no_prefix:prefix=None
# remove all at prefix if present.
self.rmvDatasrc(name=name, prefix=prefix, indent=indent)
if datasrc_node.hasNode('jaas'):
jaas_node=datasrc_node.getNode('jaas')[0]
jaas_attrs = jaas_node.getAttrs()
if jaas_attrs.create == 'true':self.rmvJaas(name=jaas_attrs.name, prefix=datasrc_attrs.prefix, indent=indent) # not allowed to destroy all.
def inject(self):
self_funct='inject'
datasrc_node = self.getTop()
datasrc_attrs = datasrc_node.getAttrs()
scope_id, scope_attrs, scope=self.getScope(parent_node=datasrc_node, indent=self.getIndent()) #-- Retreives scope
from actions.was.jdbc.by.kikonf import jdbc
indent=self.getIndent() + 3*' '
self.rmvDatasrc(name=datasrc_attrs.name, prefix=datasrc_attrs.prefix, indent=indent) #-- Destroy all first
#-- name
if datasrc_attrs.prefix==None:name=datasrc_attrs.name
else:name=datasrc_attrs.prefix + '_' + datasrc_attrs.name
self.verbose(scope_attrs, name=name, prefix=datasrc_attrs.prefix)
if datasrc_node.hasNode('jaas'):
jaas_node=datasrc_node.getNode('jaas')[0]
jaas_attrs = jaas_node.getAttrs()
jaas_name=self.inJaas(jaas_attrs, datasrc_attrs.prefix, indent=indent)
else:raise xception.kikonfActionSystemException(self, self_funct, 'Tag: jaas, is required !')
verbose('JDBCProvider retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
provider = AdminConfig.getid(self.getScopeCP()+'/JDBCProvider:' + datasrc_attrs.provider)
if provider in ('', None):raise xception.kikonfActionSystemException(self, self_funct, 'Unable to retreive provider:' + datasrc_attrs.provider + '!')
verbose('JDBCProvider:' + provider + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
dbtype=datasrc_attrs.dbtype
if AdminConfig.showAttribute(provider, 'xa')=='true':
isxa='xa'
if dbtype=='oracle':dbtype+='_6'
else:
isxa='notxa'
if dbtype=='oracle':dbtype+='_5'
if not Datasrc.DATASRC[dbtype].has_key(isxa):raise xception.kikonfActionSystemException(self, self_funct, 'This dbtype:' + datasrc_attrs.dbtype + 'do not support this xa mode:' + iswa + ' !')
dtmpl=Datasrc.DATASRC[dbtype][isxa]
cmdvalues=[]
cmdvalues.append(['name', name])
cmdvalues.append(['jndiName', datasrc_attrs.jndi_name])
if datasrc_attrs.desc!=None:cmdvalues.append(['description', datasrc_attrs.desc])
else:cmdvalues.append(['description', DESIGN_NOTICE])
cmdvalues.append(['authDataAlias', jaas_name])
cmdvalues.append(['statementCacheSize', datasrc_attrs.statement_cache_size])
if datasrc_node.hasNode('connection_pool'):
conpool_node=datasrc_node.getNode('connection_pool')[0]
cmdvalues.append(['connectionPool', getConnectionPoolCfgs(conpool_node, level=self.getVerbose(), indent=indent, logFile=self.getLogFile())])
if isxa=='xa':cmdvalues.append(['xaRecoveryAuthAlias', jaas_name])
# creates
verbose('DataSource template listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
verbose('DataSource' + datasrc_attrs.name + ' creating using template.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
ds = AdminConfig.createUsingTemplate('DataSource', provider, 'name', datasrc_attrs.name, dtmpl)
AdminConfig.modify(ds, cmdvalues)
verbose('DataSource:' + datasrc_attrs.name + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
if datasrc_node.hasNode('properties'):self.inProps(datasrc_node.getNode('properties')[0], datasrc_attrs.provider, name, indent=indent + 3*' ')
def rmvDatasrc(self, name=None, prefix=None, indent=None):
scope_id, scope_attrs, scope=self.getScope()
verbose('DataSource listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
ds=getStartByNameAsDict(split( AdminConfig.list('DataSource', scope_id) ))
for dname in ds.keys():
if prefix!=None and dname.startswith(prefix) \
or prefix==None and name!=None and name==dname \
or prefix==None and name==None:
verbose('DataSource:' + dname + ' removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
AdminConfig.remove(ds[dname])
verbose('DataSource:' + dname + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
def inJaas(self, jaas_attrs, prefix=None, indent=None):
self_funct='inJaas'
if prefix==None:name=jaas_attrs.name
else:name=prefix + '_' + jaas_attrs.name
if jaas_attrs.create == 'false':return name
self.rmvJaas(name=jaas_attrs.name, prefix=prefix, indent=indent)
if jaas_attrs.user==None or jaas_attrs.password==None:raise xception.kikonfActionSystemException(self, self_funct, 'Tag: jaas, because Attribute "create" is false, Attributes user and password must be guiven !')
cmdvalues=[]
cmdvalues.append(['alias', name])
if jaas_attrs.desc!=None:description=['description', jaas_attrs.desc]
else:description=['description', DESIGN_NOTICE]
cmdvalues.append(['userId', jaas_attrs.user])
cmdvalues.append(['password', jaas_attrs.password])
verbose('Security retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
security = AdminConfig.getid('/Cell:' + self.getCell() + '/Security:/')
verbose('JAASAuthData:' + name + ' creating.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
jaasAlias = AdminConfig.create('JAASAuthData', security, cmdvalues)
verbose('JAASAuthData:' + name + ' with name:' + jaas_attrs.user + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
return name
def rmvJaas(self, name=None, prefix=None, indent=None):
verbose('JAASAuthData listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
as=split(AdminConfig.list("JAASAuthData"))
for a in as:
aname=AdminConfig.showAttribute(a, "alias")
if prefix!=None and aname.startswith(prefix) \
or prefix==None and name!=None and name==aname:
# or prefix==None and name==None: not allowed to destroy all
verbose('JAASAuthData:' + aname + ' removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
AdminConfig.remove(a)
verbose('JAASAuthData:' + aname + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
def inProps(self, node, provider, datasrc, indent=None):
props={}
for prop_node in node.getNodes():
dct=prop_node.getdAttrs()
props[dct['name']]=dct['value']
if len(props)!=0:
self.rmvProps(provider, datasrc, upds=props.keys(), indent=indent) #-- destroy first
verbose('JDBCProvider retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
pset=AdminConfig.getid(self.getScopeCP() + '/JDBCProvider:' + provider + '/DataSource:' + datasrc + '/J2EEResourcePropertySet:/')
for prop in props.keys():
verbose('J2EEResourceProperty:' + prop + ' creating.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
AdminConfig.create('J2EEResourceProperty', pset, [['name', prop],['value', props[prop]]])
verbose('J2EEResourceProperty:' + prop + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
def rmvProps(self, provider, datasrc, upds=None, indent=None):
if upds==None:return
verbose('J2EEResourceProperty retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
ps = getStartByNameAsDict(split( AdminConfig.getid(self.getScopeCP() + '/JDBCProvider:' + provider + '/DataSource:' + datasrc + '/J2EEResourcePropertySet:/J2EEResourceProperty:/') ))
for pname in ps.keys():
if pname in upds:
verbose('J2EEResourceProperty:' + pname + ' removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
AdminConfig.remove(ps[pname])
verbose('J2EEResourceProperty:' + pname + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
def verbose(self, scope_attrs, name=None, prefix=None):
scope=str(scope_attrs).replace("'", '')[1:-1]
if name!=None and prefix!=None:verbose('DataSource:' + name + ', under prefix:' + prefix+ ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
elif name!=None:verbose('DataSource:' + name + ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
elif prefix!=None:verbose('DataSources under prefix:' + prefix + ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
else:verbose('DataSources at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
(Source: <KIKONF_INSTALLATION_DIR>/plugins/actions/was/datasrc/by/kikonf/datasrc.py)
- Line 1 to 3 say something , say something , say something
- Line 10 to 17 say something , say something , say something , say something , say something
- Line 20 to 25 say something
Trademarks :
- "Python" is a registered trademark of the Python Software Foundation.
- "IBM", "WebSphere MQ", "WebSphere", "WebSphere Aplication Server", "WAS", "Db2" and "AIX" are registred trademarks of International Business Machines Corporation.
- "oracle", "MySql", "Java" and "JVM" are a registred trademarks of Oracle and/or its affiliates.
- "Linux" is a trademark registred to Linus Torvalds
- "MS SQL Server" is a registred trademark of Microsoft Corporation.
- "IBM", "WebSphere", "WebSphere Aplication Server", "WAS" are registred trademarks of International Business Machines Corporation.
- "Java" and "JVM" are a registred trademarks of Oracle and/or its affiliates.
- Other names may be trademarks of their respective owners.
|