Merge pull request #12435 from zhongwencool/dont-add-disable-resource-to-connector

fix: don't add disable bridge to connector's channel
This commit is contained in:
zhongwencool 2024-02-01 10:39:47 +08:00 committed by GitHub
commit 42a4bc3382
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 4 deletions

View File

@ -221,6 +221,32 @@ t_create_remove(_) ->
ok = emqx_bridge_v2:remove(bridge_type(), my_test_bridge),
ok.
t_create_disabled_bridge(_) ->
Config = #{<<"connector">> := Connector} = bridge_config(),
Disable = Config#{<<"enable">> => false},
BridgeType = bridge_type(),
{ok, _} = emqx_bridge_v2:create(BridgeType, my_enable_bridge, Config),
{ok, _} = emqx_bridge_v2:create(BridgeType, my_disable_bridge, Disable),
ConnectorId = emqx_connector_resource:resource_id(con_type(), Connector),
?assertMatch(
[
{_, #{
enable := true,
connector := Connector,
bridge_type := _
}},
{_, #{
enable := false,
connector := Connector,
bridge_type := _
}}
],
emqx_bridge_v2:get_channels_for_connector(ConnectorId)
),
ok = emqx_bridge_v2:remove(bridge_type(), my_enable_bridge),
ok = emqx_bridge_v2:remove(bridge_type(), my_disable_bridge),
ok.
t_list(_) ->
[] = emqx_bridge_v2:list(),
{ok, _} = emqx_bridge_v2:create(bridge_type(), my_test_bridge, bridge_config()),

View File

@ -159,7 +159,7 @@ t_remove_fail({'init', Config}) ->
meck:new(?CONNECTOR, [non_strict]),
meck:expect(?CONNECTOR, callback_mode, 0, async_if_possible),
meck:expect(?CONNECTOR, on_start, 2, {ok, connector_state}),
meck:expect(?CONNECTOR, on_get_channels, 1, [{<<"my_channel">>, #{}}]),
meck:expect(?CONNECTOR, on_get_channels, 1, [{<<"my_channel">>, #{enable => true}}]),
meck:expect(?CONNECTOR, on_add_channel, 4, {ok, connector_state}),
meck:expect(?CONNECTOR, on_stop, 2, ok),
meck:expect(?CONNECTOR, on_get_status, 2, connected),

View File

@ -622,13 +622,16 @@ start_resource(Data, From) ->
add_channels(Data) ->
%% Add channels to the Channels map but not to the resource state
%% Channels will be added to the resouce state after the initial health_check
%% Channels will be added to the resource state after the initial health_check
%% if that succeeds.
ChannelIDConfigTuples = emqx_resource:call_get_channels(Data#data.id, Data#data.mod),
Channels = Data#data.added_channels,
NewChannels = lists:foldl(
fun({ChannelID, _Conf}, Acc) ->
maps:put(ChannelID, channel_status(), Acc)
fun
({ChannelID, #{enable := true}}, Acc) ->
maps:put(ChannelID, channel_status(), Acc);
({_, #{enable := false}}, Acc) ->
Acc
end,
Channels,
ChannelIDConfigTuples