Search in sources :

Example 11 with SimpleOperationTransformer

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

the class JDBCStoreResourceDefinition method buildTransformation.

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder builder) {
    if (InfinispanModel.VERSION_4_2_0.requiresTransformation(version) && !InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
        // DATASOURCE attribute was only supported as an add operation parameter
        builder.getAttributeBuilder().setDiscard(DiscardAttributeChecker.ALWAYS, DeprecatedAttribute.DATASOURCE.getDefinition());
    }
    if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
        // Converts pool name to its JNDI name
        Converter converter = new Converter() {

            @Override
            public void convert(PathAddress address, String name, ModelNode value, ModelNode model, TransformationContext context) {
                if (value.isDefined()) {
                    PathAddress rootAddress = address.subAddress(0, address.size() - 4);
                    PathAddress subsystemAddress = rootAddress.append(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "datasources"));
                    Resource subsystem = context.readResourceFromRoot(subsystemAddress);
                    String poolName = value.asString();
                    for (String type : Arrays.asList("data-source", "xa-data-source")) {
                        if (subsystem.hasChildren(type)) {
                            for (Resource.ResourceEntry entry : subsystem.getChildren(type)) {
                                if (entry.getName().equals(poolName)) {
                                    value.set(entry.getModel().get("jndi-name"));
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        };
        builder.getAttributeBuilder().addRename(Attribute.DATA_SOURCE.getName(), DeprecatedAttribute.DATASOURCE.getName()).setValueConverter(new SimpleAttributeConverter(converter), Attribute.DATA_SOURCE.getDefinition());
    }
    if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) {
        builder.addOperationTransformationOverride(ModelDescriptionConstants.ADD).setCustomOperationTransformer(new SimpleOperationTransformer(new LegacyPropertyAddOperationTransformer())).inheritResourceAttributeDefinitions();
    }
    if (InfinispanModel.VERSION_2_0_0.requiresTransformation(version)) {
        builder.getAttributeBuilder().setDiscard(DiscardAttributeChecker.UNDEFINED, Attribute.DIALECT.getDefinition()).addRejectCheck(RejectAttributeChecker.DEFINED, Attribute.DIALECT.getDefinition()).end();
    }
    StoreResourceDefinition.buildTransformation(version, builder);
}
Also used : LegacyPropertyAddOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) SimpleAttributeConverter(org.jboss.as.clustering.controller.transform.SimpleAttributeConverter) Converter(org.jboss.as.clustering.controller.transform.SimpleAttributeConverter.Converter) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) ModelNode(org.jboss.dmr.ModelNode) TransformationContext(org.jboss.as.controller.transform.TransformationContext) SimpleAttributeConverter(org.jboss.as.clustering.controller.transform.SimpleAttributeConverter)

Example 12 with SimpleOperationTransformer

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

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