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

The following examples show how to use org.jboss.as.controller.client.helpers.Operations#createReadAttributeOperation() . 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: CachedDcDomainTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private ModelNode readLoggingApiDependenciesAtServerOtherTwo(DomainClient client) {
    final ModelNode hostLoggingAddress = new ModelNode()
            .add(HOST, "slave")
            .add(SERVER, "other-two")
            .add(SUBSYSTEM, "logging");

    final ModelNode readAttributeOp = Operations
            .createReadAttributeOperation(hostLoggingAddress, "add-logging-api-dependencies");
    try {
        final ModelNode result = client.execute(readAttributeOp);
        assertEquals(SUCCESS, result.get(OUTCOME).asString());
        return result;
    } catch (IOException ioe) {
        throw new RuntimeException("Can't read attribute 'add-logging-api-dependencies' from address "
            + hostLoggingAddress, ioe);
    }
}
 
Example 2
Source File: AbstractTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public Boolean apply(final EmbeddedManagedProcess server) {

    try {
        final ModelControllerClient client = server.getModelControllerClient();
        final ModelNode hostAddress = determineHostAddress(client);
        final ModelNode op = Operations.createReadAttributeOperation(hostAddress, "host-state");
        final ModelNode result = client.execute(op);
        if (Operations.isSuccessfulOutcome(result) &&
                ClientConstants.CONTROLLER_PROCESS_STATE_RUNNING.equals(Operations.readResult(result).asString())) {
            return true;
        }
    } catch (IllegalStateException | IOException ignore) {
    }
    return false;
}
 
Example 3
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.getControllerClient().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 4
Source File: SocketHandlerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void tearDown(final ManagementClient managementClient) throws Exception {
    try {
        if (describeResult != null) {
            final CompositeOperationBuilder builder = CompositeOperationBuilder.create();
            // First remove the subsystem, then read add based on the describe op.
            builder.addStep(Operations.createRemoveOperation(SUBSYSTEM_ADDRESS.toModelNode()));
            for (ModelNode addOp : describeResult.asList()) {
                builder.addStep(addOp);
            }
            executeOperation(managementClient, builder.build());
        }
    } finally {
        // Reload if required
        final ModelNode op = Operations.createReadAttributeOperation(new ModelNode().setEmptyList(), "server-state");
        ModelNode result = executeOperation(managementClient, op);
        if (ClientConstants.CONTROLLER_PROCESS_STATE_RELOAD_REQUIRED.equals(result.asString())) {
            ServerReload.executeReloadAndWaitForCompletion(managementClient.getControllerClient());
        }
    }
}
 
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: SystemPropertyResetTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testHostControllerSystemProperties() throws Exception {

    final Map<String, String> setProperties = Collections.singletonMap("jboss.domain.log.dir", Environment.LOG_DIR.toString());
    setSystemProperties(setProperties);

    final Path baseDir = Environment.JBOSS_HOME.resolve("domain");

    final Map<String, String> expectedProperties = new HashMap<>();
    expectedProperties.put("jboss.domain.base.dir", resolvePath(baseDir));
    expectedProperties.put("jboss.domain.config.dir", resolvePath(baseDir, "configuration"));
    expectedProperties.put("jboss.domain.content.dir", resolvePath(baseDir, "data", "content"));
    expectedProperties.put("jboss.domain.data.dir", resolvePath(baseDir, "data"));
    expectedProperties.put("jboss.domain.temp.dir", resolvePath(baseDir, "tmp"));

    final HostController server = EmbeddedProcessFactory.createHostController(Environment.createConfigBuilder().build());

    validateNullProperties(expectedProperties.keySet());
    validateProperties(setProperties);

    startAndWaitFor(server, HOST_CONTROLLER_CHECK);
    // Ensure the server has started
    try (ModelControllerClient client = server.getModelControllerClient()) {
        final ModelNode op = Operations.createReadAttributeOperation(AbstractTestCase.EMPTY_ADDRESS, "launch-type");
        final ModelNode result = executeOperation(client, op);
        Assert.assertEquals("EMBEDDED", result.asString());
    }
    // The properties should now be set
    validateProperties(expectedProperties);
    validateProperties(setProperties);

    // Stop the server and validate the properties have been reset
    server.stop();
    validateNullProperties(expectedProperties.keySet());
    validateProperties(setProperties);
}
 
Example 7
Source File: CachedDcDomainTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ModelNode readLoggingApiDependencies(DomainClient client) throws IOException {
    final ModelNode readAttributeOp = Operations
            .createReadAttributeOperation(getProfileDefaultLoggingAddr(), "add-logging-api-dependencies");
    final ModelNode result = client.execute(readAttributeOp);
    assertEquals(SUCCESS, result.get(OUTCOME).asString());
    return result;
}
 
