Search in sources :

Example 1 with SimpleOperationTransformer

use of org.jboss.as.clustering.controller.transform.SimpleOperationTransformer in project wildfly by wildfly.

the class AbstractProtocolResourceDefinition method addTransformations.

/**
     * Builds transformations common to both stack protocols and transport.
     */
@SuppressWarnings("deprecation")
static void addTransformations(ModelVersion version, ResourceTransformationDescriptionBuilder builder) {
    if (JGroupsModel.VERSION_3_0_0.requiresTransformation(version)) {
        AttributeConverter typeConverter = new AttributeConverter.DefaultAttributeConverter() {

            @Override
            protected void convertAttribute(PathAddress address, String name, ModelNode value, TransformationContext context) {
                if (!value.isDefined()) {
                    value.set(address.getLastElement().getValue());
                }
            }
        };
        builder.getAttributeBuilder().setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(Attribute.MODULE.getDefinition().getDefaultValue()), Attribute.MODULE.getDefinition()).addRejectCheck(RejectAttributeChecker.DEFINED, Attribute.MODULE.getDefinition()).setValueConverter(typeConverter, DeprecatedAttribute.TYPE.getDefinition()).end();
        builder.addRawOperationTransformationOverride(MapOperations.MAP_GET_DEFINITION.getName(), new SimpleOperationTransformer(new LegacyPropertyMapGetOperationTransformer()));
        for (String opName : Operations.getAllWriteAttributeOperationNames()) {
            builder.addOperationTransformationOverride(opName).inheritResourceAttributeDefinitions().setCustomOperationTransformer(new LegacyPropertyWriteOperationTransformer());
        }
    }
    PropertyResourceDefinition.buildTransformation(version, builder);
}
Also used : AttributeConverter(org.jboss.as.controller.transform.description.AttributeConverter) PathAddress(org.jboss.as.controller.PathAddress) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) LegacyPropertyMapGetOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyMapGetOperationTransformer) ModelNode(org.jboss.dmr.ModelNode) TransformationContext(org.jboss.as.controller.transform.TransformationContext) LegacyPropertyWriteOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyWriteOperationTransformer)

Example 2 with SimpleOperationTransformer

use of org.jboss.as.clustering.controller.transform.SimpleOperationTransformer 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 3 with SimpleOperationTransformer

use of org.jboss.as.clustering.controller.transform.SimpleOperationTransformer in project wildfly by wildfly.

the class FileStoreResourceDefinition method buildTransformation.

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
    ResourceTransformationDescriptionBuilder builder = InfinispanModel.VERSION_4_0_0.requiresTransformation(version) ? parent.addChildRedirection(PATH, LEGACY_PATH) : parent.addChildResource(PATH);
    if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) {
        builder.addOperationTransformationOverride(ModelDescriptionConstants.ADD).setCustomOperationTransformer(new SimpleOperationTransformer(new LegacyPropertyAddOperationTransformer())).inheritResourceAttributeDefinitions();
        builder.setCustomResourceTransformer(new LegacyPropertyResourceTransformer());
    }
    StoreResourceDefinition.buildTransformation(version, builder);
}
Also used : LegacyPropertyResourceTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer) LegacyPropertyAddOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer)

Example 4 with SimpleOperationTransformer

use of org.jboss.as.clustering.controller.transform.SimpleOperationTransformer in project wildfly by wildfly.

the class BinaryTableResourceDefinition method buildTransformation.

@SuppressWarnings("deprecation")
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
    ResourceTransformationDescriptionBuilder builder = parent.addChildResource(PATH);
    if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
        OperationTransformer addTransformer = new OperationTransformer() {

            @Override
            public ModelNode transformOperation(ModelNode operation) {
                PathAddress storeAddress = Operations.getPathAddress(operation).getParent();
                ModelNode value = new ModelNode();
                for (Class<? extends org.jboss.as.clustering.controller.Attribute> attributeClass : Arrays.asList(Attribute.class, TableResourceDefinition.Attribute.class, TableResourceDefinition.ColumnAttribute.class)) {
                    for (org.jboss.as.clustering.controller.Attribute attribute : attributeClass.getEnumConstants()) {
                        String name = attribute.getName();
                        if (operation.hasDefined(name)) {
                            value.get(name).set(operation.get(name));
                        }
                    }
                }
                return value.isDefined() ? Operations.createWriteAttributeOperation(storeAddress, BinaryKeyedJDBCStoreResourceDefinition.DeprecatedAttribute.TABLE, value) : Operations.createUndefineAttributeOperation(storeAddress, BinaryKeyedJDBCStoreResourceDefinition.DeprecatedAttribute.TABLE);
            }
        };
        builder.addRawOperationTransformationOverride(ModelDescriptionConstants.ADD, new SimpleOperationTransformer(addTransformer));
        OperationTransformer removeTransformer = new OperationTransformer() {

            @Override
            public ModelNode transformOperation(ModelNode operation) {
                PathAddress storeAddress = Operations.getPathAddress(operation).getParent();
                return Operations.createUndefineAttributeOperation(storeAddress, BinaryKeyedJDBCStoreResourceDefinition.DeprecatedAttribute.TABLE);
            }
        };
        builder.addRawOperationTransformationOverride(ModelDescriptionConstants.REMOVE, new SimpleOperationTransformer(removeTransformer));
    }
}
Also used : SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) OperationTransformer(org.jboss.as.clustering.controller.transform.OperationTransformer) PathAddress(org.jboss.as.controller.PathAddress) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) ModelNode(org.jboss.dmr.ModelNode)

