Просмотр исходного кода

Merge pull request #9939 from ieQu1/mria-replicant-manual-join

Mria replicant manual join
ieQu1 3 лет назад
Родитель
Сommit
388c33395e

+ 0 - 1
apps/emqx/src/emqx_kernel_sup.erl

@@ -35,7 +35,6 @@ init([]) ->
             child_spec(emqx_hooks, worker),
             child_spec(emqx_hooks, worker),
             child_spec(emqx_stats, worker),
             child_spec(emqx_stats, worker),
             child_spec(emqx_metrics, worker),
             child_spec(emqx_metrics, worker),
-            child_spec(emqx_ctl, worker),
             child_spec(emqx_authn_authz_metrics_sup, supervisor)
             child_spec(emqx_authn_authz_metrics_sup, supervisor)
         ]
         ]
     }}.
     }}.

+ 2 - 2
apps/emqx_conf/src/emqx_conf.app.src

@@ -1,9 +1,9 @@
 {application, emqx_conf, [
 {application, emqx_conf, [
     {description, "EMQX configuration management"},
     {description, "EMQX configuration management"},
-    {vsn, "0.1.12"},
+    {vsn, "0.1.13"},
     {registered, []},
     {registered, []},
     {mod, {emqx_conf_app, []}},
     {mod, {emqx_conf_app, []}},
-    {applications, [kernel, stdlib]},
+    {applications, [kernel, stdlib, emqx_ctl]},
     {env, []},
     {env, []},
     {modules, []}
     {modules, []}
 ]}.
 ]}.

+ 4 - 0
apps/emqx_ctl/README.md

@@ -0,0 +1,4 @@
+emqx_ctl
+=====
+
+Backend module for `emqx_ctl` command.

+ 2 - 0
apps/emqx_ctl/rebar.config

@@ -0,0 +1,2 @@
+{erl_opts, [debug_info]}.
+{deps, []}.

+ 15 - 0
apps/emqx_ctl/src/emqx_ctl.app.src

@@ -0,0 +1,15 @@
+{application, emqx_ctl, [
+    {description, "Backend for emqx_ctl script"},
+    {vsn, "0.1.0"},
+    {registered, []},
+    {mod, {emqx_ctl_app, []}},
+    {applications, [
+        kernel,
+        stdlib
+    ]},
+    {env, []},
+    {modules, []},
+
+    {licenses, ["Apache-2.0"]},
+    {links, []}
+]}.

+ 17 - 10
apps/emqx/src/emqx_ctl.erl

@@ -18,8 +18,7 @@
 
 
 -behaviour(gen_server).
 -behaviour(gen_server).
 
 
--include("types.hrl").
--include("logger.hrl").
+-include_lib("kernel/include/logger.hrl").
 
 
 -export([start_link/0, stop/0]).
 -export([start_link/0, stop/0]).
 
 
@@ -70,7 +69,7 @@
 -define(SERVER, ?MODULE).
 -define(SERVER, ?MODULE).
 -define(CMD_TAB, emqx_command).
 -define(CMD_TAB, emqx_command).
 
 
--spec start_link() -> startlink_ret().
+-spec start_link() -> {ok, pid()}.
 start_link() ->
 start_link() ->
     gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
     gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
 
 
@@ -103,7 +102,7 @@ cast(Msg) -> gen_server:cast(?SERVER, Msg).
 run_command([]) ->
 run_command([]) ->
     run_command(help, []);
     run_command(help, []);
 run_command([Cmd | Args]) ->
 run_command([Cmd | Args]) ->
-    case emqx_misc:safe_to_existing_atom(Cmd) of
+    case safe_to_existing_atom(Cmd) of
         {ok, Cmd1} ->
         {ok, Cmd1} ->
             run_command(Cmd1, Args);
             run_command(Cmd1, Args);
         _ ->
         _ ->
@@ -122,7 +121,7 @@ run_command(Cmd, Args) when is_atom(Cmd) ->
                 ok
                 ok
             catch
             catch
                 _:Reason:Stacktrace ->
                 _:Reason:Stacktrace ->
