From c30666ee26cdb9974d7894b567f64774fe0149e2 Mon Sep 17 00:00:00 2001 From: wwhai <751957846@qq.com> Date: Thu, 4 Feb 2021 17:01:37 +0800 Subject: [PATCH] fix(rule-engine): remove plugin_template (#4146) chore(build): remove template plugin The template plugin is intended to work as a standalone plugin development template repo. Should not be in the umbrella project. --- apps/emqx_plugin_template/.gitignore | 19 -- apps/emqx_plugin_template/README.md | 34 --- apps/emqx_plugin_template/TODO | 3 - .../etc/emqx_plugin_template.config | 5 - apps/emqx_plugin_template/rebar.config | 3 - .../src/emqx_cli_demo.erl | 26 --- .../src/emqx_plugin_template.app.src | 14 -- .../src/emqx_plugin_template.erl | 193 ------------------ .../src/emqx_plugin_template_app.erl | 34 --- .../src/emqx_plugin_template_sup.erl | 30 --- .../test/emqx_plugin_template_SUITE.erl | 24 --- rebar.config.erl | 1 - sync-apps.sh | 1 - 13 files changed, 387 deletions(-) delete mode 100644 apps/emqx_plugin_template/.gitignore delete mode 100644 apps/emqx_plugin_template/README.md delete mode 100644 apps/emqx_plugin_template/TODO delete mode 100644 apps/emqx_plugin_template/etc/emqx_plugin_template.config delete mode 100644 apps/emqx_plugin_template/rebar.config delete mode 100644 apps/emqx_plugin_template/src/emqx_cli_demo.erl delete mode 100644 apps/emqx_plugin_template/src/emqx_plugin_template.app.src delete mode 100644 apps/emqx_plugin_template/src/emqx_plugin_template.erl delete mode 100644 apps/emqx_plugin_template/src/emqx_plugin_template_app.erl delete mode 100644 apps/emqx_plugin_template/src/emqx_plugin_template_sup.erl delete mode 100644 apps/emqx_plugin_template/test/emqx_plugin_template_SUITE.erl diff --git a/apps/emqx_plugin_template/.gitignore b/apps/emqx_plugin_template/.gitignore deleted file mode 100644 index df4afc489..000000000 --- a/apps/emqx_plugin_template/.gitignore +++ /dev/null @@ -1,19 +0,0 @@ -.eunit -deps -*.o -*.beam -*.plt -erl_crash.dump -ebin -rel/example_project -.concrete/DEV_MODE -.rebar -.erlang.mk/ -data/ -emqx_plugin_template.d -.DS_Store -erlang.mk -_build/ -rebar.lock -test/ct.cover.spec -.rebar3 diff --git a/apps/emqx_plugin_template/README.md b/apps/emqx_plugin_template/README.md deleted file mode 100644 index d8915a298..000000000 --- a/apps/emqx_plugin_template/README.md +++ /dev/null @@ -1,34 +0,0 @@ -emqx-plugin-template -==================== - -This is a template plugin for the EMQ X broker. And you can see [Plugin Development Guide](https://docs.emqx.io/broker/v3/en/plugins.html#plugin-development-template) to learning how to use it. - -Plugin Config -------------- - -Each plugin should have a 'etc/{plugin_name}.conf|config' file to store application config. - -Authentication and ACL ----------------------- - -``` -emqx:hook('client.authenticate', fun ?MODULE:on_client_authenticate/3, [Env]). -emqx:hook('client.check_acl', fun ?MODULE:on_client_check_acl/5, [Env]). -``` - -Plugin and Hooks ------------------ - -[Plugin Design](https://docs.emqx.io/broker/v3/en/design.html#plugin-design) - -[Hooks Design](https://docs.emqx.io/broker/v3/en/design.html#hooks-design) - -License -------- - -Apache License Version 2.0 - -Author ------- - -EMQ X Team. diff --git a/apps/emqx_plugin_template/TODO b/apps/emqx_plugin_template/TODO deleted file mode 100644 index 631911aa3..000000000 --- a/apps/emqx_plugin_template/TODO +++ /dev/null @@ -1,3 +0,0 @@ -1. Add a script to generate plugin project -2. Upgrade the README.md -3. Add the plugin development guide diff --git a/apps/emqx_plugin_template/etc/emqx_plugin_template.config b/apps/emqx_plugin_template/etc/emqx_plugin_template.config deleted file mode 100644 index 5dad5c19a..000000000 --- a/apps/emqx_plugin_template/etc/emqx_plugin_template.config +++ /dev/null @@ -1,5 +0,0 @@ - -[ - {emqx_plugin_template, []} -]. - diff --git a/apps/emqx_plugin_template/rebar.config b/apps/emqx_plugin_template/rebar.config deleted file mode 100644 index e331faeb3..000000000 --- a/apps/emqx_plugin_template/rebar.config +++ /dev/null @@ -1,3 +0,0 @@ -{deps, []}. - -{erl_opts, [debug_info]}. diff --git a/apps/emqx_plugin_template/src/emqx_cli_demo.erl b/apps/emqx_plugin_template/src/emqx_cli_demo.erl deleted file mode 100644 index 6186f3aa7..000000000 --- a/apps/emqx_plugin_template/src/emqx_cli_demo.erl +++ /dev/null @@ -1,26 +0,0 @@ -%%-------------------------------------------------------------------- -%% Copyright (c) 2020 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_cli_demo). - --export([cmd/1]). - -cmd(["arg1", "arg2"]) -> - emqx_ctl:print("ok"); - -cmd(_) -> - emqx_ctl:usage([{"cmd arg1 arg2", "cmd demo"}]). - diff --git a/apps/emqx_plugin_template/src/emqx_plugin_template.app.src b/apps/emqx_plugin_template/src/emqx_plugin_template.app.src deleted file mode 100644 index 50a119ec5..000000000 --- a/apps/emqx_plugin_template/src/emqx_plugin_template.app.src +++ /dev/null @@ -1,14 +0,0 @@ -{application, emqx_plugin_template, - [{description, "EMQ X Plugin Template"}, - {vsn, "4.3.0"}, % strict semver, bump manually! - {modules, []}, - {registered, [emqx_plugin_template_sup]}, - {applications, [kernel,stdlib]}, - {mod, {emqx_plugin_template_app,[]}}, - {env, []}, - {licenses, ["Apache-2.0"]}, - {maintainers, ["EMQ X Team "]}, - {links, [{"Homepage", "https://emqx.io/"}, - {"Github", "https://github.com/emqx/emqx-plugin-template"} - ]} - ]}. diff --git a/apps/emqx_plugin_template/src/emqx_plugin_template.erl b/apps/emqx_plugin_template/src/emqx_plugin_template.erl deleted file mode 100644 index 4e408f527..000000000 --- a/apps/emqx_plugin_template/src/emqx_plugin_template.erl +++ /dev/null @@ -1,193 +0,0 @@ -%%-------------------------------------------------------------------- -%% Copyright (c) 2020 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_plugin_template). - --include_lib("emqx/include/emqx.hrl"). - --export([ load/1 - , unload/0 - ]). - -%% Client Lifecircle Hooks --export([ on_client_connect/3 - , on_client_connack/4 - , on_client_connected/3 - , on_client_disconnected/4 - , on_client_authenticate/3 - , on_client_check_acl/5 - , on_client_subscribe/4 - , on_client_unsubscribe/4 - ]). - -%% Session Lifecircle Hooks --export([ on_session_created/3 - , on_session_subscribed/4 - , on_session_unsubscribed/4 - , on_session_resumed/3 - , on_session_discarded/3 - , on_session_takeovered/3 - , on_session_terminated/4 - ]). - -%% Message Pubsub Hooks --export([ on_message_publish/2 - , on_message_delivered/3 - , on_message_acked/3 - , on_message_dropped/4 - ]). - -%% Called when the plugin application start -load(Env) -> - hook('client.connect', {?MODULE, on_client_connect, [Env]}), - hook('client.connack', {?MODULE, on_client_connack, [Env]}), - hook('client.connected', {?MODULE, on_client_connected, [Env]}), - hook('client.disconnected', {?MODULE, on_client_disconnected, [Env]}), - hook('client.authenticate', {?MODULE, on_client_authenticate, [Env]}), - hook('client.check_acl', {?MODULE, on_client_check_acl, [Env]}), - hook('client.subscribe', {?MODULE, on_client_subscribe, [Env]}), - hook('client.unsubscribe', {?MODULE, on_client_unsubscribe, [Env]}), - hook('session.created', {?MODULE, on_session_created, [Env]}), - hook('session.subscribed', {?MODULE, on_session_subscribed, [Env]}), - hook('session.unsubscribed',{?MODULE, on_session_unsubscribed, [Env]}), - hook('session.resumed', {?MODULE, on_session_resumed, [Env]}), - hook('session.discarded', {?MODULE, on_session_discarded, [Env]}), - hook('session.takeovered', {?MODULE, on_session_takeovered, [Env]}), - hook('session.terminated', {?MODULE, on_session_terminated, [Env]}), - hook('message.publish', {?MODULE, on_message_publish, [Env]}), - hook('message.delivered', {?MODULE, on_message_delivered, [Env]}), - hook('message.acked', {?MODULE, on_message_acked, [Env]}), - hook('message.dropped', {?MODULE, on_message_dropped, [Env]}). - -%%-------------------------------------------------------------------- -%% Client Lifecircle Hooks -%%-------------------------------------------------------------------- - -on_client_connect(ConnInfo = #{clientid := ClientId}, Props, _Env) -> - io:format("Client(~s) connect, ConnInfo: ~p, Props: ~p~n", - [ClientId, ConnInfo, Props]), - {ok, Props}. - -on_client_connack(ConnInfo = #{clientid := ClientId}, Rc, Props, _Env) -> - io:format("Client(~s) connack, ConnInfo: ~p, Rc: ~p, Props: ~p~n", - [ClientId, ConnInfo, Rc, Props]), - {ok, Props}. - -on_client_connected(ClientInfo = #{clientid := ClientId}, ConnInfo, _Env) -> - io:format("Client(~s) connected, ClientInfo:~n~p~n, ConnInfo:~n~p~n", - [ClientId, ClientInfo, ConnInfo]). - -on_client_disconnected(ClientInfo = #{clientid := ClientId}, ReasonCode, ConnInfo, _Env) -> - io:format("Client(~s) disconnected due to ~p, ClientInfo:~n~p~n, ConnInfo:~n~p~n", - [ClientId, ReasonCode, ClientInfo, ConnInfo]). - -on_client_authenticate(_ClientInfo = #{clientid := ClientId}, Result, _Env) -> - io:format("Client(~s) authenticate, Result:~n~p~n", [ClientId, Result]), - {ok, Result}. - -on_client_check_acl(_ClientInfo = #{clientid := ClientId}, Topic, PubSub, Result, _Env) -> - io:format("Client(~s) check_acl, PubSub:~p, Topic:~p, Result:~p~n", - [ClientId, PubSub, Topic, Result]), - {ok, Result}. - -on_client_subscribe(#{clientid := ClientId}, _Properties, TopicFilters, _Env) -> - io:format("Client(~s) will subscribe: ~p~n", [ClientId, TopicFilters]), - {ok, TopicFilters}. - -on_client_unsubscribe(#{clientid := ClientId}, _Properties, TopicFilters, _Env) -> - io:format("Client(~s) will unsubscribe ~p~n", [ClientId, TopicFilters]), - {ok, TopicFilters}. - -%%-------------------------------------------------------------------- -%% Session Lifecircle Hooks -%%-------------------------------------------------------------------- - -on_session_created(#{clientid := ClientId}, SessInfo, _Env) -> - io:format("Session(~s) created, Session Info:~n~p~n", [ClientId, SessInfo]). - -on_session_subscribed(#{clientid := ClientId}, Topic, SubOpts, _Env) -> - io:format("Session(~s) subscribed ~s with subopts: ~p~n", [ClientId, Topic, SubOpts]). - -on_session_unsubscribed(#{clientid := ClientId}, Topic, Opts, _Env) -> - io:format("Session(~s) unsubscribed ~s with opts: ~p~n", [ClientId, Topic, Opts]). - -on_session_resumed(#{clientid := ClientId}, SessInfo, _Env) -> - io:format("Session(~s) resumed, Session Info:~n~p~n", [ClientId, SessInfo]). - -on_session_discarded(_ClientInfo = #{clientid := ClientId}, SessInfo, _Env) -> - io:format("Session(~s) is discarded. Session Info: ~p~n", [ClientId, SessInfo]). - -on_session_takeovered(_ClientInfo = #{clientid := ClientId}, SessInfo, _Env) -> - io:format("Session(~s) is takeovered. Session Info: ~p~n", [ClientId, SessInfo]). - -on_session_terminated(_ClientInfo = #{clientid := ClientId}, Reason, SessInfo, _Env) -> - io:format("Session(~s) is terminated due to ~p~nSession Info: ~p~n", - [ClientId, Reason, SessInfo]). - -%%-------------------------------------------------------------------- -%% Message PubSub Hooks -%%-------------------------------------------------------------------- - -%% Transform message and return -on_message_publish(Message = #message{topic = <<"$SYS/", _/binary>>}, _Env) -> - {ok, Message}; - -on_message_publish(Message, _Env) -> - io:format("Publish ~s~n", [emqx_message:format(Message)]), - {ok, Message}. - -on_message_dropped(#message{topic = <<"$SYS/", _/binary>>}, _By, _Reason, _Env) -> - ok; -on_message_dropped(Message, _By = #{node := Node}, Reason, _Env) -> - io:format("Message dropped by node ~s due to ~s: ~s~n", - [Node, Reason, emqx_message:format(Message)]). - -on_message_delivered(_ClientInfo = #{clientid := ClientId}, Message, _Env) -> - io:format("Message delivered to client(~s): ~s~n", - [ClientId, emqx_message:format(Message)]), - {ok, Message}. - -on_message_acked(_ClientInfo = #{clientid := ClientId}, Message, _Env) -> - io:format("Message acked by client(~s): ~s~n", - [ClientId, emqx_message:format(Message)]). - -%% Called when the plugin application stop -unload() -> - emqx:unhook('client.connect', {?MODULE, on_client_connect}), - emqx:unhook('client.connack', {?MODULE, on_client_connack}), - emqx:unhook('client.connected', {?MODULE, on_client_connected}), - emqx:unhook('client.disconnected', {?MODULE, on_client_disconnected}), - emqx:unhook('client.authenticate', {?MODULE, on_client_authenticate}), - emqx:unhook('client.check_acl', {?MODULE, on_client_check_acl}), - emqx:unhook('client.subscribe', {?MODULE, on_client_subscribe}), - emqx:unhook('client.unsubscribe', {?MODULE, on_client_unsubscribe}), - emqx:unhook('session.created', {?MODULE, on_session_created}), - emqx:unhook('session.subscribed', {?MODULE, on_session_subscribed}), - emqx:unhook('session.unsubscribed',{?MODULE, on_session_unsubscribed}), - emqx:unhook('session.resumed', {?MODULE, on_session_resumed}), - emqx:unhook('session.discarded', {?MODULE, on_session_discarded}), - emqx:unhook('session.takeovered', {?MODULE, on_session_takeovered}), - emqx:unhook('session.terminated', {?MODULE, on_session_terminated}), - emqx:unhook('message.publish', {?MODULE, on_message_publish}), - emqx:unhook('message.delivered', {?MODULE, on_message_delivered}), - emqx:unhook('message.acked', {?MODULE, on_message_acked}), - emqx:unhook('message.dropped', {?MODULE, on_message_dropped}). - -hook(Name, MFA) -> - case emqx:hook(Name, MFA) of - ok -> ok; - {error, already_exists} -> ok - end. diff --git a/apps/emqx_plugin_template/src/emqx_plugin_template_app.erl b/apps/emqx_plugin_template/src/emqx_plugin_template_app.erl deleted file mode 100644 index 5a4cabce8..000000000 --- a/apps/emqx_plugin_template/src/emqx_plugin_template_app.erl +++ /dev/null @@ -1,34 +0,0 @@ -%%-------------------------------------------------------------------- -%% Copyright (c) 2020 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_plugin_template_app). - --behaviour(application). - --emqx_plugin(?MODULE). - --export([ start/2 - , stop/1 - ]). - -start(_StartType, _StartArgs) -> - {ok, Sup} = emqx_plugin_template_sup:start_link(), - emqx_plugin_template:load(application:get_all_env()), - {ok, Sup}. - -stop(_State) -> - emqx_plugin_template:unload(). - diff --git a/apps/emqx_plugin_template/src/emqx_plugin_template_sup.erl b/apps/emqx_plugin_template/src/emqx_plugin_template_sup.erl deleted file mode 100644 index bd9961f3a..000000000 --- a/apps/emqx_plugin_template/src/emqx_plugin_template_sup.erl +++ /dev/null @@ -1,30 +0,0 @@ -%%-------------------------------------------------------------------- -%% Copyright (c) 2020 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_plugin_template_sup). - --behaviour(supervisor). - --export([start_link/0]). - --export([init/1]). - -start_link() -> - supervisor:start_link({local, ?MODULE}, ?MODULE, []). - -init([]) -> - {ok, { {one_for_all, 0, 1}, []} }. - diff --git a/apps/emqx_plugin_template/test/emqx_plugin_template_SUITE.erl b/apps/emqx_plugin_template/test/emqx_plugin_template_SUITE.erl deleted file mode 100644 index 912197226..000000000 --- a/apps/emqx_plugin_template/test/emqx_plugin_template_SUITE.erl +++ /dev/null @@ -1,24 +0,0 @@ -%%-------------------------------------------------------------------- -%% Copyright (c) 2020 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_plugin_template_SUITE). - --compile(nowarn_export_all). --compile(export_all). - -all() -> []. - -groups() -> []. diff --git a/rebar.config.erl b/rebar.config.erl index 90caf5c60..d417107c5 100644 --- a/rebar.config.erl +++ b/rebar.config.erl @@ -155,7 +155,6 @@ relx_plugin_apps_per_rel(cloud) -> , emqx_exproto , emqx_prometheus , emqx_psk_file - , emqx_plugin_template ]; relx_plugin_apps_per_rel(edge) -> []. diff --git a/sync-apps.sh b/sync-apps.sh index 3f66de06e..1b4b8fcc2 100755 --- a/sync-apps.sh +++ b/sync-apps.sh @@ -21,7 +21,6 @@ apps=( "emqx_lua_hook" "emqx_lwm2m" "emqx_management" -"emqx_plugin_template" "emqx_prometheus" "emqx_psk_file" "emqx_recon"