Skip to content

Commit 35bc103

Browse files
authored
feat: Adapt to the new API and adjust some resource schema structures (#76)
* feat: add deploy profile data source and related API functionality * feat: enhance import state handling for Kafka resources with structured ID format * feat: add identifier attribute for import state verification in Kafka topic resource tests * feat: add data bucket profiles data source and related API functionality * feat: add automq deploy profile data source and update Kafka instance configuration * feat: improve error handling and logging in Kafka instance operations * feat: add documentation for automq_data_bucket_profiles data source and update deploy profile example * feat: update integration types and configurations for Prometheus support * feat: standardize spacing in automq deploy profile and Kafka instance configurations * feat: enable PreCheck in Kafka ACL and instance resource tests * feat: update lifecycle stage from General Availability to Preview in documentation and provider metadata * feat: update lifecycle stage from General Availability to Preview in documentation and resource templates * feat: add compatibility note for AutoMQ provider version in documentation * feat: add deploy profile attribute to integration model and update related documentation * feat: remove 'prometheus' from integration type options in documentation and provider schema * feat: remove 'BYOK' option from data encryption mode in Kafka instance documentation and schema * feat: enhance integration handling by adding support for Set data type and new API methods * feat: fix integration instance patching and handle empty integrations in Kafka model * feat: update documentation for automq_data_bucket_profiles and kafka_instance to clarify deployment profile and data bucket details * feat: add automq_data_bucket_profiles data source and update kafka_instance examples to use it * feat: update markdown descriptions for encryption modes in Kafka instance documentation * feat: update documentation to clarify compatibility with AutoMQ control plane versions 7.3.5 and later * feat: add PreCheck function to resource test cases for improved validation * feat: skip tests if AUTOMQ_BYOC_ENDPOINT is not set for improved test reliability * fix: correct spelling of 'Integration' in API methods for consistency
1 parent 39acd89 commit 35bc103

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4615
-1328
lines changed

client/api_deploy_profile.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package client
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
)
8+
9+
const (
10+
GetDeployProfilePath = "/api/v1/profiles/%s"
11+
GetBucketProfilePath = "/api/v1/deploy-profiles/%s/data-bucket-profiles"
12+
)
13+
14+
// GetDeployProfile retrieves a deployment profile by name
15+
func (c *Client) GetDeployProfile(ctx context.Context, name string) (*DeployProfileVO, error) {
16+
data, err := c.Get(ctx, fmt.Sprintf(GetDeployProfilePath, name), nil)
17+
if err != nil {
18+
return nil, err
19+
}
20+
21+
var profile DeployProfileVO
22+
err = json.Unmarshal(data, &profile)
23+
if err != nil {
24+
return nil, fmt.Errorf("get deploy profile error: %s \nmaybe the profile does not exist", string(data))
25+
}
26+
27+
return &profile, nil
28+
}
29+
30+
// GetBucketProfile retrieves a bucket profile by name
31+
func (c *Client) GetBucketProfiles(ctx context.Context, name string) (*PageNumResultBucketProfileVO, error) {
32+
data, err := c.Get(ctx, fmt.Sprintf(GetBucketProfilePath, name), nil)
33+
if err != nil {
34+
return nil, err
35+
}
36+
37+
var profiles PageNumResultBucketProfileVO
38+
err = json.Unmarshal(data, &profiles)
39+
if err != nil {
40+
return nil, fmt.Errorf("error unmarshaling bucket profile response: %v", err)
41+
}
42+
43+
return &profiles, nil
44+
}

client/api_intergation.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77
)
88

99
const (
10-
IntegrationPath = "/api/v1/integrations"
11-
GetIntegrationPath = "/api/v1/integrations/%s"
12-
PatchIntegrationPath = "/api/v1/integrations/%s"
13-
ListInstanceIntegrationsPath = "/api/v1/instances/%s/integrations"
10+
IntegrationPath = "/api/v1/integrations"
11+
GetIntegrationPath = "/api/v1/integrations/%s"
12+
PatchIntegrationPath = "/api/v1/integrations/%s"
13+
InstanceIntegrationPath = "/api/v1/instances/%s/integrations"
14+
RemoveInstanceIntergationPath = "/api/v1/instances/%s/integrations/%s"
1415
)
1516

