Search in sources :

Example 16 with NetworkConfig

use of com.hazelcast.config.NetworkConfig 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 17 with NetworkConfig

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

the class MapWordCountAggregationPerformanceTest method buildCluster.

private static HazelcastInstance buildCluster(int memberCount) {
    Config config = new Config();
    NetworkConfig networkConfig = config.getNetworkConfig();
    networkConfig.getJoin().getMulticastConfig().setEnabled(false);
    networkConfig.getJoin().getTcpIpConfig().setEnabled(true);
    networkConfig.getJoin().getTcpIpConfig().setMembers(singletonList("127.0.0.1"));
    MapConfig mapConfig = new MapConfig();
    mapConfig.setInMemoryFormat(InMemoryFormat.OBJECT);
    mapConfig.setName(MAP_NAME);
    mapConfig.setBackupCount(0);
    config.addMapConfig(mapConfig);
    config.setProperty("hazelcast.query.predicate.parallel.evaluation", "true");
    config.setProperty("hazelcast.aggregation.accumulation.parallel.evaluation", "true");
    HazelcastInstance[] hazelcastInstances = new HazelcastInstance[memberCount];
    for (int i = 0; i < memberCount; i++) {
        hazelcastInstances[i] = Hazelcast.newHazelcastInstance(config);
    }
    return hazelcastInstances[0];
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) MapConfig(com.hazelcast.config.MapConfig)

Example 18 with NetworkConfig

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

the class PartitionServiceBeanDTOTest method getConfig.

@Override
protected Config getConfig() {
    Config config = new Config();
    // Join is disabled intentionally. will start standalone HazelcastInstance.
    NetworkConfig networkConfig = config.getNetworkConfig();
    JoinConfig join = networkConfig.getJoin();
    join.getMulticastConfig().setEnabled(false);
    join.getTcpIpConfig().setEnabled(false);
    return config;
}
Also used : Config(com.hazelcast.config.Config) NetworkConfig(com.hazelcast.config.NetworkConfig) JoinConfig(com.hazelcast.config.JoinConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) JoinConfig(com.hazelcast.config.JoinConfig)

Example 19 with NetworkConfig

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

the class DefaultAddressPicker method getInterfaces.

private Collection<InterfaceDefinition> getInterfaces() throws UnknownHostException {
    NetworkConfig networkConfig = config.getNetworkConfig();
    // address -> domain
    Map<String, String> addressDomainMap;
    TcpIpConfig tcpIpConfig = networkConfig.getJoin().getTcpIpConfig();
    if (tcpIpConfig.isEnabled()) {
        // LinkedHashMap is to guarantee order
        addressDomainMap = new LinkedHashMap<String, String>();
        Collection<String> possibleAddresses = TcpIpJoiner.getConfigurationMembers(config);
        for (String possibleAddress : possibleAddresses) {
            String addressHolder = AddressUtil.getAddressHolder(possibleAddress).getAddress();
            if (AddressUtil.isIpAddress(addressHolder)) {
                // there may be a domain registered for this address
                if (!addressDomainMap.containsKey(addressHolder)) {
                    addressDomainMap.put(addressHolder, null);
                }
            } else {
                try {
                    Collection<String> addresses = resolveDomainNames(addressHolder);
                    for (String address : addresses) {
                        addressDomainMap.put(address, addressHolder);
                    }
                } catch (UnknownHostException e) {
                    logger.warning("Cannot resolve hostname: '" + addressHolder + "'");
                }
            }
        }
    } else {
        addressDomainMap = Collections.emptyMap();
    }
    Collection<InterfaceDefinition> interfaces = new HashSet<InterfaceDefinition>();
    if (networkConfig.getInterfaces().isEnabled()) {
        Collection<String> configInterfaces = networkConfig.getInterfaces().getInterfaces();
        for (String configInterface : configInterfaces) {
            if (AddressUtil.isIpAddress(configInterface)) {
                String hostname = findHostnameMatchingInterface(addressDomainMap, configInterface);
                interfaces.add(new InterfaceDefinition(hostname, configInterface));
            } else {
                logger.info("'" + configInterface + "' is not an IP address! Removing from interface list.");
            }
        }
        logger.info("Interfaces is enabled, trying to pick one address matching to one of: " + interfaces);
    } else if (tcpIpConfig.isEnabled()) {
        for (Entry<String, String> entry : addressDomainMap.entrySet()) {
            interfaces.add(new InterfaceDefinition(entry.getValue(), entry.getKey()));
        }
        logger.info("Interfaces is disabled, trying to pick one address from TCP-IP config addresses: " + interfaces);
    }
    return interfaces;
}
Also used : Entry(java.util.Map.Entry) UnknownHostException(java.net.UnknownHostException) NetworkConfig(com.hazelcast.config.NetworkConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) HashSet(java.util.HashSet)

