WLST script to add DataSource and DBAdapter EIS Connection Factory html

WLST script to add DataSource and DBAdapter EIS Connection Factory

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()


5 Comments

  1. Kamal June 22, 2012
  2. Michel Schildmeijer February 20, 2012
  3. Edwin Biemond February 19, 2012
  4. Edwin Biemond February 19, 2012
  5. Website Designing Jaipur India February 17, 2012