error-handling - WebSphere wsadmin testConnection错误消息

标签 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,但是由于它们仅在启动服务器时存在,因此我很快放弃了它们。

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

提前致谢

最佳答案

毕竟,对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

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

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

关于error-handling - WebSphere wsadmin testConnection错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56232681/

相关文章:

java - 使用 j_security_check 进行身份验证,但不进行授权(在 Websphere 中)

python - boolean 标识 == True vs 是 True

Excel VBA 错误从控制表单框中调用 Sub

c# - 从Breeze Web API返回警告而不是错误

websphere - 正在安装 IBM HTTP Server?

java - 嵌入/嵌套自定义 JSP 标记以设置另一个 HTML 标记的属性值

java - Jython UnboundLocalError - 尝试了全局类型但仍然不起作用

java - 共享库中本地方法调用的 Jython UnsatisfiedLinkError

c++ - 您如何让cin只接受用户输入的数字?

php - 解析错误: syntax error, unexpected '$' , expecting variable (T_VARIABLE) in/var/www/html/cdf/application/models/Appointment_model.php on line 17