2024-04-18 15:13:16 +00:00
|
|
|
package validate
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/libs/diag"
|
|
|
|
"github.com/databricks/cli/libs/dyn"
|
|
|
|
)
|
|
|
|
|
|
|
|
type validate struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
type location struct {
|
|
|
|
path string
|
|
|
|
rb bundle.ReadOnlyBundle
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l location) Location() dyn.Location {
|
|
|
|
return l.rb.Config().GetLocation(l.path)
|
|
|
|
}
|
|
|
|
|
2024-07-23 17:20:11 +00:00
|
|
|
func (l location) Locations() []dyn.Location {
|
|
|
|
return l.rb.Config().GetLocations(l.path)
|
|
|
|
}
|
|
|
|
|
2024-04-18 15:13:16 +00:00
|
|
|
func (l location) Path() dyn.Path {
|
|
|
|
return dyn.MustPathFromString(l.path)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply implements bundle.Mutator.
|
|
|
|
func (v *validate) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
|
|
|
return bundle.ApplyReadOnly(ctx, bundle.ReadOnly(b), bundle.Parallel(
|
|
|
|
JobClusterKeyDefined(),
|
|
|
|
FilesToSync(),
|
|
|
|
ValidateSyncPatterns(),
|
Add JobTaskClusterSpec validate mutator (#1784)
## Changes
Add JobTaskClusterSpec validate mutator. It catches the case when tasks
don't which cluster to use.
For example, we can get this error with minor modifications to
`default-python` template:
```yaml
tasks:
- task_key: python_file_task
spark_python_task:
python_file: ../src/my_project_10/main.py
```
```
% databricks bundle validate
Error: Missing required cluster or environment settings
at resources.jobs.my_project_10_job.tasks[0]
in resources/my_project_10_job.yml:17:11
Task "print_github_stars" requires a cluster or an environment to run.
Specify one of the following fields: job_cluster_key, environment_key, existing_cluster_id, new_cluster.
```
We implicitly rely on "one of" validation, which does not exist. Many
bundle fields can't co-exist, for instance, specifying:
`JobTask.{existing_cluster_id,job_cluster_key}`, `Library.{whl,pypi}`,
`JobTask.{notebook_task,python_wheel_task}`, etc.
## Tests
Unit tests
---------
Co-authored-by: Pieter Noordhuis <pcnoordhuis@gmail.com>
2024-09-25 11:30:14 +00:00
|
|
|
JobTaskClusterSpec(),
|
2024-10-24 12:36:17 +00:00
|
|
|
ValidateFolderPermissions(),
|
2024-11-22 15:48:09 +00:00
|
|
|
SingleNodeCluster(),
|
2024-04-18 15:13:16 +00:00
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name implements bundle.Mutator.
|
|
|
|
func (v *validate) Name() string {
|
|
|
|
return "validate"
|
|
|
|
}
|
|
|
|
|
|
|
|
func Validate() bundle.Mutator {
|
|
|
|
return &validate{}
|
|
|
|
}
|