diff --git a/api/server/router/container/backend.go b/api/server/router/container/backend.go index e6a5b06b07..6c6766c324 100644 --- a/api/server/router/container/backend.go +++ b/api/server/router/container/backend.go @@ -50,7 +50,7 @@ type monitorBackend interface { ContainerInspect(ctx context.Context, name string, options backend.ContainerInspectOptions) (*container.InspectResponse, error) ContainerLogs(ctx context.Context, name string, config *container.LogsOptions) (msgs <-chan *backend.LogMessage, tty bool, err error) ContainerStats(ctx context.Context, name string, config *backend.ContainerStatsConfig) error - ContainerTop(name string, psArgs string) (*container.ContainerTopOKBody, error) + ContainerTop(name string, psArgs string) (*container.TopResponse, error) Containers(ctx context.Context, config *container.ListOptions) ([]*container.Summary, error) } diff --git a/api/swagger.yaml b/api/swagger.yaml index 707007d3ea..9fa42c8517 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -5886,6 +5886,58 @@ definitions: x-nullable: true example: 7593984 + ContainerTopResponse: + type: "object" + x-go-name: "TopResponse" + title: "ContainerTopResponse" + description: |- + Container "top" response. + properties: + Titles: + description: "The ps column titles" + type: "array" + items: + type: "string" + example: + Titles: + - "UID" + - "PID" + - "PPID" + - "C" + - "STIME" + - "TTY" + - "TIME" + - "CMD" + Processes: + description: |- + Each process running in the container, where each process + is an array of values corresponding to the titles. + type: "array" + items: + type: "array" + items: + type: "string" + example: + Processes: + - + - "root" + - "13642" + - "882" + - "0" + - "17:03" + - "pts/0" + - "00:00:00" + - "/bin/bash" + - + - "root" + - "13735" + - "13642" + - "0" + - "17:06" + - "pts/0" + - "00:00:00" + - "sleep 10" + ContainerWaitResponse: description: "OK response to ContainerWait operation" type: "object" @@ -8087,54 +8139,7 @@ paths: 200: description: "no error" schema: - type: "object" - title: "ContainerTopResponse" - description: "OK response to ContainerTop operation" - properties: - Titles: - description: "The ps column titles" - type: "array" - items: - type: "string" - Processes: - description: | - Each process running in the container, where each is process - is an array of values corresponding to the titles. - type: "array" - items: - type: "array" - items: - type: "string" - examples: - application/json: - Titles: - - "UID" - - "PID" - - "PPID" - - "C" - - "STIME" - - "TTY" - - "TIME" - - "CMD" - Processes: - - - - "root" - - "13642" - - "882" - - "0" - - "17:03" - - "pts/0" - - "00:00:00" - - "/bin/bash" - - - - "root" - - "13735" - - "13642" - - "0" - - "17:06" - - "pts/0" - - "00:00:00" - - "sleep 10" + $ref: "#/definitions/ContainerTopResponse" 404: description: "no such container" schema: diff --git a/api/types/container/container.go b/api/types/container/container.go index 9642563968..b5e6243de6 100644 --- a/api/types/container/container.go +++ b/api/types/container/container.go @@ -15,6 +15,11 @@ import ( // Deprecated: use [UpdateResponse]. This alias will be removed in the next release. type ContainerUpdateOKBody = UpdateResponse +// ContainerTopOKBody OK response to ContainerTop operation +// +// Deprecated: use [TopResponse]. This alias will be removed in the next release. +type ContainerTopOKBody = TopResponse + // PruneReport contains the response for Engine API: // POST "/containers/prune" type PruneReport struct { diff --git a/api/types/container/container_top.go b/api/types/container/container_top.go deleted file mode 100644 index 63381da367..0000000000 --- a/api/types/container/container_top.go +++ /dev/null @@ -1,22 +0,0 @@ -package container // import "github.com/docker/docker/api/types/container" - -// ---------------------------------------------------------------------------- -// Code generated by `swagger generate operation`. DO NOT EDIT. -// -// See hack/generate-swagger-api.sh -// ---------------------------------------------------------------------------- - -// ContainerTopOKBody OK response to ContainerTop operation -// 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/container/top_response.go b/api/types/container/top_response.go new file mode 100644 index 0000000000..b4bae5ef03 --- /dev/null +++ b/api/types/container/top_response.go @@ -0,0 +1,18 @@ +package container + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +// TopResponse ContainerTopResponse +// +// Container "top" response. +// swagger:model TopResponse +type TopResponse struct { + + // Each process running in the container, where each process + // is an array of values corresponding to the titles. + Processes [][]string `json:"Processes"` + + // The ps column titles + Titles []string `json:"Titles"` +} diff --git a/client/client_interfaces.go b/client/client_interfaces.go index d16991e41b..95a25da71e 100644 --- a/client/client_interfaces.go +++ b/client/client_interfaces.go @@ -93,7 +93,7 @@ type ContainerAPIClient interface { ContainerStatsOneShot(ctx context.Context, container string) (container.StatsResponseReader, error) ContainerStart(ctx context.Context, container string, options container.StartOptions) error ContainerStop(ctx context.Context, container string, options container.StopOptions) error - ContainerTop(ctx context.Context, container string, arguments []string) (container.ContainerTopOKBody, error) + ContainerTop(ctx context.Context, container string, arguments []string) (container.TopResponse, error) ContainerUnpause(ctx context.Context, container string) error ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (container.UpdateResponse, error) ContainerWait(ctx context.Context, container string, condition container.WaitCondition) (<-chan container.WaitResponse, <-chan error) diff --git a/client/container_top.go b/client/container_top.go index 4eac031fae..88299e36f4 100644 --- a/client/container_top.go +++ b/client/container_top.go @@ -10,10 +10,10 @@ import ( ) // ContainerTop shows process information from within a container. -func (cli *Client) ContainerTop(ctx context.Context, containerID string, arguments []string) (container.ContainerTopOKBody, error) { +func (cli *Client) ContainerTop(ctx context.Context, containerID string, arguments []string) (container.TopResponse, error) { containerID, err := trimID("container", containerID) if err != nil { - return container.ContainerTopOKBody{}, err + return container.TopResponse{}, err } query := url.Values{} @@ -24,10 +24,10 @@ func (cli *Client) ContainerTop(ctx context.Context, containerID string, argumen resp, err := cli.get(ctx, "/containers/"+containerID+"/top", query, nil) defer ensureReaderClosed(resp) if err != nil { - return container.ContainerTopOKBody{}, err + return container.TopResponse{}, err } - var response container.ContainerTopOKBody + var response container.TopResponse err = json.NewDecoder(resp.body).Decode(&response) return response, err } diff --git a/client/container_top_test.go b/client/container_top_test.go index 92a6626881..e6aef48886 100644 --- a/client/container_top_test.go +++ b/client/container_top_test.go @@ -52,7 +52,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(container.ContainerTopOKBody{ + b, err := json.Marshal(container.TopResponse{ Processes: [][]string{ {"p1", "p2"}, {"p3"}, diff --git a/daemon/top_unix.go b/daemon/top_unix.go index fae2183795..fd5e1d377a 100644 --- a/daemon/top_unix.go +++ b/daemon/top_unix.go @@ -50,7 +50,7 @@ func fieldsASCII(s string) []string { return strings.FieldsFunc(s, fn) } -func appendProcess2ProcList(procList *container.ContainerTopOKBody, fields []string) { +func appendProcess2ProcList(procList *container.TopResponse, fields []string) { // Make sure number of fields equals number of header titles // merging "overhanging" fields process := fields[:len(procList.Titles)-1] @@ -67,8 +67,8 @@ func hasPid(procs []uint32, pid int) bool { return false } -func parsePSOutput(output []byte, procs []uint32) (*container.ContainerTopOKBody, error) { - procList := &container.ContainerTopOKBody{} +func parsePSOutput(output []byte, procs []uint32) (*container.TopResponse, error) { + procList := &container.TopResponse{} lines := strings.Split(string(output), "\n") procList.Titles = fieldsASCII(lines[0]) @@ -139,7 +139,7 @@ func psPidsArg(pids []uint32) string { // "-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) (*container.ContainerTopOKBody, error) { +func (daemon *Daemon) ContainerTop(name string, psArgs string) (*container.TopResponse, error) { if psArgs == "" { psArgs = "-ef" } diff --git a/daemon/top_windows.go b/daemon/top_windows.go index 4e87cbfc9a..052be83aaa 100644 --- a/daemon/top_windows.go +++ b/daemon/top_windows.go @@ -6,7 +6,7 @@ import ( "fmt" "time" - containertypes "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/container" libcontainerdtypes "github.com/docker/docker/libcontainerd/types" "github.com/docker/go-units" ) @@ -26,27 +26,27 @@ 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) (*containertypes.ContainerTopOKBody, error) { +func (daemon *Daemon) ContainerTop(name string, psArgs string) (*container.TopResponse, 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") } - container, err := daemon.GetContainer(name) + ctr, err := daemon.GetContainer(name) if err != nil { return nil, err } task, err := func() (libcontainerdtypes.Task, error) { - container.Lock() - defer container.Unlock() + ctr.Lock() + defer ctr.Unlock() - task, err := container.GetRunningTask() + task, err := ctr.GetRunningTask() if err != nil { return nil, err } - if container.Restarting { - return nil, errContainerIsRestarting(container.ID) + if ctr.Restarting { + return nil, errContainerIsRestarting(ctr.ID) } return task, nil }() @@ -55,8 +55,9 @@ func (daemon *Daemon) ContainerTop(name string, psArgs string) (*containertypes. if err != nil { return nil, err } - procList := &containertypes.ContainerTopOKBody{} - procList.Titles = []string{"Name", "PID", "CPU", "Private Working Set"} + procList := &container.TopResponse{ + Titles: []string{"Name", "PID", "CPU", "Private Working Set"}, + } for _, j := range s { d := time.Duration((j.KernelTime_100Ns + j.UserTime_100Ns) * 100) // Combined time in nanoseconds diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index 04fb5acedc..ba7e1491e6 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -19,6 +19,7 @@ swagger generate model -f api/swagger.yaml \ -t api -m types/container --skip-validator -C api/swagger-gen.yaml \ -n ContainerCreateResponse \ -n ContainerUpdateResponse \ + -n ContainerTopResponse \ -n ContainerWaitResponse \ -n ContainerWaitExitError \ -n ChangeType \ @@ -45,7 +46,6 @@ swagger generate operation -f api/swagger.yaml \ -t api -a types -m types -C api/swagger-gen.yaml \ -T api/templates --skip-responses --skip-parameters --skip-validator \ -n Authenticate \ - -n ContainerTop \ -n ImageHistory swagger generate model -f api/swagger.yaml \