Search in sources :

Example 31 with PathElement

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

the class JMSConnectionFactoryDefinitionInjectionSource method startedPooledConnectionFactory.

private void startedPooledConnectionFactory(ResolutionContext context, String name, ServiceBuilder<?> serviceBuilder, ServiceTarget serviceTarget, DeploymentUnit deploymentUnit, Injector<ManagedReferenceFactory> injector, boolean external) throws DeploymentUnitProcessingException, OperationFailedException {
    Map<String, String> props = new HashMap<>(properties);
    List<String> connectors = getConnectors(props);
    clearUnknownProperties(properties);
    ModelNode model = new ModelNode();
    for (String connector : connectors) {
        model.get(CONNECTORS).add(connector);
    }
    for (Map.Entry<String, String> entry : properties.entrySet()) {
        model.get(entry.getKey()).set(entry.getValue());
    }
    model.get(MIN_POOL_SIZE.getName()).set(minPoolSize);
    model.get(MAX_POOL_SIZE.getName()).set(maxPoolSize);
    if (user != null && !user.isEmpty()) {
        model.get(ConnectionFactoryAttributes.Pooled.USER.getName()).set(user);
    }
    if (password != null && !password.isEmpty()) {
        model.get(ConnectionFactoryAttributes.Pooled.PASSWORD.getName()).set(password);
    }
    if (clientId != null && !clientId.isEmpty()) {
        model.get(CommonAttributes.CLIENT_ID.getName()).set(clientId);
    }
    final String discoveryGroupName = properties.containsKey(DISCOVERY_GROUP.getName()) ? properties.get(DISCOVERY_GROUP.getName()) : null;
    if (discoveryGroupName != null) {
        model.get(DISCOVERY_GROUP.getName()).set(discoveryGroupName);
    }
    final String jgroupsChannelName = properties.containsKey(JGROUPS_CLUSTER.getName()) ? properties.get(JGROUPS_CLUSTER.getName()) : null;
    if (jgroupsChannelName != null) {
        model.get(JGROUPS_CLUSTER.getName()).set(jgroupsChannelName);
    }
    final String managedConnectionPoolClassName = properties.containsKey(MANAGED_CONNECTION_POOL.getName()) ? properties.get(MANAGED_CONNECTION_POOL.getName()) : null;
    if (managedConnectionPoolClassName != null) {
        model.get(MANAGED_CONNECTION_POOL.getName()).set(managedConnectionPoolClassName);
    }
    final Boolean enlistmentTrace = properties.containsKey(ENLISTMENT_TRACE.getName()) ? Boolean.valueOf(properties.get(ENLISTMENT_TRACE.getName())) : null;
    List<PooledConnectionFactoryConfigProperties> adapterParams = getAdapterParams(model);
    String txSupport = transactional ? XA_TX : NO_TX;
    final String serverName;
    final String pcfName = uniqueName(context, name);
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), name);
    if (external) {
        serverName = null;
        Set<String> connectorsSocketBindings = new HashSet<>();
        ExternalBrokerConfigurationService configuration = (ExternalBrokerConfigurationService) deploymentUnit.getServiceRegistry().getRequiredService(MessagingSubsystemRootResourceDefinition.CONFIGURATION_CAPABILITY.getCapabilityServiceName()).getService().getValue();
        TransportConfiguration[] tcs = new TransportConfiguration[connectors.size()];
        for (int i = 0; i < tcs.length; i++) {
            tcs[i] = configuration.getConnectors().get(connectors.get(i));
            if (tcs[i].getParams().containsKey(ModelDescriptionConstants.SOCKET_BINDING)) {
                connectorsSocketBindings.add(tcs[i].getParams().get(ModelDescriptionConstants.SOCKET_BINDING).toString());
            }
        }
        DiscoveryGroupConfiguration discoveryGroupConfiguration = null;
        if (discoveryGroupName != null) {
            discoveryGroupConfiguration = configuration.getDiscoveryGroupConfigurations().get(discoveryGroupName);
        }
        if (connectors.isEmpty() && discoveryGroupConfiguration == null) {
            tcs = getExternalPooledConnectionFactory(resourceAdapter, deploymentUnit.getServiceRegistry()).getConnectors();
            for (int i = 0; i < tcs.length; i++) {
                if (tcs[i].getParams().containsKey(ModelDescriptionConstants.SOCKET_BINDING)) {
                    connectorsSocketBindings.add(tcs[i].getParams().get(ModelDescriptionConstants.SOCKET_BINDING).toString());
                }
            }
        }
        ExternalPooledConnectionFactoryService.installService(serviceTarget, configuration, pcfName, tcs, discoveryGroupConfiguration, connectorsSocketBindings, null, jgroupsChannelName, adapterParams, bindInfo, Collections.emptyList(), txSupport, minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace, deploymentUnit.getAttachment(CAPABILITY_SERVICE_SUPPORT));
    } else {
        serverName = getActiveMQServerName(properties);
        PooledConnectionFactoryService.installService(serviceTarget, pcfName, serverName, connectors, discoveryGroupName, jgroupsChannelName, adapterParams, bindInfo, txSupport, minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace, true);
    }
    final ServiceName referenceFactoryServiceName = ConnectionFactoryReferenceFactoryService.SERVICE_NAME_BASE.append(bindInfo.getBinderServiceName());
    serviceBuilder.addDependency(referenceFactoryServiceName, ManagedReferenceFactory.class, injector);
    // create the management registration
    String managementName = managementName(context, name);
    final DeploymentResourceSupport deploymentResourceSupport = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT);
    final PathElement pcfPath = PathElement.pathElement(POOLED_CONNECTION_FACTORY, managementName);
    PathAddress registration;
    if (external) {
        deploymentResourceSupport.getDeploymentSubsystemModel(MessagingExtension.SUBSYSTEM_NAME);
        registration = PathAddress.pathAddress(pcfPath);
    } else {
        final PathElement serverElement = PathElement.pathElement(SERVER, serverName);
        deploymentResourceSupport.getDeploymentSubModel(MessagingExtension.SUBSYSTEM_NAME, serverElement);
        registration = PathAddress.pathAddress(serverElement, pcfPath);
    }
    MessagingXmlInstallDeploymentUnitProcessor.createDeploymentSubModel(registration, deploymentUnit);
    PooledConnectionFactoryConfigurationRuntimeHandler.INSTANCE.registerResource(serverName, managementName, model);
}
Also used : HashMap(java.util.HashMap) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) PooledConnectionFactoryConfigProperties(org.wildfly.extension.messaging.activemq.jms.PooledConnectionFactoryConfigProperties) DeploymentResourceSupport(org.jboss.as.server.deployment.DeploymentResourceSupport) PathElement(org.jboss.as.controller.PathElement) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ExternalBrokerConfigurationService(org.wildfly.extension.messaging.activemq.ExternalBrokerConfigurationService) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map) HashMap(java.util.HashMap) ContextNames(org.jboss.as.naming.deployment.ContextNames) HashSet(java.util.HashSet)

