Skip to content

Commit

Permalink
finish draft pr
Browse files Browse the repository at this point in the history
  • Loading branch information
kai2321 committed Aug 27, 2023
1 parent 6f5c85b commit d22b342
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
15 changes: 15 additions & 0 deletions proto/nameserver2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,21 @@ message DeleteSnapShotResponse {
required StatusCode statusCode = 1;
}

// bs stop volumer snapshot
message StopSnapShotRequest {
required string fileName = 1;
required uint64 seq = 3;

required string owner = 2;
optional string signature = 4;
required uint64 date = 5;
}

message StopSnapShotResponse {
required StatusCode statusCode = 1;
}


// check snapshot status

message CheckSnapShotStatusRequest {
Expand Down
29 changes: 29 additions & 0 deletions tools-v2/pkg/cli/command/stop/stop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package stop

import (
basecmd "github.com/opencurve/curve/tools-v2/pkg/cli/command"
snapshot "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/stop/volume"
"github.com/spf13/cobra"
)

type StopCommand struct {
basecmd.MidCurveCmd
}

var _ basecmd.MidCurveCmdFunc = (*StopCommand)(nil)

func (dCmd *StopCommand) AddSubCommands() {
dCmd.Cmd.AddCommand(
snapshot.NewSnapShotCommand(),
)
}

func NewDeleteCommand() *cobra.Command {
dCmd := &StopCommand{
basecmd.MidCurveCmd{
Use: "stop",
Short: "stop resources in the curvebs",
},
}
return basecmd.NewMidCurveCli(&dCmd.MidCurveCmd, dCmd)
}
81 changes: 81 additions & 0 deletions tools-v2/pkg/cli/command/stop/volume/snapshot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package snapshot

import (
"context"

basecmd "github.com/opencurve/curve/tools-v2/pkg/cli/command"
"github.com/opencurve/curve/tools-v2/pkg/config"
"github.com/opencurve/curve/tools-v2/pkg/output"
"github.com/opencurve/curve/tools-v2/proto/proto/nameserver2"
"github.com/spf13/cobra"
"google.golang.org/grpc"
)

const (
stopCliExample = ``
)

type StopSnapshotRpc struct {
Info *basecmd.Rpc
Request *nameserver2.StopSnapShotRequest
mdsClient nameserver2.CurveFSServiceClient
}

type StopCommand struct {
basecmd.FinalCurveCmd
Rpc *StopSnapshotRpc
Response *nameserver2.StopSnapshotResponse
}

var _ basecmd.FinalCurveCmdFunc = (*StopCommand)(nil)

func (gRpc *StopSnapshotRpc) NewRpcClient(cc grpc.ClientConnInterface) {
gRpc.mdsClient = nameserver2.NewCurveFSServiceClient(cc)
}

func (gRpc *StopSnapshotRpc) Stub_Func(ctx context.Context) (interface{}, error) {
return gRpc.mdsClient.StopSnapshot(ctx, gRpc.Request)
}

func (deleteCommand *StopCommand) Init(cmd *cobra.Command, args []string) error {
return nil
}

func (deleteCommand *StopCommand) RunCommand(cmd *cobra.Command, args []string) error {
return nil
}

func (stopCommand *StopCommand) Print(cmd *cobra.Command, args []string) error {
return output.FinalCmdOutput(&stopCommand.FinalCurveCmd, stopCommand)
}

func (stopCommand *StopCommand) ResultPlainOutput() error {
return output.FinalCmdOutputPlain(&stopCommand.FinalCurveCmd)
}

func (stopCommand *StopCommand) AddFlags() {
config.AddBsMdsFlagOption(stopCommand.Cmd)
config.AddRpcTimeoutFlag(stopCommand.Cmd)
config.AddRpcRetryTimesFlag(stopCommand.Cmd)

config.AddBsPathRequiredFlag(stopCommand.Cmd)
config.AddBsSnapshotSeqRequiredFlag(stopCommand.Cmd)
config.AddBsUserOptionFlag(stopCommand.Cmd)
config.AddBsPasswordOptionFlag(stopCommand.Cmd)
}

func NewStopSnapShotCommand() *StopCommand {
stopCommand := &StopCommand{
FinalCurveCmd: basecmd.FinalCurveCmd{
Use: "volume snapshot",
Short: "delete volume snapshot in curvebs",
Example: stopCliExample,
},
}
basecmd.NewFinalCurveCli(&stopCommand.FinalCurveCmd, stopCommand)
return stopCommand
}

func NewSnapShotCommand() *cobra.Command {
return NewStopSnapShotCommand().Cmd
}
9 changes: 9 additions & 0 deletions tools-v2/pkg/config/bs.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ const (
CURVEBS_ALL = "all"
VIPER_CURVEBS_ALL = "curvebs.all"
CURVEBS_DEFAULT_ALL = false
CURVEBS_SNAPSHOT_SEQ = "snapshotSeq"
VIPER_CURVEBS_SNAPSHOT_SEQ = "curvebs.snapshotSeq"
CURVEBS_SNAPSHOT_SEQ_DEFAULT = uint64(0)
)

var (
Expand Down Expand Up @@ -186,6 +189,7 @@ var (
CURVEBS_SERVER_IP: VIPER_CURVEBS_SERVER_IP,
CURVEBS_SERVER_PORT: VIPER_CURVEBS_SERVER_PORT,
CURVEBS_ALL: VIPER_CURVEBS_ALL,
CURVEBS_SNAPSHOT_SEQ: VIPER_CURVEBS_SNAPSHOT_SEQ,
}

BSFLAG2DEFAULT = map[string]interface{}{
Expand All @@ -209,6 +213,7 @@ var (
CURVEBS_ALL: CURVEBS_DEFAULT_ALL,
CURVEBS_LOGIC_POOL_ID: CURVEBS_DEFAULT_LOGIC_POOL_ID,
CURVEBS_COPYSET_ID: CURVEBS_DEFAULT_COPYSET_ID,
CURVEBS_SNAPSHOT_SEQ: CURVEBS_SNAPSHOT_SEQ_DEFAULT,
}
)

Expand Down Expand Up @@ -606,6 +611,10 @@ func AddBsChunkServerAddressSliceRequiredFlag(cmd *cobra.Command) {
AddBsStringSliceRequiredFlag(cmd, CURVEBS_CHUNKSERVER_ADDRESS, "chunk server address")
}

func AddBsSnapshotSeqRequiredFlag(cmd *cobra.Command) {
AddBsUint64RequiredFlag(cmd, CURVEBS_SNAPSHOT_SEQ, "snapshot sequence num")
}

// get stingslice flag
func GetBsFlagStringSlice(cmd *cobra.Command, flagName string) []string {
var value []string
Expand Down

0 comments on commit d22b342

Please sign in to comment.