Search in sources :

Example 1 with CPSubsystemManagementService

use of com.hazelcast.cp.CPSubsystemManagementService in project hazelcast by hazelcast.

the class CPMemberAddRemoveTest method testExpandRaftGroupMultipleTimes.

@Test
public void testExpandRaftGroupMultipleTimes() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(5, 5, 3);
    CPGroupId metadataGroupId = getMetadataGroupId(instances[0]);
    waitAllForLeaderElection(Arrays.copyOf(instances, 5), metadataGroupId);
    instances[0].shutdown();
    instances[1].shutdown();
    instances[2].shutdown();
    CPSubsystemManagementService managementService = instances[3].getCPSubsystem().getCPSubsystemManagementService();
    CPGroup group = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    assertEquals(2, group.members().size());
    instances[5].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    group = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    assertEquals(3, group.members().size());
    Collection<CPMember> members = group.members();
    assertTrue(members.contains(instances[5].getCPSubsystem().getLocalCPMember()));
    assertTrueEventually(() -> assertNotNull(getRaftNode(instances[5], metadataGroupId)));
    instances[6].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    group = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    assertEquals(4, group.members().size());
    members = group.members();
    assertTrue(members.contains(instances[6].getCPSubsystem().getLocalCPMember()));
    assertTrueEventually(() -> assertNotNull(getRaftNode(instances[5], metadataGroupId)));
    instances[7].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    group = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    assertEquals(5, group.members().size());
    members = group.members();
    assertTrue(members.contains(instances[7].getCPSubsystem().getLocalCPMember()));
    assertTrueEventually(() -> assertNotNull(getRaftNode(instances[5], metadataGroupId)));
    CPGroup metadataGroup = group;
    HazelcastInstance[] newInstances = { instances[3], instances[4], instances[5], instances[6], instances[7] };
    assertTrueEventually(() -> {
        long commitIndex = getCommitIndex(getLeaderNode(newInstances, metadataGroupId));
        for (int i = 3; i < instances.length; i++) {
            HazelcastInstance instance = instances[i];
            RaftNodeImpl raftNode = getRaftNode(instance, metadataGroupId);
            assertNotNull(raftNode);
            assertEquals(commitIndex, getCommitIndex(raftNode));
            CPGroup g = queryRaftGroupLocally(instance, metadataGroupId);
            assertNotNull(g);
            assertArrayEquals(metadataGroup.members().toArray(new CPMember[0]), g.members().toArray(new CPMember[0]));
        }
    });
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) CPSubsystemManagementService(com.hazelcast.cp.CPSubsystemManagementService) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 2 with CPSubsystemManagementService

use of com.hazelcast.cp.CPSubsystemManagementService in project hazelcast by hazelcast.

the class CPMemberAddRemoveTest method testRemoveMemberFromForceDestroyedRaftGroup.

@Test
public void testRemoveMemberFromForceDestroyedRaftGroup() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(3, 3, 0);
    waitAllForLeaderElection(instances, getMetadataGroupId(instances[0]));
    CPGroupId groupId = getRaftInvocationManager(instances[0]).createRaftGroup("test", 2).get();
    CPGroup group = instances[0].getCPSubsystem().getCPSubsystemManagementService().getCPGroup(groupId.getName()).toCompletableFuture().get();
    CPMember crashedMember = group.members().iterator().next();
    HazelcastInstance runningInstance = (getAddress(instances[0])).equals(crashedMember.getAddress()) ? instances[1] : instances[0];
    factory.getInstance(crashedMember.getAddress()).getLifecycleService().terminate();
    CPSubsystemManagementService cpSubsystemManagementService = runningInstance.getCPSubsystem().getCPSubsystemManagementService();
    cpSubsystemManagementService.forceDestroyCPGroup(groupId.getName()).toCompletableFuture().get();
    cpSubsystemManagementService.removeCPMember(crashedMember.getUuid()).toCompletableFuture().get();
    Collection<CPMember> activeMembers = cpSubsystemManagementService.getCPMembers().toCompletableFuture().get();
    assertFalse(activeMembers.contains(crashedMember));
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) CPSubsystemManagementService(com.hazelcast.cp.CPSubsystemManagementService) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 3 with CPSubsystemManagementService

use of com.hazelcast.cp.CPSubsystemManagementService in project hazelcast by hazelcast.

the class GetCPMembersMessageTask method processInternal.

