Skip to content

Commit be1ac5d

Browse files
committed
api/types/container: rename ContainerTopOKBody to TopResponse
Deprecate ContainerTopOKBody, but keep an alias. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent f4dc38c commit be1ac5d

11 files changed

Lines changed: 99 additions & 92 deletions

File tree

api/server/router/container/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type monitorBackend interface {
5050
ContainerInspect(ctx context.Context, name string, options backend.ContainerInspectOptions) (*container.InspectResponse, error)
5151
ContainerLogs(ctx context.Context, name string, config *container.LogsOptions) (msgs <-chan *backend.LogMessage, tty bool, err error)
5252
ContainerStats(ctx context.Context, name string, config *backend.ContainerStatsConfig) error
53-
ContainerTop(name string, psArgs string) (*container.ContainerTopOKBody, error)
53+
ContainerTop(name string, psArgs string) (*container.TopResponse, error)
5454
Containers(ctx context.Context, config *container.ListOptions) ([]*container.Summary, error)
5555
}
5656

api/swagger.yaml

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5886,6 +5886,58 @@ definitions:
58865886
x-nullable: true
58875887
example: 7593984
58885888

5889+
ContainerTopResponse:
5890+
type: "object"
5891+
x-go-name: "TopResponse"
5892+
title: "ContainerTopResponse"
5893+
description: |-
5894+
Container "top" response.
5895+
properties:
5896+
Titles:
5897+
description: "The ps column titles"
5898+
type: "array"
5899+
items:
5900+
type: "string"
5901+
example:
5902+
Titles:
5903+
- "UID"
5904+
- "PID"
5905+
- "PPID"
5906+
- "C"
5907+
- "STIME"
5908+
- "TTY"
5909+
- "TIME"
5910+
- "CMD"
5911+
Processes:
5912+
description: |-
5913+
Each process running in the container, where each process
5914+
is an array of values corresponding to the titles.
5915+
type: "array"
5916+
items:
5917+
type: "array"
5918+
items:
5919+
type: "string"
5920+
example:
5921+
Processes:
5922+
-
5923+
- "root"
5924+
- "13642"
5925+
- "882"
5926+
- "0"
5927+
- "17:03"
5928+
- "pts/0"
5929+
- "00:00:00"
5930+
- "/bin/bash"
5931+
-
5932+
- "root"
5933+
- "13735"
5934+
- "13642"
5935+
- "0"
5936+
- "17:06"
5937+
- "pts/0"
5938+
- "00:00:00"
5939+
- "sleep 10"
5940+
58895941
ContainerWaitResponse:
58905942
description: "OK response to ContainerWait operation"
58915943
type: "object"
@@ -8087,54 +8139,7 @@ paths:
80878139
200:
80888140
description: "no error"
80898141
schema:
8090-
type: "object"
8091-
title: "ContainerTopResponse"
8092-
description: "OK response to ContainerTop operation"
8093-
properties:
8094-
Titles:
8095-
description: "The ps column titles"
8096-
type: "array"
8097-
items:
8098-
type: "string"
8099-
Processes:
8100-
description: |
8101-
Each process running in the container, where each is process
8102-
is an array of values corresponding to the titles.
8103-
type: "array"
8104-
items:
8105-
type: "array"
8106-
items:
8107-
type: "string"
8108-
examples:
8109-
application/json:
8110-
Titles:
8111-
- "UID"
8112-
- "PID"
8113-
- "PPID"
8114-
- "C"
8115-
- "STIME"
8116-
- "TTY"
8117-
- "TIME"
8118-
- "CMD"
8119-
Processes:
8120-
-
8121-
- "root"
8122-
- "13642"
8123-
- "882"
8124-
- "0"
8125-
- "17:03"
8126-
- "pts/0"
8127-
- "00:00:00"
8128-
- "/bin/bash"
8129-
-
8130-
- "root"
8131-
- "13735"
8132-
- "13642"
8133-
- "0"
8134-
- "17:06"
8135-
- "pts/0"
8136-
- "00:00:00"
8137-
- "sleep 10"
8142+
$ref: "#/definitions/ContainerTopResponse"
81388143
404:
81398144
description: "no such container"
81408145
schema:

