Search in sources :

Example 16 with TransformationContext

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

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

Aggregations

PathAddress (org.jboss.as.controller.PathAddress)17 TransformationContext (org.jboss.as.controller.transform.TransformationContext)17 ModelNode (org.jboss.dmr.ModelNode)17 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)15 DiscardAttributeChecker (org.jboss.as.controller.transform.description.DiscardAttributeChecker)11 Map (java.util.Map)4 AttributeConverter (org.jboss.as.controller.transform.description.AttributeConverter)4 SimpleOperationTransformer (org.jboss.as.clustering.controller.transform.SimpleOperationTransformer)3 RejectAttributeChecker (org.jboss.as.controller.transform.description.RejectAttributeChecker)3 LegacyPropertyAddOperationTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer)2 SimpleAttributeConverter (org.jboss.as.clustering.controller.transform.SimpleAttributeConverter)2 Converter (org.jboss.as.clustering.controller.transform.SimpleAttributeConverter.Converter)2 Resource (org.jboss.as.controller.registry.Resource)2 ChainedTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ChainedTransformationDescriptionBuilder)2 List (java.util.List)1 Set (java.util.Set)1 LegacyPropertyMapGetOperationTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyMapGetOperationTransformer)1 LegacyPropertyResourceTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer)1 LegacyPropertyWriteOperationTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyWriteOperationTransformer)1 SimpleRejectAttributeChecker (org.jboss.as.clustering.controller.transform.SimpleRejectAttributeChecker)1