Skip to content

Commit

Permalink
ddc add queryBackupStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
yangxin16 committed Mar 3, 2022
1 parent 437648d commit 7c1fc44
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bce/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

// Constants and default values for the package bce
const (
SDK_VERSION = "0.9.107"
SDK_VERSION = "0.9.108"
URI_PREFIX = "/" // now support uri without prefix "v1" so just set root path
DEFAULT_DOMAIN = "baidubce.com"
DEFAULT_PROTOCOL = "http"
Expand Down
21 changes: 21 additions & 0 deletions doc/DDCv2.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ args := &ddcrds.GetFlavorCapacityArgs{
CpuInCore: 2,
MemoryInGb: 4,
DiskInGb: 50,
// 指定亲和度
Affinity: 2,
}
// 使用默认亲和度,默认为10
// args := ddcrds.NewDefaultGetFlavorCapacityArgs(2,4,50)
capacityResult, err := client.GetFlavorCapacity(poolId, args)
if err != nil {
fmt.Printf("get flavor capacity of pool error: %+v\n", err)
Expand Down Expand Up @@ -2216,6 +2220,23 @@ if err != nil {
fmt.Printf("create backup success\n")
```

## 查询实例备份状态
使用以下代码可以查询当前实例是否正在备份以及备份开始的时间(仅支持DDC)。
```go
// import ddcrds "github.com/baidubce/bce-sdk-go/services/ddc/v2"

backupStatusResult, err := client.GetInstanceBackupStatus(instanceId)
if err != nil {
fmt.Printf("get backup status error: %+v\n", err)
return
}
fmt.Println("get backup status success.")
fmt.Println("instance is backuping: ", backupStatusResult.IsBackuping)
if backupStatusResult.IsBackuping {
fmt.Println("instance backup start time: ", backupStatusResult.SnapshotStartTime)
}
```

## 备份详情
使用以下代码可以查询一个备份的详情(仅支持DDC)。
```go
Expand Down
4 changes: 4 additions & 0 deletions services/ddc/v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,7 @@ func getMaintainTaskDetailUri() string {
func getMaintainTaskUriWithTaskId(taskId string) string {
return URI_PREFIX + REQUEST_DDC_TASK_URL + "/" + taskId
}

func getInstanceBackupStatusUrl(instanceId string) string {
return URI_PREFIX + REQUEST_DDC_INSTANCE_URL + "/" + instanceId + "/backupStatus"
}
17 changes: 17 additions & 0 deletions services/ddc/v2/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,10 @@ func TestClient_GetFlavorCapacity(t *testing.T) {
CpuInCore: 2,
MemoryInGb: 4,
DiskInGb: 50,
Affinity: 2,
}

args = NewDefaultGetFlavorCapacityArgs(2, 4, 50)
capacityResult, err := client.GetFlavorCapacity(POOL, args)
if err != nil {
fmt.Printf("get flavor capacity of pool error: %+v\n", err)
Expand Down Expand Up @@ -1683,3 +1686,17 @@ func TestClient_GetSlowLogs(t *testing.T) {
fmt.Println("slow log executeTime: ", slowLog.ExecuteTime)
}
}

func TestClient_GetInstanceBackupStatus(t *testing.T) {
instanceId = "ddc-mvxhc1fq"
backupStatusResult, err := client.GetInstanceBackupStatus(instanceId)
if err != nil {
fmt.Printf("get backup status error: %+v\n", err)
return
}
fmt.Println("get backup status success.")
fmt.Println("instance is backuping: ", backupStatusResult.IsBackuping)
if backupStatusResult.IsBackuping {
fmt.Println("instance backup start time: ", backupStatusResult.SnapshotStartTime)
}
}
23 changes: 23 additions & 0 deletions services/ddc/v2/ddc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2025,6 +2025,7 @@ func (c *DDCClient) GetFlavorCapacity(poolId string, args *GetFlavorCapacityArgs
WithQueryParam("cpuInCore", strconv.Itoa(args.CpuInCore)).
WithQueryParam("diskInGb", strconv.FormatInt(args.DiskInGb, 10)).
WithQueryParam("memoryInGb", strconv.FormatInt(args.MemoryInGb, 10)).
WithQueryParam("affinity", strconv.FormatInt(args.Affinity, 10)).
WithResult(result).
Do()
return result, err
Expand Down Expand Up @@ -2260,3 +2261,25 @@ func (c *DDCClient) GetSlowLogs(args *GetSlowLogsArgs) (*SlowLogsResponse, error

return result, err
}

// GetInstanceBackupStatus - get instance backup status and backup start time
//
// PARAMS:
// RETURNS:
// - *GetBackupStatusResponse: the response of backup status
// - error: nil if success otherwise the specific error
func (c *DDCClient) GetInstanceBackupStatus(instanceId string) (*GetBackupStatusResponse, error) {
if len(instanceId) < 1 {
return nil, fmt.Errorf("unset instanceId")
}

result := &GetBackupStatusResponse{}
err := bce.NewRequestBuilder(c).
WithMethod(http.GET).
WithURL(getInstanceBackupStatusUrl(instanceId)).
WithHeader(http.CONTENT_TYPE, bce.DEFAULT_CONTENT_TYPE).
WithResult(result).
Do()

return result, err
}
10 changes: 10 additions & 0 deletions services/ddc/v2/ddcrds.go
Original file line number Diff line number Diff line change
Expand Up @@ -1464,3 +1464,13 @@ func (c *Client) GetErrorLogs(args *GetErrorLogsArgs) (*ErrorLogsResponse, error
func (c *Client) GetSlowLogs(args *GetSlowLogsArgs) (*SlowLogsResponse, error) {
return c.ddcClient.GetSlowLogs(args)
}

// GetInstanceBackupStatus - get instance backup status and backup start time
//
// PARAMS:
// RETURNS:
// - *GetBackupStatusResponse: the response of backup status
// - error: nil if success otherwise the specific error
func (c *Client) GetInstanceBackupStatus(instanceId string) (*GetBackupStatusResponse, error) {
return c.ddcClient.GetInstanceBackupStatus(instanceId)
}
16 changes: 16 additions & 0 deletions services/ddc/v2/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,18 @@ type GetFlavorCapacityArgs struct {
CpuInCore int `json:"CpuInCore,omitempty"`
MemoryInGb int64 `json:"memoryInGb,omitempty"`
DiskInGb int64 `json:"diskInGb,omitempty"`
Affinity int64 `json:"affinity,omitempty"`
}

func NewDefaultGetFlavorCapacityArgs(cpuInCore int, memoryInGb, diskInGb int64) *GetFlavorCapacityArgs {
return &GetFlavorCapacityArgs{
CpuInCore: cpuInCore,
MemoryInGb: memoryInGb,
DiskInGb: diskInGb,
Affinity: 10,
}
}

type GetFlavorCapacityResult struct {
Capacity map[string]CapacityOfZone `json:"capacity"`
}
Expand Down Expand Up @@ -1130,3 +1141,8 @@ type SlowLogsResponse struct {
Count int `json:"count"`
SlowLogs []SlowLog `json:"slowLogs"`
}

type GetBackupStatusResponse struct {
IsBackuping bool `json:"isBackuping"`
SnapshotStartTime string `json:"snapshotStartTime"`
}

0 comments on commit 7c1fc44

Please sign in to comment.