diff options
author | Emile Joubert <emile@rabbitmq.com> | 2012-10-08 18:03:15 +0100 |
---|---|---|
committer | Emile Joubert <emile@rabbitmq.com> | 2012-10-08 18:03:15 +0100 |
commit | 939f5a70e3f855bdec85730a579ebd8a745b27fd (patch) | |
tree | 83c42896eb49fcf669354be061d55a2c9fc2187e /src | |
parent | 4e8e0fa18061a09a074e7975fd39a4003cb9b8ca (diff) | |
download | rabbitmq-server-939f5a70e3f855bdec85730a579ebd8a745b27fd.tar.gz |
Policy validation updates
Diffstat (limited to 'src')
-rw-r--r-- | src/rabbit_mirror_queue_misc.erl | 2 | ||||
-rw-r--r-- | src/rabbit_policy.erl | 7 | ||||
-rw-r--r-- | src/rabbit_runtime_parameters.erl | 21 | ||||
-rw-r--r-- | src/rabbit_runtime_parameters_test.erl | 6 |
4 files changed, 20 insertions, 16 deletions
diff --git a/src/rabbit_mirror_queue_misc.erl b/src/rabbit_mirror_queue_misc.erl index f02308a1..f0c555c9 100644 --- a/src/rabbit_mirror_queue_misc.erl +++ b/src/rabbit_mirror_queue_misc.erl @@ -352,7 +352,7 @@ validate_policy(TagList) -> [length(X)]} end; [_, _|_] -> - {error, "ha-mode may appear once at most", []}; + {error, "ha-mode may appear at most once", []}; [Other] -> {error, "~p is not a valid ha-mode value", [Other]} end. diff --git a/src/rabbit_policy.erl b/src/rabbit_policy.erl index 5540de83..cc9e05c5 100644 --- a/src/rabbit_policy.erl +++ b/src/rabbit_policy.erl @@ -83,7 +83,7 @@ notify_clear(VHost, <<"policy">>, _Name) -> list(VHost) -> [[{<<"name">>, pget(key, P)} | pget(value, P)] - || P <- rabbit_runtime_parameters:list(VHost, <<"policy">>)]. + || P <- rabbit_runtime_parameters:list_policies(VHost)]. update_policies(VHost) -> Policies = list(VHost), @@ -144,10 +144,7 @@ validation(_Name, []) -> validation(_Name, Terms) when is_list(Terms) -> {Tags, Modules} = lists:unzip( rabbit_registry:lookup_all(policy_validator)), - case lists:usort(Tags -- lists:usort(Tags)) of - [] -> ok; - Dup -> rabbit_log:warning("Duplicate policy validators: ~p~n", [Dup]) - end, + [] = lists:usort(Tags -- lists:usort(Tags)), %% ASSERTION Validators = lists:zipwith(fun (M, T) -> {M, a2b(T)} end, Modules, Tags), case lists:foldl( fun (_, {Error, _} = Acc) when Error /= ok -> diff --git a/src/rabbit_runtime_parameters.erl b/src/rabbit_runtime_parameters.erl index 70428e96..51ccab89 100644 --- a/src/rabbit_runtime_parameters.erl +++ b/src/rabbit_runtime_parameters.erl @@ -20,8 +20,8 @@ -export([parse_set/4, parse_set_policy/3, set/4, set_policy/3, clear/3, clear_policy/2, list/0, list/1, list_strict/1, list/2, list_strict/2, - list_formatted/1, list_formatted_policies/1, lookup/3, value/3, - value/4, info_keys/0]). + list_policies/0, list_policies/1, list_formatted/1, + list_formatted_policies/1, lookup/3, value/3, value/4, info_keys/0]). %%---------------------------------------------------------------------------- @@ -160,13 +160,16 @@ mnesia_clear(VHost, Component, Key) -> end). list() -> - [p(P) || P <- rabbit_misc:dirty_read_all(?TABLE)]. + [p(P) || #runtime_parameters{ key = {_VHost, Comp, _Key}} = P <- + rabbit_misc:dirty_read_all(?TABLE), Comp /= <<"policy">>]. 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, <<"policy">>, _Default) -> + {error, "policies may not be listed using this method"}; list(VHost, Component, Default) -> case component_good(Component) of true -> Match = #runtime_parameters{key = {VHost, Component, '_'}, @@ -175,13 +178,19 @@ list(VHost, Component, Default) -> _ -> Default end. +list_policies() -> + list_policies('_'). + +list_policies(VHost) -> + Match = #runtime_parameters{key = {VHost, <<"policy">>, '_'}, _ = '_'}, + [p(P) || P <- mnesia:dirty_match_object(?TABLE, Match)]. + list_formatted(VHost) -> - [pset(value, format(pget(value, P)), P) - || P <- list(VHost), pget(component, P) /= <<"policy">>]. + [pset(value, format(pget(value, P)), P) || P <- list(VHost)]. list_formatted_policies(VHost) -> [proplists:delete(component, pset(value, format(pget(value, P)), P)) - || P <- list(VHost), pget(component, P) == <<"policy">>]. + || P <- list_policies(VHost)]. lookup(VHost, Component, Key) -> case lookup0(VHost, Component, Key, rabbit_misc:const(not_found)) of diff --git a/src/rabbit_runtime_parameters_test.erl b/src/rabbit_runtime_parameters_test.erl index b39a98bc..44ae4d0f 100644 --- a/src/rabbit_runtime_parameters_test.erl +++ b/src/rabbit_runtime_parameters_test.erl @@ -68,10 +68,8 @@ validate_policy([{Tag1, Arg1}, {Tag2, Arg2}]) when is_list(Arg1), is_list(Arg2) -> case [Tag1, Tag2] -- [<<"testpos">>, <<"testeven">>] of [] -> - case {lists:all(fun (N) -> - is_integer(N) andalso - N > 0 - end, Arg1 ++ Arg2), + case {lists:all(fun (N) -> is_integer(N) andalso N > 0 end, + Arg1 ++ Arg2), length(Arg1) rem 2, length(Arg2) rem 2} of {true, 0, 0} -> ok; _ -> {error, "meh", []} |