Search in sources :

Example 1 with ResourceTransformationContext

use of org.jboss.as.controller.transform.ResourceTransformationContext 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 2 with ResourceTransformationContext

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

the class TransportResourceDefinition method buildTransformation.

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
    ResourceTransformationDescriptionBuilder builder = parent.addChildResource(WILDCARD_PATH);
    AbstractProtocolResourceDefinition.addTransformations(version, builder);
    if (JGroupsModel.VERSION_3_0_0.requiresTransformation(version)) {
        builder.getAttributeBuilder().setValueConverter(new DefaultValueAttributeConverter(Attribute.SHARED.getDefinition()), Attribute.SHARED.getDefinition());
        builder.setCustomResourceTransformer(new ResourceTransformer() {

            @Override
            public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
                new LegacyPropertyResourceTransformer().transformResource(context, LEGACY_ADDRESS_TRANSFORMER.transform(address), resource);
            }
        });
        builder.addOperationTransformationOverride(ModelDescriptionConstants.ADD).setCustomOperationTransformer(new SimpleOperationTransformer(new org.jboss.as.clustering.controller.transform.OperationTransformer() {

            @Override
            public ModelNode transformOperation(final ModelNode operation) {
                operation.get(ModelDescriptionConstants.OP_ADDR).set(LEGACY_ADDRESS_TRANSFORMER.transform(Operations.getPathAddress(operation)).toModelNode());
                return new LegacyPropertyAddOperationTransformer().transformOperation(operation);
            }
        })).inheritResourceAttributeDefinitions();
        builder.addOperationTransformationOverride(ModelDescriptionConstants.REMOVE).setCustomOperationTransformer(new SimpleRemoveOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
        builder.addOperationTransformationOverride(ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION).setCustomOperationTransformer(new SimpleReadAttributeOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
        builder.addOperationTransformationOverride(ModelDescriptionConstants.DESCRIBE).setCustomOperationTransformer(new SimpleDescribeOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
        List<OperationTransformer> getOpTransformerChain = new LinkedList<>();
        getOpTransformerChain.add(new SimplePathOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
        getOpTransformerChain.add(new SimpleOperationTransformer(new LegacyPropertyMapGetOperationTransformer()));
        ChainedOperationTransformer getOpChainedTransformer = new ChainedOperationTransformer(getOpTransformerChain, false);
        builder.addRawOperationTransformationOverride(MapOperations.MAP_GET_DEFINITION.getName(), getOpChainedTransformer);
        List<OperationTransformer> writeOpTransformerChain = new LinkedList<>();
        writeOpTransformerChain.add(new SimplePathOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
        writeOpTransformerChain.add(new LegacyPropertyWriteOperationTransformer());
        ChainedOperationTransformer writeOpChainedTransformer = new ChainedOperationTransformer(writeOpTransformerChain, false);
        for (String opName : Operations.getAllWriteAttributeOperationNames()) {
            builder.addOperationTransformationOverride(opName).inheritResourceAttributeDefinitions().setCustomOperationTransformer(writeOpChainedTransformer);
        }
        // Reject thread pool configuration, discard if undefined, support EAP 6.x slaves using deprecated attributes
        builder.addChildResource(ThreadPoolResourceDefinition.WILDCARD_PATH, RequiredChildResourceDiscardPolicy.REJECT_AND_WARN);
    } else {
        EnumSet.allOf(ThreadPoolResourceDefinition.class).forEach(p -> p.buildTransformation(version, parent));
    }
}
Also used : SimpleRemoveOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleRemoveOperationTransformer) LegacyPropertyMapGetOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyMapGetOperationTransformer) LegacyPropertyWriteOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyWriteOperationTransformer) LegacyPropertyResourceTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer) LegacyPropertyAddOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer) SimpleReadAttributeOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleReadAttributeOperationTransformer) SimplePathOperationTransformer(org.jboss.as.clustering.controller.transform.SimplePathOperationTransformer) OperationTransformer(org.jboss.as.controller.transform.OperationTransformer) SimpleDescribeOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleDescribeOperationTransformer) LegacyPropertyAddOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer) ChainedOperationTransformer(org.jboss.as.clustering.controller.transform.ChainedOperationTransformer) LegacyPropertyWriteOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyWriteOperationTransformer) SimpleRemoveOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleRemoveOperationTransformer) LegacyPropertyMapGetOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyMapGetOperationTransformer) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) SimplePathOperationTransformer(org.jboss.as.clustering.controller.transform.SimplePathOperationTransformer) SimpleReadAttributeOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleReadAttributeOperationTransformer) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) SimpleDescribeOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleDescribeOperationTransformer) ResourceTransformationContext(org.jboss.as.controller.transform.ResourceTransformationContext) LinkedList(java.util.LinkedList) ChainedOperationTransformer(org.jboss.as.clustering.controller.transform.ChainedOperationTransformer) PathAddress(org.jboss.as.controller.PathAddress) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) DefaultValueAttributeConverter(org.jboss.as.controller.transform.description.AttributeConverter.DefaultValueAttributeConverter) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) ResourceTransformer(org.jboss.as.controller.transform.ResourceTransformer) LegacyPropertyResourceTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer) ModelNode(org.jboss.dmr.ModelNode)

