api: remove admin prefix from members API

This commit is contained in:
Brian Waldon 2014-10-29 12:11:26 -07:00
parent bab19e3b0b
commit ab67fa4cc6
5 changed files with 37 additions and 37 deletions

View File

@ -1,10 +1,10 @@
## Admin API ## Members API
### GET /v2/admin/members/ ### GET /v2/members/
Return an HTTP 200 OK response code and a representation of all members in the etcd cluster: Return an HTTP 200 OK response code and a representation of all members in the etcd cluster:
``` ```
Example Request: GET Example Request: GET
http://localhost:2379/v2/admin/members/ http://localhost:2379/v2/members/
Response formats: JSON Response formats: JSON
Example Response: Example Response:
``` ```
@ -35,14 +35,14 @@ Return an HTTP 200 OK response code and a representation of all members in the e
} }
``` ```
### POST /v2/admin/members/ ### POST /v2/members/
Add a member to the cluster. Add a member to the cluster.
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. 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 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.
``` ```
Example Request: POST Example Request: POST
http://localhost:2379/v2/admin/members http://localhost:2379/v2/members
Body: Body:
{"peerURLs":["http://10.0.0.10:2379"]} {"peerURLs":["http://10.0.0.10:2379"]}
Respose formats: JSON Respose formats: JSON
@ -57,7 +57,7 @@ If the POST body is malformed an HTTP 400 will be returned. If the member exists
} }
``` ```
### DELETE /v2/admin/members/:id ### DELETE /v2/members/:id
Remove a member from the cluster. Remove a member from the cluster.
Returns empty when successful. Returns a string describing the failure condition when unsuccessful. Returns empty when successful. Returns a string describing the failure condition when unsuccessful.
@ -65,6 +65,6 @@ If the member does not exist in the cluster an HTTP 500(TODO: fix this) will be
``` ```
Response formats: JSON Response formats: JSON
Example Request: DELETE Example Request: DELETE
http://localhost:2379/v2/admin/members/272e204152 http://localhost:2379/v2/members/272e204152
Example Response: Empty Example Response: Empty
``` ```

View File

