public final void assertDefinedValue() { assertDefinedValue(null); }
@Override public boolean isRequired(ModelNodeResult serverStateResult, boolean isManagedServerInDomain) { serverStateResult.assertDefinedValue(); return Constants.CONTROLLER_PROCESS_STATE_RESTART_REQUIRED.equals(serverStateResult.stringValue()); }
/** Retrieves all hosts in domain. */ public List<String> hosts() throws IOException { ModelNodeResult result = ops.readChildrenNames(Address.root(), Constants.HOST); result.assertDefinedValue(); return result.stringListValue(); }
List<String> allRunningServers(String host) throws IOException { ModelNodeResult result = ops.readChildrenNames(Address.host(host), Constants.SERVER); result.assertDefinedValue(); List<String> servers = result.stringListValue(); List<String> startedServers = new ArrayList<String>(); for (String server : servers) { ModelNodeResult serverStatus = ops.readAttribute(Address.host(host).and(Constants.SERVER_CONFIG, server), Constants.STATUS); serverStatus.assertDefinedValue(); if ("STARTED".equals(serverStatus.stringValue())) { startedServers.add(server); } } return startedServers; }
/** Retrieves all server groups in domain. */ public List<String> serverGroups() throws IOException { ModelNodeResult result = ops.readChildrenNames(Address.root(), Constants.SERVER_GROUP); result.assertDefinedValue(); return result.stringListValue(); }
/** Retrieves all configured servers on given {@code host}. */ public List<String> allServers(String host) throws IOException { ModelNodeResult result = ops.readChildrenNames(Address.host(host), Constants.SERVER_CONFIG); result.assertDefinedValue(); return result.stringListValue(); }
private boolean isServerRunning() throws IOException { ModelNodeResult result = ops.readAttribute(Address.root(), Constants.SERVER_STATE); result.assertDefinedValue(); return ServerState.isRunning(result.stringValue()); } }
/** * Stops given {@code server} on given {@code host}. * * @return {@code true} when server was successfully stopped, {@code false} otherwise */ public boolean stopServer(String host, String server) throws IOException { ModelNodeResult result = ops.invoke("stop", Address.host(host).and(Constants.SERVER_CONFIG, server), Values.of("blocking", true)); result.assertDefinedValue(); return result.isSuccess(); }
/** * Starts given {@code server} on given {@code host}. * * @return {@code true} when server was successfully started, {@code false} otherwise */ public boolean startServer(String host, String server) throws IOException { ModelNodeResult result = ops.invoke(Constants.START, Address.host(host).and(Constants.SERVER_CONFIG, server), Values.of(Constants.BLOCKING, true)); result.assertDefinedValue(); return result.isSuccess(); }
/** * Returns the Java command the server / host controller was started with. It's read from the platform MBean * server via the management interface. * * @param host should be {@code null} for standalone server or for default host in managed domain; * should only be non-{@code null} if a specific host in managed domain is checked */ private static String commandUsedToStartTheServer(OnlineManagementClient client, String host) throws IOException { Address baseAddress = Address.root(); if (host != null) { baseAddress = Address.host(host); } ModelNodeResult systemProperties = new Operations(client).readAttribute( baseAddress.and(Constants.CORE_SERVICE, Constants.PLATFORM_MBEAN).and("type", "runtime"), "system-properties" ); systemProperties.assertDefinedValue(); // the "sun.java.command" system property exists at least on OpenJDK, Oracle Java and IBM Java return systemProperties.value().get("sun.java.command").asString(); }
private boolean areServersRunning(String host, List<String> servers) throws IOException { Address hostAddress = Address.host(host); if (servers == null || servers.isEmpty()) { ModelNodeResult result = ops.readAttribute(Address.host(host), Constants.HOST_STATE); result.assertDefinedValue(); return ServerState.isRunning(result.stringValue()); } else { for (String server : servers) { Address serverAddress = hostAddress.and(Constants.SERVER, server); ModelNodeResult result = ops.readAttribute(serverAddress, Constants.SERVER_STATE); if (!result.hasDefinedValue() || !ServerState.isRunning(result.stringValue())) { return false; } } return true; } } }
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; }