Search in sources :

Example 1 with SimpleAttributeConverter

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

the class RemoteTransactionResourceTransformer method accept.

@SuppressWarnings("deprecation")
@Override
public void accept(ModelVersion version) {
    if (InfinispanModel.VERSION_15_0_0.requiresTransformation(version)) {
        AttributeConverter converter = new SimpleAttributeConverter(new SimpleAttributeConverter.Converter() {

            @Override
            public void convert(PathAddress address, String name, ModelNode value, ModelNode model, TransformationContext context) {
                ModelNode parentModel = context.readResourceFromRoot(address.getParent()).getModel();
                if (parentModel.hasDefined(RemoteCacheContainerResourceDefinition.Attribute.TRANSACTION_TIMEOUT.getName())) {
                    value.set(parentModel.get(RemoteCacheContainerResourceDefinition.Attribute.TRANSACTION_TIMEOUT.getName()));
                }
            }
        });
        this.builder.getAttributeBuilder().setValueConverter(converter, RemoteTransactionResourceDefinition.Attribute.TIMEOUT.getDefinition());
    }
}
Also used : AttributeConverter(org.jboss.as.controller.transform.description.AttributeConverter) SimpleAttributeConverter(org.jboss.as.clustering.controller.transform.SimpleAttributeConverter) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) TransformationContext(org.jboss.as.controller.transform.TransformationContext) SimpleAttributeConverter(org.jboss.as.clustering.controller.transform.SimpleAttributeConverter)

Example 2 with SimpleAttributeConverter

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

Example 3 with SimpleAttributeConverter

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

SimpleAttributeConverter (org.jboss.as.clustering.controller.transform.SimpleAttributeConverter)3 PathAddress (org.jboss.as.controller.PathAddress)3 TransformationContext (org.jboss.as.controller.transform.TransformationContext)3 ModelNode (org.jboss.dmr.ModelNode)3 Converter (org.jboss.as.clustering.controller.transform.SimpleAttributeConverter.Converter)2 Set (java.util.Set)1 LegacyPropertyAddOperationTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer)1 SimpleOperationTransformer (org.jboss.as.clustering.controller.transform.SimpleOperationTransformer)1 SimpleRejectAttributeChecker (org.jboss.as.clustering.controller.transform.SimpleRejectAttributeChecker)1 Rejecter (org.jboss.as.clustering.controller.transform.SimpleRejectAttributeChecker.Rejecter)1 Resource (org.jboss.as.controller.registry.Resource)1 NoSuchResourceException (org.jboss.as.controller.registry.Resource.NoSuchResourceException)1 AttributeConverter (org.jboss.as.controller.transform.description.AttributeConverter)1 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)1