[#476] cli: Fix object nodes command
Some checks failed
Build / Build Components (1.20) (pull_request) Successful in 3m56s
Build / Build Components (1.19) (pull_request) Successful in 4m18s
ci/woodpecker/pr/pre-commit Pipeline was successful
Tests and linters / Lint (pull_request) Failing after 7m27s
Tests and linters / Tests (1.19) (pull_request) Successful in 7m45s
Tests and linters / Tests with -race (pull_request) Successful in 7m40s
Tests and linters / Tests (1.20) (pull_request) Successful in 14m7s
Tests and linters / Staticcheck (pull_request) Successful in 13m37s
ci/woodpecker/push/pre-commit Pipeline was successful

Do not fail if client creation failed.
Use external addresses to create the client too.
Use public key as node ID.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-07-07 18:52:32 +03:00
parent 140d970a95
commit 040a623d39

View file

@ -3,6 +3,7 @@ package object
import ( import (
"context" "context"
"crypto/ecdsa" "crypto/ecdsa"
"encoding/hex"
"errors" "errors"
"fmt" "fmt"
"strconv" "strconv"
@ -223,14 +224,12 @@ func getActualPlacement(cmd *cobra.Command, netmap *netmapSDK.NetMap, requiredPl
} }
} }
var err error
eg, egCtx := errgroup.WithContext(cmd.Context()) eg, egCtx := errgroup.WithContext(cmd.Context())
for _, cand := range candidates { for _, cand := range candidates {
cand := cand cand := cand
eg.Go(func() error { eg.Go(func() error {
var cli *client.Client cli, err := createClient(egCtx, cmd, cand, pk)
cli, err = createClient(egCtx, cmd, cand, pk)
if err != nil { if err != nil {
resultMtx.Lock() resultMtx.Lock()
defer resultMtx.Unlock() defer resultMtx.Unlock()
@ -268,13 +267,7 @@ func getActualPlacement(cmd *cobra.Command, netmap *netmapSDK.NetMap, requiredPl
}) })
} }
egErr := eg.Wait() commonCmd.ExitOnErr(cmd, "failed to get actual placement: %w", eg.Wait())
if err != nil || egErr != nil {
if err == nil {
err = egErr
}
commonCmd.ExitOnErr(cmd, "failed to get actual placement: %w", err)
}
return result return result
} }
@ -285,6 +278,7 @@ func createClient(ctx context.Context, cmd *cobra.Command, candidate netmapSDK.N
addresses = append(addresses, s) addresses = append(addresses, s)
return false return false
}) })
addresses = append(addresses, candidate.ExternalAddresses()...)
var lastErr error var lastErr error
for _, address := range addresses { for _, address := range addresses {
var networkAddr network.Address var networkAddr network.Address
@ -336,13 +330,9 @@ func printPlacement(cmd *cobra.Command, netmap *netmapSDK.NetMap, requiredPlacem
defer func() { defer func() {
commonCmd.ExitOnErr(cmd, "failed to print placement info: %w", w.Flush()) commonCmd.ExitOnErr(cmd, "failed to print placement info: %w", w.Flush())
}() }()
fmt.Fprintln(w, "Netmap node\tShould contain object\tActually contains object\t") fmt.Fprintln(w, "Node ID\tShould contain object\tActually contains object\t")
for _, n := range netmap.Nodes() { for _, n := range netmap.Nodes() {
var address string nodeID := hex.EncodeToString(n.PublicKey())
n.IterateNetworkEndpoints(func(s string) bool {
address = s
return s != ""
})
_, required := requiredPlacement[n.Hash()] _, required := requiredPlacement[n.Hash()]
actual, actualExists := actualPlacement[n.Hash()] actual, actualExists := actualPlacement[n.Hash()]
actualStr := "" actualStr := ""
@ -353,6 +343,6 @@ func printPlacement(cmd *cobra.Command, netmap *netmapSDK.NetMap, requiredPlacem
actualStr = strconv.FormatBool(actual.value) actualStr = strconv.FormatBool(actual.value)
} }
} }
fmt.Fprintf(w, "%s\t%s\t%s\t\n", address, strconv.FormatBool(required), actualStr) fmt.Fprintf(w, "%s\t%s\t%s\t\n", nodeID, strconv.FormatBool(required), actualStr)
} }
} }