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

The following examples show how to use org.jboss.as.controller.client.helpers.Operations#createAddOperation() . 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: DeploymentResourceTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void setup(ManagementClient managementClient) throws Exception {

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

    // create dummy-profile1
    builder.addStep(Operations.createAddOperation(createAddress("logging-profile", PROFILE_NAME)));

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

    executeOperation(builder.build());
}
 
Example 2
Source File: FullReplaceUndeployTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static Operation createDeployAddOperation(final InputStream content, final String name, final String runtimeName) {
    final Operations.CompositeOperationBuilder builder = Operations.CompositeOperationBuilder.create(true);
    final ModelNode address = createAddress(DEPLOYMENT, name);
    final ModelNode addOperation = createAddOperation(address);
    if (runtimeName != null) {
        addOperation.get(RUNTIME_NAME).set(runtimeName);
    }
    addContent(builder, addOperation, content);
    builder.addStep(addOperation);

    final ModelNode sgAddress = Operations.createAddress(SERVER_GROUP, "main-server-group", DEPLOYMENT, name);
    final ModelNode op = Operations.createAddOperation(sgAddress);
    op.get("enabled").set(true);
    if (runtimeName != null) {
        op.get(RUNTIME_NAME).set(runtimeName);
    }
    builder.addStep(op);
    return builder.build();
}
 
Example 3
Source File: CapabilityTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@BeforeClass
public static void startAdminOnly() throws IOException {
    Assert.assertTrue("Could not locate default standalone configuration file: " + DFT_SERVER_CONFIG, Files.exists(DFT_SERVER_CONFIG));
    // Copy the server configuration
    Files.copy(DFT_SERVER_CONFIG, SERVER_CONFIG);
    container.start(SERVER_CONFIG.getFileName().toString(), Server.StartMode.ADMIN_ONLY);
    final CompositeOperationBuilder builder = CompositeOperationBuilder.create();
    // Add a logging profile
    builder.addStep(Operations.createAddOperation(createProfileSubsystemAddress(PROFILE_NAME)));

    // Add a default formatter
    builder.addStep(Operations.createAddOperation(createProfileSubsystemAddress(PROFILE_NAME, "pattern-formatter", FORMATTER_NAME)));

    // Add a handler to the profile
    ModelNode op = Operations.createAddOperation(createProfileSubsystemAddress(PROFILE_NAME, "console-handler", HANDLER_NAME));
    op.get("named-formatter").set(FORMATTER_NAME);
    builder.addStep(op);

    op = Operations.createAddOperation(createProfileSubsystemAddress(PROFILE_NAME, "root-logger", "ROOT"));
    op.get("handlers").setEmptyList().add(HANDLER_NAME);
    builder.addStep(op);
    executeOperation(builder.build());
}
 
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 setup(final ManagementClient managementClient) throws Exception {
    // Describe the current subsystem to restore in the tearDown
    final ModelNode describeOp = Operations.createOperation("describe", SUBSYSTEM_ADDRESS.toModelNode());
    describeResult = executeOperation(managementClient, describeOp);

    final CompositeOperationBuilder builder = CompositeOperationBuilder.create();

    final ModelNode outboundSocketBindingAddress = Operations.createAddress("socket-binding-group", "standard-sockets",
            "remote-destination-outbound-socket-binding", SOCKET_BINDING_NAME);
    ModelNode op = Operations.createAddOperation(outboundSocketBindingAddress);
    op.get("host").set(HOSTNAME);
    op.get("port").set(PORT);
    builder.addStep(op);

    final ModelNode formatterAddress = SUBSYSTEM_ADDRESS.append("json-formatter", FORMATTER_NAME).toModelNode();
    builder.addStep(Operations.createAddOperation(formatterAddress));

    builder.addStep(Operations.createAddOperation(LOGGER_ADDRESS));

    executeOperation(managementClient, builder.build());
}
 
Example 5
Source File: CustomHandlerOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testCustomHandler() throws Exception {

    testCustomHandler(null);

    // Create the profile
    final String profileName = "test-profile";
    final ModelNode profileAddress = createAddress("logging-profile", profileName);
    final ModelNode addOp = Operations.createAddOperation(profileAddress);
    executeOperation(addOp);

    testCustomHandler(profileName);

    // Remove the profile
    executeOperation(Operations.createRemoveOperation(profileAddress));
    verifyRemoved(profileAddress);
}
 
