fix: remove connector as well on Bridge V1 remove

For backwards compatibility we remove the connector for the Bridge V2
bridge when performing the remove operation but only if no other
channels depend on the connector.
This commit is contained in:
Kjell Winblad 2023-10-13 07:37:46 +02:00 committed by Zaiming (Stone) Shi
parent 828bbc57ac
commit b0b518067a
2 changed files with 37 additions and 3 deletions

View File

@ -398,7 +398,11 @@ remove_v1(BridgeType, BridgeName) ->
check_deps_and_remove(BridgeType, BridgeName, RemoveDeps) -> check_deps_and_remove(BridgeType, BridgeName, RemoveDeps) ->
case emqx_bridge_v2:is_bridge_v2_type(BridgeType) of case emqx_bridge_v2:is_bridge_v2_type(BridgeType) of
true -> true ->
emqx_bridge_v2:check_deps_and_remove(BridgeType, BridgeName, RemoveDeps); emqx_bridge_v2:check_deps_and_remove_transform_to_bridge_v1(
BridgeType,
BridgeName,
RemoveDeps
);
false -> false ->
check_deps_and_remove_v1(BridgeType, BridgeName, RemoveDeps) check_deps_and_remove_v1(BridgeType, BridgeName, RemoveDeps)
end. end.

View File

@ -647,13 +647,43 @@ check_deps_and_remove(BridgeType, BridgeName, RemoveDeps) ->
end. end.
check_deps_and_remove_transform_to_bridge_v1(BridgeType, BridgeName, RemoveDeps) -> check_deps_and_remove_transform_to_bridge_v1(BridgeType, BridgeName, RemoveDeps) ->
check_deps_and_remove_transform_to_bridge_v1(
BridgeType,
BridgeName,
RemoveDeps,
lookup_raw_conf(BridgeType, BridgeName)
).
check_deps_and_remove_transform_to_bridge_v1(
BridgeType,
BridgeName,
RemoveDeps,
#{connector := ConnectorName}
) ->
case check_deps_and_remove(BridgeType, BridgeName, RemoveDeps) of case check_deps_and_remove(BridgeType, BridgeName, RemoveDeps) of
{error, _} = Error -> {error, _} = Error ->
Error; Error;
Result -> Result ->
%% TODO: We should call emqx_connector:check_deps_and_remove here %% Check if there are other channels that depends on the same connector
%% to remain as backward compatible as possible. case connector_has_channels(BridgeType, ConnectorName) of
false ->
ConnectorType = bridge_v2_type_to_connector_type(BridgeType),
emqx_connector:remove(ConnectorType, ConnectorName);
true ->
ok
end,
Result Result
end;
check_deps_and_remove_transform_to_bridge_v1(_BridgeType, _BridgeName, _RemoveDeps, Error) ->
Error.
connector_has_channels(BridgeV2Type, ConnectorName) ->
ConnectorType = bridge_v2_type_to_connector_type(BridgeV2Type),
case emqx_connector_resource:get_channels(ConnectorType, ConnectorName) of
{ok, []} ->
false;
_ ->
true
end. end.
%% NOTE: We depends on the `emqx_bridge:pre_config_update/3` to restart/stop the %% NOTE: We depends on the `emqx_bridge:pre_config_update/3` to restart/stop the