fix(bridge_v2_api): take status and error from bridge, not the connector
Fixes https://emqx.atlassian.net/browse/EMQX-11284 Fixes https://emqx.atlassian.net/browse/EMQX-11298
This commit is contained in:
parent
26094ac611
commit
f5456135aa
|
@ -709,8 +709,10 @@ format_resource(
|
||||||
#{
|
#{
|
||||||
type := Type,
|
type := Type,
|
||||||
name := Name,
|
name := Name,
|
||||||
|
status := Status,
|
||||||
|
error := Error,
|
||||||
raw_config := RawConf,
|
raw_config := RawConf,
|
||||||
resource_data := ResourceData
|
resource_data := _ResourceData
|
||||||
},
|
},
|
||||||
Node
|
Node
|
||||||
) ->
|
) ->
|
||||||
|
@ -719,14 +721,16 @@ format_resource(
|
||||||
RawConf#{
|
RawConf#{
|
||||||
type => Type,
|
type => Type,
|
||||||
name => maps:get(<<"name">>, RawConf, Name),
|
name => maps:get(<<"name">>, RawConf, Name),
|
||||||
node => Node
|
node => Node,
|
||||||
|
status => Status,
|
||||||
|
error => Error
|
||||||
},
|
},
|
||||||
format_resource_data(ResourceData)
|
format_bridge_status_and_error(#{status => Status, error => Error})
|
||||||
)
|
)
|
||||||
).
|
).
|
||||||
|
|
||||||
format_resource_data(ResData) ->
|
format_bridge_status_and_error(Data) ->
|
||||||
maps:fold(fun format_resource_data/3, #{}, maps:with([status, error], ResData)).
|
maps:fold(fun format_resource_data/3, #{}, maps:with([status, error], Data)).
|
||||||
|
|
||||||
format_resource_data(error, undefined, Result) ->
|
format_resource_data(error, undefined, Result) ->
|
||||||
Result;
|
Result;
|
||||||
|
|
|
@ -145,6 +145,39 @@ create_bridge(Config, Overrides) ->
|
||||||
ct:pal("creating bridge with config: ~p", [BridgeConfig]),
|
ct:pal("creating bridge with config: ~p", [BridgeConfig]),
|
||||||
emqx_bridge_v2:create(BridgeType, BridgeName, BridgeConfig).
|
emqx_bridge_v2:create(BridgeType, BridgeName, BridgeConfig).
|
||||||
|
|
||||||
|
list_bridges_api() ->
|
||||||
|
Params = [],
|
||||||
|
Path = emqx_mgmt_api_test_util:api_path(["actions"]),
|
||||||
|
AuthHeader = emqx_mgmt_api_test_util:auth_header_(),
|
||||||
|
Opts = #{return_all => true},
|
||||||
|
ct:pal("listing bridges (via http)"),
|
||||||
|
Res =
|
||||||
|
case emqx_mgmt_api_test_util:request_api(get, Path, "", AuthHeader, Params, Opts) of
|
||||||
|
{ok, {Status, Headers, Body0}} ->
|
||||||
|
{ok, {Status, Headers, emqx_utils_json:decode(Body0, [return_maps])}};
|
||||||
|
Error ->
|
||||||
|
Error
|
||||||
|
end,
|
||||||
|
ct:pal("list bridges result: ~p", [Res]),
|
||||||
|
Res.
|
||||||
|
|
||||||
|
get_bridge_api(BridgeType, BridgeName) ->
|
||||||
|
BridgeId = emqx_bridge_resource:bridge_id(BridgeType, BridgeName),
|
||||||
|
Params = [],
|
||||||
|
Path = emqx_mgmt_api_test_util:api_path(["actions", BridgeId]),
|
||||||
|
AuthHeader = emqx_mgmt_api_test_util:auth_header_(),
|
||||||
|
Opts = #{return_all => true},
|
||||||
|
ct:pal("get bridge ~p (via http)", [{BridgeType, BridgeName}]),
|
||||||
|
Res =
|
||||||
|
case emqx_mgmt_api_test_util:request_api(get, Path, "", AuthHeader, Params, Opts) of
|
||||||
|
{ok, {Status, Headers, Body0}} ->
|
||||||
|
{ok, {Status, Headers, emqx_utils_json:decode(Body0, [return_maps])}};
|
||||||
|
Error ->
|
||||||
|
Error
|
||||||
|
end,
|
||||||
|
ct:pal("get bridge ~p result: ~p", [{BridgeType, BridgeName}, Res]),
|
||||||
|
Res.
|
||||||
|
|
||||||
create_bridge_api(Config) ->
|
create_bridge_api(Config) ->
|
||||||
create_bridge_api(Config, _Overrides = #{}).
|
create_bridge_api(Config, _Overrides = #{}).
|
||||||
|
|
||||||
|
|
|
@ -29,25 +29,27 @@ all() ->
|
||||||
emqx_common_test_helpers:all(?MODULE).
|
emqx_common_test_helpers:all(?MODULE).
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
_ = application:load(emqx_conf),
|
Apps = emqx_cth_suite:start(
|
||||||
ok = emqx_common_test_helpers:start_apps(apps_to_start_and_stop()),
|
[
|
||||||
application:ensure_all_started(telemetry),
|
emqx,
|
||||||
application:ensure_all_started(wolff),
|
emqx_conf,
|
||||||
application:ensure_all_started(brod),
|
emqx_connector,
|
||||||
|
emqx_bridge_kafka,
|
||||||
|
emqx_bridge,
|
||||||
|
emqx_rule_engine,
|
||||||
|
emqx_management,
|
||||||
|
{emqx_dashboard, "dashboard.listeners.http { enable = true, bind = 18083 }"}
|
||||||
|
],
|
||||||
|
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||||
|
),
|
||||||
|
{ok, _} = emqx_common_test_http:create_default_app(),
|
||||||
emqx_bridge_kafka_impl_producer_SUITE:wait_until_kafka_is_up(),
|
emqx_bridge_kafka_impl_producer_SUITE:wait_until_kafka_is_up(),
|
||||||
Config.
|
[{apps, Apps} | Config].
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(Config) ->
|
||||||
emqx_common_test_helpers:stop_apps(apps_to_start_and_stop()).
|
Apps = ?config(apps, Config),
|
||||||
|
emqx_cth_suite:stop(Apps),
|
||||||
apps_to_start_and_stop() ->
|
ok.
|
||||||
[
|
|
||||||
emqx,
|
|
||||||
emqx_conf,
|
|
||||||
emqx_connector,
|
|
||||||
emqx_bridge,
|
|
||||||
emqx_rule_engine
|
|
||||||
].
|
|
||||||
|
|
||||||
t_create_remove_list(_) ->
|
t_create_remove_list(_) ->
|
||||||
[] = emqx_bridge_v2:list(),
|
[] = emqx_bridge_v2:list(),
|
||||||
|
@ -165,6 +167,24 @@ t_unknown_topic(_Config) ->
|
||||||
ok
|
ok
|
||||||
end
|
end
|
||||||
),
|
),
|
||||||
|
?assertMatch(
|
||||||
|
{ok,
|
||||||
|
{{_, 200, _}, _, [
|
||||||
|
#{
|
||||||
|
<<"status">> := <<"disconnected">>,
|
||||||
|
<<"node_status">> := [#{<<"status">> := <<"disconnected">>}]
|
||||||
|
}
|
||||||
|
]}},
|
||||||
|
emqx_bridge_v2_testlib:list_bridges_api()
|
||||||
|
),
|
||||||
|
?assertMatch(
|
||||||
|
{ok,
|
||||||
|
{{_, 200, _}, _, #{
|
||||||
|
<<"status">> := <<"disconnected">>,
|
||||||
|
<<"node_status">> := [#{<<"status">> := <<"disconnected">>}]
|
||||||
|
}}},
|
||||||
|
emqx_bridge_v2_testlib:get_bridge_api(?TYPE, BridgeName)
|
||||||
|
),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
check_send_message_with_bridge(BridgeName) ->
|
check_send_message_with_bridge(BridgeName) ->
|
||||||
|
|
Loading…
Reference in New Issue