Reference to foreign schema definitions in emqx_schema (#5090)
This commit is contained in:
parent
4157524910
commit
9977d836bc
|
@ -81,7 +81,7 @@ get_raw_config() ->
|
||||||
init(_) ->
|
init(_) ->
|
||||||
{ok, RawConf} = hocon:load(emqx_conf_name(), #{format => richmap}),
|
{ok, RawConf} = hocon:load(emqx_conf_name(), #{format => richmap}),
|
||||||
{_MappedEnvs, Conf} = hocon_schema:map_translate(emqx_schema, RawConf, #{}),
|
{_MappedEnvs, Conf} = hocon_schema:map_translate(emqx_schema, RawConf, #{}),
|
||||||
ok = save_config_to_emqx_config(Conf),
|
ok = save_config_to_emqx_config(hocon_schema:richmap_to_map(Conf)),
|
||||||
{ok, #{raw_config => hocon_schema:richmap_to_map(RawConf),
|
{ok, #{raw_config => hocon_schema:richmap_to_map(RawConf),
|
||||||
handlers => #{?MOD => ?MODULE}}}.
|
handlers => #{?MOD => ?MODULE}}}.
|
||||||
|
|
||||||
|
|
|
@ -484,7 +484,7 @@ fields("telemetry") ->
|
||||||
];
|
];
|
||||||
|
|
||||||
fields(ExtraField) ->
|
fields(ExtraField) ->
|
||||||
Mod = list_to_atom(ExtraField),
|
Mod = list_to_atom(ExtraField++"_schema"),
|
||||||
Mod:fields(ExtraField).
|
Mod:fields(ExtraField).
|
||||||
|
|
||||||
translations() -> ["ekka", "vm_args", "gen_rpc", "kernel", "emqx"].
|
translations() -> ["ekka", "vm_args", "gen_rpc", "kernel", "emqx"].
|
||||||
|
|
|
@ -26,39 +26,7 @@
|
||||||
, update_config/1
|
, update_config/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-export([structs/0, fields/1]).
|
|
||||||
|
|
||||||
%%======================================================================================
|
|
||||||
%% Hocon Schema Definitions
|
|
||||||
|
|
||||||
-define(BRIDGE_FIELDS(T),
|
|
||||||
[{name, hoconsc:t(typerefl:binary())},
|
|
||||||
{type, hoconsc:t(typerefl:atom(T))},
|
|
||||||
{config, hoconsc:t(hoconsc:ref(list_to_atom("emqx_connector_"++atom_to_list(T)), ""))}]).
|
|
||||||
|
|
||||||
-define(TYPES, [mysql, pgsql, mongo, redis, ldap]).
|
|
||||||
-define(BRIDGES, [hoconsc:ref(?MODULE, T) || T <- ?TYPES]).
|
|
||||||
|
|
||||||
structs() -> ["emqx_data_bridge"].
|
|
||||||
|
|
||||||
fields("emqx_data_bridge") ->
|
|
||||||
[{bridges, #{type => hoconsc:array(hoconsc:union(?BRIDGES)),
|
|
||||||
default => []}}];
|
|
||||||
|
|
||||||
fields(mysql) -> ?BRIDGE_FIELDS(mysql);
|
|
||||||
fields(pgsql) -> ?BRIDGE_FIELDS(pgsql);
|
|
||||||
fields(mongo) -> ?BRIDGE_FIELDS(mongo);
|
|
||||||
fields(redis) -> ?BRIDGE_FIELDS(redis);
|
|
||||||
fields(ldap) -> ?BRIDGE_FIELDS(ldap).
|
|
||||||
|
|
||||||
%%======================================================================================
|
|
||||||
|
|
||||||
load_bridges() ->
|
load_bridges() ->
|
||||||
% ConfFile = filename:join([emqx:get_env(plugins_etc_dir), ?MODULE]) ++ ".conf",
|
|
||||||
% {ok, RawConfig} = hocon:load(ConfFile, #{format => richmap}),
|
|
||||||
% #{emqx_data_bridge := #{bridges := Bridges}} =
|
|
||||||
% hocon_schema:check(emqx_data_bridge_schema, RawConfig,
|
|
||||||
% #{atom_key => true, return_plain => true}),
|
|
||||||
Bridges = emqx_config:get([emqx_data_bridge, bridges], []),
|
Bridges = emqx_config:get([emqx_data_bridge, bridges], []),
|
||||||
emqx_data_bridge_monitor:ensure_all_started(Bridges).
|
emqx_data_bridge_monitor:ensure_all_started(Bridges).
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
-module(emqx_data_bridge_schema).
|
||||||
|
|
||||||
|
-export([structs/0, fields/1]).
|
||||||
|
|
||||||
|
%%======================================================================================
|
||||||
|
%% Hocon Schema Definitions
|
||||||
|
|
||||||
|
-define(BRIDGE_FIELDS(T),
|
||||||
|
[{name, hoconsc:t(typerefl:binary())},
|
||||||
|
{type, hoconsc:t(typerefl:atom(T))},
|
||||||
|
{config, hoconsc:t(hoconsc:ref(list_to_atom("emqx_connector_"++atom_to_list(T)), ""))}]).
|
||||||
|
|
||||||
|
-define(TYPES, [mysql, pgsql, mongo, redis, ldap]).
|
||||||
|
-define(BRIDGES, [hoconsc:ref(?MODULE, T) || T <- ?TYPES]).
|
||||||
|
|
||||||
|
structs() -> ["emqx_data_bridge"].
|
||||||
|
|
||||||
|
fields("emqx_data_bridge") ->
|
||||||
|
[{bridges, #{type => hoconsc:array(hoconsc:union(?BRIDGES)),
|
||||||
|
default => []}}];
|
||||||
|
|
||||||
|
fields(mysql) -> ?BRIDGE_FIELDS(mysql);
|
||||||
|
fields(pgsql) -> ?BRIDGE_FIELDS(pgsql);
|
||||||
|
fields(mongo) -> ?BRIDGE_FIELDS(mongo);
|
||||||
|
fields(redis) -> ?BRIDGE_FIELDS(redis);
|
||||||
|
fields(ldap) -> ?BRIDGE_FIELDS(ldap).
|
|
@ -16,10 +16,6 @@
|
||||||
|
|
||||||
-module(emqx_telemetry).
|
-module(emqx_telemetry).
|
||||||
|
|
||||||
-include_lib("typerefl/include/types.hrl").
|
|
||||||
|
|
||||||
-behaviour(hocon_schema).
|
|
||||||
|
|
||||||
-behaviour(gen_server).
|
-behaviour(gen_server).
|
||||||
|
|
||||||
-include_lib("emqx/include/emqx.hrl").
|
-include_lib("emqx/include/emqx.hrl").
|
||||||
|
@ -40,9 +36,6 @@
|
||||||
, stop/0
|
, stop/0
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-export([ structs/0
|
|
||||||
, fields/1]).
|
|
||||||
|
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
-export([ init/1
|
-export([ init/1
|
||||||
, handle_call/3
|
, handle_call/3
|
||||||
|
@ -97,12 +90,6 @@
|
||||||
|
|
||||||
-define(TELEMETRY, emqx_telemetry).
|
-define(TELEMETRY, emqx_telemetry).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
structs() -> ["emqx_telemetry"].
|
|
||||||
|
|
||||||
fields("emqx_telemetry") ->
|
|
||||||
[{enabled, emqx_schema:t(boolean(), undefined, false)}].
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Mnesia bootstrap
|
%% Mnesia bootstrap
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
-module(emqx_telemetry_schema).
|
||||||
|
|
||||||
|
-include_lib("typerefl/include/types.hrl").
|
||||||
|
|
||||||
|
-behaviour(hocon_schema).
|
||||||
|
|
||||||
|
-export([ structs/0
|
||||||
|
, fields/1]).
|
||||||
|
|
||||||
|
structs() -> ["emqx_telemetry"].
|
||||||
|
|
||||||
|
fields("emqx_telemetry") ->
|
||||||
|
[{enabled, emqx_schema:t(boolean(), undefined, false)}].
|
Loading…
Reference in New Issue