You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by wo...@apache.org on 2017/07/16 16:33:28 UTC

[1/7] couchdb-setup git commit: Add support for new ensure_dbs_exist option to GET, POST/finish_cluster

Repository: couchdb-setup
Updated Branches:
  refs/heads/master c38d7aab0 -> 4d9bd589f


Add support for new ensure_dbs_exist option to GET, POST/finish_cluster

Addresses apache/couchdb:593


Project: http://git-wip-us.apache.org/repos/asf/couchdb-setup/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-setup/commit/18314a6d
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-setup/tree/18314a6d
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-setup/diff/18314a6d

Branch: refs/heads/master
Commit: 18314a6daa56a13f4b4e6f71ce61224a8940f925
Parents: c38d7aa
Author: Joan Touzet <wo...@apache.org>
Authored: Mon Jul 10 13:52:45 2017 -0700
Committer: Joan Touzet <wo...@apache.org>
Committed: Mon Jul 10 13:52:45 2017 -0700

----------------------------------------------------------------------
 .gitignore          |  2 ++
 src/setup.erl       | 24 ++++++++++++++----------
 src/setup_httpd.erl |  9 +++++++--
 3 files changed, 23 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/18314a6d/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 1dbfa4b..f84f14c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
 ebin
 .rebar
+*~
+*.swp

http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/18314a6d/src/setup.erl
----------------------------------------------------------------------
diff --git a/src/setup.erl b/src/setup.erl
index 5a71004..dd7410a 100644
--- a/src/setup.erl
+++ b/src/setup.erl
@@ -12,8 +12,8 @@
 
 -module(setup).
 
--export([enable_cluster/1, finish_cluster/0, add_node/1, receive_cookie/1]).
--export([is_cluster_enabled/0, has_cluster_system_dbs/0]).
+-export([enable_cluster/1, finish_cluster/1, add_node/1, receive_cookie/1]).
+-export([is_cluster_enabled/0, has_cluster_system_dbs/1, cluster_system_dbs/0]).
 
 -include_lib("../couch/include/couch_db.hrl").
 
@@ -54,9 +54,6 @@ cluster_system_dbs() ->
     ["_users", "_replicator", "_global_changes"].
 
 
-has_cluster_system_dbs() ->
-    has_cluster_system_dbs(cluster_system_dbs()).
-
 has_cluster_system_dbs([]) ->
     ok;
 has_cluster_system_dbs([Db|Dbs]) ->
@@ -172,12 +169,19 @@ set_admin(Username, Password) ->
   config:set("admins", binary_to_list(Username), binary_to_list(Password)).
 
 
-finish_cluster() ->
-    finish_cluster_int(has_cluster_system_dbs()).
-finish_cluster_int(ok) ->
+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.
+
+finish_cluster_int(_Dbs, ok) ->
     {error, cluster_finished};
-finish_cluster_int(no) ->
-    lists:foreach(fun fabric:create_db/1, cluster_system_dbs()).
+finish_cluster_int(Dbs, no) ->
+    lists:foreach(fun fabric:create_db/1, Dbs).
 
 
 add_node(Options) ->

http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/18314a6d/src/setup_httpd.erl
----------------------------------------------------------------------
diff --git a/src/setup_httpd.erl b/src/setup_httpd.erl
index a23a3e2..59ed5c7 100644
--- a/src/setup_httpd.erl
+++ b/src/setup_httpd.erl
@@ -29,11 +29,12 @@ handle_setup_req(#httpd{method='POST'}=Req) ->
     end;
 handle_setup_req(#httpd{method='GET'}=Req) ->
     ok = chttpd:verify_is_server_admin(Req),
+    Dbs = chttpd:qs_json_value(Req, "ensure_dbs_exist", setup:cluster_system_dbs()),
     case setup:is_cluster_enabled() of
         no ->
             chttpd:send_json(Req, 200, {[{state, cluster_disabled}]});
         ok ->
-            case setup:has_cluster_system_dbs() of
+            case setup:has_cluster_system_dbs(Dbs) of
                 no ->
                     chttpd:send_json(Req, 200, {[{state, cluster_enabled}]});
                 ok ->
@@ -74,7 +75,11 @@ handle_action("enable_cluster", Setup) ->
 
 handle_action("finish_cluster", Setup) ->
     couch_log:notice("finish_cluster: ~p~n", [Setup]),
-    case setup:finish_cluster() of
+
+    Options = get_options([
+        {ensure_dbs_exist, <<"ensure_dbs_exist">>}
+    ], Setup),
+    case setup:finish_cluster(Options) of
         {error, cluster_finished} ->
             {error, <<"Cluster is already finished">>};
         Else ->


[3/7] couchdb-setup git commit: address comments from rnewson

Posted by wo...@apache.org.
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/e153d485
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-setup/tree/e153d485
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-setup/diff/e153d485

Branch: refs/heads/master
Commit: e153d485b6b195054c87bbfcca1c2a5f54d979eb
Parents: 92dd9d1
Author: Joan Touzet <wo...@apache.org>
Authored: Tue Jul 11 16:04:46 2017 -0700
Committer: Joan Touzet <wo...@apache.org>
Committed: Tue Jul 11 16:56:44 2017 -0700

----------------------------------------------------------------------
 src/setup.erl       | 56 +++++++++++++++++++-----------------------------
 src/setup_httpd.erl | 36 +++++++++++++++----------------
 2 files changed, 40 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/e153d485/src/setup.erl
----------------------------------------------------------------------
diff --git a/src/setup.erl b/src/setup.erl
index 7aeac3e..0d17109 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(),
 

http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/e153d485/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").


[2/7] couchdb-setup git commit: Add new enable_single_node action for cluster_setup endpoint

Posted by wo...@apache.org.
Add new enable_single_node action for cluster_setup endpoint


Project: http://git-wip-us.apache.org/repos/asf/couchdb-setup/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-setup/commit/92dd9d10
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-setup/tree/92dd9d10
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-setup/diff/92dd9d10

Branch: refs/heads/master
Commit: 92dd9d10b6d3f94bf3295fd85bcc0375e8298828
Parents: 18314a6
Author: Joan Touzet <wo...@apache.org>
Authored: Mon Jul 10 16:31:17 2017 -0700
Committer: Joan Touzet <wo...@apache.org>
Committed: Mon Jul 10 16:31:17 2017 -0700

----------------------------------------------------------------------
 README.md             | 17 ++++++++-----
 src/setup.erl         | 60 ++++++++++++++++++++++++++++++++++++++--------
 src/setup_httpd.erl   | 41 +++++++++++++++++++++++++++----
 test/t-single-node.sh | 46 +++++++++++++++++++++++++++++++++++
 4 files changed, 143 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/92dd9d10/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index a6c6d18..e30c400 100644
--- a/README.md
+++ b/README.md
@@ -2,21 +2,26 @@ This module implements /_cluster_setup and manages the setting up, duh, of a Cou
 
 ### Testing
 
-```
+```bash
 git clone https://git-wip-us.apache.org/repos/asf/couchdb.git
 cd couchdb
 git checkout setup
 ./configure
 make
+dev/run --no-join -n 2 --admin a:b
+```
 
-# in dev/run comment out the line `connect_nodes("127.0.0.1", 15984)`
+Then, in a new terminal:
 
-dev/run --admin a:b
+    $ src/setup/test/t.sh
 
-# in a new terminal
-src/setup/test/t.sh
+Before running each test, kill the `dev/run` script, then reset the
+CouchDB instances with:
 
-```
+    $ rm -rf dev/lib/ dev/logs/
+    $ dev/run --no-join -n 2 --admin a:b
+
+before running the next shell script.
 
 The Plan:
 

http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/92dd9d10/src/setup.erl
----------------------------------------------------------------------
diff --git a/src/setup.erl b/src/setup.erl
index dd7410a..7aeac3e 100644
--- a/src/setup.erl
+++ b/src/setup.erl
@@ -14,6 +14,7 @@
 
 -export([enable_cluster/1, finish_cluster/1, add_node/1, receive_cookie/1]).
 -export([is_cluster_enabled/0, has_cluster_system_dbs/1, cluster_system_dbs/0]).
+-export([enable_single_node/1, is_single_node_enabled/1]).
 
 -include_lib("../couch/include/couch_db.hrl").
 
@@ -49,6 +50,15 @@ is_cluster_enabled() ->
         {_,_} -> ok
     end.
 
+is_single_node_enabled(Dbs) ->
+    % admins != empty AND dbs exist
+    Admins = config:get("admins"),
+    HasDbs = has_cluster_system_dbs(Dbs),
+    case {Admins, HasDbs} of
+        {[], _} -> no;
+        {_, no} -> no;
+        {_,_} -> ok
+    end.
 
 cluster_system_dbs() ->
     ["_users", "_replicator", "_global_changes"].
@@ -129,18 +139,27 @@ enable_cluster_int(Options, no) ->
           Pw -> Pw
         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_admins(CurrentAdmins, NewCredentials),
     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]).
