use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.
the class CPGroupInfo method toSummary.
CPGroupSummary toSummary(Collection<CPMemberInfo> cpMembers) {
Map<UUID, CPMemberInfo> cpMembersMap = new HashMap<>();
for (CPMemberInfo cpMember : cpMembers) {
cpMembersMap.put(cpMember.getUuid(), cpMember);
}
// we should preserve the member ordering so we iterate over group members instead of all cp members
List<CPMember> groupEndpoints = new ArrayList<>();
for (RaftEndpoint endpoint : members) {
CPMemberInfo memberInfo = cpMembersMap.get(endpoint.getUuid());
if (memberInfo == null) {
continue;
}
groupEndpoints.add(memberInfo);
}
if (groupEndpoints.size() != members.size()) {
throw new IllegalStateException("Missing CP member in active CP members: " + cpMembers + " for " + this);
}
return new CPGroupSummary(id, status, initialMembers, groupEndpoints);
}
use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.
the class RestCPSubsystemTest method test_getMetadataCPGroupByName.
@Test
public void test_getMetadataCPGroupByName() throws IOException {
final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);
final HazelcastInstance instance3 = Hazelcast.newHazelcastInstance(config);
waitUntilCPDiscoveryCompleted(instance1, instance2, instance3);
HTTPCommunicator communicator = new HTTPCommunicator(instance1);
ConnectionResponse response = communicator.getCPGroupByName(METADATA_CP_GROUP_NAME);
assertEquals(200, response.responseCode);
CPMember cpMember1 = instance1.getCPSubsystem().getLocalCPMember();
CPMember cpMember2 = instance2.getCPSubsystem().getLocalCPMember();
CPMember cpMember3 = instance3.getCPSubsystem().getLocalCPMember();
boolean cpMember1Found = false;
boolean cpMember2Found = false;
boolean cpMember3Found = false;
JsonObject json = (JsonObject) Json.parse(response.response);
assertEquals(METADATA_CP_GROUP_NAME, ((JsonObject) json.get("id")).getString("name", ""));
assertEquals(CPGroupStatus.ACTIVE.name(), json.getString("status", ""));
for (JsonValue val : (JsonArray) json.get("members")) {
JsonObject mem = (JsonObject) val;
cpMember1Found |= cpMember1.getUuid().equals(UUID.fromString(mem.getString("uuid", "")));
cpMember2Found |= cpMember2.getUuid().equals(UUID.fromString(mem.getString("uuid", "")));
cpMember3Found |= cpMember3.getUuid().equals(UUID.fromString(mem.getString("uuid", "")));
}
assertTrue(cpMember1Found);
assertTrue(cpMember2Found);
assertTrue(cpMember3Found);
}
use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.
the class RestCPSubsystemTest method test_promoteExistingCPMember.
@Test
public void test_promoteExistingCPMember() throws IOException, ExecutionException, InterruptedException {
final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
Hazelcast.newHazelcastInstance(config);
Hazelcast.newHazelcastInstance(config);
waitUntilCPDiscoveryCompleted(instance1);
ConnectionResponse response = new HTTPCommunicator(instance1).promoteCPMember(clusterName, null);
assertEquals(200, response.responseCode);
Collection<CPMember> cpMembers = instance1.getCPSubsystem().getCPSubsystemManagementService().getCPMembers().toCompletableFuture().get();
assertEquals(3, cpMembers.size());
}
use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.
the class RestCPSubsystemTest method test_getCustomCPGroupByName.
@Test
public void test_getCustomCPGroupByName() throws IOException {
final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);
final HazelcastInstance instance3 = Hazelcast.newHazelcastInstance(config);
waitUntilCPDiscoveryCompleted(instance1, instance2, instance3);
instance1.getCPSubsystem().getAtomicLong("long1@custom").set(5);
HTTPCommunicator communicator = new HTTPCommunicator(instance1);
ConnectionResponse response = communicator.getCPGroupByName("custom");
assertEquals(200, response.responseCode);
CPMember cpMember1 = instance1.getCPSubsystem().getLocalCPMember();
CPMember cpMember2 = instance2.getCPSubsystem().getLocalCPMember();
CPMember cpMember3 = instance3.getCPSubsystem().getLocalCPMember();
boolean cpMember1Found = false;
boolean cpMember2Found = false;
boolean cpMember3Found = false;
JsonObject json = (JsonObject) Json.parse(response.response);
assertEquals("custom", ((JsonObject) json.get("id")).getString("name", ""));
assertEquals(CPGroupStatus.ACTIVE.name(), json.getString("status", ""));
for (JsonValue val : (JsonArray) json.get("members")) {
JsonObject mem = (JsonObject) val;
cpMember1Found |= cpMember1.getUuid().equals(UUID.fromString(mem.getString("uuid", "")));
cpMember2Found |= cpMember2.getUuid().equals(UUID.fromString(mem.getString("uuid", "")));
cpMember3Found |= cpMember3.getUuid().equals(UUID.fromString(mem.getString("uuid", "")));
}
assertTrue(cpMember1Found);
assertTrue(cpMember2Found);
assertTrue(cpMember3Found);
}
use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.
the class RestCPSubsystemTest method test_removeCPMember_withInvalidCredentials.
@Test
public void test_removeCPMember_withInvalidCredentials() throws IOException {
HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);
final HazelcastInstance instance3 = Hazelcast.newHazelcastInstance(config);
waitUntilCPDiscoveryCompleted(instance1, instance2, instance3);
CPMember crashedCPMember = instance3.getCPSubsystem().getLocalCPMember();
instance3.getLifecycleService().terminate();
assertClusterSizeEventually(2, instance1, instance2);
ConnectionResponse response = new HTTPCommunicator(instance1).removeCPMember(crashedCPMember.getUuid(), "x", "x");
assertEquals(403, response.responseCode);
}
Aggregations