use of org.jboss.as.controller.PathElement in project keycloak by keycloak.
the class ThemeResourceAddHandler method populateModel.
@Override
protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException {
// TODO: localize exception. get id number
if (!operation.get(OP).asString().equals(ADD)) {
throw new OperationFailedException("Unexpected operation for add Theme. operation=" + operation.toString());
}
PathAddress address = PathAddress.pathAddress(operation.get(ADDRESS));
PathElement last = address.getLastElement();
if (!last.getValue().equals(ThemeResourceDefinition.RESOURCE_NAME)) {
throw new OperationFailedException("Theme resource with name " + last.getValue() + " not allowed.");
}
for (AttributeDefinition def : ALL_ATTRIBUTES) {
def.validateAndSet(operation, model);
}
KeycloakAdapterConfigService.INSTANCE.updateConfig(operation, model);
}
use of org.jboss.as.controller.PathElement in project keycloak by keycloak.
the class KeycloakAdapterConfigService method updateConfig.
void updateConfig(ModelNode operation, ModelNode config) {
PathAddress address = PathAddress.pathAddress(operation.get(ADDRESS));
// remove root (subsystem=keycloak-server)
address = address.subAddress(1);
ModelNode newConfig = fullConfig.clone();
ModelNode subNode = newConfig;
for (PathElement pathElement : address) {
subNode = subNode.get(pathElement.getKey(), pathElement.getValue());
}
subNode.set(config.clone());
// remove undefined properties
for (Property prop : subNode.asPropertyList()) {
if (!prop.getValue().isDefined()) {
subNode.remove(prop.getName());
}
}
fullConfig = newConfig;
}
use of org.jboss.as.controller.PathElement in project camunda-bpm-platform by camunda.
the class JBossSubsystemXMLTest method testParseSubsystemXml.
@Test
public void testParseSubsystemXml() throws Exception {
String subsystemXml = FileUtils.readFile(SUBSYSTEM_WITH_PROCESS_ENGINES_ELEMENT_ONLY);
List<ModelNode> operations = parse(subsystemXml);
assertEquals(1, operations.size());
// The add subsystem operation will happen first
ModelNode addSubsystem = operations.get(0);
assertEquals(ADD, addSubsystem.get(OP).asString());
PathAddress addr = PathAddress.pathAddress(addSubsystem.get(OP_ADDR));
assertEquals(1, addr.size());
PathElement element = addr.getElement(0);
assertEquals(SUBSYSTEM, element.getKey());
assertEquals(ModelConstants.SUBSYSTEM_NAME, element.getValue());
}
use of org.jboss.as.controller.PathElement in project wildfly by wildfly.
the class StackResourceDefinition method register.
@SuppressWarnings("deprecation")
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
ManagementResourceRegistration registration = parent.registerSubModel(this);
ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()).addAttributes(Attribute.class).addExtraParameters(TRANSPORT, PROTOCOLS).addCapabilities(Capability.class).setAddOperationTransformation(new AddOperationTransformation());
ResourceServiceHandler handler = new StackServiceHandler(this.serviceConfiguratorFactory);
new SimpleResourceRegistration(descriptor, handler).register(registration);
OperationDefinition legacyAddProtocolOperation = new SimpleOperationDefinitionBuilder("add-protocol", this.getResourceDescriptionResolver()).setParameters(MulticastProtocolResourceDefinition.Attribute.SOCKET_BINDING.getDefinition()).addParameter(AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.getDefinition()).addParameter(AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getDefinition()).setDeprecated(JGroupsModel.VERSION_3_0_0.getVersion()).build();
// Transform legacy /subsystem=jgroups/stack=*:add-protocol() operation -> /subsystem=jgroups/stack=*/protocol=*:add()
OperationStepHandler legacyAddProtocolHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
operationDeprecated(context, operation);
PathAddress address = context.getCurrentAddress();
String protocol = operation.require(AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.getName()).asString();
PathElement protocolPath = ProtocolResourceDefinition.pathElement(protocol);
PathAddress protocolAddress = address.append(protocolPath);
ModelNode protocolOperation = Util.createAddOperation(protocolAddress);
OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(protocolPath), ModelDescriptionConstants.ADD);
for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) {
String name = attribute.getName();
if (operation.hasDefined(name)) {
protocolOperation.get(name).set(operation.get(name));
}
}
context.addStep(protocolOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true);
}
};
registration.registerOperationHandler(legacyAddProtocolOperation, legacyAddProtocolHandler);
OperationDefinition legacyRemoveProtocolOperation = new SimpleOperationDefinitionBuilder("remove-protocol", this.getResourceDescriptionResolver()).setParameters(AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.getDefinition()).setDeprecated(JGroupsModel.VERSION_3_0_0.getVersion()).build();
// Transform legacy /subsystem=jgroups/stack=*:remove-protocol() operation -> /subsystem=jgroups/stack=*/protocol=*:remove()
OperationStepHandler legacyRemoveProtocolHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
operationDeprecated(context, operation);
PathAddress address = context.getCurrentAddress();
String protocol = operation.require(AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.getName()).asString();
PathElement protocolPath = ProtocolResourceDefinition.pathElement(protocol);
PathAddress protocolAddress = address.append(protocolPath);
ModelNode removeOperation = Util.createRemoveOperation(protocolAddress);
context.addStep(removeOperation, context.getResourceRegistration().getOperationHandler(PathAddress.pathAddress(protocolPath), ModelDescriptionConstants.REMOVE), context.getCurrentStage());
}
};
registration.registerOperationHandler(legacyRemoveProtocolOperation, legacyRemoveProtocolHandler);
if (registration.isRuntimeOnlyRegistrationValid()) {
new StackOperationHandler().register(registration);
}
new TransportRegistration(this.serviceConfiguratorFactory).register(registration);
new ProtocolRegistration(this.serviceConfiguratorFactory).register(registration);
new RelayResourceDefinition(this.serviceConfiguratorFactory).register(registration);
return registration;
}
use of org.jboss.as.controller.PathElement in project wildfly by wildfly.
the class JGroupsSubsystemXMLWriter method writeThreadPoolElements.
private static void writeThreadPoolElements(XMLElement element, ThreadPoolResourceDefinition pool, XMLExtendedStreamWriter writer, ModelNode transport) throws XMLStreamException {
PathElement path = pool.getPathElement();
if (transport.get(path.getKey()).hasDefined(path.getValue())) {
ModelNode threadPool = transport.get(path.getKeyValuePair());
if (hasDefined(threadPool, pool.getAttributes())) {
writer.writeStartElement(element.getLocalName());
writeAttributes(writer, threadPool, pool.getAttributes());
writer.writeEndElement();
}
}
}
Aggregations