Search in sources :

Example 1 with OutboundSocketBinding

use of org.jboss.as.network.OutboundSocketBinding in project wildfly by wildfly.

the class ElectionPolicyBuilder method configure.

@Override
public Builder<SingletonElectionPolicy> configure(OperationContext context, ModelNode model) throws OperationFailedException {
    this.preferences.clear();
    this.dependencies.clear();
    ModelNodes.optionalList(SOCKET_BINDING_PREFERENCES.resolveModelAttribute(context, model)).ifPresent(bindings -> {
        bindings.stream().map(ModelNode::asString).forEach(bindingName -> {
            InjectedValueDependency<OutboundSocketBinding> binding = new InjectedValueDependency<>(CommonUnaryRequirement.OUTBOUND_SOCKET_BINDING.getServiceName(context, bindingName), OutboundSocketBinding.class);
            this.preferences.add(new OutboundSocketBindingPreference(binding));
            this.dependencies.add(binding);
        });
    });
    ModelNodes.optionalList(NAME_PREFERENCES.resolveModelAttribute(context, model)).ifPresent(names -> {
        names.stream().map(ModelNode::asString).forEach(name -> this.preferences.add(new NamePreference(name)));
    });
    return this;
}
Also used : OutboundSocketBindingPreference(org.wildfly.extension.clustering.singleton.election.OutboundSocketBindingPreference) NamePreference(org.wildfly.clustering.singleton.election.NamePreference) OutboundSocketBinding(org.jboss.as.network.OutboundSocketBinding) InjectedValueDependency(org.wildfly.clustering.service.InjectedValueDependency)

Example 2 with OutboundSocketBinding

use of org.jboss.as.network.OutboundSocketBinding in project wildfly by wildfly.

the class ActiveMQServerService method start.

