Skip to content

Commit

Permalink
Merge branch 'integration/riak-admin-handoff-team' into feature/show-…
Browse files Browse the repository at this point in the history
…usage-when-no-id-idx-given

Conflicts:
	src/riak_core_cluster_cli.erl
  • Loading branch information
andrewjstone committed Dec 17, 2014
2 parents 8424513 + 359cf99 commit 1fcb001
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 60 deletions.
105 changes: 62 additions & 43 deletions src/riak_core_cluster_cli.erl
Expand Up @@ -18,12 +18,12 @@
%%
%% -------------------------------------------------------------------
%% @doc This module encapsulates the command line interface for the
%% "new" cluster commands:
%% "new" cluster commands:
%%
%% status, partition-count, partitions, partition-id, partition-index
%% members
%%
%% The "old" command implementations for join, leave, plan, commit,
%% The "old" command implementations for join, leave, plan, commit,
%% etc are in `riak_core_console.erl'
%%
%% @TODO: Move implementation of old commands here?
Expand All @@ -45,18 +45,20 @@ register_cli() ->
register_all_usage(),
register_all_commands().

register_all_usage() ->
clique:register_usage(["riak-admin", "cluster"], cluster_usage()),
clique:register_usage(["riak-admin", "cluster", "status"], status_usage()),
clique:register_usage(["riak-admin", "cluster", "partition"], partition_usage()),
clique:register_usage(["riak-admin", "cluster", "partitions"], partitions_usage()),
clique:register_usage(["riak-admin", "cluster", "partition_count"], partition_count_usage()),
clique:register_usage(["riak-admin", "cluster", "members"], members_usage()).

register_all_commands() ->
lists:foreach(fun(Args) -> apply(clique, register_command, Args) end,
[status_register(), partition_count_register(),
partitions_register(), partition_register(),
members_register()]).

register_all_usage() ->
lists:foreach(fun(Args) -> apply(clique, register_usage, Args) end,
[status_usage(), partition_count_usage(),
partitions_usage(), partition_usage(),
members_usage()]).

%%%
%% Cluster status
%%%
Expand All @@ -67,10 +69,21 @@ status_register() ->
[], % FlagSpecs
fun status/2]. % Implementation callback.

cluster_usage() ->
[
"riak-admin cluster <sub-command>\n\n",
" Display cluster-related status and settings.\n\n",
" Sub-commands:\n",
" status Display a summary of cluster status\n",
" partition Map partition IDs to indexes\n",
" partitions Display partitions on a node\n",
" partition-count Display ring size or node partition count\n\n",
" Use --help after a sub-command for more details.\n"
].

status_usage() ->
Text = ["riak-admin cluster status\n\n",
"Present a summary of cluster status information."],
[["riak-admin", "cluster", "status"], Text].
["riak-admin cluster status\n\n",
" Display a summary of cluster status information.\n"].

future_claim_percentage([], _Ring, _Node) ->
"--";
Expand Down Expand Up @@ -118,7 +131,7 @@ is_claimant(Node, _Other) ->

node_availability(Node, Down, MarkedDown) ->
case {lists:member(Node, Down), lists:member(Node, MarkedDown)} of
{false, false} -> " up ";
{false, false} -> " up ";
{true, true } -> " down ";
{true, false} -> " down! ";
{false, true } -> " up! "
Expand All @@ -131,16 +144,20 @@ node_availability(Node, Down, MarkedDown) ->
partition_count_register() ->
[["riak-admin", "cluster", "partition-count"], % Cmd
[], % KeySpecs
[{node, [{shortname, "n"}, {longname, "node"},
{typecast,
[{node, [{shortname, "n"}, {longname, "node"},
{typecast,
fun clique_typecast:to_node/1}]}],% FlagSpecs
fun partition_count/2]. % Implementation callback

partition_count_usage() ->
Text = ["riak-admin cluster partition-count [--node node]\n\n",
"Returns the number of partitions (ring-size) for the entire\n",
"cluster or the number of partitions on a specific node."],
[["riak-admin", "cluster", "partition-count"], Text].
["riak-admin cluster partition-count [--node node]\n\n",
" Display the number of partitions (ring-size) for the entire\n",
" cluster or the number of partitions on a specific node.\n\n",
"Options\n",
" -n <node>, --node <node>\n",
" Display the handoffs on the specified node.\n",
" This flag can currently take only one node and be used once\n"
].

partition_count([], [{node, Node}]) ->
{ok, Ring} = riak_core_ring_manager:get_my_ring(),
Expand All @@ -150,7 +167,7 @@ partition_count([], [{node, Node}]) ->
partition_count([], []) ->
{ok, Ring} = riak_core_ring_manager:get_my_ring(),
[clique_status:text(
io_lib:format("Cluster-wide partition-count: ~p",
io_lib:format("Cluster-wide partition-count: ~p",
[riak_core_ring:num_partitions(Ring)]))].

%%%
Expand All @@ -161,16 +178,19 @@ partitions_register() ->
[["riak-admin", "cluster", "partitions"], % Cmd
[], % KeySpecs
[{node, [{shortname, "n"}, {longname, "node"},
{typecast,
{typecast,
fun clique_typecast:to_node/1}]}],% FlagSpecs
fun partitions/2]. % Implementation callback


partitions_usage() ->
Text = ["riak-admin cluster partitions [--node node]\n\n",
"Returns the partitions which belong to the current node,\n",
"or to a specific node."],
[["riak-admin", "cluster", "partitions"], Text].
["riak-admin cluster partitions [--node node]\n\n",
" Display the partitions on a node. Defaults to local node.\n\n",
"Options\n",
" -n <node>, --node <node>\n",
" Display the handoffs on the specified node.\n",
" This flag can currently take only one node and be used once\n"
].

partitions([], [{node, Node}]) ->
partitions_output(Node);
Expand All @@ -182,7 +202,7 @@ partitions_output(Node) ->
RingSize = riak_core_ring:num_partitions(Ring),
{Primary, Secondary, Stopped} = riak_core_status:partitions(Node, Ring),
T0 = clique_status:text(io_lib:format("Partitions owned by ~p:", [Node])),
Rows = generate_rows(RingSize, primary, Primary)
Rows = generate_rows(RingSize, primary, Primary)
++ generate_rows(RingSize, secondary, Secondary)
++ generate_rows(RingSize, stopped, Stopped),
Table = clique_status:table(Rows),
Expand All @@ -192,12 +212,12 @@ generate_rows(_RingSize, Type, []) ->
[[{type, Type}, {index, "--"}, {id, "--"}]];
generate_rows(RingSize, Type, Ids) ->
%% Build a list of proplists, one for each partition id
[
[ {type, Type}, {index, I},
[
[ {type, Type}, {index, I},
{id, hash_to_partition_id(I, RingSize)} ]
|| I <- Ids ].

%%%
%%%
%% cluster partition id=0
%% cluster partition index=576460752303423500
%%%
Expand All @@ -210,17 +230,17 @@ partition_register() ->
fun partition/2]. % Implementation callback

partition_usage() ->
Text = ["riak-admin cluster partition id=0\n",
"riak-admin cluster partition index=22835963083295358096932575511191922182123945984\n\n",
"Returns the id or index for the specified index or id.\n"],
[["riak-admin", "cluster", "partition"], Text].
["riak-admin cluster partition id=0\n",
"riak-admin cluster partition index=228359630832953580969325755111919221821\n\n",
" Display the id for the provided index, or index for the ",
"specified id.\n"].

partition([{index, Index}], []) when Index >= 0 ->
id_out(index, Index);
partition([{id, Id}], []) when Id >= 0 ->
id_out(id, Id);
partition([{Op, Value}], []) ->
[make_alert(["ERROR: The given value ", integer_to_list(Value),
[make_alert(["ERROR: The given value ", integer_to_list(Value),
" for ", atom_to_list(Op), " is invalid."])];
partition([], []) ->
clique_status:usage().
Expand All @@ -235,13 +255,13 @@ id_out(InputType, Number) ->
id_out1(index, Index, Ring, RingSize) ->
Owner = riak_core_ring:index_owner(Ring, Index),
clique_status:text(
io_lib:format("Partition index: ~p -> id: ~p~n(owner: ~p)",
io_lib:format("Partition index: ~p -> id: ~p~n(owner: ~p)",
[Index, hash_to_partition_id(Index, RingSize), Owner]));
id_out1(id, Id, Ring, RingSize) when Id < RingSize ->
Idx = partition_id_to_hash(Id, RingSize),
Owner = riak_core_ring:index_owner(Ring, Idx),
clique_status:text(
io_lib:format("Partition id: ~p -> index: ~p~n(owner: ~p)~n",
io_lib:format("Partition id: ~p -> index: ~p~n(owner: ~p)~n",
[Id, partition_id_to_hash(Id, RingSize), Owner]));
id_out1(id, Id, _Ring, _RingSize) ->
make_alert(["ERROR: Id ", integer_to_list(Id), " is invalid."]).
Expand All @@ -253,16 +273,15 @@ id_out1(id, Id, _Ring, _RingSize) ->
members_register() ->
[["riak-admin", "cluster", "members"], % Cmd
[], % KeySpecs
[{all, [{shortname, "a"},
[{all, [{shortname, "a"},
{longname, "all"}]}], % FlagSpecs
fun members/2]. % Implementation callback

members_usage() ->
Text = ["riak-admin cluster members [--all]\n\n",
"Returns node names for all valid members in the cluster.\n",
"If you want *all* members regardless of status, give the\n",
"'--all' flag.\n"],
[["riak-admin", "cluster", "members"], Text].
["riak-admin cluster members [--all]\n\n",
"Returns node names for all valid members in the cluster.\n",
"If you want *all* members regardless of status, give the\n",
"'--all' flag.\n"].

members([], [{all, _Value}]) ->
member_output(get_status());
Expand All @@ -278,11 +297,11 @@ get_status() ->
{ok, Ring} = riak_core_ring_manager:get_my_ring(),
lists:keysort(2, riak_core_ring:all_member_status(Ring)).

%%%
%%%
%% Internal
%%%

make_alert(Iolist) ->
make_alert(Iolist) ->
Text = [clique_status:text(Iolist)],
clique_status:alert(Text).

Expand Down
37 changes: 20 additions & 17 deletions src/riak_core_handoff_cli.erl
Expand Up @@ -59,27 +59,26 @@ register_cli_usage() ->

handoff_usage() ->
[
["riak-admin", "handoff"],
[
"riak-admin handoff <sub-command>\n\n",
" View handoff related status and settings.\n\n",
" Display handoff-related status and settings.\n\n",
" Sub-commands:\n",
" enable Enable handoffs for the specified node(s)\n",
" disable Disable handoffs for the specified node(s)\n"
" enable Enable handoffs for the specified node(s)\n",
" disable Disable handoffs for the specified node(s)\n"
" summary Show cluster-wide handoff summary\n",
" details Show details of all active transfers (per-node or cluster wide)."
]
" details Show details of all active transfers (per-node or cluster wide)\n\n",
" Use --help after a sub-command for more details.\n"
].

handoff_enable_disable_usage() ->
["riak-admin handoff <enable | disable> <inbound | outbound | both> ",
"[[--node | -n] <Node>] [--all]\n\n",
" Enable or disable handoffs on the specified node(s).\n",
["riak-admin handoff <enable|disable> <inbound|outbound|both> ",
"[-n <node>|--all]\n\n",
" Enable or disable handoffs on the local or specified node(s).\n",
" If handoffs are disabled in a direction, any currently\n",
" running handoffs in that direction will be terminated.\n\n"
"Options\n",
" -n <Node>, --node <Node>\n",
" Modify the setting on the specified node (default: local node only)\n",
" -n <node>, --node <node>\n",
" Modify the setting on the specified node.\n",
" This flag can currently take only one node and be used once\n"
" -a, --all\n",
" Modify the setting on every node in the cluster\n"
].
Expand Down Expand Up @@ -121,15 +120,19 @@ details_command_spec() ->
summary_usage() ->
[
"riak-admin handoff summary\n\n",
"Displays a summarized view of handoffs.\n"
" Display a summarized view of handoffs.\n"
].

details_usage() ->
[
"riak-admin handoff details [--node node] [--all]\n\n",
"Displays a detailed list of handoffs occuring on the \n",
"current node (no flags), another node (using --node), or \n",
"the entire cluster (using --all)\n"
"riak-admin handoff details [--node <node>|--all]\n\n",
" Display a detailed list of handoffs. Defaults to local node.\n\n"
"Options\n",
" -n <node>, --node <node>\n",
" Display the handoffs on the specified node.\n",
" This flag can currently take only one node and be used once\n"
" -a, --all\n",
" Display the handoffs on every node in the cluster\n"
].


Expand Down

0 comments on commit 1fcb001

Please sign in to comment.