【问题标题】:Displaying deployed app status with Java Wildfly 9 native management API使用 Java Wildfly 9 原生管理 API 显示已部署的应用程序状态
【发布时间】:2017-06-13 15:26:18
【问题描述】:

我正在尝试使用 Wildfly 9 原生管理 API 向我显示已部署应用的状态。 jboss-cli 执行结果如下:

jboss-cli.sh --connect --controller=myserver.com:9990 --commands="/deployment=my-deployment.war :read-attribute(name=status)"
{
    "outcome" => "success",
    "result" => "OK"
}

使用下面的代码,我可以确定应用程序是否启用,但不能确定它们是否已启动并运行:

ModelNode op = new ModelNode();
op.get("operation").set("read-children-names");
op.get("child-type").set(ClientConstants.DEPLOYMENT);

谁能协助将我的 jboss-cli 命令翻译成 Java?我也尝试过连接到部署扫描器子系统,但这似乎对我没有任何用处。

【问题讨论】:

    标签: java jboss wildfly-9


    【解决方案1】:

    来自类似线程的这个答案对我们有用(稍作调整):https://stackoverflow.com/a/41261864/3486967

    【讨论】:

      【解决方案2】:

      您可以使用read-children-resource操作获取部署资源。

      类似下面的东西应该可以工作。

      try (final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getLocalHost(), 9990)) {
          ServerHelper.waitForStandalone(client, 20L);
          final ModelNode op = Operations.createOperation("read-children-resources");
          op.get(ClientConstants.CHILD_TYPE).set(ClientConstants.DEPLOYMENT);
          final ModelNode result = client.execute(op);
          if (Operations.isSuccessfulOutcome(result)) {
              final List<Property> deployments = Operations.readResult(result).asPropertyList();
              for (Property deployment : deployments) {
                  System.out.printf("Deployment %-20s enabled? %s%n", deployment.getName(), deployment.getValue().get("enabled"));
              }
          } else {
              throw new RuntimeException(Operations.getFailureDescription(result).asString());
          }
      }
      

      【讨论】:

      • ServerHelper 类是 jboss 管理 API 依赖项的一部分吗?在帮助程序包中找到了一个 ServerDeploymentHelper,但不是您在此处提到的那个,它看起来很有用。
      • 它是一个单独的包github.com/wildfly/wildfly-maven-plugin/tree/master/core的一部分。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-04
      • 2017-04-22
      • 2016-11-08
      • 2016-05-25
      • 2016-07-12
      • 2018-03-09
      相关资源
      最近更新 更多