Java Code Examples for org.jboss.as.controller.client.helpers.Operations#isSuccessfulOutcome()

The following examples show how to use org.jboss.as.controller.client.helpers.Operations#isSuccessfulOutcome() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FullReplaceUndeployTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static boolean hasDeployment(final ModelControllerClient client, final String name) throws IOException {
    final ModelNode op = Operations.createOperation(ClientConstants.READ_CHILDREN_NAMES_OPERATION);
    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;
}
 
Example 2
Source File: SNICombinedWithALPNTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Deploys the archive to the running server.
 *
 * @param archive the archive to deploy
 * @throws IOException if an error occurs deploying the archive
 */
public static void deploy(final Archive<?> archive, ManagementClient managementClient) throws IOException {
    // Use an operation to allow overriding the runtime name
    final ModelNode address = Operations.createAddress(DEPLOYMENT, archive.getName());
    final ModelNode addOp = createAddOperation(address);
    addOp.get("enabled").set(true);
    // Create the content for the add operation
    final ModelNode contentNode = addOp.get(CONTENT);
    final ModelNode contentItem = contentNode.get(0);
    contentItem.get(ClientConstants.INPUT_STREAM_INDEX).set(0);

    // Create an operation and add the input archive
    final OperationBuilder builder = OperationBuilder.create(addOp);
    builder.addInputStream(archive.as(ZipExporter.class).exportAsInputStream());

    // Deploy the content and check the results
    final ModelNode result = managementClient.getControllerClient().execute(builder.build());
    if (!Operations.isSuccessfulOutcome(result)) {
        Assert.fail(String.format("Failed to deploy %s: %s", archive, Operations.getFailureDescription(result).asString()));
    }
}
 
Example 3
Source File: AbstractLoggingOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected ModelNode testUndefine(final ModelNode address, final String attribute, final boolean expectFailure) throws IOException {
    final CompositeOperationBuilder builder = CompositeOperationBuilder.create();
    builder.addStep(Operations.createUndefineAttributeOperation(address, attribute));
    // Create the read operation
    final ModelNode readOp = Operations.createReadAttributeOperation(address, attribute);
    readOp.get("include-defaults").set(false);
    builder.addStep(readOp);
    final ModelNode result = client.getControllerClient().execute(builder.build());
    if (expectFailure) {
        assertFalse("Undefining attribute " + attribute + " should have failed.", Operations.isSuccessfulOutcome(result));
    } else {
        if (!Operations.isSuccessfulOutcome(result)) {
            Assert.fail(Operations.getFailureDescription(result).toString());
        }
        assertFalse("Attribute '" + attribute + "' was not undefined.", Operations.readResult(Operations.readResult(result).get("step-2"))
                .isDefined());
    }
    return result;
}
 
Example 4
Source File: JdkModuleDependencyTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void testModuleDependencies(Set<String> moduleDependencies) throws Exception {
    final List<String> failures = new ArrayList<>();
    final ModelControllerClient mcc = managementClient.getControllerClient();

    for (String moduleDependency : moduleDependencies) {
        String deploymentName = moduleDependency + DEPLOYMENT_NAME_SUFFIX;
        ModelNode deploymentOperationResult = deployTestDeployment(deploymentName, moduleDependency);
        if (Operations.isSuccessfulOutcome(deploymentOperationResult)) {
            if (!isDeploymentFunctional(deploymentName, mcc)) {
                failures.add(moduleDependency);
            }
            removeTestDeployment(deploymentName);
        } else {
            failures.add(moduleDependency);
        }
    }

    Assert.assertTrue("Deployments with the following module dependencies have failed: " + failures.toString(),
            failures.isEmpty());
}
 
