diff --git a/api/server/router/container/container_routes.go b/api/server/router/container/container_routes.go index f721268ba8..c0c008c010 100644 --- a/api/server/router/container/container_routes.go +++ b/api/server/router/container/container_routes.go @@ -283,8 +283,8 @@ func (s *containerRouter) postContainersWait(ctx context.Context, w http.Respons return err } - return httputils.WriteJSON(w, http.StatusOK, &types.ContainerWaitResponse{ - StatusCode: status, + return httputils.WriteJSON(w, http.StatusOK, &container.ContainerWaitOKBody{ + StatusCode: int64(status), }) } diff --git a/api/swagger.yaml b/api/swagger.yaml index 79cde950a5..94cc36a172 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -3780,18 +3780,19 @@ paths: post: summary: "Wait for a container" description: "Block until a container stops, then returns the exit code." - operationId: "PostContainerWait" - produces: - - "application/json" + operationId: "ContainerWait" + produces: ["application/json"] responses: 200: - description: "no error" + description: "The container has exit." schema: type: "object" + required: [StatusCode] properties: StatusCode: description: "Exit code of the container" type: "integer" + x-nullable: false 404: description: "no such container" schema: diff --git a/api/types/container/container_wait.go b/api/types/container/container_wait.go new file mode 100644 index 0000000000..16cf335321 --- /dev/null +++ b/api/types/container/container_wait.go @@ -0,0 +1,17 @@ +package container + +// ---------------------------------------------------------------------------- +// DO NOT EDIT THIS FILE +// This file was generated by `swagger generate operation` +// +// See hack/swagger-gen.sh +// ---------------------------------------------------------------------------- + +// ContainerWaitOKBody container wait o k body +// swagger:model ContainerWaitOKBody +type ContainerWaitOKBody struct { + + // Exit code of the container + // Required: true + StatusCode int64 `json:"StatusCode"` +} diff --git a/api/types/types.go b/api/types/types.go index 6f5f753c8b..bd9bf7bf6a 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -13,13 +13,6 @@ import ( "github.com/docker/go-connections/nat" ) -// ContainerWaitResponse contains response of Remote API: -// POST "/containers/"+containerID+"/wait" -type ContainerWaitResponse struct { - // StatusCode is the status code of the wait job - StatusCode int `json:"StatusCode"` -} - // ContainerChange contains response of Remote API: // GET "/containers/{name:.*}/changes" type ContainerChange struct { diff --git a/client/container_wait.go b/client/container_wait.go index 8a858f0ea3..93212c70ee 100644 --- a/client/container_wait.go +++ b/client/container_wait.go @@ -5,19 +5,19 @@ import ( "golang.org/x/net/context" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" ) // ContainerWait pauses execution until a container exits. // It returns the API status code as response of its readiness. -func (cli *Client) ContainerWait(ctx context.Context, containerID string) (int, error) { +func (cli *Client) ContainerWait(ctx context.Context, containerID string) (int64, error) { resp, err := cli.post(ctx, "/containers/"+containerID+"/wait", nil, nil, nil) if err != nil { return -1, err } defer ensureReaderClosed(resp) - var res types.ContainerWaitResponse + var res container.ContainerWaitOKBody if err := json.NewDecoder(resp.body).Decode(&res); err != nil { return -1, err } diff --git a/client/container_wait_test.go b/client/container_wait_test.go index dab5acbdd3..9300bc0a54 100644 --- a/client/container_wait_test.go +++ b/client/container_wait_test.go @@ -11,7 +11,7 @@ import ( "testing" "time" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "golang.org/x/net/context" ) @@ -36,7 +36,7 @@ func TestContainerWait(t *testing.T) { if !strings.HasPrefix(req.URL.Path, expectedURL) { return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) } - b, err := json.Marshal(types.ContainerWaitResponse{ + b, err := json.Marshal(container.ContainerWaitOKBody{ StatusCode: 15, }) if err != nil { diff --git a/client/interface.go b/client/interface.go index f044c32352..a78cb759cd 100644 --- a/client/interface.go +++ b/client/interface.go @@ -59,7 +59,7 @@ type ContainerAPIClient interface { ContainerTop(ctx context.Context, container string, arguments []string) (types.ContainerProcessList, error) ContainerUnpause(ctx context.Context, container string) error ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error) - ContainerWait(ctx context.Context, container string) (int, error) + ContainerWait(ctx context.Context, container string) (int64, error) CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error ContainersPrune(ctx context.Context, cfg types.ContainersPruneConfig) (types.ContainersPruneReport, error) diff --git a/daemon/cluster/executor/backend.go b/daemon/cluster/executor/backend.go index c34c2076e0..fba4adec18 100644 --- a/daemon/cluster/executor/backend.go +++ b/daemon/cluster/executor/backend.go @@ -23,7 +23,7 @@ type Backend interface { FindNetwork(idName string) (libnetwork.Network, error) SetupIngress(req clustertypes.NetworkCreateRequest, nodeIP string) error PullImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error - CreateManagedContainer(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateResponse, error) + CreateManagedContainer(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateCreatedBody, error) ContainerStart(name string, hostConfig *container.HostConfig, validateHostname bool, checkpoint string, checkpointDir string) error ContainerStop(name string, seconds *int) error ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index 2a7c8f2053..d46eaa33de 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -17,4 +17,5 @@ swagger generate operation -f api/swagger.yaml \ -n VolumesCreate \ -n ContainerCreate \ -n ContainerUpdate \ - -n Authenticate + -n Authenticate \ + -n ContainerWait diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index e4415a81be..766d676be9 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -957,9 +957,9 @@ func (s *DockerSuite) TestContainerAPIWait(c *check.C) { c.Assert(status, checker.Equals, http.StatusOK) c.Assert(waitInspect(name, "{{ .State.Running }}", "false", 60*time.Second), checker.IsNil) - var waitres types.ContainerWaitResponse + var waitres containertypes.ContainerWaitOKBody c.Assert(json.Unmarshal(body, &waitres), checker.IsNil) - c.Assert(waitres.StatusCode, checker.Equals, 0) + c.Assert(waitres.StatusCode, checker.Equals, int64(0)) } func (s *DockerSuite) TestContainerAPICopyNotExistsAnyMore(c *check.C) {