2022-10-05 13:52:46 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/sha256"
|
2024-03-29 12:59:50 +00:00
|
|
|
"errors"
|
2022-10-05 13:52:46 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
internalclient "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/client"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
|
|
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
|
|
|
containerAPI "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
2022-10-05 13:52:46 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var short bool
|
|
|
|
|
|
|
|
var containerNodesCmd = &cobra.Command{
|
|
|
|
Use: "nodes",
|
|
|
|
Short: "Show nodes for container",
|
|
|
|
Long: "Show nodes taking part in a container at the current epoch.",
|
2024-03-11 14:11:49 +00:00
|
|
|
Run: func(cmd *cobra.Command, _ []string) {
|
2023-10-31 11:56:55 +00:00
|
|
|
cnr, pkey := getContainer(cmd)
|
2022-10-05 13:52:46 +00:00
|
|
|
|
|
|
|
if pkey == nil {
|
|
|
|
pkey = key.GetOrGenerate(cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
cli := internalclient.GetSDKClientByFlag(cmd, pkey, commonflags.RPC)
|
|
|
|
|
|
|
|
var prm internalclient.NetMapSnapshotPrm
|
|
|
|
prm.SetClient(cli)
|
|
|
|
|
2023-05-24 13:51:57 +00:00
|
|
|
resmap, err := internalclient.NetMapSnapshot(cmd.Context(), prm)
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "unable to get netmap snapshot", err)
|
2022-10-05 13:52:46 +00:00
|
|
|
|
|
|
|
var id cid.ID
|
|
|
|
containerAPI.CalculateID(&id, cnr)
|
|
|
|
binCnr := make([]byte, sha256.Size)
|
|
|
|
id.Encode(binCnr)
|
|
|
|
|
2022-10-28 18:30:39 +00:00
|
|
|
policy := cnr.PlacementPolicy()
|
|
|
|
|
2022-10-05 13:52:46 +00:00
|
|
|
var cnrNodes [][]netmap.NodeInfo
|
2022-10-28 18:30:39 +00:00
|
|
|
cnrNodes, err = resmap.NetMap().ContainerNodes(policy, binCnr)
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "could not build container nodes for given container: %w", err)
|
2022-10-05 13:52:46 +00:00
|
|
|
|
|
|
|
for i := range cnrNodes {
|
2024-03-29 12:59:50 +00:00
|
|
|
if repNum := policy.ReplicaDescriptor(i).NumberOfObjects(); repNum > 0 {
|
|
|
|
cmd.Printf("Descriptor #%d, REP %d:\n", i+1, repNum)
|
|
|
|
} else if ecParts := policy.ReplicaDescriptor(i).TotalECPartCount(); ecParts > 0 {
|
|
|
|
cmd.Printf("Descriptor #%d, EC %d.%d:\n", i+1, policy.ReplicaDescriptor(i).GetECDataCount(),
|
|
|
|
policy.ReplicaDescriptor(i).GetECParityCount())
|
|
|
|
} else {
|
|
|
|
commonCmd.ExitOnErr(cmd, "%w", errors.New("no replication policy is set"))
|
|
|
|
}
|
2022-10-05 13:52:46 +00:00
|
|
|
for j := range cnrNodes[i] {
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.PrettyPrintNodeInfo(cmd, cnrNodes[i][j], j, "\t", short)
|
2022-10-05 13:52:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func initContainerNodesCmd() {
|
|
|
|
commonflags.Init(containerNodesCmd)
|
|
|
|
|
|
|
|
flags := containerNodesCmd.Flags()
|
2022-10-18 11:43:04 +00:00
|
|
|
flags.StringVar(&containerID, commonflags.CIDFlag, "", commonflags.CIDFlagUsage)
|
2022-10-05 13:52:46 +00:00
|
|
|
flags.StringVar(&containerPathFrom, fromFlag, "", fromFlagUsage)
|
|
|
|
flags.BoolVar(&short, "short", false, "Shortens output of node info")
|
|
|
|
}
|