Search in sources :

Example 11 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 12 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)

Example 13 with TransformationContext

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

the class ChannelResourceDefinition method buildTransformation.

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
    if (JGroupsModel.VERSION_3_0_0.requiresTransformation(version)) {
        DynamicDiscardPolicy channelDiscardRejectPolicy = new DynamicDiscardPolicy() {

            @Override
            public DiscardPolicy checkResource(TransformationContext context, PathAddress address) {
                // Check whether all channel resources are used by the infinispan subsystem, and transformed
                // by its corresponding transformers; reject otherwise
                // n.b. we need to hard-code the values because otherwise we would end up with cyclical dependency
                String channelName = address.getLastElement().getValue();
                PathAddress rootAddress = address.subAddress(0, address.size() - 2);
                PathAddress subsystemAddress = rootAddress.append(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "infinispan"));
                Resource infinispanResource;
                try {
                    infinispanResource = context.readResourceFromRoot(subsystemAddress);
                } catch (Resource.NoSuchResourceException ex) {
                    return DiscardPolicy.REJECT_AND_WARN;
                }
                ModelNode infinispanModel = Resource.Tools.readModel(infinispanResource);
                if (infinispanModel.hasDefined("cache-container")) {
                    for (ModelNode container : infinispanModel.get("cache-container").asList()) {
                        ModelNode cacheContainer = container.get(0);
                        if (cacheContainer.hasDefined("transport")) {
                            ModelNode transport = cacheContainer.get("transport").get("jgroups");
                            if (transport.hasDefined("channel")) {
                                String channel = transport.get("channel").asString();
                                if (channel.equals(channelName)) {
                                    return DiscardPolicy.SILENT;
                                }
                            } else {
                                // In that case, if this were the default channel, it can be discarded too
                                ModelNode subsystem = context.readResourceFromRoot(address.subAddress(0, address.size() - 1)).getModel();
                                if (subsystem.hasDefined(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_CHANNEL.getName())) {
                                    if (subsystem.get(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_CHANNEL.getName()).asString().equals(channelName)) {
                                        return DiscardPolicy.SILENT;
                                    }
                                }
                            }
                        }
                    }
                }
                // No references to this channel, we need to reject it.
                return DiscardPolicy.REJECT_AND_WARN;
            }
        };
        parent.addChildResource(WILDCARD_PATH, channelDiscardRejectPolicy);
    } else {
        ResourceTransformationDescriptionBuilder builder = parent.addChildResource(WILDCARD_PATH);
        if (JGroupsModel.VERSION_4_0_0.requiresTransformation(version)) {
            DiscardAttributeChecker discarder = new DefaultDiscardAttributeChecker(false, true) {

                @Override
                protected boolean isValueDiscardable(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) {
                    return !attributeValue.isDefined() || attributeValue.equals(new ModelNode(address.getLastElement().getValue()));
                }
            };
            builder.getAttributeBuilder().setDiscard(discarder, Attribute.CLUSTER.getDefinition()).addRejectCheck(RejectAttributeChecker.DEFINED, Attribute.CLUSTER.getDefinition());
        }
        ProtocolRegistration.buildTransformation(version, builder);
    }
}
Also used : DefaultDiscardAttributeChecker(org.jboss.as.controller.transform.description.DiscardAttributeChecker.DefaultDiscardAttributeChecker) DynamicDiscardPolicy(org.jboss.as.controller.transform.description.DynamicDiscardPolicy) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) ModelNode(org.jboss.dmr.ModelNode) TransformationContext(org.jboss.as.controller.transform.TransformationContext) DiscardAttributeChecker(org.jboss.as.controller.transform.description.DiscardAttributeChecker) DefaultDiscardAttributeChecker(org.jboss.as.controller.transform.description.DiscardAttributeChecker.DefaultDiscardAttributeChecker)

Example 14 with TransformationContext

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

the class XaDataSourceDefinition method registerTransformers200.

