summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexey Lebedeff <alebedev@mirantis.com>2016-07-14 15:46:08 +0300
committerAlexey Lebedeff <alebedev@mirantis.com>2016-07-14 15:46:08 +0300
commitdb33a5669e3b48f216dd7003a4d076bc3bd992c8 (patch)
tree6fc3208a525c0a3628e2008f915e89f368849c0a /src
parent78a9220e077f79055c225f0f319cbabe13eb3c50 (diff)
parent0c316fc3b6c135236fb0a267b31595dc5762f9eb (diff)
downloadrabbitmq-server-git-db33a5669e3b48f216dd7003a4d076bc3bd992c8.tar.gz
Merge local `node_health_check` into `master`
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_control_main.erl56
1 files changed, 36 insertions, 20 deletions
diff --git a/src/rabbit_control_main.erl b/src/rabbit_control_main.erl
index b9b21352ae..7f410ac752 100644
--- a/src/rabbit_control_main.erl
+++ b/src/rabbit_control_main.erl
@@ -114,13 +114,15 @@
[stop, stop_app, start_app, wait, reset, force_reset, rotate_logs,
join_cluster, change_cluster_node_type, update_cluster_nodes,
forget_cluster_node, rename_cluster_node, cluster_status, status,
- environment, eval, force_boot, help, node_health_check, hipe_compile]).
+ environment, eval, force_boot, help, hipe_compile]).
+%% [Command | {Command, DefaultTimeoutInMilliSeconds}]
-define(COMMANDS_WITH_TIMEOUT,
[list_user_permissions, list_policies, list_queues, list_exchanges,
list_bindings, list_connections, list_channels, list_consumers,
list_vhosts, list_parameters,
- purge_queue]).
+ purge_queue,
+ {node_health_check, 70000}]).
%%----------------------------------------------------------------------------
@@ -152,7 +154,7 @@ start() ->
end
end,
try
- T = case get_timeout(Opts) of
+ T = case get_timeout(Command, Opts) of
{ok, Timeout} ->
Timeout;
{error, _} ->
@@ -187,8 +189,23 @@ print_report0(Node, {Module, InfoFun, KeysFun}, VHostArg) ->
end,
io:nl().
-get_timeout(Opts) ->
- parse_timeout(proplists:get_value(?TIMEOUT_OPT, Opts, ?RPC_TIMEOUT)).
+get_timeout(Command, Opts) ->
+ Default = case proplists:lookup(Command, ?COMMANDS_WITH_TIMEOUT) of
+ none ->
+ infinity;
+ {Command, true} ->
+ ?RPC_TIMEOUT;
+ {Command, D} ->
+ D
+ end,
+ Result = case proplists:get_value(?TIMEOUT_OPT, Opts, Default) of
+ use_default ->
+ parse_timeout(Default);
+ Value ->
+ parse_timeout(Value)
+ end,
+ Result.
+
parse_number(N) when is_list(N) ->
try list_to_integer(N) of
@@ -234,11 +251,11 @@ do_action(Command, Node, Args, Opts, Inform, Timeout) ->
false ->
case ensure_app_running(Node) of
ok ->
- case lists:member(Command, ?COMMANDS_WITH_TIMEOUT) of
- true ->
+ case proplists:lookup(Command, ?COMMANDS_WITH_TIMEOUT) of
+ {Command, _} ->
announce_timeout(Timeout, Inform),
action(Command, Node, Args, Opts, Inform, Timeout);
- false ->
+ none ->
action(Command, Node, Args, Opts, Inform)
end;
E -> E
@@ -559,17 +576,6 @@ action(eval, Node, [Expr], _Opts, _Inform) ->
action(help, _Node, _Args, _Opts, _Inform) ->
io:format("~s", [rabbit_ctl_usage:usage()]);
-action(node_health_check, Node, _Args, _Opts, Inform) ->
- Inform("Checking health of node ~p", [Node]),
- try
- rabbit_health_check:node(Node),
- io:format("Health check passed~n")
- catch
- {node_is_ko, ErrorMsg, ErrorCode} ->
- io:format("Heath check failed:~n~s~n", [ErrorMsg]),
- halt(ErrorCode)
- end;
-
action(Command, Node, Args, Opts, Inform) ->
%% For backward compatibility, run commands accepting a timeout with
%% the default timeout.
@@ -685,7 +691,17 @@ action(list_consumers, Node, _Args, Opts, Inform, Timeout) ->
Nodes = nodes_in_cluster(Node, Timeout),
call_emitter(Node, {rabbit_amqqueue, emit_consumers_all, [Nodes, VHostArg]},
rabbit_amqqueue:consumer_info_keys(),
- [{timeout, Timeout}, {chunks, length(Nodes)}]).
+ [{timeout, Timeout}, {chunks, length(Nodes)}]);
+
+action(node_health_check, Node, _Args, _Opts, Inform, Timeout) ->
+ Inform("Checking health of node ~p", [Node]),
+ case rabbit_health_check:node(Node, Timeout) of
+ ok ->
+ io:format("Health check passed~n"),
+ ok;
+ Other ->
+ Other
+ end.
format_parse_error({_Line, Mod, Err}) -> lists:flatten(Mod:format_error(Err)).