From cbb7c27621afc3f5a800becbeadb19622f7adce9 Mon Sep 17 00:00:00 2001 From: Nishant Totla Date: Tue, 5 Apr 2016 09:16:50 -0700 Subject: [PATCH 1/2] Updating Godeps (engine-api) Signed-off-by: Nishant Totla --- Godeps/Godeps.json | 44 ++++++------- .../docker/engine-api/client/client.go | 6 ++ .../engine-api/client/container_list.go | 3 +- .../docker/engine-api/client/hijack.go | 4 +- .../docker/engine-api/client/interface.go | 1 + .../docker/engine-api/client/request.go | 12 ++-- .../docker/engine-api/types/client.go | 2 +- .../engine-api/types/container/host_config.go | 9 +-- .../docker/engine-api/types/filters/parse.go | 66 +++++++++++++++++++ .../docker/engine-api/types/stats.go | 2 +- 10 files changed, 113 insertions(+), 36 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 9e5301d48b..81fbf1e6f0 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -91,58 +91,58 @@ }, { "ImportPath": "github.com/docker/engine-api/client", - "Comment": "v0.3.1-16-g6ca9064", - "Rev": "6ca9064650fd3d66ea1722c24e475ec0138feb11" + "Comment": "v0.3.1-34-g5b9e86c", + "Rev": "5b9e86c11862e755be8871b64aada2a65ded4b8b" }, { "ImportPath": "github.com/docker/engine-api/client/transport", - "Comment": "v0.3.1-16-g6ca9064", - "Rev": "6ca9064650fd3d66ea1722c24e475ec0138feb11" + "Comment": "v0.3.1-34-g5b9e86c", + "Rev": "5b9e86c11862e755be8871b64aada2a65ded4b8b" }, { "ImportPath": "github.com/docker/engine-api/client/transport/cancellable", - "Comment": "v0.3.1-16-g6ca9064", - "Rev": "6ca9064650fd3d66ea1722c24e475ec0138feb11" + "Comment": "v0.3.1-34-g5b9e86c", + "Rev": "5b9e86c11862e755be8871b64aada2a65ded4b8b" }, { "ImportPath": "github.com/docker/engine-api/types", - "Comment": "v0.3.1-16-g6ca9064", - "Rev": "6ca9064650fd3d66ea1722c24e475ec0138feb11" + "Comment": "v0.3.1-34-g5b9e86c", + "Rev": "5b9e86c11862e755be8871b64aada2a65ded4b8b" }, { "ImportPath": "github.com/docker/engine-api/types/blkiodev", - "Comment": "v0.3.1-16-g6ca9064", - "Rev": "6ca9064650fd3d66ea1722c24e475ec0138feb11" + "Comment": "v0.3.1-34-g5b9e86c", + "Rev": "5b9e86c11862e755be8871b64aada2a65ded4b8b" }, { "ImportPath": "github.com/docker/engine-api/types/container", - "Comment": "v0.3.1-16-g6ca9064", - "Rev": "6ca9064650fd3d66ea1722c24e475ec0138feb11" + "Comment": "v0.3.1-34-g5b9e86c", + "Rev": "5b9e86c11862e755be8871b64aada2a65ded4b8b" }, { "ImportPath": "github.com/docker/engine-api/types/filters", - "Comment": "v0.3.1-16-g6ca9064", - "Rev": "6ca9064650fd3d66ea1722c24e475ec0138feb11" + "Comment": "v0.3.1-34-g5b9e86c", + "Rev": "5b9e86c11862e755be8871b64aada2a65ded4b8b" }, { "ImportPath": "github.com/docker/engine-api/types/network", - "Comment": "v0.3.1-16-g6ca9064", - "Rev": "6ca9064650fd3d66ea1722c24e475ec0138feb11" + "Comment": "v0.3.1-34-g5b9e86c", + "Rev": "5b9e86c11862e755be8871b64aada2a65ded4b8b" }, { "ImportPath": "github.com/docker/engine-api/types/registry", - "Comment": "v0.3.1-16-g6ca9064", - "Rev": "6ca9064650fd3d66ea1722c24e475ec0138feb11" + "Comment": "v0.3.1-34-g5b9e86c", + "Rev": "5b9e86c11862e755be8871b64aada2a65ded4b8b" }, { "ImportPath": "github.com/docker/engine-api/types/strslice", - "Comment": "v0.3.1-16-g6ca9064", - "Rev": "6ca9064650fd3d66ea1722c24e475ec0138feb11" + "Comment": "v0.3.1-34-g5b9e86c", + "Rev": "5b9e86c11862e755be8871b64aada2a65ded4b8b" }, { "ImportPath": "github.com/docker/engine-api/types/time", - "Comment": "v0.3.1-16-g6ca9064", - "Rev": "6ca9064650fd3d66ea1722c24e475ec0138feb11" + "Comment": "v0.3.1-34-g5b9e86c", + "Rev": "5b9e86c11862e755be8871b64aada2a65ded4b8b" }, { "ImportPath": "github.com/docker/go-connections/nat", diff --git a/Godeps/_workspace/src/github.com/docker/engine-api/client/client.go b/Godeps/_workspace/src/github.com/docker/engine-api/client/client.go index 0716667b3a..f91d235be4 100644 --- a/Godeps/_workspace/src/github.com/docker/engine-api/client/client.go +++ b/Godeps/_workspace/src/github.com/docker/engine-api/client/client.go @@ -114,6 +114,12 @@ func (cli *Client) ClientVersion() string { return cli.version } +// UpdateClientVersion updates the version string associated with this +// instance of the Client. +func (cli *Client) UpdateClientVersion(v string) { + cli.version = v +} + // ParseHost verifies that the given host strings is valid. func ParseHost(host string) (string, string, string, error) { protoAddrParts := strings.SplitN(host, "://", 2) diff --git a/Godeps/_workspace/src/github.com/docker/engine-api/client/container_list.go b/Godeps/_workspace/src/github.com/docker/engine-api/client/container_list.go index 573f41d5c6..87f7333dc7 100644 --- a/Godeps/_workspace/src/github.com/docker/engine-api/client/container_list.go +++ b/Godeps/_workspace/src/github.com/docker/engine-api/client/container_list.go @@ -35,7 +35,8 @@ func (cli *Client) ContainerList(ctx context.Context, options types.ContainerLis } if options.Filter.Len() > 0 { - filterJSON, err := filters.ToParam(options.Filter) + filterJSON, err := filters.ToParamWithVersion(cli.version, options.Filter) + if err != nil { return nil, err } diff --git a/Godeps/_workspace/src/github.com/docker/engine-api/client/hijack.go b/Godeps/_workspace/src/github.com/docker/engine-api/client/hijack.go index 2fd46b6c52..dbd91ef629 100644 --- a/Godeps/_workspace/src/github.com/docker/engine-api/client/hijack.go +++ b/Godeps/_workspace/src/github.com/docker/engine-api/client/hijack.go @@ -68,11 +68,11 @@ func (cli *Client) postHijacked(ctx context.Context, path string, query url.Valu defer clientconn.Close() // Server hijacks the connection, error 'connection closed' expected - clientconn.Do(req) + _, err = clientconn.Do(req) rwc, br := clientconn.Hijack() - return types.HijackedResponse{Conn: rwc, Reader: br}, nil + return types.HijackedResponse{Conn: rwc, Reader: br}, err } func tlsDial(network, addr string, config *tls.Config) (net.Conn, error) { diff --git a/Godeps/_workspace/src/github.com/docker/engine-api/client/interface.go b/Godeps/_workspace/src/github.com/docker/engine-api/client/interface.go index e95ed55567..4df164a77f 100644 --- a/Godeps/_workspace/src/github.com/docker/engine-api/client/interface.go +++ b/Godeps/_workspace/src/github.com/docker/engine-api/client/interface.go @@ -68,6 +68,7 @@ type APIClient interface { NetworkRemove(ctx context.Context, networkID string) error RegistryLogin(ctx context.Context, auth types.AuthConfig) (types.AuthResponse, error) ServerVersion(ctx context.Context) (types.Version, error) + UpdateClientVersion(v string) VolumeCreate(ctx context.Context, options types.VolumeCreateRequest) (types.Volume, error) VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error) VolumeList(ctx context.Context, filter filters.Args) (types.VolumesListResponse, error) diff --git a/Godeps/_workspace/src/github.com/docker/engine-api/client/request.go b/Godeps/_workspace/src/github.com/docker/engine-api/client/request.go index f45182399c..4ad2d24b88 100644 --- a/Godeps/_workspace/src/github.com/docker/engine-api/client/request.go +++ b/Godeps/_workspace/src/github.com/docker/engine-api/client/request.go @@ -56,12 +56,14 @@ func (cli *Client) delete(ctx context.Context, path string, query url.Values, he } func (cli *Client) sendRequest(ctx context.Context, method, path string, query url.Values, obj interface{}, headers map[string][]string) (*serverResponse, error) { - body, err := encodeData(obj) - if err != nil { - return nil, err - } + var body io.Reader - if body != nil { + if obj != nil { + var err error + body, err = encodeData(obj) + if err != nil { + return nil, err + } if headers == nil { headers = make(map[string][]string) } diff --git a/Godeps/_workspace/src/github.com/docker/engine-api/types/client.go b/Godeps/_workspace/src/github.com/docker/engine-api/types/client.go index 00fc97054e..975a5bb639 100644 --- a/Godeps/_workspace/src/github.com/docker/engine-api/types/client.go +++ b/Godeps/_workspace/src/github.com/docker/engine-api/types/client.go @@ -103,7 +103,7 @@ func (h *HijackedResponse) Close() { h.Conn.Close() } -// CloseWriter is an interface that implement structs +// CloseWriter is an interface that implements structs // that close input streams to prevent from writing. type CloseWriter interface { CloseWrite() error diff --git a/Godeps/_workspace/src/github.com/docker/engine-api/types/container/host_config.go b/Godeps/_workspace/src/github.com/docker/engine-api/types/container/host_config.go index 0b2af65145..7ad634b6da 100644 --- a/Godeps/_workspace/src/github.com/docker/engine-api/types/container/host_config.go +++ b/Godeps/_workspace/src/github.com/docker/engine-api/types/container/host_config.go @@ -236,10 +236,11 @@ type Resources struct { Ulimits []*units.Ulimit // List of ulimits to be set in the container // Applicable to Windows - CPUCount int64 `json:"CpuCount"` // CPU count - CPUPercent int64 `json:"CpuPercent"` // CPU percent - MaximumIOps uint64 // Maximum IOps for the container system drive - MaximumIOBps uint64 // Maximum IO in bytes per second for the container system drive + CPUCount int64 `json:"CpuCount"` // CPU count + CPUPercent int64 `json:"CpuPercent"` // CPU percent + IOMaximumIOps uint64 // Maximum IOps for the container system drive + IOMaximumBandwidth uint64 // Maximum IO in bytes per second for the container system drive + NetworkMaximumBandwidth uint64 // Maximum bandwidth of the network endpoint in bytes per second } // UpdateConfig holds the mutable attributes of a Container. diff --git a/Godeps/_workspace/src/github.com/docker/engine-api/types/filters/parse.go b/Godeps/_workspace/src/github.com/docker/engine-api/types/filters/parse.go index da2a089297..f9693c594f 100644 --- a/Godeps/_workspace/src/github.com/docker/engine-api/types/filters/parse.go +++ b/Godeps/_workspace/src/github.com/docker/engine-api/types/filters/parse.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "regexp" + "strconv" "strings" ) @@ -68,6 +69,26 @@ func ToParam(a Args) (string, error) { return string(buf), nil } +func ToParamWithVersion(version string, a Args) (string, error) { + // this way we don't URL encode {}, just empty space + if a.Len() == 0 { + return "", nil + } + + // for daemons older than v1.10, filter must be of the form map[string][]string + buf := []byte{} + err := errors.New("") + if version != "" && compareTo(version, "1.22") == -1 { + buf, err = json.Marshal(convertArgsToSlice(a.fields)) + } else { + buf, err = json.Marshal(a.fields) + } + if err != nil { + return "", err + } + return string(buf), nil +} + // FromParam unpacks the filter Args. func FromParam(p string) (Args, error) { if len(p) == 0 { @@ -255,3 +276,48 @@ func deprecatedArgs(d map[string][]string) map[string]map[string]bool { } return m } + +func convertArgsToSlice(f map[string]map[string]bool) map[string][]string { + m := map[string][]string{} + for k, v := range f { + values := []string{} + for kk, _ := range v { + if v[kk] { + values = append(values, kk) + } + } + m[k] = values + } + return m +} + +// compareTo compares two version strings +// returns -1 if v1 < v2, 1 if v1 > v2, 0 otherwise +func compareTo(v1, v2 string) int { + var ( + currTab = strings.Split(v1, ".") + otherTab = strings.Split(v2, ".") + ) + + max := len(currTab) + if len(otherTab) > max { + max = len(otherTab) + } + for i := 0; i < max; i++ { + var currInt, otherInt int + + if len(currTab) > i { + currInt, _ = strconv.Atoi(currTab[i]) + } + if len(otherTab) > i { + otherInt, _ = strconv.Atoi(otherTab[i]) + } + if currInt > otherInt { + return 1 + } + if otherInt > currInt { + return -1 + } + } + return 0 +} diff --git a/Godeps/_workspace/src/github.com/docker/engine-api/types/stats.go b/Godeps/_workspace/src/github.com/docker/engine-api/types/stats.go index 55081ae4d2..1434033410 100644 --- a/Godeps/_workspace/src/github.com/docker/engine-api/types/stats.go +++ b/Godeps/_workspace/src/github.com/docker/engine-api/types/stats.go @@ -8,7 +8,7 @@ import "time" type ThrottlingData struct { // Number of periods with throttling active Periods uint64 `json:"periods"` - // Number of periods when the container hit its throttling limit. + // Number of periods when the container hits its throttling limit. ThrottledPeriods uint64 `json:"throttled_periods"` // Aggregate time the container was throttled for in nanoseconds. ThrottledTime uint64 `json:"throttled_time"` From 012dffeee3d754e61b4e9744d39e8ea573efce41 Mon Sep 17 00:00:00 2001 From: Nishant Totla Date: Tue, 5 Apr 2016 09:17:16 -0700 Subject: [PATCH 2/2] Updating apiClient version using server version Signed-off-by: Nishant Totla --- api/mockclient/mock.go | 4 ++++ api/nopclient/nop.go | 4 ++++ cluster/engine.go | 24 +++++++++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/api/mockclient/mock.go b/api/mockclient/mock.go index 2af4969e23..16e25a0e8f 100644 --- a/api/mockclient/mock.go +++ b/api/mockclient/mock.go @@ -347,6 +347,10 @@ func (client *MockClient) ServerVersion(ctx context.Context) (types.Version, err return args.Get(0).(types.Version), args.Error(1) } +// UpdateClientVersion updates the client version +func (client *MockClient) UpdateClientVersion(v string) { +} + // VolumeCreate creates a volume in the docker host func (client *MockClient) VolumeCreate(ctx context.Context, options types.VolumeCreateRequest) (types.Volume, error) { args := client.Mock.Called(ctx, options) diff --git a/api/nopclient/nop.go b/api/nopclient/nop.go index e5eb024204..f26387d1b6 100644 --- a/api/nopclient/nop.go +++ b/api/nopclient/nop.go @@ -297,6 +297,10 @@ func (client *NopClient) ServerVersion(ctx context.Context) (types.Version, erro return types.Version{}, errNoEngine } +// UpdateClientVersion updates the client version +func (client *NopClient) UpdateClientVersion(v string) { +} + // VolumeCreate creates a volume in the docker host func (client *NopClient) VolumeCreate(ctx context.Context, options types.VolumeCreateRequest) (types.Volume, error) { return types.Volume{}, errNoEngine diff --git a/cluster/engine.go b/cluster/engine.go index b47eda94a8..4b5d93758e 100644 --- a/cluster/engine.go +++ b/cluster/engine.go @@ -414,6 +414,26 @@ func (e *Engine) CheckConnectionErr(err error) { // other errors may be ambiguous. } +// Update API Version in apiClient +func (e *Engine) updateClientVersionFromServer(serverVersion string) { + // v will be >= 1.6, since this is checked earlier + v := version.Version(serverVersion) + switch { + case v.LessThan(version.Version("1.7")): + e.apiClient.UpdateClientVersion("1.18") + case v.LessThan(version.Version("1.8")): + e.apiClient.UpdateClientVersion("1.19") + case v.LessThan(version.Version("1.9")): + e.apiClient.UpdateClientVersion("1.20") + case v.LessThan(version.Version("1.10")): + e.apiClient.UpdateClientVersion("1.21") + case v.LessThan(version.Version("1.11")): + e.apiClient.UpdateClientVersion("1.22") + default: + e.apiClient.UpdateClientVersion("1.23") + } +} + // Gather engine specs (CPU, memory, constraints, ...). func (e *Engine) updateSpecs() error { info, err := e.apiClient.Info(context.TODO()) @@ -441,8 +461,10 @@ func (e *Engine) updateSpecs() error { e.CheckConnectionErr(err) return err } - // update version + // update server version e.Version = v.Version + // update client version. engine-api handles backward compatibility where needed + e.updateClientVersionFromServer(v.Version) e.Lock() defer e.Unlock()