cubefs/cli/cmd/http_service.go
slasher 7f406e5d0e chore(cli): golangci lint apply into cli
Signed-off-by: slasher <shenjie1@oppo.com>
2023-10-23 15:31:07 +08:00

59 lines
1.4 KiB
Go

package cmd
import (
"fmt"
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/sdk/master"
"github.com/cubefs/cubefs/util"
)
type clientHandler interface {
excuteHttp() (err error)
}
type volumeClient struct {
name string
capacity uint64
opCode MasterOp
client *master.MasterClient
clientIDKey string
}
func NewVolumeClient(opCode MasterOp, client *master.MasterClient) (vol *volumeClient) {
vol = new(volumeClient)
vol.opCode = opCode
vol.client = client
return
}
func (vol *volumeClient) excuteHttp() (err error) {
switch vol.opCode {
case OpExpandVol:
var vv *proto.SimpleVolView
if vv, err = vol.client.AdminAPI().GetVolumeSimpleInfo(vol.name); err != nil {
return
}
if vol.capacity <= vv.Capacity {
return fmt.Errorf("Expand capacity must larger than %v", vv.Capacity)
}
if err = vol.client.AdminAPI().VolExpand(vol.name, vol.capacity, util.CalcAuthKey(vv.Owner), vol.clientIDKey); err != nil {
return
}
case OpShrinkVol:
var vv *proto.SimpleVolView
if vv, err = vol.client.AdminAPI().GetVolumeSimpleInfo(vol.name); err != nil {
return
}
if vol.capacity >= vv.Capacity {
return fmt.Errorf("Expand capacity must less than %v", vv.Capacity)
}
if err = vol.client.AdminAPI().VolShrink(vol.name, vol.capacity, util.CalcAuthKey(vv.Owner), vol.clientIDKey); err != nil {
return
}
case OpDeleteVol:
default:
}
return
}