@@ -11,9 +11,9 @@ import (
11
11
log "github.com/sirupsen/logrus"
12
12
)
13
13
14
- // ControlContainer control containers status
15
- func (c * Calcium ) ControlContainer (ctx context.Context , IDs []string , t string , force bool ) (chan * types.ControlContainerMessage , error ) {
16
- ch := make (chan * types.ControlContainerMessage )
14
+ // ControlWorkload control workloads status
15
+ func (c * Calcium ) ControlWorkload (ctx context.Context , IDs []string , t string , force bool ) (chan * types.ControlWorkloadMessage , error ) {
16
+ ch := make (chan * types.ControlWorkloadMessage )
17
17
18
18
go func () {
19
19
defer close (ch )
@@ -23,35 +23,35 @@ func (c *Calcium) ControlContainer(ctx context.Context, IDs []string, t string,
23
23
go func (ID string ) {
24
24
defer wg .Done ()
25
25
var message []* bytes.Buffer
26
- err := c .withContainerLocked (ctx , ID , func (container * types.Container ) error {
26
+ err := c .withWorkloadLocked (ctx , ID , func (workload * types.Workload ) error {
27
27
var err error
28
28
switch t {
29
- case cluster .ContainerStop :
30
- message , err = c .doStopContainer (ctx , container , force )
29
+ case cluster .WorkloadStop :
30
+ message , err = c .doStopWorkload (ctx , workload , force )
31
31
return err
32
- case cluster .ContainerStart :
33
- message , err = c .doStartContainer (ctx , container , force )
32
+ case cluster .WorkloadStart :
33
+ message , err = c .doStartWorkload (ctx , workload , force )
34
34
return err
35
- case cluster .ContainerRestart :
36
- message , err = c .doStopContainer (ctx , container , force )
35
+ case cluster .WorkloadRestart :
36
+ message , err = c .doStopWorkload (ctx , workload , force )
37
37
if err != nil {
38
38
return err
39
39
}
40
- startHook , err := c .doStartContainer (ctx , container , force )
40
+ startHook , err := c .doStartWorkload (ctx , workload , force )
41
41
message = append (message , startHook ... )
42
42
return err
43
43
}
44
44
return types .ErrUnknownControlType
45
45
})
46
46
if err == nil {
47
- log .Infof ("[ControlContainer] Container %s %s" , ID , t )
48
- log .Info ("[ControlContainer ] Hook Output:" )
47
+ log .Infof ("[ControlWorkload] Workload %s %s" , ID , t )
48
+ log .Info ("[ControlWorkload ] Hook Output:" )
49
49
log .Info (string (utils .MergeHookOutputs (message )))
50
50
}
51
- ch <- & types.ControlContainerMessage {
52
- ContainerID : ID ,
53
- Error : err ,
54
- Hook : message ,
51
+ ch <- & types.ControlWorkloadMessage {
52
+ WorkloadID : ID ,
53
+ Error : err ,
54
+ Hook : message ,
55
55
}
56
56
}(ID )
57
57
}
@@ -61,31 +61,31 @@ func (c *Calcium) ControlContainer(ctx context.Context, IDs []string, t string,
61
61
return ch , nil
62
62
}
63
63
64
- func (c * Calcium ) doStartContainer (ctx context.Context , container * types.Container , force bool ) (message []* bytes.Buffer , err error ) {
65
- if err = container .Start (ctx ); err != nil {
64
+ func (c * Calcium ) doStartWorkload (ctx context.Context , workload * types.Workload , force bool ) (message []* bytes.Buffer , err error ) {
65
+ if err = workload .Start (ctx ); err != nil {
66
66
return message , err
67
67
}
68
68
// TODO healthcheck first
69
- if container .Hook != nil && len (container .Hook .AfterStart ) > 0 {
69
+ if workload .Hook != nil && len (workload .Hook .AfterStart ) > 0 {
70
70
message , err = c .doHook (
71
71
ctx ,
72
- container .ID , container .User ,
73
- container .Hook .AfterStart , container .Env ,
74
- container .Hook .Force , container .Privileged ,
75
- force , container .Engine ,
72
+ workload .ID , workload .User ,
73
+ workload .Hook .AfterStart , workload .Env ,
74
+ workload .Hook .Force , workload .Privileged ,
75
+ force , workload .Engine ,
76
76
)
77
77
}
78
78
return message , err
79
79
}
80
80
81
- func (c * Calcium ) doStopContainer (ctx context.Context , container * types.Container , force bool ) (message []* bytes.Buffer , err error ) {
82
- if container .Hook != nil && len (container .Hook .BeforeStop ) > 0 {
81
+ func (c * Calcium ) doStopWorkload (ctx context.Context , workload * types.Workload , force bool ) (message []* bytes.Buffer , err error ) {
82
+ if workload .Hook != nil && len (workload .Hook .BeforeStop ) > 0 {
83
83
message , err = c .doHook (
84
84
ctx ,
85
- container .ID , container .User ,
86
- container .Hook .BeforeStop , container .Env ,
87
- container .Hook .Force , container .Privileged ,
88
- force , container .Engine ,
85
+ workload .ID , workload .User ,
86
+ workload .Hook .BeforeStop , workload .Env ,
87
+ workload .Hook .Force , workload .Privileged ,
88
+ force , workload .Engine ,
89
89
)
90
90
if err != nil {
91
91
return message , err
@@ -95,7 +95,7 @@ func (c *Calcium) doStopContainer(ctx context.Context, container *types.Containe
95
95
// 这里 block 的问题很严重,按照目前的配置是 5 分钟一级的 block
96
96
// 一个简单的处理方法是相信 ctx 不相信 engine 自身的处理
97
97
// 另外我怀疑 engine 自己的 timeout 实现是完全的等 timeout 而非结束了就退出
98
- if err = container .Stop (ctx ); err != nil {
98
+ if err = workload .Stop (ctx ); err != nil {
99
99
message = append (message , bytes .NewBufferString (err .Error ()))
100
100
}
101
101
return message , err
0 commit comments