Search in sources :

Example 91 with AttributeDefinition

use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.

the class InfinispanSubsystemXMLReader method readElement.

private static void readElement(XMLExtendedStreamReader reader, ModelNode operation, Attribute attribute) throws XMLStreamException {
    AttributeDefinition definition = attribute.getDefinition();
    AttributeParser parser = definition.getParser();
    if (parser.isParseAsElement()) {
        parser.parseElement(definition, reader, operation);
    } else {
        parser.parseAndSetParameter(definition, reader.getElementText(), operation, reader);
    }
}
Also used : AttributeParser(org.jboss.as.controller.AttributeParser) AttributeDefinition(org.jboss.as.controller.AttributeDefinition)

Example 92 with AttributeDefinition

use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.

the class LegacyMetricOperationsRegistration method register.

public void register(ManagementResourceRegistration registration) {
    // Transform legacy /subsystem=modcluster/mod-cluster-config=CONFIGURATION:add-metric(type=...) operation
    // -> /subsystem=modcluster/proxy=*/dynamic-load-provider=configuration/load-metric=...:add(...)
    OperationDefinition legacyAddMetricOperation = new SimpleOperationDefinitionBuilder("add-metric", ModClusterExtension.SUBSYSTEM_RESOLVER).addParameter(LoadMetricResourceDefinition.Attribute.TYPE.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.WEIGHT.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.CAPACITY.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.PROPERTY.getDefinition()).setDeprecated(ModClusterModel.VERSION_6_0_0.getVersion()).build();
    OperationStepHandler legacyAddMetricHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            operationDeprecated(context, operation);
            PathAddress address = translateProxyPath(context);
            String type = operation.require(LoadMetricResourceDefinition.Attribute.TYPE.getName()).asString();
            PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type));
            PathAddress metricPathAddress = address.append(metricPath);
            ModelNode metricOperation = Util.createAddOperation(metricPathAddress);
            OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.ADD);
            for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) {
                String name = attribute.getName();
                if (operation.hasDefined(name)) {
                    metricOperation.get(name).set(operation.get(name));
                }
            }
            context.addStep(metricOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true);
        }
    };
    registration.registerOperationHandler(legacyAddMetricOperation, legacyAddMetricHandler);
    // Transform legacy /subsystem=modcluster/mod-cluster-config=CONFIGURATION:remove-metric(type=...) operation
    // -> /subsystem=modcluster/proxy=*/dynamic-load-provider=configuration/load-metric=...:remove()
    OperationDefinition legacyRemoveMetricOperation = new SimpleOperationDefinitionBuilder("remove-metric", ModClusterExtension.SUBSYSTEM_RESOLVER).addParameter(LoadMetricResourceDefinition.Attribute.TYPE.getDefinition()).setDeprecated(ModClusterModel.VERSION_6_0_0.getVersion()).build();
    OperationStepHandler legacyRemoveMetricHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            operationDeprecated(context, operation);
            PathAddress address = translateProxyPath(context);
            String type = operation.require(LoadMetricResourceDefinition.Attribute.TYPE.getName()).asString();
            PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type));
            PathAddress metricPathAddress = address.append(metricPath);
            ModelNode metricOperation = Util.createRemoveOperation(metricPathAddress);
            OperationEntry removeOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.REMOVE);
            context.addStep(metricOperation, removeOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true);
        }
    };
    registration.registerOperationHandler(legacyRemoveMetricOperation, legacyRemoveMetricHandler);
    // Transform legacy /subsystem=modcluster/mod-cluster-config=CONFIGURATION:add-custom-metric(class=...) operation
    // -> /subsystem=modcluster/proxy=*/dynamic-load-provider=configuration/custom-load-metric=...:add(...)
    OperationDefinition legacyAddCustomMetricOperation = new SimpleOperationDefinitionBuilder("add-custom-metric", ModClusterExtension.SUBSYSTEM_RESOLVER).addParameter(CustomLoadMetricResourceDefinition.Attribute.CLASS.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.WEIGHT.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.CAPACITY.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.PROPERTY.getDefinition()).setDeprecated(ModClusterModel.VERSION_6_0_0.getVersion()).build();
    OperationStepHandler legacyAddCustomMetricHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            operationDeprecated(context, operation);
            PathAddress address = translateProxyPath(context);
            String type = operation.require(CustomLoadMetricResourceDefinition.Attribute.CLASS.getName()).asString();
            PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type));
            PathAddress metricPathAddress = address.append(metricPath);
            ModelNode metricOperation = Util.createAddOperation(metricPathAddress);
            OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.ADD);
            for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) {
                String name = attribute.getName();
                if (operation.hasDefined(name)) {
                    metricOperation.get(name).set(operation.get(name));
                }
            }
            context.addStep(metricOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true);
        }
    };
    registration.registerOperationHandler(legacyAddCustomMetricOperation, legacyAddCustomMetricHandler);
    // Transform legacy /subsystem=modcluster/mod-cluster-config=CONFIGURATION:remove-custom-metric(class=...) operation
    // -> /subsystem=modcluster/proxy=*/dynamic-load-provider=configuration/custom-load-metric=...:remove()
    OperationDefinition legacyRemoveCustomMetricOperation = new SimpleOperationDefinitionBuilder("remove-custom-metric", ModClusterExtension.SUBSYSTEM_RESOLVER).addParameter(CustomLoadMetricResourceDefinition.Attribute.CLASS.getDefinition()).setDeprecated(ModClusterModel.VERSION_6_0_0.getVersion()).build();
    OperationStepHandler legacyRemoveCustomMetricHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            operationDeprecated(context, operation);
            PathAddress address = translateProxyPath(context);
            String type = operation.require(CustomLoadMetricResourceDefinition.Attribute.CLASS.getName()).asString();
            PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type));
            PathAddress metricPathAddress = address.append(metricPath);
            ModelNode metricOperation = Util.createRemoveOperation(metricPathAddress);
            OperationEntry removeOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.REMOVE);
            context.addStep(metricOperation, removeOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true);
        }
    };
    registration.registerOperationHandler(legacyRemoveCustomMetricOperation, legacyRemoveCustomMetricHandler);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress) OperationEntry(org.jboss.as.controller.registry.OperationEntry) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelNode(org.jboss.dmr.ModelNode) OperationDefinition(org.jboss.as.controller.OperationDefinition)

