diff --git a/apps/emqx/src/emqx_config.erl b/apps/emqx/src/emqx_config.erl index 450f3e1b0..2f2c711ef 100644 --- a/apps/emqx/src/emqx_config.erl +++ b/apps/emqx/src/emqx_config.erl @@ -325,22 +325,32 @@ init_load(SchemaMod, Conf) when is_list(Conf) orelse is_binary(Conf) -> ok = save_schema_mod_and_names(SchemaMod), HasDeprecatedFile = has_deprecated_file(), RawConf0 = load_config_files(HasDeprecatedFile, Conf), - warning_deprecated_root_key(RawConf0), - RawConf1 = + RawConf1 = upgrade_raw_conf(SchemaMod, RawConf0), + warning_deprecated_root_key(RawConf1), + RawConf2 = case HasDeprecatedFile of true -> - overlay_v0(SchemaMod, RawConf0); + overlay_v0(SchemaMod, RawConf1); false -> - overlay_v1(SchemaMod, RawConf0) + overlay_v1(SchemaMod, RawConf1) end, - RawConf = fill_defaults_for_all_roots(SchemaMod, RawConf1), + RawConf3 = fill_defaults_for_all_roots(SchemaMod, RawConf2), %% check configs against the schema - {AppEnvs, CheckedConf} = check_config(SchemaMod, RawConf, #{}), + {AppEnvs, CheckedConf} = check_config(SchemaMod, RawConf3, #{}), save_to_app_env(AppEnvs), - ok = save_to_config_map(CheckedConf, RawConf), + ok = save_to_config_map(CheckedConf, RawConf3), maybe_init_default_zone(), ok. +upgrade_raw_conf(SchemaMod, RawConf) -> + case erlang:function_exported(SchemaMod, upgrade_raw_conf, 1) of + true -> + %% TODO make it a schema module behaviour in hocon_schema + apply(SchemaMod, upgrade_raw_conf, [RawConf]); + false -> + RawConf + end. + %% Merge environment variable overrides on top, then merge with overrides. overlay_v0(SchemaMod, RawConf) when is_map(RawConf) -> RawConfWithEnvs = merge_envs(SchemaMod, RawConf), diff --git a/apps/emqx/src/emqx_config_handler.erl b/apps/emqx/src/emqx_config_handler.erl index f38c5563a..bf11c17e8 100644 --- a/apps/emqx/src/emqx_config_handler.erl +++ b/apps/emqx/src/emqx_config_handler.erl @@ -19,7 +19,7 @@ -include("logger.hrl"). -include("emqx_schema.hrl"). --include_lib("hocon/include/hoconsc.hrl"). +-include_lib("hocon/include/hocon_types.hrl"). -behaviour(gen_server). @@ -736,7 +736,7 @@ remove_empty_leaf(KeyPath, Handlers) -> end. assert_callback_function(Mod) -> - _ = Mod:module_info(), + _ = apply(Mod, module_info, []), case erlang:function_exported(Mod, pre_config_update, 3) orelse erlang:function_exported(Mod, post_config_update, 5)