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

The following examples show how to use org.jboss.as.controller.client.helpers.Operations#createOperation() . 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: ExplodedDeploymentTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void browseContent(String path, List<String> expectedContents) throws IOException {
    ModelNode operation = Operations.createOperation(DEPLOYMENT_BROWSE_CONTENT_OPERATION, PathAddress.pathAddress(DEPLOYMENT_PATH).toModelNode());
    if (path != null && !path.isEmpty()) {
        operation.get(PATH).set(path);
    }
    AsyncFuture<ModelNode> future = masterClient.executeAsync(operation, null);
    ModelNode response = awaitSimpleOperationExecution(future);
    assertTrue(Operations.isSuccessfulOutcome(response));
    List<ModelNode> contents = Operations.readResult(response).asList();
    for (ModelNode content : contents) {
        Assert.assertTrue(content.hasDefined("path"));
        String contentPath = content.get("path").asString();
        Assert.assertTrue(content.asString() + " isn't expected", expectedContents.contains(contentPath));
        Assert.assertTrue(content.hasDefined("directory"));
        if (!content.get("directory").asBoolean()) {
            Assert.assertTrue(content.hasDefined("file-size"));
        }
        expectedContents.remove(contentPath);
    }
    Assert.assertTrue(expectedContents.isEmpty());
}
 
Example 2
Source File: SizeAppenderRestartTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@After
public void stopContainer() throws Exception {
    // Remove the servlet
    undeploy();

    final CompositeOperationBuilder builder = CompositeOperationBuilder.create();
    // Remove the handler from the root-logger
    ModelNode op = Operations.createOperation("remove-handler", ROOT_LOGGER_ADDRESS);
    op.get(NAME).set(SIZE_HANDLER_NAME);
    builder.addStep(op);

    // Remove the size-rotating handler
    builder.addStep(Operations.createRemoveOperation(SIZE_HANDLER_ADDRESS));

    executeOperation(builder.build());

    // Stop the container
    container.stop();

    // Remove log files
    clearLogs(logFile);
}
 
Example 3
Source File: AbstractLogFieldsOfLogTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
void resetUser(final CompositeOperationBuilder compositeOp) {
    if (elytronEnabled) {
        ModelNode op = Operations.createOperation("map-remove", userAuthAddress);
        op.get("name").set("properties");
        op.get("key").set(DEFAULT_USER_KEY);
        compositeOp.addStep(op.clone());
        op = Operations.createOperation("map-put", userAuthAddress);
        op.get("name").set("properties");
        op.get("key").set(DEFAULT_USER_KEY);
        op.get("value").set("$local");
        compositeOp.addStep(op.clone());

        userIdentRealmAddress = Operations.createAddress("subsystem", "elytron", "identity-realm", "local");
        compositeOp.addStep(Operations.createWriteAttributeOperation(userIdentRealmAddress, "identity", "$local"));
    } else {
        compositeOp.addStep(Operations.createWriteAttributeOperation(userAuthAddress, "default-user", "$local"));
    }
}
 
Example 4
Source File: NonExistingProfileTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void setup(final ManagementClient managementClient) throws Exception {
    final CompositeOperationBuilder builder = CompositeOperationBuilder.create();

    // add custom file-handler
    ModelNode op = Operations.createAddOperation(createAddress("periodic-rotating-file-handler", "LOGGING_TEST"));
    op.get("append").set("true");
    op.get("suffix").set(".yyyy-MM-dd");
    ModelNode file = new ModelNode();
    file.get("relative-to").set("jboss.server.log.dir");
    file.get("path").set(LOG_FILE_NAME);
    op.get("file").set(file);
    op.get("formatter").set("%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n");
    builder.addStep(op);

    // add handler to root-logger
    op = Operations.createOperation("add-handler", createAddress("root-logger", "ROOT"));
    op.get("name").set("LOGGING_TEST");
    builder.addStep(op);

    executeOperation(builder.build());
}
 
