github.com/containerd/Containerd@v1.4.13/services/tasks/service.go (about) 1 /* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package tasks 18 19 import ( 20 "context" 21 22 api "github.com/containerd/containerd/api/services/tasks/v1" 23 "github.com/containerd/containerd/plugin" 24 "github.com/containerd/containerd/services" 25 ptypes "github.com/gogo/protobuf/types" 26 "github.com/pkg/errors" 27 "google.golang.org/grpc" 28 ) 29 30 var ( 31 _ = (api.TasksServer)(&service{}) 32 ) 33 34 func init() { 35 plugin.Register(&plugin.Registration{ 36 Type: plugin.GRPCPlugin, 37 ID: "tasks", 38 Requires: []plugin.Type{ 39 plugin.ServicePlugin, 40 }, 41 InitFn: func(ic *plugin.InitContext) (interface{}, error) { 42 plugins, err := ic.GetByType(plugin.ServicePlugin) 43 if err != nil { 44 return nil, err 45 } 46 p, ok := plugins[services.TasksService] 47 if !ok { 48 return nil, errors.New("tasks service not found") 49 } 50 i, err := p.Instance() 51 if err != nil { 52 return nil, err 53 } 54 return &service{local: i.(api.TasksClient)}, nil 55 }, 56 }) 57 } 58 59 type service struct { 60 local api.TasksClient 61 } 62 63 func (s *service) Register(server *grpc.Server) error { 64 api.RegisterTasksServer(server, s) 65 return nil 66 } 67 68 func (s *service) Create(ctx context.Context, r *api.CreateTaskRequest) (*api.CreateTaskResponse, error) { 69 return s.local.Create(ctx, r) 70 } 71 72 func (s *service) Start(ctx context.Context, r *api.StartRequest) (*api.StartResponse, error) { 73 return s.local.Start(ctx, r) 74 } 75 76 func (s *service) Delete(ctx context.Context, r *api.DeleteTaskRequest) (*api.DeleteResponse, error) { 77 return s.local.Delete(ctx, r) 78 } 79 80 func (s *service) DeleteProcess(ctx context.Context, r *api.DeleteProcessRequest) (*api.DeleteResponse, error) { 81 return s.local.DeleteProcess(ctx, r) 82 } 83 84 func (s *service) Get(ctx context.Context, r *api.GetRequest) (*api.GetResponse, error) { 85 return s.local.Get(ctx, r) 86 } 87 88 func (s *service) List(ctx context.Context, r *api.ListTasksRequest) (*api.ListTasksResponse, error) { 89 return s.local.List(ctx, r) 90 } 91 92 func (s *service) Pause(ctx context.Context, r *api.PauseTaskRequest) (*ptypes.Empty, error) { 93 return s.local.Pause(ctx, r) 94 } 95 96 func (s *service) Resume(ctx context.Context, r *api.ResumeTaskRequest) (*ptypes.Empty, error) { 97 return s.local.Resume(ctx, r) 98 } 99 100 func (s *service) Kill(ctx context.Context, r *api.KillRequest) (*ptypes.Empty, error) { 101 return s.local.Kill(ctx, r) 102 } 103 104 func (s *service) ListPids(ctx context.Context, r *api.ListPidsRequest) (*api.ListPidsResponse, error) { 105 return s.local.ListPids(ctx, r) 106 } 107 108 func (s *service) Exec(ctx context.Context, r *api.ExecProcessRequest) (*ptypes.Empty, error) { 109 return s.local.Exec(ctx, r) 110 } 111 112 func (s *service) ResizePty(ctx context.Context, r *api.ResizePtyRequest) (*ptypes.Empty, error) { 113 return s.local.ResizePty(ctx, r) 114 } 115 116 func (s *service) CloseIO(ctx context.Context, r *api.CloseIORequest) (*ptypes.Empty, error) { 117 return s.local.CloseIO(ctx, r) 118 } 119 120 func (s *service) Checkpoint(ctx context.Context, r *api.CheckpointTaskRequest) (*api.CheckpointTaskResponse, error) { 121 return s.local.Checkpoint(ctx, r) 122 } 123 124 func (s *service) Update(ctx context.Context, r *api.UpdateTaskRequest) (*ptypes.Empty, error) { 125 return s.local.Update(ctx, r) 126 } 127 128 func (s *service) Metrics(ctx context.Context, r *api.MetricsRequest) (*api.MetricsResponse, error) { 129 return s.local.Metrics(ctx, r) 130 } 131 132 func (s *service) Wait(ctx context.Context, r *api.WaitRequest) (*api.WaitResponse, error) { 133 return s.local.Wait(ctx, r) 134 }