feat(acl): cache drain cr fixes

This commit is contained in:
Karol Kaczmarek 2021-03-18 20:45:47 +01:00 committed by Zaiming (Stone) Shi
parent 87ce9d666f
commit 844a1ba0af
3 changed files with 16 additions and 19 deletions

View File

@ -252,10 +252,10 @@ 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)
Results = [{Node, clean_acl_cache_all(Node)} || Node <- ekka_mnesia:running_nodes()],
case lists:filter(fun({_Node, Item}) -> Item =/= ok end, Results) of
[] -> ok;
BadNodes -> {error, BadNodes}
end.
clean_acl_cache_all(Node) when Node =:= node() ->

View File

@ -18,9 +18,6 @@
-include("emqx_mgmt.hrl").
-import(minirest, [ return/0
, return/1
]).
-rest_api(#{name => clean_acl_cache_all,
method => 'DELETE',
path => "/acl-cache",
@ -39,12 +36,12 @@
clean_all(_Bindings, _Params) ->
case emqx_mgmt:clean_acl_cache_all() of
ok -> return();
{error, Reason} -> return({error, ?ERROR1, Reason})
ok -> minirest:return();
{error, Reason} -> minirest:return({error, ?ERROR1, Reason})
end.
clean_node(#{node := Node}, _Params) ->
case emqx_mgmt:clean_acl_cache_all(Node) of
ok -> return();
{error, Reason} -> return({error, ?ERROR1, Reason})
ok -> minirest:return();
{error, Reason} -> minirest:return({error, ?ERROR1, Reason})
end.

View File

@ -581,28 +581,28 @@ data(_) ->
%% @doc acl Command
acl(["cache-clean", "node", Node]) ->
case emqx_mgmt:clean_acl_cache_all(erlang:list_to_atom(Node)) of
case emqx_mgmt:clean_acl_cache_all(erlang:list_to_existing_atom(Node)) of
ok ->
emqx_ctl:print("The emqx acl cache removed on node ~s.~n", [Node]);
emqx_ctl:print("ACL cache drain started on node ~s.~n", [Node]);
{error, Reason} ->
emqx_ctl:print("The emqx acl cache-clean on node ~s failed: ~s.~n", [Node, Reason])
emqx_ctl:print("ACL drain failed on node ~s: ~0p.~n", [Node, Reason])
end;
acl(["cache-clean", "all"]) ->
case emqx_mgmt:clean_acl_cache_all() of
ok ->
emqx_ctl:print("The emqx acl cache removed on all nodes.~n");
emqx_ctl:print("Started ACL cache drain in all nodes~n");
{error, Reason} ->
emqx_ctl:print("The emqx acl cache-clean failed: ~s.~n", [Reason])
emqx_ctl:print("ACL cache-clean failed: ~p.~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([{"acl cache-clean all", "Clears acl cache on all nodes"},
{"acl cache-clean node <Node>", "Clears acl cache on given node"},
{"acl cache-clean <ClientId>", "Clears acl cache for given client"}
]).
%%--------------------------------------------------------------------