cle_clock
Home > wikikonf >  was/actions/by kikonf > jdbc







Jdbc

print

Action : was.jdbc   (Category : was, Name : jdbc, By : kikonf)
Complete Name : was.jdbc.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 jdbc plugin : Creates one JDBC provider

The following shows the main Source Code File for the Action : was.jdbc

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 Jdbc(wasAction):
    DRIVERS=\
        {
            'db2': {
                'notxa':    ('DB2 Universal JDBC Driver Provider Only(templates/system|jdbc-resource-provider-only-templates.xml#JDBCProvider_DB2_UNI_1)', 'com.ibm.db2.jcc.DB2ConnectionPoolDataSource'),
                'xa':       ('DB2 Universal JDBC Driver Provider Only (XA)(templates/system|jdbc-resource-provider-only-templates.xml#JDBCProvider_DB2_UNI_2)', 'com.ibm.db2.jcc.DB2XADataSource'),
                'vname':   'DB2_JDBC_DRIVER_PATH',
                'pset' : ('databaseName', 'serverName', 'portNumber', 'driverType', 'currentSchema')
            },

            'oracle_5': {
                'notxa':    ('Oracle JDBC Driver Provider Only(templates/system|jdbc-resource-provider-only-templates.xml#JDBCProvider_Oracle_5)', 'oracle.jdbc.pool.OracleConnectionPoolDataSource'),
                'vname':   'ORACLE_JDBC_DRIVER_PATH',
                'pset' : ('URL',)
            },
            
            'oracle_6': {
                'xa':       ('Oracle JDBC Driver (XA)(templates/system|jdbc-resource-provider-templates.xml#JDBCProvider_Oracle_6)', 'oracle.jdbc.xa.client.OracleXADataSource'),
                'vname':   'ORACLE_JDBC_DRIVER_PATH',
                'pset' : ('URL',)
            },
            
            'msql': {
                'notxa':    ('WebSphere embedded ConnectJDBC driver for MS SQL Server Provider Only(templates/system|jdbc-resource-provider-only-templates.xml#JDBCProvider_DataDirect_1a)', 'com.ibm.websphere.jdbcx.sqlserver.SQLServerDataSource'),
                'xa':       ('WebSphere embedded ConnectJDBC driver for MS SQL Server Provider Only (XA)(templates/system|jdbc-resource-provider-only-templates.xml#JDBCProvider_DataDirect_2a)', 'com.ibm.websphere.jdbcx.sqlserver.SQLServerDataSource'),
                'vname':    'MSSQLSERVER_JDBC_DRIVER_PATH',
                'pset' : []
            },
        }


    def extract(self, scope_attrs, name=None, prefix=None, doRaise=True, **keywords):
        self_funct='extract'
        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('JDBCProvider listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        pvs=getStartByNameAsDict(split( AdminConfig.list('JDBCProvider', scope_id) ))

        for jname in pvs.keys(): 

            if not (prefix!=None and name!=None and jname==prefix + '_' + name \
            or prefix==None and name!=None and name==jname \
            or prefix!=None and name==None and jname.startswith(prefix) \
            or prefix==None and name==None):continue
            verbose('JDBCProvider:' + jname + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())            

            providers=getShowAsDict(AdminConfig.show(pvs[jname]))
            
            try:
                ptype=getProviderType(pvs[jname], self)
            except:
                verbose('Unmanaged provider:' + jname + ' found, skipping !', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
                continue

            xa=providers['xa']
            
            if providers.has_key('description') and providers['description']!=None:desc=providers['description'][1:-1]
            else:desc=None
            if desc==DESIGN_NOTICE:desc=None
            
            #-- path
            path='?'
            vname=Jdbc.DRIVERS[ptype]['vname']            
            if prefix!=None:vname=prefix + '_' + vname            
            verbose('VariableSubstitutionEntry listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
            vars = split(AdminConfig.list('VariableSubstitutionEntry', scope_id))
            
            for var in vars:
                var_name = AdminConfig.showAttribute(var, 'symbolicName')
                if vname==var_name:path=AdminConfig.showAttribute(var, "value")
                
            if path=='?':verbose('Unable to retreive WebSphere variable named: ' + vname + ' at scope: ' + str(scope_attrs) + ' ! keep going on.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
        
            jdbc_node=self.newTop()                                             # Tag: jdbc
            _name=jname
            if prefix!=None:_name=jname.split(prefix + '_')[1]
            attrs={'name':_name, 'desc':desc, 'path':path, 'prefix':prefix}
            jdbc_node.setAttrs(**attrs)

            mkNodeScope(jdbc_node, scope_attrs, isUnique=True) #-- creates a scope node.

            cp=providers['classpath']                                                 # Tags: oracle, db2, msql
            l=cp.split(';')
            from os import path
            jars=';'.join([path.basename(p) for p in l])
            if ptype.startswith('oracle'):version=ptype[-1]=='true'
            else:version=''

            if ptype.startswith('oracle'):
                jdbc_node.newNode('oracle', version=ptype[-1], jars=jars)
            else:
                jdbc_node.newNode(ptype, xa=xa, jars=jars)

    def remove(self, no_name, no_name_no_prefix):
        self_funct='remove'
        jdbc_node = self.getTop()        
        jdbc_attrs = jdbc_node.getAttrs()
        scope_id, scope_attrs, scope=self.getScope(parent_node=jdbc_node, indent=self.getIndent()) #-- Retreives scope
        self.verbose(scope_attrs, name=jdbc_attrs.name, prefix=jdbc_attrs.prefix)
        indent=self.getIndent() + 3*' '

        # no_name/no_name_no_prefix
        prefix=jdbc_attrs.prefix        
        name=jdbc_attrs.name
        if no_name or no_name_no_prefix:name=None
        if no_name_no_prefix:prefix=None

        self.rmvProvider(name=name, prefix=prefix, indent=indent)
            
    def inject(self):
        self_funct='inject'
        jdbc_node = self.getTop()        
        jdbc_attrs = jdbc_node.getAttrs()
        scope_id, scope_attrs, scope=self.getScope(parent_node=jdbc_node, indent=self.getIndent()) #-- Retreives scope
        self.verbose(scope_attrs, name=jdbc_attrs.name, prefix=jdbc_attrs.prefix)
        indent=self.getIndent() + 3*' '

        self.rmvProvider(name=jdbc_attrs.name, prefix=jdbc_attrs.prefix, indent=indent) #-- Removing first
        
        #-- name
        if jdbc_attrs.prefix==None:jname=jdbc_attrs.name
        else:jname=jdbc_attrs.prefix + '_' + jdbc_attrs.name
        
        #-- Check unique node:
        keys=Jdbc.DRIVERS.keys()
        driver_nodes=list()
        l=jdbc_node.getNodes()
        for driver_node in l:
            if driver_node.getTag() in keys or driver_node.getTag()=='oracle':driver_nodes.append(driver_node)
            
        if len(driver_nodes)==0:raise xception.kikonfActionSystemException(self, self_funct, 'At least one node of: "oracle", "db2" or "msql" tag is required !')    
        elif len(driver_nodes)>1:raise xception.kikonfActionSystemException(self, self_funct, 'Only one node of: "oracle", "db2" or "msql" tag is allowed !')    
        
        #-- Several variables
        driver_node=driver_nodes[0]
        driver_attrs=driver_node.getAttrs()
        tag=driver_node.getTag()
        
        cmdvalues=[]

        if tag=='oracle':                                                       # Tag: oracle
            #-- Oracle 5 driver
            if driver_attrs.version==5:                                       # Attribute: oracle/version          
                vname=Jdbc.DRIVERS[tag + '_5']['vname']
                ptmpl=Jdbc.DRIVERS[tag + '_5']['notxa'][0]                      
            else:                                                               # Other Tags: db2, msql
                #-- Oracle 6 driver
                vname=Jdbc.DRIVERS[tag + '_6']['vname']
                ptmpl=Jdbc.DRIVERS[tag + '_6']['xa'][0]
        else:
            #-- Other drivers
            vname=Jdbc.DRIVERS[tag]['vname']
            if driver_attrs.xa=='true':
                ptmpl=Jdbc.DRIVERS[tag]['xa'][0] # Attribute: /xa
            else:
                ptmpl=Jdbc.DRIVERS[tag]['notxa'][0]

        cmdvalues.append(['name', jname])
        
        if jdbc_attrs.desc!=None:cmdvalues.append(['description', jdbc_attrs.desc])
        else:cmdvalues.append(['description', DESIGN_NOTICE])

        spl=driver_attrs.jars.split(';')
        
        if driver_attrs.jars.find(',')>=0:raise xception.kikonfActionSystemException(self, self_funct, 'Tag:' + tag + ', Incorrrect Attribute: jars. ";" are not allowed. Only "," are allowed. Your value:' + driver_attrs.jars + ' !')
        bp='${' + vname + '}/'
        cp = bp + (';' + bp).join(driver_attrs.jars.split(';'))                 # Attribute: /jars
        cmdvalues.append(['classpath', cp])
        cmdvalues.append(['nativepath', ''])

        # Creates
        verbose('JDBCProvider creating using template.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        AdminConfig.createUsingTemplate("JDBCProvider", scope_id, cmdvalues, ptmpl)
        verbose('JDBCProvider:' + jname + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
    
        #-- Adjusts var Driver path
        self.inVar(vname, jdbc_attrs.path, jdbc_attrs.prefix, indent=self.getIndent() + 3*' ')
        
    def rmvProvider(self, name=None, prefix=None, indent=None):
        scope_id, scope_attrs, scope=self.getScope()
        verbose('JDBCProvider listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        jds=getStartByNameAsDict(split(AdminConfig.list('JDBCProvider', scope_id)))

        for jdname in jds.keys():
            if prefix!=None and jdname.startswith(prefix) \
            or prefix==None and name!=None and jdname==name \
            or prefix==None and name==None:

                #-- retreiving ptype
                try:
                    ptype=getProviderType(jds[jdname], self)
                    ptfound=True
                except:
                    verbose('Unmanaged provider:' + jdname + ' no var entry to remove !', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
                    ptfound=False
            
                verbose('JDBCProvider:' + jdname + ' removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
                AdminConfig.remove(jds[jdname])
                verbose('JDBCProvider:' + jdname + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
                
                if ptfound:
                    vname=Jdbc.DRIVERS[ptype]['vname']
                    self.rmvVar(vname, prefix=prefix, indent=self.getIndent() + 3*' ')
    
    def inVar(self, name, value, prefix=None, indent=None):                    # Attribute: path
        if prefix==None:name=name
        else:name=prefix + '_' + name
        cmdvalues=[]
        cmdvalues.append(['symbolicName', name])
        cmdvalues.append(['value', value])

        verbose('VariableMap retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        varmap = AdminConfig.getid(self.getScopeCP() + '/VariableMap:/')
        
        verbose('VariableMap modifying.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        AdminConfig.modify(varmap, 'entries', [cmdvalues])    
        verbose('VariableMap:' + name + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
        
    def rmvVar(self, name, prefix=None, indent=None):
        scope_id, scope_attrs, scope=self.getScope()
        verbose('VariableSubstitutionEntry listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())         
        vars = split(AdminConfig.list('VariableSubstitutionEntry', scope_id))

        for var in vars:
            vname = AdminConfig.showAttribute(var, 'symbolicName')
            
            if prefix!=None and vname.startswith(prefix) \
            or prefix==None and name!=None and vname==name:
                verbose('VariableSubstitutionEntry:' + vname + ' removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
                AdminConfig.remove(var)
                verbose('VariableSubstitutionEntry:' + vname + ' 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('JDBCProvider:' + name + ', under prefix:' + prefix + ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
        elif name!=None:verbose('JDBCProvider:' + name + ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
        elif prefix!=None:verbose('JDBCProviders under prefix:' + prefix + ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
        else:verbose('JDBCProviders at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())

def getProviderType(pv, action): 
    self_funct='getProviderType'
    
    found=False
    ic=AdminConfig.showAttribute(pv, 'implementationClassName')
    for db in Jdbc.DRIVERS.keys():

        if Jdbc.DRIVERS[db].has_key('notxa') and ic==Jdbc.DRIVERS[db]['notxa'][1]:
            found=True
            break
        if Jdbc.DRIVERS[db].has_key('xa') and ic==Jdbc.DRIVERS[db]['xa'][1]:
            found=True
            break
        
    if found:return db
    else:raise xception.kikonfActionSystemException(action, 'Main', self_funct, 'Provider type not found for porvider:' + pv + '!')
							
(Source: <KIKONF_INSTALLATION_DIR>/plugins/actions/was/jdbc/by/kikonf/jdbc.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 :
  • "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.

Copyright © 2011 - Patrick Placidoux, Hélène Malamoud