diff options
-rw-r--r-- | src/rabbit_control.erl | 2 | ||||
-rw-r--r-- | src/rabbit_misc.erl | 20 | ||||
-rw-r--r-- | src/rabbit_nodes.erl | 23 | ||||
-rw-r--r-- | src/rabbit_prelaunch.erl | 4 | ||||
-rw-r--r-- | src/rabbit_tests.erl | 4 |
5 files changed, 26 insertions, 27 deletions
diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index 48d319c8..06efaaa7 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -66,7 +66,7 @@ start() -> CmdArgsAndOpts -> CmdArgsAndOpts end, Opts1 = [case K of - ?NODE_OPT -> {?NODE_OPT, rabbit_misc:makenode(V)}; + ?NODE_OPT -> {?NODE_OPT, rabbit_nodes:make(V)}; _ -> {K, V} end || {K, V} <- Opts], Command = list_to_atom(Command0), diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 0578cf7d..ea9567dd 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -34,7 +34,7 @@ -export([execute_mnesia_transaction/2]). -export([execute_mnesia_tx_with_tail/1]). -export([ensure_ok/2]). --export([makenode/1, nodeparts/1, cookie_hash/0, tcp_name/3]). +-export([cookie_hash/0, tcp_name/3]). -export([upmap/2, map_in_order/2]). -export([table_filter/3]). -export([dirty_read_all/1, dirty_foreach_key/2, dirty_dump_log/1]). @@ -141,8 +141,6 @@ -spec(execute_mnesia_tx_with_tail/1 :: (thunk(fun ((boolean()) -> B))) -> B | (fun ((boolean()) -> B))). -spec(ensure_ok/2 :: (ok_or_error(), atom()) -> 'ok'). --spec(makenode/1 :: ({string(), string()} | string()) -> node()). --spec(nodeparts/1 :: (node() | string()) -> {string(), string()}). -spec(cookie_hash/0 :: () -> string()). -spec(tcp_name/3 :: (atom(), inet:ip_address(), rabbit_networking:ip_port()) @@ -337,7 +335,7 @@ enable_cover(Dirs) -> end, ok, Dirs). start_cover(NodesS) -> - {ok, _} = cover:start([makenode(N) || N <- NodesS]), + {ok, _} = cover:start([rabbit_nodes:make(N) || N <- NodesS]), ok. report_cover() -> report_cover(["."]). @@ -450,20 +448,6 @@ execute_mnesia_tx_with_tail(TxFun) -> ensure_ok(ok, _) -> ok; ensure_ok({error, Reason}, ErrorTag) -> throw({error, {ErrorTag, Reason}}). -makenode({Prefix, Suffix}) -> - list_to_atom(lists:append([Prefix, "@", Suffix])); -makenode(NodeStr) -> - makenode(nodeparts(NodeStr)). - -nodeparts(Node) when is_atom(Node) -> - nodeparts(atom_to_list(Node)); -nodeparts(NodeStr) -> - case lists:splitwith(fun (E) -> E =/= $@ end, NodeStr) of - {Prefix, []} -> {_, Suffix} = nodeparts(node()), - {Prefix, Suffix}; - {Prefix, Suffix} -> {Prefix, tl(Suffix)} - end. - cookie_hash() -> base64:encode_to_string(erlang:md5(atom_to_list(erlang:get_cookie()))). diff --git a/src/rabbit_nodes.erl b/src/rabbit_nodes.erl index f3305127..9a39d16b 100644 --- a/src/rabbit_nodes.erl +++ b/src/rabbit_nodes.erl @@ -11,12 +11,12 @@ %% The Original Code is RabbitMQ. %% %% The Initial Developer of the Original Code is VMware, Inc. -%% Copyright (c) 2007-2011 VMware, Inc. All rights reserved. +%% Copyright (c) 2007-2012 VMware, Inc. All rights reserved. %% -module(rabbit_nodes). --export([names/1, diagnostics/1]). +-export([names/1, diagnostics/1, make/1, parts/1]). -define(EPMD_TIMEOUT, 30000). @@ -29,6 +29,8 @@ -spec(names/1 :: (string()) -> rabbit_types:ok_or_error2( [{string(), integer()}], term())). -spec(diagnostics/1 :: ([node()]) -> string()). +-spec(make/1 :: ({string(), string()} | string()) -> node()). +-spec(parts/1 :: (node() | string()) -> {string(), string()}). -endif. @@ -47,8 +49,7 @@ names(Hostname) -> Res. diagnostics(Nodes) -> - Hosts = lists:usort([element(2, rabbit_misc:nodeparts(Node)) || - Node <- Nodes]), + Hosts = lists:usort([element(2, parts(Node)) || Node <- Nodes]), NodeDiags = [{"~nDIAGNOSTICS~n===========~n~n" "nodes in question: ~p~n~n" "hosts, their running nodes and ports:", [Nodes]}] ++ @@ -75,3 +76,17 @@ diagnostics_host(Host) -> [Host, [{list_to_atom(Name), Port} || {Name, Port} <- NamePorts]]} end. + +make({Prefix, Suffix}) -> + list_to_atom(lists:append([Prefix, "@", Suffix])); +make(NodeStr) -> + make(parts(NodeStr)). + +parts(Node) when is_atom(Node) -> + parts(atom_to_list(Node)); +parts(NodeStr) -> + case lists:splitwith(fun (E) -> E =/= $@ end, NodeStr) of + {Prefix, []} -> {_, Suffix} = parts(node()), + {Prefix, Suffix}; + {Prefix, Suffix} -> {Prefix, tl(Suffix)} + end. diff --git a/src/rabbit_prelaunch.erl b/src/rabbit_prelaunch.erl index 2dc1b156..b3d18e42 100644 --- a/src/rabbit_prelaunch.erl +++ b/src/rabbit_prelaunch.erl @@ -243,8 +243,8 @@ duplicate_node_check([]) -> %% Ignore running node while installing windows service ok; duplicate_node_check(NodeStr) -> - Node = rabbit_misc:makenode(NodeStr), - {NodeName, NodeHost} = rabbit_misc:nodeparts(Node), + Node = rabbit_nodes:make(NodeStr), + {NodeName, NodeHost} = rabbit_nodes:parts(Node), case rabbit_nodes:names(NodeHost) of {ok, NamePorts} -> case proplists:is_defined(NodeName, NamePorts) of diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index 343e79e5..234ad470 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -59,7 +59,7 @@ all_tests() -> passed. maybe_run_cluster_dependent_tests() -> - SecondaryNode = rabbit_misc:makenode("hare"), + SecondaryNode = rabbit_nodes:make("hare"), case net_adm:ping(SecondaryNode) of pong -> passed = run_cluster_dependent_tests(SecondaryNode); @@ -859,7 +859,7 @@ test_cluster_management() -> "invalid2@invalid"]), ok = assert_ram_node(), - SecondaryNode = rabbit_misc:makenode("hare"), + SecondaryNode = rabbit_nodes:make("hare"), case net_adm:ping(SecondaryNode) of pong -> passed = test_cluster_management2(SecondaryNode); pang -> io:format("Skipping clustering tests with node ~p~n", |