Example 93 with AttributeDefinition

use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.

the class NamingBindingResourceDefinition method registerOperations.

@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
    super.registerOperations(resourceRegistration);
    SimpleOperationDefinitionBuilder builder = new SimpleOperationDefinitionBuilder(NamingSubsystemModel.REBIND, getResourceDescriptionResolver()).addParameter(SimpleAttributeDefinitionBuilder.create(BINDING_TYPE).setValidator(new EnumValidator<>(BindingType.class, EnumSet.complementOf(EnumSet.of(BindingType.EXTERNAL_CONTEXT)))).build()).addParameter(TYPE).addParameter(VALUE).addParameter(CLASS).addParameter(MODULE).addParameter(LOOKUP).addParameter(ENVIRONMENT);
    resourceRegistration.registerOperationHandler(builder.build(), new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            context.addStep(new OperationStepHandler() {

                @Override
                public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                    Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
                    ModelNode model = resource.getModel();
                    for (AttributeDefinition attr : ATTRIBUTES) {
                        attr.validateAndSet(operation, model);
                    }
                    context.addStep(NamingBindingResourceDefinition.VALIDATE_RESOURCE_MODEL_OPERATION_STEP_HANDLER, OperationContext.Stage.MODEL);
                    context.addStep(new OperationStepHandler() {

                        @Override
                        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                            final String name = context.getCurrentAddressValue();
                            final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(name);
                            ServiceController<ManagedReferenceFactory> service = (ServiceController<ManagedReferenceFactory>) context.getServiceRegistry(false).getService(bindInfo.getBinderServiceName());
                            if (service == null) {
                                context.reloadRequired();
                                return;
                            }
                            NamingBindingAdd.INSTANCE.doRebind(context, operation, (BinderService) service.getService());
                        }
                    }, OperationContext.Stage.RUNTIME);
                }
            }, OperationContext.Stage.MODEL);
        }
    });
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) Resource(org.jboss.as.controller.registry.Resource) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) PropertiesAttributeDefinition(org.jboss.as.controller.PropertiesAttributeDefinition) BinderService(org.jboss.as.naming.service.BinderService) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ServiceController(org.jboss.msc.service.ServiceController) ModelNode(org.jboss.dmr.ModelNode)

