Skip to content

Commit

Permalink
feature: add master api 'listVols'; remove redundant 'deleteVolPolicy…
Browse files Browse the repository at this point in the history
…' in deleteBucket

Signed-off-by: wenjia322 <[email protected]>
  • Loading branch information
wenjia322 committed Mar 16, 2020
1 parent adee753 commit ecce5dc
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 7 deletions.
30 changes: 28 additions & 2 deletions master/api_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,11 @@ func (m *Server) markDeleteVol(w http.ResponseWriter, r *http.Request) {
sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()})
return
}
if err = m.cluster.markDeleteVol(name, authKey); err != nil {
if err = m.user.deleteVolPolicy(name); err != nil {
sendErrReply(w, r, newErrHTTPReply(err))
return
}
if err = m.user.deleteVolPolicy(name); err != nil {
if err = m.cluster.markDeleteVol(name, authKey); err != nil {
sendErrReply(w, r, newErrHTTPReply(err))
return
}
Expand Down Expand Up @@ -1629,6 +1629,32 @@ func (m *Server) getMetaPartition(w http.ResponseWriter, r *http.Request) {
sendOkReply(w, r, newSuccessHTTPReply(toInfo(mp)))
}

func (m *Server) listVols(w http.ResponseWriter, r *http.Request) {
var (
err error
keywords string
vol *Vol
volsInfo []*proto.VolInfo
)
if keywords, err = parseKeywords(r); err != nil {
sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()})
return
}
volsInfo = make([]*proto.VolInfo, 0)
for _, name := range m.cluster.allVolNames() {
if strings.Contains(name, keywords) {
if vol, err = m.cluster.getVol(name); err != nil {
sendErrReply(w, r, newErrHTTPReply(proto.ErrVolNotExists))
return
}
stat := volStat(vol)
volInfo := proto.NewVolInfo(vol.Name, vol.Owner, vol.createTime, vol.status(), stat.TotalSize, stat.UsedSize)
volsInfo = append(volsInfo, volInfo)
}
}
sendOkReply(w, r, newSuccessHTTPReply(volsInfo))
}

func parseAndExtractPartitionInfo(r *http.Request) (partitionID uint64, err error) {
if err = r.ParseForm(); err != nil {
return
Expand Down
3 changes: 3 additions & 0 deletions master/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func (m *Server) registerAPIRoutes(router *mux.Router) {
router.NewRoute().Methods(http.MethodGet).
Path(proto.GetTopologyView).
HandlerFunc(m.getTopology)
router.NewRoute().Methods(http.MethodGet).
Path(proto.AdminListVols).
HandlerFunc(m.listVols)

// node task response APIs
router.NewRoute().Methods(http.MethodGet, http.MethodPost).
Expand Down
5 changes: 0 additions & 5 deletions objectnode/api_handler_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,6 @@ func (o *ObjectNode) deleteBucketHandler(w http.ResponseWriter, r *http.Request)
_ = BucketNotEmpty.ServeResponse(w, r)
return
}
if err = mc.UserAPI().DeleteVolPolicy(bucket); err != nil {
log.LogErrorf("delete bucket[%v] error: delete related policy err(%v)", bucket, err)
_ = InternalError.ServeResponse(w, r)
return
}
// delete Volume from master
if authKey, err = calculateAuthKey(akPolicy.UserID); err != nil {
log.LogErrorf("delete bucket[%v] error: calculate authKey(%v) err(%v)", bucket, akPolicy.UserID, err)
Expand Down
21 changes: 21 additions & 0 deletions proto/admin_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
AdminGetIP = "/admin/getIp"
AdminCreateMetaPartition = "/metaPartition/create"
AdminSetMetaNodeThreshold = "/threshold/set"
AdminListVols = "/vol/list"

// Client APIs
ClientDataPartitions = "/client/partitions"
Expand Down Expand Up @@ -438,3 +439,23 @@ type MasterAPIAccessResp struct {
APIResp APIAccessResp `json:"api_resp"`
Data []byte `json:"data"`
}

type VolInfo struct {
Name string
Owner string
CreateTime int64
Status uint8
TotalSize uint64
UsedSize uint64
}

func NewVolInfo(name, owner string, createTime int64, status uint8, totalSize, usedSize uint64) *VolInfo {
return &VolInfo{
Name: name,
Owner: owner,
CreateTime: createTime,
Status: status,
TotalSize: totalSize,
UsedSize: usedSize,
}
}
14 changes: 14 additions & 0 deletions sdk/master/api_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,17 @@ func (api *AdminAPI) CreateMetaPartition(volName string, inodeStart uint64) (err
}
return
}

func (api *AdminAPI) ListVols(keywords string) (volsInfo []*proto.VolInfo, err error) {
var request = newAPIRequest(http.MethodGet, proto.AdminListVols)
request.addParam("keywords", keywords)
var data []byte
if data, err = api.mc.serveRequest(request); err != nil {
return
}
volsInfo = make([]*proto.VolInfo, 0)
if err = json.Unmarshal(data, &volsInfo); err != nil {
return
}
return
}

0 comments on commit ecce5dc

Please sign in to comment.