From b2c1df69bd3ffaac8209d347282c1b89358ea4c8 Mon Sep 17 00:00:00 2001 From: pengpengSir <2968332764@qq.com> Date: Sat, 20 May 2023 12:21:45 +0000 Subject: [PATCH] fix bs check server based on pr2463 Signed-off-by: caoxianfei1 --- tools-v2/README.md | 44 +---- tools-v2/internal/error/error.go | 3 - tools-v2/internal/utils/row.go | 15 +- .../curvebs/check/server/get_chunk_info.go | 142 ------------- .../curvebs/check/server/get_copyset_ids.go | 143 -------------- .../command/curvebs/check/server/server.go | 172 ++++++---------- .../curvebs/list/chunkserver/chunkserver.go | 37 +++- .../curvebs/list/chunkserver/copyset.go | 1 - tools-v2/pkg/config/bs.go | 187 +++--------------- 9 files changed, 125 insertions(+), 619 deletions(-) delete mode 100644 tools-v2/pkg/cli/command/curvebs/check/server/get_chunk_info.go delete mode 100644 tools-v2/pkg/cli/command/curvebs/check/server/get_copyset_ids.go diff --git a/tools-v2/README.md b/tools-v2/README.md index 8c08f977b9..314f6dc0b8 100644 --- a/tools-v2/README.md +++ b/tools-v2/README.md @@ -1749,7 +1749,6 @@ Output: ### curve bs -<<<<<<< HEAD | old | new | | ------------------------------------ | --------------------------------- | | curve_ops_tool logical-pool-list | curve bs list logical-pool | @@ -1786,44 +1785,5 @@ Output: | curve_ops_tool status | | | curve_ops_tool check-consistency | | | curve_ops_tool check-chunkserver | | -| curve_ops_tool check-server | | - -======= -| old | new | -| ------------------------------------ | ------------------------------ | -| curve_ops_tool logical-pool-list | curve bs list logical-pool | -| curve_ops_tool get -fileName= | curve bs query file -path | -| curve_ops_tool etcd-status | curve bs status etcd | -| curve_ops_tool mds-status | curve bs status mds | -| curve_ops_tool server-list | curve bs list server | -| curve_ops_tool client-list | curve bs list client | -| curve_ops_tool delete | curve bs delete file | -| curve_ops_tool list | curve bs list dir | -| curve_ops_tool create | curve bs create file/dir | -| curve_ops_tool seginfo | curve bs query seginfo | -| curve_ops_tool chunk-location | curve bs query chunk | -| curve_ops_tool remove-peer | curve bs delete peer | -| curve_ops_tool reset-peer | curve bs update peer | -| curve_ops_tool space | curve bs list space | -| curve_ops_tool update-throttle | curve bs update throttle | -| curve_ops_tool check-copyset | curve bs check copyset | -| curve_ops_tool client-status | curve bs status client | -| curve_ops_tool check-operator | curve bs check operator | -| curve_ops_tool check-server | curve bs check server | -| curve_ops_tool snapshot-clone-status | curve bs status snapshotserver | -| curve_ops_tool transfer-leader | curve bs update leader | -| curve_ops_tool do-snapshot | curve bs snapshot copyset | -| curve_ops_tool set-scan-state | curve bs update scan-state | -| curve_ops_tool chunkserver-status | curve bs status chunkserver | -| curve_ops_tool status | | -| curve_ops_tool copysets-status | | -| curve_ops_tool chunkserver-list | curve bs list chunkserver | -| curve_ops_tool clean-recycle | | -| curve_ops_tool check-consistency | | -| curve_ops_tool do-snapshot-all | | -| curve_ops_tool check-chunkserver | | -| curve_ops_tool list-may-broken-vol | | -| curve_ops_tool set-copyset-availflag | | -| curve_ops_tool rapid-leader-schedule | | -| curve_ops_tool scan-status | | ->>>>>>> fix bs check server +| curve_ops_tool check-server | curve bs check server | + diff --git a/tools-v2/internal/error/error.go b/tools-v2/internal/error/error.go index 9624909da3..280054f3aa 100644 --- a/tools-v2/internal/error/error.go +++ b/tools-v2/internal/error/error.go @@ -475,9 +475,6 @@ var ( ErrBsGetAllSnapshotResult = func() *CmdError { return NewInternalCmdError(72, "get all snapshot results fail, err: %s") } - ErrBsGetChunkServerInfos = func() *CmdError { - return NewInternalCmdError(55, "get chunkserver infos fail, err: %s") - } // http error ErrHttpUnreadableResult = func() *CmdError { diff --git a/tools-v2/internal/utils/row.go b/tools-v2/internal/utils/row.go index 39f6272c5c..4cbc76dd4a 100644 --- a/tools-v2/internal/utils/row.go +++ b/tools-v2/internal/utils/row.go @@ -119,13 +119,14 @@ const ( ROW_AVAILFLAG = "availFlag" ROW_DRYRUN = "dryrun" - ROW_RW_STATUS = "rwStatus" - ROW_DISK_STATE = "diskState" - ROW_COPYSET_NUM = "copysetNum" - ROW_DISK_CAPACITY = "diskCapacity" - ROW_DISK_USED = "diskUsed" - ROW_UNHEALTHY_COPYSET = "unhealthyCopyset" - ROW_EXT_ADDR = "extAddr" + ROW_RW_STATUS = "rwStatus" + ROW_DISK_STATE = "diskState" + ROW_COPYSET_NUM = "copysetNum" + ROW_DISK_CAPACITY = "diskCapacity" + ROW_DISK_USED = "diskUsed" + ROW_UNHEALTHY_COPYSET = "unhealthyCopyset" + ROW_UNHEALTHY_COPYSET_RATIO = "unhealthyCopysetRatio" + ROW_EXT_ADDR = "extAddr" // s3 ROW_S3CHUNKINFO_CHUNKID = "s3ChunkId" diff --git a/tools-v2/pkg/cli/command/curvebs/check/server/get_chunk_info.go b/tools-v2/pkg/cli/command/curvebs/check/server/get_chunk_info.go deleted file mode 100644 index 5d1eb7feec..0000000000 --- a/tools-v2/pkg/cli/command/curvebs/check/server/get_chunk_info.go +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2023 NetEase Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Project: CurveCli - * Created Date: 2023-05-07 - * Author: pengpengSir - */ -package server - -import ( - "context" - - cmderror "github.com/opencurve/curve/tools-v2/internal/error" - 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/topology" - "github.com/spf13/cobra" - "google.golang.org/grpc" -) - -type GetChunkServerInfosRpc struct { - Info *basecmd.Rpc - Request *topology.ListChunkServerRequest - topologyClient topology.TopologyServiceClient -} - -type GetChunkInfosCommand struct { - basecmd.FinalCurveCmd - Rpc *GetChunkServerInfosRpc - Response *topology.ListChunkServerResponse -} - -var _ basecmd.FinalCurveCmdFunc = (*GetChunkInfosCommand)(nil) - -func NewChunkInfosCommand() *cobra.Command { - return NewGetChunkServerInfosCommand().Cmd -} - -func NewGetChunkServerInfosCommand() *GetChunkInfosCommand { - gCmd := &GetChunkInfosCommand{ - FinalCurveCmd: basecmd.FinalCurveCmd{}, - } - basecmd.NewFinalCurveCli(&gCmd.FinalCurveCmd, gCmd) - return gCmd -} - -func (gcRpc *GetChunkServerInfosRpc) NewRpcClient(cc grpc.ClientConnInterface) { - gcRpc.topologyClient = topology.NewTopologyServiceClient(cc) -} - -func (gcRpc *GetChunkServerInfosRpc) Stub_Func(ctx context.Context) (interface{}, error) { - return gcRpc.topologyClient.ListChunkServer(ctx, gcRpc.Request) -} - -func (gCmd *GetChunkInfosCommand) AddFlags() { - config.AddBsMdsFlagOption(gCmd.Cmd) - config.AddRpcRetryTimesFlag(gCmd.Cmd) - config.AddRpcTimeoutFlag(gCmd.Cmd) - config.AddBsServerIdOptionFlag(gCmd.Cmd) - config.AddBsIpOptionFlag(gCmd.Cmd) - config.AddBsPortOptionFlag(gCmd.Cmd) -} - -func (gCmd *GetChunkInfosCommand) Init(cmd *cobra.Command, args []string) error { - timeout := config.GetFlagDuration(gCmd.Cmd, config.RPCTIMEOUT) - retrytimes := config.GetFlagInt32(gCmd.Cmd, config.RPCRETRYTIMES) - mdsAddrs, _ := config.GetBsMdsAddrSlice(gCmd.Cmd) - ip := config.GetFlagString(gCmd.Cmd, config.CURVEBS_IP) - port := config.GetFlagUint32(gCmd.Cmd, config.CURVEBS_PORT) - serverid := config.GetFlagUint32(gCmd.Cmd, config.CURVEBS_SERVER_ID) - - if ip != "" { - rpc := &GetChunkServerInfosRpc{ - Request: &topology.ListChunkServerRequest{ - Ip: &ip, - Port: &port, - }, - Info: basecmd.NewRpc(mdsAddrs, timeout, retrytimes, "ListChunkServer"), - } - gCmd.Rpc = rpc - } else { - rpc := &GetChunkServerInfosRpc{ - Request: &topology.ListChunkServerRequest{ - ServerID: &serverid, - }, - Info: basecmd.NewRpc(mdsAddrs, timeout, retrytimes, "ListChunkServer"), - } - gCmd.Rpc = rpc - } - return nil -} - -func (gCmd *GetChunkInfosCommand) Print(cmd *cobra.Command, args []string) error { - return output.FinalCmdOutput(&gCmd.FinalCurveCmd, gCmd) -} - -func (gCmd *GetChunkInfosCommand) ResultPlainOutput() error { - return output.FinalCmdOutputPlain(&gCmd.FinalCurveCmd) -} - -func (gCmd *GetChunkInfosCommand) RunCommand(cmd *cobra.Command, args []string) error { - result, err := basecmd.GetRpcResponse(gCmd.Rpc.Info, gCmd.Rpc) - if err.TypeCode() != cmderror.CODE_SUCCESS { - return err.ToError() - } - gCmd.Response = result.(*topology.ListChunkServerResponse) - return nil -} - -func GetChunkserverInfos(caller *cobra.Command) ([]*topology.ChunkServerInfo, *cmderror.CmdError) { - gCmd := NewGetChunkServerInfosCommand() - config.AlignFlagsValue(caller, gCmd.Cmd, []string{ - config.CURVEBS_MDSADDR, config.RPCRETRYTIMES, config.RPCTIMEOUT, config.CURVEBS_SERVER_ID, config.CURVEBS_IP, config.CURVEBS_PORT, - }) - - gCmd.Cmd.SilenceErrors = true - gCmd.Cmd.SilenceUsage = true - gCmd.Cmd.SetArgs([]string{"--format", config.FORMAT_NOOUT}) - err := gCmd.Cmd.Execute() - if err != nil { - retErr := cmderror.ErrBsGetChunkServerInfos() - retErr.Format(err.Error()) - return nil, retErr - } - - return gCmd.Response.ChunkServerInfos, cmderror.Success() -} diff --git a/tools-v2/pkg/cli/command/curvebs/check/server/get_copyset_ids.go b/tools-v2/pkg/cli/command/curvebs/check/server/get_copyset_ids.go deleted file mode 100644 index c8831c4372..0000000000 --- a/tools-v2/pkg/cli/command/curvebs/check/server/get_copyset_ids.go +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2023 NetEase Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Project: CurveCli - * Created Date: 2023-05-07 - * Author: pengpengSir - */ -package server - -import ( - "context" - "fmt" - - cmderror "github.com/opencurve/curve/tools-v2/internal/error" - 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/topology" - "github.com/spf13/cobra" - "google.golang.org/grpc" -) - -type GetChunkServerCopysetsRpc struct { - Info *basecmd.Rpc - Request *topology.GetCopySetsInChunkServerRequest - topologyClient topology.TopologyServiceClient -} - -type CopysetidsCommand struct { - basecmd.FinalCurveCmd - Rpc *GetChunkServerCopysetsRpc - Response *topology.GetCopySetsInChunkServerResponse -} - -var _ basecmd.FinalCurveCmdFunc = (*CopysetidsCommand)(nil) - -func NewCopysetCommand() *cobra.Command { - return NewCopysetidsCommand().Cmd -} - -func NewCopysetidsCommand() *CopysetidsCommand { - cCmd := &CopysetidsCommand{ - FinalCurveCmd: basecmd.FinalCurveCmd{}, - } - basecmd.NewFinalCurveCli(&cCmd.FinalCurveCmd, cCmd) - return cCmd -} - -func (tRpc *GetChunkServerCopysetsRpc) NewRpcClient(cc grpc.ClientConnInterface) { - tRpc.topologyClient = topology.NewTopologyServiceClient(cc) -} - -func (tRpc *GetChunkServerCopysetsRpc) Stub_Func(ctx context.Context) (interface{}, error) { - return tRpc.topologyClient.GetCopySetsInChunkServer(ctx, tRpc.Request) -} - -func (cCmd *CopysetidsCommand) AddFlags() { - config.AddBsMdsFlagOption(cCmd.Cmd) - config.AddRpcRetryTimesFlag(cCmd.Cmd) - config.AddRpcTimeoutFlag(cCmd.Cmd) - config.AddBsChunkServerIDOptionFlag(cCmd.Cmd) - config.AddBsIpOptionFlag(cCmd.Cmd) - config.AddBsPortOptionFlag(cCmd.Cmd) -} - -func (cCmd *CopysetidsCommand) Init(cmd *cobra.Command, args []string) error { - timeout := config.GetFlagDuration(cCmd.Cmd, config.RPCTIMEOUT) - retrytimes := config.GetFlagInt32(cCmd.Cmd, config.RPCRETRYTIMES) - mdsAddrs, _ := config.GetBsMdsAddrSlice(cCmd.Cmd) - - chunkserverId := config.GetBsFlagUint32(cCmd.Cmd, config.CURVEBS_CHUNKSERVER_ID) - hostip := config.GetBsFlagString(cCmd.Cmd, config.CURVEBS_IP) - port := config.GetBsFlagUint32(cCmd.Cmd, config.CURVEBS_PORT) - - rpc := &GetChunkServerCopysetsRpc{ - Request: &topology.GetCopySetsInChunkServerRequest{ - ChunkServerID: &chunkserverId, - HostIp: &hostip, - Port: &port, - }, - Info: basecmd.NewRpc(mdsAddrs, timeout, retrytimes, "GetCopysetInChunkServer"), - } - cCmd.Rpc = rpc - return nil -} - -func (cCmd *CopysetidsCommand) Print(cmd *cobra.Command, args []string) error { - return output.FinalCmdOutput(&cCmd.FinalCurveCmd, cCmd) -} - -func (cCmd *CopysetidsCommand) ResultPlainOutput() error { - return output.FinalCmdOutputPlain(&cCmd.FinalCurveCmd) -} - -func (cCmd *CopysetidsCommand) RunCommand(cmd *cobra.Command, args []string) error { - result, err := basecmd.GetRpcResponse(cCmd.Rpc.Info, cCmd.Rpc) - - if err.TypeCode() != cmderror.CODE_SUCCESS { - fmt.Print(err.Message) - return err.ToError() - } - - cCmd.Response = result.(*topology.GetCopySetsInChunkServerResponse) - return nil -} - -func GetCopysetids(caller *cobra.Command) (*map[uint32]uint32, *cmderror.CmdError) { - cCmd := NewCopysetidsCommand() - config.AlignFlagsValue(caller, cCmd.Cmd, []string{ - config.CURVEBS_MDSADDR, config.RPCRETRYTIMES, config.RPCTIMEOUT, config.CURVEBS_CHUNKSERVER_ID, - config.CURVEBS_IP, config.CURVEBS_PORT, - }) - cCmd.Cmd.SilenceErrors = true - cCmd.Cmd.SilenceUsage = true - cCmd.Cmd.SetArgs([]string{"--format", config.FORMAT_NOOUT}) - err := cCmd.Cmd.Execute() - if err != nil { - retErr := cmderror.ErrBsGetCopysetStatus() - retErr.Format(err.Error()) - return nil, retErr - } - - copysetID2PoolId := make(map[uint32]uint32) - for _, copysetInfo := range cCmd.Response.GetCopysetInfos() { - copysetID2PoolId[copysetInfo.GetCopysetId()] = copysetInfo.GetLogicalPoolId() - } - - return ©setID2PoolId, cmderror.Success() -} diff --git a/tools-v2/pkg/cli/command/curvebs/check/server/server.go b/tools-v2/pkg/cli/command/curvebs/check/server/server.go index 57456defef..68b39b26a5 100644 --- a/tools-v2/pkg/cli/command/curvebs/check/server/server.go +++ b/tools-v2/pkg/cli/command/curvebs/check/server/server.go @@ -23,29 +23,33 @@ package server import ( "fmt" - "time" + "strconv" cmderror "github.com/opencurve/curve/tools-v2/internal/error" cobrautil "github.com/opencurve/curve/tools-v2/internal/utils" basecmd "github.com/opencurve/curve/tools-v2/pkg/cli/command" - - copysetbs "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/status/copyset" + checkcopyset "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/check/copyset" + "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/list/chunkserver" "github.com/opencurve/curve/tools-v2/pkg/config" + "github.com/opencurve/curve/tools-v2/pkg/output" - "github.com/opencurve/curve/tools-v2/proto/proto/copyset" - "github.com/opencurve/curve/tools-v2/proto/proto/topology" "github.com/spf13/cobra" ) const ( - serverExample = `$ curve bs check server` + serverExample = `$ curve bs check server \ +$ curve bs check server --serverid=1 \ +$ curve bs check server --ip 127.0.0.1 --port 8200` ) type ServerCommand struct { basecmd.FinalCurveCmd - ServerID uint32 - ServerIP string - Port uint32 + + ServerID uint32 + ServerIP string + ServerPort uint32 + + rows []map[string]string } var _ basecmd.FinalCurveCmdFunc = (*ServerCommand)(nil) @@ -58,9 +62,10 @@ func (sCmd *ServerCommand) AddFlags() { config.AddBsMdsFlagOption(sCmd.Cmd) config.AddRpcRetryTimesFlag(sCmd.Cmd) config.AddRpcTimeoutFlag(sCmd.Cmd) + config.AddBsServerIdOptionFlag(sCmd.Cmd) - config.AddBsIpOptionFlag(sCmd.Cmd) - config.AddBsPortOptionFlag(sCmd.Cmd) + config.AddBsServerIpOptionFlag(sCmd.Cmd) + config.AddBsServerPortOptionFlag(sCmd.Cmd) } func NewCheckServerCommand() *ServerCommand { @@ -77,16 +82,12 @@ func NewCheckServerCommand() *ServerCommand { } func (sCmd *ServerCommand) Init(cmd *cobra.Command, args []string) error { - - serverID := config.GetBsFlagUint32(sCmd.Cmd, config.CURVEBS_SERVER_ID) - serverIP := config.GetBsFlagString(sCmd.Cmd, config.CURVEBS_IP) - port := config.GetBsFlagUint32(sCmd.Cmd, config.CURVEBS_PORT) - sCmd.ServerID = serverID - sCmd.ServerIP = serverIP - sCmd.Port = port + sCmd.ServerID = config.GetBsFlagUint32(sCmd.Cmd, config.CURVEBS_SERVER_ID) + sCmd.ServerIP = config.GetBsFlagString(sCmd.Cmd, config.CURVEBS_SERVER_IP) + sCmd.ServerPort = config.GetBsFlagUint32(sCmd.Cmd, config.CURVEBS_SERVER_PORT) header := []string{cobrautil.ROW_SERVER, cobrautil.ROW_IP, cobrautil.ROW_TOTAL, - cobrautil.ROW_UNHEALTHY_COPYSET, + cobrautil.ROW_UNHEALTHY_COPYSET, cobrautil.ROW_UNHEALTHY_COPYSET_RATIO, } sCmd.SetHeader(header) return nil @@ -101,113 +102,58 @@ func (sCmd *ServerCommand) ResultPlainOutput() error { } func (sCmd *ServerCommand) RunCommand(cmd *cobra.Command, args []string) error { - // 1 send RPCs to get all ChunkServerInfo on server - timeout := config.GetFlagDuration(sCmd.Cmd, config.RPCTIMEOUT) - retrytimes := config.GetFlagInt32(sCmd.Cmd, config.RPCRETRYTIMES) - mdsAddr := config.GetBsFlagString(cmd, config.CURVEBS_MDSADDR) - copysetid2Status := make(map[uint32]*copyset.COPYSET_OP_STATUS) - ip_out := sCmd.ServerIP - - total := 0 - healthy := 0 - unhelthy := 0 - - chunkServerInfos, err := GetChunkserverInfos(sCmd.Cmd) + chunkServerInfos, err := chunkserver.ListChunkServerInfos(sCmd.Cmd) if err.TypeCode() != cmderror.CODE_SUCCESS { + sCmd.Error = err return err.ToError() } - - if len(chunkServerInfos) != 0 { - ip_out = chunkServerInfos[0].GetHostIp() + if len(chunkServerInfos) == 0 { + return nil } + config.AddBsChunkServerIdFlag(sCmd.Cmd) + config.AddBsLogicalPoolIdRequiredFlag(sCmd.Cmd) + config.AddBsCopysetIdRequiredFlag(sCmd.Cmd) for _, item := range chunkServerInfos { - err := sCmd.GetStatus(item, &timeout, uint32(retrytimes), mdsAddr, ©setid2Status) + row := make(map[string]string) + chunkId := item.GetChunkServerID() + sCmd.Cmd.Flags().Set(config.CURVEBS_CHUNKSERVER_ID, strconv.FormatUint(uint64(chunkId), 10)) + copySets, err := chunkserver.GetCopySetsInChunkServer(sCmd.Cmd) if err.TypeCode() != cmderror.CODE_SUCCESS { - sCmd.Error = err return err.ToError() } - for _, status := range copysetid2Status { - total++ - if status.Enum() == copyset.COPYSET_OP_STATUS_COPYSET_OP_STATUS_SUCCESS.Enum() { - healthy++ - } else { - unhelthy++ + total := len(copySets) + var unhealthy int + for _, copyset := range copySets { + logicalPoolId := copyset.GetLogicalPoolId() + copysetId := copyset.GetCopysetId() + + copysetKey := cobrautil.GetCopysetKey(uint64(logicalPoolId), uint64(copysetId)) + sCmd.Cmd.Flags().Set(config.CURVEBS_COPYSET_ID, strconv.FormatUint(uint64(copysetId), 10)) + sCmd.Cmd.Flags().Set(config.CURVEBS_LOGIC_POOL_ID, strconv.FormatUint(uint64(logicalPoolId), 10)) + copysetKey2Status, err := checkcopyset.CheckCopysets(sCmd.Cmd) + if err.TypeCode() != cmderror.CODE_SUCCESS { + return err.ToError() } - } + if copysetKey2Status[copysetKey] != cobrautil.HEALTH_OK { + unhealthy++ + } + } + row[cobrautil.ROW_SERVER] = strconv.FormatUint(uint64(chunkId), 10) + row[cobrautil.ROW_IP] = item.GetExternalIp() + row[cobrautil.ROW_TOTAL] = strconv.FormatUint(uint64(total), 10) + row[cobrautil.ROW_UNHEALTHY_COPYSET] = strconv.FormatUint(uint64(unhealthy), 10) + row[cobrautil.ROW_UNHEALTHY_COPYSET_RATIO] = fmt.Sprintf("%v%%", (unhealthy/total)*100) + sCmd.rows = append(sCmd.rows, row) + sCmd.Error = err } - row := make(map[string]string) - row[cobrautil.ROW_SERVER] = fmt.Sprintf("%d", sCmd.ServerID) - row[cobrautil.ROW_TOTAL] = fmt.Sprintf("%d", total) - row[cobrautil.ROW_IP] = ip_out - if total == 0 { - row[cobrautil.ROW_UNHEALTHY_COPYSET] = fmt.Sprintf("%d(%d%%)", 0, 0) - } else { - row[cobrautil.ROW_UNHEALTHY_COPYSET] = fmt.Sprintf("%d(%v%%)", unhelthy, (unhelthy/total)*100) - } - - list := cobrautil.Map2List(row, sCmd.Header) - sCmd.TableNew.Append(list) - return nil -} -func (sCmd *ServerCommand) GetStatus(item *topology.ChunkServerInfo, timeout *time.Duration, - retrytimes uint32, mdsAddrs string, copysetid2Status *map[uint32]*copyset.COPYSET_OP_STATUS) *cmderror.CmdError { - chunkServerID := item.GetChunkServerID() - - hostip := item.GetHostIp() - port := item.GetPort() - sCmd.Cmd.ResetFlags() - config.AddBsMdsFlagOption(sCmd.Cmd) - config.AddRpcRetryTimesFlag(sCmd.Cmd) - config.AddRpcTimeoutFlag(sCmd.Cmd) - config.AddBsChunkServerIDOptionFlag(sCmd.Cmd) - config.AddBsIpOptionFlag(sCmd.Cmd) - config.AddBsPortOptionFlag(sCmd.Cmd) - - sCmd.Cmd.ParseFlags([]string{ - fmt.Sprintf("--%s", config.CURVEBS_MDSADDR), mdsAddrs, - fmt.Sprintf("--%s", config.RPCRETRYTIMES), fmt.Sprintf("%d", retrytimes), - fmt.Sprintf("--%s", config.RPCTIMEOUT), timeout.String(), - fmt.Sprintf("--%s", config.CURVEBS_CHUNKSERVER_ID), fmt.Sprintf("%d", chunkServerID), - fmt.Sprintf("--%s", config.VIPER_CURVEBS_SERVER_ID), hostip, - fmt.Sprintf("--%s", config.CURVEBS_PORT), fmt.Sprintf("%d", port), + list := cobrautil.ListMap2ListSortByKeys(sCmd.rows, sCmd.Header, []string{ + cobrautil.ROW_SERVER, }) - - copysetids2poolids, err := GetCopysetids(sCmd.Cmd) - if err.TypeCode() != cmderror.CODE_SUCCESS { - return err - } - - // get copyset status - peerAddr := fmt.Sprintf("%s:%d", hostip, port) - - for copysetid, poolid := range *copysetids2poolids { - sCmd.Cmd.ResetFlags() - config.AddBsMdsFlagOption(sCmd.Cmd) - config.AddRpcRetryTimesFlag(sCmd.Cmd) - config.AddRpcTimeoutFlag(sCmd.Cmd) - config.AddBSCopysetIdRequiredFlag(sCmd.Cmd) - config.AddBSLogicalPoolIdRequiredFlag(sCmd.Cmd) - config.AddBSPeersConfFlag(sCmd.Cmd) - sCmd.Cmd.ParseFlags([]string{ - fmt.Sprintf("--%s", config.CURVEBS_MDSADDR), mdsAddrs, - fmt.Sprintf("--%s", config.RPCRETRYTIMES), fmt.Sprintf("%d", retrytimes), - fmt.Sprintf("--%s", config.RPCTIMEOUT), timeout.String(), - fmt.Sprintf("--%s", config.CURVEBS_COPYSET_ID), fmt.Sprintf("%d", copysetid), - fmt.Sprintf("--%s", config.CURVEBS_LOGIC_POOL_ID), fmt.Sprintf("%d", poolid), - fmt.Sprintf("--%s", config.CURVEBS_PEERS_ADDRESS), peerAddr, - }) - - result, err := copysetbs.GetCopysetStatus(sCmd.Cmd) - if err.TypeCode() != cmderror.CODE_SUCCESS { - return err - } - for _, staRes := range *result { - (*copysetid2Status)[copysetid] = staRes.Status - } - } - return cmderror.Success() + sCmd.TableNew.AppendBulk(list) + sCmd.Result = sCmd.rows + return nil } diff --git a/tools-v2/pkg/cli/command/curvebs/list/chunkserver/chunkserver.go b/tools-v2/pkg/cli/command/curvebs/list/chunkserver/chunkserver.go index 8f14920040..ebabb9345f 100644 --- a/tools-v2/pkg/cli/command/curvebs/list/chunkserver/chunkserver.go +++ b/tools-v2/pkg/cli/command/curvebs/list/chunkserver/chunkserver.go @@ -96,6 +96,11 @@ func (pCmd *ChunkServerCommand) AddFlags() { config.AddBsCheckHealthOptionFlag(pCmd.Cmd) config.AddBsCSOfflineOptionFlag(pCmd.Cmd) config.AddBsCSUnhealthyOptionFlag(pCmd.Cmd) + + // use either ip or serverID to list Chunkserver under one server + config.AddBsServerIdOptionFlag(pCmd.Cmd) + config.AddBsServerIpOptionFlag(pCmd.Cmd) + config.AddBsServerPortOptionFlag(pCmd.Cmd) } // Init implements basecmd.FinalCurveCmdFunc @@ -107,17 +112,38 @@ func (pCmd *ChunkServerCommand) Init(cmd *cobra.Command, args []string) error { timeout := config.GetFlagDuration(pCmd.Cmd, config.RPCTIMEOUT) retrytimes := config.GetFlagInt32(pCmd.Cmd, config.RPCRETRYTIMES) + serverId := config.GetBsFlagUint32(pCmd.Cmd, config.CURVEBS_SERVER_ID) + serverIp := config.GetBsFlagString(pCmd.Cmd, config.CURVEBS_SERVER_IP) + serverPort := config.GetBsFlagUint32(pCmd.Cmd, config.CURVEBS_SERVER_PORT) + servers, err := server.ListServer(pCmd.Cmd) if err.TypeCode() != cmderror.CODE_SUCCESS { return err.ToError() } + + // Filter servers by serverId or serverIp + if serverId != 0 && serverIp != "" { + return fmt.Errorf("flag --%s and --%s cannot be specified together", + config.CURVEBS_SERVER_ID, config.CURVEBS_SERVER_IP) + } + for _, server := range servers { - id := server.GetServerID() rpc := &ListChunkServerRpc{ - Request: &topology.ListChunkServerRequest{ - ServerID: &id, - }, - Info: basecmd.NewRpc(mdsAddrs, timeout, retrytimes, "ListChunkServer"), + Request: &topology.ListChunkServerRequest{}, + Info: basecmd.NewRpc(mdsAddrs, timeout, retrytimes, "ListChunkServer"), + } + if serverIp != "" { + rpc.Request.Ip = &serverIp + rpc.Request.Port = &serverPort + pCmd.Rpc = append(pCmd.Rpc, rpc) + break + } else if serverId != 0 { + rpc.Request.ServerID = &serverId + pCmd.Rpc = append(pCmd.Rpc, rpc) + break + } else { + id := server.GetServerID() + rpc.Request.ServerID = &id } pCmd.Rpc = append(pCmd.Rpc, rpc) } @@ -256,6 +282,7 @@ func ListChunkServerInfos(caller *cobra.Command) ([]*topology.ChunkServerInfo, * lCmd := NewListChunkServerCommand() config.AlignFlagsValue(caller, lCmd.Cmd, []string{ config.RPCRETRYTIMES, config.RPCTIMEOUT, config.CURVEBS_MDSADDR, + config.CURVEBS_SERVER_IP, config.CURVEBS_SERVER_PORT, config.CURVEBS_SERVER_ID, }) lCmd.Cmd.SilenceErrors = true lCmd.Cmd.SilenceUsage = true diff --git a/tools-v2/pkg/cli/command/curvebs/list/chunkserver/copyset.go b/tools-v2/pkg/cli/command/curvebs/list/chunkserver/copyset.go index b76c6f0f72..a57b83c031 100644 --- a/tools-v2/pkg/cli/command/curvebs/list/chunkserver/copyset.go +++ b/tools-v2/pkg/cli/command/curvebs/list/chunkserver/copyset.go @@ -134,7 +134,6 @@ func (pCmd *CopySetCommand) Print(cmd *cobra.Command, args []string) error { // RunCommand implements basecmd.FinalCurveCmdFunc func (pCmd *CopySetCommand) RunCommand(cmd *cobra.Command, args []string) error { - result, err := basecmd.GetRpcResponse(pCmd.Rpc.Info, pCmd.Rpc) if err.TypeCode() != cmderror.CODE_SUCCESS { pCmd.Error = err diff --git a/tools-v2/pkg/config/bs.go b/tools-v2/pkg/config/bs.go index 50765a3d3a..32e6324b05 100644 --- a/tools-v2/pkg/config/bs.go +++ b/tools-v2/pkg/config/bs.go @@ -35,7 +35,6 @@ import ( const ( // curvebs -<<<<<<< HEAD CURVEBS_MDSADDR = "mdsaddr" VIPER_CURVEBS_MDSADDR = "curvebs.mdsAddr" CURVEBS_MDSDUMMYADDR = "mdsdummyaddr" @@ -128,98 +127,15 @@ const ( CURVEBS_FIlTER = "filter" VIPER_CURVEBS_FILTER = "curvebs.filter" CURVEBS_DEFAULT_FILTER = false + CURVEBS_SERVER_ID = "serverid" + VIPER_CURVEBS_SERVER_ID = "curvebs.serverid" + CURVEBS_SERVER_IP = "ip" + VIPER_CURVEBS_SERVER_IP = "curvebs.ip" + CURVEBS_SERVER_PORT = "port" + VIPER_CURVEBS_SERVER_PORT = "curvebs.port" CURVEBS_ALL = "all" VIPER_CURVEBS_ALL = "curvebs.all" CURVEBS_DEFAULT_ALL = false -======= - CURVEBS_MDSADDR = "mdsaddr" - VIPER_CURVEBS_MDSADDR = "curvebs.mdsAddr" - CURVEBS_MDSDUMMYADDR = "mdsdummyaddr" - VIPER_CURVEBS_MDSDUMMYADDR = "curvebs.mdsDummyAddr" - CURVEBS_ETCDADDR = "etcdaddr" - VIPER_CURVEBS_ETCDADDR = "curvebs.etcdAddr" - CURVEBS_PATH = "path" - VIPER_CURVEBS_PATH = "curvebs.path" - CURVEBS_DEFAULT_PATH = "/test" - CURVEBS_USER = "user" - VIPER_CURVEBS_USER = "curvebs.root.user" - CURVEBS_DEFAULT_USER = "root" - CURVEBS_PASSWORD = "password" - VIPER_CURVEBS_PASSWORD = "curvebs.root.password" - CURVEBS_DEFAULT_PASSWORD = "root_password" - CURVEBS_CLUSTERMAP = "clustermap" - VIPER_CURVEBS_CLUSTERMAP = "curvebs.clustermap" - CURVEBS_FORCE = "force" - VIPER_CURVEBS_FORCE = "curvebs.force" - CURVEBS_DEFAULT_FORCE = false - CURVEBS_LOGIC_POOL_ID = "logicalpoolid" - VIPER_CURVEBS_LOGIC_POOL_ID = "curvebs.logicalpoolid" - CURVEBS_COPYSET_ID = "copysetid" - VIPER_CURVEBS_COPYSET_ID = "curvebs.copysetid" - CURVEBS_PEERS_ADDRESS = "peers" - VIPER_CURVEBS_PEERS_ADDRESS = "curvebs.peers" - CURVEBS_OFFSET = "offset" - VIPER_CURVEBS_OFFSET = "curvebs.offset" - CURVEBS_SIZE = "size" - VIPER_CURVEBS_SIZE = "curvebs.size" - CURVEBS_DEFAULT_SIZE = uint64(10) - CURVEBS_TYPE = "type" - VIPER_CURVEBS_TYPE = "curvebs.type" - CURVEBS_STRIPE_UNIT = "stripeunit" - VIPER_CURVEBS_STRIPE_UNIT = "curvebs.stripeunit" - CURVEBS_DEFAULT_STRIPE_UNIT = "32 KiB" - CURVEBS_STRIPE_COUNT = "stripecount" - VIPER_CURVEBS_STRIPE_COUNT = "curvebs.stripecount" - CURVEBS_DEFAULT_STRIPE_COUNT = uint64(32) - CURVEBS_RECYCLE_PREFIX = "recycleprefix" - VIPER_RECYCLE_PREFIX = "curvebs.recycleprefix" - CURVEBS_EXPIRED_TIME = "expiredtime" - VIPER_CURVEBS_EXPIRED_TIME = "curvebs.expiredtime" - CURVEBS_LIMIT = "limit" - VIPER_CURVEBS_LIMIT = "curvebs.limit" - CURVEBS_BURST = "burst" - VIPER_CURVEBS_BURST = "curvebs.burst" - CURVEBS_DEFAULT_BURST = uint64(30000) - CURVEBS_BURST_LENGTH = "burstlength" - VIPER_CURVEBS_BURST_LENGTH = "curvebs.burstlength" - CURVEBS_DEFAULT_BURST_LENGTH = uint64(10) - CURVEBS_OP = "op" - VIPER_CURVEBS_OP = "curvebs.op" - CURVEBS_DEFAULT_OP = "operator" - CURVEBS_CHECK_TIME = "checktime" - VIPER_CURVEBS_CHECK_TIME = "curvebs.checktime" - CURVEBS_DEFAULT_CHECK_TIME = 30 * time.Second - CURVEBS_MARGIN = "margin" - VIPER_CURVEBS_MARGIN = "curvebs.margin" - CURVEBS_DEFAULT_MARGIN = uint64(1000) - CURVEBS_SNAPSHOTADDR = "snapshotaddr" - VIPER_CURVEBS_SNAPSHOTADDR = "curvebs.snapshotAddr" - CURVEBS_SNAPSHOTDUMMYADDR = "snapshotdummyaddr" - VIPER_CURVEBS_SNAPSHOTDUMMYADDR = "curvebs.snapshotDummyAddr" - CURVEBS_SCAN = "scan" - VIPER_CURVEBS_SCAN = "curvebs.scan" - CURVEBS_DEFAULT_SCAN = true - CURVEBS_CHUNKSERVER_ID = "chunkserverid" - VIPER_CHUNKSERVER_ID = "curvebs.chunkserverid" - CURVEBS_DEFAULT_CHUNKSERVER_ID = "*" - CURVEBS_CHECK_CSALIVE = "checkalive" - VIPER_CURVEBS_CHECK_CSALIVE = "curvebs.checkalive" - CURVEBS_CHECK_HEALTH = "checkhealth" - VIPER_CURVEBS_CHECK_HEALTH = "curvebs.checkHealth" - CURVEBS_CS_OFFLINE = "offline" - VIPER_CURVEBS_CS_OFFLINE = "curvebs.offline" - CURVEBS_CS_UNHEALTHY = "unhealthy" - VIPER_CURVEBS_CS_UNHEALTHY = "curvebs.unhealthy" - CURVEBS_SERVER_ID = "serverid" - VIPER_CURVEBS_SERVER_ID = "curvebs.serverid" - CURVEBS_DEFAULT_SERVER_ID = 1 - CURVEBS_IP = "ip" - VIPER_CURVEBS_IP = "curvebs.ip" - CURVEBS_DEFAULT_IP = "127.0.0.1" - CURVEBS_PORT = "port" - VIPER_CURVEBS_PORT = "curvebs.port" - CURVEBS_DEFAULT_PORT = 8200 ->>>>>>> fix bs check server ) var ( @@ -229,7 +145,6 @@ var ( RPCRETRYTIMES: VIPER_GLOBALE_RPCRETRYTIMES, // bs -<<<<<<< HEAD CURVEBS_MDSADDR: VIPER_CURVEBS_MDSADDR, CURVEBS_MDSDUMMYADDR: VIPER_CURVEBS_MDSDUMMYADDR, CURVEBS_PATH: VIPER_CURVEBS_PATH, @@ -267,44 +182,10 @@ var ( CURVEBS_CHUNK_ID: VIPER_CURVEBS_CHUNK_ID, CURVEBS_CHUNKSERVER_ADDRESS: VIPER_CURVEBS_CHUNKSERVER_ADDRESS, CURVEBS_FIlTER: VIPER_CURVEBS_FILTER, + CURVEBS_SERVER_ID: VIPER_CURVEBS_SERVER_ID, + CURVEBS_SERVER_IP: VIPER_CURVEBS_SERVER_IP, + CURVEBS_SERVER_PORT: VIPER_CURVEBS_SERVER_PORT, CURVEBS_ALL: VIPER_CURVEBS_ALL, -======= - CURVEBS_MDSADDR: VIPER_CURVEBS_MDSADDR, - CURVEBS_MDSDUMMYADDR: VIPER_CURVEBS_MDSDUMMYADDR, - CURVEBS_PATH: VIPER_CURVEBS_PATH, - CURVEBS_USER: VIPER_CURVEBS_USER, - CURVEBS_PASSWORD: VIPER_CURVEBS_PASSWORD, - CURVEBS_ETCDADDR: VIPER_CURVEBS_ETCDADDR, - CURVEBS_LOGIC_POOL_ID: VIPER_CURVEBS_LOGIC_POOL_ID, - CURVEBS_COPYSET_ID: VIPER_CURVEBS_COPYSET_ID, - CURVEBS_PEERS_ADDRESS: VIPER_CURVEBS_PEERS_ADDRESS, - CURVEBS_CLUSTERMAP: VIPER_CURVEBS_CLUSTERMAP, - CURVEBS_OFFSET: VIPER_CURVEBS_OFFSET, - CURVEBS_SIZE: VIPER_CURVEBS_SIZE, - CURVEBS_STRIPE_UNIT: VIPER_CURVEBS_STRIPE_UNIT, - CURVEBS_STRIPE_COUNT: VIPER_CURVEBS_STRIPE_COUNT, - CURVEBS_LIMIT: VIPER_CURVEBS_LIMIT, - CURVEBS_BURST: VIPER_CURVEBS_BURST, - CURVEBS_BURST_LENGTH: VIPER_CURVEBS_BURST_LENGTH, - CURVEBS_FORCE: VIPER_CURVEBS_FORCE, - CURVEBS_TYPE: VIPER_CURVEBS_TYPE, - CURVEBS_EXPIRED_TIME: VIPER_CURVEBS_EXPIRED_TIME, - CURVEBS_RECYCLE_PREFIX: VIPER_RECYCLE_PREFIX, - CURVEBS_MARGIN: VIPER_CURVEBS_MARGIN, - CURVEBS_OP: VIPER_CURVEBS_OP, - CURVEBS_CHECK_TIME: VIPER_CURVEBS_CHECK_TIME, - CURVEBS_SNAPSHOTADDR: VIPER_CURVEBS_SNAPSHOTADDR, - CURVEBS_SNAPSHOTDUMMYADDR: VIPER_CURVEBS_SNAPSHOTDUMMYADDR, - CURVEBS_SCAN: VIPER_CURVEBS_SCAN, - CURVEBS_CHUNKSERVER_ID: VIPER_CHUNKSERVER_ID, - CURVEBS_CHECK_CSALIVE: VIPER_CURVEBS_CHECK_CSALIVE, - CURVEBS_CHECK_HEALTH: VIPER_CURVEBS_CHECK_HEALTH, - CURVEBS_CS_OFFLINE: VIPER_CURVEBS_CS_OFFLINE, - CURVEBS_CS_UNHEALTHY: VIPER_CURVEBS_CS_UNHEALTHY, - CURVEBS_SERVER_ID: VIPER_CURVEBS_SERVER_ID, - CURVEBS_IP: VIPER_CURVEBS_IP, - CURVEBS_PORT: VIPER_CURVEBS_PORT, ->>>>>>> fix bs check server } BSFLAG2DEFAULT = map[string]interface{}{ @@ -323,17 +204,11 @@ var ( CURVEBS_CHECK_TIME: CURVEBS_DEFAULT_CHECK_TIME, CURVEBS_SCAN: CURVEBS_DEFAULT_SCAN, CURVEBS_CHUNKSERVER_ID: CURVEBS_DEFAULT_CHUNKSERVER_ID, -<<<<<<< HEAD CURVEBS_DRYRUN: CURVEBS_DEFAULT_DRYRUN, CURVEBS_FIlTER: CURVEBS_DEFAULT_FILTER, CURVEBS_ALL: CURVEBS_DEFAULT_ALL, CURVEBS_LOGIC_POOL_ID: CURVEBS_DEFAULT_LOGIC_POOL_ID, CURVEBS_COPYSET_ID: CURVEBS_DEFAULT_COPYSET_ID, -======= - CURVEBS_SERVER_ID: CURVEBS_DEFAULT_SERVER_ID, - CURVEBS_IP: CURVEBS_DEFAULT_IP, - CURVEBS_PORT: CURVEBS_DEFAULT_PORT, ->>>>>>> fix bs check server } ) @@ -630,6 +505,21 @@ func AddBsCopysetIdOptionFlag(cmd *cobra.Command) { AddBsUint32OptionFlag(cmd, CURVEBS_COPYSET_ID, "copyset id") } +// serverid +func AddBsServerIdOptionFlag(cmd *cobra.Command) { + AddBsUint32OptionFlag(cmd, CURVEBS_SERVER_ID, "server id") +} + +// ip(server) +func AddBsServerIpOptionFlag(cmd *cobra.Command) { + AddBsStringOptionFlag(cmd, CURVEBS_SERVER_IP, "server ip") +} + +// port(server) +func AddBsServerPortOptionFlag(cmd *cobra.Command) { + AddBsUint32OptionFlag(cmd, CURVEBS_SERVER_PORT, "port") +} + // add flag required // add path[required] func AddBsPathRequiredFlag(cmd *cobra.Command) { @@ -704,7 +594,6 @@ func AddBsCSUnhealthyOptionFlag(cmd *cobra.Command) { AddBsBoolOptionFlag(cmd, CURVEBS_CS_UNHEALTHY, "unhealthy") } -<<<<<<< HEAD func AddBsAvailFlagRequireFlag(cmd *cobra.Command) { AddBsBoolRequireFlag(cmd, CURVEBS_AVAILFLAG, "copysets available flag") } @@ -715,34 +604,6 @@ func AddBsChunkIdSliceRequiredFlag(cmd *cobra.Command) { func AddBsChunkServerAddressSliceRequiredFlag(cmd *cobra.Command) { AddBsStringSliceRequiredFlag(cmd, CURVEBS_CHUNKSERVER_ADDRESS, "chunk server address") -======= -func AddBsServerIdOptionFlag(cmd *cobra.Command) { - AddBSUint32OptionFlag(cmd, CURVEBS_SERVER_ID, "server id") -} - -func AddBsIpOptionFlag(cmd *cobra.Command) { - AddBsStringOptionFlag(cmd, CURVEBS_IP, "server ip") -} - -func AddBsPortOptionFlag(cmd *cobra.Command) { - AddBSUint32OptionFlag(cmd, CURVEBS_PORT, "port") -} - -func AddBsChunkServerIDOptionFlag(cmd *cobra.Command) { - AddBsStringOptionFlag(cmd, CURVEBS_CHUNKSERVER_ID, "chunk server id") -} - -func AddBSUint32OptionFlag(cmd *cobra.Command, name string, usage string) { - defaultValue := BSFLAG2DEFAULT[name] - if defaultValue == nil { - defaultValue = 0 - } - cmd.Flags().Int(name, defaultValue.(int), usage) - err := viper.BindPFlag(BSFLAG2VIPER[name], cmd.Flags().Lookup(name)) - if err != nil { - cobra.CheckErr(err) - } ->>>>>>> fix bs check server } // get stingslice flag