From 3cb885c6b25c4139fa7b3f77058caf00c5b05c6e Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Thu, 6 Nov 2014 11:07:25 -0800 Subject: [PATCH 1/2] etcdhttp: return 409 instead of 412 when there is a conflict when adding a member --- etcdserver/etcdhttp/client.go | 2 +- etcdserver/etcdhttp/client_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/etcdserver/etcdhttp/client.go b/etcdserver/etcdhttp/client.go index 5c322fc92..53f1c4620 100644 --- a/etcdserver/etcdhttp/client.go +++ b/etcdserver/etcdhttp/client.go @@ -189,7 +189,7 @@ func (h *membersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { err = h.server.AddMember(ctx, *m) switch { case err == etcdserver.ErrIDExists || err == etcdserver.ErrPeerURLexists: - writeError(w, httptypes.NewHTTPError(http.StatusPreconditionFailed, err.Error())) + writeError(w, httptypes.NewHTTPError(http.StatusConflict, err.Error())) return case err != nil: log.Printf("etcdhttp: error adding node %s: %v", m.ID, err) diff --git a/etcdserver/etcdhttp/client_test.go b/etcdserver/etcdhttp/client_test.go index bf7632b68..f03846c06 100644 --- a/etcdserver/etcdhttp/client_test.go +++ b/etcdserver/etcdhttp/client_test.go @@ -773,6 +773,34 @@ func TestServeMembersFail(t *testing.T) { http.StatusInternalServerError, }, + { + // etcdserver.AddMember error + &http.Request{ + URL: mustNewURL(t, membersPrefix), + Method: "POST", + Body: ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://127.0.0.1:1"]}`)), + Header: map[string][]string{"Content-Type": []string{"application/json"}}, + }, + &errServer{ + etcdserver.ErrIDExists, + }, + + http.StatusConflict, + }, + { + // etcdserver.AddMember error + &http.Request{ + URL: mustNewURL(t, membersPrefix), + Method: "POST", + Body: ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://127.0.0.1:1"]}`)), + Header: map[string][]string{"Content-Type": []string{"application/json"}}, + }, + &errServer{ + etcdserver.ErrPeerURLexists, + }, + + http.StatusConflict, + }, { // etcdserver.RemoveMember error with arbitrary server error &http.Request{ From a1f5df22ad594f58f047e2bfce1fd18ee657dddd Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Thu, 6 Nov 2014 11:10:13 -0800 Subject: [PATCH 2/2] doc: document conflict case when adding a member --- Documentation/0.5/other_apis.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/0.5/other_apis.md b/Documentation/0.5/other_apis.md index 76d096b7e..cb1afb4f0 100644 --- a/Documentation/0.5/other_apis.md +++ b/Documentation/0.5/other_apis.md @@ -51,7 +51,7 @@ curl http://10.0.0.10:2379/v2/members Returns an HTTP 201 response code and the representation of added member with a newly generated a memberID when successful. Returns a string describing the failure condition when unsuccessful. -If the POST body is malformed an HTTP 400 will be returned. If the member exists in the cluster or existed in the cluster at some point in the past an HTTP 500(TODO: fix this) will be returned. If the cluster fails to process the request within timeout an HTTP 500 will be returned, though the request may be processed later. +If the POST body is malformed an HTTP 400 will be returned. If the member exists in the cluster or existed in the cluster at some point in the past an HTTP 409 will be returned. If any of the given peerURLs exists in the cluster an HTTP 409 will be returned. If the cluster fails to process the request within timeout an HTTP 500 will be returned, though the request may be processed later. ### Request