WLST script to add DataSource and DBAdapter EIS Connection Factory

Michel Schildmeijer 5
0 0
Read Time:3 Minute, 51 Second

Creating a EIS ConnectionFactory in your Database Adapter can be done with the WebLogic Administration Console, but of course this is also “scriptable”. What I needed was a script that created a Data Source with EIS Connection factory bound to the specific datasource.

First I created a properties file, let’s call it DsCf.properties. Everything between <> should be replaced with your own values:

# Propertie file for creating datasource and EIS DB Adapter
# Created by Michel Schildmeijer
# Domain settings
domainname="<your WLS DOMAIN>"
adminurl=<WLS HOST:Admin Port>
adminusername=weblogic
adminpassword=<passwd weblogic>
#datasource settings
datasourcename=<Name DataSource>
datasourcedatabasename=<database>
datasourcetarget=<targeted manaegd server>
datasourcefilename= datasourcename + '.xml'
datasourcejndiname= 'jdbc/' + datasourcename
datasourcedriverclass=oracle.jdbc.OracleDriver
datasourceurl=jdbc:oracle:thin:@<db host>:1521:<db sid>
datasourceusername=<db user>
datasourcepassword=<db user password
datasourcetestquery=SQL SELECT * FROM DUAL
#EIS Connection Factory settings
connfactname=eis/DB/<Connection factory Name>

Second, I created a WLST script to execute these properties and added the DataSource and ConnectionFactory. See the script below.

When running on a UNIX or linux system, navigate to the WLS DOMAIN DIR /bin( Specified during domaincreation) like /app/oracle/middleware/user_projects/domains/<Your domain>/bin and run

./setDomainEnv.sh

After this you are able to deploy the DataSource en ConnectionFactory:

java weblogic.WLST loadProperties DsCf.properties

After finished you can check in the WebLogic Admin Console to see:

  • If datasource is created
  • If in your outbound connections of the database adapter the EIS connection factory with binding to the DataSource has been created.

Script DsCf.py

 

import os
import time
domainName = domainname
adminURL= adminurl
adminUserName= adminusername
adminPassword= adminpassword
dsName= datasourcename
dsFileName= datasourcefilename
dsDatabaseName=datasourcedatabasename
datasourceTarget=datasourcetarget
dsJNDIName=datasourcejndiname
dsDriverName=datasourcedriverclass
dsURL=datasourceurl
dsUserName=datasourceusername
dsPassword=datasourcepassword
dsTestQuery=datasourcetestquery
connect(adminUserName, adminPassword, adminURL)
TargetServerName='soa_server1'
edit()
startEdit()
cd('/')
cmo.createJDBCSystemResource(dsName)
cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName)
cmo.setName(dsName)
cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDataSourceParams/' + dsName )
set('JNDINames',jarray.array([String('jdbc/' + dsName )], String))
cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName )
cmo.setUrl(dsURL)
cmo.setDriverName( dsDriverName )
cmo.setPassword(dsPassword)
cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCConnectionPoolParams/' + dsName )
cmo.setTestTableName(dsTestQuery)
cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName )
cmo.createProperty('user')
cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName + '/Properties/user')
cmo.setValue(dsUserName)
cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName )
cmo.createProperty('databaseName')
cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName + '/Properties/databaseName')
cmo.setValue(dsDatabaseName)
cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDataSourceParams/' + dsName )
cmo.setGlobalTransactionsProtocol('OnePhaseCommit')
cd('/SystemResources/' + dsName )
set('Targets',jarray.array([ObjectName('com.bea:Name=' + datasourceTarget + ',Type=Server')], ObjectName))
save()
activate()
print 'Data source ' + dsName + ' configured'

#Connect
#appPath='/app/oracle/middleware/soa11g/soa/connectors/DbAdapter.rar'
#planPath='/app/oracle/middleware/soa11g/soa/connectors/DbAdapterPlanGenerated.xml'
oracleHome = os.environ.get(“ORACLE_HOME”)
appPath= oracleHome + 'soa/connectors/DbAdapter.rar'
planPath=oracleHome + 'soa/connectors/DbAdapterPlanGenerated.xml'

