-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set metadata fields required to enable break-glass UI for jobs (#880)
## Changes This PR sets the following fields for all jobs that are deployed from a DAB 1. `deployment`: This provides the platform with the path to a file to read the metadata from. 2. `edit_mode`: This tells the platform to display the break-glass UI for jobs deployed from a DAB. Setting this is required to re-lock the UI after a user clicks "disconnect from source". 3. `format = MULTI_TASK`. This makes the Terraform provider always use jobs API 2.1 for creating/updating the job. Required because `deployment` and `edit_mode` are only available in API 2.1. ## Tests Unit test and manually. Manually verified that deployments trigger the break glass UI. Manually verified there is no Terraform drift when all three fields are set. --------- Co-authored-by: Pieter Noordhuis <[email protected]>
- Loading branch information
1 parent
5526cd3
commit 2d93f62
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package metadata | ||
|
||
import ( | ||
"context" | ||
"path" | ||
|
||
"github.com/databricks/cli/bundle" | ||
"github.com/databricks/databricks-sdk-go/service/jobs" | ||
) | ||
|
||
type annotateJobs struct{} | ||
|
||
func AnnotateJobs() bundle.Mutator { | ||
return &annotateJobs{} | ||
} | ||
|
||
func (m *annotateJobs) Name() string { | ||
return "metadata.AnnotateJobs" | ||
} | ||
|
||
func (m *annotateJobs) Apply(_ context.Context, b *bundle.Bundle) error { | ||
for _, job := range b.Config.Resources.Jobs { | ||
if job.JobSettings == nil { | ||
continue | ||
} | ||
|
||
job.JobSettings.Deployment = &jobs.JobDeployment{ | ||
Kind: jobs.JobDeploymentKindBundle, | ||
MetadataFilePath: path.Join(b.Config.Workspace.StatePath, MetadataFileName), | ||
} | ||
job.JobSettings.EditMode = jobs.JobSettingsEditModeUiLocked | ||
job.JobSettings.Format = jobs.FormatMultiTask | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package metadata | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/databricks/cli/bundle" | ||
"github.com/databricks/cli/bundle/config" | ||
"github.com/databricks/cli/bundle/config/resources" | ||
"github.com/databricks/databricks-sdk-go/service/jobs" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAnnotateJobsMutator(t *testing.T) { | ||
b := &bundle.Bundle{ | ||
Config: config.Root{ | ||
Workspace: config.Workspace{ | ||
StatePath: "/a/b/c", | ||
}, | ||
Resources: config.Resources{ | ||
Jobs: map[string]*resources.Job{ | ||
"my-job-1": { | ||
JobSettings: &jobs.JobSettings{ | ||
Name: "My Job One", | ||
}, | ||
}, | ||
"my-job-2": { | ||
JobSettings: &jobs.JobSettings{ | ||
Name: "My Job Two", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
err := AnnotateJobs().Apply(context.Background(), b) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, | ||
&jobs.JobDeployment{ | ||
Kind: jobs.JobDeploymentKindBundle, | ||
MetadataFilePath: "/a/b/c/metadata.json", | ||
}, | ||
b.Config.Resources.Jobs["my-job-1"].JobSettings.Deployment) | ||
assert.Equal(t, jobs.JobSettingsEditModeUiLocked, b.Config.Resources.Jobs["my-job-1"].EditMode) | ||
assert.Equal(t, jobs.FormatMultiTask, b.Config.Resources.Jobs["my-job-1"].Format) | ||
|
||
assert.Equal(t, | ||
&jobs.JobDeployment{ | ||
Kind: jobs.JobDeploymentKindBundle, | ||
MetadataFilePath: "/a/b/c/metadata.json", | ||
}, | ||
b.Config.Resources.Jobs["my-job-2"].JobSettings.Deployment) | ||
assert.Equal(t, jobs.JobSettingsEditModeUiLocked, b.Config.Resources.Jobs["my-job-2"].EditMode) | ||
assert.Equal(t, jobs.FormatMultiTask, b.Config.Resources.Jobs["my-job-2"].Format) | ||
} | ||
|
||
func TestAnnotateJobsMutatorJobWithoutSettings(t *testing.T) { | ||
b := &bundle.Bundle{ | ||
Config: config.Root{ | ||
Resources: config.Resources{ | ||
Jobs: map[string]*resources.Job{ | ||
"my-job-1": {}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
err := AnnotateJobs().Apply(context.Background(), b) | ||
assert.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters