Search in sources :

Example 1 with TcpIpConfig

use of com.hazelcast.config.TcpIpConfig 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 TcpIpConfig

use of com.hazelcast.config.TcpIpConfig 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 3 with TcpIpConfig

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

the class JoinStressTest method initNetworkConfig.

private void initNetworkConfig(NetworkConfig networkConfig, int basePort, int portSeed, boolean multicast, int nodeCount) {
    networkConfig.setPortAutoIncrement(false);
    networkConfig.setPort(basePort + portSeed);
    JoinConfig join = networkConfig.getJoin();
    MulticastConfig multicastConfig = join.getMulticastConfig();
    multicastConfig.setEnabled(multicast);
    multicastConfig.setMulticastTimeoutSeconds(5);
    TcpIpConfig tcpIpConfig = join.getTcpIpConfig();
    tcpIpConfig.setEnabled(!multicast);
    tcpIpConfig.setConnectionTimeoutSeconds(5);
    List<String> members = new ArrayList<String>(nodeCount);
    for (int i = 0; i < nodeCount; i++) {
        members.add("127.0.0.1:" + (basePort + i));
    }
    Collections.sort(members);
    tcpIpConfig.setMembers(members);
}
Also used : JoinConfig(com.hazelcast.config.JoinConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) ArrayList(java.util.ArrayList) TcpIpConfig(com.hazelcast.config.TcpIpConfig)

Example 4 with TcpIpConfig

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

the class TcpIpJoinTest method test_whenNoExplicitPortConfigured.

@Test
public void test_whenNoExplicitPortConfigured() 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");
    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 5 with TcpIpConfig

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

the class TcpIpJoinTest method test_whenHostUnresolvable.

@Test
public void test_whenHostUnresolvable() {
    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("localhost");
    tcpIpConfig.addMember("nonexistinghost");
    HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
    assertClusterSize(1, hz);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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)

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