0
votes

I'm trying to write a script to test all DataSources of a WebSphere Cell/Node/Cluster. While this is possible from the Admin Console a script is better for certain audiences.

So I found the following article from IBM https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/txml_testconnection.html which looks promising as it describles exactly what I need.

After having a basic script like:

ds_ids = AdminConfig.list("DataSource").splitlines()

for ds_id in ds_ids:
  AdminControl.testConnection(ds_id)

I experienced some undocumented behavior. Contrary to the article above the testConnection function does not always return a String, but may also throw a exception.

So I simply use a try-catch block:

try:
  AdminControl.testConnection(ds_id)
except: # it actually is a com.ibm.ws.scripting.ScriptingException
   exc_type, exc_value, exc_traceback = sys.exc_info()

now when I print the exc_value this is what one gets:

com.ibm.ws.scripting.ScriptingException: com.ibm.websphere.management.exception.AdminException: javax.management.MBeanException: Exception thrown in RequiredModelMBean while trying to invoke operation testConnection

Now this error message is always the same no matter what's wrong. I tested authentication errors, missing WebSphere Variables and missing driver classes. While the Admin Console prints reasonable messages, the script keeps printing the same meaningless message.

The very weird thing is, as long as I don't catch the exception and the script just exits by error, a descriptive error message is shown.

Accessing the Java-Exceptions cause exc_value.getCause() gives None. I've also had a look at the DataSource MBeans, but as they only exist if the servers are started, I quickly gave up on them.

I hope someone knows how to access the error messages I see when not catching the Exception.

thanks in advance

1

1 Answers

1
votes

After all the research and testing AdminControl seems to be nothing more than a convinience facade to some of the commonly used MBeans.

So I tried issuing the Test Connection Service (like in the java example here https://www.ibm.com/support/knowledgecenter/en/SSEQTP_8.5.5/com.ibm.websphere.base.doc/ae/cdat_testcon.html ) directly:

    ds_id = AdminConfig.list("DataSource").splitlines()[0]
    # other queries may be 'process=server1' or 'process=dmgr'
    ds_cfg_helpers = __wat.AdminControl.queryNames("WebSphere:process=nodeagent,type=DataSourceCfgHelper,*").splitlines()

    try:
        # invoke MBean method directly
        warning_cnt = __wat.AdminControl.invoke(ds_cfg_helpers[0], "testConnection", ds_id)
        if warning_cnt == "0":
            print = "success"
        else:
            print "%s warning(s)" % warning_cnt

    except ScriptingException as exc:
        # get to the root of all evil ignoring exception wrappers
        exc_cause = exc
        while exc_cause.getCause():
            exc_cause = exc_cause.getCause()
        print exc_cause

This works the way I hoped for. The downside is that the code gets much more complicated if one needs to test DataSources that are defined on all kinds of scopes (Cell/Node/Cluster/Server/Application).

I don't need this so I left it out, but I still hope the example is useful to others too.