Wednesday, August 8, 2018

Updating WebLogic Datasource properties WSLT Offline

When we have multiple environments for different releases, it is very common to change the weblogic database properties to point corresponding database. Instead of going to Weblogic console and doing it manually, it can be done using WSLT scripts offline quickly.
The below scripts and properties file is used to update the datasource properties.

/u01/scripts/update-datasource.py

from java.io import FileInputStream

propInputStream = FileInputStream("/u01/scripts/ds.properties")
configProps = Properties()
configProps.load(propInputStream)

dsnames= configProps.get("ds.names")

readDomain(configProps.get("domain.path"))
dsName=''
for member in dsnames:
if member == ",":
print 'updating the password for ' + dsName
cd('/JDBCSystemResource/'+dsName+'/JdbcResource/'+dsName+'/JDBCDriverParams/NO_NAME_0')
set('PasswordEncrypted', encrypt(configProps.get("ds."+dsName+".pwd")))
set('URL',configProps.get("ds."+dsName+".url"))
cd('Properties/NO_NAME_0')
cd('Property')
cd('user')
set('Value', configProps.get("ds."+dsName+".username"))
dsName=''
else:
dsName=dsName+member
updateDomain()
exit()


/u01/scripts/ds.properties
domain.path=/u01/oracle/user_projects/domains/base_domain

ds.names=appatg,appcat,appmarket,appnotme,
ds.appatg.username=STR01_ATGAPP
ds.appatg.pwd=tst1to5appusers
ds.appatg.url=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=zlt13574.vci.att.com)(PORT=1524)))(CONNECT_DATA=(SERVICE_NAME=t1c4d857)))

ds.appcat.pwd=catpwd
ds.appmarket.pwd=marketpwd
ds.appnotme.pwd=notmepwd

/u01/scripts/update-datasource.sh
#!/bin/bash
cd /u01/oracle/user_projects/domains/base_domain

/u01/oracle/wlserver/common/bin/wlst.sh /u01/scripts/ds.py
cd -

Execute the script:
$ /u01/scripts/update-datasources.sh


No comments:

Post a Comment