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()
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
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.
Â
Â
By the way Richard ( at the bottom of this link ) https://forums.oracle.com/forums/thread.jspa?threadID=1079094 Â made some great adjustments to this script
The above sample worked, but I changed 2 things.1. Load the existing plan that was used to update DbAdapter, and modify that plan2. when the variables aready exists in the script came in an infinete loop, so the variables and variable Assignments are deleted seperatly
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.
Â
Â
Â
Â
Â
Really an awesome blog to be appreciable, it covers some significant matters that are very helpful and needful.