Hi,

Jay SenSharma

Jay SenSharma

Here are two Simple WLST Scripts which helps us to Shutdown the DataSources and then start them back to the running state. Usually we need this kind of scripts when we have a schedule database maintenance and we want that our DataSource should be Shutdown to reduce the overhead on WebLogic Server … Once the Database comes up after the maintenance we can restart the DataSources back to the Normal Running state.
You can refer to the following Link to Quickly Create a DataSource Using Ant Script: http://middlewaremagic.com/weblogic/?p=1400

Step1). Create a Directory somewhere in your file system “C:stop_start_DataSources” .

Step2). Write the following WLST script “shutdownDataSource.py” inside “C:stop_start_DataSources”:

connect(‘weblogic’,'weblogic’,'t3://localhost:7001')
domainRuntime()
cd(‘ServerRuntimes/AdminServer/JDBCServiceRuntime/AdminServer/JDBCDataSourceRuntimeMBeans/TestDS’)
objectArray = jarray.array([], java.lang.Object)
stringArray = jarray.array([], java.lang.String)
invoke(’shutdown’, objectArray, stringArray)
exit()

Step3). Write the following WLST script “startDataSource.py” inside “C:stop_start_DataSources”:

connect(‘weblogic’,'weblogic’,'t3://localhost:7001')
domainRuntime()
cd(‘ServerRuntimes/AdminServer/JDBCServiceRuntime/AdminServer/JDBCDataSourceRuntimeMBeans/TestDS’)
objectArray = jarray.array([], java.lang.Object)
stringArray = jarray.array([], java.lang.String)
invoke(’start’, objectArray, stringArray)
exit()

Step5). Now run the “setWLSEnv.sh” or “setWLSEnv.cmd” file according to your operating system then run the WLST Script “shutdownDataSource.py”

Step6). Now u can verify from adminConsole that the DataSource is Shutdown…right now if you will try to test the DataSource (or if a Client will try to get a fresh connection from DataSource) then you will get the following Error:

weblogic.common.resourcepool.ResourceDisabledException: Data Source TestDS is not active, cannot allocate connections to applications
at weblogic.jdbc.common.internal.ConnectionPool.reserve(ConnectionPool.java:324)
at weblogic.jdbc.common.internal.ConnectionPool.reserve(ConnectionPool.java:316)
at weblogic.jdbc.common.internal.DataSourceRuntimeMBeanImpl.testPool(DataSourceRuntimeMBeanImpl.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)

Step7). Start the dataSource using the “startDataSource.py” WLST Script:

connect(‘weblogic’,'weblogic’,'t3://localhost:7001')
domainRuntime()
cd(‘ServerRuntimes/AdminServer/JDBCServiceRuntime/AdminServer/JDBCDataSourceRuntimeMBeans/TestDS’)
objectArray = jarray.array([], java.lang.Object)
stringArray = jarray.array([], java.lang.String)
invoke(’start’, objectArray, stringArray)
exit()

.
.
Thanks
Jay SenSharma

If you enjoyed this post, please considerleaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.