Search in sources :

Example 56 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class MessagingXmlInstallDeploymentUnitProcessor method createDeploymentSubModel.

static ManagementResourceRegistration createDeploymentSubModel(final PathAddress address, final DeploymentUnit unit) {
    final Resource root = unit.getAttachment(DeploymentModelUtils.DEPLOYMENT_RESOURCE);
    synchronized (root) {
        final ManagementResourceRegistration registration = unit.getAttachment(DeploymentModelUtils.MUTABLE_REGISTRATION_ATTACHMENT);
        final PathAddress subsystemAddress = PathAddress.pathAddress(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, MessagingExtension.SUBSYSTEM_NAME));
        final Resource subsystem = getOrCreate(root, subsystemAddress);
        Set<String> childTypes = subsystem.getChildTypes();
        final ManagementResourceRegistration subModel = registration.getSubModel(subsystemAddress.append(address));
        if (subModel == null) {
            throw new IllegalStateException(address.toString());
        }
        getOrCreate(subsystem, address);
        return subModel;
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration)

Example 57 with Resource

use of org.jboss.as.controller.registry.Resource 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 58 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class TransportResourceDefinition method buildTransformation.

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
    ResourceTransformationDescriptionBuilder builder = parent.addChildResource(WILDCARD_PATH);
    AbstractProtocolResourceDefinition.addTransformations(version, builder);
    if (JGroupsModel.VERSION_3_0_0.requiresTransformation(version)) {
        builder.getAttributeBuilder().setValueConverter(new DefaultValueAttributeConverter(Attribute.SHARED.getDefinition()), Attribute.SHARED.getDefinition());
        builder.setCustomResourceTransformer(new ResourceTransformer() {

            @Override
            public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
                new LegacyPropertyResourceTransformer().transformResource(context, LEGACY_ADDRESS_TRANSFORMER.transform(address), resource);
            }
        });
        builder.addOperationTransformationOverride(ModelDescriptionConstants.ADD).setCustomOperationTransformer(new SimpleOperationTransformer(new org.jboss.as.clustering.controller.transform.OperationTransformer() {

            @Override
            public ModelNode transformOperation(final ModelNode operation) {
                operation.get(ModelDescriptionConstants.OP_ADDR).set(LEGACY_ADDRESS_TRANSFORMER.transform(Operations.getPathAddress(operation)).toModelNode());
                return new LegacyPropertyAddOperationTransformer().transformOperation(operation);
            }
        })).inheritResourceAttributeDefinitions();
        builder.addOperationTransformationOverride(ModelDescriptionConstants.REMOVE).setCustomOperationTransformer(new SimpleRemoveOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
        builder.addOperationTransformationOverride(ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION).setCustomOperationTransformer(new SimpleReadAttributeOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
        builder.addOperationTransformationOverride(ModelDescriptionConstants.DESCRIBE).setCustomOperationTransformer(new SimpleDescribeOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
        List<OperationTransformer> getOpTransformerChain = new LinkedList<>();
        getOpTransformerChain.add(new SimplePathOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
        getOpTransformerChain.add(new SimpleOperationTransformer(new LegacyPropertyMapGetOperationTransformer()));
        ChainedOperationTransformer getOpChainedTransformer = new ChainedOperationTransformer(getOpTransformerChain, false);
        builder.addRawOperationTransformationOverride(MapOperations.MAP_GET_DEFINITION.getName(), getOpChainedTransformer);
        List<OperationTransformer> writeOpTransformerChain = new LinkedList<>();
        writeOpTransformerChain.add(new SimplePathOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
        writeOpTransformerChain.add(new LegacyPropertyWriteOperationTransformer());
        ChainedOperationTransformer writeOpChainedTransformer = new ChainedOperationTransformer(writeOpTransformerChain, false);
        for (String opName : Operations.getAllWriteAttributeOperationNames()) {
            builder.addOperationTransformationOverride(opName).inheritResourceAttributeDefinitions().setCustomOperationTransformer(writeOpChainedTransformer);
        }
        // Reject thread pool configuration, discard if undefined, support EAP 6.x slaves using deprecated attributes
        builder.addChildResource(ThreadPoolResourceDefinition.WILDCARD_PATH, RequiredChildResourceDiscardPolicy.REJECT_AND_WARN);
    } else {
        EnumSet.allOf(ThreadPoolResourceDefinition.class).forEach(p -> p.buildTransformation(version, parent));
    }
}
Also used : SimpleRemoveOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleRemoveOperationTransformer) LegacyPropertyMapGetOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyMapGetOperationTransformer) LegacyPropertyWriteOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyWriteOperationTransformer) LegacyPropertyResourceTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer) LegacyPropertyAddOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer) SimpleReadAttributeOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleReadAttributeOperationTransformer) SimplePathOperationTransformer(org.jboss.as.clustering.controller.transform.SimplePathOperationTransformer) OperationTransformer(org.jboss.as.controller.transform.OperationTransformer) SimpleDescribeOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleDescribeOperationTransformer) LegacyPropertyAddOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer) ChainedOperationTransformer(org.jboss.as.clustering.controller.transform.ChainedOperationTransformer) LegacyPropertyWriteOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyWriteOperationTransformer) SimpleRemoveOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleRemoveOperationTransformer) LegacyPropertyMapGetOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyMapGetOperationTransformer) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) SimplePathOperationTransformer(org.jboss.as.clustering.controller.transform.SimplePathOperationTransformer) SimpleReadAttributeOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleReadAttributeOperationTransformer) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) SimpleDescribeOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleDescribeOperationTransformer) ResourceTransformationContext(org.jboss.as.controller.transform.ResourceTransformationContext) LinkedList(java.util.LinkedList) ChainedOperationTransformer(org.jboss.as.clustering.controller.transform.ChainedOperationTransformer) PathAddress(org.jboss.as.controller.PathAddress) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) DefaultValueAttributeConverter(org.jboss.as.controller.transform.description.AttributeConverter.DefaultValueAttributeConverter) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) ResourceTransformer(org.jboss.as.controller.transform.ResourceTransformer) LegacyPropertyResourceTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer) ModelNode(org.jboss.dmr.ModelNode)

