From 00f93e626fd48a5cfad8484e48b61594388071af Mon Sep 17 00:00:00 2001 From: Linary Date: Fri, 16 Apr 2021 19:47:02 +0800 Subject: [PATCH] Fix raft-tools script small bug (#1416) * Fix raft-tools script small bug Change-Id: I5b095d19f58b58113ae903578ad6a1377aa52119 --- .../com/baidu/hugegraph/api/raft/RaftAPI.java | 24 ++--- .../store/raft/RaftGroupManagerImpl.java | 4 +- .../src/assembly/static/bin/raft-tools.sh | 90 +++++++++---------- 3 files changed, 55 insertions(+), 63 deletions(-) diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/raft/RaftAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/raft/RaftAPI.java index 8508ffeae8..9f06852c6f 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/raft/RaftAPI.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/raft/RaftAPI.java @@ -54,7 +54,7 @@ public class RaftAPI extends API { @GET @Timed - @Path("list-peers") + @Path("list_peers") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"admin"}) @@ -66,14 +66,14 @@ public Map> listPeers(@Context GraphManager manager, LOG.debug("Graph [{}] prepare to get leader", graph); HugeGraph g = graph(manager, graph); - RaftGroupManager raftManager = raftGroupManager(g, group, "list-peers"); + RaftGroupManager raftManager = raftGroupManager(g, group, "list_peers"); List peers = raftManager.listPeers(); return ImmutableMap.of(raftManager.group(), peers); } @GET @Timed - @Path("get-leader") + @Path("get_leader") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"admin"}) @@ -85,7 +85,7 @@ public Map getLeader(@Context GraphManager manager, LOG.debug("Graph [{}] prepare to get leader", graph); HugeGraph g = graph(manager, graph); - RaftGroupManager raftManager = raftGroupManager(g, group, "get-leader"); + RaftGroupManager raftManager = raftGroupManager(g, group, "get_leader"); String leaderId = raftManager.getLeader(); return ImmutableMap.of(raftManager.group(), leaderId); } @@ -93,7 +93,7 @@ public Map getLeader(@Context GraphManager manager, @POST @Timed @Status(Status.OK) - @Path("transfer-leader") + @Path("transfer_leader") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"admin"}) @@ -109,7 +109,7 @@ public Map transferLeader(@Context GraphManager manager, HugeGraph g = graph(manager, graph); RaftGroupManager raftManager = raftGroupManager(g, group, - "transfer-leader"); + "transfer_leader"); String leaderId = raftManager.transferLeaderTo(endpoint); return ImmutableMap.of(raftManager.group(), leaderId); } @@ -117,7 +117,7 @@ public Map transferLeader(@Context GraphManager manager, @POST @Timed @Status(Status.OK) - @Path("set-leader") + @Path("set_leader") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"admin"}) @@ -132,7 +132,7 @@ public Map setLeader(@Context GraphManager manager, graph, endpoint); HugeGraph g = graph(manager, graph); - RaftGroupManager raftManager = raftGroupManager(g, group, "set-leader"); + RaftGroupManager raftManager = raftGroupManager(g, group, "set_leader"); String leaderId = raftManager.setLeader(endpoint); return ImmutableMap.of(raftManager.group(), leaderId); } @@ -140,7 +140,7 @@ public Map setLeader(@Context GraphManager manager, @POST @Timed @Status(Status.OK) - @Path("add-peer") + @Path("add_peer") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"admin"}) @@ -154,7 +154,7 @@ public Map addPeer(@Context GraphManager manager, LOG.debug("Graph [{}] prepare to add peer: {}", graph, endpoint); HugeGraph g = graph(manager, graph); - RaftGroupManager raftManager = raftGroupManager(g, group, "add-peer"); + RaftGroupManager raftManager = raftGroupManager(g, group, "add_peer"); String peerId = raftManager.addPeer(endpoint); return ImmutableMap.of(raftManager.group(), peerId); } @@ -162,7 +162,7 @@ public Map addPeer(@Context GraphManager manager, @POST @Timed @Status(Status.OK) - @Path("remove-peer") + @Path("remove_peer") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"admin"}) @@ -177,7 +177,7 @@ public Map removePeer(@Context GraphManager manager, HugeGraph g = graph(manager, graph); RaftGroupManager raftManager = raftGroupManager(g, group, - "remove-peer"); + "remove_peer"); String peerId = raftManager.removePeer(endpoint); return ImmutableMap.of(raftManager.group(), peerId); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/RaftGroupManagerImpl.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/RaftGroupManagerImpl.java index 28fa6eeb00..29d5d41689 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/RaftGroupManagerImpl.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/RaftGroupManagerImpl.java @@ -121,7 +121,7 @@ public String setLeader(String endpoint) { @Override public String addPeer(String endpoint) { E.checkArgument(this.raftNode.selfIsLeader(), - "Operation add-peer can only be executed on leader"); + "Operation add_peer can only be executed on leader"); PeerId peerId = PeerId.parsePeer(endpoint); RaftClosure future = new RaftClosure<>(); try { @@ -136,7 +136,7 @@ public String addPeer(String endpoint) { @Override public String removePeer(String endpoint) { E.checkArgument(this.raftNode.selfIsLeader(), - "Operation add-peer can only be executed on leader"); + "Operation add_peer can only be executed on leader"); PeerId peerId = PeerId.parsePeer(endpoint); RaftClosure future = new RaftClosure<>(); try { diff --git a/hugegraph-dist/src/assembly/static/bin/raft-tools.sh b/hugegraph-dist/src/assembly/static/bin/raft-tools.sh index aa5faa2e59..4f0e6fc57d 100755 --- a/hugegraph-dist/src/assembly/static/bin/raft-tools.sh +++ b/hugegraph-dist/src/assembly/static/bin/raft-tools.sh @@ -37,7 +37,7 @@ fi function list_peers() { local graph=$1 local rest_server_url=`read_property ${CONF_PATH}/rest-server.properties restserver.url` - local url=${rest_server_url}/graphs/${graph}/raft/list-peers + local url=${rest_server_url}/graphs/${graph}/raft/list_peers curl ${url} } @@ -45,7 +45,7 @@ function list_peers() { function get_leader() { local graph=$1 local rest_server_url=`read_property ${CONF_PATH}/rest-server.properties restserver.url` - local url=${rest_server_url}/graphs/${graph}/raft/get-leader + local url=${rest_server_url}/graphs/${graph}/raft/get_leader curl ${url} } @@ -54,7 +54,7 @@ function set_leader() { local graph=$1 local endpoint=$2 local rest_server_url=`read_property ${CONF_PATH}/rest-server.properties restserver.url` - local url=${rest_server_url}/graphs/${graph}/raft/set-leader?endpoint=${endpoint} + local url=${rest_server_url}/graphs/${graph}/raft/set_leader?endpoint=${endpoint} curl -X POST ${url} } @@ -63,7 +63,7 @@ function transfer_leader() { local graph=$1 local endpoint=$2 local rest_server_url=`read_property ${CONF_PATH}/rest-server.properties restserver.url` - local url=${rest_server_url}/graphs/${graph}/raft/transfer-leader?endpoint=${endpoint} + local url=${rest_server_url}/graphs/${graph}/raft/transfer_leader?endpoint=${endpoint} curl -X POST ${url} } @@ -72,7 +72,7 @@ function add_peer() { local graph=$1 local endpoint=$2 local rest_server_url=`read_property ${CONF_PATH}/rest-server.properties restserver.url` - local url=${rest_server_url}/graphs/${graph}/raft/add-peer?endpoint=${endpoint} + local url=${rest_server_url}/graphs/${graph}/raft/add_peer?endpoint=${endpoint} curl -X POST ${url} } @@ -81,51 +81,43 @@ function remove_peer() { local graph=$1 local endpoint=$2 local rest_server_url=`read_property ${CONF_PATH}/rest-server.properties restserver.url` - local url=${rest_server_url}/graphs/${graph}/raft/remove-peer?endpoint=${endpoint} + local url=${rest_server_url}/graphs/${graph}/raft/remove_peer?endpoint=${endpoint} curl -X POST ${url} } -while [[ $# -gt 0 ]]; do - case $1 in - # help - --help|-h) - print_usage - shift - ;; - # list-peers - --list-peers|-l) - list_peers $2 - shift 2 - ;; - # get-leader - --get-leader|-g) - get_leader $2 - shift 2 - ;; - # set-leader - --set-leader|-s) - set_leader $2 $3 - shift 3 - ;; - # transfer-leader - --transfer-leader|-t) - transfer_leader $2 $3 - shift 3 - ;; - # add-peer - --add-peer|-a) - add_peer $2 $3 - shift 3 - ;; - # remove-peer - --remove-peer|-r) - remove_peer $2 $3 - shift 3 - ;; - *) - print_usage - exit 0 - ;; - esac -done +case $1 in + # help + --help|-h) + print_usage + ;; + # list-peers + --list-peers|-l) + list_peers $2 + ;; + # get-leader + --get-leader|-g) + get_leader $2 + ;; + # set-leader + --set-leader|-s) + set_leader $2 $3 + ;; + # transfer-leader + --transfer-leader|-t) + transfer_leader $2 $3 + ;; + # add-peer + --add-peer|-a) + add_peer $2 $3 + ;; + # remove-peer + --remove-peer|-r) + remove_peer $2 $3 + ;; + *) + print_usage + exit 0 + ;; +esac +echo ""