Example 5 with SimpleOperationTransformer

use of org.jboss.as.clustering.controller.transform.SimpleOperationTransformer in project wildfly by wildfly.

the class MixedKeyedJDBCStoreResourceDefinition method buildTransformation.

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
    ResourceTransformationDescriptionBuilder builder = InfinispanModel.VERSION_4_0_0.requiresTransformation(version) ? parent.addChildRedirection(PATH, LEGACY_PATH) : parent.addChildResource(PATH);
    BinaryTableResourceDefinition.buildTransformation(version, builder);
    StringTableResourceDefinition.buildTransformation(version, builder);
    JDBCStoreResourceDefinition.buildTransformation(version, builder);
    if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
        builder.setCustomResourceTransformer(new ResourceTransformer() {

            @Override
            public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
                final ModelNode model = resource.getModel();
                final ModelNode binaryTableModel = Resource.Tools.readModel(resource.removeChild(BinaryTableResourceDefinition.PATH));
                if (binaryTableModel != null && binaryTableModel.isDefined()) {
                    model.get(DeprecatedAttribute.BINARY_TABLE.getName()).set(binaryTableModel);
                }
                final ModelNode stringTableModel = Resource.Tools.readModel(resource.removeChild(StringTableResourceDefinition.PATH));
                if (stringTableModel != null && stringTableModel.isDefined()) {
                    model.get(DeprecatedAttribute.STRING_TABLE.getName()).set(stringTableModel);
                }
                final ModelNode properties = model.remove(StoreResourceDefinition.Attribute.PROPERTIES.getName());
                final ResourceTransformationContext childContext = context.addTransformedResource(PathAddress.EMPTY_ADDRESS, resource);
                LegacyPropertyResourceTransformer.transformPropertiesToChildrenResources(properties, address, childContext);
                context.processChildren(resource);
            }
        });
    }
    if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) {
        builder.addRawOperationTransformationOverride(MapOperations.MAP_GET_DEFINITION.getName(), new SimpleOperationTransformer(new LegacyPropertyMapGetOperationTransformer()));
        for (String opName : Operations.getAllWriteAttributeOperationNames()) {
            builder.addOperationTransformationOverride(opName).inheritResourceAttributeDefinitions().setCustomOperationTransformer(new LegacyPropertyWriteOperationTransformer());
        }
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) LegacyPropertyMapGetOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyMapGetOperationTransformer) LegacyPropertyResourceTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer) ResourceTransformer(org.jboss.as.controller.transform.ResourceTransformer) ModelNode(org.jboss.dmr.ModelNode) ResourceTransformationContext(org.jboss.as.controller.transform.ResourceTransformationContext) LegacyPropertyWriteOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyWriteOperationTransformer)

Aggregations

SimpleOperationTransformer (org.jboss.as.clustering.controller.transform.SimpleOperationTransformer)12 PathAddress (org.jboss.as.controller.PathAddress)10 ModelNode (org.jboss.dmr.ModelNode)10 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)9 LegacyPropertyAddOperationTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer)6 LegacyPropertyResourceTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer)6 OperationTransformer (org.jboss.as.clustering.controller.transform.OperationTransformer)5 Resource (org.jboss.as.controller.registry.Resource)4 LegacyPropertyMapGetOperationTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyMapGetOperationTransformer)3 LegacyPropertyWriteOperationTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyWriteOperationTransformer)3 ResourceTransformationContext (org.jboss.as.controller.transform.ResourceTransformationContext)3 ResourceTransformer (org.jboss.as.controller.transform.ResourceTransformer)3 TransformationContext (org.jboss.as.controller.transform.TransformationContext)3 LinkedList (java.util.LinkedList)2 ChainedOperationTransformer (org.jboss.as.clustering.controller.transform.ChainedOperationTransformer)2 OperationFailedException (org.jboss.as.controller.OperationFailedException)2 AttributeConverter (org.jboss.as.controller.transform.description.AttributeConverter)2 DefaultValueAttributeConverter (org.jboss.as.controller.transform.description.AttributeConverter.DefaultValueAttributeConverter)2 HashMap (java.util.HashMap)1 List (java.util.List)1