Search in sources :

Example 26 with PathAddress

use of org.jboss.as.controller.PathAddress in project wildfly by wildfly.

the class ForkProtocolResourceRegistrationHandler method findProtocol.

@Override
public Protocol findProtocol(OperationContext context) throws ClassNotFoundException, ModuleLoadException {
    PathAddress address = context.getCurrentAddress();
    String channelName = address.getElement(address.size() - 3).getValue();
    String forkName = address.getElement(address.size() - 2).getValue();
    String protocolName = address.getElement(address.size() - 1).getValue();
    ServiceRegistry registry = context.getServiceRegistry(false);
    ServiceController<?> controller = registry.getService(JGroupsRequirement.CHANNEL.getServiceName(context, channelName));
    if (controller != null) {
        Channel channel = (Channel) controller.getValue();
        if (channel != null) {
            FORK fork = (FORK) channel.getProtocolStack().findProtocol(FORK.class);
            if (fork != null) {
                controller = registry.getService(JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, channelName));
                if (controller != null) {
                    ChannelFactory factory = (ChannelFactory) controller.getValue();
                    if (factory != null) {
                        ProtocolStackConfiguration configuration = factory.getProtocolStackConfiguration();
                        ProtocolConfiguration<? extends TP> transport = configuration.getTransport();
                        if (transport.getName().equals(protocolName)) {
                            Class<? extends Protocol> protocolClass = transport.createProtocol().getClass();
                            return channel.getProtocolStack().findProtocol(protocolClass);
                        }
                        for (ProtocolConfiguration<? extends Protocol> protocol : configuration.getProtocols()) {
                            if (protocol.getName().equals(protocolName)) {
                                Class<? extends Protocol> protocolClass = protocol.createProtocol().getClass();
                                return fork.get(forkName).getProtocolStack().findProtocol(protocolClass);
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : FORK(org.jgroups.protocols.FORK) PathAddress(org.jboss.as.controller.PathAddress) Channel(org.jgroups.Channel) ProtocolStackConfiguration(org.wildfly.clustering.jgroups.spi.ProtocolStackConfiguration) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ChannelFactory(org.wildfly.clustering.jgroups.spi.ChannelFactory)

Example 27 with PathAddress

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

Example 28 with PathAddress

use of org.jboss.as.controller.PathAddress in project wildfly by wildfly.

the class TransactionResourceDefinition 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, RequiredChildResourceDiscardPolicy.NEVER) : parent.addChildResource(PATH);
    List<org.jboss.as.controller.transform.OperationTransformer> addOperationTransformers = new LinkedList<>();
    List<org.jboss.as.controller.transform.OperationTransformer> removeOperationTransformers = new LinkedList<>();
    Map<String, org.jboss.as.controller.transform.OperationTransformer> readAttributeTransformers = new HashMap<>();
    Map<String, org.jboss.as.controller.transform.OperationTransformer> writeAttributeTransformers = new HashMap<>();
    Map<String, org.jboss.as.controller.transform.OperationTransformer> undefineAttributeTransformers = new HashMap<>();
    if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) {
        // Convert BATCH -> NONE, and include write-attribute:name=batching
        OperationTransformer addTransformer = new OperationTransformer() {

            @Override
            public ModelNode transformOperation(ModelNode operation) {
                if (operation.hasDefined(Attribute.MODE.getName())) {
                    ModelNode mode = operation.get(Attribute.MODE.getName());
                    if ((mode.getType() == ModelType.STRING) && (TransactionMode.valueOf(mode.asString()) == TransactionMode.BATCH)) {
                        mode.set(TransactionMode.NONE.name());
                        PathAddress address = Operations.getPathAddress(operation);
                        return Operations.createCompositeOperation(operation, Operations.createWriteAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING, new ModelNode(true)));
                    }
                }
                return operation;
            }
        };
        addOperationTransformers.add(new SimpleOperationTransformer(addTransformer));
        // Additionally include undefine-attribute:name=batching
        OperationTransformer removeTransformer = new OperationTransformer() {

            @Override
            public ModelNode transformOperation(ModelNode operation) {
                PathAddress address = Operations.getPathAddress(operation);
                return Operations.createCompositeOperation(operation, Operations.createUndefineAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING));
            }
        };
        removeOperationTransformers.add(new SimpleOperationTransformer(removeTransformer));
        // If read-attribute:name=batching is true, return BATCH, otherwise use result from read-attribute:name=mode
        OperationTransformer readAttributeOperationTransformer = new OperationTransformer() {

            @Override
            public ModelNode transformOperation(ModelNode operation) {
                PathAddress address = Operations.getPathAddress(operation);
                return Operations.createCompositeOperation(Operations.createReadAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING), operation);
            }
        };
        OperationResultTransformer readAttributeResultTransformer = new OperationResultTransformer() {

            @Override
            public ModelNode transformResult(ModelNode result) {
                ModelNode readBatchingResult = result.get(0);
                return readBatchingResult.asBoolean() ? new ModelNode(TransactionMode.BATCH.name()) : result.get(1);
            }
        };
        readAttributeTransformers.put(Attribute.MODE.getName(), new SimpleOperationTransformer(readAttributeOperationTransformer, readAttributeResultTransformer));
        // Convert BATCH -> NONE, and include write-attribute:name=batching
        OperationTransformer writeAttributeTransformer = new OperationTransformer() {

            @Override
            public ModelNode transformOperation(ModelNode operation) {
                ModelNode mode = Operations.getAttributeValue(operation);
                boolean batching = (mode.isDefined() && (mode.getType() == ModelType.STRING)) ? (TransactionMode.valueOf(mode.asString()) == TransactionMode.BATCH) : false;
                if (batching) {
                    mode.set(TransactionMode.NONE.name());
                }
                PathAddress address = Operations.getPathAddress(operation);
                return Operations.createCompositeOperation(operation, Operations.createWriteAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING, new ModelNode(batching)));
            }
        };
        writeAttributeTransformers.put(Attribute.MODE.getName(), new SimpleOperationTransformer(writeAttributeTransformer));
        // Include undefine-attribute:name=batching
        OperationTransformer undefineAttributeTransformer = new OperationTransformer() {

            @Override
            public ModelNode transformOperation(ModelNode operation) {
                PathAddress address = Operations.getPathAddress(operation);
                return Operations.createCompositeOperation(operation, Operations.createUndefineAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING));
            }
        };
        undefineAttributeTransformers.put(Attribute.MODE.getName(), new SimpleOperationTransformer(undefineAttributeTransformer));
        // Convert BATCH -> NONE
        ResourceTransformer modeTransformer = new ResourceTransformer() {

            @Override
            public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
                ModelNode model = resource.getModel();
                if (model.hasDefined(Attribute.MODE.getName())) {
                    ModelNode value = model.get(Attribute.MODE.getName());
                    if ((value.getType() == ModelType.STRING) && (TransactionMode.valueOf(value.asString()) == TransactionMode.BATCH)) {
                        value.set(TransactionMode.NONE.name());
                    }
                }
                context.addTransformedResource(PathAddress.EMPTY_ADDRESS, resource).processChildren(resource);
            }
        };
        builder.setCustomResourceTransformer(modeTransformer);
        // change default value of stop-timeout attribute
        builder.getAttributeBuilder().setValueConverter(new DefaultValueAttributeConverter(Attribute.STOP_TIMEOUT.getDefinition()), Attribute.STOP_TIMEOUT.getDefinition());
    }
    buildOperationTransformation(builder, ModelDescriptionConstants.ADD, addOperationTransformers);
    buildOperationTransformation(builder, ModelDescriptionConstants.REMOVE, removeOperationTransformers);
    buildOperationTransformation(builder, ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION, readAttributeTransformers);
    buildOperationTransformation(builder, ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION, writeAttributeTransformers);
    buildOperationTransformation(builder, ModelDescriptionConstants.UNDEFINE_ATTRIBUTE_OPERATION, undefineAttributeTransformers);
}
Also used : OperationResultTransformer(org.jboss.as.controller.transform.OperationResultTransformer) ChainedOperationTransformer(org.jboss.as.clustering.controller.transform.ChainedOperationTransformer) AttributeOperationTransformer(org.jboss.as.clustering.controller.transform.AttributeOperationTransformer) OperationTransformer(org.jboss.as.clustering.controller.transform.OperationTransformer) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) HashMap(java.util.HashMap) Resource(org.jboss.as.controller.registry.Resource) ResourceTransformationContext(org.jboss.as.controller.transform.ResourceTransformationContext) LinkedList(java.util.LinkedList) PathAddress(org.jboss.as.controller.PathAddress) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) DefaultValueAttributeConverter(org.jboss.as.controller.transform.description.AttributeConverter.DefaultValueAttributeConverter) ModelNode(org.jboss.dmr.ModelNode) ResourceTransformer(org.jboss.as.controller.transform.ResourceTransformer)

