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