Example 59 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class StackResourceDefinition method buildTransformation.

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
    ResourceTransformationDescriptionBuilder builder = parent.addChildResource(WILDCARD_PATH);
    if (JGroupsModel.VERSION_3_0_0.requiresTransformation(version)) {
        // Create legacy "protocols" attributes, which lists protocols by name
        ResourceTransformer transformer = new ResourceTransformer() {

            @Override
            public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
                for (String name : resource.getChildrenNames(ProtocolResourceDefinition.WILDCARD_PATH.getKey())) {
                    resource.getModel().get(PROTOCOLS.getName()).add(name);
                }
                context.addTransformedResource(PathAddress.EMPTY_ADDRESS, resource).processChildren(resource);
            }
        };
        builder.setCustomResourceTransformer(transformer);
    }
    if (JGroupsModel.VERSION_2_0_0.requiresTransformation(version)) {
        builder.rejectChildResource(RelayResourceDefinition.PATH);
    } else {
        RelayResourceDefinition.buildTransformation(version, builder);
    }
    TransportResourceDefinition.buildTransformation(version, builder);
    ProtocolRegistration.buildTransformation(version, builder);
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) ResourceTransformer(org.jboss.as.controller.transform.ResourceTransformer) ResourceTransformationContext(org.jboss.as.controller.transform.ResourceTransformationContext)

Example 60 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class ForkChannelFactoryBuilder method configure.

@Override
public Builder<ChannelFactory> configure(OperationContext context, ModelNode model) throws OperationFailedException {
    PathAddress address = context.getCurrentAddress();
    Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
    this.protocols = resource.getChildren(ProtocolResourceDefinition.WILDCARD_PATH.getKey()).stream().filter(Resource::isModelDefined).map(entry -> new InjectedValueDependency<>(new ProtocolServiceNameProvider(address, entry.getPathElement()), ProtocolConfiguration.class)).collect(Collectors.toList());
    this.parentChannel = new InjectedValueDependency<>(JGroupsRequirement.CHANNEL.getServiceName(context, this.channelName), Channel.class);
    this.parentFactory = new InjectedValueDependency<>(JGroupsRequirement.CHANNEL_SOURCE.getServiceName(context, this.channelName), ChannelFactory.class);
    return this;
}
Also used : ProtocolConfiguration(org.wildfly.clustering.jgroups.spi.ProtocolConfiguration) PathAddress(org.jboss.as.controller.PathAddress) Channel(org.jgroups.Channel) Resource(org.jboss.as.controller.registry.Resource) ForkChannelFactory(org.jboss.as.clustering.jgroups.ForkChannelFactory) ChannelFactory(org.wildfly.clustering.jgroups.spi.ChannelFactory)

Aggregations

Resource (org.jboss.as.controller.registry.Resource)93 PathAddress (org.jboss.as.controller.PathAddress)52 ModelNode (org.jboss.dmr.ModelNode)52 PathElement (org.jboss.as.controller.PathElement)25 OperationFailedException (org.jboss.as.controller.OperationFailedException)24 OperationContext (org.jboss.as.controller.OperationContext)15 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)12 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)11 Map (java.util.Map)10 ServiceName (org.jboss.msc.service.ServiceName)10 ServiceTarget (org.jboss.msc.service.ServiceTarget)10 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)9 ResourceTransformationContext (org.jboss.as.controller.transform.ResourceTransformationContext)6 ResourceTransformer (org.jboss.as.controller.transform.ResourceTransformer)6 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)6 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)6 ObjectName (javax.management.ObjectName)5 Activation (org.jboss.jca.common.api.metadata.resourceadapter.Activation)5 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)5 ArrayList (java.util.ArrayList)4