Example 5
Source File: Log4jCustomHandlerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void setup(final ManagementClient managementClient) throws Exception {
    logFile = getAbsoluteLogFilePath(FILE_NAME);

    final CompositeOperationBuilder builder = CompositeOperationBuilder.create();

    // Create the custom handler
    ModelNode op = Operations.createAddOperation(CUSTOM_HANDLER_ADDRESS);
    op.get("class").set("org.apache.log4j.FileAppender");
    op.get("module").set("org.apache.log4j");
    ModelNode opProperties = op.get("properties").setEmptyObject();
    opProperties.get("file").set(logFile.normalize().toString());
    opProperties.get("immediateFlush").set(true);
    builder.addStep(op);

    // Add the handler to the root-logger
    op = Operations.createOperation("add-handler", createAddress("root-logger", "ROOT"));
    op.get(ModelDescriptionConstants.NAME).set(CUSTOM_HANDLER_NAME);
    builder.addStep(op);

    executeOperation(builder.build());
}
 
Example 6
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 7
Source File: ServerHelper.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Shuts down a domain server.
 *
 * @throws IOException if an error occurs communicating with the server
 */
public static void shutdownDomain(final DomainClient client) throws IOException {
    // Now shutdown the host
    final ModelNode address = ServerHelper.determineHostAddress(client);
    final ModelNode shutdownOp = Operations.createOperation("shutdown", address);
    final ModelNode response = client.execute(shutdownOp);
    if (!Operations.isSuccessfulOutcome(response)) {
        Assert.fail("Failed to stop servers: " + response);
    }
}
 
Example 8
Source File: AbstractGitRepositoryTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void removeContentFromDeployment() throws UnsuccessfulOperationException {
    ModelNode op = Operations.createOperation("remove-content",
            new ModelNode().add("deployment", TEST_DEPLOYMENT_RUNTIME_NAME));
    op.get("paths").setEmptyList();
    op.get("paths").add("test.properties");
    ManagementClient client = container.getClient();
    client.executeForResult(op);
}
 
Example 9
Source File: SlaveHostControllerAuthenticationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void addAliasOperation(ModelNode credentialStoreAddress, String aliasName, String secretValue)
    throws IOException {
    ModelNode op = Operations.createOperation("add-alias", credentialStoreAddress);
    op.get("secret-value").set(secretValue);
    op.get("alias").set(aliasName);
    getDomainSlaveClient().execute(new OperationBuilder(op).build());
}
 
Example 10
Source File: AbstractLogFieldsOfLogTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
void configureUser(final ModelControllerClient client, final CompositeOperationBuilder compositeOp) throws IOException {

        // Determine the we should be using a security-realm or SASL (we assume SASL means Elytron is enabled)
        String securityRealm = "ManagementRealm";
        ModelNode op = Operations.createReadResourceOperation(Operations.createAddress("core-service", "management", "management-interface", "http-interface"));
        ModelNode result = executeForSuccess(client, OperationBuilder.create(op).build());
        if (result.hasDefined("security-realm")) {
            securityRealm = result.get("security-realm").asString();
        } else if (result.hasDefined("http-upgrade")) {
            final ModelNode httpUpgrade = result.get("http-upgrade");
            // We could query this further to get the actual name of the configurable-sasl-server-factory. Since this
            // is a test we're making some assumptions to limit the number of query calls made to the server.
            if (httpUpgrade.hasDefined("sasl-authentication-factory")) {
                elytronEnabled = true;
            }
        }

        if (elytronEnabled) {
            userAuthAddress = Operations.createAddress("subsystem", "elytron", "configurable-sasl-server-factory", "configured");
            op = Operations.createOperation("map-remove", userAuthAddress);
            op.get("name").set("properties");
            op.get("key").set(DEFAULT_USER_KEY);
            compositeOp.addStep(op.clone());
            op = Operations.createOperation("map-put", userAuthAddress);
            op.get("name").set("properties");
            op.get("key").set(DEFAULT_USER_KEY);
            op.get("value").set("IAmAdmin");
            compositeOp.addStep(op.clone());

            userIdentRealmAddress = Operations.createAddress("subsystem", "elytron", "identity-realm", "local");
            compositeOp.addStep(Operations.createWriteAttributeOperation(userIdentRealmAddress, "identity", "IAmAdmin"));

        } else {
            userAuthAddress = Operations.createAddress(CORE_SERVICE, MANAGEMENT, SECURITY_REALM, securityRealm, AUTHENTICATION, LOCAL);
            compositeOp.addStep(Operations.createWriteAttributeOperation(userAuthAddress, "default-user", "IAmAdmin"));
        }
    }
 
