WLST script to create Gridlink data source in weblogic
This tutorial explains the approach to create Gridlink data source through WLST script in weblogic
Refer the below URL for details on Gridlink data source
https://www.albinsblog.com/2014/04/different-approaches-for-connecting.html
The below WLST script creates the Gridlink datasource with enabled configurations
Refer the below URL for details on Gridlink data source
https://www.albinsblog.com/2014/04/different-approaches-for-connecting.html
WLST Script
The below WLST script creates the Gridlink datasource with enabled configurations
GridLinkDataSource.properties
dbURL=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=dbhost1)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=dbhost2)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=SERVICENAME)))
connectionpool.test.query=SQL SELECT * FROM DUAL
connectionpool.driver.class=oracle.jdbc.OracleDriver
connectionpool.username=SOA_EAIOWNER
connectionpool.password=orasoa11g
connectionpool.initCapacity=10
connectionpool.maxCapacity=60
datasource.name=EAISOAMetadataSource
datasource.jndi.name=eai/ds/EAISOAMetadataSource
datasource.target=Servers/AdminServer
domain.AdminIP=localhost
domain.AdminPort=7201
domain.AdminPasswd=Albin123!
GridLinkDatasourceCreation.py
from java.io import FileInputStreamdef createGridLinkJDBCResources(configProps): edit() startEdit() server='AdminServer' cd("Servers/"+server) target=cmo cd("../..") print '=========================================' print 'Creating GridLink DataSource....' print '=========================================' dsTestQuery=configProps.get("connectionpool.test.query") dsDriverName=configProps.get("connectionpool.driver.class") cd('/') dbURL= configProps.get("dbURL") dsUserName = configProps.get("connectionpool.username") dsPassword = configProps.get("connectionpool.password") initCapacity = configProps.get("connectionpool.initCapacity") maxCapacity = configProps.get("connectionpool.maxCapacity") dsName = configProps.get("datasource.name") jndiname = configProps.get("datasource.jndi.name") datasourceTargets = configProps.get("datasource.target").split(",")print 'dsUserName',dsUserName print 'dsPassword',dsPassword print 'initCapacity',initCapacity print 'maxCapacity',maxCapacity print 'dsName',dsName print 'jndiname',jndiname print 'datasourceTargets',datasourceTargetsprint 'Creating DataSource: ',dsName,' ....' myResourceName = dsName jdbcSystemResource = create(myResourceName,"JDBCSystemResource") myFile = jdbcSystemResource.getDescriptorFileName() jdbcResource = jdbcSystemResource.getJDBCResource() jdbcResource.setName(myResourceName)# Create the DataSource Params dpBean = jdbcResource.getJDBCDataSourceParams() myName=jndiname dpBean.setJNDINames([myName]) dpBean.setGlobalTransactionsProtocol('TwoPhaseCommit') # Create the Driver Params drBean = jdbcResource.getJDBCDriverParams() drBean.setPassword(dsPassword) drBean.setUrl(dbURL) drBean.setDriverName(dsDriverName)#Create the Oracle params orapr=jdbcResource.getJDBCOracleParams() orapr.setFanEnabled(true) orapr.setOnsNodeList('node1:6200,node2:6200') propBean = drBean.getProperties() driverProps = Properties() driverProps.setProperty("user",dsUserName) e = driverProps.propertyNames() while e.hasMoreElements() : propName = e.nextElement() myBean = propBean.createProperty(propName) myBean.setValue(driverProps.getProperty(propName)) # Create the ConnectionPool Params ppBean = jdbcResource.getJDBCConnectionPoolParams() ppBean.setInitialCapacity(int(initCapacity)) ppBean.setMaxCapacity(int(maxCapacity)) ppBean.setTestConnectionsOnReserve(true) ppBean.setTestTableName('SQL SELECT 1 FROM DUAL')xaParams = jdbcResource.getJDBCXAParams() xaParams.setKeepXaConnTillTxComplete(1)# Add Target for datasourceTarget in datasourceTargets: print 'DataSourceTargets',datasourceTargets print 'DataSourceTarget',datasourceTarget if datasourceTarget=='': print '' else: jdbcSystemResource.addTarget(getMBean(datasourceTarget)) print 'DataSource: ',dsName,', has been created Successfully !!!' print '=========================================' save() activate()def main(): propInputStream1 = FileInputStream("GridLinkDataSource.properties") configProps = util.Properties() configProps.load(propInputStream1) adminURL='t3://'+configProps.get('domain.AdminIP')+':'+configProps.get('domain.AdminPort') adminUserName='weblogic' adminPassword=configProps.get("domain.AdminPasswd") connect(adminUserName, adminPassword, adminURL) createGridLinkJDBCResources(configProps); print 'Successfully created JDBC resources for SOACoreDomain'disconnect()main()
Script
https://github.com/techforum-repo/youttubedata/tree/master/scripts/wlst/GridLinkDatasourceCreation
Before executing the script, change the configurations as required.Change the ONS node details in the script.
Execute the script — <<Oracle_Home>>\oracle_common\common\bin\wlst.cmd GridLinkDatasourceCreation.py
After the successful execution of the script login to console and verify the Gridlink datasource created.
Hi Albin;
ReplyDeleteNice blogs and very good contents. I have never used silent configuration using wlst. first time i saw this and its really nice. I tried this script but getting issue on line number 83/84-
[oracle@retdb ~]$ java weblogic.WLST GridLinkDatasourceCreation.py GridLinkDataSource.properties
Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
Problem invoking WLST - Traceback (innermost last):
(no code object) at line 0
File "/home/oracle/GridLinkDatasourceCreation.py", line 83
print 'DataSourceTargets',datasourceTargets
^
SyntaxError: invalid syntax
***********************************************************
81 # Add Target
82 for datasourceTarget in datasourceTargets:
83 print 'DataSourceTargets',datasourceTargets
84 print 'DataSourceTarget',datasourceTarget
85 if datasourceTarget=='':
86 print ''
87 else:
88 jdbcSystemResource.addTarget(getMBean(datasourceTarget))
89
90
91 print 'DataSource: ',dsName,', has been created Successfully !!!'
92 print '========================================='
93
*****************************************************************************
I am very new and really dont understand more in wlst scripting. need your help to teat the same.
Please do the needful.
it is working when you edit GridLinkDatasourceCreation.py at the below place
Delete# Add Target
for datasourceTarget in datasourceTargets:
print 'DataSourceTargets',datasourceTargets
print 'DataSourceTarget',datasourceTarget
if datasourceTarget=='':
print ''
else:
jdbcSystemResource.addTarget(getMBean(datasourceTarget))
FYI Its just a few spaces that was causing the run time error.
Now I can create the Gridlink data source through WLST script thank you very much for precious experience. Find for more in here writing a white paper
ReplyDeletethanks a lot!
i need to pass dynamic values for intial capacity and maximun capacity
ReplyDeleteType help() for help on available commands
ReplyDeleteProblem invoking WLST - Traceback (innermost last):
(no code object) at line 0
File "/opt/soa/TA/SCRIPTS/Grid/GridLinkDatasourceCreation.py", line 82
print 'DataSourceTargets',datasourceTargets
^
SyntaxError: invalid syntax
Getting above Error .can anyone suggest here please below is code
# Add Target
for datasourceTarget in datasourceTargets:
print 'DataSourceTargets',datasourceTargets
print 'DataSourceTarget',datasourceTarget
if datasourceTarget=='':
print ''
else:
jdbcSystemResource.addTarget(getMBean(datasourceTarget))
Attached the working GridLinkDatasourceCreation.py script
DeleteThis comment has been removed by the author.
ReplyDeletehow we can parametried it for multiple grid dataosurces ..
ReplyDeletePlease help me on this ..
You can implement the approach followed here - https://www.albinsblog.com/2012/09/modifying-targets-of-jdbc-datasources.html
DeleteHi,
ReplyDeleteMai i know what value in the script is deciding it should be generic or grid
Thanks
Vipin Alakkadan
Hi
ReplyDeleteit is not creating the datasource .
wlst.sh /mypath/GridLinkDatasourceCreation.py
Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
even Not connecting to the admin console
Thanks