Creating a Data Source via WLST Offline

Peter Lorenzen
22/02-2013

I have been messing around with silent install of FMW and creating domains via WLST. I was initially trying to get as much as possible done via offline WLST and therefore wanted to create a Data Source. I could not find any examples online which was a bit puzzling since there are lots of online WLST scripts around. I now realize that this is because it is a bit more complicated to do offline :-) When you do it online a lot of things gets created for you while you have to create everything yourself if is offline.

I am not sure if I will keep trying to do everything offline, but here is some WLST that creates a Data Source offline.

print 'create wlsbjmsrpDataSource'
create('wlsbjmsrpDataSource', 'JDBCSystemResource')
cd('/JDBCSystemResource/wlsbjmsrpDataSource')
set('Target','AdminServer,osb_server1')

cd('/JDBCSystemResource/wlsbjmsrpDataSource/JdbcResource/wlsbjmsrpDataSource')
cmo.setName('wlsbjmsrpDataSource')

print 'create JDBCDataSourceParams'
cd('/JDBCSystemResource/wlsbjmsrpDataSource/JdbcResource/wlsbjmsrpDataSource')
create('myJdbcDataSourceParams','JDBCDataSourceParams')
cd('JDBCDataSourceParams/NO_NAME_0')
set('JNDIName', java.lang.String('wlsbjmsrpDataSource'))
set('GlobalTransactionsProtocol', java.lang.String('None'))

print 'create JDBCDriverParams'
cd('/JDBCSystemResource/wlsbjmsrpDataSource/JdbcResource/wlsbjmsrpDataSource')
create('myJdbcDriverParams','JDBCDriverParams')
cd('JDBCDriverParams/NO_NAME_0')
set('DriverName','oracle.jdbc.OracleDriver')
set('URL','jdbc:oracle:thin:@wintermute:1521:mysid')
set('PasswordEncrypted', 'manager')
set('UseXADataSourceInterface', 'false')

print 'create JDBCDriverParams Properties'
create('myProperties','Properties')
cd('Properties/NO_NAME_0')
create('user','Property')
cd('Property')
cd('user')
set('Value', 'scott')

print 'create JDBCConnectionPoolParams'
cd('/JDBCSystemResource/wlsbjmsrpDataSource/JdbcResource/wlsbjmsrpDataSource')
create('myJdbcConnectionPoolParams','JDBCConnectionPoolParams')
cd('JDBCConnectionPoolParams/NO_NAME_0')
set('TestTableName','SQL SELECT 1 FROM DUAL')

{ 4 comments… read them below or add one }

Lin, Ren June 27, 2014 at 07:11

Hi,

I also have a similar python script to add a data source using WLST offline. But I got exception here:

Error: only getter and setter are supported
Error: cd() failed. Do dumpStack() to see details.
Problem invoking WLST – Traceback (innermost last):
File “/home/liren/ocsg_express/noDB_install/user_projects/domains/base_domain/bin/createDataSource.py”, line 34, in ?
File “/tmp/WLSTOfflineIni2390475154009476767.py”, line 39, in cd
at com.oracle.cie.domain.script.jython.CommandExceptionHandler.handleException(CommandExceptionHandler.java:56)
at com.oracle.cie.domain.script.jython.WLScriptContext.handleException(WLScriptContext.java:2469)
at com.oracle.cie.domain.script.jython.WLScriptContext.cd(WLScriptContext.java:1258)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)

com.oracle.cie.domain.script.jython.WLSTException: com.oracle.cie.domain.script.jython.WLSTException: java.lang.UnsupportedOperationException: Could not create generic operation:JDBCResource

Below is my python script:
==============================================================

from java.io import FileInputStream

propInputStream = FileInputStream(“details.properties”)
configProps = Properties()
configProps.load(propInputStream)

domainName=configProps.get(“domain.name”)
adminUserName=configProps.get(“admin.userName”)
adminPassword=configProps.get(“admin.password”)

#Datasource name
dsName=configProps.get(“datasource.name”)
dsName2=configProps.get(“datasource2.name”)

dsDatabaseName=configProps.get(“datasource.database.name”)
datasourceTarget=configProps.get(“datasource.target”)

dsJNDIName=configProps.get(“datasource.jndiname”)
dsJNDIName2=configProps.get(“datasource2.jndiname”)

dsDriverName=configProps.get(“datasource.driver.class”)
dsDriverName2=configProps.get(“datasource2.driver.class”)

dsURL=configProps.get(“datasource.url”)
dsUserName=configProps.get(“datasource.username”)
dsPassword=configProps.get(“datasource.password”)
dsTestQuery=configProps.get(“datasource.test.query”)

readDomain(domainName)

