Repository: couchdb-setup Updated Branches: refs/heads/593-setup-single-node 92dd9d10b -> f70f244b5
address comments from rnewson Project: http://git-wip-us.apache.org/repos/asf/couchdb-setup/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-setup/commit/f70f244b Tree: http://git-wip-us.apache.org/repos/asf/couchdb-setup/tree/f70f244b Diff: http://git-wip-us.apache.org/repos/asf/couchdb-setup/diff/f70f244b Branch: refs/heads/593-setup-single-node Commit: f70f244b5426f3ef50cb2d23c03f002fca77bbbb Parents: 92dd9d1 Author: Joan Touzet <[email protected]> Authored: Tue Jul 11 16:04:46 2017 -0700 Committer: Joan Touzet <[email protected]> Committed: Tue Jul 11 16:04:46 2017 -0700 ---------------------------------------------------------------------- src/setup.erl | 47 ++++++++++++++++++++--------------------------- src/setup_httpd.erl | 36 ++++++++++++++++++------------------ 2 files changed, 38 insertions(+), 45 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/f70f244b/src/setup.erl ---------------------------------------------------------------------- diff --git a/src/setup.erl b/src/setup.erl index 7aeac3e..fc2c22e 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,10 +202,8 @@ 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), @@ -227,9 +220,9 @@ enable_single_node(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(), http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/f70f244b/src/setup_httpd.erl ---------------------------------------------------------------------- diff --git a/src/setup_httpd.erl b/src/setup_httpd.erl index a5a8157..a9cbfe8 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").