+
+setup_node(NewCredentials, NewBindAddress, NodeCount, Port) ->
     case NewCredentials of
         {undefined, undefined} ->
             ok;
         {Username, Password} ->
-            set_admin(Username, Password)
+            config:set("admins", binary_to_list(Username), binary_to_list(Password))
     end,
 
     case NewBindAddress of
@@ -150,11 +169,8 @@ enable_cluster_int(Options, no) ->
             config:set("chttpd", "bind_address", binary_to_list(NewBindAddress))
     end,
 
-    NodeCount = couch_util:get_value(node_count, Options),
-    ok = require_node_count(NodeCount),
     config:set_integer("cluster", "n", NodeCount),
 
-    Port = proplists:get_value(port, Options),
     case Port of
         undefined ->
             ok;
@@ -162,11 +178,7 @@ enable_cluster_int(Options, no) ->
             config:set("chttpd", "port", binary_to_list(Port));
         Port when is_integer(Port) ->
             config:set_integer("chttpd", "port", Port)
-    end,
-    couch_log:notice("Enable Cluster: ~p~n", [Options]).
-
-set_admin(Username, Password) ->
-  config:set("admins", binary_to_list(Username), binary_to_list(Password)).
+    end.
 
 
 finish_cluster(Options) ->
@@ -184,6 +196,34 @@ finish_cluster_int(Dbs, no) ->
     lists:foreach(fun fabric:create_db/1, Dbs).
 
 
+enable_single_node(Options) ->
+    % if no admin in config and no admin in req -> error
+    CurrentAdmins = config:get("admins"),
+    NewCredentials = {
+        proplists:get_value(username, Options),
+        case proplists:get_value(password_hash, Options) of
+          undefined -> proplists:get_value(password, Options);
+          Pw -> Pw
+        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,
+    couch_log:notice("Enable Single Node: ~p~n", [Options]).
+
+
 add_node(Options) ->
     add_node_int(Options, is_cluster_enabled()).
 

http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/92dd9d10/src/setup_httpd.erl
----------------------------------------------------------------------
diff --git a/src/setup_httpd.erl b/src/setup_httpd.erl
index 59ed5c7..a5a8157 100644
--- a/src/setup_httpd.erl
+++ b/src/setup_httpd.erl
@@ -30,16 +30,27 @@ handle_setup_req(#httpd{method='POST'}=Req) ->
 handle_setup_req(#httpd{method='GET'}=Req) ->
     ok = chttpd:verify_is_server_admin(Req),
     Dbs = chttpd:qs_json_value(Req, "ensure_dbs_exist", setup:cluster_system_dbs()),
-    case setup:is_cluster_enabled() of
+    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}]})
+            no ->
+                chttpd:send_json(Req, 200, {[{state, cluster_enabled}]});
+            ok ->
+                chttpd:send_json(Req, 200, {[{state, cluster_finished}]})
             end
