From 7c1fc4488f07032bf0eb2674d70caee748ffb0d0 Mon Sep 17 00:00:00 2001 From: yangxin16 Date: Thu, 3 Mar 2022 18:03:04 +0800 Subject: [PATCH] ddc add queryBackupStatus --- bce/config.go | 2 +- doc/DDCv2.md | 21 +++++++++++++++++++++ services/ddc/v2/client.go | 4 ++++ services/ddc/v2/client_test.go | 17 +++++++++++++++++ services/ddc/v2/ddc.go | 23 +++++++++++++++++++++++ services/ddc/v2/ddcrds.go | 10 ++++++++++ services/ddc/v2/model.go | 16 ++++++++++++++++ 7 files changed, 92 insertions(+), 1 deletion(-) diff --git a/bce/config.go b/bce/config.go index b36d4361..40147ec2 100644 --- a/bce/config.go +++ b/bce/config.go @@ -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" diff --git a/doc/DDCv2.md b/doc/DDCv2.md index ed8aa62c..a5672f7d 100644 --- a/doc/DDCv2.md +++ b/doc/DDCv2.md @@ -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) @@ -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 diff --git a/services/ddc/v2/client.go b/services/ddc/v2/client.go index 772a539e..2869e1b8 100644 --- a/services/ddc/v2/client.go +++ b/services/ddc/v2/client.go @@ -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" +} diff --git a/services/ddc/v2/client_test.go b/services/ddc/v2/client_test.go index 45adcd7f..9a45d309 100644 --- a/services/ddc/v2/client_test.go +++ b/services/ddc/v2/client_test.go @@ -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) @@ -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) + } +} diff --git a/services/ddc/v2/ddc.go b/services/ddc/v2/ddc.go index c92838e3..22f3cbb6 100644 --- a/services/ddc/v2/ddc.go +++ b/services/ddc/v2/ddc.go @@ -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 @@ -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 +} diff --git a/services/ddc/v2/ddcrds.go b/services/ddc/v2/ddcrds.go index a2e34360..49553aff 100644 --- a/services/ddc/v2/ddcrds.go +++ b/services/ddc/v2/ddcrds.go @@ -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) +} diff --git a/services/ddc/v2/model.go b/services/ddc/v2/model.go index 89776697..7b9a6c4b 100644 --- a/services/ddc/v2/model.go +++ b/services/ddc/v2/model.go @@ -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"` } @@ -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"` +}