Kaynağa Gözat

refactor(influxdb connector): to use emqx_connector_info

This commit refactors the influxdb connector to use the
`emqx_connector_info` behavior.
Kjell Winblad 1 yıl önce
ebeveyn
işleme
159ab81904

+ 5 - 2
apps/emqx_bridge_influxdb/src/emqx_bridge_influxdb.app.src

@@ -1,6 +1,6 @@
 {application, emqx_bridge_influxdb, [
     {description, "EMQX Enterprise InfluxDB Bridge"},
-    {vsn, "0.2.0"},
+    {vsn, "0.2.1"},
     {registered, []},
     {applications, [
         kernel,
@@ -8,7 +8,10 @@
         emqx_resource,
         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, []},
     {links, []}
 ]}.

+ 42 - 0
apps/emqx_bridge_influxdb/src/emqx_bridge_influxdb_connector_info.erl

@@ -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"
+    ).

+ 2 - 1
apps/emqx_connector/src/emqx_connector_info.erl

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

+ 0 - 12
apps/emqx_connector/src/schema/emqx_connector_ee_schema.erl

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

+ 0 - 2
apps/emqx_connector/src/schema/emqx_connector_schema.erl

@@ -127,8 +127,6 @@ connector_info_schema_modules() ->
 
 %% @doc Return old bridge(v1) and/or connector(v2) type
 %% 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) ->
     [cassandra];
 connector_type_to_bridge_types(clickhouse) ->