Browse code

Convert ContainerTopOKResponse from swagger spec.

Signed-off-by: Daniel Nephin <dnephin@docker.com>

Daniel Nephin authored on 2016/11/15 04:50:16
Showing 10 changed files
... ...
@@ -53,7 +53,7 @@ type monitorBackend interface {
53 53
 	ContainerInspect(name string, size bool, version string) (interface{}, error)
54 54
 	ContainerLogs(ctx context.Context, name string, config *backend.ContainerLogsConfig, started chan struct{}) error
55 55
 	ContainerStats(ctx context.Context, name string, config *backend.ContainerStatsConfig) error
56
-	ContainerTop(name string, psArgs string) (*types.ContainerProcessList, error)
56
+	ContainerTop(name string, psArgs string) (*container.ContainerTopOKBody, error)
57 57
 
58 58
 	Containers(config *types.ContainerListOptions) ([]*types.Container, error)
59 59
 }
... ...
@@ -3384,12 +3384,14 @@ paths:
3384 3384
     get:
3385 3385
       summary: "Get container stats based on resource usage"
3386 3386
       description: |
3387
-        This endpoint returns a live stream of a container’s resource usage statistics.
3387
+        This endpoint returns a live stream of a container’s resource usage
3388
+        statistics.
3388 3389
 
3389
-        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.
3390
+        The `precpu_stats` is the CPU statistic of last read, which is used
3391
+        for calculating the CPU usage percentage. It is not the same as the
3392
+        `cpu_stats` field.
3390 3393
       operationId: "ContainerStats"
3391
-      produces:
3392
-        - "application/json"
3394
+      produces: ["application/json"]
3393 3395
       responses:
3394 3396
         200:
3395 3397
           description: "no error"
... ...
@@ -4111,7 +4113,7 @@ paths:
4111 4111
     head:
4112 4112
       summary: "Get information about files in a container"
4113 4113
       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."
4114
-      operationId: "ContainerArchiveHead"
4114
+      operationId: "ContainerArchiveInfo"
4115 4115
       responses:
4116 4116
         200:
4117 4117
           description: "no error"
... ...
@@ -4156,9 +4158,8 @@ paths:
4156 4156
     get:
4157 4157
       summary: "Get an archive of a filesystem resource in a container"
4158 4158
       description: "Get a tar archive of a resource in the filesystem of container id."
4159
-      operationId: "ContainerGetArchive"
4160
-      produces:
4161
-        - "application/x-tar"
4159
+      operationId: "ContainerArchive"
4160
+      produces: ["application/x-tar"]
4162 4161
       responses:
4163 4162
         200:
4164 4163
           description: "no error"
... ...
@@ -4199,10 +4200,8 @@ paths:
4199 4199
     put:
4200 4200
       summary: "Extract an archive of files or folders to a directory in a container"
4201 4201
       description: "Upload a tar archive to be extracted to a path in the filesystem of container id."
4202
-      operationId: "ContainerPutArchive"
4203
-      consumes:
4204
-        - "application/x-tar"
4205
-        - "application/octet-stream"
4202
+      operationId: "PutContainerArchive"
4203
+      consumes: ["application/x-tar", "application/octet-stream"]
4206 4204
       responses:
4207 4205
         200:
4208 4206
           description: "The content was extracted successfully"
4209 4207
new file mode 100644
... ...
@@ -0,0 +1,21 @@
0
+package container
1
+
2
+// ----------------------------------------------------------------------------
3
+// DO NOT EDIT THIS FILE
4
+// This file was generated by `swagger generate operation`
5
+//
6
+// See hack/swagger-gen.sh
7
+// ----------------------------------------------------------------------------
8
+
9
+// ContainerTopOKBody container top o k body
10
+// swagger:model ContainerTopOKBody
11
+type ContainerTopOKBody struct {
12
+
13
+	// Each process running in the container, where each is process is an array of values corresponding to the titles
14
+	// Required: true
15
+	Processes [][]string `json:"Processes"`
16
+
17
+	// The ps column titles
18
+	// Required: true
19
+	Titles []string `json:"Titles"`
20
+}
... ...
@@ -93,12 +93,6 @@ type ContainerStats struct {
93 93
 	OSType string        `json:"ostype"`
94 94
 }
95 95
 
96
-// ContainerProcessList contains response of Engine API:
97
-// GET "/containers/{name:.*}/top"
98
-type ContainerProcessList struct {
99
-	Processes [][]string
100
-	Titles    []string
101
-}
102 96
 
103 97
 // Ping contains response of Engine API:
104 98
 // GET "/_ping"
... ...
@@ -5,13 +5,13 @@ import (
5 5
 	"net/url"
6 6
 	"strings"
7 7
 
8
-	"github.com/docker/docker/api/types"
8
+	"github.com/docker/docker/api/types/container"
9 9
 	"golang.org/x/net/context"
10 10
 )
11 11
 
12 12
 // ContainerTop shows process information from within a container.
