use of com.baidu.hugegraph.backend.store.raft.RaftGroupManager in project incubator-hugegraph by apache.
the class RaftAPI method getLeader.
@GET
@Timed
@Path("get_leader")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin" })
public Map<String, String> getLeader(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("group") @DefaultValue("default") String group) {
LOG.debug("Graph [{}] prepare to get leader", graph);
HugeGraph g = graph(manager, graph);
RaftGroupManager raftManager = raftGroupManager(g, group, "get_leader");
String leaderId = raftManager.getLeader();
return ImmutableMap.of(raftManager.group(), leaderId);
}
use of com.baidu.hugegraph.backend.store.raft.RaftGroupManager in project incubator-hugegraph by apache.
the class RaftAPI method addPeer.
@POST
@Timed
@Status(Status.OK)
@Path("add_peer")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin" })
public Map<String, String> addPeer(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("group") @DefaultValue("default") String group, @QueryParam("endpoint") String endpoint) {
LOG.debug("Graph [{}] prepare to add peer: {}", graph, endpoint);
HugeGraph g = graph(manager, graph);
RaftGroupManager raftManager = raftGroupManager(g, group, "add_peer");
String peerId = raftManager.addPeer(endpoint);
return ImmutableMap.of(raftManager.group(), peerId);
}
use of com.baidu.hugegraph.backend.store.raft.RaftGroupManager in project incubator-hugegraph by apache.
the class RaftAPI method listPeers.
@GET
@Timed
@Path("list_peers")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin" })
public Map<String, List<String>> listPeers(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("group") @DefaultValue("default") String group) {
LOG.debug("Graph [{}] prepare to get leader", graph);
HugeGraph g = graph(manager, graph);
RaftGroupManager raftManager = raftGroupManager(g, group, "list_peers");
List<String> peers = raftManager.listPeers();
return ImmutableMap.of(raftManager.group(), peers);
}
use of com.baidu.hugegraph.backend.store.raft.RaftGroupManager in project incubator-hugegraph by apache.
the class SetLeaderProcessor method processRequest.
@Override
public Message processRequest(SetLeaderRequest request, RpcRequestClosure done) {
LOG.debug("Processing SetLeaderRequest {}", request.getClass());
RaftGroupManager nodeManager = this.context.raftNodeManager(RaftSharedContext.DEFAULT_GROUP);
try {
nodeManager.setLeader(request.getEndpoint());
CommonResponse common = CommonResponse.newBuilder().setStatus(true).build();
return SetLeaderResponse.newBuilder().setCommon(common).build();
} catch (Throwable e) {
CommonResponse common = CommonResponse.newBuilder().setStatus(false).setMessage(e.toString()).build();
return SetLeaderResponse.newBuilder().setCommon(common).build();
}
}
use of com.baidu.hugegraph.backend.store.raft.RaftGroupManager in project incubator-hugegraph by apache.
the class RaftAPI method transferLeader.
@POST
@Timed
@Status(Status.OK)
@Path("transfer_leader")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin" })
public Map<String, String> transferLeader(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("group") @DefaultValue("default") String group, @QueryParam("endpoint") String endpoint) {
LOG.debug("Graph [{}] prepare to transfer leader to: {}", graph, endpoint);
HugeGraph g = graph(manager, graph);
RaftGroupManager raftManager = raftGroupManager(g, group, "transfer_leader");
String leaderId = raftManager.transferLeaderTo(endpoint);
return ImmutableMap.of(raftManager.group(), leaderId);
}
Aggregations