Search in sources :

Example 36 with CPMember

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

the class NodeEngineRaftIntegration method send.

private boolean send(AsyncRaftOp operation, RaftEndpoint target) {
    CPMember targetMember = getCPMember(target);
    if (targetMember == null || localAddress.equals(targetMember.getAddress())) {
        if (localCPMember.getUuid().equals(target.getUuid())) {
            throw new IllegalStateException("Cannot send " + operation + " to " + target + " because it's same with the local CP member!");
        }
        return false;
    }
    operation.setTargetEndpoint(target).setPartitionId(partitionId);
    return operationService.send(operation, targetMember.getAddress());
}
Also used : CPMember(com.hazelcast.cp.CPMember)

Example 37 with CPMember

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

the class RaftInvocationManager method triggerRaftNodeCreation.

void triggerRaftNodeCreation(CPGroupSummary group) {
    for (CPMember groupMember : group.members()) {
        if (groupMember.equals(raftService.getLocalCPMember())) {
            ExecutionService executionService = nodeEngine.getExecutionService();
            executionService.execute(CP_SUBSYSTEM_EXECUTOR, () -> raftService.createRaftNode(group.id(), group.initialMembers()));
        } else {
            Operation op = new CreateRaftNodeOp(group.id(), group.initialMembers());
            OperationService operationService = nodeEngine.getOperationService();
            operationService.send(op, groupMember.getAddress());
        }
    }
}
Also used : CreateRaftNodeOp(com.hazelcast.cp.internal.raftop.metadata.CreateRaftNodeOp) Operation(com.hazelcast.spi.impl.operationservice.Operation) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) CPMember(com.hazelcast.cp.CPMember)

Example 38 with CPMember

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

the class RaftNodeImpl method printMemberState.

public void printMemberState() {
    CPGroupId groupId = state.groupId();
    StringBuilder sb = new StringBuilder("\n\nCP Group Members {").append("groupId: ").append(groupId.getName()).append("(").append(groupId.getId()).append(")").append(", size:").append(state.memberCount()).append(", term:").append(state.term()).append(", logIndex:").append(state.membersLogIndex()).append("} [");
    for (RaftEndpoint member : state.members()) {
        CPMember cpMember = raftIntegration.getCPMember(member);
        sb.append("\n\t").append(cpMember != null ? cpMember : member);
        if (state.localEndpoint().equals(member)) {
            sb.append(" - ").append(state.role()).append(" this");
        } else if (member.equals(state.leader())) {
            sb.append(" - ").append(LEADER);
        }
    }
    sb.append("\n]\n");
    logger.info(sb.toString());
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPMember(com.hazelcast.cp.CPMember)

Example 39 with CPMember

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

the class HttpGetCommandProcessor method handleGetCPGroupByName.

private void handleGetCPGroupByName(final HttpGetCommand command) {
    String prefix = URI_CP_GROUPS_URL + "/";
    String groupName = command.getURI().substring(prefix.length()).trim();
    CompletionStage<CPGroup> f = getCpSubsystemManagementService().getCPGroup(groupName);
    f.whenCompleteAsync((group, t) -> {
        if (t == null) {
            if (group != null) {
                JsonObject json = new JsonObject();
                json.add("id", toJson(group.id())).add("status", group.status().name());
                JsonArray membersArr = new JsonArray();
                for (CPMember member : group.members()) {
                    membersArr.add(toJson(member));
                }
                json.add("members", membersArr);
                prepareResponse(command, json);
            } else {
                command.send404();
            }
            textCommandService.sendResponse(command);
        } else {
            command.send500();
            textCommandService.sendResponse(command);
        }
    });
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) CPGroup(com.hazelcast.cp.CPGroup) JsonObject(com.hazelcast.internal.json.JsonObject) CPMember(com.hazelcast.cp.CPMember)

Example 40 with CPMember

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

the class HttpGetCommandProcessor method handleGetCPMembers.

private void handleGetCPMembers(final HttpGetCommand command) {
    CompletionStage<Collection<CPMember>> f = getCpSubsystemManagementService().getCPMembers();
    f.whenCompleteAsync((cpMembers, t) -> {
        if (t == null) {
            JsonArray arr = new JsonArray();
            for (CPMember cpMember : cpMembers) {
                arr.add(toJson(cpMember));
            }
            prepareResponse(command, arr);
            textCommandService.sendResponse(command);
        } else {
            command.send500();
            textCommandService.sendResponse(command);
        }
    });
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) Collection(java.util.Collection) CPMember(com.hazelcast.cp.CPMember)

Aggregations

CPMember (com.hazelcast.cp.CPMember)57 HazelcastInstance (com.hazelcast.core.HazelcastInstance)40 Test (org.junit.Test)38 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)27 SlowTest (com.hazelcast.test.annotation.SlowTest)27 CPGroup (com.hazelcast.cp.CPGroup)17 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)16 CPGroupId (com.hazelcast.cp.CPGroupId)14 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)11 QuickTest (com.hazelcast.test.annotation.QuickTest)11 ArrayList (java.util.ArrayList)11 Config (com.hazelcast.config.Config)10 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)10 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)7 GetActiveCPMembersOp (com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp)6 JsonArray (com.hazelcast.internal.json.JsonArray)6 JsonObject (com.hazelcast.internal.json.JsonObject)6 TestHazelcastInstanceFactory.initOrCreateConfig (com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig)6 CPSubsystemManagementService (com.hazelcast.cp.CPSubsystemManagementService)4 JsonValue (com.hazelcast.internal.json.JsonValue)4