mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
feat(cli): support query decommission disk progress in cli
Signed-off-by: NaturalSelect <2145973003@qq.com>
This commit is contained in:
parent
9b1f6270ae
commit
25af0b0935
@ -27,6 +27,7 @@ const (
|
||||
CliOpUpdate = "update"
|
||||
CliOpDecommission = "decommission"
|
||||
CliOpRecommission = "recommission"
|
||||
CliOpQueryProgress = "query-progress"
|
||||
CliOpMigrate = "migrate"
|
||||
CliOpDownloadZip = "load"
|
||||
CliOpMetaCompatibility = "meta"
|
||||
|
||||
@ -24,6 +24,7 @@ func newDiskCmd(client *master.MasterClient) *cobra.Command {
|
||||
newListBadDiskCmd(client),
|
||||
newDecommissionDiskCmd(client),
|
||||
newRecommissionDiskCmd(client),
|
||||
newQueryDecommissionDiskCmd(client),
|
||||
)
|
||||
return cmd
|
||||
}
|
||||
@ -106,3 +107,27 @@ func newRecommissionDiskCmd(client *master.MasterClient) *cobra.Command {
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
const (
|
||||
cmdQueryDecommissionDiskProgressShort = "Query decommmission progress on datanode"
|
||||
)
|
||||
|
||||
func newQueryDecommissionDiskCmd(client *master.MasterClient) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: CliOpQueryProgress + " [DATA NODE ADDR] [DISK]",
|
||||
Short: cmdQueryDecommissionDiskProgressShort,
|
||||
Args: cobra.MinimumNArgs(2),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var err error
|
||||
defer func() {
|
||||
errout(err)
|
||||
}()
|
||||
progress, err := client.AdminAPI().QueryDecommissionDiskProgress(args[0], args[1])
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
stdout("%v", formatDecommissionProgress(progress))
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
@ -872,3 +872,13 @@ func formatBadDiskInfoRow(disk proto.BadDiskInfo) string {
|
||||
msgDpIdList := fmt.Sprintf("%v", disk.DiskErrPartitionList)
|
||||
return fmt.Sprintf(badDiskDetailTableRowPattern, disk.Address, disk.Path, disk.TotalPartitionCnt, len(disk.DiskErrPartitionList), msgDpIdList)
|
||||
}
|
||||
|
||||
func formatDecommissionProgress(progress *proto.DecommissionProgress) string {
|
||||
sb := strings.Builder{}
|
||||
sb.WriteString(fmt.Sprintf("Status: %v\n", progress.StatusMessage))
|
||||
sb.WriteString(fmt.Sprintf("Progress: %v\n", progress.Progress))
|
||||
if len(progress.FailedDps) != 0 {
|
||||
sb.WriteString(fmt.Sprintf("Failed Dps: %v\n", progress.FailedDps))
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
@ -3857,8 +3857,9 @@ func (m *Server) queryDiskDecoProgress(w http.ResponseWriter, r *http.Request) {
|
||||
status, progress := disk.updateDecommissionStatus(m.cluster, true)
|
||||
progress, _ = FormatFloatFloor(progress, 4)
|
||||
resp := &proto.DecommissionProgress{
|
||||
Status: status,
|
||||
Progress: fmt.Sprintf("%.2f%%", progress*float64(100)),
|
||||
Status: status,
|
||||
Progress: fmt.Sprintf("%.2f%%", progress*float64(100)),
|
||||
StatusMessage: GetDecommissionStatusMessage(status),
|
||||
}
|
||||
if status == DecommissionFail {
|
||||
dps := disk.GetLatestDecommissionDP(m.cluster)
|
||||
@ -5305,8 +5306,9 @@ func (m *Server) queryDataNodeDecoProgress(w http.ResponseWriter, r *http.Reques
|
||||
status, progress := dn.updateDecommissionStatus(m.cluster, true)
|
||||
progress, _ = FormatFloatFloor(progress, 4)
|
||||
resp := &proto.DecommissionProgress{
|
||||
Status: status,
|
||||
Progress: fmt.Sprintf("%.2f%%", progress*float64(100)),
|
||||
Status: status,
|
||||
Progress: fmt.Sprintf("%.2f%%", progress*float64(100)),
|
||||
StatusMessage: GetDecommissionStatusMessage(status),
|
||||
}
|
||||
if status == DecommissionFail {
|
||||
err, dps := dn.GetDecommissionFailedDPByTerm(m.cluster)
|
||||
|
||||
@ -1029,6 +1029,25 @@ const (
|
||||
defaultDecommissionDiskParallelFactor = 0
|
||||
)
|
||||
|
||||
func GetDecommissionStatusMessage(status uint32) string {
|
||||
switch status {
|
||||
case DecommissionInitial:
|
||||
return "Initial"
|
||||
case markDecommission:
|
||||
return "Marked"
|
||||
case DecommissionPause:
|
||||
return "Paused"
|
||||
case DecommissionRunning:
|
||||
return "Running"
|
||||
case DecommissionSuccess:
|
||||
return "Success"
|
||||
case DecommissionFail:
|
||||
return "Failed"
|
||||
default:
|
||||
return "Unknown"
|
||||
}
|
||||
}
|
||||
|
||||
func (partition *DataPartition) MarkDecommissionStatus(srcAddr, dstAddr, srcDisk string, raftForce bool, term uint64, c *Cluster) bool {
|
||||
if !partition.canMarkDecommission(term) {
|
||||
log.LogWarnf("action[MarkDecommissionStatus] dp[%v] cannot make decommission:status[%v]",
|
||||
|
||||
@ -331,9 +331,10 @@ type MetaPartitionDiagnosis struct {
|
||||
}
|
||||
|
||||
type DecommissionProgress struct {
|
||||
Status uint32
|
||||
Progress string
|
||||
FailedDps []uint64
|
||||
Status uint32
|
||||
Progress string
|
||||
FailedDps []uint64
|
||||
StatusMessage string
|
||||
}
|
||||
|
||||
type BadDiskInfo struct {
|
||||
|
||||
@ -853,6 +853,21 @@ func (api *AdminAPI) RecommissionDisk(addr string, disk string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (api *AdminAPI) QueryDecommissionDiskProgress(addr string, disk string) (progress *proto.DecommissionProgress, err error) {
|
||||
var data []byte
|
||||
request := newAPIRequest(http.MethodPost, proto.QueryDiskDecoProgress)
|
||||
request.params["addr"] = addr
|
||||
request.params["disk"] = disk
|
||||
if data, err = api.mc.serveRequest(request); err != nil {
|
||||
return
|
||||
}
|
||||
progress = &proto.DecommissionProgress{}
|
||||
if err = json.Unmarshal(data, progress); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (api *AdminAPI) ListQuotaAll() (volsInfo []*proto.VolInfo, err error) {
|
||||
var request = newAPIRequest(http.MethodGet, proto.QuotaListAll)
|
||||
var data []byte
|
||||
|
||||
Loading…
Reference in New Issue
Block a user