refactor(influxdb connector): to use emqx_connector_info

This commit refactors the influxdb connector to use the
`emqx_connector_info` behavior.
This commit is contained in:
Kjell Winblad 2024-03-20 10:39:16 +01:00
parent c1e6092013
commit 159ab81904
5 changed files with 49 additions and 17 deletions

View File

@ -1,6 +1,6 @@
{application, emqx_bridge_influxdb, [ {application, emqx_bridge_influxdb, [
{description, "EMQX Enterprise InfluxDB Bridge"}, {description, "EMQX Enterprise InfluxDB Bridge"},
{vsn, "0.2.0"}, {vsn, "0.2.1"},
{registered, []}, {registered, []},
{applications, [ {applications, [
kernel, kernel,
@ -8,7 +8,10 @@
emqx_resource, emqx_resource,
influxdb influxdb
]}, ]},
{env, [{emqx_action_info_modules, [emqx_bridge_influxdb_action_info]}]}, {env, [
{emqx_action_info_modules, [emqx_bridge_influxdb_action_info]},
{emqx_connector_info_modules, [emqx_bridge_influxdb_connector_info]}
]},
{modules, []}, {modules, []},
{links, []} {links, []}
]}. ]}.

View File

@ -0,0 +1,42 @@
%%--------------------------------------------------------------------
%% Copyright (c) 2024 EMQ Technologies Co., Ltd. All Rights Reserved.
%%--------------------------------------------------------------------
-module(emqx_bridge_influxdb_connector_info).
-behaviour(emqx_connector_info).
-export([
type_name/0,
bridge_types/0,
resource_callback_module/0,
config_schema/0,
schema_module/0,
api_schema/1
]).
type_name() ->
influxdb.
bridge_types() ->
[influxdb, influxdb_api_v1, influxdb_api_v2].
resource_callback_module() ->
emqx_bridge_influxdb_connector.
config_schema() ->
{influxdb,
hoconsc:mk(
hoconsc:map(name, hoconsc:ref(emqx_bridge_influxdb, "config_connector")),
#{
desc => <<"InfluxDB Connector Config">>,
required => false
}
)}.
schema_module() ->
emqx_bridge_influxdb.
api_schema(Method) ->
emqx_connector_schema:api_ref(
emqx_bridge_influxdb, <<"influxdb">>, Method ++ "_connector"
).

View File

@ -69,7 +69,8 @@ hard_coded_connector_info_modules_ee() ->
emqx_bridge_pgsql_connector_info, emqx_bridge_pgsql_connector_info,
emqx_bridge_timescale_connector_info, emqx_bridge_timescale_connector_info,
emqx_bridge_mongodb_connector_info, emqx_bridge_mongodb_connector_info,
emqx_bridge_oracle_connector_info emqx_bridge_oracle_connector_info,
emqx_bridge_influxdb_connector_info
]. ].
-else. -else.
hard_coded_connector_info_modules_ee() -> hard_coded_connector_info_modules_ee() ->

View File

@ -21,8 +21,6 @@
resource_type(Type) when is_binary(Type) -> resource_type(Type) when is_binary(Type) ->
resource_type(binary_to_atom(Type, utf8)); resource_type(binary_to_atom(Type, utf8));
resource_type(influxdb) ->
emqx_bridge_influxdb_connector;
resource_type(cassandra) -> resource_type(cassandra) ->
emqx_bridge_cassandra_connector; emqx_bridge_cassandra_connector;
resource_type(clickhouse) -> resource_type(clickhouse) ->
@ -83,14 +81,6 @@ fields(connectors) ->
connector_structs() -> connector_structs() ->
[ [
{influxdb,
mk(
hoconsc:map(name, ref(emqx_bridge_influxdb, "config_connector")),
#{
desc => <<"InfluxDB Connector Config">>,
required => false
}
)},
{cassandra, {cassandra,
mk( mk(
hoconsc:map(name, ref(emqx_bridge_cassandra, "config_connector")), hoconsc:map(name, ref(emqx_bridge_cassandra, "config_connector")),
@ -223,7 +213,6 @@ connector_structs() ->
schema_modules() -> schema_modules() ->
[ [
emqx_bridge_influxdb,
emqx_bridge_cassandra, emqx_bridge_cassandra,
emqx_bridge_clickhouse, emqx_bridge_clickhouse,
emqx_bridge_mysql, emqx_bridge_mysql,
@ -247,7 +236,6 @@ api_schemas(Method) ->
[ [
%% We need to map the `type' field of a request (binary) to a %% We need to map the `type' field of a request (binary) to a
%% connector schema module. %% connector schema module.
api_ref(emqx_bridge_influxdb, <<"influxdb">>, Method ++ "_connector"),
api_ref(emqx_bridge_cassandra, <<"cassandra">>, Method ++ "_connector"), api_ref(emqx_bridge_cassandra, <<"cassandra">>, Method ++ "_connector"),
api_ref(emqx_bridge_clickhouse, <<"clickhouse">>, Method ++ "_connector"), api_ref(emqx_bridge_clickhouse, <<"clickhouse">>, Method ++ "_connector"),
api_ref(emqx_bridge_mysql, <<"mysql">>, Method ++ "_connector"), api_ref(emqx_bridge_mysql, <<"mysql">>, Method ++ "_connector"),

View File

@ -127,8 +127,6 @@ connector_info_schema_modules() ->
%% @doc Return old bridge(v1) and/or connector(v2) type %% @doc Return old bridge(v1) and/or connector(v2) type
%% from the latest connector type name. %% from the latest connector type name.
connector_type_to_bridge_types(influxdb) ->
[influxdb, influxdb_api_v1, influxdb_api_v2];
connector_type_to_bridge_types(cassandra) -> connector_type_to_bridge_types(cassandra) ->
[cassandra]; [cassandra];
connector_type_to_bridge_types(clickhouse) -> connector_type_to_bridge_types(clickhouse) ->