use of com.hazelcast.config.JoinConfig in project hazelcast by hazelcast.
the class ClientMemberAttributeTest method testAddAttributes.
@Test(timeout = 120000)
public void testAddAttributes() throws Exception {
Config c = new Config();
JoinConfig join = c.getNetworkConfig().getJoin();
join.getTcpIpConfig().addMember("127.0.0.1").setEnabled(true);
join.getMulticastConfig().setEnabled(false);
HazelcastInstance h1 = hazelcastFactory.newHazelcastInstance(c);
Member m1 = h1.getCluster().getLocalMember();
m1.setIntAttribute("Test", 123);
HazelcastInstance h2 = hazelcastFactory.newHazelcastInstance(c);
assertEquals(2, h2.getCluster().getMembers().size());
Member member = null;
for (Member m : h2.getCluster().getMembers()) {
if (m == h2.getCluster().getLocalMember()) {
continue;
}
member = m;
}
assertNotNull(member);
assertEquals(m1, member);
assertNotNull(member.getIntAttribute("Test"));
assertEquals(123, (int) member.getIntAttribute("Test"));
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
final CountDownLatch latch = new CountDownLatch(3);
final MembershipListener listener = new LatchMembershipListener(latch);
h2.getCluster().addMembershipListener(listener);
h1.getCluster().addMembershipListener(listener);
client.getCluster().addMembershipListener(listener);
m1.setIntAttribute("Test2", 321);
// Force sleep to distribute value
assertOpenEventually(latch);
assertNotNull(member.getIntAttribute("Test2"));
assertEquals(321, (int) member.getIntAttribute("Test2"));
boolean found = false;
Collection<Member> members = client.getCluster().getMembers();
for (Member m : members) {
if (m.equals(m1)) {
assertEquals(321, (int) m.getIntAttribute("Test2"));
found = true;
}
}
assertTrue(found);
}
use of com.hazelcast.config.JoinConfig in project hazelcast by hazelcast.
the class SplitBrainHandlerTest method testClusterShouldNotMergeDifferentGroupName.
@Test
public void testClusterShouldNotMergeDifferentGroupName() throws Exception {
Config config1 = new Config();
config1.setProperty(GroupProperty.MERGE_FIRST_RUN_DELAY_SECONDS.getName(), "5");
config1.setProperty(GroupProperty.MERGE_NEXT_RUN_DELAY_SECONDS.getName(), "3");
String firstGroupName = generateRandomString(10);
config1.getGroupConfig().setName(firstGroupName);
NetworkConfig networkConfig1 = config1.getNetworkConfig();
JoinConfig join1 = networkConfig1.getJoin();
join1.getMulticastConfig().setEnabled(true);
join1.getTcpIpConfig().addMember("127.0.0.1");
Config config2 = new Config();
config2.setProperty(GroupProperty.MERGE_FIRST_RUN_DELAY_SECONDS.getName(), "5");
config2.setProperty(GroupProperty.MERGE_NEXT_RUN_DELAY_SECONDS.getName(), "3");
String secondGroupName = generateRandomString(10);
config2.getGroupConfig().setName(secondGroupName);
NetworkConfig networkConfig2 = config2.getNetworkConfig();
JoinConfig join2 = networkConfig2.getJoin();
join2.getMulticastConfig().setEnabled(true);
join2.getTcpIpConfig().addMember("127.0.0.1");
HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config1);
HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config2);
LifecycleCountingListener l = new LifecycleCountingListener();
h2.getLifecycleService().addLifecycleListener(l);
assertEquals(1, h1.getCluster().getMembers().size());
assertEquals(1, h2.getCluster().getMembers().size());
HazelcastTestSupport.sleepSeconds(10);
assertEquals(0, l.getCount(LifecycleState.MERGING));
assertEquals(0, l.getCount(LifecycleState.MERGED));
assertEquals(1, h1.getCluster().getMembers().size());
assertEquals(1, h2.getCluster().getMembers().size());
}
use of com.hazelcast.config.JoinConfig in project cas by apereo.
the class HazelcastConfigurationFactory method createDiscoveryJoinConfig.
private JoinConfig createDiscoveryJoinConfig(final Config config, final HazelcastClusterProperties cluster) {
final JoinConfig joinConfig = new JoinConfig();
LOGGER.debug("Disabling multicast and TCP/IP configuration for discovery");
joinConfig.getMulticastConfig().setEnabled(false);
joinConfig.getTcpIpConfig().setEnabled(false);
final DiscoveryConfig discoveryConfig = new DiscoveryConfig();
final DiscoveryStrategyConfig strategyConfig = locateDiscoveryStrategyConfig(cluster);
LOGGER.debug("Creating discovery strategy configuration as [{}]", strategyConfig);
discoveryConfig.setDiscoveryStrategyConfigs(CollectionUtils.wrap(strategyConfig));
joinConfig.setDiscoveryConfig(discoveryConfig);
return joinConfig;
}
use of com.hazelcast.config.JoinConfig in project cas by apereo.
the class HazelcastConfigurationFactory method createDefaultJoinConfig.
private static JoinConfig createDefaultJoinConfig(final HazelcastClusterProperties cluster) {
val tcpIpConfig = new TcpIpConfig().setEnabled(cluster.getNetwork().isTcpipEnabled()).setMembers(cluster.getNetwork().getMembers()).setConnectionTimeoutSeconds(cluster.getCore().getTimeout());
LOGGER.trace("Created Hazelcast TCP/IP configuration [{}] for members [{}]", tcpIpConfig, cluster.getNetwork().getMembers());
val multicast = cluster.getDiscovery().getMulticast();
val multicastConfig = new MulticastConfig().setEnabled(multicast.isEnabled());
if (multicast.isEnabled()) {
LOGGER.debug("Created Hazelcast Multicast configuration [{}]", multicastConfig);
multicastConfig.setMulticastGroup(multicast.getGroup());
multicastConfig.setMulticastPort(multicast.getPort());
val trustedInterfaces = StringUtils.commaDelimitedListToSet(multicast.getTrustedInterfaces());
if (!trustedInterfaces.isEmpty()) {
multicastConfig.setTrustedInterfaces(trustedInterfaces);
}
multicastConfig.setMulticastTimeoutSeconds(multicast.getTimeout());
multicastConfig.setMulticastTimeToLive(multicast.getTimeToLive());
} else {
LOGGER.debug("Skipped Hazelcast Multicast configuration since feature is disabled");
}
return new JoinConfig().setMulticastConfig(multicastConfig).setTcpIpConfig(tcpIpConfig);
}
use of com.hazelcast.config.JoinConfig in project cas by apereo.
the class HazelcastConfigurationFactory method build.
/**
* Build config.
*
* @param hz the hz
* @return the config
*/
public static Config build(final BaseHazelcastProperties hz) {
val cluster = hz.getCluster();
val config = new Config();
config.setLicenseKey(hz.getCore().getLicenseKey());
if (cluster.getCore().getCpMemberCount() > 0) {
config.getCPSubsystemConfig().setCPMemberCount(cluster.getCore().getCpMemberCount());
}
buildManagementCenterConfig(hz, config);
val networkConfig = new NetworkConfig().setPort(cluster.getNetwork().getPort()).setPortAutoIncrement(cluster.getNetwork().isPortAutoIncrement());
buildNetworkSslConfig(networkConfig, hz);
if (StringUtils.hasText(cluster.getNetwork().getNetworkInterfaces())) {
networkConfig.getInterfaces().setEnabled(true);
StringUtils.commaDelimitedListToSet(cluster.getNetwork().getNetworkInterfaces()).forEach(faceIp -> networkConfig.getInterfaces().addInterface(faceIp));
}
if (StringUtils.hasText(cluster.getNetwork().getLocalAddress())) {
config.setProperty(BaseHazelcastProperties.HAZELCAST_LOCAL_ADDRESS_PROP, cluster.getNetwork().getLocalAddress());
}
if (StringUtils.hasText(cluster.getNetwork().getPublicAddress())) {
config.setProperty(BaseHazelcastProperties.HAZELCAST_PUBLIC_ADDRESS_PROP, cluster.getNetwork().getPublicAddress());
networkConfig.setPublicAddress(cluster.getNetwork().getPublicAddress());
}
cluster.getNetwork().getOutboundPorts().forEach(networkConfig::addOutboundPortDefinition);
if (cluster.getWanReplication().isEnabled()) {
if (!StringUtils.hasText(hz.getCore().getLicenseKey())) {
throw new IllegalArgumentException("Cannot activate WAN replication, a Hazelcast enterprise feature, without a license key");
}
LOGGER.warn("Using Hazelcast WAN Replication requires a Hazelcast Enterprise subscription. Make sure you " + "have acquired the proper license, SDK and tooling from Hazelcast before activating this feature.");
buildWanReplicationSettingsForConfig(hz, config);
}
val joinConfig = cluster.getDiscovery().isEnabled() ? createDiscoveryJoinConfig(config, cluster, networkConfig) : createDefaultJoinConfig(cluster);
LOGGER.trace("Created Hazelcast join configuration [{}]", joinConfig);
networkConfig.setJoin(joinConfig);
LOGGER.trace("Created Hazelcast network configuration [{}]", networkConfig);
config.setNetworkConfig(networkConfig);
config.getSerializationConfig().setEnableCompression(hz.getCore().isEnableCompression());
val instanceName = StringUtils.hasText(cluster.getCore().getInstanceName()) ? SpringExpressionLanguageValueResolver.getInstance().resolve(cluster.getCore().getInstanceName()) : UUID.randomUUID().toString();
LOGGER.trace("Configuring Hazelcast instance name [{}]", instanceName);
return config.setInstanceName(instanceName).setProperty(BaseHazelcastProperties.HAZELCAST_DISCOVERY_ENABLED_PROP, BooleanUtils.toStringTrueFalse(cluster.getDiscovery().isEnabled())).setProperty(BaseHazelcastProperties.IPV4_STACK_PROP, String.valueOf(cluster.getNetwork().isIpv4Enabled())).setProperty(BaseHazelcastProperties.LOGGING_TYPE_PROP, cluster.getCore().getLoggingType()).setProperty(BaseHazelcastProperties.MAX_HEARTBEAT_SECONDS_PROP, String.valueOf(cluster.getCore().getMaxNoHeartbeatSeconds()));
}
Aggregations