Skip to content

Commit

Permalink
ADB: Improves the invoking adb api method and supports refreshing cre…
Browse files Browse the repository at this point in the history
…dential automatically
  • Loading branch information
xiaozhu36 committed Dec 23, 2024
1 parent 7f454dd commit 33414e4
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 379 deletions.
53 changes: 0 additions & 53 deletions alicloud/connectivity/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2015,35 +2015,6 @@ func (client *AliyunClient) WithHbaseClient(do func(*hbase.Client) (interface{},
return do(client.hbaseconn)
}

func (client *AliyunClient) NewAdbClient() (*rpc.Client, error) {
productCode := "ads"
endpoint := ""
if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" {
if v := client.config.AdbEndpoint; v != "" {
client.config.Endpoints.Store(productCode, v)
}
if err := client.loadEndpoint(productCode); err != nil {
return nil, err
}
}
if v, exist := client.config.Endpoints.Load(productCode); exist && v.(string) != "" {
endpoint = v.(string)
}
if endpoint == "" {
return nil, fmt.Errorf("[ERROR] missing the product %s endpoint.", productCode)
}

sdkConfig := client.teaSdkConfig
sdkConfig.SetEndpoint(endpoint)

conn, err := rpc.NewClient(&sdkConfig)
if err != nil {
return nil, fmt.Errorf("unable to initialize the %s client: %#v", productCode, err)
}

return conn, nil
}

func (client *AliyunClient) WithAdbClient(do func(*adb.Client) (interface{}, error)) (interface{}, error) {
// Initialize the adb client if necessary
if client.adbconn == nil {
Expand Down Expand Up @@ -2995,30 +2966,6 @@ func (client *AliyunClient) NewHcsSgwClient() (*rpc.Client, error) {
}
return conn, nil
}

func (client *AliyunClient) NewAdsClient() (*rpc.Client, error) {
productCode := "ads"
endpoint := ""
if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" {
if err := client.loadEndpoint(productCode); err != nil {
return nil, err
}
}
if v, ok := client.config.Endpoints.Load(productCode); ok && v.(string) != "" {
endpoint = v.(string)
}
if endpoint == "" {
return nil, fmt.Errorf("[ERROR] missing the product %s endpoint.", productCode)
}
sdkConfig := client.teaSdkConfig
sdkConfig.SetEndpoint(endpoint)
conn, err := rpc.NewClient(&sdkConfig)
if err != nil {
return nil, fmt.Errorf("unable to initialize the %s client: %#v", productCode, err)
}
return conn, nil
}

func (client *AliyunClient) NewDdoscooClient() (*rpc.Client, error) {
productCode := "ddoscoo"
endpoint := ""
Expand Down
11 changes: 2 additions & 9 deletions alicloud/data_source_alicloud_adb_db_cluster_lake_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -182,28 +181,22 @@ func dataSourceAlicloudAdbDbClusterLakeVersionsRead(d *schema.ResourceData, meta
}
}

conn, err := client.NewAdsClient()
if err != nil {
return WrapError(err)
}
var objects []interface{}
var response map[string]interface{}
var err error

for {
action := "DescribeDBClusters"
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2021-12-01"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("adb", "2021-12-01", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
response = resp
addDebug(action, response, request)
return nil
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,16 @@ variable "name" {
data "alicloud_resource_manager_resource_groups" "default" {}
data "alicloud_zones" "default" {
available_resource_creation = "VSwitch"
data "alicloud_adb_zones" "default" {
}
data "alicloud_vpcs" "default" {
name_regex = "^default-NODELETING$"
name_regex = "^default-NODELETING$"
}
data "alicloud_vswitches" "default" {
vpc_id = data.alicloud_vpcs.default.ids.0
zone_id = data.alicloud_zones.default.ids[length(data.alicloud_zones.default.ids) - 1]
vpc_id = data.alicloud_vpcs.default.ids.0
zone_id = data.alicloud_adb_zones.default.ids.0
}
resource "alicloud_adb_db_cluster_lake_version" "default" {
Expand All @@ -129,7 +128,7 @@ resource "alicloud_adb_db_cluster_lake_version" "default" {
storage_resource = "0ACU"
vswitch_id = data.alicloud_vswitches.default.ids.0
vpc_id = data.alicloud_vpcs.default.ids.0
zone_id = data.alicloud_zones.default.ids[length(data.alicloud_zones.default.ids) - 1]
zone_id = data.alicloud_adb_zones.default.ids.0
}
data "alicloud_adb_db_cluster_lake_versions" "default" {
Expand Down
10 changes: 2 additions & 8 deletions alicloud/data_source_alicloud_adb_db_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down Expand Up @@ -313,14 +312,9 @@ func dataSourceAlicloudAdbDbClustersRead(d *schema.ResourceData, meta interface{
}
}
var response map[string]interface{}
conn, err := client.NewAdsClient()
if err != nil {
return WrapError(err)
}
var err error
for {
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-03-15"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("adb", "2019-03-15", action, nil, request, true)
if err != nil {
return WrapErrorf(err, DataDefaultErrorMsg, "alicloud_adb_db_clusters", action, AlibabaCloudSdkGoERROR)
}
Expand Down
11 changes: 2 additions & 9 deletions alicloud/data_source_alicloud_adb_resource_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -99,26 +98,20 @@ func dataSourceAlicloudAdbResourceGroupsRead(d *schema.ResourceData, meta interf
}
}

conn, err := client.NewAdsClient()
if err != nil {
return WrapError(err)
}
var objects []interface{}
var response map[string]interface{}
var err error
action := "DescribeDBResourceGroup"
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-03-15"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("adb", "2019-03-15", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
response = resp
addDebug(action, response, request)
return nil
})
Expand Down
Loading

0 comments on commit 33414e4

Please sign in to comment.