couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [18/23] couchdb-setup git commit: wip: full receive feature, setup now works yay
Date Fri, 07 Nov 2014 14:46:42 GMT
wip: full receive feature, setup now works yay


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

Branch: refs/heads/master
Commit: 92da54ed202802e4e8cc8f2e5c5e62fd70ea4dd7
Parents: 277ca66
Author: Jan Lehnardt <jan@apache.org>
Authored: Fri Nov 7 15:01:29 2014 +0100
Committer: Jan Lehnardt <jan@apache.org>
Committed: Fri Nov 7 15:01:29 2014 +0100

----------------------------------------------------------------------
 src/setup.erl       | 43 ++++++++++++++++++++++++++++++-------------
 src/setup_httpd.erl |  5 ++---
 2 files changed, 32 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/92da54ed/src/setup.erl
----------------------------------------------------------------------
diff --git a/src/setup.erl b/src/setup.erl
index 4a4524c..e5afb2a 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)).

http://git-wip-us.apache.org/repos/asf/couchdb-setup/blob/92da54ed/src/setup_httpd.erl
----------------------------------------------------------------------
diff --git a/src/setup_httpd.erl b/src/setup_httpd.erl
index e0751d2..550b04a 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} ->


Mime
View raw message