api/types/container/container.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import (
1515
// Deprecated: use [UpdateResponse]. This alias will be removed in the next release.
1616
type ContainerUpdateOKBody = UpdateResponse
1717

18+
// ContainerTopOKBody OK response to ContainerTop operation
19+
//
20+
// Deprecated: use [TopResponse]. This alias will be removed in the next release.
21+
type ContainerTopOKBody = TopResponse
22+
1823
// PruneReport contains the response for Engine API:
1924
// POST "/containers/prune"
2025
type PruneReport struct {

api/types/container/container_top.go

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package container
2+
3+
// This file was generated by the swagger tool.
4+
// Editing this file might prove futile when you re-run the swagger generate command
5+
6+
// TopResponse ContainerTopResponse
7+
//
8+
// Container "top" response.
9+
// swagger:model TopResponse
10+
type TopResponse struct {
11+
12+
// Each process running in the container, where each process
13+
// is an array of values corresponding to the titles.
14+
Processes [][]string `json:"Processes"`
15+
16+
// The ps column titles
17+
Titles []string `json:"Titles"`
18+
}

client/client_interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ type ContainerAPIClient interface {
9393
ContainerStatsOneShot(ctx context.Context, container string) (container.StatsResponseReader, error)
9494
ContainerStart(ctx context.Context, container string, options container.StartOptions) error
9595
ContainerStop(ctx context.Context, container string, options container.StopOptions) error
96-
ContainerTop(ctx context.Context, container string, arguments []string) (container.ContainerTopOKBody, error)
96+
ContainerTop(ctx context.Context, container string, arguments []string) (container.TopResponse, error)
9797
ContainerUnpause(ctx context.Context, container string) error
9898
ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (container.UpdateResponse, error)
9999
ContainerWait(ctx context.Context, container string, condition container.WaitCondition) (<-chan container.WaitResponse, <-chan error)

client/container_top.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
)
1111

1212
// ContainerTop shows process information from within a container.
13-
func (cli *Client) ContainerTop(ctx context.Context, containerID string, arguments []string) (container.ContainerTopOKBody, error) {
13+
func (cli *Client) ContainerTop(ctx context.Context, containerID string, arguments []string) (container.TopResponse, error) {
1414
containerID, err := trimID("container", containerID)
1515
if err != nil {
16-
return container.ContainerTopOKBody{}, err
16+
return container.TopResponse{}, err
1717
}
1818

1919
query := url.Values{}
@@ -24,10 +24,10 @@ func (cli *Client) ContainerTop(ctx context.Context, containerID string, argumen
2424
resp, err := cli.get(ctx, "/containers/"+containerID+"/top", query, nil)
2525
defer ensureReaderClosed(resp)
2626
if err != nil {
27-
return container.ContainerTopOKBody{}, err
27+
return container.TopResponse{}, err
2828
}
2929

30-
var response container.ContainerTopOKBody
30+
var response container.TopResponse
3131
err = json.NewDecoder(resp.body).Decode(&response)
3232
return response, err
3333
}

client/container_top_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestContainerTop(t *testing.T) {
5252
return nil, fmt.Errorf("args not set in URL query properly. Expected 'arg1 arg2', got %v", args)
5353
}
5454

55-
b, err := json.Marshal(container.ContainerTopOKBody{
55+
b, err := json.Marshal(container.TopResponse{
5656
Processes: [][]string{
5757
{"p1", "p2"},
5858
{"p3"},

daemon/top_unix.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func fieldsASCII(s string) []string {
5050
return strings.FieldsFunc(s, fn)
5151
}
5252

53-
func appendProcess2ProcList(procList *container.ContainerTopOKBody, fields []string) {
53+
func appendProcess2ProcList(procList *container.TopResponse, fields []string) {
5454
// Make sure number of fields equals number of header titles
5555
// merging "overhanging" fields
5656
process := fields[:len(procList.Titles)-1]
@@ -67,8 +67,8 @@ func hasPid(procs []uint32, pid int) bool {
6767
return false
6868
}
6969

70-
func parsePSOutput(output []byte, procs []uint32) (*container.ContainerTopOKBody, error) {
71-
procList := &container.ContainerTopOKBody{}
70+
func parsePSOutput(output []byte, procs []uint32) (*container.TopResponse, error) {
71+
procList := &container.TopResponse{}
7272

7373
lines := strings.Split(string(output), "\n")
7474
procList.Titles = fieldsASCII(lines[0])
@@ -139,7 +139,7 @@ func psPidsArg(pids []uint32) string {
139139
// "-ef" if no args are given. An error is returned if the container
140140
// is not found, or is not running, or if there are any problems
141141
// running ps, or parsing the output.
142-
func (daemon *Daemon) ContainerTop(name string, psArgs string) (*container.ContainerTopOKBody, error) {
142+
func (daemon *Daemon) ContainerTop(name string, psArgs string) (*container.TopResponse, error) {
143143
if psArgs == "" {
144144
psArgs = "-ef"
145145
}

daemon/top_windows.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"fmt"
77
"time"
88

9-
containertypes "github.com/docker/docker/api/types/container"
9+
"github.com/docker/docker/api/types/container"
1010
libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
1111
"github.com/docker/go-units"
1212
)
@@ -26,27 +26,27 @@ import (
2626
// task manager does and use the private working set as the memory counter.
2727
// We could return more info for those who really understand how memory
2828
// management works in Windows if we introduced a "raw" stats (above).
29-
func (daemon *Daemon) ContainerTop(name string, psArgs string) (*containertypes.ContainerTopOKBody, error) {
29+
func (daemon *Daemon) ContainerTop(name string, psArgs string) (*container.TopResponse, error) {
3030
// It's not at all an equivalent to linux 'ps' on Windows
3131
if psArgs != "" {
3232
return nil, errors.New("Windows does not support arguments to top")
3333
}
3434

35-
container, err := daemon.GetContainer(name)
35+
ctr, err := daemon.GetContainer(name)
3636
if err != nil {
3737
return nil, err
3838
}
3939

4040
task, err := func() (libcontainerdtypes.Task, error) {
41-
container.Lock()
42-
defer container.Unlock()
41+
ctr.Lock()
42+
defer ctr.Unlock()
4343

44-
task, err := container.GetRunningTask()
44+
task, err := ctr.GetRunningTask()
4545
if err != nil {
4646
return nil, err
4747
}
48-
if container.Restarting {
49-
return nil, errContainerIsRestarting(container.ID)
48+
if ctr.Restarting {
49+
return nil, errContainerIsRestarting(ctr.ID)
5050
}
5151
return task, nil
5252
}()
@@ -55,8 +55,9 @@ func (daemon *Daemon) ContainerTop(name string, psArgs string) (*containertypes.
5555
if err != nil {
5656
return nil, err
5757
}
58-
procList := &containertypes.ContainerTopOKBody{}
59-
procList.Titles = []string{"Name", "PID", "CPU", "Private Working Set"}
58+
procList := &container.TopResponse{
59+
Titles: []string{"Name", "PID", "CPU", "Private Working Set"},
60+
}
6061

6162
for _, j := range s {
6263
d := time.Duration((j.KernelTime_100Ns + j.UserTime_100Ns) * 100) // Combined time in nanoseconds

0 commit comments

Comments
 (0)