Suspend weblogic datasource on command line

2019-07-25 11:31发布

问题:

I was Wondering if there is anyway of suspending / resuming weblogic 10 jdbc datasources via the command line. I am aware that i can do this in the admin console, but because our app has many different datasources it is a bit of a pain.

The reason behind this is that our testers are doing error flow tests and have to simulate the db going down. Ideally i would like to give then a bat file for suspending all datasources and another one for resuming all datasources.

Any ideas?

Thanks

回答1:

You can use the WLST scripting to do that. From the command line, run $BEA_HOME/wlserver10.0/common/bin/wlst.sh (.cmd on Windows): Connect to the running server. Use the managed server port as this is a server runtime property:

wls:/offline> connect('weblogic','weblogic','t3://localhost:7002')

Go to the serverRuntime tree: wls:/mydomain/serverConfig> serverRuntime()

Navigate to the JDBCService, to your managed server name, the JDBCDataSource Runtime and finally to your datasource name:

wls:/mydomain/serverRuntime> cd('JDBCServiceRuntime/managedsrv1/JDBCDataSourceRuntimeMBeans/MyDS')

Then just suspend and resume it:

wls:/mydomain/serverRuntime/JDBCServiceRuntime/managedsrv1/JDBCDataSourceRuntimeMBeans/MyDS> cmo.suspend()
wls:/mydomain/serverRuntime/JDBCServiceRuntime/managedsrv1/JDBCDataSourceRuntimeMBeans/MyDS> cmo.resume()

use command ls() to see the the other variables and operations.



回答2:

You can record your script... might be easier than writing the batch file in some cases.

You can get help with the methods via javadocs.