diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2012-08-21 16:42:43 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2012-08-21 16:42:43 +0100 |
commit | 3cd55264c69a9bd9955817da1801ac6e0af9842d (patch) | |
tree | e0981c692e019a6a0e05757b30a10d56c9006bb3 | |
parent | 1ab8e0cbc66e711c3182d7ae734c704d5b0f183b (diff) | |
parent | 3637d9825e7e7bf85e0b69b1635ae2c9a16d6baf (diff) | |
download | rabbitmq-server-3cd55264c69a9bd9955817da1801ac6e0af9842d.tar.gz |
Merge default
-rw-r--r-- | docs/rabbitmqctl.1.xml | 27 | ||||
-rw-r--r-- | packaging/macports/Portfile.in | 2 | ||||
-rw-r--r-- | src/rabbit_control_main.erl | 22 | ||||
-rw-r--r-- | src/rabbit_heartbeat.erl | 45 | ||||
-rw-r--r-- | src/rabbit_mirror_queue_misc.erl | 7 | ||||
-rw-r--r-- | src/rabbit_policy.erl | 56 | ||||
-rw-r--r-- | src/rabbit_runtime_parameter.erl | 18 | ||||
-rw-r--r-- | src/rabbit_runtime_parameters.erl | 134 | ||||
-rw-r--r-- | src/rabbit_runtime_parameters_test.erl | 18 | ||||
-rw-r--r-- | src/rabbit_vhost.erl | 13 |
10 files changed, 169 insertions, 173 deletions
diff --git a/docs/rabbitmqctl.1.xml b/docs/rabbitmqctl.1.xml index 2d25edee..6d93db4c 100644 --- a/docs/rabbitmqctl.1.xml +++ b/docs/rabbitmqctl.1.xml @@ -581,7 +581,7 @@ </para> <para> Deleting a virtual host deletes all its exchanges, - queues, user mappings and associated permissions. + queues, bindings, user permissions and parameters. </para> <para role="example-prefix">For example:</para> <screen role="example">rabbitmqctl delete_vhost test</screen> @@ -750,15 +750,16 @@ Certain features of RabbitMQ (such as the federation plugin) are controlled by dynamic, cluster-wide <emphasis>parameters</emphasis>. Each parameter - consists of a component name, a key and a value. The - component name and key are strings, and the value is an - Erlang term. Parameters can be set, cleared and listed. In - general you should refer to the documentation for the feature - in question to see how to set parameters. + consists of a component name, a key and a value, and is + associated with a virtual host. The component name and key are + strings, and the value is an Erlang term. Parameters can be + set, cleared and listed. In general you should refer to the + documentation for the feature in question to see how to set + parameters. </para> <variablelist> <varlistentry> - <term><cmdsynopsis><command>set_parameter</command> <arg choice="req"><replaceable>component_name</replaceable></arg> <arg choice="req"><replaceable>key</replaceable></arg> <arg choice="req"><replaceable>value</replaceable></arg></cmdsynopsis></term> + <term><cmdsynopsis><command>set_parameter</command> <arg choice="opt">-p <replaceable>vhostpath</replaceable></arg> <arg choice="req"><replaceable>component_name</replaceable></arg> <arg choice="req"><replaceable>key</replaceable></arg> <arg choice="req"><replaceable>value</replaceable></arg></cmdsynopsis></term> <listitem> <para> Sets a parameter. @@ -789,12 +790,12 @@ <para role="example-prefix">For example:</para> <screen role="example">rabbitmqctl set_parameter federation local_username '<<"guest">>'</screen> <para role="example"> - This command sets the parameter <command>local_username</command> for the <command>federation</command> component to the Erlang term <command><<"guest">></command>. + This command sets the parameter <command>local_username</command> for the <command>federation</command> component in the default virtual host to the Erlang term <command><<"guest">></command>. </para> </listitem> </varlistentry> <varlistentry> - <term><cmdsynopsis><command>clear_parameter</command> <arg choice="req"><replaceable>component_name</replaceable></arg> <arg choice="req"><replaceable>key</replaceable></arg></cmdsynopsis></term> + <term><cmdsynopsis><command>clear_parameter</command> <arg choice="opt">-p <replaceable>vhostpath</replaceable></arg> <arg choice="req"><replaceable>component_name</replaceable></arg> <arg choice="req"><replaceable>key</replaceable></arg></cmdsynopsis></term> <listitem> <para> Clears a parameter. @@ -817,20 +818,20 @@ <para role="example-prefix">For example:</para> <screen role="example">rabbitmqctl clear_parameter federation local_username</screen> <para role="example"> - This command clears the parameter <command>local_username</command> for the <command>federation</command> component. + This command clears the parameter <command>local_username</command> for the <command>federation</command> component in the default virtual host. </para> </listitem> </varlistentry> <varlistentry> - <term><cmdsynopsis><command>list_parameters</command></cmdsynopsis></term> + <term><cmdsynopsis><command>list_parameters</command> <arg choice="opt">-p <replaceable>vhostpath</replaceable></arg></cmdsynopsis></term> <listitem> <para> - Lists all parameters. + Lists all parameters for a virtual host. </para> <para role="example-prefix">For example:</para> <screen role="example">rabbitmqctl list_parameters</screen> <para role="example"> - This command lists all parameters. + This command lists all parameters in the default virtual host. </para> </listitem> </varlistentry> diff --git a/packaging/macports/Portfile.in b/packaging/macports/Portfile.in index e461e49e..82c1fb0c 100644 --- a/packaging/macports/Portfile.in +++ b/packaging/macports/Portfile.in @@ -59,7 +59,7 @@ set mandest ${destroot}${prefix}/share/man use_configure no -use_parallel_build yes +use_parallel_build no build.env-append HOME=${workpath} diff --git a/src/rabbit_control_main.erl b/src/rabbit_control_main.erl index 27a35142..08b96757 100644 --- a/src/rabbit_control_main.erl +++ b/src/rabbit_control_main.erl @@ -60,9 +60,9 @@ {list_permissions, [?VHOST_DEF]}, list_user_permissions, - set_parameter, - clear_parameter, - list_parameters, + {set_parameter, [?VHOST_DEF]}, + {clear_parameter, [?VHOST_DEF]}, + {list_parameters, [?VHOST_DEF]}, {list_queues, [?VHOST_DEF]}, {list_exchanges, [?VHOST_DEF]}, @@ -414,21 +414,25 @@ action(list_permissions, Node, [], Opts, Inform) -> list_vhost_permissions, [VHost]}), rabbit_auth_backend_internal:vhost_perms_info_keys()); -action(set_parameter, Node, [Component, Key, Value], _Opts, Inform) -> +action(set_parameter, Node, [Component, Key, Value], Opts, Inform) -> + VHostArg = list_to_binary(proplists:get_value(?VHOST_OPT, Opts)), Inform("Setting runtime parameter ~p for component ~p to ~p", [Key, Component, Value]), rpc_call(Node, rabbit_runtime_parameters, parse_set, - [list_to_binary(Component), list_to_binary(Key), Value]); + [VHostArg, list_to_binary(Component), list_to_binary(Key), Value]); -action(clear_parameter, Node, [Component, Key], _Opts, Inform) -> +action(clear_parameter, Node, [Component, Key], Opts, Inform) -> + VHostArg = list_to_binary(proplists:get_value(?VHOST_OPT, Opts)), Inform("Clearing runtime parameter ~p for component ~p", [Key, Component]), - rpc_call(Node, rabbit_runtime_parameters, clear, [list_to_binary(Component), + rpc_call(Node, rabbit_runtime_parameters, clear, [VHostArg, + list_to_binary(Component), list_to_binary(Key)]); -action(list_parameters, Node, Args = [], _Opts, Inform) -> +action(list_parameters, Node, [], Opts, Inform) -> + VHostArg = list_to_binary(proplists:get_value(?VHOST_OPT, Opts)), Inform("Listing runtime parameters", []), display_info_list( - rpc_call(Node, rabbit_runtime_parameters, list_formatted, Args), + rpc_call(Node, rabbit_runtime_parameters, list_formatted, [VHostArg]), rabbit_runtime_parameters:info_keys()); action(report, Node, _Args, _Opts, Inform) -> diff --git a/src/rabbit_heartbeat.erl b/src/rabbit_heartbeat.erl index 80b4e768..05aad8c9 100644 --- a/src/rabbit_heartbeat.erl +++ b/src/rabbit_heartbeat.erl @@ -59,21 +59,15 @@ start_heartbeat_sender(Sock, TimeoutSec, SendFun) -> %% the 'div 2' is there so that we don't end up waiting for nearly %% 2 * TimeoutSec before sending a heartbeat in the boundary case %% where the last message was sent just after a heartbeat. - heartbeater( - {Sock, TimeoutSec * 1000 div 2, send_oct, 0, - fun () -> - SendFun(), - continue - end}). + heartbeater({Sock, TimeoutSec * 1000 div 2, send_oct, 0, + fun () -> SendFun(), continue end}). start_heartbeat_receiver(Sock, TimeoutSec, ReceiveFun) -> %% we check for incoming data every interval, and time out after %% two checks with no change. As a result we will time out between %% 2 and 3 intervals after the last data has been received. - heartbeater({Sock, TimeoutSec * 1000, recv_oct, 1, fun () -> - ReceiveFun(), - stop - end}). + heartbeater({Sock, TimeoutSec * 1000, recv_oct, 1, + fun () -> ReceiveFun(), stop end}). start_heartbeat_fun(SupPid) -> fun (Sock, SendTimeoutSec, SendFun, ReceiveTimeoutSec, ReceiveFun) -> @@ -88,17 +82,11 @@ start_heartbeat_fun(SupPid) -> {Sender, Receiver} end. -pause_monitor({_Sender, none}) -> - ok; -pause_monitor({_Sender, Receiver}) -> - Receiver ! pause, - ok. +pause_monitor({_Sender, none}) -> ok; +pause_monitor({_Sender, Receiver}) -> Receiver ! pause, ok. -resume_monitor({_Sender, none}) -> - ok; -resume_monitor({_Sender, Receiver}) -> - Receiver ! resume, - ok. +resume_monitor({_Sender, none}) -> ok; +resume_monitor({_Sender, Receiver}) -> Receiver ! resume, ok. %%---------------------------------------------------------------------------- start_heartbeater(0, _SupPid, _Sock, _TimeoutFun, _Name, _Callback) -> @@ -106,8 +94,7 @@ start_heartbeater(0, _SupPid, _Sock, _TimeoutFun, _Name, _Callback) -> start_heartbeater(TimeoutSec, SupPid, Sock, TimeoutFun, Name, Callback) -> supervisor2:start_child( SupPid, {Name, - {rabbit_heartbeat, Callback, - [Sock, TimeoutSec, TimeoutFun]}, + {rabbit_heartbeat, Callback, [Sock, TimeoutSec, TimeoutFun]}, transient, ?MAX_WAIT, worker, [rabbit_heartbeat]}). heartbeater(Params) -> @@ -117,15 +104,11 @@ heartbeater({Sock, TimeoutMillisec, StatName, Threshold, Handler} = Params, {StatVal, SameCount}) -> Recurse = fun (V) -> heartbeater(Params, V) end, receive - pause -> - receive - resume -> - Recurse({0, 0}); - Other -> - exit({unexpected_message, Other}) - end; - Other -> - exit({unexpected_message, Other}) + pause -> receive + resume -> Recurse({0, 0}); + Other -> exit({unexpected_message, Other}) + end; + Other -> exit({unexpected_message, Other}) after TimeoutMillisec -> case rabbit_net:getstat(Sock, [StatName]) of {ok, [{StatName, NewStatVal}]} -> diff --git a/src/rabbit_mirror_queue_misc.erl b/src/rabbit_mirror_queue_misc.erl index 52846f58..0383a15b 100644 --- a/src/rabbit_mirror_queue_misc.erl +++ b/src/rabbit_mirror_queue_misc.erl @@ -80,12 +80,7 @@ remove_from_queue0(QueueName, DeadGMPids) -> pid = QPid, slave_pids = SPids }] -> Alive = [Pid || Pid <- [QPid | SPids], - not lists:member(node(Pid), - DeadNodes) orelse - %% TODO when bug 25104 hits default do whatever it does. - false], - %% rabbit_misc:is_process_alive(Pid)], - {QPid1, SPids1} = promote_slave(Alive), + not lists:member(node(Pid), DeadNodes)], case {{QPid, SPids}, {QPid1, SPids1}} of {Same, Same} -> {ok, QPid1, [], []}; diff --git a/src/rabbit_policy.erl b/src/rabbit_policy.erl index 1551795f..05b43a2e 100644 --- a/src/rabbit_policy.erl +++ b/src/rabbit_policy.erl @@ -26,7 +26,7 @@ -export([register/0]). -export([name/1, get/2, set/1]). --export([validate/3, validate_clear/2, notify/3, notify_clear/2]). +-export([validate/4, validate_clear/3, notify/4, notify_clear/3]). -rabbit_boot_step({?MODULE, [{description, "policy parameters"}, @@ -46,12 +46,13 @@ name0(Policy) -> pget(<<"name">>, Policy). set(Q = #amqqueue{name = Name}) -> Q#amqqueue{policy = set0(Name)}; set(X = #exchange{name = Name}) -> X#exchange{policy = set0(Name)}. -set0(Name) -> match(Name, list()). +set0(Name = #resource{virtual_host = VHost}) -> match(Name, list(VHost)). get(Name, #amqqueue{policy = Policy}) -> get0(Name, Policy); get(Name, #exchange{policy = Policy}) -> get0(Name, Policy); %% Caution - SLOW. -get(Name, EntityName = #resource{}) -> get0(Name, match(EntityName, list())). +get(Name, EntityName = #resource{virtual_host = VHost}) -> + get0(Name, match(EntityName, list(VHost))). get0(_Name, undefined) -> {error, not_found}; get0(Name, List) -> case pget(<<"policy">>, List) of @@ -64,35 +65,33 @@ get0(Name, List) -> case pget(<<"policy">>, List) of %%---------------------------------------------------------------------------- -validate(<<"policy">>, Name, Term) -> +validate(_VHost, <<"policy">>, Name, Term) -> rabbit_parameter_validation:proplist( Name, policy_validation(), Term). -validate_clear(<<"policy">>, _Name) -> +validate_clear(_VHost, <<"policy">>, _Name) -> ok. -notify(<<"policy">>, _Name, _Term) -> - update_policies(). +notify(VHost, <<"policy">>, _Name, _Term) -> + update_policies(VHost). -notify_clear(<<"policy">>, _Name) -> - update_policies(). +notify_clear(VHost, <<"policy">>, _Name) -> + update_policies(VHost). %%---------------------------------------------------------------------------- -list() -> +list(VHost) -> [[{<<"name">>, pget(key, P)} | pget(value, P)] - || P <- rabbit_runtime_parameters:list(<<"policy">>)]. + || P <- rabbit_runtime_parameters:list(VHost, <<"policy">>)]. -update_policies() -> - Policies = list(), +update_policies(VHost) -> + Policies = list(VHost), {Xs, Qs} = rabbit_misc:execute_mnesia_transaction( fun() -> {[update_exchange(X, Policies) || - VHost <- rabbit_vhost:list(), - X <- rabbit_exchange:list(VHost)], + X <- rabbit_exchange:list(VHost)], [update_queue(Q, Policies) || - VHost <- rabbit_vhost:list(), - Q <- rabbit_amqqueue:list(VHost)]} + Q <- rabbit_amqqueue:list(VHost)]} end), [notify(X) || X <- Xs], [notify(Q) || Q <- Qs], @@ -129,28 +128,15 @@ match(Name, Policies) -> [Policy | _Rest] -> Policy end. -matches(#resource{name = Name, virtual_host = VHost}, Policy) -> - Prefix = pget(<<"prefix">>, Policy), - case pget(<<"vhost">>, Policy) of - undefined -> prefix(Prefix, Name); - VHost -> prefix(Prefix, Name); - _ -> false - end. - -prefix(A, B) -> lists:prefix(binary_to_list(A), binary_to_list(B)). +matches(#resource{name = Name}, Policy) -> + lists:prefix(binary_to_list(pget(<<"prefix">>, Policy)), + binary_to_list(Name)). sort_pred(A, B) -> - R = size(pget(<<"prefix">>, A)) >= size(pget(<<"prefix">>, B)), - case {pget(<<"vhost">>, A), pget(<<"vhost">>, B)} of - {undefined, undefined} -> R; - {undefined, _} -> true; - {_, undefined} -> false; - _ -> R - end. + size(pget(<<"prefix">>, A)) >= size(pget(<<"prefix">>, B)). %%---------------------------------------------------------------------------- policy_validation() -> - [{<<"vhost">>, fun rabbit_parameter_validation:binary/2, optional}, - {<<"prefix">>, fun rabbit_parameter_validation:binary/2, mandatory}, + [{<<"prefix">>, fun rabbit_parameter_validation:binary/2, mandatory}, {<<"policy">>, fun rabbit_parameter_validation:list/2, mandatory}]. diff --git a/src/rabbit_runtime_parameter.erl b/src/rabbit_runtime_parameter.erl index c7d30116..18668049 100644 --- a/src/rabbit_runtime_parameter.erl +++ b/src/rabbit_runtime_parameter.erl @@ -21,10 +21,12 @@ -type(validate_results() :: 'ok' | {error, string(), [term()]} | [validate_results()]). --callback validate(binary(), binary(), term()) -> validate_results(). --callback validate_clear(binary(), binary()) -> validate_results(). --callback notify(binary(), binary(), term()) -> 'ok'. --callback notify_clear(binary(), binary()) -> 'ok'. +-callback validate(rabbit_types:vhost(), binary(), binary(), + term()) -> validate_results(). +-callback validate_clear(rabbit_types:vhost(), binary(), + binary()) -> validate_results(). +-callback notify(rabbit_types:vhost(), binary(), binary(), term()) -> 'ok'. +-callback notify_clear(rabbit_types:vhost(), binary(), binary()) -> 'ok'. -else. @@ -32,10 +34,10 @@ behaviour_info(callbacks) -> [ - {validate, 3}, - {validate_clear, 2}, - {notify, 3}, - {notify_clear, 2} + {validate, 4}, + {validate_clear, 3}, + {notify, 4}, + {notify_clear, 3} ]; behaviour_info(_Other) -> undefined. diff --git a/src/rabbit_runtime_parameters.erl b/src/rabbit_runtime_parameters.erl index 3a54e8f6..0707193c 100644 --- a/src/rabbit_runtime_parameters.erl +++ b/src/rabbit_runtime_parameters.erl @@ -18,8 +18,9 @@ -include("rabbit.hrl"). --export([parse_set/3, set/3, clear/2, list/0, list/1, list_strict/1, - list_formatted/0, lookup/2, value/2, value/3, info_keys/0]). +-export([parse_set/4, set/4, clear/3, + list/0, list/1, list_strict/1, list/2, list_strict/2, list_formatted/1, + lookup/3, value/3, value/4, info_keys/0]). %%---------------------------------------------------------------------------- @@ -27,16 +28,23 @@ -type(ok_or_error_string() :: 'ok' | {'error_string', string()}). --spec(parse_set/3 :: (binary(), binary(), string()) -> ok_or_error_string()). --spec(set/3 :: (binary(), binary(), term()) -> ok_or_error_string()). --spec(clear/2 :: (binary(), binary()) -> ok_or_error_string()). +-spec(parse_set/4 :: (rabbit_types:vhost(), binary(), binary(), string()) + -> ok_or_error_string()). +-spec(set/4 :: (rabbit_types:vhost(), binary(), binary(), term()) + -> ok_or_error_string()). +-spec(clear/3 :: (rabbit_types:vhost(), binary(), binary()) + -> ok_or_error_string()). -spec(list/0 :: () -> [rabbit_types:infos()]). --spec(list/1 :: (binary()) -> [rabbit_types:infos()]). +-spec(list/1 :: (rabbit_types:vhost()) -> [rabbit_types:infos()]). -spec(list_strict/1 :: (binary()) -> [rabbit_types:infos()] | 'not_found'). --spec(list_formatted/0 :: () -> [rabbit_types:infos()]). --spec(lookup/2 :: (binary(), binary()) -> rabbit_types:infos()). --spec(value/2 :: (binary(), binary()) -> term()). --spec(value/3 :: (binary(), binary(), term()) -> term()). +-spec(list/2 :: (rabbit_types:vhost(), binary()) -> [rabbit_types:infos()]). +-spec(list_strict/2 :: (rabbit_types:vhost(), binary()) + -> [rabbit_types:infos()] | 'not_found'). +-spec(list_formatted/1 :: (rabbit_types:vhost()) -> [rabbit_types:infos()]). +-spec(lookup/3 :: (rabbit_types:vhost(), binary(), binary()) + -> rabbit_types:infos()). +-spec(value/3 :: (rabbit_types:vhost(), binary(), binary()) -> term()). +-spec(value/4 :: (rabbit_types:vhost(), binary(), binary(), term()) -> term()). -spec(info_keys/0 :: () -> rabbit_types:info_keys()). -endif. @@ -49,14 +57,14 @@ %%--------------------------------------------------------------------------- -parse_set(Component, Key, String) -> +parse_set(VHost, Component, Key, String) -> case parse(String) of - {ok, Term} -> set(Component, Key, Term); + {ok, Term} -> set(VHost, Component, Key, Term); {errors, L} -> format_error(L) end. -set(Component, Key, Term) -> - case set0(Component, Key, Term) of +set(VHost, Component, Key, Term) -> + case set0(VHost, Component, Key, Term) of ok -> ok; {errors, L} -> format_error(L) end. @@ -64,16 +72,18 @@ set(Component, Key, Term) -> format_error(L) -> {error_string, rabbit_misc:format_many([{"Validation failed~n", []} | L])}. -set0(Component, Key, Term) -> +set0(VHost, Component, Key, Term) -> case lookup_component(Component) of {ok, Mod} -> case flatten_errors(validate(Term)) of ok -> - case flatten_errors(Mod:validate(Component, Key, Term)) of + case flatten_errors( + Mod:validate(VHost, Component, Key, Term)) of ok -> - case mnesia_update(Component, Key, Term) of + case mnesia_update(VHost, Component, Key, Term) of {old, Term} -> ok; - _ -> Mod:notify(Component, Key, Term) + _ -> Mod:notify( + VHost, Component, Key, Term) end, ok; E -> @@ -86,95 +96,103 @@ set0(Component, Key, Term) -> E end. -mnesia_update(Component, Key, Term) -> +mnesia_update(VHost, Component, Key, Term) -> rabbit_misc:execute_mnesia_transaction( fun () -> - Res = case mnesia:read(?TABLE, {Component, Key}, read) of + Res = case mnesia:read(?TABLE, {VHost, Component, Key}, read) of [] -> new; [Params] -> {old, Params#runtime_parameters.value} end, - ok = mnesia:write(?TABLE, c(Component, Key, Term), write), + ok = mnesia:write(?TABLE, c(VHost, Component, Key, Term), write), Res end). -clear(Component, Key) -> - case clear0(Component, Key) of +clear(VHost, Component, Key) -> + case clear0(VHost, Component, Key) of ok -> ok; {errors, L} -> format_error(L) end. -clear0(Component, Key) -> +clear0(VHost, Component, Key) -> case lookup_component(Component) of - {ok, Mod} -> case flatten_errors(Mod:validate_clear(Component, Key)) of - ok -> mnesia_clear(Component, Key), - Mod:notify_clear(Component, Key), + {ok, Mod} -> case flatten_errors( + Mod:validate_clear(VHost, Component, Key)) of + ok -> mnesia_clear(VHost, Component, Key), + Mod:notify_clear(VHost, Component, Key), ok; E -> E end; E -> E end. -mnesia_clear(Component, Key) -> +mnesia_clear(VHost, Component, Key) -> ok = rabbit_misc:execute_mnesia_transaction( fun () -> - ok = mnesia:delete(?TABLE, {Component, Key}, write) + ok = mnesia:delete(?TABLE, {VHost, Component, Key}, write) end). list() -> [p(P) || P <- rabbit_misc:dirty_read_all(?TABLE)]. -list(Component) -> list(Component, []). -list_strict(Component) -> list(Component, not_found). - -list(Component, Default) -> - case lookup_component(Component) of - {ok, _} -> Match = #runtime_parameters{key = {Component, '_'}, _ = '_'}, - [p(P) || P <- mnesia:dirty_match_object(?TABLE, Match)]; - _ -> Default +list(VHost) -> list(VHost, '_', []). +list_strict(Component) -> list('_', Component, not_found). +list(VHost, Component) -> list(VHost, Component, []). +list_strict(VHost, Component) -> list(VHost, Component, not_found). + +list(VHost, Component, Default) -> + case component_good(Component) of + true -> Match = #runtime_parameters{key = {VHost, Component, '_'}, + _ = '_'}, + [p(P) || P <- mnesia:dirty_match_object(?TABLE, Match)]; + _ -> Default end. -list_formatted() -> - [pset(value, format(pget(value, P)), P) || P <- list()]. +list_formatted(VHost) -> + [pset(value, format(pget(value, P)), P) || P <- list(VHost)]. -lookup(Component, Key) -> - case lookup0(Component, Key, rabbit_misc:const(not_found)) of +lookup(VHost, Component, Key) -> + case lookup0(VHost, Component, Key, rabbit_misc:const(not_found)) of not_found -> not_found; Params -> p(Params) end. -value(Component, Key) -> - case lookup0(Component, Key, rabbit_misc:const(not_found)) of +value(VHost, Component, Key) -> + case lookup0(VHost, Component, Key, rabbit_misc:const(not_found)) of not_found -> not_found; Params -> Params#runtime_parameters.value end. -value(Component, Key, Default) -> - Params = lookup0(Component, Key, - fun () -> lookup_missing(Component, Key, Default) end), +value(VHost, Component, Key, Default) -> + Params = lookup0(VHost, Component, Key, + fun () -> + lookup_missing(VHost, Component, Key, Default) + end), Params#runtime_parameters.value. -lookup0(Component, Key, DefaultFun) -> - case mnesia:dirty_read(?TABLE, {Component, Key}) of +lookup0(VHost, Component, Key, DefaultFun) -> + case mnesia:dirty_read(?TABLE, {VHost, Component, Key}) of [] -> DefaultFun(); [R] -> R end. -lookup_missing(Component, Key, Default) -> +lookup_missing(VHost, Component, Key, Default) -> rabbit_misc:execute_mnesia_transaction( fun () -> - case mnesia:read(?TABLE, {Component, Key}, read) of - [] -> Record = c(Component, Key, Default), + case mnesia:read(?TABLE, {VHost, Component, Key}, read) of + [] -> Record = c(VHost, Component, Key, Default), mnesia:write(?TABLE, Record, write), Record; [R] -> R end end). -c(Component, Key, Default) -> #runtime_parameters{key = {Component, Key}, - value = Default}. +c(VHost, Component, Key, Default) -> + #runtime_parameters{key = {VHost, Component, Key}, + value = Default}. -p(#runtime_parameters{key = {Component, Key}, value = Value}) -> - [{component, Component}, +p(#runtime_parameters{key = {VHost, Component, Key}, value = Value}) -> + [{vhost, VHost}, + {component, Component}, {key, Key}, {value, Value}]. @@ -182,6 +200,12 @@ info_keys() -> [component, key, value]. %%--------------------------------------------------------------------------- +component_good('_') -> true; +component_good(Component) -> case lookup_component(Component) of + {ok, _} -> true; + _ -> false + end. + lookup_component(Component) -> case rabbit_registry:lookup_module( runtime_parameter, list_to_atom(binary_to_list(Component))) of diff --git a/src/rabbit_runtime_parameters_test.erl b/src/rabbit_runtime_parameters_test.erl index f23b3227..5224ccaa 100644 --- a/src/rabbit_runtime_parameters_test.erl +++ b/src/rabbit_runtime_parameters_test.erl @@ -17,7 +17,7 @@ -module(rabbit_runtime_parameters_test). -behaviour(rabbit_runtime_parameter). --export([validate/3, validate_clear/2, notify/3, notify_clear/2]). +-export([validate/4, validate_clear/3, notify/4, notify_clear/3]). -export([register/0, unregister/0]). register() -> @@ -26,13 +26,13 @@ register() -> unregister() -> rabbit_registry:unregister(runtime_parameter, <<"test">>). -validate(<<"test">>, <<"good">>, _Term) -> ok; -validate(<<"test">>, <<"maybe">>, <<"good">>) -> ok; -validate(<<"test">>, _, _) -> {error, "meh", []}. +validate(_, <<"test">>, <<"good">>, _Term) -> ok; +validate(_, <<"test">>, <<"maybe">>, <<"good">>) -> ok; +validate(_, <<"test">>, _, _) -> {error, "meh", []}. -validate_clear(<<"test">>, <<"good">>) -> ok; -validate_clear(<<"test">>, <<"maybe">>) -> ok; -validate_clear(<<"test">>, _) -> {error, "meh", []}. +validate_clear(_, <<"test">>, <<"good">>) -> ok; +validate_clear(_, <<"test">>, <<"maybe">>) -> ok; +validate_clear(_, <<"test">>, _) -> {error, "meh", []}. -notify(_, _, _) -> ok. -notify_clear(_, _) -> ok. +notify(_, _, _, _) -> ok. +notify_clear(_, _, _) -> ok. diff --git a/src/rabbit_vhost.erl b/src/rabbit_vhost.erl index 5548ef6d..03dfbe24 100644 --- a/src/rabbit_vhost.erl +++ b/src/rabbit_vhost.erl @@ -90,12 +90,13 @@ delete(VHostPath) -> R. internal_delete(VHostPath) -> - lists:foreach( - fun (Info) -> - ok = rabbit_auth_backend_internal:clear_permissions( - proplists:get_value(user, Info), VHostPath) - end, - rabbit_auth_backend_internal:list_vhost_permissions(VHostPath)), + [ok = rabbit_auth_backend_internal:clear_permissions( + proplists:get_value(user, Info), VHostPath) + || Info <- rabbit_auth_backend_internal:list_vhost_permissions(VHostPath)], + [ok = rabbit_runtime_parameters:clear(VHostPath, + proplists:get_value(component, Info), + proplists:get_value(key, Info)) + || Info <- rabbit_runtime_parameters:list(VHostPath)], ok = mnesia:delete({rabbit_vhost, VHostPath}), ok. |