diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2011-12-16 17:00:40 +0000 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2011-12-16 17:00:40 +0000 |
commit | eda932b35ff58c6ffd9b46522ad33380915c3d4a (patch) | |
tree | 20aca8ea1544cd5d9ffb1eff7c6735b6fafc985e | |
parent | 49f181c2cf8aa7d185b388ffe00e72568148454d (diff) | |
download | rabbitmq-server-eda932b35ff58c6ffd9b46522ad33380915c3d4a.tar.gz |
Make rabbit:diagnostics/1 just return a string. It's still most convenient to assemble it the way we did before, but now the API is saner.
-rw-r--r-- | src/rabbit.erl | 38 | ||||
-rw-r--r-- | src/rabbit_control.erl | 2 | ||||
-rw-r--r-- | src/rabbit_prelaunch.erl | 3 |
3 files changed, 22 insertions, 21 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl index bcc4dfde..8e747b7a 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -235,7 +235,7 @@ {'required',[any(),...]}}} | {'ok',pid()}). -spec(stop/1 :: (_) -> 'ok'). --spec(diagnostics/1 :: ([node()]) -> [{string(), [any()]}]). +-spec(diagnostics/1 :: ([node()]) -> string()). -endif. @@ -490,19 +490,15 @@ sort_boot_steps(UnsortedSteps) -> end. boot_failed({error, {timeout_waiting_for_tables, _}}, _Stacktrace) -> - {Fmt0, Args0, Nodes} = + {Err, Nodes} = case rabbit_mnesia:read_previously_running_nodes() of [] -> {"Timeout waiting for tables.~n" - "Diagnostics for all cluster nodes follow:~n", [], + "Diagnostics for all cluster nodes follow:~n", rabbit_mnesia:all_clustered_nodes()}; - Ns -> {"Timeout waiting for tables from nodes: ~p.~n" - "Diagnostics for these nodes follow:~n", [Ns], Ns} + Ns -> {format("Timeout waiting for tables from nodes: ~p.~n" + "Diagnostics for these nodes follow:~n", [Ns]), Ns} end, - {Fmt, Args} = lists:foldl( - fun({F, A}, {Fmt1, Args1}) -> - {Fmt1 ++ "~n" ++ F, Args1 ++ A} - end, {[], []}, [{Fmt0, Args0} | diagnostics(Nodes)]), - boot_error(Fmt ++ "~n~n", Args); + boot_error(Err ++ diagnostics(Nodes) ++ "~n~n", []); boot_failed(Reason, Stacktrace) -> boot_error("FAILED~nReason: ~p~nStacktrace: ~p~n", [Reason, Stacktrace]). @@ -514,17 +510,21 @@ boot_error(Format, Args) -> exit({?MODULE, failure_during_boot}). diagnostics(Nodes) -> - lists:flatten([diagnostics_node(Node) || Node <- Nodes]) ++ - [{"- current node: ~w", [node()]}, - case init:get_argument(home) of - {ok, [[Home]]} -> {"- current node home dir: ~s", [Home]}; - Other -> {"- no current node home dir: ~p", [Other]} - end, - {"- current node cookie hash: ~s", [rabbit_misc:cookie_hash()]}]. + lists:foldl(fun({F, A}, Str) -> Str ++ format(F ++ "~n", A) end, "", + lists:flatten([diagnostics_node(Node) || Node <- Nodes]) ++ + diagnostics0()). + +diagnostics0() -> + [{"- current node: ~w", [node()]}, + case init:get_argument(home) of + {ok, [[Home]]} -> {"- current node home dir: ~s", [Home]}; + Other -> {"- no current node home dir: ~p", [Other]} + end, + {"- current node cookie hash: ~s", [rabbit_misc:cookie_hash()]}]. diagnostics_node(Node) -> {_NodeName, NodeHost} = rabbit_misc:nodeparts(Node), - [{"diagnostics for node ~s:", [Node]}, + [{"~ndiagnostics for node ~s:", [Node]}, case net_adm:names(NodeHost) of {error, EpmdReason} -> {"- unable to connect to epmd on ~s: ~w", @@ -535,6 +535,8 @@ diagnostics_node(Node) -> {Name, Port} <- NamePorts]]} end]. +format(F, A) -> binary_to_list(iolist_to_binary(io_lib:format(F, A))). + %%--------------------------------------------------------------------------- %% boot step functions diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index d2dad500..976c6a12 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -134,7 +134,7 @@ print_report0(Node, {Module, InfoFun, KeysFun}, VHostArg) -> print_error(Format, Args) -> fmt_stderr("Error: " ++ Format, Args). print_badrpc_diagnostics(Node) -> - [fmt_stderr(Fmt, Args) || {Fmt, Args} <- rabbit:diagnostics([Node])]. + fmt_stderr(rabbit:diagnostics([Node]), []). stop() -> ok. diff --git a/src/rabbit_prelaunch.erl b/src/rabbit_prelaunch.erl index 040759f1..5fc67662 100644 --- a/src/rabbit_prelaunch.erl +++ b/src/rabbit_prelaunch.erl @@ -252,8 +252,7 @@ duplicate_node_check(NodeStr) -> true -> io:format("node with name ~p " "already running on ~p~n", [NodeName, NodeHost]), - [io:format(Fmt ++ "~n", Args) || - {Fmt, Args} <- rabbit:diagnostics([Node])], + io:format(rabbit:diagnostics([Node]) ++ "~n"), terminate(?ERROR_CODE); false -> ok end; |