Search in sources :

Example 1 with ConfigurationPersistence

use of org.jboss.as.logging.logmanager.ConfigurationPersistence in project wildfly-core by wildfly.

the class LoggingSubsystemRollbackTestCase method rollbackWriteAttribute.

public void rollbackWriteAttribute(final String profileName) throws Exception {
    // Save the current model
    final ModelNode validSubsystemModel = getSubsystemModel(kernelServices);
    // Add a handler to be removed
    final PathAddress consoleHandler = createConsoleHandlerAddress(profileName, "CONSOLE");
    // Create a new handler
    ModelNode op = SubsystemOperations.createWriteAttributeOperation(consoleHandler.toModelNode(), ConsoleHandlerResourceDefinition.TARGET, "System.err");
    ModelNode result = kernelServices.executeOperation(op);
    Assert.assertFalse("The write operation should have failed, but was successful: " + result, SubsystemOperations.isSuccessfulOutcome(result));
    // verify the subsystem model matches the old model
    ModelNode currentModel = getSubsystemModel(kernelServices);
    compare(profileName, validSubsystemModel, currentModel);
    final LogContext logContext = (profileName == null ? LogContext.getLogContext() : LoggingProfileContextSelector.getInstance().get(profileName));
    ConfigurationPersistence config = ConfigurationPersistence.getConfigurationPersistence(logContext);
    compare(profileName, currentModel, config);
    // Fail on a logger write attribute
    final PathAddress rootLoggerAddress = createRootLoggerAddress(profileName);
    op = SubsystemOperations.createWriteAttributeOperation(rootLoggerAddress.toModelNode(), CommonAttributes.LEVEL, "TRACE");
    result = kernelServices.executeOperation(op);
    Assert.assertFalse("The write operation should have failed, but was successful: " + result, SubsystemOperations.isSuccessfulOutcome(result));
    // verify the subsystem model matches the old model
    currentModel = getSubsystemModel(kernelServices);
    compare(profileName, validSubsystemModel, currentModel);
    config = ConfigurationPersistence.getConfigurationPersistence(logContext);
    compare(profileName, currentModel, config);
}
Also used : ConfigurationPersistence(org.jboss.as.logging.logmanager.ConfigurationPersistence) PathAddress(org.jboss.as.controller.PathAddress) LogContext(org.jboss.logmanager.LogContext) ModelNode(org.jboss.dmr.ModelNode)

Example 2 with ConfigurationPersistence

use of org.jboss.as.logging.logmanager.ConfigurationPersistence in project wildfly-core by wildfly.

the class LoggingSubsystemRollbackTestCase method rollbackAdd.

public void rollbackAdd(final String profileName) throws Exception {
    // Save the current model
    final ModelNode validSubsystemModel = getSubsystemModel(kernelServices);
    // Add a handler to be removed
    final PathAddress consoleHandler = createConsoleHandlerAddress(profileName, "CONSOLE2");
    // Create a new handler
    ModelNode op = SubsystemOperations.createAddOperation(consoleHandler.toModelNode());
    op.get(CommonAttributes.LEVEL.getName()).set("INFO");
    op.get(AbstractHandlerDefinition.FORMATTER.getName()).set("%d{HH:mm:ss,SSS} %-5p [%c] (%t) CONSOLE2: %s%e%n");
    ModelNode result = kernelServices.executeOperation(op);
    Assert.assertFalse("The add operation should have failed, but was successful: " + result, SubsystemOperations.isSuccessfulOutcome(result));
    // verify the subsystem model matches the old model
    ModelNode currentModel = getSubsystemModel(kernelServices);
    compare(profileName, validSubsystemModel, currentModel);
    final LogContext logContext = (profileName == null ? LogContext.getLogContext() : LoggingProfileContextSelector.getInstance().get(profileName));
    ConfigurationPersistence config = ConfigurationPersistence.getConfigurationPersistence(logContext);
    compare(profileName, currentModel, config);
    // Fail on a logger write attribute
    final PathAddress loggerAddress = createLoggerAddress(profileName, "org.jboss.as.logging.test");
    op = SubsystemOperations.createAddOperation(loggerAddress.toModelNode());
    result = kernelServices.executeOperation(op);
    Assert.assertFalse("The add operation should have failed, but was successful: " + result, SubsystemOperations.isSuccessfulOutcome(result));
    // verify the subsystem model matches the old model
    currentModel = getSubsystemModel(kernelServices);
    compare(profileName, validSubsystemModel, currentModel);
    config = ConfigurationPersistence.getConfigurationPersistence(logContext);
    compare(profileName, currentModel, config);
}
Also used : ConfigurationPersistence(org.jboss.as.logging.logmanager.ConfigurationPersistence) PathAddress(org.jboss.as.controller.PathAddress) LogContext(org.jboss.logmanager.LogContext) ModelNode(org.jboss.dmr.ModelNode)

