2021-01-13 12:51:36 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2021-06-15 07:54:09 +00:00
|
|
|
"crypto/ecdsa"
|
2021-10-15 11:24:02 +00:00
|
|
|
"crypto/tls"
|
2021-01-15 11:55:06 +00:00
|
|
|
"fmt"
|
2021-01-13 12:51:36 +00:00
|
|
|
|
2021-12-20 10:03:29 +00:00
|
|
|
"github.com/mr-tron/base58"
|
2022-03-11 15:24:11 +00:00
|
|
|
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
2021-01-13 13:46:39 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
2021-06-15 07:54:09 +00:00
|
|
|
ircontrol "github.com/nspcc-dev/neofs-node/pkg/services/control/ir"
|
|
|
|
ircontrolsrv "github.com/nspcc-dev/neofs-node/pkg/services/control/ir/server"
|
2021-01-13 13:46:39 +00:00
|
|
|
controlSvc "github.com/nspcc-dev/neofs-node/pkg/services/control/server"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/client"
|
2022-01-26 12:11:13 +00:00
|
|
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/util/signature"
|
2021-01-13 12:51:36 +00:00
|
|
|
"github.com/spf13/cobra"
|
2021-10-15 11:24:02 +00:00
|
|
|
"github.com/spf13/viper"
|
2021-01-13 12:51:36 +00:00
|
|
|
)
|
|
|
|
|
2021-01-13 13:46:39 +00:00
|
|
|
var controlCmd = &cobra.Command{
|
|
|
|
Use: "control",
|
2021-01-13 12:51:36 +00:00
|
|
|
Short: "Operations with storage node",
|
|
|
|
Long: `Operations with storage node`,
|
2021-10-08 13:42:40 +00:00
|
|
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
2021-10-15 11:24:02 +00:00
|
|
|
ff := cmd.Flags()
|
|
|
|
|
|
|
|
_ = viper.BindPFlag(walletPath, ff.Lookup(walletPath))
|
|
|
|
_ = viper.BindPFlag(address, ff.Lookup(address))
|
|
|
|
_ = viper.BindPFlag(controlRPC, ff.Lookup(controlRPC))
|
2021-10-08 13:42:40 +00:00
|
|
|
},
|
2021-01-13 12:51:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var healthCheckCmd = &cobra.Command{
|
|
|
|
Use: "healthcheck",
|
2022-01-26 07:57:24 +00:00
|
|
|
Short: "Health check of the NeoFS node",
|
|
|
|
Long: "Health check of the NeoFS node. Checks storage node by default, use --ir flag to work with Inner Ring.",
|
2021-06-20 23:02:56 +00:00
|
|
|
Run: healthCheck,
|
2021-01-13 12:51:36 +00:00
|
|
|
}
|
|
|
|
|
2021-01-15 11:55:06 +00:00
|
|
|
var setNetmapStatusCmd = &cobra.Command{
|
|
|
|
Use: "set-status",
|
|
|
|
Short: "Set status of the storage node in NeoFS network map",
|
|
|
|
Long: "Set status of the storage node in NeoFS network map",
|
2021-06-20 23:02:56 +00:00
|
|
|
Run: setNetmapStatus,
|
2021-01-15 11:55:06 +00:00
|
|
|
}
|
|
|
|
|
2021-12-27 17:44:29 +00:00
|
|
|
var setShardModeCmd = &cobra.Command{
|
|
|
|
Use: "set-mode",
|
|
|
|
Short: "Set work mode of the shard",
|
|
|
|
Long: "Set work mode of the shard",
|
|
|
|
Run: setShardMode,
|
|
|
|
}
|
|
|
|
|
2021-12-20 10:03:29 +00:00
|
|
|
var listShardsCmd = &cobra.Command{
|
|
|
|
Use: "list",
|
|
|
|
Short: "List shards of the storage node",
|
|
|
|
Long: "List shards of the storage node",
|
|
|
|
Run: listShards,
|
|
|
|
}
|
|
|
|
|
|
|
|
var shardsCmd = &cobra.Command{
|
|
|
|
Use: "shards",
|
|
|
|
Short: "Operations with storage node's shards",
|
|
|
|
Long: "Operations with storage node's shards",
|
|
|
|
}
|
|
|
|
|
2021-01-15 11:55:06 +00:00
|
|
|
const (
|
|
|
|
netmapStatusFlag = "status"
|
|
|
|
|
2021-11-09 15:49:05 +00:00
|
|
|
netmapStatusOnline = "online"
|
|
|
|
netmapStatusOffline = "offline"
|
|
|
|
netmapStatusMaintenance = "maintenance"
|
2021-12-27 17:44:29 +00:00
|
|
|
|
2022-01-31 15:15:33 +00:00
|
|
|
shardModeFlag = "mode"
|
|
|
|
shardIDFlag = "id"
|
|
|
|
shardClearErrorsFlag = "clear-errors"
|
2021-12-27 17:44:29 +00:00
|
|
|
|
|
|
|
shardModeReadOnly = "read-only"
|
|
|
|
shardModeReadWrite = "read-write"
|
2022-03-17 11:55:25 +00:00
|
|
|
shardModeDegraded = "degraded"
|
2021-01-15 11:55:06 +00:00
|
|
|
)
|
|
|
|
|
2021-10-15 11:24:02 +00:00
|
|
|
const (
|
|
|
|
controlRPC = "endpoint"
|
|
|
|
controlRPCDefault = ""
|
|
|
|
controlRPCUsage = "remote node control address (as 'multiaddr' or '<host>:<port>')"
|
|
|
|
)
|
|
|
|
|
2021-06-15 07:54:09 +00:00
|
|
|
// control healthcheck flags
|
|
|
|
const (
|
|
|
|
healthcheckIRFlag = "ir"
|
|
|
|
)
|
|
|
|
|
|
|
|
// control healthcheck vars
|
|
|
|
var (
|
|
|
|
healthCheckIRVar bool
|
|
|
|
)
|
|
|
|
|
2021-12-27 17:44:29 +00:00
|
|
|
// control netmap vars
|
|
|
|
var (
|
|
|
|
netmapStatus string
|
|
|
|
)
|
|
|
|
|
|
|
|
// control shard vars
|
|
|
|
var (
|
|
|
|
shardMode string
|
|
|
|
shardID string
|
|
|
|
)
|
2021-01-15 11:55:06 +00:00
|
|
|
|
2021-09-27 15:36:14 +00:00
|
|
|
func initControlHealthCheckCmd() {
|
2021-10-15 11:24:02 +00:00
|
|
|
initCommonFlagsWithoutRPC(healthCheckCmd)
|
2021-01-13 12:51:36 +00:00
|
|
|
|
2021-10-15 11:24:02 +00:00
|
|
|
flags := healthCheckCmd.Flags()
|
|
|
|
|
|
|
|
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
|
|
|
|
flags.BoolVar(&healthCheckIRVar, healthcheckIRFlag, false, "Communicate with IR node")
|
2021-09-27 15:36:14 +00:00
|
|
|
}
|
|
|
|
|
2021-12-27 17:44:29 +00:00
|
|
|
func initControlSetShardModeCmd() {
|
|
|
|
initCommonFlagsWithoutRPC(setShardModeCmd)
|
|
|
|
|
|
|
|
flags := setShardModeCmd.Flags()
|
|
|
|
|
|
|
|
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
|
|
|
|
flags.StringVarP(&shardID, shardIDFlag, "", "", "ID of the shard in base58 encoding")
|
|
|
|
flags.StringVarP(&shardMode, shardModeFlag, "", "",
|
2022-03-17 11:55:25 +00:00
|
|
|
fmt.Sprintf("new shard mode keyword ('%s', '%s', '%s')",
|
2021-12-27 17:44:29 +00:00
|
|
|
shardModeReadWrite,
|
|
|
|
shardModeReadOnly,
|
2022-03-17 11:55:25 +00:00
|
|
|
shardModeDegraded,
|
2021-12-27 17:44:29 +00:00
|
|
|
),
|
|
|
|
)
|
2022-01-31 15:15:33 +00:00
|
|
|
flags.Bool(shardClearErrorsFlag, false, "Set shard error count to 0")
|
2021-12-27 17:44:29 +00:00
|
|
|
}
|
|
|
|
|
2021-12-20 10:03:29 +00:00
|
|
|
func initControlShardsListCmd() {
|
|
|
|
initCommonFlagsWithoutRPC(listShardsCmd)
|
|
|
|
|
|
|
|
flags := listShardsCmd.Flags()
|
|
|
|
|
|
|
|
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
|
|
|
|
}
|
|
|
|
|
2021-09-27 15:36:14 +00:00
|
|
|
func initControlSetNetmapStatusCmd() {
|
2021-10-15 11:24:02 +00:00
|
|
|
initCommonFlagsWithoutRPC(setNetmapStatusCmd)
|
|
|
|
|
|
|
|
flags := setNetmapStatusCmd.Flags()
|
2021-01-15 11:55:06 +00:00
|
|
|
|
2021-10-15 11:24:02 +00:00
|
|
|
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
|
|
|
|
flags.StringVarP(&netmapStatus, netmapStatusFlag, "", "",
|
2021-11-09 15:49:05 +00:00
|
|
|
fmt.Sprintf("new netmap status keyword ('%s', '%s', '%s')",
|
2021-01-15 11:55:06 +00:00
|
|
|
netmapStatusOnline,
|
|
|
|
netmapStatusOffline,
|
2021-11-09 15:49:05 +00:00
|
|
|
netmapStatusMaintenance,
|
2021-01-15 11:55:06 +00:00
|
|
|
),
|
|
|
|
)
|
2021-01-14 18:32:14 +00:00
|
|
|
|
2021-01-15 11:55:06 +00:00
|
|
|
_ = setNetmapStatusCmd.MarkFlagRequired(netmapStatusFlag)
|
2021-09-27 15:36:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func initControlDropObjectsCmd() {
|
2021-10-15 11:24:02 +00:00
|
|
|
initCommonFlagsWithoutRPC(dropObjectsCmd)
|
2021-02-21 08:33:00 +00:00
|
|
|
|
2021-10-15 11:24:02 +00:00
|
|
|
flags := dropObjectsCmd.Flags()
|
|
|
|
|
|
|
|
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
|
|
|
|
flags.StringSliceVarP(&dropObjectsList, dropObjectsFlag, "o", nil,
|
2021-02-21 08:33:00 +00:00
|
|
|
"List of object addresses to be removed in string format")
|
|
|
|
|
|
|
|
_ = dropObjectsCmd.MarkFlagRequired(dropObjectsFlag)
|
2021-09-27 15:36:14 +00:00
|
|
|
}
|
2021-06-15 07:54:09 +00:00
|
|
|
|
2021-09-27 15:36:14 +00:00
|
|
|
func initControlSnapshotCmd() {
|
2021-10-15 11:24:02 +00:00
|
|
|
initCommonFlagsWithoutRPC(snapshotCmd)
|
|
|
|
|
|
|
|
flags := snapshotCmd.Flags()
|
2021-06-28 13:28:12 +00:00
|
|
|
|
2021-10-25 15:06:10 +00:00
|
|
|
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
|
2021-10-15 11:24:02 +00:00
|
|
|
flags.BoolVar(&netmapSnapshotJSON, "json", false,
|
2021-06-28 13:28:12 +00:00
|
|
|
"print netmap structure in JSON format")
|
2021-01-14 18:32:14 +00:00
|
|
|
}
|
|
|
|
|
2021-09-27 15:36:14 +00:00
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(controlCmd)
|
|
|
|
|
2021-12-20 10:03:29 +00:00
|
|
|
shardsCmd.AddCommand(listShardsCmd)
|
2021-12-27 17:44:29 +00:00
|
|
|
shardsCmd.AddCommand(setShardModeCmd)
|
2022-01-24 12:22:47 +00:00
|
|
|
shardsCmd.AddCommand(dumpShardCmd)
|
2022-01-25 11:57:58 +00:00
|
|
|
shardsCmd.AddCommand(restoreShardCmd)
|
2021-12-20 10:03:29 +00:00
|
|
|
|
2021-09-27 15:36:14 +00:00
|
|
|
controlCmd.AddCommand(
|
|
|
|
healthCheckCmd,
|
|
|
|
setNetmapStatusCmd,
|
|
|
|
dropObjectsCmd,
|
|
|
|
snapshotCmd,
|
2021-12-20 10:03:29 +00:00
|
|
|
shardsCmd,
|
2021-09-27 15:36:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
initControlHealthCheckCmd()
|
|
|
|
initControlSetNetmapStatusCmd()
|
|
|
|
initControlDropObjectsCmd()
|
|
|
|
initControlSnapshotCmd()
|
2021-12-20 10:03:29 +00:00
|
|
|
initControlShardsListCmd()
|
2021-12-27 17:44:29 +00:00
|
|
|
initControlSetShardModeCmd()
|
2022-01-24 12:22:47 +00:00
|
|
|
initControlDumpShardCmd()
|
2022-01-25 11:57:58 +00:00
|
|
|
initControlRestoreShardCmd()
|
2021-09-27 15:36:14 +00:00
|
|
|
}
|
|
|
|
|
2021-06-20 23:02:56 +00:00
|
|
|
func healthCheck(cmd *cobra.Command, _ []string) {
|
2022-01-26 07:53:30 +00:00
|
|
|
key, err := getKeyNoGenerate()
|
2021-07-06 12:27:54 +00:00
|
|
|
exitOnErr(cmd, err)
|
2021-01-13 12:51:36 +00:00
|
|
|
|
2021-10-15 11:24:02 +00:00
|
|
|
cli, err := getControlSDKClient(key)
|
2021-07-06 12:27:54 +00:00
|
|
|
exitOnErr(cmd, err)
|
2021-06-15 07:54:09 +00:00
|
|
|
|
|
|
|
if healthCheckIRVar {
|
|
|
|
healthCheckIR(cmd, key, cli)
|
2021-06-20 23:02:56 +00:00
|
|
|
return
|
2021-06-15 07:54:09 +00:00
|
|
|
}
|
|
|
|
|
2021-01-13 13:46:39 +00:00
|
|
|
req := new(control.HealthCheckRequest)
|
2021-01-13 12:51:36 +00:00
|
|
|
|
2021-01-13 13:46:39 +00:00
|
|
|
req.SetBody(new(control.HealthCheckRequest_Body))
|
2021-01-13 12:51:36 +00:00
|
|
|
|
2021-07-06 12:27:54 +00:00
|
|
|
err = controlSvc.SignMessage(key, req)
|
2021-09-01 16:33:48 +00:00
|
|
|
exitOnErr(cmd, errf("could not sign message: %w", err))
|
2021-01-13 12:51:36 +00:00
|
|
|
|
2022-03-11 15:24:11 +00:00
|
|
|
var resp *control.HealthCheckResponse
|
|
|
|
err = cli.ExecRaw(func(client *rawclient.Client) error {
|
|
|
|
resp, err = control.HealthCheck(client, req)
|
|
|
|
return err
|
|
|
|
})
|
2021-09-01 16:33:48 +00:00
|
|
|
exitOnErr(cmd, errf("rpc error: %w", err))
|
2021-01-13 12:51:36 +00:00
|
|
|
|
|
|
|
sign := resp.GetSignature()
|
|
|
|
|
2021-07-06 12:27:54 +00:00
|
|
|
err = signature.VerifyDataWithSource(
|
|
|
|
resp,
|
|
|
|
func() ([]byte, []byte) {
|
|
|
|
return sign.GetKey(), sign.GetSign()
|
|
|
|
},
|
|
|
|
)
|
2021-09-01 16:33:48 +00:00
|
|
|
exitOnErr(cmd, errf("invalid response signature: %w", err))
|
2021-01-13 12:51:36 +00:00
|
|
|
|
2021-01-15 10:34:07 +00:00
|
|
|
cmd.Printf("Network status: %s\n", resp.GetBody().GetNetmapStatus())
|
|
|
|
cmd.Printf("Health status: %s\n", resp.GetBody().GetHealthStatus())
|
2021-01-13 12:51:36 +00:00
|
|
|
}
|
2021-01-15 11:55:06 +00:00
|
|
|
|
2022-01-13 15:01:50 +00:00
|
|
|
func healthCheckIR(cmd *cobra.Command, key *ecdsa.PrivateKey, c *client.Client) {
|
2021-06-15 07:54:09 +00:00
|
|
|
req := new(ircontrol.HealthCheckRequest)
|
|
|
|
|
|
|
|
req.SetBody(new(ircontrol.HealthCheckRequest_Body))
|
|
|
|
|
2021-07-06 12:27:54 +00:00
|
|
|
err := ircontrolsrv.SignMessage(key, req)
|
|
|
|
exitOnErr(cmd, errf("could not sign request: %w", err))
|
2021-06-15 07:54:09 +00:00
|
|
|
|
2022-03-11 15:24:11 +00:00
|
|
|
var resp *ircontrol.HealthCheckResponse
|
|
|
|
err = c.ExecRaw(func(client *rawclient.Client) error {
|
|
|
|
resp, err = ircontrol.HealthCheck(client, req)
|
|
|
|
return err
|
|
|
|
})
|
2021-09-01 16:33:48 +00:00
|
|
|
exitOnErr(cmd, errf("rpc error: %w", err))
|
2021-06-15 07:54:09 +00:00
|
|
|
|
|
|
|
sign := resp.GetSignature()
|
|
|
|
|
2021-07-06 12:27:54 +00:00
|
|
|
err = signature.VerifyDataWithSource(
|
|
|
|
resp,
|
|
|
|
func() ([]byte, []byte) {
|
|
|
|
return sign.GetKey(), sign.GetSign()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
exitOnErr(cmd, errf("invalid response signature: %w", err))
|
2021-06-15 07:54:09 +00:00
|
|
|
|
|
|
|
cmd.Printf("Health status: %s\n", resp.GetBody().GetHealthStatus())
|
|
|
|
}
|
|
|
|
|
2021-06-20 23:02:56 +00:00
|
|
|
func setNetmapStatus(cmd *cobra.Command, _ []string) {
|
2022-01-26 07:53:30 +00:00
|
|
|
key, err := getKeyNoGenerate()
|
2021-07-06 12:27:54 +00:00
|
|
|
exitOnErr(cmd, err)
|
2021-01-15 11:55:06 +00:00
|
|
|
|
|
|
|
var status control.NetmapStatus
|
|
|
|
|
|
|
|
switch netmapStatus {
|
|
|
|
default:
|
2021-07-06 12:27:54 +00:00
|
|
|
exitOnErr(cmd, fmt.Errorf("unsupported status %s", netmapStatus))
|
2021-01-15 11:55:06 +00:00
|
|
|
case netmapStatusOnline:
|
|
|
|
status = control.NetmapStatus_ONLINE
|
|
|
|
case netmapStatusOffline:
|
|
|
|
status = control.NetmapStatus_OFFLINE
|
2021-11-09 15:49:05 +00:00
|
|
|
case netmapStatusMaintenance:
|
|
|
|
status = control.NetmapStatus_MAINTENANCE
|
2021-01-15 11:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
req := new(control.SetNetmapStatusRequest)
|
|
|
|
|
|
|
|
body := new(control.SetNetmapStatusRequest_Body)
|
|
|
|
req.SetBody(body)
|
|
|
|
|
|
|
|
body.SetStatus(status)
|
|
|
|
|
2021-07-06 12:27:54 +00:00
|
|
|
err = controlSvc.SignMessage(key, req)
|
2021-09-01 16:33:48 +00:00
|
|
|
exitOnErr(cmd, errf("could not sign request: %w", err))
|
2021-01-15 11:55:06 +00:00
|
|
|
|
2021-10-15 11:24:02 +00:00
|
|
|
cli, err := getControlSDKClient(key)
|
2021-07-06 12:27:54 +00:00
|
|
|
exitOnErr(cmd, err)
|
2021-01-15 11:55:06 +00:00
|
|
|
|
2022-03-11 15:24:11 +00:00
|
|
|
var resp *control.SetNetmapStatusResponse
|
|
|
|
err = cli.ExecRaw(func(client *rawclient.Client) error {
|
|
|
|
resp, err = control.SetNetmapStatus(client, req)
|
|
|
|
return err
|
|
|
|
})
|
2021-09-01 16:33:48 +00:00
|
|
|
exitOnErr(cmd, errf("rpc error: %w", err))
|
2021-01-15 11:55:06 +00:00
|
|
|
|
|
|
|
sign := resp.GetSignature()
|
|
|
|
|
2021-07-06 12:27:54 +00:00
|
|
|
err = signature.VerifyDataWithSource(
|
|
|
|
resp,
|
|
|
|
func() ([]byte, []byte) {
|
|
|
|
return sign.GetKey(), sign.GetSign()
|
|
|
|
},
|
|
|
|
)
|
2021-09-01 16:33:48 +00:00
|
|
|
exitOnErr(cmd, errf("invalid response signature: %w", err))
|
2021-01-15 11:55:06 +00:00
|
|
|
|
|
|
|
cmd.Println("Network status update request successfully sent.")
|
|
|
|
}
|
2021-02-21 08:33:00 +00:00
|
|
|
|
|
|
|
const dropObjectsFlag = "objects"
|
|
|
|
|
|
|
|
var dropObjectsList []string
|
|
|
|
|
|
|
|
var dropObjectsCmd = &cobra.Command{
|
|
|
|
Use: "drop-objects",
|
|
|
|
Short: "Drop objects from the node's local storage",
|
|
|
|
Long: "Drop objects from the node's local storage",
|
2021-06-20 23:02:56 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2022-01-26 07:53:30 +00:00
|
|
|
key, err := getKeyNoGenerate()
|
2021-07-06 12:27:54 +00:00
|
|
|
exitOnErr(cmd, err)
|
2021-02-21 08:33:00 +00:00
|
|
|
|
|
|
|
binAddrList := make([][]byte, 0, len(dropObjectsList))
|
|
|
|
|
|
|
|
for i := range dropObjectsList {
|
2022-01-26 12:11:13 +00:00
|
|
|
a := addressSDK.NewAddress()
|
2021-02-21 08:33:00 +00:00
|
|
|
|
|
|
|
err := a.Parse(dropObjectsList[i])
|
|
|
|
if err != nil {
|
2021-07-06 12:27:54 +00:00
|
|
|
exitOnErr(cmd, fmt.Errorf("could not parse address #%d: %w", i, err))
|
2021-02-21 08:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
binAddr, err := a.Marshal()
|
2021-07-06 12:27:54 +00:00
|
|
|
exitOnErr(cmd, errf("could not marshal the address: %w", err))
|
2021-02-21 08:33:00 +00:00
|
|
|
|
|
|
|
binAddrList = append(binAddrList, binAddr)
|
|
|
|
}
|
|
|
|
|
|
|
|
req := new(control.DropObjectsRequest)
|
|
|
|
|
|
|
|
body := new(control.DropObjectsRequest_Body)
|
|
|
|
req.SetBody(body)
|
|
|
|
|
|
|
|
body.SetAddressList(binAddrList)
|
|
|
|
|
2021-07-06 12:27:54 +00:00
|
|
|
err = controlSvc.SignMessage(key, req)
|
2021-09-01 16:33:48 +00:00
|
|
|
exitOnErr(cmd, errf("could not sign request: %w", err))
|
2021-02-21 08:33:00 +00:00
|
|
|
|
2021-10-15 11:24:02 +00:00
|
|
|
cli, err := getControlSDKClient(key)
|
2021-07-06 12:27:54 +00:00
|
|
|
exitOnErr(cmd, err)
|
2021-02-21 08:33:00 +00:00
|
|
|
|
2022-03-11 15:24:11 +00:00
|
|
|
var resp *control.DropObjectsResponse
|
|
|
|
err = cli.ExecRaw(func(client *rawclient.Client) error {
|
|
|
|
resp, err = control.DropObjects(client, req)
|
|
|
|
return err
|
|
|
|
})
|
2021-09-01 16:33:48 +00:00
|
|
|
exitOnErr(cmd, errf("rpc error: %w", err))
|
2021-02-21 08:33:00 +00:00
|
|
|
|
|
|
|
sign := resp.GetSignature()
|
|
|
|
|
2021-07-06 12:27:54 +00:00
|
|
|
err = signature.VerifyDataWithSource(
|
|
|
|
resp,
|
|
|
|
func() ([]byte, []byte) {
|
|
|
|
return sign.GetKey(), sign.GetSign()
|
|
|
|
},
|
|
|
|
)
|
2021-09-01 16:33:48 +00:00
|
|
|
exitOnErr(cmd, errf("invalid response signature: %w", err))
|
2021-02-21 08:33:00 +00:00
|
|
|
|
|
|
|
cmd.Println("Objects were successfully marked to be removed.")
|
|
|
|
},
|
|
|
|
}
|
2021-06-28 13:28:12 +00:00
|
|
|
|
|
|
|
var snapshotCmd = &cobra.Command{
|
|
|
|
Use: "netmap-snapshot",
|
|
|
|
Short: "Get network map snapshot",
|
|
|
|
Long: "Get network map snapshot",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2022-01-26 07:53:30 +00:00
|
|
|
key, err := getKeyNoGenerate()
|
2021-07-06 12:27:54 +00:00
|
|
|
exitOnErr(cmd, err)
|
2021-06-28 13:28:12 +00:00
|
|
|
|
|
|
|
req := new(control.NetmapSnapshotRequest)
|
|
|
|
req.SetBody(new(control.NetmapSnapshotRequest_Body))
|
|
|
|
|
2021-07-06 12:27:54 +00:00
|
|
|
err = controlSvc.SignMessage(key, req)
|
2021-09-01 16:33:48 +00:00
|
|
|
exitOnErr(cmd, errf("could not sign request: %w", err))
|
2021-06-28 13:28:12 +00:00
|
|
|
|
2021-10-15 11:24:02 +00:00
|
|
|
cli, err := getControlSDKClient(key)
|
2021-07-06 12:27:54 +00:00
|
|
|
exitOnErr(cmd, err)
|
2021-06-28 13:28:12 +00:00
|
|
|
|
2022-03-11 15:24:11 +00:00
|
|
|
var resp *control.NetmapSnapshotResponse
|
|
|
|
err = cli.ExecRaw(func(client *rawclient.Client) error {
|
|
|
|
resp, err = control.NetmapSnapshot(client, req)
|
|
|
|
return err
|
|
|
|
})
|
2021-09-01 16:33:48 +00:00
|
|
|
exitOnErr(cmd, errf("rpc error: %w", err))
|
2021-06-28 13:28:12 +00:00
|
|
|
|
|
|
|
sign := resp.GetSignature()
|
|
|
|
|
2021-07-06 12:27:54 +00:00
|
|
|
err = signature.VerifyDataWithSource(
|
|
|
|
resp,
|
|
|
|
func() ([]byte, []byte) {
|
|
|
|
return sign.GetKey(), sign.GetSign()
|
|
|
|
},
|
|
|
|
)
|
2021-09-01 16:33:48 +00:00
|
|
|
exitOnErr(cmd, errf("invalid response signature: %w", err))
|
2021-06-28 13:28:12 +00:00
|
|
|
|
|
|
|
prettyPrintNetmap(cmd, resp.GetBody().GetNetmap(), netmapSnapshotJSON)
|
|
|
|
},
|
|
|
|
}
|
2021-10-15 11:24:02 +00:00
|
|
|
|
2021-12-20 10:03:29 +00:00
|
|
|
func listShards(cmd *cobra.Command, _ []string) {
|
2022-01-26 07:53:30 +00:00
|
|
|
key, err := getKeyNoGenerate()
|
2021-12-20 10:03:29 +00:00
|
|
|
exitOnErr(cmd, err)
|
|
|
|
|
|
|
|
req := new(control.ListShardsRequest)
|
|
|
|
req.SetBody(new(control.ListShardsRequest_Body))
|
|
|
|
|
|
|
|
err = controlSvc.SignMessage(key, req)
|
|
|
|
exitOnErr(cmd, errf("could not sign request: %w", err))
|
|
|
|
|
|
|
|
cli, err := getControlSDKClient(key)
|
|
|
|
exitOnErr(cmd, err)
|
|
|
|
|
2022-03-11 15:24:11 +00:00
|
|
|
var resp *control.ListShardsResponse
|
|
|
|
err = cli.ExecRaw(func(client *rawclient.Client) error {
|
|
|
|
resp, err = control.ListShards(client, req)
|
|
|
|
return err
|
|
|
|
})
|
2021-12-20 10:03:29 +00:00
|
|
|
exitOnErr(cmd, errf("rpc error: %w", err))
|
|
|
|
|
|
|
|
sign := resp.GetSignature()
|
|
|
|
err = signature.VerifyDataWithSource(
|
|
|
|
resp,
|
|
|
|
func() ([]byte, []byte) {
|
|
|
|
return sign.GetKey(), sign.GetSign()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
exitOnErr(cmd, errf("invalid response signature: %w", err))
|
|
|
|
|
|
|
|
prettyPrintShards(cmd, resp.GetBody().GetShards())
|
|
|
|
}
|
|
|
|
|
2021-10-15 11:24:02 +00:00
|
|
|
// getControlSDKClient is the same getSDKClient but with
|
|
|
|
// another RPC endpoint flag.
|
2022-01-13 15:01:50 +00:00
|
|
|
func getControlSDKClient(key *ecdsa.PrivateKey) (*client.Client, error) {
|
2022-03-11 15:24:11 +00:00
|
|
|
var (
|
|
|
|
c client.Client
|
|
|
|
prmInit client.PrmInit
|
|
|
|
prmDial client.PrmDial
|
|
|
|
)
|
|
|
|
|
2021-10-15 11:24:02 +00:00
|
|
|
netAddr, err := getEndpointAddress(controlRPC)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-03-11 15:24:11 +00:00
|
|
|
prmInit.SetDefaultPrivateKey(*key)
|
|
|
|
prmDial.SetServerURI(netAddr.HostAddr())
|
2021-10-15 11:24:02 +00:00
|
|
|
|
|
|
|
if netAddr.TLSEnabled() {
|
2022-03-11 15:24:11 +00:00
|
|
|
prmDial.SetTLSConfig(&tls.Config{})
|
2021-10-15 11:24:02 +00:00
|
|
|
}
|
|
|
|
|
2022-03-11 15:24:11 +00:00
|
|
|
c.Init(prmInit)
|
2021-10-15 11:24:02 +00:00
|
|
|
|
2022-03-11 15:24:11 +00:00
|
|
|
return &c, c.Dial(prmDial)
|
2021-10-15 11:24:02 +00:00
|
|
|
}
|
2021-12-20 10:03:29 +00:00
|
|
|
|
|
|
|
func prettyPrintShards(cmd *cobra.Command, ii []*control.ShardInfo) {
|
|
|
|
for _, i := range ii {
|
|
|
|
var mode string
|
|
|
|
|
|
|
|
switch i.GetMode() {
|
|
|
|
case control.ShardMode_READ_WRITE:
|
|
|
|
mode = "read-write"
|
|
|
|
case control.ShardMode_READ_ONLY:
|
|
|
|
mode = "read-only"
|
2022-03-17 11:55:25 +00:00
|
|
|
case control.ShardMode_DEGRADED:
|
|
|
|
mode = "degraded"
|
2021-12-20 10:03:29 +00:00
|
|
|
default:
|
|
|
|
mode = "unknown"
|
|
|
|
}
|
|
|
|
|
|
|
|
pathPrinter := func(name, path string) string {
|
|
|
|
if path == "" {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("%s: %s\n", name, path)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Printf("Shard %s:\nMode: %s\n"+
|
|
|
|
pathPrinter("Metabase", i.GetMetabasePath())+
|
|
|
|
pathPrinter("Blobstor", i.GetBlobstorPath())+
|
2022-01-31 15:23:19 +00:00
|
|
|
pathPrinter("Write-cache", i.GetWritecachePath())+
|
|
|
|
fmt.Sprintf("Error count: %d\n", i.GetErrorCount()),
|
2021-12-20 10:03:29 +00:00
|
|
|
base58.Encode(i.Shard_ID),
|
|
|
|
mode,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2021-12-27 17:44:29 +00:00
|
|
|
|
|
|
|
func setShardMode(cmd *cobra.Command, _ []string) {
|
2022-01-26 07:53:30 +00:00
|
|
|
key, err := getKeyNoGenerate()
|
2021-12-27 17:44:29 +00:00
|
|
|
exitOnErr(cmd, err)
|
|
|
|
|
|
|
|
var mode control.ShardMode
|
|
|
|
|
|
|
|
switch shardMode {
|
|
|
|
default:
|
|
|
|
exitOnErr(cmd, fmt.Errorf("unsupported mode %s", mode))
|
|
|
|
case shardModeReadWrite:
|
|
|
|
mode = control.ShardMode_READ_WRITE
|
|
|
|
case shardModeReadOnly:
|
|
|
|
mode = control.ShardMode_READ_ONLY
|
2022-03-17 11:55:25 +00:00
|
|
|
case shardModeDegraded:
|
|
|
|
mode = control.ShardMode_DEGRADED
|
2021-12-27 17:44:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
req := new(control.SetShardModeRequest)
|
|
|
|
|
|
|
|
body := new(control.SetShardModeRequest_Body)
|
|
|
|
req.SetBody(body)
|
|
|
|
|
|
|
|
rawID, err := base58.Decode(shardID)
|
|
|
|
exitOnErr(cmd, errf("incorrect shard ID encoding: %w", err))
|
|
|
|
|
|
|
|
body.SetMode(mode)
|
|
|
|
body.SetShardID(rawID)
|
|
|
|
|
2022-01-31 15:15:33 +00:00
|
|
|
reset, _ := cmd.Flags().GetBool(shardClearErrorsFlag)
|
|
|
|
body.ClearErrorCounter(reset)
|
|
|
|
|
2021-12-27 17:44:29 +00:00
|
|
|
err = controlSvc.SignMessage(key, req)
|
|
|
|
exitOnErr(cmd, errf("could not sign request: %w", err))
|
|
|
|
|
|
|
|
cli, err := getControlSDKClient(key)
|
|
|
|
exitOnErr(cmd, err)
|
|
|
|
|
2022-03-11 15:24:11 +00:00
|
|
|
var resp *control.SetShardModeResponse
|
|
|
|
err = cli.ExecRaw(func(client *rawclient.Client) error {
|
|
|
|
resp, err = control.SetShardMode(client, req)
|
|
|
|
return err
|
|
|
|
})
|
2021-12-27 17:44:29 +00:00
|
|
|
exitOnErr(cmd, errf("rpc error: %w", err))
|
|
|
|
|
|
|
|
sign := resp.GetSignature()
|
|
|
|
|
|
|
|
err = signature.VerifyDataWithSource(
|
|
|
|
resp,
|
|
|
|
func() ([]byte, []byte) {
|
|
|
|
return sign.GetKey(), sign.GetSign()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
exitOnErr(cmd, errf("invalid response signature: %w", err))
|
|
|
|
|
|
|
|
cmd.Println("Shard mode update request successfully sent.")
|
|
|
|
}
|