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 /src | |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/rabbit_policy.erl | 32 | ||||
-rw-r--r-- | src/rabbit_runtime_parameters.erl | 85 |
2 files changed, 59 insertions, 58 deletions
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]. %%--------------------------------------------------------------------------- |