Example 94 with AttributeDefinition

use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.

the class HandlerResourceDefinition method createAttributeWriterHandler.

@Override
protected OperationStepHandler createAttributeWriterHandler() {
    return new ModelOnlyWriteAttributeHandler(getAttributes().toArray(new AttributeDefinition[0])) {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            context.addStep(new UniqueTypeValidationStepHandler(ModelElement.COMMON_HANDLER) {

                @Override
                protected String getType(OperationContext context, ModelNode model) throws OperationFailedException {
                    return getHandlerType(context, model);
                }
            }, OperationContext.Stage.MODEL);
            super.execute(context, operation);
        }
    };
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) ModelOnlyWriteAttributeHandler(org.jboss.as.controller.ModelOnlyWriteAttributeHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) UniqueTypeValidationStepHandler(org.wildfly.extension.picketlink.common.model.validator.UniqueTypeValidationStepHandler) ModelNode(org.jboss.dmr.ModelNode)

Example 95 with AttributeDefinition

use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.

the class ElytronIntegrationResourceDefinitions method getElytronRealmResourceDefinition.

/**
 * Defines a resource that represents an Elytron-compatible realm that can be exported by the legacy security subsystem.
 * The constructed {@code SecurityRealm} wraps a legacy {@code SecurityDomainContext} and delegates authentication
 * decisions to that context.
 *
 * To export the realm the resource uses a {@code BasicAddHandler} implementation that registers the security-realm
 * capability and implements a {@code org.jboss.as.security.elytron.BasicService.ValueSupplier} that uses the injected
 * {@code SecurityDomainContext} to create and return an instance of {@code SecurityDomainContextRealm}.
 */
public static ResourceDefinition getElytronRealmResourceDefinition() {
    final AttributeDefinition[] attributes = new AttributeDefinition[] { LEGACY_JAAS_CONFIG, APPLY_ROLE_MAPPERS };
    final AbstractAddStepHandler addHandler = createAddHandler(attributes, SECURITY_REALM_RUNTIME_CAPABILITY);
    return new BasicResourceDefinition(Constants.ELYTRON_REALM, addHandler, attributes, SECURITY_REALM_RUNTIME_CAPABILITY);
}
Also used : AbstractAddStepHandler(org.jboss.as.controller.AbstractAddStepHandler) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition)

Aggregations

AttributeDefinition (org.jboss.as.controller.AttributeDefinition)102 ModelNode (org.jboss.dmr.ModelNode)48 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)40 PathAddress (org.jboss.as.controller.PathAddress)17 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)16 ReloadRequiredWriteAttributeHandler (org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)14 OperationContext (org.jboss.as.controller.OperationContext)13 Resource (org.jboss.as.controller.registry.Resource)12 Property (org.jboss.dmr.Property)12 ObjectTypeAttributeDefinition (org.jboss.as.controller.ObjectTypeAttributeDefinition)9 PropertiesAttributeDefinition (org.jboss.as.controller.PropertiesAttributeDefinition)9 StringListAttributeDefinition (org.jboss.as.controller.StringListAttributeDefinition)9 OperationFailedException (org.jboss.as.controller.OperationFailedException)8 ArrayList (java.util.ArrayList)7 PrimitiveListAttributeDefinition (org.jboss.as.controller.PrimitiveListAttributeDefinition)6 Map (java.util.Map)5 AbstractAddStepHandler (org.jboss.as.controller.AbstractAddStepHandler)5 SimpleListAttributeDefinition (org.jboss.as.controller.SimpleListAttributeDefinition)5 SimpleOperationDefinitionBuilder (org.jboss.as.controller.SimpleOperationDefinitionBuilder)5 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)5