2022-05-23 16:26:27 +00:00
|
|
|
package control
|
2022-01-24 12:22:47 +00:00
|
|
|
|
|
|
|
import (
|
2022-03-11 15:24:11 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
2022-05-18 11:03:40 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
|
2022-05-18 09:22:02 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
|
2022-01-24 12:22:47 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
dumpFilepathFlag = "path"
|
|
|
|
dumpIgnoreErrorsFlag = "no-errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
var dumpShardCmd = &cobra.Command{
|
|
|
|
Use: "dump",
|
|
|
|
Short: "Dump objects from shard",
|
|
|
|
Long: "Dump objects from shard to a file",
|
|
|
|
Run: dumpShard,
|
|
|
|
}
|
|
|
|
|
|
|
|
func dumpShard(cmd *cobra.Command, _ []string) {
|
2022-05-23 16:26:27 +00:00
|
|
|
pk := getKey(cmd)
|
2022-01-24 12:22:47 +00:00
|
|
|
|
|
|
|
body := new(control.DumpShardRequest_Body)
|
2022-05-23 16:26:27 +00:00
|
|
|
body.SetShardID(getShardID(cmd))
|
2022-01-24 12:22:47 +00:00
|
|
|
|
|
|
|
p, _ := cmd.Flags().GetString(dumpFilepathFlag)
|
|
|
|
body.SetFilepath(p)
|
|
|
|
|
|
|
|
ignore, _ := cmd.Flags().GetBool(dumpIgnoreErrorsFlag)
|
|
|
|
body.SetIgnoreErrors(ignore)
|
|
|
|
|
|
|
|
req := new(control.DumpShardRequest)
|
|
|
|
req.SetBody(body)
|
|
|
|
|
2022-05-23 16:26:27 +00:00
|
|
|
signRequest(cmd, pk, req)
|
2022-01-24 12:22:47 +00:00
|
|
|
|
2022-05-23 16:26:27 +00:00
|
|
|
cli := getClient(cmd, pk)
|
2022-01-24 12:22:47 +00:00
|
|
|
|
2022-03-11 15:24:11 +00:00
|
|
|
var resp *control.DumpShardResponse
|
2022-05-23 16:26:27 +00:00
|
|
|
var err error
|
2022-03-11 15:24:11 +00:00
|
|
|
err = cli.ExecRaw(func(client *client.Client) error {
|
|
|
|
resp, err = control.DumpShard(client, req)
|
|
|
|
return err
|
|
|
|
})
|
2022-05-18 11:03:40 +00:00
|
|
|
common.ExitOnErr(cmd, "rpc error: %w", err)
|
2022-01-24 12:22:47 +00:00
|
|
|
|
2022-05-23 16:26:27 +00:00
|
|
|
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
2022-01-24 12:22:47 +00:00
|
|
|
|
|
|
|
cmd.Println("Shard has been dumped successfully.")
|
|
|
|
}
|
|
|
|
|
|
|
|
func initControlDumpShardCmd() {
|
2022-05-18 09:22:02 +00:00
|
|
|
commonflags.InitWithoutRPC(dumpShardCmd)
|
2022-01-24 12:22:47 +00:00
|
|
|
|
|
|
|
flags := dumpShardCmd.Flags()
|
|
|
|
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
|
2022-05-23 16:26:27 +00:00
|
|
|
flags.String(shardIDFlag, "", "Shard ID in base58 encoding")
|
2022-01-24 12:22:47 +00:00
|
|
|
flags.String(dumpFilepathFlag, "", "File to write objects to")
|
|
|
|
flags.Bool(dumpIgnoreErrorsFlag, false, "Skip invalid/unreadable objects")
|
|
|
|
|
|
|
|
_ = dumpShardCmd.MarkFlagRequired(shardIDFlag)
|
|
|
|
_ = dumpShardCmd.MarkFlagRequired(dumpFilepathFlag)
|
|
|
|
_ = dumpShardCmd.MarkFlagRequired(controlRPC)
|
|
|
|
}
|