Skip to content

Commit

Permalink
Fix raft-tools script small bug (#1416)
Browse files Browse the repository at this point in the history
* Fix raft-tools script small bug

Change-Id: I5b095d19f58b58113ae903578ad6a1377aa52119
  • Loading branch information
Linary authored Apr 16, 2021
1 parent acaeb3a commit 00f93e6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand All @@ -66,14 +66,14 @@ public Map<String, List<String>> 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<String> 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"})
Expand All @@ -85,15 +85,15 @@ public Map<String, String> 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);
}

@POST
@Timed
@Status(Status.OK)
@Path("transfer-leader")
@Path("transfer_leader")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({"admin"})
Expand All @@ -109,15 +109,15 @@ public Map<String, String> 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);
}

@POST
@Timed
@Status(Status.OK)
@Path("set-leader")
@Path("set_leader")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({"admin"})
Expand All @@ -132,15 +132,15 @@ public Map<String, String> 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);
}

@POST
@Timed
@Status(Status.OK)
@Path("add-peer")
@Path("add_peer")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({"admin"})
Expand All @@ -154,15 +154,15 @@ public Map<String, String> 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);
}

@POST
@Timed
@Status(Status.OK)
@Path("remove-peer")
@Path("remove_peer")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({"admin"})
Expand All @@ -177,7 +177,7 @@ public Map<String, String> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
90 changes: 41 additions & 49 deletions hugegraph-dist/src/assembly/static/bin/raft-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ 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}
}

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}
}
Expand All @@ -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}
}
Expand All @@ -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}
}
Expand All @@ -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}
}
Expand All @@ -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 ""

0 comments on commit 00f93e6

Please sign in to comment.