diff --git a/api/mockclient/mock.go b/api/mockclient/mock.go index 4918a0e727..e019b6f600 100644 --- a/api/mockclient/mock.go +++ b/api/mockclient/mock.go @@ -2,6 +2,7 @@ package mockclient import ( "io" + "time" "github.com/docker/engine-api/types" "github.com/docker/engine-api/types/container" @@ -161,7 +162,7 @@ func (client *MockClient) ContainerResize(ctx context.Context, container string, } // ContainerRestart stops and starts a container again -func (client *MockClient) ContainerRestart(ctx context.Context, container string, timeout int) error { +func (client *MockClient) ContainerRestart(ctx context.Context, container string, timeout *time.Duration) error { args := client.Mock.Called(ctx, container, timeout) return args.Error(0) } @@ -179,13 +180,13 @@ func (client *MockClient) ContainerStats(ctx context.Context, container string, } // ContainerStart sends a request to the docker daemon to start a container -func (client *MockClient) ContainerStart(ctx context.Context, container string, checkpointID string) error { - args := client.Mock.Called(ctx, container, checkpointID) +func (client *MockClient) ContainerStart(ctx context.Context, container string, options types.ContainerStartOptions) error { + args := client.Mock.Called(ctx, container, options) return args.Error(0) } // ContainerStop stops a container without terminating the process -func (client *MockClient) ContainerStop(ctx context.Context, container string, timeout int) error { +func (client *MockClient) ContainerStop(ctx context.Context, container string, timeout *time.Duration) error { args := client.Mock.Called(ctx, container, timeout) return args.Error(0) } @@ -305,8 +306,8 @@ func (client *MockClient) ImageSave(ctx context.Context, images []string) (io.Re } // ImageTag tags an image in the docker host -func (client *MockClient) ImageTag(ctx context.Context, image, ref string, options types.ImageTagOptions) error { - args := client.Mock.Called(ctx, image, ref, options) +func (client *MockClient) ImageTag(ctx context.Context, image, ref string) error { + args := client.Mock.Called(ctx, image, ref) return args.Error(0) } diff --git a/api/mockclient/mock_test.go b/api/mockclient/mock_test.go index 475666427b..dbb3ae56fd 100644 --- a/api/mockclient/mock_test.go +++ b/api/mockclient/mock_test.go @@ -6,8 +6,8 @@ import ( "golang.org/x/net/context" - "github.com/docker/engine-api/client" "github.com/docker/engine-api/types" + "github.com/docker/swarm/swarmclient" "github.com/stretchr/testify/mock" ) @@ -27,10 +27,10 @@ func TestMock(t *testing.T) { } func TestMockInterface(t *testing.T) { - iface := reflect.TypeOf((*client.APIClient)(nil)).Elem() + iface := reflect.TypeOf((*swarmclient.SwarmAPIClient)(nil)).Elem() mockClient := NewMockClient() if !reflect.TypeOf(mockClient).Implements(iface) { - t.Fatalf("Mock does not implement the APIClient interface") + t.Fatalf("Mock does not implement the SwarmAPIClient interface") } } diff --git a/api/nopclient/nop.go b/api/nopclient/nop.go index ecb979be53..4282d1acf2 100644 --- a/api/nopclient/nop.go +++ b/api/nopclient/nop.go @@ -3,6 +3,7 @@ package nopclient import ( "errors" "io" + "time" "golang.org/x/net/context" @@ -142,7 +143,7 @@ func (client *NopClient) ContainerResize(ctx context.Context, container string, } // ContainerRestart stops and starts a container again -func (client *NopClient) ContainerRestart(ctx context.Context, container string, timeout int) error { +func (client *NopClient) ContainerRestart(ctx context.Context, container string, timeout *time.Duration) error { return errNoEngine } @@ -157,12 +158,12 @@ func (client *NopClient) ContainerStats(ctx context.Context, container string, s } // ContainerStart sends a request to the docker daemon to start a container -func (client *NopClient) ContainerStart(ctx context.Context, container string, checkpointID string) error { +func (client *NopClient) ContainerStart(ctx context.Context, container string, options types.ContainerStartOptions) error { return errNoEngine } // ContainerStop stops a container without terminating the process -func (client *NopClient) ContainerStop(ctx context.Context, container string, timeout int) error { +func (client *NopClient) ContainerStop(ctx context.Context, container string, timeout *time.Duration) error { return errNoEngine } @@ -262,7 +263,7 @@ func (client *NopClient) ImageSave(ctx context.Context, images []string) (io.Rea } // ImageTag tags an image in the docker host -func (client *NopClient) ImageTag(ctx context.Context, image, ref string, options types.ImageTagOptions) error { +func (client *NopClient) ImageTag(ctx context.Context, image, ref string) error { return errNoEngine } diff --git a/api/nopclient/nop_test.go b/api/nopclient/nop_test.go index 76a152cb3e..d80fb684bf 100644 --- a/api/nopclient/nop_test.go +++ b/api/nopclient/nop_test.go @@ -4,9 +4,8 @@ import ( "reflect" "testing" + "github.com/docker/swarm/swarmclient" "golang.org/x/net/context" - - "github.com/docker/engine-api/client" ) func TestNop(t *testing.T) { @@ -18,10 +17,10 @@ func TestNop(t *testing.T) { } func TestNopInterface(t *testing.T) { - iface := reflect.TypeOf((*client.APIClient)(nil)).Elem() + iface := reflect.TypeOf((*swarmclient.SwarmAPIClient)(nil)).Elem() nop := NewNopClient() if !reflect.TypeOf(nop).Implements(iface) { - t.Fatalf("Nop does not implement the APIClient interface") + t.Fatalf("Nop does not implement the SwarmAPIClient interface") } } diff --git a/cluster/engine.go b/cluster/engine.go index 70f5410e2e..235d48e4f9 100644 --- a/cluster/engine.go +++ b/cluster/engine.go @@ -25,6 +25,7 @@ import ( "github.com/docker/engine-api/types/filters" networktypes "github.com/docker/engine-api/types/network" engineapinop "github.com/docker/swarm/api/nopclient" + "github.com/docker/swarm/swarmclient" "github.com/samalba/dockerclient" "github.com/samalba/dockerclient/nopclient" ) @@ -123,7 +124,7 @@ type Engine struct { networks map[string]*Network volumes map[string]*Volume client dockerclient.Client - apiClient engineapi.APIClient + apiClient swarmclient.SwarmAPIClient eventHandler EventHandler state engineState lastError string @@ -209,7 +210,7 @@ func (e *Engine) StartMonitorEvents() { } // ConnectWithClient is exported -func (e *Engine) ConnectWithClient(client dockerclient.Client, apiClient engineapi.APIClient) error { +func (e *Engine) ConnectWithClient(client dockerclient.Client, apiClient swarmclient.SwarmAPIClient) error { e.client = client e.apiClient = apiClient e.eventsMonitor = NewEventsMonitor(e.apiClient, e.handler) @@ -1335,8 +1336,8 @@ func (e *Engine) StartContainer(id string, hostConfig *dockerclient.HostConfig) if hostConfig != nil { err = e.client.StartContainer(id, hostConfig) } else { - // TODO(nishanttotla): Figure out what the checkpoint id (second string argument) should be - err = e.apiClient.ContainerStart(context.Background(), id, "") + // TODO(nishanttotla): Should ContainerStartOptions be provided? + err = e.apiClient.ContainerStart(context.Background(), id, types.ContainerStartOptions{}) } e.CheckConnectionErr(err) if err != nil { @@ -1375,11 +1376,7 @@ func (e *Engine) BuildImage(buildContext io.Reader, buildImage *types.ImageBuild // TagImage tags an image func (e *Engine) TagImage(IDOrName string, ref string, force bool) error { // send tag request to docker engine - opts := types.ImageTagOptions{ - Force: force, - } - - err := e.apiClient.ImageTag(context.Background(), IDOrName, ref, opts) + err := e.apiClient.ImageTag(context.Background(), IDOrName, ref) e.CheckConnectionErr(err) if err != nil { return err diff --git a/cluster/event_monitor.go b/cluster/event_monitor.go index 2e22124b12..69da976176 100644 --- a/cluster/event_monitor.go +++ b/cluster/event_monitor.go @@ -4,16 +4,16 @@ import ( "encoding/json" "io" - "github.com/docker/engine-api/client" "github.com/docker/engine-api/types" "github.com/docker/engine-api/types/events" + "github.com/docker/swarm/swarmclient" "golang.org/x/net/context" ) //EventsMonitor monitors events type EventsMonitor struct { stopChan chan struct{} - cli client.APIClient + cli swarmclient.SwarmAPIClient handler func(msg events.Message) error } @@ -23,7 +23,7 @@ type decodingResult struct { } // NewEventsMonitor returns an EventsMonitor -func NewEventsMonitor(cli client.APIClient, handler func(msg events.Message) error) *EventsMonitor { +func NewEventsMonitor(cli swarmclient.SwarmAPIClient, handler func(msg events.Message) error) *EventsMonitor { return &EventsMonitor{ cli: cli, handler: handler, diff --git a/cluster/swarm/cluster_test.go b/cluster/swarm/cluster_test.go index de09f1f051..bd84bab395 100644 --- a/cluster/swarm/cluster_test.go +++ b/cluster/swarm/cluster_test.go @@ -264,7 +264,7 @@ func TestTagImage(t *testing.T) { c.engines[engine.ID] = engine // tag image - apiClient.On("ImageTag", mock.Anything, mock.Anything, mock.Anything, mock.AnythingOfType("types.ImageTagOptions")).Return(nil).Once() + apiClient.On("ImageTag", mock.Anything, mock.Anything, mock.Anything).Return(nil).Once() assert.Nil(t, c.TagImage("busybox", "test_busybox:latest", false)) assert.NotNil(t, c.TagImage("busybox_not_exists", "test_busybox:latest", false)) } diff --git a/swarmclient/interface.go b/swarmclient/interface.go new file mode 100644 index 0000000000..86fc19dacc --- /dev/null +++ b/swarmclient/interface.go @@ -0,0 +1,19 @@ +package swarmclient + +import ( + "github.com/docker/engine-api/client" + "github.com/docker/engine-api/types" + "golang.org/x/net/context" +) + +// SwarmAPIClient contains the subset of the engine-api interface relevant to Docker Swarm +type SwarmAPIClient interface { + client.ContainerAPIClient + client.ImageAPIClient + client.NetworkAPIClient + client.SystemAPIClient + client.VolumeAPIClient + ClientVersion() string + ServerVersion(ctx context.Context) (types.Version, error) + UpdateClientVersion(v string) +}