feat(acl): working cache drain cli/rest handlers
This commit is contained in:
parent
71a0901c92
commit
87ce9d666f
|
@ -43,9 +43,9 @@
|
|||
, lookup_client/3
|
||||
, kickout_client/1
|
||||
, list_acl_cache/1
|
||||
, clean_acl_cache/0
|
||||
, clean_acl_cache/1
|
||||
, clean_acl_cache/2
|
||||
, clean_acl_cache_all/0
|
||||
, clean_acl_cache_all/1
|
||||
, set_ratelimit_policy/2
|
||||
, set_quota_policy/2
|
||||
|
@ -233,13 +233,6 @@ kickout_client(Node, ClientId) ->
|
|||
list_acl_cache(ClientId) ->
|
||||
call_client(ClientId, list_acl_cache).
|
||||
|
||||
clean_acl_cache() ->
|
||||
Results = [clean_acl_cache_all(Node) || Node <- ekka_mnesia:running_nodes()],
|
||||
case lists:any(fun(Item) -> Item =:= ok end, Results) of
|
||||
true -> ok;
|
||||
false -> lists:last(Results)
|
||||
end.
|
||||
|
||||
clean_acl_cache(ClientId) ->
|
||||
Results = [clean_acl_cache(Node, ClientId) || Node <- ekka_mnesia:running_nodes()],
|
||||
case lists:any(fun(Item) -> Item =:= ok end, Results) of
|
||||
|
@ -258,12 +251,18 @@ clean_acl_cache(Node, ClientId) when Node =:= node() ->
|
|||
clean_acl_cache(Node, ClientId) ->
|
||||
rpc_call(Node, clean_acl_cache, [Node, ClientId]).
|
||||
|
||||
clean_acl_cache_all() ->
|
||||
Results = [clean_acl_cache_all(Node) || Node <- ekka_mnesia:running_nodes()],
|
||||
case lists:any(fun(Item) -> Item =:= ok end, Results) of
|
||||
true -> ok;
|
||||
false -> lists:last(Results)
|
||||
end.
|
||||
|
||||
clean_acl_cache_all(Node) when Node =:= node() ->
|
||||
_ = emqx_acl_cache:drain_cache(),
|
||||
ok;
|
||||
emqx_acl_cache:drain_cache();
|
||||
|
||||
clean_acl_cache_all(Node) ->
|
||||
rpc_call(Node, clean_acl_cache, []).
|
||||
rpc_call(Node, clean_acl_cache_all, [Node]).
|
||||
|
||||
set_ratelimit_policy(ClientId, Policy) ->
|
||||
call_client(ClientId, {ratelimit, Policy}).
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
]).
|
||||
-rest_api(#{name => clean_acl_cache_all,
|
||||
method => 'DELETE',
|
||||
path => "/acl-cache/",
|
||||
path => "/acl-cache",
|
||||
func => clean_all,
|
||||
descr => "Clean acl cache on all nodes"}).
|
||||
|
||||
|
@ -38,13 +38,13 @@
|
|||
]).
|
||||
|
||||
clean_all(_Bindings, _Params) ->
|
||||
case emqx_mgmt:clean_acl_cache() of
|
||||
case emqx_mgmt:clean_acl_cache_all() of
|
||||
ok -> return();
|
||||
{error, Reason} -> return({error, ?ERROR1, Reason})
|
||||
end.
|
||||
|
||||
clean_node(#{node := Node}, _Params) ->
|
||||
case emqx_mgmt:clean_acl_cache(Node) of
|
||||
case emqx_mgmt:clean_acl_cache_all(Node) of
|
||||
ok -> return();
|
||||
{error, Reason} -> return({error, ?ERROR1, Reason})
|
||||
end.
|
||||
|
|
|
@ -580,19 +580,30 @@ data(_) ->
|
|||
%%--------------------------------------------------------------------
|
||||
%% @doc acl Command
|
||||
|
||||
acl(["cache-clean", "node", SNode]) ->
|
||||
emqx_mgmt:clean_acl_cache_all(ekka_node:parse_name(SNode));
|
||||
acl(["cache-clean", "node", Node]) ->
|
||||
case emqx_mgmt:clean_acl_cache_all(erlang:list_to_atom(Node)) of
|
||||
ok ->
|
||||
emqx_ctl:print("The emqx acl cache removed on node ~s.~n", [Node]);
|
||||
{error, Reason} ->
|
||||
emqx_ctl:print("The emqx acl cache-clean on node ~s failed: ~s.~n", [Node, Reason])
|
||||
end;
|
||||
|
||||
acl(["cache-clean", "all"]) ->
|
||||
emqx_mgmt:clean_acl_cache();
|
||||
case emqx_mgmt:clean_acl_cache_all() of
|
||||
ok ->
|
||||
emqx_ctl:print("The emqx acl cache removed on all nodes.~n");
|
||||
{error, Reason} ->
|
||||
emqx_ctl:print("The emqx acl cache-clean failed: ~s.~n", [Reason])
|
||||
end;
|
||||
|
||||
acl(["cache-clean", ClientId]) ->
|
||||
emqx_mgmt:clean_acl_cache(ClientId);
|
||||
|
||||
acl(_) ->
|
||||
emqx_ctl:usage([{"cache-clean all", "Clears acl cache on all nodes"},
|
||||
{"cache-clean node <Node>", "Clears acl cache on given node"},
|
||||
{"cache-clean <ClientId>", "Clears acl cache for given client"}]).
|
||||
emqx_ctl:usage([{"cache-clean all", "Clears acl cache on all nodes"},
|
||||
{"cache-clean node <Node>", "Clears acl cache on given node"},
|
||||
{"cache-clean <ClientId>", "Clears acl cache for given client"}
|
||||
]).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Dump ETS
|
||||
|
|
Loading…
Reference in New Issue