Hi,
Here is a Simple WLST script which we can run to check whether the DataSource is running properly or not,. This WLSt script can also be set as part of a Scheduled CRON job in Unix based Operating Systems .. using mailx tool so that we will keep on getting E-Mails about the status of the DataSource:
NOTE: Before running the Below script we need to enable “Test Connect On Reserve” and provide the “Test Table Name” name for the DataSource.
NOTE: Make sure that in the connect() function you are passing the IP Address/HostName of the Server where the DataSource is actually targeted. In the below sample I targeted my DataSource to the AdminServer that’s why i am passing the AdminServer URL in the thrid argument of the connect() function.
TestDS.py (Beware in WLST scripts alignment is very important)
connect('weblogic', 'weblogic', 't3://localhost:7001') serverRuntime() dsMBeans = cmo.getJDBCServiceRuntime().getJDBCDataSourceRuntimeMBeans() ds_name = "myDataSourceName" for ds in dsMBeans: if (ds_name == ds.getName()): print 'DS name is: '+ds.getName() print 'State is ' +ds.getState() print ds.testPool()
Please run the “. ./setWLSEnv.sh” before running the above WLST
java weblogic.WLST /my/scripts/locations/TestDS.py
As an alternative you can also use “weblogic.Admin” utility to test the DataSources:
Example:
java weblogic.Admin -username weblogic -password weblogic -url t3://HostName:9001 TEST_POOL TestDataSource
.
.
Thanks
Jay SenSharma
April 27th, 2010 on 6:55 am
Please let me know if we can write the script to get the state of DS and resume it automatically or any parameter if available
Neha
April 27th, 2010 on 10:05 pm
Hi Neha,
You can use “weblogic.Admin” utility to Enable and Disable the Pool (DataSource):
To suspend:
java weblogic.Admin -url t3://localhost:7001 -username weblogic -password weblogic SUSPEND_POOL YourDataSourceName
To re-enable:
java weblogic.Admin -url t3://localhost:7001 -username weblogic -password weblogic RESUME_POOL YourDataSourceName
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
May 25th, 2010 on 7:30 am
This script doesn’t work if the Data Sources are targeted to cluster, right?. Is there any way to get the status of DS for each MS in cluster environment?
May 25th, 2010 on 9:05 pm
Hi Ranga,
The same script should work even if the DataSources are targeted to a Cluster. Did u try running this script in a Clustered Environment? While running it in Clustered Environment did u find any Issue? Please post the complete stacktrace.
Which version of WLS are u using…? I will try the same in the same WLS Version to reproduce the issue. I have tested it in 2 Different versions of WLS and i didnot find any issue.
Please update us with the error u are getting. It will help us in finding the root cause faster.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
December 8th, 2010 on 8:29 pm
The script is fine and bit clear. The only concern is the output of the testpool() method. It will print None unless we fetch the query and print the result. If we use default JDBC package and query “SELECT count( * ) FROM `systables`” to fetch data from default SYSTABLE the same result will be printed, unless we use fetchall() method.
Please try the below script and compare.
from com.ziclix.python.sql import zxJDBC
from dbexts import dbexts
con = zxJDBC.connect(“jdbc:mysql://localhost:3306/php”,
“weblogic”, “weblogic123”,
“com.mysql.jdbc.Driver”)
cursor = con.cursor()
cursor.execute(“SELECT count( * ) FROM `systables` WHERE 1”)
result=cursor.fetchall()
print result
Please share your comments!!
-Jaydeep
August 27th, 2012 on 6:43 pm
Jai,
In our env we have multiple datasource targeted to 5 mananged server.How can i use the above WLST script to achieve it.
January 14th, 2013 on 11:46 pm
Thanks for the script.
ds.testPool() gives me a very abstract message. Is there any other way to get more meaningful message?
Connection test failed with the following exception: java.lang.NullPointerException
Thanks in advance.
March 5th, 2013 on 3:09 am
Hi,
I just ran the above code..below are my two files that I used to run the script..I am not sure if the code did what I wanted..
TestDS.py
connect(‘weblogic’, ‘weblogic’, ‘t3://server:port’)
serverRuntime()
dsMBeans = cmo.getJDBCServiceRuntime().getJDBCDataSourceRuntimeMBeans()
ds_name = “DSNode1”
for ds in dsMBeans:
if (ds_name == ds.getName()):
print ‘DS name is: ‘+ds.getName()
print ‘State is ‘ +ds.getState()
print ds.testPool()
test.sh
#!/bin/sh
cd /home/wlserver_10.3/server/bin
. ./setWLSEnv.sh
java weblogic.WLST /ess/NewFolder/TestDS.py
when I ran the test.sh..below was the output
[dgfadm@admtae01 NewFolder]$ ./TestDatasource.sh
CLASSPATH=Class Path
PATH=Path
Your environment has been set.
Initializing WebLogic Scripting Tool (WLST) …
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
Connecting to t3://localhost:port with userid weblogic …
Successfully connected to Admin Server ‘AdminServer’ that belongs to domain ‘Domain’.
Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.
Location changed to serverRuntime tree. This is a read-only tree with ServerRuntimeMBean as the root.
For more help, use help(serverRuntime)
Does this mean it threw an error or there is some issue with the code?
Initially I am trying to test the status of one DataSource
I would also like to reset the Datasource if its down or in suspended state. when the Datasource is in suspended state is there any we can send an email using the script?
Thanks for your help..
May 24th, 2013 on 4:18 pm
Hi,
I’m able to check the status of data source using cmo.getState() but I want to print whether the datasource is enabled or not for below attribute
-r– Enabled true
Since it is a boolean value, I couldnt print it. Please suggest me here.
May 24th, 2013 on 4:45 pm
Hi Jaysen,
Please ignore my previous post. I can do it by get(‘Enabled’).. it returns “1” it means Enabled = true and if it returns 0 then it is false. Thank you
July 26th, 2013 on 2:28 am
Hi Jaysen,
Thank you for the script, it works good for me. But, how to test more than one data source (example: we have 30 data sources to test by using this script) how to do that.
Thanks,
Teja
July 27th, 2013 on 3:12 am
Hi Rene,
Thanks for your reply. I have tried running the script based on your previous response, but unable to get output.
connect(‘weblogic’, ‘welcome1’, ‘t3://localhost:7001’)
serverRuntime()
dataSources = cmo.getJDBCServiceRuntime().getJDBCDataSourceRuntimeMBeans()
if (len(dataSources) > 0):
for dataSource in dataSources:
if (dataSourcename == datasource.get(name)):
print ‘DS name is: ‘+dataSource.getName()
print ‘State is ‘ +dataSource.getState()
print dataSource.testPool()
errors: NameError: dataSourcename
Thanks,
Swaroop
September 3rd, 2013 on 1:25 am
HI Rene-
I am now successfully testing all the data sources for a managed server. Is there any way i can test the data sources for all the managed servers (ie., we have 4 SOA managed servers) at a time by using the script.
Thanks,
Swaroop