CFName=connfactname
dsName=datasourcename
appName='DbAdapter'
moduleOverrideName=appName+'.rar'
moduleDescriptorName='META-INF/weblogic-ra.xml'
def makeDeploymentPlanVariable(wlstPlan, name, value, xpath, origin='planbased'):
while wlstPlan.getVariableAssignment(name, moduleOverrideName, moduleDescriptorName):
wlstPlan.destroyVariableAssignment(name, moduleOverrideName, moduleDescriptorName)
while wlstPlan.getVariable(name):
wlstPlan.destroyVariable(name)
variableAssignment = wlstPlan.createVariableAssignment( name, moduleOverrideName, moduleDescriptorName )
variableAssignment.setXpath( xpath )
variableAssignment.setOrigin( origin )
wlstPlan.createVariable( name, value )
             def main():
                     connect(adminUserName, adminPassword, adminURL)
                     edit()
                           try:
                           startEdit()
                           planPath = get('/AppDeployments/DbAdapter/PlanPath')
                           print '__ Using plan ' + planPath
                           myPlan=loadApplication(appPath, planPath)
                           print '___ BEGIN change plan'
                           makeDeploymentPlanVariable(myPlan, 'ConnectionInstance_' '+ CFName' +'_JNDIName_abc123XXX','+ CFName', '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ CFName + '"]/jndi-name')
                           makeDeploymentPlanVariable(myPlan, 'ConfigProperty_xADataSourceName_'+ dsName +'_abc123XXX',dsName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ CFName + '"]/connection-properties/properties/property/[name="xADataSourceName"]/value')
                           print '___ DONE change plan'
                           myPlan.save();
                           save();
                           activate(block='true');
                           cd('/AppDeployments/DbAdapter/Targets');

                           redeploy(appName, planPath,targets=cmo.getTargets());
                           print 'EIS Connection factory ' + CFName + 'using' + dsName + ' configured';
                    except:
                           stopEdit('y')
main()


About Post Author

Michel Schildmeijer

Started in pharmacy, I made the change to IT in 1996. I am an Oracle Fusion Middleware Architect at AMIS, with focus on technical infrastructure, Serverside solutions, installing, administering, configuring the Oracle Fusion Middleware stack. My experience is from integrations at telco´s using Oracle AIA, Oracle Portal, OID, Forms&Reports, Discoverer upto the latest Oracle WebLogic 11g releases with practically all Oracle products running on top of it
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

5 thoughts on “WLST script to add DataSource and DBAdapter EIS Connection Factory

  1. Hi,
    I’m new to this WLST script. I’m trying to do this.
    BTW, you have provided the Python script in this article but I’m confused where to keep this script and how to run.
    Please clarify.

    Thanks,
    Kamal

  2. Hi Edwin
    Thanks for you input
    About the hard paths
    You als could set the paths in you property file instead of the run script
    First get the ORACLE_HOME thats been set
    oracleHome = os.environ.get(“ORACLE_HOME”)
    And add this to you plan and app path:
    appPath= oracleHome + ‘/soa/connectors/DbAdapter.rar’

    planPath=oracleHome + ‘/soa/connectors/DbAdapterPlanGenerated.xml’
    About specific connectionfactory settings, it depends on wht you want to create with it. I’ll try to extend it with more options later on.
     


     

  3. Hi,
    great post, I was always wondering if it is possible. but it would be great to make it more flexible and add some warnings
    like
    appPath='/app/oracle/middleware/soa11g/soa/connectors/DbAdapter.rar'
    planPath='/app/oracle/middleware/soa11g/soa/connectors/DbAdapterPlanGenerated.xml'

    this is a hard path to your soa env and also has a DB plan with a hard value.
    And second you can only add the XA Datasource property , sometimes you need to add the datasource or set transacted.
    but I make some ANT macrodefs and use it in my scripts, also do this for AQ and JMS and make it more flexible.
    Keep up the good work.
     
     
     
     
     

Comments are closed.

Next Post

Fusion Middleware 11gR1 - Patch Set 5 is available (at last) - First impressions

It had been announced at Oracle Open World 2011 and sort of promised for December 2011 – a promise or at least a suggestion reiterated in early December even. But for whatever reason, it slipped – not shipped – and Christmas break that perfect time of the year for playing […]
%d bloggers like this: