Search in sources :

Example 1 with RaftGroupManager

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);
}
Also used : RaftGroupManager(com.baidu.hugegraph.backend.store.raft.RaftGroupManager) HugeGraph(com.baidu.hugegraph.HugeGraph) Path(jakarta.ws.rs.Path) RolesAllowed(jakarta.annotation.security.RolesAllowed) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 2 with RaftGroupManager

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);
}
Also used : RaftGroupManager(com.baidu.hugegraph.backend.store.raft.RaftGroupManager) HugeGraph(com.baidu.hugegraph.HugeGraph) Status(com.baidu.hugegraph.api.filter.StatusFilter.Status) Path(jakarta.ws.rs.Path) RolesAllowed(jakarta.annotation.security.RolesAllowed) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed)

Example 3 with RaftGroupManager

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);
}
Also used : RaftGroupManager(com.baidu.hugegraph.backend.store.raft.RaftGroupManager) HugeGraph(com.baidu.hugegraph.HugeGraph) Path(jakarta.ws.rs.Path) RolesAllowed(jakarta.annotation.security.RolesAllowed) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 4 with RaftGroupManager

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();
    }
}
Also used : RaftGroupManager(com.baidu.hugegraph.backend.store.raft.RaftGroupManager) CommonResponse(com.baidu.hugegraph.backend.store.raft.rpc.RaftRequests.CommonResponse)

Example 5 with RaftGroupManager

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);
}
Also used : RaftGroupManager(com.baidu.hugegraph.backend.store.raft.RaftGroupManager) HugeGraph(com.baidu.hugegraph.HugeGraph) Status(com.baidu.hugegraph.api.filter.StatusFilter.Status) Path(jakarta.ws.rs.Path) RolesAllowed(jakarta.annotation.security.RolesAllowed) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

RaftGroupManager (com.baidu.hugegraph.backend.store.raft.RaftGroupManager)8 HugeGraph (com.baidu.hugegraph.HugeGraph)6 Timed (com.codahale.metrics.annotation.Timed)6 RolesAllowed (jakarta.annotation.security.RolesAllowed)6 Consumes (jakarta.ws.rs.Consumes)6 Path (jakarta.ws.rs.Path)6 Produces (jakarta.ws.rs.Produces)6 Status (com.baidu.hugegraph.api.filter.StatusFilter.Status)4 POST (jakarta.ws.rs.POST)4 CommonResponse (com.baidu.hugegraph.backend.store.raft.rpc.RaftRequests.CommonResponse)2 GET (jakarta.ws.rs.GET)2