Feng před 10 roky
rodič
revize
b9b75fdb65
2 změnil soubory, kde provedl 52 přidání a 22 odebrání
  1. 2 22
      src/emqttd_cli.erl
  2. 50 0
      src/emqttd_dist.erl

+ 2 - 22
src/emqttd_cli.erl

@@ -43,8 +43,6 @@
          clients/1, sessions/1, plugins/1, listeners/1,
          vm/1, mnesia/1, trace/1]).
 
--export([node_name/1]).
-
 -define(PROC_INFOKEYS, [status,
                         memory,
                         message_queue_len,
@@ -128,7 +126,7 @@ cluster(usage) ->
     ?PRINT_CMD("cluster [<Node>]", "cluster with node, query cluster info ");
 
 cluster([SNode]) ->
-    Node = node_name(SNode),
+    Node = emqttd_dist:parse_node(SNode),
     case lists:member(Node, emqttd_broker:running_nodes()) of
         true ->
             ?PRINT("~s is already clustered~n", [Node]);
@@ -161,7 +159,7 @@ cluster(pong, Node, DoCluster) ->
     end;
 
 cluster(pang, Node, _DoCluster) ->
-    ?PRINT("Failed to connect ~s~n", [Node]).
+    ?PRINT("Cannot connect to ~s~n", [Node]).
 
 %%------------------------------------------------------------------------------
 %% @doc Query clients
@@ -409,24 +407,6 @@ listeners([]) ->
 listeners(_) ->
     ?PRINT_CMD("listeners", "query broker listeners").
 
-node_name(SNode) ->
-    SNode1 =
-    case string:tokens(SNode, "@") of
-        [_Node, _Server] ->
-            SNode;
-        _ ->
-            case net_kernel:longnames() of
-             true ->
-                 SNode ++ "@" ++ inet_db:gethostname() ++
-                      "." ++ inet_db:res_option(domain);
-             false ->
-                 SNode ++ "@" ++ inet_db:gethostname();
-             _ ->
-                 SNode
-             end
-    end,
-    list_to_atom(SNode1).
-
 print(#mqtt_plugin{name = Name, version = Ver, descr = Descr, active = Active}) ->
     ?PRINT("Plugin(~s, version=~s, description=~s, active=~s)~n",
                [Name, Ver, Descr, Active]);

+ 50 - 0
src/emqttd_dist.erl

@@ -0,0 +1,50 @@
+%%%-----------------------------------------------------------------------------
+%%% Copyright (c) 2012-2015 eMQTT.IO, All Rights Reserved.
+%%%
+%%% Permission is hereby granted, free of charge, to any person obtaining a copy
+%%% of this software and associated documentation files (the "Software"), to deal
+%%% in the Software without restriction, including without limitation the rights
+%%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+%%% copies of the Software, and to permit persons to whom the Software is
+%%% furnished to do so, subject to the following conditions:
+%%%
+%%% The above copyright notice and this permission notice shall be included in all
+%%% copies or substantial portions of the Software.
+%%%
+%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+%%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+%%% SOFTWARE.
+%%%-----------------------------------------------------------------------------
+%%% @doc
+%%% emqttd distribution functions.
+%%%
+%%% @end
+%%%-----------------------------------------------------------------------------
+
+-module(emqttd_dist).
+
+-export([parse_node/1]).
+
+parse_node(Name) when is_list(Name) ->
+    case string:tokens(Name, "@") of
+        [_Node, _Server] ->
+            list_to_atom(Name);
+        _ ->
+            list_to_atom(with_domain(Name))
+    end.
+
+with_domain(Name) ->
+    case net_kernel:longnames() of
+    true ->
+        Name ++ "@" ++ inet_db:gethostname() ++
+             "." ++ inet_db:res_option(domain);
+    false ->
+        Name ++ "@" ++ inet_db:gethostname();
+    _ ->
+        Name
+    end.
+