@Override
protected CompletableFuture<List<SimpleEntry<UUID, UUID>>> processInternal() {
    CPSubsystemManagementService cpService = nodeEngine.getHazelcastInstance().getCPSubsystem().getCPSubsystemManagementService();
    ClusterService clusterService = nodeEngine.getClusterService();
    return cpService.getCPMembers().toCompletableFuture().thenApply(cpMembers -> {
        List<SimpleEntry<UUID, UUID>> result = new ArrayList<>(cpMembers.size());
        for (CPMember cpMember : cpMembers) {
            UUID apUuid = clusterService.getMember(cpMember.getAddress()).getUuid();
            result.add(new SimpleEntry<>(cpMember.getUuid(), apUuid));
        }
        return result;
    });
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) SimpleEntry(java.util.AbstractMap.SimpleEntry) ArrayList(java.util.ArrayList) CPSubsystemManagementService(com.hazelcast.cp.CPSubsystemManagementService) UUID(java.util.UUID) CPMember(com.hazelcast.cp.CPMember)

Example 4 with CPSubsystemManagementService

use of com.hazelcast.cp.CPSubsystemManagementService in project hazelcast by hazelcast.

the class CPMemberAddRemoveTest method testExpandMultipleRaftGroupsMultipleTimes.

@Test
public void testExpandMultipleRaftGroupsMultipleTimes() throws ExecutionException, InterruptedException, TimeoutException {
    HazelcastInstance[] instances = newInstances(5, 5, 2);
    CPGroupId metadataGroupId = getMetadataGroupId(instances[0]);
    CPSubsystemManagementService managementService = instances[6].getCPSubsystem().getCPSubsystemManagementService();
    String groupName = "group1";
    instances[0].getCPSubsystem().getAtomicLong("long1@" + groupName).set(5);
    CPGroup otherGroup = managementService.getCPGroup(groupName).toCompletableFuture().get();
    CPGroupId groupId = otherGroup.id();
    waitAllForLeaderElection(Arrays.copyOf(instances, 5), groupId);
    CPMember[] otherGroupMembers = otherGroup.members().toArray(new CPMember[0]);
    List<Address> shutdownAddresses = asList(otherGroupMembers[0].getAddress(), otherGroupMembers[1].getAddress());
    instances[5].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get(30, TimeUnit.SECONDS);
    HazelcastInstance[] runningInstances = new HazelcastInstance[instances.length - shutdownAddresses.size()];
    for (int i = 0, j = 0; i < instances.length; i++) {
        HazelcastInstance instance = instances[i];
        if (shutdownAddresses.contains(getAddress(instance))) {
            instance.shutdown();
        } else {
            runningInstances[j++] = instance;
        }
    }
    CPGroup metadataGroup = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    otherGroup = managementService.getCPGroup(groupName).toCompletableFuture().get();
    assertEquals(4, metadataGroup.members().size());
    assertEquals(4, otherGroup.members().size());
    assertTrueEventually(() -> {
        assertNotNull(getRaftNode(instances[5], metadataGroupId));
        assertNotNull(getRaftNode(instances[5], groupId));
    });
    instances[6].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get(30, TimeUnit.SECONDS);
    metadataGroup = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    otherGroup = managementService.getCPGroup(groupName).toCompletableFuture().get();
    assertEquals(5, metadataGroup.members().size());
    assertEquals(5, otherGroup.members().size());
    CPGroup metadataGroupRef = metadataGroup;
    CPGroup otherGroupRef = otherGroup;
    assertTrueEventually(() -> {
        long commitIndex = getCommitIndex(getLeaderNode(runningInstances, metadataGroupId));
        assertNotNull(getRaftNode(instances[6], groupId));
        for (HazelcastInstance instance : asList(instances[5], instances[6])) {
            RaftNodeImpl raftNode = getRaftNode(instance, metadataGroupId);
            assertNotNull(raftNode);
            assertEquals(commitIndex, getCommitIndex(raftNode));
            CPGroup g1 = queryRaftGroupLocally(instance, metadataGroupId);
            CPGroup g2 = queryRaftGroupLocally(instance, otherGroupRef.id());
            assertNotNull(g1);
            assertNotNull(g2);
            assertArrayEquals(metadataGroupRef.members().toArray(new CPMember[0]), g1.members().toArray(new CPMember[0]));
            assertArrayEquals(otherGroupRef.members().toArray(new CPMember[0]), g2.members().toArray(new CPMember[0]));
        }
    });
}
Also used : Address(com.hazelcast.cluster.Address) Accessors.getAddress(com.hazelcast.test.Accessors.getAddress) RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) CPMember(com.hazelcast.cp.CPMember) CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) CPSubsystemManagementService(com.hazelcast.cp.CPSubsystemManagementService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

CPMember (com.hazelcast.cp.CPMember)4 CPSubsystemManagementService (com.hazelcast.cp.CPSubsystemManagementService)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 CPGroup (com.hazelcast.cp.CPGroup)3 CPGroupId (com.hazelcast.cp.CPGroupId)3 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 SlowTest (com.hazelcast.test.annotation.SlowTest)3 Test (org.junit.Test)3 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)2 Address (com.hazelcast.cluster.Address)1 ClusterService (com.hazelcast.internal.cluster.ClusterService)1 Accessors.getAddress (com.hazelcast.test.Accessors.getAddress)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1