Skip to content

Commit

Permalink
Refactor properties based on feedback
Browse files Browse the repository at this point in the history
Move the properties high level, rename some of them to a more meaningful
name.
  • Loading branch information
tevesz committed Dec 16, 2024
1 parent b42887f commit 27c1b72
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 242 deletions.
86 changes: 36 additions & 50 deletions resources/dw/virtualwarehouse/hive/model_hive_vw.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,48 +20,40 @@ import (
"github.com/cloudera/terraform-provider-cdp/utils"
)

type autoscaling struct {
MinClusters types.Int64 `tfsdk:"min_clusters"`
MaxClusters types.Int64 `tfsdk:"max_clusters"`
DisableAutoSuspend types.Bool `tfsdk:"disable_auto_suspend"`
AutoSuspendTimeoutSeconds types.Int64 `tfsdk:"auto_suspend_timeout_seconds"`
HiveScaleWaitTimeSeconds types.Int64 `tfsdk:"hive_scale_wait_time_seconds"`
HiveDesiredFreeCapacity types.Int64 `tfsdk:"hive_desired_free_capacity"`
}

type awsOptions struct {
AvailabilityZone types.String `tfsdk:"availability_zone"`
EbsLLAPSpillGb types.Int64 `tfsdk:"ebs_llap_spill_gb"`
Tags types.Map `tfsdk:"tags"`
}

type queryIsolationOptions struct {
MaxQueries types.Int64 `tfsdk:"max_queries"`
MaxNodesPerQuery types.Int64 `tfsdk:"max_nodes_per_query"`
}

type resourceModel struct {
ID types.String `tfsdk:"id"`
ClusterID types.String `tfsdk:"cluster_id"`
DatabaseCatalogID types.String `tfsdk:"database_catalog_id"`
Name types.String `tfsdk:"name"`
ImageVersion types.String `tfsdk:"image_version"`
NodeCount types.Int64 `tfsdk:"node_count"`
PlatformJwtAuth types.Bool `tfsdk:"platform_jwt_auth"`
LdapGroups types.List `tfsdk:"ldap_groups"`
EnableSSO types.Bool `tfsdk:"enable_sso"`
Compactor types.Bool `tfsdk:"compactor"`
JdbcUrl types.String `tfsdk:"jdbc_url"`
KerberosJdbcUrl types.String `tfsdk:"kerberos_jdbc_url"`
HueUrl types.String `tfsdk:"hue_url"`
JwtConnectionString types.String `tfsdk:"jwt_connection_string"`
JwtTokenGenUrl types.String `tfsdk:"jwt_token_gen_url"`
Autoscaling *autoscaling `tfsdk:"autoscaling"`
AwsOptions *awsOptions `tfsdk:"aws_options"`
QueryIsolationOptions *queryIsolationOptions `tfsdk:"query_isolation_options"`
LastUpdated types.String `tfsdk:"last_updated"`
Status types.String `tfsdk:"status"`
PollingOptions *utils.PollingOptions `tfsdk:"polling_options"`
ID types.String `tfsdk:"id"`
ClusterID types.String `tfsdk:"cluster_id"`
DatabaseCatalogID types.String `tfsdk:"database_catalog_id"`
Name types.String `tfsdk:"name"`
ImageVersion types.String `tfsdk:"image_version"`
GroupSize types.Int64 `tfsdk:"group_size"`
PlatformJwtAuth types.Bool `tfsdk:"platform_jwt_auth"`
LdapGroups types.List `tfsdk:"ldap_groups"`
EnableSSO types.Bool `tfsdk:"enable_sso"`
Compactor types.Bool `tfsdk:"compactor"`
JdbcUrl types.String `tfsdk:"jdbc_url"`
KerberosJdbcUrl types.String `tfsdk:"kerberos_jdbc_url"`
HueUrl types.String `tfsdk:"hue_url"`
JwtConnectionString types.String `tfsdk:"jwt_connection_string"`
JwtTokenGenUrl types.String `tfsdk:"jwt_token_gen_url"`
MinGroupCount types.Int64 `tfsdk:"min_group_count"`
MaxGroupCount types.Int64 `tfsdk:"max_group_count"`
DisableAutoSuspend types.Bool `tfsdk:"disable_auto_suspend"`
AutoSuspendTimeoutSeconds types.Int64 `tfsdk:"auto_suspend_timeout_seconds"`
ScaleWaitTimeSeconds types.Int64 `tfsdk:"scale_wait_time_seconds"`
Headroom types.Int64 `tfsdk:"headroom"`
MaxConcurrentIsolatedQueries types.Int64 `tfsdk:"max_concurrent_isolated_queries"`
MaxNodesPerIsolatedQuery types.Int64 `tfsdk:"max_nodes_per_isolated_query"`
AwsOptions *awsOptions `tfsdk:"aws_options"`
LastUpdated types.String `tfsdk:"last_updated"`
Status types.String `tfsdk:"status"`
PollingOptions *utils.PollingOptions `tfsdk:"polling_options"`
}

