|
| 1 | +%% @doc Interface for mfmn-admin commands. |
| 2 | +-module(mfmn_console). |
| 3 | +-export([join/1, |
| 4 | + leave/1, |
| 5 | + remove/1, |
| 6 | + ringready/1]). |
| 7 | + |
| 8 | +join([NodeStr]) -> |
| 9 | + try riak_core:join(NodeStr) of |
| 10 | + ok -> |
| 11 | + io:format("Sent join request to ~s\n", [NodeStr]), |
| 12 | + ok; |
| 13 | + {error, not_reachable} -> |
| 14 | + io:format("Node ~s is not reachable!\n", [NodeStr]), |
| 15 | + error; |
| 16 | + {error, different_ring_sizes} -> |
| 17 | + io:format("Failed: ~s has a different ring_creation_size~n", |
| 18 | + [NodeStr]), |
| 19 | + error |
| 20 | + catch |
| 21 | + Exception:Reason -> |
| 22 | + lager:error("Join failed ~p:~p", [Exception, Reason]), |
| 23 | + io:format("Join failed, see log for details~n"), |
| 24 | + error |
| 25 | + end. |
| 26 | + |
| 27 | +leave([]) -> |
| 28 | + remove_node(node()). |
| 29 | + |
| 30 | +remove([Node]) -> |
| 31 | + remove_node(list_to_atom(Node)). |
| 32 | + |
| 33 | +remove_node(Node) when is_atom(Node) -> |
| 34 | + try catch(riak_core:remove_from_cluster(Node)) of |
| 35 | + {'EXIT', {badarg, [{erlang, hd, [[]]}|_]}} -> |
| 36 | + %% This is a workaround because |
| 37 | + %% riak_core_gossip:remove_from_cluster doesn't check if |
| 38 | + %% the result of subtracting the current node from the |
| 39 | + %% cluster member list results in the empty list. When |
| 40 | + %% that code gets refactored this can probably go away. |
| 41 | + io:format("Leave failed, this node is the only member.~n"), |
| 42 | + error; |
| 43 | + Res -> |
| 44 | + io:format(" ~p\n", [Res]) |
| 45 | + catch |
| 46 | + Exception:Reason -> |
| 47 | + lager:error("Leave failed ~p:~p", [Exception, Reason]), |
| 48 | + io:format("Leave failed, see log for details~n"), |
| 49 | + error |
| 50 | + end. |
| 51 | + |
| 52 | +-spec(ringready([]) -> ok | error). |
| 53 | +ringready([]) -> |
| 54 | + try riak_core_status:ringready() of |
| 55 | + {ok, Nodes} -> |
| 56 | + io:format("TRUE All nodes agree on the ring ~p\n", [Nodes]); |
| 57 | + {error, {different_owners, N1, N2}} -> |
| 58 | + io:format("FALSE Node ~p and ~p list different partition owners\n", |
| 59 | + [N1, N2]), |
| 60 | + error; |
| 61 | + {error, {nodes_down, Down}} -> |
| 62 | + io:format("FALSE ~p down. All nodes need to be up to check.\n", |
| 63 | + [Down]), |
| 64 | + error |
| 65 | + catch |
| 66 | + Exception:Reason -> |
| 67 | + lager:error("Ringready failed ~p:~p", [Exception, Reason]), |
| 68 | + io:format("Ringready failed, see log for details~n"), |
| 69 | + error |
| 70 | + end. |
0 commit comments