16-
func (c *Client) CreateIntergration(ctx context.Context, param IntegrationParam) (*IntegrationVO, error) {
17+
func (c *Client) CreateIntegration(ctx context.Context, param IntegrationParam) (*IntegrationVO, error) {
1718
body, err := c.Post(ctx, IntegrationPath, param)
1819
if err != nil {
1920
return nil, err
@@ -55,6 +56,22 @@ func (c *Client) UpdateIntergration(ctx context.Context, integrationId string, p
5556
return &integration, nil
5657
}
5758

59+
func (c *Client) AddInstanceIntergation(ctx context.Context, instanceId string, param *IntegrationInstanceAddParam) error {
60+
_, err := c.Patch(ctx, fmt.Sprintf(InstanceIntegrationPath, instanceId), param)
61+
if err != nil {
62+
return err
63+
}
64+
return nil
65+
}
66+
67+
func (c *Client) RemoveInstanceIntergation(ctx context.Context, instanceId string, integrationId string) error {
68+
_, err := c.Delete(ctx, fmt.Sprintf(RemoveInstanceIntergationPath, instanceId, integrationId))
69+
if err != nil {
70+
return err
71+
}
72+
return nil
73+
}
74+
5875
func (c *Client) DeleteIntergration(ctx context.Context, integrationId string) error {
5976
_, err := c.Delete(ctx, fmt.Sprintf(PatchIntegrationPath, integrationId))
6077
if err != nil {
@@ -64,7 +81,7 @@ func (c *Client) DeleteIntergration(ctx context.Context, integrationId string) e
6481
}
6582

6683
func (c *Client) ListInstanceIntegrations(ctx context.Context, instanceId string) ([]IntegrationVO, error) {
67-
body, err := c.Get(ctx, fmt.Sprintf(ListInstanceIntegrationsPath, instanceId), nil)
84+
body, err := c.Get(ctx, fmt.Sprintf(InstanceIntegrationPath, instanceId), nil)
6885
if err != nil {
6986
return nil, err
7087
}

client/api_kafka_instance.go

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,51 @@ const (
1717
UpdateInstanceBasicInfoPath = "/api/v1/instances/%s/basic"
1818
UpdateInstanceVersionPath = "/api/v1/instances/%s/versions/%s"
1919
UpdateInstanceComputeSpecsPath = "/api/v1/instances/%s/spec"
20+
UpdateInstancePath = "/api/v1/instances/%s"
21+
UpdateInstanceCertificatePath = "/api/v1/instances/%s/certificate"
2022
)
2123

22-
func (c *Client) CreateKafkaInstance(ctx context.Context, kafka KafkaInstanceRequest) (*KafkaInstanceResponse, error) {
24+
func (c *Client) CreateKafkaInstance(ctx context.Context, kafka InstanceCreateParam) (*InstanceSummaryVO, error) {
2325
body, err := c.Post(ctx, InstancePath, kafka)
2426
if err != nil {
2527
return nil, err
2628
}
27-
newkafka := KafkaInstanceResponse{}
29+
newkafka := InstanceSummaryVO{}
2830
err = json.Unmarshal(body, &newkafka)
2931
if err != nil {
3032
return nil, err
3133
}
3234
return &newkafka, nil
3335
}
3436

35-
func (c *Client) GetKafkaInstance(ctx context.Context, instanceId string) (*KafkaInstanceResponse, error) {
37+
func (c *Client) GetKafkaInstance(ctx context.Context, instanceId string) (*InstanceVO, error) {
3638
body, err := c.Get(ctx, fmt.Sprintf(GetInstancePath, instanceId), nil)
3739
if err != nil {
3840
return nil, err
3941
}
40-
instance := KafkaInstanceResponse{}
42+
instance := InstanceVO{}
4143
err = json.Unmarshal(body, &instance)
4244
if err != nil {
4345
return nil, err
4446
}
4547
return &instance, nil
4648
}
4749

48-
func (c *Client) GetKafkaInstanceByName(ctx context.Context, name string) (*KafkaInstanceResponse, error) {
50+
func (c *Client) GetKafkaInstanceByName(ctx context.Context, name string) (*InstanceVO, error) {
4951
queryParams := make(map[string]string)
5052
queryParams["keyword"] = name
5153
body, err := c.Get(ctx, InstancePath, queryParams)
5254
if err != nil {
5355
return nil, err
5456
}
55-
instances := KafkaInstanceResponseList{}
57+
instances := PageNumResultInstanceVO{}
5658
err = json.Unmarshal(body, &instances)
5759
if err != nil {
5860
return nil, err
5961
}
6062
if len(instances.List) > 0 {
6163
for _, item := range instances.List {
62-
if item.DisplayName == name {
64+
if *item.Name == name {
6365
return &item, nil
6466
}
6567
}
@@ -131,27 +133,31 @@ func (c *Client) UpdateKafkaInstanceVersion(ctx context.Context, instanceId stri
131133
return nil
132134
}
133135

134-
func (c *Client) UpdateKafkaInstanceBasicInfo(ctx context.Context, instanceId string, updateParam InstanceBasicParam) (*KafkaInstanceResponse, error) {
136+
func (c *Client) UpdateKafkaInstanceBasicInfo(ctx context.Context, instanceId string, updateParam InstanceBasicParam) error {
135137
return c.updateInstance(ctx, instanceId, updateParam, UpdateInstanceBasicInfoPath)
136138
}
137139

138-
func (c *Client) UpdateKafkaInstanceConfig(ctx context.Context, instanceId string, updateParam InstanceConfigParam) (*KafkaInstanceResponse, error) {
140+
func (c *Client) UpdateKafkaInstanceConfig(ctx context.Context, instanceId string, updateParam InstanceConfigParam) error {
139141
return c.updateInstance(ctx, instanceId, updateParam, InstanceConfigPath)
140142
}
141143

142-
func (c *Client) UpdateKafkaInstanceComputeSpecs(ctx context.Context, instanceId string, updateParam SpecificationUpdateParam) (*KafkaInstanceResponse, error) {
143-
return c.updateInstance(ctx, instanceId, updateParam, UpdateInstanceComputeSpecsPath)
144+
func (c *Client) UpdateKafkaInstanceComputeSpecs(ctx context.Context, instanceId string, updateParam InstanceUpdateParam) error {
145+
return c.updateInstance(ctx, instanceId, updateParam, UpdateInstancePath)
144146
}
145147

146-
func (c *Client) updateInstance(ctx context.Context, instanceId string, updateParam interface{}, path string) (*KafkaInstanceResponse, error) {
147-
body, err := c.Patch(ctx, fmt.Sprintf(path, instanceId), updateParam)
148+
func (c *Client) UpdateKafkaInstanceCertificate(ctx context.Context, instanceId string, updateParam InstanceCertificateParam) error {
149+
_, err := c.Put(ctx, fmt.Sprintf(UpdateInstanceCertificatePath, instanceId), updateParam)
148150
if err != nil {
149-
return nil, err
151+
return err
150152
}
151-
instance := KafkaInstanceResponse{}
152-
err = json.Unmarshal(body, &instance)
153+
return nil
154+
}
155+
156+
func (c *Client) updateInstance(ctx context.Context, instanceId string, updateParam interface{}, path string) error {
157+
_, err := c.Patch(ctx, fmt.Sprintf(path, instanceId), updateParam)
153158
if err != nil {
154-
return nil, err
159+
return err
155160
}
156-
return &instance, nil
161+
162+
return nil
157163
}

client/client.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type Client struct {
1818
Token string
1919
Credentials AuthCredentials
2020
Signer *signer.Signer
21+
MaxRetries int
22+
RetryDelay time.Duration
2123
}
2224

2325
type EnvironmentID string
@@ -67,17 +69,44 @@ func (e *ErrorResponse) Error() string {
6769

6870
func NewClient(ctx context.Context, host string, credentials AuthCredentials) (*Client, error) {
6971
c := &Client{
70-
HTTPClient: &http.Client{Timeout: 0 * time.Second},
72+
HTTPClient: &http.Client{
73+
Timeout: 30 * time.Second,
74+
},
7175
HostURL: host,
7276
Credentials: credentials,
7377
Signer: signer.NewSigner(signer.Credentials{
7478
AccessKeyID: credentials.AccessKeyID,
7579
SecretAccessKey: credentials.SecretAccessKey,
7680
}),
81+
MaxRetries: 3,
82+
RetryDelay: 500 * time.Millisecond,
7783
}
7884
return c, nil
7985
}
8086

87+
func (c *Client) retryOperation(operation func() ([]byte, error)) ([]byte, error) {
88+
var lastErr error
89+
for i := 0; i <= c.MaxRetries; i++ {
90+
if i > 0 {
91+
time.Sleep(c.RetryDelay)
92+
}
93+
94+
result, err := operation()
95+
if err == nil {
96+
return result, nil
97+
}
98+
99+
lastErr = err
100+
// only retry on server errors (5xx) or network errors
101+
if e, ok := err.(*ErrorResponse); ok {
102+
if e.Code < 500 && e.Code != 0 {
103+
return nil, err
104+
}
105+
}
106+
}
107+
return nil, fmt.Errorf("after %d retries: %v", c.MaxRetries, lastErr)
108+
}
109+
81110
func (c *Client) Post(ctx context.Context, path string, body interface{}) ([]byte, error) {
82111
b, err := json.Marshal(body)
83112
if err != nil {
@@ -90,7 +119,11 @@ func (c *Client) Get(ctx context.Context, path string, queryParams map[string]st
90119
if queryParams != nil {
91120
path += "?" + buildQueryParams(queryParams)
92121
}
93-
return c.doRequest(ctx, "GET", path, nil)
122+
123+
operation := func() ([]byte, error) {
124+
return c.doRequest(ctx, "GET", path, nil)
125+
}
126+
return c.retryOperation(operation)
94127
}
95128

96129
func (c *Client) Delete(ctx context.Context, path string) ([]byte, error) {

client/model_deploy_profile.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package client
2+
3+
import "time"
4+
5+
// DeployProfileVO represents the response structure for a deployment profile
6+
type DeployProfileVO struct {
7+
Name *string `json:"name,omitempty"`
8+
Provider *string `json:"provider,omitempty"`
9+
Region *string `json:"region,omitempty"`
10+
Vpc *string `json:"vpc,omitempty"`
11+
InstancePlatform *string `json:"instancePlatform,omitempty"`
12+
CredentialType *string `json:"credentialType,omitempty"`
13+
ClusterId *string `json:"clusterId,omitempty"`
14+
GmtCreate *time.Time `json:"gmtCreate,omitempty"`
15+
GmtModified *time.Time `json:"gmtModified,omitempty"`
16+
Available *bool `json:"available,omitempty"`
17+
System *bool `json:"system,omitempty"`
18+
KubeConfig *string `json:"kubeConfig,omitempty"`
19+
OpsBucket *BucketProfileDetailVO `json:"opsBucket,omitempty"`
20+
DnsZone *string `json:"dnsZone,omitempty"`
21+
InstanceProfile *string `json:"instanceProfile,omitempty"`
22+
CredentialId *string `json:"credentialId,omitempty"`
23+
}
24+
25+
// BucketProfileVO
26+
type PageNumResultBucketProfileVO struct {
27+
PageNum *int32 `json:"pageNum,omitempty"`
28+
PageSize *int32 `json:"pageSize,omitempty"`
29+
Total *int64 `json:"total,omitempty"`
30+
List []BucketProfileVO `json:"list,omitempty"`
31+
TotalPage *int64 `json:"totalPage,omitempty"`
32+
}
33+
34+
// BucketProfileVO struct for BucketProfileVO
35+
type BucketProfileVO struct {
36+
Id *string `json:"id,omitempty"`
37+
BucketName *string `json:"bucketName,omitempty"`
38+
GmtCreate *time.Time `json:"gmtCreate,omitempty"`
39+
GmtModified *time.Time `json:"gmtModified,omitempty"`
40+
}
41+
42+
// BucketProfileDetailVO represents the response structure for a bucket profile
43+
type BucketProfileDetailVO struct {
44+
Id *string `json:"id,omitempty"`
45+
BucketName *string `json:"bucketName,omitempty"`
46+
GmtCreate *time.Time `json:"gmtCreate,omitempty"`
47+
GmtModified *time.Time `json:"gmtModified,omitempty"`
48+
Provider *string `json:"provider,omitempty"`
49+
Region *string `json:"region,omitempty"`
50+
}

client/model_integration.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type IntegrationVO struct {
99
Type string `json:"type,omitempty"`
1010
Code string `json:"code,omitempty"`
1111
Name string `json:"name,omitempty"`
12+
Profile string `json:"profile,omitempty"`
1213
EndPoint *string `json:"endPoint,omitempty"`
1314
Config map[string]interface{} `json:"config,omitempty"`
1415
}
@@ -17,6 +18,7 @@ type IntegrationVO struct {
1718
type IntegrationParam struct {
1819
Type *string `json:"type,omitempty"`
1920
Name string `json:"name" validate:"regexp=^[a-zA-Z\\\\u4e00-\\\\u9fa5][a-z0-9A-Z\\\\u4e00-\\\\u9fa5_\\\\s-]*$"`
21+
Profile string `json:"profile"`
2022
EndPoint string `json:"endPoint"`
2123
Config []ConfigItemParam `json:"config,omitempty"`
2224
}

0 commit comments

Comments
 (0)