Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
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: #2
Reviewed-By: Jan Lehnardt <jan@apache.org>
Reviewed-By: Alexander Shorin <kxepal@apache.org>
  • Loading branch information
robertkowalski committed Jun 24, 2015
1 parent ecb601b commit 616789bac1bcdf9897e6725baaf0249f742389fd
Showing 3 changed files with 105 additions and 2 deletions.
@@ -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};
@@ -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} ->
@@ -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"

0 comments on commit 616789b

Please sign in to comment.