+        end
     end;
 handle_setup_req(#httpd{}=Req) ->
     chttpd:send_method_not_allowed(Req, "GET,POST").
@@ -87,6 +98,26 @@ handle_action("finish_cluster", Setup) ->
             ok
     end;
 
+handle_action("enable_single_node", Setup) ->
+    couch_log:notice("enable_single_node: ~p~n", [Setup]),
+
+    Options = get_options([
+        {ensure_dbs_exist, <<"ensure_dbs_exist">>},
+        {username, <<"username">>},
+        {password, <<"password">>},
+        {password_hash, <<"password_hash">>},
+        {bind_address, <<"bind_address">>},
+        {port, <<"port">>}
+    ], Setup),
+    case setup:enable_single_node(Options) of
+        {error, cluster_finished} ->
+            {error, <<"Cluster is already finished">>};
+        Else ->
+            couch_log:notice("Else: ~p~n", [Else]),
+            ok
+    end;
+
+
 handle_action("add_node", Setup) ->
     couch_log:notice("add_node: ~p~n", [Setup]),
 

http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/92dd9d10/test/t-single-node.sh
----------------------------------------------------------------------
diff --git a/test/t-single-node.sh b/test/t-single-node.sh
new file mode 100755
index 0000000..d490437
--- /dev/null
+++ b/test/t-single-node.sh
@@ -0,0 +1,46 @@
+#!/bin/sh -ex
+# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+HEADERS="-HContent-Type:application/json"
+# show cluster state:
+curl a:b@127.0.0.1:15986/_nodes/_all_docs
+curl a:b@127.0.0.1:15984/_cluster_setup
+
+# Enable Cluster on single node
+curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"enable_single_node","username":"foo","password":"baz","bind_address":"127.0.0.1"}' $HEADERS
+
+# Show cluster state:
+curl a:b@127.0.0.1:15986/_nodes/_all_docs
+curl a:b@127.0.0.1:15984/_all_dbs
+curl a:b@127.0.0.1:15984/_cluster_setup
+
+# Delete a database
+curl -X DELETE a:b@127.0.0.1:15984/_global_changes
+
+# Should show single_node_disabled
+curl a:b@127.0.0.1:15984/_cluster_setup
+
+# Change the check
+curl -g 'a:b@127.0.0.1:15984/_cluster_setup?ensure_dbs_exist=["_replicator","_users"]'
+
+# delete all the things
+curl -X DELETE a:b@127.0.0.1:15984/_replicator
+curl -X DELETE a:b@127.0.0.1:15984/_users
+
+# setup only creating _users
+curl -g a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"enable_single_node","username":"foo","password":"baz","bind_address":"127.0.0.1","ensure_dbs_exist":["_users"]}' $HEADERS
+
+# check it
+curl -g 'a:b@127.0.0.1:15984/_cluster_setup?ensure_dbs_exist=["_users"]'
+
+echo "YAY ALL GOOD"


[7/7] couchdb-setup git commit: Merge branch '593-setup-single-node' of https://github.com/apache/couchdb-setup

Posted by wo...@apache.org.
Merge branch '593-setup-single-node' of https://github.com/apache/couchdb-setup


Project: http://git-wip-us.apache.org/repos/asf/couchdb-setup/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-setup/commit/4d9bd589
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-setup/tree/4d9bd589
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-setup/diff/4d9bd589

Branch: refs/heads/master
Commit: 4d9bd589fe68d6108021ef8417f3e5d91e4d113e
Parents: c38d7aa 4b90eca
Author: Joan Touzet <jo...@atypical.net>
Authored: Sun Jul 16 12:32:41 2017 -0400
Committer: Joan Touzet <jo...@atypical.net>
Committed: Sun Jul 16 12:32:41 2017 -0400

----------------------------------------------------------------------
 .gitignore            |  2 ++
 README.md             | 17 +++++----
 src/setup.erl         | 88 +++++++++++++++++++++++++++++++---------------
 src/setup_httpd.erl   | 56 +++++++++++++++++++++++------
 test/t-single-node.sh | 46 ++++++++++++++++++++++++
 5 files changed, 165 insertions(+), 44 deletions(-)