Example 3 with ResourceTransformationContext

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

the class StackResourceDefinition method buildTransformation.

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
    ResourceTransformationDescriptionBuilder builder = parent.addChildResource(WILDCARD_PATH);
    if (JGroupsModel.VERSION_3_0_0.requiresTransformation(version)) {
        // Create legacy "protocols" attributes, which lists protocols by name
        ResourceTransformer transformer = new ResourceTransformer() {

            @Override
            public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
                for (String name : resource.getChildrenNames(ProtocolResourceDefinition.WILDCARD_PATH.getKey())) {
                    resource.getModel().get(PROTOCOLS.getName()).add(name);
                }
                context.addTransformedResource(PathAddress.EMPTY_ADDRESS, resource).processChildren(resource);
            }
        };
        builder.setCustomResourceTransformer(transformer);
    }
    if (JGroupsModel.VERSION_2_0_0.requiresTransformation(version)) {
        builder.rejectChildResource(RelayResourceDefinition.PATH);
    } else {
        RelayResourceDefinition.buildTransformation(version, builder);
    }
    TransportResourceDefinition.buildTransformation(version, builder);
    ProtocolRegistration.buildTransformation(version, builder);
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) ResourceTransformer(org.jboss.as.controller.transform.ResourceTransformer) ResourceTransformationContext(org.jboss.as.controller.transform.ResourceTransformationContext)

Example 4 with ResourceTransformationContext

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

the class LegacyPropertyResourceTransformer method transformResource.

@Override
public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
    final ModelNode model = resource.getModel();
    final ModelNode properties = model.remove(PROPERTIES);
    final ResourceTransformationContext parentContext = context.addTransformedResourceFromRoot(address, resource);
    transformPropertiesToChildrenResources(properties, address, parentContext);
    context.processChildren(resource);
}
Also used : ModelNode(org.jboss.dmr.ModelNode) ResourceTransformationContext(org.jboss.as.controller.transform.ResourceTransformationContext)

Example 5 with ResourceTransformationContext

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

