use of com.hazelcast.config.JoinConfig 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.getAutoDetectionConfig().setEnabled(false);
DiscoveryConfig discoveryConfig = join.getDiscoveryConfig();
discoveryConfig.getDiscoveryStrategyConfigs().clear();
DiscoveryStrategyConfig strategyConfig = new DiscoveryStrategyConfig(factory, Collections.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.emptyMap());
discoveryConfig.addDiscoveryStrategyConfig(strategyConfig);
final HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
assertNotNull(hazelcastInstance1);
assertNotNull(hazelcastInstance2);
assertNotNull(hazelcastInstance3);
assertNotNull(client);
assertClusterSizeEventually(3, hazelcastInstance1, hazelcastInstance2, hazelcastInstance3, client);
} finally {
HazelcastClient.shutdownAll();
Hazelcast.shutdownAll();
}
}
use of com.hazelcast.config.JoinConfig 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.getAutoDetectionConfig().setEnabled(false);
DiscoveryConfig discoveryConfig = join.getDiscoveryConfig();
discoveryConfig.getDiscoveryStrategyConfigs().clear();
DiscoveryStrategyConfig strategyConfig = new DiscoveryStrategyConfig(factory, Collections.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.emptyMap());
discoveryConfig.addDiscoveryStrategyConfig(strategyConfig);
final HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
assertNotNull(hazelcastInstance);
assertNotNull(client);
// When
HazelcastClient.shutdownAll();
Hazelcast.shutdownAll();
// Then
assertOpenEventually(startLatch);
assertOpenEventually(stopLatch);
}
use of com.hazelcast.config.JoinConfig in project hazelcast by hazelcast.
the class CacheClientListenerTest method getCachingProvider.
@Override
protected CachingProvider getCachingProvider() {
Config config = new Config();
JoinConfig joinConfig = config.getNetworkConfig().getJoin();
joinConfig.getAwsConfig().setEnabled(false);
joinConfig.getMulticastConfig().setEnabled(false);
joinConfig.getTcpIpConfig().setEnabled(false);
Hazelcast.newHazelcastInstance(config);
Hazelcast.newHazelcastInstance(config);
ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().addAddress("127.0.0.1");
hazelcastInstance = HazelcastClient.newHazelcastClient(clientConfig);
return createClientCachingProvider(hazelcastInstance);
}
use of com.hazelcast.config.JoinConfig in project sonarqube by SonarSource.
the class HazelcastMemberBuilder method build.
public HazelcastMember build() {
Config config = new Config();
// do not use the value defined by property sonar.cluster.name.
// Hazelcast does not fail when joining a cluster with different name.
// Apparently this behavior exists since Hazelcast 3.8.2 (see note
// at http://docs.hazelcast.org/docs/3.8.6/manual/html-single/index.html#creating-cluster-groups)
config.setClusterName("SonarQube");
// Configure network
NetworkConfig netConfig = config.getNetworkConfig();
netConfig.setPort(port).setPortAutoIncrement(false).setReuseAddress(true);
netConfig.getInterfaces().setEnabled(true).setInterfaces(singletonList(requireNonNull(networkInterface, "Network interface is missing")));
JoinConfig joinConfig = netConfig.getJoin();
joinConfig.getAwsConfig().setEnabled(false);
joinConfig.getMulticastConfig().setEnabled(false);
if (KUBERNETES.equals(type)) {
joinConfig.getKubernetesConfig().setEnabled(true).setProperty("service-dns", requireNonNull(members, "Service DNS is missing")).setProperty("service-port", CLUSTER_NODE_HZ_PORT.getDefaultValue());
} else {
List<String> addressesWithDefaultPorts = Stream.of(this.members.split(",")).filter(host -> !host.isBlank()).map(String::trim).map(HazelcastMemberBuilder::applyDefaultPortToHost).collect(Collectors.toList());
joinConfig.getTcpIpConfig().setEnabled(true);
joinConfig.getTcpIpConfig().setMembers(requireNonNull(addressesWithDefaultPorts, "Members are missing"));
}
// We are not using the partition group of Hazelcast, so disabling it
config.getPartitionGroupConfig().setEnabled(false);
// Tweak HazelCast configuration
config.setProperty("hazelcast.tcp.join.port.try.count", "10").setProperty("hazelcast.socket.bind.any", "false").setProperty("hazelcast.phone.home.enabled", "false").setProperty("hazelcast.logging.type", "slf4j");
MemberAttributeConfig attributes = config.getMemberAttributeConfig();
attributes.setAttribute(Attribute.NODE_NAME.getKey(), requireNonNull(nodeName, "Node name is missing"));
attributes.setAttribute(Attribute.PROCESS_KEY.getKey(), requireNonNull(processId, "Process key is missing").getKey());
return new HazelcastMemberImpl(Hazelcast.newHazelcastInstance(config));
}
use of com.hazelcast.config.JoinConfig in project hazelcast by hazelcast.
the class HazelcastBootstrap method createStandaloneInstance.
private static HazelcastInstance createStandaloneInstance() {
configureLogging();
LOGGER.info("Bootstrapped instance requested but application wasn't called from hazelcast submit script. " + "Creating a standalone Hazelcast instance instead. Jet is enabled in this standalone instance.");
Config config = Config.load();
// enable jet
config.getJetConfig().setEnabled(true);
// Disable Hazelcast from binding to all local network interfaces
config.setProperty(ClusterProperty.SOCKET_BIND_ANY.getName(), "false");
// Enable the interfaces approach for binding, and add localhost to available interfaces to bind
config.getNetworkConfig().getInterfaces().setEnabled(true).addInterface("127.0.0.1");
// turn off all discovery to make sure node doesn't join any existing cluster
config.setProperty("hazelcast.wait.seconds.before.join", "0");
config.getAdvancedNetworkConfig().setEnabled(false);
JoinConfig join = config.getNetworkConfig().getJoin();
join.getAutoDetectionConfig().setEnabled(false);
join.getMulticastConfig().setEnabled(false);
join.getTcpIpConfig().setEnabled(false);
join.getAwsConfig().setEnabled(false);
join.getGcpConfig().setEnabled(false);
join.getAzureConfig().setEnabled(false);
join.getKubernetesConfig().setEnabled(false);
join.getEurekaConfig().setEnabled(false);
join.setDiscoveryConfig(new DiscoveryConfig());
return Hazelcast.newHazelcastInstance(config);
}
Aggregations