Search in sources :

Example 1 with InterfacesConfig

use of com.hazelcast.config.InterfacesConfig in project neo4j by neo4j.

the class HazelcastCoreTopologyService method createHazelcastInstance.

private HazelcastInstance createHazelcastInstance() {
    System.setProperty(WAIT_SECONDS_BEFORE_JOIN.getName(), "1");
    JoinConfig joinConfig = new JoinConfig();
    joinConfig.getMulticastConfig().setEnabled(false);
    joinConfig.getAwsConfig().setEnabled(false);
    TcpIpConfig tcpIpConfig = joinConfig.getTcpIpConfig();
    tcpIpConfig.setEnabled(true);
    List<AdvertisedSocketAddress> initialMembers = config.get(CausalClusteringSettings.initial_discovery_members);
    for (AdvertisedSocketAddress address : initialMembers) {
        tcpIpConfig.addMember(address.toString());
    }
    Setting<ListenSocketAddress> discovery_listen_address = CausalClusteringSettings.discovery_listen_address;
    ListenSocketAddress hazelcastAddress = config.get(discovery_listen_address);
    InterfacesConfig interfaces = new InterfacesConfig();
    interfaces.addInterface(hazelcastAddress.getHostname());
    NetworkConfig networkConfig = new NetworkConfig();
    networkConfig.setInterfaces(interfaces);
    networkConfig.setPort(hazelcastAddress.getPort());
    networkConfig.setJoin(joinConfig);
    networkConfig.setPortAutoIncrement(false);
    com.hazelcast.config.Config c = new com.hazelcast.config.Config();
    c.setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), String.valueOf(10_000));
    c.setProperty(MERGE_NEXT_RUN_DELAY_SECONDS.getName(), "10");
    c.setProperty(MERGE_FIRST_RUN_DELAY_SECONDS.getName(), "10");
    c.setProperty(INITIAL_MIN_CLUSTER_SIZE.getName(), String.valueOf(minimumClusterSizeThatCanTolerateOneFaultForExpectedClusterSize()));
    c.setProperty(LOGGING_TYPE.getName(), "none");
    c.setNetworkConfig(networkConfig);
    MemberAttributeConfig memberAttributeConfig = HazelcastClusterTopology.buildMemberAttributesForCore(myself, config);
    c.setMemberAttributeConfig(memberAttributeConfig);
    logConnectionInfo(initialMembers);
    JobScheduler.JobHandle logJob = scheduler.schedule("HazelcastHealth", HAZELCAST_IS_HEALTHY_TIMEOUT_MS, () -> log.warn("The server has not been able to connect in a timely fashion to the " + "cluster. Please consult the logs for more details. Rebooting the server may " + "solve the problem."));
    try {
        hazelcastInstance = Hazelcast.newHazelcastInstance(c);
        logJob.cancel(true);
    } catch (HazelcastException e) {
        String errorMessage = String.format("Hazelcast was unable to start with setting: %s = %s", discovery_listen_address.name(), config.get(discovery_listen_address));
        userLog.error(errorMessage);
        log.error(errorMessage, e);
        throw new RuntimeException(e);
    }
    List<String> groups = config.get(CausalClusteringSettings.server_groups);
    refreshGroups(hazelcastInstance, myself.getUuid().toString(), groups);
    return hazelcastInstance;
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) InterfacesConfig(com.hazelcast.config.InterfacesConfig) HazelcastException(com.hazelcast.core.HazelcastException) JoinConfig(com.hazelcast.config.JoinConfig) MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig) Config(org.neo4j.kernel.configuration.Config) NetworkConfig(com.hazelcast.config.NetworkConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) ListenSocketAddress(org.neo4j.helpers.ListenSocketAddress) JoinConfig(com.hazelcast.config.JoinConfig) MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig)

Example 2 with InterfacesConfig

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

the class ClientDiscoverySpiTest method testNodeStartup.