static void registerTransformers200(ResourceTransformationDescriptionBuilder parentBuilder) {
    ResourceTransformationDescriptionBuilder builder = parentBuilder.addChildResource(PATH_XA_DATASOURCE);
    builder.getAttributeBuilder().setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(new ModelNode(false)), CONNECTABLE).setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(false, false, new ModelNode(true)), STATISTICS_ENABLED).setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(new ModelNode(true)), ENLISTMENT_TRACE).setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(new ModelNode(LEGACY_MCP)), MCP).setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(false, true, new ModelNode(false)), Constants.ELYTRON_ENABLED, Constants.RECOVERY_ELYTRON_ENABLED).setDiscard(DiscardAttributeChecker.UNDEFINED, Constants.AUTHENTICATION_CONTEXT, RECOVERY_AUTHENTICATION_CONTEXT, CREDENTIAL_REFERENCE, RECOVERY_CREDENTIAL_REFERENCE).addRejectCheck(RejectAttributeChecker.DEFINED, ENLISTMENT_TRACE).addRejectCheck(RejectAttributeChecker.DEFINED, MCP).addRejectCheck(new RejectAttributeChecker.DefaultRejectAttributeChecker() {

        @Override
        public String getRejectionLogMessage(Map<String, ModelNode> attributes) {
            return ConnectorLogger.ROOT_LOGGER.rejectAttributesMustBeTrue(attributes.keySet());
        }

        @Override
        protected boolean rejectAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) {
            //This will not get called if it was discarded, so reject if it is undefined (default==false) or if defined and != 'true'
            return !attributeValue.isDefined() || !attributeValue.asString().equals("true");
        }
    }, STATISTICS_ENABLED).setDiscard(DiscardAttributeChecker.UNDEFINED, TRACKING).addRejectCheck(RejectAttributeChecker.DEFINED, TRACKING).addRejectCheck(RejectAttributeChecker.SIMPLE_EXPRESSIONS, ENABLED).addRejectCheck(RejectAttributeChecker.DEFINED, Constants.ELYTRON_ENABLED, Constants.RECOVERY_ELYTRON_ENABLED, AUTHENTICATION_CONTEXT, RECOVERY_AUTHENTICATION_CONTEXT, CREDENTIAL_REFERENCE, RECOVERY_CREDENTIAL_REFERENCE).end().addOperationTransformationOverride(DATASOURCE_ENABLE.getName()).end().addOperationTransformationOverride(DATASOURCE_DISABLE.getName()).end();
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) ModelNode(org.jboss.dmr.ModelNode) DiscardAttributeChecker(org.jboss.as.controller.transform.description.DiscardAttributeChecker) Map(java.util.Map) TransformationContext(org.jboss.as.controller.transform.TransformationContext)

Example 15 with TransformationContext

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

the class DataSourceDefinition method registerTransformers130.

static void registerTransformers130(ResourceTransformationDescriptionBuilder parentBuilder) {
    ResourceTransformationDescriptionBuilder builder = parentBuilder.addChildResource(PATH_DATASOURCE);
    builder.getAttributeBuilder().setDiscard(new DiscardAttributeChecker.DefaultDiscardAttributeChecker() {

        @Override
        protected boolean isValueDiscardable(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) {
            return attributeValue.equals(new ModelNode(false));
        }
    }, TRACKING).setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(false, true, new ModelNode(false)), ELYTRON_ENABLED, RECOVERY_ELYTRON_ENABLED).setDiscard(DiscardAttributeChecker.UNDEFINED, AUTHENTICATION_CONTEXT, RECOVERY_AUTHENTICATION_CONTEXT, CREDENTIAL_REFERENCE).addRejectCheck(RejectAttributeChecker.SIMPLE_EXPRESSIONS, ENABLED).addRejectCheck(RejectAttributeChecker.DEFINED, TRACKING).addRejectCheck(RejectAttributeChecker.DEFINED, ELYTRON_ENABLED, RECOVERY_ELYTRON_ENABLED, AUTHENTICATION_CONTEXT, RECOVERY_AUTHENTICATION_CONTEXT, CREDENTIAL_REFERENCE).addRejectCheck(createConnURLRejectChecker(), CONNECTION_URL).end();
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) ModelNode(org.jboss.dmr.ModelNode) TransformationContext(org.jboss.as.controller.transform.TransformationContext) DiscardAttributeChecker(org.jboss.as.controller.transform.description.DiscardAttributeChecker)

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