(_ swarm.Service, tasks []swarm.Task, activeNodes map[string]struct{}, rollback bool)
| 414 | } |
| 415 | |
| 416 | func (u *globalProgressUpdater) update(_ swarm.Service, tasks []swarm.Task, activeNodes map[string]struct{}, rollback bool) (bool, error) { |
| 417 | tasksByNode := u.tasksByNode(tasks) |
| 418 | |
| 419 | // We don't have perfect knowledge of how many nodes meet the |
| 420 | // constraints for this service. But the orchestrator creates tasks |
| 421 | // for all eligible nodes at the same time, so we should see all those |
| 422 | // nodes represented among the up-to-date tasks. |
| 423 | nodeCount := len(tasksByNode) |
| 424 | |
| 425 | if !u.initialized { |
| 426 | if nodeCount == 0 { |
| 427 | // Two possibilities: either the orchestrator hasn't created |
| 428 | // the tasks yet, or the service doesn't meet constraints for |
| 429 | // any node. Either way, we wait. |
| 430 | u.progressOut.WriteProgress(progress.Progress{ |
| 431 | ID: "overall progress", |
| 432 | Action: "waiting for new tasks", |
| 433 | }) |
| 434 | return false, nil |
| 435 | } |
| 436 | |
| 437 | writeOverallProgress(u.progressOut, 0, nodeCount, rollback) |
| 438 | u.initialized = true |
| 439 | } |
| 440 | |
| 441 | // If we had reached a converged state, check if we are still converged. |
| 442 | if u.done { |
| 443 | for _, task := range tasksByNode { |
| 444 | if task.Status.State != swarm.TaskStateRunning { |
| 445 | u.done = false |
| 446 | break |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | running := 0 |
| 452 | |
| 453 | for _, task := range tasksByNode { |
| 454 | if _, nodeActive := activeNodes[task.NodeID]; nodeActive { |
| 455 | if !terminalState(task.DesiredState) && task.Status.State == swarm.TaskStateRunning { |
| 456 | running++ |
| 457 | } |
| 458 | |
| 459 | u.writeTaskProgress(task, nodeCount) |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | if !u.done { |
| 464 | writeOverallProgress(u.progressOut, running, nodeCount, rollback) |
| 465 | |
| 466 | if running == nodeCount { |
| 467 | u.done = true |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | return running == nodeCount, nil |
| 472 | } |
| 473 |
nothing calls this directly
no test coverage detected