diff options
| author | Diana Corbacho <diana@rabbitmq.com> | 2017-02-24 10:58:09 +0000 |
|---|---|---|
| committer | Diana Corbacho <diana@rabbitmq.com> | 2017-02-27 15:54:33 +0000 |
| commit | 74eace424e303ad452cda41a703d2f62426348f6 (patch) | |
| tree | 380346831cbe49e4a5f7904d216b91920b442257 /src | |
| parent | 9b2d2af672b8075bbdff9a38347b71a2cd0f609f (diff) | |
| download | rabbitmq-server-git-74eace424e303ad452cda41a703d2f62426348f6.tar.gz | |
Exclude apps that are not RabbitMQ plugins from the list of plugins
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit.erl | 2 | ||||
| -rw-r--r-- | src/rabbit_plugins.erl | 25 | ||||
| -rw-r--r-- | src/rabbit_plugins_main.erl | 33 |
3 files changed, 45 insertions, 15 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl index 1f8181dafd..b8e608aa51 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -327,7 +327,7 @@ broker_start() -> ToBeLoaded = Plugins ++ ?APPS, start_apps(ToBeLoaded), maybe_sd_notify(), - ok = log_broker_started(rabbit_plugins:active()). + ok = log_broker_started(rabbit_plugins:strict_plugins(rabbit_plugins:active())). %% Try to send systemd ready notification if it makes sense in the %% current environment. standard_error is used intentionally in all diff --git a/src/rabbit_plugins.erl b/src/rabbit_plugins.erl index 994e027eac..465500e910 100644 --- a/src/rabbit_plugins.erl +++ b/src/rabbit_plugins.erl @@ -22,6 +22,7 @@ -export([ensure/1]). -export([extract_schemas/1]). -export([validate_plugins/1, format_invalid_plugins/1]). +-export([is_strict_plugin/1, strict_plugins/2, strict_plugins/1]). % Export for testing purpose. -export([is_version_supported/2, validate_plugins/2]). @@ -37,6 +38,9 @@ -spec dependencies(boolean(), [plugin_name()], [#plugin{}]) -> [plugin_name()]. -spec ensure(string()) -> {'ok', [atom()], [atom()]} | {error, any()}. +-spec strict_plugins([plugin_name()], [#plugin{}]) -> [plugin_name()]. +-spec strict_plugins([plugin_name()]) -> [plugin_name()]. +-spec is_strict_plugin(#plugin{}) -> boolean(). %%---------------------------------------------------------------------------- @@ -174,6 +178,24 @@ dependencies(Reverse, Sources, AllPlugins) -> true = digraph:delete(G), OrderedDests. +%% Filter real plugins from application dependencies +is_strict_plugin(#plugin{extra_dependencies = ExtraDeps}) -> + lists:member(rabbit, ExtraDeps). + +strict_plugins(Plugins, AllPlugins) -> + lists:filter( + fun(Name) -> + is_strict_plugin(lists:keyfind(Name, #plugin.name, AllPlugins)) + end, Plugins). + +strict_plugins(Plugins) -> + {ok, ExpandDir} = application:get_env(rabbit, plugins_expand_dir), + AllPlugins = list(ExpandDir), + lists:filter( + fun(Name) -> + is_strict_plugin(lists:keyfind(Name, #plugin.name, AllPlugins)) + end, Plugins). + %% For a few known cases, an externally provided plugin can be trusted. %% In this special case, it overrides the plugin. plugin_provided_by_otp(#plugin{name = eldap}) -> @@ -200,7 +222,8 @@ ensure_dependencies(Plugins) -> end, Deps)], throw({error, {missing_dependencies, Missing, Blame}}) end, - [P#plugin{dependencies = Deps -- OTP} + [P#plugin{dependencies = Deps -- OTP, + extra_dependencies = Deps -- (Deps -- OTP)} || P = #plugin{dependencies = Deps} <- Plugins]. is_loadable(App) -> diff --git a/src/rabbit_plugins_main.erl b/src/rabbit_plugins_main.erl index dccdd92969..d4dd37668c 100644 --- a/src/rabbit_plugins_main.erl +++ b/src/rabbit_plugins_main.erl @@ -102,10 +102,10 @@ action(enable, Node, ToEnable0, Opts, State = #cli{all = All, rabbit_plugins:format_invalid_plugins(Invalid)}) end, NewImplicit = write_enabled_plugins(NewEnabled, State), - case NewEnabled -- Implicit of + case rabbit_plugins:strict_plugins(NewEnabled -- Implicit, All) of [] -> io:format("Plugin configuration unchanged.~n"); _ -> print_list("The following plugins have been enabled:", - NewImplicit -- Implicit) + rabbit_plugins:strict_plugins(NewImplicit -- Implicit, All)) end, action_change(Opts, Node, Implicit, NewImplicit, State); @@ -124,10 +124,10 @@ action(set, Node, NewEnabled0, Opts, State = #cli{all = All, rabbit_plugins:format_invalid_plugins(Invalid)}) end, NewImplicit = write_enabled_plugins(NewEnabled, State), - case NewImplicit of + case rabbit_plugins:strict_plugins(NewImplicit, All) of [] -> io:format("All plugins are now disabled.~n"); - _ -> print_list("The following plugins are now enabled:", - NewImplicit) + Plugins -> print_list("The following plugins are now enabled:", + Plugins) end, action_change(Opts, Node, Implicit, NewImplicit, State); @@ -151,7 +151,8 @@ action(disable, Node, ToDisable0, Opts, State = #cli{all = All, case length(Enabled) =:= length(NewEnabled) of true -> io:format("Plugin configuration unchanged.~n"); false -> print_list("The following plugins have been disabled:", - Implicit -- NewImplicit) + rabbit_plugins:strict_plugins(Implicit -- NewImplicit, + All)) end, action_change(Opts, Node, Implicit, NewImplicit, State); @@ -203,7 +204,8 @@ format_plugins(Node, Pattern, Opts, #cli{all = All, OnlyEnabledAll -> lists:member(Name, Enabled) or lists:member(Name,EnabledImplicitly); true -> true - end], + end, + rabbit_plugins:is_strict_plugin(Plugin)], Plugins1 = usort_plugins(Plugins), MaxWidth = lists:max([length(atom_to_list(Name)) || #plugin{name = Name} <- Plugins1] ++ [0]), @@ -293,19 +295,24 @@ action_change0(true, _Online, _Node, _Old, _New, _State) -> action_change0(false, Online, Node, _Old, _New, State) -> sync(Node, Online, State). -sync(Node, ForceOnline, #cli{file = File}) -> - rpc_call(Node, ForceOnline, rabbit_plugins, ensure, [File]). +sync(Node, ForceOnline, #cli{file = File, + all = All}) -> + rpc_call(Node, ForceOnline, rabbit_plugins, ensure, [File], All). -rpc_call(Node, Online, Mod, Fun, Args) -> +rpc_call(Node, Online, Mod, Fun, Args, All) -> io:format("~nApplying plugin configuration to ~s...", [Node]), case rabbit_misc:rpc_call(Node, Mod, Fun, Args) of {ok, [], []} -> io:format(" nothing to do.~n", []); - {ok, Start, []} -> + {ok, Start0, []} -> + Start = rabbit_plugins:strict_plugins(Start0, All), io:format(" started ~b plugin~s.~n", [length(Start), plur(Start)]); - {ok, [], Stop} -> + {ok, [], Stop0} -> + Stop = rabbit_plugins:strict_plugins(Stop0, All), io:format(" stopped ~b plugin~s.~n", [length(Stop), plur(Stop)]); - {ok, Start, Stop} -> + {ok, Start0, Stop0} -> + Start = rabbit_plugins:strict_plugins(Start0, All), + Stop = rabbit_plugins:strict_plugins(Stop0, All), io:format(" stopped ~b plugin~s and started ~b plugin~s.~n", [length(Stop), plur(Stop), length(Start), plur(Start)]); {badrpc, nodedown} = Error -> |
