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

The following examples show how to use org.jboss.as.controller.client.helpers.Operations#createWriteAttributeOperation() . 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: SocketHandlerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testOutboundSocketBindingChange() throws Exception {
    // Add a new outbound-socket-binding
    final String altName = "alt-log-server";
    final ModelNode outboundSocketBindingAddress = Operations.createAddress("socket-binding-group", "standard-sockets",
            "remote-destination-outbound-socket-binding", altName);
    ModelNode op = Operations.createAddOperation(outboundSocketBindingAddress);
    op.get("host").set(HOSTNAME);
    op.get("port").set(ALT_PORT);
    executeOperation(op);
    resourcesToRemove.addLast(outboundSocketBindingAddress);

    // Create the server, plus a new server listening on the alternate port
    try (JsonLogServer server = JsonLogServer.createTcpServer(PORT);
         JsonLogServer altServer = JsonLogServer.createTcpServer(ALT_PORT)
    ) {
        server.start(DFT_TIMEOUT);
        altServer.start(DFT_TIMEOUT);
        final ModelNode altAddress = addSocketHandler("test-log-server-alt", null, null);

        // Log a single message to the current log server and validate
        JsonObject foundMessage = executeRequest("Test first message",
                Collections.singletonMap(LoggingServiceActivator.LOG_LEVELS_KEY, "INFO"), server);
        Assert.assertEquals("Test first message", foundMessage.getString("message"));

        // Change the outbound-socket-binding-ref, which should require a reload
        op = Operations.createWriteAttributeOperation(altAddress, "outbound-socket-binding-ref", altName);
        executeOperation(op);
        ServerReload.executeReloadAndWaitForCompletion(client.getControllerClient());

        // Log a single message to the alternate log server and validate
        foundMessage = executeRequest("Test alternate message",
                Collections.singletonMap(LoggingServiceActivator.LOG_LEVELS_KEY, "INFO"), altServer);
        Assert.assertEquals("Test alternate message", foundMessage.getString("message"));
    }
}
 
Example 2
Source File: FilterTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testLoggerAndHandlerPropertyChangeFilter() throws Exception {
    configure(FILTER_NAME, FILTER_NAME);
    final String msg = "Test handler filter";
    String expectedMsg = msg + " | constructor text | property text | constructor text | property text";
    final int offset = test(msg, expectedMsg);

    final String changedPropertyMsg = " | changed text";
    final ModelNode properties = new ModelNode().setEmptyObject();
    properties.get("propertyText").set(changedPropertyMsg);
    final ModelNode op = Operations.createWriteAttributeOperation(FILTER_ADDRESS, "properties", properties);
    executeOperation(op);
    expectedMsg = msg + " | constructor text | changed text | constructor text | changed text";
    test(msg, expectedMsg, offset);
}
 
Example 3
Source File: FilterTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testLoggerAndHandlerConstructorChangeFilter() throws Exception {
    configure(FILTER_NAME, FILTER_NAME);
    final String msg = "Test handler filter";
    String expectedMsg = msg + " | constructor text | property text | constructor text | property text";
    final int offset = test(msg, expectedMsg);

    final String changedPropertyMsg = " | changed text";
    final ModelNode properties = new ModelNode().setEmptyObject();
    properties.get("constructorText").set(changedPropertyMsg);
    final ModelNode op = Operations.createWriteAttributeOperation(FILTER_ADDRESS, "constructor-properties", properties);
    executeOperation(Operation.Factory.create(op), true);
    expectedMsg = msg + " | changed text | property text | changed text | property text";
    test(msg, expectedMsg, offset);
}
 
Example 4
Source File: LoggerCapabilityTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testWriteInvalidHandlerToRootLogger() throws IOException {
    final ModelNode address = createSubsystemAddress("root-logger", "ROOT");
    final ModelNode handlers = new ModelNode().setEmptyList().add("non-existing");
    final ModelNode op = Operations.createWriteAttributeOperation(address, "handlers", handlers);
    executeOperationForFailure(op, NOT_FOUND);
}
 
Example 5
Source File: LoggerCapabilityTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testWriteInvalidHandlerToLogger() throws IOException {
    final ModelNode address = createSubsystemAddress("logger", LOGGER_NAME);
    executeOperation(Operations.createAddOperation(address));
    final ModelNode handlers = new ModelNode().setEmptyList().add("non-existing");
    final ModelNode op = Operations.createWriteAttributeOperation(address, "handlers", handlers);
    executeOperationForFailure(op, NOT_FOUND);
    executeOperation(Operations.createRemoveOperation(address));
}
 
Example 6
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 7
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 8
Source File: JmxRBACProviderHostScopedRolesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void setNonCoreMbeanSensitivity(DomainClient domainClient, boolean sensitivity) throws IOException {
    ModelNode op = Operations.createWriteAttributeOperation(
            PathAddress.pathAddress(PathElement.pathElement(PROFILE, "profile-a"), PathElement.pathElement(SUBSYSTEM, "jmx")).toModelNode(),
            "non-core-mbean-sensitivity", sensitivity);
    ModelNode result = domainClient.execute(op);
    assertTrue(Operations.isSuccessfulOutcome(result));
    op = Operations.createWriteAttributeOperation(
            PathAddress.pathAddress(PathElement.pathElement(PROFILE, "profile-b"), PathElement.pathElement(SUBSYSTEM, "jmx")).toModelNode(),
            "non-core-mbean-sensitivity", sensitivity);
    result = domainClient.execute(op);
    assertTrue(Operations.isSuccessfulOutcome(result));
}
 
Example 9
Source File: JmxRBACProviderServerGroupScopedRolesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void setNonCoreMbeanSensitivity(DomainClient domainClient, boolean sensitivity) throws IOException {
    ModelNode op = Operations.createWriteAttributeOperation(
            PathAddress.pathAddress(PathElement.pathElement(PROFILE, "profile-a"), PathElement.pathElement(SUBSYSTEM, "jmx")).toModelNode(),
            "non-core-mbean-sensitivity", sensitivity);
    ModelNode result = domainClient.execute(op);
    assertTrue(Operations.isSuccessfulOutcome(result));
    op = Operations.createWriteAttributeOperation(
            PathAddress.pathAddress(PathElement.pathElement(PROFILE, "profile-b"), PathElement.pathElement(SUBSYSTEM, "jmx")).toModelNode(),
            "non-core-mbean-sensitivity", sensitivity);
    result = domainClient.execute(op);
    assertTrue(Operations.isSuccessfulOutcome(result));
}
 
Example 10
Source File: CachedDcDomainTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private boolean setLoggingApiDependencies(DomainClient client) throws IOException {
    boolean isAddLoggingApiDependencies = readLoggingApiDependencies(client).get("result").asBoolean();

    final ModelNode writeAttributeOp = Operations
        .createWriteAttributeOperation(getProfileDefaultLoggingAddr(), "add-logging-api-dependencies", !isAddLoggingApiDependencies);
    final ModelNode result = client.execute(writeAttributeOp);
    assertEquals(SUCCESS, result.get(OUTCOME).asString());
    return !isAddLoggingApiDependencies;
}
 
Example 11
Source File: LogFilterTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void addLoggingFilter() {
    ModelNode consoleAddress = createAddress("console-handler", "CONSOLE").toModelNode();
    ModelNode replaceValue = new ModelNode();
    replaceValue.get("pattern").set("JBAS");
    replaceValue.get("replacement").set("DUMMY");
    replaceValue.get("replace-all").set(true);
    ModelNode filterAttributeValue = new ModelNode();
    filterAttributeValue.get("replace").set(replaceValue);

    final ModelNode writeOp = Operations.createWriteAttributeOperation(consoleAddress, "filter", filterAttributeValue);
    executeOperation(kernelServices, writeOp);
    // Create the read operation
    final ModelNode readAttributeOp = Operations.createReadAttributeOperation(consoleAddress, "filter");
    ModelNode result = executeOperation(kernelServices, readAttributeOp);
    assertThat(result, is(notNullValue()));
    assertThat(result.get(OUTCOME).asString(), is("success"));
    assertEquals("{\"replace\" => {\"replace-all\" => true,\"pattern\" => \"JBAS\",\"replacement\" => \"DUMMY\"}}",
            Operations.readResult(result).asString());
    ModelNode readResourceOp = Operations.createReadResourceOperation(consoleAddress);
    result = executeOperation(kernelServices, readResourceOp);
    assertThat(result, is(notNullValue()));
    assertThat(result.get(OUTCOME).asString(), is("success"));
    assertThat(result.get(RESULT).hasDefined("filter-spec"), is(true));
    ModelNode filterSpec = result.get(RESULT).get("filter-spec");
    assertThat(filterSpec.asString(), is("substituteAll(\"JBAS\",\"DUMMY\")"));

    assertThat(result.get(RESULT).hasDefined("filter"), is(true));
    assertThat(result.get(RESULT).get("filter").hasDefined("replace"), is(true));
    ModelNode replaceResult = result.get(RESULT).get("filter").get("replace");
    assertThat(replaceResult.hasDefined("pattern"), is(true));
    assertThat(replaceResult.get("pattern").asString(), is("JBAS"));
    assertThat(replaceResult.hasDefined("replacement"), is(true));
    assertThat(replaceResult.get("replacement").asString(), is("DUMMY"));
    assertThat(replaceResult.hasDefined("pattern"), is(true));
    assertThat(replaceResult.get("pattern").asString(), is("JBAS"));
}
 
