Search in sources :

Example 1 with ServerIdentity

use of org.jboss.as.controller.client.helpers.domain.ServerIdentity in project wildfly by wildfly.

the class ServerHelper method isDomainRunning.

/**
 * Checks to see if a domain server is running.
 *
 * @param client      the client used to communicate with the server
 * @param forShutdown if this is checking for a shutdown
 *
 * @return {@code true} if the server, and it's auto-start servers, are running, otherwise {@code false}
 */
public static boolean isDomainRunning(final ModelControllerClient client, final boolean forShutdown) {
    final DomainClient domainClient = (client instanceof DomainClient ? (DomainClient) client : DomainClient.Factory.create(client));
    try {
        // Check for admin-only
        final ModelNode hostAddress = determineHostAddress(domainClient);
        final Operations.CompositeOperationBuilder builder = Operations.CompositeOperationBuilder.create().addStep(Operations.createReadAttributeOperation(hostAddress, "running-mode")).addStep(Operations.createReadAttributeOperation(hostAddress, "host-state"));
        ModelNode response = domainClient.execute(builder.build());
        if (Operations.isSuccessfulOutcome(response)) {
            response = Operations.readResult(response);
            if ("ADMIN_ONLY".equals(Operations.readResult(response.get("step-1")).asString())) {
                if (Operations.isSuccessfulOutcome(response.get("step-2"))) {
                    final String state = Operations.readResult(response).asString();
                    return !CONTROLLER_PROCESS_STATE_STARTING.equals(state) && !CONTROLLER_PROCESS_STATE_STOPPING.equals(state);
                }
            }
        }
        final Map<ServerIdentity, ServerStatus> servers = new HashMap<>();
        final Map<ServerIdentity, ServerStatus> statuses = domainClient.getServerStatuses();
        for (ServerIdentity id : statuses.keySet()) {
            final ServerStatus status = statuses.get(id);
            switch(status) {
                case DISABLED:
                case STARTED:
                    {
                        servers.put(id, status);
                        break;
                    }
            }
        }
        if (forShutdown) {
            return statuses.isEmpty();
        }
        return statuses.size() == servers.size();
    } catch (IllegalStateException | IOException ignore) {
    }
    return false;
}
Also used : DomainClient(org.jboss.as.controller.client.helpers.domain.DomainClient) ServerIdentity(org.jboss.as.controller.client.helpers.domain.ServerIdentity) HashMap(java.util.HashMap) ServerStatus(org.jboss.as.controller.client.helpers.domain.ServerStatus) IOException(java.io.IOException) ModelNode(org.jboss.dmr.ModelNode) Operations(org.jboss.as.controller.client.helpers.Operations)

Example 2 with ServerIdentity

use of org.jboss.as.controller.client.helpers.domain.ServerIdentity in project wildfly by wildfly.

the class ServerHelper method waitForManagedServer.

public static void waitForManagedServer(final DomainClient client, final String serverName, final Supplier<String> failureDescription) throws InterruptedException {
    waitForStart(null, failureDescription, () -> {
        // Wait for the server to start
        ServerStatus serverStatus = null;
        final Map<ServerIdentity, ServerStatus> statuses = client.getServerStatuses();
        for (Map.Entry<ServerIdentity, ServerStatus> entry : statuses.entrySet()) {
            if (serverName.equals(entry.getKey().getServerName())) {
                serverStatus = entry.getValue();
                break;
            }
        }
        return serverStatus == ServerStatus.STARTED;
    });
}
Also used : ServerIdentity(org.jboss.as.controller.client.helpers.domain.ServerIdentity) ServerStatus(org.jboss.as.controller.client.helpers.domain.ServerStatus) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)2 ServerIdentity (org.jboss.as.controller.client.helpers.domain.ServerIdentity)2 ServerStatus (org.jboss.as.controller.client.helpers.domain.ServerStatus)2 IOException (java.io.IOException)1 Map (java.util.Map)1 Operations (org.jboss.as.controller.client.helpers.Operations)1 DomainClient (org.jboss.as.controller.client.helpers.domain.DomainClient)1 ModelNode (org.jboss.dmr.ModelNode)1