Merge pull request #6699 from JimMoen/fix-sub-info
fix(mgmt): fix subscription info format
This commit is contained in:
commit
92f1b5b01a
|
@ -59,3 +59,4 @@ erlang_ls.config
|
||||||
*#
|
*#
|
||||||
# For direnv
|
# For direnv
|
||||||
.envrc
|
.envrc
|
||||||
|
mix.lock
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{application, emqx_management,
|
{application, emqx_management,
|
||||||
[{description, "EMQ X Management API and CLI"},
|
[{description, "EMQ X Management API and CLI"},
|
||||||
{vsn, "4.3.10"}, % strict semver, bump manually!
|
{vsn, "4.3.11"}, % strict semver, bump manually!
|
||||||
{modules, []},
|
{modules, []},
|
||||||
{registered, [emqx_management_sup]},
|
{registered, [emqx_management_sup]},
|
||||||
{applications, [kernel,stdlib,minirest]},
|
{applications, [kernel,stdlib,minirest]},
|
||||||
|
|
|
@ -58,8 +58,8 @@
|
||||||
-export([ list_subscriptions/1
|
-export([ list_subscriptions/1
|
||||||
, list_subscriptions_via_topic/2
|
, list_subscriptions_via_topic/2
|
||||||
, list_subscriptions_via_topic/3
|
, list_subscriptions_via_topic/3
|
||||||
, lookup_subscriptions/1
|
|
||||||
, lookup_subscriptions/2
|
, lookup_subscriptions/2
|
||||||
|
, lookup_subscriptions/3
|
||||||
]).
|
]).
|
||||||
|
|
||||||
%% Routes
|
%% Routes
|
||||||
|
@ -322,18 +322,20 @@ list_subscriptions_via_topic(Node, Topic, {M,F}) when Node =:= node() ->
|
||||||
list_subscriptions_via_topic(Node, Topic, FormatFun) ->
|
list_subscriptions_via_topic(Node, Topic, FormatFun) ->
|
||||||
rpc_call(Node, list_subscriptions_via_topic, [Node, Topic, FormatFun]).
|
rpc_call(Node, list_subscriptions_via_topic, [Node, Topic, FormatFun]).
|
||||||
|
|
||||||
lookup_subscriptions(ClientId) ->
|
lookup_subscriptions(ClientId, FormatFun) ->
|
||||||
lists:append([lookup_subscriptions(Node, ClientId) || Node <- ekka_mnesia:running_nodes()]).
|
lists:append([lookup_subscriptions(Node, ClientId, FormatFun) || Node <- ekka_mnesia:running_nodes()]).
|
||||||
|
|
||||||
lookup_subscriptions(Node, ClientId) when Node =:= node() ->
|
lookup_subscriptions(Node, ClientId, {M, F}) when Node =:= node() ->
|
||||||
case ets:lookup(emqx_subid, ClientId) of
|
Result = case ets:lookup(emqx_subid, ClientId) of
|
||||||
[] -> [];
|
[] -> [];
|
||||||
[{_, Pid}] ->
|
[{_, Pid}] ->
|
||||||
ets:match_object(emqx_suboption, {{Pid, '_'}, '_'})
|
ets:match_object(emqx_suboption, {{Pid, '_'}, '_'})
|
||||||
end;
|
end,
|
||||||
|
%% format at the called node
|
||||||
|
erlang:apply(M, F, [Result]);
|
||||||
|
|
||||||
lookup_subscriptions(Node, ClientId) ->
|
lookup_subscriptions(Node, ClientId, FormatFun) ->
|
||||||
rpc_call(Node, lookup_subscriptions, [Node, ClientId]).
|
rpc_call(Node, lookup_subscriptions, [Node, ClientId, FormatFun]).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Routes
|
%% Routes
|
||||||
|
|
|
@ -85,10 +85,10 @@ list(#{node := Node} = Bindings, Params) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
lookup(#{node := Node, clientid := ClientId}, _Params) ->
|
lookup(#{node := Node, clientid := ClientId}, _Params) ->
|
||||||
minirest:return({ok, format(emqx_mgmt:lookup_subscriptions(Node, emqx_mgmt_util:urldecode(ClientId)))});
|
minirest:return({ok, emqx_mgmt:lookup_subscriptions(Node, emqx_mgmt_util:urldecode(ClientId), ?format_fun)});
|
||||||
|
|
||||||
lookup(#{clientid := ClientId}, _Params) ->
|
lookup(#{clientid := ClientId}, _Params) ->
|
||||||
minirest:return({ok, format(emqx_mgmt:lookup_subscriptions(emqx_mgmt_util:urldecode(ClientId)))}).
|
minirest:return({ok, emqx_mgmt:lookup_subscriptions(emqx_mgmt_util:urldecode(ClientId), ?format_fun)}).
|
||||||
|
|
||||||
format(Items) when is_list(Items) ->
|
format(Items) when is_list(Items) ->
|
||||||
[format(Item) || Item <- Items];
|
[format(Item) || Item <- Items];
|
||||||
|
|
Loading…
Reference in New Issue