Elif Sahin
Elif Sahin

Reputation: 75

Check Wildfly server state from application

My wildfly standalone is running on a different machine and I use its IP for connection within my application. My goal is to make sure it's running and set a client state based on the answer. To do this, I simply send a query through ejb and if I receive a "Failed to connect to any server", I set client state to offline. Is there a way to do it better? Maybe a cli api to send a command for checking war deployment state? I know we can check it from jboss client on the machine if we're connected with deployment-info --name=App.war. But I couldn't find anything for my case. Does wildfly-core's org.jboss.as.cli.impl cover a case like this?

Upvotes: 0

Views: 689

Answers (1)

James R. Perkins
James R. Perkins

Reputation: 17780

You'd want to use the ModelControllerClient API to do the query. You can read the deployment resource to get information. Something like:

try (ModelControllerClient client = ModelControllerClient.Factory.create(address, 9990)) {
    final ModelNode address = Operations.createAddress("deployment", "App.war");
    final ModelNode op = Operations.createReadResourceOperation(address);
    op.get("include-runtime").set(true);
    final ModelNode outcome = client.execute(op);
    if (Operations.isSuccessfulOutcome(outcome)) {
        // do something
    } else {
        throw new RuntimeException(Operations.getFailureDescription(outcome).asString());
    }
}

That should return similiar info to the CLI command.

Upvotes: 2

Related Questions