Search in sources :

Example 6 with TransformationContext

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

the class JcaDistributedWorkManagerDefinition method registerTransformers300.

static void registerTransformers300(ResourceTransformationDescriptionBuilder parentBuilder) {
    ResourceTransformationDescriptionBuilder builder = parentBuilder.addChildResource(PATH_DISTRIBUTED_WORK_MANAGER);
    builder.addOperationTransformationOverride("add").inheritResourceAttributeDefinitions().setCustomOperationTransformer(new OperationTransformer() {

        @Override
        public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) throws OperationFailedException {
            ModelNode copy = operation.clone();
            copy.add("transport-jgroups-cluster").set(address.getLastElement().toString());
            return new TransformedOperation(copy, TransformedOperation.ORIGINAL_RESULT);
        }
    }).end().getAttributeBuilder().setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(false, true, new ModelNode(false)), DWmParameters.ELYTRON_ENABLED.getAttribute()).addRejectCheck(RejectAttributeChecker.DEFINED, DWmParameters.ELYTRON_ENABLED.getAttribute()).end();
}
Also used : OperationTransformer(org.jboss.as.controller.transform.OperationTransformer) 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 7 with TransformationContext

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

the class XaDataSourceDefinition method registerTransformers120.

static void registerTransformers120(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 8 with TransformationContext

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

the class XaDataSourceDefinition method registerTransformers130.

static void registerTransformers130(ResourceTransformationDescriptionBuilder parentBuilder) {
    ResourceTransformationDescriptionBuilder builder = parentBuilder.addChildResource(PATH_XA_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)), Constants.ELYTRON_ENABLED, Constants.RECOVERY_ELYTRON_ENABLED).setDiscard(DiscardAttributeChecker.UNDEFINED, Constants.AUTHENTICATION_CONTEXT, RECOVERY_AUTHENTICATION_CONTEXT, CREDENTIAL_REFERENCE, RECOVERY_CREDENTIAL_REFERENCE).addRejectCheck(RejectAttributeChecker.SIMPLE_EXPRESSIONS, ENABLED).addRejectCheck(RejectAttributeChecker.DEFINED, TRACKING).addRejectCheck(RejectAttributeChecker.DEFINED, Constants.ELYTRON_ENABLED, Constants.RECOVERY_ELYTRON_ENABLED, AUTHENTICATION_CONTEXT, RECOVERY_AUTHENTICATION_CONTEXT, CREDENTIAL_REFERENCE, RECOVERY_CREDENTIAL_REFERENCE).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) TransformationContext(org.jboss.as.controller.transform.TransformationContext)

Example 9 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 10 with TransformationContext

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

the class JGroupsTransportResourceDefinition method buildTransformation.

