【问题标题】:WebSphere wsadmin testConnection error messageWebSphere wsadmin testConnection 错误消息
【发布时间】:2019-10-07 12:24:41
【问题描述】:

我正在尝试编写一个脚本来测试 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 函数并不总是返回 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 变量和缺少驱动程序类。 虽然 Admin Console 会打印合理的消息,但脚本会继续打印相同的无意义消息。

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

访问 Java 异常会导致 exc_value.getCause() 给出 None。 我还查看了 DataSource MBean,但由于它们仅在服务器启动时才存在,所以我很快就放弃了。

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

提前致谢

【问题讨论】:

    标签: error-handling websphere jython wsadmin


    【解决方案1】:

    在所有研究和测试之后,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
    

    这按我希望的方式工作。不利的一面是,如果需要测试在各种范围(Cell/Node/Cluster/Server/Application)上定义的 DataSource,代码会变得更加复杂。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-02
      • 2015-09-17
      • 1970-01-01
      相关资源
      最近更新 更多