fix: schema mod error
This commit is contained in:
parent
7942de53a0
commit
7beaa91814
|
@ -41,7 +41,7 @@ description() ->
|
||||||
|
|
||||||
%% @doc Return EMQX edition info.
|
%% @doc Return EMQX edition info.
|
||||||
%% Read info from persistent_term at runtime.
|
%% Read info from persistent_term at runtime.
|
||||||
%% Or meck this function to run tests for another eidtion.
|
%% Or meck this function to run tests for another edition.
|
||||||
-spec edition() -> ce | ee | edge.
|
-spec edition() -> ce | ee | edge.
|
||||||
-ifdef(EMQX_RELEASE_EDITION).
|
-ifdef(EMQX_RELEASE_EDITION).
|
||||||
edition() -> ?EMQX_RELEASE_EDITION.
|
edition() -> ?EMQX_RELEASE_EDITION.
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
-export([remove/2, remove/3]).
|
-export([remove/2, remove/3]).
|
||||||
-export([reset/2, reset/3]).
|
-export([reset/2, reset/3]).
|
||||||
-export([dump_schema/1, dump_schema/2]).
|
-export([dump_schema/1, dump_schema/2]).
|
||||||
|
-export([schema_module/0]).
|
||||||
|
|
||||||
%% for rpc
|
%% for rpc
|
||||||
-export([get_node_and_config/1]).
|
-export([get_node_and_config/1]).
|
||||||
|
@ -145,6 +146,14 @@ dump_schema(Dir, SchemaModule) ->
|
||||||
ok = gen_hot_conf_schema(HotConfigSchemaFile),
|
ok = gen_hot_conf_schema(HotConfigSchemaFile),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
%% @doc return the root schema module.
|
||||||
|
-spec schema_module() -> module().
|
||||||
|
schema_module() ->
|
||||||
|
case os:getenv("SCHEMA_MOD") of
|
||||||
|
false -> emqx_conf_schema;
|
||||||
|
Value -> list_to_existing_atom(Value)
|
||||||
|
end.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
|
@ -35,15 +35,9 @@ stop(_State) ->
|
||||||
init_conf() ->
|
init_conf() ->
|
||||||
{ok, TnxId} = copy_override_conf_from_core_node(),
|
{ok, TnxId} = copy_override_conf_from_core_node(),
|
||||||
emqx_app:set_init_tnx_id(TnxId),
|
emqx_app:set_init_tnx_id(TnxId),
|
||||||
emqx_config:init_load(schema_module()),
|
emqx_config:init_load(emqx_conf:schema_module()),
|
||||||
emqx_app:set_init_config_load_done().
|
emqx_app:set_init_config_load_done().
|
||||||
|
|
||||||
schema_module() ->
|
|
||||||
case os:getenv("SCHEMA_MOD") of
|
|
||||||
false -> emqx_conf_schema;
|
|
||||||
Value -> list_to_existing_atom(Value)
|
|
||||||
end.
|
|
||||||
|
|
||||||
copy_override_conf_from_core_node() ->
|
copy_override_conf_from_core_node() ->
|
||||||
case nodes() of
|
case nodes() of
|
||||||
[] -> %% The first core nodes is self.
|
[] -> %% The first core nodes is self.
|
||||||
|
|
|
@ -136,10 +136,12 @@ find_schema(Path) ->
|
||||||
Configs = config_list(),
|
Configs = config_list(),
|
||||||
lists:keyfind(list_to_binary(Root), 1, Configs).
|
lists:keyfind(list_to_binary(Root), 1, Configs).
|
||||||
|
|
||||||
%% we load all configs from emqx_conf_schema, some of them are defined as local ref
|
%% we load all configs from emqx_*_schema, some of them are defined as local ref
|
||||||
%% we need redirect to emqx_conf_schema.
|
%% we need redirect to emqx_*_schema.
|
||||||
%% such as hoconsc:ref("node") to hoconsc:ref(emqx_conf_schema, "node")
|
%% such as hoconsc:ref("node") to hoconsc:ref(emqx_*_schema, "node")
|
||||||
fields(Field) -> emqx_conf_schema:fields(Field).
|
fields(Field) ->
|
||||||
|
Mod = emqx_conf:schema_module(),
|
||||||
|
apply(Mod, fields, [Field]).
|
||||||
|
|
||||||
%%%==============================================================================================
|
%%%==============================================================================================
|
||||||
%% HTTP API Callbacks
|
%% HTTP API Callbacks
|
||||||
|
@ -201,7 +203,8 @@ conf_path_from_querystr(Req) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
config_list() ->
|
config_list() ->
|
||||||
Roots = hocon_schema:roots(emqx_conf_schema),
|
Mod = emqx_conf:schema_module(),
|
||||||
|
Roots = hocon_schema:roots(Mod),
|
||||||
lists:foldl(fun(Key, Acc) -> lists:keydelete(Key, 1, Acc) end, Roots, ?EXCLUDES).
|
lists:foldl(fun(Key, Acc) -> lists:keydelete(Key, 1, Acc) end, Roots, ?EXCLUDES).
|
||||||
|
|
||||||
conf_path(Req) ->
|
conf_path(Req) ->
|
||||||
|
|
|
@ -35,7 +35,7 @@ t_get(_Config) ->
|
||||||
maps:map(fun(Name, Value) ->
|
maps:map(fun(Name, Value) ->
|
||||||
{ok, Config} = get_config(Name),
|
{ok, Config} = get_config(Name),
|
||||||
?assertEqual(Value, Config)
|
?assertEqual(Value, Config)
|
||||||
end, Configs),
|
end, maps:remove(<<"license">>, Configs)),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
t_update(_Config) ->
|
t_update(_Config) ->
|
||||||
|
|
Loading…
Reference in New Issue