DockerCLI/cli/command/task/print.go

117 lines
3.4 KiB
Go
Raw Normal View History

package task
import (
"context"
"fmt"
"sort"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/cli/command/idresolver"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/docker/api/types/swarm"
"github.com/fvbommel/sortorder"
)
Improve service tasks grouping on printing When printing services' tasks with `docker service ps` command, tasks are grouped only by task slot. This leads to interleaving tasks from different services when `docker service ps` is called with multiple services. Besides this, global services do not have slots at all and printing tasks for them doesn't group and doesn't properly indent tasks with \_. With this patch all tasks are grouped by service ID, slot and node ID (relevant only for global services) and it fixes issue 533. Before this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 5 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 2 seconds ago kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 5 seconds ago pubrerosvsw5 b.1 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago fu08gfi8tfyv a.1 nginx:alpine docker-desktop Shutdown Shutdown 7 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Ready 1 second ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago xq8dogqcbxd2 a.2 nginx:alpine docker-desktop Running Running 44 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Starting less than a second ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 5 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qn7c7jmjuo76 a.3 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 2 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago ``` After this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 32 seconds ago fu08gfi8tfyv \_ a.1 nginx:alpine docker-desktop Shutdown Shutdown 34 seconds ago 3pam0limnn24 a.2 nginx:alpine docker-desktop Running Running 23 seconds ago xq8dogqcbxd2 \_ a.2 nginx:alpine docker-desktop Shutdown Shutdown 24 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Running 26 seconds ago qn7c7jmjuo76 \_ a.3 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 29 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 29 seconds ago pubrerosvsw5 \_ b.1 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Running 26 seconds ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 32 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 32 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago ``` Signed-off-by: Andrii Berehuliak <berkusandrew@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-22 12:22:23 -04:00
type tasksSortable []swarm.Task
Improve service tasks grouping on printing When printing services' tasks with `docker service ps` command, tasks are grouped only by task slot. This leads to interleaving tasks from different services when `docker service ps` is called with multiple services. Besides this, global services do not have slots at all and printing tasks for them doesn't group and doesn't properly indent tasks with \_. With this patch all tasks are grouped by service ID, slot and node ID (relevant only for global services) and it fixes issue 533. Before this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 5 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 2 seconds ago kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 5 seconds ago pubrerosvsw5 b.1 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago fu08gfi8tfyv a.1 nginx:alpine docker-desktop Shutdown Shutdown 7 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Ready 1 second ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago xq8dogqcbxd2 a.2 nginx:alpine docker-desktop Running Running 44 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Starting less than a second ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 5 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qn7c7jmjuo76 a.3 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 2 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago ``` After this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 32 seconds ago fu08gfi8tfyv \_ a.1 nginx:alpine docker-desktop Shutdown Shutdown 34 seconds ago 3pam0limnn24 a.2 nginx:alpine docker-desktop Running Running 23 seconds ago xq8dogqcbxd2 \_ a.2 nginx:alpine docker-desktop Shutdown Shutdown 24 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Running 26 seconds ago qn7c7jmjuo76 \_ a.3 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 29 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 29 seconds ago pubrerosvsw5 \_ b.1 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Running 26 seconds ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 32 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 32 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago ``` Signed-off-by: Andrii Berehuliak <berkusandrew@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-22 12:22:23 -04:00
func (t tasksSortable) Len() int {
return len(t)
}
Improve service tasks grouping on printing When printing services' tasks with `docker service ps` command, tasks are grouped only by task slot. This leads to interleaving tasks from different services when `docker service ps` is called with multiple services. Besides this, global services do not have slots at all and printing tasks for them doesn't group and doesn't properly indent tasks with \_. With this patch all tasks are grouped by service ID, slot and node ID (relevant only for global services) and it fixes issue 533. Before this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 5 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 2 seconds ago kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 5 seconds ago pubrerosvsw5 b.1 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago fu08gfi8tfyv a.1 nginx:alpine docker-desktop Shutdown Shutdown 7 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Ready 1 second ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago xq8dogqcbxd2 a.2 nginx:alpine docker-desktop Running Running 44 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Starting less than a second ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 5 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qn7c7jmjuo76 a.3 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 2 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago ``` After this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 32 seconds ago fu08gfi8tfyv \_ a.1 nginx:alpine docker-desktop Shutdown Shutdown 34 seconds ago 3pam0limnn24 a.2 nginx:alpine docker-desktop Running Running 23 seconds ago xq8dogqcbxd2 \_ a.2 nginx:alpine docker-desktop Shutdown Shutdown 24 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Running 26 seconds ago qn7c7jmjuo76 \_ a.3 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 29 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 29 seconds ago pubrerosvsw5 \_ b.1 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Running 26 seconds ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 32 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 32 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago ``` Signed-off-by: Andrii Berehuliak <berkusandrew@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-22 12:22:23 -04:00
func (t tasksSortable) Swap(i, j int) {
t[i], t[j] = t[j], t[i]
}
Improve service tasks grouping on printing When printing services' tasks with `docker service ps` command, tasks are grouped only by task slot. This leads to interleaving tasks from different services when `docker service ps` is called with multiple services. Besides this, global services do not have slots at all and printing tasks for them doesn't group and doesn't properly indent tasks with \_. With this patch all tasks are grouped by service ID, slot and node ID (relevant only for global services) and it fixes issue 533. Before this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 5 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 2 seconds ago kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 5 seconds ago pubrerosvsw5 b.1 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago fu08gfi8tfyv a.1 nginx:alpine docker-desktop Shutdown Shutdown 7 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Ready 1 second ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago xq8dogqcbxd2 a.2 nginx:alpine docker-desktop Running Running 44 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Starting less than a second ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 5 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qn7c7jmjuo76 a.3 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 2 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago ``` After this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 32 seconds ago fu08gfi8tfyv \_ a.1 nginx:alpine docker-desktop Shutdown Shutdown 34 seconds ago 3pam0limnn24 a.2 nginx:alpine docker-desktop Running Running 23 seconds ago xq8dogqcbxd2 \_ a.2 nginx:alpine docker-desktop Shutdown Shutdown 24 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Running 26 seconds ago qn7c7jmjuo76 \_ a.3 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 29 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 29 seconds ago pubrerosvsw5 \_ b.1 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Running 26 seconds ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 32 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 32 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago ``` Signed-off-by: Andrii Berehuliak <berkusandrew@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-22 12:22:23 -04:00
func (t tasksSortable) Less(i, j int) bool {
if t[i].Name != t[j].Name {
return sortorder.NaturalLess(t[i].Name, t[j].Name)
}
Improve service tasks grouping on printing When printing services' tasks with `docker service ps` command, tasks are grouped only by task slot. This leads to interleaving tasks from different services when `docker service ps` is called with multiple services. Besides this, global services do not have slots at all and printing tasks for them doesn't group and doesn't properly indent tasks with \_. With this patch all tasks are grouped by service ID, slot and node ID (relevant only for global services) and it fixes issue 533. Before this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 5 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 2 seconds ago kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 5 seconds ago pubrerosvsw5 b.1 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago fu08gfi8tfyv a.1 nginx:alpine docker-desktop Shutdown Shutdown 7 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Ready 1 second ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago xq8dogqcbxd2 a.2 nginx:alpine docker-desktop Running Running 44 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Starting less than a second ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 5 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qn7c7jmjuo76 a.3 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 2 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago ``` After this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 32 seconds ago fu08gfi8tfyv \_ a.1 nginx:alpine docker-desktop Shutdown Shutdown 34 seconds ago 3pam0limnn24 a.2 nginx:alpine docker-desktop Running Running 23 seconds ago xq8dogqcbxd2 \_ a.2 nginx:alpine docker-desktop Shutdown Shutdown 24 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Running 26 seconds ago qn7c7jmjuo76 \_ a.3 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 29 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 29 seconds ago pubrerosvsw5 \_ b.1 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Running 26 seconds ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 32 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 32 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago ``` Signed-off-by: Andrii Berehuliak <berkusandrew@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-22 12:22:23 -04:00
// Sort tasks for the same service and slot by most recent.
return t[j].Meta.CreatedAt.Before(t[i].CreatedAt)
}
// Print task information in a format.
// Besides this, command `docker node ps <node>`
// and `docker stack ps` will call this, too.
func Print(ctx context.Context, dockerCli command.Cli, tasks []swarm.Task, resolver *idresolver.IDResolver, trunc, quiet bool, format string) error {
Improve service tasks grouping on printing When printing services' tasks with `docker service ps` command, tasks are grouped only by task slot. This leads to interleaving tasks from different services when `docker service ps` is called with multiple services. Besides this, global services do not have slots at all and printing tasks for them doesn't group and doesn't properly indent tasks with \_. With this patch all tasks are grouped by service ID, slot and node ID (relevant only for global services) and it fixes issue 533. Before this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 5 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 2 seconds ago kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 5 seconds ago pubrerosvsw5 b.1 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago fu08gfi8tfyv a.1 nginx:alpine docker-desktop Shutdown Shutdown 7 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Ready 1 second ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago xq8dogqcbxd2 a.2 nginx:alpine docker-desktop Running Running 44 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Starting less than a second ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 5 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qn7c7jmjuo76 a.3 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 2 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago ``` After this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 32 seconds ago fu08gfi8tfyv \_ a.1 nginx:alpine docker-desktop Shutdown Shutdown 34 seconds ago 3pam0limnn24 a.2 nginx:alpine docker-desktop Running Running 23 seconds ago xq8dogqcbxd2 \_ a.2 nginx:alpine docker-desktop Shutdown Shutdown 24 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Running 26 seconds ago qn7c7jmjuo76 \_ a.3 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 29 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 29 seconds ago pubrerosvsw5 \_ b.1 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Running 26 seconds ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 32 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 32 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago ``` Signed-off-by: Andrii Berehuliak <berkusandrew@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-22 12:22:23 -04:00
tasks, err := generateTaskNames(ctx, tasks, resolver)
if err != nil {
return err
}
// First sort tasks, so that all tasks (including previous ones) of the same
// service and slot are together. This must be done first, to print "previous"
// tasks indented
sort.Stable(tasksSortable(tasks))
names := map[string]string{}
nodes := map[string]string{}
tasksCtx := formatter.Context{
Output: dockerCli.Out(),
Format: NewTaskFormat(format, quiet),
Trunc: trunc,
}
Improve service tasks grouping on printing When printing services' tasks with `docker service ps` command, tasks are grouped only by task slot. This leads to interleaving tasks from different services when `docker service ps` is called with multiple services. Besides this, global services do not have slots at all and printing tasks for them doesn't group and doesn't properly indent tasks with \_. With this patch all tasks are grouped by service ID, slot and node ID (relevant only for global services) and it fixes issue 533. Before this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 5 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 2 seconds ago kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 5 seconds ago pubrerosvsw5 b.1 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago fu08gfi8tfyv a.1 nginx:alpine docker-desktop Shutdown Shutdown 7 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Ready 1 second ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago xq8dogqcbxd2 a.2 nginx:alpine docker-desktop Running Running 44 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Starting less than a second ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 5 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qn7c7jmjuo76 a.3 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 2 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago ``` After this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 32 seconds ago fu08gfi8tfyv \_ a.1 nginx:alpine docker-desktop Shutdown Shutdown 34 seconds ago 3pam0limnn24 a.2 nginx:alpine docker-desktop Running Running 23 seconds ago xq8dogqcbxd2 \_ a.2 nginx:alpine docker-desktop Shutdown Shutdown 24 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Running 26 seconds ago qn7c7jmjuo76 \_ a.3 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 29 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 29 seconds ago pubrerosvsw5 \_ b.1 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Running 26 seconds ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 32 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 32 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago ``` Signed-off-by: Andrii Berehuliak <berkusandrew@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-22 12:22:23 -04:00
var indent string
if tasksCtx.Format.IsTable() {
indent = ` \_ `
}
prevName := ""
for _, task := range tasks {
Improve service tasks grouping on printing When printing services' tasks with `docker service ps` command, tasks are grouped only by task slot. This leads to interleaving tasks from different services when `docker service ps` is called with multiple services. Besides this, global services do not have slots at all and printing tasks for them doesn't group and doesn't properly indent tasks with \_. With this patch all tasks are grouped by service ID, slot and node ID (relevant only for global services) and it fixes issue 533. Before this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 5 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 2 seconds ago kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 5 seconds ago pubrerosvsw5 b.1 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago fu08gfi8tfyv a.1 nginx:alpine docker-desktop Shutdown Shutdown 7 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Ready 1 second ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago xq8dogqcbxd2 a.2 nginx:alpine docker-desktop Running Running 44 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Starting less than a second ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 5 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qn7c7jmjuo76 a.3 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 2 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago ``` After this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 32 seconds ago fu08gfi8tfyv \_ a.1 nginx:alpine docker-desktop Shutdown Shutdown 34 seconds ago 3pam0limnn24 a.2 nginx:alpine docker-desktop Running Running 23 seconds ago xq8dogqcbxd2 \_ a.2 nginx:alpine docker-desktop Shutdown Shutdown 24 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Running 26 seconds ago qn7c7jmjuo76 \_ a.3 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 29 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 29 seconds ago pubrerosvsw5 \_ b.1 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Running 26 seconds ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 32 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 32 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago ``` Signed-off-by: Andrii Berehuliak <berkusandrew@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-22 12:22:23 -04:00
if task.Name == prevName {
// Indent previous tasks of the same slot
names[task.ID] = indent + task.Name
} else {
names[task.ID] = task.Name
}
Improve service tasks grouping on printing When printing services' tasks with `docker service ps` command, tasks are grouped only by task slot. This leads to interleaving tasks from different services when `docker service ps` is called with multiple services. Besides this, global services do not have slots at all and printing tasks for them doesn't group and doesn't properly indent tasks with \_. With this patch all tasks are grouped by service ID, slot and node ID (relevant only for global services) and it fixes issue 533. Before this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 5 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 2 seconds ago kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 5 seconds ago pubrerosvsw5 b.1 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago fu08gfi8tfyv a.1 nginx:alpine docker-desktop Shutdown Shutdown 7 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Ready 1 second ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago xq8dogqcbxd2 a.2 nginx:alpine docker-desktop Running Running 44 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Starting less than a second ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 5 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qn7c7jmjuo76 a.3 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 2 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago ``` After this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 32 seconds ago fu08gfi8tfyv \_ a.1 nginx:alpine docker-desktop Shutdown Shutdown 34 seconds ago 3pam0limnn24 a.2 nginx:alpine docker-desktop Running Running 23 seconds ago xq8dogqcbxd2 \_ a.2 nginx:alpine docker-desktop Shutdown Shutdown 24 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Running 26 seconds ago qn7c7jmjuo76 \_ a.3 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 29 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 29 seconds ago pubrerosvsw5 \_ b.1 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Running 26 seconds ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 32 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 32 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago ``` Signed-off-by: Andrii Berehuliak <berkusandrew@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-22 12:22:23 -04:00
prevName = task.Name
nodeValue, err := resolver.Resolve(ctx, swarm.Node{}, task.NodeID)
if err != nil {
return err
}
Improve service tasks grouping on printing When printing services' tasks with `docker service ps` command, tasks are grouped only by task slot. This leads to interleaving tasks from different services when `docker service ps` is called with multiple services. Besides this, global services do not have slots at all and printing tasks for them doesn't group and doesn't properly indent tasks with \_. With this patch all tasks are grouped by service ID, slot and node ID (relevant only for global services) and it fixes issue 533. Before this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 5 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 2 seconds ago kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 5 seconds ago pubrerosvsw5 b.1 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago fu08gfi8tfyv a.1 nginx:alpine docker-desktop Shutdown Shutdown 7 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Ready 1 second ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago xq8dogqcbxd2 a.2 nginx:alpine docker-desktop Running Running 44 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Starting less than a second ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 5 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qn7c7jmjuo76 a.3 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 2 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago ``` After this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 32 seconds ago fu08gfi8tfyv \_ a.1 nginx:alpine docker-desktop Shutdown Shutdown 34 seconds ago 3pam0limnn24 a.2 nginx:alpine docker-desktop Running Running 23 seconds ago xq8dogqcbxd2 \_ a.2 nginx:alpine docker-desktop Shutdown Shutdown 24 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Running 26 seconds ago qn7c7jmjuo76 \_ a.3 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 29 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 29 seconds ago pubrerosvsw5 \_ b.1 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Running 26 seconds ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 32 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 32 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago ``` Signed-off-by: Andrii Berehuliak <berkusandrew@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-22 12:22:23 -04:00
nodes[task.ID] = nodeValue
}
Improve service tasks grouping on printing When printing services' tasks with `docker service ps` command, tasks are grouped only by task slot. This leads to interleaving tasks from different services when `docker service ps` is called with multiple services. Besides this, global services do not have slots at all and printing tasks for them doesn't group and doesn't properly indent tasks with \_. With this patch all tasks are grouped by service ID, slot and node ID (relevant only for global services) and it fixes issue 533. Before this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 5 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 2 seconds ago kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 5 seconds ago pubrerosvsw5 b.1 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago fu08gfi8tfyv a.1 nginx:alpine docker-desktop Shutdown Shutdown 7 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Ready 1 second ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago xq8dogqcbxd2 a.2 nginx:alpine docker-desktop Running Running 44 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Starting less than a second ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 5 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qn7c7jmjuo76 a.3 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 2 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago ``` After this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 32 seconds ago fu08gfi8tfyv \_ a.1 nginx:alpine docker-desktop Shutdown Shutdown 34 seconds ago 3pam0limnn24 a.2 nginx:alpine docker-desktop Running Running 23 seconds ago xq8dogqcbxd2 \_ a.2 nginx:alpine docker-desktop Shutdown Shutdown 24 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Running 26 seconds ago qn7c7jmjuo76 \_ a.3 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 29 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 29 seconds ago pubrerosvsw5 \_ b.1 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Running 26 seconds ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 32 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 32 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago ``` Signed-off-by: Andrii Berehuliak <berkusandrew@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-22 12:22:23 -04:00
return FormatWrite(tasksCtx, tasks, names, nodes)
}
Improve service tasks grouping on printing When printing services' tasks with `docker service ps` command, tasks are grouped only by task slot. This leads to interleaving tasks from different services when `docker service ps` is called with multiple services. Besides this, global services do not have slots at all and printing tasks for them doesn't group and doesn't properly indent tasks with \_. With this patch all tasks are grouped by service ID, slot and node ID (relevant only for global services) and it fixes issue 533. Before this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 5 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 2 seconds ago kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 5 seconds ago pubrerosvsw5 b.1 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago fu08gfi8tfyv a.1 nginx:alpine docker-desktop Shutdown Shutdown 7 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Ready 1 second ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago xq8dogqcbxd2 a.2 nginx:alpine docker-desktop Running Running 44 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Starting less than a second ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 5 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qn7c7jmjuo76 a.3 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 2 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago ``` After this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 32 seconds ago fu08gfi8tfyv \_ a.1 nginx:alpine docker-desktop Shutdown Shutdown 34 seconds ago 3pam0limnn24 a.2 nginx:alpine docker-desktop Running Running 23 seconds ago xq8dogqcbxd2 \_ a.2 nginx:alpine docker-desktop Shutdown Shutdown 24 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Running 26 seconds ago qn7c7jmjuo76 \_ a.3 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 29 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 29 seconds ago pubrerosvsw5 \_ b.1 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Running 26 seconds ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 32 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 32 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago ``` Signed-off-by: Andrii Berehuliak <berkusandrew@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-22 12:22:23 -04:00
// generateTaskNames generates names for the given tasks, and returns a copy of
// the slice with the 'Name' field set.
//
// Depending if the "--no-resolve" option is set, names have the following pattern:
//
// - ServiceName.Slot or ServiceID.Slot for tasks that are part of a replicated service
// - ServiceName.NodeName or ServiceID.NodeID for tasks that are part of a global service
//
// Task-names are not unique in cases where "tasks" contains previous/rotated tasks.
func generateTaskNames(ctx context.Context, tasks []swarm.Task, resolver *idresolver.IDResolver) ([]swarm.Task, error) {
// Use a copy of the tasks list, to not modify the original slice
// see https://github.com/go101/go101/wiki/How-to-efficiently-clone-a-slice%3F
t := append(tasks[:0:0], tasks...) //nolint:gocritic // ignore appendAssign: append result not assigned to the same slice
Improve service tasks grouping on printing When printing services' tasks with `docker service ps` command, tasks are grouped only by task slot. This leads to interleaving tasks from different services when `docker service ps` is called with multiple services. Besides this, global services do not have slots at all and printing tasks for them doesn't group and doesn't properly indent tasks with \_. With this patch all tasks are grouped by service ID, slot and node ID (relevant only for global services) and it fixes issue 533. Before this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 5 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 2 seconds ago kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 5 seconds ago pubrerosvsw5 b.1 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago fu08gfi8tfyv a.1 nginx:alpine docker-desktop Shutdown Shutdown 7 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Ready 1 second ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago xq8dogqcbxd2 a.2 nginx:alpine docker-desktop Running Running 44 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Starting less than a second ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 5 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qn7c7jmjuo76 a.3 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 2 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago ``` After this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 32 seconds ago fu08gfi8tfyv \_ a.1 nginx:alpine docker-desktop Shutdown Shutdown 34 seconds ago 3pam0limnn24 a.2 nginx:alpine docker-desktop Running Running 23 seconds ago xq8dogqcbxd2 \_ a.2 nginx:alpine docker-desktop Shutdown Shutdown 24 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Running 26 seconds ago qn7c7jmjuo76 \_ a.3 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 29 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 29 seconds ago pubrerosvsw5 \_ b.1 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Running 26 seconds ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 32 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 32 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago ``` Signed-off-by: Andrii Berehuliak <berkusandrew@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-22 12:22:23 -04:00
for i, task := range t {
serviceName, err := resolver.Resolve(ctx, swarm.Service{}, task.ServiceID)
if err != nil {
return nil, err
}
Improve service tasks grouping on printing When printing services' tasks with `docker service ps` command, tasks are grouped only by task slot. This leads to interleaving tasks from different services when `docker service ps` is called with multiple services. Besides this, global services do not have slots at all and printing tasks for them doesn't group and doesn't properly indent tasks with \_. With this patch all tasks are grouped by service ID, slot and node ID (relevant only for global services) and it fixes issue 533. Before this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 5 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 2 seconds ago kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 5 seconds ago pubrerosvsw5 b.1 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago fu08gfi8tfyv a.1 nginx:alpine docker-desktop Shutdown Shutdown 7 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Ready 1 second ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago xq8dogqcbxd2 a.2 nginx:alpine docker-desktop Running Running 44 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Starting less than a second ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 5 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qn7c7jmjuo76 a.3 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 2 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago ``` After this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 32 seconds ago fu08gfi8tfyv \_ a.1 nginx:alpine docker-desktop Shutdown Shutdown 34 seconds ago 3pam0limnn24 a.2 nginx:alpine docker-desktop Running Running 23 seconds ago xq8dogqcbxd2 \_ a.2 nginx:alpine docker-desktop Shutdown Shutdown 24 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Running 26 seconds ago qn7c7jmjuo76 \_ a.3 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 29 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 29 seconds ago pubrerosvsw5 \_ b.1 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Running 26 seconds ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 32 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 32 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago ``` Signed-off-by: Andrii Berehuliak <berkusandrew@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-22 12:22:23 -04:00
if task.Slot != 0 {
t[i].Name = fmt.Sprintf("%v.%v", serviceName, task.Slot)
} else {
t[i].Name = fmt.Sprintf("%v.%v", serviceName, task.NodeID)
}
}
Improve service tasks grouping on printing When printing services' tasks with `docker service ps` command, tasks are grouped only by task slot. This leads to interleaving tasks from different services when `docker service ps` is called with multiple services. Besides this, global services do not have slots at all and printing tasks for them doesn't group and doesn't properly indent tasks with \_. With this patch all tasks are grouped by service ID, slot and node ID (relevant only for global services) and it fixes issue 533. Before this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 5 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 2 seconds ago kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 5 seconds ago pubrerosvsw5 b.1 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago fu08gfi8tfyv a.1 nginx:alpine docker-desktop Shutdown Shutdown 7 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Ready 1 second ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago xq8dogqcbxd2 a.2 nginx:alpine docker-desktop Running Running 44 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Starting less than a second ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 5 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 6 seconds ago qn7c7jmjuo76 a.3 nginx:alpine docker-desktop Shutdown Shutdown less than a second ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 2 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 3 seconds ago ``` After this patch: ```console docker service ps a b c ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS kfjo1hly92l4 a.1 nginx:alpine docker-desktop Running Running 32 seconds ago fu08gfi8tfyv \_ a.1 nginx:alpine docker-desktop Shutdown Shutdown 34 seconds ago 3pam0limnn24 a.2 nginx:alpine docker-desktop Running Running 23 seconds ago xq8dogqcbxd2 \_ a.2 nginx:alpine docker-desktop Shutdown Shutdown 24 seconds ago rm40lofzed0h a.3 nginx:alpine docker-desktop Running Running 26 seconds ago qn7c7jmjuo76 \_ a.3 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago wi9330mbabpg a.4 nginx:alpine docker-desktop Running Running 29 seconds ago p5oy6h7nkvc3 \_ a.4 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago qpcgdsx1r21a b.1 nginx:alpine docker-desktop Running Running 29 seconds ago pubrerosvsw5 \_ b.1 nginx:alpine docker-desktop Shutdown Shutdown 30 seconds ago pu6qmgyoibq4 b.2 nginx:alpine docker-desktop Running Running 26 seconds ago tz1n4hjne6pk \_ b.2 nginx:alpine docker-desktop Shutdown Shutdown 27 seconds ago sqqj2n9fpi82 b.3 nginx:alpine docker-desktop Running Running 32 seconds ago prv3gymkvqk6 \_ b.3 nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago xbzm6ed776yw c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Running Running 32 seconds ago 4mcsovp8ckwn \_ c.j1afavbqqhr21jvnid3nnfoyt nginx:alpine docker-desktop Shutdown Shutdown 33 seconds ago ``` Signed-off-by: Andrii Berehuliak <berkusandrew@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-22 12:22:23 -04:00
return t, nil
}
// DefaultFormat returns the default format from the config file, or table
// format if nothing is set in the config.
func DefaultFormat(configFile *configfile.ConfigFile, quiet bool) string {
if len(configFile.TasksFormat) > 0 && !quiet {
return configFile.TasksFormat
}
return formatter.TableFormatKey
}