Example 3 with ConfigurationPersistence

use of org.jboss.as.logging.logmanager.ConfigurationPersistence in project wildfly-core by wildfly.

the class LoggingSubsystemRollbackTestCase method testRollbackRemoveProfile.

@Test
@BMRules(rules = { @BMRule(name = "Test handler write-attribute rollback handler", targetClass = "org.jboss.as.logging.loggers.LoggerOperations$LoggerWriteAttributeHandler", targetMethod = "applyUpdate", targetLocation = "AT EXIT", condition = "$1.getCurrentAddressValue().equals(\"ROOT\")", action = "$1.setRollbackOnly()") })
public void testRollbackRemoveProfile() throws Exception {
    // Save the current model
    final ModelNode validSubsystemModel = getSubsystemModel(kernelServices);
    final CompositeOperationBuilder compositeOperationBuilder = CompositeOperationBuilder.create();
    // The handler address to remove
    final PathAddress profileAddress = createAddress(CommonAttributes.LOGGING_PROFILE, PROFILE_NAME);
    // Remove the handler
    compositeOperationBuilder.addStep(SubsystemOperations.createRemoveOperation(profileAddress.toModelNode(), true));
    // Add a step to fail
    final ModelNode rootLoggerAddress = createRootLoggerAddress().toModelNode();
    compositeOperationBuilder.addStep(SubsystemOperations.createWriteAttributeOperation(rootLoggerAddress, CommonAttributes.LEVEL, "INFO"));
    ModelNode result = kernelServices.executeOperation(compositeOperationBuilder.build().getOperation());
    Assert.assertFalse("The update operation should have failed, but was successful: " + result, SubsystemOperations.isSuccessfulOutcome(result));
    // verify the subsystem model matches the old model
    final ModelNode currentModel = getSubsystemModel(kernelServices);
    compare(validSubsystemModel, currentModel);
    ConfigurationPersistence config = ConfigurationPersistence.getConfigurationPersistence(LogContext.getLogContext());
    compare(currentModel, config);
    // Check the profile was rolled back
    config = ConfigurationPersistence.getConfigurationPersistence(LoggingProfileContextSelector.getInstance().get(PROFILE_NAME));
    compare(PROFILE_NAME, currentModel, config);
}
Also used : CompositeOperationBuilder(org.jboss.as.controller.client.helpers.Operations.CompositeOperationBuilder) ConfigurationPersistence(org.jboss.as.logging.logmanager.ConfigurationPersistence) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 4 with ConfigurationPersistence

use of org.jboss.as.logging.logmanager.ConfigurationPersistence in project wildfly-core by wildfly.

the class LoggingSubsystemRollbackTestCase method testRollbackComposite.

@Test
@BMRule(name = "Test handler rollback handler", targetClass = "org.jboss.as.logging.loggers.LoggerOperations$LoggerWriteAttributeHandler", targetMethod = "applyUpdate", targetLocation = "AT EXIT", condition = "$1.getCurrentAddressValue().equals(\"org.jboss.as.logging\")", action = "$1.setRollbackOnly()")
public void testRollbackComposite() throws Exception {
    // Add a handler to be removed
    final PathAddress consoleHandler = createConsoleHandlerAddress("CONSOLE2");
    // Create a new handler
    ModelNode op = SubsystemOperations.createAddOperation(consoleHandler.toModelNode());
    op.get(CommonAttributes.LEVEL.getName()).set("INFO");
    op.get(AbstractHandlerDefinition.FORMATTER.getName()).set("%d{HH:mm:ss,SSS} %-5p [%c] (%t) CONSOLE2: %s%e%n");
    ModelNode result = kernelServices.executeOperation(op);
    Assert.assertTrue(SubsystemOperations.getFailureDescriptionAsString(result), SubsystemOperations.isSuccessfulOutcome(result));
    // Add the handler to a logger
    final PathAddress loggerAddress = createLoggerAddress("org.jboss.as.logging");
    op = SubsystemOperations.createOperation(CommonAttributes.ADD_HANDLER_OPERATION_NAME, loggerAddress.toModelNode());
    op.get(CommonAttributes.HANDLER_NAME.getName()).set(consoleHandler.getLastElement().getValue());
    result = kernelServices.executeOperation(op);
    Assert.assertTrue(SubsystemOperations.getFailureDescriptionAsString(result), SubsystemOperations.isSuccessfulOutcome(result));
    // Save the current model
    final ModelNode validSubsystemModel = getSubsystemModel(kernelServices);
    final CompositeOperationBuilder operationBuilder = CompositeOperationBuilder.create();
    // create a new handler
    final PathAddress fileHandlerAddress = createFileHandlerAddress("fail-fh");
    final ModelNode fileHandlerOp = SubsystemOperations.createAddOperation(fileHandlerAddress.toModelNode());
    fileHandlerOp.get(CommonAttributes.FILE.getName(), PathResourceDefinition.RELATIVE_TO.getName()).set("jboss.server.log.dir");
    fileHandlerOp.get(CommonAttributes.FILE.getName(), PathResourceDefinition.PATH.getName()).set("fail-fh.log");
    fileHandlerOp.get(CommonAttributes.AUTOFLUSH.getName()).set(true);
    operationBuilder.addStep(fileHandlerOp);
    // create a new logger
    final PathAddress testLoggerAddress = createLoggerAddress("test");
    final ModelNode testLoggerOp = SubsystemOperations.createAddOperation(testLoggerAddress.toModelNode());
    operationBuilder.addStep(testLoggerOp);
    // add handler to logger
    operationBuilder.addStep(SubsystemOperations.createWriteAttributeOperation(testLoggerAddress.toModelNode(), LoggerAttributes.HANDLERS, new ModelNode().setEmptyList().add("fail-fh")));
    // remove the console handler
    operationBuilder.addStep(SubsystemOperations.createRemoveOperation(consoleHandler.toModelNode()));
    // add handler to existing logger - should force fail on this one
    operationBuilder.addStep(SubsystemOperations.createWriteAttributeOperation(loggerAddress.toModelNode(), LoggerAttributes.HANDLERS, new ModelNode().setEmptyList().add("fail-fh")));
    // verify the operation failed
    result = kernelServices.executeOperation(operationBuilder.build().getOperation());
    Assert.assertFalse("The add operation should have failed, but was successful: " + result, SubsystemOperations.isSuccessfulOutcome(result));
    // verify the subsystem model matches the old model
    final ModelNode currentModel = getSubsystemModel(kernelServices);
    compare(validSubsystemModel, currentModel);
    final ConfigurationPersistence config = ConfigurationPersistence.getConfigurationPersistence(LogContext.getLogContext());
    compare(currentModel, config);
}
Also used : CompositeOperationBuilder(org.jboss.as.controller.client.helpers.Operations.CompositeOperationBuilder) ConfigurationPersistence(org.jboss.as.logging.logmanager.ConfigurationPersistence) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) BMRule(org.jboss.byteman.contrib.bmunit.BMRule) Test(org.junit.Test)

Example 5 with ConfigurationPersistence

use of org.jboss.as.logging.logmanager.ConfigurationPersistence in project wildfly-core by wildfly.

the class LoggingSubsystemRollbackTestCase method testRollbackCompositeLoggingProfile.

