Skip to content

Commit

Permalink
Add autorenew in rds and fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
duanliguo committed Feb 7, 2021
1 parent 4659c12 commit 0febd23
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 53 deletions.
19 changes: 19 additions & 0 deletions doc/DDC.md
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,10 @@ args := &ddc.CreateRdsArgs{
TagValue: "tagV",
},
},
// 部署集id 可选
DeployId:"xxxyyy-123",
// 资源池id 必选
PoolId:"xxxyzzzyy-123",
}
result, err := client.CreateRds(args)
if err != nil {
Expand Down Expand Up @@ -681,6 +685,21 @@ args := &ddc.CreateReadReplicaArgs{
TagValue: "tagV",
},
},
// 部署集id 可选
DeployId:"xxxyyy-123",
// 资源池id 必选与主实例保持一致
PoolId:"xxxyzzzyy-123",
// RO组ID。(创建只读实例时) 可选
// 如果不传,默认会创建一个RO组,并将该只读加入RO组中
RoGroupId:"yyzzcc",
// RO组是否启用延迟剔除,默认不启动。(创建只读实例时)可选
EnableDelayOff:false,
// 延迟阈值。(创建只读实例时)可选
DelayThreshold: 1,
// RO组最少保留实例数目。默认为1. (创建只读实例时)可选
LeastInstanceAmount: 1,
// 只读实例在RO组中的读流量权重。默认为1(创建只读实例时)可选
RoGroupWeight: 1,
}
result, err := client.CreateReadReplica(args)
if err != nil {
Expand Down
31 changes: 30 additions & 1 deletion doc/RDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ for _, e := range result.Instances {
fmt.Println("rds instanceCreateTime: ", e.InstanceCreateTime)
fmt.Println("rds instanceExpireTime: ", e.InstanceExpireTime)
fmt.Println("rds publicAccessStatus: ", e.PublicAccessStatus)
fmt.Println("rds task: ", e.Task)
fmt.Println("rds vpcId: ", e.VpcId)
}
```
Expand Down Expand Up @@ -588,11 +589,39 @@ if err != nil {
}
fmt.Printf("update instance name success\n")
```

> 注意:
>
> - 实例名称支持大小写字母、数字以及-_ /.等特殊字符,必须以字母开头,长度1-64。
## 已创建实例自动续费

使用以下代码可以为已创建的预付费实例创建自动续费
```go
// import "github.com/baidubce/bce-sdk-go/services/rds"

args := &rds.AutoRenewArgs{
// 自动续费时长(续费单位为year 不大于3,续费单位为month 不大于9)必选
AutoRenewTime: 1,
// 自动续费单位("year";"month")必选
AutoRenewTimeUnit: "year",
// 实例id集合 必选
InstanceIds: []string{
"rds-y9dJu77d",
"rds-aQFOoncr",
},
}
err := client.AutoRenew(args)
if err != nil {
fmt.Printf("create auto renew error: %+v\n", err)
return
}
```
> 注意:
>
> - 用于已创建的实例开启自动续费。
> - 可以传入多个实例id,多个实例需保证在同一地域。

## 修改同步模式

使用以下代码可以修改RDS实例同步模式。
Expand Down
50 changes: 31 additions & 19 deletions services/ddc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,36 @@ func ExpectEqual(alert func(format string, args ...interface{}),
}

func TestClient_CreateInstance(t *testing.T) {
//id := strconv.FormatInt(time.Now().Unix(),10)
args := &CreateInstanceArgs{

InstanceType: "RDS",
Number: 1,
Instance: CreateInstance{
Engine: "mysql",
EngineVersion: "5.7",
CpuCount: 1,
AllocatedMemoryInGB: 8,
AllocatedStorageInGB: 10,
AZone: "zoneA",
SubnetId: "zoneA:11c4f322-3a0e-4f26-8883-285cf64d0f03",
DiskIoType: "normal_io",
DeployId: "",
PoolId: "",
args := &CreateRdsArgs{
PurchaseCount: 1,
InstanceName: "mysql_5.7",
//SourceInstanceId: "ddc-mmqptugx",
Engine: "mysql",
EngineVersion: "5.7",
CpuCount: 1,
MemoryCapacity: 1,
VolumeCapacity: 5,
Billing: Billing{
PaymentTiming: "Postpaid",
Reservation: Reservation{ReservationLength: 1, ReservationTimeUnit: "Month"},
},
}
DDC_CLIENT.CreateInstance(args)
VpcId: "vpc-80m2ksi6sv0f",
ZoneNames: []string{
"cn-su-c",
},
Subnets: []SubnetMap{
{
ZoneName: "cn-su-c",
SubnetId: "sbn-8v3p33vhyhq5",
},

},
DeployId: "",
PoolId: "xdb_gaiabase_pool",
}
rds, err := DDC_CLIENT.CreateRds(args)
ExpectEqual(t.Errorf, nil, err)
fmt.Println(rds)
}

func TestClient_ListDeploySets(t *testing.T) {
Expand Down Expand Up @@ -391,8 +401,10 @@ func TestClient_CreateRds(t *testing.T) {
ZoneName: "cn-su-c",
SubnetId: "sbn-8v3p33vhyhq5",
},

},
DeployId: "",
PoolId: "xdb_gaiabase_pool",

}
rds, err := DDC_CLIENT.CreateRds(args)
ExpectEqual(t.Errorf, nil, err)
Expand Down
20 changes: 16 additions & 4 deletions services/rds/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const (

func init() {
_, f, _, _ := runtime.Caller(0)
for i := 0; i < 7; i++ {
for i := 0; i < 1; i++ {
f = filepath.Dir(f)
}
conf := filepath.Join(f, "config.json")
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestClient_ListRds(t *testing.T) {
}

func TestClient_GetDetail(t *testing.T) {
result, err := RDS_CLIENT.GetDetail(RDS_ID)
result, err := RDS_CLIENT.GetDetail("rds-TTDYFqXr")
ExpectEqual(t.Errorf, nil, err)
ExpectEqual(t.Errorf, "MySQL", result.Engine)
ExpectEqual(t.Errorf, "5.6", result.EngineVersion)
Expand Down Expand Up @@ -272,7 +272,7 @@ func TestClient_ModifyPublicAccess(t *testing.T) {
}

func TestClient_GetBackupList(t *testing.T) {
isAvailable(RDS_ID)
isAvailable("rds-ZLlMF0c3")
listRdsArgs := &ListRdsArgs{}
result, err := RDS_CLIENT.ListRds(listRdsArgs)
ExpectEqual(t.Errorf, nil, err)
Expand All @@ -282,6 +282,7 @@ func TestClient_GetBackupList(t *testing.T) {
_, err := RDS_CLIENT.GetBackupList(e.InstanceId, args)
ExpectEqual(t.Errorf, nil, err)
}
fmt.Println(e)
}
}

Expand Down Expand Up @@ -399,4 +400,15 @@ func isAvailable(instanceId string) {
break
}
}
}
}

func TestClient_AutoRenew(t *testing.T) {
err := RDS_CLIENT.AutoRenew(&AutoRenewArgs{
AutoRenewTimeUnit: "month",
AutoRenewTime: 1,
InstanceIds: []string{
"rds-rbmh6gJl",
},
})
ExpectEqual(t.Errorf, nil, err)
}
62 changes: 33 additions & 29 deletions services/rds/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type Instance struct {
VpcId string `json:"vpcId"`
Subnets []Subnet `json:"subnets"`
Topology Topology `json:"topology"`
Task string `json:"task"`
PaymentTiming string `json:"paymentTiming"`
}

Expand Down Expand Up @@ -218,64 +219,67 @@ type GetBackupListArgs struct {
}

type GetBackupListResult struct {
Marker string `json:"marker"`
MaxKeys int `json:"maxKeys"`
IsTruncated bool `json:"isTruncated"`
NextMarker string `json:"nextMarker"`
Instances []Instance `json:"instances"`
Marker string `json:"marker"`
MaxKeys int `json:"maxKeys"`
IsTruncated bool `json:"isTruncated"`
NextMarker string `json:"nextMarker"`
Backups []BackupPolicy `json:"backups"`
}

type GetZoneListResult struct {
Zones []ZoneName `json:"zones"`
Zones []ZoneName `json:"zones"`
}

type ZoneName struct {
ZoneNames []string `json:"zoneNames"`
ZoneNames []string `json:"zoneNames"`
}

type ListSubnetsArgs struct {
VpcId string `json:"vpcId"`
ZoneName string `json:"zoneName"`
VpcId string `json:"vpcId"`
ZoneName string `json:"zoneName"`
}

type ListSubnetsResult struct {
Subnets []Subnet `json:"subnets"`
Subnets []Subnet `json:"subnets"`
}

type GetSecurityIpsResult struct {
Etag string `json:"etag"`
SecurityIps []string `json:"securityIps"`
Etag string `json:"etag"`
SecurityIps []string `json:"securityIps"`
}

type UpdateSecurityIpsArgs struct {
SecurityIps []string `json:"securityIps"`
SecurityIps []string `json:"securityIps"`
}

type ListParametersResult struct {
Etag string `json:"etag"`
Parameters []Parameter `json:"parameters"`
Etag string `json:"etag"`
Parameters []Parameter `json:"parameters"`
}

type Parameter struct {
Name string `json:"name"`
DefaultValue string `json:"defaultValue"`
Value string `json:"value"`
PendingValue string `json:"pendingValue"`
Type string `json:"type"`
Dynamic string `json:"dynamic"`
Modifiable string `json:"modifiable"`
AllowedValues string `json:"allowedValues"`
Desc string `json:"desc"`
Name string `json:"name"`
DefaultValue string `json:"defaultValue"`
Value string `json:"value"`
PendingValue string `json:"pendingValue"`
Type string `json:"type"`
Dynamic string `json:"dynamic"`
Modifiable string `json:"modifiable"`
AllowedValues string `json:"allowedValues"`
Desc string `json:"desc"`
}

type UpdateParameterArgs struct {
Parameters []KVParameter `json:"parameters"`
Parameters []KVParameter `json:"parameters"`
}

type KVParameter struct {
Name string `json:"name"`
Value string `json:"value"`
Name string `json:"name"`
Value string `json:"value"`
}



type AutoRenewArgs struct {
InstanceIds []string `json:"instanceIds"`
AutoRenewTimeUnit string `json:"autoRenewTimeUnit"`
AutoRenewTime int `json:"autoRenewTime"`
}
15 changes: 15 additions & 0 deletions services/rds/rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,18 @@ func (c *Client) UpdateParameter(instanceId, Etag string, args *UpdateParameterA
Do()
}

// autoRenew - create autoRenew
//
// PARAMS:
// - Args: *autoRenewArgs
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) AutoRenew(args *AutoRenewArgs) error {

return bce.NewRequestBuilder(c).
WithMethod(http.PUT).
WithURL(getRdsUri()).
WithQueryParam("autoRenew","").
WithBody(args).
Do()
}

0 comments on commit 0febd23

Please sign in to comment.