@Test
public void testNodeStartup() {
    Config config = new Config();
    config.setProperty("hazelcast.discovery.enabled", "true");
    config.getNetworkConfig().setPort(50001);
    InterfacesConfig interfaces = config.getNetworkConfig().getInterfaces();
    interfaces.clear();
    interfaces.setEnabled(true);
    interfaces.addInterface("127.0.0.1");
    List<DiscoveryNode> discoveryNodes = new CopyOnWriteArrayList<DiscoveryNode>();
    DiscoveryStrategyFactory factory = new CollectingDiscoveryStrategyFactory(discoveryNodes);
    JoinConfig join = config.getNetworkConfig().getJoin();
    join.getTcpIpConfig().setEnabled(false);
    join.getMulticastConfig().setEnabled(false);
    DiscoveryConfig discoveryConfig = join.getDiscoveryConfig();
    discoveryConfig.getDiscoveryStrategyConfigs().clear();
    DiscoveryStrategyConfig strategyConfig = new DiscoveryStrategyConfig(factory, Collections.<String, Comparable>emptyMap());
    discoveryConfig.addDiscoveryStrategyConfig(strategyConfig);
    final HazelcastInstance hazelcastInstance1 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance hazelcastInstance2 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance hazelcastInstance3 = Hazelcast.newHazelcastInstance(config);
    try {
        ClientConfig clientConfig = new ClientConfig();
        clientConfig.setProperty("hazelcast.discovery.enabled", "true");
        discoveryConfig = clientConfig.getNetworkConfig().getDiscoveryConfig();
        discoveryConfig.getDiscoveryStrategyConfigs().clear();
        strategyConfig = new DiscoveryStrategyConfig(factory, Collections.<String, Comparable>emptyMap());
        discoveryConfig.addDiscoveryStrategyConfig(strategyConfig);
        final HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
        assertNotNull(hazelcastInstance1);
        assertNotNull(hazelcastInstance2);
        assertNotNull(hazelcastInstance3);
        assertNotNull(client);
        assertTrueEventually(new AssertTask() {

            @Override
            public void run() throws Exception {
                assertEquals(3, hazelcastInstance1.getCluster().getMembers().size());
                assertEquals(3, hazelcastInstance2.getCluster().getMembers().size());
                assertEquals(3, hazelcastInstance3.getCluster().getMembers().size());
                assertEquals(3, client.getCluster().getMembers().size());
            }
        });
    } finally {
        HazelcastClient.shutdownAll();
        Hazelcast.shutdownAll();
    }
}
Also used : InterfacesConfig(com.hazelcast.config.InterfacesConfig) DiscoveryNode(com.hazelcast.spi.discovery.DiscoveryNode) SimpleDiscoveryNode(com.hazelcast.spi.discovery.SimpleDiscoveryNode) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) AwsConfig(com.hazelcast.config.AwsConfig) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) JoinConfig(com.hazelcast.config.JoinConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) DiscoveryStrategyFactory(com.hazelcast.spi.discovery.DiscoveryStrategyFactory) HazelcastInstance(com.hazelcast.core.HazelcastInstance) JoinConfig(com.hazelcast.config.JoinConfig) AssertTask(com.hazelcast.test.AssertTask) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with InterfacesConfig

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

the class ClientDiscoverySpiTest method testDiscoveryServiceLifecycleMethodsCalledWhenClientAndServerStartAndShutdown.

@Test
public void testDiscoveryServiceLifecycleMethodsCalledWhenClientAndServerStartAndShutdown() {
    //Given
    Config config = new Config();
    config.setProperty("hazelcast.discovery.enabled", "true");
    config.getNetworkConfig().setPort(50001);
    InterfacesConfig interfaces = config.getNetworkConfig().getInterfaces();
    interfaces.clear();
    interfaces.setEnabled(true);
    interfaces.addInterface("127.0.0.1");
    //Both server and client are using the same LifecycleDiscoveryStrategyFactory so latch count is set to 2.
    CountDownLatch startLatch = new CountDownLatch(2);
    CountDownLatch stopLatch = new CountDownLatch(2);
    List<DiscoveryNode> discoveryNodes = new CopyOnWriteArrayList<DiscoveryNode>();
    DiscoveryStrategyFactory factory = new LifecycleDiscoveryStrategyFactory(startLatch, stopLatch, discoveryNodes);
    JoinConfig join = config.getNetworkConfig().getJoin();
    join.getTcpIpConfig().setEnabled(false);
    join.getMulticastConfig().setEnabled(false);
    DiscoveryConfig discoveryConfig = join.getDiscoveryConfig();
    discoveryConfig.getDiscoveryStrategyConfigs().clear();
    DiscoveryStrategyConfig strategyConfig = new DiscoveryStrategyConfig(factory, Collections.<String, Comparable>emptyMap());
    discoveryConfig.addDiscoveryStrategyConfig(strategyConfig);
    final HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setProperty("hazelcast.discovery.enabled", "true");
    discoveryConfig = clientConfig.getNetworkConfig().getDiscoveryConfig();
    discoveryConfig.getDiscoveryStrategyConfigs().clear();
    strategyConfig = new DiscoveryStrategyConfig(factory, Collections.<String, Comparable>emptyMap());
    discoveryConfig.addDiscoveryStrategyConfig(strategyConfig);
    final HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
    assertNotNull(hazelcastInstance);
    assertNotNull(client);
    //When
    HazelcastClient.shutdownAll();
    Hazelcast.shutdownAll();
    //Then
    assertOpenEventually(startLatch);
    assertOpenEventually(stopLatch);
}
Also used : InterfacesConfig(com.hazelcast.config.InterfacesConfig) DiscoveryNode(com.hazelcast.spi.discovery.DiscoveryNode) SimpleDiscoveryNode(com.hazelcast.spi.discovery.SimpleDiscoveryNode) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) AwsConfig(com.hazelcast.config.AwsConfig) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) JoinConfig(com.hazelcast.config.JoinConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) CountDownLatch(java.util.concurrent.CountDownLatch) DiscoveryStrategyFactory(com.hazelcast.spi.discovery.DiscoveryStrategyFactory) HazelcastInstance(com.hazelcast.core.HazelcastInstance) JoinConfig(com.hazelcast.config.JoinConfig) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with InterfacesConfig

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

