Skip to content

Commit

Permalink
See rabbitmq#7323. Rename default policy for ha-* and add option to m…
Browse files Browse the repository at this point in the history
…assage key/value for aggregate_props
  • Loading branch information
SimonUnge committed Feb 22, 2023
1 parent 232c7fa commit d66b38d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
12 changes: 9 additions & 3 deletions deps/rabbit/priv/schema/rabbit.schema
Original file line number Diff line number Diff line change
Expand Up @@ -743,16 +743,22 @@ end}.
{datatype, integer}
]}.

{mapping, "default_policies.operator.$id.ha_mode", "rabbit.default_policies.operator", [
{mapping, "default_policies.operator.$id.classic_queues.ha_mode", "rabbit.default_policies.operator", [
{datatype, string}
]}.

{mapping, "default_policies.operator.$id.ha_params", "rabbit.default_policies.operator", [
{mapping, "default_policies.operator.$id.classic_queues.ha_params", "rabbit.default_policies.operator", [
{datatype, [integer, {list, string}]}
]}.

{translation, "rabbit.default_policies.operator", fun(Conf) ->
Props = rabbit_cuttlefish:aggregate_props(Conf, ["default_policies", "operator"]),
Props = rabbit_cuttlefish:aggregate_props(
Conf,
["default_policies", "operator"],
fun({["default_policies","operator",ID,"classic_queues"|T], V}) ->
{["default_policies","operator",ID|T],V};
(E) -> E
end),
Props1 = lists:map(
fun({K, Ss}) ->
{K,
Expand Down
13 changes: 10 additions & 3 deletions deps/rabbit/src/rabbit_cuttlefish.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,28 @@
-module(rabbit_cuttlefish).

-export([
aggregate_props/2
aggregate_props/2,
aggregate_props/3
]).

-type keyed_props() :: [{binary(), [{binary(), any()}]}].

-spec aggregate_props([{string(), any()}], [string()]) ->
keyed_props().
aggregate_props(Conf, Prefix) ->
aggregate_props(Conf, Prefix, fun(E) -> E end).

-spec aggregate_props([{string(), any()}], [string()], function()) ->
keyed_props().
aggregate_props(Conf, Prefix, KeyFun) ->
Pattern = Prefix ++ ["$id", "$_"],
PrefixLen = length(Prefix),
FlatList = lists:filtermap(
fun({K, V}) ->
fun(E) ->
{K, V} = KeyFun(E),
case cuttlefish_variable:is_fuzzy_match(K, Pattern) of
true -> {true, {lists:nthtail(PrefixLen, K), V}};
_ -> false
false -> false
end
end,
Conf
Expand Down
4 changes: 4 additions & 0 deletions deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,13 @@ ssl_options.fail_if_no_peer_cert = true",
default_policies.operator.a.expires = 1h
default_policies.operator.a.queue_pattern = apple
default_policies.operator.a.vhost_pattern = banana
default_policies.operator.a.classic_queues.ha_mode = exactly
default_policies.operator.a.classic_queues.ha_params = 2
",
[{rabbit, [{default_policies, [{operator, [
{<<"a">>, [{<<"expires">>, 3600000},
{<<"ha-mode">>, "exactly"},
{<<"ha-params">>, 2},
{<<"queue-pattern">>, "apple"},
{<<"vhost-pattern">>, "banana"}]}]}]}]}],
[]},
Expand Down

0 comments on commit d66b38d

Please sign in to comment.