Example 6
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 7
Source File: SizeAppenderRestartTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Before
public void startContainer() throws Exception {
    // Start the server
    container.start();
    Assert.assertTrue("Container is not started", container.isStarted());
    logFile = getAbsoluteLogFilePath(FILE_NAME);
    // Deploy the servlet
    deploy();

    // Create the size-rotating handler
    ModelNode op = Operations.createAddOperation(SIZE_HANDLER_ADDRESS);
    ModelNode file = new ModelNode();
    file.get("path").set(logFile.normalize().toString());
    op.get(FILE).set(file);
    executeOperation(op);

    // Add the handler to the root-logger
    op = Operations.createOperation("add-handler", ROOT_LOGGER_ADDRESS);
    op.get(NAME).set(SIZE_HANDLER_NAME);
    executeOperation(op);
}
 
Example 8
Source File: LoggingPreferencesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Before
public void prepareContainer() throws Exception {
    // Start the container
    container.start();

    if (profileLog == null) {
        profileLog = getAbsoluteLogFilePath(FILE_HANDLER_FILE_NAME);
        perDeployLog = getAbsoluteLogFilePath(PER_DEPLOY_FILE_NAME);
    }

    final CompositeOperationBuilder builder = CompositeOperationBuilder.create();
    // Create a new logging profile
    builder.addStep(Operations.createAddOperation(PROFILE_ADDRESS));

    // Add root logger to the profile
    builder.addStep(Operations.createAddOperation(ROOT_LOGGER_ADDRESS));

    // Add file handler to the profile
    ModelNode op = Operations.createAddOperation(FILE_HANDLER_ADDRESS);
    ModelNode file = new ModelNode();
    file.get(PATH).set(profileLog.normalize().toString());
    op.get(FILE).set(file);
    builder.addStep(op);

    executeOperation(builder.build());

    // Register file logger to root
    op = Operations.createOperation("add-handler", ROOT_LOGGER_ADDRESS);
    op.get(NAME).set(FILE_HANDLER_NAME);
    executeOperation(op);

    final JavaArchive archive = createDeployment(Collections.singletonMap("Logging-Profile", PROFILE_NAME))
            .addAsResource(LoggingPreferencesTestCase.class.getPackage(), "per-deploy-logging.properties", "META-INF/logging.properties");
    deploy(archive);
}
 
Example 9
Source File: LegacySecurityRealmPropagationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ModelNode addSecurityRealm() {
    ModelNode operation = Operations.createCompositeOperation();
    operation.get(STEPS).add(Operations.createAddOperation(PathAddress.parseCLIStyleAddress("/host=master/core-service=management/security-realm=TestRealm").toModelNode()));
    ModelNode authAddOp = Operations.createAddOperation(PathAddress.parseCLIStyleAddress("/host=master/core-service=management/security-realm=TestRealm/authentication=properties").toModelNode());
    authAddOp.get("path").set("test-users.properties");
    authAddOp.get("relative-to").set("jboss.domain.config.dir");
    operation.get(STEPS).add(authAddOp);
    operation.get(STEPS).add(Operations.createAddOperation(PathAddress.parseCLIStyleAddress("/host=slave/core-service=management/security-realm=TestRealm").toModelNode()));
    authAddOp = Operations.createAddOperation(PathAddress.parseCLIStyleAddress("/host=slave/core-service=management/security-realm=TestRealm/authentication=properties").toModelNode());
    authAddOp.get("path").set("test-users.properties");
    authAddOp.get("relative-to").set("jboss.domain.config.dir");
    operation.get(STEPS).add(authAddOp);
    return operation;
}
 
Example 10
Source File: BasicOperationsUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testRemoveAddSystemPropertyInBatch() throws Exception {
    final String propertyName = "my.property";
    ModelNode addPropertyOp = Operations.createAddOperation(PathAddress.EMPTY_ADDRESS.append(SYSTEM_PROPERTY, propertyName).toModelNode());
    addPropertyOp.get(VALUE).set("test");
    ModelNode removePropertyOp = Operations.createRemoveOperation(PathAddress.EMPTY_ADDRESS.append(SYSTEM_PROPERTY, propertyName).toModelNode());
    try {
        int origPropCount = countSystemProperties();

        Map<String, String> properties = Collections.singletonMap(propertyName, "test");
        validateSystemProperty(properties, propertyName, false, origPropCount);

        ModelNode response = managementClient.getControllerClient().execute(addPropertyOp);
        validateResponse(response, false);
        validateSystemProperty(properties, propertyName, true, origPropCount);

        ModelNode composite = new ModelNode();
        composite.get(OP).set(CompositeOperationHandler.NAME);
        composite.get(OP_ADDR).setEmptyList();
        composite.get(OPERATION_HEADERS, ROLLBACK_ON_RUNTIME_FAILURE).set(false);

        composite.get(STEPS).add(removePropertyOp);
        composite.get(STEPS).add(addPropertyOp);

        ModelNode result = managementClient.getControllerClient().execute(composite);
        validateResponse(result);
        validateSystemProperty(properties, propertyName, true, origPropCount);
    } finally {
        managementClient.getControllerClient().execute(removePropertyOp);
    }
}
 
