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());
}
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);
}
}
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);
}
}
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);
}
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()));
}
}
}
}
}
Aggregations