mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
feat(common): apply http argument parser in nodes
. #22032841 of #22032813 Signed-off-by: slasher <shenjie1@oppo.com>
This commit is contained in:
parent
e0961daeb1
commit
59538d3a98
@ -24,13 +24,21 @@ type (
|
||||
|
||||
func (b *Bool) Key(key string) *Argument { return NewArgument(key, &b.V) }
|
||||
func (b *Bool) Enable() *Argument { return b.Key("enable") }
|
||||
func (b *Bool) Status() *Argument { return b.Key("status") }
|
||||
|
||||
func (i *Int) Key(key string) *Argument { return NewArgument(key, &i.V) }
|
||||
func (i *Int) ID() *Argument { return i.Key("id") }
|
||||
func (i *Int) ExtentID() *Argument { return i.Key("extentID") }
|
||||
|
||||
func (u *Uint) Key(key string) *Argument { return NewArgument(key, &u.V) }
|
||||
func (u *Uint) ID() *Argument { return u.Key("id") }
|
||||
func (u *Uint) PID() *Argument { return u.Key("pid") }
|
||||
func (u *Uint) PartitionID() *Argument { return u.Key("partitionID") }
|
||||
func (u *Uint) Ino() *Argument { return u.Key("ino") }
|
||||
func (u *Uint) ParentIno() *Argument { return u.Key("parentIno") }
|
||||
|
||||
func (f *Float) Key(key string) *Argument { return NewArgument(key, &f.V) }
|
||||
|
||||
func (s *String) Key(key string) *Argument { return NewArgument(key, &s.V) }
|
||||
func (s *String) Disk() *Argument { return s.Key("disk") }
|
||||
func (s *String) DiskPath() *Argument { return s.Key("diskPath") }
|
||||
|
||||
@ -23,6 +23,7 @@ import (
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/cubefs/cubefs/cmd/common"
|
||||
"github.com/cubefs/cubefs/depends/tiglabs/raft"
|
||||
"github.com/cubefs/cubefs/proto"
|
||||
"github.com/cubefs/cubefs/storage"
|
||||
@ -30,6 +31,8 @@ import (
|
||||
"github.com/cubefs/cubefs/util/log"
|
||||
)
|
||||
|
||||
var parseArgs = common.ParseArguments
|
||||
|
||||
var AutoRepairStatus = true
|
||||
|
||||
func (s *DataNode) getDiskAPI(w http.ResponseWriter, r *http.Request) {
|
||||
@ -80,40 +83,22 @@ func (s *DataNode) getStatAPI(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *DataNode) setAutoRepairStatus(w http.ResponseWriter, r *http.Request) {
|
||||
const (
|
||||
paramAutoRepair = "autoRepair"
|
||||
)
|
||||
if err := r.ParseForm(); err != nil {
|
||||
err = fmt.Errorf("parse form fail: %v", err)
|
||||
var autoRepair common.Bool
|
||||
if err := parseArgs(r, autoRepair.Key("autoRepair")); err != nil {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
autoRepair, err := strconv.ParseBool(r.FormValue(paramAutoRepair))
|
||||
if err != nil {
|
||||
err = fmt.Errorf("parse param %v fail: %v", paramAutoRepair, err)
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
AutoRepairStatus = autoRepair
|
||||
s.buildSuccessResp(w, autoRepair)
|
||||
AutoRepairStatus = autoRepair.V
|
||||
s.buildSuccessResp(w, autoRepair.V)
|
||||
}
|
||||
|
||||
func (s *DataNode) getRaftStatus(w http.ResponseWriter, r *http.Request) {
|
||||
const (
|
||||
paramRaftID = "raftID"
|
||||
)
|
||||
if err := r.ParseForm(); err != nil {
|
||||
err = fmt.Errorf("parse form fail: %v", err)
|
||||
var raftID common.Uint
|
||||
if err := parseArgs(r, raftID.Key("raftID")); err != nil {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
raftID, err := strconv.ParseUint(r.FormValue(paramRaftID), 10, 64)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("parse param %v fail: %v", paramRaftID, err)
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
raftStatus := s.raftStore.RaftStatus(raftID)
|
||||
raftStatus := s.raftStore.RaftStatus(raftID.V)
|
||||
s.buildSuccessResp(w, raftStatus)
|
||||
}
|
||||
|
||||
@ -149,27 +134,18 @@ func (s *DataNode) getPartitionsAPI(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *DataNode) getPartitionAPI(w http.ResponseWriter, r *http.Request) {
|
||||
const (
|
||||
paramPartitionID = "id"
|
||||
)
|
||||
var (
|
||||
partitionID uint64
|
||||
pid common.Uint
|
||||
files []*storage.ExtentInfo
|
||||
err error
|
||||
tinyDeleteRecordSize int64
|
||||
raftSt *raft.Status
|
||||
)
|
||||
if err = r.ParseForm(); err != nil {
|
||||
err = fmt.Errorf("parse form fail: %v", err)
|
||||
if err := parseArgs(r, pid.ID()); err != nil {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
if partitionID, err = strconv.ParseUint(r.FormValue(paramPartitionID), 10, 64); err != nil {
|
||||
err = fmt.Errorf("parse param %v fail: %v", paramPartitionID, err)
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
partition := s.space.Partition(partitionID)
|
||||
partition := s.space.Partition(pid.V)
|
||||
if partition == nil {
|
||||
s.buildFailureResp(w, http.StatusNotFound, "partition not exist")
|
||||
return
|
||||
@ -221,29 +197,21 @@ func (s *DataNode) getPartitionAPI(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (s *DataNode) getExtentAPI(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
partitionID uint64
|
||||
extentID int
|
||||
err error
|
||||
extentInfo *storage.ExtentInfo
|
||||
pid common.Uint
|
||||
eid common.Int
|
||||
err error
|
||||
extentInfo *storage.ExtentInfo
|
||||
)
|
||||
if err = r.ParseForm(); err != nil {
|
||||
if err = parseArgs(r, pid.PartitionID(), eid.ExtentID()); err != nil {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
if partitionID, err = strconv.ParseUint(r.FormValue("partitionID"), 10, 64); err != nil {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
if extentID, err = strconv.Atoi(r.FormValue("extentID")); err != nil {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
partition := s.space.Partition(partitionID)
|
||||
partition := s.space.Partition(pid.V)
|
||||
if partition == nil {
|
||||
s.buildFailureResp(w, http.StatusNotFound, "partition not exist")
|
||||
return
|
||||
}
|
||||
if extentInfo, err = partition.ExtentStore().Watermark(uint64(extentID)); err != nil {
|
||||
if extentInfo, err = partition.ExtentStore().Watermark(uint64(eid.V)); err != nil {
|
||||
s.buildFailureResp(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
@ -253,51 +221,38 @@ func (s *DataNode) getExtentAPI(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (s *DataNode) getBlockCrcAPI(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
partitionID uint64
|
||||
extentID int
|
||||
err error
|
||||
blocks []*storage.BlockCrc
|
||||
pid common.Uint
|
||||
eid common.Int
|
||||
err error
|
||||
blocks []*storage.BlockCrc
|
||||
)
|
||||
if err = r.ParseForm(); err != nil {
|
||||
if err = parseArgs(r, pid.PartitionID(), eid.ExtentID()); err != nil {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
if partitionID, err = strconv.ParseUint(r.FormValue("partitionID"), 10, 64); err != nil {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
if extentID, err = strconv.Atoi(r.FormValue("extentID")); err != nil {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
partition := s.space.Partition(partitionID)
|
||||
partition := s.space.Partition(pid.V)
|
||||
if partition == nil {
|
||||
s.buildFailureResp(w, http.StatusNotFound, "partition not exist")
|
||||
return
|
||||
}
|
||||
if blocks, err = partition.ExtentStore().ScanBlocks(uint64(extentID)); err != nil {
|
||||
if blocks, err = partition.ExtentStore().ScanBlocks(uint64(eid.V)); err != nil {
|
||||
s.buildFailureResp(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
s.buildSuccessResp(w, blocks)
|
||||
}
|
||||
|
||||
func (s *DataNode) getTinyDeleted(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
partitionID uint64
|
||||
err error
|
||||
extentInfo []storage.ExtentDeleted
|
||||
pid common.Uint
|
||||
err error
|
||||
extentInfo []storage.ExtentDeleted
|
||||
)
|
||||
if err = r.ParseForm(); err != nil {
|
||||
if err = parseArgs(r, pid.ID()); err != nil {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
if partitionID, err = strconv.ParseUint(r.FormValue("id"), 10, 64); err != nil {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
partition := s.space.Partition(partitionID)
|
||||
partition := s.space.Partition(pid.V)
|
||||
if partition == nil {
|
||||
s.buildFailureResp(w, http.StatusNotFound, "partition not exist")
|
||||
return
|
||||
@ -306,25 +261,20 @@ func (s *DataNode) getTinyDeleted(w http.ResponseWriter, r *http.Request) {
|
||||
s.buildFailureResp(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
s.buildSuccessResp(w, extentInfo)
|
||||
}
|
||||
|
||||
func (s *DataNode) getNormalDeleted(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
partitionID uint64
|
||||
err error
|
||||
extentInfo []storage.ExtentDeleted
|
||||
pid common.Uint
|
||||
err error
|
||||
extentInfo []storage.ExtentDeleted
|
||||
)
|
||||
if err = r.ParseForm(); err != nil {
|
||||
if err = parseArgs(r, pid.ID()); err != nil {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
if partitionID, err = strconv.ParseUint(r.FormValue("id"), 10, 64); err != nil {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
partition := s.space.Partition(partitionID)
|
||||
partition := s.space.Partition(pid.V)
|
||||
if partition == nil {
|
||||
s.buildFailureResp(w, http.StatusNotFound, "partition not exist")
|
||||
return
|
||||
@ -333,25 +283,17 @@ func (s *DataNode) getNormalDeleted(w http.ResponseWriter, r *http.Request) {
|
||||
s.buildFailureResp(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
s.buildSuccessResp(w, extentInfo)
|
||||
}
|
||||
|
||||
func (s *DataNode) setQosEnable() func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
err error
|
||||
enable bool
|
||||
)
|
||||
if err = r.ParseForm(); err != nil {
|
||||
var enable common.Bool
|
||||
if err := parseArgs(r, enable.Enable()); err != nil {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
if enable, err = strconv.ParseBool(r.FormValue("enable")); err != nil {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
s.diskQosEnable = enable
|
||||
s.diskQosEnable = enable.V
|
||||
s.buildSuccessResp(w, "success")
|
||||
}
|
||||
}
|
||||
@ -437,20 +379,21 @@ func (s *DataNode) getSmuxPoolStat() func(http.ResponseWriter, *http.Request) {
|
||||
}
|
||||
|
||||
func (s *DataNode) setMetricsDegrade(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
key := "level"
|
||||
var level common.Int
|
||||
if err := parseArgs(r, level.Key(key).OmitEmpty().
|
||||
OnError(func() error {
|
||||
w.Write([]byte("Set metrics degrade level parse failed\n"))
|
||||
return nil
|
||||
}).
|
||||
OnValue(func() error {
|
||||
atomic.StoreInt64(&s.metricsDegrade, level.V)
|
||||
w.Write([]byte(fmt.Sprintf("Set metrics degrade level to %d successfully\n", level.V)))
|
||||
return nil
|
||||
})); err != nil {
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if level := r.FormValue("level"); level != "" {
|
||||
val, err := strconv.Atoi(level)
|
||||
if err != nil {
|
||||
w.Write([]byte("Set metrics degrade level failed\n"))
|
||||
} else {
|
||||
atomic.StoreInt64(&s.metricsDegrade, int64(val))
|
||||
w.Write([]byte(fmt.Sprintf("Set metrics degrade level to %v successfully\n", val)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DataNode) getMetricsDegrade(w http.ResponseWriter, r *http.Request) {
|
||||
@ -504,31 +447,19 @@ func (s *DataNode) buildJSONResp(w http.ResponseWriter, code int, data interface
|
||||
}
|
||||
|
||||
func (s *DataNode) setDiskBadAPI(w http.ResponseWriter, r *http.Request) {
|
||||
const (
|
||||
paramDiskPath = "diskPath"
|
||||
)
|
||||
var (
|
||||
err error
|
||||
diskPath string
|
||||
diskPath common.String
|
||||
disk *Disk
|
||||
)
|
||||
|
||||
if err = r.ParseForm(); err != nil {
|
||||
err = fmt.Errorf("parse form fail: %v", err)
|
||||
if err = parseArgs(r, diskPath.DiskPath()); err != nil {
|
||||
log.LogErrorf("[setDiskBadAPI] %v", err.Error())
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if diskPath = r.FormValue(paramDiskPath); diskPath == "" {
|
||||
err = fmt.Errorf("param(%v) is empty", paramDiskPath)
|
||||
log.LogErrorf("[setDiskBadAPI] %v", err.Error())
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if disk, err = s.space.GetDisk(diskPath); err != nil {
|
||||
err = fmt.Errorf("not exit such dissk, path: %v", diskPath)
|
||||
if disk, err = s.space.GetDisk(diskPath.V); err != nil {
|
||||
err = fmt.Errorf("not exit such dissk, path: %v", diskPath.V)
|
||||
log.LogErrorf("[setDiskBadAPI] %v", err.Error())
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
@ -548,24 +479,18 @@ func (s *DataNode) setDiskBadAPI(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *DataNode) reloadDataPartition(w http.ResponseWriter, r *http.Request) {
|
||||
const (
|
||||
paramID = "id"
|
||||
)
|
||||
if !s.checkAllDiskLoaded() {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, "please wait for disk loading")
|
||||
return
|
||||
}
|
||||
if err := r.ParseForm(); err != nil {
|
||||
var pid common.Uint
|
||||
if err := parseArgs(r, pid.ID()); err != nil {
|
||||
err = fmt.Errorf("parse form fail: %v", err)
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
partitionID, err := strconv.ParseUint(r.FormValue(paramID), 10, 64)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("parse param %v fail: %v", paramID, err)
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
partitionID := pid.V
|
||||
|
||||
partition := s.space.Partition(partitionID)
|
||||
if partition == nil {
|
||||
s.buildFailureResp(w, http.StatusNotFound, "partition not exist")
|
||||
@ -583,8 +508,7 @@ func (s *DataNode) reloadDataPartition(w http.ResponseWriter, r *http.Request) {
|
||||
partition.Disk().DetachDataPartition(partition)
|
||||
|
||||
log.LogDebugf("data partition %v is detached", partitionID)
|
||||
_, err = LoadDataPartition(rootDir, disk)
|
||||
if err != nil {
|
||||
if _, err := LoadDataPartition(rootDir, disk); err != nil {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
s.buildSuccessResp(w, "success")
|
||||
@ -592,22 +516,13 @@ func (s *DataNode) reloadDataPartition(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *DataNode) setDiskExtentReadLimitStatus(w http.ResponseWriter, r *http.Request) {
|
||||
const (
|
||||
paramStatus = "status"
|
||||
)
|
||||
if err := r.ParseForm(); err != nil {
|
||||
err = fmt.Errorf("parse form fail: %v", err)
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
status, err := strconv.ParseBool(r.FormValue(paramStatus))
|
||||
if err != nil {
|
||||
err = fmt.Errorf("parse param %v fail: %v", paramStatus, err)
|
||||
var status common.Bool
|
||||
if err := parseArgs(r, status.Status()); err != nil {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
for _, disk := range s.space.disks {
|
||||
disk.SetExtentRepairReadLimitStatus(status)
|
||||
disk.SetExtentRepairReadLimitStatus(status.V)
|
||||
}
|
||||
s.buildSuccessResp(w, "success")
|
||||
}
|
||||
@ -632,20 +547,14 @@ func (s *DataNode) queryDiskExtentReadLimitStatus(w http.ResponseWriter, r *http
|
||||
}
|
||||
|
||||
func (s *DataNode) detachDataPartition(w http.ResponseWriter, r *http.Request) {
|
||||
const (
|
||||
paramID = "id"
|
||||
)
|
||||
if err := r.ParseForm(); err != nil {
|
||||
var pid common.Uint
|
||||
if err := parseArgs(r, pid.ID()); err != nil {
|
||||
err = fmt.Errorf("parse form fail: %v", err)
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
partitionID, err := strconv.ParseUint(r.FormValue(paramID), 10, 64)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("parse param %v fail: %v", paramID, err)
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
partitionID := pid.V
|
||||
|
||||
partition := s.space.Partition(partitionID)
|
||||
if partition == nil {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, "partition not exist")
|
||||
@ -667,15 +576,13 @@ func (s *DataNode) detachDataPartition(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *DataNode) releaseDiskExtentReadLimitToken(w http.ResponseWriter, r *http.Request) {
|
||||
const (
|
||||
paramDisk = "disk"
|
||||
)
|
||||
if err := r.ParseForm(); err != nil {
|
||||
var diskParam common.String
|
||||
if err := parseArgs(r, diskParam.Disk()); err != nil {
|
||||
err = fmt.Errorf("parse form fail: %v", err)
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
diskPath := r.FormValue(paramDisk)
|
||||
diskPath := diskParam.V
|
||||
// store disk path and root of dp
|
||||
disk, err := s.space.GetDisk(diskPath)
|
||||
if err != nil {
|
||||
@ -688,27 +595,21 @@ func (s *DataNode) releaseDiskExtentReadLimitToken(w http.ResponseWriter, r *htt
|
||||
}
|
||||
|
||||
func (s *DataNode) loadDataPartition(w http.ResponseWriter, r *http.Request) {
|
||||
const (
|
||||
paramID = "id"
|
||||
paramDisk = "disk"
|
||||
)
|
||||
if err := r.ParseForm(); err != nil {
|
||||
var pid common.Uint
|
||||
var diskParam common.String
|
||||
if err := parseArgs(r, pid.ID(), diskParam.Disk()); err != nil {
|
||||
err = fmt.Errorf("parse form fail: %v", err)
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
partitionID, err := strconv.ParseUint(r.FormValue(paramID), 10, 64)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("parse param %v fail: %v", paramID, err)
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
partitionID := pid.V
|
||||
diskPath := diskParam.V
|
||||
|
||||
partition := s.space.Partition(partitionID)
|
||||
if partition != nil {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, "partition is already loaded")
|
||||
return
|
||||
}
|
||||
diskPath := r.FormValue(paramDisk)
|
||||
// store disk path and root of dp
|
||||
disk, err := s.space.GetDisk(diskPath)
|
||||
if err != nil {
|
||||
|
||||
@ -23,14 +23,16 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
|
||||
"github.com/cubefs/cubefs/cmd/common"
|
||||
"github.com/cubefs/cubefs/proto"
|
||||
"github.com/cubefs/cubefs/util/config"
|
||||
"github.com/cubefs/cubefs/util/errors"
|
||||
"github.com/cubefs/cubefs/util/log"
|
||||
)
|
||||
|
||||
var parseArgs = common.ParseArguments
|
||||
|
||||
// APIResponse defines the structure of the response to an HTTP request
|
||||
type APIResponse struct {
|
||||
Code int `json:"code"`
|
||||
@ -108,7 +110,6 @@ func (m *MetaNode) getPartitionsHandler(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
func (m *MetaNode) getPartitionByIDHandler(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
resp := NewAPIResponse(http.StatusBadRequest, "")
|
||||
defer func() {
|
||||
data, _ := resp.Marshal()
|
||||
@ -116,12 +117,12 @@ func (m *MetaNode) getPartitionByIDHandler(w http.ResponseWriter, r *http.Reques
|
||||
log.LogErrorf("[getPartitionByIDHandler] response %s", err)
|
||||
}
|
||||
}()
|
||||
pid, err := strconv.ParseUint(r.FormValue("pid"), 10, 64)
|
||||
if err != nil {
|
||||
var pid common.Uint
|
||||
if err := parseArgs(r, pid.PID()); err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
mp, err := m.metadataManager.GetPartition(pid)
|
||||
mp, err := m.metadataManager.GetPartition(pid.V)
|
||||
if err != nil {
|
||||
resp.Code = http.StatusNotFound
|
||||
resp.Msg = err.Error()
|
||||
@ -176,14 +177,11 @@ func (m *MetaNode) getAllInodesHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}()
|
||||
|
||||
if err = r.ParseForm(); err != nil {
|
||||
var pid common.Uint
|
||||
if err = parseArgs(r, pid.PID()); err != nil {
|
||||
return
|
||||
}
|
||||
id, err := strconv.ParseUint(r.FormValue("pid"), 10, 64)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
mp, err := m.metadataManager.GetPartition(id)
|
||||
mp, err := m.metadataManager.GetPartition(pid.V)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -227,7 +225,6 @@ func (m *MetaNode) getAllInodesHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (m *MetaNode) getSplitKeyHandler(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
log.LogDebugf("getSplitKeyHandler")
|
||||
resp := NewAPIResponse(http.StatusBadRequest, "")
|
||||
defer func() {
|
||||
@ -236,26 +233,20 @@ func (m *MetaNode) getSplitKeyHandler(w http.ResponseWriter, r *http.Request) {
|
||||
log.LogErrorf("[getSplitKeyHandler] response %s", err)
|
||||
}
|
||||
}()
|
||||
pid, err := strconv.ParseUint(r.FormValue("pid"), 10, 64)
|
||||
if err != nil {
|
||||
var pid, ino common.Uint
|
||||
var verAll common.Bool
|
||||
if err := parseArgs(r, pid.PID(), ino.Ino(),
|
||||
verAll.Key("verAll").OmitEmpty().OmitError()); err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
log.LogDebugf("getSplitKeyHandler")
|
||||
id, err := strconv.ParseUint(r.FormValue("ino"), 10, 64)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
log.LogDebugf("getSplitKeyHandler")
|
||||
|
||||
verSeq, err := m.getRealVerSeq(w, r)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
log.LogDebugf("getSplitKeyHandler")
|
||||
verAll, _ := strconv.ParseBool(r.FormValue("verAll"))
|
||||
mp, err := m.metadataManager.GetPartition(pid)
|
||||
mp, err := m.metadataManager.GetPartition(pid.V)
|
||||
if err != nil {
|
||||
resp.Code = http.StatusNotFound
|
||||
resp.Msg = err.Error()
|
||||
@ -263,10 +254,10 @@ func (m *MetaNode) getSplitKeyHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
log.LogDebugf("getSplitKeyHandler")
|
||||
req := &InodeGetSplitReq{
|
||||
PartitionID: pid,
|
||||
Inode: id,
|
||||
PartitionID: pid.V,
|
||||
Inode: ino.V,
|
||||
VerSeq: verSeq,
|
||||
VerAll: verAll,
|
||||
VerAll: verAll.V,
|
||||
}
|
||||
log.LogDebugf("getSplitKeyHandler")
|
||||
p := &Packet{}
|
||||
@ -288,7 +279,6 @@ func (m *MetaNode) getSplitKeyHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (m *MetaNode) getInodeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
resp := NewAPIResponse(http.StatusBadRequest, "")
|
||||
defer func() {
|
||||
data, _ := resp.Marshal()
|
||||
@ -296,13 +286,10 @@ func (m *MetaNode) getInodeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
log.LogErrorf("[getInodeHandler] response %s", err)
|
||||
}
|
||||
}()
|
||||
pid, err := strconv.ParseUint(r.FormValue("pid"), 10, 64)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
id, err := strconv.ParseUint(r.FormValue("ino"), 10, 64)
|
||||
if err != nil {
|
||||
var pid, ino common.Uint
|
||||
var verAll common.Bool
|
||||
if err := parseArgs(r, pid.PID(), ino.Ino(),
|
||||
verAll.Key("verAll").OmitEmpty().OmitError()); err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
@ -312,20 +299,17 @@ func (m *MetaNode) getInodeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
verAll, _ := strconv.ParseBool(r.FormValue("verAll"))
|
||||
|
||||
mp, err := m.metadataManager.GetPartition(pid)
|
||||
mp, err := m.metadataManager.GetPartition(pid.V)
|
||||
if err != nil {
|
||||
resp.Code = http.StatusNotFound
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
req := &InodeGetReq{
|
||||
PartitionID: pid,
|
||||
Inode: id,
|
||||
PartitionID: pid.V,
|
||||
Inode: ino.V,
|
||||
VerSeq: verSeq,
|
||||
VerAll: verAll,
|
||||
VerAll: verAll.V,
|
||||
}
|
||||
p := &Packet{}
|
||||
err = mp.InodeGet(req, p)
|
||||
@ -342,10 +326,6 @@ func (m *MetaNode) getInodeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (m *MetaNode) getRaftStatusHandler(w http.ResponseWriter, r *http.Request) {
|
||||
const (
|
||||
paramRaftID = "id"
|
||||
)
|
||||
|
||||
resp := NewAPIResponse(http.StatusOK, http.StatusText(http.StatusOK))
|
||||
defer func() {
|
||||
data, _ := resp.Marshal()
|
||||
@ -353,21 +333,17 @@ func (m *MetaNode) getRaftStatusHandler(w http.ResponseWriter, r *http.Request)
|
||||
log.LogErrorf("[getRaftStatusHandler] response %s", err)
|
||||
}
|
||||
}()
|
||||
|
||||
raftID, err := strconv.ParseUint(r.FormValue(paramRaftID), 10, 64)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("parse param %v fail: %v", paramRaftID, err)
|
||||
var raftID common.Uint
|
||||
if err := parseArgs(r, raftID.ID()); err != nil {
|
||||
resp.Msg = err.Error()
|
||||
resp.Code = http.StatusBadRequest
|
||||
return
|
||||
}
|
||||
|
||||
raftStatus := m.raftStore.RaftStatus(raftID)
|
||||
raftStatus := m.raftStore.RaftStatus(raftID.V)
|
||||
resp.Data = raftStatus
|
||||
}
|
||||
|
||||
func (m *MetaNode) getEbsExtentsByInodeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
resp := NewAPIResponse(http.StatusBadRequest, "")
|
||||
defer func() {
|
||||
data, _ := resp.Marshal()
|
||||
@ -375,25 +351,20 @@ func (m *MetaNode) getEbsExtentsByInodeHandler(w http.ResponseWriter, r *http.Re
|
||||
log.LogErrorf("[getEbsExtentsByInodeHandler] response %s", err)
|
||||
}
|
||||
}()
|
||||
pid, err := strconv.ParseUint(r.FormValue("pid"), 10, 64)
|
||||
if err != nil {
|
||||
var pid, ino common.Uint
|
||||
if err := parseArgs(r, pid.PID(), ino.Ino()); err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
id, err := strconv.ParseUint(r.FormValue("ino"), 10, 64)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
mp, err := m.metadataManager.GetPartition(pid)
|
||||
mp, err := m.metadataManager.GetPartition(pid.V)
|
||||
if err != nil {
|
||||
resp.Code = http.StatusNotFound
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
req := &proto.GetExtentsRequest{
|
||||
PartitionID: pid,
|
||||
Inode: id,
|
||||
PartitionID: pid.V,
|
||||
Inode: ino.V,
|
||||
}
|
||||
p := &Packet{}
|
||||
if err = mp.ObjExtentsList(req, p); err != nil {
|
||||
@ -409,7 +380,6 @@ func (m *MetaNode) getEbsExtentsByInodeHandler(w http.ResponseWriter, r *http.Re
|
||||
}
|
||||
|
||||
func (m *MetaNode) getExtentsByInodeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
resp := NewAPIResponse(http.StatusBadRequest, "")
|
||||
defer func() {
|
||||
data, _ := resp.Marshal()
|
||||
@ -417,13 +387,10 @@ func (m *MetaNode) getExtentsByInodeHandler(w http.ResponseWriter, r *http.Reque
|
||||
log.LogErrorf("[getExtentsByInodeHandler] response %s", err)
|
||||
}
|
||||
}()
|
||||
pid, err := strconv.ParseUint(r.FormValue("pid"), 10, 64)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
id, err := strconv.ParseUint(r.FormValue("ino"), 10, 64)
|
||||
if err != nil {
|
||||
var pid, ino common.Uint
|
||||
var verAll common.Bool
|
||||
if err := parseArgs(r, pid.PID(), ino.Ino(),
|
||||
verAll.Key("verAll").OmitEmpty().OmitError()); err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
@ -433,8 +400,7 @@ func (m *MetaNode) getExtentsByInodeHandler(w http.ResponseWriter, r *http.Reque
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
verAll, _ := strconv.ParseBool(r.FormValue("verAll"))
|
||||
mp, err := m.metadataManager.GetPartition(pid)
|
||||
mp, err := m.metadataManager.GetPartition(pid.V)
|
||||
if err != nil {
|
||||
resp.Code = http.StatusNotFound
|
||||
resp.Msg = err.Error()
|
||||
@ -442,10 +408,10 @@ func (m *MetaNode) getExtentsByInodeHandler(w http.ResponseWriter, r *http.Reque
|
||||
}
|
||||
|
||||
req := &proto.GetExtentsRequest{
|
||||
PartitionID: pid,
|
||||
Inode: id,
|
||||
PartitionID: pid.V,
|
||||
Inode: ino.V,
|
||||
VerSeq: uint64(verSeq),
|
||||
VerAll: verAll,
|
||||
VerAll: verAll.V,
|
||||
}
|
||||
p := &Packet{}
|
||||
if err = mp.ExtentsList(req, p); err != nil {
|
||||
@ -461,8 +427,6 @@ func (m *MetaNode) getExtentsByInodeHandler(w http.ResponseWriter, r *http.Reque
|
||||
}
|
||||
|
||||
func (m *MetaNode) getDentryHandler(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
name := r.FormValue("name")
|
||||
resp := NewAPIResponse(http.StatusBadRequest, "")
|
||||
defer func() {
|
||||
data, _ := resp.Marshal()
|
||||
@ -470,38 +434,33 @@ func (m *MetaNode) getDentryHandler(w http.ResponseWriter, r *http.Request) {
|
||||
log.LogErrorf("[getDentryHandler] response %s", err)
|
||||
}
|
||||
}()
|
||||
var (
|
||||
pid uint64
|
||||
pIno uint64
|
||||
err error
|
||||
)
|
||||
if pid, err = strconv.ParseUint(r.FormValue("pid"), 10, 64); err == nil {
|
||||
pIno, err = strconv.ParseUint(r.FormValue("parentIno"), 10, 64)
|
||||
}
|
||||
if err != nil {
|
||||
var pid, pIno common.Uint
|
||||
var verAll common.Bool
|
||||
if err := parseArgs(r, pid.PID(), pIno.ParentIno(),
|
||||
verAll.Key("verAll").OmitEmpty().OmitError()); err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
name := r.FormValue("name")
|
||||
|
||||
verSeq, err := m.getRealVerSeq(w, r)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
verAll, _ := strconv.ParseBool(r.FormValue("verAll"))
|
||||
|
||||
mp, err := m.metadataManager.GetPartition(pid)
|
||||
mp, err := m.metadataManager.GetPartition(pid.V)
|
||||
if err != nil {
|
||||
resp.Code = http.StatusNotFound
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
req := &LookupReq{
|
||||
PartitionID: pid,
|
||||
ParentID: pIno,
|
||||
PartitionID: pid.V,
|
||||
ParentID: pIno.V,
|
||||
Name: name,
|
||||
VerSeq: verSeq,
|
||||
VerAll: verAll,
|
||||
VerAll: verAll.V,
|
||||
}
|
||||
p := &Packet{}
|
||||
if err = mp.Lookup(req, p); err != nil {
|
||||
@ -518,7 +477,6 @@ func (m *MetaNode) getDentryHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (m *MetaNode) getTxHandler(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
resp := NewAPIResponse(http.StatusBadRequest, "")
|
||||
defer func() {
|
||||
data, _ := resp.Marshal()
|
||||
@ -526,30 +484,22 @@ func (m *MetaNode) getTxHandler(w http.ResponseWriter, r *http.Request) {
|
||||
log.LogErrorf("[getTxHandler] response %s", err)
|
||||
}
|
||||
}()
|
||||
var (
|
||||
pid uint64
|
||||
txId string
|
||||
err error
|
||||
)
|
||||
if pid, err = strconv.ParseUint(r.FormValue("pid"), 10, 64); err == nil {
|
||||
if txId = r.FormValue("txId"); txId == "" {
|
||||
err = fmt.Errorf("no txId")
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
var pid common.Uint
|
||||
var txid common.String
|
||||
if err := parseArgs(r, pid.PID(), txid.Key("txId")); err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
mp, err := m.metadataManager.GetPartition(pid)
|
||||
mp, err := m.metadataManager.GetPartition(pid.V)
|
||||
if err != nil {
|
||||
resp.Code = http.StatusNotFound
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
req := &proto.TxGetInfoRequest{
|
||||
Pid: pid,
|
||||
TxID: txId,
|
||||
Pid: pid.V,
|
||||
TxID: txid.V,
|
||||
}
|
||||
p := &Packet{}
|
||||
if err = mp.TxGetInfo(req, p); err != nil {
|
||||
@ -566,21 +516,18 @@ func (m *MetaNode) getTxHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (m *MetaNode) getRealVerSeq(w http.ResponseWriter, r *http.Request) (verSeq uint64, err error) {
|
||||
if r.FormValue("verSeq") != "" {
|
||||
var ver int64
|
||||
if ver, err = strconv.ParseInt(r.FormValue("verSeq"), 10, 64); err != nil {
|
||||
return
|
||||
}
|
||||
verSeq = uint64(ver)
|
||||
var seq common.Uint
|
||||
err = parseArgs(r, seq.Key("verSeq").OmitEmpty().OnValue(func() error {
|
||||
verSeq = seq.V
|
||||
if verSeq == 0 {
|
||||
verSeq = math.MaxUint64
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}))
|
||||
return
|
||||
}
|
||||
|
||||
func (m *MetaNode) getAllDentriesHandler(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
resp := NewAPIResponse(http.StatusSeeOther, "")
|
||||
shouldSkip := false
|
||||
defer func() {
|
||||
@ -591,13 +538,13 @@ func (m *MetaNode) getAllDentriesHandler(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
}
|
||||
}()
|
||||
pid, err := strconv.ParseUint(r.FormValue("pid"), 10, 64)
|
||||
if err != nil {
|
||||
var pid common.Uint
|
||||
if err := parseArgs(r, pid.PID()); err != nil {
|
||||
resp.Code = http.StatusBadRequest
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
mp, err := m.metadataManager.GetPartition(pid)
|
||||
mp, err := m.metadataManager.GetPartition(pid.V)
|
||||
if err != nil {
|
||||
resp.Code = http.StatusNotFound
|
||||
resp.Msg = err.Error()
|
||||
@ -653,7 +600,6 @@ func (m *MetaNode) getAllDentriesHandler(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
func (m *MetaNode) getAllTxHandler(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
resp := NewAPIResponse(http.StatusOK, "")
|
||||
shouldSkip := false
|
||||
defer func() {
|
||||
@ -664,13 +610,13 @@ func (m *MetaNode) getAllTxHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
}()
|
||||
pid, err := strconv.ParseUint(r.FormValue("pid"), 10, 64)
|
||||
if err != nil {
|
||||
var pid common.Uint
|
||||
if err := parseArgs(r, pid.PID()); err != nil {
|
||||
resp.Code = http.StatusBadRequest
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
mp, err := m.metadataManager.GetPartition(pid)
|
||||
mp, err := m.metadataManager.GetPartition(pid.V)
|
||||
if err != nil {
|
||||
resp.Code = http.StatusNotFound
|
||||
resp.Msg = err.Error()
|
||||
@ -737,32 +683,25 @@ func (m *MetaNode) getDirectoryHandler(w http.ResponseWriter, r *http.Request) {
|
||||
log.LogErrorf("[getDirectoryHandler] response %s", err)
|
||||
}
|
||||
}()
|
||||
pid, err := strconv.ParseUint(r.FormValue("pid"), 10, 64)
|
||||
if err != nil {
|
||||
var pid, pIno common.Uint
|
||||
if err := parseArgs(r, pid.PID(), pIno.ParentIno()); err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
pIno, err := strconv.ParseUint(r.FormValue("parentIno"), 10, 64)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
verSeq, err := m.getRealVerSeq(w, r)
|
||||
if err != nil {
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
mp, err := m.metadataManager.GetPartition(pid)
|
||||
mp, err := m.metadataManager.GetPartition(pid.V)
|
||||
if err != nil {
|
||||
resp.Code = http.StatusNotFound
|
||||
resp.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
req := ReadDirReq{
|
||||
ParentID: pIno,
|
||||
ParentID: pIno.V,
|
||||
VerSeq: verSeq,
|
||||
}
|
||||
p := &Packet{}
|
||||
@ -824,14 +763,11 @@ func (m *MetaNode) getSnapshotHandler(w http.ResponseWriter, r *http.Request, fi
|
||||
}
|
||||
}
|
||||
}()
|
||||
if err = r.ParseForm(); err != nil {
|
||||
var pid common.Uint
|
||||
if err = parseArgs(r, pid.PID()); err != nil {
|
||||
return
|
||||
}
|
||||
id, err := strconv.ParseUint(r.FormValue("pid"), 10, 64)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
mp, err := m.metadataManager.GetPartition(id)
|
||||
mp, err := m.metadataManager.GetPartition(pid.V)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user