#——————-Create wlng-jdbc————————————————#
cd(‘/’)
cmo.createJDBCSystemResource(dsName)
cd(‘/JDBCSystemResources/’ + dsName + ‘/JDBCResource/’ + dsName)
cmo.setName(dsName)

cd(‘/JDBCSystemResources/’ + dsName + ‘/JDBCResource/’ + dsName + ‘/JDBCDataSourceParams/’ + dsName )
set(‘JNDINames’,jarray.array([String(dsJNDIName)], String))

cd(‘/JDBCSystemResources/’ + dsName + ‘/JDBCResource/’ + dsName + ‘/JDBCDriverParams/’ + dsName )
cmo.setUrl(dsURL)
cmo.setDriverName( dsDriverName2 )
cmo.setPassword(dsPassword)

cd(‘/JDBCSystemResources/’ + dsName + ‘/JDBCResource/’ + dsName + ‘/JDBCConnectionPoolParams/’ + dsName )
cmo.setTestTableName(dsTestQuery)
cmo.setMaxCapacity(150)
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 + ‘;create=true’)

cd(‘/JDBCSystemResources/’ + dsName + ‘/JDBCResource/’ + dsName + ‘/JDBCDataSourceParams/’ + dsName )
cmo.setGlobalTransactionsProtocol(‘TwoPhaseCommit’)

cd(‘/SystemResources/’ + dsName )
set(‘Targets’,jarray.array([ObjectName(‘com.bea:Name=’ + datasourceTarget + ‘,Type=Server’)], ObjectName))

#——————-Create wlng-local-jdbc————————————————#

cd(‘/’)
cmo.createJDBCSystemResource(dsName2)
cd(‘/JDBCSystemResources/’ + dsName2 + ‘/JDBCResource/’ + dsName2)
cmo.setName(dsName2)

cd(‘/JDBCSystemResources/’ + dsName2 + ‘/JDBCResource/’ + dsName2 + ‘/JDBCDataSourceParams/’ + dsName2 )
set(‘JNDINames’,jarray.array([String(dsJNDIName2)], String))

cd(‘/JDBCSystemResources/’ + dsName2 + ‘/JDBCResource/’ + dsName2 + ‘/JDBCDriverParams/’ + dsName2 )
cmo.setUrl(dsURL)
cmo.setDriverName( dsDriverName )
cmo.setPassword(dsPassword)

cd(‘/JDBCSystemResources/’ + dsName2 + ‘/JDBCResource/’ + dsName2 + ‘/JDBCConnectionPoolParams/’ + dsName2 )
cmo.setTestTableName(dsTestQuery)
cmo.setMaxCapacity(150)
cd(‘/JDBCSystemResources/’ + dsName2 + ‘/JDBCResource/’ + dsName2 + ‘/JDBCDriverParams/’ + dsName2 + ‘/Properties/’ + dsName2 )
cmo.createProperty(‘user’)

cd(‘/JDBCSystemResources/’ + dsName2 + ‘/JDBCResource/’ + dsName2 + ‘/JDBCDriverParams/’ + dsName2 + ‘/Properties/’ + dsName2 + ‘/Properties/user’)
cmo.setValue(dsUserName)

cd(‘/JDBCSystemResources/’ + dsName2 + ‘/JDBCResource/’ + dsName2 + ‘/JDBCDriverParams/’ + dsName2 + ‘/Properties/’ + dsName2 )
cmo.createProperty(‘databaseName’)

cd(‘/JDBCSystemResources/’ + dsName2 + ‘/JDBCResource/’ + dsName2 + ‘/JDBCDriverParams/’ + dsName2 + ‘/Properties/’ + dsName2 + ‘/Properties/databaseName’)
cmo.setValue(dsDatabaseName + ‘;create=true’)

cd(‘/JDBCSystemResources/’ + dsName2 + ‘/JDBCResource/’ + dsName2 + ‘/JDBCDataSourceParams/’ + dsName2 )
cmo.setGlobalTransactionsProtocol(‘none’)

cd(‘/SystemResources/’ + dsName2 )
set(‘Targets’,jarray.array([ObjectName(‘com.bea:Name=’ + datasourceTarget + ‘,Type=Server’)], ObjectName))

updateDomain()
closeDomain()

exit()

========================================================

Can you please help on this? Thx!

Peter Lorenzen June 27, 2014 at 12:14

Hi Lin,
When you use offline WLST you are limited in which methods you can call. Even though some menthols works in online WLST they are not allowed in offline WLST. You can have a look here:
http://docs.oracle.com/middleware/1212/wls/WLSTG/domains.htm#i1008951
Regards Peter

Lin, Ren July 1, 2014 at 02:33

Hi Peter,

Thanks very much for your comments! I’ve got what I want.

Thanks again!

Lin

Iman July 3, 2014 at 02:23

YOU the MAN. very nice. and it works perfectly.

Leave a Comment

Previous post:

Next post: