Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WFCORE-5953/WFCORE-5954: Fixing several YAML extension issues #5139

Merged
merged 2 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ private void processResource(PathAddress parentAddress, Map<String, Object> yaml
} else {
if (value != null) {
MGMT_OP_LOGGER.unexpectedValueForResource(value, address.toCLIStyleString(), name);
} else {// ADD operation without parameters
processAttributes(address, rootRegistration, operationEntry, null, postExtensionOps);
}
}
}
Expand Down Expand Up @@ -306,6 +308,8 @@ private void processAttribute(PathAddress address, ImmutableManagementResourceRe
op.get(NAME).set(attributeName);
ModelNode list = op.get(VALUE).setEmptyList();
processListAttribute((ListAttributeDefinition) att, list, value);
MGMT_OP_LOGGER.debugf("Updating attribute %s for resource %s with operation %s", attributeName, address, op);
postExtensionOps.add(new ParsedBootOp(op, operationEntry.getOperationHandler()));
}
}
break;
Expand Down Expand Up @@ -342,25 +346,27 @@ private void processAttributes(PathAddress address, ImmutableManagementResourceR
}
attributes.addAll(Arrays.asList(operationEntry.getOperationDefinition().getParameters()));
ModelNode op = createOperation(address, operationEntry);
for (AttributeDefinition att : attributes) {
if (map.containsKey(att.getName())) {
Object value = map.get(att.getName());
map.remove(att.getName());
switch (att.getType()) {
case OBJECT:
if (att instanceof MapAttributeDefinition) {
processMapAttribute((MapAttributeDefinition) att, op, (Map<String, Object>) value);
} else {
op.get(att.getName()).set(processObjectAttribute((ObjectTypeAttributeDefinition) att, (Map<String, Object>) value));
}
break;
case LIST:
ModelNode list = op.get(att.getName()).setEmptyList();
processListAttribute((ListAttributeDefinition) att, list, value);
break;
default:
op.get(att.getName()).set(value.toString());
break;
if (map != null) {
for (AttributeDefinition att : attributes) {
if (map.containsKey(att.getName())) {
Object value = map.get(att.getName());
map.remove(att.getName());
switch (att.getType()) {
case OBJECT:
if (att instanceof MapAttributeDefinition) {
processMapAttribute((MapAttributeDefinition) att, op, (Map<String, Object>) value);
} else {
op.get(att.getName()).set(processObjectAttribute((ObjectTypeAttributeDefinition) att, (Map<String, Object>) value));
}
break;
case LIST:
ModelNode list = op.get(att.getName()).setEmptyList();
processListAttribute((ListAttributeDefinition) att, list, value);
break;
default:
op.get(att.getName()).set(value.toString());
break;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,21 @@ public void registerAttributes(ManagementResourceRegistration resourceRegistrati
resourceRegistration.registerReadWriteAttribute(listAtt, null, new ModelOnlyWriteAttributeHandler(valueAtt));
}
};
SimpleResourceDefinition basicResource = new SimpleResourceDefinition(new SimpleResourceDefinition.Parameters(PathElement.pathElement("basic"), descriptionResolver)
.setAddHandler(new AbstractBoottimeAddStepHandler(valueAtt) {
})) {
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
super.registerAttributes(resourceRegistration);
resourceRegistration.registerReadWriteAttribute(valueAtt, null, new ModelOnlyWriteAttributeHandler(valueAtt));
}
};
ManagementResourceRegistration root = ManagementResourceRegistration.Factory.forProcessType(ProcessType.EMBEDDED_SERVER).createRegistration(rootResource);
GlobalOperationHandlers.registerGlobalOperations(root, ProcessType.EMBEDDED_SERVER);
root.registerSubModel(systemPropertyResource);
root.registerSubModel(extensionResource);
root.registerSubModel(listResource);
root.registerSubModel(basicResource);
AttributeDefinition connectorType = SimpleAttributeDefinitionBuilder.create("type", STRING, true)
.setAllowExpression(true)
.setValidator(new StringLengthValidator(0, true, true))
Expand Down Expand Up @@ -147,19 +157,22 @@ public void testAddingNewResources() throws URISyntaxException {
ConfigurationExtension instance = ConfigurationExtensionFactory.createConfigurationExtension(Paths.get(this.getClass().getResource("simple.yml").toURI()));
instance.processOperations(rootRegistration, postExtensionOps);
assertFalse(postExtensionOps.isEmpty());
assertEquals(3, postExtensionOps.size());
assertEquals(4, 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(PathAddress.pathAddress("basic", "test"), postExtensionOps.get(0).address);
assertFalse(postExtensionOps.get(0).operation.hasDefined("value"));
assertEquals(ADD, postExtensionOps.get(1).operationName);
assertEquals(PathAddress.pathAddress("system-property", "bbb"), postExtensionOps.get(1).address);
assertEquals(PathAddress.pathAddress("system-property", "aaa"), postExtensionOps.get(1).address);
assertTrue(postExtensionOps.get(1).operation.hasDefined("value"));
assertEquals("bar", postExtensionOps.get(1).operation.get("value").asString());
assertEquals("foo", postExtensionOps.get(1).operation.get("value").asString());
assertEquals(ADD, postExtensionOps.get(2).operationName);
assertEquals(PathAddress.pathAddress("system-property", "ccc"), postExtensionOps.get(2).address);
assertEquals(PathAddress.pathAddress("system-property", "bbb"), postExtensionOps.get(2).address);
assertTrue(postExtensionOps.get(2).operation.hasDefined("value"));
assertEquals("test", postExtensionOps.get(2).operation.get("value").asString());
assertEquals("bar", postExtensionOps.get(2).operation.get("value").asString());
assertEquals(ADD, postExtensionOps.get(3).operationName);
assertEquals(PathAddress.pathAddress("system-property", "ccc"), postExtensionOps.get(3).address);
assertTrue(postExtensionOps.get(3).operation.hasDefined("value"));
assertEquals("test", postExtensionOps.get(3).operation.get("value").asString());
}

/**
Expand Down Expand Up @@ -217,23 +230,28 @@ public void testWriteAttribute() throws URISyntaxException {
ConfigurationExtension instance = ConfigurationExtensionFactory.createConfigurationExtension(Paths.get(this.getClass().getResource("simple.yml").toURI()));
instance.processOperations(rootRegistration, postExtensionOps);
assertFalse(postExtensionOps.isEmpty());
assertEquals(5, postExtensionOps.size());
assertEquals(6, postExtensionOps.size());
assertEquals(ADD, postExtensionOps.get(0).operationName);
assertEquals(PathAddress.pathAddress("system-property", "aaa"), postExtensionOps.get(0).address);
assertFalse(postExtensionOps.get(0).operation.hasDefined("value"));
assertEquals(ADD, postExtensionOps.get(1).operationName);
assertEquals(PathAddress.pathAddress("system-property", "bbb"), postExtensionOps.get(1).address);
assertFalse(postExtensionOps.get(1).operation.hasDefined("value"));
assertEquals(PathAddress.pathAddress("system-property", "aaa"), postExtensionOps.get(2).address);
assertEquals(WRITE_ATTRIBUTE_OPERATION, postExtensionOps.get(2).operationName);
assertEquals("foo", postExtensionOps.get(2).operation.get("value").asString());
assertEquals(PathAddress.pathAddress("system-property", "bbb"), postExtensionOps.get(3).address);
assertEquals(ADD, postExtensionOps.get(2).operationName);
assertEquals(PathAddress.pathAddress("basic", "test"), postExtensionOps.get(2).address);
assertFalse(postExtensionOps.get(2).operation.hasDefined("value"));
assertEquals(PathAddress.pathAddress("system-property", "aaa"), postExtensionOps.get(3).address);
assertEquals(WRITE_ATTRIBUTE_OPERATION, postExtensionOps.get(3).operationName);
assertEquals("bar", postExtensionOps.get(3).operation.get("value").asString());
assertEquals(ADD, postExtensionOps.get(4).operationName);
assertEquals(PathAddress.pathAddress("system-property", "ccc"), postExtensionOps.get(4).address);
assertTrue(postExtensionOps.get(3).operation.hasDefined("value"));
assertEquals("foo", postExtensionOps.get(3).operation.get("value").asString());
assertEquals(PathAddress.pathAddress("system-property", "bbb"), postExtensionOps.get(4).address);
assertEquals(WRITE_ATTRIBUTE_OPERATION, postExtensionOps.get(4).operationName);
assertTrue(postExtensionOps.get(4).operation.hasDefined("value"));
assertEquals("test", postExtensionOps.get(4).operation.get("value").asString());
assertEquals("bar", postExtensionOps.get(4).operation.get("value").asString());
assertEquals(ADD, postExtensionOps.get(5).operationName);
assertEquals(PathAddress.pathAddress("system-property", "ccc"), postExtensionOps.get(5).address);
assertTrue(postExtensionOps.get(5).operation.hasDefined("value"));
assertEquals("test", postExtensionOps.get(5).operation.get("value").asString());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ wildfly-configuration:
system-property:
ccc:
value: test
basic:
test:
#User defined elements, must be ignored.
org:
foo:
Expand Down