fix(connector): update the connector config failed

This commit is contained in:
Shawn 2021-12-18 20:19:34 +08:00
parent a44e18e869
commit cfaad15364
2 changed files with 15 additions and 7 deletions

View File

@ -129,12 +129,11 @@ on_start(InstId, Conf) ->
},
case ?MODULE:create_bridge(BridgeConf) of
{ok, _Pid} ->
case emqx_connector_mqtt_worker:ensure_started(InstanceId) of
ok -> {ok, #{name => InstanceId}};
{error, Reason} -> {error, Reason}
end;
ensure_mqtt_worker_started(InstanceId);
{error, {already_started, _Pid}} ->
{ok, #{name => InstanceId}};
ok = ?MODULE:drop_bridge(InstanceId),
{ok, _} = ?MODULE:create_bridge(BridgeConf),
ensure_mqtt_worker_started(InstanceId);
{error, Reason} ->
{error, Reason}
end.
@ -162,6 +161,12 @@ on_health_check(_InstId, #{name := InstanceId} = State) ->
_ -> {error, {connector_down, InstanceId}, State}
end.
ensure_mqtt_worker_started(InstanceId) ->
case emqx_connector_mqtt_worker:ensure_started(InstanceId) of
ok -> {ok, #{name => InstanceId}};
{error, Reason} -> {error, Reason}
end.
make_sub_confs(EmptyMap) when map_size(EmptyMap) == 0 ->
undefined;
make_sub_confs(undefined) ->

View File

@ -422,9 +422,12 @@ t_mqtt_conn_update2(_) ->
, <<"connector">> := ?CONNECTR_ID
}, jsx:decode(Bridge)),
%% we fix the 'server' parameter to a normal one, it should work
{ok, 200, Bridge2} = request(put, uri(["connectors", ?CONNECTR_ID]),
{ok, 200, _} = request(put, uri(["connectors", ?CONNECTR_ID]),
?MQTT_CONNECOTR2(<<"127.0.0.1:1883">>)),
?assertMatch(#{<<"status">> := <<"connected">>}, jsx:decode(Bridge2)),
{ok, 200, BridgeStr} = request(get, uri(["bridges", ?BRIDGE_ID_EGRESS]), []),
?assertMatch(#{ <<"id">> := ?BRIDGE_ID_EGRESS
, <<"status">> := <<"connected">>
}, jsx:decode(BridgeStr)),
%% delete the bridge
{ok, 204, <<>>} = request(delete, uri(["bridges", ?BRIDGE_ID_EGRESS]), []),
{ok, 200, <<"[]">>} = request(get, uri(["bridges"]), []),