Example 32 with PathElement

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

the class MessagingXmlInstallDeploymentUnitProcessor method getOrCreate.

static Resource getOrCreate(final Resource parent, final PathAddress address) {
    Resource current = parent;
    for (final PathElement element : address) {
        synchronized (current) {
            if (current.hasChild(element)) {
                current = current.requireChild(element);
            } else {
                final Resource resource = Resource.Factory.create();
                current.registerChild(element, resource);
                current = resource;
            }
        }
    }
    return current;
}
Also used : PathElement(org.jboss.as.controller.PathElement) Resource(org.jboss.as.controller.registry.Resource)

Example 33 with PathElement

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

the class MessagingXmlInstallDeploymentUnitProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final List<ParseResult> parseResults = deploymentUnit.getAttachmentList(MessagingAttachments.PARSE_RESULT);
    final DeploymentResourceSupport deploymentResourceSupport = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT);
    for (final ParseResult parseResult : parseResults) {
        for (final JmsDestination topic : parseResult.getTopics()) {
            final ServiceName serverServiceName = MessagingServices.getActiveMQServiceName(topic.getServer());
            String[] jndiBindings = null;
            if (topic.getDestination().hasDefined(CommonAttributes.DESTINATION_ENTRIES.getName())) {
                final ModelNode entries = topic.getDestination().resolve().get(CommonAttributes.DESTINATION_ENTRIES.getName());
                jndiBindings = JMSServices.getJndiBindings(entries);
            }
            JMSTopicService topicService = JMSTopicService.installService(topic.getName(), serverServiceName, phaseContext.getServiceTarget());
            final ServiceName topicServiceName = JMSServices.getJmsTopicBaseServiceName(serverServiceName).append(topic.getName());
            for (String binding : jndiBindings) {
                BinderServiceUtil.installBinderService(phaseContext.getServiceTarget(), binding, topicService, topicServiceName);
            }
            // create the management registration
            final PathElement serverElement = PathElement.pathElement(SERVER, topic.getServer());
            final PathElement destination = PathElement.pathElement(JMS_TOPIC, topic.getName());
            deploymentResourceSupport.getDeploymentSubModel(MessagingExtension.SUBSYSTEM_NAME, serverElement);
            PathAddress registration = PathAddress.pathAddress(serverElement, destination);
            createDeploymentSubModel(registration, deploymentUnit);
            JMSTopicConfigurationRuntimeHandler.INSTANCE.registerResource(topic.getServer(), topic.getName(), topic.getDestination());
        }
        for (final JmsDestination queue : parseResult.getQueues()) {
            final ServiceName serverServiceName = MessagingServices.getActiveMQServiceName(queue.getServer());
            String[] jndiBindings = null;
            final ModelNode destination = queue.getDestination();
            if (destination.hasDefined(CommonAttributes.DESTINATION_ENTRIES.getName())) {
                final ModelNode entries = destination.resolve().get(CommonAttributes.DESTINATION_ENTRIES.getName());
                jndiBindings = JMSServices.getJndiBindings(entries);
            }
            final String selector = destination.hasDefined(SELECTOR.getName()) ? destination.get(SELECTOR.getName()).resolve().asString() : null;
            final boolean durable = destination.hasDefined(DURABLE.getName()) ? destination.get(DURABLE.getName()).resolve().asBoolean() : false;
            Service<Queue> queueService = JMSQueueService.installService(queue.getName(), phaseContext.getServiceTarget(), serverServiceName, selector, durable);
            final ServiceName queueServiceName = JMSServices.getJmsQueueBaseServiceName(serverServiceName).append(queue.getName());
            for (String binding : jndiBindings) {
                BinderServiceUtil.installBinderService(phaseContext.getServiceTarget(), binding, queueService, queueServiceName);
            }
            // create the management registration
            final PathElement serverElement = PathElement.pathElement(SERVER, queue.getServer());
            final PathElement dest = PathElement.pathElement(JMS_QUEUE, queue.getName());
            deploymentResourceSupport.getDeploymentSubModel(MessagingExtension.SUBSYSTEM_NAME, serverElement);
            PathAddress registration = PathAddress.pathAddress(serverElement, dest);
            createDeploymentSubModel(registration, deploymentUnit);
            JMSQueueConfigurationRuntimeHandler.INSTANCE.registerResource(queue.getServer(), queue.getName(), destination);
        }
    }
}
Also used : JMSTopicService(org.wildfly.extension.messaging.activemq.jms.JMSTopicService) DeploymentResourceSupport(org.jboss.as.server.deployment.DeploymentResourceSupport) PathElement(org.jboss.as.controller.PathElement) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) Queue(javax.jms.Queue)

