Skip to content

Commit

Permalink
Allow multiple WAN server sockets to be configured with YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
blazember committed Mar 29, 2019
1 parent 6add8c0 commit 3ff109b
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 29 deletions.
Expand Up @@ -686,7 +686,7 @@ private void handleClientServerSocketEndpointConfig(Node node) throws Exception
handleServerSocketEndpointConfig(config, node);
}

private void handleWanServerSocketEndpointConfig(Node node) throws Exception {
protected void handleWanServerSocketEndpointConfig(Node node) throws Exception {
ServerSocketEndpointConfig config = new ServerSocketEndpointConfig();
config.setProtocolType(ProtocolType.WAN);
handleServerSocketEndpointConfig(config, node);
Expand Down Expand Up @@ -717,9 +717,13 @@ protected void handleWanEndpointConfig(Node node) throws Exception {
handleEndpointConfig(config, node);
}

private void handleServerSocketEndpointConfig(ServerSocketEndpointConfig endpointConfig, Node node)
throws Exception {
private void handleServerSocketEndpointConfig(ServerSocketEndpointConfig endpointConfig, Node node) throws Exception {
String name = getAttribute(node, "name");
handleServerSocketEndpointConfig(endpointConfig, node, name);
}

protected void handleServerSocketEndpointConfig(ServerSocketEndpointConfig endpointConfig, Node node, String name)
throws Exception {
endpointConfig.setName(name);
for (Node child : childElements(node)) {
String nodeName = cleanNodeName(child);
Expand Down
Expand Up @@ -16,10 +16,10 @@

package com.hazelcast.config;

import com.hazelcast.instance.ProtocolType;
import com.hazelcast.config.cp.CPSemaphoreConfig;
import com.hazelcast.config.cp.CPSubsystemConfig;
import com.hazelcast.config.cp.FencedLockConfig;
import com.hazelcast.instance.ProtocolType;
import com.hazelcast.internal.yaml.YamlMapping;
import com.hazelcast.internal.yaml.YamlNode;
import com.hazelcast.internal.yaml.YamlScalar;
Expand Down Expand Up @@ -910,6 +910,16 @@ protected void handlePort(Node node, ServerSocketEndpointConfig endpointConfig)
handlePortAttributes(node, endpointConfig);
}

@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);
}
}

@Override
protected void handleWanEndpointConfig(Node node) throws Exception {
for (Node wanEndpointNode : childElements(node)) {
Expand Down
10 changes: 5 additions & 5 deletions hazelcast/src/main/resources/hazelcast-full-example.yaml
Expand Up @@ -2691,12 +2691,12 @@ hazelcast:
password: thepassword
iteration-count: 1000
wan-server-socket-endpoint-config:
name: wan-server-socket-config
interfaces:
enabled: false
wan-server-socket-config:
interfaces:
- 192.168.8.101
- 10.20.10.100
enabled: false
interfaces:
- 192.168.8.101
- 10.20.10.100
memcache-server-socket-endpoint-config:
name: memcache
port:
Expand Down
Expand Up @@ -538,17 +538,25 @@ public void testCompleteAdvancedNetworkConfig() {
assertEquals(MEMCACHE, memcacheEndpointConfig.getProtocolType());
assertEquals("42000-42100", memcacheEndpointConfig.getOutboundPortDefinitions().iterator().next());

// WAN server socket config
EndpointConfig wanServerSockerEndpointConfig = advancedNetworkConfig.getEndpointConfigs()
.get(EndpointQualifier.resolve(WAN, "WAN_SERVER"));
assertEquals(WAN, wanServerSockerEndpointConfig.getProtocolType());
assertEquals("52000-52100", wanServerSockerEndpointConfig.getOutboundPortDefinitions().iterator().next());
// WAN server socket configs
EndpointConfig wanServerSockerEndpointConfig1 = advancedNetworkConfig.getEndpointConfigs()
.get(EndpointQualifier.resolve(WAN, "WAN_SERVER1"));
EndpointConfig wanServerSockerEndpointConfig2 = advancedNetworkConfig.getEndpointConfigs()
.get(EndpointQualifier.resolve(WAN, "WAN_SERVER2"));
assertEquals(WAN, wanServerSockerEndpointConfig1.getProtocolType());
assertEquals("52000-52100", wanServerSockerEndpointConfig1.getOutboundPortDefinitions().iterator().next());
assertEquals(WAN, wanServerSockerEndpointConfig2.getProtocolType());
assertEquals("53000-53100", wanServerSockerEndpointConfig2.getOutboundPortDefinitions().iterator().next());

// WAN endpoint config
EndpointConfig wanEndpointConfig = advancedNetworkConfig.getEndpointConfigs()
.get(EndpointQualifier.resolve(WAN, "WAN_ENDPOINT"));
assertEquals(WAN, wanEndpointConfig.getProtocolType());
assertEquals("62000-62100", wanEndpointConfig.getOutboundPortDefinitions().iterator().next());
EndpointConfig wanEndpointConfig1 = advancedNetworkConfig.getEndpointConfigs()
.get(EndpointQualifier.resolve(WAN, "WAN_ENDPOINT1"));
EndpointConfig wanEndpointConfig2 = advancedNetworkConfig.getEndpointConfigs()
.get(EndpointQualifier.resolve(WAN, "WAN_ENDPOINT2"));
assertEquals(WAN, wanEndpointConfig1.getProtocolType());
assertEquals("62000-62100", wanEndpointConfig1.getOutboundPortDefinitions().iterator().next());
assertEquals(WAN, wanEndpointConfig2.getProtocolType());
assertEquals("63000-63100", wanEndpointConfig2.getOutboundPortDefinitions().iterator().next());

// client server socket config
EndpointConfig clientServerSocketConfig = advancedNetworkConfig.getEndpointConfigs().get(EndpointQualifier.CLIENT);
Expand Down
Expand Up @@ -3401,12 +3401,18 @@ protected Config buildCompleteAdvancedNetworkConfig() {
+ " <memcache-server-socket-endpoint-config name=\"MEMCACHE\">\n"
+ " <outbound-ports><ports>42000-42100</ports></outbound-ports>\n"
+ " </memcache-server-socket-endpoint-config>\n"
+ " <wan-server-socket-endpoint-config name=\"WAN_SERVER\">\n"
+ " <wan-server-socket-endpoint-config name=\"WAN_SERVER1\">\n"
+ " <outbound-ports><ports>52000-52100</ports></outbound-ports>\n"
+ " </wan-server-socket-endpoint-config>\n"
+ " <wan-endpoint-config name=\"WAN_ENDPOINT\">\n"
+ " <wan-server-socket-endpoint-config name=\"WAN_SERVER2\">\n"
+ " <outbound-ports><ports>53000-53100</ports></outbound-ports>\n"
+ " </wan-server-socket-endpoint-config>\n"
+ " <wan-endpoint-config name=\"WAN_ENDPOINT1\">\n"
+ " <outbound-ports><ports>62000-62100</ports></outbound-ports>\n"
+ " </wan-endpoint-config>\n"
+ " <wan-endpoint-config name=\"WAN_ENDPOINT2\">\n"
+ " <outbound-ports><ports>63000-63100</ports></outbound-ports>\n"
+ " </wan-endpoint-config>\n"
+ " <client-server-socket-endpoint-config name=\"CLIENT\">\n"
+ " <outbound-ports><ports>72000-72100</ports></outbound-ports>\n"
+ " </client-server-socket-endpoint-config>\n"
Expand Down
Expand Up @@ -113,6 +113,37 @@ public void testFullExample() throws IOException {
assertEquals(xmlConfigFromXml, xmlConfigFromYaml);
}

@Test
public void testFullExampleWithAdvancedNetwork() throws IOException {
String fullExampleXml = readResourceToString("hazelcast-full-example.xml");
String fullExampleYaml = readResourceToString("hazelcast-full-example.yaml");

// remove imports to prevent the test from failing with importing non-existing files
fullExampleXml = fullExampleXml.replace("<import resource=\"your-configuration-XML-file\"/>", "");
fullExampleYaml = fullExampleYaml
.replace("\r", "")
.replace("import:\n - your-configuration-YAML-file", "");

// create file to the working directory needed for the EncryptionReplacer
createPasswordFile("password.txt", "h4z3lc4$t");

Config xmlConfig = new InMemoryXmlConfig(fullExampleXml);
Config yamlConfig = new InMemoryYamlConfig(fullExampleYaml);

// enabling advanced network configuration to compare the advanced
// network config instead of the regular network configs
xmlConfig.getAdvancedNetworkConfig().setEnabled(true);
yamlConfig.getAdvancedNetworkConfig().setEnabled(true);

sortClientPermissionConfigs(xmlConfig);
sortClientPermissionConfigs(yamlConfig);

String xmlConfigFromXml = new ConfigXmlGenerator(true).generate(xmlConfig);
String xmlConfigFromYaml = new ConfigXmlGenerator(true).generate(yamlConfig);

assertEquals(xmlConfigFromXml, xmlConfigFromYaml);
}

public String readResourceToString(String resource) throws IOException {
InputStream xmlInputStream = XmlYamlConfigBuilderEqualsTest.class.getClassLoader().getResourceAsStream(resource);
return new String(IOUtil.toByteArray(xmlInputStream));
Expand Down
Expand Up @@ -3456,13 +3456,19 @@ protected Config buildCompleteAdvancedNetworkConfig() {
+ " outbound-ports:\n"
+ " ports: 42000-42100\n"
+ " wan-server-socket-endpoint-config:\n"
+ " name: WAN_SERVER\n"
+ " outbound-ports:\n"
+ " ports: 52000-52100\n"
+ " WAN_SERVER1:\n"
+ " outbound-ports:\n"
+ " ports: 52000-52100\n"
+ " WAN_SERVER2:\n"
+ " outbound-ports:\n"
+ " ports: 53000-53100\n"
+ " wan-endpoint-config:\n"
+ " WAN_ENDPOINT:\n"
+ " WAN_ENDPOINT1:\n"
+ " outbound-ports:\n"
+ " ports: 62000-62100\n"
+ " WAN_ENDPOINT2:\n"
+ " outbound-ports:\n"
+ " ports: 63000-63100\n"
+ " client-server-socket-endpoint-config:\n"
+ " name: CLIENT\n"
+ " outbound-ports:\n"
Expand Down
Expand Up @@ -211,12 +211,12 @@ hazelcast:
password: thepassword
iteration-count: 1000
wan-server-socket-endpoint-config:
name: wan-server-socket-config
interfaces:
enabled: false
wan-server-socket-config:
interfaces:
- 192.168.8.101
- 10.20.10.100
enabled: false
interfaces:
- 192.168.8.101
- 10.20.10.100
memcache-server-socket-endpoint-config:
name: memcache
port:
Expand Down

0 comments on commit 3ff109b

Please sign in to comment.