forked from TrueCloudLab/frostfs-node
Move to frostfs-node
Signed-off-by: Pavel Karpy <p.karpy@yadro.com>
This commit is contained in:
parent
42554a9298
commit
923f84722a
934 changed files with 3470 additions and 3451 deletions
59
cmd/frostfs-cli/modules/control/drop_objects.go
Normal file
59
cmd/frostfs-cli/modules/control/drop_objects.go
Normal file
|
@ -0,0 +1,59 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
rawclient "github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
||||
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const dropObjectsFlag = "objects"
|
||||
|
||||
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",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
pk := key.Get(cmd)
|
||||
|
||||
dropObjectsList, _ := cmd.Flags().GetStringSlice(dropObjectsFlag)
|
||||
binAddrList := make([][]byte, len(dropObjectsList))
|
||||
|
||||
for i := range dropObjectsList {
|
||||
binAddrList[i] = []byte(dropObjectsList[i])
|
||||
}
|
||||
|
||||
body := new(control.DropObjectsRequest_Body)
|
||||
body.SetAddressList(binAddrList)
|
||||
|
||||
req := new(control.DropObjectsRequest)
|
||||
req.SetBody(body)
|
||||
|
||||
signRequest(cmd, pk, req)
|
||||
|
||||
cli := getClient(cmd, pk)
|
||||
|
||||
var resp *control.DropObjectsResponse
|
||||
var err error
|
||||
err = cli.ExecRaw(func(client *rawclient.Client) error {
|
||||
resp, err = control.DropObjects(client, req)
|
||||
return err
|
||||
})
|
||||
common.ExitOnErr(cmd, "rpc error: %w", err)
|
||||
|
||||
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
||||
|
||||
cmd.Println("Objects were successfully marked to be removed.")
|
||||
},
|
||||
}
|
||||
|
||||
func initControlDropObjectsCmd() {
|
||||
initControlFlags(dropObjectsCmd)
|
||||
|
||||
flags := dropObjectsCmd.Flags()
|
||||
flags.StringSliceP(dropObjectsFlag, "o", nil,
|
||||
"List of object addresses to be removed in string format")
|
||||
|
||||
_ = dropObjectsCmd.MarkFlagRequired(dropObjectsFlag)
|
||||
}
|
53
cmd/frostfs-cli/modules/control/evacuate_shard.go
Normal file
53
cmd/frostfs-cli/modules/control/evacuate_shard.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
||||
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var evacuateShardCmd = &cobra.Command{
|
||||
Use: "evacuate",
|
||||
Short: "Evacuate objects from shard",
|
||||
Long: "Evacuate objects from shard to other shards",
|
||||
Run: evacuateShard,
|
||||
}
|
||||
|
||||
func evacuateShard(cmd *cobra.Command, _ []string) {
|
||||
pk := key.Get(cmd)
|
||||
|
||||
req := &control.EvacuateShardRequest{Body: new(control.EvacuateShardRequest_Body)}
|
||||
req.Body.Shard_ID = getShardIDList(cmd)
|
||||
req.Body.IgnoreErrors, _ = cmd.Flags().GetBool(dumpIgnoreErrorsFlag)
|
||||
|
||||
signRequest(cmd, pk, req)
|
||||
|
||||
cli := getClient(cmd, pk)
|
||||
|
||||
var resp *control.EvacuateShardResponse
|
||||
var err error
|
||||
err = cli.ExecRaw(func(client *client.Client) error {
|
||||
resp, err = control.EvacuateShard(client, req)
|
||||
return err
|
||||
})
|
||||
common.ExitOnErr(cmd, "rpc error: %w", err)
|
||||
|
||||
cmd.Printf("Objects moved: %d\n", resp.GetBody().GetCount())
|
||||
|
||||
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
||||
|
||||
cmd.Println("Shard has successfully been evacuated.")
|
||||
}
|
||||
|
||||
func initControlEvacuateShardCmd() {
|
||||
initControlFlags(evacuateShardCmd)
|
||||
|
||||
flags := evacuateShardCmd.Flags()
|
||||
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")
|
||||
|
||||
evacuateShardCmd.MarkFlagsMutuallyExclusive(shardIDFlag, shardAllFlag)
|
||||
}
|
49
cmd/frostfs-cli/modules/control/flush_cache.go
Normal file
49
cmd/frostfs-cli/modules/control/flush_cache.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
||||
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var flushCacheCmd = &cobra.Command{
|
||||
Use: "flush-cache",
|
||||
Short: "Flush objects from the write-cache to the main storage",
|
||||
Long: "Flush objects from the write-cache to the main storage",
|
||||
Run: flushCache,
|
||||
}
|
||||
|
||||
func flushCache(cmd *cobra.Command, _ []string) {
|
||||
pk := key.Get(cmd)
|
||||
|
||||
req := &control.FlushCacheRequest{Body: new(control.FlushCacheRequest_Body)}
|
||||
req.Body.Shard_ID = getShardIDList(cmd)
|
||||
|
||||
signRequest(cmd, pk, req)
|
||||
|
||||
cli := getClient(cmd, pk)
|
||||
|
||||
var resp *control.FlushCacheResponse
|
||||
var err error
|
||||
err = cli.ExecRaw(func(client *client.Client) error {
|
||||
resp, err = control.FlushCache(client, req)
|
||||
return err
|
||||
})
|
||||
common.ExitOnErr(cmd, "rpc error: %w", err)
|
||||
|
||||
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
||||
|
||||
cmd.Println("Write-cache has been flushed.")
|
||||
}
|
||||
|
||||
func initControlFlushCacheCmd() {
|
||||
initControlFlags(flushCacheCmd)
|
||||
|
||||
ff := flushCacheCmd.Flags()
|
||||
ff.StringSlice(shardIDFlag, nil, "List of shard IDs in base58 encoding")
|
||||
ff.Bool(shardAllFlag, false, "Process all shards")
|
||||
|
||||
flushCacheCmd.MarkFlagsMutuallyExclusive(shardIDFlag, shardAllFlag)
|
||||
}
|
81
cmd/frostfs-cli/modules/control/healthcheck.go
Normal file
81
cmd/frostfs-cli/modules/control/healthcheck.go
Normal file
|
@ -0,0 +1,81 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
|
||||
rawclient "github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
||||
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
|
||||
ircontrol "github.com/TrueCloudLab/frostfs-node/pkg/services/control/ir"
|
||||
ircontrolsrv "github.com/TrueCloudLab/frostfs-node/pkg/services/control/ir/server"
|
||||
"github.com/TrueCloudLab/frostfs-sdk-go/client"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const (
|
||||
healthcheckIRFlag = "ir"
|
||||
)
|
||||
|
||||
var healthCheckCmd = &cobra.Command{
|
||||
Use: "healthcheck",
|
||||
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.",
|
||||
Run: healthCheck,
|
||||
}
|
||||
|
||||
func initControlHealthCheckCmd() {
|
||||
initControlFlags(healthCheckCmd)
|
||||
|
||||
flags := healthCheckCmd.Flags()
|
||||
flags.Bool(healthcheckIRFlag, false, "Communicate with IR node")
|
||||
}
|
||||
|
||||
func healthCheck(cmd *cobra.Command, _ []string) {
|
||||
pk := key.Get(cmd)
|
||||
|
||||
cli := getClient(cmd, pk)
|
||||
|
||||
if isIR, _ := cmd.Flags().GetBool(healthcheckIRFlag); isIR {
|
||||
healthCheckIR(cmd, pk, cli)
|
||||
return
|
||||
}
|
||||
|
||||
req := new(control.HealthCheckRequest)
|
||||
req.SetBody(new(control.HealthCheckRequest_Body))
|
||||
|
||||
signRequest(cmd, pk, req)
|
||||
|
||||
var resp *control.HealthCheckResponse
|
||||
var err error
|
||||
err = cli.ExecRaw(func(client *rawclient.Client) error {
|
||||
resp, err = control.HealthCheck(client, req)
|
||||
return err
|
||||
})
|
||||
common.ExitOnErr(cmd, "rpc error: %w", err)
|
||||
|
||||
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
||||
|
||||
cmd.Printf("Network status: %s\n", resp.GetBody().GetNetmapStatus())
|
||||
cmd.Printf("Health status: %s\n", resp.GetBody().GetHealthStatus())
|
||||
}
|
||||
|
||||
func healthCheckIR(cmd *cobra.Command, key *ecdsa.PrivateKey, c *client.Client) {
|
||||
req := new(ircontrol.HealthCheckRequest)
|
||||
|
||||
req.SetBody(new(ircontrol.HealthCheckRequest_Body))
|
||||
|
||||
err := ircontrolsrv.SignMessage(key, req)
|
||||
common.ExitOnErr(cmd, "could not sign request: %w", err)
|
||||
|
||||
var resp *ircontrol.HealthCheckResponse
|
||||
err = c.ExecRaw(func(client *rawclient.Client) error {
|
||||
resp, err = ircontrol.HealthCheck(client, req)
|
||||
return err
|
||||
})
|
||||
common.ExitOnErr(cmd, "rpc error: %w", err)
|
||||
|
||||
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
||||
|
||||
cmd.Printf("Health status: %s\n", resp.GetBody().GetHealthStatus())
|
||||
}
|
43
cmd/frostfs-cli/modules/control/root.go
Normal file
43
cmd/frostfs-cli/modules/control/root.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var Cmd = &cobra.Command{
|
||||
Use: "control",
|
||||
Short: "Operations with storage node",
|
||||
Long: `Operations with storage node`,
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
ff := cmd.Flags()
|
||||
|
||||
_ = 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))
|
||||
},
|
||||
}
|
||||
|
||||
const (
|
||||
controlRPC = "endpoint"
|
||||
controlRPCDefault = ""
|
||||
controlRPCUsage = "Remote node control address (as 'multiaddr' or '<host>:<port>')"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Cmd.AddCommand(
|
||||
healthCheckCmd,
|
||||
setNetmapStatusCmd,
|
||||
dropObjectsCmd,
|
||||
shardsCmd,
|
||||
synchronizeTreeCmd,
|
||||
)
|
||||
|
||||
initControlHealthCheckCmd()
|
||||
initControlSetNetmapStatusCmd()
|
||||
initControlDropObjectsCmd()
|
||||
initControlShardsCmd()
|
||||
initControlSynchronizeTreeCmd()
|
||||
}
|
94
cmd/frostfs-cli/modules/control/set_netmap_status.go
Normal file
94
cmd/frostfs-cli/modules/control/set_netmap_status.go
Normal file
|
@ -0,0 +1,94 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
rawclient "github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
||||
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const (
|
||||
netmapStatusFlag = "status"
|
||||
|
||||
netmapStatusOnline = "online"
|
||||
netmapStatusOffline = "offline"
|
||||
netmapStatusMaintenance = "maintenance"
|
||||
)
|
||||
|
||||
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",
|
||||
Run: setNetmapStatus,
|
||||
}
|
||||
|
||||
func initControlSetNetmapStatusCmd() {
|
||||
initControlFlags(setNetmapStatusCmd)
|
||||
|
||||
flags := setNetmapStatusCmd.Flags()
|
||||
flags.String(netmapStatusFlag, "",
|
||||
fmt.Sprintf("New netmap status keyword ('%s', '%s', '%s')",
|
||||
netmapStatusOnline,
|
||||
netmapStatusOffline,
|
||||
netmapStatusMaintenance,
|
||||
),
|
||||
)
|
||||
|
||||
_ = setNetmapStatusCmd.MarkFlagRequired(netmapStatusFlag)
|
||||
|
||||
flags.BoolP(commonflags.ForceFlag, commonflags.ForceFlagShorthand, false,
|
||||
"Force turning to local maintenance")
|
||||
}
|
||||
|
||||
func setNetmapStatus(cmd *cobra.Command, _ []string) {
|
||||
pk := key.Get(cmd)
|
||||
body := new(control.SetNetmapStatusRequest_Body)
|
||||
force, _ := cmd.Flags().GetBool(commonflags.ForceFlag)
|
||||
|
||||
printIgnoreForce := func(st control.NetmapStatus) {
|
||||
if force {
|
||||
common.PrintVerbose("Ignore --%s flag for %s state.", commonflags.ForceFlag, st)
|
||||
}
|
||||
}
|
||||
|
||||
switch st, _ := cmd.Flags().GetString(netmapStatusFlag); st {
|
||||
default:
|
||||
common.ExitOnErr(cmd, "", fmt.Errorf("unsupported status %s", st))
|
||||
case netmapStatusOnline:
|
||||
body.SetStatus(control.NetmapStatus_ONLINE)
|
||||
printIgnoreForce(control.NetmapStatus_ONLINE)
|
||||
case netmapStatusOffline:
|
||||
body.SetStatus(control.NetmapStatus_OFFLINE)
|
||||
printIgnoreForce(control.NetmapStatus_OFFLINE)
|
||||
case netmapStatusMaintenance:
|
||||
body.SetStatus(control.NetmapStatus_MAINTENANCE)
|
||||
|
||||
if force {
|
||||
body.SetForceMaintenance()
|
||||
common.PrintVerbose("Local maintenance will be forced.")
|
||||
}
|
||||
}
|
||||
|
||||
req := new(control.SetNetmapStatusRequest)
|
||||
req.SetBody(body)
|
||||
|
||||
signRequest(cmd, pk, req)
|
||||
|
||||
cli := getClient(cmd, pk)
|
||||
|
||||
var resp *control.SetNetmapStatusResponse
|
||||
var err error
|
||||
err = cli.ExecRaw(func(client *rawclient.Client) error {
|
||||
resp, err = control.SetNetmapStatus(client, req)
|
||||
return err
|
||||
})
|
||||
common.ExitOnErr(cmd, "rpc error: %w", err)
|
||||
|
||||
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
||||
|
||||
cmd.Println("Network status update request successfully sent.")
|
||||
}
|
27
cmd/frostfs-cli/modules/control/shards.go
Normal file
27
cmd/frostfs-cli/modules/control/shards.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var shardsCmd = &cobra.Command{
|
||||
Use: "shards",
|
||||
Short: "Operations with storage node's shards",
|
||||
Long: "Operations with storage node's shards",
|
||||
}
|
||||
|
||||
func initControlShardsCmd() {
|
||||
shardsCmd.AddCommand(listShardsCmd)
|
||||
shardsCmd.AddCommand(setShardModeCmd)
|
||||
shardsCmd.AddCommand(dumpShardCmd)
|
||||
shardsCmd.AddCommand(restoreShardCmd)
|
||||
shardsCmd.AddCommand(evacuateShardCmd)
|
||||
shardsCmd.AddCommand(flushCacheCmd)
|
||||
|
||||
initControlShardsListCmd()
|
||||
initControlSetShardModeCmd()
|
||||
initControlDumpShardCmd()
|
||||
initControlRestoreShardCmd()
|
||||
initControlEvacuateShardCmd()
|
||||
initControlFlushCacheCmd()
|
||||
}
|
66
cmd/frostfs-cli/modules/control/shards_dump.go
Normal file
66
cmd/frostfs-cli/modules/control/shards_dump.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
||||
"github.com/TrueCloudLab/frostfs-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) {
|
||||
pk := key.Get(cmd)
|
||||
|
||||
body := new(control.DumpShardRequest_Body)
|
||||
body.SetShardID(getShardID(cmd))
|
||||
|
||||
p, _ := cmd.Flags().GetString(dumpFilepathFlag)
|
||||
body.SetFilepath(p)
|
||||
|
||||
ignore, _ := cmd.Flags().GetBool(dumpIgnoreErrorsFlag)
|
||||
body.SetIgnoreErrors(ignore)
|
||||
|
||||
req := new(control.DumpShardRequest)
|
||||
req.SetBody(body)
|
||||
|
||||
signRequest(cmd, pk, req)
|
||||
|
||||
cli := getClient(cmd, pk)
|
||||
|
||||
var resp *control.DumpShardResponse
|
||||
var err error
|
||||
err = cli.ExecRaw(func(client *client.Client) error {
|
||||
resp, err = control.DumpShard(client, req)
|
||||
return err
|
||||
})
|
||||
common.ExitOnErr(cmd, "rpc error: %w", err)
|
||||
|
||||
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
||||
|
||||
cmd.Println("Shard has been dumped successfully.")
|
||||
}
|
||||
|
||||
func initControlDumpShardCmd() {
|
||||
initControlFlags(dumpShardCmd)
|
||||
|
||||
flags := dumpShardCmd.Flags()
|
||||
flags.String(shardIDFlag, "", "Shard ID in base58 encoding")
|
||||
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)
|
||||
}
|
117
cmd/frostfs-cli/modules/control/shards_list.go
Normal file
117
cmd/frostfs-cli/modules/control/shards_list.go
Normal file
|
@ -0,0 +1,117 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
rawclient "github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
||||
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
|
||||
"github.com/mr-tron/base58"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var listShardsCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List shards of the storage node",
|
||||
Long: "List shards of the storage node",
|
||||
Run: listShards,
|
||||
}
|
||||
|
||||
func initControlShardsListCmd() {
|
||||
initControlFlags(listShardsCmd)
|
||||
|
||||
flags := listShardsCmd.Flags()
|
||||
flags.Bool(commonflags.JSON, false, "Print shard info as a JSON array")
|
||||
}
|
||||
|
||||
func listShards(cmd *cobra.Command, _ []string) {
|
||||
pk := key.Get(cmd)
|
||||
|
||||
req := new(control.ListShardsRequest)
|
||||
req.SetBody(new(control.ListShardsRequest_Body))
|
||||
|
||||
signRequest(cmd, pk, req)
|
||||
|
||||
cli := getClient(cmd, pk)
|
||||
|
||||
var resp *control.ListShardsResponse
|
||||
var err error
|
||||
err = cli.ExecRaw(func(client *rawclient.Client) error {
|
||||
resp, err = control.ListShards(client, req)
|
||||
return err
|
||||
})
|
||||
common.ExitOnErr(cmd, "rpc error: %w", err)
|
||||
|
||||
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
||||
|
||||
isJSON, _ := cmd.Flags().GetBool(commonflags.JSON)
|
||||
if isJSON {
|
||||
prettyPrintShardsJSON(cmd, resp.GetBody().GetShards())
|
||||
} else {
|
||||
prettyPrintShards(cmd, resp.GetBody().GetShards())
|
||||
}
|
||||
}
|
||||
|
||||
func prettyPrintShardsJSON(cmd *cobra.Command, ii []*control.ShardInfo) {
|
||||
out := make([]map[string]interface{}, 0, len(ii))
|
||||
for _, i := range ii {
|
||||
out = append(out, map[string]interface{}{
|
||||
"shard_id": base58.Encode(i.Shard_ID),
|
||||
"mode": shardModeToString(i.GetMode()),
|
||||
"metabase": i.GetMetabasePath(),
|
||||
"blobstor": i.GetBlobstor(),
|
||||
"writecache": i.GetWritecachePath(),
|
||||
"error_count": i.GetErrorCount(),
|
||||
})
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer(nil)
|
||||
enc := json.NewEncoder(buf)
|
||||
enc.SetIndent("", " ")
|
||||
common.ExitOnErr(cmd, "cannot shard info to JSON: %w", enc.Encode(out))
|
||||
|
||||
cmd.Print(buf.String()) // pretty printer emits newline, to no need for Println
|
||||
}
|
||||
|
||||
func prettyPrintShards(cmd *cobra.Command, ii []*control.ShardInfo) {
|
||||
for _, i := range ii {
|
||||
pathPrinter := func(name, path string) string {
|
||||
if path == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s: %s\n", name, path)
|
||||
}
|
||||
|
||||
var sb strings.Builder
|
||||
sb.WriteString("Blobstor:\n")
|
||||
for j, info := range i.GetBlobstor() {
|
||||
sb.WriteString(fmt.Sprintf("\tPath %d: %s\n\tType %d: %s\n",
|
||||
j, info.GetPath(), j, info.GetType()))
|
||||
}
|
||||
|
||||
cmd.Printf("Shard %s:\nMode: %s\n"+
|
||||
pathPrinter("Metabase", i.GetMetabasePath())+
|
||||
sb.String()+
|
||||
pathPrinter("Write-cache", i.GetWritecachePath())+
|
||||
pathPrinter("Pilorama", i.GetPiloramaPath())+
|
||||
fmt.Sprintf("Error count: %d\n", i.GetErrorCount()),
|
||||
base58.Encode(i.Shard_ID),
|
||||
shardModeToString(i.GetMode()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func shardModeToString(m control.ShardMode) string {
|
||||
strMode, ok := lookUpShardModeString(m)
|
||||
if ok {
|
||||
return strMode
|
||||
}
|
||||
|
||||
return "unknown"
|
||||
}
|
66
cmd/frostfs-cli/modules/control/shards_restore.go
Normal file
66
cmd/frostfs-cli/modules/control/shards_restore.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
||||
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const (
|
||||
restoreFilepathFlag = "path"
|
||||
restoreIgnoreErrorsFlag = "no-errors"
|
||||
)
|
||||
|
||||
var restoreShardCmd = &cobra.Command{
|
||||
Use: "restore",
|
||||
Short: "Restore objects from shard",
|
||||
Long: "Restore objects from shard to a file",
|
||||
Run: restoreShard,
|
||||
}
|
||||
|
||||
func restoreShard(cmd *cobra.Command, _ []string) {
|
||||
pk := key.Get(cmd)
|
||||
|
||||
body := new(control.RestoreShardRequest_Body)
|
||||
body.SetShardID(getShardID(cmd))
|
||||
|
||||
p, _ := cmd.Flags().GetString(restoreFilepathFlag)
|
||||
body.SetFilepath(p)
|
||||
|
||||
ignore, _ := cmd.Flags().GetBool(restoreIgnoreErrorsFlag)
|
||||
body.SetIgnoreErrors(ignore)
|
||||
|
||||
req := new(control.RestoreShardRequest)
|
||||
req.SetBody(body)
|
||||
|
||||
signRequest(cmd, pk, req)
|
||||
|
||||
cli := getClient(cmd, pk)
|
||||
|
||||
var resp *control.RestoreShardResponse
|
||||
var err error
|
||||
err = cli.ExecRaw(func(client *client.Client) error {
|
||||
resp, err = control.RestoreShard(client, req)
|
||||
return err
|
||||
})
|
||||
common.ExitOnErr(cmd, "rpc error: %w", err)
|
||||
|
||||
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
||||
|
||||
cmd.Println("Shard has been restored successfully.")
|
||||
}
|
||||
|
||||
func initControlRestoreShardCmd() {
|
||||
initControlFlags(restoreShardCmd)
|
||||
|
||||
flags := restoreShardCmd.Flags()
|
||||
flags.String(shardIDFlag, "", "Shard ID in base58 encoding")
|
||||
flags.String(restoreFilepathFlag, "", "File to read objects from")
|
||||
flags.Bool(restoreIgnoreErrorsFlag, false, "Skip invalid/unreadable objects")
|
||||
|
||||
_ = restoreShardCmd.MarkFlagRequired(shardIDFlag)
|
||||
_ = restoreShardCmd.MarkFlagRequired(restoreFilepathFlag)
|
||||
_ = restoreShardCmd.MarkFlagRequired(controlRPC)
|
||||
}
|
177
cmd/frostfs-cli/modules/control/shards_set_mode.go
Normal file
177
cmd/frostfs-cli/modules/control/shards_set_mode.go
Normal file
|
@ -0,0 +1,177 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
rawclient "github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
||||
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
|
||||
"github.com/mr-tron/base58"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const (
|
||||
shardModeFlag = "mode"
|
||||
shardIDFlag = "id"
|
||||
shardAllFlag = "all"
|
||||
shardClearErrorsFlag = "clear-errors"
|
||||
)
|
||||
|
||||
// maps string command input to control.ShardMode. To support new mode, it's
|
||||
// enough to add the map entry. Modes are automatically printed in command help
|
||||
// messages.
|
||||
var mShardModes = map[string]struct {
|
||||
val control.ShardMode
|
||||
|
||||
// flag to support shard mode implicitly without help message. The flag is set
|
||||
// for values which are not expected to be set by users but still supported
|
||||
// for developers.
|
||||
unsafe bool
|
||||
}{
|
||||
"read-only": {val: control.ShardMode_READ_ONLY},
|
||||
"read-write": {val: control.ShardMode_READ_WRITE},
|
||||
"degraded-read-write": {val: control.ShardMode_DEGRADED, unsafe: true},
|
||||
"degraded-read-only": {val: control.ShardMode_DEGRADED_READ_ONLY},
|
||||
}
|
||||
|
||||
// iterates over string representations of safe supported shard modes. Safe means
|
||||
// modes which are expected to be used by any user. All other supported modes
|
||||
// are for developers only.
|
||||
func iterateSafeShardModes(f func(string)) {
|
||||
for strMode, mode := range mShardModes {
|
||||
if !mode.unsafe {
|
||||
f(strMode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// looks up for supported control.ShardMode represented by the given string.
|
||||
// Returns false if no corresponding mode exists.
|
||||
func lookUpShardModeFromString(str string) (control.ShardMode, bool) {
|
||||
mode, ok := mShardModes[str]
|
||||
if !ok {
|
||||
return control.ShardMode_SHARD_MODE_UNDEFINED, false
|
||||
}
|
||||
|
||||
return mode.val, true
|
||||
}
|
||||
|
||||
// looks up for string representation of supported shard mode. Returns false
|
||||
// if mode is not supported.
|
||||
func lookUpShardModeString(m control.ShardMode) (string, bool) {
|
||||
for strMode, mode := range mShardModes {
|
||||
if mode.val == m {
|
||||
return strMode, true
|
||||
}
|
||||
}
|
||||
|
||||
return "", false
|
||||
}
|
||||
|
||||
var setShardModeCmd = &cobra.Command{
|
||||
Use: "set-mode",
|
||||
Short: "Set work mode of the shard",
|
||||
Long: "Set work mode of the shard",
|
||||
Run: setShardMode,
|
||||
}
|
||||
|
||||
func initControlSetShardModeCmd() {
|
||||
initControlFlags(setShardModeCmd)
|
||||
|
||||
flags := setShardModeCmd.Flags()
|
||||
flags.StringSlice(shardIDFlag, nil, "List of shard IDs in base58 encoding")
|
||||
flags.Bool(shardAllFlag, false, "Process all shards")
|
||||
|
||||
modes := make([]string, 0)
|
||||
|
||||
iterateSafeShardModes(func(strMode string) {
|
||||
modes = append(modes, "'"+strMode+"'")
|
||||
})
|
||||
|
||||
flags.String(shardModeFlag, "",
|
||||
fmt.Sprintf("New shard mode (%s)", strings.Join(modes, ", ")),
|
||||
)
|
||||
flags.Bool(shardClearErrorsFlag, false, "Set shard error count to 0")
|
||||
|
||||
setShardModeCmd.MarkFlagsMutuallyExclusive(shardIDFlag, shardAllFlag)
|
||||
}
|
||||
|
||||
func setShardMode(cmd *cobra.Command, _ []string) {
|
||||
pk := key.Get(cmd)
|
||||
|
||||
strMode, _ := cmd.Flags().GetString(shardModeFlag)
|
||||
|
||||
mode, ok := lookUpShardModeFromString(strMode)
|
||||
if !ok {
|
||||
common.ExitOnErr(cmd, "", fmt.Errorf("unsupported mode %s", strMode))
|
||||
}
|
||||
|
||||
req := new(control.SetShardModeRequest)
|
||||
|
||||
body := new(control.SetShardModeRequest_Body)
|
||||
req.SetBody(body)
|
||||
|
||||
body.SetMode(mode)
|
||||
body.SetShardIDList(getShardIDList(cmd))
|
||||
|
||||
reset, _ := cmd.Flags().GetBool(shardClearErrorsFlag)
|
||||
body.ClearErrorCounter(reset)
|
||||
|
||||
signRequest(cmd, pk, req)
|
||||
|
||||
cli := getClient(cmd, pk)
|
||||
|
||||
var resp *control.SetShardModeResponse
|
||||
var err error
|
||||
err = cli.ExecRaw(func(client *rawclient.Client) error {
|
||||
resp, err = control.SetShardMode(client, req)
|
||||
return err
|
||||
})
|
||||
common.ExitOnErr(cmd, "rpc error: %w", err)
|
||||
|
||||
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
||||
|
||||
cmd.Println("Shard mode update request successfully sent.")
|
||||
}
|
||||
|
||||
func getShardID(cmd *cobra.Command) []byte {
|
||||
sid, _ := cmd.Flags().GetString(shardIDFlag)
|
||||
raw, err := base58.Decode(sid)
|
||||
common.ExitOnErr(cmd, "incorrect shard ID encoding: %w", err)
|
||||
return raw
|
||||
}
|
||||
|
||||
func getShardIDList(cmd *cobra.Command) [][]byte {
|
||||
all, _ := cmd.Flags().GetBool(shardAllFlag)
|
||||
if all {
|
||||
return nil
|
||||
}
|
||||
|
||||
sidList, _ := cmd.Flags().GetStringSlice(shardIDFlag)
|
||||
if len(sidList) == 0 {
|
||||
common.ExitOnErr(cmd, "", fmt.Errorf("either --%s or --%s flag must be provided", shardIDFlag, shardAllFlag))
|
||||
}
|
||||
|
||||
// We can sort the ID list and perform this check without additional allocations,
|
||||
// but preserving the user order is a nice thing to have.
|
||||
// Also, this is a CLI, we don't care too much about this.
|
||||
seen := make(map[string]struct{})
|
||||
for i := range sidList {
|
||||
if _, ok := seen[sidList[i]]; ok {
|
||||
common.ExitOnErr(cmd, "", fmt.Errorf("duplicated shard IDs: %s", sidList[i]))
|
||||
}
|
||||
seen[sidList[i]] = struct{}{}
|
||||
}
|
||||
|
||||
res := make([][]byte, 0, len(sidList))
|
||||
for i := range sidList {
|
||||
raw, err := base58.Decode(sidList[i])
|
||||
common.ExitOnErr(cmd, "incorrect shard ID encoding: %w", err)
|
||||
|
||||
res = append(res, raw)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
78
cmd/frostfs-cli/modules/control/synchronize_tree.go
Normal file
78
cmd/frostfs-cli/modules/control/synchronize_tree.go
Normal file
|
@ -0,0 +1,78 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
|
||||
rawclient "github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
||||
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
|
||||
controlSvc "github.com/TrueCloudLab/frostfs-node/pkg/services/control/server"
|
||||
cid "github.com/TrueCloudLab/frostfs-sdk-go/container/id"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const (
|
||||
synchronizeTreeIDFlag = "tree-id"
|
||||
synchronizeTreeHeightFlag = "height"
|
||||
)
|
||||
|
||||
var synchronizeTreeCmd = &cobra.Command{
|
||||
Use: "synchronize-tree",
|
||||
Short: "Synchronize log for the tree",
|
||||
Long: "Synchronize log for the tree in an object tree service.",
|
||||
Run: synchronizeTree,
|
||||
}
|
||||
|
||||
func initControlSynchronizeTreeCmd() {
|
||||
initControlFlags(synchronizeTreeCmd)
|
||||
|
||||
flags := synchronizeTreeCmd.Flags()
|
||||
flags.String(commonflags.CIDFlag, "", commonflags.CIDFlagUsage)
|
||||
flags.String(synchronizeTreeIDFlag, "", "Tree ID")
|
||||
flags.Uint64(synchronizeTreeHeightFlag, 0, "Starting height")
|
||||
}
|
||||
|
||||
func synchronizeTree(cmd *cobra.Command, _ []string) {
|
||||
pk := key.Get(cmd)
|
||||
|
||||
var cnr cid.ID
|
||||
cidStr, _ := cmd.Flags().GetString(commonflags.CIDFlag)
|
||||
common.ExitOnErr(cmd, "can't decode container ID: %w", cnr.DecodeString(cidStr))
|
||||
|
||||
treeID, _ := cmd.Flags().GetString("tree-id")
|
||||
if treeID == "" {
|
||||
common.ExitOnErr(cmd, "", errors.New("tree ID must not be empty"))
|
||||
}
|
||||
|
||||
height, _ := cmd.Flags().GetUint64("height")
|
||||
|
||||
rawCID := make([]byte, sha256.Size)
|
||||
cnr.Encode(rawCID)
|
||||
|
||||
req := &control.SynchronizeTreeRequest{
|
||||
Body: &control.SynchronizeTreeRequest_Body{
|
||||
ContainerId: rawCID,
|
||||
TreeId: treeID,
|
||||
Height: height,
|
||||
},
|
||||
}
|
||||
|
||||
err := controlSvc.SignMessage(pk, req)
|
||||
common.ExitOnErr(cmd, "could not sign request: %w", err)
|
||||
|
||||
cli := getClient(cmd, pk)
|
||||
|
||||
var resp *control.SynchronizeTreeResponse
|
||||
err = cli.ExecRaw(func(client *rawclient.Client) error {
|
||||
resp, err = control.SynchronizeTree(client, req)
|
||||
return err
|
||||
})
|
||||
common.ExitOnErr(cmd, "rpc error: %w", err)
|
||||
|
||||
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
||||
|
||||
cmd.Println("Tree has been synchronized successfully.")
|
||||
}
|
59
cmd/frostfs-cli/modules/control/util.go
Normal file
59
cmd/frostfs-cli/modules/control/util.go
Normal file
|
@ -0,0 +1,59 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"errors"
|
||||
|
||||
"github.com/TrueCloudLab/frostfs-api-go/v2/refs"
|
||||
internalclient "github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/client"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
||||
controlSvc "github.com/TrueCloudLab/frostfs-node/pkg/services/control/server"
|
||||
"github.com/TrueCloudLab/frostfs-sdk-go/client"
|
||||
frostfscrypto "github.com/TrueCloudLab/frostfs-sdk-go/crypto"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func initControlFlags(cmd *cobra.Command) {
|
||||
ff := cmd.Flags()
|
||||
ff.StringP(commonflags.WalletPath, commonflags.WalletPathShorthand, commonflags.WalletPathDefault, commonflags.WalletPathUsage)
|
||||
ff.StringP(commonflags.Account, commonflags.AccountShorthand, commonflags.AccountDefault, commonflags.AccountUsage)
|
||||
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)
|
||||
}
|
||||
|
||||
func verifyResponse(cmd *cobra.Command,
|
||||
sigControl interface {
|
||||
GetKey() []byte
|
||||
GetSign() []byte
|
||||
},
|
||||
body interface {
|
||||
StableMarshal([]byte) []byte
|
||||
},
|
||||
) {
|
||||
if sigControl == nil {
|
||||
common.ExitOnErr(cmd, "", errors.New("missing response signature"))
|
||||
}
|
||||
|
||||
// TODO(@cthulhu-rider): #1387 use Signature message from NeoFS API to avoid conversion
|
||||
var sigV2 refs.Signature
|
||||
sigV2.SetScheme(refs.ECDSA_SHA512)
|
||||
sigV2.SetKey(sigControl.GetKey())
|
||||
sigV2.SetSign(sigControl.GetSign())
|
||||
|
||||
var sig frostfscrypto.Signature
|
||||
common.ExitOnErr(cmd, "can't read signature: %w", sig.ReadFromV2(sigV2))
|
||||
|
||||
if !sig.Verify(body.StableMarshal(nil)) {
|
||||
common.ExitOnErr(cmd, "", errors.New("invalid response signature"))
|
||||
}
|
||||
}
|
||||
|
||||
func getClient(cmd *cobra.Command, pk *ecdsa.PrivateKey) *client.Client {
|
||||
return internalclient.GetSDKClientByFlag(cmd, pk, controlRPC)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue