summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEmile Joubert <emile@rabbitmq.com>2012-10-09 15:44:47 +0100
committerEmile Joubert <emile@rabbitmq.com>2012-10-09 15:44:47 +0100
commit3b6b74c13ebd0490ccfe85e7a1c25d22bd1dd598 (patch)
treefec7a51b6be6290c1b730c3e11fc16713c7449f0 /src
parentc0db9df803e28355acf8978923061473e0f302fe (diff)
downloadrabbitmq-server-3b6b74c13ebd0490ccfe85e7a1c25d22bd1dd598.tar.gz
Simpler policy interface
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_control_main.erl9
-rw-r--r--src/rabbit_runtime_parameters.erl26
2 files changed, 25 insertions, 10 deletions
diff --git a/src/rabbit_control_main.erl b/src/rabbit_control_main.erl
index 15fa1fd5..473f4237 100644
--- a/src/rabbit_control_main.erl
+++ b/src/rabbit_control_main.erl
@@ -462,11 +462,14 @@ action(list_parameters, Node, [], Opts, Inform) ->
rpc_call(Node, rabbit_runtime_parameters, list_formatted, [VHostArg]),
rabbit_runtime_parameters:info_keys());
-action(set_policy, Node, [Key, Value], Opts, Inform) ->
+action(set_policy, Node, [Key, Pattern, Defn], Opts, Inform) ->
+ action(set_policy, Node, [Key, Pattern, Defn, default], Opts, Inform);
+
+action(set_policy, Node, [Key, Pattern, Defn, Priority], Opts, Inform) ->
VHostArg = list_to_binary(proplists:get_value(?VHOST_OPT, Opts)),
- Inform("Setting policy ~p to ~p", [Key, Value]),
+ Inform("Setting policy ~p to ~p", [Key, Defn]),
rpc_call(Node, rabbit_runtime_parameters, parse_set_policy,
- [VHostArg, list_to_binary(Key), Value]);
+ [VHostArg, list_to_binary(Key), Pattern, Defn, Priority]);
action(clear_policy, Node, [Key], Opts, Inform) ->
VHostArg = list_to_binary(proplists:get_value(?VHOST_OPT, Opts)),
diff --git a/src/rabbit_runtime_parameters.erl b/src/rabbit_runtime_parameters.erl
index 51ccab89..f814e0f0 100644
--- a/src/rabbit_runtime_parameters.erl
+++ b/src/rabbit_runtime_parameters.erl
@@ -18,7 +18,7 @@
-include("rabbit.hrl").
--export([parse_set/4, parse_set_policy/3, set/4, set_policy/3, clear/3,
+-export([parse_set/4, parse_set_policy/5, set/4, set_policy/3, clear/3,
clear_policy/2, list/0, list/1, list_strict/1, list/2, list_strict/2,
list_policies/0, list_policies/1, list_formatted/1,
list_formatted_policies/1, lookup/3, value/3, value/4, info_keys/0]).
@@ -31,8 +31,8 @@
-spec(parse_set/4 :: (rabbit_types:vhost(), binary(), binary(), string())
-> ok_or_error_string()).
--spec(parse_set_policy/3 :: (rabbit_types:vhost(), binary(), string())
- -> ok_or_error_string()).
+-spec(parse_set_policy/5 :: (rabbit_types:vhost(), binary(), string(), string(),
+ string()) -> ok_or_error_string()).
-spec(set/4 :: (rabbit_types:vhost(), binary(), binary(), term())
-> ok_or_error_string()).
-spec(set_policy/3 :: (rabbit_types:vhost(), binary(), term())
@@ -74,11 +74,23 @@ parse_set(VHost, Component, Key, String) ->
error -> {error_string, "JSON decoding error"}
end.
-parse_set_policy(VHost, Key, String) ->
- case rabbit_misc:json_decode(String) of
+parse_set_policy(VHost, Key, Pat, Defn, default) ->
+ parse_set_policy0(VHost, Key, Pat, Defn, []);
+parse_set_policy(VHost, Key, Pat, Defn, Priority) ->
+ try list_to_integer(Priority) of
+ Num -> parse_set_policy0(VHost, Key, Pat, Defn, [{<<"priority">>, Num}])
+ catch
+ _:_ -> {error, "~p priority must be a number", [Priority]}
+ end.
+
+parse_set_policy0(VHost, Key, Pattern, Defn, Priority) ->
+ case rabbit_misc:json_decode(Defn) of
{ok, JSON} ->
- set_policy(VHost, Key, rabbit_misc:json_to_term(JSON));
- error ->
+ set_policy(VHost, Key, pset(<<"pattern">>, list_to_binary(Pattern),
+ pset(<<"policy">>,
+ rabbit_misc:json_to_term(JSON),
+ Priority)),
+ error ->
{error_string, "JSON decoding error"}
end.