Search in sources :

Example 81 with ResourceTransformationDescriptionBuilder

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

the class NamingExtension method registerTransformers.

private void registerTransformers(SubsystemRegistration subsystem) {
    final ModelVersion v2_0_0 = ModelVersion.create(2, 0, 0);
    ChainedTransformationDescriptionBuilder chainedBuilder = TransformationDescriptionBuilder.Factory.createChainedSubystemInstance(subsystem.getSubsystemVersion());
    ResourceTransformationDescriptionBuilder builder_2_0 = chainedBuilder.createBuilder(subsystem.getSubsystemVersion(), v2_0_0);
    NamingBindingResourceDefinition.INSTANCE.registerTransformers_2_0(builder_2_0);
    chainedBuilder.buildAndRegister(subsystem, new ModelVersion[] { v2_0_0 });
}
Also used : ChainedTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ChainedTransformationDescriptionBuilder) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) ModelVersion(org.jboss.as.controller.ModelVersion)

Example 82 with ResourceTransformationDescriptionBuilder

use of org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder 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 83 with ResourceTransformationDescriptionBuilder

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

the class LocalCacheResourceDefinition method buildTransformation.

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
    ResourceTransformationDescriptionBuilder builder = parent.addChildResource(WILDCARD_PATH);
    CacheResourceDefinition.buildTransformation(version, builder);
}
Also used : ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)

Example 84 with ResourceTransformationDescriptionBuilder

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

the class MixedKeyedJDBCStoreResourceDefinition 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);
    BinaryTableResourceDefinition.buildTransformation(version, builder);
    StringTableResourceDefinition.buildTransformation(version, builder);
    JDBCStoreResourceDefinition.buildTransformation(version, builder);
    if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
        builder.setCustomResourceTransformer(new ResourceTransformer() {

            @Override
            public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
                final ModelNode model = resource.getModel();
                final ModelNode binaryTableModel = Resource.Tools.readModel(resource.removeChild(BinaryTableResourceDefinition.PATH));
                if (binaryTableModel != null && binaryTableModel.isDefined()) {
                    model.get(DeprecatedAttribute.BINARY_TABLE.getName()).set(binaryTableModel);
                }
                final ModelNode stringTableModel = Resource.Tools.readModel(resource.removeChild(StringTableResourceDefinition.PATH));
                if (stringTableModel != null && stringTableModel.isDefined()) {
                    model.get(DeprecatedAttribute.STRING_TABLE.getName()).set(stringTableModel);
                }
                final ModelNode properties = model.remove(StoreResourceDefinition.Attribute.PROPERTIES.getName());
                final ResourceTransformationContext childContext = context.addTransformedResource(PathAddress.EMPTY_ADDRESS, resource);
                LegacyPropertyResourceTransformer.transformPropertiesToChildrenResources(properties, address, childContext);
                context.processChildren(resource);
            }
        });
    }
    if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) {
        builder.addRawOperationTransformationOverride(MapOperations.MAP_GET_DEFINITION.getName(), new SimpleOperationTransformer(new LegacyPropertyMapGetOperationTransformer()));
        for (String opName : Operations.getAllWriteAttributeOperationNames()) {
            builder.addOperationTransformationOverride(opName).inheritResourceAttributeDefinitions().setCustomOperationTransformer(new LegacyPropertyWriteOperationTransformer());
        }
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) LegacyPropertyMapGetOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyMapGetOperationTransformer) LegacyPropertyResourceTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer) ResourceTransformer(org.jboss.as.controller.transform.ResourceTransformer) ModelNode(org.jboss.dmr.ModelNode) ResourceTransformationContext(org.jboss.as.controller.transform.ResourceTransformationContext) LegacyPropertyWriteOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyWriteOperationTransformer)

Example 85 with ResourceTransformationDescriptionBuilder

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

Aggregations

ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)93 ModelNode (org.jboss.dmr.ModelNode)46 PathAddress (org.jboss.as.controller.PathAddress)25 DiscardAttributeChecker (org.jboss.as.controller.transform.description.DiscardAttributeChecker)24 TransformationContext (org.jboss.as.controller.transform.TransformationContext)15 SimpleOperationTransformer (org.jboss.as.clustering.controller.transform.SimpleOperationTransformer)9 LegacyPropertyResourceTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer)7 ModelVersion (org.jboss.as.controller.ModelVersion)7 Resource (org.jboss.as.controller.registry.Resource)7 ChainedTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ChainedTransformationDescriptionBuilder)7 ResourceTransformationContext (org.jboss.as.controller.transform.ResourceTransformationContext)6 ResourceTransformer (org.jboss.as.controller.transform.ResourceTransformer)6 AttributeConverter (org.jboss.as.controller.transform.description.AttributeConverter)6 Map (java.util.Map)4 LegacyPropertyAddOperationTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer)4 OperationTransformer (org.jboss.as.clustering.controller.transform.OperationTransformer)4 OperationFailedException (org.jboss.as.controller.OperationFailedException)4 PathElement (org.jboss.as.controller.PathElement)4 RejectAttributeChecker (org.jboss.as.controller.transform.description.RejectAttributeChecker)4 LinkedList (java.util.LinkedList)2