Skip to content

Commit c49c9c7

Browse files
committed
[skip ci] 不涉及资源分配的 rpc 接口就不要等待完成了
1 parent 619c202 commit c49c9c7

File tree

1 file changed

+0
-48
lines changed

1 file changed

+0
-48
lines changed

rpc/rpc.go

-48
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ type virbranium struct {
2323

2424
// ListPods returns a list of pods
2525
func (v *virbranium) ListPods(ctx context.Context, empty *pb.Empty) (*pb.Pods, error) {
26-
v.taskAdd("ListPods", false)
27-
defer v.taskDone("ListPods", false)
28-
2926
ps, err := v.cluster.ListPods()
3027
if err != nil {
3128
return nil, err
@@ -42,9 +39,6 @@ func (v *virbranium) ListPods(ctx context.Context, empty *pb.Empty) (*pb.Pods, e
4239

4340
// AddPod saves a pod, and returns it to client
4441
func (v *virbranium) AddPod(ctx context.Context, opts *pb.AddPodOptions) (*pb.Pod, error) {
45-
v.taskAdd("AddPod", false)
46-
defer v.taskDone("AddPod", false)
47-
4842
p, err := v.cluster.AddPod(opts.Name, opts.Desc)
4943
if err != nil {
5044
return nil, err
@@ -55,9 +49,6 @@ func (v *virbranium) AddPod(ctx context.Context, opts *pb.AddPodOptions) (*pb.Po
5549

5650
// GetPod
5751
func (v *virbranium) GetPod(ctx context.Context, opts *pb.GetPodOptions) (*pb.Pod, error) {
58-
v.taskAdd("GetPod", false)
59-
defer v.taskDone("GetPod", false)
60-
6152
p, err := v.cluster.GetPod(opts.Name)
6253
if err != nil {
6354
return nil, err
@@ -69,9 +60,6 @@ func (v *virbranium) GetPod(ctx context.Context, opts *pb.GetPodOptions) (*pb.Po
6960
// AddNode saves a node and returns it to client
7061
// Method must be called synchronously, or nothing will be returned
7162
func (v *virbranium) AddNode(ctx context.Context, opts *pb.AddNodeOptions) (*pb.Node, error) {
72-
v.taskAdd("AddNode", false)
73-
defer v.taskDone("AddNode", false)
74-
7563
n, err := v.cluster.AddNode(opts.Nodename, opts.Endpoint, opts.Podname, opts.Cafile, opts.Certfile, opts.Keyfile, opts.Public)
7664
if err != nil {
7765
return nil, err
@@ -83,9 +71,6 @@ func (v *virbranium) AddNode(ctx context.Context, opts *pb.AddNodeOptions) (*pb.
8371
// AddNode saves a node and returns it to client
8472
// Method must be called synchronously, or nothing will be returned
8573
func (v *virbranium) RemoveNode(ctx context.Context, opts *pb.RemoveNodeOptions) (*pb.Pod, error) {
86-
v.taskAdd("RemoveNode", false)
87-
defer v.taskDone("RemoveNode", false)
88-
8974
p, err := v.cluster.RemoveNode(opts.Nodename, opts.Podname)
9075
if err != nil {
9176
return nil, err
@@ -96,9 +81,6 @@ func (v *virbranium) RemoveNode(ctx context.Context, opts *pb.RemoveNodeOptions)
9681

9782
// GetNode
9883
func (v *virbranium) GetNode(ctx context.Context, opts *pb.GetNodeOptions) (*pb.Node, error) {
99-
v.taskAdd("GetNode", false)
100-
defer v.taskDone("GetNode", false)
101-
10284
n, err := v.cluster.GetNode(opts.Podname, opts.Nodename)
10385
if err != nil {
10486
return nil, err
@@ -109,9 +91,6 @@ func (v *virbranium) GetNode(ctx context.Context, opts *pb.GetNodeOptions) (*pb.
10991

11092
// ListPodNodes returns a list of node for pod
11193
func (v *virbranium) ListPodNodes(ctx context.Context, opts *pb.ListNodesOptions) (*pb.Nodes, error) {
112-
v.taskAdd("ListPodNodes", false)
113-
defer v.taskDone("ListPodNodes", false)
114-
11594
ns, err := v.cluster.ListPodNodes(opts.Podname, opts.All)
11695
if err != nil {
11796
return nil, err
@@ -127,9 +106,6 @@ func (v *virbranium) ListPodNodes(ctx context.Context, opts *pb.ListNodesOptions
127106
// GetContainer
128107
// More information will be shown
129108
func (v *virbranium) GetContainer(ctx context.Context, id *pb.ContainerID) (*pb.Container, error) {
130-
v.taskAdd("GetContainer", false)
131-
defer v.taskDone("GetContainer", false)
132-
133109
container, err := v.cluster.GetContainer(id.Id)
134110
if err != nil {
135111
return nil, err
@@ -151,9 +127,6 @@ func (v *virbranium) GetContainer(ctx context.Context, id *pb.ContainerID) (*pb.
151127
// GetContainers
152128
// like GetContainer, information should be returned
153129
func (v *virbranium) GetContainers(ctx context.Context, cids *pb.ContainerIDs) (*pb.Containers, error) {
154-
v.taskAdd("GetContainers", false)
155-
defer v.taskDone("GetContainers", false)
156-
157130
ids := []string{}
158131
for _, id := range cids.Ids {
159132
ids = append(ids, id.Id)
@@ -183,9 +156,6 @@ func (v *virbranium) GetContainers(ctx context.Context, cids *pb.ContainerIDs) (
183156

184157
// list networks for pod
185158
func (v *virbranium) ListNetworks(ctx context.Context, opts *pb.GetPodOptions) (*pb.Networks, error) {
186-
v.taskAdd("ListNetworks", false)
187-
defer v.taskDone("ListNetworks", false)
188-
189159
networks, err := v.cluster.ListNetworks(opts.Name)
190160
if err != nil {
191161
return nil, err
@@ -200,9 +170,6 @@ func (v *virbranium) ListNetworks(ctx context.Context, opts *pb.GetPodOptions) (
200170

201171
// set node availability
202172
func (v *virbranium) SetNodeAvailable(ctx context.Context, opts *pb.NodeAvailable) (*pb.Node, error) {
203-
v.taskAdd("SetNodeAvailable", false)
204-
defer v.taskDone("SetNodeAvailable", false)
205-
206173
n, err := v.cluster.SetNodeAvailable(opts.Podname, opts.Nodename, opts.Available)
207174
if err != nil {
208175
return nil, err
@@ -213,8 +180,6 @@ func (v *virbranium) SetNodeAvailable(ctx context.Context, opts *pb.NodeAvailabl
213180
// streamed returned functions
214181
// caller must ensure that timeout will not be too short because these actions take a little time
215182
func (v *virbranium) BuildImage(opts *pb.BuildImageOptions, stream pb.CoreRPC_BuildImageServer) error {
216-
v.taskAdd("BuildImage", true)
217-
218183
ch, err := v.cluster.BuildImage(opts.Repo, opts.Version, opts.Uid, opts.Artifact)
219184
if err != nil {
220185
return err
@@ -223,21 +188,13 @@ func (v *virbranium) BuildImage(opts *pb.BuildImageOptions, stream pb.CoreRPC_Bu
223188
for m := range ch {
224189
if err := stream.Send(toRPCBuildImageMessage(m)); err != nil {
225190
go func() {
226-
// stream的返回这里也需要一个done.
227-
// 如果send出错, 需要这里读完channel, 那么其实是走了另外一个函数来结束这个调用.
228-
// 于是需要这里补一个done.
229-
// 下面都一样
230-
defer v.taskDone("BuildImage", true)
231191
for r := range ch {
232192
log.Infof("[BuildImage] Unsent streamed message: %v", r)
233193
}
234194
}()
235195
return err
236196
}
237197
}
238-
// 如果send没有出错, 那么说明可以完整读完这个channel
239-
// 正常done就可以了, 这里不能defer, 不然会两次done.
240-
v.taskDone("BuildImage", true)
241198
return nil
242199
}
243200

@@ -362,8 +319,6 @@ func (v *virbranium) RemoveContainer(cids *pb.ContainerIDs, stream pb.CoreRPC_Re
362319
}
363320

364321
func (v *virbranium) RemoveImage(opts *pb.RemoveImageOptions, stream pb.CoreRPC_RemoveImageServer) error {
365-
v.taskAdd("RemoveImage", true)
366-
367322
ch, err := v.cluster.RemoveImage(opts.Podname, opts.Nodename, opts.Images)
368323
if err != nil {
369324
return err
@@ -372,16 +327,13 @@ func (v *virbranium) RemoveImage(opts *pb.RemoveImageOptions, stream pb.CoreRPC_
372327
for m := range ch {
373328
if err := stream.Send(toRPCRemoveImageMessage(m)); err != nil {
374329
go func() {
375-
defer v.taskDone("RemoveImage", true)
376330
for r := range ch {
377331
log.Infof("[RemoveImage] Unsent streamed message: %v", r)
378332
}
379333
}()
380334
return err
381335
}
382336
}
383-
384-
v.taskDone("RemoveImage", true)
385337
return nil
386338
}
387339

0 commit comments

Comments
 (0)