Skip to content

Commit

Permalink
New Resource: alicloud_schedulerx_app_group; New Resource: alicloud_s…
Browse files Browse the repository at this point in the history
…chedulerx_job; resource/alicloud_schedulerx_namespace: add new attribute namespace_uid.
  • Loading branch information
ChenHanZhang committed Dec 25, 2024
1 parent 0ed2303 commit 981e821
Show file tree
Hide file tree
Showing 12 changed files with 2,601 additions and 113 deletions.
27 changes: 26 additions & 1 deletion alicloud/connectivity/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package connectivity

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"log"
"net/http"
"net/url"
Expand All @@ -13,6 +12,8 @@ import (
"sync"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"

util "github.com/alibabacloud-go/tea-utils/service"

ossclient "github.com/alibabacloud-go/alibabacloud-gateway-oss/client"
Expand Down Expand Up @@ -5957,3 +5958,27 @@ func (client *AliyunClient) NewPaiClient() (*roa.Client, error) {
}
return conn, nil
}
func (client *AliyunClient) NewSchedulerxClient() (*rpc.Client, error) {
productCode := "edasschedulerx"
endpoint := ""
if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" {
if err := client.loadEndpoint(productCode); err != nil {
endpoint = fmt.Sprintf("schedulerx.%s.aliyuncs.com", client.config.RegionId)
client.config.Endpoints.Store(productCode, endpoint)
log.Printf("[ERROR] loading %s endpoint got an error: %#v. Using the endpoint %s instead.", productCode, err, endpoint)
}
}
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
}
4 changes: 3 additions & 1 deletion alicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,8 @@ func Provider() terraform.ResourceProvider {
"alicloud_cms_site_monitors": dataSourceAliCloudCloudMonitorServiceSiteMonitors(),
},
ResourcesMap: map[string]*schema.Resource{
"alicloud_schedulerx_app_group": resourceAliCloudSchedulerxAppGroup(),
"alicloud_schedulerx_job": resourceAliCloudSchedulerxJob(),
"alicloud_express_connect_router_grant_association": resourceAliCloudExpressConnectRouterGrantAssociation(),
"alicloud_live_caster": resourceAliCloudLiveCaster(),
"alicloud_vpc_ipam_ipam_pool_allocation": resourceAliCloudVpcIpamIpamPoolAllocation(),
Expand Down Expand Up @@ -1671,7 +1673,7 @@ func Provider() terraform.ResourceProvider {
"alicloud_cms_sls_group": resourceAlicloudCmsSlsGroup(),
"alicloud_config_aggregate_delivery": resourceAliCloudConfigAggregateDelivery(),
"alicloud_edas_namespace": resourceAlicloudEdasNamespace(),
"alicloud_schedulerx_namespace": resourceAlicloudSchedulerxNamespace(),
"alicloud_schedulerx_namespace": resourceAliCloudSchedulerxNamespace(),
"alicloud_ehpc_cluster": resourceAlicloudEhpcCluster(),
"alicloud_cen_traffic_marking_policy": resourceAliCloudCenTrafficMarkingPolicy(),
"alicloud_ecs_instance_set": resourceAlicloudEcsInstanceSet(),
Expand Down
322 changes: 322 additions & 0 deletions alicloud/resource_alicloud_schedulerx_app_group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,322 @@
// Package alicloud. This file is generated automatically. Please do not modify it manually, thank you!
package alicloud

import (
"fmt"
"log"
"strconv"
"strings"
"time"

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"
)

func resourceAliCloudSchedulerxAppGroup() *schema.Resource {
return &schema.Resource{
Create: resourceAliCloudSchedulerxAppGroupCreate,
Read: resourceAliCloudSchedulerxAppGroupRead,
Update: resourceAliCloudSchedulerxAppGroupUpdate,
Delete: resourceAliCloudSchedulerxAppGroupDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(5 * time.Minute),
Update: schema.DefaultTimeout(5 * time.Minute),
Delete: schema.DefaultTimeout(5 * time.Minute),
},
Schema: map[string]*schema.Schema{
"app_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"app_type": {
Type: schema.TypeInt,
Optional: true,
},
"app_version": {
Type: schema.TypeString,
Optional: true,
},
"delete_jobs": {
Type: schema.TypeBool,
Optional: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
},
"enable_log": {
Type: schema.TypeBool,
Optional: true,
},
"group_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"max_concurrency": {
Type: schema.TypeInt,
Optional: true,
},
"max_jobs": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},
"monitor_config_json": {
Type: schema.TypeString,
Optional: true,
},
"monitor_contacts_json": {
Type: schema.TypeString,
Optional: true,
},
"namespace": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"namespace_name": {
Type: schema.TypeString,
Required: true,
},
"namespace_source": {
Type: schema.TypeString,
Optional: true,
},
"schedule_busy_workers": {
Type: schema.TypeBool,
Optional: true,
},
},
}
}