func (p *resourceModel) GetPollingOptions() *utils.PollingOptions {
Expand All @@ -76,7 +68,7 @@ func (p *resourceModel) convertToCreateVwRequest() *models.CreateVwRequest {
EbsLLAPSpillGB: p.getEbsLLAPSpillGB(),
ImageVersion: p.getImageVersion(),
Name: p.Name.ValueStringPointer(),
NodeCount: utils.Int64To32(p.NodeCount),
NodeCount: utils.Int64To32(p.GroupSize),
PlatformJwtAuth: p.PlatformJwtAuth.ValueBoolPointer(),
QueryIsolationOptions: p.getQueryIsolationOptions(),
Autoscaling: p.getAutoscaling(),
Expand Down Expand Up @@ -122,12 +114,9 @@ func (p *resourceModel) getTags() []*models.TagRequest {
}

func (p *resourceModel) getQueryIsolationOptions() *models.QueryIsolationOptionsRequest {
if p.QueryIsolationOptions == nil {
return nil
}
return &models.QueryIsolationOptionsRequest{
MaxQueries: utils.Int64To32(p.QueryIsolationOptions.MaxQueries),
MaxNodesPerQuery: utils.Int64To32(p.QueryIsolationOptions.MaxNodesPerQuery),
MaxQueries: utils.Int64To32(p.MaxConcurrentIsolatedQueries),
MaxNodesPerQuery: utils.Int64To32(p.MaxNodesPerIsolatedQuery),
}
}

Expand All @@ -146,16 +135,13 @@ func (p *resourceModel) getEbsLLAPSpillGB() int32 {
}

func (p *resourceModel) getAutoscaling() *models.AutoscalingOptionsCreateRequest {
if p.Autoscaling == nil {
return nil
}
return &models.AutoscalingOptionsCreateRequest{
MinClusters: utils.Int64To32Pointer(p.Autoscaling.MinClusters),
MaxClusters: utils.Int64To32Pointer(p.Autoscaling.MaxClusters),
DisableAutoSuspend: p.Autoscaling.DisableAutoSuspend.ValueBool(),
AutoSuspendTimeoutSeconds: utils.Int64To32(p.Autoscaling.AutoSuspendTimeoutSeconds),
HiveScaleWaitTimeSeconds: utils.Int64To32(p.Autoscaling.HiveScaleWaitTimeSeconds),
HiveDesiredFreeCapacity: utils.Int64To32(p.Autoscaling.HiveDesiredFreeCapacity),
MinClusters: utils.Int64To32Pointer(p.MinGroupCount),
MaxClusters: utils.Int64To32Pointer(p.MaxGroupCount),
DisableAutoSuspend: p.DisableAutoSuspend.ValueBool(),
AutoSuspendTimeoutSeconds: utils.Int64To32(p.AutoSuspendTimeoutSeconds),
HiveScaleWaitTimeSeconds: utils.Int64To32(p.ScaleWaitTimeSeconds),
HiveDesiredFreeCapacity: utils.Int64To32(p.Headroom),
}
}

Expand Down
22 changes: 8 additions & 14 deletions resources/dw/virtualwarehouse/hive/resource_hive_vw_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ func TestAccHive_basic(t *testing.T) {
resource.TestCheckResourceAttr("cdp_dw_vw_hive.test_hive", "database_catalog_id", params.DatabaseCatalogID),
resource.TestCheckResourceAttrSet("cdp_dw_vw_hive.test_hive", "compactor"),
resource.TestCheckResourceAttrSet("cdp_dw_vw_hive.test_hive", "jdbc_url"),
resource.TestCheckResourceAttrSet("cdp_dw_vw_hive.test_hive", "kerberos_jdbc_url"),
resource.TestCheckResourceAttrSet("cdp_dw_vw_hive.test_hive", "hue_url"),
resource.TestCheckResourceAttrSet("cdp_dw_vw_hive.test_hive", "jwt_connection_string"),
resource.TestCheckResourceAttrSet("cdp_dw_vw_hive.test_hive", "jwt_token_gen_url"),
),
},
Expand All @@ -86,27 +84,23 @@ func testAccHiveBasicConfig(params hiveTestParameters) string {
cluster_id = %[1]q
database_catalog_id = %[2]q
name = %[3]q
node_count = 2
group_size = 2
platform_jwt_auth = true
enable_sso = true
autoscaling = {
min_clusters = 2
max_clusters = 5
disable_auto_suspend = false
auto_suspend_timeout_seconds = 100
hive_scale_wait_time_seconds = 230
}
min_group_count = 2
max_group_count = 5
disable_auto_suspend = false
auto_suspend_timeout_seconds = 100
scale_wait_time_seconds = 230
max_concurrent_isolated_queries = 10
max_nodes_per_isolated_query = 10
aws_options = {
availability_zone = "us-west-2a"
ebs_llap_spill_gb = 300
tags = {
owner = "[email protected]"
}
}
query_isolation_options = {
max_queries = 100
max_nodes_per_query = 10
}
}
`, params.ClusterID, params.DatabaseCatalogID, params.Name)
}
Expand Down
Loading

0 comments on commit 27c1b72

Please sign in to comment.