Pages

Thursday, May 21, 2015

Changing Weblogic Server Datasource configuration using WLST script in less than 1 minute!!!



Many occasion wherein we are administrating large number of WLS instance, we need to do repetitive tasks. In order to do these tasks we have one best option available with us; generate WLST python script and use the same to perform particular task in all environments.

Task could be anything such as log location change, datasource creation, datasource modification JMS module creation etc.

In this post I will demonstrate a simple WLST python script which will change Existing Datasource properties.

Below are three steps which required to perform this activity - 

1) ModifyDSConfig.properties - This is property file which contains datasources names and WLS server credentials. 

2) ModifyDSConfig.py - This is python script which contains all coding

3) Run ModifyDSConfig.py script – Need to run the ModifyDSConfig.py script and pass the ModifyDSConfig.properties path as an argument. 


ModifyDSConfig.properties –I have consider changing only few parameter values, but that could less or more depending up on each environment business requirement. Please modify the script and properties file as per your requirement.  


Using this script I will change below properties – 

Property Type
Property value
JDBC URL
jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname-SCAN)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=SOA11P)))
System Properties
oracle.jdbc.ReadTimeout=10000
oracle.net.CONNECT_TIMEOUT
Data source connection value
Initial Capacity:30
Maximum Capacity:30
Minimum Capacity:30
Timeout parameters
Statement Timeout:15
XA Transaction Timeout:0
Connection Reserve Timeout:10
Enable disable properties
Test Connections On Reserve=true
Set XA Transaction Timeout=true
Remove Infected Connections Enabled =true
Properties values
Seconds to Trust an Idle Pool Connection:10
Connection Creation Retry Frequency:10
Inactive Connection Timeout:35
ONS Config change
FAN Enabled =true
ONS Nodes = ONSHOST1:6200

ModifyDSConfig.properties file example values

USER="weblogic"
PASSWORD="xxxxx"
ADMIN_URL="t3://hostname.domain.com.au:7001"
DATASOURCES1 ={
                                                "NAME":"SOADataSource",
                                                "SERVICE_NAME":"SOA11AUA"
                                                }
DATASOURCES2 ={
                                                "NAME":"BAMDataSource",
                                                "SERVICE_NAME":"SOA11UAT"
                                                }
DATASOURCE_ARRAY=(DATASOURCES1,DATASOURCES2)


ModifyDSConfig.py script definition –

import sys
#read properties file

if len(sys.argv) != 2:
    print "Invalid Arguments :: Usage CreateDataSource.py <DataSource Properties file>"
    exit()
try:
    print "Load properties file"
    properties=sys.argv[1]
    file=open(properties,'r')
    print "Read properties file"
    exec file
    print "Execute properties file"
    file.close
except:
    exit()

connect(USER,PASSWORD,ADMIN_URL)
edit()
server='AdminServer'
cd("Servers/"+server)
target=cmo

for dataSource in DATASOURCE_ARRAY:
   
            dsName=dataSource['NAME']
            print 'This Datasource Properties will be changed : ',dsName
            srvName=dataSource['SERVICE_NAME']
            print 'Service Name used for this DataSource : ',srvName
           
            startEdit()
            cd('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCDriverParams/'+dsName+'')
            cmo.setUrl('URL=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=Hostname-SCAN)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME='+srvName+'))')
           
            cd('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCDriverParams/'+dsName+'/Properties/'+dsName+'')
            try:
                        cmo.createProperty('oracle.jdbc.ReadTimeout')
            except:
                        pass
           
            cd('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCDriverParams/'+dsName+'/Properties/'+dsName+'/Properties/oracle.jdbc.ReadTimeout')
            cmo.setSysPropValue('10000')
           

            cd('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCDriverParams/'+dsName+'/Properties/'+dsName+'')
            try:
                        cmo.createProperty('oracle.net.READ_TIMEOUT')
            except:
                        pass
                       
            cd('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCDriverParams/'+dsName+'/Properties/'+dsName+'/Properties/oracle.net.READ_TIMEOUT')
            cmo.setSysPropValue('1000')

            cd('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCConnectionPoolParams/'+dsName+'')
            cmo.setMaxCapacity(30)
            cmo.setMinCapacity(30)
            cmo.setInitialCapacity(30)

            cd('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCConnectionPoolParams/'+dsName+'')
            cmo.setConnectionReserveTimeoutSeconds(10)
            cmo.setInactiveConnectionTimeoutSeconds(35)
            cmo.setStatementTimeout(10)
            cmo.setRemoveInfectedConnections(true)
            cmo.setConnectionCreationRetryFrequencySeconds(10)
            cmo.setSecondsToTrustAnIdlePoolConnection(10)
            cmo.setTestConnectionsOnReserve(true)
            cmo.setTestTableName('SQL SELECT 1 FROM DUAL\r\n')

            cd('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCXAParams/'+dsName+'')
            cmo.setXaSetTransactionTimeout(true)

            cd('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCOracleParams/'+dsName+'')
            cmo.setFanEnabled(true)
            cmo.setOnsNodeList('ONSHOST1:6200\r\nONSHOST2:6200\r\n')

            try:
                        activate()
                       
            except:       
                        undo(defaultAnswer='y')
exit(defaultAnswer='y')         

Run the Script-

/u01/app/oracle/product/fmw/wlserver_10.3/common/bin/wlst.sh /u01/app/oracle /ModifyDS/ModifyDSConfig.py /u01/app/oracle/ModifyDS/ModifyDSConfig.properties

Verify the Datasource from WLS console-


I hope this post will help to all administrator to fasten the configuration of WLS Datasource change.