0

I am trying to use the Wildfly 9 native management API to show me the status of my deployed apps. The jboss-cli execution and result is below:

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

Using the code below, I am able to determine if the apps are enabled, but not if they are up and running:

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

Can anyone assist in translating my jboss-cli commands into Java? I've tried hooking into the deployment-scanner subsystem as well, but that doesn't seem to get me anywhere useful.

SourMonk
  • 344
  • 1
  • 3
  • 15

2 Answers2

0

This answer from a similar thread worked for us (with some minor tweaking): https://stackoverflow.com/a/41261864/3486967

SourMonk
  • 344
  • 1
  • 3
  • 15
0

You can use the read-children-resource operation to get the deployment resources.

Something like the following should work.

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());
    }
}
James R. Perkins
  • 16,800
  • 44
  • 60
  • Is the ServerHelper class part of the dependencies for the jboss management API ? Found a ServerDeploymentHelper in a helper package, but not the one you mentioned here, and it looks useful. – g0dzax Apr 13 '20 at 07:09
  • It's part of a separate package https://github.com/wildfly/wildfly-maven-plugin/tree/master/core. – James R. Perkins Apr 13 '20 at 20:59