refactor: always recreate resources no matter it is connected or not

This commit is contained in:
Shawn 2022-04-20 10:58:58 +08:00
parent 278e9145b0
commit 3ce969fd79
3 changed files with 8 additions and 13 deletions

View File

@ -207,6 +207,7 @@ basic_config(#{
replayq => ReplayQ,
%% connection opts
server => Server,
connect_timeout => 30, %% 30s
reconnect_interval => ReconnIntv,
proto_ver => ProtoVer,
bridge_mode => true,

View File

@ -366,9 +366,10 @@ t_mqtt_conn_update(_) ->
BridgeIDEgress = emqx_bridge:bridge_id(?CONNECTR_TYPE, ?BRIDGE_NAME_EGRESS),
wait_for_resource_ready(BridgeIDEgress, 5),
%% then we try to update 'server' of the connector, to an unavailable IP address
%% the update should fail because of 'unreachable' or 'connrefused'
{ok, 500, _ErrorMsg} = request(put, uri(["connectors", ConnctorID]),
%% Then we try to update 'server' of the connector, to an unavailable IP address
%% The update OK, we recreate the resource even if the resource is current connected,
%% and the target resource we're going to update is unavailable.
{ok, 200, _} = request(put, uri(["connectors", ConnctorID]),
?MQTT_CONNECTOR2(<<"127.0.0.1:2603">>)),
%% we fix the 'server' parameter to a normal one, it should work
{ok, 200, _} = request(put, uri(["connectors", ConnctorID]),

View File

@ -166,16 +166,9 @@ code_change(_OldVsn, State, _Extra) ->
do_recreate(InstId, ResourceType, NewConfig, Opts) ->
case lookup(InstId) of
{ok, Group, #{mod := ResourceType, status := connected} = Data} ->
%% If this resource is in use (status='connected'), we should make sure
%% the new config is OK before removing the old one.
case do_create_dry_run(ResourceType, NewConfig) of
ok ->
do_remove(Group, Data, false),
do_create(InstId, Group, ResourceType, NewConfig, Opts);
Error ->
Error
end;
%% We recreate the resource no matter if it is connected and in use!
%% As we can not know if the resource is "really disconnected" or we mark the status
%% to "disconnected" because the emqx_resource_instance process is not responding.
{ok, Group, #{mod := ResourceType, status := _} = Data} ->
do_remove(Group, Data, false),
do_create(InstId, Group, ResourceType, NewConfig, Opts);