Search in sources :

Example 16 with ResourceTransformationDescriptionBuilder

use of org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder in project wildfly by wildfly.

the class ProtocolResourceDefinition method buildTransformation.

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
    ResourceTransformationDescriptionBuilder builder = parent.addChildResource(WILDCARD_PATH);
    addTransformations(version, builder);
}
Also used : ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)

Example 17 with ResourceTransformationDescriptionBuilder

use of org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder in project wildfly by wildfly.

the class TransactionResourceDefinition method buildTransformation.

@SuppressWarnings("deprecation")
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
    ResourceTransformationDescriptionBuilder builder = InfinispanModel.VERSION_4_0_0.requiresTransformation(version) ? parent.addChildRedirection(PATH, LEGACY_PATH, RequiredChildResourceDiscardPolicy.NEVER) : parent.addChildResource(PATH);
    List<org.jboss.as.controller.transform.OperationTransformer> addOperationTransformers = new LinkedList<>();
    List<org.jboss.as.controller.transform.OperationTransformer> removeOperationTransformers = new LinkedList<>();
    Map<String, org.jboss.as.controller.transform.OperationTransformer> readAttributeTransformers = new HashMap<>();
    Map<String, org.jboss.as.controller.transform.OperationTransformer> writeAttributeTransformers = new HashMap<>();
    Map<String, org.jboss.as.controller.transform.OperationTransformer> undefineAttributeTransformers = new HashMap<>();
    if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) {
        // Convert BATCH -> NONE, and include write-attribute:name=batching
        OperationTransformer addTransformer = new OperationTransformer() {

            @Override
            public ModelNode transformOperation(ModelNode operation) {
                if (operation.hasDefined(Attribute.MODE.getName())) {
                    ModelNode mode = operation.get(Attribute.MODE.getName());
                    if ((mode.getType() == ModelType.STRING) && (TransactionMode.valueOf(mode.asString()) == TransactionMode.BATCH)) {
                        mode.set(TransactionMode.NONE.name());
                        PathAddress address = Operations.getPathAddress(operation);
                        return Operations.createCompositeOperation(operation, Operations.createWriteAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING, new ModelNode(true)));
                    }
                }
                return operation;
            }
        };
        addOperationTransformers.add(new SimpleOperationTransformer(addTransformer));
        // Additionally include undefine-attribute:name=batching
        OperationTransformer removeTransformer = new OperationTransformer() {

            @Override
            public ModelNode transformOperation(ModelNode operation) {
                PathAddress address = Operations.getPathAddress(operation);
                return Operations.createCompositeOperation(operation, Operations.createUndefineAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING));
            }
        };
        removeOperationTransformers.add(new SimpleOperationTransformer(removeTransformer));
        // If read-attribute:name=batching is true, return BATCH, otherwise use result from read-attribute:name=mode
        OperationTransformer readAttributeOperationTransformer = new OperationTransformer() {

            @Override
            public ModelNode transformOperation(ModelNode operation) {
                PathAddress address = Operations.getPathAddress(operation);
                return Operations.createCompositeOperation(Operations.createReadAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING), operation);
            }
        };
        OperationResultTransformer readAttributeResultTransformer = new OperationResultTransformer() {

            @Override
            public ModelNode transformResult(ModelNode result) {
                ModelNode readBatchingResult = result.get(0);
                return readBatchingResult.asBoolean() ? new ModelNode(TransactionMode.BATCH.name()) : result.get(1);
            }
        };
        readAttributeTransformers.put(Attribute.MODE.getName(), new SimpleOperationTransformer(readAttributeOperationTransformer, readAttributeResultTransformer));
        // Convert BATCH -> NONE, and include write-attribute:name=batching
        OperationTransformer writeAttributeTransformer = new OperationTransformer() {

            @Override
            public ModelNode transformOperation(ModelNode operation) {
                ModelNode mode = Operations.getAttributeValue(operation);
                boolean batching = (mode.isDefined() && (mode.getType() == ModelType.STRING)) ? (TransactionMode.valueOf(mode.asString()) == TransactionMode.BATCH) : false;
                if (batching) {
                    mode.set(TransactionMode.NONE.name());
                }
                PathAddress address = Operations.getPathAddress(operation);
                return Operations.createCompositeOperation(operation, Operations.createWriteAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING, new ModelNode(batching)));
            }
        };
        writeAttributeTransformers.put(Attribute.MODE.getName(), new SimpleOperationTransformer(writeAttributeTransformer));
        // Include undefine-attribute:name=batching
        OperationTransformer undefineAttributeTransformer = new OperationTransformer() {

            @Override
            public ModelNode transformOperation(ModelNode operation) {
                PathAddress address = Operations.getPathAddress(operation);
                return Operations.createCompositeOperation(operation, Operations.createUndefineAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING));
            }
        };
        undefineAttributeTransformers.put(Attribute.MODE.getName(), new SimpleOperationTransformer(undefineAttributeTransformer));
        // Convert BATCH -> NONE
        ResourceTransformer modeTransformer = new ResourceTransformer() {

            @Override
            public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
                ModelNode model = resource.getModel();
                if (model.hasDefined(Attribute.MODE.getName())) {
                    ModelNode value = model.get(Attribute.MODE.getName());
                    if ((value.getType() == ModelType.STRING) && (TransactionMode.valueOf(value.asString()) == TransactionMode.BATCH)) {
                        value.set(TransactionMode.NONE.name());
                    }
                }
                context.addTransformedResource(PathAddress.EMPTY_ADDRESS, resource).processChildren(resource);
            }
        };
        builder.setCustomResourceTransformer(modeTransformer);
        // change default value of stop-timeout attribute
        builder.getAttributeBuilder().setValueConverter(new DefaultValueAttributeConverter(Attribute.STOP_TIMEOUT.getDefinition()), Attribute.STOP_TIMEOUT.getDefinition());
    }
    buildOperationTransformation(builder, ModelDescriptionConstants.ADD, addOperationTransformers);
    buildOperationTransformation(builder, ModelDescriptionConstants.REMOVE, removeOperationTransformers);
    buildOperationTransformation(builder, ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION, readAttributeTransformers);
    buildOperationTransformation(builder, ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION, writeAttributeTransformers);
    buildOperationTransformation(builder, ModelDescriptionConstants.UNDEFINE_ATTRIBUTE_OPERATION, undefineAttributeTransformers);
}
Also used : OperationResultTransformer(org.jboss.as.controller.transform.OperationResultTransformer) ChainedOperationTransformer(org.jboss.as.clustering.controller.transform.ChainedOperationTransformer) AttributeOperationTransformer(org.jboss.as.clustering.controller.transform.AttributeOperationTransformer) OperationTransformer(org.jboss.as.clustering.controller.transform.OperationTransformer) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) HashMap(java.util.HashMap) Resource(org.jboss.as.controller.registry.Resource) ResourceTransformationContext(org.jboss.as.controller.transform.ResourceTransformationContext) LinkedList(java.util.LinkedList) PathAddress(org.jboss.as.controller.PathAddress) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) DefaultValueAttributeConverter(org.jboss.as.controller.transform.description.AttributeConverter.DefaultValueAttributeConverter) ModelNode(org.jboss.dmr.ModelNode) ResourceTransformer(org.jboss.as.controller.transform.ResourceTransformer)

