瀏覽代碼

feat(acl): cache drain cr fixes

Karol Kaczmarek 4 年之前
父節點
當前提交
844a1ba0af

+ 4 - 4
apps/emqx_management/src/emqx_mgmt.erl

@@ -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()],
-    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.
     end.
 
 
 clean_acl_cache_all(Node) when Node =:= node() ->
 clean_acl_cache_all(Node) when Node =:= node() ->

+ 4 - 7
apps/emqx_management/src/emqx_mgmt_api_acl.erl

@@ -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();
-      {error, Reason} -> return({error, ?ERROR1, Reason})
+      ok -> minirest:return();
+      {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();
-      {error, Reason} -> return({error, ?ERROR1, Reason})
+      ok -> minirest:return();
+      {error, Reason} -> minirest:return({error, ?ERROR1, Reason})
     end.
     end.

+ 8 - 8
apps/emqx_management/src/emqx_mgmt_cli.erl

@@ -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"},
-                    {"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"}
                    ]).
                    ]).
 
 
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------