Skip to content

Commit

Permalink
[WFCORE-1261]: Changing the max-history attribute value for configura…
Browse files Browse the repository at this point in the history
…tion-changes fails.

Moving the update of the model to the MODEL phase instead of the RUNTIME one.
  • Loading branch information
ehsavoie committed Jan 4, 2016
1 parent 51183be commit 3cc16b1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
public class ConfigurationChangeResourceDefinition extends SimpleResourceDefinition {

public static final SimpleAttributeDefinition MAX_HISTORY = SimpleAttributeDefinitionBuilder.create(
ModelDescriptionConstants.MAX_HISTORY, ModelType.INT)
ModelDescriptionConstants.MAX_HISTORY, ModelType.INT, true)
.setDefaultValue(new ModelNode(10))
.build();
public static final PathElement PATH = PathElement.pathElement(SERVICE, CONFIGURATION_CHANGES);
Expand Down Expand Up @@ -125,19 +125,18 @@ private static class MaxHistoryWriteHandler extends AbstractWriteAttributeHandle
private final ConfigurationChangesCollector collector;

private MaxHistoryWriteHandler(ConfigurationChangesCollector collector) {
super(MAX_HISTORY);
this.collector = collector;
}

@Override
protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<Integer> handbackHolder) throws OperationFailedException {
MAX_HISTORY.validateAndSet(operation, context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel());
collector.setMaxHistory(resolvedValue.asInt());
return true;
}

@Override
protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Integer handback) throws OperationFailedException {
MAX_HISTORY.validateAndSet(operation, context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel());
collector.setMaxHistory(valueToRestore.asInt());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
@RunWith(WildflyTestRunner.class)
public class ConfigurationChangesHistoryTestCase extends ContainerResourceMgmtTestBase {

private static final int ALL_MAX_HISTORY_SIZE = 5;
private static final int MAX_HISTORY_SIZE = 4;

private static final PathAddress ALLOWED_ORIGINS_ADDRESS = PathAddress.pathAddress()
Expand Down Expand Up @@ -156,4 +157,48 @@ public void testConfigurationChanges() throws Exception {
assertThat(currentChangeOp.get(OP_ADDR).asString(), is(SYSTEM_PROPERTY_ADDRESS.toModelNode().asString()));
assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS));
}

@Test
public void testAllConfigurationChanges() throws Exception {
final ModelNode update = Util.getWriteAttributeOperation(ADDRESS, ConfigurationChangeResourceDefinition.MAX_HISTORY.getName(), ALL_MAX_HISTORY_SIZE);
getModelControllerClient().execute(update);
final ModelNode listConfigurationChanges = Util.createOperation(ConfigurationChangeResourceDefinition.OPERATION_NAME, ADDRESS);
List<ModelNode> changes = getManagementClient().executeForResult(listConfigurationChanges).asList();
assertThat(changes.size(), is(ALL_MAX_HISTORY_SIZE));
for(ModelNode change : changes) {
assertThat(change.hasDefined(OPERATION_DATE), is(true));
assertThat(change.hasDefined(USER_ID), is(false));
assertThat(change.hasDefined(DOMAIN_UUID), is(false));
assertThat(change.hasDefined(ACCESS_MECHANISM), is(true));
assertThat(change.get(ACCESS_MECHANISM).asString(), is("NATIVE"));
assertThat(change.hasDefined(REMOTE_ADDRESS), is(true));
assertThat(change.get(OPERATIONS).asList().size(), is(1));
}

ModelNode currentChange = changes.get(0);
ModelNode currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
assertThat(currentChangeOp.get(OP).asString(), is(WRITE_ATTRIBUTE_OPERATION));
assertThat(currentChangeOp.get(OP_ADDR).asString(), is(ADDRESS.toModelNode().asString()));
assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS));
currentChange = changes.get(1);
currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
assertThat(currentChangeOp.get(OP).asString(), is(WRITE_ATTRIBUTE_OPERATION));
assertThat(currentChangeOp.get(OP_ADDR).asString(), is(ALLOWED_ORIGINS_ADDRESS.toModelNode().asString()));
assertThat(currentChange.get(OUTCOME).asString(), is(FAILED));
currentChange = changes.get(2);
currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
assertThat(currentChangeOp.get(OP).asString(), is(REMOVE));
assertThat(currentChangeOp.get(OP_ADDR).asString(), is(SYSTEM_PROPERTY_ADDRESS.toString()));
assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS));
currentChange = changes.get(3);
currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
assertThat(currentChangeOp.get(OP).asString(), is(UNDEFINE_ATTRIBUTE_OPERATION));
assertThat(currentChangeOp.get(OP_ADDR).asString(), is(ALLOWED_ORIGINS_ADDRESS.toModelNode().asString()));
assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS));
currentChange = changes.get(4);
currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
assertThat(currentChangeOp.get(OP).asString(), is(ADD));
assertThat(currentChangeOp.get(OP_ADDR).asString(), is(SYSTEM_PROPERTY_ADDRESS.toModelNode().asString()));
assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS));
}
}

0 comments on commit 3cc16b1

Please sign in to comment.