forked from basho/rebar_riak_core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathriak_core_console.erl
97 lines (92 loc) · 3.31 KB
/
riak_core_console.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
%% @doc Interface for riak_searchng-admin commands.
-module({{appid}}_console).
-export([staged_join/1,
down/1,
ringready/1]).
-ignore_xref([join/1,
leave/1,
remove/1,
ringready/1]).
staged_join([NodeStr]) ->
Node = list_to_atom(NodeStr),
join(NodeStr, fun riak_core:staged_join/1,
"Success: staged join request for ~p to ~p~n", [node(), Node]).
join(NodeStr, JoinFn, SuccessFmt, SuccessArgs) ->
try
case JoinFn(NodeStr) of
ok ->
io:format(SuccessFmt, SuccessArgs),
ok;
{error, not_reachable} ->
io:format("Node ~s is not reachable!~n", [NodeStr]),
error;
{error, different_ring_sizes} ->
io:format("Failed: ~s has a different ring_creation_size~n",
[NodeStr]),
error;
{error, unable_to_get_join_ring} ->
io:format("Failed: Unable to get ring from ~s~n", [NodeStr]),
error;
{error, not_single_node} ->
io:format("Failed: This node is already a member of a "
"cluster~n"),
error;
{error, self_join} ->
io:format("Failed: This node cannot join itself in a "
"cluster~n"),
error;
{error, _} ->
io:format("Join failed. Try again in a few moments.~n", []),
error
end
catch
Exception:Reason ->
lager:error("Join failed ~p:~p", [Exception, Reason]),
io:format("Join failed, see log for details~n"),
error
end.
down([Node]) ->
try
case riak_core:down(list_to_atom(Node)) of
ok ->
io:format("Success: ~p marked as down~n", [Node]),
ok;
{error, legacy_mode} ->
io:format("Cluster is currently in legacy mode~n"),
ok;
{error, is_up} ->
io:format("Failed: ~s is up~n", [Node]),
error;
{error, not_member} ->
io:format("Failed: ~p is not a member of the cluster.~n",
[Node]),
error;
{error, only_member} ->
io:format("Failed: ~p is the only member.~n", [Node]),
error
end
catch
Exception:Reason ->
lager:error("Down failed ~p:~p", [Exception, Reason]),
io:format("Down failed, see log for details~n"),
error
end.
ringready([]) ->
try
case riak_core_status:ringready() of
{ok, Nodes} ->
io:format("TRUE All nodes agree on the ring ~p\n", [Nodes]);
{error, {different_owners, N1, N2}} ->
io:format("FALSE Node ~p and ~p list different partition owners\n", [N1, N2]),
error;
{error, {nodes_down, Down}} ->
io:format("FALSE ~p down. All nodes need to be up to check.\n", [Down]),
error
end
catch
Exception:Reason ->
lager:error("Ringready failed ~p:~p", [Exception,
Reason]),
io:format("Ringready failed, see log for details~n"),
error
end.