void shutdownServers(String host, List<String> servers) throws IOException, InterruptedException, TimeoutException { Batch batch = new Batch(); for (String server : servers) { batch.invoke(Constants.STOP, Address.host(host).and(Constants.SERVER_CONFIG, server)); } ops.batch(batch); }
void restartServers(String host, List<String> servers) throws IOException, InterruptedException, TimeoutException { Batch batch = new Batch(); for (String server : servers) { batch.invoke(Constants.RESTART, Address.host(host).and(Constants.SERVER_CONFIG, server)); } boolean needsToReconnect = false; try { ops.batch(batch); } catch (Throwable e) { // server went down before we received the response, this can happen needsToReconnect = true; } domainOps.waitUntilServersAreRunning(host, servers, needsToReconnect); }
void shutdownServersGracefully(String host, List<String> servers, int timeoutInSeconds) throws IOException, InterruptedException, TimeoutException { client.version().assertAtLeast(ServerVersion.VERSION_3_0_0, "Graceful shutdown is only supported since WildFly 9"); Batch batch = new Batch(); for (String server : servers) { batch.invoke(Constants.STOP, Address.host(host).and(Constants.SERVER_CONFIG, server), Values.of(Constants.TIMEOUT, timeoutInSeconds)); } ops.batch(batch); }
void shutdown(String host, int timeoutInSeconds) throws IOException { if (timeoutInSeconds == 0) { // older versions don't understand the "timeout" parameter ops.invoke(Constants.SHUTDOWN, Address.host(host)); } else { Batch batch = new Batch(); for (String server : allRunningServers(host)) { batch.invoke(Constants.STOP, Address.host(host).and(Constants.SERVER_CONFIG, server), Values.of(Constants.TIMEOUT, timeoutInSeconds)); } batch.invoke(Constants.SHUTDOWN, Address.host(host)); ops.batch(batch); } }
boolean isRestartOperationRequired(String host, CommonRestartOperation restartOperation) throws IOException { List<String> allServers = allRunningServers(host); Batch batch = new Batch(); batch.readAttribute(Address.host(host), Constants.HOST_STATE); for (String server : allServers) { batch.readAttribute(Address.host(host).and(Constants.SERVER, server), Constants.SERVER_STATE); } ModelNodeResult result = ops.batch(batch); result.assertDefinedValue(); int counter = 0; // 0 == host, > 0 == server for (ModelNodeResult stepResult : result.forAllBatchSteps()) { if (restartOperation.isRequired(stepResult, counter > 0)) { return true; } counter++; } return false; }