refactor: fix type upgrade calls and move compatiblitly logic

Some bridge V1 to V2 calls were wrong but did not seem to cause issues
(perhaps due to locking test coverage). This commit also move
compatibility logic from the API module to the emqx_bridge_v2 module
where most of the compatibility logic exists.
This commit is contained in:
Kjell Winblad 2024-01-16 11:51:53 +01:00 committed by Thales Macedo Garitezi
parent 440a543a85
commit c6cd3adccb
4 changed files with 12 additions and 8 deletions

View File

@ -352,10 +352,10 @@ get_metrics(ActionType, Name) ->
true -> true ->
case emqx_bridge_v2:bridge_v1_is_valid(ActionType, Name) of case emqx_bridge_v2:bridge_v1_is_valid(ActionType, Name) of
true -> true ->
BridgeV2Type = emqx_bridge_v2:bridge_v2_type_to_connector_type(ActionType), BridgeV2Type = emqx_bridge_v2:bridge_v1_type_to_bridge_v2_type(ActionType),
try try
ConfRootKey = emqx_bridge_v2:get_conf_root_key_if_only_one( ConfRootKey = emqx_bridge_v2:get_conf_root_key_if_only_one(
ActionType, Name BridgeV2Type, Name
), ),
emqx_bridge_v2:get_metrics(ConfRootKey, BridgeV2Type, Name) emqx_bridge_v2:get_metrics(ConfRootKey, BridgeV2Type, Name)
catch catch

View File

@ -554,11 +554,7 @@ schema("/bridges_probe") ->
case emqx_bridge_v2:is_bridge_v2_type(BridgeType) of case emqx_bridge_v2:is_bridge_v2_type(BridgeType) of
true -> true ->
try try
ConfRootKey = emqx_bridge_v2:get_conf_root_key_if_only_one( ok = emqx_bridge_v2:bridge_v1_reset_metrics(BridgeType, BridgeName),
BridgeType, BridgeName
),
BridgeV2Type = emqx_bridge_v2:bridge_v1_type_to_bridge_v2_type(BridgeType),
ok = emqx_bridge_v2:reset_metrics(ConfRootKey, BridgeV2Type, BridgeName),
?NO_CONTENT ?NO_CONTENT
catch catch
error:Reason -> error:Reason ->

View File

@ -147,7 +147,7 @@ reset_metrics(ResourceId) ->
true -> true ->
case emqx_bridge_v2:bridge_v1_is_valid(Type, Name) of case emqx_bridge_v2:bridge_v1_is_valid(Type, Name) of
true -> true ->
BridgeV2Type = emqx_bridge_v2:bridge_v2_type_to_connector_type(Type), BridgeV2Type = emqx_bridge_v2:bridge_v1_type_to_bridge_v2_type(Type),
emqx_bridge_v2:reset_metrics(BridgeV2Type, Name); emqx_bridge_v2:reset_metrics(BridgeV2Type, Name);
false -> false ->
{error, not_bridge_v1_compatible} {error, not_bridge_v1_compatible}

View File

@ -135,6 +135,7 @@
bridge_v1_restart/2, bridge_v1_restart/2,
bridge_v1_stop/2, bridge_v1_stop/2,
bridge_v1_start/2, bridge_v1_start/2,
bridge_v1_reset_metrics/2,
%% For test cases only %% For test cases only
bridge_v1_remove/2, bridge_v1_remove/2,
get_conf_root_key_if_only_one/2 get_conf_root_key_if_only_one/2
@ -1815,6 +1816,13 @@ bridge_v1_operation_helper(BridgeV1Type, Name, ConnectorOpFun, DoHealthCheck) ->
{error, not_bridge_v1_compatible} {error, not_bridge_v1_compatible}
end. end.
bridge_v1_reset_metrics(BridgeV1Type, BridgeName) ->
BridgeV2Type = bridge_v1_type_to_bridge_v2_type(BridgeV1Type),
ConfRootKey = get_conf_root_key_if_only_one(
BridgeV2Type, BridgeName
),
ok = reset_metrics(ConfRootKey, BridgeV2Type, BridgeName).
%%==================================================================== %%====================================================================
%% Misc helper functions %% Misc helper functions
%%==================================================================== %%====================================================================