|
| 1 | +package copyset |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + cmderror "github.com/opencurve/curve/tools-v2/internal/error" |
| 6 | + basecmd "github.com/opencurve/curve/tools-v2/pkg/cli/command" |
| 7 | + "github.com/opencurve/curve/tools-v2/pkg/config" |
| 8 | + "github.com/opencurve/curve/tools-v2/pkg/output" |
| 9 | + "github.com/opencurve/curve/tools-v2/proto/proto/topology" |
| 10 | + "github.com/spf13/cobra" |
| 11 | + "google.golang.org/grpc" |
| 12 | + "strconv" |
| 13 | +) |
| 14 | + |
| 15 | +const ( |
| 16 | + deleteBrokenCopySetExample = `$ curve bs delete broken-copyset --chunkserverid=1` |
| 17 | +) |
| 18 | + |
| 19 | +type DeleteBrokenCopySetInChunkServerRpc struct { |
| 20 | + Info *basecmd.Rpc |
| 21 | + Request *topology.DeleteBrokenCopysetInChunkServerRequest |
| 22 | + topologyClient topology.TopologyServiceClient |
| 23 | +} |
| 24 | + |
| 25 | +var _ basecmd.RpcFunc = (*DeleteBrokenCopySetInChunkServerRpc)(nil) // check interface |
| 26 | + |
| 27 | +type DeleteBrokenCopySetCommand struct { |
| 28 | + basecmd.FinalCurveCmd |
| 29 | + Rpc *DeleteBrokenCopySetInChunkServerRpc |
| 30 | + Servers []*topology.ServerInfo |
| 31 | + chunkserverid uint32 |
| 32 | +} |
| 33 | + |
| 34 | +func (d *DeleteBrokenCopySetInChunkServerRpc) Stub_Func(ctx context.Context) (interface{}, error) { |
| 35 | + return d.topologyClient.DeleteBrokenCopysetInChunkServer(ctx, d.Request) |
| 36 | +} |
| 37 | + |
| 38 | +func NewDeleteCommand() *cobra.Command { |
| 39 | + return NewDeleteBrokenCopySetCommand().Cmd |
| 40 | +} |
| 41 | + |
| 42 | +func NewDeleteBrokenCopySetCommand() *DeleteBrokenCopySetCommand { |
| 43 | + cmd := &DeleteBrokenCopySetCommand{ |
| 44 | + FinalCurveCmd: basecmd.FinalCurveCmd{ |
| 45 | + Use: "broken-copyset", |
| 46 | + Short: "delete broken copyset in chunkserver", |
| 47 | + Example: deleteBrokenCopySetExample, |
| 48 | + }, |
| 49 | + } |
| 50 | + |
| 51 | + basecmd.NewFinalCurveCli(&cmd.FinalCurveCmd, cmd) |
| 52 | + return cmd |
| 53 | +} |
| 54 | + |
| 55 | +func (d *DeleteBrokenCopySetCommand) AddFlags() { |
| 56 | + config.AddBsMdsFlagOption(d.Cmd) |
| 57 | + config.AddRpcRetryTimesFlag(d.Cmd) |
| 58 | + config.AddRpcTimeoutFlag(d.Cmd) |
| 59 | + config.AddBsChunkServerIdFlag(d.Cmd) |
| 60 | +} |
| 61 | + |
| 62 | +func (d *DeleteBrokenCopySetInChunkServerRpc) NewRpcClient(cc grpc.ClientConnInterface) { |
| 63 | + d.topologyClient = topology.NewTopologyServiceClient(cc) |
| 64 | +} |
| 65 | + |
| 66 | +func (d *DeleteBrokenCopySetCommand) Init(cmd *cobra.Command, args []string) error { |
| 67 | + mdsAddrs, err := config.GetBsMdsAddrSlice(d.Cmd) |
| 68 | + if err.TypeCode() != cmderror.CODE_SUCCESS { |
| 69 | + return err.ToError() |
| 70 | + } |
| 71 | + timeout := config.GetFlagDuration(d.Cmd, config.RPCTIMEOUT) |
| 72 | + retrytimes := config.GetFlagInt32(d.Cmd, config.RPCRETRYTIMES) |
| 73 | + strid, e := strconv.Atoi(config.GetBsFlagString(d.Cmd, config.CURVEBS_CHUNKSERVER_ID)) |
| 74 | + if e != nil { |
| 75 | + return e |
| 76 | + } |
| 77 | + d.chunkserverid = uint32(strid) |
| 78 | + d.Rpc = &DeleteBrokenCopySetInChunkServerRpc{ |
| 79 | + Info: basecmd.NewRpc(mdsAddrs, timeout, retrytimes, "DeleteBrokenCopysetInChunkServer"), |
| 80 | + Request: &topology.DeleteBrokenCopysetInChunkServerRequest{ |
| 81 | + ChunkServerID: &d.chunkserverid, |
| 82 | + }, |
| 83 | + } |
| 84 | + return nil |
| 85 | +} |
| 86 | + |
| 87 | +func (d *DeleteBrokenCopySetCommand) RunCommand(cmd *cobra.Command, args []string) error { |
| 88 | + result, errCmd := basecmd.GetRpcResponse(d.Rpc.Info, d.Rpc) |
| 89 | + if errCmd.TypeCode() != cmderror.CODE_SUCCESS { |
| 90 | + return errCmd.ToError() |
| 91 | + } |
| 92 | + d.Result = result |
| 93 | + return nil |
| 94 | +} |
| 95 | + |
| 96 | +func (d *DeleteBrokenCopySetCommand) Print(cmd *cobra.Command, args []string) error { |
| 97 | + return output.FinalCmdOutput(&d.FinalCurveCmd, d) |
| 98 | +} |
| 99 | + |
| 100 | +func (d *DeleteBrokenCopySetCommand) ResultPlainOutput() error { |
| 101 | + return output.FinalCmdOutputPlain(&d.FinalCurveCmd) |
| 102 | +} |
0 commit comments