Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bundle/artifacts/prepare.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,11 +34,13 @@ func (m *prepare) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics
return diag.Errorf("artifact doesn't exist: %s", m.name)
}

l := b.Config.GetLocation("artifacts." + m.name)
dirPath := filepath.Dir(l.File)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change covered by TestExpandGlobs_* unit tests


// Check if source paths are absolute, if not, make them absolute
for k := range artifact.Files {
f := &artifact.Files[k]
if !filepath.IsAbs(f.Source) {
dirPath := filepath.Dir(artifact.ConfigFilePath)
f.Source = filepath.Join(dirPath, f.Source)
}
}
Expand All@@ -49,7 +51,6 @@ func (m *prepare) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics
}

if !filepath.IsAbs(artifact.Path) {
dirPath := filepath.Dir(artifact.ConfigFilePath)
artifact.Path = filepath.Join(dirPath, artifact.Path)
}

Expand Down
9 changes: 0 additions & 9 deletions bundle/config/artifact.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,18 +4,11 @@ import (
"context"
"fmt"

"github.com/databricks/cli/bundle/config/paths"
"github.com/databricks/cli/libs/exec"
)

type Artifacts map[string]*Artifact

func (artifacts Artifacts) ConfigureConfigFilePath() {
for _, artifact := range artifacts {
artifact.ConfigureConfigFilePath()
}
}

type ArtifactType string

const ArtifactPythonWheel ArtifactType = `whl`
Expand All@@ -40,8 +33,6 @@ type Artifact struct {
BuildCommand string `json:"build,omitempty"`

Executable exec.ExecutableType `json:"executable,omitempty"`

paths.Paths
}