Example 11
Source File: RotatingFileHandlerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void setup(final ManagementClient managementClient) throws Exception {
    final Operations.CompositeOperationBuilder builder = Operations.CompositeOperationBuilder.create();

    final ModelNode formatterAddress = createAddress("json-formatter", FORMATTER_NAME);
    builder.addStep(Operations.createAddOperation(formatterAddress));
    removeOps.addLast(Operations.createRemoveOperation(formatterAddress));

    ModelNode address = createAddress("size-rotating-file-handler", SIZE_FILE_NAME);
    ModelNode op = Operations.createAddOperation(address);
    ModelNode file = op.get("file").setEmptyObject();
    file.get("relative-to").set("jboss.server.log.dir");
    file.get("path").set(SIZE_FILE_NAME);
    op.get("max-backup-index").set(1);
    op.get("rotate-size").set("5k");
    op.get("named-formatter").set(FORMATTER_NAME);
    builder.addStep(op);
    removeOps.addFirst(Operations.createRemoveOperation(address));

    address = createAddress("size-rotating-file-handler", SIZE_COMPRESSED_FILE_NAME);
    op = Operations.createAddOperation(address);
    file = op.get("file").setEmptyObject();
    file.get("relative-to").set("jboss.server.log.dir");
    file.get("path").set(SIZE_COMPRESSED_FILE_NAME);
    op.get("max-backup-index").set(1);
    op.get("rotate-size").set("5k");
    op.get("named-formatter").set(FORMATTER_NAME);
    op.get("suffix").set(".zip");
    builder.addStep(op);
    removeOps.addFirst(Operations.createRemoveOperation(address));

    address = createAddress("periodic-size-rotating-file-handler", PERIODIC_SIZE_FILE_NAME);
    op = Operations.createAddOperation(address);
    file = op.get("file").setEmptyObject();
    file.get("relative-to").set("jboss.server.log.dir");
    file.get("path").set(PERIODIC_SIZE_FILE_NAME);
    op.get("max-backup-index").set(1);
    op.get("rotate-size").set("5k");
    op.get("named-formatter").set(FORMATTER_NAME);
    op.get("suffix").set("mm");
    builder.addStep(op);
    removeOps.addFirst(Operations.createRemoveOperation(address));

    address = createAddress("periodic-size-rotating-file-handler", PERIODIC_SIZE_COMPRESSED_FILE_NAME);
    op = Operations.createAddOperation(address);
    file = op.get("file").setEmptyObject();
    file.get("relative-to").set("jboss.server.log.dir");
    file.get("path").set(PERIODIC_SIZE_COMPRESSED_FILE_NAME);
    op.get("max-backup-index").set(1);
    op.get("rotate-size").set("5k");
    op.get("named-formatter").set(FORMATTER_NAME);
    op.get("suffix").set("mm.zip");
    builder.addStep(op);
    removeOps.addFirst(Operations.createRemoveOperation(address));

    address = createAddress("logger", SIZE_LOGGER_NAME);
    op = Operations.createAddOperation(address);
    op.get("handlers").setEmptyList().add(SIZE_FILE_NAME);
    op.get("use-parent-handlers").set(false);
    builder.addStep(op);
    removeOps.addFirst(Operations.createRemoveOperation(address));

    address = createAddress("logger", SIZE_COMPRESSED_LOGGER_NAME);
    op = Operations.createAddOperation(address);
    op.get("handlers").setEmptyList().add(SIZE_COMPRESSED_FILE_NAME);
    op.get("use-parent-handlers").set(false);
    builder.addStep(op);
    removeOps.addFirst(Operations.createRemoveOperation(address));

    address = createAddress("logger", PERIODIC_SIZE_LOGGER_NAME);
    op = Operations.createAddOperation(address);
    op.get("handlers").setEmptyList().add(PERIODIC_SIZE_FILE_NAME);
    op.get("use-parent-handlers").set(false);
    builder.addStep(op);
    removeOps.addFirst(Operations.createRemoveOperation(address));

    address = createAddress("logger", PERIODIC_SIZE_COMPRESSED_LOGGER_NAME);
    op = Operations.createAddOperation(address);
    op.get("handlers").setEmptyList().add(PERIODIC_SIZE_COMPRESSED_FILE_NAME);
    op.get("use-parent-handlers").set(false);
    builder.addStep(op);
    removeOps.addFirst(Operations.createRemoveOperation(address));

    executeOperation(managementClient, builder.build());
}
 
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: CachedDcDomainTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ModelNode getCreateOperationTestLoggingCategory() {
    final ModelNode addrLogger = getProfileDefaultLoggingAddr();
    addrLogger.add(LOGGER, TEST_LOGGER_NAME);

    final ModelNode createOp = Operations.createAddOperation(addrLogger);
    createOp.get("level").set("TRACE");
    createOp.get("category").set(TEST_LOGGER_NAME);
    return createOp;
}
 
