Search in sources :

Example 6 with ServerSocketEndpointConfig

use of com.hazelcast.config.ServerSocketEndpointConfig in project hazelcast by hazelcast.

the class ExternalMemberConfigurationOverrideEnvTest method shouldHandleAdvancedNetworkEndpointConfiguration.

@Test
public void shouldHandleAdvancedNetworkEndpointConfiguration() throws Exception {
    Config config = new Config();
    config.getAdvancedNetworkConfig().setClientEndpointConfig(new ServerSocketEndpointConfig().setPort(9000).setPublicAddress("172.29.1.1"));
    config.getAdvancedNetworkConfig().setMemberEndpointConfig(new ServerSocketEndpointConfig().setPort(9001).setPublicAddress("172.29.1.1"));
    config.getAdvancedNetworkConfig().setRestEndpointConfig(new RestServerEndpointConfig().setPort(9002).setPublicAddress("172.29.1.1"));
    config.getAdvancedNetworkConfig().setMemcacheEndpointConfig(new ServerSocketEndpointConfig().setPort(9003).setPublicAddress("172.29.1.1"));
    Map<String, String> envVariables = new HashMap<>();
    envVariables.put("HZ_ADVANCEDNETWORK_CLIENTSERVERSOCKETENDPOINTCONFIG.PUBLICADDRESS", "127.0.0.1");
    envVariables.put("HZ_ADVANCEDNETWORK_MEMBERSERVERSOCKETENDPOINTCONFIG.PUBLICADDRESS", "127.0.0.2");
    envVariables.put("HZ_ADVANCEDNETWORK_RESTSERVERSOCKETENDPOINTCONFIG.PUBLICADDRESS", "127.0.0.3");
    envVariables.put("HZ_ADVANCEDNETWORK_MEMCACHESERVERSOCKETENDPOINTCONFIG.PUBLICADDRESS", "127.0.0.4");
    new ExternalConfigurationOverride(envVariables, System::getProperties).overwriteMemberConfig(config);
    ServerSocketEndpointConfig clientEndpointConfig = (ServerSocketEndpointConfig) config.getAdvancedNetworkConfig().getEndpointConfigs().get(EndpointQualifier.CLIENT);
    ServerSocketEndpointConfig memberEndpointConfig = (ServerSocketEndpointConfig) config.getAdvancedNetworkConfig().getEndpointConfigs().get(EndpointQualifier.MEMBER);
    ServerSocketEndpointConfig restEndpointConfig = (ServerSocketEndpointConfig) config.getAdvancedNetworkConfig().getEndpointConfigs().get(EndpointQualifier.REST);
    ServerSocketEndpointConfig memcacheEndpointConfig = (ServerSocketEndpointConfig) config.getAdvancedNetworkConfig().getEndpointConfigs().get(EndpointQualifier.MEMCACHE);
    assertEquals(9000, clientEndpointConfig.getPort());
    assertEquals("127.0.0.1", clientEndpointConfig.getPublicAddress());
    assertEquals(9001, memberEndpointConfig.getPort());
    assertEquals("127.0.0.2", memberEndpointConfig.getPublicAddress());
    assertEquals(9002, restEndpointConfig.getPort());
    assertEquals("127.0.0.3", restEndpointConfig.getPublicAddress());
    assertEquals(9003, memcacheEndpointConfig.getPort());
    assertEquals("127.0.0.4", memcacheEndpointConfig.getPublicAddress());
}
Also used : HashMap(java.util.HashMap) EventJournalConfig(com.hazelcast.config.EventJournalConfig) UserCodeDeploymentConfig(com.hazelcast.config.UserCodeDeploymentConfig) Config(com.hazelcast.config.Config) ServerSocketEndpointConfig(com.hazelcast.config.ServerSocketEndpointConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) MerkleTreeConfig(com.hazelcast.config.MerkleTreeConfig) RestServerEndpointConfig(com.hazelcast.config.RestServerEndpointConfig) ServerSocketEndpointConfig(com.hazelcast.config.ServerSocketEndpointConfig) RestServerEndpointConfig(com.hazelcast.config.RestServerEndpointConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with ServerSocketEndpointConfig

use of com.hazelcast.config.ServerSocketEndpointConfig in project hazelcast by hazelcast.

the class YamlMemberDomConfigProcessor method handleWanServerSocketEndpointConfig.

@Override
protected void handleWanServerSocketEndpointConfig(Node node) throws Exception {
    for (Node wanEndpointNode : childElements(node)) {
        ServerSocketEndpointConfig config = new ServerSocketEndpointConfig();
        config.setProtocolType(ProtocolType.WAN);
        String name = wanEndpointNode.getNodeName();
        handleServerSocketEndpointConfig(config, wanEndpointNode, name);
    }
}
Also used : Node(org.w3c.dom.Node) YamlNode(com.hazelcast.internal.yaml.YamlNode) ServerSocketEndpointConfig(com.hazelcast.config.ServerSocketEndpointConfig)

Example 8 with ServerSocketEndpointConfig

use of com.hazelcast.config.ServerSocketEndpointConfig in project hazelcast by hazelcast.

the class DelegatingAddressPicker method pickAddressFromEndpointConfig.

private void pickAddressFromEndpointConfig() {
    InetSocketAddress bindAddress;
    InetSocketAddress publicAddress;
    ServerSocketChannel serverSocketChannel;
    for (EndpointConfig config : config.getAdvancedNetworkConfig().getEndpointConfigs().values()) {
        if (!(config instanceof ServerSocketEndpointConfig)) {
            continue;
        }
        ServerSocketEndpointConfig endpointConfig = (ServerSocketEndpointConfig) config;
        EndpointQualifier qualifier = endpointConfig.getQualifier();
        bindAddress = memberAddressProvider.getBindAddress(qualifier);
        publicAddress = memberAddressProvider.getPublicAddress(qualifier);
        validatePublicAddress(publicAddress);
        if (!bindAddresses.values().contains(bindAddress)) {
            // bind new server socket
            serverSocketChannel = createServerSocketChannel(logger, config, bindAddress.getAddress(), bindAddress.getPort() == 0 ? endpointConfig.getPort() : bindAddress.getPort(), endpointConfig.getPortCount(), endpointConfig.isPortAutoIncrement(), endpointConfig.isReuseAddress(), false);
            serverSocketChannels.put(qualifier, serverSocketChannel);
            int port = serverSocketChannel.socket().getLocalPort();
            if (port != bindAddress.getPort()) {
                bindAddress = new InetSocketAddress(bindAddress.getAddress(), port);
            }
            if (publicAddress.getPort() == 0) {
                publicAddress = new InetSocketAddress(publicAddress.getAddress(), port);
            }
        }
        logger.info("Using bind address: " + bindAddress + ", " + "public address: " + publicAddress + " for qualifier " + qualifier);
        bindAddresses.put(qualifier, bindAddress);
        publicAddresses.put(qualifier, publicAddress);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) ServerSocketEndpointConfig(com.hazelcast.config.ServerSocketEndpointConfig) ServerSocketChannel(java.nio.channels.ServerSocketChannel) ServerSocketHelper.createServerSocketChannel(com.hazelcast.instance.impl.ServerSocketHelper.createServerSocketChannel) EndpointConfig(com.hazelcast.config.EndpointConfig) ServerSocketEndpointConfig(com.hazelcast.config.ServerSocketEndpointConfig)

Example 9 with ServerSocketEndpointConfig

use of com.hazelcast.config.ServerSocketEndpointConfig in project hazelcast by hazelcast.

the class MemberDomConfigProcessor method handleClientServerSocketEndpointConfig.

private void handleClientServerSocketEndpointConfig(Node node) throws Exception {
    ServerSocketEndpointConfig config = (ServerSocketEndpointConfig) this.config.getAdvancedNetworkConfig().getEndpointConfigs().getOrDefault(EndpointQualifier.CLIENT, new ServerSocketEndpointConfig());
    config.setProtocolType(ProtocolType.CLIENT);
    handleServerSocketEndpointConfig(config, node);
}
Also used : ServerSocketEndpointConfig(com.hazelcast.config.ServerSocketEndpointConfig)

Example 10 with ServerSocketEndpointConfig

use of com.hazelcast.config.ServerSocketEndpointConfig in project hazelcast by hazelcast.

the class ConfigValidator method checkAdvancedNetworkConfig.

@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity", "checkstyle:booleanexpressioncomplexity" })
public static void checkAdvancedNetworkConfig(Config config) {
    if (!config.getAdvancedNetworkConfig().isEnabled()) {
        return;
    }
    EnumMap<ProtocolType, MutableInteger> serverSocketsPerProtocolType = new EnumMap<>(ProtocolType.class);
    for (ProtocolType protocolType : ProtocolType.values()) {
        serverSocketsPerProtocolType.put(protocolType, new MutableInteger());
    }
    Map<EndpointQualifier, EndpointConfig> endpointConfigs = config.getAdvancedNetworkConfig().getEndpointConfigs();
    for (EndpointConfig endpointConfig : endpointConfigs.values()) {
        if (endpointConfig instanceof ServerSocketEndpointConfig) {
            serverSocketsPerProtocolType.get(endpointConfig.getProtocolType()).getAndInc();
        }
    }
    for (ProtocolType protocolType : ProtocolType.values()) {
        int serverSocketCount = serverSocketsPerProtocolType.get(protocolType).value;
        if (serverSocketCount > protocolType.getServerSocketCardinality()) {
            throw new InvalidConfigurationException(format("Protocol type %s allows definition " + "of up to %d server sockets but %d were configured", protocolType, protocolType.getServerSocketCardinality(), serverSocketCount));
        }
    }
    // ensure there is 1 MEMBER type server socket
    if (serverSocketsPerProtocolType.get(MEMBER).value != 1) {
        throw new InvalidConfigurationException("A member-server-socket-endpoint" + " configuration is required for the cluster to form.");
    }
    // endpoint qualifiers referenced by WAN publishers must exist
    for (WanReplicationConfig wanReplicationConfig : config.getWanReplicationConfigs().values()) {
        for (WanBatchPublisherConfig wanPublisherConfig : wanReplicationConfig.getBatchPublisherConfigs()) {
            if (wanPublisherConfig.getEndpoint() != null) {
                EndpointQualifier qualifier = EndpointQualifier.resolve(WAN, wanPublisherConfig.getEndpoint());
                if (endpointConfigs.get(qualifier) == null) {
                    throw new InvalidConfigurationException(format("WAN publisher config for cluster name '%s' requires an wan-endpoint " + "config with identifier '%s' but none was found", wanPublisherConfig.getClusterName(), wanPublisherConfig.getEndpoint()));
                }
            }
        }
    }
}
Also used : WanBatchPublisherConfig(com.hazelcast.config.WanBatchPublisherConfig) WanReplicationConfig(com.hazelcast.config.WanReplicationConfig) ProtocolType(com.hazelcast.instance.ProtocolType) MutableInteger(com.hazelcast.internal.util.MutableInteger) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) ServerSocketEndpointConfig(com.hazelcast.config.ServerSocketEndpointConfig) EnumMap(java.util.EnumMap) EndpointConfig(com.hazelcast.config.EndpointConfig) ServerSocketEndpointConfig(com.hazelcast.config.ServerSocketEndpointConfig) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Aggregations

ServerSocketEndpointConfig (com.hazelcast.config.ServerSocketEndpointConfig)20 Config (com.hazelcast.config.Config)12 AdvancedNetworkConfig (com.hazelcast.config.AdvancedNetworkConfig)5 JoinConfig (com.hazelcast.config.JoinConfig)5 RestServerEndpointConfig (com.hazelcast.config.RestServerEndpointConfig)5 EndpointConfig (com.hazelcast.config.EndpointConfig)3 TcpIpConfig (com.hazelcast.config.TcpIpConfig)2 WanBatchPublisherConfig (com.hazelcast.config.WanBatchPublisherConfig)2 WanReplicationConfig (com.hazelcast.config.WanReplicationConfig)2 EndpointQualifier (com.hazelcast.instance.EndpointQualifier)2 HazelcastTestSupport.smallInstanceConfig (com.hazelcast.test.HazelcastTestSupport.smallInstanceConfig)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Test (org.junit.Test)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 EventJournalConfig (com.hazelcast.config.EventJournalConfig)1 InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)1 MemberAddressProviderConfig (com.hazelcast.config.MemberAddressProviderConfig)1 MerkleTreeConfig (com.hazelcast.config.MerkleTreeConfig)1 NearCacheConfig (com.hazelcast.config.NearCacheConfig)1 NetworkConfig (com.hazelcast.config.NetworkConfig)1