use of com.hazelcast.config.TcpIpConfig in project hazelcast by hazelcast.
the class TcpIpJoinTest method test_whenExplicitPortConfigured.
@Test
public void test_whenExplicitPortConfigured() throws Exception {
Config config = new Config();
NetworkConfig networkConfig = config.getNetworkConfig();
JoinConfig join = networkConfig.getJoin();
join.getMulticastConfig().setEnabled(false);
TcpIpConfig tcpIpConfig = join.getTcpIpConfig();
tcpIpConfig.setEnabled(true);
tcpIpConfig.addMember("127.0.0.1:5701");
tcpIpConfig.addMember("127.0.0.1:5702");
testJoin(config);
}
use of com.hazelcast.config.TcpIpConfig in project cas by apereo.
the class HazelcastTicketRegistryConfiguration method getConfig.
private Config getConfig(final TicketCatalog ticketCatalog) {
final HazelcastProperties hz = casProperties.getTicket().getRegistry().getHazelcast();
final HazelcastProperties.Cluster cluster = hz.getCluster();
final Config config;
if (hz.getConfigLocation() != null && hz.getConfigLocation().exists()) {
try {
final URL configUrl = hz.getConfigLocation().getURL();
LOGGER.debug("Loading Hazelcast configuration from [{}]", configUrl);
config = new XmlConfigBuilder(hz.getConfigLocation().getInputStream()).build();
config.setConfigurationUrl(configUrl);
} catch (final Exception e) {
throw Throwables.propagate(e);
}
} else {
// No config location, so do a default config programmatically with handful of properties exposed by CAS
config = new Config();
config.setProperty("hazelcast.prefer.ipv4.stack", String.valueOf(cluster.isIpv4Enabled()));
// TCP config
final TcpIpConfig tcpIpConfig = new TcpIpConfig().setEnabled(cluster.isTcpipEnabled()).setMembers(cluster.getMembers()).setConnectionTimeoutSeconds(cluster.getTimeout());
LOGGER.debug("Created Hazelcast TCP/IP configuration [{}]", tcpIpConfig);
// Multicast config
final MulticastConfig multicastConfig = new MulticastConfig().setEnabled(cluster.isMulticastEnabled());
if (cluster.isMulticastEnabled()) {
multicastConfig.setMulticastGroup(cluster.getMulticastGroup());
multicastConfig.setMulticastPort(cluster.getMulticastPort());
final Set<String> trustedInterfaces = StringUtils.commaDelimitedListToSet(cluster.getMulticastTrustedInterfaces());
if (!trustedInterfaces.isEmpty()) {
multicastConfig.setTrustedInterfaces(trustedInterfaces);
}
multicastConfig.setMulticastTimeoutSeconds(cluster.getMulticastTimeout());
multicastConfig.setMulticastTimeToLive(cluster.getMulticastTimeToLive());
}
LOGGER.debug("Created Hazelcast Multicast configuration [{}]", multicastConfig);
// Join config
final JoinConfig joinConfig = new JoinConfig().setMulticastConfig(multicastConfig).setTcpIpConfig(tcpIpConfig);
LOGGER.debug("Created Hazelcast join configuration [{}]", joinConfig);
// Network config
final NetworkConfig networkConfig = new NetworkConfig().setPort(cluster.getPort()).setPortAutoIncrement(cluster.isPortAutoIncrement()).setJoin(joinConfig);
LOGGER.debug("Created Hazelcast network configuration [{}]", networkConfig);
// Finally aggregate all those config into the main Config
config.setMapConfigs(buildHazelcastMapConfigurations(ticketCatalog)).setNetworkConfig(networkConfig);
}
// Add additional default config properties regardless of the configuration source
return config.setInstanceName(cluster.getInstanceName()).setProperty(HazelcastProperties.LOGGING_TYPE_PROP, cluster.getLoggingType()).setProperty(HazelcastProperties.MAX_HEARTBEAT_SECONDS_PROP, String.valueOf(cluster.getMaxNoHeartbeatSeconds()));
}
use of com.hazelcast.config.TcpIpConfig in project hazelcast by hazelcast.
the class DiscoverySpiTest method testParsing.
@Test
public void testParsing() throws Exception {
String xmlFileName = "test-hazelcast-discovery-spi.xml";
InputStream xmlResource = DiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
Config config = new XmlConfigBuilder(xmlResource).build();
JoinConfig joinConfig = config.getNetworkConfig().getJoin();
AwsConfig awsConfig = joinConfig.getAwsConfig();
assertFalse(awsConfig.isEnabled());
TcpIpConfig tcpIpConfig = joinConfig.getTcpIpConfig();
assertFalse(tcpIpConfig.isEnabled());
MulticastConfig multicastConfig = joinConfig.getMulticastConfig();
assertFalse(multicastConfig.isEnabled());
DiscoveryConfig discoveryConfig = joinConfig.getDiscoveryConfig();
assertTrue(discoveryConfig.isEnabled());
assertEquals(1, discoveryConfig.getDiscoveryStrategyConfigs().size());
DiscoveryStrategyConfig providerConfig = discoveryConfig.getDiscoveryStrategyConfigs().iterator().next();
assertEquals(3, providerConfig.getProperties().size());
assertEquals("foo", providerConfig.getProperties().get("key-string"));
assertEquals("123", providerConfig.getProperties().get("key-int"));
assertEquals("true", providerConfig.getProperties().get("key-boolean"));
}
use of com.hazelcast.config.TcpIpConfig in project hazelcast by hazelcast.
the class TcpIpJoinTest method test_whenPortAndInterfacesConfigured.
@Test
public void test_whenPortAndInterfacesConfigured() throws Exception {
Config config = new Config();
NetworkConfig networkConfig = config.getNetworkConfig();
JoinConfig join = networkConfig.getJoin();
join.getMulticastConfig().setEnabled(false);
TcpIpConfig tcpIpConfig = join.getTcpIpConfig();
tcpIpConfig.setEnabled(true);
tcpIpConfig.addMember("127.0.0.1:5701");
tcpIpConfig.addMember("127.0.0.1:5702");
InterfacesConfig interfaces = networkConfig.getInterfaces();
interfaces.setEnabled(true);
interfaces.addInterface("127.0.0.1");
testJoin(config);
}
use of com.hazelcast.config.TcpIpConfig in project hazelcast by hazelcast.
the class TestFullApplicationContext method testNetworkConfig.
@Test
public void testNetworkConfig() {
NetworkConfig networkConfig = config.getNetworkConfig();
assertNotNull(networkConfig);
assertEquals(5700, networkConfig.getPort());
assertFalse(networkConfig.isPortAutoIncrement());
Collection<String> allowedPorts = networkConfig.getOutboundPortDefinitions();
assertEquals(2, allowedPorts.size());
Iterator portIter = allowedPorts.iterator();
assertEquals("35000-35100", portIter.next());
assertEquals("36000,36100", portIter.next());
assertFalse(networkConfig.getJoin().getMulticastConfig().isEnabled());
assertEquals(networkConfig.getJoin().getMulticastConfig().getMulticastTimeoutSeconds(), 8);
assertEquals(networkConfig.getJoin().getMulticastConfig().getMulticastTimeToLive(), 16);
assertEquals(false, networkConfig.getJoin().getMulticastConfig().isLoopbackModeEnabled());
Set<String> tis = networkConfig.getJoin().getMulticastConfig().getTrustedInterfaces();
assertEquals(1, tis.size());
assertEquals("10.10.10.*", tis.iterator().next());
assertFalse(networkConfig.getInterfaces().isEnabled());
assertEquals(1, networkConfig.getInterfaces().getInterfaces().size());
assertEquals("10.10.1.*", networkConfig.getInterfaces().getInterfaces().iterator().next());
TcpIpConfig tcp = networkConfig.getJoin().getTcpIpConfig();
assertNotNull(tcp);
assertTrue(tcp.isEnabled());
assertTrue(networkConfig.getSymmetricEncryptionConfig().isEnabled());
List<String> members = tcp.getMembers();
assertEquals(members.toString(), 2, members.size());
assertEquals("127.0.0.1:5700", members.get(0));
assertEquals("127.0.0.1:5701", members.get(1));
assertEquals("127.0.0.1:5700", tcp.getRequiredMember());
AwsConfig aws = networkConfig.getJoin().getAwsConfig();
assertFalse(aws.isEnabled());
assertEquals("sample-access-key", aws.getAccessKey());
assertEquals("sample-secret-key", aws.getSecretKey());
assertEquals("sample-region", aws.getRegion());
assertEquals("sample-group", aws.getSecurityGroupName());
assertEquals("sample-tag-key", aws.getTagKey());
assertEquals("sample-tag-value", aws.getTagValue());
assertEquals("sample-role", aws.getIamRole());
assertTrue("reuse-address", networkConfig.isReuseAddress());
DiscoveryConfig discoveryConfig = networkConfig.getJoin().getDiscoveryConfig();
assertTrue(discoveryConfig.getDiscoveryServiceProvider() instanceof DummyDiscoveryServiceProvider);
assertTrue(discoveryConfig.getNodeFilter() instanceof DummyNodeFilter);
List<DiscoveryStrategyConfig> discoveryStrategyConfigs = (List<DiscoveryStrategyConfig>) discoveryConfig.getDiscoveryStrategyConfigs();
assertEquals(2, discoveryStrategyConfigs.size());
DiscoveryStrategyConfig discoveryStrategyConfig = discoveryStrategyConfigs.get(0);
assertTrue(discoveryStrategyConfig.getDiscoveryStrategyFactory() instanceof DummyDiscoveryStrategyFactory);
assertEquals(3, discoveryStrategyConfig.getProperties().size());
assertEquals("foo", discoveryStrategyConfig.getProperties().get("key-string"));
assertEquals("123", discoveryStrategyConfig.getProperties().get("key-int"));
assertEquals("true", discoveryStrategyConfig.getProperties().get("key-boolean"));
DiscoveryStrategyConfig discoveryStrategyConfig2 = discoveryStrategyConfigs.get(1);
assertEquals(DummyDiscoveryStrategy.class.getName(), discoveryStrategyConfig2.getClassName());
assertEquals(1, discoveryStrategyConfig2.getProperties().size());
assertEquals("foo2", discoveryStrategyConfig2.getProperties().get("key-string"));
}
Aggregations