-                    ?SLOG(error, #{
+                    ?LOG_ERROR(#{
                         msg => "ctl_command_crashed",
                         msg => "ctl_command_crashed",
                         stacktrace => Stacktrace,
                         stacktrace => Stacktrace,
                         reason => Reason
                         reason => Reason
@@ -220,7 +219,7 @@ format_usage(CmdParams, Desc, Width) ->
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
 
 
 init([]) ->
 init([]) ->
-    ok = emqx_tables:new(?CMD_TAB, [protected, ordered_set]),
+    _ = ets:new(?CMD_TAB, [named_table, protected, ordered_set]),
     {ok, #state{seq = 0}}.
     {ok, #state{seq = 0}}.
 
 
 handle_call({register_command, Cmd, MF, Opts}, _From, State = #state{seq = Seq}) ->
 handle_call({register_command, Cmd, MF, Opts}, _From, State = #state{seq = Seq}) ->
@@ -229,23 +228,23 @@ handle_call({register_command, Cmd, MF, Opts}, _From, State = #state{seq = Seq})
             ets:insert(?CMD_TAB, {{Seq, Cmd}, MF, Opts}),
             ets:insert(?CMD_TAB, {{Seq, Cmd}, MF, Opts}),
             {reply, ok, next_seq(State)};
             {reply, ok, next_seq(State)};
         [[OriginSeq] | _] ->
         [[OriginSeq] | _] ->
-            ?SLOG(warning, #{msg => "CMD_overidden", cmd => Cmd, mf => MF}),
+            ?LOG_WARNING(#{msg => "CMD_overidden", cmd => Cmd, mf => MF}),
             true = ets:insert(?CMD_TAB, {{OriginSeq, Cmd}, MF, Opts}),
             true = ets:insert(?CMD_TAB, {{OriginSeq, Cmd}, MF, Opts}),
             {reply, ok, State}
             {reply, ok, State}
     end;
     end;
 handle_call(Req, _From, State) ->
 handle_call(Req, _From, State) ->
-    ?SLOG(error, #{msg => "unexpected_call", call => Req}),
+    ?LOG_ERROR(#{msg => "unexpected_call", call => Req}),
     {reply, ignored, State}.
     {reply, ignored, State}.
 
 
 handle_cast({unregister_command, Cmd}, State) ->
 handle_cast({unregister_command, Cmd}, State) ->
     ets:match_delete(?CMD_TAB, {{'_', Cmd}, '_', '_'}),
     ets:match_delete(?CMD_TAB, {{'_', Cmd}, '_', '_'}),
     noreply(State);
     noreply(State);
 handle_cast(Msg, State) ->
 handle_cast(Msg, State) ->
-    ?SLOG(error, #{msg => "unexpected_cast", cast => Msg}),
+    ?LOG_ERROR(#{msg => "unexpected_cast", cast => Msg}),
     noreply(State).
     noreply(State).
 
 
 handle_info(Info, State) ->
 handle_info(Info, State) ->
-    ?SLOG(error, #{msg => "unexpected_info", info => Info}),
+    ?LOG_ERROR(#{msg => "unexpected_info", info => Info}),
     noreply(State).
     noreply(State).
 
 
 terminate(_Reason, _State) ->
 terminate(_Reason, _State) ->
@@ -272,3 +271,11 @@ zip_cmd([X | Xs], [Y | Ys]) -> [{X, Y} | zip_cmd(Xs, Ys)];
 zip_cmd([X | Xs], []) -> [{X, ""} | zip_cmd(Xs, [])];
 zip_cmd([X | Xs], []) -> [{X, ""} | zip_cmd(Xs, [])];
 zip_cmd([], [Y | Ys]) -> [{"", Y} | zip_cmd([], Ys)];
 zip_cmd([], [Y | Ys]) -> [{"", Y} | zip_cmd([], Ys)];
 zip_cmd([], []) -> [].
 zip_cmd([], []) -> [].
+
+safe_to_existing_atom(Str) ->
+    try
+        {ok, list_to_existing_atom(Str)}
+    catch
+        _:badarg ->
+            undefined
+    end.

+ 18 - 0
apps/emqx_ctl/src/emqx_ctl_app.erl

@@ -0,0 +1,18 @@
+%%%-------------------------------------------------------------------
+%% @doc emqx_ctl public API
+%% @end
+%%%-------------------------------------------------------------------
+
+-module(emqx_ctl_app).
+
+-behaviour(application).
+
+-export([start/2, stop/1]).
+
+start(_StartType, _StartArgs) ->
+    emqx_ctl_sup:start_link().
+
+stop(_State) ->
+    ok.
+
+%% internal functions

+ 33 - 0
apps/emqx_ctl/src/emqx_ctl_sup.erl

@@ -0,0 +1,33 @@
+%%%-------------------------------------------------------------------
+%% @doc emqx_ctl top level supervisor.
+%% @end
+%%%-------------------------------------------------------------------
+
+-module(emqx_ctl_sup).
+
+-behaviour(supervisor).
+
+-export([start_link/0]).
+
+-export([init/1]).
+
+-define(SERVER, ?MODULE).
+
+start_link() ->
+    supervisor:start_link({local, ?SERVER}, ?MODULE, []).
+
+init([]) ->
+    SupFlags = #{
+        strategy => one_for_all,
+        intensity => 0,
+        period => 1
+    },
+    ChildSpecs = [
+        #{
+            id => emqx_ctl,
+            start => {emqx_ctl, start_link, []},
+            type => worker,
+            restart => permanent
+        }
+    ],
+    {ok, {SupFlags, ChildSpecs}}.

+ 2 - 4
apps/emqx/test/emqx_ctl_SUITE.erl

@@ -22,12 +22,10 @@
 -include_lib("eunit/include/eunit.hrl").
 -include_lib("eunit/include/eunit.hrl").
 -include_lib("common_test/include/ct.hrl").
 -include_lib("common_test/include/ct.hrl").
 
 
-all() -> emqx_common_test_helpers:all(?MODULE).
+all() -> [t_reg_unreg_command, t_run_commands, t_print, t_usage, t_unexpected].
 
 
 init_per_suite(Config) ->
 init_per_suite(Config) ->
-    %% ensure stopped, this suite tests emqx_ctl process independently
-    application:stop(emqx),
-    ok = emqx_logger:set_log_level(emergency),
+    application:stop(emqx_ctl),
     Config.
     Config.
 
 
 end_per_suite(_Config) ->
 end_per_suite(_Config) ->

+ 2 - 2
apps/emqx_dashboard/src/emqx_dashboard.app.src

@@ -2,10 +2,10 @@
 {application, emqx_dashboard, [
 {application, emqx_dashboard, [
     {description, "EMQX Web Dashboard"},
     {description, "EMQX Web Dashboard"},
     % strict semver, bump manually!
     % strict semver, bump manually!
-    {vsn, "5.0.13"},
+    {vsn, "5.0.14"},
     {modules, []},
     {modules, []},
     {registered, [emqx_dashboard_sup]},
     {registered, [emqx_dashboard_sup]},
-    {applications, [kernel, stdlib, mnesia, minirest, emqx]},
+    {applications, [kernel, stdlib, mnesia, minirest, emqx, emqx_ctl]},
     {mod, {emqx_dashboard_app, []}},
     {mod, {emqx_dashboard_app, []}},
     {env, []},
     {env, []},
     {licenses, ["Apache-2.0"]},
     {licenses, ["Apache-2.0"]},

+ 2 - 2
apps/emqx_gateway/src/emqx_gateway.app.src

@@ -1,10 +1,10 @@
 %% -*- mode: erlang -*-
 %% -*- mode: erlang -*-
 {application, emqx_gateway, [
 {application, emqx_gateway, [
     {description, "The Gateway management application"},
     {description, "The Gateway management application"},
-    {vsn, "0.1.11"},
+    {vsn, "0.1.12"},
     {registered, []},
     {registered, []},
     {mod, {emqx_gateway_app, []}},
     {mod, {emqx_gateway_app, []}},
-    {applications, [kernel, stdlib, grpc, emqx, emqx_authn]},
+    {applications, [kernel, stdlib, grpc, emqx, emqx_authn, emqx_ctl]},
     {env, []},
     {env, []},
     {modules, []},
     {modules, []},
     {licenses, ["Apache 2.0"]},
     {licenses, ["Apache 2.0"]},

+ 2 - 2
apps/emqx_machine/src/emqx_machine.app.src

@@ -3,10 +3,10 @@
     {id, "emqx_machine"},
     {id, "emqx_machine"},
     {description, "The EMQX Machine"},
     {description, "The EMQX Machine"},
     % strict semver, bump manually!
     % strict semver, bump manually!
-    {vsn, "0.1.3"},
+    {vsn, "0.1.4"},
     {modules, []},
     {modules, []},
     {registered, []},
     {registered, []},
-    {applications, [kernel, stdlib]},
+    {applications, [kernel, stdlib, emqx_ctl]},
     {mod, {emqx_machine_app, []}},
     {mod, {emqx_machine_app, []}},
     {env, []},
     {env, []},
     {licenses, ["Apache-2.0"]},
     {licenses, ["Apache-2.0"]},

+ 1 - 0
apps/emqx_machine/src/emqx_machine.erl

@@ -29,6 +29,7 @@
 
 
 %% @doc EMQX boot entrypoint.
 %% @doc EMQX boot entrypoint.
 start() ->
 start() ->
+    emqx_mgmt_cli:load(),
     case os:type() of
     case os:type() of
         {win32, nt} ->
         {win32, nt} ->
             ok;
             ok;

+ 1 - 1
apps/emqx_management/src/emqx_management.app.src

@@ -5,7 +5,7 @@
     {vsn, "5.0.15"},
     {vsn, "5.0.15"},
     {modules, []},
     {modules, []},
     {registered, [emqx_management_sup]},
     {registered, [emqx_management_sup]},
-    {applications, [kernel, stdlib, emqx_plugins, minirest, emqx]},
+    {applications, [kernel, stdlib, emqx_plugins, minirest, emqx, emqx_ctl]},
     {mod, {emqx_mgmt_app, []}},
     {mod, {emqx_mgmt_app, []}},
     {env, []},
     {env, []},
     {licenses, ["Apache-2.0"]},
     {licenses, ["Apache-2.0"]},

+ 1 - 3
apps/emqx_management/src/emqx_mgmt_app.erl

@@ -31,9 +31,7 @@ start(_Type, _Args) ->
     ok = mria_rlog:wait_for_shards([?MANAGEMENT_SHARD], infinity),
     ok = mria_rlog:wait_for_shards([?MANAGEMENT_SHARD], infinity),
     case emqx_mgmt_auth:init_bootstrap_file() of
     case emqx_mgmt_auth:init_bootstrap_file() of
         ok ->
         ok ->
-            {ok, Sup} = emqx_mgmt_sup:start_link(),
-            ok = emqx_mgmt_cli:load(),
-            {ok, Sup};
+            emqx_mgmt_sup:start_link();
         {error, Reason} ->
         {error, Reason} ->
             {error, Reason}
             {error, Reason}
     end.
     end.

+ 2 - 2
apps/emqx_modules/src/emqx_modules.app.src

@@ -1,9 +1,9 @@
 %% -*- mode: erlang -*-
 %% -*- mode: erlang -*-
 {application, emqx_modules, [
 {application, emqx_modules, [
     {description, "EMQX Modules"},
     {description, "EMQX Modules"},
-    {vsn, "5.0.9"},
+    {vsn, "5.0.10"},
     {modules, []},
     {modules, []},
-    {applications, [kernel, stdlib, emqx]},
+    {applications, [kernel, stdlib, emqx, emqx_ctl]},
     {mod, {emqx_modules_app, []}},
     {mod, {emqx_modules_app, []}},
     {registered, [emqx_modules_sup]},
     {registered, [emqx_modules_sup]},
     {env, []}
     {env, []}

+ 2 - 2
apps/emqx_retainer/src/emqx_retainer.app.src

@@ -2,10 +2,10 @@
 {application, emqx_retainer, [
 {application, emqx_retainer, [
     {description, "EMQX Retainer"},
     {description, "EMQX Retainer"},
     % strict semver, bump manually!
     % strict semver, bump manually!
-    {vsn, "5.0.9"},
+    {vsn, "5.0.10"},
     {modules, []},
     {modules, []},
     {registered, [emqx_retainer_sup]},
     {registered, [emqx_retainer_sup]},
-    {applications, [kernel, stdlib, emqx]},
+    {applications, [kernel, stdlib, emqx, emqx_ctl]},
     {mod, {emqx_retainer_app, []}},
     {mod, {emqx_retainer_app, []}},
     {env, []},
     {env, []},
     {licenses, ["Apache-2.0"]},
     {licenses, ["Apache-2.0"]},

+ 2 - 2
apps/emqx_rule_engine/src/emqx_rule_engine.app.src

@@ -2,10 +2,10 @@
 {application, emqx_rule_engine, [
 {application, emqx_rule_engine, [
     {description, "EMQX Rule Engine"},
     {description, "EMQX Rule Engine"},
     % strict semver, bump manually!
     % strict semver, bump manually!
-    {vsn, "5.0.8"},
+    {vsn, "5.0.9"},
     {modules, []},
     {modules, []},
     {registered, [emqx_rule_engine_sup, emqx_rule_engine]},
     {registered, [emqx_rule_engine_sup, emqx_rule_engine]},
-    {applications, [kernel, stdlib, rulesql, getopt]},
+    {applications, [kernel, stdlib, rulesql, getopt, emqx_ctl]},
     {mod, {emqx_rule_engine_app, []}},
     {mod, {emqx_rule_engine_app, []}},
     {env, []},
     {env, []},
     {licenses, ["Apache-2.0"]},
     {licenses, ["Apache-2.0"]},

+ 2 - 2
lib-ee/emqx_license/src/emqx_license.app.src

@@ -1,8 +1,8 @@
 {application, emqx_license, [
 {application, emqx_license, [
     {description, "EMQX License"},
     {description, "EMQX License"},
-    {vsn, "5.0.5"},
+    {vsn, "5.0.6"},
     {modules, []},
     {modules, []},
     {registered, [emqx_license_sup]},
     {registered, [emqx_license_sup]},
-    {applications, [kernel, stdlib]},
+    {applications, [kernel, stdlib, emqx_ctl]},
     {mod, {emqx_license_app, []}}
     {mod, {emqx_license_app, []}}
 ]}.
 ]}.