func (a *Artifact) Build(ctx context.Context) ([]byte, error) {
Expand Down
4 changes: 0 additions & 4 deletions bundle/config/mutator/trampoline_test.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,6 @@ import (

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/config/paths"
"github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/stretchr/testify/require"
Expand DownExpand Up@@ -65,9 +64,6 @@ func TestGenerateTrampoline(t *testing.T) {
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"test": {
Paths: paths.Paths{
ConfigFilePath: tmpDir,
},
JobSettings: &jobs.JobSettings{
Tasks: tasks,
},
Expand Down
22 changes: 0 additions & 22 deletions bundle/config/paths/paths.go

This file was deleted.

77 changes: 5 additions & 72 deletions bundle/config/resources.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,81 +21,14 @@ type Resources struct {
Schemas map[string]*resources.Schema `json:"schemas,omitempty"`
}

type resource struct {
resource ConfigResource
resource_type string
key string
}

func (r *Resources) allResources() []resource {
all := make([]resource, 0)
for k, e := range r.Jobs {
all = append(all, resource{resource_type: "job", resource: e, key: k})
}
for k, e := range r.Pipelines {
all = append(all, resource{resource_type: "pipeline", resource: e, key: k})
}
for k, e := range r.Models {
all = append(all, resource{resource_type: "model", resource: e, key: k})
}
for k, e := range r.Experiments {
all = append(all, resource{resource_type: "experiment", resource: e, key: k})
}
for k, e := range r.ModelServingEndpoints {
all = append(all, resource{resource_type: "serving endpoint", resource: e, key: k})
}
for k, e := range r.RegisteredModels {
all = append(all, resource{resource_type: "registered model", resource: e, key: k})
}
for k, e := range r.QualityMonitors {
all = append(all, resource{resource_type: "quality monitor", resource: e, key: k})
}
return all
}

func (r *Resources) VerifyAllResourcesDefined() error {
all := r.allResources()
for _, e := range all {
err := e.resource.Validate()
if err != nil {
return fmt.Errorf("%s %s is not defined", e.resource_type, e.key)
}
}

return nil
}

// ConfigureConfigFilePath sets the specified path for all resources contained in this instance.
// This property is used to correctly resolve paths relative to the path
// of the configuration file they were defined in.
func (r *Resources) ConfigureConfigFilePath() {
for _, e := range r.Jobs {
e.ConfigureConfigFilePath()
}
for _, e := range r.Pipelines {
e.ConfigureConfigFilePath()
}
for _, e := range r.Models {
e.ConfigureConfigFilePath()
}
for _, e := range r.Experiments {
e.ConfigureConfigFilePath()
}
for _, e := range r.ModelServingEndpoints {
e.ConfigureConfigFilePath()
}
for _, e := range r.RegisteredModels {
e.ConfigureConfigFilePath()
}
for _, e := range r.QualityMonitors {
e.ConfigureConfigFilePath()
}
}

type ConfigResource interface {
Comment thread
pietern marked this conversation as resolved.
// Function to assert if the resource exists in the workspace configured in
// the input workspace client.
Exists(ctx context.Context, w *databricks.WorkspaceClient, id string) (bool, error)

// Terraform equivalent name of the resource. For example "databricks_job"
// for jobs and "databricks_pipeline" for pipelines.
TerraformResourceName() string
Validate() error
}

func (r *Resources) FindResourceByConfigKey(key string) (ConfigResource, error) {
Expand Down
12 changes: 0 additions & 12 deletions bundle/config/resources/job.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,10 +2,8 @@ package resources

import (
"context"
"fmt"
"strconv"

"github.com/databricks/cli/bundle/config/paths"
"github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/marshal"
Expand All@@ -17,8 +15,6 @@ type Job struct {
Permissions []Permission `json:"permissions,omitempty"`
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`

paths.Paths

*jobs.JobSettings
}

Expand DownExpand Up@@ -48,11 +44,3 @@ func (j *Job) Exists(ctx context.Context, w *databricks.WorkspaceClient, id stri
func (j *Job) TerraformResourceName() string {
return "databricks_job"
}

func (j *Job) Validate() error {
if j == nil || !j.DynamicValue.IsValid() || j.JobSettings == nil {
return fmt.Errorf("job is not defined")
}

return nil
}
12 changes: 0 additions & 12 deletions bundle/config/resources/mlflow_experiment.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,9 +2,7 @@ package resources

import (
"context"
"fmt"

"github.com/databricks/cli/bundle/config/paths"
"github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/marshal"
Expand All@@ -16,8 +14,6 @@ type MlflowExperiment struct {
Permissions []Permission `json:"permissions,omitempty"`
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`

paths.Paths

*ml.Experiment
}

Expand All@@ -43,11 +39,3 @@ func (s *MlflowExperiment) Exists(ctx context.Context, w *databricks.WorkspaceCl
func (s *MlflowExperiment) TerraformResourceName() string {
return "databricks_mlflow_experiment"
}

func (s *MlflowExperiment) Validate() error {
if s == nil || !s.DynamicValue.IsValid() {
return fmt.Errorf("experiment is not defined")
}

return nil
}
12 changes: 0 additions & 12 deletions bundle/config/resources/mlflow_model.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,9 +2,7 @@ package resources

import (
"context"
"fmt"

"github.com/databricks/cli/bundle/config/paths"
"github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/marshal"
Expand All@@ -16,8 +14,6 @@ type MlflowModel struct {
Permissions []Permission `json:"permissions,omitempty"`
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`

paths.Paths

*ml.Model
}

Expand All@@ -43,11 +39,3 @@ func (s *MlflowModel) Exists(ctx context.Context, w *databricks.WorkspaceClient,
func (s *MlflowModel) TerraformResourceName() string {
return "databricks_mlflow_model"
}

func (s *MlflowModel) Validate() error {
if s == nil || !s.DynamicValue.IsValid() {
return fmt.Errorf("model is not defined")
}

return nil
}
14 changes: 0 additions & 14 deletions bundle/config/resources/model_serving_endpoint.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,9 +2,7 @@ package resources

import (
"context"
"fmt"

"github.com/databricks/cli/bundle/config/paths"
"github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/marshal"
Expand All@@ -20,10 +18,6 @@ type ModelServingEndpoint struct {
// as a reference in other resources. This value is returned by terraform.
ID string `json:"id,omitempty" bundle:"readonly"`

// Path to config file where the resource is defined. All bundle resources
// include this for interpolation purposes.
paths.Paths

// This is a resource agnostic implementation of permissions for ACLs.
// Implementation could be different based on the resource type.
Permissions []Permission `json:"permissions,omitempty"`
Expand DownExpand Up@@ -53,11 +47,3 @@ func (s *ModelServingEndpoint) Exists(ctx context.Context, w *databricks.Workspa
func (s *ModelServingEndpoint) TerraformResourceName() string {
return "databricks_model_serving"
}

func (s *ModelServingEndpoint) Validate() error {
if s == nil || !s.DynamicValue.IsValid() {
return fmt.Errorf("serving endpoint is not defined")
}

return nil
}
12 changes: 0 additions & 12 deletions bundle/config/resources/pipeline.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,9 +2,7 @@ package resources

import (
"context"
"fmt"

"github.com/databricks/cli/bundle/config/paths"
"github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/marshal"
Expand All@@ -16,8 +14,6 @@ type Pipeline struct {
Permissions []Permission `json:"permissions,omitempty"`
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`

paths.Paths

*pipelines.PipelineSpec
}

Expand All@@ -43,11 +39,3 @@ func (p *Pipeline) Exists(ctx context.Context, w *databricks.WorkspaceClient, id
func (p *Pipeline) TerraformResourceName() string {
return "databricks_pipeline"
}

func (p *Pipeline) Validate() error {
if p == nil || !p.DynamicValue.IsValid() {
return fmt.Errorf("pipeline is not defined")
}

return nil
}
14 changes: 0 additions & 14 deletions bundle/config/resources/quality_monitor.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,9 +2,7 @@ package resources

import (
"context"
"fmt"

"github.com/databricks/cli/bundle/config/paths"
"github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/marshal"
Expand All@@ -21,10 +19,6 @@ type QualityMonitor struct {
// as a reference in other resources. This value is returned by terraform.
ID string `json:"id,omitempty" bundle:"readonly"`

// Path to config file where the resource is defined. All bundle resources
// include this for interpolation purposes.
paths.Paths

ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
}

Expand All@@ -50,11 +44,3 @@ func (s *QualityMonitor) Exists(ctx context.Context, w *databricks.WorkspaceClie
func (s *QualityMonitor) TerraformResourceName() string {
return "databricks_quality_monitor"
}

func (s *QualityMonitor) Validate() error {
if s == nil || !s.DynamicValue.IsValid() {
return fmt.Errorf("quality monitor is not defined")
}

return nil
}
Loading