summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/rabbit.hrl2
-rw-r--r--src/rabbit_cluster_config.erl64
-rw-r--r--src/rabbit_control.erl13
-rw-r--r--src/rabbit_mnesia.erl5
-rw-r--r--src/rabbit_upgrade_functions.erl8
5 files changed, 92 insertions, 0 deletions
diff --git a/include/rabbit.hrl b/include/rabbit.hrl
index faf3059ac7..517a701006 100644
--- a/include/rabbit.hrl
+++ b/include/rabbit.hrl
@@ -66,6 +66,8 @@
-record(listener, {node, protocol, host, ip_address, port}).
+-record(cluster_config, {key, value}).
+
-record(basic_message, {exchange_name, routing_keys = [], content, id,
is_persistent}).
diff --git a/src/rabbit_cluster_config.erl b/src/rabbit_cluster_config.erl
new file mode 100644
index 0000000000..55db588256
--- /dev/null
+++ b/src/rabbit_cluster_config.erl
@@ -0,0 +1,64 @@
+%% The contents of this file are subject to the Mozilla Public License
+%% Version 1.1 (the "License"); you may not use this file except in
+%% compliance with the License. You may obtain a copy of the License
+%% at http://www.mozilla.org/MPL/
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and
+%% limitations under the License.
+%%
+%% The Original Code is RabbitMQ.
+%%
+%% The Initial Developer of the Original Code is VMware, Inc.
+%% Copyright (c) 2007-2012 VMware, Inc. All rights reserved.
+%%
+
+-module(rabbit_cluster_config).
+
+-include("rabbit.hrl").
+
+-export([set/3, clear/2, list/0, info_keys/0]).
+
+%%---------------------------------------------------------------------------
+
+set(AppName, Key, Value) ->
+ rabbit_misc:execute_mnesia_transaction(
+ fun () ->
+ ok = mnesia:write(
+ rabbit_cluster_config,
+ #cluster_config{key = {AppName, Key},
+ value = parse(Value)},
+ write)
+ end).
+
+clear(AppName, Key) ->
+ rabbit_misc:execute_mnesia_transaction(
+ fun () ->
+ ok = mnesia:delete(rabbit_cluster_config, {AppName, Key}, write)
+ end).
+
+list() ->
+ All = rabbit_misc:dirty_read_all(rabbit_cluster_config),
+ [[{app_name, AppName},
+ {key, Key},
+ {value, Value}] || #cluster_config{key = {AppName, Key},
+ value = Value} <- All].
+
+info_keys() -> [app_name, key, value].
+
+parse(Bin) ->
+ case erl_scan:string(binary_to_list(Bin)) of
+ {ok, Scanned, _} ->
+ case erl_parse:parse_term(Scanned) of
+ {ok, Parsed} ->
+ Parsed;
+ {error, E} ->
+ exit({could_not_parse_value, format_parse_error(E)})
+ end;
+ {error, E, _} ->
+ exit({could_not_scan_value, format_parse_error(E)})
+ end.
+
+format_parse_error({_Line, Mod, Err}) ->
+ lists:flatten(Mod:format_error(Err)).
diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl
index 6a775adfb0..8b3974e778 100644
--- a/src/rabbit_control.erl
+++ b/src/rabbit_control.erl
@@ -267,6 +267,19 @@ action(list_user_permissions, Node, Args = [_Username], _Opts, Inform) ->
list_user_permissions, Args}),
rabbit_auth_backend_internal:user_perms_info_keys());
+action(set_config_item, Node, Args = [AppName, Key, Value], _Opts, Inform) ->
+ Inform("Setting config item ~p for app ~p to ~p", [Key, AppName, Value]),
+ call(Node, {rabbit_cluster_config, set, Args});
+
+action(clear_config_item, Node, Args = [AppName, Key], _Opts, Inform) ->
+ Inform("Clearing config item ~p for app ~p", [Key, AppName]),
+ call(Node, {rabbit_cluster_config, clear, Args});
+
+action(list_config_items, Node, Args = [], _Opts, Inform) ->
+ Inform("Listing config items", []),
+ display_info_list(rpc_call(Node, rabbit_cluster_config, list, Args),
+ rabbit_cluster_config:info_keys());
+
action(list_queues, Node, Args, Opts, Inform) ->
Inform("Listing queues", []),
VHostArg = list_to_binary(proplists:get_value(?VHOST_OPT, Opts)),
diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl
index 4d419fd9a9..996d502c41 100644
--- a/src/rabbit_mnesia.erl
+++ b/src/rabbit_mnesia.erl
@@ -296,6 +296,11 @@ table_definitions() ->
[{record_name, exchange_serial},
{attributes, record_info(fields, exchange_serial)},
{match, #exchange_serial{name = exchange_name_match(), _='_'}}]},
+ {rabbit_cluster_config,
+ [{record_name, cluster_config},
+ {attributes, record_info(fields, cluster_config)},
+ {disc_copies, [node()]},
+ {match, #cluster_config{_='_'}}]},
{rabbit_durable_queue,
[{record_name, amqqueue},
{attributes, record_info(fields, amqqueue)},
diff --git a/src/rabbit_upgrade_functions.erl b/src/rabbit_upgrade_functions.erl
index 9f2535bd04..67ec151bb4 100644
--- a/src/rabbit_upgrade_functions.erl
+++ b/src/rabbit_upgrade_functions.erl
@@ -36,6 +36,7 @@
-rabbit_upgrade({exchange_scratch, mnesia, [trace_exchanges]}).
-rabbit_upgrade({mirrored_supervisor, mnesia, []}).
-rabbit_upgrade({topic_trie_node, mnesia, []}).
+-rabbit_upgrade({cluster_config, mnesia, []}).
%% -------------------------------------------------------------------
@@ -56,6 +57,7 @@
-spec(exchange_scratch/0 :: () -> 'ok').
-spec(mirrored_supervisor/0 :: () -> 'ok').
-spec(topic_trie_node/0 :: () -> 'ok').
+-spec(cluster_config/0 :: () -> 'ok').
-endif.
@@ -185,6 +187,12 @@ topic_trie_node() ->
{attributes, [trie_node, edge_count, binding_count]},
{type, ordered_set}]).
+cluster_config() ->
+ create(rabbit_cluster_config,
+ [{record_name, cluster_config},
+ {attributes, [key, value]},
+ {disc_copies, [node()]}]).
+
%%--------------------------------------------------------------------
transform(TableName, Fun, FieldList) ->