Update GRPC for consistency
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
		| @@ -22,10 +22,13 @@ func containersToProto(containers []containers.Container) []api.Container { | ||||
|  | ||||
| func containerToProto(container *containers.Container) api.Container { | ||||
| 	return api.Container{ | ||||
| 		ID:      container.ID, | ||||
| 		Labels:  container.Labels, | ||||
| 		Image:   container.Image, | ||||
| 		Runtime: container.Runtime, | ||||
| 		ID:     container.ID, | ||||
| 		Labels: container.Labels, | ||||
| 		Image:  container.Image, | ||||
| 		Runtime: &api.Container_Runtime{ | ||||
| 			Name:    container.Runtime.Name, | ||||
| 			Options: container.Runtime.Options, | ||||
| 		}, | ||||
| 		Spec: &types.Any{ | ||||
| 			TypeUrl: specs.Version, | ||||
| 			Value:   container.Spec, | ||||
| @@ -36,12 +39,15 @@ func containerToProto(container *containers.Container) api.Container { | ||||
|  | ||||
| func containerFromProto(containerpb *api.Container) containers.Container { | ||||
| 	return containers.Container{ | ||||
| 		ID:      containerpb.ID, | ||||
| 		Labels:  containerpb.Labels, | ||||
| 		Image:   containerpb.Image, | ||||
| 		Runtime: containerpb.Runtime, | ||||
| 		Spec:    containerpb.Spec.Value, | ||||
| 		RootFS:  containerpb.RootFS, | ||||
| 		ID:     containerpb.ID, | ||||
| 		Labels: containerpb.Labels, | ||||
| 		Image:  containerpb.Image, | ||||
| 		Runtime: containers.RuntimeInfo{ | ||||
| 			Name:    containerpb.Runtime.Name, | ||||
| 			Options: containerpb.Runtime.Options, | ||||
| 		}, | ||||
| 		Spec:   containerpb.Spec.Value, | ||||
| 		RootFS: containerpb.RootFS, | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -96,7 +96,10 @@ func (s *Service) Create(ctx context.Context, req *api.CreateContainerRequest) ( | ||||
| 	if err := s.emit(ctx, "/containers/create", event.ContainerCreate{ | ||||
| 		ContainerID: resp.Container.ID, | ||||
| 		Image:       resp.Container.Image, | ||||
| 		Runtime:     resp.Container.Runtime, | ||||
| 		Runtime: &event.ContainerCreate_Runtime{ | ||||
| 			Name:    resp.Container.Runtime.Name, | ||||
| 			Options: resp.Container.Runtime.Options, | ||||
| 		}, | ||||
| 	}); err != nil { | ||||
| 		return &resp, err | ||||
| 	} | ||||
|   | ||||
| @@ -26,7 +26,7 @@ func (rr *remoteReader) Read(p []byte) (n int, err error) { | ||||
|  | ||||
| 	p = p[n:] | ||||
| 	for len(p) > 0 { | ||||
| 		var resp *contentapi.ReadResponse | ||||
| 		var resp *contentapi.ReadContentResponse | ||||
| 		// fill our buffer up until we can fill p. | ||||
| 		resp, err = rr.client.Recv() | ||||
| 		if err != nil { | ||||
| @@ -56,7 +56,7 @@ type remoteReaderAt struct { | ||||
| } | ||||
|  | ||||
| func (ra *remoteReaderAt) ReadAt(p []byte, off int64) (n int, err error) { | ||||
| 	rr := &contentapi.ReadRequest{ | ||||
| 	rr := &contentapi.ReadContentRequest{ | ||||
| 		Digest: ra.digest, | ||||
| 		Offset: off, | ||||
| 		Size_:  int64(len(p)), | ||||
| @@ -67,7 +67,7 @@ func (ra *remoteReaderAt) ReadAt(p []byte, off int64) (n int, err error) { | ||||
| 	} | ||||
|  | ||||
| 	for len(p) > 0 { | ||||
| 		var resp *contentapi.ReadResponse | ||||
| 		var resp *contentapi.ReadContentResponse | ||||
| 		// fill our buffer up until we can fill p. | ||||
| 		resp, err = rc.Recv() | ||||
| 		if err != nil { | ||||
|   | ||||
| @@ -137,7 +137,7 @@ func (s *Service) Delete(ctx context.Context, req *api.DeleteContentRequest) (*e | ||||
| 	return &empty.Empty{}, nil | ||||
| } | ||||
|  | ||||
| func (s *Service) Read(req *api.ReadRequest, session api.Content_ReadServer) error { | ||||
| func (s *Service) Read(req *api.ReadContentRequest, session api.Content_ReadServer) error { | ||||
| 	if err := req.Digest.Validate(); err != nil { | ||||
| 		return grpc.Errorf(codes.InvalidArgument, "%v: %v", req.Digest, err) | ||||
| 	} | ||||
| @@ -193,7 +193,7 @@ func (s *Service) Read(req *api.ReadRequest, session api.Content_ReadServer) err | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // readResponseWriter is a writer that places the output into ReadResponse messages. | ||||
| // readResponseWriter is a writer that places the output into ReadContentRequest messages. | ||||
| // | ||||
| // This allows io.CopyBuffer to do the heavy lifting of chunking the responses | ||||
| // into the buffer size. | ||||
| @@ -203,7 +203,7 @@ type readResponseWriter struct { | ||||
| } | ||||
|  | ||||
| func (rw *readResponseWriter) Write(p []byte) (n int, err error) { | ||||
| 	if err := rw.session.Send(&api.ReadResponse{ | ||||
| 	if err := rw.session.Send(&api.ReadContentResponse{ | ||||
| 		Offset: rw.offset, | ||||
| 		Data:   p, | ||||
| 	}); err != nil { | ||||
| @@ -215,9 +215,9 @@ func (rw *readResponseWriter) Write(p []byte) (n int, err error) { | ||||
| } | ||||
|  | ||||
| func (s *Service) Status(ctx context.Context, req *api.StatusRequest) (*api.StatusResponse, error) { | ||||
| 	statuses, err := s.store.Status(ctx, req.Regexp) | ||||
| 	statuses, err := s.store.Status(ctx, req.Filter) | ||||
| 	if err != nil { | ||||
| 		return nil, serverErrorToGRPC(err, req.Regexp) | ||||
| 		return nil, serverErrorToGRPC(err, req.Filter) | ||||
| 	} | ||||
|  | ||||
| 	var resp api.StatusResponse | ||||
| @@ -238,14 +238,14 @@ func (s *Service) Status(ctx context.Context, req *api.StatusRequest) (*api.Stat | ||||
| func (s *Service) Write(session api.Content_WriteServer) (err error) { | ||||
| 	var ( | ||||
| 		ctx      = session.Context() | ||||
| 		msg      api.WriteResponse | ||||
| 		req      *api.WriteRequest | ||||
| 		msg      api.WriteContentResponse | ||||
| 		req      *api.WriteContentRequest | ||||
| 		ref      string | ||||
| 		total    int64 | ||||
| 		expected digest.Digest | ||||
| 	) | ||||
|  | ||||
| 	defer func(msg *api.WriteResponse) { | ||||
| 	defer func(msg *api.WriteContentResponse) { | ||||
| 		// pump through the last message if no error was encountered | ||||
| 		if err != nil { | ||||
| 			if grpc.Code(err) != codes.AlreadyExists { | ||||
|   | ||||
| @@ -75,7 +75,7 @@ func (rs *remoteStore) Delete(ctx context.Context, dgst digest.Digest) error { | ||||
| } | ||||
|  | ||||
| func (rs *remoteStore) Reader(ctx context.Context, dgst digest.Digest) (io.ReadCloser, error) { | ||||
| 	client, err := rs.client.Read(ctx, &contentapi.ReadRequest{Digest: dgst}) | ||||
| 	client, err := rs.client.Read(ctx, &contentapi.ReadContentRequest{Digest: dgst}) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| @@ -93,9 +93,9 @@ func (rs *remoteStore) ReaderAt(ctx context.Context, dgst digest.Digest) (io.Rea | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| func (rs *remoteStore) Status(ctx context.Context, re string) ([]content.Status, error) { | ||||
| func (rs *remoteStore) Status(ctx context.Context, filter string) ([]content.Status, error) { | ||||
| 	resp, err := rs.client.Status(ctx, &contentapi.StatusRequest{ | ||||
| 		Regexp: re, | ||||
| 		Filter: filter, | ||||
| 	}) | ||||
| 	if err != nil { | ||||
| 		return nil, rewriteGRPCError(err) | ||||
| @@ -146,7 +146,7 @@ func (rs *remoteStore) negotiate(ctx context.Context, ref string, size int64, ex | ||||
| 		return nil, 0, err | ||||
| 	} | ||||
|  | ||||
| 	if err := wrclient.Send(&contentapi.WriteRequest{ | ||||
| 	if err := wrclient.Send(&contentapi.WriteContentRequest{ | ||||
| 		Action:   contentapi.WriteActionStat, | ||||
| 		Ref:      ref, | ||||
| 		Total:    size, | ||||
|   | ||||
| @@ -17,7 +17,7 @@ type remoteWriter struct { | ||||
| } | ||||
|  | ||||
| // send performs a synchronous req-resp cycle on the client. | ||||
| func (rw *remoteWriter) send(req *contentapi.WriteRequest) (*contentapi.WriteResponse, error) { | ||||
| func (rw *remoteWriter) send(req *contentapi.WriteContentRequest) (*contentapi.WriteContentResponse, error) { | ||||
| 	if err := rw.client.Send(req); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| @@ -35,7 +35,7 @@ func (rw *remoteWriter) send(req *contentapi.WriteRequest) (*contentapi.WriteRes | ||||
| } | ||||
|  | ||||
| func (rw *remoteWriter) Status() (content.Status, error) { | ||||
| 	resp, err := rw.send(&contentapi.WriteRequest{ | ||||
| 	resp, err := rw.send(&contentapi.WriteContentRequest{ | ||||
| 		Action: contentapi.WriteActionStat, | ||||
| 	}) | ||||
| 	if err != nil { | ||||
| @@ -57,7 +57,7 @@ func (rw *remoteWriter) Digest() digest.Digest { | ||||
| func (rw *remoteWriter) Write(p []byte) (n int, err error) { | ||||
| 	offset := rw.offset | ||||
|  | ||||
| 	resp, err := rw.send(&contentapi.WriteRequest{ | ||||
| 	resp, err := rw.send(&contentapi.WriteContentRequest{ | ||||
| 		Action: contentapi.WriteActionWrite, | ||||
| 		Offset: offset, | ||||
| 		Data:   p, | ||||
| @@ -79,7 +79,7 @@ func (rw *remoteWriter) Write(p []byte) (n int, err error) { | ||||
| } | ||||
|  | ||||
| func (rw *remoteWriter) Commit(size int64, expected digest.Digest) error { | ||||
| 	resp, err := rw.send(&contentapi.WriteRequest{ | ||||
| 	resp, err := rw.send(&contentapi.WriteContentRequest{ | ||||
| 		Action:   contentapi.WriteActionCommit, | ||||
| 		Total:    size, | ||||
| 		Offset:   rw.offset, | ||||
|   | ||||
| @@ -35,7 +35,7 @@ func (s *Service) Register(server *grpc.Server) error { | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (s *Service) EventStream(req *api.EventStreamRequest, srv api.Events_EventStreamServer) error { | ||||
| func (s *Service) Stream(req *api.StreamEventsRequest, srv api.Events_StreamServer) error { | ||||
| 	clientID := fmt.Sprintf("%d", time.Now().UnixNano()) | ||||
| 	for { | ||||
| 		e := <-s.emitter.Events(srv.Context(), clientID) | ||||
|   | ||||
| @@ -1,89 +0,0 @@ | ||||
| package execution | ||||
|  | ||||
| import ( | ||||
| 	"sync" | ||||
|  | ||||
| 	"github.com/containerd/containerd/plugin" | ||||
|  | ||||
| 	"golang.org/x/net/context" | ||||
| ) | ||||
|  | ||||
| func newCollector(ctx context.Context, runtimes map[string]plugin.Runtime) (*collector, error) { | ||||
| 	c := &collector{ | ||||
| 		context:      ctx, | ||||
| 		ch:           make(chan *plugin.Event, 2048), | ||||
| 		eventClients: make(map[*eventClient]struct{}), | ||||
| 	} | ||||
| 	for _, r := range runtimes { | ||||
| 		if err := c.collect(r); err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 	} | ||||
| 	// run the publisher | ||||
| 	go c.publisher() | ||||
| 	// run a goroutine that waits for the context to be done | ||||
| 	// and closes the channel after all writes have finished | ||||
| 	go c.waitDone() | ||||
| 	return c, nil | ||||
| } | ||||
|  | ||||
| type eventClient struct { | ||||
| 	eCh chan error | ||||
| 	w   *grpcEventWriter | ||||
| } | ||||
|  | ||||
| type collector struct { | ||||
| 	mu sync.Mutex | ||||
| 	wg sync.WaitGroup | ||||
|  | ||||
| 	context      context.Context | ||||
| 	ch           chan *plugin.Event | ||||
| 	eventClients map[*eventClient]struct{} | ||||
| } | ||||
|  | ||||
| // collect collects events from the provided runtime | ||||
| func (c *collector) collect(r plugin.Runtime) error { | ||||
| 	c.wg.Add(1) | ||||
| 	go func() { | ||||
| 		defer c.wg.Done() | ||||
| 		for e := range r.Events(c.context) { | ||||
| 			c.ch <- e | ||||
| 		} | ||||
| 	}() | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (c *collector) forward(w *grpcEventWriter) error { | ||||
| 	client := &eventClient{ | ||||
| 		w:   w, | ||||
| 		eCh: make(chan error, 1), | ||||
| 	} | ||||
| 	c.mu.Lock() | ||||
| 	c.eventClients[client] = struct{}{} | ||||
| 	c.mu.Unlock() | ||||
| 	err := <-client.eCh | ||||
| 	c.mu.Lock() | ||||
| 	delete(c.eventClients, client) | ||||
| 	c.mu.Unlock() | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| func (c *collector) publisher() { | ||||
| 	for e := range c.ch { | ||||
| 		c.mu.Lock() | ||||
| 		for client := range c.eventClients { | ||||
| 			if err := client.w.Write(e); err != nil { | ||||
| 				client.eCh <- err | ||||
| 			} | ||||
| 		} | ||||
| 		c.mu.Unlock() | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // waitDone waits for the context to finish, waits for all the goroutines to finish | ||||
| // collecting grpc events from the shim, and closes the output channel | ||||
| func (c *collector) waitDone() { | ||||
| 	<-c.context.Done() | ||||
| 	c.wg.Wait() | ||||
| 	close(c.ch) | ||||
| } | ||||
| @@ -67,26 +67,20 @@ func New(ic *plugin.InitContext) (interface{}, error) { | ||||
| 		r := rr.(plugin.Runtime) | ||||
| 		runtimes[r.ID()] = r | ||||
| 	} | ||||
| 	c, err := newCollector(ic.Context, runtimes) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	e := events.GetPoster(ic.Context) | ||||
| 	return &Service{ | ||||
| 		runtimes:  runtimes, | ||||
| 		db:        m.(*bolt.DB), | ||||
| 		collector: c, | ||||
| 		store:     ct.(content.Store), | ||||
| 		emitter:   e, | ||||
| 		runtimes: runtimes, | ||||
| 		db:       m.(*bolt.DB), | ||||
| 		store:    ct.(content.Store), | ||||
| 		emitter:  e, | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| type Service struct { | ||||
| 	runtimes  map[string]plugin.Runtime | ||||
| 	db        *bolt.DB | ||||
| 	collector *collector | ||||
| 	store     content.Store | ||||
| 	emitter   events.Poster | ||||
| 	runtimes map[string]plugin.Runtime | ||||
| 	db       *bolt.DB | ||||
| 	store    content.Store | ||||
| 	emitter  events.Poster | ||||
| } | ||||
|  | ||||
| func (s *Service) Register(server *grpc.Server) error { | ||||
| @@ -94,7 +88,7 @@ func (s *Service) Register(server *grpc.Server) error { | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (s *Service) Create(ctx context.Context, r *api.CreateRequest) (*api.CreateResponse, error) { | ||||
| func (s *Service) Create(ctx context.Context, r *api.CreateTaskRequest) (*api.CreateTaskResponse, error) { | ||||
| 	var ( | ||||
| 		checkpointPath string | ||||
| 		err            error | ||||
| @@ -152,7 +146,7 @@ func (s *Service) Create(ctx context.Context, r *api.CreateRequest) (*api.Create | ||||
| 			Options: m.Options, | ||||
| 		}) | ||||
| 	} | ||||
| 	runtime, err := s.getRuntime(container.Runtime) | ||||
| 	runtime, err := s.getRuntime(container.Runtime.Name) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| @@ -171,13 +165,13 @@ func (s *Service) Create(ctx context.Context, r *api.CreateRequest) (*api.Create | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	return &api.CreateResponse{ | ||||
| 	return &api.CreateTaskResponse{ | ||||
| 		ContainerID: r.ContainerID, | ||||
| 		Pid:         state.Pid, | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| func (s *Service) Start(ctx context.Context, r *api.StartRequest) (*google_protobuf.Empty, error) { | ||||
| func (s *Service) Start(ctx context.Context, r *api.StartTaskRequest) (*google_protobuf.Empty, error) { | ||||
| 	t, err := s.getTask(ctx, r.ContainerID) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| @@ -195,7 +189,7 @@ func (s *Service) Start(ctx context.Context, r *api.StartRequest) (*google_proto | ||||
| 	return empty, nil | ||||
| } | ||||
|  | ||||
| func (s *Service) Delete(ctx context.Context, r *api.DeleteRequest) (*api.DeleteResponse, error) { | ||||
| func (s *Service) Delete(ctx context.Context, r *api.DeleteTaskRequest) (*api.DeleteResponse, error) { | ||||
| 	t, err := s.getTask(ctx, r.ContainerID) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| @@ -271,7 +265,7 @@ func taskFromContainerd(ctx context.Context, c plugin.Task) (*task.Task, error) | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| func (s *Service) Info(ctx context.Context, r *api.InfoRequest) (*api.InfoResponse, error) { | ||||
| func (s *Service) Get(ctx context.Context, r *api.GetTaskRequest) (*api.GetTaskResponse, error) { | ||||
| 	task, err := s.getTask(ctx, r.ContainerID) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| @@ -280,13 +274,13 @@ func (s *Service) Info(ctx context.Context, r *api.InfoRequest) (*api.InfoRespon | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return &api.InfoResponse{ | ||||
| 	return &api.GetTaskResponse{ | ||||
| 		Task: t, | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| func (s *Service) List(ctx context.Context, r *api.ListRequest) (*api.ListResponse, error) { | ||||
| 	resp := &api.ListResponse{} | ||||
| func (s *Service) List(ctx context.Context, r *api.ListTasksRequest) (*api.ListTasksResponse, error) { | ||||
| 	resp := &api.ListTasksResponse{} | ||||
| 	for _, r := range s.runtimes { | ||||
| 		tasks, err := r.Tasks(ctx) | ||||
| 		if err != nil { | ||||
| @@ -303,7 +297,7 @@ func (s *Service) List(ctx context.Context, r *api.ListRequest) (*api.ListRespon | ||||
| 	return resp, nil | ||||
| } | ||||
|  | ||||
| func (s *Service) Pause(ctx context.Context, r *api.PauseRequest) (*google_protobuf.Empty, error) { | ||||
| func (s *Service) Pause(ctx context.Context, r *api.PauseTaskRequest) (*google_protobuf.Empty, error) { | ||||
| 	t, err := s.getTask(ctx, r.ContainerID) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| @@ -315,7 +309,7 @@ func (s *Service) Pause(ctx context.Context, r *api.PauseRequest) (*google_proto | ||||
| 	return empty, nil | ||||
| } | ||||
|  | ||||
| func (s *Service) Resume(ctx context.Context, r *api.ResumeRequest) (*google_protobuf.Empty, error) { | ||||
| func (s *Service) Resume(ctx context.Context, r *api.ResumeTaskRequest) (*google_protobuf.Empty, error) { | ||||
| 	t, err := s.getTask(ctx, r.ContainerID) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| @@ -348,7 +342,7 @@ func (s *Service) Kill(ctx context.Context, r *api.KillRequest) (*google_protobu | ||||
| 	return empty, nil | ||||
| } | ||||
|  | ||||
| func (s *Service) Processes(ctx context.Context, r *api.ProcessesRequest) (*api.ProcessesResponse, error) { | ||||
| func (s *Service) ListProcesses(ctx context.Context, r *api.ListProcessesRequest) (*api.ListProcessesResponse, error) { | ||||
| 	t, err := s.getTask(ctx, r.ContainerID) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| @@ -365,22 +359,12 @@ func (s *Service) Processes(ctx context.Context, r *api.ProcessesRequest) (*api. | ||||
| 			Pid: pid, | ||||
| 		}) | ||||
| 	} | ||||
|  | ||||
| 	resp := &api.ProcessesResponse{ | ||||
| 	return &api.ListProcessesResponse{ | ||||
| 		Processes: ps, | ||||
| 	} | ||||
|  | ||||
| 	return resp, nil | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| func (s *Service) Events(r *api.EventsRequest, server api.Tasks_EventsServer) error { | ||||
| 	w := &grpcEventWriter{ | ||||
| 		server: server, | ||||
| 	} | ||||
| 	return s.collector.forward(w) | ||||
| } | ||||
|  | ||||
| func (s *Service) Exec(ctx context.Context, r *api.ExecRequest) (*api.ExecResponse, error) { | ||||
| func (s *Service) Exec(ctx context.Context, r *api.ExecProcessRequest) (*api.ExecProcessResponse, error) { | ||||
| 	t, err := s.getTask(ctx, r.ContainerID) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| @@ -401,12 +385,12 @@ func (s *Service) Exec(ctx context.Context, r *api.ExecRequest) (*api.ExecRespon | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return &api.ExecResponse{ | ||||
| 	return &api.ExecProcessResponse{ | ||||
| 		Pid: state.Pid, | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| func (s *Service) Pty(ctx context.Context, r *api.PtyRequest) (*google_protobuf.Empty, error) { | ||||
| func (s *Service) ResizePty(ctx context.Context, r *api.ResizePtyRequest) (*google_protobuf.Empty, error) { | ||||
| 	t, err := s.getTask(ctx, r.ContainerID) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| @@ -420,18 +404,20 @@ func (s *Service) Pty(ctx context.Context, r *api.PtyRequest) (*google_protobuf. | ||||
| 	return empty, nil | ||||
| } | ||||
|  | ||||
| func (s *Service) CloseStdin(ctx context.Context, r *api.CloseStdinRequest) (*google_protobuf.Empty, error) { | ||||
| func (s *Service) CloseIO(ctx context.Context, r *api.CloseIORequest) (*google_protobuf.Empty, error) { | ||||
| 	t, err := s.getTask(ctx, r.ContainerID) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	if err := t.CloseStdin(ctx, r.Pid); err != nil { | ||||
| 		return nil, err | ||||
| 	if r.Stdin { | ||||
| 		if err := t.CloseStdin(ctx, r.Pid); err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 	} | ||||
| 	return empty, nil | ||||
| } | ||||
|  | ||||
| func (s *Service) Checkpoint(ctx context.Context, r *api.CheckpointRequest) (*api.CheckpointResponse, error) { | ||||
| func (s *Service) Checkpoint(ctx context.Context, r *api.CheckpointTaskRequest) (*api.CheckpointTaskResponse, error) { | ||||
| 	t, err := s.getTask(ctx, r.ContainerID) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| @@ -441,16 +427,7 @@ func (s *Service) Checkpoint(ctx context.Context, r *api.CheckpointRequest) (*ap | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	defer os.RemoveAll(image) | ||||
| 	if err := t.Checkpoint(ctx, plugin.CheckpointOpts{ | ||||
| 		Exit:             r.Exit, | ||||
| 		AllowTCP:         r.AllowTcp, | ||||
| 		AllowTerminal:    r.AllowTerminal, | ||||
| 		AllowUnixSockets: r.AllowUnixSockets, | ||||
| 		FileLocks:        r.FileLocks, | ||||
| 		// ParentImage: r.ParentImage, | ||||
| 		EmptyNamespaces: r.EmptyNamespaces, | ||||
| 		Path:            image, | ||||
| 	}); err != nil { | ||||
| 	if err := t.Checkpoint(ctx, image, r.Options); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	// write checkpoint to the content store | ||||
| @@ -469,7 +446,7 @@ func (s *Service) Checkpoint(ctx context.Context, r *api.CheckpointRequest) (*ap | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return &api.CheckpointResponse{ | ||||
| 	return &api.CheckpointTaskResponse{ | ||||
| 		Descriptors: []*descriptor.Descriptor{ | ||||
| 			cp, | ||||
| 			specD, | ||||
| @@ -523,31 +500,3 @@ func (s *Service) emit(ctx context.Context, topic string, evt interface{}) error | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| type grpcEventWriter struct { | ||||
| 	server api.Tasks_EventsServer | ||||
| } | ||||
|  | ||||
| func (g *grpcEventWriter) Write(e *plugin.Event) error { | ||||
| 	var t task.Event_EventType | ||||
| 	switch e.Type { | ||||
| 	case plugin.ExitEvent: | ||||
| 		t = task.Event_EXIT | ||||
| 	case plugin.ExecAddEvent: | ||||
| 		t = task.Event_EXEC_ADDED | ||||
| 	case plugin.PausedEvent: | ||||
| 		t = task.Event_PAUSED | ||||
| 	case plugin.CreateEvent: | ||||
| 		t = task.Event_CREATE | ||||
| 	case plugin.StartEvent: | ||||
| 		t = task.Event_START | ||||
| 	case plugin.OOMEvent: | ||||
| 		t = task.Event_OOM | ||||
| 	} | ||||
| 	return g.server.Send(&task.Event{ | ||||
| 		Type:       t, | ||||
| 		ID:         e.ID, | ||||
| 		Pid:        e.Pid, | ||||
| 		ExitStatus: e.ExitStatus, | ||||
| 	}) | ||||
| } | ||||
|   | ||||
| @@ -18,10 +18,10 @@ func NewStoreFromClient(client imagesapi.ImagesClient) images.Store { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (s *remoteStore) Put(ctx context.Context, name string, desc ocispec.Descriptor) error { | ||||
| func (s *remoteStore) Update(ctx context.Context, name string, desc ocispec.Descriptor) error { | ||||
| 	// TODO(stevvooe): Consider that the remote may want to augment and return | ||||
| 	// a modified image. | ||||
| 	_, err := s.client.Put(ctx, &imagesapi.PutRequest{ | ||||
| 	_, err := s.client.Update(ctx, &imagesapi.UpdateImageRequest{ | ||||
| 		Image: imagesapi.Image{ | ||||
| 			Name:   name, | ||||
| 			Target: descToProto(&desc), | ||||
| @@ -32,7 +32,7 @@ func (s *remoteStore) Put(ctx context.Context, name string, desc ocispec.Descrip | ||||
| } | ||||
|  | ||||
| func (s *remoteStore) Get(ctx context.Context, name string) (images.Image, error) { | ||||
| 	resp, err := s.client.Get(ctx, &imagesapi.GetRequest{ | ||||
| 	resp, err := s.client.Get(ctx, &imagesapi.GetImageRequest{ | ||||
| 		Name: name, | ||||
| 	}) | ||||
| 	if err != nil { | ||||
| @@ -43,7 +43,7 @@ func (s *remoteStore) Get(ctx context.Context, name string) (images.Image, error | ||||
| } | ||||
|  | ||||
| func (s *remoteStore) List(ctx context.Context) ([]images.Image, error) { | ||||
| 	resp, err := s.client.List(ctx, &imagesapi.ListRequest{}) | ||||
| 	resp, err := s.client.List(ctx, &imagesapi.ListImagesRequest{}) | ||||
| 	if err != nil { | ||||
| 		return nil, rewriteGRPCError(err) | ||||
| 	} | ||||
| @@ -52,7 +52,7 @@ func (s *remoteStore) List(ctx context.Context) ([]images.Image, error) { | ||||
| } | ||||
|  | ||||
| func (s *remoteStore) Delete(ctx context.Context, name string) error { | ||||
| 	_, err := s.client.Delete(ctx, &imagesapi.DeleteRequest{ | ||||
| 	_, err := s.client.Delete(ctx, &imagesapi.DeleteImageRequest{ | ||||
| 		Name: name, | ||||
| 	}) | ||||
|  | ||||
|   | ||||
| @@ -48,8 +48,8 @@ func (s *Service) Register(server *grpc.Server) error { | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (s *Service) Get(ctx context.Context, req *imagesapi.GetRequest) (*imagesapi.GetResponse, error) { | ||||
| 	var resp imagesapi.GetResponse | ||||
| func (s *Service) Get(ctx context.Context, req *imagesapi.GetImageRequest) (*imagesapi.GetImageResponse, error) { | ||||
| 	var resp imagesapi.GetImageResponse | ||||
|  | ||||
| 	return &resp, s.withStoreView(ctx, func(ctx context.Context, store images.Store) error { | ||||
| 		image, err := store.Get(ctx, req.Name) | ||||
| @@ -62,25 +62,28 @@ func (s *Service) Get(ctx context.Context, req *imagesapi.GetRequest) (*imagesap | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func (s *Service) Put(ctx context.Context, req *imagesapi.PutRequest) (*empty.Empty, error) { | ||||
| func (s *Service) Update(ctx context.Context, req *imagesapi.UpdateImageRequest) (*imagesapi.UpdateImageResponse, error) { | ||||
| 	if err := s.withStoreUpdate(ctx, func(ctx context.Context, store images.Store) error { | ||||
| 		return mapGRPCError(store.Put(ctx, req.Image.Name, descFromProto(&req.Image.Target)), req.Image.Name) | ||||
| 		return mapGRPCError(store.Update(ctx, req.Image.Name, descFromProto(&req.Image.Target)), req.Image.Name) | ||||
| 	}); err != nil { | ||||
| 		return &empty.Empty{}, err | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	if err := s.emit(ctx, "/images/put", event.ImagePut{ | ||||
| 	if err := s.emit(ctx, "/images/update", event.ImageUpdate{ | ||||
| 		Name:   req.Image.Name, | ||||
| 		Labels: req.Image.Labels, | ||||
| 	}); err != nil { | ||||
| 		return &empty.Empty{}, err | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	return &empty.Empty{}, nil | ||||
| 	// TODO: get image back out to return | ||||
| 	return &imagesapi.UpdateImageResponse{ | ||||
| 	//Image: nil, | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| func (s *Service) List(ctx context.Context, _ *imagesapi.ListRequest) (*imagesapi.ListResponse, error) { | ||||
| 	var resp imagesapi.ListResponse | ||||
| func (s *Service) List(ctx context.Context, _ *imagesapi.ListImagesRequest) (*imagesapi.ListImagesResponse, error) { | ||||
| 	var resp imagesapi.ListImagesResponse | ||||
|  | ||||
| 	return &resp, s.withStoreView(ctx, func(ctx context.Context, store images.Store) error { | ||||
| 		images, err := store.List(ctx) | ||||
| @@ -93,17 +96,17 @@ func (s *Service) List(ctx context.Context, _ *imagesapi.ListRequest) (*imagesap | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func (s *Service) Delete(ctx context.Context, req *imagesapi.DeleteRequest) (*empty.Empty, error) { | ||||
| func (s *Service) Delete(ctx context.Context, req *imagesapi.DeleteImageRequest) (*empty.Empty, error) { | ||||
| 	if err := s.withStoreUpdate(ctx, func(ctx context.Context, store images.Store) error { | ||||
| 		return mapGRPCError(store.Delete(ctx, req.Name), req.Name) | ||||
| 	}); err != nil { | ||||
| 		return &empty.Empty{}, err | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	if err := s.emit(ctx, "/images/delete", event.ImageDelete{ | ||||
| 		Name: req.Name, | ||||
| 	}); err != nil { | ||||
| 		return &empty.Empty{}, err | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	return &empty.Empty{}, nil | ||||
|   | ||||
| @@ -9,6 +9,7 @@ import ( | ||||
| 	"google.golang.org/grpc/codes" | ||||
|  | ||||
| 	snapshotapi "github.com/containerd/containerd/api/services/snapshot" | ||||
| 	mountapi "github.com/containerd/containerd/api/types/mount" | ||||
| 	"github.com/containerd/containerd/mount" | ||||
| 	"github.com/containerd/containerd/snapshot" | ||||
| 	"github.com/pkg/errors" | ||||
| @@ -16,18 +17,18 @@ import ( | ||||
|  | ||||
| // NewSnapshotterFromClient returns a new Snapshotter which communicates | ||||
| // over a GRPC connection. | ||||
| func NewSnapshotterFromClient(client snapshotapi.SnapshotClient) snapshot.Snapshotter { | ||||
| func NewSnapshotterFromClient(client snapshotapi.SnapshotsClient) snapshot.Snapshotter { | ||||
| 	return &remoteSnapshotter{ | ||||
| 		client: client, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| type remoteSnapshotter struct { | ||||
| 	client snapshotapi.SnapshotClient | ||||
| 	client snapshotapi.SnapshotsClient | ||||
| } | ||||
|  | ||||
| func (r *remoteSnapshotter) Stat(ctx context.Context, key string) (snapshot.Info, error) { | ||||
| 	resp, err := r.client.Stat(ctx, &snapshotapi.StatRequest{Key: key}) | ||||
| 	resp, err := r.client.Stat(ctx, &snapshotapi.StatSnapshotRequest{Key: key}) | ||||
| 	if err != nil { | ||||
| 		return snapshot.Info{}, rewriteGRPCError(err) | ||||
| 	} | ||||
| @@ -47,27 +48,27 @@ func (r *remoteSnapshotter) Mounts(ctx context.Context, key string) ([]mount.Mou | ||||
| 	if err != nil { | ||||
| 		return nil, rewriteGRPCError(err) | ||||
| 	} | ||||
| 	return toMounts(resp), nil | ||||
| 	return toMounts(resp.Mounts), nil | ||||
| } | ||||
|  | ||||
| func (r *remoteSnapshotter) Prepare(ctx context.Context, key, parent string) ([]mount.Mount, error) { | ||||
| 	resp, err := r.client.Prepare(ctx, &snapshotapi.PrepareRequest{Key: key, Parent: parent}) | ||||
| 	resp, err := r.client.Prepare(ctx, &snapshotapi.PrepareSnapshotRequest{Key: key, Parent: parent}) | ||||
| 	if err != nil { | ||||
| 		return nil, rewriteGRPCError(err) | ||||
| 	} | ||||
| 	return toMounts(resp), nil | ||||
| 	return toMounts(resp.Mounts), nil | ||||
| } | ||||
|  | ||||
| func (r *remoteSnapshotter) View(ctx context.Context, key, parent string) ([]mount.Mount, error) { | ||||
| 	resp, err := r.client.View(ctx, &snapshotapi.PrepareRequest{Key: key, Parent: parent}) | ||||
| 	resp, err := r.client.View(ctx, &snapshotapi.ViewSnapshotRequest{Key: key, Parent: parent}) | ||||
| 	if err != nil { | ||||
| 		return nil, rewriteGRPCError(err) | ||||
| 	} | ||||
| 	return toMounts(resp), nil | ||||
| 	return toMounts(resp.Mounts), nil | ||||
| } | ||||
|  | ||||
| func (r *remoteSnapshotter) Commit(ctx context.Context, name, key string) error { | ||||
| 	_, err := r.client.Commit(ctx, &snapshotapi.CommitRequest{ | ||||
| 	_, err := r.client.Commit(ctx, &snapshotapi.CommitSnapshotRequest{ | ||||
| 		Name: name, | ||||
| 		Key:  key, | ||||
| 	}) | ||||
| @@ -75,12 +76,12 @@ func (r *remoteSnapshotter) Commit(ctx context.Context, name, key string) error | ||||
| } | ||||
|  | ||||
| func (r *remoteSnapshotter) Remove(ctx context.Context, key string) error { | ||||
| 	_, err := r.client.Remove(ctx, &snapshotapi.RemoveRequest{Key: key}) | ||||
| 	_, err := r.client.Remove(ctx, &snapshotapi.RemoveSnapshotRequest{Key: key}) | ||||
| 	return rewriteGRPCError(err) | ||||
| } | ||||
|  | ||||
| func (r *remoteSnapshotter) Walk(ctx context.Context, fn func(context.Context, snapshot.Info) error) error { | ||||
| 	sc, err := r.client.List(ctx, &snapshotapi.ListRequest{}) | ||||
| 	sc, err := r.client.List(ctx, &snapshotapi.ListSnapshotsRequest{}) | ||||
| 	if err != nil { | ||||
| 		rewriteGRPCError(err) | ||||
| 	} | ||||
| @@ -145,9 +146,9 @@ func toUsage(resp *snapshotapi.UsageResponse) snapshot.Usage { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func toMounts(resp *snapshotapi.MountsResponse) []mount.Mount { | ||||
| 	mounts := make([]mount.Mount, len(resp.Mounts)) | ||||
| 	for i, m := range resp.Mounts { | ||||
| func toMounts(mm []*mountapi.Mount) []mount.Mount { | ||||
| 	mounts := make([]mount.Mount, len(mm)) | ||||
| 	for i, m := range mm { | ||||
| 		mounts[i] = mount.Mount{ | ||||
| 			Type:    m.Type, | ||||
| 			Source:  m.Source, | ||||
|   | ||||
| @@ -50,11 +50,11 @@ func newService(snapshotter snapshot.Snapshotter, evts events.Poster) (*service, | ||||
| } | ||||
|  | ||||
| func (s *service) Register(gs *grpc.Server) error { | ||||
| 	snapshotapi.RegisterSnapshotServer(gs, s) | ||||
| 	snapshotapi.RegisterSnapshotsServer(gs, s) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (s *service) Prepare(ctx context.Context, pr *snapshotapi.PrepareRequest) (*snapshotapi.MountsResponse, error) { | ||||
| func (s *service) Prepare(ctx context.Context, pr *snapshotapi.PrepareSnapshotRequest) (*snapshotapi.PrepareSnapshotResponse, error) { | ||||
| 	log.G(ctx).WithField("parent", pr.Parent).WithField("key", pr.Key).Debugf("Preparing snapshot") | ||||
| 	// TODO: Apply namespace | ||||
| 	// TODO: Lookup snapshot id from metadata store | ||||
| @@ -69,11 +69,12 @@ func (s *service) Prepare(ctx context.Context, pr *snapshotapi.PrepareRequest) ( | ||||
| 	}); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	return fromMounts(mounts), nil | ||||
| 	return &snapshotapi.PrepareSnapshotResponse{ | ||||
| 		Mounts: fromMounts(mounts), | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| func (s *service) View(ctx context.Context, pr *snapshotapi.PrepareRequest) (*snapshotapi.MountsResponse, error) { | ||||
| func (s *service) View(ctx context.Context, pr *snapshotapi.ViewSnapshotRequest) (*snapshotapi.ViewSnapshotResponse, error) { | ||||
| 	log.G(ctx).WithField("parent", pr.Parent).WithField("key", pr.Key).Debugf("Preparing view snapshot") | ||||
| 	// TODO: Apply namespace | ||||
| 	// TODO: Lookup snapshot id from metadata store | ||||
| @@ -81,7 +82,9 @@ func (s *service) View(ctx context.Context, pr *snapshotapi.PrepareRequest) (*sn | ||||
| 	if err != nil { | ||||
| 		return nil, grpcError(err) | ||||
| 	} | ||||
| 	return fromMounts(mounts), nil | ||||
| 	return &snapshotapi.ViewSnapshotResponse{ | ||||
| 		Mounts: fromMounts(mounts), | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| func (s *service) Mounts(ctx context.Context, mr *snapshotapi.MountsRequest) (*snapshotapi.MountsResponse, error) { | ||||
| @@ -92,10 +95,12 @@ func (s *service) Mounts(ctx context.Context, mr *snapshotapi.MountsRequest) (*s | ||||
| 	if err != nil { | ||||
| 		return nil, grpcError(err) | ||||
| 	} | ||||
| 	return fromMounts(mounts), nil | ||||
| 	return &snapshotapi.MountsResponse{ | ||||
| 		Mounts: fromMounts(mounts), | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| func (s *service) Commit(ctx context.Context, cr *snapshotapi.CommitRequest) (*protoempty.Empty, error) { | ||||
| func (s *service) Commit(ctx context.Context, cr *snapshotapi.CommitSnapshotRequest) (*protoempty.Empty, error) { | ||||
| 	log.G(ctx).WithField("key", cr.Key).WithField("name", cr.Name).Debugf("Committing snapshot") | ||||
| 	// TODO: Apply namespace | ||||
| 	// TODO: Lookup snapshot id from metadata store | ||||
| @@ -112,7 +117,7 @@ func (s *service) Commit(ctx context.Context, cr *snapshotapi.CommitRequest) (*p | ||||
| 	return empty, nil | ||||
| } | ||||
|  | ||||
| func (s *service) Remove(ctx context.Context, rr *snapshotapi.RemoveRequest) (*protoempty.Empty, error) { | ||||
| func (s *service) Remove(ctx context.Context, rr *snapshotapi.RemoveSnapshotRequest) (*protoempty.Empty, error) { | ||||
| 	log.G(ctx).WithField("key", rr.Key).Debugf("Removing snapshot") | ||||
| 	// TODO: Apply namespace | ||||
| 	// TODO: Lookup snapshot id from metadata store | ||||
| @@ -128,7 +133,7 @@ func (s *service) Remove(ctx context.Context, rr *snapshotapi.RemoveRequest) (*p | ||||
| 	return empty, nil | ||||
| } | ||||
|  | ||||
| func (s *service) Stat(ctx context.Context, sr *snapshotapi.StatRequest) (*snapshotapi.StatResponse, error) { | ||||
| func (s *service) Stat(ctx context.Context, sr *snapshotapi.StatSnapshotRequest) (*snapshotapi.StatSnapshotResponse, error) { | ||||
| 	log.G(ctx).WithField("key", sr.Key).Debugf("Statting snapshot") | ||||
| 	// TODO: Apply namespace | ||||
| 	info, err := s.snapshotter.Stat(ctx, sr.Key) | ||||
| @@ -136,16 +141,15 @@ func (s *service) Stat(ctx context.Context, sr *snapshotapi.StatRequest) (*snaps | ||||
| 		return nil, grpcError(err) | ||||
| 	} | ||||
|  | ||||
| 	return &snapshotapi.StatResponse{Info: fromInfo(info)}, nil | ||||
| 	return &snapshotapi.StatSnapshotResponse{Info: fromInfo(info)}, nil | ||||
| } | ||||
|  | ||||
| func (s *service) List(sr *snapshotapi.ListRequest, ss snapshotapi.Snapshot_ListServer) error { | ||||
| func (s *service) List(sr *snapshotapi.ListSnapshotsRequest, ss snapshotapi.Snapshots_ListServer) error { | ||||
| 	// TODO: Apply namespace | ||||
|  | ||||
| 	var ( | ||||
| 		buffer    []snapshotapi.Info | ||||
| 		sendBlock = func(block []snapshotapi.Info) error { | ||||
| 			return ss.Send(&snapshotapi.ListResponse{ | ||||
| 			return ss.Send(&snapshotapi.ListSnapshotsResponse{ | ||||
| 				Info: block, | ||||
| 			}) | ||||
| 		} | ||||
| @@ -223,18 +227,16 @@ func fromUsage(usage snapshot.Usage) *snapshotapi.UsageResponse { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func fromMounts(mounts []mount.Mount) *snapshotapi.MountsResponse { | ||||
| 	resp := &snapshotapi.MountsResponse{ | ||||
| 		Mounts: make([]*mounttypes.Mount, len(mounts)), | ||||
| 	} | ||||
| func fromMounts(mounts []mount.Mount) []*mounttypes.Mount { | ||||
| 	out := make([]*mounttypes.Mount, len(mounts)) | ||||
| 	for i, m := range mounts { | ||||
| 		resp.Mounts[i] = &mounttypes.Mount{ | ||||
| 		out[i] = &mounttypes.Mount{ | ||||
| 			Type:    m.Type, | ||||
| 			Source:  m.Source, | ||||
| 			Options: m.Options, | ||||
| 		} | ||||
| 	} | ||||
| 	return resp | ||||
| 	return out | ||||
| } | ||||
|  | ||||
| func (s *service) emit(ctx context.Context, topic string, evt interface{}) error { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Michael Crosby
					Michael Crosby