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







Ra

print

Action : was.ra   (Category : was, Name : ra, By : kikonf)
Complete Name : was.ra.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 ra plugin : Configure a Resource Adaptor

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

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 Ra(wasAction):
    
    TYPES={'cics':'ECIResourceAdapter', 'ims':'IMSResourceAdapter', 'sib':'SIBResourceAdapter'}
    CRITICAL_PROPERTIES={
        'cics':['ConnectionURL', 'ServerName', 'UserName', 'TranName', 'TPNName'],
        'ims':['DataStoreName', 'HostName', 'PortNumber', 'UserName', 'Password'],
        'sib':['UserName', 'Password', 'BusName']
    }

    def extract(self, scope_attrs=None, name=None, prefix=None, **keywords):
        self_funct='extract'
        scope_id, scope_attrs, scope=self.getScope(scope_attrs=scope_attrs, indent=self.getIndent())
        self.verbose(scope_attrs, name=name, prefix=prefix)
        indent=self.getIndent() + 3*' '

        verbose('J2CResourceAdapter retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())        
        ras=getStartByNameAsDict(split( AdminConfig.getid(self.getScopeCP() + '/J2CResourceAdapter:/') ))
        for raname in ras.keys():

            if prefix!=None and name!=None and raname==prefix + '_' + name \
            or prefix==None and name!=None and raname==name \
            or prefix!=None and name==None and raname.startswith(prefix) \
            or prefix==None and name==None:
            
                verbose('J2CResourceAdapter:' + raname + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())                
                radaptors=getShowAsDict(AdminConfig.show(ras[raname]))
                
                ra_type=None
                desc = radaptors['description'][1:-1]
                
                if desc.startswith('type:'):desc=desc.split('type:')[1].split('/')[0]
                if desc in Ra.TYPES.keys():ra_type=desc
                else:
                    print indent + 'Unmanaged Resource Adapter type for:' + raname + ', Managed types are:' + str(Ra.TYPES) + '. Properties will be skipped !'
                    continue
                
                ra_node=self.newTop()                                           # Tag: ra
                
                _name=raname
                if prefix!=None:_name=raname.split(prefix + '_')[1]
                attrs={'name':_name, 'ra_type':ra_type, 'ra_archive_path':radaptors['archivePath'], 'prefix':prefix}
                ra_node.setAttrs(**attrs)
                
                mkNodeScope(ra_node, scope_attrs, isUnique=True)                # tag: scope
                
                self.extJcf(ra_node, raname, ra_type=ra_type, prefix=prefix, indent=self.getIndent() + 3*' ')

    def remove(self, no_name, no_name_no_prefix):
        self_funct='inJcf'
        ra_node = self.getTop()        
        ra_attrs = ra_node.getAttrs()
        scope_id, scope_attrs, scope=self.getScope(parent_node=ra_node, indent=self.getIndent()) #-- Retreives scope
        self.verbose(scope_attrs, ra_attrs.name, prefix=ra_attrs.prefix)
        indent=self.getIndent() + 3*' '
        
        # no_name/no_name_no_prefix
        prefix=ra_attrs.prefix        
        name=ra_attrs.name
        if no_name or no_name_no_prefix:name=None
        if no_name_no_prefix:prefix=None

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

        if ra_attrs.prefix==None:name=ra_attrs.name
        else:name=ra_attrs.prefix + '_' + ra_attrs.name 
                
        ra=AdminConfig.getid(self.getScopeCP() + '/J2CResourceAdapter:' + name + '/')
        
        # -- installing rar file on guiven Node.
        if ra_attrs.ra_force=='true' and (ra_attrs.ra_path==None or ra_attrs.ra_archive_path==None):raise xception.kikonfActionSystemException(self, self_funct, 'Attribute "ra_file" must be provided when "ra_force" is true !')
        if  ra_attrs.ra_path!=None:
            if ra_attrs.ra_force=='true' or (ra_attrs.ra_force=='false' and ra==''):
                self.rmvRa(name=ra_attrs.name, prefix=ra_attrs.prefix, indent=indent)            

                verbose('J2CResourceAdapter:' + name + '  installing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())

                cde="-nodeName " + scope_attrs['node'] + ' -rarPath ' + ra_attrs.ra_path + ' -rar.name ' + name + ' -rar.desc ' + '"type:' + ra_attrs.ra_type + '/kikonf mark:Please do not delete this text !"  -rar.archivePath ' + ra_attrs.ra_archive_path
                ra=AdminTask.installResourceAdapter(cde)
                verbose('J2CResourceAdapter:' + name + '  installed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())

                # -- creating J2C Resource Adaptor using rar file.
                ra_archive_path=AdminConfig.showAttribute(ra, "archivePath")
                cmdvalues=[]
                cmdvalues.append(["name", name])
                cmdvalues.append(["archivePath", ra_attrs.ra_archive_path])
                
                verbose('J2CResourceAdapter creating.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
                AdminConfig.createUsingTemplate("J2CResourceAdapter", scope_id, cmdvalues, ra)
                verbose('J2CResourceAdapter:' + name + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())                
                
        if ra=='':raise xception.kikonfActionSystemException(self, self_funct, 'Unable to find resource Adaptor:' + name + ', ra_path and ra_archive_path should be given, in order to create the absent Resource adapor !')

        if ra_node.hasNode('jcfs') and ra_node.getNode('jcfs')[0].hasNode('jcf'):
            jcfs=ra_node.getNode('jcfs')[0].getNode('jcf')
            for jcf_node in jcfs:
                jcf_attrs=jcf_node.getAttrs()
                self.rmvJcf(name=jcf_attrs.name, prefix=ra_attrs.prefix, provider=name, indent=indent)
            for jcf_node in jcfs:self.inJcf(jcf_node, name, prefix=ra_attrs.prefix, indent=indent + 3*' ')
        
    def rmvRa(self, name, prefix=None, indent=None):
        verbose('J2CResourceAdapter retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        ras=getStartByNameAsDict(split( AdminConfig.getid(self.getScopeCP() + '/J2CResourceAdapter:/') ))
        
        for raname in ras.keys():
            
            if prefix!=None and raname.startswith(prefix) \
            or prefix==None and name!=None and name==raname \
            or prefix==None and name==None:

                self.rmvJcf(provider=raname, indent=indent)
                verbose('J2CResourceAdapter removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
                AdminConfig.remove(ras[raname])
                verbose('J2CResourceAdapter:' + raname + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())                

    def inJcf(self, jcf_node, provider, prefix=None, indent=None):
        self_funct='inJcf'
        jcf_attrs = jcf_node.getAttrs()        
        if prefix==None:name=jcf_attrs.name
        else:name=prefix + '_' + jcf_attrs.name
        
        jcf_attrs=jcf_node.getAttrs()
        
        # -- retreive ra
        verbose('J2CResourceAdapter retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        ra = AdminConfig.getid(self.getScopeCP() + '/J2CResourceAdapter:' + provider)
        if ra=='':raise xception.kikonfActionSystemException(self, self_funct, 'Resource adaptor named:' + str(ra_name) + ' is not configured !')

        # -- create jcf
        cmdvalues=[]
        cmdvalues.append(["name", name])
        cmdvalues.append(["jndiName", jcf_attrs.jndi_name])
        
        # --  connection pool
        if jcf_node.hasNode('connection_pool'):            
            conpool_node=jcf_node.getNode('connection_pool')[0]
            
            cmdvalues.append(['connectionPool', getConnectionPoolCfgs(conpool_node, level=self.getVerbose(), indent=indent + 3*' ', logFile=self.getLogFile())])

        # --  ConnectionDefinition
        fis=[]
        found=None
        cds=split(AdminConfig.list('ConnectionDefinition', ra))
        if len(cds)==0:raise xception.kikonfActionSystemException(self, self_funct, 'No Factory Interface found for Resource Adaptor:' + provider + '.')
        for cd in cds:
            fi=AdminConfig.showAttribute(cd, 'connectionFactoryInterface')
            fis.append(fi)
            if jcf_attrs.factory_interface!=None and jcf_attrs.factory_interface==fi:found=cd

        if found==None and jcf_attrs.factory_interface==None and len(cds)==1:found=cds[0]
        
        if found==None:
            mes_your_fi=''
            if jcf_attrs.factory_interface!=None:mes_your_fi='Your Factory Interface:' + jcf_attrs.factory_interface
            raise xception.kikonfActionSystemException(self, self_funct, 'No matching Factory Interface found for Connection Factory:' + name + '. ' + mes_your_fi + '. Supported Factory Interfaces for Resource Adaptor:' + provider + ' are:' + str(fis) + ' !')

        cmdvalues.append(['connectionDefinition', found])

        verbose('J2CConnectionFactory:' + name + ' creating.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        jcf=AdminConfig.create("J2CConnectionFactory", ra, cmdvalues)
        verbose('J2CConnectionFactory:' + name + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())                            
            
        if jcf_node.hasNode('properties'):self.inProps(jcf_node.getNode('properties')[0], provider, name, indent=indent)
        
    def rmvJcf(self, name=None, prefix=None, provider=None, indent=None):
        verbose('J2CResourceAdapter retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        cfs=getStartByNameAsDict(split( AdminConfig.getid(self.getScopeCP() + '/J2CResourceAdapter:' + provider + '/J2CConnectionFactory:/') ))

        for cname in cfs.keys():
            
            if prefix!=None and cname.startswith(prefix) \
            or prefix==None and name!=None and name==cname \
            or prefix==None and name==None:
            
                verbose('J2CConnectionFactory:' + cname + ' removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
                AdminConfig.remove(cfs[cname])
                verbose('J2CConnectionFactory:' + cname + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())                

    def extJcf(self, parent_node, provider, ra_type=None, prefix=None, indent=None):
        self_funct='extJcf'
        verbose('J2CResourceAdapter retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        jcfs=split(AdminConfig.getid(self.getScopeCP() + '/J2CResourceAdapter:' + provider + '/J2CConnectionFactory:/'))        
        
        if len(jcfs)>0:jcfs_node=parent_node.newNode('jcfs')
        for jcf in jcfs:
            typ=None
            confacts=getShowAsDict(AdminConfig.show(jcf))
            name=confacts['name']
            
            # -- factory_interface
            cd=confacts['connectionDefinition']
            factory_interface=AdminConfig.showAttribute(cd, 'connectionFactoryInterface')

            # -- jcf
            _name=name
            if prefix!=None:_name=name.split(prefix + '_')[1]
            attrs={'name':_name, 'jndi_name':confacts['jndiName'], 'factory_interface':factory_interface}
            jcf_node=jcfs_node.newNode('jcf', **attrs)

            # -- connection pool
            connection_pool_node=jcf_node.newNode('connection_pool')
            indent=indent+3*' '
            getConnectionPoolAttrs(confacts['connectionPool'], connection_pool_node, level=self.getVerbose(), indent=indent, logFile=self.getLogFile())
            
            # -- properties
            self.extProps(jcf_node, ra_type, provider, name, indent=indent)
            
            # Note : This shows J2C Activation Specs
            # AdminConfig.list('J2CActivationSpec', self.getScope())

    def inProps(self, node, provider, jcf_name, indent=None):
        self_funct='inProps'
        
        # xml props
        props={}
        l=node.getNodes()
        for prop_node in l:
            prop_attrs=prop_node.getAttrs()
            props[prop_attrs.name]=prop_attrs.value
            
        # was conf props
        verbose('J2CResourceAdapter retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        ps=getStartByNameAsDict(split( AdminConfig.getid(self.getScopeCP() + '/J2CResourceAdapter:' + provider + '/J2CConnectionFactory:' + jcf_name + '/J2EEResourcePropertySet:/J2EEResourceProperty:/') ))
        
        for property in props.keys():
            if property not in ps.keys():raise  xception.kikonfActionSystemException(self, self_funct, 'Unmanaged property:' + property + ', do not exist into the property list of the connection factory:' + jcf_name + ' ! Applowed properties are:' + str(ps.keys()) + ' !')
            
            verbose('Properties modifying.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
            AdminConfig.modify(ps[property], 'value', props[property])
            verbose('Property:' + property + ' modified.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
            
    def extProps(self, parent_node, ra_type, provider, jcf_name, indent=None):
        self_funct='extProps'
        if ra_type==None:return
        properties_node=parent_node.newNode('properties')
            
        # was conf props
        verbose('J2CResourceAdapter retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        ps=split(AdminConfig.getid(self.getScopeCP() + '/J2CResourceAdapter:' + provider + '/J2CConnectionFactory:' + jcf_name + '/J2EEResourcePropertySet:/J2EEResourceProperty:/'))
        ps=getStartByNameAsDict(ps)
        
        for property in Ra.CRITICAL_PROPERTIES[ra_type]:
            if property not in ps.keys():raise  xception.kikonfActionSystemException(self, self_funct, 'Unmanaged property:' + property + ', do not exist into the propertie list of the connection factory:' + jcf_name + ', for resource adaptor:' + provider + ' of type:' + ra_type + ' !')
            value=AdminConfig.showAttribute(ps[property], 'value')
            if value==None:continue
            properties_node.newNode('property', name=property, value=value)
            
    def verbose(self, scope_attrs, name=None, prefix=None):
        scope=str(scope_attrs).replace("'", '')[1:-1]
        
        if name!=None:verbose('J2CResourceAdapter:' + name + ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
        elif prefix!=None:verbose('J2CResourceAdapters under prefix:' + prefix + ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
        else:verbose('J2CResourceAdapters at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
							
(Source: <KIKONF_INSTALLATION_DIR>/plugins/actions/was/ra/by/kikonf/ra.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