Skip to content

Commit

Permalink
[WFCORE-6718]: Overriding socket binding attributes using yaml fails.
Browse files Browse the repository at this point in the history
 * Tracking all added resources so that we update the resource instead
   of trying to create it a 2nd time.

Jira: https://issues.redhat.com/browse/WFCORE-6718

Signed-off-by: Emmanuel Hugonnet <[email protected]>
  • Loading branch information
ehsavoie committed Feb 28, 2024
1 parent 2a9e0b5 commit 9d1bd11
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private void processResource(PathAddress parentAddress, Map<String, Object> yaml
if (value == null && !isExistingResource(xmlOperations, address)) { //empty resource
OperationEntry operationEntry = rootRegistration.getOperationEntry(address, ADD);
if(operationEntry != null) {
processAttributes(address, rootRegistration, operationEntry, Collections.emptyMap(), postExtensionOps);
processAttributes(address, rootRegistration, operationEntry, Collections.emptyMap(), postExtensionOps, xmlOperations);
} else {
throw MGMT_OP_LOGGER.missingOperationForResource("ADD", address.toCLIStyleString());
}
Expand Down Expand Up @@ -236,7 +236,7 @@ private void processResource(PathAddress parentAddress, Map<String, Object> yaml
if (! address.equals(op.getAddress())) { // else already processed
Map<String, Object> map = value instanceof Map ? new HashMap<>((Map)value) : new HashMap<>(yaml);
//need to process attributes for adding
processAttributes(address, rootRegistration, operationEntry, map, postExtensionOps);
processAttributes(address, rootRegistration, operationEntry, map, postExtensionOps, xmlOperations);
processResource(address, map, rootRegistration, resourceRegistration, xmlOperations, postExtensionOps, false);
}
}
Expand All @@ -262,13 +262,13 @@ private void processResource(PathAddress parentAddress, Map<String, Object> yaml
if (value instanceof Map) {
Map<String, Object> map = (Map<String, Object>) value;
//need to process attributes for adding
processAttributes(address, rootRegistration, operationEntry, map, postExtensionOps);
processAttributes(address, rootRegistration, operationEntry, map, postExtensionOps, xmlOperations);
processResource(address, map, rootRegistration, childResourceRegistration, xmlOperations, postExtensionOps, false);
} else {
if (value != null) {
MGMT_OP_LOGGER.unexpectedValueForResource(value, address.toCLIStyleString(), name);
} else {// ADD operation without parameters
processAttributes(address, rootRegistration, operationEntry, null, postExtensionOps);
processAttributes(address, rootRegistration, operationEntry, null, postExtensionOps, xmlOperations);
}
}
} else {
Expand Down Expand Up @@ -344,7 +344,7 @@ private void processAttribute(PathAddress address, ImmutableManagementResourceRe
}

@SuppressWarnings("unchecked")
private void processAttributes(PathAddress address, ImmutableManagementResourceRegistration rootRegistration, OperationEntry operationEntry, Map<String, Object> map, List<ParsedBootOp> postExtensionOps) {
private void processAttributes(PathAddress address, ImmutableManagementResourceRegistration rootRegistration, OperationEntry operationEntry, Map<String, Object> map, List<ParsedBootOp> postExtensionOps, Map<PathAddress, ParsedBootOp> xmlOperations) {
Set<AttributeDefinition> attributes = new HashSet<>();
for (AttributeAccess attributeAccess : rootRegistration.getAttributes(address).values()) {
if (attributeAccess.getStorageType() == AttributeAccess.Storage.CONFIGURATION) {
Expand Down Expand Up @@ -385,6 +385,9 @@ private void processAttributes(PathAddress address, ImmutableManagementResourceR
ParsedBootOp operation = new ParsedBootOp(op, operationEntry.getOperationHandler());
MGMT_OP_LOGGER.debugf("Adding resource with operation %s", op);
postExtensionOps.add(operation);
if(ADD.equals(operationEntry.getOperationDefinition().getName())) {
xmlOperations.put(address, operation);
}
}

private ModelNode createOperation(PathAddress address, OperationEntry operationEntry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,33 @@ public void testAddResourceOverwrite() throws URISyntaxException {
assertEquals("test", postExtensionOps.get(1).operation.get("value").asString());
}

/**
* Verify that resource creation will be updated with the YAML definition.
*
* @throws URISyntaxException
*/
@Test
public void testAddResourceOverride() throws URISyntaxException {
List<ParsedBootOp> postExtensionOps = new ArrayList<>();
ConfigurationExtension instance = new YamlConfigurationExtension();
instance.load(Paths.get(this.getClass().getResource("simple_overwrite.yml").toURI()), Paths.get(this.getClass().getResource("simple_override.yml").toURI()));
instance.processOperations(rootRegistration, postExtensionOps);
assertFalse(postExtensionOps.isEmpty());
assertEquals(3, postExtensionOps.size());
assertEquals(ADD, postExtensionOps.get(0).operationName);
assertEquals(PathAddress.pathAddress("system-property", "aaa"), postExtensionOps.get(0).address);
assertTrue(postExtensionOps.get(0).operation.hasDefined("value"));
assertEquals("foo", postExtensionOps.get(0).operation.get("value").asString());
assertEquals(ADD, postExtensionOps.get(1).operationName);
assertEquals(PathAddress.pathAddress("system-property", "bbb"), postExtensionOps.get(1).address);
assertTrue(postExtensionOps.get(1).operation.hasDefined("value"));
assertEquals("test", postExtensionOps.get(1).operation.get("value").asString());
assertEquals(WRITE_ATTRIBUTE_OPERATION, postExtensionOps.get(2).operationName);
assertEquals(PathAddress.pathAddress("system-property", "bbb"), postExtensionOps.get(2).address);
assertTrue(postExtensionOps.get(2).operation.hasDefined("value"));
assertEquals("test-override", postExtensionOps.get(2).operation.get("value").asString());
}

/**
* Verify removing a resource and adding it again.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
wildfly-configuration:
extension:
org.jboss.as.failure:
module: org.jboss.as.failure
system-property:
bbb:
value: test-override
#User defined elements, must be ignored.
org:
foo:
bar: true

0 comments on commit 9d1bd11

Please sign in to comment.