refactor(emqx_connector_info): remove code that is no longer needed

This commit is contained in:
Kjell Winblad 2024-03-21 11:58:54 +01:00
parent a3b75eb39d
commit 89befa580e
6 changed files with 23 additions and 148 deletions

View File

@ -248,16 +248,8 @@ end_per_testcase(_TestCase, Config) ->
-define(CONNECTOR_IMPL, emqx_bridge_v2_dummy_connector).
init_mocks() ->
case emqx_release:edition() of
ee ->
meck:new(emqx_connector_ee_schema, [passthrough, no_link]),
meck:expect(emqx_connector_ee_schema, resource_type, 1, ?CONNECTOR_IMPL),
ok;
ce ->
meck:new(emqx_connector_resource, [passthrough, no_link]),
meck:expect(emqx_connector_resource, connector_to_resource_type, 1, ?CONNECTOR_IMPL),
ok
end,
meck:new(emqx_connector_resource, [passthrough, no_link]),
meck:expect(emqx_connector_resource, connector_to_resource_type, 1, ?CONNECTOR_IMPL),
meck:new(?CONNECTOR_IMPL, [non_strict, no_link]),
meck:expect(?CONNECTOR_IMPL, callback_mode, 0, async_if_possible),
meck:expect(

View File

@ -57,38 +57,7 @@ when
ParsedConfig :: #{atom() => any()}, Context :: #{atom() => any()}.
-optional_callbacks([connector_config/2]).
-if(?EMQX_RELEASE_EDITION == ee).
connector_to_resource_type(ConnectorType) ->
try
emqx_connector_ee_schema:resource_type(ConnectorType)
catch
error:{unknown_connector_type, _} ->
%% maybe it's a CE connector
connector_to_resource_type_ce(ConnectorType)
end.
connector_impl_module(ConnectorType) when is_binary(ConnectorType) ->
connector_impl_module(binary_to_atom(ConnectorType, utf8));
connector_impl_module(ConnectorType) ->
case emqx_connector_ee_schema:connector_impl_module(ConnectorType) of
undefined ->
emqx_connector_info:config_transform_module(ConnectorType);
Module ->
Module
end.
-else.
connector_to_resource_type(ConnectorType) ->
connector_to_resource_type_ce(ConnectorType).
connector_impl_module(ConnectorType) when is_binary(ConnectorType) ->
connector_impl_module(binary_to_atom(ConnectorType, utf8));
connector_impl_module(ConnectorType) ->
emqx_connector_info:config_transform_module(ConnectorType).
-endif.
connector_to_resource_type_ce(ConnectorType) ->
try
emqx_connector_info:resource_callback_module(ConnectorType)
catch
@ -96,6 +65,11 @@ connector_to_resource_type_ce(ConnectorType) ->
error({unknown_connector_type, ConnectorType})
end.
connector_impl_module(ConnectorType) when is_binary(ConnectorType) ->
connector_impl_module(binary_to_atom(ConnectorType, utf8));
connector_impl_module(ConnectorType) ->
emqx_connector_info:config_transform_module(ConnectorType).
resource_id(ConnectorId) when is_binary(ConnectorId) ->
<<"connector:", ConnectorId/binary>>.

View File

@ -1,49 +0,0 @@
%%--------------------------------------------------------------------
%% Copyright (c) 2022-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
%%--------------------------------------------------------------------
-module(emqx_connector_ee_schema).
-if(?EMQX_RELEASE_EDITION == ee).
-export([
resource_type/1,
connector_impl_module/1
]).
-import(hoconsc, [mk/2, enum/1, ref/2]).
-export([
api_schemas/1,
fields/1,
schema_modules/0,
namespace/0
]).
resource_type(Type) when is_binary(Type) ->
resource_type(binary_to_atom(Type, utf8));
resource_type(Type) ->
error({unknown_connector_type, Type}).
%% For connectors that need to override connector configurations.
connector_impl_module(ConnectorType) when is_binary(ConnectorType) ->
connector_impl_module(binary_to_atom(ConnectorType, utf8));
connector_impl_module(_ConnectorType) ->
undefined.
namespace() -> undefined.
fields(connectors) ->
connector_structs().
connector_structs() ->
[].
schema_modules() ->
[].
api_schemas(_Method) ->
[].
-else.
-endif.

View File

@ -58,38 +58,6 @@
-export([examples/1]).
-if(?EMQX_RELEASE_EDITION == ee).
enterprise_api_schemas(Method) ->
%% We *must* do this to ensure the module is really loaded, especially when we use
%% `call_hocon' from `nodetool' to generate initial configurations.
_ = emqx_connector_ee_schema:module_info(),
case erlang:function_exported(emqx_connector_ee_schema, api_schemas, 1) of
true -> emqx_connector_ee_schema:api_schemas(Method);
false -> []
end.
enterprise_fields_connectors() ->
%% We *must* do this to ensure the module is really loaded, especially when we use
%% `call_hocon' from `nodetool' to generate initial configurations.
_ = emqx_connector_ee_schema:module_info(),
case erlang:function_exported(emqx_connector_ee_schema, fields, 1) of
true ->
emqx_connector_ee_schema:fields(connectors);
false ->
[]
end.
-else.
enterprise_api_schemas(_Method) -> [].
enterprise_fields_connectors() -> [].
-endif.
api_schemas(_Method) ->
[].
api_ref(Module, Type, Method) ->
{Type, ref(Module, Method)}.
@ -105,15 +73,7 @@ examples(Method) ->
end,
lists:foldl(Fun, #{}, schema_modules()).
-if(?EMQX_RELEASE_EDITION == ee).
schema_modules() ->
emqx_connector_ee_schema:schema_modules() ++ connector_info_schema_modules().
-else.
schema_modules() ->
connector_info_schema_modules().
-endif.
connector_info_schema_modules() ->
ConnectorTypes = emqx_connector_info:connector_types(),
[
emqx_connector_info:schema_module(Type)
@ -417,10 +377,8 @@ post_request() ->
api_schema("post").
api_schema(Method) ->
CE = api_schemas(Method),
EE = enterprise_api_schemas(Method),
InfoModSchemas = emqx_connector_info_api_schemas(Method),
hoconsc:union(connector_api_union(CE ++ EE ++ InfoModSchemas)).
hoconsc:union(connector_api_union(InfoModSchemas)).
emqx_connector_info_api_schemas(Method) ->
ConnectorTypes = emqx_connector_info:connector_types(),
@ -472,7 +430,7 @@ roots() ->
end.
fields(connectors) ->
[] ++ enterprise_fields_connectors() ++ connector_info_fields_connectors();
connector_info_fields_connectors();
fields("node_status") ->
[
node_name(),

View File

@ -44,14 +44,14 @@ end_per_testcase(TestCase, Config) ->
%% the 2 test cases below are based on kafka connector which is ee only
-if(?EMQX_RELEASE_EDITION == ee).
t_connector_lifecycle({init, Config}) ->
meck:new(emqx_connector_ee_schema, [passthrough]),
meck:expect(emqx_connector_ee_schema, resource_type, 1, ?CONNECTOR),
meck:new(emqx_connector_resource, [passthrough]),
meck:expect(emqx_connector_resource, connector_to_resource_type, 1, ?CONNECTOR),
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_stop, 2, ok),
meck:expect(?CONNECTOR, on_get_status, 2, connected),
[{mocked_mods, [?CONNECTOR, emqx_connector_ee_schema]} | Config];
[{mocked_mods, [?CONNECTOR, emqx_connector_resource]} | Config];
t_connector_lifecycle({'end', Config}) ->
MockedMods = ?config(mocked_mods, Config),
meck:unload(MockedMods),
@ -164,8 +164,8 @@ t_connector_lifecycle(_Config) ->
ok.
t_remove_fail({'init', Config}) ->
meck:new(emqx_connector_ee_schema, [passthrough]),
meck:expect(emqx_connector_ee_schema, resource_type, 1, ?CONNECTOR),
meck:new(emqx_connector_resource, [passthrough]),
meck:expect(emqx_connector_resource, connector_to_resource_type, 1, ?CONNECTOR),
meck:new(?CONNECTOR, [non_strict]),
meck:expect(?CONNECTOR, callback_mode, 0, async_if_possible),
meck:expect(?CONNECTOR, on_start, 2, {ok, connector_state}),
@ -228,8 +228,8 @@ t_remove_fail(_Config) ->
ok.
t_create_with_bad_name_direct_path({init, Config}) ->
meck:new(emqx_connector_ee_schema, [passthrough]),
meck:expect(emqx_connector_ee_schema, resource_type, 1, ?CONNECTOR),
meck:new(emqx_connector_resource, [passthrough]),
meck:expect(emqx_connector_resource, connector_to_resource_type, 1, ?CONNECTOR),
meck:new(?CONNECTOR, [non_strict]),
meck:expect(?CONNECTOR, callback_mode, 0, async_if_possible),
meck:expect(?CONNECTOR, on_start, 2, {ok, connector_state}),
@ -259,8 +259,8 @@ t_create_with_bad_name_direct_path(_Config) ->
ok.
t_create_with_bad_name_root_path({init, Config}) ->
meck:new(emqx_connector_ee_schema, [passthrough]),
meck:expect(emqx_connector_ee_schema, resource_type, 1, ?CONNECTOR),
meck:new(emqx_connector_resource, [passthrough]),
meck:expect(emqx_connector_resource, connector_to_resource_type, 1, ?CONNECTOR),
meck:new(?CONNECTOR, [non_strict]),
meck:expect(?CONNECTOR, callback_mode, 0, async_if_possible),
meck:expect(?CONNECTOR, on_start, 2, {ok, connector_state}),
@ -293,8 +293,8 @@ t_create_with_bad_name_root_path(_Config) ->
ok.
t_no_buffer_workers({'init', Config}) ->
meck:new(emqx_connector_ee_schema, [passthrough]),
meck:expect(emqx_connector_ee_schema, resource_type, 1, ?CONNECTOR),
meck:new(emqx_connector_resource, [passthrough]),
meck:expect(emqx_connector_resource, connector_to_resource_type, 1, ?CONNECTOR),
meck:new(?CONNECTOR, [non_strict]),
meck:expect(?CONNECTOR, callback_mode, 0, async_if_possible),
meck:expect(?CONNECTOR, on_start, 2, {ok, connector_state}),

View File

@ -221,8 +221,8 @@ end_per_testcase(TestCase, Config) ->
-define(CONNECTOR_IMPL, dummy_connector_impl).
init_mocks(_TestCase) ->
meck:new(emqx_connector_ee_schema, [passthrough, no_link]),
meck:expect(emqx_connector_ee_schema, resource_type, 1, ?CONNECTOR_IMPL),
meck:new(emqx_connector_resource, [passthrough, no_link]),
meck:expect(emqx_connector_resource, connector_to_resource_type, 1, ?CONNECTOR_IMPL),
meck:new(?CONNECTOR_IMPL, [non_strict, no_link]),
meck:expect(?CONNECTOR_IMPL, callback_mode, 0, async_if_possible),
meck:expect(
@ -265,7 +265,7 @@ init_mocks(_TestCase) ->
emqx_bridge_v2:get_channels_for_connector(ResId)
end
),
[?CONNECTOR_IMPL, emqx_connector_ee_schema].
[?CONNECTOR_IMPL, emqx_connector_resource].
clear_resources(_) ->
lists:foreach(