From d9b93b12c1536953cb3286753f115b4162f88c65 Mon Sep 17 00:00:00 2001 From: Ekaterina Lebedeva Date: Mon, 18 Sep 2023 10:05:17 +0300 Subject: [PATCH 1/3] [#333] Sort shards by shard_ID in cli output Signed-off-by: Ekaterina Lebedeva --- cmd/frostfs-cli/modules/control/shards_list.go | 14 ++++++++++++-- cmd/frostfs-cli/modules/control/shards_set_mode.go | 6 ++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cmd/frostfs-cli/modules/control/shards_list.go b/cmd/frostfs-cli/modules/control/shards_list.go index ec515e6b4..4d09667b8 100644 --- a/cmd/frostfs-cli/modules/control/shards_list.go +++ b/cmd/frostfs-cli/modules/control/shards_list.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "sort" "strings" rawclient "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" @@ -49,11 +50,14 @@ func listShards(cmd *cobra.Command, _ []string) { verifyResponse(cmd, resp.GetSignature(), resp.GetBody()) + shards := resp.GetBody().GetShards() + sortShardsByID(shards) + isJSON, _ := cmd.Flags().GetBool(commonflags.JSON) if isJSON { - prettyPrintShardsJSON(cmd, resp.GetBody().GetShards()) + prettyPrintShardsJSON(cmd, shards) } else { - prettyPrintShards(cmd, resp.GetBody().GetShards()) + prettyPrintShards(cmd, shards) } } @@ -115,3 +119,9 @@ func shardModeToString(m control.ShardMode) string { return "unknown" } + +func sortShardsByID(ii []*control.ShardInfo) { + sort.Slice(ii, func(i, j int) bool { + return bytes.Compare(ii[i].Shard_ID, ii[j].Shard_ID) < 0 + }) +} diff --git a/cmd/frostfs-cli/modules/control/shards_set_mode.go b/cmd/frostfs-cli/modules/control/shards_set_mode.go index 135c0efa6..78f768965 100644 --- a/cmd/frostfs-cli/modules/control/shards_set_mode.go +++ b/cmd/frostfs-cli/modules/control/shards_set_mode.go @@ -1,7 +1,9 @@ package control import ( + "bytes" "fmt" + "sort" "strings" rawclient "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" @@ -167,5 +169,9 @@ func getShardIDList(cmd *cobra.Command) [][]byte { res = append(res, raw) } + sort.Slice(res, func(i, j int) bool { + return bytes.Compare(res[i], res[j]) < 0 + }) + return res } -- 2.45.3 From c14c9a023cbd96e12a60909f87f0d1e56ffba97b Mon Sep 17 00:00:00 2001 From: Ekaterina Lebedeva Date: Wed, 20 Sep 2023 18:26:28 +0300 Subject: [PATCH 2/3] [#333] Sort objects by ID in SearchObjects Signed-off-by: Ekaterina Lebedeva --- cmd/frostfs-cli/internal/client/client.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/frostfs-cli/internal/client/client.go b/cmd/frostfs-cli/internal/client/client.go index e8869bc8c..26d8aa83b 100644 --- a/cmd/frostfs-cli/internal/client/client.go +++ b/cmd/frostfs-cli/internal/client/client.go @@ -6,6 +6,8 @@ import ( "errors" "fmt" "io" + "sort" + "strings" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/accounting" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/checksum" @@ -727,6 +729,11 @@ func SearchObjects(ctx context.Context, prm SearchObjectsPrm) (*SearchObjectsRes return nil, fmt.Errorf("read object list: %w", err) } + sort.Slice(list, func(i, j int) bool { + lhs, rhs := list[i].EncodeToString(), list[j].EncodeToString() + return strings.Compare(lhs, rhs) < 0 + }) + return &SearchObjectsRes{ ids: list, }, nil -- 2.45.3 From b8c3c2486d13a2a2bcf4ea0b8b85c03571f80e57 Mon Sep 17 00:00:00 2001 From: Ekaterina Lebedeva Date: Mon, 25 Sep 2023 09:58:26 +0300 Subject: [PATCH 3/3] [#333] Sort containers by ID Signed-off-by: Ekaterina Lebedeva --- cmd/frostfs-cli/internal/client/client.go | 10 ++++++++++ cmd/frostfs-cli/modules/container/list.go | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/frostfs-cli/internal/client/client.go b/cmd/frostfs-cli/internal/client/client.go index 26d8aa83b..9cb7c8161 100644 --- a/cmd/frostfs-cli/internal/client/client.go +++ b/cmd/frostfs-cli/internal/client/client.go @@ -71,6 +71,16 @@ func ListContainers(ctx context.Context, prm ListContainersPrm) (res ListContain return } +// SortedIDList returns sorted list of identifiers of user's containers. +func (x ListContainersRes) SortedIDList() []cid.ID { + list := x.cliRes.Containers() + sort.Slice(list, func(i, j int) bool { + lhs, rhs := list[i].EncodeToString(), list[j].EncodeToString() + return strings.Compare(lhs, rhs) < 0 + }) + return list +} + // PutContainerPrm groups parameters of PutContainer operation. type PutContainerPrm struct { Client *client.Client diff --git a/cmd/frostfs-cli/modules/container/list.go b/cmd/frostfs-cli/modules/container/list.go index c8b891d32..1c7787760 100644 --- a/cmd/frostfs-cli/modules/container/list.go +++ b/cmd/frostfs-cli/modules/container/list.go @@ -56,7 +56,7 @@ var listContainersCmd = &cobra.Command{ Client: cli, } - containerIDs := res.IDList() + containerIDs := res.SortedIDList() for _, cnrID := range containerIDs { if flagVarListName == "" && !flagVarListPrintAttr { cmd.Println(cnrID.String()) -- 2.45.3