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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations