Merge pull request #1631 from xiangli-cmu/validate_doc

Validate doc
This commit is contained in:
Xiang Li 2014-11-06 11:45:00 -08:00
commit b53a98eb38
3 changed files with 30 additions and 2 deletions

View File

@ -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

View File

@ -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)

View File

@ -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{