@ -28,7 +28,7 @@ import (
) )
var ( var (
DefaultV2MembersPrefix = "/v2/admin/members" DefaultV2MembersPrefix = "/v2/members"
) )
func NewMembersAPI(tr *http.Transport, ep string, to time.Duration) (MembersAPI, error) { func NewMembersAPI(tr *http.Transport, ep string, to time.Duration) (MembersAPI, error) {

View File

@ -23,11 +23,11 @@ import (
) )
func TestMembersAPIListAction(t *testing.T) { func TestMembersAPIListAction(t *testing.T) {
ep := url.URL{Scheme: "http", Host: "example.com/v2/admin/members"} ep := url.URL{Scheme: "http", Host: "example.com/v2/members"}
wantURL := &url.URL{ wantURL := &url.URL{
Scheme: "http", Scheme: "http",
Host: "example.com", Host: "example.com",
Path: "/v2/admin/members", Path: "/v2/members",
} }
act := &membersAPIActionList{} act := &membersAPIActionList{}

View File

@ -43,7 +43,7 @@ import (
const ( const (
keysPrefix = "/v2/keys" keysPrefix = "/v2/keys"
deprecatedMachinesPrefix = "/v2/machines" deprecatedMachinesPrefix = "/v2/machines"
adminMembersPrefix = "/v2/admin/members" membersPrefix = "/v2/members"
statsPrefix = "/v2/stats" statsPrefix = "/v2/stats"
versionPrefix = "/version" versionPrefix = "/version"
) )
@ -61,7 +61,7 @@ func NewClientHandler(server *etcdserver.EtcdServer) http.Handler {
stats: server, stats: server,
} }
amh := &adminMembersHandler{ mh := &membersHandler{
server: server, server: server,
clusterInfo: server.Cluster, clusterInfo: server.Cluster,
clock: clockwork.NewRealClock(), clock: clockwork.NewRealClock(),
@ -79,8 +79,8 @@ func NewClientHandler(server *etcdserver.EtcdServer) http.Handler {
mux.HandleFunc(statsPrefix+"/store", sh.serveStore) mux.HandleFunc(statsPrefix+"/store", sh.serveStore)
mux.HandleFunc(statsPrefix+"/self", sh.serveSelf) mux.HandleFunc(statsPrefix+"/self", sh.serveSelf)
mux.HandleFunc(statsPrefix+"/leader", sh.serveLeader) mux.HandleFunc(statsPrefix+"/leader", sh.serveLeader)
mux.Handle(adminMembersPrefix, amh) mux.Handle(membersPrefix, mh)
mux.Handle(adminMembersPrefix+"/", amh) mux.Handle(membersPrefix+"/", mh)
mux.Handle(deprecatedMachinesPrefix, dmh) mux.Handle(deprecatedMachinesPrefix, dmh)
return mux return mux
} }
@ -142,13 +142,13 @@ func (h *deprecatedMachinesHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
w.Write([]byte(strings.Join(endpoints, ", "))) w.Write([]byte(strings.Join(endpoints, ", ")))
} }
type adminMembersHandler struct { type membersHandler struct {
server etcdserver.Server server etcdserver.Server
clusterInfo etcdserver.ClusterInfo clusterInfo etcdserver.ClusterInfo
clock clockwork.Clock clock clockwork.Clock
} }
func (h *adminMembersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h *membersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if !allowMethod(w, r.Method, "GET", "POST", "DELETE") { if !allowMethod(w, r.Method, "GET", "POST", "DELETE") {
return return
} }
@ -160,7 +160,7 @@ func (h *adminMembersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
switch r.Method { switch r.Method {
case "GET": case "GET":
if trimPrefix(r.URL.Path, adminMembersPrefix) != "" { if trimPrefix(r.URL.Path, membersPrefix) != "" {
writeError(w, httptypes.NewHTTPError(http.StatusNotFound, "Not found")) writeError(w, httptypes.NewHTTPError(http.StatusNotFound, "Not found"))
return return
} }
@ -202,7 +202,7 @@ func (h *adminMembersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
log.Printf("etcdhttp: %v", err) log.Printf("etcdhttp: %v", err)
} }
case "DELETE": case "DELETE":
idStr := trimPrefix(r.URL.Path, adminMembersPrefix) idStr := trimPrefix(r.URL.Path, membersPrefix)
if idStr == "" { if idStr == "" {
http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
return return

View File

@ -556,7 +556,7 @@ func TestServeAdminMembers(t *testing.T) {
id: 1, id: 1,
members: map[uint64]*etcdserver.Member{1: &memb1, 2: &memb2}, members: map[uint64]*etcdserver.Member{1: &memb1, 2: &memb2},
} }
h := &adminMembersHandler{ h := &membersHandler{
server: &serverRecorder{}, server: &serverRecorder{},
clock: clockwork.NewFakeClock(), clock: clockwork.NewFakeClock(),
clusterInfo: cluster, clusterInfo: cluster,
@ -570,10 +570,10 @@ func TestServeAdminMembers(t *testing.T) {
wct string wct string
wbody string wbody string
}{ }{
{adminMembersPrefix, http.StatusOK, "application/json", wmc + "\n"}, {membersPrefix, http.StatusOK, "application/json", wmc + "\n"},
{adminMembersPrefix + "/", http.StatusOK, "application/json", wmc + "\n"}, {membersPrefix + "/", http.StatusOK, "application/json", wmc + "\n"},
{path.Join(adminMembersPrefix, "100"), http.StatusNotFound, "application/json", `{"message":"Not found"}`}, {path.Join(membersPrefix, "100"), http.StatusNotFound, "application/json", `{"message":"Not found"}`},
{path.Join(adminMembersPrefix, "foobar"), http.StatusNotFound, "application/json", `{"message":"Not found"}`}, {path.Join(membersPrefix, "foobar"), http.StatusNotFound, "application/json", `{"message":"Not found"}`},
} }
for i, tt := range tests { for i, tt := range tests {
@ -602,7 +602,7 @@ func TestServeAdminMembers(t *testing.T) {
} }
func TestServeAdminMembersCreate(t *testing.T) { func TestServeAdminMembersCreate(t *testing.T) {
u := mustNewURL(t, adminMembersPrefix) u := mustNewURL(t, membersPrefix)
b := []byte(`{"peerURLs":["http://127.0.0.1:1"]}`) b := []byte(`{"peerURLs":["http://127.0.0.1:1"]}`)
req, err := http.NewRequest("POST", u.String(), bytes.NewReader(b)) req, err := http.NewRequest("POST", u.String(), bytes.NewReader(b))
if err != nil { if err != nil {
@ -610,7 +610,7 @@ func TestServeAdminMembersCreate(t *testing.T) {
} }
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
s := &serverRecorder{} s := &serverRecorder{}
h := &adminMembersHandler{ h := &membersHandler{
server: s, server: s,
clock: clockwork.NewFakeClock(), clock: clockwork.NewFakeClock(),
clusterInfo: &fakeCluster{id: 1}, clusterInfo: &fakeCluster{id: 1},
@ -656,10 +656,10 @@ func TestServeAdminMembersCreate(t *testing.T) {
func TestServeAdminMembersDelete(t *testing.T) { func TestServeAdminMembersDelete(t *testing.T) {
req := &http.Request{ req := &http.Request{
Method: "DELETE", Method: "DELETE",
URL: mustNewURL(t, path.Join(adminMembersPrefix, "BEEF")), URL: mustNewURL(t, path.Join(membersPrefix, "BEEF")),
} }
s := &serverRecorder{} s := &serverRecorder{}
h := &adminMembersHandler{ h := &membersHandler{
server: s, server: s,
clusterInfo: &fakeCluster{id: 1}, clusterInfo: &fakeCluster{id: 1},
} }
@ -714,7 +714,7 @@ func TestServeAdminMembersFail(t *testing.T) {
{ {
// parse body error // parse body error
&http.Request{ &http.Request{
URL: mustNewURL(t, adminMembersPrefix), URL: mustNewURL(t, membersPrefix),
Method: "POST", Method: "POST",
Body: ioutil.NopCloser(strings.NewReader("bad json")), Body: ioutil.NopCloser(strings.NewReader("bad json")),
Header: map[string][]string{"Content-Type": []string{"application/json"}}, Header: map[string][]string{"Content-Type": []string{"application/json"}},
@ -726,7 +726,7 @@ func TestServeAdminMembersFail(t *testing.T) {
{ {
// bad content type // bad content type
&http.Request{ &http.Request{
URL: mustNewURL(t, adminMembersPrefix), URL: mustNewURL(t, membersPrefix),
Method: "POST", Method: "POST",
Body: ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://127.0.0.1:1"]}`)), Body: ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://127.0.0.1:1"]}`)),
Header: map[string][]string{"Content-Type": []string{"application/bad"}}, Header: map[string][]string{"Content-Type": []string{"application/bad"}},
@ -738,7 +738,7 @@ func TestServeAdminMembersFail(t *testing.T) {
{ {
// bad url // bad url
&http.Request{ &http.Request{
URL: mustNewURL(t, adminMembersPrefix), URL: mustNewURL(t, membersPrefix),
Method: "POST", Method: "POST",
Body: ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://a"]}`)), Body: ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://a"]}`)),
Header: map[string][]string{"Content-Type": []string{"application/json"}}, Header: map[string][]string{"Content-Type": []string{"application/json"}},
@ -750,7 +750,7 @@ func TestServeAdminMembersFail(t *testing.T) {
{ {
// etcdserver.AddMember error // etcdserver.AddMember error
&http.Request{ &http.Request{
URL: mustNewURL(t, adminMembersPrefix), URL: mustNewURL(t, membersPrefix),
Method: "POST", Method: "POST",
Body: ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://127.0.0.1:1"]}`)), Body: ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://127.0.0.1:1"]}`)),
Header: map[string][]string{"Content-Type": []string{"application/json"}}, Header: map[string][]string{"Content-Type": []string{"application/json"}},
@ -764,7 +764,7 @@ func TestServeAdminMembersFail(t *testing.T) {
{ {
// etcdserver.RemoveMember error // etcdserver.RemoveMember error
&http.Request{ &http.Request{
URL: mustNewURL(t, path.Join(adminMembersPrefix, "1")), URL: mustNewURL(t, path.Join(membersPrefix, "1")),
Method: "DELETE", Method: "DELETE",
}, },
&errServer{ &errServer{
@ -776,7 +776,7 @@ func TestServeAdminMembersFail(t *testing.T) {
{ {
// etcdserver.RemoveMember error // etcdserver.RemoveMember error
&http.Request{ &http.Request{
URL: mustNewURL(t, adminMembersPrefix), URL: mustNewURL(t, membersPrefix),
Method: "DELETE", Method: "DELETE",
}, },
nil, nil,
@ -785,7 +785,7 @@ func TestServeAdminMembersFail(t *testing.T) {
}, },
} }
for i, tt := range tests { for i, tt := range tests {
h := &adminMembersHandler{ h := &membersHandler{
server: tt.server, server: tt.server,
clusterInfo: &fakeCluster{id: 1}, clusterInfo: &fakeCluster{id: 1},
clock: clockwork.NewFakeClock(), clock: clockwork.NewFakeClock(),
@ -1552,9 +1552,9 @@ func TestTrimPrefix(t *testing.T) {
prefix string prefix string
w string w string
}{ }{
{"/v2/admin/members", "/v2/admin/members", ""}, {"/v2/members", "/v2/members", ""},
{"/v2/admin/members/", "/v2/admin/members", ""}, {"/v2/members/", "/v2/members", ""},
{"/v2/admin/members/foo", "/v2/admin/members", "foo"}, {"/v2/members/foo", "/v2/members", "foo"},
} }
for i, tt := range tests { for i, tt := range tests {
if g := trimPrefix(tt.in, tt.prefix); g != tt.w { if g := trimPrefix(tt.in, tt.prefix); g != tt.w {