如何通过编程方式检查Wildfly 8.2.1是否正确部署了我的应用程序?

时间:2015-09-28 13:06:24

标签: java deployment jboss wildfly jmx

我需要检查我的应用程序的部署状态,该程序由Wildfly 8.2.1以编程方式部署(最好是java)。就我而言,可以通过多种方式实现这一目标:

  1. 监视部署文件夹中的信号量文件(如果已部署,则为war文件创建.deployed文件)。
  2. 通过调用在成功部署war文件时应该可用的休息服务进行检查
  3. 使用JMX mbeans
  4. 可能还有其他方法,我还没有意识到。但我更感兴趣的是学习使用 JMX mbeans 的方法。但不幸的是,我的在线搜索没有给我任何好的方向。如果有人能够对此有所启发,那将会非常有帮助。

1 个答案:

答案 0 :(得分:2)

您可以使用管理操作来检查您是否存在部署。这有点旧,但是在deypted API上有一个tutorial

try (final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getLocalHost(), 9990)) {
    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 ModelNode deployments = Operations.readResult(result);
        for (String deploymentName : deployments.keys()) {
            final ModelNode deploymentDetails = deployments.get(deploymentName);
            // do stuff
        }
    } else {
        throw new RuntimeException("Failed to list deployments: " + Operations.getFailureDescription(result).asString());
    }
}

从结果中,您可以阅读有关部署的各种信息。输出如下:

{
    "content" => [{"hash" => bytes {
        0x77, 0x1f, 0x1a, 0xa1, 0x9e, 0x46, 0x11, 0x75,
        0x2f, 0x58, 0xce, 0x1b, 0x01, 0x29, 0x45, 0x43,
        0x16, 0x87, 0x22, 0x9a
    }}],
    "enabled" => true,
    "enabled-time" => 1443485828919L,
    "enabled-timestamp" => "2015-09-28 17:17:08,919 PDT",
    "name" => "batch-chunk.war",
    "owner" => undefined,
    "persistent" => true,
    "runtime-name" => "batch-chunk.war",
    "subdeployment" => undefined,
    "subsystem" => {
        "jaxrs" => undefined,
        "batch" => undefined,
        "undertow" => undefined
    }
}

如果您想查看是否已启用

if (!deploymentDetails.get("enabled")) {
    throw new RuntimeException(String.format("Deployment %s is not enabled", deploymentName);
}