Search in sources :

Example 6 with ResourceTransformer

use of org.jboss.as.controller.transform.ResourceTransformer 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)

Example 7 with ResourceTransformer

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

the class BinaryKeyedJDBCStoreResourceDefinition 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_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.TABLE.getName()).set(binaryTableModel);
                }
                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);
            }
        });
    }
    BinaryTableResourceDefinition.buildTransformation(version, builder);
    JDBCStoreResourceDefinition.buildTransformation(version, builder);
}
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) 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)

Aggregations

PathAddress (org.jboss.as.controller.PathAddress)7 Resource (org.jboss.as.controller.registry.Resource)7 ResourceTransformationContext (org.jboss.as.controller.transform.ResourceTransformationContext)7 ResourceTransformer (org.jboss.as.controller.transform.ResourceTransformer)7 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)6 ModelNode (org.jboss.dmr.ModelNode)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