Search in sources :

Example 1 with TransformationContext

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

the class IIOPExtension method registerTransformers.

protected static void registerTransformers(final SubsystemRegistration subsystem) {
    ChainedTransformationDescriptionBuilder chained = ResourceTransformationDescriptionBuilder.Factory.createChainedSubystemInstance(CURRENT_MODEL_VERSION);
    ResourceTransformationDescriptionBuilder builder = chained.createBuilder(CURRENT_MODEL_VERSION, VERSION_1);
    builder.getAttributeBuilder().addRejectCheck(RejectAttributeChecker.DEFINED, IIOPRootDefinition.SERVER_SSL_CONTEXT).addRejectCheck(RejectAttributeChecker.DEFINED, IIOPRootDefinition.CLIENT_SSL_CONTEXT).addRejectCheck(RejectAttributeChecker.DEFINED, IIOPRootDefinition.AUTHENTICATION_CONTEXT).addRejectCheck(new RejectAttributeChecker.DefaultRejectAttributeChecker() {

        @Override
        protected boolean rejectAttribute(PathAddress pathAddress, String s, ModelNode attributeValue, TransformationContext transformationContext) {
            return attributeValue.asString().equals("true");
        }

        @Override
        public String getRejectionLogMessage(Map<String, ModelNode> map) {
            return IIOPLogger.ROOT_LOGGER.serverRequiresSslNotSupportedInPreviousVersions();
        }
    }, IIOPRootDefinition.SERVER_REQUIRES_SSL).addRejectCheck(new RejectAttributeChecker.DefaultRejectAttributeChecker() {

        @Override
        protected boolean rejectAttribute(PathAddress pathAddress, String s, ModelNode attributeValue, TransformationContext transformationContext) {
            return attributeValue.asString().equalsIgnoreCase(Constants.ELYTRON);
        }

        @Override
        public String getRejectionLogMessage(Map<String, ModelNode> map) {
            return IIOPLogger.ROOT_LOGGER.elytronInitializerNotSupportedInPreviousVersions();
        }
    }, IIOPRootDefinition.SECURITY).setValueConverter(new AttributeConverter() {

        @Override
        public void convertOperationParameter(PathAddress pathAddress, String s, ModelNode attributeValue, ModelNode operation, TransformationContext transformationContext) {
            convert(attributeValue);
        }

        @Override
        public void convertResourceAttribute(PathAddress pathAddress, String s, ModelNode attributeValue, TransformationContext transformationContext) {
            convert(attributeValue);
        }

        private void convert(ModelNode attributeValue) {
            final boolean clientRequiresSsl = attributeValue.asBoolean();
            if (clientRequiresSsl) {
                attributeValue.set(SSLConfigValue.MUTUALAUTH.toString());
            } else {
                attributeValue.set(SSLConfigValue.NONE.toString());
            }
        }
    }, IIOPRootDefinition.CLIENT_REQUIRES_SSL);
    chained.buildAndRegister(subsystem, new ModelVersion[] { VERSION_1 });
}
Also used : ChainedTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ChainedTransformationDescriptionBuilder) TransformationContext(org.jboss.as.controller.transform.TransformationContext) AttributeConverter(org.jboss.as.controller.transform.description.AttributeConverter) PathAddress(org.jboss.as.controller.PathAddress) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) ModelNode(org.jboss.dmr.ModelNode) RejectAttributeChecker(org.jboss.as.controller.transform.description.RejectAttributeChecker) Map(java.util.Map)

Example 2 with TransformationContext

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

the class XTSExtension method registerTransformers1x.

private void registerTransformers1x(SubsystemRegistration subsystem) {
    ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createSubsystemInstance();
    builder.getAttributeBuilder().setDiscard(new DiscardAttributeChecker.DefaultDiscardAttributeChecker() {

        @Override
        protected boolean isValueDiscardable(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) {
            return attributeValue.isDefined() && attributeValue.equals(XTSSubsystemDefinition.HOST_NAME.getDefaultValue());
        }
    }, XTSSubsystemDefinition.HOST_NAME).setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(new ModelNode(false)), XTSSubsystemDefinition.DEFAULT_CONTEXT_PROPAGATION).addRejectCheck(RejectAttributeChecker.DEFINED, XTSSubsystemDefinition.HOST_NAME, XTSSubsystemDefinition.DEFAULT_CONTEXT_PROPAGATION).end();
    TransformationDescription.Tools.register(builder.build(), subsystem, ModelVersion.create(1, 1, 0));
}
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)