@Test
@BMRule(name = "Test handler rollback handler", targetClass = "org.jboss.as.logging.loggers.LoggerOperations$LoggerWriteAttributeHandler", targetMethod = "applyUpdate", targetLocation = "AT EXIT", condition = "$1.getCurrentAddressValue().equals(\"org.jboss.as.logging\")", action = "$1.setRollbackOnly()")
public void testRollbackCompositeLoggingProfile() throws Exception {
    // Add a handler to be removed
    final PathAddress consoleHandler = createConsoleHandlerAddress("CONSOLE2");
    // Create a new handler
    ModelNode op = SubsystemOperations.createAddOperation(consoleHandler.toModelNode());
    op.get(CommonAttributes.LEVEL.getName()).set("INFO");
    op.get(AbstractHandlerDefinition.FORMATTER.getName()).set("%d{HH:mm:ss,SSS} %-5p [%c] (%t) CONSOLE2: %s%e%n");
    ModelNode result = kernelServices.executeOperation(op);
    Assert.assertTrue(SubsystemOperations.getFailureDescriptionAsString(result), SubsystemOperations.isSuccessfulOutcome(result));
    // Add the handler to a logger
    final PathAddress loggerAddress = createLoggerAddress("org.jboss.as.logging");
    op = SubsystemOperations.createOperation(CommonAttributes.ADD_HANDLER_OPERATION_NAME, loggerAddress.toModelNode());
    op.get(CommonAttributes.HANDLER_NAME.getName()).set(consoleHandler.getLastElement().getValue());
    result = kernelServices.executeOperation(op);
    Assert.assertTrue(SubsystemOperations.getFailureDescriptionAsString(result), SubsystemOperations.isSuccessfulOutcome(result));
    // Save the current model
    final ModelNode validSubsystemModel = getSubsystemModel(kernelServices);
    final CompositeOperationBuilder operationBuilder = CompositeOperationBuilder.create();
    // create a new handler
    final PathAddress fileHandlerAddress = createFileHandlerAddress("fail-fh");
    final ModelNode fileHandlerOp = SubsystemOperations.createAddOperation(fileHandlerAddress.toModelNode());
    fileHandlerOp.get(CommonAttributes.FILE.getName(), PathResourceDefinition.RELATIVE_TO.getName()).set("jboss.server.log.dir");
    fileHandlerOp.get(CommonAttributes.FILE.getName(), PathResourceDefinition.PATH.getName()).set("fail-fh.log");
    fileHandlerOp.get(CommonAttributes.AUTOFLUSH.getName()).set(true);
    operationBuilder.addStep(fileHandlerOp);
    // create a new logger
    final PathAddress testLoggerAddress = createLoggerAddress(PROFILE_NAME, "test");
    final ModelNode testLoggerOp = SubsystemOperations.createAddOperation(testLoggerAddress.toModelNode());
    operationBuilder.addStep(testLoggerOp);
    // remove the console handler
    operationBuilder.addStep(SubsystemOperations.createRemoveOperation(consoleHandler.toModelNode()));
    // add handler to existing logger - should force fail on this one
    operationBuilder.addStep(SubsystemOperations.createWriteAttributeOperation(loggerAddress.toModelNode(), LoggerAttributes.HANDLERS, new ModelNode().setEmptyList().add("fail-fh")));
    // verify the operation failed
    result = kernelServices.executeOperation(operationBuilder.build().getOperation());
    Assert.assertFalse("The add operation should have failed, but was successful: " + result, SubsystemOperations.isSuccessfulOutcome(result));
    // verify the subsystem model matches the old model
    final ModelNode currentModel = getSubsystemModel(kernelServices);
    compare(validSubsystemModel, currentModel);
    final ConfigurationPersistence config = ConfigurationPersistence.getConfigurationPersistence(LogContext.getLogContext());
    compare(currentModel, config);
}
Also used : CompositeOperationBuilder(org.jboss.as.controller.client.helpers.Operations.CompositeOperationBuilder) ConfigurationPersistence(org.jboss.as.logging.logmanager.ConfigurationPersistence) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) BMRule(org.jboss.byteman.contrib.bmunit.BMRule) Test(org.junit.Test)

Aggregations

ConfigurationPersistence (org.jboss.as.logging.logmanager.ConfigurationPersistence)12 PathAddress (org.jboss.as.controller.PathAddress)10 ModelNode (org.jboss.dmr.ModelNode)10 LogContext (org.jboss.logmanager.LogContext)6 Test (org.junit.Test)6 CompositeOperationBuilder (org.jboss.as.controller.client.helpers.Operations.CompositeOperationBuilder)4 BMRule (org.jboss.byteman.contrib.bmunit.BMRule)4 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 Resource (org.jboss.as.controller.registry.Resource)1 LoggingConfigDeploymentProcessor (org.jboss.as.logging.deployments.LoggingConfigDeploymentProcessor)1 LoggingDependencyDeploymentProcessor (org.jboss.as.logging.deployments.LoggingDependencyDeploymentProcessor)1 LoggingDeploymentResourceProcessor (org.jboss.as.logging.deployments.LoggingDeploymentResourceProcessor)1 LoggingProfileDeploymentProcessor (org.jboss.as.logging.deployments.LoggingProfileDeploymentProcessor)1 AbstractDeploymentChainStep (org.jboss.as.server.AbstractDeploymentChainStep)1 DeploymentProcessorTarget (org.jboss.as.server.DeploymentProcessorTarget)1 KernelServices (org.jboss.as.subsystem.test.KernelServices)1 BMRules (org.jboss.byteman.contrib.bmunit.BMRules)1 LogContextConfiguration (org.jboss.logmanager.config.LogContextConfiguration)1