Example 11
Source File: JMXFacadeListenerInStaticModuleSetupTask.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void setup(ManagementClient managementClient) throws Exception {
    final File dir = new File("target/archives");
    if(dir.exists()) {
        cleanFile(dir);
    }
    dir.mkdirs();
    file = new File(dir, ARCHIVE);
    ServiceActivatorDeploymentUtil.createServiceActivatorListenerArchiveForModule(file, TARGET_OBJECT_NAME, ControlledStateNotificationListener.class);

    // create the module named jmx-notification-listener
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream("jmx-listener-module.xml")) {
        Path moduleXml = Files.createTempFile("jmx-module", ".xml");
        Files.copy(is, moduleXml, StandardCopyOption.REPLACE_EXISTING);

        jmxListenerModule = new TestModule("jmx-notification-listener", moduleXml.toFile());
        jmxListenerModule.addJavaArchive(file);
        jmxListenerModule.create(true);

        Files.delete(moduleXml);
    }

    // add management extension
    final ModelNode op = Operations.createOperation("add", EXTENSION_DMR_ADDRESS.toModelNode());
    op.get("module").set("jmx-notification-listener");
    managementClient.executeForResult(op);
}
 
Example 12
Source File: HandlerCapabilityTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testAsyncAddHandlerInvalidSubhandler() throws Exception {
    final ModelNode address = createSubsystemAddress("async-handler", "async");
    ModelNode op = Operations.createAddOperation(address);
    op.get("queue-length").set(QUEUE_LENGTH);

    executeOperation(op);

    op = Operations.createOperation("add-handler", address);
    op.get("name").set("non-existing");
    executeOperationForFailure(op, NOT_FOUND);

    executeOperation(Operations.createRemoveOperation(address));
}
 
Example 13
Source File: AuditLogBootingSyslogTest.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
void configureAliases(final CompositeOperationBuilder compositeOp) throws IOException {
    ModelNode op = Operations.createOperation("add-alias", PathAddress.parseCLIStyleAddress("/subsystem=elytron/credential-store=test").toModelNode());
    op.get("alias").set(TRUSTSTORE);
    op.get("secret-value").set("123456");
    compositeOp.addStep(op.clone());

    op = Operations.createOperation("add-alias", PathAddress.parseCLIStyleAddress("/subsystem=elytron/credential-store=test").toModelNode());
    op.get("alias").set(CLIENT_CERT_STORE);
    op.get("secret-value").set("123456");
    compositeOp.addStep(op.clone());
}
 
Example 14
Source File: Log4jAppenderTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Before
public void startContainer() throws Exception {
    // Start the server
    container.start();

    logFile = getAbsoluteLogFilePath(FILE_NAME);

    final CompositeOperationBuilder builder = CompositeOperationBuilder.create();

    // Create the custom handler
    ModelNode op = Operations.createAddOperation(CUSTOM_HANDLER_ADDRESS);
    op.get("class").set("org.apache.log4j.FileAppender");
    op.get("module").set("org.apache.log4j");
    ModelNode opProperties = op.get("properties").setEmptyObject();
    opProperties.get("file").set(logFile.normalize().toString());
    opProperties.get("immediateFlush").set(true);
    builder.addStep(op);

    // Add the handler to the root-logger
    op = Operations.createOperation("add-handler", ROOT_LOGGER_ADDRESS);
    op.get(ModelDescriptionConstants.NAME).set(CUSTOM_HANDLER_NAME);
    builder.addStep(op);

    executeOperation(builder.build());

    // Stop the container
    container.stop();
    // Start the server again
    container.start();

    Assert.assertTrue("Container is not started", container.isStarted());

    // Deploy the servlet
    deploy(createDeployment(Log4jServiceActivator.class, Log4jServiceActivator.DEPENDENCIES), DEPLOYMENT_NAME);
}
 
Example 15
Source File: ExplodedDeploymentTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void checkNoContent(String path) throws IOException {
    ModelNode operation = Operations.createOperation(READ_CONTENT, PathAddress.pathAddress(DEPLOYMENT_PATH).toModelNode());
    operation.get(PATH).set(path);
    AsyncFuture<ModelNode> future = masterClient.executeAsync(operation, null);
    ModelNode result = awaitSimpleOperationExecution(future);
    assertFalse(Operations.isSuccessfulOutcome(result));
}
 
