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());
}
}
Aggregations