Example 8
Source File: AutoIgnoredResourcesDomainTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void setIgnoreUnusedConfiguration(boolean ignoreUnusedConfiguration) throws Exception {
    ModelNode slaveModel = validateResponse(masterClient.execute(Operations.createReadAttributeOperation(SLAVE_ROOT_ADDRESS, DOMAIN_CONTROLLER)), true);
    slaveModel.get(REMOTE).get(IGNORE_UNUSED_CONFIG).set(ignoreUnusedConfiguration);
    ModelNode op = Operations.createWriteAttributeOperation(SLAVE_ROOT_ADDRESS, DOMAIN_CONTROLLER, slaveModel);
    validateResponse(masterClient.execute(op));

    // reload slave
    Assert.assertEquals(RELOAD_REQUIRED, getSlaveHostStatus());
    reloadSlaveHost();

    // verify value of ignore-unused-configuration
    op = Operations.createReadAttributeOperation(SLAVE_ROOT_ADDRESS, DOMAIN_CONTROLLER);
    Assert.assertEquals(ignoreUnusedConfiguration, validateResponse(masterClient.execute(op), true).get(REMOTE).get(IGNORE_UNUSED_CONFIG).asBoolean());
}
 
Example 9
Source File: AutoIgnoredResourcesDomainTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void undefineIgnoreUnsusedConfiguration() throws Exception {
    // undefine ignore-unused-configuration
    ModelNode slaveModel = validateResponse(masterClient.execute(Operations.createReadAttributeOperation(SLAVE_ROOT_ADDRESS, DOMAIN_CONTROLLER)), true);
    slaveModel.get(REMOTE).remove(IGNORE_UNUSED_CONFIG);
    ModelNode op = Operations.createWriteAttributeOperation(SLAVE_ROOT_ADDRESS, DOMAIN_CONTROLLER, slaveModel);
    validateResponse(masterClient.execute(op));

    // reload slave
    Assert.assertEquals(RELOAD_REQUIRED, getSlaveHostStatus());
    reloadSlaveHost();

    // verify that ignore-unused-configuration is undefined
    op = Operations.createReadAttributeOperation(SLAVE_ROOT_ADDRESS, DOMAIN_CONTROLLER);
    Assert.assertFalse(validateResponse(masterClient.execute(op), true).get(REMOTE).hasDefined(IGNORE_UNUSED_CONFIG));
}
 
Example 10
Source File: ServerHelper.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static List<JsonObject> readLogFileFromModel(final String logFileName, final String... addressPrefix) throws IOException {
    final Collection<String> addr = new ArrayList<>();
    if (addressPrefix != null) {
        Collections.addAll(addr, addressPrefix);
    }
    addr.add("subsystem");
    addr.add("logging");
    addr.add("log-file");
    addr.add(logFileName);
    final ModelNode address = Operations.createAddress(addr);
    final ModelNode op = Operations.createReadAttributeOperation(address, "stream");
    try (ModelControllerClient client = TestSuiteEnvironment.getModelControllerClient()) {
        final OperationResponse response = client.executeOperation(Operation.Factory.create(op), OperationMessageHandler.logging);
        final ModelNode result = response.getResponseNode();
        if (Operations.isSuccessfulOutcome(result)) {
            final OperationResponse.StreamEntry entry = response.getInputStream(Operations.readResult(result).asString());
            if (entry == null) {
                throw new RuntimeException(String.format("Failed to find entry with UUID %s for log file %s",
                        Operations.readResult(result).asString(), logFileName));
            }
            final List<JsonObject> lines = new ArrayList<>();
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(entry.getStream(), StandardCharsets.UTF_8))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    try (JsonReader jsonReader = Json.createReader(new StringReader(line))) {
                        lines.add(jsonReader.readObject());
                    }
                }
            }
            return lines;
        }
        throw new RuntimeException(String.format("Failed to read log file %s: %s", logFileName, Operations.getFailureDescription(result).asString()));
    }
}
 
Example 11
Source File: ElytronModelControllerClientTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void testConnection() throws IOException {

        final ModelNode op = Operations.createReadAttributeOperation(new ModelNode().setEmptyList(), "server-state");
        ModelNode result = CONTROLLER.getClient().getControllerClient().execute(op);
        if (!Operations.isSuccessfulOutcome(result)) {
            Assert.fail(Operations.getFailureDescription(result).asString());
        }
    }
 
