use of org.apache.ignite.raft.jraft.rpc.CliRequests.TransferLeaderRequest in project ignite-3 by apache.
the class CliServiceImpl method transferLeader.
@Override
public Status transferLeader(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 = getLeader(groupId, conf, leaderId);
if (!st.isOk()) {
return st;
}
if (!this.cliClientService.connect(leaderId.getEndpoint())) {
return new Status(-1, "Fail to init channel to leader %s", leaderId);
}
TransferLeaderRequest rb = cliOptions.getRaftMessagesFactory().transferLeaderRequest().groupId(groupId).leaderId(leaderId.toString()).peerId(peer.isEmpty() ? null : peer.toString()).build();
try {
final Message result = this.cliClientService.transferLeader(leaderId.getEndpoint(), rb, null).get();
return statusFromResponse(result);
} catch (final Exception e) {
return new Status(-1, e.getMessage());
}
}
use of org.apache.ignite.raft.jraft.rpc.CliRequests.TransferLeaderRequest in project ignite-3 by apache.
the class RaftGroupServiceImpl method transferLeadership.
/**
* {@inheritDoc}
*/
@Override
public CompletableFuture<Void> transferLeadership(Peer newLeader) {
Peer leader = this.leader;
if (leader == null)
return refreshLeader().thenCompose(res -> transferLeadership(newLeader));
TransferLeaderRequest req = factory.transferLeaderRequest().groupId(groupId).leaderId(PeerId.fromPeer(newLeader).toString()).build();
CompletableFuture<NetworkMessage> fut = cluster.messagingService().invoke(newLeader.address(), req, rpcTimeout);
return fut.thenCompose(resp -> {
if (resp != null) {
RpcRequests.ErrorResponse resp0 = (RpcRequests.ErrorResponse) resp;
if (resp0.errorCode() != RaftError.SUCCESS.getNumber())
CompletableFuture.failedFuture(new RaftException(RaftError.forNumber(resp0.errorCode()), resp0.errorMsg()));
else
this.leader = newLeader;
}
return CompletableFuture.completedFuture(null);
});
}
Aggregations