public static boolean isDomainServer(final ModelControllerClient client) throws IOException { boolean result = false; // Check this is really a domain server final ModelNode op = ServerOperations.createReadAttributeOperation(ServerOperations.LAUNCH_TYPE); final ModelNode opResult = client.execute(op); if (ServerOperations.isSuccessfulOutcome(opResult)) { result = ("DOMAIN".equals(ServerOperations.readResultAsString(opResult))); } return result; }
/** * Checks the existence of a resource. If the resource exists, {@code true} is returned, otherwise * {@code false}. * * @param address the address of the resource to check. * @param client the client used to execute the operation. * @return {@code true} if the resources exists, otherwise {@code false}. * @throws IOException if an error occurs executing the operation. * @throws RuntimeException if the operation fails. */ private boolean resourceExists(final ModelNode address, final ModelControllerClient client) throws IOException { final Property childAddress = ServerOperations.getChildAddress(address); final ModelNode parentAddress = ServerOperations.getParentAddress(address); final ModelNode r = client.execute( ServerOperations.createOperation(ServerOperations.READ_RESOURCE, parentAddress, false)); reportFailure(r); boolean found = false; final String name = childAddress.getName(); if (ServerOperations.isSuccessfulOutcome(r)) { for (ModelNode dataSource : ServerOperations.readResult(r).get(name).asList()) { if (dataSource.asProperty().getName().equals(childAddress.getValue().asString())) { found = true; } } } return found; }
private void reportFailure(final ModelNode result) { if (!ServerOperations.isSuccessfulOutcome(result)) { throw new RuntimeException(ServerOperations.getFailureDescriptionAsString(result)); } }