Просмотр исходного кода

chore: mv emqx_connector to emqx_data_bridge

Turtle 4 лет назад
Родитель
Сommit
d640e2ccfa

+ 0 - 19
apps/emqx_connector/.gitignore

@@ -1,19 +0,0 @@
-.rebar3
-_*
-.eunit
-*.o
-*.beam
-*.plt
-*.swp
-*.swo
-.erlang.cookie
-ebin
-log
-erl_crash.dump
-.rebar
-logs
-_build
-.idea
-*.iml
-rebar3.crashdump
-*~

+ 0 - 27
apps/emqx_connector/README.md

@@ -1,27 +0,0 @@
-# emqx_connector
-
-This application is a collection of `connectors`.
-
-A `connector` is a callback module of `emqx_resource` that maintains the data related to
-external resources. Put all resource related callback modules in a single application is good as
-we can put some util functions/modules here for reusing purpose.
-
-For example, a mysql connector is an emqx resource that maintains all the mysql connection
-related parameters (configs) and the TCP connections to the mysql server.
-
-An mysql connector can be used as following:
-
-```
-(emqx@127.0.0.1)5> emqx_resource:list_instances_verbose().
-[#{config =>
-       #{auto_reconnect => true,cacertfile => [],certfile => [],
-         database => "mqtt",keyfile => [],password => "public",
-         pool_size => 1,
-         server => {{127,0,0,1},3306},
-         ssl => false,user => "root",verify => false},
-   id => <<"mysql-abc">>,mod => emqx_connector_mysql,
-   state => #{poolname => 'mysql-abc'},
-   status => started}]
-(emqx@127.0.0.1)6> emqx_resource:query(<<"mysql-abc">>, {sql, <<"SELECT count(1)">>}).
-{ok,[<<"count(1)">>],[[1]]}
-```

+ 0 - 4
apps/emqx_connector/etc/emqx_connector.conf

@@ -1,4 +0,0 @@
-##--------------------------------------------------------------------
-## EMQ X CONNECTOR Plugin
-##--------------------------------------------------------------------
-

+ 0 - 2
apps/emqx_connector/priv/emqx_connector.schema

@@ -1,2 +0,0 @@
-%%-*- mode: erlang -*-
-%% emqx_connector config mapping

+ 0 - 13
apps/emqx_connector/rebar.config

@@ -1,13 +0,0 @@
-{erl_opts, [
-  nowarn_unused_import,
-  debug_info
-]}.
-
-{deps, [
-  {mysql, {git, "https://github.com/emqx/mysql-otp", {tag, "1.7.1"}}}
-]}.
-
-{shell, [
-  % {config, "config/sys.config"},
-    {apps, [emqx_connector]}
-]}.

+ 0 - 17
apps/emqx_connector/src/emqx_connector.app.src

@@ -1,17 +0,0 @@
-{application, emqx_connector,
- [{description, "An OTP application"},
-  {vsn, "0.1.0"},
-  {registered, []},
-  {mod, {emqx_connector_app, []}},
-  {applications,
-   [kernel,
-    stdlib,
-    emqx_resource,
-    ecpool
-   ]},
-  {env,[]},
-  {modules, []},
-
-  {licenses, ["Apache 2.0"]},
-  {links, []}
- ]}.

+ 0 - 16
apps/emqx_connector/src/emqx_connector.erl

@@ -1,16 +0,0 @@
-%%--------------------------------------------------------------------
-%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved.
-%%
-%% Licensed under the Apache License, Version 2.0 (the "License");
-%% you may not use this file except in compliance with the License.
-%% You may obtain a copy of the License at
-%%
-%%     http://www.apache.org/licenses/LICENSE-2.0
-%%
-%% Unless required by applicable law or agreed to in writing, software
-%% distributed under the License is distributed on an "AS IS" BASIS,
-%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-%% See the License for the specific language governing permissions and
-%% limitations under the License.
-%%--------------------------------------------------------------------
--module(emqx_connector).

+ 0 - 31
apps/emqx_connector/src/emqx_connector_app.erl

