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;
}
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;
});
}
Aggregations