Example 20 with NetworkConfig

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

the class TcpIpJoiner method getPossibleAddresses.

@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity" })
protected Collection<Address> getPossibleAddresses() {
    final Collection<String> possibleMembers = getMembers();
    final Set<Address> possibleAddresses = new HashSet<Address>();
    final NetworkConfig networkConfig = config.getNetworkConfig();
    for (String possibleMember : possibleMembers) {
        AddressHolder addressHolder = AddressUtil.getAddressHolder(possibleMember);
        try {
            boolean portIsDefined = addressHolder.getPort() != -1 || !networkConfig.isPortAutoIncrement();
            int count = portIsDefined ? 1 : maxPortTryCount;
            int port = addressHolder.getPort() != -1 ? addressHolder.getPort() : networkConfig.getPort();
            AddressMatcher addressMatcher = null;
            try {
                addressMatcher = AddressUtil.getAddressMatcher(addressHolder.getAddress());
            } catch (InvalidAddressException ignore) {
                EmptyStatement.ignore(ignore);
            }
            if (addressMatcher != null) {
                final Collection<String> matchedAddresses;
                if (addressMatcher.isIPv4()) {
                    matchedAddresses = AddressUtil.getMatchingIpv4Addresses(addressMatcher);
                } else {
                    // for IPv6 we are not doing wildcard matching
                    matchedAddresses = Collections.singleton(addressHolder.getAddress());
                }
                for (String matchedAddress : matchedAddresses) {
                    addPossibleAddresses(possibleAddresses, null, InetAddress.getByName(matchedAddress), port, count);
                }
            } else {
                final String host = addressHolder.getAddress();
                final InterfacesConfig interfaces = networkConfig.getInterfaces();
                if (interfaces.isEnabled()) {
                    final InetAddress[] inetAddresses = InetAddress.getAllByName(host);
                    for (InetAddress inetAddress : inetAddresses) {
                        if (AddressUtil.matchAnyInterface(inetAddress.getHostAddress(), interfaces.getInterfaces())) {
                            addPossibleAddresses(possibleAddresses, host, inetAddress, port, count);
                        }
                    }
                } else {
                    addPossibleAddresses(possibleAddresses, host, null, port, count);
                }
            }
        } catch (UnknownHostException e) {
            logger.warning("Cannot resolve hostname '" + addressHolder.getAddress() + "'. Please make sure host is valid and reachable.");
            if (logger.isFineEnabled()) {
                logger.fine("Error during resolving possible target!", e);
            }
        }
    }
    possibleAddresses.remove(node.getThisAddress());
    return possibleAddresses;
}
Also used : InterfacesConfig(com.hazelcast.config.InterfacesConfig) Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) UnknownHostException(java.net.UnknownHostException) NetworkConfig(com.hazelcast.config.NetworkConfig) AddressMatcher(com.hazelcast.util.AddressUtil.AddressMatcher) AddressHolder(com.hazelcast.util.AddressUtil.AddressHolder) InetAddress(java.net.InetAddress) InvalidAddressException(com.hazelcast.util.AddressUtil.InvalidAddressException) HashSet(java.util.HashSet)

Aggregations

NetworkConfig (com.hazelcast.config.NetworkConfig)34 Config (com.hazelcast.config.Config)25 JoinConfig (com.hazelcast.config.JoinConfig)23 Test (org.junit.Test)13 TcpIpConfig (com.hazelcast.config.TcpIpConfig)11 InterfacesConfig (com.hazelcast.config.InterfacesConfig)10 QuickTest (com.hazelcast.test.annotation.QuickTest)10 PartitionGroupConfig (com.hazelcast.config.PartitionGroupConfig)9 ListenerConfig (com.hazelcast.config.ListenerConfig)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)8 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance)6 MulticastConfig (com.hazelcast.config.MulticastConfig)4 MembershipEvent (com.hazelcast.core.MembershipEvent)4 Node (com.hazelcast.instance.Node)4 UnknownHostException (java.net.UnknownHostException)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 MembershipAdapter (com.hazelcast.core.MembershipAdapter)3 FirewallingTcpIpConnectionManager (com.hazelcast.nio.tcp.FirewallingTcpIpConnectionManager)3 NightlyTest (com.hazelcast.test.annotation.NightlyTest)3 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)2