WebSphere wsadmin testConnection错误消息



我正在尝试编写一个脚本来测试WebSphere单元/节点/群集的所有数据源。虽然从管理员控制台可以使用脚本,但对于某些受众来说更好。

所以我从IBM https://www.ibm.com/support/knowledgecenter/en/ssaw57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/txml_testconnection.html找到了以下文章有希望,因为它是我需要的。

拥有一个基本脚本之后:

ds_ids = AdminConfig.list("DataSource").splitlines()
for ds_id in ds_ids:
  AdminControl.testConnection(ds_id)

我经历了一些无证件的行为。与上面的文章相反,testConnection函数并不总是返回字符串,但也可能会引发例外。

所以我只使用一个try-catch块:

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

现在,当我打印exc_value时,这就是一个人:

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

现在,无论出什么问题,此错误消息始终是相同的。我测试了身份验证错误,缺少WebSphere变量和缺少驱动程序类。当管理控制台打印合理的消息时,脚本不断打印相同的毫无意义的消息。

非常奇怪的是,只要我不捕获异常,并且脚本只是通过错误退出,就会显示一个描述性错误消息。

访问Java-Exceptions导致exc_value.getCause()给出None。我也看过数据源Mbeans,但是由于它们仅在服务器启动时存在,所以我很快就放弃了它们。

我希望有人知道如何访问我不捕获异常时看到的错误消息。

预先感谢

在所有研究和测试之后,AdminControl似乎不过是一些常用MBEAN的说服力。

所以我尝试发布测试连接服务(例如在Java示例中https://www.ibm.com/support/knowledgecenter/en/sseqtp_8.5.5/com.ibm.m.webase.base.base.base.doc/ae/cdat_testcon.html(直接:

    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

这按我希望的方式起作用。不利的一面是,如果需要测试在各种范围(cell/node/cluster/server/application(中定义的数据量,则代码变得更加复杂。

我不需要它,所以我把它遗漏了,但是我仍然希望这个示例对他人也很有用。

最新更新