feat(acl): cache drain cr fixes
This commit is contained in:
parent
87ce9d666f
commit
844a1ba0af
|
@ -252,10 +252,10 @@ clean_acl_cache(Node, ClientId) ->
|
||||||
rpc_call(Node, clean_acl_cache, [Node, ClientId]).
|
rpc_call(Node, clean_acl_cache, [Node, ClientId]).
|
||||||
|
|
||||||
clean_acl_cache_all() ->
|
clean_acl_cache_all() ->
|
||||||
Results = [clean_acl_cache_all(Node) || Node <- ekka_mnesia:running_nodes()],
|
Results = [{Node, clean_acl_cache_all(Node)} || Node <- ekka_mnesia:running_nodes()],
|
||||||
case lists:any(fun(Item) -> Item =:= ok end, Results) of
|
case lists:filter(fun({_Node, Item}) -> Item =/= ok end, Results) of
|
||||||
true -> ok;
|
[] -> ok;
|
||||||
false -> lists:last(Results)
|
BadNodes -> {error, BadNodes}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
clean_acl_cache_all(Node) when Node =:= node() ->
|
clean_acl_cache_all(Node) when Node =:= node() ->
|
||||||
|
|
|
@ -18,9 +18,6 @@
|
||||||
|
|
||||||
-include("emqx_mgmt.hrl").
|
-include("emqx_mgmt.hrl").
|
||||||
|
|
||||||
-import(minirest, [ return/0
|
|
||||||
, return/1
|
|
||||||
]).
|
|
||||||
-rest_api(#{name => clean_acl_cache_all,
|
-rest_api(#{name => clean_acl_cache_all,
|
||||||
method => 'DELETE',
|
method => 'DELETE',
|
||||||
path => "/acl-cache",
|
path => "/acl-cache",
|
||||||
|
@ -39,12 +36,12 @@
|
||||||
|
|
||||||
clean_all(_Bindings, _Params) ->
|
clean_all(_Bindings, _Params) ->
|
||||||
case emqx_mgmt:clean_acl_cache_all() of
|
case emqx_mgmt:clean_acl_cache_all() of
|
||||||
ok -> return();
|
ok -> minirest:return();
|
||||||
{error, Reason} -> return({error, ?ERROR1, Reason})
|
{error, Reason} -> minirest:return({error, ?ERROR1, Reason})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
clean_node(#{node := Node}, _Params) ->
|
clean_node(#{node := Node}, _Params) ->
|
||||||
case emqx_mgmt:clean_acl_cache_all(Node) of
|
case emqx_mgmt:clean_acl_cache_all(Node) of
|
||||||
ok -> return();
|
ok -> minirest:return();
|
||||||
{error, Reason} -> return({error, ?ERROR1, Reason})
|
{error, Reason} -> minirest:return({error, ?ERROR1, Reason})
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -581,28 +581,28 @@ data(_) ->
|
||||||
%% @doc acl Command
|
%% @doc acl Command
|
||||||
|
|
||||||
acl(["cache-clean", "node", Node]) ->
|
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 ->
|
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} ->
|
{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;
|
end;
|
||||||
|
|
||||||
acl(["cache-clean", "all"]) ->
|
acl(["cache-clean", "all"]) ->
|
||||||
case emqx_mgmt:clean_acl_cache_all() of
|
case emqx_mgmt:clean_acl_cache_all() of
|
||||||
ok ->
|
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} ->
|
{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;
|
end;
|
||||||
|
|
||||||
acl(["cache-clean", ClientId]) ->
|
acl(["cache-clean", ClientId]) ->
|
||||||
emqx_mgmt:clean_acl_cache(ClientId);
|
emqx_mgmt:clean_acl_cache(ClientId);
|
||||||
|
|
||||||
acl(_) ->
|
acl(_) ->
|
||||||
emqx_ctl:usage([{"cache-clean all", "Clears acl cache on all nodes"},
|
emqx_ctl:usage([{"acl cache-clean all", "Clears acl cache on all nodes"},
|
||||||
{"cache-clean node <Node>", "Clears acl cache on given node"},
|
{"acl cache-clean node <Node>", "Clears acl cache on given node"},
|
||||||
{"cache-clean <ClientId>", "Clears acl cache for given client"}
|
{"acl cache-clean <ClientId>", "Clears acl cache for given client"}
|
||||||
]).
|
]).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue