forked from TrueCloudLab/frostfs-node
[#932] adm: Move remove-nodes
to package node
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
9690bd02aa
commit
ce42547980
6 changed files with 57 additions and 45 deletions
|
@ -1,17 +1,12 @@
|
|||
package morph
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
util2 "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
@ -34,7 +29,7 @@ func forceNewEpochCmd(cmd *cobra.Command, _ []string) error {
|
|||
}
|
||||
|
||||
bw := io.NewBufBinWriter()
|
||||
if err := emitNewEpochCall(bw, wCtx, nmHash); err != nil {
|
||||
if err := util2.EmitNewEpochCall(bw, wCtx, nmHash); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -47,18 +42,3 @@ func forceNewEpochCmd(cmd *cobra.Command, _ []string) error {
|
|||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func emitNewEpochCall(bw *io.BufBinWriter, wCtx *util2.InitializeContext, nmHash util.Uint160) error {
|
||||
curr, err := unwrap.Int64(wCtx.ReadOnlyInvoker.Call(nmHash, "epoch"))
|
||||
if err != nil {
|
||||
return errors.New("can't fetch current epoch from the netmap contract")
|
||||
}
|
||||
|
||||
newEpoch := curr + 1
|
||||
wCtx.Command.Printf("Current epoch: %d, increase to %d.\n", curr, newEpoch)
|
||||
|
||||
// In NeoFS this is done via Notary contract. Here, however, we can form the
|
||||
// transaction locally.
|
||||
emit.AppCall(bw.BinWriter, nmHash, "newEpoch", callflag.All, newEpoch)
|
||||
return bw.Err
|
||||
}
|
||||
|
|
|
@ -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/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"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring"
|
||||
|
@ -88,8 +89,8 @@ func testInitialize(t *testing.T, committeeSize int) {
|
|||
require.NoError(t, err)
|
||||
|
||||
pub := hex.EncodeToString(pk.PublicKey().Bytes())
|
||||
require.NoError(t, removeNodes.Flags().Set(util.LocalDumpFlag, dumpPath))
|
||||
require.NoError(t, removeNodesCmd(removeNodes, []string{pub}))
|
||||
require.NoError(t, node.RemoveCmd.Flags().Set(util.LocalDumpFlag, dumpPath))
|
||||
require.NoError(t, node.RemoveNodesCmd(node.RemoveCmd, []string{pub}))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package morph
|
||||
package node
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
@ -15,7 +15,7 @@ import (
|
|||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func removeNodesCmd(cmd *cobra.Command, args []string) error {
|
||||
func RemoveNodesCmd(cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 0 {
|
||||
return errors.New("at least one node key must be provided")
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ func removeNodesCmd(cmd *cobra.Command, args []string) error {
|
|||
int64(netmapcontract.NodeStateOffline), nodeKeys[i].Bytes())
|
||||
}
|
||||
|
||||
if err := emitNewEpochCall(bw, wCtx, nmHash); err != nil {
|
||||
if err := util.EmitNewEpochCall(bw, wCtx, nmHash); err != nil {
|
||||
return err
|
||||
}
|
||||
|
28
cmd/frostfs-adm/internal/modules/morph/node/root.go
Normal file
28
cmd/frostfs-adm/internal/modules/morph/node/root.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package node
|
||||
|
||||
import (
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var RemoveCmd = &cobra.Command{
|
||||
Use: "remove-nodes key1 [key2 [...]]",
|
||||
Short: "Remove storage nodes from the netmap",
|
||||
Long: `Move nodes to the Offline state in the candidates list and tick an epoch to update the netmap`,
|
||||
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: RemoveNodesCmd,
|
||||
}
|
||||
|
||||
func initRemoveNodesCmd() {
|
||||
RemoveCmd.Flags().String(util.AlphabetWalletsFlag, "", util.AlphabetWalletsFlagDesc)
|
||||
RemoveCmd.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc)
|
||||
RemoveCmd.Flags().String(util.LocalDumpFlag, "", "Path to the blocks dump file")
|
||||
}
|
||||
|
||||
func init() {
|
||||
initRemoveNodesCmd()
|
||||
}
|
|
@ -7,6 +7,7 @@ import (
|
|||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/container"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/frostfsid"
|
||||
"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/notary"
|
||||
"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/proxy"
|
||||
|
@ -107,17 +108,6 @@ var (
|
|||
RunE: forceNewEpochCmd,
|
||||
}
|
||||
|
||||
removeNodes = &cobra.Command{
|
||||
Use: "remove-nodes key1 [key2 [...]]",
|
||||
Short: "Remove storage nodes from the netmap",
|
||||
Long: `Move nodes to the Offline state in the candidates list and tick an epoch to update the netmap`,
|
||||
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: removeNodesCmd,
|
||||
}
|
||||
|
||||
dumpContractHashesCmd = &cobra.Command{
|
||||
Use: "dump-hashes",
|
||||
Short: "Dump deployed contract hashes",
|
||||
|
@ -144,7 +134,7 @@ func init() {
|
|||
initDeployCmd()
|
||||
initGenerateStorageCmd()
|
||||
initForceNewEpochCmd()
|
||||
initRemoveNodesCmd()
|
||||
RootCmd.AddCommand(node.RemoveCmd)
|
||||
RootCmd.AddCommand(policy.Set)
|
||||
RootCmd.AddCommand(policy.Dump)
|
||||
initDumpContractHashesCmd()
|
||||
|
@ -191,13 +181,6 @@ func initDumpContractHashesCmd() {
|
|||
dumpContractHashesCmd.Flags().String(customZoneFlag, "", "Custom zone to search.")
|
||||
}
|
||||
|
||||
func initRemoveNodesCmd() {
|
||||
RootCmd.AddCommand(removeNodes)
|
||||
removeNodes.Flags().String(util.AlphabetWalletsFlag, "", util.AlphabetWalletsFlagDesc)
|
||||
removeNodes.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc)
|
||||
removeNodes.Flags().String(util.LocalDumpFlag, "", "Path to the blocks dump file")
|
||||
}
|
||||
|
||||
func initForceNewEpochCmd() {
|
||||
RootCmd.AddCommand(forceNewEpoch)
|
||||
forceNewEpoch.Flags().String(util.AlphabetWalletsFlag, "", util.AlphabetWalletsFlagDesc)
|
||||
|
|
|
@ -5,6 +5,11 @@ import (
|
|||
"fmt"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
@ -47,3 +52,18 @@ func ParseConfigFromNetmapContract(arr []stackitem.Item) (map[string][]byte, err
|
|||
func InvalidConfigValueErr(key string) error {
|
||||
return fmt.Errorf("invalid %s config value from netmap contract", key)
|
||||
}
|
||||
|
||||
func EmitNewEpochCall(bw *io.BufBinWriter, wCtx *InitializeContext, nmHash util.Uint160) error {
|
||||
curr, err := unwrap.Int64(wCtx.ReadOnlyInvoker.Call(nmHash, "epoch"))
|
||||
if err != nil {
|
||||
return errors.New("can't fetch current epoch from the netmap contract")
|
||||
}
|
||||
|
||||
newEpoch := curr + 1
|
||||
wCtx.Command.Printf("Current epoch: %d, increase to %d.\n", curr, newEpoch)
|
||||
|
||||
// In NeoFS this is done via Notary contract. Here, however, we can form the
|
||||
// transaction locally.
|
||||
emit.AppCall(bw.BinWriter, nmHash, "newEpoch", callflag.All, newEpoch)
|
||||
return bw.Err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue