Search in sources :

Example 6 with TcpIpConfig

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);
}
Also used : Config(com.hazelcast.config.Config) NetworkConfig(com.hazelcast.config.NetworkConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) JoinConfig(com.hazelcast.config.JoinConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) PartitionGroupConfig(com.hazelcast.config.PartitionGroupConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) JoinConfig(com.hazelcast.config.JoinConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with TcpIpConfig

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()));
}
Also used : HazelcastProperties(org.apereo.cas.configuration.model.support.hazelcast.HazelcastProperties) XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) MulticastConfig(com.hazelcast.config.MulticastConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) JoinConfig(com.hazelcast.config.JoinConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) URL(java.net.URL)

Example 8 with TcpIpConfig

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"));
}
Also used : AwsConfig(com.hazelcast.config.AwsConfig) XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) InputStream(java.io.InputStream) AwsConfig(com.hazelcast.config.AwsConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) JoinConfig(com.hazelcast.config.JoinConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with TcpIpConfig

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);
}
Also used : InterfacesConfig(com.hazelcast.config.InterfacesConfig) Config(com.hazelcast.config.Config) NetworkConfig(com.hazelcast.config.NetworkConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) JoinConfig(com.hazelcast.config.JoinConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) PartitionGroupConfig(com.hazelcast.config.PartitionGroupConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) JoinConfig(com.hazelcast.config.JoinConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with TcpIpConfig

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"));
}
Also used : AwsConfig(com.hazelcast.config.AwsConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) Iterator(java.util.Iterator) List(java.util.List) IList(com.hazelcast.core.IList) TcpIpConfig(com.hazelcast.config.TcpIpConfig) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) Test(org.junit.Test) QuickTest(com.hazelcast.test.annotation.QuickTest)

Aggregations

TcpIpConfig (com.hazelcast.config.TcpIpConfig)12 JoinConfig (com.hazelcast.config.JoinConfig)8 NetworkConfig (com.hazelcast.config.NetworkConfig)8 InterfacesConfig (com.hazelcast.config.InterfacesConfig)7 Config (com.hazelcast.config.Config)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 PartitionGroupConfig (com.hazelcast.config.PartitionGroupConfig)4 MulticastConfig (com.hazelcast.config.MulticastConfig)3 AwsConfig (com.hazelcast.config.AwsConfig)2 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)2 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)2 XmlConfigBuilder (com.hazelcast.config.XmlConfigBuilder)2 UnknownHostException (java.net.UnknownHostException)2 HashSet (java.util.HashSet)2 MapConfig (com.hazelcast.config.MapConfig)1 MaxSizeConfig (com.hazelcast.config.MaxSizeConfig)1 MemberAttributeConfig (com.hazelcast.config.MemberAttributeConfig)1 HazelcastException (com.hazelcast.core.HazelcastException)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1