Example 3 with TransformationContext

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

the class WeldExtension method registerTransformers.

private void registerTransformers(SubsystemRegistration subsystem) {
    ModelVersion version1_0_0 = ModelVersion.create(1, 0, 0);
    ModelVersion version3_0_0 = ModelVersion.create(3, 0, 0);
    ChainedTransformationDescriptionBuilder chainedBuilder = TransformationDescriptionBuilder.Factory.createChainedSubystemInstance(subsystem.getSubsystemVersion());
    // Differences between the current version and 3.0.0
    ResourceTransformationDescriptionBuilder builder300 = chainedBuilder.createBuilder(subsystem.getSubsystemVersion(), version3_0_0);
    builder300.getAttributeBuilder().setDiscard(DiscardAttributeChecker.UNDEFINED, WeldResourceDefinition.THREAD_POOL_SIZE_ATTRIBUTE).addRejectCheck(RejectAttributeChecker.DEFINED, WeldResourceDefinition.THREAD_POOL_SIZE_ATTRIBUTE).end();
    // Differences between 3.0.0 and 1.0.0
    ResourceTransformationDescriptionBuilder builder100 = chainedBuilder.createBuilder(version3_0_0, version1_0_0);
    builder100.getAttributeBuilder().setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(false, false, new ModelNode(true)), WeldResourceDefinition.NON_PORTABLE_MODE_ATTRIBUTE, WeldResourceDefinition.REQUIRE_BEAN_DESCRIPTOR_ATTRIBUTE).addRejectCheck(new RejectAttributeChecker.DefaultRejectAttributeChecker() {

        @Override
        public String getRejectionLogMessage(Map<String, ModelNode> attributes) {
            return WeldLogger.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");
        }
    }, WeldResourceDefinition.NON_PORTABLE_MODE_ATTRIBUTE, WeldResourceDefinition.REQUIRE_BEAN_DESCRIPTOR_ATTRIBUTE).setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(new ModelNode(false)), WeldResourceDefinition.DEVELOPMENT_MODE_ATTRIBUTE).addRejectCheck(RejectAttributeChecker.DEFINED, WeldResourceDefinition.DEVELOPMENT_MODE_ATTRIBUTE).end();
    chainedBuilder.buildAndRegister(subsystem, new ModelVersion[] { version1_0_0, version3_0_0 });
}
Also used : ChainedTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ChainedTransformationDescriptionBuilder) PathAddress(org.jboss.as.controller.PathAddress) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) ModelVersion(org.jboss.as.controller.ModelVersion) 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 4 with TransformationContext

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

the class RemoteSiteResourceDefinition method buildTransformation.

