4 "github.com/docker/swarmkit/api"
5 "github.com/docker/swarmkit/manager/state/store"
8 // Slot is a list of the running tasks occupying a certain slot. Generally this
9 // will only be one task, but some rolling update situations involve
10 // temporarily having two running tasks in the same slot. Note that this use of
11 // "slot" is more generic than the Slot number for replicated services - a node
12 // is also considered a slot for global services.
15 // GetRunnableAndDeadSlots returns two maps of slots. The first contains slots
16 // that have at least one task with a desired state above NEW and lesser or
17 // equal to RUNNING. The second is for slots that only contain tasks with a
18 // desired state above RUNNING.
19 func GetRunnableAndDeadSlots(s *store.MemoryStore, serviceID string) (map[uint64]Slot, map[uint64]Slot, error) {
24 s.View(func(tx store.ReadTx) {
25 tasks, err = store.FindTasks(tx, store.ByServiceID(serviceID))
31 runningSlots := make(map[uint64]Slot)
32 for _, t := range tasks {
33 if t.DesiredState <= api.TaskStateRunning {
34 runningSlots[t.Slot] = append(runningSlots[t.Slot], t)
38 deadSlots := make(map[uint64]Slot)
39 for _, t := range tasks {
40 if _, exists := runningSlots[t.Slot]; !exists {
41 deadSlots[t.Slot] = append(deadSlots[t.Slot], t)
45 return runningSlots, deadSlots, nil