Example 12
Source File: DeploymentScannerShutdownTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Path getAbsoluteLogFilePath(final String relativePath, final String fileName) throws UnsuccessfulOperationException {
    final ModelNode address = PathAddress.pathAddress(
            PathElement.pathElement(ModelDescriptionConstants.PATH, relativePath)).toModelNode();
    final ModelNode result;
    try {
        final ModelNode op = Operations.createReadAttributeOperation(address, ModelDescriptionConstants.PATH);
        result = container.getClient().executeForResult(op);
        return Paths.get(result.asString(), fileName);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
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: AbstractTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static ModelNode determineHostAddress(final ModelControllerClient client) throws IOException {
    final ModelNode op = Operations.createReadAttributeOperation(EMPTY_ADDRESS, "local-host-name");
    ModelNode response = client.execute(op);
    if (Operations.isSuccessfulOutcome(response)) {
        return Operations.createAddress("host", Operations.readResult(response).asString());
    }
    throw new IOException("Failed to determine host name: " + Operations.readResult(response).asString());
}
 
Example 15
Source File: SystemPropertyResetTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testStandaloneSystemProperties() throws Exception {
    final Map<String, String> setProperties = Collections.singletonMap("jboss.server.log.dir", Environment.LOG_DIR.toString());
    setSystemProperties(setProperties);

    final Path baseDir = Environment.JBOSS_HOME.resolve("standalone");

    final Map<String, String> expectedProperties = new HashMap<>();
    expectedProperties.put("jboss.server.base.dir", resolvePath(baseDir));
    expectedProperties.put("jboss.server.config.dir", resolvePath(baseDir, "configuration"));
    expectedProperties.put("jboss.server.content.dir", resolvePath(baseDir, "data", "content"));
    expectedProperties.put("jboss.server.data.dir", resolvePath(baseDir, "data"));
    expectedProperties.put("jboss.server.temp.dir", resolvePath(baseDir, "tmp"));

    final StandaloneServer server = EmbeddedProcessFactory.createStandaloneServer(Environment.createConfigBuilder().build());

    validateNullProperties(expectedProperties.keySet());
    validateProperties(setProperties);

    startAndWaitFor(server, STANDALONE_CHECK);
    // Ensure the server has started
    try (ModelControllerClient client = server.getModelControllerClient()) {
        final ModelNode op = Operations.createReadAttributeOperation(AbstractTestCase.EMPTY_ADDRESS, "launch-type");
        final ModelNode result = executeOperation(client, op);
        Assert.assertEquals("EMBEDDED", result.asString());
    }
    // The properties should now be set
    validateProperties(expectedProperties);
    validateProperties(setProperties);

    // Stop the server and validate the properties have been reset
    server.stop();
    validateNullProperties(expectedProperties.keySet());
    validateProperties(setProperties);
}
 
Example 16
Source File: ServerAutoStartTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void assertAutoStartStatus(final ModelControllerClient client, ModelNode address, boolean autostart) throws IOException {
    final ModelNode operation = Operations.createReadAttributeOperation(address, AUTO_START);
    ModelNode result = validateResponse(client.execute(operation));
    Assert.assertThat(result.asBoolean(), is(autostart));
}
 
Example 17
Source File: AbstractDeploymentManagerTest.java    From wildfly-maven-plugin with GNU Lesser General Public License v2.1 4 votes vote down vote up
private long readLastEnabledTime(final ModelNode address) throws IOException {
    final ModelNode op = Operations.createReadAttributeOperation(address, "enabled-time");
    final ModelNode response = executeOp(op);
    return response.isDefined() ? response.asLong() : 0L;
}
 
Example 18
Source File: ServerHelper.java    From wildfly-core with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Attempts to determine the name for a domain server.
 *
 * @param client the client used to communicate with the server
 *
 * @return the host name
 *
 * @throws IOException if an error occurs determining the host name
 */
public static String determineHostName(final ModelControllerClient client) throws IOException {
    final ModelNode op = Operations.createReadAttributeOperation(EMPTY_ADDRESS, "local-host-name");
    ModelNode response = client.execute(op);
    if (Operations.isSuccessfulOutcome(response)) {
        return Operations.readResult(response).asString();
    }
    throw new IOException("Failed to determine host name: " + Operations.readResult(response).asString());
}
 
Example 19
Source File: ServerHelper.java    From wildfly-maven-plugin with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * 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);
}
 
Example 20
Source File: ServerHelper.java    From wildfly-maven-plugin with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Checks the running server to determine if it is a managed domain server.
 * <p>
 * Note that if the operation fails this will return {@code false}. It's better to use the
 * {@link ContainerDescription#isDomain()} which can be queried via the
 * {@link #getContainerDescription(ModelControllerClient)}. This will throw a {@link OperationExecutionException}
 * if the operation fails.
 * </p>
 *
 * @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
 * @see #getContainerDescription(ModelControllerClient)
 * @deprecated use {@link ContainerDescription#isDomain()}
 */
@Deprecated
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;
}