fix: compatible with bridge v1
This commit is contained in:
parent
9143d5994d
commit
00d50479f5
|
@ -1,3 +1,7 @@
|
|||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2024 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-module(emqx_bridge_clickhouse_action_info).
|
||||
|
||||
-behaviour(emqx_action_info).
|
||||
|
|
|
@ -96,6 +96,7 @@ connector_values() ->
|
|||
pool_size => 8,
|
||||
username => <<"sa">>,
|
||||
password => <<"******">>,
|
||||
driver => ?DEFAULT_DRIVER,
|
||||
resource_opts => #{health_check_interval => <<"20s">>}
|
||||
}.
|
||||
|
||||
|
@ -113,7 +114,10 @@ bridge_v2_examples(Method) ->
|
|||
].
|
||||
|
||||
action_values() ->
|
||||
#{parameters => #{sql => ?DEFAULT_SQL}}.
|
||||
#{
|
||||
<<"parameters">> =>
|
||||
#{<<"sql">> => ?DEFAULT_SQL}
|
||||
}.
|
||||
|
||||
%% -------------------------------------------------------------------------------------------------
|
||||
%% Hocon Schema Definitions
|
||||
|
@ -138,9 +142,20 @@ fields(Field) when
|
|||
fields("config_connector") -- emqx_connector_schema:common_fields()
|
||||
);
|
||||
fields("config_connector") ->
|
||||
emqx_connector_schema:common_fields() ++
|
||||
emqx_bridge_sqlserver_connector:fields(config) ++
|
||||
emqx_connector_schema:resource_opts_ref(?MODULE, connector_resource_opts);
|
||||
Config =
|
||||
driver_fields() ++
|
||||
emqx_connector_schema:common_fields() ++
|
||||
emqx_bridge_sqlserver_connector:fields(config) ++
|
||||
emqx_connector_schema:resource_opts_ref(?MODULE, connector_resource_opts),
|
||||
lists:foldl(
|
||||
fun(Key, Acc) ->
|
||||
proplists:delete(Key, Acc)
|
||||
end,
|
||||
Config,
|
||||
[
|
||||
auto_reconnect
|
||||
]
|
||||
);
|
||||
fields(connector_resource_opts) ->
|
||||
emqx_connector_schema:resource_opts_fields();
|
||||
fields("config") ->
|
||||
|
@ -151,7 +166,6 @@ fields("config") ->
|
|||
binary(),
|
||||
#{desc => ?DESC("sql_template"), default => ?DEFAULT_SQL, format => <<"sql">>}
|
||||
)},
|
||||
{driver, mk(binary(), #{desc => ?DESC("driver"), default => ?DEFAULT_DRIVER})},
|
||||
{local_topic,
|
||||
mk(
|
||||
binary(),
|
||||
|
@ -166,7 +180,7 @@ fields("config") ->
|
|||
desc => ?DESC(emqx_resource_schema, <<"resource_opts">>)
|
||||
}
|
||||
)}
|
||||
] ++
|
||||
] ++ driver_fields() ++
|
||||
(emqx_bridge_sqlserver_connector:fields(config) --
|
||||
emqx_connector_schema_lib:prepare_statement_fields());
|
||||
fields(action) ->
|
||||
|
@ -202,6 +216,9 @@ fields("get") ->
|
|||
fields("post", Type) ->
|
||||
[type_field(Type), name_field() | fields("config")].
|
||||
|
||||
driver_fields() ->
|
||||
[{driver, mk(binary(), #{desc => ?DESC("driver"), default => ?DEFAULT_DRIVER})}].
|
||||
|
||||
desc("config") ->
|
||||
?DESC("desc_config");
|
||||
desc(Method) when Method =:= "get"; Method =:= "put"; Method =:= "post" ->
|
||||
|
|
|
@ -6,17 +6,67 @@
|
|||
|
||||
-behaviour(emqx_action_info).
|
||||
|
||||
-elvis([{elvis_style, invalid_dynamic_call, disable}]).
|
||||
|
||||
-export([
|
||||
bridge_v1_type_name/0,
|
||||
action_type_name/0,
|
||||
connector_type_name/0,
|
||||
schema_module/0
|
||||
schema_module/0,
|
||||
bridge_v1_config_to_action_config/2,
|
||||
bridge_v1_config_to_connector_config/1,
|
||||
connector_action_config_to_bridge_v1_config/2
|
||||
]).
|
||||
|
||||
bridge_v1_type_name() -> sqlserver.
|
||||
-import(emqx_utils_conv, [bin/1]).
|
||||
|
||||
action_type_name() -> sqlserver.
|
||||
-define(ACTION_TYPE, sqlserver).
|
||||
-define(SCHEMA_MODULE, emqx_bridge_sqlserver).
|
||||
|
||||
connector_type_name() -> sqlserver.
|
||||
bridge_v1_type_name() -> ?ACTION_TYPE.
|
||||
|
||||
schema_module() -> emqx_bridge_sqlserver.
|
||||
action_type_name() -> ?ACTION_TYPE.
|
||||
|
||||
connector_type_name() -> ?ACTION_TYPE.
|
||||
|
||||
schema_module() -> ?SCHEMA_MODULE.
|
||||
|
||||
bridge_v1_config_to_action_config(BridgeV1Config, ConnectorName) ->
|
||||
ActionTopLevelKeys = schema_keys(sqlserver_action),
|
||||
ActionParametersKeys = schema_keys(action_parameters),
|
||||
ActionKeys = ActionTopLevelKeys ++ ActionParametersKeys,
|
||||
ActionConfig = make_config_map(ActionKeys, ActionParametersKeys, BridgeV1Config),
|
||||
emqx_utils_maps:update_if_present(
|
||||
<<"resource_opts">>,
|
||||
fun emqx_bridge_v2_schema:project_to_actions_resource_opts/1,
|
||||
ActionConfig#{<<"connector">> => ConnectorName}
|
||||
).
|
||||
|
||||
bridge_v1_config_to_connector_config(BridgeV1Config) ->
|
||||
ActionTopLevelKeys = schema_keys(sqlserver_action),
|
||||
ActionParametersKeys = schema_keys(action_parameters),
|
||||
ActionKeys = ActionTopLevelKeys ++ ActionParametersKeys,
|
||||
ConnectorTopLevelKeys = schema_keys("config_connector"),
|
||||
ConnectorKeys = maps:keys(BridgeV1Config) -- (ActionKeys -- ConnectorTopLevelKeys),
|
||||
ConnConfig0 = maps:with(ConnectorKeys, BridgeV1Config),
|
||||
emqx_utils_maps:update_if_present(
|
||||
<<"resource_opts">>,
|
||||
fun emqx_connector_schema:project_to_connector_resource_opts/1,
|
||||
ConnConfig0
|
||||
).
|
||||
|
||||
connector_action_config_to_bridge_v1_config(ConnectorConfig, ActionConfig) ->
|
||||
V1Config = emqx_action_info:connector_action_config_to_bridge_v1_config(
|
||||
ConnectorConfig, ActionConfig
|
||||
),
|
||||
maps:remove(<<"local_topic">>, V1Config).
|
||||
|
||||
make_config_map(PickKeys, IndentKeys, Config) ->
|
||||
Conf0 = maps:with(PickKeys, Config),
|
||||
emqx_utils_maps:indent(<<"parameters">>, IndentKeys, Conf0).
|
||||
|
||||
schema_keys(Name) ->
|
||||
schema_keys(?SCHEMA_MODULE, Name).
|
||||
|
||||
schema_keys(Mod, Name) ->
|
||||
[bin(Key) || Key <- proplists:get_keys(Mod:fields(Name))].
|
||||
|
|
|
@ -61,7 +61,7 @@ resource_type(syskeeper_forwarder) ->
|
|||
resource_type(syskeeper_proxy) ->
|
||||
emqx_bridge_syskeeper_proxy_server;
|
||||
resource_type(sqlserver) ->
|
||||
emqx_bridge_sqlserver;
|
||||
emqx_bridge_sqlserver_connector;
|
||||
resource_type(timescale) ->
|
||||
emqx_postgresql;
|
||||
resource_type(redis) ->
|
||||
|
|
Loading…
Reference in New Issue