Example 34 with PathElement

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

the class JMSDestinationDefinitionInjectionSource method startTopic.

private void startTopic(String topicName, ServiceTarget serviceTarget, ServiceName serverServiceName, ServiceBuilder<?> serviceBuilder, DeploymentUnit deploymentUnit, Injector<ManagedReferenceFactory> injector, final boolean external) {
    final String managementAddress = properties.containsKey(MANAGEMENT_ADDRESS.getName()) ? properties.get(MANAGEMENT_ADDRESS.getName()) : MANAGEMENT_ADDRESS.getDefaultValue().asString();
    final String user = properties.containsKey("management-user") ? properties.get("management-user") : null;
    final String password = properties.containsKey("management-password") ? properties.get("management-password") : null;
    ModelNode destination = new ModelNode();
    destination.get(NAME).set(topicName);
    destination.get(ENTRIES).add(jndiName);
    Service<Topic> topicService;
    if (external) {
        // check @JMSDestinationDefinitions boolean property named enable-amq1-prefix for runtime topic
        final boolean enabledAMQ1Prefix = properties.containsKey(External.ENABLE_AMQ1_PREFIX.getName()) ? Boolean.valueOf(properties.get(External.ENABLE_AMQ1_PREFIX.getName())) : External.ENABLE_AMQ1_PREFIX.getDefaultValue().asBoolean();
        ServiceName pcfName = JMSServices.getPooledConnectionFactoryBaseServiceName(serverServiceName).append(resourceAdapter);
        final ServiceName jmsTopicServiceName = JMSServices.getJmsTopicBaseServiceName(serverServiceName).append(topicName);
        topicService = ExternalJMSTopicService.installRuntimeTopicService(DestinationConfiguration.Builder.getInstance().setResourceAdapter(resourceAdapter).setName(topicName).setManagementQueueAddress(managementAddress).setManagementUsername(user).setManagementPassword(password).setDestinationServiceName(jmsTopicServiceName).build(), serviceTarget, pcfName, enabledAMQ1Prefix);
    } else {
        topicService = JMSTopicService.installService(topicName, serverServiceName, serviceTarget);
    }
    inject(serviceBuilder, injector, topicService);
    // create the management registration
    String serverName = null;
    final DeploymentResourceSupport deploymentResourceSupport = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT);
    PathAddress registration;
    if (external) {
        final PathElement dest = PathElement.pathElement(EXTERNAL_JMS_TOPIC, topicName);
        deploymentResourceSupport.getDeploymentSubsystemModel(MessagingExtension.SUBSYSTEM_NAME);
        registration = PathAddress.pathAddress(dest);
    } else {
        serverName = getActiveMQServerName(properties);
        final PathElement dest = PathElement.pathElement(JMS_TOPIC, topicName);
        final PathElement serverElement = PathElement.pathElement(SERVER, serverName);
        deploymentResourceSupport.getDeploymentSubModel(MessagingExtension.SUBSYSTEM_NAME, serverElement);
        registration = PathAddress.pathAddress(serverElement, dest);
    }
    MessagingXmlInstallDeploymentUnitProcessor.createDeploymentSubModel(registration, deploymentUnit);
    JMSTopicConfigurationRuntimeHandler.INSTANCE.registerResource(serverName, topicName, destination);
}
Also used : DeploymentResourceSupport(org.jboss.as.server.deployment.DeploymentResourceSupport) PathElement(org.jboss.as.controller.PathElement) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) Topic(javax.jms.Topic)

