From 16bdbaaa3357dc1be7d74a283a3ed8d0d861a461 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Mon, 14 Nov 2016 14:50:16 -0500 Subject: [PATCH] Convert ContainerTopOKResponse from swagger spec. Signed-off-by: Daniel Nephin --- api/server/router/container/backend.go | 2 +- api/swagger.yaml | 23 +++++++++++------------ api/types/container/container_top.go | 21 +++++++++++++++++++++ api/types/types.go | 6 ------ client/container_top.go | 6 +++--- client/container_top_test.go | 4 ++-- client/interface.go | 2 +- daemon/top_unix.go | 8 ++++---- daemon/top_windows.go | 6 +++--- hack/generate-swagger-api.sh | 1 + 10 files changed, 47 insertions(+), 32 deletions(-) create mode 100644 api/types/container/container_top.go diff --git a/api/server/router/container/backend.go b/api/server/router/container/backend.go index 0d20188ccf..6f729bea16 100644 --- a/api/server/router/container/backend.go +++ b/api/server/router/container/backend.go @@ -53,7 +53,7 @@ type monitorBackend interface { ContainerInspect(name string, size bool, version string) (interface{}, error) ContainerLogs(ctx context.Context, name string, config *backend.ContainerLogsConfig, started chan struct{}) error ContainerStats(ctx context.Context, name string, config *backend.ContainerStatsConfig) error - ContainerTop(name string, psArgs string) (*types.ContainerProcessList, error) + ContainerTop(name string, psArgs string) (*container.ContainerTopOKBody, error) Containers(config *types.ContainerListOptions) ([]*types.Container, error) } diff --git a/api/swagger.yaml b/api/swagger.yaml index 3bf244554f..f7ab6cd199 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -3384,12 +3384,14 @@ paths: get: summary: "Get container stats based on resource usage" description: | - This endpoint returns a live stream of a container’s resource usage statistics. + This endpoint returns a live stream of a container’s resource usage + statistics. - The `precpu_stats` is the CPU statistic of last read, which is used for calculating the CPU usage percentage. It is not the same as the `cpu_stats` field. + The `precpu_stats` is the CPU statistic of last read, which is used + for calculating the CPU usage percentage. It is not the same as the + `cpu_stats` field. operationId: "ContainerStats" - produces: - - "application/json" + produces: ["application/json"] responses: 200: description: "no error" @@ -4111,7 +4113,7 @@ paths: head: summary: "Get information about files in a container" description: "A response header `X-Docker-Container-Path-Stat` is return containing a base64 - encoded JSON object with some filesystem header information about the path." - operationId: "ContainerArchiveHead" + operationId: "ContainerArchiveInfo" responses: 200: description: "no error" @@ -4156,9 +4158,8 @@ paths: get: summary: "Get an archive of a filesystem resource in a container" description: "Get a tar archive of a resource in the filesystem of container id." - operationId: "ContainerGetArchive" - produces: - - "application/x-tar" + operationId: "ContainerArchive" + produces: ["application/x-tar"] responses: 200: description: "no error" @@ -4199,10 +4200,8 @@ paths: put: summary: "Extract an archive of files or folders to a directory in a container" description: "Upload a tar archive to be extracted to a path in the filesystem of container id." - operationId: "ContainerPutArchive" - consumes: - - "application/x-tar" - - "application/octet-stream" + operationId: "PutContainerArchive" + consumes: ["application/x-tar", "application/octet-stream"] responses: 200: description: "The content was extracted successfully" diff --git a/api/types/container/container_top.go b/api/types/container/container_top.go new file mode 100644 index 0000000000..e1e7602842 --- /dev/null +++ b/api/types/container/container_top.go @@ -0,0 +1,21 @@ +package container + +// ---------------------------------------------------------------------------- +// DO NOT EDIT THIS FILE +// This file was generated by `swagger generate operation` +// +// See hack/swagger-gen.sh +// ---------------------------------------------------------------------------- + +// ContainerTopOKBody container top o k body +// swagger:model ContainerTopOKBody +type ContainerTopOKBody struct { + + // Each process running in the container, where each is process is an array of values corresponding to the titles + // Required: true + Processes [][]string `json:"Processes"` + + // The ps column titles + // Required: true + Titles []string `json:"Titles"` +} diff --git a/api/types/types.go b/api/types/types.go index 3539b0b05b..b4fc1c6408 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -93,12 +93,6 @@ type ContainerStats struct { OSType string `json:"ostype"` } -// ContainerProcessList contains response of Engine API: -// GET "/containers/{name:.*}/top" -type ContainerProcessList struct { - Processes [][]string - Titles []string -} // Ping contains response of Engine API: // GET "/_ping" diff --git a/client/container_top.go b/client/container_top.go index 4e7270ea22..9689123a40 100644 --- a/client/container_top.go +++ b/client/container_top.go @@ -5,13 +5,13 @@ import ( "net/url" "strings" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "golang.org/x/net/context" ) // ContainerTop shows process information from within a container. -func (cli *Client) ContainerTop(ctx context.Context, containerID string, arguments []string) (types.ContainerProcessList, error) { - var response types.ContainerProcessList +func (cli *Client) ContainerTop(ctx context.Context, containerID string, arguments []string) (container.ContainerTopOKBody, error) { + var response container.ContainerTopOKBody query := url.Values{} if len(arguments) > 0 { query.Set("ps_args", strings.Join(arguments, " ")) diff --git a/client/container_top_test.go b/client/container_top_test.go index 7802be063e..68ccef505d 100644 --- a/client/container_top_test.go +++ b/client/container_top_test.go @@ -10,7 +10,7 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "golang.org/x/net/context" ) @@ -43,7 +43,7 @@ func TestContainerTop(t *testing.T) { return nil, fmt.Errorf("args not set in URL query properly. Expected 'arg1 arg2', got %v", args) } - b, err := json.Marshal(types.ContainerProcessList{ + b, err := json.Marshal(container.ContainerTopOKBody{ Processes: [][]string{ {"p1", "p2"}, {"p3"}, diff --git a/client/interface.go b/client/interface.go index e3bcb19950..ef9b10bba3 100644 --- a/client/interface.go +++ b/client/interface.go @@ -59,7 +59,7 @@ type ContainerAPIClient interface { ContainerStats(ctx context.Context, container string, stream bool) (types.ContainerStats, error) ContainerStart(ctx context.Context, container string, options types.ContainerStartOptions) error ContainerStop(ctx context.Context, container string, timeout *time.Duration) error - ContainerTop(ctx context.Context, container string, arguments []string) (types.ContainerProcessList, error) + ContainerTop(ctx context.Context, container string, arguments []string) (container.ContainerTopOKBody, 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) (int64, error) diff --git a/daemon/top_unix.go b/daemon/top_unix.go index 7fb81d0148..864c5f5422 100644 --- a/daemon/top_unix.go +++ b/daemon/top_unix.go @@ -9,7 +9,7 @@ import ( "strconv" "strings" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" ) func validatePSArgs(psArgs string) error { @@ -41,8 +41,8 @@ func fieldsASCII(s string) []string { return strings.FieldsFunc(s, fn) } -func parsePSOutput(output []byte, pids []int) (*types.ContainerProcessList, error) { - procList := &types.ContainerProcessList{} +func parsePSOutput(output []byte, pids []int) (*container.ContainerTopOKBody, error) { + procList := &container.ContainerTopOKBody{} lines := strings.Split(string(output), "\n") procList.Titles = fieldsASCII(lines[0]) @@ -86,7 +86,7 @@ func parsePSOutput(output []byte, pids []int) (*types.ContainerProcessList, erro // "-ef" if no args are given. An error is returned if the container // is not found, or is not running, or if there are any problems // running ps, or parsing the output. -func (daemon *Daemon) ContainerTop(name string, psArgs string) (*types.ContainerProcessList, error) { +func (daemon *Daemon) ContainerTop(name string, psArgs string) (*container.ContainerTopOKBody, error) { if psArgs == "" { psArgs = "-ef" } diff --git a/daemon/top_windows.go b/daemon/top_windows.go index 3dd8ead468..000720b004 100644 --- a/daemon/top_windows.go +++ b/daemon/top_windows.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/docker/docker/api/types" + containertypes "github.com/docker/docker/api/types/container" "github.com/docker/go-units" ) @@ -23,7 +23,7 @@ import ( // task manager does and use the private working set as the memory counter. // We could return more info for those who really understand how memory // management works in Windows if we introduced a "raw" stats (above). -func (daemon *Daemon) ContainerTop(name string, psArgs string) (*types.ContainerProcessList, error) { +func (daemon *Daemon) ContainerTop(name string, psArgs string) (*containertypes.ContainerTopOKBody, error) { // It's not at all an equivalent to linux 'ps' on Windows if psArgs != "" { return nil, errors.New("Windows does not support arguments to top") @@ -38,7 +38,7 @@ func (daemon *Daemon) ContainerTop(name string, psArgs string) (*types.Container if err != nil { return nil, err } - procList := &types.ContainerProcessList{} + procList := &containertypes.ContainerTopOKBody{} procList.Titles = []string{"Name", "PID", "CPU", "Private Working Set"} for _, j := range s { diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index 0edda3c68b..9bbd8de5d7 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -19,6 +19,7 @@ swagger generate operation -f api/swagger.yaml \ -n Authenticate \ -n ContainerChanges \ -n ContainerCreate \ + -n ContainerTop \ -n ContainerUpdate \ -n ContainerWait \ -n ImageHistory \