13
-func (cli *Client) ContainerTop(ctx context.Context, containerID string, arguments []string) (types.ContainerProcessList, error) {
14
-	var response types.ContainerProcessList
13
+func (cli *Client) ContainerTop(ctx context.Context, containerID string, arguments []string) (container.ContainerTopOKBody, error) {
14
+	var response container.ContainerTopOKBody
15 15
 	query := url.Values{}
16 16
 	if len(arguments) > 0 {
17 17
 		query.Set("ps_args", strings.Join(arguments, " "))
... ...
@@ -10,7 +10,7 @@ import (
10 10
 	"strings"
11 11
 	"testing"
12 12
 
13
-	"github.com/docker/docker/api/types"
13
+	"github.com/docker/docker/api/types/container"
14 14
 	"golang.org/x/net/context"
15 15
 )
16 16
 
... ...
@@ -43,7 +43,7 @@ func TestContainerTop(t *testing.T) {
43 43
 				return nil, fmt.Errorf("args not set in URL query properly. Expected 'arg1 arg2', got %v", args)
44 44
 			}
45 45
 
46
-			b, err := json.Marshal(types.ContainerProcessList{
46
+			b, err := json.Marshal(container.ContainerTopOKBody{
47 47
 				Processes: [][]string{
48 48
 					{"p1", "p2"},
49 49
 					{"p3"},
... ...
@@ -59,7 +59,7 @@ type ContainerAPIClient interface {
59 59
 	ContainerStats(ctx context.Context, container string, stream bool) (types.ContainerStats, error)
60 60
 	ContainerStart(ctx context.Context, container string, options types.ContainerStartOptions) error
61 61
 	ContainerStop(ctx context.Context, container string, timeout *time.Duration) error
62
-	ContainerTop(ctx context.Context, container string, arguments []string) (types.ContainerProcessList, error)
62
+	ContainerTop(ctx context.Context, container string, arguments []string) (container.ContainerTopOKBody, error)
63 63
 	ContainerUnpause(ctx context.Context, container string) error
64 64
 	ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error)
65 65
 	ContainerWait(ctx context.Context, container string) (int64, error)
... ...
@@ -9,7 +9,7 @@ import (
9 9
 	"strconv"
10 10
 	"strings"
11 11
 
12
-	"github.com/docker/docker/api/types"
12
+	"github.com/docker/docker/api/types/container"
13 13
 )
14 14
 
15 15
 func validatePSArgs(psArgs string) error {
... ...
@@ -41,8 +41,8 @@ func fieldsASCII(s string) []string {
41 41
 	return strings.FieldsFunc(s, fn)
42 42
 }
43 43
 
44
-func parsePSOutput(output []byte, pids []int) (*types.ContainerProcessList, error) {
45
-	procList := &types.ContainerProcessList{}
44
+func parsePSOutput(output []byte, pids []int) (*container.ContainerTopOKBody, error) {
45
+	procList := &container.ContainerTopOKBody{}
46 46
 
47 47
 	lines := strings.Split(string(output), "\n")
48 48
 	procList.Titles = fieldsASCII(lines[0])
... ...
@@ -86,7 +86,7 @@ func parsePSOutput(output []byte, pids []int) (*types.ContainerProcessList, erro
86 86
 // "-ef" if no args are given.  An error is returned if the container
87 87
 // is not found, or is not running, or if there are any problems
88 88
 // running ps, or parsing the output.
89
-func (daemon *Daemon) ContainerTop(name string, psArgs string) (*types.ContainerProcessList, error) {
89
+func (daemon *Daemon) ContainerTop(name string, psArgs string) (*container.ContainerTopOKBody, error) {
90 90
 	if psArgs == "" {
91 91
 		psArgs = "-ef"
92 92
 	}
... ...
@@ -5,7 +5,7 @@ import (
5 5
 	"fmt"
6 6
 	"time"
7 7
 
8
-	"github.com/docker/docker/api/types"
8
+	containertypes "github.com/docker/docker/api/types/container"
9 9
 	"github.com/docker/go-units"
10 10
 )
11 11
 
... ...
@@ -23,7 +23,7 @@ import (
23 23
 //    task manager does and use the private working set as the memory counter.
24 24
 //    We could return more info for those who really understand how memory
25 25
 //    management works in Windows if we introduced a "raw" stats (above).
26
-func (daemon *Daemon) ContainerTop(name string, psArgs string) (*types.ContainerProcessList, error) {
26
+func (daemon *Daemon) ContainerTop(name string, psArgs string) (*containertypes.ContainerTopOKBody, error) {
27 27
 	// It's not at all an equivalent to linux 'ps' on Windows
28 28
 	if psArgs != "" {
29 29
 		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
38 38
 	if err != nil {
39 39
 		return nil, err
40 40
 	}
41
-	procList := &types.ContainerProcessList{}
41
+	procList := &containertypes.ContainerTopOKBody{}
42 42
 	procList.Titles = []string{"Name", "PID", "CPU", "Private Working Set"}
43 43
 
44 44
 	for _, j := range s {
... ...
@@ -19,6 +19,7 @@ swagger generate operation -f api/swagger.yaml \
19 19
     -n Authenticate \
20 20
     -n ContainerChanges \
21 21
     -n ContainerCreate \
22
+    -n ContainerTop \
22 23
     -n ContainerUpdate \
23 24
     -n ContainerWait \
24 25
     -n ImageHistory \