|
@@ -59,7 +59,7 @@ func SetHttpHandler(w *http.ResponseWriter, req *http.Request) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- debugf("[recv] POST %v/v1/keys/%s [%s]", info.EtcdURL, key, req.RemoteAddr)
|
|
|
|
|
|
|
+ debugf("[recv] POST %v/v1/keys/%s [%s]", e.url, key, req.RemoteAddr)
|
|
|
|
|
|
|
|
value := req.FormValue("value")
|
|
value := req.FormValue("value")
|
|
|
|
|
|
|
@@ -110,7 +110,7 @@ func SetHttpHandler(w *http.ResponseWriter, req *http.Request) {
|
|
|
func DeleteHttpHandler(w *http.ResponseWriter, req *http.Request) {
|
|
func DeleteHttpHandler(w *http.ResponseWriter, req *http.Request) {
|
|
|
key := req.URL.Path[len("/v1/keys/"):]
|
|
key := req.URL.Path[len("/v1/keys/"):]
|
|
|
|
|
|
|
|
- debugf("[recv] DELETE %v/v1/keys/%s [%s]", info.EtcdURL, key, req.RemoteAddr)
|
|
|
|
|
|
|
+ debugf("[recv] DELETE %v/v1/keys/%s [%s]", e.url, key, req.RemoteAddr)
|
|
|
|
|
|
|
|
command := &DeleteCommand{
|
|
command := &DeleteCommand{
|
|
|
Key: key,
|
|
Key: key,
|
|
@@ -122,8 +122,8 @@ func DeleteHttpHandler(w *http.ResponseWriter, req *http.Request) {
|
|
|
// Dispatch the command to leader
|
|
// Dispatch the command to leader
|
|
|
func dispatch(c Command, w *http.ResponseWriter, req *http.Request, etcd bool) {
|
|
func dispatch(c Command, w *http.ResponseWriter, req *http.Request, etcd bool) {
|
|
|
|
|
|
|
|
- if raftServer.State() == raft.Leader {
|
|
|
|
|
- if body, err := raftServer.Do(c); err != nil {
|
|
|
|
|
|
|
+ if r.server.State() == raft.Leader {
|
|
|
|
|
+ if body, err := r.server.Do(c); err != nil {
|
|
|
|
|
|
|
|
if _, ok := err.(store.NotFoundError); ok {
|
|
if _, ok := err.(store.NotFoundError); ok {
|
|
|
(*w).WriteHeader(http.StatusNotFound)
|
|
(*w).WriteHeader(http.StatusNotFound)
|
|
@@ -167,7 +167,7 @@ func dispatch(c Command, w *http.ResponseWriter, req *http.Request, etcd bool) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- leader := raftServer.Leader()
|
|
|
|
|
|
|
+ leader := r.server.Leader()
|
|
|
// current no leader
|
|
// current no leader
|
|
|
if leader == "" {
|
|
if leader == "" {
|
|
|
(*w).WriteHeader(http.StatusInternalServerError)
|
|
(*w).WriteHeader(http.StatusInternalServerError)
|
|
@@ -211,7 +211,7 @@ func dispatch(c Command, w *http.ResponseWriter, req *http.Request, etcd bool) {
|
|
|
|
|
|
|
|
// Handler to return the current leader's raft address
|
|
// Handler to return the current leader's raft address
|
|
|
func LeaderHttpHandler(w http.ResponseWriter, req *http.Request) {
|
|
func LeaderHttpHandler(w http.ResponseWriter, req *http.Request) {
|
|
|
- leader := raftServer.Leader()
|
|
|
|
|
|
|
+ leader := r.server.Leader()
|
|
|
|
|
|
|
|
if leader != "" {
|
|
if leader != "" {
|
|
|
w.WriteHeader(http.StatusOK)
|
|
w.WriteHeader(http.StatusOK)
|
|
@@ -250,13 +250,13 @@ func StatsHttpHandler(w http.ResponseWriter, req *http.Request) {
|
|
|
func GetHttpHandler(w *http.ResponseWriter, req *http.Request) {
|
|
func GetHttpHandler(w *http.ResponseWriter, req *http.Request) {
|
|
|
key := req.URL.Path[len("/v1/keys/"):]
|
|
key := req.URL.Path[len("/v1/keys/"):]
|
|
|
|
|
|
|
|
- debugf("[recv] GET %s/v1/keys/%s [%s]", info.EtcdURL, key, req.RemoteAddr)
|
|
|
|
|
|
|
+ debugf("[recv] GET %s/v1/keys/%s [%s]", e.url, key, req.RemoteAddr)
|
|
|
|
|
|
|
|
command := &GetCommand{
|
|
command := &GetCommand{
|
|
|
Key: key,
|
|
Key: key,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if body, err := command.Apply(raftServer); err != nil {
|
|
|
|
|
|
|
+ if body, err := command.Apply(r.server); err != nil {
|
|
|
|
|
|
|
|
if _, ok := err.(store.NotFoundError); ok {
|
|
if _, ok := err.(store.NotFoundError); ok {
|
|
|
(*w).WriteHeader(http.StatusNotFound)
|
|
(*w).WriteHeader(http.StatusNotFound)
|
|
@@ -289,13 +289,13 @@ func WatchHttpHandler(w http.ResponseWriter, req *http.Request) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if req.Method == "GET" {
|
|
if req.Method == "GET" {
|
|
|
- debugf("[recv] GET %s/watch/%s [%s]", info.EtcdURL, key, req.RemoteAddr)
|
|
|
|
|
|
|
+ debugf("[recv] GET %s/watch/%s [%s]", e.url, key, req.RemoteAddr)
|
|
|
command.SinceIndex = 0
|
|
command.SinceIndex = 0
|
|
|
|
|
|
|
|
} else if req.Method == "POST" {
|
|
} else if req.Method == "POST" {
|
|
|
// watch from a specific index
|
|
// watch from a specific index
|
|
|
|
|
|
|
|
- debugf("[recv] POST %s/watch/%s [%s]", info.EtcdURL, key, req.RemoteAddr)
|
|
|
|
|
|
|
+ debugf("[recv] POST %s/watch/%s [%s]", e.url, key, req.RemoteAddr)
|
|
|
content := req.FormValue("index")
|
|
content := req.FormValue("index")
|
|
|
|
|
|
|
|
sinceIndex, err := strconv.ParseUint(string(content), 10, 64)
|
|
sinceIndex, err := strconv.ParseUint(string(content), 10, 64)
|
|
@@ -310,7 +310,7 @@ func WatchHttpHandler(w http.ResponseWriter, req *http.Request) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if body, err := command.Apply(raftServer); err != nil {
|
|
|
|
|
|
|
+ if body, err := command.Apply(r.server); err != nil {
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
w.Write(newJsonError(500, key))
|
|
w.Write(newJsonError(500, key))
|
|
|
} else {
|
|
} else {
|