Example 5
Source File: AbstractLoggingTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static String resolveRelativePath(final String relativePath) {
    final ModelNode address = PathAddress.pathAddress(
            PathElement.pathElement(ModelDescriptionConstants.PATH, relativePath)
    ).toModelNode();
    final ModelNode result;
    try {
        final ModelNode op = Operations.createReadAttributeOperation(address, ModelDescriptionConstants.PATH);
        result = client.execute(op);
        if (Operations.isSuccessfulOutcome(result)) {
            return Operations.readResult(result).asString();
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    throw new RuntimeException(Operations.getFailureDescription(result).asString());
}
 
Example 6
Source File: ServerHelper.java    From wildfly-maven-plugin with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Shuts down a standalone server.
 *
 * @param client  the client used to communicate with the server
 * @param timeout the graceful shutdown timeout, a value of {@code -1} will wait indefinitely and a value of
 *                {@code 0} will not attempt a graceful shutdown
 *
 * @throws IOException if an error occurs communicating with the server
 */
public static void shutdownStandalone(final ModelControllerClient client, final int timeout) throws IOException {
    final ModelNode op = Operations.createOperation("shutdown");
    op.get("timeout").set(timeout);
    final ModelNode response = client.execute(op);
    if (Operations.isSuccessfulOutcome(response)) {
        while (true) {
            if (isStandaloneRunning(client)) {
                try {
                    TimeUnit.MILLISECONDS.sleep(20L);
                } catch (InterruptedException e) {
                    LOGGER.trace("Interrupted during sleep", e);
                }
            } else {
                break;
            }
        }
    } else {
        throw new OperationExecutionException(op, response);
    }
}
 
Example 7
Source File: TrustedDomainsConfigurator.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void create(ModelControllerClient client, CLIWrapper cli) throws Exception {
    final PathAddress domainAddress = PathAddress.pathAddress().append("subsystem", "elytron").append("security-domain",
            name);
    ModelNode op = Util.createEmptyOperation("read-attribute", domainAddress);
    op.get("name").set("trusted-security-domains");
    ModelNode result = client.execute(op);
    if (Operations.isSuccessfulOutcome(result)) {
        result = Operations.readResult(result);
        originalDomains = result.isDefined() ? result : null;
    } else {
        throw new RuntimeException("Reading existing value of trusted-security-domains attribute failed: "
                + Operations.getFailureDescription(result));
    }

    op = Util.createEmptyOperation("write-attribute", domainAddress);
    op.get("name").set("trusted-security-domains");
    for (String domain : trustedSecurityDomains) {
        op.get("value").add(domain);
    }
    CoreUtils.applyUpdate(op, client);
}
 
Example 8
Source File: AbstractTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static ModelNode executeOperation(final ModelControllerClient client, final Operation op) throws IOException {
    final ModelNode result = client.execute(op);
    if (!Operations.isSuccessfulOutcome(result)) {
        Assert.fail(String.format("Failed to execute op: %s%nFailure Description: %s", op, Operations.getFailureDescription(result)));
    }
    return Operations.readResult(result);
}
 
Example 9
Source File: SocketHandlerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ModelNode executeOperation(final ManagementClient managementClient, final ModelNode op) throws IOException {
    final ModelNode result = managementClient.getControllerClient().execute(op);
    if (!Operations.isSuccessfulOutcome(result)) {
        throw new RuntimeException(Operations.getFailureDescription(result).toString());
    }
    return Operations.readResult(result);
}
 
Example 10
Source File: DeploymentTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void cleanUp(String deployment) {
    ModelNode op = new ModelNode();
    op.get(OP).set(READ_RESOURCE_OPERATION);
    op.get(OP_ADDR).set(ModelDescriptionConstants.DEPLOYMENT, deployment);
    ModelControllerClient client = managementClient.getControllerClient();
    ModelNode result;
    try {
        result = client.execute(op);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    if (result != null && Operations.isSuccessfulOutcome(result)) {
        ServerDeploymentManager manager = ServerDeploymentManager.Factory.create(client);
        Future<?> future = manager.execute(manager.newDeploymentPlan()
                .undeploy(deployment)
                .remove(deployment)
                .build());

        awaitDeploymentExecution(future);
    }

    String jbossBaseDir = System.getProperty("jboss.home");
    Assert.assertNotNull(jbossBaseDir);
    Path dataDir = new File(jbossBaseDir).toPath().resolve("standalone").resolve("data");
    if (Files.exists(dataDir)) { cleanFile(dataDir.resolve("managed-exploded").toFile()); }
    File archivesDir = new File("target", "archives");
    if (Files.exists(archivesDir.toPath())) { cleanFile(archivesDir); }
}
 
Example 11
Source File: ServerHelper.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 ignore) {
    }
    return false;
}
 
Example 12
Source File: DeploymentOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private boolean explodeDeploymentAndGetOutcome(String deploymentName) {
    ModelNode op = new ModelNode();
    op.get(OP).set(EXPLODE);
    op.get(OP_ADDR).add(DEPLOYMENT, deploymentName);

    return Operations.isSuccessfulOutcome(awaitOperationExecutionAndReturnResult(op));
}
 
Example 13
Source File: DefaultDeploymentManager.java    From wildfly-maven-plugin with GNU Lesser General Public License v2.1 5 votes vote down vote up
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);
    }
}
 
Example 14
Source File: HttpMgmtConfigurator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private String readAttribute(ModelControllerClient client, String name) throws Exception {
    String originalVal;
    ModelNode op = Util.createEmptyOperation("read-attribute", HTTP_IFACE_ADDR);
    op.get("name").set(name);
    ModelNode result = client.execute(op);
    if (Operations.isSuccessfulOutcome(result)) {
        result = Operations.readResult(result);
        originalVal = result.isDefined() ? result.asString() : null;
    } else {
        throw new RuntimeException(
                "Reading existing value of attribute " + name + " failed: " + Operations.getFailureDescription(result));
    }
    return originalVal;
}
 
Example 15
Source File: ManagementAuthenticationUsersServerSetupTask.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ModelNode executeForSuccess(final ModelControllerClient client, final ModelNode op) throws IOException {
    final ModelNode result = client.execute(op);
    if (!Operations.isSuccessfulOutcome(result)) {
        Assert.fail(Operations.getFailureDescription(result).asString());
    }
    return Operations.readResult(result);
}
 
