|
|
@@ -28,17 +28,17 @@
|
|
|
%%--------------------------------------------------------------------
|
|
|
%% exported API
|
|
|
%%--------------------------------------------------------------------
|
|
|
--spec with_node(binary(), fun((atom()) -> {ok, term()} | {error, term()})) ->
|
|
|
+-spec with_node(binary() | atom(), fun((atom()) -> {ok, term()} | {error, term()})) ->
|
|
|
?OK(term()) | ?NOT_FOUND(binary()) | ?BAD_REQUEST(term()).
|
|
|
-with_node(BinNode, Fun) ->
|
|
|
- case lookup_node(BinNode) of
|
|
|
+with_node(Node0, Fun) ->
|
|
|
+ case lookup_node(Node0) of
|
|
|
{ok, Node} ->
|
|
|
handle_result(Fun(Node));
|
|
|
not_found ->
|
|
|
- ?NODE_NOT_FOUND(BinNode)
|
|
|
+ ?NODE_NOT_FOUND(Node0)
|
|
|
end.
|
|
|
|
|
|
--spec with_node_or_cluster(binary(), fun((atom()) -> {ok, term()} | {error, term()})) ->
|
|
|
+-spec with_node_or_cluster(binary() | atom(), fun((atom()) -> {ok, term()} | {error, term()})) ->
|
|
|
?OK(term()) | ?NOT_FOUND(iolist()) | ?BAD_REQUEST(term()).
|
|
|
with_node_or_cluster(<<"all">>, Fun) ->
|
|
|
handle_result(Fun(all));
|
|
|
@@ -49,18 +49,24 @@ with_node_or_cluster(Node, Fun) ->
|
|
|
%% Internal
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
|
|
--spec lookup_node(binary()) -> {ok, atom()} | not_found.
|
|
|
-lookup_node(BinNode) ->
|
|
|
+-spec lookup_node(atom() | binary()) -> {ok, atom()} | not_found.
|
|
|
+lookup_node(BinNode) when is_binary(BinNode) ->
|
|
|
case emqx_misc:safe_to_existing_atom(BinNode, utf8) of
|
|
|
{ok, Node} ->
|
|
|
- case lists:member(Node, mria:running_nodes()) of
|
|
|
- true ->
|
|
|
- {ok, Node};
|
|
|
- false ->
|
|
|
- not_found
|
|
|
- end;
|
|
|
+ is_running_node(Node);
|
|
|
_Error ->
|
|
|
not_found
|
|
|
+ end;
|
|
|
+lookup_node(Node) when is_atom(Node) ->
|
|
|
+ is_running_node(Node).
|
|
|
+
|
|
|
+-spec is_running_node(atom()) -> {ok, atom()} | not_found.
|
|
|
+is_running_node(Node) ->
|
|
|
+ case lists:member(Node, mria:running_nodes()) of
|
|
|
+ true ->
|
|
|
+ {ok, Node};
|
|
|
+ false ->
|
|
|
+ not_found
|
|
|
end.
|
|
|
|
|
|
handle_result({ok, Result}) ->
|