forked from TrueCloudLab/frostfs-node
[#1374] cli: Drop deprecated grpc connection method
For `frostfs-cli` it is ok to use grpc-client without blocking, as `frostfs-cli` will perform RPC call anyway. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
bb44867491
commit
944160427b
10 changed files with 39 additions and 28 deletions
|
@ -47,9 +47,10 @@ func add(cmd *cobra.Command, _ []string) {
|
|||
meta, err := parseMeta(cmd)
|
||||
commonCmd.ExitOnErr(cmd, "meta data parsing: %w", err)
|
||||
|
||||
ctx := cmd.Context()
|
||||
ctx, cancel := contextWithTimeout(cmd)
|
||||
defer cancel()
|
||||
|
||||
cli, err := _client(ctx)
|
||||
cli, err := _client()
|
||||
commonCmd.ExitOnErr(cmd, "failed to create client: %w", err)
|
||||
|
||||
rawCID := make([]byte, sha256.Size)
|
||||
|
|
|
@ -50,9 +50,10 @@ func addByPath(cmd *cobra.Command, _ []string) {
|
|||
commonCmd.ExitOnErr(cmd, "decode container ID string: %w", err)
|
||||
|
||||
tid, _ := cmd.Flags().GetString(treeIDFlagKey)
|
||||
ctx := cmd.Context()
|
||||
ctx, cancel := contextWithTimeout(cmd)
|
||||
defer cancel()
|
||||
|
||||
cli, err := _client(ctx)
|
||||
cli, err := _client()
|
||||
commonCmd.ExitOnErr(cmd, "failed to create client: %w", err)
|
||||
|
||||
rawCID := make([]byte, sha256.Size)
|
||||
|
|
|
@ -3,13 +3,14 @@ package tree
|
|||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/network"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/tree"
|
||||
metrics "git.frostfs.info/TrueCloudLab/frostfs-observability/metrics/grpc"
|
||||
tracing "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing/grpc"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
|
@ -17,7 +18,7 @@ import (
|
|||
|
||||
// _client returns grpc Tree service client. Should be removed
|
||||
// after making Tree API public.
|
||||
func _client(ctx context.Context) (tree.TreeServiceClient, error) {
|
||||
func _client() (tree.TreeServiceClient, error) {
|
||||
var netAddr network.Address
|
||||
err := netAddr.FromString(viper.GetString(commonflags.RPC))
|
||||
if err != nil {
|
||||
|
@ -25,7 +26,6 @@ func _client(ctx context.Context) (tree.TreeServiceClient, error) {
|
|||
}
|
||||
|
||||
opts := []grpc.DialOption{
|
||||
grpc.WithBlock(),
|
||||
grpc.WithChainUnaryInterceptor(
|
||||
metrics.NewUnaryClientInterceptor(),
|
||||
tracing.NewUnaryClientInteceptor(),
|
||||
|
@ -40,12 +40,14 @@ func _client(ctx context.Context) (tree.TreeServiceClient, error) {
|
|||
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
}
|
||||
|
||||
// a default connection establishing timeout
|
||||
const defaultClientConnectTimeout = time.Second * 2
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, defaultClientConnectTimeout)
|
||||
cc, err := grpc.DialContext(ctx, netAddr.URIAddr(), opts...)
|
||||
cancel()
|
||||
|
||||
cc, err := grpc.NewClient(netAddr.URIAddr(), opts...)
|
||||
return tree.NewTreeServiceClient(cc), err
|
||||
}
|
||||
|
||||
func contextWithTimeout(cmd *cobra.Command) (context.Context, context.CancelFunc) {
|
||||
if timeout := viper.GetDuration(commonflags.Timeout); timeout > 0 {
|
||||
common.PrintVerbose(cmd, "Set request timeout to %s.", timeout)
|
||||
return context.WithTimeout(cmd.Context(), timeout)
|
||||
}
|
||||
return context.WithTimeout(cmd.Context(), commonflags.TimeoutDefault)
|
||||
}
|
||||
|
|
|
@ -50,9 +50,10 @@ func getByPath(cmd *cobra.Command, _ []string) {
|
|||
commonCmd.ExitOnErr(cmd, "decode container ID string: %w", err)
|
||||
|
||||
tid, _ := cmd.Flags().GetString(treeIDFlagKey)
|
||||
ctx := cmd.Context()
|
||||
ctx, cancel := contextWithTimeout(cmd)
|
||||
defer cancel()
|
||||
|
||||
cli, err := _client(ctx)
|
||||
cli, err := _client()
|
||||
commonCmd.ExitOnErr(cmd, "failed to create client: %w", err)
|
||||
|
||||
rawCID := make([]byte, sha256.Size)
|
||||
|
|
|
@ -44,9 +44,10 @@ func getOpLog(cmd *cobra.Command, _ []string) {
|
|||
commonCmd.ExitOnErr(cmd, "decode container ID string: %w", err)
|
||||
|
||||
tid, _ := cmd.Flags().GetString(treeIDFlagKey)
|
||||
ctx := cmd.Context()
|
||||
ctx, cancel := contextWithTimeout(cmd)
|
||||
defer cancel()
|
||||
|
||||
cli, err := _client(ctx)
|
||||
cli, err := _client()
|
||||
commonCmd.ExitOnErr(cmd, "failed to create client: %w", err)
|
||||
|
||||
rawCID := make([]byte, sha256.Size)
|
||||
|
|
|
@ -26,9 +26,10 @@ func initHealthcheckCmd() {
|
|||
|
||||
func healthcheck(cmd *cobra.Command, _ []string) {
|
||||
pk := key.GetOrGenerate(cmd)
|
||||
ctx := cmd.Context()
|
||||
ctx, cancel := contextWithTimeout(cmd)
|
||||
defer cancel()
|
||||
|
||||
cli, err := _client(ctx)
|
||||
cli, err := _client()
|
||||
commonCmd.ExitOnErr(cmd, "failed to create client: %w", err)
|
||||
|
||||
req := &tree.HealthcheckRequest{
|
||||
|
|
|
@ -38,9 +38,10 @@ func list(cmd *cobra.Command, _ []string) {
|
|||
err := cnr.DecodeString(cidString)
|
||||
commonCmd.ExitOnErr(cmd, "decode container ID string: %w", err)
|
||||
|
||||
ctx := cmd.Context()
|
||||
ctx, cancel := contextWithTimeout(cmd)
|
||||
defer cancel()
|
||||
|
||||
cli, err := _client(ctx)
|
||||
cli, err := _client()
|
||||
commonCmd.ExitOnErr(cmd, "failed to create client: %w", err)
|
||||
|
||||
rawCID := make([]byte, sha256.Size)
|
||||
|
|
|
@ -45,9 +45,10 @@ func move(cmd *cobra.Command, _ []string) {
|
|||
err := cnr.DecodeString(cidString)
|
||||
commonCmd.ExitOnErr(cmd, "decode container ID string: %w", err)
|
||||
|
||||
ctx := cmd.Context()
|
||||
ctx, cancel := contextWithTimeout(cmd)
|
||||
defer cancel()
|
||||
|
||||
cli, err := _client(ctx)
|
||||
cli, err := _client()
|
||||
commonCmd.ExitOnErr(cmd, "failed to create client: %w", err)
|
||||
|
||||
rawCID := make([]byte, sha256.Size)
|
||||
|
|
|
@ -41,9 +41,10 @@ func remove(cmd *cobra.Command, _ []string) {
|
|||
err := cnr.DecodeString(cidString)
|
||||
commonCmd.ExitOnErr(cmd, "decode container ID string: %w", err)
|
||||
|
||||
ctx := cmd.Context()
|
||||
ctx, cancel := contextWithTimeout(cmd)
|
||||
defer cancel()
|
||||
|
||||
cli, err := _client(ctx)
|
||||
cli, err := _client()
|
||||
commonCmd.ExitOnErr(cmd, "failed to create client: %w", err)
|
||||
|
||||
rawCID := make([]byte, sha256.Size)
|
||||
|
|
|
@ -46,9 +46,10 @@ func getSubTree(cmd *cobra.Command, _ []string) {
|
|||
err := cnr.DecodeString(cidString)
|
||||
commonCmd.ExitOnErr(cmd, "decode container ID string: %w", err)
|
||||
|
||||
ctx := cmd.Context()
|
||||
ctx, cancel := contextWithTimeout(cmd)
|
||||
defer cancel()
|
||||
|
||||
cli, err := _client(ctx)
|
||||
cli, err := _client()
|
||||
commonCmd.ExitOnErr(cmd, "failed to create client: %w", err)
|
||||
|
||||
rawCID := make([]byte, sha256.Size)
|
||||
|
|
Loading…
Reference in a new issue