Skip to content
This repository was archived by the owner on May 25, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ UI shows an “Add Node” interface with the fields admin, and node:
},
"node": {
"host": "hostname",
["port": 5984]
["port": 5984],
"name": "node1" // as in “node1@hostname”, same as in vm.args
}
}
```
Expand Down
8 changes: 4 additions & 4 deletions src/setup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,14 @@ add_node_int(Options, ok) ->

Host = proplists:get_value(host, Options),
Port = get_port(proplists:get_value(port, Options, 5984)),
Name = proplists:get_value(name, Options, get_default_name(Port)),

Url = binary_to_list(<<"http://", Host/binary, ":", Port/binary, "/_cluster_setup">>),

case ibrowse:send_req(Url, Headers, post, Body, RequestOptions) of
{ok, "201", _, _} ->
% when done, PUT :5986/nodes/nodeB
create_node_doc(Host, Port);
create_node_doc(Host, Name);
Else ->
couch_log:notice("send_req: ~p~n", [Else]),
Else
Expand All @@ -219,16 +220,15 @@ get_port(Port) when is_list(Port) ->
get_port(Port) when is_binary(Port) ->
Port.

create_node_doc(Host, Port) ->
create_node_doc(Host, Name) ->
{ok, Db} = couch_db:open_int(<<"_nodes">>, []),
Name = get_name(Port),
Doc = {[{<<"_id">>, <<Name/binary, "@", Host/binary>>}]},
Options = [],
CouchDoc = couch_doc:from_json_obj(Doc),

couch_db:update_doc(Db, CouchDoc, Options).

get_name(Port) ->
get_default_name(Port) ->
case Port of
% shortcut for easier development
<<"15984">> ->
Expand Down
3 changes: 2 additions & 1 deletion src/setup_httpd.erl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ handle_action("add_node", Setup) ->
{username, <<"username">>},
{password, <<"password">>},
{host, <<"host">>},
{port, <<"port">>}
{port, <<"port">>},
{name, <<"name">>}
], Setup),
case setup:add_node(Options) of
{error, cluster_not_enabled} ->
Expand Down
2 changes: 1 addition & 1 deletion test/t-frontend-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"enable_cluster","username
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
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,"name":"node2"}' $HEADERS

# Show cluster state:
curl a:b@127.0.0.1:15986/_nodes/_all_docs
Expand Down
2 changes: 1 addition & 1 deletion test/t.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"enable_cluster","username
curl a:b@127.0.0.1:25984/_cluster_setup -d '{"action":"enable_cluster","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
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,"name":"node2"}' $HEADERS

# Show cluster state:
curl a:b@127.0.0.1:15986/_nodes/_all_docs
Expand Down