public synchronized void start(final StartContext context) throws StartException {
    ClassLoader origTCCL = org.wildfly.security.manager.WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
    // Validate whether the AIO native layer can be used
    JournalType jtype = configuration.getJournalType();
    if (jtype == JournalType.ASYNCIO) {
        boolean supportsAIO = AIOSequentialFileFactory.isSupported();
        if (supportsAIO == false) {
            String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
            if (osName.contains("nux")) {
                ROOT_LOGGER.aioInfoLinux();
            } else {
                ROOT_LOGGER.aioInfo();
            }
            configuration.setJournalType(JournalType.NIO);
        }
    }
    // Setup paths
    PathManager pathManager = this.pathManager.getValue();
    configuration.setBindingsDirectory(pathConfig.resolveBindingsPath(pathManager));
    configuration.setLargeMessagesDirectory(pathConfig.resolveLargeMessagePath(pathManager));
    configuration.setJournalDirectory(pathConfig.resolveJournalPath(pathManager));
    configuration.setPagingDirectory(pathConfig.resolvePagingPath(pathManager));
    pathConfig.registerCallbacks(pathManager);
    try {
        // Update the acceptor/connector port/host values from the
        // Map the socket bindings onto the connectors/acceptors
        Collection<TransportConfiguration> acceptors = configuration.getAcceptorConfigurations();
        Collection<TransportConfiguration> connectors = configuration.getConnectorConfigurations().values();
        Collection<BroadcastGroupConfiguration> broadcastGroups = configuration.getBroadcastGroupConfigurations();
        Map<String, DiscoveryGroupConfiguration> discoveryGroups = configuration.getDiscoveryGroupConfigurations();
        if (connectors != null) {
            for (TransportConfiguration tc : connectors) {
                // If there is a socket binding set the HOST/PORT values
                Object socketRef = tc.getParams().remove(SOCKET_REF);
                if (socketRef != null) {
                    String name = socketRef.toString();
                    String host;
                    int port;
                    OutboundSocketBinding binding = outboundSocketBindings.get(name);
                    if (binding == null) {
                        final SocketBinding socketBinding = socketBindings.get(name);
                        if (socketBinding == null) {
                            throw MessagingLogger.ROOT_LOGGER.failedToFindConnectorSocketBinding(tc.getName());
                        }
                        InetSocketAddress sa = socketBinding.getSocketAddress();
                        port = sa.getPort();
                        // resolve the host name of the address only if a loopback address has been set
                        if (sa.getAddress().isLoopbackAddress()) {
                            host = NetworkUtils.canonize(sa.getAddress().getHostName());
                        } else {
                            host = NetworkUtils.canonize(sa.getAddress().getHostAddress());
                        }
                    } else {
                        port = binding.getDestinationPort();
                        host = NetworkUtils.canonize(binding.getUnresolvedDestinationAddress());
                        if (binding.getSourceAddress() != null) {
                            tc.getParams().put(TransportConstants.LOCAL_ADDRESS_PROP_NAME, NetworkUtils.canonize(binding.getSourceAddress().getHostAddress()));
                        }
                        if (binding.getSourcePort() != null) {
                            // Use absolute port to account for source port offset/fixation
                            tc.getParams().put(TransportConstants.LOCAL_PORT_PROP_NAME, binding.getAbsoluteSourcePort());
                        }
                    }
                    tc.getParams().put(HOST, host);
                    tc.getParams().put(PORT, port);
                }
            }
        }
        if (acceptors != null) {
            for (TransportConfiguration tc : acceptors) {
                // If there is a socket binding set the HOST/PORT values
                Object socketRef = tc.getParams().remove(SOCKET_REF);
                if (socketRef != null) {
                    String name = socketRef.toString();
                    SocketBinding binding = socketBindings.get(name);
                    if (binding == null) {
                        throw MessagingLogger.ROOT_LOGGER.failedToFindConnectorSocketBinding(tc.getName());
                    }
                    binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
                    InetSocketAddress socketAddress = binding.getSocketAddress();
                    tc.getParams().put(HOST, socketAddress.getAddress().getHostAddress());
                    tc.getParams().put(PORT, socketAddress.getPort());
                }
            }
        }
        if (broadcastGroups != null) {
            final List<BroadcastGroupConfiguration> newConfigs = new ArrayList<BroadcastGroupConfiguration>();
            for (final BroadcastGroupConfiguration config : broadcastGroups) {
                final String name = config.getName();
                final String key = "broadcast" + name;
                if (jgroupFactories.containsKey(key)) {
                    ChannelFactory channelFactory = jgroupFactories.get(key);
                    String channelName = jgroupsChannels.get(key);
                    JChannel channel = (JChannel) channelFactory.createChannel(channelName);
                    channels.put(channelName, channel);
                    newConfigs.add(BroadcastGroupAdd.createBroadcastGroupConfiguration(name, config, channel, channelName));
                } else {
                    final SocketBinding binding = groupBindings.get(key);
                    if (binding == null) {
                        throw MessagingLogger.ROOT_LOGGER.failedToFindBroadcastSocketBinding(name);
                    }
                    binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
                    newConfigs.add(BroadcastGroupAdd.createBroadcastGroupConfiguration(name, config, binding));
                }
            }
            configuration.getBroadcastGroupConfigurations().clear();
            configuration.getBroadcastGroupConfigurations().addAll(newConfigs);
        }
        if (discoveryGroups != null) {
            configuration.setDiscoveryGroupConfigurations(new HashMap<String, DiscoveryGroupConfiguration>());
            for (final Map.Entry<String, DiscoveryGroupConfiguration> entry : discoveryGroups.entrySet()) {
                final String name = entry.getKey();
                final String key = "discovery" + name;
                DiscoveryGroupConfiguration config = null;
                if (jgroupFactories.containsKey(key)) {
                    ChannelFactory channelFactory = jgroupFactories.get(key);
                    String channelName = jgroupsChannels.get(key);
                    JChannel channel = channels.get(channelName);
                    if (channel == null) {
                        channel = (JChannel) channelFactory.createChannel(key);
                        channels.put(channelName, channel);
                    }
                    config = DiscoveryGroupAdd.createDiscoveryGroupConfiguration(name, entry.getValue(), channel, channelName);
                } else {
                    final SocketBinding binding = groupBindings.get(key);
                    if (binding == null) {
                        throw MessagingLogger.ROOT_LOGGER.failedToFindDiscoverySocketBinding(name);
                    }
                    config = DiscoveryGroupAdd.createDiscoveryGroupConfiguration(name, entry.getValue(), binding);
                    binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
                }
                configuration.getDiscoveryGroupConfigurations().put(name, config);
            }
        }
        // security - if an Elytron domain has been defined we delegate security checks to the Elytron based security manager.
        ActiveMQSecurityManager securityManager = null;
        final SecurityDomain elytronDomain = this.elytronSecurityDomain.getOptionalValue();
        if (elytronDomain != null) {
            securityManager = new ElytronSecurityManager(elytronDomain);
        } else {
            securityManager = new WildFlySecurityManager(securityDomainContextValue.getValue());
        }
        // insert possible credential source hold passwords
        setBridgePasswordsFromCredentialSource();
        setClusterPasswordFromCredentialSource();
        DataSource ds = dataSource.getOptionalValue();
        if (ds != null) {
            DatabaseStorageConfiguration dbConfiguration = (DatabaseStorageConfiguration) configuration.getStoreConfiguration();
            dbConfiguration.setDataSource(ds);
            // inject the datasource into the PropertySQLProviderFactory to be able to determine the
            // type of database for the datasource metadata
            PropertySQLProviderFactory sqlProviderFactory = (PropertySQLProviderFactory) dbConfiguration.getSqlProviderFactory();
            sqlProviderFactory.investigateDialect(ds);
            configuration.setStoreConfiguration(dbConfiguration);
            ROOT_LOGGER.infof("use JDBC store for Artemis server, bindingsTable:%s", dbConfiguration.getBindingsTableName());
        }
        // Now start the server
        server = new ActiveMQServerImpl(configuration, mbeanServer.getOptionalValue(), securityManager);
        if (ActiveMQDefaultConfiguration.getDefaultClusterPassword().equals(server.getConfiguration().getClusterPassword())) {
            server.getConfiguration().setClusterPassword(java.util.UUID.randomUUID().toString());
        }
        for (Interceptor incomingInterceptor : incomingInterceptors) {
            server.getServiceRegistry().addIncomingInterceptor(incomingInterceptor);
        }
        for (Interceptor outgoingInterceptor : outgoingInterceptors) {
            server.getServiceRegistry().addOutgoingInterceptor(outgoingInterceptor);
        }
    // the server is actually started by the JMSService.
    } catch (Exception e) {
        throw MessagingLogger.ROOT_LOGGER.failedToStartService(e);
    } finally {
        org.wildfly.security.manager.WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(origTCCL);
    }
}
Also used : OutboundSocketBinding(org.jboss.as.network.OutboundSocketBinding) SocketBinding(org.jboss.as.network.SocketBinding) JChannel(org.jgroups.JChannel) OutboundSocketBinding(org.jboss.as.network.OutboundSocketBinding) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain) BroadcastGroupConfiguration(org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration) ActiveMQSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager) Interceptor(org.apache.activemq.artemis.api.core.Interceptor) PathManager(org.jboss.as.controller.services.path.PathManager) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) ChannelFactory(org.wildfly.clustering.jgroups.spi.ChannelFactory) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) StartException(org.jboss.msc.service.StartException) DataSource(javax.sql.DataSource) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) JournalType(org.apache.activemq.artemis.core.server.JournalType) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with OutboundSocketBinding

