From 9b65f1595aef0ebd43fedf419a3a8b96acfb2132 Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Thu, 1 Feb 2024 17:59:53 +0300 Subject: [PATCH] [#932] adm: Move `force-new-epoch` to package `netmap` Signed-off-by: Anton Nikiforov --- .../internal/modules/morph/initialize_test.go | 5 +-- .../modules/morph/{ => netmap}/epoch.go | 4 +-- .../internal/modules/morph/netmap/root.go | 36 ++++++++++++++----- .../internal/modules/morph/root.go | 19 +--------- 4 files changed, 33 insertions(+), 31 deletions(-) rename cmd/frostfs-adm/internal/modules/morph/{ => netmap}/epoch.go (93%) diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize_test.go b/cmd/frostfs-adm/internal/modules/morph/initialize_test.go index 02af6458..8b0fddf3 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_test.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize_test.go @@ -10,6 +10,7 @@ import ( "time" cmdConfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/config" + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/netmap" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/node" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/policy" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util" @@ -73,8 +74,8 @@ func testInitialize(t *testing.T, committeeSize int) { require.NoError(t, initializeSideChainCmd(initCmd, nil)) t.Run("force-new-epoch", func(t *testing.T) { - require.NoError(t, forceNewEpoch.Flags().Set(util.LocalDumpFlag, dumpPath)) - require.NoError(t, forceNewEpochCmd(forceNewEpoch, nil)) + require.NoError(t, netmap.ForceNewEpoch.Flags().Set(util.LocalDumpFlag, dumpPath)) + require.NoError(t, netmap.ForceNewEpochCmd(netmap.ForceNewEpoch, nil)) }) t.Run("set-config", func(t *testing.T) { require.NoError(t, cmdConfig.SetCmd.Flags().Set(util.LocalDumpFlag, dumpPath)) diff --git a/cmd/frostfs-adm/internal/modules/morph/epoch.go b/cmd/frostfs-adm/internal/modules/morph/netmap/epoch.go similarity index 93% rename from cmd/frostfs-adm/internal/modules/morph/epoch.go rename to cmd/frostfs-adm/internal/modules/morph/netmap/epoch.go index 69d4d315..4d64f190 100644 --- a/cmd/frostfs-adm/internal/modules/morph/epoch.go +++ b/cmd/frostfs-adm/internal/modules/morph/netmap/epoch.go @@ -1,4 +1,4 @@ -package morph +package netmap import ( "fmt" @@ -11,7 +11,7 @@ import ( "github.com/spf13/viper" ) -func forceNewEpochCmd(cmd *cobra.Command, _ []string) error { +func ForceNewEpochCmd(cmd *cobra.Command, _ []string) error { wCtx, err := util2.NewInitializeContext(cmd, viper.GetViper()) if err != nil { return fmt.Errorf("can't to initialize context: %w", err) diff --git a/cmd/frostfs-adm/internal/modules/morph/netmap/root.go b/cmd/frostfs-adm/internal/modules/morph/netmap/root.go index b8f9a61d..888b994e 100644 --- a/cmd/frostfs-adm/internal/modules/morph/netmap/root.go +++ b/cmd/frostfs-adm/internal/modules/morph/netmap/root.go @@ -6,20 +6,38 @@ import ( "github.com/spf13/viper" ) -var CandidatesCmd = &cobra.Command{ - Use: "netmap-candidates", - Short: "List netmap candidates nodes", - PreRun: func(cmd *cobra.Command, _ []string) { - _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) - _ = viper.BindPFlag(util.AlphabetWalletsFlag, cmd.Flags().Lookup(util.AlphabetWalletsFlag)) - }, - Run: listNetmapCandidatesNodes, -} +var ( + CandidatesCmd = &cobra.Command{ + Use: "netmap-candidates", + Short: "List netmap candidates nodes", + PreRun: func(cmd *cobra.Command, _ []string) { + _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) + _ = viper.BindPFlag(util.AlphabetWalletsFlag, cmd.Flags().Lookup(util.AlphabetWalletsFlag)) + }, + Run: listNetmapCandidatesNodes, + } + ForceNewEpoch = &cobra.Command{ + Use: "force-new-epoch", + Short: "Create new FrostFS epoch event in the side chain", + PreRun: func(cmd *cobra.Command, _ []string) { + _ = viper.BindPFlag(util.AlphabetWalletsFlag, cmd.Flags().Lookup(util.AlphabetWalletsFlag)) + _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) + }, + RunE: ForceNewEpochCmd, + } +) func initNetmapCandidatesCmd() { CandidatesCmd.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc) } +func initForceNewEpochCmd() { + ForceNewEpoch.Flags().String(util.AlphabetWalletsFlag, "", util.AlphabetWalletsFlagDesc) + ForceNewEpoch.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc) + ForceNewEpoch.Flags().String(util.LocalDumpFlag, "", "Path to the blocks dump file") +} + func init() { initNetmapCandidatesCmd() + initForceNewEpochCmd() } diff --git a/cmd/frostfs-adm/internal/modules/morph/root.go b/cmd/frostfs-adm/internal/modules/morph/root.go index 23c413bf..6546b6de 100644 --- a/cmd/frostfs-adm/internal/modules/morph/root.go +++ b/cmd/frostfs-adm/internal/modules/morph/root.go @@ -98,16 +98,6 @@ var ( }, } - forceNewEpoch = &cobra.Command{ - Use: "force-new-epoch", - Short: "Create new FrostFS epoch event in the side chain", - PreRun: func(cmd *cobra.Command, _ []string) { - _ = viper.BindPFlag(util.AlphabetWalletsFlag, cmd.Flags().Lookup(util.AlphabetWalletsFlag)) - _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) - }, - RunE: forceNewEpochCmd, - } - dumpContractHashesCmd = &cobra.Command{ Use: "dump-hashes", Short: "Dump deployed contract hashes", @@ -133,7 +123,7 @@ func init() { initInitCmd() initDeployCmd() initGenerateStorageCmd() - initForceNewEpochCmd() + RootCmd.AddCommand(netmap.ForceNewEpoch) RootCmd.AddCommand(node.RemoveCmd) RootCmd.AddCommand(policy.Set) RootCmd.AddCommand(policy.Dump) @@ -181,13 +171,6 @@ func initDumpContractHashesCmd() { dumpContractHashesCmd.Flags().String(customZoneFlag, "", "Custom zone to search.") } -func initForceNewEpochCmd() { - RootCmd.AddCommand(forceNewEpoch) - forceNewEpoch.Flags().String(util.AlphabetWalletsFlag, "", util.AlphabetWalletsFlagDesc) - forceNewEpoch.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc) - forceNewEpoch.Flags().String(util.LocalDumpFlag, "", "Path to the blocks dump file") -} - func initGenerateStorageCmd() { RootCmd.AddCommand(generateStorageCmd) generateStorageCmd.Flags().String(util.AlphabetWalletsFlag, "", util.AlphabetWalletsFlagDesc)