@@ -1,31 +0,0 @@
-%%--------------------------------------------------------------------
-%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved.
-%%
-%% Licensed under the Apache License, Version 2.0 (the "License");
-%% you may not use this file except in compliance with the License.
-%% You may obtain a copy of the License at
-%%
-%%     http://www.apache.org/licenses/LICENSE-2.0
-%%
-%% Unless required by applicable law or agreed to in writing, software
-%% distributed under the License is distributed on an "AS IS" BASIS,
-%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-%% See the License for the specific language governing permissions and
-%% limitations under the License.
-%%--------------------------------------------------------------------
-
--module(emqx_connector_app).
-
--behaviour(application).
-
--emqx_plugin(?MODULE).
-
--export([start/2, stop/1]).
-
-start(_StartType, _StartArgs) ->
-    emqx_connector_sup:start_link().
-
-stop(_State) ->
-    ok.
-
-%% internal functions

+ 0 - 36
apps/emqx_connector/src/emqx_connector_sup.erl

@@ -1,36 +0,0 @@
-%%--------------------------------------------------------------------
-%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved.
-%%
-%% Licensed under the Apache License, Version 2.0 (the "License");
-%% you may not use this file except in compliance with the License.
-%% You may obtain a copy of the License at
-%%
-%%     http://www.apache.org/licenses/LICENSE-2.0
-%%
-%% Unless required by applicable law or agreed to in writing, software
-%% distributed under the License is distributed on an "AS IS" BASIS,
-%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-%% See the License for the specific language governing permissions and
-%% limitations under the License.
-%%--------------------------------------------------------------------
--module(emqx_connector_sup).
-
--behaviour(supervisor).
-
--export([start_link/0]).
-
--export([init/1]).
-
--define(SERVER, ?MODULE).
-
-start_link() ->
-    supervisor:start_link({local, ?SERVER}, ?MODULE, []).
-
-init([]) ->
-    SupFlags = #{strategy => one_for_all,
-                 intensity => 0,
-                 period => 1},
-    ChildSpecs = [],
-    {ok, {SupFlags, ChildSpecs}}.
-
-%% internal functions

apps/emqx_connector/include/emqx_connector.hrl → apps/emqx_data_bridge/include/emqx_data_bridge.hrl


+ 0 - 16
apps/emqx_data_bridge/priv/emqx_data_bridge.schema

@@ -1,16 +0,0 @@
-%%-*- mode: erlang -*-
-%% emqx_data_bridge config mapping
-
-{mapping, "emqx_data_bridge.bridges", "emqx_data_bridge.bridges", [
-  {default, []},
-  {datatype, string}
-]}.
-
-% fields("emqx_data_bridge") ->
-%     [
-%         {bridges,
-%           [fun(mapping) -> "emqx_data_bridge.bridges";
-%               (type) -> list();
-%               (_) -> undefined
-%            end]}
-%     ]

+ 1 - 0
apps/emqx_data_bridge/rebar.config

@@ -1,5 +1,6 @@
 {erl_opts, [debug_info]}.
 {deps, []}.