@SuppressWarnings("deprecation")
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_3_0_0.requiresTransformation(version)) {
        // We need to reject if we cannot determine the underlying stack via the jgroups subsystem
        Rejecter stackRejecter = new Rejecter() {

            @Override
            public boolean reject(PathAddress address, String name, ModelNode value, ModelNode model, TransformationContext context) {
                if (value.isDefined())
                    return false;
                PathAddress rootAddress = address.subAddress(0, address.size() - 3);
                PathAddress subsystemAddress = rootAddress.append(JGroupsSubsystemResourceDefinition.PATH);
                ModelNode subsystemModel = context.readResourceFromRoot(subsystemAddress).getModel();
                String channelName = null;
                if (model.hasDefined(Attribute.CHANNEL.getName())) {
                    ModelNode channel = model.get(Attribute.CHANNEL.getName());
                    if (channel.getType() == ModelType.STRING) {
                        channelName = channel.asString();
                    }
                } else if (subsystemModel.hasDefined(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_CHANNEL.getName())) {
                    ModelNode defaultChannel = subsystemModel.get(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_CHANNEL.getName());
                    if (defaultChannel.getType() == ModelType.STRING) {
                        channelName = defaultChannel.asString();
                    }
                }
                if (channelName == null)
                    return true;
                String stackName = null;
                PathAddress channelAddress = subsystemAddress.append(ChannelResourceDefinition.pathElement(channelName));
                try {
                    ModelNode channel = context.readResourceFromRoot(channelAddress).getModel();
                    if (channel.hasDefined(ChannelResourceDefinition.Attribute.STACK.getName())) {
                        ModelNode stack = channel.get(ChannelResourceDefinition.Attribute.STACK.getName());
                        if (stack.getType() == ModelType.STRING) {
                            stackName = stack.asString();
                        }
                    } else if (subsystemModel.hasDefined(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_STACK.getName())) {
                        ModelNode defaultStack = subsystemModel.get(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_STACK.getName());
                        if (defaultStack.getType() == ModelType.STRING) {
                            stackName = defaultStack.asString();
                        }
                    }
                } catch (NoSuchResourceException e) {
                // Ignore
                }
                return (stackName == null);
            }

            @Override
            public String getRejectedMessage(Set<String> attributes) {
                return InfinispanLogger.ROOT_LOGGER.indeterminiteStack();
            }
        };
        // Lookup the stack via the jgroups channel resource, if necessary
        Converter stackConverter = 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() - 3);
                    PathAddress subsystemAddress = rootAddress.append(JGroupsSubsystemResourceDefinition.PATH);
                    ModelNode subsystemModel = context.readResourceFromRoot(subsystemAddress).getModel();
                    String channelName = null;
                    if (model.hasDefined(Attribute.CHANNEL.getName())) {
                        ModelNode channel = model.get(Attribute.CHANNEL.getName());
                        if (channel.getType() == ModelType.STRING) {
                            channelName = channel.asString();
                        }
                    } else if (subsystemModel.hasDefined(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_CHANNEL.getName())) {
                        ModelNode defaultChannel = subsystemModel.get(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_CHANNEL.getName());
                        if (defaultChannel.getType() == ModelType.STRING) {
                            channelName = defaultChannel.asString();
                        }
                    }
                    if (channelName != null) {
                        PathAddress channelAddress = subsystemAddress.append(ChannelResourceDefinition.pathElement(channelName));
                        try {
                            ModelNode channel = context.readResourceFromRoot(channelAddress).getModel();
                            if (channel.hasDefined(ChannelResourceDefinition.Attribute.STACK.getName())) {
                                ModelNode stack = channel.get(ChannelResourceDefinition.Attribute.STACK.getName());
                                if (stack.getType() == ModelType.STRING) {
                                    value.set(stack.asString());
                                }
                            } else if (subsystemModel.hasDefined(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_STACK.getName())) {
                                ModelNode defaultStack = subsystemModel.get(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_STACK.getName());
                                if (defaultStack.getType() == ModelType.STRING) {
                                    value.set(defaultStack.asString());
                                }
                            }
                        } catch (NoSuchResourceException e) {
                        // Ignore
                        }
                    }
                }
            }
        };
        builder.getAttributeBuilder().addRejectCheck(new SimpleRejectAttributeChecker(stackRejecter), DeprecatedAttribute.STACK.getDefinition()).setValueConverter(new SimpleAttributeConverter(stackConverter), DeprecatedAttribute.STACK.getDefinition()).addRename(Attribute.CHANNEL.getDefinition(), DeprecatedAttribute.CLUSTER.getDefinition().getName()).end();
    }
}
Also used : NoSuchResourceException(org.jboss.as.controller.registry.Resource.NoSuchResourceException) Set(java.util.Set) SimpleRejectAttributeChecker(org.jboss.as.clustering.controller.transform.SimpleRejectAttributeChecker) PathAddress(org.jboss.as.controller.PathAddress) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) Rejecter(org.jboss.as.clustering.controller.transform.SimpleRejectAttributeChecker.Rejecter) SimpleAttributeConverter(org.jboss.as.clustering.controller.transform.SimpleAttributeConverter) Converter(org.jboss.as.clustering.controller.transform.SimpleAttributeConverter.Converter) 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