Example 16
Source File: DisableLocalAuthServerSetupTask.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void tearDown(final ManagementClient managementClient) throws Exception {
    try (final ModelControllerClient client = createNativeClient()) {

        final Operations.CompositeOperationBuilder compositeOp = Operations.CompositeOperationBuilder.create();

        // Remove the native interface
        compositeOp.addStep(Operations.createRemoveOperation(nativeInterfaceAddress));
        // Remove the native-interface
        compositeOp.addStep(Operations.createRemoveOperation(nativeSecurityRealmAddress));
        // Remove the socket binding for the native-interface
        compositeOp.addStep(Operations.createRemoveOperation(nativeSocketBindingAddress));

        // Re-enable Elytron local-auth
        ModelNode op = Operations.createReadResourceOperation(saslFactoryAddress);
        ModelNode result = client.execute(op);
        if (Operations.isSuccessfulOutcome(result)) {
            op = Operations.createOperation("map-put", saslFactoryAddress);
            op.get("name").set("properties");
            op.get("key").set(defaultUserKey);
            op.get("value").set("$local");
            compositeOp.addStep(op.clone());
        }

        // Re-enable the legacy local-auth
        op = Operations.createReadResourceOperation(managementRealmAddress);
        result = client.execute(op);
        if (Operations.isSuccessfulOutcome(result)) {
            ///core-service=management/security-realm=ManagementRealm/authentication=local:undefine-attribute(name=default-user)
            compositeOp.addStep(Operations.createWriteAttributeOperation(managementRealmAddress, "default-user", "$local"));

        }

        executeForSuccess(client, compositeOp.build());

        // Use the native client to execute the reload, completion waiting should create a new http+remote client
        ServerReload.executeReloadAndWaitForCompletion(client);
    }

}
 
Example 17
Source File: AuditLogFieldsOfLogTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean makeOneLog() throws IOException {
    ModelNode op = Util.getWriteAttributeOperation(auditLogConfigAddress,
            AuditLogLoggerResourceDefinition.LOG_BOOT.getName(), ModelNode.TRUE);
    ModelNode result = container.getClient().getControllerClient().execute(op);
    return Operations.isSuccessfulOutcome(result);
}
 
Example 18
Source File: ServerHelper.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * 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;
}
 
Example 19
Source File: DisableLocalAuthServerSetupTask.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void setup(final ManagementClient managementClient) throws Exception {

    final ModelControllerClient client = managementClient.getControllerClient();
    final Operations.CompositeOperationBuilder compositeOp = Operations.CompositeOperationBuilder.create();

    // Add the socket binding for the native-interface
    ModelNode op = Operations.createAddOperation(nativeSocketBindingAddress);
    op.get("port").set(9999);
    op.get("interface").set("management");
    compositeOp.addStep(op.clone());

    // Add the native-interface
    compositeOp.addStep(Operations.createAddOperation(nativeSecurityRealmAddress));

    // Add the native-interface local authentication
    final ModelNode nativeRealmLocalAuthAddress = nativeSecurityRealmAddress.clone().add("authentication", "local");
    op = Operations.createAddOperation(nativeRealmLocalAuthAddress);
    op.get("default-user").set("$local");
    compositeOp.addStep(op.clone());

    // Add the native interface
    op = Operations.createAddOperation(nativeInterfaceAddress);
    op.get("security-realm").set("native-realm");
    op.get("socket-binding").set("management-native");
    compositeOp.addStep(op.clone());

    // Undefine Elytron local-auth
    op = Operations.createReadResourceOperation(saslFactoryAddress);
    ModelNode result = client.execute(op);
    if (Operations.isSuccessfulOutcome(result)) {
        op = Operations.createOperation("map-remove", saslFactoryAddress);
        op.get("name").set("properties");
        op.get("key").set(defaultUserKey);
        compositeOp.addStep(op.clone());
    }

    // Undefine the legacy local-auth
    op = Operations.createReadResourceOperation(managementRealmAddress);
    result = client.execute(op);
    if (Operations.isSuccessfulOutcome(result)) {
        compositeOp.addStep(Operations.createUndefineAttributeOperation(managementRealmAddress, "default-user"));

    }

    executeForSuccess(client, compositeOp.build());

    // Use the current client to execute the reload, but the native client to ensure the reload is complete
    ServerReload.executeReloadAndWaitForCompletion(client, ServerReload.TIMEOUT, false, protocol, host, port);
}
 
Example 20
Source File: SocketHandlerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void executeOperation(final ManagementClient managementClient, final Operation op) throws IOException {
    final ModelNode result = managementClient.getControllerClient().execute(op);
    if (!Operations.isSuccessfulOutcome(result)) {
        throw new RuntimeException(Operations.getFailureDescription(result).toString());
    }
}