summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiana Corbacho <diana.corbacho@erlang-solutions.com>2016-02-25 16:27:54 +0000
committerDiana Corbacho <diana.corbacho@erlang-solutions.com>2016-02-25 16:27:54 +0000
commite6cea86b4d4db00b182083a1ed34f8e0c8336415 (patch)
treeef46e769d0d3f178bc7004ff5c96ad88b7f5ee94
parent0b8e52ae62fb80ce4902c7fddc9aaf5f522483dd (diff)
downloadrabbitmq-server-git-e6cea86b4d4db00b182083a1ed34f8e0c8336415.tar.gz
Move health checks to rabbit_common and rabbit_cli:rpc_call to rabbit/rabbit_misc
-rw-r--r--include/rabbit_cli.hrl2
-rw-r--r--src/rabbit_cli.erl23
-rw-r--r--src/rabbit_control_main.erl62
-rw-r--r--src/rabbit_plugins_main.erl4
4 files changed, 8 insertions, 83 deletions
diff --git a/include/rabbit_cli.hrl b/include/rabbit_cli.hrl
index 2e687e2eb8..7f5db6053b 100644
--- a/include/rabbit_cli.hrl
+++ b/include/rabbit_cli.hrl
@@ -47,8 +47,6 @@
-define(OFFLINE_DEF, {?OFFLINE_OPT, flag}).
-define(ONLINE_DEF, {?ONLINE_OPT, flag}).
--define(RPC_TIMEOUT, infinity).
-
%% Subset of standartized exit codes from sysexits.h, see
%% https://github.com/rabbitmq/rabbitmq-server/issues/396 for discussion.
-define(EX_OK , 0).
diff --git a/src/rabbit_cli.erl b/src/rabbit_cli.erl
index 4aad3c0916..b9b15b20a4 100644
--- a/src/rabbit_cli.erl
+++ b/src/rabbit_cli.erl
@@ -18,7 +18,7 @@
-include("rabbit_cli.hrl").
-export([main/3, start_distribution/0, start_distribution/1,
- parse_arguments/4, rpc_call/4, rpc_call/5, rpc_call/7]).
+ parse_arguments/4]).
%%----------------------------------------------------------------------------
@@ -38,10 +38,6 @@
-spec(parse_arguments/4 ::
([{atom(), [{string(), optdef()}]} | atom()],
[{string(), optdef()}], string(), [string()]) -> parse_result()).
--spec(rpc_call/4 :: (node(), atom(), atom(), [any()]) -> any()).
--spec(rpc_call/5 :: (node(), atom(), atom(), [any()], number()) -> any()).
--spec(rpc_call/7 :: (node(), atom(), atom(), [any()], reference(), pid(),
- number()) -> any()).
-endif.
@@ -249,20 +245,3 @@ print_error(Format, Args) -> fmt_stderr("Error: " ++ Format, Args).
print_badrpc_diagnostics(Nodes) ->
fmt_stderr(rabbit_nodes:diagnostics(Nodes), []).
-
-%% If the server we are talking to has non-standard net_ticktime, and
-%% our connection lasts a while, we could get disconnected because of
-%% a timeout unless we set our ticktime to be the same. So let's do
-%% that.
-rpc_call(Node, Mod, Fun, Args) ->
- rpc_call(Node, Mod, Fun, Args, ?RPC_TIMEOUT).
-
-rpc_call(Node, Mod, Fun, Args, Timeout) ->
- case rpc:call(Node, net_kernel, get_net_ticktime, [], Timeout) of
- {badrpc, _} = E -> E;
- Time -> net_kernel:set_net_ticktime(Time, 0),
- rpc:call(Node, Mod, Fun, Args, Timeout)
- end.
-
-rpc_call(Node, Mod, Fun, Args, Ref, Pid, Timeout) ->
- rpc_call(Node, Mod, Fun, Args++[Ref, Pid], Timeout).
diff --git a/src/rabbit_control_main.erl b/src/rabbit_control_main.erl
index 1b27990d03..8b3b0273ce 100644
--- a/src/rabbit_control_main.erl
+++ b/src/rabbit_control_main.erl
@@ -17,15 +17,15 @@
-module(rabbit_control_main).
-include("rabbit.hrl").
-include("rabbit_cli.hrl").
+-include("rabbit_misc.hrl").
-export([start/0, stop/0, parse_arguments/2, action/5, action/6,
sync_queue/1, cancel_sync_queue/1, become/1,
purge_queue/1]).
--import(rabbit_cli, [rpc_call/4, rpc_call/5, rpc_call/7]).
+-import(rabbit_misc, [rpc_call/4, rpc_call/5, rpc_call/7]).
-define(EXTERNAL_CHECK_INTERVAL, 1000).
--define(NODE_HEALTH_CHECK_TIMEOUT, 70000).
-define(GLOBAL_DEFS(Node), [?QUIET_DEF, ?NODE_DEF(Node), ?TIMEOUT_DEF]).
@@ -552,14 +552,11 @@ action(help, _Node, _Args, _Opts, _Inform) ->
action(node_health_check, Node, _Args, _Opts, Inform) ->
Inform("Health check of node ~p", [Node]),
try
- node_health_check(Node, is_running),
- node_health_check(Node, list_channels),
- node_health_check(Node, list_queues),
- node_health_check(Node, alarms),
+ rabbit_health_check:node(Node),
io:format("Node ~p is up and running~n", [Node])
catch
- node_is_ko ->
- io:format("Problems encountered in node ~p~n", [Node])
+ {node_is_ko, ErrorMsg} ->
+ io:format("~s~nProblems encountered in node ~p~n", [ErrorMsg, Node])
end;
action(Command, Node, Args, Opts, Inform) ->
@@ -904,52 +901,3 @@ alarms_by_node(Name) ->
Status = unsafe_rpc(Name, rabbit, status, []),
{_, As} = lists:keyfind(alarms, 1, Status),
{Name, As}.
-
-node_health_check(Node, is_running) ->
- node_health_check(Node, {rabbit, is_running, []},
- fun(true) ->
- true;
- (false) ->
- io:format("rabbit application is not running~n"),
- throw(node_is_ko)
- end);
-node_health_check(Node, list_channels) ->
- node_health_check(Node, {rabbit_channel, info_all, [[pid]]},
- fun(L) when is_list(L) ->
- true;
- (Other) ->
- io:format("list_channels unexpected output: ~p~n", [Other]),
- throw(node_is_ko)
- end);
-node_health_check(Node, list_queues) ->
- node_health_check(Node, {rabbit_amqqueue, info_all, [[pid]]},
- fun(L) when is_list(L) ->
- true;
- (Other) ->
- io:format("list_queues unexpected output: ~p~n", [Other]),
- throw(node_is_ko)
- end);
-node_health_check(Node, alarms) ->
- node_health_check(Node, {rabbit, status, []},
- fun(Props) ->
- case proplists:get_value(alarms, Props) of
- [] ->
- true;
- Alarms ->
- io:format("alarms raised ~p~n", [Alarms]),
- throw(node_is_ko)
- end
- end).
-
-node_health_check(Node, {M, F, A}, Fun) ->
- case rpc_call(Node, M, F, A, ?NODE_HEALTH_CHECK_TIMEOUT) of
- {badrpc, timeout} ->
- io:format("health check of node ~p fails: timed out (~p ms)~n",
- [Node, ?NODE_HEALTH_CHECK_TIMEOUT]),
- throw(node_is_ko);
- {badrpc, Reason} ->
- io:format("health check of node ~p fails: ~p~n", [Node, Reason]),
- throw(node_is_ko);
- Other ->
- Fun(Other)
- end.
diff --git a/src/rabbit_plugins_main.erl b/src/rabbit_plugins_main.erl
index 4aeed4826c..e248989a7a 100644
--- a/src/rabbit_plugins_main.erl
+++ b/src/rabbit_plugins_main.erl
@@ -173,7 +173,7 @@ format_plugins(Node, Pattern, Opts, #cli{all = All,
EnabledImplicitly = Implicit -- Enabled,
{StatusMsg, Running} =
- case rabbit_cli:rpc_call(Node, rabbit_plugins, active, []) of
+ case rabbit_misc:rpc_call(Node, rabbit_plugins, active, []) of
{badrpc, _} -> {"[failed to contact ~s - status not shown]", []};
Active -> {"* = running on ~s", Active}
end,
@@ -279,7 +279,7 @@ sync(Node, ForceOnline, #cli{file = File}) ->
rpc_call(Node, Online, Mod, Fun, Args) ->
io:format("~nApplying plugin configuration to ~s...", [Node]),
- case rabbit_cli:rpc_call(Node, Mod, Fun, Args) of
+ case rabbit_misc:rpc_call(Node, Mod, Fun, Args) of
{ok, [], []} ->
io:format(" nothing to do.~n", []);
{ok, Start, []} ->