couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertkowal...@apache.org
Subject [1/3] couchdb-setup git commit: cluster_enable: add remote_node feature
Date Wed, 24 Jun 2015 13:39:12 GMT
Repository: couchdb-setup
Updated Branches:
  refs/heads/master ecb601b20 -> aa17a557b


cluster_enable: add remote_node feature

this feature makes it easier to setup a cluster for browser
applications like fauxton as browsers follow the same-origin
policy. Before this PR you had to open the wizard in Fauxton on
all three nodes and enter your data there, which was quite
confusing and hard to explain. Now you can stay in the same tab
at the same address.

This PR enables three new params in the body:

`remote_node`:

ip of the remote node where we want to send the `enable_cluster`
request

`remote_current_user`:

the current admin username of the remote node

`remote_current_password`:

the current admin password of the remote node

To test, I run:

```
rm -rf dev/lib/ && ./dev/run --no-join --admin=a:b
```

and then run the test script:

```
./src/setup/test/t-frontend-setup.sh
```

COUCHDB-2598

PR: #2
PR-URL: https://github.com/apache/couchdb-setup/pull/2
Reviewed-By: Jan Lehnardt <jan@apache.org>
Reviewed-By: Alexander Shorin <kxepal@apache.org>


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

Branch: refs/heads/master
Commit: 616789bac1bcdf9897e6725baaf0249f742389fd
Parents: ecb601b
Author: Robert Kowalski <rok@kowalski.gd>
Authored: Tue May 26 02:33:50 2015 +0200
Committer: Robert Kowalski <robertkowalski@apache.org>
Committed: Wed Jun 24 15:37:16 2015 +0200

----------------------------------------------------------------------
 src/setup.erl            | 42 +++++++++++++++++++++++++++++-
 src/setup_httpd.erl      |  5 +++-
 test/t-frontend-setup.sh | 60 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 105 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/616789ba/src/setup.erl
----------------------------------------------------------------------
diff --git a/src/setup.erl b/src/setup.erl
index 1943835..9aa98f9 100644
--- a/src/setup.erl
+++ b/src/setup.erl
@@ -61,7 +61,47 @@ has_cluster_system_dbs([Db|Dbs]) ->
     end.
 
 enable_cluster(Options) ->
-    enable_cluster_int(Options, is_cluster_enabled()).
+
+    case couch_util:get_value(remote_node, Options, undefined) of
+        undefined ->
+            enable_cluster_int(Options, is_cluster_enabled());
+        _ ->
+            enable_cluster_http(Options)
+    end.
+
+enable_cluster_http(Options) ->
+    % POST to nodeB/_setup
+    RequestOptions = [
+        {basic_auth, {
+            binary_to_list(couch_util:get_value(remote_current_user, Options)),
+            binary_to_list(couch_util:get_value(remote_current_password, Options))
+        }}
+    ],
+
+    Body = ?JSON_ENCODE({[
+        {<<"action">>, <<"enable_cluster">>},
+        {<<"username">>, couch_util:get_value(username, Options)},
+        {<<"password">>, couch_util:get_value(password, Options)},
+        {<<"bind_address">>, couch_util:get_value(bind_address, Options)},
+        {<<"port">>, couch_util:get_value(port, Options)}
+    ]}),
+
+    Headers = [
+        {"Content-Type","application/json"}
+    ],
+
+    RemoteNode = couch_util:get_value(remote_node, Options),
+    Port = get_port(couch_util:get_value(port, Options, 5984)),
+
+    Url = binary_to_list(<<"http://", RemoteNode/binary, ":", Port/binary, "/_cluster_setup">>),
+
+    case ibrowse:send_req(Url, Headers, post, Body, RequestOptions) of
+        {ok, "201", _, _} ->
+            ok;
+        Else ->
+            io:format("~nsend_req: ~p~n", [Else]),
+            {error, Else}
+    end.
 
 enable_cluster_int(_Options, ok) ->
     {error, cluster_enabled};

http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/616789ba/src/setup_httpd.erl
----------------------------------------------------------------------
diff --git a/src/setup_httpd.erl b/src/setup_httpd.erl
index aca98e7..de1bff5 100644
--- a/src/setup_httpd.erl
+++ b/src/setup_httpd.erl
@@ -55,7 +55,10 @@ handle_action("enable_cluster", Setup) ->
         {username, <<"username">>},
         {password, <<"password">>},
         {bind_address, <<"bind_address">>},
-        {port, <<"port">>}
+        {port, <<"port">>},
+        {remote_node, <<"remote_node">>},
+        {remote_current_user, <<"remote_current_user">>},
+        {remote_current_password, <<"remote_current_password">>}
     ], Setup),
     case setup:enable_cluster(Options) of
         {error, cluster_enabled} ->

http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/616789ba/test/t-frontend-setup.sh
----------------------------------------------------------------------
diff --git a/test/t-frontend-setup.sh b/test/t-frontend-setup.sh
new file mode 100755
index 0000000..1c610b6
--- /dev/null
+++ b/test/t-frontend-setup.sh
@@ -0,0 +1,60 @@
+#!/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
+
+# Enable Cluster on node A
+curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"enable_cluster","username":"foo","password":"baz","bind_address":"0.0.0.0"}'
$HEADERS
+
+# Enable Cluster on node B
+curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"enable_cluster","remote_node":"127.0.0.1","port":"25984","remote_current_user":"a","remote_current_password":"b","username":"foo","password":"baz","bind_address":"0.0.0.0"}'
$HEADERS
+
+# Add node B on node A
+curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"add_node","username":"foo","password":"baz","host":"127.0.0.1","port":25984}'
$HEADERS
+
+# Show cluster state:
+curl a:b@127.0.0.1:15986/_nodes/_all_docs
+
+# Show db doesn’t exist on node A
+curl a:b@127.0.0.1:15984/foo
+
+# Show db doesn’t exist on node B
+curl a:b@127.0.0.1:25984/foo
+
+# Create database (on node A)
+curl -X PUT a:b@127.0.0.1:15984/foo
+
+# Show db does exist on node A
+curl a:b@127.0.0.1:15984/foo
+
+# Show db does exist on node B
+curl a:b@127.0.0.1:25984/foo
+
+# Finish cluster
+curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"finish_cluster"}' $HEADERS
+
+# Show system dbs exist on node A
+curl a:b@127.0.0.1:15984/_users
+curl a:b@127.0.0.1:15984/_replicator
+curl a:b@127.0.0.1:15984/_metadata
+curl a:b@127.0.0.1:15984/_global_changes
+
+# Show system dbs exist on node B
+curl a:b@127.0.0.1:25984/_users
+curl a:b@127.0.0.1:25984/_replicator
+curl a:b@127.0.0.1:25984/_metadata
+curl a:b@127.0.0.1:25984/_global_changes
+
+echo "YAY ALL GOOD"


Mime
View raw message