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