diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2012-10-22 15:05:49 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2012-10-22 15:05:49 +0100 |
commit | 1400865c9a9b996b9137953ed882fc41d7c0dc64 (patch) | |
tree | e5ff9d19a3222065b5c37359497d3773f684ae59 | |
parent | 3cd89a4583d5e06d8a6cd08f50512736aa66e96b (diff) | |
download | rabbitmq-server-bug25142.tar.gz |
s/key/name/, and a couple of other minor tidyups that I noticed at the same time.bug25142
-rw-r--r-- | docs/rabbitmqctl.1.xml | 34 | ||||
-rw-r--r-- | src/rabbit_policy.erl | 32 | ||||
-rw-r--r-- | src/rabbit_runtime_parameters.erl | 85 |
3 files changed, 76 insertions, 75 deletions
diff --git a/docs/rabbitmqctl.1.xml b/docs/rabbitmqctl.1.xml index 522a51ee..53411d8b 100644 --- a/docs/rabbitmqctl.1.xml +++ b/docs/rabbitmqctl.1.xml @@ -806,8 +806,8 @@ 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, and is - associated with a virtual host. The component name and key are + consists of a component name, a name and a value, and is + associated with a virtual host. The component name and name 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 @@ -815,7 +815,7 @@ </para> <variablelist> <varlistentry> - <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> + <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>name</replaceable></arg> <arg choice="req"><replaceable>value</replaceable></arg></cmdsynopsis></term> <listitem> <para> Sets a parameter. @@ -829,24 +829,24 @@ </para></listitem> </varlistentry> <varlistentry> - <term>key</term> + <term>name</term> <listitem><para> - The key for which the parameter is being set. + The name of the parameter being set. </para></listitem> </varlistentry> <varlistentry> <term>value</term> <listitem><para> - The value for the parameter, as an - Erlang term. In most shells you are very likely to + The value for the parameter, as a + JSON term. In most shells you are very likely to need to quote this. </para></listitem> </varlistentry> </variablelist> <para role="example-prefix">For example:</para> - <screen role="example">rabbitmqctl set_parameter federation local_username '<<"guest">>'</screen> + <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 in the default virtual host 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 JSON term <command>"guest"</command>. </para> </listitem> </varlistentry> @@ -865,9 +865,9 @@ </para></listitem> </varlistentry> <varlistentry> - <term>key</term> + <term>name</term> <listitem><para> - The key for which the parameter is being cleared. + The name of the parameter being cleared. </para></listitem> </varlistentry> </variablelist> @@ -899,19 +899,19 @@ <para> Policies are used to control and modify the behaviour of queues and exchanges on a cluster-wide basis. Policies apply within a - given vhost, and consist of a key, pattern, definition and an + given vhost, and consist of a name, pattern, definition and an optional priority. Policies can be set, cleared and listed. </para> <variablelist> <varlistentry> - <term><cmdsynopsis><command>set_policy</command> <arg choice="opt">-p <replaceable>vhostpath</replaceable></arg> <arg choice="req"><replaceable>key</replaceable></arg> <arg choice="req"><replaceable>pattern</replaceable></arg> <arg choice="req"><replaceable>definition</replaceable></arg> <arg choice="opt"><replaceable>priority</replaceable></arg> </cmdsynopsis></term> + <term><cmdsynopsis><command>set_policy</command> <arg choice="opt">-p <replaceable>vhostpath</replaceable></arg> <arg choice="req"><replaceable>name</replaceable></arg> <arg choice="req"><replaceable>pattern</replaceable></arg> <arg choice="req"><replaceable>definition</replaceable></arg> <arg choice="opt"><replaceable>priority</replaceable></arg> </cmdsynopsis></term> <listitem> <para> Sets a policy. </para> <variablelist> <varlistentry> - <term>key</term> + <term>name</term> <listitem><para> The name of the policy. </para></listitem> @@ -926,7 +926,7 @@ <term>definition</term> <listitem><para> The definition of the policy, as a - JSON string. In most shells you are very likely to + JSON term. In most shells you are very likely to need to quote this. </para></listitem> </varlistentry> @@ -945,14 +945,14 @@ </listitem> </varlistentry> <varlistentry> - <term><cmdsynopsis><command>clear_policy</command> <arg choice="opt">-p <replaceable>vhostpath</replaceable></arg> <arg choice="req"><replaceable>key</replaceable></arg></cmdsynopsis></term> + <term><cmdsynopsis><command>clear_policy</command> <arg choice="opt">-p <replaceable>vhostpath</replaceable></arg> <arg choice="req"><replaceable>name</replaceable></arg></cmdsynopsis></term> <listitem> <para> Clears a policy. </para> <variablelist> <varlistentry> - <term>key</term> + <term>name</term> <listitem><para> The name of the policy being cleared. </para></listitem> diff --git a/src/rabbit_policy.erl b/src/rabbit_policy.erl index 4dcce4e0..9af8fa18 100644 --- a/src/rabbit_policy.erl +++ b/src/rabbit_policy.erl @@ -67,19 +67,19 @@ get0(Name, List) -> case pget(definition, List) of %%---------------------------------------------------------------------------- -parse_set(VHost, Key, Pattern, Definition, undefined) -> - parse_set0(VHost, Key, Pattern, Definition, 0); -parse_set(VHost, Key, Pattern, Definition, Priority) -> +parse_set(VHost, Name, Pattern, Definition, undefined) -> + parse_set0(VHost, Name, Pattern, Definition, 0); +parse_set(VHost, Name, Pattern, Definition, Priority) -> try list_to_integer(Priority) of - Num -> parse_set0(VHost, Key, Pattern, Definition, Num) + Num -> parse_set0(VHost, Name, Pattern, Definition, Num) catch error:badarg -> {error, "~p priority must be a number", [Priority]} end. -parse_set0(VHost, Key, Pattern, Defn, Priority) -> +parse_set0(VHost, Name, Pattern, Defn, Priority) -> case rabbit_misc:json_decode(Defn) of {ok, JSON} -> - set0(VHost, Key, + set0(VHost, Name, [{<<"pattern">>, list_to_binary(Pattern)}, {<<"definition">>, rabbit_misc:json_to_term(JSON)}, {<<"priority">>, Priority}]); @@ -87,23 +87,23 @@ parse_set0(VHost, Key, Pattern, Defn, Priority) -> {error_string, "JSON decoding error"} end. -set(VHost, Key, Pattern, Definition, Priority) -> +set(VHost, Name, Pattern, Definition, Priority) -> PolicyProps = [{<<"pattern">>, Pattern}, {<<"definition">>, Definition}, {<<"priority">>, case Priority of undefined -> 0; _ -> Priority end}], - set0(VHost, Key, PolicyProps). + set0(VHost, Name, PolicyProps). -set0(VHost, Key, Term) -> - rabbit_runtime_parameters:set_any(VHost, <<"policy">>, Key, Term). +set0(VHost, Name, Term) -> + rabbit_runtime_parameters:set_any(VHost, <<"policy">>, Name, Term). -delete(VHost, Key) -> - rabbit_runtime_parameters:clear_any(VHost, <<"policy">>, Key). +delete(VHost, Name) -> + rabbit_runtime_parameters:clear_any(VHost, <<"policy">>, Name). -lookup(VHost, Key) -> - case rabbit_runtime_parameters:lookup(VHost, <<"policy">>, Key) of +lookup(VHost, Name) -> + case rabbit_runtime_parameters:lookup(VHost, <<"policy">>, Name) of not_found -> not_found; P -> p(P, fun ident/1) end. @@ -127,7 +127,7 @@ order_policies(PropList) -> p(Parameter, DefnFun) -> Value = pget(value, Parameter), [{vhost, pget(vhost, Parameter)}, - {key, pget(key, Parameter)}, + {name, pget(name, Parameter)}, {pattern, pget(<<"pattern">>, Value)}, {definition, DefnFun(pget(<<"definition">>, Value))}, {priority, pget(<<"priority">>, Value)}]. @@ -138,7 +138,7 @@ format(Term) -> ident(X) -> X. -info_keys() -> [vhost, key, pattern, definition, priority]. +info_keys() -> [vhost, name, pattern, definition, priority]. %%---------------------------------------------------------------------------- diff --git a/src/rabbit_runtime_parameters.erl b/src/rabbit_runtime_parameters.erl index 3ee93fa1..4a83e61f 100644 --- a/src/rabbit_runtime_parameters.erl +++ b/src/rabbit_runtime_parameters.erl @@ -63,34 +63,35 @@ parse_set(_, <<"policy">>, _, _) -> {error_string, "policies may not be set using this method"}; -parse_set(VHost, Component, Key, String) -> +parse_set(VHost, Component, Name, String) -> case rabbit_misc:json_decode(String) of - {ok, JSON} -> set(VHost, Component, Key, rabbit_misc:json_to_term(JSON)); + {ok, JSON} -> set(VHost, Component, Name, + rabbit_misc:json_to_term(JSON)); error -> {error_string, "JSON decoding error"} end. set(_, <<"policy">>, _, _) -> {error_string, "policies may not be set using this method"}; -set(VHost, Component, Key, Term) -> - set_any(VHost, Component, Key, Term). +set(VHost, Component, Name, Term) -> + set_any(VHost, Component, Name, Term). format_error(L) -> {error_string, rabbit_misc:format_many([{"Validation failed~n", []} | L])}. -set_any(VHost, Component, Key, Term) -> - case set_any0(VHost, Component, Key, Term) of +set_any(VHost, Component, Name, Term) -> + case set_any0(VHost, Component, Name, Term) of ok -> ok; {errors, L} -> format_error(L) end. -set_any0(VHost, Component, Key, Term) -> +set_any0(VHost, Component, Name, Term) -> case lookup_component(Component) of {ok, Mod} -> - case flatten_errors(Mod:validate(VHost, Component, Key, Term)) of + case flatten_errors(Mod:validate(VHost, Component, Name, Term)) of ok -> - case mnesia_update(VHost, Component, Key, Term) of + case mnesia_update(VHost, Component, Name, Term) of {old, Term} -> ok; - _ -> Mod:notify(VHost, Component, Key, Term) + _ -> Mod:notify(VHost, Component, Name, Term) end, ok; E -> @@ -100,48 +101,48 @@ set_any0(VHost, Component, Key, Term) -> E end. -mnesia_update(VHost, Component, Key, Term) -> +mnesia_update(VHost, Component, Name, Term) -> rabbit_misc:execute_mnesia_transaction( fun () -> - Res = case mnesia:read(?TABLE, {VHost, Component, Key}, read) of + Res = case mnesia:read(?TABLE, {VHost, Component, Name}, read) of [] -> new; [Params] -> {old, Params#runtime_parameters.value} end, - ok = mnesia:write(?TABLE, c(VHost, Component, Key, Term), write), + ok = mnesia:write(?TABLE, c(VHost, Component, Name, Term), write), Res end). clear(_, <<"policy">> , _) -> {error_string, "policies may not be cleared using this method"}; -clear(VHost, Component, Key) -> - clear_any(VHost, Component, Key). +clear(VHost, Component, Name) -> + clear_any(VHost, Component, Name). -clear_any(VHost, Component, Key) -> - case clear_any0(VHost, Component, Key) of +clear_any(VHost, Component, Name) -> + case clear_any0(VHost, Component, Name) of ok -> ok; {errors, L} -> format_error(L) end. -clear_any0(VHost, Component, Key) -> +clear_any0(VHost, Component, Name) -> case lookup_component(Component) of {ok, Mod} -> case flatten_errors( - Mod:validate_clear(VHost, Component, Key)) of - ok -> mnesia_clear(VHost, Component, Key), - Mod:notify_clear(VHost, Component, Key), + Mod:validate_clear(VHost, Component, Name)) of + ok -> mnesia_clear(VHost, Component, Name), + Mod:notify_clear(VHost, Component, Name), ok; E -> E end; E -> E end. -mnesia_clear(VHost, Component, Key) -> +mnesia_clear(VHost, Component, Name) -> ok = rabbit_misc:execute_mnesia_transaction( fun () -> - ok = mnesia:delete(?TABLE, {VHost, Component, Key}, write) + ok = mnesia:delete(?TABLE, {VHost, Component, Name}, write) end). list() -> - [p(P) || #runtime_parameters{ key = {_VHost, Comp, _Key}} = P <- + [p(P) || #runtime_parameters{ key = {_VHost, Comp, _Name}} = P <- rabbit_misc:dirty_read_all(?TABLE), Comp /= <<"policy">>]. list(VHost) -> list(VHost, '_', []). @@ -153,7 +154,7 @@ list(VHost, Component, Default) -> case component_good(Component) of true -> Match = #runtime_parameters{key = {VHost, Component, '_'}, _ = '_'}, - [p(P) || #runtime_parameters{ key = {_VHost, Comp, _Key}} = P <- + [p(P) || #runtime_parameters{ key = {_VHost, Comp, _Name}} = P <- mnesia:dirty_match_object(?TABLE, Match), Comp =/= <<"policy">> orelse Component =:= <<"policy">>]; @@ -163,53 +164,53 @@ list(VHost, Component, Default) -> list_formatted(VHost) -> [pset(value, format(pget(value, P)), P) || P <- list(VHost)]. -lookup(VHost, Component, Key) -> - case lookup0(VHost, Component, Key, rabbit_misc:const(not_found)) of +lookup(VHost, Component, Name) -> + case lookup0(VHost, Component, Name, rabbit_misc:const(not_found)) of not_found -> not_found; Params -> p(Params) end. -value(VHost, Component, Key) -> - case lookup0(VHost, Component, Key, rabbit_misc:const(not_found)) of +value(VHost, Component, Name) -> + case lookup0(VHost, Component, Name, rabbit_misc:const(not_found)) of not_found -> not_found; Params -> Params#runtime_parameters.value end. -value(VHost, Component, Key, Default) -> - Params = lookup0(VHost, Component, Key, +value(VHost, Component, Name, Default) -> + Params = lookup0(VHost, Component, Name, fun () -> - lookup_missing(VHost, Component, Key, Default) + lookup_missing(VHost, Component, Name, Default) end), Params#runtime_parameters.value. -lookup0(VHost, Component, Key, DefaultFun) -> - case mnesia:dirty_read(?TABLE, {VHost, Component, Key}) of +lookup0(VHost, Component, Name, DefaultFun) -> + case mnesia:dirty_read(?TABLE, {VHost, Component, Name}) of [] -> DefaultFun(); [R] -> R end. -lookup_missing(VHost, Component, Key, Default) -> +lookup_missing(VHost, Component, Name, Default) -> rabbit_misc:execute_mnesia_transaction( fun () -> - case mnesia:read(?TABLE, {VHost, Component, Key}, read) of - [] -> Record = c(VHost, Component, Key, Default), + case mnesia:read(?TABLE, {VHost, Component, Name}, read) of + [] -> Record = c(VHost, Component, Name, Default), mnesia:write(?TABLE, Record, write), Record; [R] -> R end end). -c(VHost, Component, Key, Default) -> - #runtime_parameters{key = {VHost, Component, Key}, +c(VHost, Component, Name, Default) -> + #runtime_parameters{key = {VHost, Component, Name}, value = Default}. -p(#runtime_parameters{key = {VHost, Component, Key}, value = Value}) -> +p(#runtime_parameters{key = {VHost, Component, Name}, value = Value}) -> [{vhost, VHost}, {component, Component}, - {key, Key}, + {name, Name}, {value, Value}]. -info_keys() -> [component, key, value]. +info_keys() -> [component, name, value]. %%--------------------------------------------------------------------------- |