Search in sources :

Example 1 with MemberAttributeConfig

use of com.hazelcast.config.MemberAttributeConfig in project neo4j by neo4j.

the class HazelcastClusterTopology method buildMemberAttributesForCore.

static MemberAttributeConfig buildMemberAttributesForCore(MemberId myself, Config config) {
    MemberAttributeConfig memberAttributeConfig = new MemberAttributeConfig();
    memberAttributeConfig.setStringAttribute(MEMBER_UUID, myself.getUuid().toString());
    AdvertisedSocketAddress discoveryAddress = config.get(CausalClusteringSettings.discovery_advertised_address);
    memberAttributeConfig.setStringAttribute(DISCOVERY_SERVER, discoveryAddress.toString());
    AdvertisedSocketAddress transactionSource = config.get(CausalClusteringSettings.transaction_advertised_address);
    memberAttributeConfig.setStringAttribute(TRANSACTION_SERVER, transactionSource.toString());
    AdvertisedSocketAddress raftAddress = config.get(CausalClusteringSettings.raft_advertised_address);
    memberAttributeConfig.setStringAttribute(RAFT_SERVER, raftAddress.toString());
    ClientConnectorAddresses clientConnectorAddresses = ClientConnectorAddresses.extractFromConfig(config);
    memberAttributeConfig.setStringAttribute(CLIENT_CONNECTOR_ADDRESSES, clientConnectorAddresses.toString());
    memberAttributeConfig.setBooleanAttribute(REFUSE_TO_BE_LEADER_KEY, config.get(CausalClusteringSettings.refuse_to_be_leader));
    return memberAttributeConfig;
}
Also used : MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress)

Example 2 with MemberAttributeConfig

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

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

the class ClientMemberAttributeTest method testConfigAttributes.

@Test(timeout = 120000)
public void testConfigAttributes() throws Exception {
    Config c = new Config();
    JoinConfig join = c.getNetworkConfig().getJoin();
    join.getTcpIpConfig().addMember("127.0.0.1").setEnabled(true);
    join.getMulticastConfig().setEnabled(false);
    MemberAttributeConfig memberAttributeConfig = c.getMemberAttributeConfig();
    memberAttributeConfig.setIntAttribute("Test", 123);
    HazelcastInstance h1 = hazelcastFactory.newHazelcastInstance(c);
    Member m1 = h1.getCluster().getLocalMember();
    assertEquals(123, (int) m1.getIntAttribute("Test"));
    HazelcastInstance h2 = hazelcastFactory.newHazelcastInstance(c);
    Member m2 = h2.getCluster().getLocalMember();
    assertEquals(123, (int) m2.getIntAttribute("Test"));
    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();
    Collection<Member> members = client.getCluster().getMembers();
    for (Member m : members) {
        assertEquals(123, (int) m.getIntAttribute("Test"));
    }
}
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) MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with MemberAttributeConfig

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

the class MemberAttributeTest method testConfigAttributes.

@Test(timeout = 120000)
public void testConfigAttributes() throws Exception {
    Config config = new Config();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    MemberAttributeConfig memberAttributeConfig = config.getMemberAttributeConfig();
    memberAttributeConfig.setIntAttribute("Test", 123);
    HazelcastInstance h1 = factory.newHazelcastInstance(config);
    Member m1 = h1.getCluster().getLocalMember();
    assertEquals(123, (int) m1.getIntAttribute("Test"));
    HazelcastInstance h2 = factory.newHazelcastInstance(config);
    Member m2 = h2.getCluster().getLocalMember();
    assertEquals(123, (int) m2.getIntAttribute("Test"));
    assertEquals(2, h1.getCluster().getMembers().size());
    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"));
    for (Member m : h1.getCluster().getMembers()) {
        if (m == h1.getCluster().getLocalMember())
            continue;
        member = m;
    }
    assertNotNull(member);
    assertEquals(m2, member);
    assertNotNull(member.getIntAttribute("Test"));
    assertEquals(123, (int) member.getIntAttribute("Test"));
    h1.shutdown();
    h2.shutdown();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig) MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with MemberAttributeConfig

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

the class TestFullApplicationContext method testMemberAttributesConfig.

@Test
public void testMemberAttributesConfig() {
    MemberAttributeConfig memberAttributeConfig = config.getMemberAttributeConfig();
    assertNotNull(memberAttributeConfig);
    assertEquals("spring-group", memberAttributeConfig.getStringAttribute("cluster.group.name"));
    assertEquals(new Integer(5700), memberAttributeConfig.getIntAttribute("cluster.port.int"));
    assertEquals(new Long(5700), memberAttributeConfig.getLongAttribute("cluster.port.long"));
    assertEquals(new Short("5700"), memberAttributeConfig.getShortAttribute("cluster.port.short"));
    assertEquals(new Byte("111"), memberAttributeConfig.getByteAttribute("attribute.byte"));
    assertTrue(memberAttributeConfig.getBooleanAttribute("attribute.boolean"));
    assertEquals(0.0d, memberAttributeConfig.getDoubleAttribute("attribute.double"), 0.0001d);
    assertEquals(1234.5678, memberAttributeConfig.getFloatAttribute("attribute.float"), 0.0001);
}
Also used : MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig) IAtomicLong(com.hazelcast.core.IAtomicLong) Test(org.junit.Test) QuickTest(com.hazelcast.test.annotation.QuickTest)

Aggregations

MemberAttributeConfig (com.hazelcast.config.MemberAttributeConfig)5 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Test (org.junit.Test)3 Config (com.hazelcast.config.Config)2 JoinConfig (com.hazelcast.config.JoinConfig)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 Member (com.hazelcast.core.Member)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 AdvertisedSocketAddress (org.neo4j.helpers.AdvertisedSocketAddress)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 InterfacesConfig (com.hazelcast.config.InterfacesConfig)1 ListenerConfig (com.hazelcast.config.ListenerConfig)1 NetworkConfig (com.hazelcast.config.NetworkConfig)1 TcpIpConfig (com.hazelcast.config.TcpIpConfig)1 HazelcastException (com.hazelcast.core.HazelcastException)1 IAtomicLong (com.hazelcast.core.IAtomicLong)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 ListenSocketAddress (org.neo4j.helpers.ListenSocketAddress)1 Config (org.neo4j.kernel.configuration.Config)1 JobScheduler (org.neo4j.kernel.impl.util.JobScheduler)1