Skip to content

Commit

Permalink
update ddc v2
Browse files Browse the repository at this point in the history
  • Loading branch information
yangxin16 committed Apr 20, 2021
1 parent 30266e4 commit 61cc870
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 5 deletions.
54 changes: 54 additions & 0 deletions doc/DDCv2.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,60 @@ for i := range result.Result {
}
```

## 查询资源池余量
使用以下代码可以查询当前指定资源池的资源余量(仅支持DDC)。
```go
// import ddcrds "github.com/baidubce/bce-sdk-go/services/ddc/v2"

residual, err := client.GetResidual(poolId)
if err != nil {
fmt.Printf("get residual of pool error: %+v\n", err)
return
}
fmt.Println("get residual of pool success.")
for zoneName, residualByZone := range residual.Residual {
// 可用区名称
fmt.Println("Zone name: ", zoneName)
// 单机版余量
fmt.Printf("Single residual: disk %v GB, memory %v GB, cpu cores %d\n",
residualByZone.Single.DiskInGb, residualByZone.Single.MemoryInGb, residualByZone.Single.CPUInCore)
// 只读资源余量
fmt.Printf("Slave residual: disk %v GB, memory %v GB, cpu cores %d\n",
residualByZone.Slave.DiskInGb, residualByZone.Slave.MemoryInGb, residualByZone.Slave.CPUInCore)
// 双机版余量
fmt.Printf("HA residual: disk %v GB, memory %v GB, cpu cores %d\n",
residualByZone.HA.DiskInGb, residualByZone.HA.MemoryInGb, residualByZone.HA.CPUInCore)
}
```

## 查询资源池套餐余量
使用以下代码可以查询当前指定资源池的套餐余量(仅支持DDC)。
```go
// import ddcrds "github.com/baidubce/bce-sdk-go/services/ddc/v2"
// 指定套餐
args := &ddcrds.GetFlavorCapacityArgs{
CpuInCore: 2,
MemoryInGb: 4,
DiskInGb: 50,
}
capacityResult, err := client.GetFlavorCapacity(poolId, args)
if err != nil {
fmt.Printf("get flavor capacity of pool error: %+v\n", err)
return
}
fmt.Println("get flavor capacity of pool success.")
for zoneName, residualByZone := range capacityResult.Capacity {
// 可用区名称
fmt.Println("Zone name: ", zoneName)
// 双机版余量
fmt.Printf("HA capacity: %d\n", residualByZone.HA)
// 单机版余量
fmt.Printf("Single capacity: %d\n", residualByZone.Single)
// 只读实例余量
fmt.Printf("Slave capacity: %d\n", residualByZone.Slave)
}
```

# 部署集管理

## 创建部署集
Expand Down
45 changes: 42 additions & 3 deletions services/ddc/v2/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package ddcrds
import (
"encoding/json"
"fmt"
"github.com/baidubce/bce-sdk-go/util"
"github.com/baidubce/bce-sdk-go/util/log"
"os"
"path/filepath"
"reflect"
"runtime"
"testing"
"time"

"github.com/baidubce/bce-sdk-go/util"
"github.com/baidubce/bce-sdk-go/util/log"
)

var (
Expand All @@ -33,7 +34,7 @@ type Conf struct {

const (
SDK_NAME_PREFIX = "sdk_rds_"
POOL = "xdb_gaiabase_pool"
POOL = "xdb_005a2d79-a4f4-4bfb-8284-0ffe9ddaa307_pool"
PNETIP = "100.88.65.121"
DEPLOY_ID = "ab89d829-9068-d88e-75bc-64bb6367d036"
DDC_INSTANCE_ID = "ddc-mw3by2yl"
Expand Down Expand Up @@ -1288,3 +1289,41 @@ func TestClient_GetDisk(t *testing.T) {
fmt.Println("get disk of instance success.")
fmt.Println("disk CapacityRatio: ", disk.CapacityRatio)
}

func TestClient_GetResidual(t *testing.T) {
residual, err := client.GetResidual(POOL)
if err != nil {
fmt.Printf("get residual of pool error: %+v\n", err)
return
}
fmt.Println("get residual of pool success.")
for zoneName, residualByZone := range residual.Residual {
fmt.Println("zone name: ", zoneName)
fmt.Printf("Single residual: disk %v GB, memory %v GB, cpu cores %d\n",
residualByZone.Single.DiskInGb, residualByZone.Single.MemoryInGb, residualByZone.Single.CPUInCore)
fmt.Printf("Slave residual: disk %v GB, memory %v GB, cpu cores %d\n",
residualByZone.Slave.DiskInGb, residualByZone.Slave.MemoryInGb, residualByZone.Slave.CPUInCore)
fmt.Printf("HA residual: disk %v GB, memory %v GB, cpu cores %d\n",
residualByZone.HA.DiskInGb, residualByZone.HA.MemoryInGb, residualByZone.HA.CPUInCore)
}
}

func TestClient_GetFlavorCapacity(t *testing.T) {
args := &GetFlavorCapacityArgs{
CpuInCore: 2,
MemoryInGb: 4,
DiskInGb: 50,
}
capacityResult, err := client.GetFlavorCapacity(POOL, args)
if err != nil {
fmt.Printf("get flavor capacity of pool error: %+v\n", err)
return
}
fmt.Println("get flavor capacity of pool success.")
for zoneName, residualByZone := range capacityResult.Capacity {
fmt.Println("zone name: ", zoneName)
fmt.Printf("HA capacity: %d\n", residualByZone.HA)
fmt.Printf("Single capacity: %d\n", residualByZone.Single)
fmt.Printf("Slave capacity: %d\n", residualByZone.Slave)
}
}
72 changes: 70 additions & 2 deletions services/ddc/v2/ddc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
package ddcrds

import (
"encoding/json"
"errors"
"fmt"
"github.com/baidubce/bce-sdk-go/bce"
"github.com/baidubce/bce-sdk-go/http"
"strconv"
"strings"
"time"

"github.com/baidubce/bce-sdk-go/bce"
"github.com/baidubce/bce-sdk-go/http"
)

const (
Expand All @@ -45,6 +47,18 @@ func getMarkerParams(marker *Marker) map[string]string {
return params
}

// Convert struct to request params
func getQueryParams(val interface{}) (map[string]string, error) {
var params map[string]string
if val != nil {
err := json.Unmarshal([]byte(Json(val)), &params)
if err != nil {
return nil, err
}
}
return params, nil
}

// CreateInstance - create a Instance with the specific parameters
//
// PARAMS:
Expand Down Expand Up @@ -1827,3 +1841,57 @@ func (c *DDCClient) GetDisk(instanceId string) (*Disk, error) {
Do()
return result, err
}

// GetResidual - get residual of pool
//
// PARAMS:
// - poolId: id of pool
// - zoneName: the zone name
// RETURNS:
// - *GetResidualResult:residual of pool
// - error: nil if success otherwise the specific error
func (c *DDCClient) GetResidual(poolId string) (*GetResidualResult, error) {
if len(poolId) < 1 {
return nil, fmt.Errorf("unset poolId")
}

result := &GetResidualResult{}

err := bce.NewRequestBuilder(c).
WithMethod(http.GET).
WithURL(getPoolUriWithId(poolId)+"/residual").
WithHeader(http.CONTENT_TYPE, bce.DEFAULT_CONTENT_TYPE).
WithResult(result).
Do()
return result, err
}

// GetFlavorCapacity - get flavor capacity of pool
//
// PARAMS:
// - poolId: id of pool
// - args: request params
// RETURNS:
// - *GetResidualResult:get flavor capacity of pool
// - error: nil if success otherwise the specific error
func (c *DDCClient) GetFlavorCapacity(poolId string, args *GetFlavorCapacityArgs) (*GetFlavorCapacityResult, error) {
if args == nil {
return nil, fmt.Errorf("unset args")
}
if len(poolId) < 1 {
return nil, fmt.Errorf("unset poolId")
}

result := &GetFlavorCapacityResult{}

err := bce.NewRequestBuilder(c).
WithMethod(http.GET).
WithURL(getPoolUriWithId(poolId)+"/flavorCap").
WithHeader(http.CONTENT_TYPE, bce.DEFAULT_CONTENT_TYPE).
WithQueryParam("cpuInCore", strconv.Itoa(args.CpuInCore)).
WithQueryParam("diskInGb", strconv.FormatInt(args.DiskInGb, 10)).
WithQueryParam("memoryInGb", strconv.FormatInt(args.MemoryInGb, 10)).
WithResult(result).
Do()
return result, err
}
24 changes: 24 additions & 0 deletions services/ddc/v2/ddcrds.go
Original file line number Diff line number Diff line change
Expand Up @@ -1291,3 +1291,27 @@ func (c *Client) GetDisk(instanceId string) (*Disk, error) {
}
return c.ddcClient.GetDisk(instanceId)
}

// GetResidual - get residual of pool
//
// PARAMS:
// - poolId: id of pool
// - zoneName: the zone name
// RETURNS:
// - *GetResidualResult:residual of pool
// - error: nil if success otherwise the specific error
func (c *Client) GetResidual(poolId string) (*GetResidualResult, error) {
return c.ddcClient.GetResidual(poolId)
}

// GetFlavorCapacity - get flavor capacity of pool
//
// PARAMS:
// - poolId: id of pool
// - args: request params
// RETURNS:
// - *GetResidualResult:get flavor capacity of pool
// - error: nil if success otherwise the specific error
func (c *Client) GetFlavorCapacity(poolId string, args *GetFlavorCapacityArgs) (*GetFlavorCapacityResult, error) {
return c.ddcClient.GetFlavorCapacity(poolId, args)
}
37 changes: 37 additions & 0 deletions services/ddc/v2/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,3 +877,40 @@ type CreateTableHardLinkArgs struct {
type Disk struct {
CapacityRatio []string `json:"capacityRatio"`
}

type GetResidualResult struct {
Residual map[string]ResidualOfZone `json:"residual"`
}
type Slave struct {
DiskInGb float64 `json:"diskInGb"`
MemoryInGb float64 `json:"memoryInGb"`
CPUInCore int `json:"cpuInCore"`
}
type Single struct {
DiskInGb float64 `json:"diskInGb"`
MemoryInGb float64 `json:"memoryInGb"`
CPUInCore int `json:"cpuInCore"`
}
type HA struct {
DiskInGb float64 `json:"diskInGb"`
MemoryInGb float64 `json:"memoryInGb"`
CPUInCore int `json:"cpuInCore"`
}
type ResidualOfZone struct {
Slave Slave `json:"slave"`
Single Single `json:"single"`
HA HA `json:"HA"`
}
type GetFlavorCapacityArgs struct {
CpuInCore int `json:"CpuInCore,omitempty"`
MemoryInGb int64 `json:"memoryInGb,omitempty"`
DiskInGb int64 `json:"diskInGb,omitempty"`
}
type GetFlavorCapacityResult struct {
Capacity map[string]CapacityOfZone `json:"capacity"`
}
type CapacityOfZone struct {
Single int `json:"single"`
Slave int `json:"slave"`
HA int `json:"HA"`
}

0 comments on commit 61cc870

Please sign in to comment.