Merge pull request #12142 from sstrigler/EMQX-11487-e-5-4-0-mongodb-test-connection-failed
mongodb test connection failed
This commit is contained in:
commit
71011ad084
|
@ -26,8 +26,8 @@
|
|||
bridge_v1_type_to_action_type/1,
|
||||
is_action_type/1,
|
||||
registered_schema_modules/0,
|
||||
connector_action_config_to_bridge_v1_config/2,
|
||||
connector_action_config_to_bridge_v1_config/3,
|
||||
has_custom_connector_action_config_to_bridge_v1_config/1,
|
||||
bridge_v1_config_to_connector_config/2,
|
||||
has_custom_bridge_v1_config_to_connector_config/1,
|
||||
bridge_v1_config_to_action_config/3,
|
||||
|
@ -162,14 +162,24 @@ registered_schema_modules() ->
|
|||
Schemas = maps:get(action_type_to_schema_module, InfoMap),
|
||||
maps:to_list(Schemas).
|
||||
|
||||
has_custom_connector_action_config_to_bridge_v1_config(ActionOrBridgeType) ->
|
||||
Module = get_action_info_module(ActionOrBridgeType),
|
||||
erlang:function_exported(Module, connector_action_config_to_bridge_v1_config, 2).
|
||||
|
||||
connector_action_config_to_bridge_v1_config(ActionOrBridgeType, ConnectorConfig, ActionConfig) ->
|
||||
Module = get_action_info_module(ActionOrBridgeType),
|
||||
%% should only be called if defined
|
||||
Module:connector_action_config_to_bridge_v1_config(ConnectorConfig, ActionConfig).
|
||||
case erlang:function_exported(Module, connector_action_config_to_bridge_v1_config, 2) of
|
||||
true ->
|
||||
Module:connector_action_config_to_bridge_v1_config(ConnectorConfig, ActionConfig);
|
||||
false ->
|
||||
connector_action_config_to_bridge_v1_config(ConnectorConfig, ActionConfig)
|
||||
end.
|
||||
|
||||
connector_action_config_to_bridge_v1_config(ConnectorConfig, ActionConfig) ->
|
||||
Merged = emqx_utils_maps:deep_merge(
|
||||
maps:without(
|
||||
[<<"connector">>],
|
||||
emqx_utils_maps:unindent(<<"parameters">>, ActionConfig)
|
||||
),
|
||||
emqx_utils_maps:unindent(<<"parameters">>, ConnectorConfig)
|
||||
),
|
||||
maps:without([<<"description">>], Merged).
|
||||
|
||||
has_custom_bridge_v1_config_to_connector_config(ActionOrBridgeType) ->
|
||||
Module = get_action_info_module(ActionOrBridgeType),
|
||||
|
|
|
@ -913,7 +913,7 @@ format_resource(
|
|||
redact(
|
||||
maps:merge(
|
||||
RawConfFull#{
|
||||
type => downgrade_type(Type, RawConf),
|
||||
type => downgrade_type(Type, emqx_bridge_lib:get_conf(Type, BridgeName)),
|
||||
name => maps:get(<<"name">>, RawConf, BridgeName),
|
||||
node => Node
|
||||
},
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
-export([
|
||||
maybe_withdraw_rule_action/3,
|
||||
upgrade_type/1,
|
||||
downgrade_type/2
|
||||
downgrade_type/2,
|
||||
get_conf/2
|
||||
]).
|
||||
|
||||
%% @doc A bridge can be used as a rule action.
|
||||
|
|
|
@ -1112,40 +1112,25 @@ bridge_v1_lookup_and_transform(ActionType, Name) ->
|
|||
not_bridge_v1_compatible_error() ->
|
||||
{error, not_bridge_v1_compatible}.
|
||||
|
||||
connector_raw_config(Connector, ConnectorType) ->
|
||||
get_raw_with_defaults(Connector, ConnectorType, <<"connectors">>, emqx_connector_schema).
|
||||
|
||||
action_raw_config(Action, ActionType) ->
|
||||
get_raw_with_defaults(Action, ActionType, <<"actions">>, emqx_bridge_v2_schema).
|
||||
|
||||
get_raw_with_defaults(Config, Type, TopLevelConf, SchemaModule) ->
|
||||
RawConfig = maps:get(raw_config, Config),
|
||||
fill_defaults(Type, RawConfig, TopLevelConf, SchemaModule).
|
||||
|
||||
bridge_v1_lookup_and_transform_helper(
|
||||
BridgeV1Type, BridgeName, ActionType, Action, ConnectorType, Connector
|
||||
) ->
|
||||
ConnectorRawConfig1 = maps:get(raw_config, Connector),
|
||||
ConnectorRawConfig2 = fill_defaults(
|
||||
ConnectorType,
|
||||
ConnectorRawConfig1,
|
||||
<<"connectors">>,
|
||||
emqx_connector_schema
|
||||
ConnectorRawConfig = connector_raw_config(Connector, ConnectorType),
|
||||
ActionRawConfig = action_raw_config(Action, ActionType),
|
||||
BridgeV1Config = emqx_action_info:connector_action_config_to_bridge_v1_config(
|
||||
BridgeV1Type, ConnectorRawConfig, ActionRawConfig
|
||||
),
|
||||
ActionRawConfig1 = maps:get(raw_config, Action),
|
||||
ActionRawConfig2 = fill_defaults(
|
||||
ActionType,
|
||||
ActionRawConfig1,
|
||||
<<"actions">>,
|
||||
emqx_bridge_v2_schema
|
||||
),
|
||||
BridgeV1ConfigFinal =
|
||||
case
|
||||
emqx_action_info:has_custom_connector_action_config_to_bridge_v1_config(BridgeV1Type)
|
||||
of
|
||||
false ->
|
||||
BridgeV1Config1 = maps:remove(<<"connector">>, ActionRawConfig2),
|
||||
%% Move parameters to the top level
|
||||
ParametersMap = maps:get(<<"parameters">>, BridgeV1Config1, #{}),
|
||||
BridgeV1Config2 = maps:remove(<<"parameters">>, BridgeV1Config1),
|
||||
BridgeV1Config3 = emqx_utils_maps:deep_merge(BridgeV1Config2, ParametersMap),
|
||||
emqx_utils_maps:deep_merge(ConnectorRawConfig2, BridgeV1Config3);
|
||||
true ->
|
||||
emqx_action_info:connector_action_config_to_bridge_v1_config(
|
||||
BridgeV1Type, ConnectorRawConfig2, ActionRawConfig2
|
||||
)
|
||||
end,
|
||||
BridgeV1Tmp = maps:put(raw_config, BridgeV1ConfigFinal, Action),
|
||||
BridgeV1Tmp = maps:put(raw_config, BridgeV1Config, Action),
|
||||
BridgeV1 = maps:remove(status, BridgeV1Tmp),
|
||||
BridgeV2Status = maps:get(status, Action, undefined),
|
||||
BridgeV2Error = maps:get(error, Action, undefined),
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
-export([
|
||||
bridge_v1_config_to_action_config/2,
|
||||
bridge_v1_config_to_connector_config/1,
|
||||
connector_action_config_to_bridge_v1_config/2,
|
||||
action_type_name/0,
|
||||
bridge_v1_type_name/0,
|
||||
connector_type_name/0,
|
||||
|
@ -26,20 +25,6 @@
|
|||
|
||||
-define(SCHEMA_MODULE, emqx_bridge_mongodb).
|
||||
|
||||
connector_action_config_to_bridge_v1_config(ConnectorConfig, ActionConfig) ->
|
||||
fix_v1_type(
|
||||
maps:merge(
|
||||
maps:without(
|
||||
[<<"connector">>],
|
||||
emqx_utils_maps:unindent(<<"parameters">>, ActionConfig)
|
||||
),
|
||||
emqx_utils_maps:unindent(<<"parameters">>, ConnectorConfig)
|
||||
)
|
||||
).
|
||||
|
||||
fix_v1_type(#{<<"mongo_type">> := MongoType} = Conf) ->
|
||||
Conf#{<<"type">> => v1_type(MongoType)}.
|
||||
|
||||
bridge_v1_config_to_action_config(BridgeV1Config, ConnectorName) ->
|
||||
ActionTopLevelKeys = schema_keys(mongodb_action),
|
||||
ActionParametersKeys = schema_keys(action_parameters),
|
||||
|
|
|
@ -129,7 +129,7 @@ fields(action) ->
|
|||
{mysql,
|
||||
mk(
|
||||
hoconsc:map(name, ref(?MODULE, mysql_action)),
|
||||
#{desc => <<"MySQL Action Config">>, required => false}
|
||||
#{desc => ?DESC("mysql_action"), required => false}
|
||||
)};
|
||||
fields(mysql_action) ->
|
||||
emqx_bridge_v2_schema:make_producer_action_schema(
|
||||
|
|
|
@ -773,7 +773,6 @@ t_missing_table(Config) ->
|
|||
),
|
||||
Val = integer_to_binary(erlang:unique_integer()),
|
||||
SentData = #{payload => Val, timestamp => 1668602148000},
|
||||
%Timeout = 1000,
|
||||
ResourceID = emqx_bridge_v2:id(BridgeType, Name),
|
||||
Request = {ResourceID, SentData},
|
||||
Result =
|
||||
|
|
|
@ -345,7 +345,7 @@ indent(IndentKey, PickKeys, Map) ->
|
|||
|
||||
-spec unindent(term(), map()) -> map().
|
||||
unindent(Key, Map) ->
|
||||
maps:merge(
|
||||
deep_merge(
|
||||
maps:remove(Key, Map),
|
||||
maps:get(Key, Map, #{})
|
||||
).
|
||||
|
|
|
@ -170,5 +170,9 @@ map_indent_unindent_test_() ->
|
|||
?_assertEqual(
|
||||
#{a => 1, b => 2},
|
||||
unindent(c, M)
|
||||
),
|
||||
?_assertEqual(
|
||||
#{a => #{c => 3, d => 4}},
|
||||
unindent(b, #{a => #{c => 3}, b => #{a => #{d => 4}}})
|
||||
)
|
||||
].
|
||||
|
|
Loading…
Reference in New Issue