(service swarm.Service, tasks []swarm.Task, activeNodes map[string]struct{}, rollback bool)
| 292 | } |
| 293 | |
| 294 | func (u *replicatedProgressUpdater) update(service swarm.Service, tasks []swarm.Task, activeNodes map[string]struct{}, rollback bool) (bool, error) { |
| 295 | if service.Spec.Mode.Replicated == nil || service.Spec.Mode.Replicated.Replicas == nil { |
| 296 | return false, errors.New("no replica count") |
| 297 | } |
| 298 | replicas := *service.Spec.Mode.Replicated.Replicas |
| 299 | |
| 300 | if !u.initialized { |
| 301 | u.slotMap = make(map[int]int) |
| 302 | |
| 303 | // Draw progress bars in order |
| 304 | writeOverallProgress(u.progressOut, 0, int(replicas), rollback) |
| 305 | |
| 306 | if replicas <= maxProgressBars { |
| 307 | for i := uint64(1); i <= replicas; i++ { |
| 308 | progress.Update(u.progressOut, fmt.Sprintf("%d/%d", i, replicas), " ") |
| 309 | } |
| 310 | } |
| 311 | u.initialized = true |
| 312 | } |
| 313 | |
| 314 | tasksBySlot := u.tasksBySlot(tasks, activeNodes) |
| 315 | |
| 316 | // If we had reached a converged state, check if we are still converged. |
| 317 | if u.done { |
| 318 | for _, task := range tasksBySlot { |
| 319 | if task.Status.State != swarm.TaskStateRunning { |
| 320 | u.done = false |
| 321 | break |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | running := uint64(0) |
| 327 | |
| 328 | for _, task := range tasksBySlot { |
| 329 | mappedSlot := u.slotMap[task.Slot] |
| 330 | if mappedSlot == 0 { |
| 331 | mappedSlot = len(u.slotMap) + 1 |
| 332 | u.slotMap[task.Slot] = mappedSlot |
| 333 | } |
| 334 | |
| 335 | if !terminalState(task.DesiredState) && task.Status.State == swarm.TaskStateRunning { |
| 336 | running++ |
| 337 | } |
| 338 | |
| 339 | u.writeTaskProgress(task, mappedSlot, replicas) |
| 340 | } |
| 341 | |
| 342 | if !u.done { |
| 343 | writeOverallProgress(u.progressOut, int(running), int(replicas), rollback) |
| 344 | |
| 345 | if running == replicas { |
| 346 | u.done = true |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | return running == replicas, nil |
| 351 | } |
nothing calls this directly
no test coverage detected