func resourceAliCloudSchedulerxAppGroupCreate(d *schema.ResourceData, meta interface{}) error {

client := meta.(*connectivity.AliyunClient)

action := "CreateAppGroup"
var request map[string]interface{}
var response map[string]interface{}
query := make(map[string]interface{})
conn, err := client.NewSchedulerxClient()
if err != nil {
return WrapError(err)
}
request = make(map[string]interface{})
query["Namespace"] = d.Get("namespace")
query["GroupId"] = d.Get("group_id")
query["RegionId"] = client.RegionId

if v, ok := d.GetOk("description"); ok {
query["Description"] = StringPointer(v.(string))
}

if v, ok := d.GetOk("monitor_config_json"); ok {
query["MonitorConfigJson"] = StringPointer(v.(string))
}

if v, ok := d.GetOk("max_jobs"); ok {
query["MaxJobs"] = StringPointer(strconv.Itoa(v.(int)))
}

if v, ok := d.GetOk("app_type"); ok {
query["AppType"] = StringPointer(strconv.Itoa(v.(int)))
}

if v, ok := d.GetOk("schedule_busy_workers"); ok {
query["ScheduleBusyWorkers"] = StringPointer(strconv.FormatBool(v.(bool)))
}

if v, ok := d.GetOk("namespace_source"); ok {
query["NamespaceSource"] = StringPointer(v.(string))
}

if v, ok := d.GetOk("namespace_name"); ok {
query["NamespaceName"] = StringPointer(v.(string))
}

if v, ok := d.GetOk("enable_log"); ok {
query["EnableLog"] = StringPointer(strconv.FormatBool(v.(bool)))
}

if v, ok := d.GetOk("app_name"); ok {
query["AppName"] = StringPointer(v.(string))
}

if v, ok := d.GetOk("app_version"); ok {
query["AppVersion"] = StringPointer(v.(string))
}

if v, ok := d.GetOk("monitor_contacts_json"); ok {
query["MonitorContactsJson"] = StringPointer(v.(string))
}

runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 5*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("GET"), StringPointer("2019-04-30"), StringPointer("AK"), query, request, &runtime)
if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
addDebug(action, response, request)

if err != nil {
return WrapErrorf(err, DefaultErrorMsg, "alicloud_schedulerx_app_group", action, AlibabaCloudSdkGoERROR)
}

d.SetId(fmt.Sprintf("%v:%v", query["Namespace"], query["GroupId"]))

return resourceAliCloudSchedulerxAppGroupRead(d, meta)
}

func resourceAliCloudSchedulerxAppGroupRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.AliyunClient)
schedulerxServiceV2 := SchedulerxServiceV2{client}

objectRaw, err := schedulerxServiceV2.DescribeSchedulerxAppGroup(d.Id())
if err != nil {
if !d.IsNewResource() && NotFoundError(err) {
log.Printf("[DEBUG] Resource alicloud_schedulerx_app_group DescribeSchedulerxAppGroup Failed!!! %s", err)
d.SetId("")
return nil
}
return WrapError(err)
}

if objectRaw["AppName"] != nil {
d.Set("app_name", objectRaw["AppName"])
}
if objectRaw["AppVersion"] != nil {
d.Set("app_version", objectRaw["AppVersion"])
}
if objectRaw["Description"] != nil {
d.Set("description", objectRaw["Description"])
}
if objectRaw["MaxJobs"] != nil {
d.Set("max_jobs", objectRaw["MaxJobs"])
}
if objectRaw["GroupId"] != nil {
d.Set("group_id", objectRaw["GroupId"])
}

parts := strings.Split(d.Id(), ":")
d.Set("namespace", parts[0])

return nil
}

func resourceAliCloudSchedulerxAppGroupUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.AliyunClient)
var request map[string]interface{}
var response map[string]interface{}
var query map[string]interface{}
update := false

parts := strings.Split(d.Id(), ":")
action := "UpdateAppGroup"
conn, err := client.NewSchedulerxClient()
if err != nil {
return WrapError(err)
}
request = make(map[string]interface{})
query = make(map[string]interface{})
request["Namespace"] = parts[0]
request["GroupId"] = parts[1]
request["RegionId"] = client.RegionId
if d.HasChange("description") {
update = true
request["Description"] = d.Get("description")
}

if d.HasChange("app_version") {
update = true
request["AppVersion"] = d.Get("app_version")
}

if v, ok := d.GetOkExists("max_concurrency"); ok {
request["MaxConcurrency"] = v
}
if update {
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 5*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-04-30"), StringPointer("AK"), query, request, &runtime)
if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
addDebug(action, response, request)
if err != nil {
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
}
}

return resourceAliCloudSchedulerxAppGroupRead(d, meta)
}

func resourceAliCloudSchedulerxAppGroupDelete(d *schema.ResourceData, meta interface{}) error {

client := meta.(*connectivity.AliyunClient)
parts := strings.Split(d.Id(), ":")
action := "DeleteAppGroup"
var request map[string]interface{}
var response map[string]interface{}
query := make(map[string]interface{})
conn, err := client.NewSchedulerxClient()
if err != nil {
return WrapError(err)
}
request = make(map[string]interface{})
request["Namespace"] = parts[0]
request["GroupId"] = parts[1]
request["RegionId"] = client.RegionId

if v, ok := d.GetOkExists("delete_jobs"); ok {
request["DeleteJobs"] = v
}
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 5*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-04-30"), StringPointer("AK"), query, request, &runtime)

if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
addDebug(action, response, request)

if err != nil {
if NotFoundError(err) {
return nil
}
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
}

return nil
}
Loading

0 comments on commit 981e821

Please sign in to comment.