Example 29 with PathAddress

use of org.jboss.as.controller.PathAddress in project wildfly by wildfly.

the class TransportConfigurationBuilder method configure.

@Override
public Builder<TransportConfiguration<T>> configure(OperationContext context, ModelNode model) throws OperationFailedException {
    this.socketBinding = new InjectedValueDependency<>(CommonUnaryRequirement.SOCKET_BINDING.getServiceName(context, SOCKET_BINDING.resolveModelAttribute(context, model).asString()), SocketBinding.class);
    this.diagnosticsSocketBinding = ModelNodes.optionalString(DIAGNOSTICS_SOCKET_BINDING.resolveModelAttribute(context, model)).map(diagnosticsBinding -> new InjectedValueDependency<>(CommonUnaryRequirement.SOCKET_BINDING.getServiceName(context, diagnosticsBinding), SocketBinding.class)).orElse(null);
    Optional<String> machine = ModelNodes.optionalString(MACHINE.resolveModelAttribute(context, model));
    Optional<String> rack = ModelNodes.optionalString(RACK.resolveModelAttribute(context, model));
    Optional<String> site = ModelNodes.optionalString(SITE.resolveModelAttribute(context, model));
    if (site.isPresent() || rack.isPresent() || machine.isPresent()) {
        this.topology = new Topology() {

            @Override
            public String getMachine() {
                return machine.orElse(null);
            }

            @Override
            public String getRack() {
                return rack.orElse(null);
            }

            @Override
            public String getSite() {
                return site.orElse(null);
            }
        };
    }
    PathAddress address = context.getCurrentAddress();
    EnumSet.complementOf(EnumSet.of(ThreadPoolResourceDefinition.TIMER)).forEach(pool -> this.threadPoolFactories.put(pool, new InjectedValueDependency<>(new ThreadPoolServiceNameProvider(address, pool.getPathElement()), ThreadPoolFactory.class)));
    this.timerFactory = new InjectedValueDependency<>(new ThreadPoolServiceNameProvider(address, ThreadPoolResourceDefinition.TIMER.getPathElement()), TimerFactory.class);
    return super.configure(context, model);
}
Also used : SocketBinding(org.jboss.as.network.SocketBinding) InjectedValueDependency(org.wildfly.clustering.service.InjectedValueDependency) PathAddress(org.jboss.as.controller.PathAddress)

Example 30 with PathAddress

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

Aggregations

PathAddress (org.jboss.as.controller.PathAddress)644 ModelNode (org.jboss.dmr.ModelNode)492 Resource (org.jboss.as.controller.registry.Resource)70 Test (org.junit.Test)66 PathElement (org.jboss.as.controller.PathElement)63 KernelServices (org.jboss.as.subsystem.test.KernelServices)51 ServiceName (org.jboss.msc.service.ServiceName)51 OperationFailedException (org.jboss.as.controller.OperationFailedException)43 ParseUtils.requireNoNamespaceAttribute (org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute)35 ParseUtils.unexpectedAttribute (org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute)35 FailedOperationTransformationConfig (org.jboss.as.model.test.FailedOperationTransformationConfig)34 KernelServicesBuilder (org.jboss.as.subsystem.test.KernelServicesBuilder)33 ServiceTarget (org.jboss.msc.service.ServiceTarget)32 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)31 Map (java.util.Map)30 ParseUtils.unexpectedElement (org.jboss.as.controller.parsing.ParseUtils.unexpectedElement)29 IOException (java.io.IOException)28 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)26 ArrayList (java.util.ArrayList)25 OperationContext (org.jboss.as.controller.OperationContext)23