@@ -121,7 +121,7 @@ var containersCache = struct {
121
121
func (h * HatcherySwarm ) getContainers () ([]docker.APIContainers , error ) {
122
122
t := time .Now ()
123
123
124
- defer log .Debug ("getContainers() : %d s" , time .Since (t ).Seconds ())
124
+ defer log .Debug ("getContainers() : %f s" , time .Since (t ).Seconds ())
125
125
126
126
containersCache .mu .RLock ()
127
127
nbServers := len (containersCache .list )
@@ -137,6 +137,11 @@ func (h *HatcherySwarm) getContainers() ([]docker.APIContainers, error) {
137
137
containersCache .mu .Lock ()
138
138
containersCache .list = s
139
139
containersCache .mu .Unlock ()
140
+
141
+ log .Debug ("getContainers> %d containers on this host" , len (s ))
142
+ for _ , v := range s {
143
+ log .Debug ("getContainers> container ID:%s names:%+v image:%s created:%d state:%s, status:%s" , v .ID , v .Names , v .Image , v .Created , v .State , v .Status )
144
+ }
140
145
//Remove data from the cache after 2 seconds
141
146
go func () {
142
147
time .Sleep (2 * time .Second )
@@ -193,18 +198,19 @@ func (h *HatcherySwarm) killAndRemove(ID string) {
193
198
return
194
199
}
195
200
196
- network , err := h .dockerClient .NetworkInfo (container .NetworkSettings .NetworkID )
197
- if err != nil {
198
- log .Info ("killAndRemove> cannot NetworkInfo: %v" , err )
199
- h .killAndRemoveContainer (ID )
200
- return
201
- }
202
-
203
- // If we succeed to get the network, kill and remove all the container on the network
204
- if netname , ok := network .Labels ["worker_net" ]; ok {
205
- log .Info ("killAndRemove> Remove network %s" , netname )
206
- for id := range network .Containers {
207
- h .killAndRemoveContainer (id )
201
+ for _ , cnetwork := range container .NetworkSettings .Networks {
202
+ network , err := h .dockerClient .NetworkInfo (cnetwork .NetworkID )
203
+ if err != nil {
204
+ log .Info ("killAndRemove> cannot NetworkInfo: %v" , err )
205
+ h .killAndRemoveContainer (ID )
206
+ return
207
+ }
208
+ // If we succeed to get the network, kill and remove all the container on the network
209
+ if netname , ok := network .Labels ["worker_net" ]; ok {
210
+ log .Info ("killAndRemove> Remove network %s" , netname )
211
+ for id := range network .Containers {
212
+ h .killAndRemoveContainer (id )
213
+ }
208
214
}
209
215
}
210
216
}
@@ -421,14 +427,20 @@ func (h *HatcherySwarm) CanSpawn(model *sdk.Model, jobID int64, requirements []s
421
427
}
422
428
}
423
429
424
- // hatcherySwarm.ratioService: Percent reserved for spwaning worker with service requirement
430
+ // hatcherySwarm.ratioService: Percent reserved for spawning worker with service requirement
425
431
// if no link -> we need to check ratioService
426
- if len (links ) == 0 && len (cs ) > 0 {
427
- percentFree := 100 - (100 * len (cs ) / h .Config .MaxContainers )
428
- if percentFree <= h .Config .RatioService {
429
- log .Info ("CanSpawn> ratio reached. percentFree:%d ratioService:%d" , percentFree , h .Config .RatioService )
432
+ if len (links ) == 0 {
433
+ if h .Config .RatioService >= 100 {
434
+ log .Debug ("CanSpawn> ratioService 100 by conf - no spawn worker without CDS Service" )
430
435
return false
431
436
}
437
+ if len (cs ) > 0 {
438
+ percentFree := 100 - (100 * len (cs ) / h .Config .MaxContainers )
439
+ if percentFree <= h .Config .RatioService {
440
+ log .Debug ("CanSpawn> ratio reached. percentFree:%d ratioService:%d" , percentFree , h .Config .RatioService )
441
+ return false
442
+ }
443
+ }
432
444
}
433
445
434
446
log .Debug ("CanSpawn> %s need %v" , model .Name , links )
0 commit comments