summaryrefslogtreecommitdiff
path: root/src/rabbit_runtime_parameters.erl
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2012-04-05 12:29:17 +0100
committerSimon MacMullen <simon@rabbitmq.com>2012-04-05 12:29:17 +0100
commit506218c2c232f83223ab70eb157939473dfba7f6 (patch)
treea17d9cae2cf98429cc5138924379e80a7a6c2f3d /src/rabbit_runtime_parameters.erl
parente1d4fcef58c6deec86b290523d395eb945a271c5 (diff)
downloadrabbitmq-server-506218c2c232f83223ab70eb157939473dfba7f6.tar.gz
We should validate clearing as well.
Diffstat (limited to 'src/rabbit_runtime_parameters.erl')
-rw-r--r--src/rabbit_runtime_parameters.erl58
1 files changed, 35 insertions, 23 deletions
diff --git a/src/rabbit_runtime_parameters.erl b/src/rabbit_runtime_parameters.erl
index 3e2788c0..fd240fa7 100644
--- a/src/rabbit_runtime_parameters.erl
+++ b/src/rabbit_runtime_parameters.erl
@@ -30,44 +30,56 @@
set(AppName, Key, Term) ->
case set0(AppName, Key, Term) of
ok -> ok;
- {errors, L} -> {error_string, rabbit_misc:format_many(
- [{"Validation failed~n", []} | L])}
+ {errors, L} -> format_error(L)
end.
+format_error(L) ->
+ {error_string, rabbit_misc:format_many([{"Validation failed~n", []} | L])}.
+
set0(AppName, Key, Term) ->
case lookup_app(AppName) of
- {ok, Module} -> case flatten_errors(validate(Term)) of
- ok -> case flatten_errors(
- Module:validate(AppName, Key, Term)) of
- ok -> update(AppName, Key, Term),
- Module:notify(AppName, Key, Term),
- ok;
- E -> E
- end;
- E -> E
- end;
- E -> E
+ {ok, Mod} -> case flatten_errors(validate(Term)) of
+ ok -> case flatten_errors(
+ Mod:validate(AppName, Key, Term)) of
+ ok -> mnesia_update(AppName, Key, Term),
+ Mod:notify(AppName, Key, Term),
+ ok;
+ E -> E
+ end;
+ E -> E
+ end;
+ E -> E
end.
-update(AppName, Key, Term) ->
+mnesia_update(AppName, Key, Term) ->
ok = rabbit_misc:execute_mnesia_transaction(
fun () ->
ok = mnesia:write(?TABLE, c(AppName, Key, Term), write)
end).
clear(AppName, Key) ->
+ case clear0(AppName, Key) of
+ ok -> ok;
+ {errors, L} -> format_error(L)
+ end.
+
+clear0(AppName, Key) ->
case lookup_app(AppName) of
- {ok, Module} ->
- ok = rabbit_misc:execute_mnesia_transaction(
- fun () ->
- ok = mnesia:delete(?TABLE, {AppName, Key}, write)
- end),
- Module:notify_clear(AppName, Key),
- ok;
- E ->
- E
+ {ok, Mod} -> case flatten_errors(Mod:validate_clear(AppName, Key)) of
+ ok -> mnesia_clear(AppName, Key),
+ Mod:notify_clear(AppName, Key),
+ ok;
+ E -> E
+ end;
+ E -> E
end.
+mnesia_clear(AppName, Key) ->
+ ok = rabbit_misc:execute_mnesia_transaction(
+ fun () ->
+ ok = mnesia:delete(?TABLE, {AppName, Key}, write)
+ end).
+
list() ->
[p(P) || P <- rabbit_misc:dirty_read_all(?TABLE)].