Search in sources :

Example 1 with RemovePeerResponse

use of com.alipay.sofa.jraft.rpc.CliRequests.RemovePeerResponse in project sofa-jraft by sofastack.

the class CliServiceImpl method removePeer.

@Override
public Status removePeer(final String groupId, final Configuration conf, final PeerId peer) {
    Requires.requireTrue(!StringUtils.isBlank(groupId), "Blank group id");
    Requires.requireNonNull(conf, "Null configuration");
    Requires.requireNonNull(peer, "Null peer");
    Requires.requireTrue(!peer.isEmpty(), "Removing peer is blank");
    final PeerId leaderId = new PeerId();
    final Status st = checkLeaderAndConnect(groupId, conf, leaderId);
    if (!st.isOk()) {
        return st;
    }
    final RemovePeerRequest.Builder rb = // 
    RemovePeerRequest.newBuilder().setGroupId(// 
    groupId).setLeaderId(// 
    leaderId.toString()).setPeerId(peer.toString());
    try {
        final Message result = this.cliClientService.removePeer(leaderId.getEndpoint(), rb.build(), null).get();
        if (result instanceof RemovePeerResponse) {
            final RemovePeerResponse resp = (RemovePeerResponse) result;
            recordConfigurationChange(groupId, resp.getOldPeersList(), resp.getNewPeersList());
            return Status.OK();
        } else {
            return statusFromResponse(result);
        }
    } catch (final Exception e) {
        return new Status(-1, e.getMessage());
    }
}
Also used : Status(com.alipay.sofa.jraft.Status) Message(com.google.protobuf.Message) RemovePeerResponse(com.alipay.sofa.jraft.rpc.CliRequests.RemovePeerResponse) JRaftException(com.alipay.sofa.jraft.error.JRaftException) PeerId(com.alipay.sofa.jraft.entity.PeerId) RemovePeerRequest(com.alipay.sofa.jraft.rpc.CliRequests.RemovePeerRequest)

Aggregations

Status (com.alipay.sofa.jraft.Status)1 PeerId (com.alipay.sofa.jraft.entity.PeerId)1 JRaftException (com.alipay.sofa.jraft.error.JRaftException)1 RemovePeerRequest (com.alipay.sofa.jraft.rpc.CliRequests.RemovePeerRequest)1 RemovePeerResponse (com.alipay.sofa.jraft.rpc.CliRequests.RemovePeerResponse)1 Message (com.google.protobuf.Message)1