Search in sources :

Example 1 with AddPeerResponse

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

the class CliServiceImpl method addPeer.

@Override
public Status addPeer(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");
    final PeerId leaderId = new PeerId();
    final Status st = checkLeaderAndConnect(groupId, conf, leaderId);
    if (!st.isOk()) {
        return st;
    }
    final AddPeerRequest.Builder rb = // 
    AddPeerRequest.newBuilder().setGroupId(// 
    groupId).setLeaderId(// 
    leaderId.toString()).setPeerId(peer.toString());
    try {
        final Message result = this.cliClientService.addPeer(leaderId.getEndpoint(), rb.build(), null).get();
        if (result instanceof AddPeerResponse) {
            final AddPeerResponse resp = (AddPeerResponse) 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) AddPeerRequest(com.alipay.sofa.jraft.rpc.CliRequests.AddPeerRequest) AddPeerResponse(com.alipay.sofa.jraft.rpc.CliRequests.AddPeerResponse) JRaftException(com.alipay.sofa.jraft.error.JRaftException) PeerId(com.alipay.sofa.jraft.entity.PeerId)

Aggregations

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