summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rabbit_plugins_main.erl86
1 files changed, 64 insertions, 22 deletions
diff --git a/src/rabbit_plugins_main.erl b/src/rabbit_plugins_main.erl
index 408fc4e10b..e7f9c02217 100644
--- a/src/rabbit_plugins_main.erl
+++ b/src/rabbit_plugins_main.erl
@@ -24,19 +24,24 @@
-define(MINIMAL_OPT, "-m").
-define(ENABLED_OPT, "-E").
-define(ENABLED_ALL_OPT, "-e").
+-define(ACTIVE_ONLY_OPT, "-A").
+-define(INACTIVE_ONLY_OPT, "-I").
-define(NODE_DEF(Node), {?NODE_OPT, {option, Node}}).
-define(VERBOSE_DEF, {?VERBOSE_OPT, flag}).
-define(MINIMAL_DEF, {?MINIMAL_OPT, flag}).
-define(ENABLED_DEF, {?ENABLED_OPT, flag}).
-define(ENABLED_ALL_DEF, {?ENABLED_ALL_OPT, flag}).
+-define(ACTIVE_ONLY_DEF, {?ACTIVE_ONLY_OPT, flag}).
+-define(INACTIVE_ONLY_DEF, {?INACTIVE_ONLY_OPT, flag}).
-define(RPC_TIMEOUT, infinity).
-define(GLOBAL_DEFS(Node), [?NODE_DEF(Node)]).
-define(COMMANDS,
- [{list, [?VERBOSE_DEF, ?MINIMAL_DEF, ?ENABLED_DEF, ?ENABLED_ALL_DEF]},
+ [{list, [?VERBOSE_DEF, ?MINIMAL_DEF, ?ENABLED_DEF,
+ ?ENABLED_ALL_DEF, ?ACTIVE_ONLY_DEF, ?INACTIVE_ONLY_DEF]},
enable,
disable]).
@@ -111,8 +116,8 @@ parse_arguments(CmdLine, NodeStr) ->
action(list, Node, [], Opts, PluginsFile, PluginsDir) ->
action(list, Node, [".*"], Opts, PluginsFile, PluginsDir);
-action(list, _Node, [Pat], Opts, PluginsFile, PluginsDir) ->
- format_plugins(Pat, Opts, PluginsFile, PluginsDir);
+action(list, Node, [Pat], Opts, PluginsFile, PluginsDir) ->
+ format_plugins(Node, Pat, Opts, PluginsFile, PluginsDir);
action(enable, Node, ToEnable0, _Opts, PluginsFile, PluginsDir) ->
case ToEnable0 of
@@ -125,7 +130,16 @@ action(enable, Node, ToEnable0, _Opts, PluginsFile, PluginsDir) ->
Enabled, AllPlugins),
ToEnable = [list_to_atom(Name) || Name <- ToEnable0],
Missing = ToEnable -- plugin_names(AllPlugins),
- NewEnabled = lists:usort(Enabled ++ ToEnable),
+ ExplicitlyEnabled = lists:usort(Enabled ++ ToEnable),
+ NewEnabled =
+ case rpc:call(Node, rabbit_plugins, active, [], ?RPC_TIMEOUT) of
+ {badrpc, _} -> ExplicitlyEnabled;
+ [] -> ExplicitlyEnabled;
+ ActiveList -> EnabledSet = sets:from_list(ExplicitlyEnabled),
+ ActiveSet = sets:from_list(ActiveList),
+ Intersect = sets:intersection(EnabledSet, ActiveSet),
+ sets:to_list(sets:subtract(EnabledSet, Intersect))
+ end,
NewImplicitlyEnabled = rabbit_plugins:dependencies(false,
NewEnabled, AllPlugins),
MissingDeps = (NewImplicitlyEnabled -- plugin_names(AllPlugins)) -- Missing,
@@ -137,11 +151,11 @@ action(enable, Node, ToEnable0, _Opts, PluginsFile, PluginsDir) ->
fmt_missing("plugins", Missing) ++
fmt_missing("dependencies", MissingDeps)})
end,
- write_enabled_plugins(PluginsFile, NewEnabled),
- case NewEnabled -- ImplicitlyEnabled of
+ write_enabled_plugins(PluginsFile, ExplicitlyEnabled),
+ case NewEnabled -- (ImplicitlyEnabled -- ExplicitlyEnabled) of
[] -> io:format("Plugin configuration unchanged.~n");
_ -> print_list("The following plugins have been enabled:",
- NewImplicitlyEnabled -- ImplicitlyEnabled),
+ NewEnabled),
action_change(Node, enable, NewEnabled)
end;
@@ -160,11 +174,17 @@ action(disable, Node, ToDisable0, _Opts, PluginsFile, PluginsDir) ->
Missing)
end,
ToDisableDeps = rabbit_plugins:dependencies(true, ToDisable, AllPlugins),
+ Active =
+ case rpc:call(Node, rabbit_plugins, active, [], ?RPC_TIMEOUT) of
+ {badrpc, _} -> Enabled;
+ [] -> Enabled;
+ ActiveList -> ActiveList
+ end,
NewEnabled = Enabled -- ToDisableDeps,
- case length(Enabled) =:= length(NewEnabled) of
+ case length(Active) =:= length(NewEnabled) of
true -> io:format("Plugin configuration unchanged.~n");
false -> ImplicitlyEnabled =
- rabbit_plugins:dependencies(false, Enabled, AllPlugins),
+ rabbit_plugins:dependencies(false, Active, AllPlugins),
NewImplicitlyEnabled =
rabbit_plugins:dependencies(false,
NewEnabled, AllPlugins),
@@ -185,7 +205,7 @@ usage() ->
rabbit_misc:quit(1).
%% Pretty print a list of plugins.
-format_plugins(Pattern, Opts, PluginsFile, PluginsDir) ->
+format_plugins(Node, Pattern, Opts, PluginsFile, PluginsDir) ->
Verbose = proplists:get_bool(?VERBOSE_OPT, Opts),
Minimal = proplists:get_bool(?MINIMAL_OPT, Opts),
Format = case {Verbose, Minimal} of
@@ -197,7 +217,14 @@ format_plugins(Pattern, Opts, PluginsFile, PluginsDir) ->
end,
OnlyEnabled = proplists:get_bool(?ENABLED_OPT, Opts),
OnlyEnabledAll = proplists:get_bool(?ENABLED_ALL_OPT, Opts),
-
+ OnlyActive = proplists:get_bool(?ACTIVE_ONLY_OPT, Opts),
+ OnlyInactive = proplists:get_bool(?INACTIVE_ONLY_OPT, Opts),
+
+ ActivePlugins = case rpc:call(Node, rabbit_plugins, active,
+ [], ?RPC_TIMEOUT) of
+ {badrpc, _} -> [];
+ Active -> Active
+ end,
AvailablePlugins = rabbit_plugins:list(PluginsDir),
EnabledExplicitly = rabbit_plugins:read_enabled(PluginsFile),
EnabledImplicitly =
@@ -211,29 +238,44 @@ format_plugins(Pattern, Opts, PluginsFile, PluginsDir) ->
Plugin = #plugin{name = Name} <- AvailablePlugins ++ Missing,
re:run(atom_to_list(Name), RE, [{capture, none}]) =:= match,
if OnlyEnabled -> lists:member(Name, EnabledExplicitly);
- OnlyEnabledAll -> (lists:member(Name,
- EnabledExplicitly) or
- lists:member(Name, EnabledImplicitly));
+ OnlyEnabledAll -> is_enabled(Name, EnabledExplicitly,
+ EnabledImplicitly);
+ OnlyActive -> (lists:member(Name, ActivePlugins)
+ andalso not
+ (is_enabled(Name, EnabledExplicitly,
+ EnabledImplicitly)));
+ OnlyInactive -> (is_enabled(Name, EnabledExplicitly,
+ EnabledImplicitly)
+ andalso not
+ lists:member(Name, ActivePlugins));
true -> true
end],
Plugins1 = usort_plugins(Plugins),
MaxWidth = lists:max([length(atom_to_list(Name)) ||
#plugin{name = Name} <- Plugins1] ++ [0]),
- [format_plugin(P, EnabledExplicitly, EnabledImplicitly,
+ [format_plugin(P, EnabledExplicitly, EnabledImplicitly, ActivePlugins,
plugin_names(Missing), Format, MaxWidth) || P <- Plugins1],
ok.
+is_enabled(Name, EnabledExplicitly, EnabledImplicitly) ->
+ lists:member(Name,EnabledExplicitly) or
+ lists:member(Name, EnabledImplicitly).
+
format_plugin(#plugin{name = Name, version = Version,
description = Description, dependencies = Deps},
- EnabledExplicitly, EnabledImplicitly, Missing,
- Format, MaxWidth) ->
+ EnabledExplicitly, EnabledImplicitly, Active,
+ Missing, Format, MaxWidth) ->
Glyph = case {lists:member(Name, EnabledExplicitly),
lists:member(Name, EnabledImplicitly),
- lists:member(Name, Missing)} of
- {true, false, false} -> "[E]";
- {false, true, false} -> "[e]";
- {_, _, true} -> "[!]";
- _ -> "[ ]"
+ lists:member(Name, Missing),
+ lists:member(Name, Active)} of
+ {true, false, false, false} -> "[I]";
+ {false, true, false, false} -> "[i]";
+ {false, false, false, true} -> "[A]";
+ {true, false, false, true} -> "[E]";
+ {false, true, false, true} -> "[e]";
+ {_, _, true, _} -> "[!]";
+ _ -> "[ ]"
end,
Opt = fun (_F, A, A) -> ok;
( F, A, _) -> io:format(F, [A])