@SuppressWarnings("deprecation")
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
    ResourceTransformationDescriptionBuilder builder = parent.addChildResource(WILDCARD_PATH);
    if (JGroupsModel.VERSION_3_0_0.requiresTransformation(version)) {
        AttributeConverter converter = new AttributeConverter() {

            @Override
            public void convertOperationParameter(PathAddress address, String name, ModelNode value, ModelNode operation, TransformationContext context) {
            // Nothing to convert
            }

            @Override
            public void convertResourceAttribute(PathAddress address, String name, ModelNode value, TransformationContext context) {
                ModelNode remoteSite = context.readResourceFromRoot(address).getModel();
                String channelName = remoteSite.get(Attribute.CHANNEL.getName()).asString();
                if (DeprecatedAttribute.STACK.getName().equals(name)) {
                    PathAddress subsystemAddress = address.subAddress(0, address.size() - 3);
                    PathAddress channelAddress = subsystemAddress.append(ChannelResourceDefinition.pathElement(channelName));
                    ModelNode channel = context.readResourceFromRoot(channelAddress).getModel();
                    if (channel.hasDefined(ChannelResourceDefinition.Attribute.STACK.getName())) {
                        value.set(channel.get(ChannelResourceDefinition.Attribute.STACK.getName()).asString());
                    } else {
                        ModelNode subsystem = context.readResourceFromRoot(subsystemAddress).getModel();
                        value.set(subsystem.get(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_STACK.getName()).asString());
                    }
                } else if (DeprecatedAttribute.CLUSTER.getName().equals(name)) {
                    value.set(channelName);
                } else {
                    throw new IllegalStateException();
                }
            }
        };
        builder.getAttributeBuilder().setValueConverter(converter, DeprecatedAttribute.STACK.getDefinition(), DeprecatedAttribute.CLUSTER.getDefinition()).setDiscard(DiscardAttributeChecker.ALWAYS, Attribute.CHANNEL.getDefinition()).end();
    }
}
Also used : AttributeConverter(org.jboss.as.controller.transform.description.AttributeConverter) 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)

Example 5 with TransformationContext

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

the class AbstractProtocolResourceDefinition method addTransformations.

/**
     * Builds transformations common to both stack protocols and transport.
     */
@SuppressWarnings("deprecation")
static void addTransformations(ModelVersion version, ResourceTransformationDescriptionBuilder builder) {
    if (JGroupsModel.VERSION_3_0_0.requiresTransformation(version)) {
        AttributeConverter typeConverter = new AttributeConverter.DefaultAttributeConverter() {

            @Override
            protected void convertAttribute(PathAddress address, String name, ModelNode value, TransformationContext context) {
                if (!value.isDefined()) {
                    value.set(address.getLastElement().getValue());
                }
            }
        };
        builder.getAttributeBuilder().setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(Attribute.MODULE.getDefinition().getDefaultValue()), Attribute.MODULE.getDefinition()).addRejectCheck(RejectAttributeChecker.DEFINED, Attribute.MODULE.getDefinition()).setValueConverter(typeConverter, DeprecatedAttribute.TYPE.getDefinition()).end();
        builder.addRawOperationTransformationOverride(MapOperations.MAP_GET_DEFINITION.getName(), new SimpleOperationTransformer(new LegacyPropertyMapGetOperationTransformer()));
        for (String opName : Operations.getAllWriteAttributeOperationNames()) {
            builder.addOperationTransformationOverride(opName).inheritResourceAttributeDefinitions().setCustomOperationTransformer(new LegacyPropertyWriteOperationTransformer());
        }
    }
    PropertyResourceDefinition.buildTransformation(version, builder);
}
Also used : AttributeConverter(org.jboss.as.controller.transform.description.AttributeConverter) PathAddress(org.jboss.as.controller.PathAddress) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) LegacyPropertyMapGetOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyMapGetOperationTransformer) ModelNode(org.jboss.dmr.ModelNode) TransformationContext(org.jboss.as.controller.transform.TransformationContext) LegacyPropertyWriteOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyWriteOperationTransformer)

Aggregations

PathAddress (org.jboss.as.controller.PathAddress)19 TransformationContext (org.jboss.as.controller.transform.TransformationContext)19 ModelNode (org.jboss.dmr.ModelNode)19 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)16 DiscardAttributeChecker (org.jboss.as.controller.transform.description.DiscardAttributeChecker)12 AttributeConverter (org.jboss.as.controller.transform.description.AttributeConverter)5 Map (java.util.Map)4 SimpleAttributeConverter (org.jboss.as.clustering.controller.transform.SimpleAttributeConverter)3 SimpleOperationTransformer (org.jboss.as.clustering.controller.transform.SimpleOperationTransformer)3 ChainedTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ChainedTransformationDescriptionBuilder)3 RejectAttributeChecker (org.jboss.as.controller.transform.description.RejectAttributeChecker)3 LegacyPropertyAddOperationTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer)2 Converter (org.jboss.as.clustering.controller.transform.SimpleAttributeConverter.Converter)2 Resource (org.jboss.as.controller.registry.Resource)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