private String obtainServerUUID() throws OperationFailedException { try { ModelNode operation = Operations.createReadAttributeOperation(new ModelNode().setEmptyList(), UUID); operation.get(INCLUDE_RUNTIME).set(true); ModelControllerClient client = env.getClient(); if (client == null) { client = env.getCli().getCommandContext().getModelControllerClient(); } ModelNode result = client.execute(operation); if (Operations.isSuccessfulOutcome(result)) { return Operations.readResult(result).asString(); } return null; } catch (IOException ex) { return null; } }
private String obtainProductVersion() { try { ModelNode operation = Operations.createReadAttributeOperation(new ModelNode().setEmptyList(), PRODUCT_VERSION); operation.get(INCLUDE_RUNTIME).set(false); ModelControllerClient client = env.getClient(); if (client == null) { client = env.getCli().getCommandContext().getModelControllerClient(); } ModelNode result = client.execute(operation); if (Operations.isSuccessfulOutcome(result)) { return Operations.readResult(result).asString(); } return "undefined"; } catch (IOException e) { // This should not be needed since a product version is always returned, even if it doesn't exist. // In that case "undefined" is returned return "undefined"; } } }
private String obtainProductName() { try { ModelNode operation = Operations.createReadAttributeOperation(new ModelNode().setEmptyList(), PRODUCT_NAME); operation.get(INCLUDE_RUNTIME).set(false); ModelControllerClient client = env.getClient(); if (client == null) { client = env.getCli().getCommandContext().getModelControllerClient(); } ModelNode result = client.execute(operation); if (Operations.isSuccessfulOutcome(result)) { return Operations.readResult(result).asString(); } return "undefined"; } catch (IOException e) { // This should not be needed since a product name is always returned, even if it doesn't exist. // In that case "undefined" is returned return "undefined"; } }
String getLastUpdateDate() { List<ModelNode> result = Operations.readResult(patchingInfo).asList(); for (ModelNode patchAtt : result) { if (patchAtt.has("applied-at")) { return patchAtt.get("applied-at").asString(); } } return null; }
String getLastUpdateDate() { if (patchingInfo.isDefined()) { List<ModelNode> result = Operations.readResult(patchingInfo).asList(); for (ModelNode patchAtt : result) { if (patchAtt.has("applied-at")) { return patchAtt.get("applied-at").asString(); } } } return null; }
@Override public Set<String> getDeploymentNames() throws IOException { final ModelNode readDeployments = Operations.createOperation(READ_CHILDREN_NAMES_OPERATION); readDeployments.get(CHILD_TYPE).set(DEPLOYMENT); final Set<String> deployments = new LinkedHashSet<>(); final ModelNode result = client.execute(readDeployments); if (Operations.isSuccessfulOutcome(result)) { for (ModelNode deployment : Operations.readResult(result).asList()) { final String deploymentName = deployment.asString(); deployments.add(deploymentName); } return deployments; } throw new RuntimeException("Failed to get listing of deployments. Reason: " + Operations.getFailureDescription(result).asString()); }
private ModelNode executeForSuccess(final ModelNode op) throws IOException { final ModelControllerClient client = Objects.requireNonNull(getModelControllerClient(), "The client cannot be null"); final ModelNode result = client.execute(op); if (!Operations.isSuccessfulOutcome(result)) { throw new RuntimeException(Operations.getFailureDescription(result).asString()); } return Operations.readResult(result); } }
/** * Checks to see if a standalone server is running. * * @param client the client used to communicate with the server * * @return {@code true} if the server is running, otherwise {@code false} */ public static boolean isStandaloneRunning(final ModelControllerClient client) { try { final ModelNode response = client.execute(Operations.createReadAttributeOperation(EMPTY_ADDRESS, "server-state")); if (Operations.isSuccessfulOutcome(response)) { final String state = Operations.readResult(response).asString(); return !CONTROLLER_PROCESS_STATE_STARTING.equals(state) && !CONTROLLER_PROCESS_STATE_STOPPING.equals(state); } } catch (RuntimeException | IOException e) { LOGGER.trace("Interrupted determining if standalone is running", e); } return false; }
private boolean isEnabled(final ModelNode address) { final ModelNode op = Operations.createReadAttributeOperation(address, DeploymentOperations.ENABLED); try { final ModelNode result = client.execute(op); // Check to make sure there is an outcome if (Operations.isSuccessfulOutcome(result)) { return Operations.readResult(result).asBoolean(); } else { throw new IllegalStateException(Operations.getFailureDescription(result).asString()); } } catch (IOException e) { throw new IllegalStateException(String.format("Could not execute operation '%s'", op), e); } }
private boolean hasDeployment(final ModelNode address, final String name) { final ModelNode op = Operations.createOperation(READ_CHILDREN_NAMES_OPERATION, address); op.get(CHILD_TYPE).set(DEPLOYMENT); final ModelNode listDeploymentsResult; try { listDeploymentsResult = client.execute(op); // Check to make sure there is an outcome if (Operations.isSuccessfulOutcome(listDeploymentsResult)) { final List<ModelNode> deployments = Operations.readResult(listDeploymentsResult).asList(); for (ModelNode deployment : deployments) { if (name.equals(deployment.asString())) { return true; } } } else { throw new IllegalStateException(Operations.getFailureDescription(listDeploymentsResult).asString()); } } catch (IOException e) { throw new IllegalStateException(String.format("Could not execute operation '%s'", op), e); } return false; }
private String setElytronDomain(ModelControllerClient client, String domainToSet) throws Exception { String origDomainValue = null; ModelNode op = Util.createEmptyOperation("read-attribute", messagingServerAddress); op.get("name").set("elytron-domain"); ModelNode result = client.execute(op); boolean isConfigured = Operations.isSuccessfulOutcome(result); op = null; if (isConfigured) { result = Operations.readResult(result); origDomainValue = result.isDefined() ? result.asString() : null; } op = Util.createEmptyOperation("write-attribute", messagingServerAddress); op.get("name").set("elytron-domain"); op.get("value").set(domainToSet); Utils.applyUpdate(op, client); return origDomainValue; }
@Override public Set<ServerDescription> getServers(final String hostName) { checkState(false); final Set<ServerDescription> servers = new LinkedHashSet<>(); // Get all the servers in the servers final ModelNode op = Operations.createReadResourceOperation(Operations.createAddress(ClientConstants.HOST, hostName, ClientConstants.SERVER_CONFIG)); final ModelNode results = runtimeExecuteForSuccess(op); for (ModelNode result : results.asList()) { final ModelNode serverConfig = Operations.readResult(result); final String name = serverConfig.get(ClientConstants.NAME).asString(); final String groupName = serverConfig.get(ClientConstants.GROUP).asString(); servers.add(new ServerDescription() { @Override public String getHostName() { return hostName; } @Override public String getName() { return name; } @Override public String getGroupName() { return groupName; } }); } return Collections.unmodifiableSet(servers); }
ModelNode response = client.execute(op); if (Operations.isSuccessfulOutcome(response)) { ModelNode result = Operations.readResult(response); final Collection<String> files = new ArrayList<>(); final CompositeOperationBuilder builder = CompositeOperationBuilder.create(); ModelNode fileListing = new ModelNode().setEmptyList(); if (Operations.isSuccessfulOutcome(result)) { final List<ModelNode> attributes = Operations.readResult(result).asList(); int i = 0; if (attributes.size() != (files.size() * 2)) { final ModelNode node = new ModelNode(); node.get("file-name").set(file); node.get("file-size").set(Operations.readResult(attributes.get(i++).get(0))); node.get("last-modified-time").set(Operations.readResult(attributes.get(i++).get(0))); fileListing.add(node);
/** * Checks the running server to determine if it is a managed domain server. * * @param client the client used to query the server * * @return {@code true} if the running server is a managed domain, otherwise {@code false} * * @throws IOException if an error occurs communicating with the server */ public static boolean isDomainServer(final ModelControllerClient client) throws IOException { boolean result = false; // Check this is really a domain server final ModelNode op = Operations.createReadAttributeOperation(EMPTY_ADDRESS, "launch-type"); final ModelNode opResult = Assert.checkNotNullParam("client", client).execute(op); if (Operations.isSuccessfulOutcome(opResult)) { result = ("DOMAIN".equalsIgnoreCase(Operations.readResult(opResult).asString())); } return result; }
@Override public Set<ServerDescription> getServers() { checkState(false); final Set<ServerDescription> servers = new LinkedHashSet<>(); // Get all the servers in the servers final ModelNode op = Operations.createReadResourceOperation(Operations.createAddress(ClientConstants.HOST, "*", ClientConstants.SERVER_CONFIG)); final ModelNode results = runtimeExecuteForSuccess(op); for (ModelNode result : results.asList()) { final ModelNode serverConfig = Operations.readResult(result); final String name = serverConfig.get(ClientConstants.NAME).asString(); final String groupName = serverConfig.get(ClientConstants.GROUP).asString(); final String hostName = Operations.getOperationAddress(result).asList().get(0).get(ClientConstants.HOST).asString(); servers.add(new ServerDescription() { @Override public String getHostName() { return hostName; } @Override public String getName() { return name; } @Override public String getGroupName() { return groupName; } }); } return Collections.unmodifiableSet(servers); }
@Override public boolean isServerStarted(final String hostName, final String serverName) { checkState(true); final ModelNode op = Operations.createReadAttributeOperation(Operations.createAddress(ClientConstants.HOST, hostName, ClientConstants.SERVER_CONFIG, serverName), "status"); try { final ModelNode result = getModelControllerClient().execute(op); if (Operations.isSuccessfulOutcome(result)) { return "STARTED".equals(Operations.readResult(result).asString()); } } catch (IOException ignore) { } return false; }
/** * Determines the address for the host being used. * * @param client the client used to communicate with the server * * @return the address of the host * * @throws IOException if an error occurs communicating with the server * @throws OperationExecutionException if the operation used to determine the host name fails */ public static ModelNode determineHostAddress(final ModelControllerClient client) throws IOException, OperationExecutionException { final ModelNode op = Operations.createReadAttributeOperation(EMPTY_ADDRESS, "local-host-name"); ModelNode response = client.execute(op); if (Operations.isSuccessfulOutcome(response)) { return DeploymentOperations.createAddress("host", Operations.readResult(response).asString()); } throw new OperationExecutionException(op, response); }
private DeploymentDescription getServerGroupDeployment(final String name) throws IOException { final Set<String> serverGroups = new LinkedHashSet<>(); final ModelNode address = createAddress(SERVER_GROUP, "*", DEPLOYMENT, name); final ModelNode result = client.execute(Operations.createReadResourceOperation(address)); if (Operations.isSuccessfulOutcome(result)) { // Load the server groups for (ModelNode r : Operations.readResult(result).asList()) { final List<Property> resultAddress = Operations.getOperationAddress(r).asPropertyList(); String foundServerGroup = null; for (Property property : resultAddress) { if (SERVER_GROUP.equals(property.getName())) { foundServerGroup = property.getValue().asString(); } } // Add the server-group to the map of deployments serverGroups.add(foundServerGroup); } return SimpleDeploymentDescription.of(name, serverGroups); } throw new RuntimeException("Failed to get listing of deployments. Reason: " + Operations.getFailureDescription(result).asString()); }
final ModelNode result = client.getControllerClient().execute(op); if (Operations.isSuccessfulOutcome(result)) { final ModelNode model = Operations.readResult(result); final String productName; if (model.hasDefined("product-name")) {
/** * Queries the running container and attempts to lookup the information from the running container. * * @param client the client used to execute the management operation * * @return the container description * * @throws IOException if an error occurs while executing the management operation * @throws OperationExecutionException if the operation used to query the container fails */ static DefaultContainerDescription lookup(final ModelControllerClient client) throws IOException, OperationExecutionException { final ModelNode op = Operations.createReadResourceOperation(new ModelNode().setEmptyList()); op.get(ClientConstants.INCLUDE_RUNTIME).set(true); final ModelNode result = client.execute(op); if (Operations.isSuccessfulOutcome(result)) { final ModelNode model = Operations.readResult(result); final String productName = getValue(model, "product-name", "WildFly"); final String productVersion = getValue(model, "product-version"); final String releaseVersion = getValue(model, "release-version"); final String launchType = getValue(model, "launch-type"); return new DefaultContainerDescription(productName, productVersion, releaseVersion, launchType, "DOMAIN".equalsIgnoreCase(launchType)); } throw new OperationExecutionException(op, result); }