Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardfeng-db committed Jun 4, 2024
1 parent 53598c5 commit a1f629b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 32 deletions.
7 changes: 1 addition & 6 deletions clusters/clusters_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,15 +497,10 @@ func (cluster *Cluster) FixInstancePoolChangeIfAny(d *schema.ResourceData) {
}

// TODO: Remove this once we fully migrate away from jobs api 2.0
func (cluster *Cluster) SetForceSendFieldsForClusterCreate(d *schema.ResourceData, getPrefix string) {
func (cluster *Cluster) SetForceSendFieldsForClusterCreate(d *schema.ResourceData) {
if cluster.Autoscale == nil {
cluster.ForceSendFields = []string{"NumWorkers"}
}
if cluster.GcpAttributes != nil {
if _, ok := d.GetOkExists(fmt.Sprintf("%s.gcp_attributes.0.local_ssd_count", getPrefix)); ok {
cluster.GcpAttributes.ForceSendFields = []string{"LocalSsdCount"}
}
}
}

// ClusterList shows existing clusters
Expand Down
14 changes: 2 additions & 12 deletions clusters/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,27 +264,17 @@ func FixInstancePoolChangeIfAny(d *schema.ResourceData, cluster any) error {
}
}

func SetForceSendFieldsForClusterCreate(cluster any, d *schema.ResourceData, getPrefix string) error {
func SetForceSendFieldsForClusterCreate(cluster any, d *schema.ResourceData) error {
switch c := cluster.(type) {
case *compute.ClusterSpec:
if c.Autoscale == nil {
c.ForceSendFields = []string{"NumWorkers"}
}
if c.GcpAttributes != nil {
if _, ok := d.GetOkExists(fmt.Sprintf("%s.gcp_attributes.0.local_ssd_count", getPrefix)); ok {
c.GcpAttributes.ForceSendFields = []string{"LocalSsdCount"}
}
}
return nil
case *compute.CreateCluster:
if c.Autoscale == nil {
c.ForceSendFields = []string{"NumWorkers"}
}
if c.GcpAttributes != nil {
if _, ok := d.GetOkExists(getPrefix + fmt.Sprintf("%s.gcp_attributes.0.local_ssd_count", getPrefix)); ok {
c.GcpAttributes.ForceSendFields = []string{"LocalSsdCount"}
}
}
return nil
default:
return fmt.Errorf(unsupportedExceptCreateEditClusterSpecErr, cluster, "*", "*", "*")
Expand Down Expand Up @@ -407,7 +397,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, c *commo
if err = ModifyRequestOnInstancePool(&createClusterRequest); err != nil {
return err
}
SetForceSendFieldsForClusterCreate(&createClusterRequest, d, "")
SetForceSendFieldsForClusterCreate(&createClusterRequest, d)
clusterWaiter, err := clusters.Create(ctx, createClusterRequest)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/acceptance/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestAccJobTasks(t *testing.T) {
job_cluster {
job_cluster_key = "j"
new_cluster {
num_workers = 20
num_workers = 0 // Setting it to zero intentionally to cover edge case.
spark_version = data.databricks_spark_version.latest.id
node_type_id = data.databricks_node_type.smallest.id
}
Expand Down
8 changes: 3 additions & 5 deletions jobs/jobs_api_go_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,16 @@ func prepareJobSettingsForUpdateGoSdk(d *schema.ResourceData, js *JobSettingsRes
}

func prepareJobSettingsForCreateGoSdk(d *schema.ResourceData, jc *JobCreateStruct) error {
for i, task := range jc.Tasks {
for _, task := range jc.Tasks {
if task.NewCluster != nil {
getPrefix := fmt.Sprintf("task.%d.new_cluster", i)
err := clusters.SetForceSendFieldsForClusterCreate(task.NewCluster, d, getPrefix)
err := clusters.SetForceSendFieldsForClusterCreate(task.NewCluster, d)
if err != nil {
return err
}
}
}
for i := range jc.JobClusters {
getPrefix := fmt.Sprintf("job_cluster.%d.new_cluster", i)
err := clusters.SetForceSendFieldsForClusterCreate(&jc.JobClusters[i].NewCluster, d, getPrefix)
err := clusters.SetForceSendFieldsForClusterCreate(&jc.JobClusters[i].NewCluster, d)
if err != nil {
return err
}
Expand Down
13 changes: 5 additions & 8 deletions jobs/resource_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -1036,19 +1036,16 @@ func prepareJobSettingsForUpdate(d *schema.ResourceData, js JobSettings) {

func prepareJobSettingsForCreate(d *schema.ResourceData, js JobSettings) {
if js.NewCluster != nil {
getPrefix := "new_cluster"
js.NewCluster.SetForceSendFieldsForClusterCreate(d, getPrefix)
js.NewCluster.SetForceSendFieldsForClusterCreate(d)
}
for i, task := range js.Tasks {
for _, task := range js.Tasks {
if task.NewCluster != nil {
getPrefix := fmt.Sprintf("task.%d.new_cluster", i)
task.NewCluster.SetForceSendFieldsForClusterCreate(d, getPrefix)
task.NewCluster.SetForceSendFieldsForClusterCreate(d)
}
}
for i, jc := range js.JobClusters {
for _, jc := range js.JobClusters {
if jc.NewCluster != nil {
getPrefix := fmt.Sprintf("job_cluster.%d.new_cluster", i)
jc.NewCluster.SetForceSendFieldsForClusterCreate(d, getPrefix)
jc.NewCluster.SetForceSendFieldsForClusterCreate(d)
}
}
}
Expand Down

0 comments on commit a1f629b

Please sign in to comment.