fix(redis_bridge_schema): use correct `resource_opts` subfields for connector and action
This commit is contained in:
parent
fbbb55633d
commit
593283df93
|
@ -48,7 +48,8 @@
|
||||||
-export([
|
-export([
|
||||||
make_producer_action_schema/1,
|
make_producer_action_schema/1,
|
||||||
make_consumer_action_schema/1,
|
make_consumer_action_schema/1,
|
||||||
top_level_common_action_keys/0
|
top_level_common_action_keys/0,
|
||||||
|
project_to_actions_resource_opts/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-export_type([action_type/0]).
|
-export_type([action_type/0]).
|
||||||
|
@ -203,8 +204,8 @@ types_sc() ->
|
||||||
resource_opts_fields() ->
|
resource_opts_fields() ->
|
||||||
resource_opts_fields(_Overrides = []).
|
resource_opts_fields(_Overrides = []).
|
||||||
|
|
||||||
resource_opts_fields(Overrides) ->
|
common_resource_opts_subfields() ->
|
||||||
ActionROFields = [
|
[
|
||||||
batch_size,
|
batch_size,
|
||||||
batch_time,
|
batch_time,
|
||||||
buffer_mode,
|
buffer_mode,
|
||||||
|
@ -219,7 +220,13 @@ resource_opts_fields(Overrides) ->
|
||||||
start_after_created,
|
start_after_created,
|
||||||
start_timeout,
|
start_timeout,
|
||||||
worker_pool_size
|
worker_pool_size
|
||||||
],
|
].
|
||||||
|
|
||||||
|
common_resource_opts_subfields_bin() ->
|
||||||
|
lists:map(fun atom_to_binary/1, common_resource_opts_subfields()).
|
||||||
|
|
||||||
|
resource_opts_fields(Overrides) ->
|
||||||
|
ActionROFields = common_resource_opts_subfields(),
|
||||||
lists:filter(
|
lists:filter(
|
||||||
fun({Key, _Sc}) -> lists:member(Key, ActionROFields) end,
|
fun({Key, _Sc}) -> lists:member(Key, ActionROFields) end,
|
||||||
emqx_resource_schema:create_opts(Overrides)
|
emqx_resource_schema:create_opts(Overrides)
|
||||||
|
@ -274,6 +281,10 @@ make_consumer_action_schema(ActionParametersRef) ->
|
||||||
})}
|
})}
|
||||||
].
|
].
|
||||||
|
|
||||||
|
project_to_actions_resource_opts(OldResourceOpts) ->
|
||||||
|
Subfields = common_resource_opts_subfields_bin(),
|
||||||
|
maps:with(Subfields, OldResourceOpts).
|
||||||
|
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
-include_lib("hocon/include/hocon_types.hrl").
|
-include_lib("hocon/include/hocon_types.hrl").
|
||||||
schema_homogeneous_test() ->
|
schema_homogeneous_test() ->
|
||||||
|
|
|
@ -120,6 +120,7 @@ fields("get_sentinel") ->
|
||||||
method_fields(get, redis_sentinel);
|
method_fields(get, redis_sentinel);
|
||||||
fields("get_cluster") ->
|
fields("get_cluster") ->
|
||||||
method_fields(get, redis_cluster);
|
method_fields(get, redis_cluster);
|
||||||
|
%% old bridge v1 schema
|
||||||
fields(Type) when
|
fields(Type) when
|
||||||
Type == redis_single orelse Type == redis_sentinel orelse Type == redis_cluster
|
Type == redis_single orelse Type == redis_sentinel orelse Type == redis_cluster
|
||||||
->
|
->
|
||||||
|
@ -147,7 +148,7 @@ redis_bridge_common_fields(Type) ->
|
||||||
{local_topic, mk(binary(), #{required => false, desc => ?DESC("desc_local_topic")})}
|
{local_topic, mk(binary(), #{required => false, desc => ?DESC("desc_local_topic")})}
|
||||||
| fields(action_parameters)
|
| fields(action_parameters)
|
||||||
] ++
|
] ++
|
||||||
resource_fields(Type).
|
v1_resource_fields(Type).
|
||||||
|
|
||||||
connector_fields(Type) ->
|
connector_fields(Type) ->
|
||||||
emqx_redis:fields(Type).
|
emqx_redis:fields(Type).
|
||||||
|
@ -158,7 +159,7 @@ type_name_fields(Type) ->
|
||||||
{name, mk(binary(), #{required => true, desc => ?DESC("desc_name")})}
|
{name, mk(binary(), #{required => true, desc => ?DESC("desc_name")})}
|
||||||
].
|
].
|
||||||
|
|
||||||
resource_fields(Type) ->
|
v1_resource_fields(Type) ->
|
||||||
[
|
[
|
||||||
{resource_opts,
|
{resource_opts,
|
||||||
mk(
|
mk(
|
||||||
|
|
|
@ -43,7 +43,12 @@ bridge_v1_config_to_action_config(BridgeV1Config, ConnectorName) ->
|
||||||
ActionTopLevelKeys = schema_keys(?SCHEMA_MODULE:fields(redis_action)),
|
ActionTopLevelKeys = schema_keys(?SCHEMA_MODULE:fields(redis_action)),
|
||||||
ActionParametersKeys = schema_keys(emqx_bridge_redis:fields(action_parameters)),
|
ActionParametersKeys = schema_keys(emqx_bridge_redis:fields(action_parameters)),
|
||||||
ActionKeys = ActionTopLevelKeys ++ ActionParametersKeys,
|
ActionKeys = ActionTopLevelKeys ++ ActionParametersKeys,
|
||||||
ActionConfig = make_config_map(ActionKeys, ActionParametersKeys, BridgeV1Config),
|
ActionConfig0 = make_config_map(ActionKeys, ActionParametersKeys, BridgeV1Config),
|
||||||
|
ActionConfig = emqx_utils_maps:update_if_present(
|
||||||
|
<<"resource_opts">>,
|
||||||
|
fun emqx_bridge_v2_schema:project_to_actions_resource_opts/1,
|
||||||
|
ActionConfig0
|
||||||
|
),
|
||||||
ActionConfig#{<<"connector">> => ConnectorName}.
|
ActionConfig#{<<"connector">> => ConnectorName}.
|
||||||
|
|
||||||
bridge_v1_config_to_connector_config(BridgeV1Config) ->
|
bridge_v1_config_to_connector_config(BridgeV1Config) ->
|
||||||
|
@ -57,7 +62,12 @@ bridge_v1_config_to_connector_config(BridgeV1Config) ->
|
||||||
(maps:keys(BridgeV1Config) -- (ActionKeys -- ConnectorTopLevelKeys)) ++
|
(maps:keys(BridgeV1Config) -- (ActionKeys -- ConnectorTopLevelKeys)) ++
|
||||||
[<<"redis_type">>],
|
[<<"redis_type">>],
|
||||||
ConnectorParametersKeys = ConnectorKeys -- ConnectorTopLevelKeys,
|
ConnectorParametersKeys = ConnectorKeys -- ConnectorTopLevelKeys,
|
||||||
make_config_map(ConnectorKeys, ConnectorParametersKeys, BridgeV1Config).
|
ConnectorConfig0 = make_config_map(ConnectorKeys, ConnectorParametersKeys, BridgeV1Config),
|
||||||
|
emqx_utils_maps:update_if_present(
|
||||||
|
<<"resource_opts">>,
|
||||||
|
fun emqx_connector_schema:project_to_connector_resource_opts/1,
|
||||||
|
ConnectorConfig0
|
||||||
|
).
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------------------
|
||||||
%% Internal helper fns
|
%% Internal helper fns
|
||||||
|
|
|
@ -51,8 +51,10 @@ fields("config_connector") ->
|
||||||
)}
|
)}
|
||||||
] ++
|
] ++
|
||||||
emqx_redis:redis_fields() ++
|
emqx_redis:redis_fields() ++
|
||||||
emqx_connector_schema:resource_opts_ref(?MODULE, resource_opts) ++
|
emqx_connector_schema:resource_opts_ref(?MODULE, connector_resource_opts) ++
|
||||||
emqx_connector_schema_lib:ssl_fields();
|
emqx_connector_schema_lib:ssl_fields();
|
||||||
|
fields(connector_resource_opts) ->
|
||||||
|
emqx_connector_schema:resource_opts_fields();
|
||||||
fields(action) ->
|
fields(action) ->
|
||||||
{?TYPE,
|
{?TYPE,
|
||||||
?HOCON(
|
?HOCON(
|
||||||
|
@ -74,15 +76,7 @@ fields(redis_action) ->
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
ResOpts =
|
[ResOpts] = emqx_connector_schema:resource_opts_ref(?MODULE, action_resource_opts),
|
||||||
{resource_opts,
|
|
||||||
?HOCON(
|
|
||||||
?R_REF(resource_opts),
|
|
||||||
#{
|
|
||||||
required => true,
|
|
||||||
desc => ?DESC(emqx_resource_schema, resource_opts)
|
|
||||||
}
|
|
||||||
)},
|
|
||||||
RedisType =
|
RedisType =
|
||||||
{redis_type,
|
{redis_type,
|
||||||
?HOCON(
|
?HOCON(
|
||||||
|
@ -90,8 +84,8 @@ fields(redis_action) ->
|
||||||
#{required => true, desc => ?DESC(redis_type)}
|
#{required => true, desc => ?DESC(redis_type)}
|
||||||
)},
|
)},
|
||||||
[RedisType | lists:keyreplace(resource_opts, 1, Schema, ResOpts)];
|
[RedisType | lists:keyreplace(resource_opts, 1, Schema, ResOpts)];
|
||||||
fields(resource_opts) ->
|
fields(action_resource_opts) ->
|
||||||
emqx_resource_schema:create_opts([
|
emqx_bridge_v2_schema:resource_opts_fields([
|
||||||
{batch_size, #{desc => ?DESC(batch_size)}},
|
{batch_size, #{desc => ?DESC(batch_size)}},
|
||||||
{batch_time, #{desc => ?DESC(batch_time)}}
|
{batch_time, #{desc => ?DESC(batch_time)}}
|
||||||
]);
|
]);
|
||||||
|
@ -124,6 +118,10 @@ desc(redis_action) ->
|
||||||
?DESC(redis_action);
|
?DESC(redis_action);
|
||||||
desc(resource_opts) ->
|
desc(resource_opts) ->
|
||||||
?DESC(emqx_resource_schema, resource_opts);
|
?DESC(emqx_resource_schema, resource_opts);
|
||||||
|
desc(connector_resource_opts) ->
|
||||||
|
?DESC(emqx_resource_schema, "resource_opts");
|
||||||
|
desc(action_resource_opts) ->
|
||||||
|
?DESC(emqx_resource_schema, "resource_opts");
|
||||||
desc(_Name) ->
|
desc(_Name) ->
|
||||||
undefined.
|
undefined.
|
||||||
|
|
||||||
|
|
|
@ -123,10 +123,19 @@ wait_for_ci_redis(Checks, Config) ->
|
||||||
ProxyHost = os:getenv("PROXY_HOST", ?PROXY_HOST),
|
ProxyHost = os:getenv("PROXY_HOST", ?PROXY_HOST),
|
||||||
ProxyPort = list_to_integer(os:getenv("PROXY_PORT", ?PROXY_PORT)),
|
ProxyPort = list_to_integer(os:getenv("PROXY_PORT", ?PROXY_PORT)),
|
||||||
emqx_common_test_helpers:reset_proxy(ProxyHost, ProxyPort),
|
emqx_common_test_helpers:reset_proxy(ProxyHost, ProxyPort),
|
||||||
ok = emqx_common_test_helpers:start_apps([
|
Apps = emqx_cth_suite:start(
|
||||||
emqx_conf, emqx_resource, emqx_connector, emqx_bridge, emqx_rule_engine
|
[
|
||||||
]),
|
emqx,
|
||||||
|
emqx_conf,
|
||||||
|
emqx_resource,
|
||||||
|
emqx_connector,
|
||||||
|
emqx_bridge,
|
||||||
|
emqx_rule_engine
|
||||||
|
],
|
||||||
|
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||||
|
),
|
||||||
[
|
[
|
||||||
|
{apps, Apps},
|
||||||
{proxy_host, ProxyHost},
|
{proxy_host, ProxyHost},
|
||||||
{proxy_port, ProxyPort}
|
{proxy_port, ProxyPort}
|
||||||
| Config
|
| Config
|
||||||
|
@ -143,11 +152,9 @@ redis_checks() ->
|
||||||
1
|
1
|
||||||
end.
|
end.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(Config) ->
|
||||||
ok = emqx_bridge_v2_SUITE:delete_all_bridges_and_connectors(),
|
Apps = ?config(apps, Config),
|
||||||
ok = emqx_common_test_helpers:stop_apps([emqx_conf]),
|
emqx_cth_suite:stop(Apps),
|
||||||
ok = emqx_connector_test_helpers:stop_apps([emqx_rule_engine, emqx_bridge, emqx_resource]),
|
|
||||||
_ = application:stop(emqx_connector),
|
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
init_per_testcase(Testcase, Config0) ->
|
init_per_testcase(Testcase, Config0) ->
|
||||||
|
|
|
@ -28,7 +28,8 @@
|
||||||
-export([
|
-export([
|
||||||
transform_bridges_v1_to_connectors_and_bridges_v2/1,
|
transform_bridges_v1_to_connectors_and_bridges_v2/1,
|
||||||
transform_bridge_v1_config_to_action_config/4,
|
transform_bridge_v1_config_to_action_config/4,
|
||||||
top_level_common_connector_keys/0
|
top_level_common_connector_keys/0,
|
||||||
|
project_to_connector_resource_opts/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-export([roots/0, fields/1, desc/1, namespace/0, tags/0]).
|
-export([roots/0, fields/1, desc/1, namespace/0, tags/0]).
|
||||||
|
@ -195,7 +196,7 @@ split_bridge_to_connector_and_action(
|
||||||
case maps:is_key(ConnectorFieldNameBin, BridgeV1Conf) of
|
case maps:is_key(ConnectorFieldNameBin, BridgeV1Conf) of
|
||||||
true ->
|
true ->
|
||||||
PrevFieldConfig =
|
PrevFieldConfig =
|
||||||
project_to_connector_resource_opts(
|
maybe_project_to_connector_resource_opts(
|
||||||
ConnectorFieldNameBin,
|
ConnectorFieldNameBin,
|
||||||
maps:get(ConnectorFieldNameBin, BridgeV1Conf)
|
maps:get(ConnectorFieldNameBin, BridgeV1Conf)
|
||||||
),
|
),
|
||||||
|
@ -231,12 +232,15 @@ split_bridge_to_connector_and_action(
|
||||||
end,
|
end,
|
||||||
{BridgeType, BridgeName, ActionMap, ConnectorName, ConnectorMap}.
|
{BridgeType, BridgeName, ActionMap, ConnectorName, ConnectorMap}.
|
||||||
|
|
||||||
project_to_connector_resource_opts(<<"resource_opts">>, OldResourceOpts) ->
|
maybe_project_to_connector_resource_opts(<<"resource_opts">>, OldResourceOpts) ->
|
||||||
Subfields = common_resource_opts_subfields_bin(),
|
project_to_connector_resource_opts(OldResourceOpts);
|
||||||
maps:with(Subfields, OldResourceOpts);
|
maybe_project_to_connector_resource_opts(_, OldConfig) ->
|
||||||
project_to_connector_resource_opts(_, OldConfig) ->
|
|
||||||
OldConfig.
|
OldConfig.
|
||||||
|
|
||||||
|
project_to_connector_resource_opts(OldResourceOpts) ->
|
||||||
|
Subfields = common_resource_opts_subfields_bin(),
|
||||||
|
maps:with(Subfields, OldResourceOpts).
|
||||||
|
|
||||||
transform_bridge_v1_config_to_action_config(
|
transform_bridge_v1_config_to_action_config(
|
||||||
BridgeV1Conf, ConnectorName, ConnectorConfSchemaMod, ConnectorConfSchemaName
|
BridgeV1Conf, ConnectorName, ConnectorConfSchemaMod, ConnectorConfSchemaName
|
||||||
) ->
|
) ->
|
||||||
|
|
Loading…
Reference in New Issue