Search in sources :

Example 21 with JoinConfig

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

the class RestTest method setup.

@Before
public void setup() {
    config.setProperty(GroupProperty.REST_ENABLED.getName(), "true");
    int firstPort = port.getAndIncrement();
    int secondPort = port.getAndIncrement();
    // we start pairs of HazelcastInstances which form a cluster to have remote invocations for all operations
    JoinConfig join = config.getNetworkConfig().getJoin();
    join.getMulticastConfig().setEnabled(false);
    join.getTcpIpConfig().setEnabled(true).addMember("127.0.0.1:" + firstPort).addMember("127.0.0.1:" + secondPort);
    config.getNetworkConfig().setPort(firstPort);
    instance = Hazelcast.newHazelcastInstance(config);
    config.getNetworkConfig().setPort(secondPort);
    remoteInstance = Hazelcast.newHazelcastInstance(config);
    communicator = new HTTPCommunicator(instance);
}
Also used : JoinConfig(com.hazelcast.config.JoinConfig) Before(org.junit.Before)

Example 22 with JoinConfig

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

the class DiscoverySpiTest method testNodeFilter_from_xml.

@Test
public void testNodeFilter_from_xml() 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();
    DiscoveryConfig discoveryConfig = joinConfig.getDiscoveryConfig();
    Address address = new Address("localhost", 5701);
    DiscoveryServiceSettings settings = buildDiscoveryServiceSettings(address, discoveryConfig, DiscoveryMode.Client);
    DiscoveryServiceProvider provider = new DefaultDiscoveryServiceProvider();
    DiscoveryService discoveryService = provider.newDiscoveryService(settings);
    discoveryService.start();
    discoveryService.discoverNodes();
    discoveryService.destroy();
    Field nodeFilterField = DefaultDiscoveryService.class.getDeclaredField("nodeFilter");
    nodeFilterField.setAccessible(true);
    TestNodeFilter nodeFilter = (TestNodeFilter) nodeFilterField.get(discoveryService);
    assertEquals(4, nodeFilter.getNodes().size());
}
Also used : XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) 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) DiscoveryServiceSettings(com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings) DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) Field(java.lang.reflect.Field) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) JoinConfig(com.hazelcast.config.JoinConfig) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) DiscoveryService(com.hazelcast.spi.discovery.integration.DiscoveryService) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with JoinConfig

use of com.hazelcast.config.JoinConfig 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 24 with JoinConfig

use of com.hazelcast.config.JoinConfig 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 25 with JoinConfig

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

the class SplitBrainHandlerTest method buildConfig.

private Config buildConfig(final String groupName, final boolean liteMember) {
    Config config = new Config();
    config.setProperty(GroupProperty.MERGE_FIRST_RUN_DELAY_SECONDS.getName(), "5");
    config.setProperty(GroupProperty.MERGE_NEXT_RUN_DELAY_SECONDS.getName(), "3");
    config.getGroupConfig().setName(groupName);
    config.setLiteMember(liteMember);
    NetworkConfig networkConfig = config.getNetworkConfig();
    JoinConfig join = networkConfig.getJoin();
    join.getMulticastConfig().setEnabled(true);
    config.getMapConfig("default").setMergePolicy(PassThroughMergePolicy.class.getName());
    return config;
}
Also used : PassThroughMergePolicy(com.hazelcast.map.merge.PassThroughMergePolicy) ListenerConfig(com.hazelcast.config.ListenerConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) NetworkConfig(com.hazelcast.config.NetworkConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) JoinConfig(com.hazelcast.config.JoinConfig)

Aggregations

JoinConfig (com.hazelcast.config.JoinConfig)37 Config (com.hazelcast.config.Config)28 Test (org.junit.Test)20 NetworkConfig (com.hazelcast.config.NetworkConfig)19 QuickTest (com.hazelcast.test.annotation.QuickTest)19 InterfacesConfig (com.hazelcast.config.InterfacesConfig)14 TcpIpConfig (com.hazelcast.config.TcpIpConfig)11 HazelcastInstance (com.hazelcast.core.HazelcastInstance)11 ListenerConfig (com.hazelcast.config.ListenerConfig)9 PartitionGroupConfig (com.hazelcast.config.PartitionGroupConfig)9 ClientConfig (com.hazelcast.client.config.ClientConfig)8 MulticastConfig (com.hazelcast.config.MulticastConfig)8 MemberAttributeConfig (com.hazelcast.config.MemberAttributeConfig)6 AwsConfig (com.hazelcast.config.AwsConfig)5 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)5 Member (com.hazelcast.core.Member)5 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)4 MembershipListener (com.hazelcast.core.MembershipListener)4