summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Lehnardt <jan@apache.org>2014-11-07 15:01:29 +0100
committerJan Lehnardt <jan@apache.org>2014-11-07 15:01:29 +0100
commit92da54ed202802e4e8cc8f2e5c5e62fd70ea4dd7 (patch)
treeb202ece99a5925f3077b34d9630a33888db8ad86
parent277ca66441bf56f93132137c0e8d7d1337c99f06 (diff)
downloadcouchdb-92da54ed202802e4e8cc8f2e5c5e62fd70ea4dd7.tar.gz
wip: full receive feature, setup now works yay
-rw-r--r--src/setup.erl43
-rw-r--r--src/setup_httpd.erl5
2 files changed, 32 insertions, 16 deletions
diff --git a/src/setup.erl b/src/setup.erl
index 4a4524c43..e5afb2a9b 100644
--- a/src/setup.erl
+++ b/src/setup.erl
@@ -12,7 +12,7 @@
-module(setup).
--export([enable_cluster/1, finish_cluster/0, add_node/1]).
+-export([enable_cluster/1, finish_cluster/0, add_node/1, receive_cookie/1]).
-include_lib("../couch/include/couch_db.hrl").
@@ -121,8 +121,8 @@ add_node_int(Options, ok) ->
% POST to nodeB/_setup
RequestOptions = [
{basic_auth, {
- proplists:get_value(username, Options),
- proplists:get_value(password, Options)
+ binary_to_list(proplists:get_value(username, Options)),
+ binary_to_list(proplists:get_value(password, Options))
}}
],
@@ -136,14 +136,11 @@ add_node_int(Options, ok) ->
],
Host = proplists:get_value(host, Options),
- Port = proplists:get_value(port, Options, <<"5984">>),
- Url = binary_to_list(<<"http://", Host/binary, ":", Port/binary, "/_setup">>),
-
- io:format("~nUrl: ~p~n", [Url]),
- io:format("~nBody: ~p~n", [Body]),
+ Port = integer_to_binary(proplists:get_value(port, Options, 5984)),
+ Url = binary_to_list(<<"http://", Host/binary, ":", Port/binary, "/_cluster_setup">>),
case ibrowse:send_req(Url, Headers, post, Body, RequestOptions) of
- {ok, 200, _, _} ->
+ {ok, "201", _, _} ->
% when done, PUT :5986/nodes/nodeB
create_node_doc(Host, Port);
Else ->
@@ -151,9 +148,29 @@ add_node_int(Options, ok) ->
Else
end.
-
create_node_doc(Host, Port) ->
- {ok, Db} = couch_db:open_int("nodes"),
- Doc = {[{<<"_id">>, <<Host/binary, ":", Port/binary>>}]},
+ {ok, Db} = couch_db:open_int(<<"nodes">>, []),
+ Name = get_name(Port),
+ Doc = {[{<<"_id">>, <<Name/binary, "@", Host/binary>>}]},
Options = [],
- couch_db:update_doc(Db, Doc, Options).
+ CouchDoc = couch_doc:from_json_obj(Doc),
+
+ couch_db:update_doc(Db, CouchDoc, Options).
+
+get_name(Port) ->
+ case Port of
+ % shortcut for easier development
+ <<"15984">> ->
+ <<"node1">>;
+ <<"25984">> ->
+ <<"node2">>;
+ <<"35984">> ->
+ <<"node3">>;
+ % by default, all nodes have the user `couchdb`
+ _ ->
+ <<"couchdb">>
+ end.
+
+receive_cookie(Options) ->
+ Cookie = proplists:get_value(cookie, Options),
+ erlang:set_cookie(node(), binary_to_atom(Cookie, latin1)).
diff --git a/src/setup_httpd.erl b/src/setup_httpd.erl
index e0751d210..550b04aad 100644
--- a/src/setup_httpd.erl
+++ b/src/setup_httpd.erl
@@ -16,8 +16,7 @@
handle_setup_req(Req) ->
ok = chttpd:verify_is_server_admin(Req),
- % TBD uncomment after devving
- %couch_httpd:validate_ctype(Req, "application/json"),
+ couch_httpd:validate_ctype(Req, "application/json"),
Setup = get_body(Req),
io:format("~nSetup: ~p~n", [Setup]),
Action = binary_to_list(couch_util:get_value(<<"action">>, Setup, <<"missing">>)),
@@ -87,7 +86,7 @@ handle_action("remove_node", Setup) ->
handle_action("receive_cookie", Setup) ->
io:format("~nreceive_cookie: ~p~n", [Setup]),
Options = get_options([
- {cookue, <<"cookie">>}
+ {cookie, <<"cookie">>}
], Setup),
case setup:receive_cookie(Options) of
{error, Error} ->