Merge pull request #1579 from vieux/fix_api_code

fix status code when container found on unhealthy node
This commit is contained in:
Xian Chaobo 2016-01-06 09:30:25 +08:00
commit ef8fb1cbc8
3 changed files with 23 additions and 7 deletions

View File

@ -375,7 +375,7 @@ func getContainerJSON(c *context, w http.ResponseWriter, r *http.Request) {
}
if !container.Engine.IsHealthy() {
httpError(w, fmt.Sprintf("Container %s running on unhealthy node %s", name, container.Engine.Name), http.StatusNotFound)
httpError(w, fmt.Sprintf("Container %s running on unhealthy node %s", name, container.Engine.Name), http.StatusInternalServerError)
return
}
@ -848,7 +848,10 @@ func proxyNetworkContainerOperation(c *context, w http.ResponseWriter, r *http.R
func proxyContainer(c *context, w http.ResponseWriter, r *http.Request) {
name, container, err := getContainerFromVars(c, mux.Vars(r))
if err != nil {
httpError(w, err.Error(), http.StatusNotFound)
if container == nil {
httpError(w, err.Error(), http.StatusNotFound)
}
httpError(w, err.Error(), http.StatusInternalServerError)
return
}
@ -868,7 +871,10 @@ func proxyContainer(c *context, w http.ResponseWriter, r *http.Request) {
func proxyContainerAndForceRefresh(c *context, w http.ResponseWriter, r *http.Request) {
name, container, err := getContainerFromVars(c, mux.Vars(r))
if err != nil {
httpError(w, err.Error(), http.StatusNotFound)
if container == nil {
httpError(w, err.Error(), http.StatusNotFound)
}
httpError(w, err.Error(), http.StatusInternalServerError)
return
}
@ -998,7 +1004,10 @@ func postCommit(c *context, w http.ResponseWriter, r *http.Request) {
// get container
name, container, err := getContainerFromVars(c, vars)
if err != nil {
httpError(w, err.Error(), http.StatusNotFound)
if container == nil {
httpError(w, err.Error(), http.StatusNotFound)
}
httpError(w, err.Error(), http.StatusInternalServerError)
return
}
// Set the full container ID in the proxied URL path.
@ -1074,7 +1083,10 @@ func postBuild(c *context, w http.ResponseWriter, r *http.Request) {
func postRenameContainer(c *context, w http.ResponseWriter, r *http.Request) {
_, container, err := getContainerFromVars(c, mux.Vars(r))
if err != nil {
httpError(w, err.Error(), http.StatusNotFound)
if container == nil {
httpError(w, err.Error(), http.StatusNotFound)
}
httpError(w, err.Error(), http.StatusInternalServerError)
return
}
@ -1097,7 +1109,10 @@ func postRenameContainer(c *context, w http.ResponseWriter, r *http.Request) {
func proxyHijack(c *context, w http.ResponseWriter, r *http.Request) {
name, container, err := getContainerFromVars(c, mux.Vars(r))
if err != nil {
httpError(w, err.Error(), http.StatusNotFound)
if container == nil {
httpError(w, err.Error(), http.StatusNotFound)
}
httpError(w, err.Error(), http.StatusInternalServerError)
return
}
// Set the full container ID in the proxied URL path.

View File

@ -65,7 +65,7 @@ func getContainerFromVars(c *context, vars map[string]string) (string, *cluster.
if name, ok := vars["name"]; ok {
if container := c.cluster.Container(name); container != nil {
if !container.Engine.IsHealthy() {
return name, nil, fmt.Errorf("Container %s running on unhealthy node %s", name, container.Engine.Name)
return name, container, fmt.Errorf("Container %s running on unhealthy node %s", name, container.Engine.Name)
}
return name, container, nil
}

View File

@ -50,6 +50,7 @@ function teardown() {
swarm_manage
docker_swarm run -d --name c1 busybox echo c1
sleep 1 #sleep so the 2 containers don't start at the same second
docker_swarm run -d --name c2 busybox echo c2
run eval "docker_swarm ps --before c1 2>/dev/null"