Example 35 with PathElement

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

the class AbstractJMSRuntimeHandler method getResourceConfig.

private T getResourceConfig(final PathAddress operationAddress) throws OperationFailedException {
    final String name = operationAddress.getLastElement().getValue();
    PathElement serverElt = operationAddress.getParent().getLastElement();
    final String server;
    if (serverElt != null && SERVER.equals(serverElt.getKey())) {
        server = serverElt.getValue();
    } else {
        server = "";
    }
    T config = resources.get(new ResourceConfig(server, name));
    if (config == null) {
        throw new OperationFailedException(MessagingLogger.ROOT_LOGGER.noDestinationRegisteredForAddress(operationAddress));
    }
    return config;
}
Also used : PathElement(org.jboss.as.controller.PathElement) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Aggregations

PathElement (org.jboss.as.controller.PathElement)84 PathAddress (org.jboss.as.controller.PathAddress)47 ModelNode (org.jboss.dmr.ModelNode)46 Resource (org.jboss.as.controller.registry.Resource)24 OperationFailedException (org.jboss.as.controller.OperationFailedException)12 ServiceName (org.jboss.msc.service.ServiceName)12 Test (org.junit.Test)10 Map (java.util.Map)9 ArrayList (java.util.ArrayList)8 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)8 ParseUtils.requireNoNamespaceAttribute (org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute)7 ParseUtils.unexpectedAttribute (org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute)7 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)7 DeploymentResourceSupport (org.jboss.as.server.deployment.DeploymentResourceSupport)7 AbstractSubsystemBaseTest (org.jboss.as.subsystem.test.AbstractSubsystemBaseTest)7 ServiceTarget (org.jboss.msc.service.ServiceTarget)6 StatisticsResourceDefinition (org.jboss.as.connector.dynamicresource.StatisticsResourceDefinition)4 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)4 OperationContext (org.jboss.as.controller.OperationContext)4 StandardResourceDescriptionResolver (org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver)4