chore: mv emqx_connector to emqx_data_bridge

This commit is contained in:
Turtle 2021-06-17 15:11:26 +08:00 committed by turtleDeng
parent 56c6cf560a
commit d640e2ccfa
23 changed files with 13 additions and 199 deletions

View File

@ -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
*~

View File

@ -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]]}
```

View File

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

View File

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

View File

@ -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]}
]}.

View File

@ -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, []}
]}.

View File

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

View File

@ -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

View File

@ -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

View File

@ -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]}
% ]

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,7 +5,4 @@
{emqx_retainer, {{enable_plugin_emqx_retainer}}}. {emqx_retainer, {{enable_plugin_emqx_retainer}}}.
{emqx_telemetry, {{enable_plugin_emqx_telemetry}}}. {emqx_telemetry, {{enable_plugin_emqx_telemetry}}}.
{emqx_rule_engine, {{enable_plugin_emqx_rule_engine}}}. {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}}}. {emqx_bridge_mqtt, {{enable_plugin_emqx_bridge_mqtt}}}.

View File

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