@@ -23,8 +23,8 @@ type virbranium struct {
23
23
24
24
// ListPods returns a list of pods
25
25
func (v * virbranium ) ListPods (ctx context.Context , empty * pb.Empty ) (* pb.Pods , error ) {
26
- v .taskAdd ("ListPods" )
27
- defer v .taskDone ("ListPods" )
26
+ v .taskAdd ("ListPods" , false )
27
+ defer v .taskDone ("ListPods" , false )
28
28
29
29
ps , err := v .cluster .ListPods ()
30
30
if err != nil {
@@ -42,8 +42,8 @@ func (v *virbranium) ListPods(ctx context.Context, empty *pb.Empty) (*pb.Pods, e
42
42
43
43
// AddPod saves a pod, and returns it to client
44
44
func (v * virbranium ) AddPod (ctx context.Context , opts * pb.AddPodOptions ) (* pb.Pod , error ) {
45
- v .taskAdd ("AddPod" )
46
- defer v .taskDone ("AddPod" )
45
+ v .taskAdd ("AddPod" , false )
46
+ defer v .taskDone ("AddPod" , false )
47
47
48
48
p , err := v .cluster .AddPod (opts .Name , opts .Desc )
49
49
if err != nil {
@@ -55,8 +55,8 @@ func (v *virbranium) AddPod(ctx context.Context, opts *pb.AddPodOptions) (*pb.Po
55
55
56
56
// GetPod
57
57
func (v * virbranium ) GetPod (ctx context.Context , opts * pb.GetPodOptions ) (* pb.Pod , error ) {
58
- v .taskAdd ("GetPod" )
59
- defer v .taskDone ("GetPod" )
58
+ v .taskAdd ("GetPod" , false )
59
+ defer v .taskDone ("GetPod" , false )
60
60
61
61
p , err := v .cluster .GetPod (opts .Name )
62
62
if err != nil {
@@ -69,8 +69,8 @@ func (v *virbranium) GetPod(ctx context.Context, opts *pb.GetPodOptions) (*pb.Po
69
69
// AddNode saves a node and returns it to client
70
70
// Method must be called synchronously, or nothing will be returned
71
71
func (v * virbranium ) AddNode (ctx context.Context , opts * pb.AddNodeOptions ) (* pb.Node , error ) {
72
- v .taskAdd ("AddNode" )
73
- defer v .taskDone ("AddNode" )
72
+ v .taskAdd ("AddNode" , false )
73
+ defer v .taskDone ("AddNode" , false )
74
74
75
75
n , err := v .cluster .AddNode (opts .Nodename , opts .Endpoint , opts .Podname , opts .Cafile , opts .Certfile , opts .Keyfile , opts .Public )
76
76
if err != nil {
@@ -83,8 +83,8 @@ func (v *virbranium) AddNode(ctx context.Context, opts *pb.AddNodeOptions) (*pb.
83
83
// AddNode saves a node and returns it to client
84
84
// Method must be called synchronously, or nothing will be returned
85
85
func (v * virbranium ) RemoveNode (ctx context.Context , opts * pb.RemoveNodeOptions ) (* pb.Pod , error ) {
86
- v .taskAdd ("RemoveNode" )
87
- defer v .taskDone ("RemoveNode" )
86
+ v .taskAdd ("RemoveNode" , false )
87
+ defer v .taskDone ("RemoveNode" , false )
88
88
89
89
p , err := v .cluster .RemoveNode (opts .Nodename , opts .Podname )
90
90
if err != nil {
@@ -96,8 +96,8 @@ func (v *virbranium) RemoveNode(ctx context.Context, opts *pb.RemoveNodeOptions)
96
96
97
97
// GetNode
98
98
func (v * virbranium ) GetNode (ctx context.Context , opts * pb.GetNodeOptions ) (* pb.Node , error ) {
99
- v .taskAdd ("GetNode" )
100
- defer v .taskDone ("GetNode" )
99
+ v .taskAdd ("GetNode" , false )
100
+ defer v .taskDone ("GetNode" , false )
101
101
102
102
n , err := v .cluster .GetNode (opts .Podname , opts .Nodename )
103
103
if err != nil {
@@ -109,8 +109,8 @@ func (v *virbranium) GetNode(ctx context.Context, opts *pb.GetNodeOptions) (*pb.
109
109
110
110
// ListPodNodes returns a list of node for pod
111
111
func (v * virbranium ) ListPodNodes (ctx context.Context , opts * pb.ListNodesOptions ) (* pb.Nodes , error ) {
112
- v .taskAdd ("ListPodNodes" )
113
- defer v .taskDone ("ListPodNodes" )
112
+ v .taskAdd ("ListPodNodes" , false )
113
+ defer v .taskDone ("ListPodNodes" , false )
114
114
115
115
ns , err := v .cluster .ListPodNodes (opts .Podname , opts .All )
116
116
if err != nil {
@@ -127,8 +127,8 @@ func (v *virbranium) ListPodNodes(ctx context.Context, opts *pb.ListNodesOptions
127
127
// GetContainer
128
128
// More information will be shown
129
129
func (v * virbranium ) GetContainer (ctx context.Context , id * pb.ContainerID ) (* pb.Container , error ) {
130
- v .taskAdd ("GetContainer" )
131
- defer v .taskDone ("GetContainer" )
130
+ v .taskAdd ("GetContainer" , false )
131
+ defer v .taskDone ("GetContainer" , false )
132
132
133
133
container , err := v .cluster .GetContainer (id .Id )
134
134
if err != nil {
@@ -151,8 +151,8 @@ func (v *virbranium) GetContainer(ctx context.Context, id *pb.ContainerID) (*pb.
151
151
// GetContainers
152
152
// like GetContainer, information should be returned
153
153
func (v * virbranium ) GetContainers (ctx context.Context , cids * pb.ContainerIDs ) (* pb.Containers , error ) {
154
- v .taskAdd ("GetContainers" )
155
- defer v .taskDone ("GetContainers" )
154
+ v .taskAdd ("GetContainers" , false )
155
+ defer v .taskDone ("GetContainers" , false )
156
156
157
157
ids := []string {}
158
158
for _ , id := range cids .Ids {
@@ -183,8 +183,8 @@ func (v *virbranium) GetContainers(ctx context.Context, cids *pb.ContainerIDs) (
183
183
184
184
// list networks for pod
185
185
func (v * virbranium ) ListNetworks (ctx context.Context , opts * pb.GetPodOptions ) (* pb.Networks , error ) {
186
- v .taskAdd ("ListNetworks" )
187
- defer v .taskDone ("ListNetworks" )
186
+ v .taskAdd ("ListNetworks" , false )
187
+ defer v .taskDone ("ListNetworks" , false )
188
188
189
189
networks , err := v .cluster .ListNetworks (opts .Name )
190
190
if err != nil {
@@ -200,8 +200,8 @@ func (v *virbranium) ListNetworks(ctx context.Context, opts *pb.GetPodOptions) (
200
200
201
201
// set node availability
202
202
func (v * virbranium ) SetNodeAvailable (ctx context.Context , opts * pb.NodeAvailable ) (* pb.Node , error ) {
203
- v .taskAdd ("SetNodeAvailable" )
204
- defer v .taskDone ("SetNodeAvailable" )
203
+ v .taskAdd ("SetNodeAvailable" , false )
204
+ defer v .taskDone ("SetNodeAvailable" , false )
205
205
206
206
n , err := v .cluster .SetNodeAvailable (opts .Podname , opts .Nodename , opts .Available )
207
207
if err != nil {
@@ -213,7 +213,7 @@ func (v *virbranium) SetNodeAvailable(ctx context.Context, opts *pb.NodeAvailabl
213
213
// streamed returned functions
214
214
// caller must ensure that timeout will not be too short because these actions take a little time
215
215
func (v * virbranium ) BuildImage (opts * pb.BuildImageOptions , stream pb.CoreRPC_BuildImageServer ) error {
216
- v .taskAdd ("BuildImage" )
216
+ v .taskAdd ("BuildImage" , true )
217
217
218
218
ch , err := v .cluster .BuildImage (opts .Repo , opts .Version , opts .Uid , opts .Artifact )
219
219
if err != nil {
@@ -227,7 +227,7 @@ func (v *virbranium) BuildImage(opts *pb.BuildImageOptions, stream pb.CoreRPC_Bu
227
227
// 如果send出错, 需要这里读完channel, 那么其实是走了另外一个函数来结束这个调用.
228
228
// 于是需要这里补一个done.
229
229
// 下面都一样
230
- defer v .taskDone ("BuildImage" )
230
+ defer v .taskDone ("BuildImage" , true )
231
231
for r := range ch {
232
232
log .Infof ("[BuildImage] Unsent streamed message: %v" , r )
233
233
}
@@ -237,12 +237,12 @@ func (v *virbranium) BuildImage(opts *pb.BuildImageOptions, stream pb.CoreRPC_Bu
237
237
}
238
238
// 如果send没有出错, 那么说明可以完整读完这个channel
239
239
// 正常done就可以了, 这里不能defer, 不然会两次done.
240
- v .taskDone ("BuildImage" )
240
+ v .taskDone ("BuildImage" , true )
241
241
return nil
242
242
}
243
243
244
244
func (v * virbranium ) CreateContainer (opts * pb.DeployOptions , stream pb.CoreRPC_CreateContainerServer ) error {
245
- v .taskAdd ("CreateContainer" )
245
+ v .taskAdd ("CreateContainer" , true )
246
246
247
247
specs , err := types .LoadSpecs (opts .Specs )
248
248
if err != nil {
@@ -257,7 +257,7 @@ func (v *virbranium) CreateContainer(opts *pb.DeployOptions, stream pb.CoreRPC_C
257
257
for m := range ch {
258
258
if err := stream .Send (toRPCCreateContainerMessage (m )); err != nil {
259
259
go func () {
260
- defer v .taskDone ("CreateContainer" )
260
+ defer v .taskDone ("CreateContainer" , true )
261
261
for r := range ch {
262
262
log .Infof ("[CreateContainer] Unsent streamed message: %v" , r )
263
263
}
@@ -266,12 +266,12 @@ func (v *virbranium) CreateContainer(opts *pb.DeployOptions, stream pb.CoreRPC_C
266
266
}
267
267
}
268
268
269
- v .taskDone ("CreateContainer" )
269
+ v .taskDone ("CreateContainer" , true )
270
270
return nil
271
271
}
272
272
273
273
func (v * virbranium ) RunAndWait (opts * pb.DeployOptions , stream pb.CoreRPC_RunAndWaitServer ) error {
274
- v .taskAdd ("RunAndWait" )
274
+ v .taskAdd ("RunAndWait" , true )
275
275
276
276
specs , err := types .LoadSpecs (opts .Specs )
277
277
if err != nil {
@@ -286,7 +286,7 @@ func (v *virbranium) RunAndWait(opts *pb.DeployOptions, stream pb.CoreRPC_RunAnd
286
286
for m := range ch {
287
287
if err := stream .Send (toRPCRunAndWaitMessage (m )); err != nil {
288
288
go func () {
289
- defer v .taskDone ("RunAndWait" )
289
+ defer v .taskDone ("RunAndWait" , true )
290
290
for r := range ch {
291
291
log .Infof ("[RunAndWait] Unsent streamed message: %v" , r .Data )
292
292
}
@@ -295,12 +295,12 @@ func (v *virbranium) RunAndWait(opts *pb.DeployOptions, stream pb.CoreRPC_RunAnd
295
295
}
296
296
}
297
297
298
- v .taskDone ("RunAndWait" )
298
+ v .taskDone ("RunAndWait" , true )
299
299
return nil
300
300
}
301
301
302
302
func (v * virbranium ) UpgradeContainer (opts * pb.UpgradeOptions , stream pb.CoreRPC_UpgradeContainerServer ) error {
303
- v .taskAdd ("UpgradeContainer" )
303
+ v .taskAdd ("UpgradeContainer" , true )
304
304
305
305
ids := []string {}
306
306
for _ , id := range opts .Ids {
@@ -315,7 +315,7 @@ func (v *virbranium) UpgradeContainer(opts *pb.UpgradeOptions, stream pb.CoreRPC
315
315
for m := range ch {
316
316
if err := stream .Send (toRPCUpgradeContainerMessage (m )); err != nil {
317
317
go func () {
318
- defer v .taskDone ("UpgradeContainer" )
318
+ defer v .taskDone ("UpgradeContainer" , true )
319
319
for r := range ch {
320
320
log .Infof ("[UpgradeContainer] Unsent streamed message: %v" , r )
321
321
}
@@ -324,12 +324,12 @@ func (v *virbranium) UpgradeContainer(opts *pb.UpgradeOptions, stream pb.CoreRPC
324
324
}
325
325
}
326
326
327
- v .taskDone ("UpgradeContainer" )
327
+ v .taskDone ("UpgradeContainer" , true )
328
328
return nil
329
329
}
330
330
331
331
func (v * virbranium ) RemoveContainer (cids * pb.ContainerIDs , stream pb.CoreRPC_RemoveContainerServer ) error {
332
- v .taskAdd ("RemoveContainer" )
332
+ v .taskAdd ("RemoveContainer" , true )
333
333
334
334
ids := []string {}
335
335
for _ , id := range cids .Ids {
@@ -348,7 +348,7 @@ func (v *virbranium) RemoveContainer(cids *pb.ContainerIDs, stream pb.CoreRPC_Re
348
348
for m := range ch {
349
349
if err := stream .Send (toRPCRemoveContainerMessage (m )); err != nil {
350
350
go func () {
351
- defer v .taskDone ("RemoveContainer" )
351
+ defer v .taskDone ("RemoveContainer" , true )
352
352
for r := range ch {
353
353
log .Infof ("[RemoveContainer] Unsent streamed message: %v" , r )
354
354
}
@@ -357,12 +357,12 @@ func (v *virbranium) RemoveContainer(cids *pb.ContainerIDs, stream pb.CoreRPC_Re
357
357
}
358
358
}
359
359
360
- v .taskDone ("RemoveContainer" )
360
+ v .taskDone ("RemoveContainer" , true )
361
361
return nil
362
362
}
363
363
364
364
func (v * virbranium ) RemoveImage (opts * pb.RemoveImageOptions , stream pb.CoreRPC_RemoveImageServer ) error {
365
- v .taskAdd ("RemoveImage" )
365
+ v .taskAdd ("RemoveImage" , true )
366
366
367
367
ch , err := v .cluster .RemoveImage (opts .Podname , opts .Nodename , opts .Images )
368
368
if err != nil {
@@ -372,7 +372,7 @@ func (v *virbranium) RemoveImage(opts *pb.RemoveImageOptions, stream pb.CoreRPC_
372
372
for m := range ch {
373
373
if err := stream .Send (toRPCRemoveImageMessage (m )); err != nil {
374
374
go func () {
375
- defer v .taskDone ("RemoveImage" )
375
+ defer v .taskDone ("RemoveImage" , true )
376
376
for r := range ch {
377
377
log .Infof ("[RemoveImage] Unsent streamed message: %v" , r )
378
378
}
@@ -381,13 +381,13 @@ func (v *virbranium) RemoveImage(opts *pb.RemoveImageOptions, stream pb.CoreRPC_
381
381
}
382
382
}
383
383
384
- v .taskDone ("RemoveImage" )
384
+ v .taskDone ("RemoveImage" , true )
385
385
return nil
386
386
}
387
387
388
388
func (v * virbranium ) Backup (ctx context.Context , opts * pb.BackupOptions ) (* pb.BackupMessage , error ) {
389
- v .taskAdd ("Backup" )
390
- defer v .taskDone ("Backup" )
389
+ v .taskAdd ("Backup" , false )
390
+ defer v .taskDone ("Backup" , false )
391
391
392
392
backupMessage , err := v .cluster .Backup (opts .Id , opts .SrcPath )
393
393
if err != nil {
0 commit comments