Skip to content

Commit 6a63f9b

Browse files
WeiMengXSWeiMengXS
andauthored
Feat/dlc datasource event (#2387)
* feat: support async task * feat: doc * feat: doc --------- Co-authored-by: WeiMengXS <nickcchen@tencent.com>
1 parent 0d31ff9 commit 6a63f9b

9 files changed

+260
-0
lines changed

.changelog/2387.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-data-source
2+
resource/tencentcloud_dlc_describe_data_engine_events
3+
```
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
package tencentcloud
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
dlc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dlc/v20210125"
9+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
10+
)
11+
12+
func dataSourceTencentCloudDlcDescribeDataEngineEvents() *schema.Resource {
13+
return &schema.Resource{
14+
Read: dataSourceTencentCloudDlcDescribeDataEngineEventsRead,
15+
Schema: map[string]*schema.Schema{
16+
"data_engine_name": {
17+
Required: true,
18+
Type: schema.TypeString,
19+
Description: "Data engine name.",
20+
},
21+
22+
"events": {
23+
Computed: true,
24+
Type: schema.TypeList,
25+
Description: "Event details.",
26+
Elem: &schema.Resource{
27+
Schema: map[string]*schema.Schema{
28+
"time": {
29+
Type: schema.TypeSet,
30+
Elem: &schema.Schema{
31+
Type: schema.TypeString,
32+
},
33+
Computed: true,
34+
Description: "Event time.",
35+
},
36+
"events_action": {
37+
Type: schema.TypeSet,
38+
Elem: &schema.Schema{
39+
Type: schema.TypeString,
40+
},
41+
Computed: true,
42+
Description: "Event action.",
43+
},
44+
"cluster_info": {
45+
Type: schema.TypeSet,
46+
Elem: &schema.Schema{
47+
Type: schema.TypeString,
48+
},
49+
Computed: true,
50+
Description: "Cluster information.",
51+
},
52+
},
53+
},
54+
},
55+
56+
"result_output_file": {
57+
Type: schema.TypeString,
58+
Optional: true,
59+
Description: "Used to save results.",
60+
},
61+
},
62+
}
63+
}
64+
65+
func dataSourceTencentCloudDlcDescribeDataEngineEventsRead(d *schema.ResourceData, meta interface{}) error {
66+
defer logElapsed("data_source.tencentcloud_dlc_describe_data_engine_events.read")()
67+
defer inconsistentCheck(d, meta)()
68+
69+
logId := getLogId(contextNil)
70+
71+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
72+
73+
paramMap := make(map[string]interface{})
74+
if v, ok := d.GetOk("data_engine_name"); ok {
75+
paramMap["DataEngineName"] = helper.String(v.(string))
76+
}
77+
78+
service := DlcService{client: meta.(*TencentCloudClient).apiV3Conn}
79+
80+
var events []*dlc.HouseEventsInfo
81+
82+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
83+
result, e := service.DescribeDlcDescribeDataEngineEventsByFilter(ctx, paramMap)
84+
if e != nil {
85+
return retryError(e)
86+
}
87+
events = result
88+
return nil
89+
})
90+
if err != nil {
91+
return err
92+
}
93+
94+
ids := make([]string, 0, len(events))
95+
tmpList := make([]map[string]interface{}, 0, len(events))
96+
97+
if events != nil {
98+
for _, houseEventsInfo := range events {
99+
houseEventsInfoMap := map[string]interface{}{}
100+
101+
if houseEventsInfo.Time != nil {
102+
houseEventsInfoMap["time"] = houseEventsInfo.Time
103+
}
104+
105+
if houseEventsInfo.EventsAction != nil {
106+
houseEventsInfoMap["events_action"] = houseEventsInfo.EventsAction
107+
}
108+
109+
if houseEventsInfo.ClusterInfo != nil {
110+
houseEventsInfoMap["cluster_info"] = houseEventsInfo.ClusterInfo
111+
}
112+
113+
tmpList = append(tmpList, houseEventsInfoMap)
114+
}
115+
116+
_ = d.Set("events", tmpList)
117+
}
118+
119+
d.SetId(helper.DataResourceIdsHash(ids))
120+
output, ok := d.GetOk("result_output_file")
121+
if ok && output.(string) != "" {
122+
if e := writeToFile(output.(string), tmpList); e != nil {
123+
return e
124+
}
125+
}
126+
return nil
127+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudDlcDescribeDataEngineEventsDataSource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheck(t)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccDlcDescribeDataEngineEventsDataSource,
19+
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_dlc_describe_data_engine_events.describe_data_engine_events")),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccDlcDescribeDataEngineEventsDataSource = `
26+
27+
data "tencentcloud_dlc_describe_data_engine_events" "describe_data_engine_events" {
28+
data_engine_name = "iac-keep-config"
29+
}
30+
31+
`
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Use this data source to query detailed information of dlc describe_data_engine_events
2+
3+
Example Usage
4+
5+
```hcl
6+
data "tencentcloud_dlc_describe_data_engine_events" "describe_data_engine_events" {
7+
data_engine_name = "test"
8+
}
9+
```

tencentcloud/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ func Provider() *schema.Provider {
861861
"tencentcloud_dlc_describe_work_group_info": dataSourceTencentCloudDlcDescribeWorkGroupInfo(),
862862
"tencentcloud_dlc_check_data_engine_config_pairs_validity": dataSourceTencentCloudDlcCheckDataEngineConfigPairsValidity(),
863863
"tencentcloud_dlc_describe_updatable_data_engines": dataSourceTencentCloudDlcDescribeUpdatableDataEngines(),
864+
"tencentcloud_dlc_describe_data_engine_events": dataSourceTencentCloudDlcDescribeDataEngineEvents(),
864865
"tencentcloud_bi_project": dataSourceTencentCloudBiProject(),
865866
"tencentcloud_bi_user_project": dataSourceTencentCloudBiUserProject(),
866867
"tencentcloud_antiddos_basic_device_status": dataSourceTencentCloudAntiddosBasicDeviceStatus(),

tencentcloud/provider.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,6 +1963,7 @@ Data Lake Compute(DLC)
19631963
tencentcloud_dlc_check_data_engine_image_can_be_upgrade
19641964
tencentcloud_dlc_check_data_engine_config_pairs_validity
19651965
tencentcloud_dlc_describe_updatable_data_engines
1966+
tencentcloud_dlc_describe_data_engine_events
19661967

19671968
Resource
19681969
tencentcloud_dlc_work_group

tencentcloud/service_tencentcloud_dlc.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,3 +782,50 @@ func (me *DlcService) DescribeDlcDescribeUpdatableDataEnginesByFilter(ctx contex
782782

783783
return
784784
}
785+
func (me *DlcService) DescribeDlcDescribeDataEngineEventsByFilter(ctx context.Context, param map[string]interface{}) (describeDataEngineEvents []*dlc.HouseEventsInfo, errRet error) {
786+
var (
787+
logId = getLogId(ctx)
788+
request = dlc.NewDescribeDataEngineEventsRequest()
789+
)
790+
791+
defer func() {
792+
if errRet != nil {
793+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
794+
}
795+
}()
796+
797+
for k, v := range param {
798+
if k == "DataEngineName" {
799+
request.DataEngineName = v.(*string)
800+
}
801+
}
802+
803+
ratelimit.Check(request.GetAction())
804+
805+
var (
806+
offset int64 = 0
807+
limit int64 = 20
808+
)
809+
for {
810+
request.Offset = &offset
811+
request.Limit = &limit
812+
response, err := me.client.UseDlcClient().DescribeDataEngineEvents(request)
813+
if err != nil {
814+
errRet = err
815+
return
816+
}
817+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
818+
819+
if response == nil || len(response.Response.Events) < 1 {
820+
break
821+
}
822+
823+
describeDataEngineEvents = append(describeDataEngineEvents, response.Response.Events...)
824+
if len(response.Response.Events) < int(limit) {
825+
break
826+
}
827+
offset += limit
828+
}
829+
830+
return
831+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
subcategory: "Data Lake Compute(DLC)"
3+
layout: "tencentcloud"
4+
page_title: "TencentCloud: tencentcloud_dlc_describe_data_engine_events"
5+
sidebar_current: "docs-tencentcloud-datasource-dlc_describe_data_engine_events"
6+
description: |-
7+
Use this data source to query detailed information of dlc describe_data_engine_events
8+
---
9+
10+
# tencentcloud_dlc_describe_data_engine_events
11+
12+
Use this data source to query detailed information of dlc describe_data_engine_events
13+
14+
## Example Usage
15+
16+
```hcl
17+
data "tencentcloud_dlc_describe_data_engine_events" "describe_data_engine_events" {
18+
data_engine_name = "test"
19+
}
20+
```
21+
22+
## Argument Reference
23+
24+
The following arguments are supported:
25+
26+
* `data_engine_name` - (Required, String) Data engine name.
27+
* `result_output_file` - (Optional, String) Used to save results.
28+
29+
## Attributes Reference
30+
31+
In addition to all arguments above, the following attributes are exported:
32+
33+
* `events` - Event details.
34+
* `cluster_info` - Cluster information.
35+
* `events_action` - Event action.
36+
* `time` - Event time.
37+
38+

website/tencentcloud.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,6 +2032,9 @@
20322032
<li>
20332033
<a href="/docs/providers/tencentcloud/d/dlc_describe_data_engine.html">tencentcloud_dlc_describe_data_engine</a>
20342034
</li>
2035+
<li>
2036+
<a href="/docs/providers/tencentcloud/d/dlc_describe_data_engine_events.html">tencentcloud_dlc_describe_data_engine_events</a>
2037+
</li>
20352038
<li>
20362039
<a href="/docs/providers/tencentcloud/d/dlc_describe_data_engine_image_versions.html">tencentcloud_dlc_describe_data_engine_image_versions</a>
20372040
</li>

0 commit comments

Comments
 (0)