Merge pull request #10410 from HJianBo/fix-load-gw-from-confs

fix(gw): load emqx applications before hocon configs checking
This commit is contained in:
JianBo He 2023-04-17 18:01:31 +08:00 committed by GitHub
commit 19eda3bc5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 7 deletions

View File

@ -45,7 +45,7 @@ load_default_gateway_applications() ->
fun(Def) -> fun(Def) ->
load_gateway_application(Def) load_gateway_application(Def)
end, end,
emqx_gateway_utils:find_gateway_definations() emqx_gateway_utils:find_gateway_definitions()
). ).
load_gateway_application( load_gateway_application(

View File

@ -75,7 +75,7 @@ fields(gateway) ->
} }
)} )}
end, end,
emqx_gateway_utils:find_gateway_definations() emqx_gateway_utils:find_gateway_definitions()
); );
fields(clientinfo_override) -> fields(clientinfo_override) ->
[ [

View File

@ -47,7 +47,7 @@
listener_chain/3, listener_chain/3,
make_deprecated_paths/1, make_deprecated_paths/1,
make_compatible_schema/2, make_compatible_schema/2,
find_gateway_definations/0 find_gateway_definitions/0
]). ]).
-export([stringfy/1]). -export([stringfy/1]).
@ -564,8 +564,8 @@ make_compatible_schema2(Path, SchemaFun) ->
Schema Schema
). ).
-spec find_gateway_definations() -> list(gateway_def()). -spec find_gateway_definitions() -> list(gateway_def()).
find_gateway_definations() -> find_gateway_definitions() ->
lists:flatten( lists:flatten(
lists:map( lists:map(
fun(App) -> fun(App) ->

View File

@ -272,7 +272,7 @@ chkconfig(File) ->
end. end.
check_license(Config) -> check_license(Config) ->
ok = application:load(emqx_license), ok = ensure_application_load(emqx_license),
%% This checks formal license validity to ensure %% This checks formal license validity to ensure
%% that the node can successfully start with the given license. %% that the node can successfully start with the given license.
@ -362,6 +362,27 @@ add_libs_dir() ->
add_lib_dir(RootDir, Name, Vsn) -> add_lib_dir(RootDir, Name, Vsn) ->
LibDir = filename:join([RootDir, lib, atom_to_list(Name) ++ "-" ++ Vsn, ebin]), LibDir = filename:join([RootDir, lib, atom_to_list(Name) ++ "-" ++ Vsn, ebin]),
case code:add_patha(LibDir) of case code:add_patha(LibDir) of
true -> ok; true ->
%% load all applications into application controller, before performing
%% the configuration check of HOCON
%%
%% It helps to implement the feature of dynamically searching schema.
%% See `emqx_gateway_schema:fields(gateway)`
is_emqx_application(Name) andalso ensure_application_load(Name),
ok;
{error, _} -> error(LibDir) {error, _} -> error(LibDir)
end. end.
is_emqx_application(Name) when is_atom(Name) ->
is_emqx_application(atom_to_list(Name));
is_emqx_application("emqx_" ++ _Rest) ->
true;
is_emqx_application(_) ->
false.
ensure_application_load(Name) ->
case application:load(Name) of
ok -> ok;
{error, {already_loaded, _}} -> ok;
{error, Reason} -> error({failed_to_load_application, Name, Reason})
end.

View File

@ -0,0 +1,2 @@
Fix config check failed when gateways are configured in emqx.conf.
This issue was first introduced in v5.0.22 via [#10278](https://github.com/emqx/emqx/pull/10278), the boot-time config check was missing.