[#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 (
"context"
"crypto/ecdsa"
"encoding/hex"
"errors"
"fmt"
"strconv"
@ -223,14 +224,12 @@ func getActualPlacement(cmd *cobra.Command, netmap *netmapSDK.NetMap, requiredPl
}
}
var err error
eg, egCtx := errgroup.WithContext(cmd.Context())
for _, cand := range candidates {
cand := cand
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 {
resultMtx.Lock()
defer resultMtx.Unlock()
@ -268,13 +267,7 @@ func getActualPlacement(cmd *cobra.Command, netmap *netmapSDK.NetMap, requiredPl
})
}
egErr := eg.Wait()
if err != nil || egErr != nil {
if err == nil {
err = egErr
}
commonCmd.ExitOnErr(cmd, "failed to get actual placement: %w", err)
}
commonCmd.ExitOnErr(cmd, "failed to get actual placement: %w", eg.Wait())
return result
}
@ -285,6 +278,7 @@ func createClient(ctx context.Context, cmd *cobra.Command, candidate netmapSDK.N
addresses = append(addresses, s)
return false
})
addresses = append(addresses, candidate.ExternalAddresses()...)
var lastErr error
for _, address := range addresses {
var networkAddr network.Address
@ -336,13 +330,9 @@ func printPlacement(cmd *cobra.Command, netmap *netmapSDK.NetMap, requiredPlacem
defer func() {
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() {
var address string
n.IterateNetworkEndpoints(func(s string) bool {
address = s
return s != ""
})
nodeID := hex.EncodeToString(n.PublicKey())
_, required := requiredPlacement[n.Hash()]
actual, actualExists := actualPlacement[n.Hash()]
actualStr := ""
@ -353,6 +343,6 @@ func printPlacement(cmd *cobra.Command, netmap *netmapSDK.NetMap, requiredPlacem
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)
}
}