Example 12
Source File: AbstractLoggingTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void setEnabled(final ModelNode address, final boolean enabled) throws IOException {
    final ModelNode op = Operations.createWriteAttributeOperation(address, ModelDescriptionConstants.ENABLED, enabled);
    executeOperation(op);
}
 
Example 13
Source File: ServerConfigurator.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void configureDomain() throws IOException, InterruptedException {
    final Path stdout = Paths.get(TestSuiteEnvironment.getTmpDir(), "config-domain-stdout.txt");
    final DomainCommandBuilder builder = DomainCommandBuilder.of(ServerHelper.JBOSS_HOME)
            .addHostControllerJavaOptions(ServerHelper.DEFAULT_SERVER_JAVA_OPTS);

    final String localRepo = System.getProperty("maven.repo.local");
    if (localRepo != null) {
        builder.addHostControllerJavaOption("-Dmaven.repo.local=" + localRepo)
                .addProcessControllerJavaOption("-Dmaven.repo.local=" + localRepo);
    }

    Process process = null;
    try {
        process = Launcher.of(builder)
                .setRedirectErrorStream(true)
                .redirectOutput(stdout)
                .launch();
        ServerHelper.waitForDomain(process, () -> readStdout(stdout));

        // Start server-three, configure it, then stop it
        try (DomainClient client = DomainClient.Factory.create(TestSuiteEnvironment.getModelControllerClient())) {
            final String hostName = ServerHelper.determineHostName(client);
            // Configure server-three to launch with an agent
            final CompositeOperationBuilder opBuilder = CompositeOperationBuilder.create();
            ModelNode address = Operations.createAddress("profile", "default");
            ModelNode op = Operations.createOperation("clone", address);
            op.get("to-profile").set("test");
            opBuilder.addStep(op);

            address = Operations.createAddress("server-group", "other-server-group");
            op = Operations.createWriteAttributeOperation(address, "profile", "test");
            opBuilder.addStep(op);

            address = Operations.createAddress("host", hostName, "server-config", "server-three", "jvm", "default");
            op = Operations.createAddOperation(address);
            op.get("module-options").setEmptyList().add("-javaagent:" + ServerHelper.JBOSS_HOME.resolve("logging-agent-tests.jar") + "=" + LoggingAgent.DEBUG_ARG);
            opBuilder.addStep(op);

            address = Operations.createAddress("profile", "test", "subsystem", "logging", "custom-formatter", "json");
            op = Operations.createAddOperation(address);
            op.get("class").set("org.jboss.logmanager.formatters.JsonFormatter");
            op.get("module").set("org.jboss.logmanager");
            final ModelNode properties = op.get("properties").setEmptyObject();
            properties.get("exceptionOutputType").set("FORMATTED");
            properties.get("prettyPrint").set(false);
            opBuilder.addStep(op);

            address = Operations.createAddress("profile", "test", "subsystem", "logging", "file-handler", "json");
            op = Operations.createAddOperation(address);
            op.get("append").set(false);
            op.get("level").set("DEBUG");
            op.get("autoflush").set(true);
            op.get("named-formatter").set("json");
            final ModelNode file = op.get("file");
            file.get("relative-to").set("jboss.server.log.dir");
            file.get("path").set("json.log");
            opBuilder.addStep(op);

            address = Operations.createAddress("profile", "test", "subsystem", "logging", "logger", "org.wildfly.common.test.LoggingAgent");
            op = Operations.createAddOperation(address);
            op.get("handlers").setEmptyList().add("json");
            op.get("level").set("DEBUG");
            opBuilder.addStep(op);

            executeOperation(client, opBuilder.build());


            client.startServer(hostName, "server-three");
            ServerHelper.waitForManagedServer(client, "server-three", () -> readStdout(stdout));
            ServerHelper.shutdownDomain(client);
        }
        if (!process.waitFor(ServerHelper.TIMEOUT, TimeUnit.SECONDS)) {
            Assert.fail(readStdout(stdout));
        }

        if (process.exitValue() != 0) {
            Assert.fail(readStdout(stdout));
        }
    } finally {
        ProcessHelper.destroyProcess(process);
    }
}