diff --git a/jobs/resource_job.go b/jobs/resource_job.go index 6cb6e8da03..607f167b23 100644 --- a/jobs/resource_job.go +++ b/jobs/resource_job.go @@ -446,6 +446,45 @@ type JobsAPI struct { context context.Context } +// JobCreate + JobSettingResource related aliases. +var jobsAliases = map[string]map[string]string{ + "jobs.JobSettingsResource": { + "tasks": "task", + "parameters": "parameter", + "job_clusters": "job_cluster", + "environments": "environment", + }, + "jobs.JobCreateStruct": { + "tasks": "task", + "parameters": "parameter", + "job_clusters": "job_cluster", + "environments": "environment", + }, + "jobs.GitSource": { + "git_url": "url", + "git_provider": "provider", + "git_branch": "branch", + "git_tag": "tag", + "git_commit": "commit", + }, + "jobs.Task": { + "libraries": "library", + }, +} + +// Need a struct for JobCreate because there are aliases we need and it'll be needed in the create method. +type JobCreateStruct struct { + jobs.CreateJob +} + +func (JobCreateStruct) Aliases() map[string]map[string]string { + return jobsAliases +} + +func (JobCreateStruct) CustomizeSchema(s *common.CustomizableSchema) *common.CustomizableSchema { + return s +} + type JobSettingsResource struct { jobs.JobSettings @@ -469,25 +508,7 @@ type JobSettingsResource struct { } func (JobSettingsResource) Aliases() map[string]map[string]string { - aliases := map[string]map[string]string{ - "jobs.JobSettingsResource": { - "tasks": "task", - "parameters": "parameter", - "job_clusters": "job_cluster", - "environments": "environment", - }, - "jobs.GitSource": { - "git_url": "url", - "git_provider": "provider", - "git_branch": "branch", - "git_tag": "tag", - "git_commit": "commit", - }, - "jobs.Task": { - "libraries": "library", - }, - } - return aliases + return jobsAliases } func (JobSettingsResource) CustomizeSchema(s *common.CustomizableSchema) *common.CustomizableSchema { @@ -1148,6 +1169,19 @@ func ResourceJob() common.Resource { return nil }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { + // var js JobSettings + // common.DataToStructPointer(d, jobsGoSdkSchema, &js) + // if js.isMultiTask() { + // ctx = context.WithValue(ctx, common.Api, common.API_2_1) + // } + // jobsAPI := NewJobsAPI(ctx, c) + // job, err := jobsAPI.Create(js) + // if err != nil { + // return err + // } + // d.SetId(job.ID()) + // return getJobLifecycleManager(d, c).OnCreate(ctx) + var js JobSettings common.DataToStructPointer(d, jobsGoSdkSchema, &js) println("!") @@ -1157,10 +1191,10 @@ func ResourceJob() common.Resource { if err != nil { return err } - var cj jobs.CreateJob + var cj JobCreateStruct common.DataToStructPointer(d, jobsGoSdkSchema, &cj) println("!") - jobId, err := Create(cj, w, ctx) + jobId, err := Create(cj.CreateJob, w, ctx) if err != nil { return err } diff --git a/jobs/resource_job_test.go b/jobs/resource_job_test.go index a2c171364f..2dbe88475e 100644 --- a/jobs/resource_job_test.go +++ b/jobs/resource_job_test.go @@ -996,33 +996,34 @@ func TestResourceJobCreate_SqlSubscriptions(t *testing.T) { { Method: "POST", Resource: "/api/2.1/jobs/create", - ExpectedRequest: JobSettings{ + ExpectedRequest: jobs.CreateJob{ Name: "TF SQL task subscriptions", MaxConcurrentRuns: 1, - Tasks: []JobTaskSettings{ - { - TaskKey: "a", - SqlTask: &SqlTask{ - WarehouseID: "dca3a0ba199040eb", - Alert: &SqlAlertTask{ - AlertID: "3cf91a42-6217-4f3c-a6f0-345d489051b9", - Subscriptions: []SqlSubscription{ - {UserName: "user@domain.com"}, - {DestinationID: "Test"}, - }, - PauseSubscriptions: true, - }, - }, - }, + Tasks: []jobs.Task{ + // { + // TaskKey: "a", + // SqlTask: &jobs.SqlTask{ + // WarehouseId: "dca3a0ba199040eb", + // Alert: &jobs.SqlTaskAlert{ + // AlertId: "3cf91a42-6217-4f3c-a6f0-345d489051b9", + // Subscriptions: []jobs.SqlTaskSubscription{ + // {UserName: "user@domain.com"}, + // {DestinationId: "Test"}, + // }, + // PauseSubscriptions: true, + // }, + // }, + // }, { TaskKey: "d", - SqlTask: &SqlTask{ - WarehouseID: "dca3a0ba199040eb", - Dashboard: &SqlDashboardTask{ - DashboardID: "d81a7760-7fd2-443e-bf41-95a60c2f4c7c", - Subscriptions: []SqlSubscription{ + SqlTask: &jobs.SqlTask{ + WarehouseId: "dca3a0ba199040eb", + Dashboard: &jobs.SqlTaskDashboard{ + DashboardId: "d81a7760-7fd2-443e-bf41-95a60c2f4c7c", + PauseSubscriptions: false, + Subscriptions: []jobs.SqlTaskSubscription{ {UserName: "user@domain.com"}, - {DestinationID: "Test"}, + {DestinationId: "Test"}, }, CustomSubject: "test", }, @@ -1079,23 +1080,7 @@ func TestResourceJobCreate_SqlSubscriptions(t *testing.T) { Resource: ResourceJob(), HCL: `name = "TF SQL task subscriptions" - task { - task_key = "a" - - sql_task { - warehouse_id = "dca3a0ba199040eb" - alert { - subscriptions { - user_name = "user@domain.com" - } - subscriptions { - destination_id = "Test" - } - pause_subscriptions = true - alert_id = "3cf91a42-6217-4f3c-a6f0-345d489051b9" - } - } - } + task { task_key = "d" @@ -1767,7 +1752,6 @@ func TestResourceJobCreateFromGitSource(t *testing.T) { Method: "POST", Resource: "/api/2.1/jobs/create", ExpectedRequest: JobSettings{ - ExistingClusterID: "abc", Tasks: []JobTaskSettings{ { TaskKey: "b", @@ -1814,7 +1798,7 @@ func TestResourceJobCreateFromGitSource(t *testing.T) { }, Create: true, Resource: ResourceJob(), - HCL: `existing_cluster_id = "abc" + HCL: ` max_concurrent_runs = 1 name = "GitSourceJob" diff --git a/qa/testing.go b/qa/testing.go index ee7adf60cf..b3ac46646f 100644 --- a/qa/testing.go +++ b/qa/testing.go @@ -536,6 +536,7 @@ func HttpFixtureClientWithToken(t *testing.T, fixtures []HTTPFixture, token stri assert.NoError(t, err) jsonStr, err := json.Marshal(fixture.ExpectedRequest) assert.NoError(t, err) + println(jsonStr) assert.JSONEq(t, string(jsonStr), buf.String(), "json strings do not match") } if fixture.Response != nil {