refactor: delete module emqx_license_installer

after the previous refactoring, emqx_license app is now restarted
after join/rejoin the cluster, so there is no longer a need for the
installer process which monitors the 'emqx' name registration changes
and then issue license reloading and hook re-adding etc.
This commit is contained in:
Zaiming (Stone) Shi 2023-05-24 10:55:16 +02:00
parent 492a591298
commit 798fa8c2c2
3 changed files with 0 additions and 184 deletions

View File

@ -1,86 +0,0 @@
%%--------------------------------------------------------------------
%% Copyright (c) 2022-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
%%--------------------------------------------------------------------
-module(emqx_license_installer).
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
-behaviour(gen_server).
-export([
start_link/1,
start_link/4
]).
%% gen_server callbacks
-export([
init/1,
handle_call/3,
handle_cast/2,
handle_info/2
]).
-define(NAME, emqx).
-define(INTERVAL, 5000).
%%------------------------------------------------------------------------------
%% API
%%------------------------------------------------------------------------------
start_link(Callback) ->
start_link(?NAME, ?MODULE, ?INTERVAL, Callback).
start_link(Name, ServerName, Interval, Callback) ->
gen_server:start_link({local, ServerName}, ?MODULE, [Name, Interval, Callback], []).
%%------------------------------------------------------------------------------
%% gen_server callbacks
%%------------------------------------------------------------------------------
init([Name, Interval, Callback]) ->
Pid = whereis(Name),
State = #{
interval => Interval,
name => Name,
pid => Pid,
callback => Callback
},
{ok, ensure_timer(State)}.
handle_call(_Req, _From, State) ->
{reply, unknown, State}.
handle_cast(_Msg, State) ->
{noreply, State}.
handle_info({timeout, Timer, check_pid}, #{timer := Timer} = State) ->
NewState = check_pid(State),
{noreply, ensure_timer(NewState)};
handle_info(_Msg, State) ->
{noreply, State}.
%%------------------------------------------------------------------------------
%% Private functions
%%------------------------------------------------------------------------------
ensure_timer(#{interval := Interval} = State) ->
_ =
case State of
#{timer := Timer} -> erlang:cancel_timer(Timer);
_ -> ok
end,
State#{timer => erlang:start_timer(Interval, self(), check_pid)}.
check_pid(#{name := Name, pid := OldPid, callback := Callback} = State) ->
case whereis(Name) of
undefined ->
?tp(emqx_license_installer_noproc, #{old_pid => OldPid}),
State;
OldPid ->
?tp(emqx_license_installer_nochange, #{old_pid => OldPid}),
State;
NewPid ->
_ = Callback(),
?tp(info, license_reloaded_after_emqx_app_restart, #{old_pid => OldPid}),
State#{pid => NewPid}
end.

View File

@ -41,15 +41,6 @@ init([]) ->
shutdown => 5000,
type => worker,
modules => [emqx_license_resources]
},
#{
id => license_installer,
start => {emqx_license_installer, start_link, [fun emqx_license:load/0]},
restart => permanent,
shutdown => 5000,
type => worker,
modules => [emqx_license_installer]
}
]
}}.

View File

@ -1,89 +0,0 @@
%%--------------------------------------------------------------------
%% Copyright (c) 2022-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
%%--------------------------------------------------------------------
-module(emqx_license_installer_SUITE).
-compile(nowarn_export_all).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl").
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
all() ->
emqx_common_test_helpers:all(?MODULE).
init_per_suite(Config) ->
_ = application:load(emqx_conf),
emqx_common_test_helpers:start_apps([emqx_license], fun set_special_configs/1),
Config.
end_per_suite(_) ->
emqx_common_test_helpers:stop_apps([emqx_license]),
ok.
init_per_testcase(_Case, Config) ->
{ok, _} = emqx_cluster_rpc:start_link(node(), emqx_cluster_rpc, 1000),
Config.
end_per_testcase(_Case, _Config) ->
ok.
set_special_configs(emqx_license) ->
Config = #{key => emqx_license_test_lib:default_license()},
emqx_config:put([license], Config);
set_special_configs(_) ->
ok.
%%------------------------------------------------------------------------------
%% Tests
%%------------------------------------------------------------------------------
t_update(_Config) ->
?check_trace(
begin
?wait_async_action(
begin
Pid0 = spawn_link(fun() ->
receive
exit -> ok
end
end),
register(installer_test, Pid0),
{ok, _} = emqx_license_installer:start_link(
installer_test,
?MODULE,
10,
fun() -> ok end
),
{ok, _} = ?block_until(
#{?snk_kind := emqx_license_installer_nochange},
100
),
Pid0 ! exit,
{ok, _} = ?block_until(
#{?snk_kind := emqx_license_installer_noproc},
100
),
Pid1 = spawn_link(fun() -> timer:sleep(100) end),
register(installer_test, Pid1)
end,
#{?snk_kind := license_reloaded_after_emqx_app_restart},
1000
)
end,
fun(Trace) ->
?assertMatch([_ | _], ?of_kind(license_reloaded_after_emqx_app_restart, Trace))
end
).
t_unknown_calls(_Config) ->
ok = gen_server:cast(emqx_license_installer, some_cast),
some_msg = erlang:send(emqx_license_installer, some_msg),
?assertEqual(unknown, gen_server:call(emqx_license_installer, some_request)).