From 0a1530afa06520f7fac00997ca119e566762499a Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 17 Oct 2022 18:37:15 +0300 Subject: [PATCH] [#1917] neofs-cli: Support timeout in `control` commands Signed-off-by: Evgenii Stratonikov --- CHANGELOG.md | 2 ++ cmd/neofs-cli/modules/control/drop_objects.go | 5 +---- cmd/neofs-cli/modules/control/evacuate_shard.go | 4 +--- cmd/neofs-cli/modules/control/flush_cache.go | 4 +--- cmd/neofs-cli/modules/control/healthcheck.go | 5 +---- cmd/neofs-cli/modules/control/root.go | 1 + cmd/neofs-cli/modules/control/set_netmap_status.go | 5 +---- cmd/neofs-cli/modules/control/shards_dump.go | 4 +--- cmd/neofs-cli/modules/control/shards_list.go | 4 +--- cmd/neofs-cli/modules/control/shards_restore.go | 4 +--- cmd/neofs-cli/modules/control/shards_set_mode.go | 5 +---- cmd/neofs-cli/modules/control/synchronize_tree.go | 4 +--- cmd/neofs-cli/modules/control/util.go | 9 +++++++++ 13 files changed, 22 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81c8e9616..d36581f03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Changelog for NeoFS Node ## [Unreleased] ### Added +- `--timeout` flag in `neofs-cli control` commands (#1917) + ### Changed ### Fixed ### Removed diff --git a/cmd/neofs-cli/modules/control/drop_objects.go b/cmd/neofs-cli/modules/control/drop_objects.go index 839577391..955c45d1f 100644 --- a/cmd/neofs-cli/modules/control/drop_objects.go +++ b/cmd/neofs-cli/modules/control/drop_objects.go @@ -3,7 +3,6 @@ package control import ( rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common" - "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" "github.com/nspcc-dev/neofs-node/pkg/services/control" "github.com/spf13/cobra" @@ -50,11 +49,9 @@ var dropObjectsCmd = &cobra.Command{ } func initControlDropObjectsCmd() { - commonflags.InitWithoutRPC(dropObjectsCmd) + initControlFlags(dropObjectsCmd) flags := dropObjectsCmd.Flags() - - flags.String(controlRPC, controlRPCDefault, controlRPCUsage) flags.StringSliceP(dropObjectsFlag, "o", nil, "List of object addresses to be removed in string format") diff --git a/cmd/neofs-cli/modules/control/evacuate_shard.go b/cmd/neofs-cli/modules/control/evacuate_shard.go index 3c4ccf28a..dd82cefd4 100644 --- a/cmd/neofs-cli/modules/control/evacuate_shard.go +++ b/cmd/neofs-cli/modules/control/evacuate_shard.go @@ -3,7 +3,6 @@ package control import ( "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common" - "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" "github.com/nspcc-dev/neofs-node/pkg/services/control" "github.com/spf13/cobra" @@ -43,10 +42,9 @@ func evacuateShard(cmd *cobra.Command, _ []string) { } func initControlEvacuateShardCmd() { - commonflags.InitWithoutRPC(evacuateShardCmd) + initControlFlags(evacuateShardCmd) flags := evacuateShardCmd.Flags() - flags.String(controlRPC, controlRPCDefault, controlRPCUsage) flags.StringSlice(shardIDFlag, nil, "List of shard IDs in base58 encoding") flags.Bool(shardAllFlag, false, "Process all shards") flags.Bool(dumpIgnoreErrorsFlag, false, "Skip invalid/unreadable objects") diff --git a/cmd/neofs-cli/modules/control/flush_cache.go b/cmd/neofs-cli/modules/control/flush_cache.go index 898b5dc83..31ef9c978 100644 --- a/cmd/neofs-cli/modules/control/flush_cache.go +++ b/cmd/neofs-cli/modules/control/flush_cache.go @@ -3,7 +3,6 @@ package control import ( "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common" - "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" "github.com/nspcc-dev/neofs-node/pkg/services/control" "github.com/spf13/cobra" @@ -40,10 +39,9 @@ func flushCache(cmd *cobra.Command, _ []string) { } func initControlFlushCacheCmd() { - commonflags.InitWithoutRPC(flushCacheCmd) + initControlFlags(flushCacheCmd) ff := flushCacheCmd.Flags() - ff.String(controlRPC, controlRPCDefault, controlRPCUsage) ff.StringSlice(shardIDFlag, nil, "List of shard IDs in base58 encoding") ff.Bool(shardAllFlag, false, "Process all shards") diff --git a/cmd/neofs-cli/modules/control/healthcheck.go b/cmd/neofs-cli/modules/control/healthcheck.go index d5ac252d6..7d5f50b8f 100644 --- a/cmd/neofs-cli/modules/control/healthcheck.go +++ b/cmd/neofs-cli/modules/control/healthcheck.go @@ -5,7 +5,6 @@ import ( rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common" - "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" "github.com/nspcc-dev/neofs-node/pkg/services/control" ircontrol "github.com/nspcc-dev/neofs-node/pkg/services/control/ir" @@ -26,11 +25,9 @@ var healthCheckCmd = &cobra.Command{ } func initControlHealthCheckCmd() { - commonflags.InitWithoutRPC(healthCheckCmd) + initControlFlags(healthCheckCmd) flags := healthCheckCmd.Flags() - - flags.String(controlRPC, controlRPCDefault, controlRPCUsage) flags.Bool(healthcheckIRFlag, false, "Communicate with IR node") } diff --git a/cmd/neofs-cli/modules/control/root.go b/cmd/neofs-cli/modules/control/root.go index f1c773b37..660be7793 100644 --- a/cmd/neofs-cli/modules/control/root.go +++ b/cmd/neofs-cli/modules/control/root.go @@ -16,6 +16,7 @@ var Cmd = &cobra.Command{ _ = viper.BindPFlag(commonflags.WalletPath, ff.Lookup(commonflags.WalletPath)) _ = viper.BindPFlag(commonflags.Account, ff.Lookup(commonflags.Account)) _ = viper.BindPFlag(controlRPC, ff.Lookup(controlRPC)) + _ = viper.BindPFlag(commonflags.Timeout, ff.Lookup(commonflags.Timeout)) }, } diff --git a/cmd/neofs-cli/modules/control/set_netmap_status.go b/cmd/neofs-cli/modules/control/set_netmap_status.go index 7d18e69cb..9d3c86a54 100644 --- a/cmd/neofs-cli/modules/control/set_netmap_status.go +++ b/cmd/neofs-cli/modules/control/set_netmap_status.go @@ -5,7 +5,6 @@ import ( rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common" - "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" "github.com/nspcc-dev/neofs-node/pkg/services/control" "github.com/spf13/cobra" @@ -27,11 +26,9 @@ var setNetmapStatusCmd = &cobra.Command{ } func initControlSetNetmapStatusCmd() { - commonflags.InitWithoutRPC(setNetmapStatusCmd) + initControlFlags(setNetmapStatusCmd) flags := setNetmapStatusCmd.Flags() - - flags.String(controlRPC, controlRPCDefault, controlRPCUsage) flags.String(netmapStatusFlag, "", fmt.Sprintf("New netmap status keyword ('%s', '%s', '%s')", netmapStatusOnline, diff --git a/cmd/neofs-cli/modules/control/shards_dump.go b/cmd/neofs-cli/modules/control/shards_dump.go index 4c7ad824e..4b04a323d 100644 --- a/cmd/neofs-cli/modules/control/shards_dump.go +++ b/cmd/neofs-cli/modules/control/shards_dump.go @@ -3,7 +3,6 @@ package control import ( "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common" - "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" "github.com/nspcc-dev/neofs-node/pkg/services/control" "github.com/spf13/cobra" @@ -54,10 +53,9 @@ func dumpShard(cmd *cobra.Command, _ []string) { } func initControlDumpShardCmd() { - commonflags.InitWithoutRPC(dumpShardCmd) + initControlFlags(dumpShardCmd) flags := dumpShardCmd.Flags() - flags.String(controlRPC, controlRPCDefault, controlRPCUsage) flags.String(shardIDFlag, "", "Shard ID in base58 encoding") flags.String(dumpFilepathFlag, "", "File to write objects to") flags.Bool(dumpIgnoreErrorsFlag, false, "Skip invalid/unreadable objects") diff --git a/cmd/neofs-cli/modules/control/shards_list.go b/cmd/neofs-cli/modules/control/shards_list.go index 879b712b0..03243aacf 100644 --- a/cmd/neofs-cli/modules/control/shards_list.go +++ b/cmd/neofs-cli/modules/control/shards_list.go @@ -23,11 +23,9 @@ var listShardsCmd = &cobra.Command{ } func initControlShardsListCmd() { - commonflags.InitWithoutRPC(listShardsCmd) + initControlFlags(listShardsCmd) flags := listShardsCmd.Flags() - - flags.String(controlRPC, controlRPCDefault, controlRPCUsage) flags.Bool(commonflags.JSON, false, "Print shard info as a JSON array") } diff --git a/cmd/neofs-cli/modules/control/shards_restore.go b/cmd/neofs-cli/modules/control/shards_restore.go index 33ccbb8d6..b61ccee97 100644 --- a/cmd/neofs-cli/modules/control/shards_restore.go +++ b/cmd/neofs-cli/modules/control/shards_restore.go @@ -3,7 +3,6 @@ package control import ( "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common" - "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" "github.com/nspcc-dev/neofs-node/pkg/services/control" "github.com/spf13/cobra" @@ -54,10 +53,9 @@ func restoreShard(cmd *cobra.Command, _ []string) { } func initControlRestoreShardCmd() { - commonflags.InitWithoutRPC(restoreShardCmd) + initControlFlags(restoreShardCmd) flags := restoreShardCmd.Flags() - flags.String(controlRPC, controlRPCDefault, controlRPCUsage) flags.String(shardIDFlag, "", "Shard ID in base58 encoding") flags.String(restoreFilepathFlag, "", "File to read objects from") flags.Bool(restoreIgnoreErrorsFlag, false, "Skip invalid/unreadable objects") diff --git a/cmd/neofs-cli/modules/control/shards_set_mode.go b/cmd/neofs-cli/modules/control/shards_set_mode.go index f41718430..a39027e21 100644 --- a/cmd/neofs-cli/modules/control/shards_set_mode.go +++ b/cmd/neofs-cli/modules/control/shards_set_mode.go @@ -6,7 +6,6 @@ import ( "github.com/mr-tron/base58" rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common" - "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" "github.com/nspcc-dev/neofs-node/pkg/services/control" "github.com/spf13/cobra" @@ -32,11 +31,9 @@ var setShardModeCmd = &cobra.Command{ } func initControlSetShardModeCmd() { - commonflags.InitWithoutRPC(setShardModeCmd) + initControlFlags(setShardModeCmd) flags := setShardModeCmd.Flags() - - flags.String(controlRPC, controlRPCDefault, controlRPCUsage) flags.StringSlice(shardIDFlag, nil, "List of shard IDs in base58 encoding") flags.Bool(shardAllFlag, false, "Process all shards") flags.String(shardModeFlag, "", diff --git a/cmd/neofs-cli/modules/control/synchronize_tree.go b/cmd/neofs-cli/modules/control/synchronize_tree.go index 07696a0e9..fcbd08cb6 100644 --- a/cmd/neofs-cli/modules/control/synchronize_tree.go +++ b/cmd/neofs-cli/modules/control/synchronize_tree.go @@ -6,7 +6,6 @@ import ( rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common" - "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" "github.com/nspcc-dev/neofs-node/pkg/services/control" controlSvc "github.com/nspcc-dev/neofs-node/pkg/services/control/server" @@ -27,10 +26,9 @@ var synchronizeTreeCmd = &cobra.Command{ } func initControlSynchronizeTreeCmd() { - commonflags.InitWithoutRPC(synchronizeTreeCmd) + initControlFlags(synchronizeTreeCmd) flags := synchronizeTreeCmd.Flags() - flags.String(controlRPC, controlRPCDefault, controlRPCUsage) flags.String("cid", "", "Container ID") flags.String(synchronizeTreeIDFlag, "", "Tree ID") flags.Uint64(synchronizeTreeHeightFlag, 0, "Starting height") diff --git a/cmd/neofs-cli/modules/control/util.go b/cmd/neofs-cli/modules/control/util.go index d700d6aa0..04459c3f6 100644 --- a/cmd/neofs-cli/modules/control/util.go +++ b/cmd/neofs-cli/modules/control/util.go @@ -7,12 +7,21 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/refs" internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common" + "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" controlSvc "github.com/nspcc-dev/neofs-node/pkg/services/control/server" "github.com/nspcc-dev/neofs-sdk-go/client" neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto" "github.com/spf13/cobra" ) +func initControlFlags(cmd *cobra.Command) { + commonflags.InitWithoutRPC(cmd) + + ff := cmd.Flags() + ff.String(controlRPC, controlRPCDefault, controlRPCUsage) + ff.DurationP(commonflags.Timeout, commonflags.TimeoutShorthand, commonflags.TimeoutDefault, commonflags.TimeoutUsage) +} + func signRequest(cmd *cobra.Command, pk *ecdsa.PrivateKey, req controlSvc.SignedMessage) { err := controlSvc.SignMessage(pk, req) common.ExitOnErr(cmd, "could not sign request: %w", err)