summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2011-05-23 15:06:10 +0100
committerSimon MacMullen <simon@rabbitmq.com>2011-05-23 15:06:10 +0100
commit26097dd85c3bf96fc6ddf8f5d7f79b8e42571984 (patch)
treed2dd581fdd5104f22a78828a4cae42c0e6a23c9c
parentf6faad9903a5e9b612345bd3f790c998af75e188 (diff)
downloadrabbitmq-server-bug24129.tar.gz
Add a "tracing" column to the list_vhosts command. A bigger change than expected, as vhosts didn't have the standard info item infrastructure.bug24129
-rw-r--r--docs/rabbitmqctl.1.xml23
-rw-r--r--src/rabbit_control.erl5
-rw-r--r--src/rabbit_trace.erl10
-rw-r--r--src/rabbit_vhost.erl23
4 files changed, 53 insertions, 8 deletions
diff --git a/docs/rabbitmqctl.1.xml b/docs/rabbitmqctl.1.xml
index 4d801ef1..ffa01894 100644
--- a/docs/rabbitmqctl.1.xml
+++ b/docs/rabbitmqctl.1.xml
@@ -624,14 +624,31 @@
</listitem>
</varlistentry>
- <varlistentry>
- <term><cmdsynopsis><command>list_vhosts</command></cmdsynopsis></term>
+ <varlistentry role="usage-has-option-list">
+ <term><cmdsynopsis><command>list_vhosts</command> <arg choice="opt" role="usage-option-list"><replaceable>vhostinfoitem</replaceable> ...</arg></cmdsynopsis></term>
<listitem>
<para>
Lists virtual hosts.
</para>
+ <para>
+ The <command>vhostinfoitem</command> parameter is used to indicate which
+ virtual host information items to include in the results. The column order in the
+ results will match the order of the parameters.
+ <command>vhostinfoitem</command> can take any value from
+ the list that follows:
+ </para>
+ <variablelist>
+ <varlistentry>
+ <term>name</term>
+ <listitem><para>The name of the virtual host with non-ASCII characters escaped as in C.</para></listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>tracing</term>
+ <listitem><para>Whether tracing is enabled for this virtual host.</para></listitem>
+ </varlistentry>
+ </variablelist>
<para role="example-prefix">For example:</para>
- <screen role="example">rabbitmqctl list_vhosts</screen>
+ <screen role="example">rabbitmqctl list_vhosts name tracing</screen>
<para role="example">
This command instructs the RabbitMQ broker to list all
virtual hosts.
diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl
index e5251438..8172f804 100644
--- a/src/rabbit_control.erl
+++ b/src/rabbit_control.erl
@@ -221,9 +221,10 @@ action(delete_vhost, Node, Args = [_VHostPath], _Opts, Inform) ->
Inform("Deleting vhost ~p", Args),
call(Node, {rabbit_vhost, delete, Args});
-action(list_vhosts, Node, [], _Opts, Inform) ->
+action(list_vhosts, Node, Args, _Opts, Inform) ->
Inform("Listing vhosts", []),
- display_list(call(Node, {rabbit_vhost, list, []}));
+ ArgAtoms = default_if_empty(Args, [name]),
+ display_info_list(call(Node, {rabbit_vhost, info_all, []}), ArgAtoms);
action(list_user_permissions, Node, Args = [_Username], _Opts, Inform) ->
Inform("Listing permissions for user ~p", Args),
diff --git a/src/rabbit_trace.erl b/src/rabbit_trace.erl
index 172e8a7a..7d36856a 100644
--- a/src/rabbit_trace.erl
+++ b/src/rabbit_trace.erl
@@ -16,7 +16,7 @@
-module(rabbit_trace).
--export([init/1, tap_trace_in/2, tap_trace_out/2, start/1, stop/1]).
+-export([init/1, tracing/1, tap_trace_in/2, tap_trace_out/2, start/1, stop/1]).
-include("rabbit.hrl").
-include("rabbit_framing.hrl").
@@ -31,6 +31,7 @@
-type(state() :: rabbit_types:exchange() | 'none').
-spec(init/1 :: (rabbit_types:vhost()) -> state()).
+-spec(tracing/1 :: (rabbit_types:vhost()) -> boolean()).
-spec(tap_trace_in/2 :: (rabbit_types:basic_message(), state()) -> 'ok').
-spec(tap_trace_out/2 :: (rabbit_amqqueue:qmsg(), state()) -> 'ok').
@@ -42,14 +43,17 @@
%%----------------------------------------------------------------------------
init(VHost) ->
- {ok, VHosts} = application:get_env(rabbit, ?TRACE_VHOSTS),
- case lists:member(VHost, VHosts) of
+ case tracing(VHost) of
false -> none;
true -> {ok, X} = rabbit_exchange:lookup(
rabbit_misc:r(VHost, exchange, ?XNAME)),
X
end.
+tracing(VHost) ->
+ {ok, VHosts} = application:get_env(rabbit, ?TRACE_VHOSTS),
+ lists:member(VHost, VHosts).
+
tap_trace_in(Msg = #basic_message{exchange_name = #resource{name = XName}},
TraceX) ->
maybe_trace(TraceX, Msg, <<"publish">>, XName, []).
diff --git a/src/rabbit_vhost.erl b/src/rabbit_vhost.erl
index 67c73cf2..5270d80b 100644
--- a/src/rabbit_vhost.erl
+++ b/src/rabbit_vhost.erl
@@ -21,6 +21,7 @@
%%----------------------------------------------------------------------------
-export([add/1, delete/1, exists/1, list/0, with/2]).
+-export([info/1, info/2, info_all/0, info_all/1]).
-ifdef(use_specs).
@@ -30,10 +31,18 @@
-spec(list/0 :: () -> [rabbit_types:vhost()]).
-spec(with/2 :: (rabbit_types:vhost(), rabbit_misc:thunk(A)) -> A).
+-spec(info/1 :: (rabbit_types:vhost()) -> rabbit_types:infos()).
+-spec(info/2 :: (rabbit_types:vhost(), rabbit_types:info_keys())
+ -> rabbit_types:infos()).
+-spec(info_all/0 :: () -> [rabbit_types:infos()]).
+-spec(info_all/1 :: (rabbit_types:info_keys()) -> [rabbit_types:infos()]).
+
-endif.
%%----------------------------------------------------------------------------
+-define(INFO_KEYS, [name, tracing]).
+
add(VHostPath) ->
R = rabbit_misc:execute_mnesia_transaction(
fun () ->
@@ -105,3 +114,17 @@ with(VHostPath, Thunk) ->
Thunk()
end
end.
+
+%%----------------------------------------------------------------------------
+
+infos(Items, X) -> [{Item, i(Item, X)} || Item <- Items].
+
+i(name, VHost) -> VHost;
+i(tracing, VHost) -> rabbit_trace:tracing(VHost);
+i(Item, _) -> throw({bad_argument, Item}).
+
+info(VHost) -> infos(?INFO_KEYS, VHost).
+info(VHost, Items) -> infos(Items, VHost).
+
+info_all() -> info_all(?INFO_KEYS).
+info_all(Items) -> [info(VHost, Items) || VHost <- list()].