the class TcpIpJoiner method getRequiredMemberAddress.

private Address getRequiredMemberAddress() {
    TcpIpConfig tcpIpConfig = config.getNetworkConfig().getJoin().getTcpIpConfig();
    String host = tcpIpConfig.getRequiredMember();
    try {
        AddressHolder addressHolder = AddressUtil.getAddressHolder(host, config.getNetworkConfig().getPort());
        if (AddressUtil.isIpAddress(addressHolder.getAddress())) {
            return new Address(addressHolder.getAddress(), addressHolder.getPort());
        }
        InterfacesConfig interfaces = config.getNetworkConfig().getInterfaces();
        if (interfaces.isEnabled()) {
            InetAddress[] inetAddresses = InetAddress.getAllByName(addressHolder.getAddress());
            if (inetAddresses.length > 1) {
                for (InetAddress inetAddress : inetAddresses) {
                    if (AddressUtil.matchAnyInterface(inetAddress.getHostAddress(), interfaces.getInterfaces())) {
                        return new Address(inetAddress, addressHolder.getPort());
                    }
                }
            } else if (AddressUtil.matchAnyInterface(inetAddresses[0].getHostAddress(), interfaces.getInterfaces())) {
                return new Address(addressHolder.getAddress(), addressHolder.getPort());
            }
        } else {
            return new Address(addressHolder.getAddress(), addressHolder.getPort());
        }
    } catch (final Exception e) {
        logger.warning(e);
    }
    return null;
}
Also used : AddressHolder(com.hazelcast.util.AddressUtil.AddressHolder) InterfacesConfig(com.hazelcast.config.InterfacesConfig) Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) TcpIpConfig(com.hazelcast.config.TcpIpConfig) InetAddress(java.net.InetAddress) InvalidAddressException(com.hazelcast.util.AddressUtil.InvalidAddressException) UnknownHostException(java.net.UnknownHostException)

Example 5 with InterfacesConfig

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

the class MulticastJoinTest method test_whenInterfacesEnabled.

@Test
public void test_whenInterfacesEnabled() throws Exception {
    Config config = new Config();
    NetworkConfig networkConfig = config.getNetworkConfig();
    JoinConfig join = networkConfig.getJoin();
    join.getTcpIpConfig().setEnabled(false);
    MulticastConfig multicastConfig = join.getMulticastConfig();
    multicastConfig.setEnabled(true);
    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) MulticastConfig(com.hazelcast.config.MulticastConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) 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) MulticastConfig(com.hazelcast.config.MulticastConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

InterfacesConfig (com.hazelcast.config.InterfacesConfig)8 JoinConfig (com.hazelcast.config.JoinConfig)6 Config (com.hazelcast.config.Config)5 NetworkConfig (com.hazelcast.config.NetworkConfig)4 TcpIpConfig (com.hazelcast.config.TcpIpConfig)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 AwsConfig (com.hazelcast.config.AwsConfig)3 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)3 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)2 MulticastConfig (com.hazelcast.config.MulticastConfig)2 PartitionGroupConfig (com.hazelcast.config.PartitionGroupConfig)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 Address (com.hazelcast.nio.Address)2 DiscoveryNode (com.hazelcast.spi.discovery.DiscoveryNode)2 DiscoveryStrategyFactory (com.hazelcast.spi.discovery.DiscoveryStrategyFactory)2 SimpleDiscoveryNode (com.hazelcast.spi.discovery.SimpleDiscoveryNode)2