Example 18 with ResourceTransformationDescriptionBuilder

use of org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder in project wildfly by wildfly.

the class JcaDistributedWorkManagerDefinition method registerElytronTransformers.

static void registerElytronTransformers(ResourceTransformationDescriptionBuilder parentBuilder) {
    ResourceTransformationDescriptionBuilder builder = parentBuilder.addChildResource(PATH_DISTRIBUTED_WORK_MANAGER);
    builder.getAttributeBuilder().setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(false, true, new ModelNode(false)), DWmParameters.ELYTRON_ENABLED.getAttribute()).addRejectCheck(RejectAttributeChecker.DEFINED, DWmParameters.ELYTRON_ENABLED.getAttribute()).end();
}
Also used : ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) ModelNode(org.jboss.dmr.ModelNode) DiscardAttributeChecker(org.jboss.as.controller.transform.description.DiscardAttributeChecker)

Example 19 with ResourceTransformationDescriptionBuilder

use of org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder in project wildfly by wildfly.

the class JcaDistributedWorkManagerDefinition method registerTransformers300.

static void registerTransformers300(ResourceTransformationDescriptionBuilder parentBuilder) {
    ResourceTransformationDescriptionBuilder builder = parentBuilder.addChildResource(PATH_DISTRIBUTED_WORK_MANAGER);
    builder.addOperationTransformationOverride("add").inheritResourceAttributeDefinitions().setCustomOperationTransformer(new OperationTransformer() {

        @Override
        public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) throws OperationFailedException {
            ModelNode copy = operation.clone();
            copy.add("transport-jgroups-cluster").set(address.getLastElement().toString());
            return new TransformedOperation(copy, TransformedOperation.ORIGINAL_RESULT);
        }
    }).end().getAttributeBuilder().setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(false, true, new ModelNode(false)), DWmParameters.ELYTRON_ENABLED.getAttribute()).addRejectCheck(RejectAttributeChecker.DEFINED, DWmParameters.ELYTRON_ENABLED.getAttribute()).end();
}
Also used : OperationTransformer(org.jboss.as.controller.transform.OperationTransformer) PathAddress(org.jboss.as.controller.PathAddress) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) ModelNode(org.jboss.dmr.ModelNode) TransformationContext(org.jboss.as.controller.transform.TransformationContext) DiscardAttributeChecker(org.jboss.as.controller.transform.description.DiscardAttributeChecker)

