refactor(mgmt_cli): Call mria directly

This commit is contained in:
ieQu1 2023-07-18 17:30:19 +02:00
parent f0ab8e36d1
commit 293700773f
1 changed files with 10 additions and 5 deletions

View File

@ -110,7 +110,7 @@ broker(_) ->
%% @doc Cluster with other nodes %% @doc Cluster with other nodes
cluster(["join", SNode]) -> cluster(["join", SNode]) ->
case ekka:join(ekka_node:parse_name(SNode)) of case mria:join(ekka_node:parse_name(SNode)) of
ok -> ok ->
emqx_ctl:print("Join the cluster successfully.~n"), emqx_ctl:print("Join the cluster successfully.~n"),
cluster(["status"]); cluster(["status"]);
@ -120,7 +120,7 @@ cluster(["join", SNode]) ->
emqx_ctl:print("Failed to join the cluster: ~0p~n", [Error]) emqx_ctl:print("Failed to join the cluster: ~0p~n", [Error])
end; end;
cluster(["leave"]) -> cluster(["leave"]) ->
case ekka:leave() of case mria:leave() of
ok -> ok ->
emqx_ctl:print("Leave the cluster successfully.~n"), emqx_ctl:print("Leave the cluster successfully.~n"),
cluster(["status"]); cluster(["status"]);
@ -128,7 +128,7 @@ cluster(["leave"]) ->
emqx_ctl:print("Failed to leave the cluster: ~0p~n", [Error]) emqx_ctl:print("Failed to leave the cluster: ~0p~n", [Error])
end; end;
cluster(["force-leave", SNode]) -> cluster(["force-leave", SNode]) ->
case ekka:force_leave(ekka_node:parse_name(SNode)) of case mria:force_leave(ekka_node:parse_name(SNode)) of
ok -> ok ->
emqx_ctl:print("Remove the node from cluster successfully.~n"), emqx_ctl:print("Remove the node from cluster successfully.~n"),
cluster(["status"]); cluster(["status"]);
@ -138,9 +138,9 @@ cluster(["force-leave", SNode]) ->
emqx_ctl:print("Failed to remove the node from cluster: ~0p~n", [Error]) emqx_ctl:print("Failed to remove the node from cluster: ~0p~n", [Error])
end; end;
cluster(["status"]) -> cluster(["status"]) ->
emqx_ctl:print("Cluster status: ~p~n", [ekka_cluster:info()]); emqx_ctl:print("Cluster status: ~p~n", [cluster_info()]);
cluster(["status", "--json"]) -> cluster(["status", "--json"]) ->
Info = sort_map_list_fields(ekka_cluster:info()), Info = sort_map_list_fields(cluster_info()),
emqx_ctl:print("~ts~n", [emqx_logger_jsonfmt:best_effort_json(Info)]); emqx_ctl:print("~ts~n", [emqx_logger_jsonfmt:best_effort_json(Info)]);
cluster(_) -> cluster(_) ->
emqx_ctl:usage([ emqx_ctl:usage([
@ -925,3 +925,8 @@ with_log(Fun, Msg) ->
{error, Reason} -> {error, Reason} ->
emqx_ctl:print("~s FAILED~n~p~n", [Msg, Reason]) emqx_ctl:print("~s FAILED~n~p~n", [Msg, Reason])
end. end.
cluster_info() ->
#{ running_nodes => mria:running_nodes()
, stopped_nodes => mria:cluster_nodes(stopped)
}.