the class CacheResourceDefinition method buildTransformation.

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder builder) {
    if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
        builder.discardChildResource(NoStoreResourceDefinition.PATH);
    } else {
        NoStoreResourceDefinition.buildTransformation(version, builder);
    }
    if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) {
        // Set batching=true if transaction mode=BATCH
        ResourceTransformer batchingTransformer = new ResourceTransformer() {

            @Override
            public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
                PathAddress transactionAddress = address.append(TransactionResourceDefinition.PATH);
                try {
                    ModelNode transaction = context.readResourceFromRoot(transactionAddress).getModel();
                    if (transaction.hasDefined(TransactionResourceDefinition.Attribute.MODE.getName())) {
                        ModelNode mode = transaction.get(TransactionResourceDefinition.Attribute.MODE.getName());
                        if ((mode.getType() == ModelType.STRING) && (TransactionMode.valueOf(mode.asString()) == TransactionMode.BATCH)) {
                            resource.getModel().get(DeprecatedAttribute.BATCHING.getName()).set(true);
                        }
                    }
                } catch (NoSuchElementException e) {
                // Ignore, nothing to convert
                }
                context.addTransformedResource(PathAddress.EMPTY_ADDRESS, resource).processChildren(resource);
            }
        };
        builder.setCustomResourceTransformer(batchingTransformer);
    }
    if (InfinispanModel.VERSION_1_5_0.requiresTransformation(version)) {
        builder.getAttributeBuilder().setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(false, false, new ModelNode(true)), Attribute.STATISTICS_ENABLED.getDefinition()).addRejectCheck(RejectAttributeChecker.UNDEFINED, Attribute.STATISTICS_ENABLED.getDefinition()).addRejectCheck(RejectAttributeChecker.SIMPLE_EXPRESSIONS, Attribute.STATISTICS_ENABLED.getDefinition()).addRejectCheck(new RejectAttributeChecker.SimpleRejectAttributeChecker(new ModelNode(false)), Attribute.STATISTICS_ENABLED.getDefinition());
    }
    LockingResourceDefinition.buildTransformation(version, builder);
    EvictionResourceDefinition.buildTransformation(version, builder);
    ExpirationResourceDefinition.buildTransformation(version, builder);
    TransactionResourceDefinition.buildTransformation(version, builder);
    FileStoreResourceDefinition.buildTransformation(version, builder);
    BinaryKeyedJDBCStoreResourceDefinition.buildTransformation(version, builder);
    MixedKeyedJDBCStoreResourceDefinition.buildTransformation(version, builder);
    StringKeyedJDBCStoreResourceDefinition.buildTransformation(version, builder);
    RemoteStoreResourceDefinition.buildTransformation(version, builder);
    CustomStoreResourceDefinition.buildTransformation(version, builder);
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) ResourceTransformer(org.jboss.as.controller.transform.ResourceTransformer) ModelNode(org.jboss.dmr.ModelNode) ResourceTransformationContext(org.jboss.as.controller.transform.ResourceTransformationContext) RejectAttributeChecker(org.jboss.as.controller.transform.description.RejectAttributeChecker) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

ResourceTransformationContext (org.jboss.as.controller.transform.ResourceTransformationContext)8 PathAddress (org.jboss.as.controller.PathAddress)7 Resource (org.jboss.as.controller.registry.Resource)7 ResourceTransformer (org.jboss.as.controller.transform.ResourceTransformer)7 ModelNode (org.jboss.dmr.ModelNode)7 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)6 LegacyPropertyResourceTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer)4 OperationFailedException (org.jboss.as.controller.OperationFailedException)4 SimpleOperationTransformer (org.jboss.as.clustering.controller.transform.SimpleOperationTransformer)3 LinkedList (java.util.LinkedList)2 ChainedOperationTransformer (org.jboss.as.clustering.controller.transform.ChainedOperationTransformer)2 LegacyPropertyMapGetOperationTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyMapGetOperationTransformer)2 LegacyPropertyWriteOperationTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyWriteOperationTransformer)2 DefaultValueAttributeConverter (org.jboss.as.controller.transform.description.AttributeConverter.DefaultValueAttributeConverter)2 HashMap (java.util.HashMap)1 NoSuchElementException (java.util.NoSuchElementException)1 AttributeOperationTransformer (org.jboss.as.clustering.controller.transform.AttributeOperationTransformer)1 LegacyPropertyAddOperationTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer)1 OperationTransformer (org.jboss.as.clustering.controller.transform.OperationTransformer)1 SimpleDescribeOperationTransformer (org.jboss.as.clustering.controller.transform.SimpleDescribeOperationTransformer)1