Search in sources :

Example 6 with PathElement

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);
}
Also used : PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException) AttributeDefinition(org.jboss.as.controller.AttributeDefinition)

Example 7 with PathElement

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;
}
Also used : PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Example 8 with PathElement

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());
}
Also used : PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) AbstractSubsystemTest(org.jboss.as.subsystem.test.AbstractSubsystemTest) Test(org.junit.Test)

Example 9 with PathElement

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;
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) UnaryRequirementCapability(org.jboss.as.clustering.controller.UnaryRequirementCapability) SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationEntry(org.jboss.as.controller.registry.OperationEntry) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ObjectListAttributeDefinition(org.jboss.as.controller.ObjectListAttributeDefinition) ObjectTypeAttributeDefinition(org.jboss.as.controller.ObjectTypeAttributeDefinition) ManagementResourceRegistration(org.jboss.as.clustering.controller.ManagementResourceRegistration) SimpleResourceRegistration(org.jboss.as.clustering.controller.SimpleResourceRegistration) PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) ResourceServiceHandler(org.jboss.as.clustering.controller.ResourceServiceHandler) OperationDefinition(org.jboss.as.controller.OperationDefinition) ResourceDescriptor(org.jboss.as.clustering.controller.ResourceDescriptor)

Example 10 with PathElement

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();
        }
    }
}
Also used : PathElement(org.jboss.as.controller.PathElement) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

PathElement (org.jboss.as.controller.PathElement)84 PathAddress (org.jboss.as.controller.PathAddress)47 ModelNode (org.jboss.dmr.ModelNode)46 Resource (org.jboss.as.controller.registry.Resource)24 OperationFailedException (org.jboss.as.controller.OperationFailedException)12 ServiceName (org.jboss.msc.service.ServiceName)12 Test (org.junit.Test)10 Map (java.util.Map)9 ArrayList (java.util.ArrayList)8 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)8 ParseUtils.requireNoNamespaceAttribute (org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute)7 ParseUtils.unexpectedAttribute (org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute)7 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)7 DeploymentResourceSupport (org.jboss.as.server.deployment.DeploymentResourceSupport)7 AbstractSubsystemBaseTest (org.jboss.as.subsystem.test.AbstractSubsystemBaseTest)7 ServiceTarget (org.jboss.msc.service.ServiceTarget)6 StatisticsResourceDefinition (org.jboss.as.connector.dynamicresource.StatisticsResourceDefinition)4 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)4 OperationContext (org.jboss.as.controller.OperationContext)4 StandardResourceDescriptionResolver (org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver)4