----------------------------------------------------------------------



[4/7] couchdb-setup git commit: fix typo/compilation error

Posted by wo...@apache.org.
fix typo/compilation error


Project: http://git-wip-us.apache.org/repos/asf/couchdb-setup/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-setup/commit/d61381a0
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-setup/tree/d61381a0
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-setup/diff/d61381a0

Branch: refs/heads/master
Commit: d61381a094a7f67ea688c58edacb3b204babcaa9
Parents: e153d48
Author: Jan Lehnardt <ja...@apache.org>
Authored: Sun Jul 16 17:24:55 2017 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Sun Jul 16 17:24:55 2017 +0200

----------------------------------------------------------------------
 src/setup.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/d61381a0/src/setup.erl
----------------------------------------------------------------------
diff --git a/src/setup.erl b/src/setup.erl
index 0d17109..d0ecd2c 100644
--- a/src/setup.erl
+++ b/src/setup.erl
@@ -208,7 +208,7 @@ enable_single_node(Options) ->
 
     setup_node(NewCredentials, NewBindAddress, 1, Port),
     Dbs = proplists:get_value(ensure_dbs_exist, Options, cluster_system_dbs()),
-    finish_cluster_int(Dbs, has_cluster_system_dbs(Dbs))
+    finish_cluster_int(Dbs, has_cluster_system_dbs(Dbs)),
     couch_log:notice("Enable Single Node: ~p~n", [Options]).
 
 


[5/7] couchdb-setup git commit: chore: whitespace

Posted by wo...@apache.org.
chore: whitespace


Project: http://git-wip-us.apache.org/repos/asf/couchdb-setup/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-setup/commit/942c665c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-setup/tree/942c665c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-setup/diff/942c665c

Branch: refs/heads/master
Commit: 942c665c6e44c4f954a77d72a59aac856f20a6f3
Parents: d61381a
Author: Jan Lehnardt <ja...@apache.org>
Authored: Sun Jul 16 17:44:51 2017 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Sun Jul 16 17:44:51 2017 +0200

----------------------------------------------------------------------
 src/setup_httpd.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/942c665c/src/setup_httpd.erl
----------------------------------------------------------------------
diff --git a/src/setup_httpd.erl b/src/setup_httpd.erl
index a9cbfe8..1f5b7aa 100644
--- a/src/setup_httpd.erl
+++ b/src/setup_httpd.erl
@@ -39,7 +39,7 @@ handle_setup_req(#httpd{method='GET'}=Req) ->
                 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}]});


[6/7] couchdb-setup git commit: chore: better log output

Posted by wo...@apache.org.
chore: better log output


Project: http://git-wip-us.apache.org/repos/asf/couchdb-setup/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-setup/commit/4b90eca7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-setup/tree/4b90eca7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-setup/diff/4b90eca7

Branch: refs/heads/master
Commit: 4b90eca7ede04abaa72a36e38740cdd9c9b22ebe
Parents: 942c665
Author: Jan Lehnardt <ja...@apache.org>
Authored: Sun Jul 16 17:45:13 2017 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Sun Jul 16 17:45:13 2017 +0200

----------------------------------------------------------------------
 src/setup_httpd.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/4b90eca7/src/setup_httpd.erl
----------------------------------------------------------------------
diff --git a/src/setup_httpd.erl b/src/setup_httpd.erl
index 1f5b7aa..f4e05ce 100644
--- a/src/setup_httpd.erl
+++ b/src/setup_httpd.erl
@@ -94,7 +94,7 @@ handle_action("finish_cluster", Setup) ->
         {error, cluster_finished} ->
             {error, <<"Cluster is already finished">>};
         Else ->
-            couch_log:notice("Else: ~p~n", [Else]),
+            couch_log:notice("finish_cluster: ~p~n", [Else]),
             ok
     end;