Search in sources :

Example 51 with JoinConfig

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ListenerConfig(com.hazelcast.config.ListenerConfig) JoinConfig(com.hazelcast.config.JoinConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig) JoinConfig(com.hazelcast.config.JoinConfig) CountDownLatch(java.util.concurrent.CountDownLatch) MembershipListener(com.hazelcast.core.MembershipListener) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 52 with JoinConfig

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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance) ListenerConfig(com.hazelcast.config.ListenerConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) NetworkConfig(com.hazelcast.config.NetworkConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) JoinConfig(com.hazelcast.config.JoinConfig) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 53 with JoinConfig

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;
}
Also used : DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) JoinConfig(com.hazelcast.config.JoinConfig) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig)

Example 54 with 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);
}
Also used : lombok.val(lombok.val) MulticastConfig(com.hazelcast.config.MulticastConfig) JoinConfig(com.hazelcast.config.JoinConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig)

Example 55 with JoinConfig

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()));
}
Also used : lombok.val(lombok.val) SSLConfig(com.hazelcast.config.SSLConfig) WanSyncConfig(com.hazelcast.config.WanSyncConfig) MapConfig(com.hazelcast.config.MapConfig) WanBatchPublisherConfig(com.hazelcast.config.WanBatchPublisherConfig) JoinConfig(com.hazelcast.config.JoinConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) NamedConfig(com.hazelcast.config.NamedConfig) Config(com.hazelcast.config.Config) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) ManagementCenterConfig(com.hazelcast.config.ManagementCenterConfig) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) WanReplicationConfig(com.hazelcast.config.WanReplicationConfig) MergePolicyConfig(com.hazelcast.config.MergePolicyConfig) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) PartitionGroupConfig(com.hazelcast.config.PartitionGroupConfig) NetworkConfig(com.hazelcast.config.NetworkConfig)

Aggregations

JoinConfig (com.hazelcast.config.JoinConfig)90 Config (com.hazelcast.config.Config)64 NetworkConfig (com.hazelcast.config.NetworkConfig)32 Test (org.junit.Test)32 TcpIpConfig (com.hazelcast.config.TcpIpConfig)27 QuickTest (com.hazelcast.test.annotation.QuickTest)20 InterfacesConfig (com.hazelcast.config.InterfacesConfig)18 HazelcastInstance (com.hazelcast.core.HazelcastInstance)18 MulticastConfig (com.hazelcast.config.MulticastConfig)15 PartitionGroupConfig (com.hazelcast.config.PartitionGroupConfig)15 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)13 SlowTest (com.hazelcast.test.annotation.SlowTest)12 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)11 RealmConfig (com.hazelcast.config.security.RealmConfig)11 ClientConfig (com.hazelcast.client.config.ClientConfig)9 ListenerConfig (com.hazelcast.config.ListenerConfig)8 AwsConfig (com.hazelcast.config.AwsConfig)7 MemberAttributeConfig (com.hazelcast.config.MemberAttributeConfig)7 ServerSocketEndpointConfig (com.hazelcast.config.ServerSocketEndpointConfig)6 CountDownLatch (java.util.concurrent.CountDownLatch)6