use of org.jboss.as.network.OutboundSocketBinding in project wildfly by wildfly.

the class ModClusterConfigurationServiceBuilder method getValue.

@Override
public ModClusterConfiguration getValue() throws IllegalStateException, IllegalArgumentException {
    // Advertise
    if (advertiseSocketDependency != null) {
        final SocketBinding binding = advertiseSocketDependency.getValue();
        builder.advertise().setAdvertiseSocketAddress(binding.getMulticastSocketAddress()).setAdvertiseInterface(binding.getSocketAddress().getAddress());
        if (!isMulticastEnabled(binding.getSocketBindings().getDefaultInterfaceBinding().getNetworkInterfaces())) {
            ROOT_LOGGER.multicastInterfaceNotAvailable();
        }
    }
    // Proxies
    List<ProxyConfiguration> proxies = new LinkedList<>();
    for (final ValueDependency<OutboundSocketBinding> outboundSocketBindingValueDependency : outboundSocketBindings) {
        OutboundSocketBinding binding = outboundSocketBindingValueDependency.getValue();
        proxies.add(new ProxyConfiguration() {

            @Override
            public InetSocketAddress getRemoteAddress() {
                // Don't do resolving here, let mod_cluster deal with it
                return new InetSocketAddress(binding.getUnresolvedDestinationAddress(), binding.getDestinationPort());
            }

            @Override
            public InetSocketAddress getLocalAddress() {
                if (binding.getOptionalSourceAddress() != null) {
                    return new InetSocketAddress(binding.getOptionalSourceAddress(), binding.getAbsoluteSourcePort() == null ? 0 : binding.getAbsoluteSourcePort());
                } else if (binding.getAbsoluteSourcePort() != null) {
                    // Bind to port only if source address is not configured
                    return new InetSocketAddress(binding.getAbsoluteSourcePort());
                }
                // No binding configured so don't bind
                return null;
            }
        });
    }
    builder.mcmp().setProxyConfigurations(proxies);
    // SSL
    if (sslContextDependency != null) {
        builder.mcmp().setSocketFactory(sslContextDependency.getValue().getSocketFactory());
    }
    return builder.build();
}
Also used : OutboundSocketBinding(org.jboss.as.network.OutboundSocketBinding) SocketBinding(org.jboss.as.network.SocketBinding) ProxyConfiguration(org.jboss.modcluster.config.ProxyConfiguration) OutboundSocketBinding(org.jboss.as.network.OutboundSocketBinding) InetSocketAddress(java.net.InetSocketAddress) LinkedList(java.util.LinkedList)

Aggregations

OutboundSocketBinding (org.jboss.as.network.OutboundSocketBinding)3 InetSocketAddress (java.net.InetSocketAddress)2 SocketBinding (org.jboss.as.network.SocketBinding)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 DataSource (javax.sql.DataSource)1 BroadcastGroupConfiguration (org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration)1 DiscoveryGroupConfiguration (org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration)1 Interceptor (org.apache.activemq.artemis.api.core.Interceptor)1 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)1 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)1 JournalType (org.apache.activemq.artemis.core.server.JournalType)1 ActiveMQServerImpl (org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl)1 ActiveMQSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager)1 PathManager (org.jboss.as.controller.services.path.PathManager)1 ProxyConfiguration (org.jboss.modcluster.config.ProxyConfiguration)1 StartException (org.jboss.msc.service.StartException)1 JChannel (org.jgroups.JChannel)1