Search in sources :

Example 96 with ResourceTransformationDescriptionBuilder

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

the class RemoteStoreResourceDefinition 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.getAttributeBuilder().setValueConverter(new AttributeConverter.DefaultAttributeConverter() {

            @Override
            protected void convertAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) {
                if (attributeValue.isDefined()) {
                    List<ModelNode> remoteServers = attributeValue.clone().asList();
                    ModelNode legacyListObject = new ModelNode();
                    for (ModelNode server : remoteServers) {
                        ModelNode legacyListItem = new ModelNode();
                        legacyListItem.get("outbound-socket-binding").set(server);
                        legacyListObject.add(legacyListItem);
                    }
                    attributeValue.set(legacyListObject);
                }
            }
        }, Attribute.SOCKET_BINDINGS.getDefinition());
    }
    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 : AttributeConverter(org.jboss.as.controller.transform.description.AttributeConverter) LegacyPropertyResourceTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer) LegacyPropertyAddOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer) PathAddress(org.jboss.as.controller.PathAddress) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) List(java.util.List) ModelNode(org.jboss.dmr.ModelNode) TransformationContext(org.jboss.as.controller.transform.TransformationContext)

Example 97 with ResourceTransformationDescriptionBuilder

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

the class ReplicatedCacheResourceDefinition method buildTransformation.

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

Example 98 with ResourceTransformationDescriptionBuilder

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

the class StringKeyedJDBCStoreResourceDefinition 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 stringTableModel = Resource.Tools.readModel(resource.removeChild(StringTableResourceDefinition.PATH));
                if (stringTableModel != null && stringTableModel.isDefined()) {
                    model.get(DeprecatedAttribute.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);
            }
        });
    }
    StringTableResourceDefinition.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)

Example 99 with ResourceTransformationDescriptionBuilder

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

the class StringTableResourceDefinition 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, StringKeyedJDBCStoreResourceDefinition.DeprecatedAttribute.TABLE, value) : Operations.createUndefineAttributeOperation(storeAddress, StringKeyedJDBCStoreResourceDefinition.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, StringKeyedJDBCStoreResourceDefinition.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 100 with ResourceTransformationDescriptionBuilder

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

the class InfinispanSubsystemResourceDefinition method buildTransformation.

static TransformationDescription buildTransformation(ModelVersion version) {
    ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createSubsystemInstance();
    CacheContainerResourceDefinition.buildTransformation(version, builder);
    return builder.build();
}
Also used : ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)

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