modify code to compile on updated containerd

Signed-off-by: Mike Brown <brownwm@us.ibm.com>
This commit is contained in:
Mike Brown
2017-06-07 14:41:30 -05:00
committed by Lantao Liu
parent 67e884e6cf
commit 484a326717
27 changed files with 444 additions and 453 deletions

View File

@@ -22,9 +22,9 @@ import (
"sync"
"time"
"github.com/containerd/containerd"
"github.com/containerd/containerd/api/services/execution"
"github.com/containerd/containerd/api/types/container"
"github.com/containerd/containerd/api/types/task"
"github.com/containerd/containerd/plugin"
googleprotobuf "github.com/golang/protobuf/ptypes/empty"
"golang.org/x/net/context"
"google.golang.org/grpc"
@@ -32,7 +32,7 @@ import (
)
// ContainerNotExistError is the fake error returned when container does not exist.
var ContainerNotExistError = grpc.Errorf(codes.Unknown, containerd.ErrContainerNotExist.Error())
var ContainerNotExistError = grpc.Errorf(codes.Unknown, plugin.ErrContainerNotExist.Error())
// CalledDetail is the struct contains called function name and arguments.
type CalledDetail struct {
@@ -42,16 +42,16 @@ type CalledDetail struct {
Argument interface{}
}
var _ execution.ContainerService_EventsClient = &EventClient{}
var _ execution.Tasks_EventsClient = &EventClient{}
// EventClient is a test implementation of execution.ContainerService_EventsClient
type EventClient struct {
Events chan *container.Event
Events chan *task.Event
grpc.ClientStream
}
// Recv is a test implementation of Recv
func (cli *EventClient) Recv() (*container.Event, error) {
func (cli *EventClient) Recv() (*task.Event, error) {
event, ok := <-cli.Events
if !ok {
return nil, fmt.Errorf("event channel closed")
@@ -65,18 +65,18 @@ type FakeExecutionClient struct {
sync.Mutex
called []CalledDetail
errors map[string]error
ContainerList map[string]container.Container
eventsQueue chan *container.Event
ContainerList map[string]task.Task
eventsQueue chan *task.Event
eventClients []*EventClient
}
var _ execution.ContainerServiceClient = &FakeExecutionClient{}
var _ execution.TasksClient = &FakeExecutionClient{}
// NewFakeExecutionClient creates a FakeExecutionClient
func NewFakeExecutionClient() *FakeExecutionClient {
return &FakeExecutionClient{
errors: make(map[string]error),
ContainerList: make(map[string]container.Container),
ContainerList: make(map[string]task.Task),
}
}
@@ -95,7 +95,7 @@ func (f *FakeExecutionClient) Stop() {
// WithEvents setup events publisher for FakeExecutionClient
func (f *FakeExecutionClient) WithEvents() *FakeExecutionClient {
f.eventsQueue = make(chan *container.Event, 1024)
f.eventsQueue = make(chan *task.Event, 1024)
go func() {
for e := range f.eventsQueue {
f.Lock()
@@ -146,7 +146,7 @@ func generatePid() uint32 {
return randPid
}
func (f *FakeExecutionClient) sendEvent(event *container.Event) {
func (f *FakeExecutionClient) sendEvent(event *task.Event) {
if f.eventsQueue != nil {
f.eventsQueue <- event
}
@@ -184,7 +184,7 @@ func (f *FakeExecutionClient) GetCalledDetails() []CalledDetail {
}
// SetFakeContainers injects fake containers.
func (f *FakeExecutionClient) SetFakeContainers(containers []container.Container) {
func (f *FakeExecutionClient) SetFakeContainers(containers []task.Task) {
f.Lock()
defer f.Unlock()
for _, c := range containers {
@@ -200,24 +200,24 @@ func (f *FakeExecutionClient) Create(ctx context.Context, createOpts *execution.
if err := f.getError("create"); err != nil {
return nil, err
}
_, ok := f.ContainerList[createOpts.ID]
_, ok := f.ContainerList[createOpts.ContainerID]
if ok {
return nil, containerd.ErrContainerExists
return nil, plugin.ErrContainerExists
}
pid := generatePid()
f.ContainerList[createOpts.ID] = container.Container{
ID: createOpts.ID,
Pid: pid,
Status: container.Status_CREATED,
f.ContainerList[createOpts.ContainerID] = task.Task{
ContainerID: createOpts.ContainerID,
Pid: pid,
Status: task.StatusCreated,
}
f.sendEvent(&container.Event{
ID: createOpts.ID,
Type: container.Event_CREATE,
f.sendEvent(&task.Event{
ID: createOpts.ContainerID,
Type: task.Event_CREATE,
Pid: pid,
})
return &execution.CreateResponse{
ID: createOpts.ID,
Pid: pid,
ContainerID: createOpts.ContainerID,
Pid: pid,
}, nil
}
@@ -229,23 +229,23 @@ func (f *FakeExecutionClient) Start(ctx context.Context, startOpts *execution.St
if err := f.getError("start"); err != nil {
return nil, err
}
c, ok := f.ContainerList[startOpts.ID]
c, ok := f.ContainerList[startOpts.ContainerID]
if !ok {
return nil, ContainerNotExistError
}
f.sendEvent(&container.Event{
f.sendEvent(&task.Event{
ID: c.ID,
Type: container.Event_START,
Type: task.Event_START,
Pid: c.Pid,
})
switch c.Status {
case container.Status_CREATED:
c.Status = container.Status_RUNNING
f.ContainerList[startOpts.ID] = c
case task.StatusCreated:
c.Status = task.StatusRunning
f.ContainerList[startOpts.ContainerID] = c
return &googleprotobuf.Empty{}, nil
case container.Status_STOPPED:
case task.StatusStopped:
return &googleprotobuf.Empty{}, fmt.Errorf("cannot start a container that has stopped")
case container.Status_RUNNING:
case task.StatusRunning:
return &googleprotobuf.Empty{}, fmt.Errorf("cannot start an already running container")
default:
return &googleprotobuf.Empty{}, fmt.Errorf("cannot start a container in the %s state", c.Status)
@@ -260,32 +260,32 @@ func (f *FakeExecutionClient) Delete(ctx context.Context, deleteOpts *execution.
if err := f.getError("delete"); err != nil {
return nil, err
}
c, ok := f.ContainerList[deleteOpts.ID]
c, ok := f.ContainerList[deleteOpts.ContainerID]
if !ok {
return nil, ContainerNotExistError
}
delete(f.ContainerList, deleteOpts.ID)
f.sendEvent(&container.Event{
delete(f.ContainerList, deleteOpts.ContainerID)
f.sendEvent(&task.Event{
ID: c.ID,
Type: container.Event_EXIT,
Type: task.Event_EXIT,
Pid: c.Pid,
})
return nil, nil
}
// Info is a test implementation of execution.Info
func (f *FakeExecutionClient) Info(ctx context.Context, infoOpts *execution.InfoRequest, opts ...grpc.CallOption) (*container.Container, error) {
func (f *FakeExecutionClient) Info(ctx context.Context, infoOpts *execution.InfoRequest, opts ...grpc.CallOption) (*execution.InfoResponse, error) {
f.Lock()
defer f.Unlock()
f.appendCalled("info", infoOpts)
if err := f.getError("info"); err != nil {
return nil, err
}
c, ok := f.ContainerList[infoOpts.ID]
c, ok := f.ContainerList[infoOpts.ContainerID]
if !ok {
return nil, ContainerNotExistError
}
return &c, nil
return &execution.InfoResponse{Task: &c}, nil
}
// List is a test implementation of execution.List
@@ -298,7 +298,7 @@ func (f *FakeExecutionClient) List(ctx context.Context, listOpts *execution.List
}
resp := &execution.ListResponse{}
for _, c := range f.ContainerList {
resp.Containers = append(resp.Containers, &container.Container{
resp.Tasks = append(resp.Tasks, &task.Task{
ID: c.ID,
Pid: c.Pid,
Status: c.Status,
@@ -315,22 +315,22 @@ func (f *FakeExecutionClient) Kill(ctx context.Context, killOpts *execution.Kill
if err := f.getError("kill"); err != nil {
return nil, err
}
c, ok := f.ContainerList[killOpts.ID]
c, ok := f.ContainerList[killOpts.ContainerID]
if !ok {
return nil, ContainerNotExistError
}
c.Status = container.Status_STOPPED
f.ContainerList[killOpts.ID] = c
f.sendEvent(&container.Event{
c.Status = task.StatusStopped
f.ContainerList[killOpts.ContainerID] = c
f.sendEvent(&task.Event{
ID: c.ID,
Type: container.Event_EXIT,
Type: task.Event_EXIT,
Pid: c.Pid,
})
return &googleprotobuf.Empty{}, nil
}
// Events is a test implementation of execution.Events
func (f *FakeExecutionClient) Events(ctx context.Context, eventsOpts *execution.EventsRequest, opts ...grpc.CallOption) (execution.ContainerService_EventsClient, error) {
func (f *FakeExecutionClient) Events(ctx context.Context, eventsOpts *execution.EventsRequest, opts ...grpc.CallOption) (execution.Tasks_EventsClient, error) {
f.Lock()
defer f.Unlock()
f.appendCalled("events", eventsOpts)
@@ -338,7 +338,7 @@ func (f *FakeExecutionClient) Events(ctx context.Context, eventsOpts *execution.
return nil, err
}
var client = &EventClient{
Events: make(chan *container.Event, 100),
Events: make(chan *task.Event, 100),
}
f.eventClients = append(f.eventClients, client)
return client, nil
@@ -373,3 +373,15 @@ func (f *FakeExecutionClient) Resume(ctx context.Context, in *execution.ResumeRe
// TODO: implement Resume()
return nil, nil
}
// Checkpoint is a test implementation of execution.Checkpoint
func (f *FakeExecutionClient) Checkpoint(ctx context.Context, in *execution.CheckpointRequest, opts ...grpc.CallOption) (*execution.CheckpointResponse, error) {
// TODO: implement Checkpoint()
return nil, nil
}
// Processes is a test implementation of execution.Processes
func (f *FakeExecutionClient) Processes(ctx context.Context, in *execution.ProcessesRequest, opts ...grpc.CallOption) (*execution.ProcessesResponse, error) {
// TODO: implement Processes()
return nil, nil
}