summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoan Touzet <wohali@apache.org>2017-07-11 16:04:46 -0700
committerJoan Touzet <wohali@apache.org>2017-07-11 16:56:44 -0700
commite153d485b6b195054c87bbfcca1c2a5f54d979eb (patch)
tree9d6f69a27d275deff35d721989a14890e329762d
parent92dd9d10b6d3f94bf3295fd85bcc0375e8298828 (diff)
downloadcouchdb-e153d485b6b195054c87bbfcca1c2a5f54d979eb.tar.gz
address comments from rnewson
-rw-r--r--src/setup.erl56
-rw-r--r--src/setup_httpd.erl36
2 files changed, 40 insertions, 52 deletions
diff --git a/src/setup.erl b/src/setup.erl
index 7aeac3ec5..0d1710947 100644
--- a/src/setup.erl
+++ b/src/setup.erl
@@ -45,9 +45,9 @@ is_cluster_enabled() ->
BindAddress = config:get("chttpd", "bind_address"),
Admins = config:get("admins"),
case {BindAddress, Admins} of
- {"127.0.0.1", _} -> no;
- {_,[]} -> no;
- {_,_} -> ok
+ {"127.0.0.1", _} -> false;
+ {_,[]} -> false;
+ {_,_} -> true
end.
is_single_node_enabled(Dbs) ->
@@ -55,9 +55,9 @@ is_single_node_enabled(Dbs) ->
Admins = config:get("admins"),
HasDbs = has_cluster_system_dbs(Dbs),
case {Admins, HasDbs} of
- {[], _} -> no;
- {_, no} -> no;
- {_,_} -> ok
+ {[], _} -> false;
+ {_, false} -> false;
+ {_,_} -> true
end.
cluster_system_dbs() ->
@@ -65,11 +65,11 @@ cluster_system_dbs() ->
has_cluster_system_dbs([]) ->
- ok;
+ true;
has_cluster_system_dbs([Db|Dbs]) ->
case catch fabric:get_db_info(Db) of
{ok, _} -> has_cluster_system_dbs(Dbs);
- _ -> no
+ _ -> false
end.
enable_cluster(Options) ->
@@ -126,9 +126,9 @@ enable_cluster_http(Options) ->
{error, Else}
end.
-enable_cluster_int(_Options, ok) ->
+enable_cluster_int(_Options, true) ->
{error, cluster_enabled};
-enable_cluster_int(Options, no) ->
+enable_cluster_int(Options, false) ->
% if no admin in config and no admin in req -> error
CurrentAdmins = config:get("admins"),
@@ -140,26 +140,26 @@ enable_cluster_int(Options, no) ->
end
},
ok = require_admins(CurrentAdmins, NewCredentials),
-
% if bind_address == 127.0.0.1 and no bind_address in req -> error
CurrentBindAddress = config:get("chttpd","bind_address"),
NewBindAddress = proplists:get_value(bind_address, Options),
ok = require_bind_address(CurrentBindAddress, NewBindAddress),
-
NodeCount = couch_util:get_value(node_count, Options),
ok = require_node_count(NodeCount),
-
Port = proplists:get_value(port, Options),
setup_node(NewCredentials, NewBindAddress, NodeCount, Port),
couch_log:notice("Enable Cluster: ~p~n", [Options]).
+set_admin(Username, Password) ->
+ config:set("admins", binary_to_list(Username), binary_to_list(Password)).
+
setup_node(NewCredentials, NewBindAddress, NodeCount, Port) ->
case NewCredentials of
{undefined, undefined} ->
ok;
{Username, Password} ->
- config:set("admins", binary_to_list(Username), binary_to_list(Password))
+ set_admin(Username, Password)
end,
case NewBindAddress of
@@ -182,17 +182,12 @@ setup_node(NewCredentials, NewBindAddress, NodeCount, Port) ->
finish_cluster(Options) ->
- Dbs = proplists:get_value(ensure_dbs_exist, Options),
- case Dbs of
- undefined ->
- finish_cluster_int(cluster_system_dbs(), has_cluster_system_dbs(cluster_system_dbs()));
- Dbs ->
- finish_cluster_int(Dbs, has_cluster_system_dbs(Dbs))
- end.
+ Dbs = proplists:get_value(ensure_dbs_exist, Options, cluster_system_dbs()),
+ finish_cluster_int(Dbs, has_cluster_system_dbs(Dbs)).
-finish_cluster_int(_Dbs, ok) ->
+finish_cluster_int(_Dbs, true) ->
{error, cluster_finished};
-finish_cluster_int(Dbs, no) ->
+finish_cluster_int(Dbs, false) ->
lists:foreach(fun fabric:create_db/1, Dbs).
@@ -207,29 +202,22 @@ enable_single_node(Options) ->
end
},
ok = require_admins(CurrentAdmins, NewCredentials),
-
% skip bind_address validation, anything is fine
NewBindAddress = proplists:get_value(bind_address, Options),
-
Port = proplists:get_value(port, Options),
setup_node(NewCredentials, NewBindAddress, 1, Port),
- Dbs = proplists:get_value(ensure_dbs_exist, Options),
- case Dbs of
- undefined ->
- finish_cluster_int(cluster_system_dbs(), has_cluster_system_dbs(cluster_system_dbs()));
- Dbs ->
- finish_cluster_int(Dbs, has_cluster_system_dbs(Dbs))
- end,
+ Dbs = proplists:get_value(ensure_dbs_exist, Options, cluster_system_dbs()),
+ finish_cluster_int(Dbs, has_cluster_system_dbs(Dbs))
couch_log:notice("Enable Single Node: ~p~n", [Options]).
add_node(Options) ->
add_node_int(Options, is_cluster_enabled()).
-add_node_int(_Options, no) ->
+add_node_int(_Options, false) ->
{error, cluster_not_enabled};
-add_node_int(Options, ok) ->
+add_node_int(Options, true) ->
couch_log:notice("add node_int: ~p~n", [Options]),
ErlangCookie = erlang:get_cookie(),
diff --git a/src/setup_httpd.erl b/src/setup_httpd.erl
index a5a8157c8..a9cbfe822 100644
--- a/src/setup_httpd.erl
+++ b/src/setup_httpd.erl
@@ -32,25 +32,25 @@ handle_setup_req(#httpd{method='GET'}=Req) ->
Dbs = chttpd:qs_json_value(Req, "ensure_dbs_exist", setup:cluster_system_dbs()),
couch_log:notice("Dbs: ~p~n", [Dbs]),
case erlang:list_to_integer(config:get("cluster", "n", undefined)) of
- 1 ->
- case setup:is_single_node_enabled(Dbs) of
- no ->
- chttpd:send_json(Req, 200, {[{state, single_node_disabled}]});
- ok ->
- chttpd:send_json(Req, 200, {[{state, single_node_enabled}]})
- end;
- _ ->
- case setup:is_cluster_enabled() of
- no ->
- chttpd:send_json(Req, 200, {[{state, cluster_disabled}]});
- ok ->
- case setup:has_cluster_system_dbs(Dbs) of
- no ->
- chttpd:send_json(Req, 200, {[{state, cluster_enabled}]});
- ok ->
- chttpd:send_json(Req, 200, {[{state, cluster_finished}]})
+ 1 ->
+ case setup:is_single_node_enabled(Dbs) of
+ false ->
+ chttpd:send_json(Req, 200, {[{state, single_node_disabled}]});
+ true ->
+ chttpd:send_json(Req, 200, {[{state, single_node_enabled}]})
+ end;
+ _ ->
+ case setup:is_cluster_enabled() of
+ false ->
+ chttpd:send_json(Req, 200, {[{state, cluster_disabled}]});
+ true ->
+ case setup:has_cluster_system_dbs(Dbs) of
+ false ->
+ chttpd:send_json(Req, 200, {[{state, cluster_enabled}]});
+ true ->
+ chttpd:send_json(Req, 200, {[{state, cluster_finished}]})
+ end
end
- end
end;
handle_setup_req(#httpd{}=Req) ->
chttpd:send_method_not_allowed(Req, "GET,POST").