Example 20 with ResourceTransformationDescriptionBuilder

use of org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder in project wildfly by wildfly.

the class DataSourceDefinition method registerTransformers300.

static void registerTransformers300(ResourceTransformationDescriptionBuilder parentBuilder) {
    ResourceTransformationDescriptionBuilder builder = parentBuilder.addChildResource(PATH_DATASOURCE);
    builder.getAttributeBuilder().setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(new ModelNode(true)), org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FAIR).setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(new ModelNode(true)), ENLISTMENT_TRACE).setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(new ModelNode(LEGACY_MCP)), MCP).setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(false, true, new ModelNode(false)), ELYTRON_ENABLED, RECOVERY_ELYTRON_ENABLED).setDiscard(DiscardAttributeChecker.UNDEFINED, AUTHENTICATION_CONTEXT, RECOVERY_AUTHENTICATION_CONTEXT, CREDENTIAL_REFERENCE).addRejectCheck(RejectAttributeChecker.SIMPLE_EXPRESSIONS, ALLOW_MULTIPLE_USERS).addRejectCheck(RejectAttributeChecker.DEFINED, org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FAIR).addRejectCheck(RejectAttributeChecker.DEFINED, ENLISTMENT_TRACE).addRejectCheck(RejectAttributeChecker.DEFINED, MCP).addRejectCheck(RejectAttributeChecker.DEFINED, ELYTRON_ENABLED, RECOVERY_ELYTRON_ENABLED, AUTHENTICATION_CONTEXT, RECOVERY_AUTHENTICATION_CONTEXT, CREDENTIAL_REFERENCE).addRejectCheck(createConnURLRejectChecker(), CONNECTION_URL).end();
}
Also used : ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) ModelNode(org.jboss.dmr.ModelNode) DiscardAttributeChecker(org.jboss.as.controller.transform.description.DiscardAttributeChecker)

Aggregations

ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)119 ModelNode (org.jboss.dmr.ModelNode)50 DiscardAttributeChecker (org.jboss.as.controller.transform.description.DiscardAttributeChecker)27 PathAddress (org.jboss.as.controller.PathAddress)26 TransformationContext (org.jboss.as.controller.transform.TransformationContext)16 SimpleOperationTransformer (org.jboss.as.clustering.controller.transform.SimpleOperationTransformer)9 ChainedTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ChainedTransformationDescriptionBuilder)9 ModelVersion (org.jboss.as.controller.ModelVersion)8 LegacyPropertyResourceTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer)7 Resource (org.jboss.as.controller.registry.Resource)7 ResourceTransformationContext (org.jboss.as.controller.transform.ResourceTransformationContext)6 ResourceTransformer (org.jboss.as.controller.transform.ResourceTransformer)6 Map (java.util.Map)4 LegacyPropertyAddOperationTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer)4 OperationTransformer (org.jboss.as.clustering.controller.transform.OperationTransformer)4 OperationFailedException (org.jboss.as.controller.OperationFailedException)4 AttributeConverter (org.jboss.as.controller.transform.description.AttributeConverter)4 RejectAttributeChecker (org.jboss.as.controller.transform.description.RejectAttributeChecker)4 LinkedList (java.util.LinkedList)2 ChainedOperationTransformer (org.jboss.as.clustering.controller.transform.ChainedOperationTransformer)2