WebSphere wsadmin testConnection错误消息

时间:2019-05-21 06:54:36

标签: error-handling websphere jython wsadmin

我正在尝试编写脚本来测试WebSphere Cell / Node / Cluster的所有数据源。尽管可以通过管理控制台实现此功能,但对于某些受众而言,脚本更合适。

因此,我从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函数相反,该函数并不总是返回String,但是也可能引发异常。

所以我只使用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异常原因exc_value.getCause()给出None。 我也看过DataSource MBean,但是由于它们仅在服务器启动时存在,因此我很快放弃了。

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

预先感谢

1 个答案:

答案 0 :(得分:0)

毕竟,对AdminControl的研究和测试似乎不过是一些常用MBean的便利外观。

因此,我尝试发布了测试连接服务(例如此处的Java示例https://www.ibm.com/support/knowledgecenter/en/SSEQTP_8.5.5/com.ibm.websphere.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

这按我希望的方式工作。缺点是,如果需要测试在各种作用域(单元/节点/群集/服务器/应用程序)上定义的数据源,则代码将变得更加复杂。

我不需要这个,所以我把它省略了,但是我仍然希望这个例子对其他人也有用。