Example 16
Source File: ExplodedDeploymentTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private ModelNode deployOnServerGroup() throws MalformedURLException {
    ModelNode operation = Operations.createOperation(ADD, PathAddress.pathAddress(MAIN_SERVER_GROUP, DEPLOYMENT_PATH).toModelNode());
    operation.get(ENABLED).set(true);
    return operation;
}
 
Example 17
Source File: AuditLogBootingSyslogTest.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
void configureServerName(final CompositeOperationBuilder compositeOp) throws IOException {
    ModelNode op = Operations.createOperation("write-attribute", PathAddress.EMPTY_ADDRESS.toModelNode());
    op.get("name").set("name");
    op.get("value").set("supercalifragilisticexpialidocious");
    compositeOp.addStep(op);
}
 
Example 18
Source File: SocketHandlerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private ModelNode addSocketHandler(final String name, final String level, final String protocol, final Path keyStore) throws IOException {
    final CompositeOperationBuilder builder = CompositeOperationBuilder.create();
    // Add a socket handler
    final ModelNode address = SUBSYSTEM_ADDRESS.append("socket-handler", name).toModelNode();
    ModelNode op = Operations.createAddOperation(address);
    op.get("named-formatter").set(FORMATTER_NAME);
    op.get("outbound-socket-binding-ref").set(SOCKET_BINDING_NAME);
    if (level != null) {
        op.get("level").set(level);
    }
    if (protocol != null) {
        op.get("protocol").set(protocol);
    }
    if (keyStore != null) {
        // We need to add the SSL context to Elytron
        final ModelNode keyStoreAddress = Operations.createAddress("subsystem", "elytron", "key-store", "log-test-ks");
        resourcesToRemove.addFirst(keyStoreAddress);
        final ModelNode keyStoreAddOp = Operations.createAddOperation(keyStoreAddress);
        keyStoreAddOp.get("path").set(keyStore.toAbsolutePath().toString());
        keyStoreAddOp.get("type").set("JKS");
        final ModelNode creds = keyStoreAddOp.get("credential-reference").setEmptyObject();
        creds.get("clear-text").set(TEST_PASSWORD);
        builder.addStep(keyStoreAddOp);

        final ModelNode keyManagerAddress = Operations.createAddress("subsystem", "elytron", "trust-manager", "log-test-tm");
        resourcesToRemove.addLast(keyManagerAddress);
        final ModelNode keyManagerAddOp = Operations.createAddOperation(keyManagerAddress);
        keyManagerAddOp.get("key-store").set("log-test-ks");
        builder.addStep(keyManagerAddOp);

        final ModelNode sslContextAddress = Operations.createAddress("subsystem", "elytron", "client-ssl-context", "log-test-ssl-context");
        resourcesToRemove.addLast(sslContextAddress);
        final ModelNode sslContextAddOp = Operations.createAddOperation(sslContextAddress);
        sslContextAddOp.get("trust-manager").set("log-test-tm");
        sslContextAddOp.get("protocols").setEmptyList().add("TLSv1.2");
        builder.addStep(sslContextAddOp);

        op.get("ssl-context").set("log-test-ssl-context");
    }
    builder.addStep(op);
    resourcesToRemove.addFirst(address);

    // Add the handler to the logger
    op = Operations.createOperation("add-handler", LOGGER_ADDRESS);
    op.get("name").set(name);
    builder.addStep(op);
    executeOperation(builder.build());
    return address;
}
 
Example 19
Source File: PreparedResponseTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void block(ManagementClient client) throws UnsuccessfulOperationException {
    ModelNode blockOp = Operations.createOperation("block", PathAddress.pathAddress(SUBSYSTEM, BlockerExtension.SUBSYSTEM_NAME).toModelNode());
    blockOp.get("block-point").set("SERVICE_STOP");
    blockOp.get("block-time").set(SHUTDOWN_WAITING_TIME);
    client.executeForResult(blockOp);
}
 
Example 20
Source File: AbstractGitRepositoryTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void undeployDeployment() throws UnsuccessfulOperationException {
    ModelNode op = Operations.createOperation("undeploy",
            new ModelNode().add("deployment", TEST_DEPLOYMENT_RUNTIME_NAME));
    ManagementClient client = container.getClient();
    client.executeForResult(op);
}