Example 14
Source File: LegacySecurityRealmPropagationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void test() throws Throwable {
    DomainClient client = domainMasterLifecycleUtil.getDomainClient();
    DomainTestSupport.validateResponse(client.execute(addSecurityRealm()), false);
    ModelNode addRemotingOp = Operations.createAddOperation(PathAddress.parseCLIStyleAddress("/profile=other/subsystem=remoting/connector=test").toModelNode());
    addRemotingOp.get("security-realm").set("TestRealm");
    addRemotingOp.get("socket-binding").set("remoting");
    DomainTestSupport.validateResponse(client.execute(addRemotingOp), false);
    addRemotingOp = Operations.createAddOperation(PathAddress.parseCLIStyleAddress("/profile=default/subsystem=remoting/connector=test").toModelNode());
    addRemotingOp.get("security-realm").set("TestRealm");
    addRemotingOp.get("socket-binding").set("remoting");
    DomainTestSupport.validateResponse(client.execute(addRemotingOp), false);
}
 
Example 15
Source File: HandlerCapabilityTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testAddInvalidFormatter() throws Exception {
    final ModelNode address = createSubsystemAddress("console-handler", "failed");
    final ModelNode op = Operations.createAddOperation(address);
    op.get("named-formatter").set("non-existing");
    executeOperationForFailure(op, NOT_FOUND);
}
 
Example 16
Source File: ServerConfigurator.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void configureStandalone() throws InterruptedException, IOException {
    final Path stdout = Paths.get(TestSuiteEnvironment.getTmpDir(), "config-standalone-stdout.txt");
    final StandaloneCommandBuilder builder = StandaloneCommandBuilder.of(ServerHelper.JBOSS_HOME)
            .addJavaOptions(ServerHelper.DEFAULT_SERVER_JAVA_OPTS);

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

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

        try (ModelControllerClient client = TestSuiteEnvironment.getModelControllerClient()) {
            final CompositeOperationBuilder opBuilder = CompositeOperationBuilder.create();
            ModelNode address = Operations.createAddress("subsystem", "logging", "custom-formatter", "json");
            ModelNode 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("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("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());
            ServerHelper.shutdownStandalone(client);
        }

        if (!process.waitFor(ServerHelper.TIMEOUT, TimeUnit.SECONDS)) {
            Assert.fail(readStdout(stdout));
        }

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

    } finally {
        ProcessHelper.destroyProcess(process);
    }
}
 
Example 17
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 18
Source File: FilterTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void configure(final String loggerFilter, final String handlerFilter) throws IOException {

        final CompositeOperationBuilder builder = CompositeOperationBuilder.create();

        // Create a JSON formatter
        ModelNode op = Operations.createAddOperation(FORMATTER_ADDRESS);
        // This should always be false so that the each line will be a separate entry since we're writing to a file
        op.get("pretty-print").set(false);
        builder.addStep(op);

        // Create the filter
        op = Operations.createAddOperation(FILTER_ADDRESS);
        op.get("module").set("org.jboss.as.logging.test");
        op.get("class").set(TestFilter.class.getName());
        ModelNode constructorProperties = op.get("constructor-properties").setEmptyObject();
        constructorProperties.get("constructorText").set(" | constructor text");
        ModelNode properties = op.get("properties").setEmptyObject();
        properties.get("propertyText").set(" | property text");
        builder.addStep(op);

        // Create the handler
        op = Operations.createAddOperation(HANDLER_ADDRESS);
        final ModelNode fileNode = op.get("file").setEmptyObject();
        fileNode.get("relative-to").set("jboss.server.log.dir");
        fileNode.get("path").set(logFile.getFileName().toString());
        op.get("autoFlush").set(true);
        op.get("append").set(false);
        op.get("named-formatter").set(JSON_FORMATTER_NAME);
        if (handlerFilter != null) {
            op.get("filter-spec").set(handlerFilter);
        }
        builder.addStep(op);

        // Add the handler to the root-logger
        op = Operations.createAddOperation(LOGGER_ADDRESS);
        op.get("handlers").setEmptyList().add(JSON_HANDLER_NAME);
        if (loggerFilter != null) {
            op.get("filter-spec").set(loggerFilter);
        }
        builder.addStep(op);

        executeOperation(builder.build());
    }
 
Example 19
Source File: HttpDeploymentUploadUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private HttpEntity createAddEntity(final byte[] hash) throws IOException {
    final ModelNode op = Operations.createAddOperation(deploymentAddress);
    op.get("content").get(0).get("hash").set(hash);
    op.get("enabled").set(true);
    return new StringEntity(op.toJSONString(true));
}
 
Example 20
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);
    }
}