+% {extra_src_dirs, [{"src", [{recursive, true}]}]}.
 
 {shell, [
   % {config, "config/sys.config"},

+ 1 - 1
apps/emqx_connector/src/emqx_connector_ldap.erl

@@ -15,7 +15,7 @@
 %%--------------------------------------------------------------------
 -module(emqx_connector_ldap).
 
--include("emqx_connector.hrl").
+-include("emqx_data_bridge.hrl").
 -include_lib("typerefl/include/types.hrl").
 -include_lib("emqx_resource/include/emqx_resource_behaviour.hrl").
 

+ 1 - 1
apps/emqx_connector/src/emqx_connector_mongo.erl

@@ -15,7 +15,7 @@
 %%--------------------------------------------------------------------
 -module(emqx_connector_mongo).
 
--include("emqx_connector.hrl").
+-include("emqx_data_bridge.hrl").
 -include_lib("typerefl/include/types.hrl").
 -include_lib("emqx_resource/include/emqx_resource_behaviour.hrl").
 

apps/emqx_connector/src/emqx_connector_mysql.erl → apps/emqx_data_bridge/src/connector/emqx_connector_mysql.erl


apps/emqx_connector/src/emqx_connector_pgsql.erl → apps/emqx_data_bridge/src/connector/emqx_connector_pgsql.erl


+ 1 - 1
apps/emqx_connector/src/emqx_connector_redis.erl

@@ -15,7 +15,7 @@
 %%--------------------------------------------------------------------
 -module(emqx_connector_redis).
 
--include("emqx_connector.hrl").
+-include("emqx_data_bridge.hrl").
 -include_lib("typerefl/include/types.hrl").
 -include_lib("emqx_resource/include/emqx_resource_behaviour.hrl").
 

+ 1 - 1
apps/emqx_connector/src/emqx_connector_schema_lib.erl

@@ -15,7 +15,7 @@
 %%--------------------------------------------------------------------
 -module(emqx_connector_schema_lib).
 
--include("emqx_connector.hrl").
+-include("emqx_data_bridge.hrl").
 -include_lib("typerefl/include/types.hrl").
 
 -export([ relational_db_fields/0

+ 2 - 1
apps/emqx_data_bridge/src/emqx_data_bridge.app.src

@@ -5,7 +5,8 @@
   {mod, {emqx_data_bridge_app, []}},
   {applications,
    [kernel,
-    stdlib
+    stdlib,
+    ecpool
    ]},
   {env,[]},
   {modules, []},

+ 3 - 2
apps/emqx_data_bridge/src/emqx_data_bridge.erl

@@ -25,8 +25,9 @@
         ]).
 
 load_bridges() ->
-    Bridges = proplists:get_value(bridges,
-        application:get_all_env(emqx_data_bridge), []),
+    ConfFile = filename:join([emqx:get_env(plugins_etc_dir), ?MODULE]) ++ ".conf",
+    {ok, #{<<"emqx_data_bridge">> := RawConfig}} = hocon:load(ConfFile),
+    Bridges = maps:get(<<"bridges">>, RawConfig, []),
     emqx_data_bridge_monitor:ensure_all_started(Bridges).
 
 resource_type(<<"mysql">>) -> emqx_connector_mysql;

+ 0 - 2
apps/emqx_resource/priv/emqx_resource.schema

@@ -1,2 +0,0 @@
-%%-*- mode: erlang -*-
-%% emqx-resource config mapping

+ 0 - 3
data/loaded_plugins.tmpl

@@ -5,7 +5,4 @@
 {emqx_retainer, {{enable_plugin_emqx_retainer}}}.
 {emqx_telemetry, {{enable_plugin_emqx_telemetry}}}.
 {emqx_rule_engine, {{enable_plugin_emqx_rule_engine}}}.
-{emqx_resource, {{enable_plugin_emqx_resource}}}.
-{emqx_connector, {{enable_plugin_emqx_connector}}}.
-{emqx_data_bridge, {{enable_plugin_emqx_data_bridge}}}.
 {emqx_bridge_mqtt, {{enable_plugin_emqx_bridge_mqtt}}}.

+ 3 - 6
rebar.config.erl

@@ -186,9 +186,6 @@ overlay_vars_rel(RelType) ->
              end,
     [ {enable_plugin_emqx_rule_engine, RelType =:= cloud}
     , {enable_plugin_emqx_bridge_mqtt, RelType =:= edge}
-    , {enable_plugin_emqx_resource, true}
-    , {enable_plugin_emqx_connector, true}
-    , {enable_plugin_emqx_data_bridge, true}
     , {enable_plugin_emqx_modules, false} %% modules is not a plugin in ce
     , {enable_plugin_emqx_recon, true}
     , {enable_plugin_emqx_retainer, true}
@@ -247,6 +244,8 @@ relx_apps(ReleaseType) ->
     , {emqx_plugin_libs, load}
     , observer_cli
     , emqx_http_lib
+    , emqx_resource
+    , emqx_data_bridge
     ]
     ++ [emqx_modules || not is_enterprise()]
     ++ [emqx_license || is_enterprise()]
@@ -284,10 +283,8 @@ relx_plugin_apps(ReleaseType) ->
     , emqx_auth_mnesia
     , emqx_web_hook
     , emqx_recon
-    , emqx_resource
-    , emqx_connector
-    , emqx_data_bridge
     , emqx_rule_engine
+    , emqx_data_bridge
     , emqx_sasl
     ]
     ++ [emqx_telemetry || not is_enterprise()]