Skip to content
This repository has been archived by the owner. It is now read-only.
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:


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


the current admin username of the remote node


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:



PR: #2
PR-URL: #2
Reviewed-By: Jan Lehnardt <>
Reviewed-By: Alexander Shorin <>
  • 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]) ->

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) ->
% 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 = [

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", _, _} ->
Else ->
io:format("~nsend_req: ~p~n", [Else]),
{error, Else}

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
# 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.

# show cluster state:
curl a:b@

# Enable Cluster on node A
curl a:b@ -d '{"action":"enable_cluster","username":"foo","password":"baz","bind_address":""}' $HEADERS

# Enable Cluster on node B
curl a:b@ -d '{"action":"enable_cluster","remote_node":"","port":"25984","remote_current_user":"a","remote_current_password":"b","username":"foo","password":"baz","bind_address":""}' $HEADERS

# Add node B on node A
curl a:b@ -d '{"action":"add_node","username":"foo","password":"baz","host":"","port":25984}' $HEADERS

# Show cluster state:
curl a:b@

# Show db doesn’t exist on node A
curl a:b@

# Show db doesn’t exist on node B
curl a:b@

# Create database (on node A)
curl -X PUT a:b@

# Show db does exist on node A
curl a:b@

# Show db does exist on node B
curl a:b@

# Finish cluster
curl a:b@ -d '{"action":"finish_cluster"}' $HEADERS

# Show system dbs exist on node A
curl a:b@
curl a:b@
curl a:b@
curl a:b@

# Show system dbs exist on node B
curl a:b@
curl a:b@
curl a:b@
curl a:b@


0 comments on commit 616789b

Please sign in to comment.