-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into kanterov/python-locations
- Loading branch information
Showing
38 changed files
with
1,129 additions
and
70 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
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
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,87 @@ | ||
package mutator | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/databricks/cli/bundle" | ||
"github.com/databricks/cli/libs/diag" | ||
"github.com/databricks/cli/libs/dyn" | ||
) | ||
|
||
type computeIdToClusterId struct{} | ||
|
||
func ComputeIdToClusterId() bundle.Mutator { | ||
return &computeIdToClusterId{} | ||
} | ||
|
||
func (m *computeIdToClusterId) Name() string { | ||
return "ComputeIdToClusterId" | ||
} | ||
|
||
func (m *computeIdToClusterId) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { | ||
var diags diag.Diagnostics | ||
|
||
// The "compute_id" key is set; rewrite it to "cluster_id". | ||
err := b.Config.Mutate(func(v dyn.Value) (dyn.Value, error) { | ||
v, d := rewriteComputeIdToClusterId(v, dyn.NewPath(dyn.Key("bundle"))) | ||
diags = diags.Extend(d) | ||
|
||
// Check if the "compute_id" key is set in any target overrides. | ||
return dyn.MapByPattern(v, dyn.NewPattern(dyn.Key("targets"), dyn.AnyKey()), func(p dyn.Path, v dyn.Value) (dyn.Value, error) { | ||
v, d := rewriteComputeIdToClusterId(v, dyn.Path{}) | ||
diags = diags.Extend(d) | ||
return v, nil | ||
}) | ||
}) | ||
|
||
diags = diags.Extend(diag.FromErr(err)) | ||
return diags | ||
} | ||
|
||
func rewriteComputeIdToClusterId(v dyn.Value, p dyn.Path) (dyn.Value, diag.Diagnostics) { | ||
var diags diag.Diagnostics | ||
computeIdPath := p.Append(dyn.Key("compute_id")) | ||
computeId, err := dyn.GetByPath(v, computeIdPath) | ||
|
||
// If the "compute_id" key is not set, we don't need to do anything. | ||
if err != nil { | ||
return v, nil | ||
} | ||
|
||
if computeId.Kind() == dyn.KindInvalid { | ||
return v, nil | ||
} | ||
|
||
diags = diags.Append(diag.Diagnostic{ | ||
Severity: diag.Warning, | ||
Summary: "compute_id is deprecated, please use cluster_id instead", | ||
Locations: computeId.Locations(), | ||
Paths: []dyn.Path{computeIdPath}, | ||
}) | ||
|
||
clusterIdPath := p.Append(dyn.Key("cluster_id")) | ||
nv, err := dyn.SetByPath(v, clusterIdPath, computeId) | ||
if err != nil { | ||
return dyn.InvalidValue, diag.FromErr(err) | ||
} | ||
// Drop the "compute_id" key. | ||
vout, err := dyn.Walk(nv, func(p dyn.Path, v dyn.Value) (dyn.Value, error) { | ||
switch len(p) { | ||
case 0: | ||
return v, nil | ||
case 1: | ||
if p[0] == dyn.Key("compute_id") { | ||
return v, dyn.ErrDrop | ||
} | ||
return v, nil | ||
case 2: | ||
if p[1] == dyn.Key("compute_id") { | ||
return v, dyn.ErrDrop | ||
} | ||
} | ||
return v, dyn.ErrSkip | ||
}) | ||
|
||
diags = diags.Extend(diag.FromErr(err)) | ||
return vout, diags | ||
} |
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,57 @@ | ||
package mutator_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/databricks/cli/bundle" | ||
"github.com/databricks/cli/bundle/config" | ||
"github.com/databricks/cli/bundle/config/mutator" | ||
"github.com/databricks/cli/libs/diag" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestComputeIdToClusterId(t *testing.T) { | ||
b := &bundle.Bundle{ | ||
Config: config.Root{ | ||
Bundle: config.Bundle{ | ||
ComputeId: "compute-id", | ||
}, | ||
}, | ||
} | ||
|
||
diags := bundle.Apply(context.Background(), b, mutator.ComputeIdToClusterId()) | ||
assert.NoError(t, diags.Error()) | ||
assert.Equal(t, "compute-id", b.Config.Bundle.ClusterId) | ||
assert.Empty(t, b.Config.Bundle.ComputeId) | ||
|
||
assert.Len(t, diags, 1) | ||
assert.Equal(t, "compute_id is deprecated, please use cluster_id instead", diags[0].Summary) | ||
assert.Equal(t, diag.Warning, diags[0].Severity) | ||
} | ||
|
||
func TestComputeIdToClusterIdInTargetOverride(t *testing.T) { | ||
b := &bundle.Bundle{ | ||
Config: config.Root{ | ||
Targets: map[string]*config.Target{ | ||
"dev": { | ||
ComputeId: "compute-id-dev", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
diags := bundle.Apply(context.Background(), b, mutator.ComputeIdToClusterId()) | ||
assert.NoError(t, diags.Error()) | ||
assert.Empty(t, b.Config.Targets["dev"].ComputeId) | ||
|
||
diags = diags.Extend(bundle.Apply(context.Background(), b, mutator.SelectTarget("dev"))) | ||
assert.NoError(t, diags.Error()) | ||
|
||
assert.Equal(t, "compute-id-dev", b.Config.Bundle.ClusterId) | ||
assert.Empty(t, b.Config.Bundle.ComputeId) | ||
|
||
assert.Len(t, diags, 1) | ||
assert.Equal(t, "compute_id is deprecated, please use cluster_id instead", diags[0].Summary) | ||
assert.Equal(t, diag.Warning, diags[0].Severity) | ||
} |
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
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
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
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
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
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
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,39 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/databricks/cli/libs/log" | ||
"github.com/databricks/databricks-sdk-go" | ||
"github.com/databricks/databricks-sdk-go/marshal" | ||
"github.com/databricks/databricks-sdk-go/service/compute" | ||
) | ||
|
||
type Cluster struct { | ||
ID string `json:"id,omitempty" bundle:"readonly"` | ||
Permissions []Permission `json:"permissions,omitempty"` | ||
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"` | ||
|
||
*compute.ClusterSpec | ||
} | ||
|
||
func (s *Cluster) UnmarshalJSON(b []byte) error { | ||
return marshal.Unmarshal(b, s) | ||
} | ||
|
||
func (s Cluster) MarshalJSON() ([]byte, error) { | ||
return marshal.Marshal(s) | ||
} | ||
|
||
func (s *Cluster) Exists(ctx context.Context, w *databricks.WorkspaceClient, id string) (bool, error) { | ||
_, err := w.Clusters.GetByClusterId(ctx, id) | ||
if err != nil { | ||
log.Debugf(ctx, "cluster %s does not exist", id) | ||
return false, err | ||
} | ||
return true, nil | ||
} | ||
|
||
func (s *Cluster) TerraformResourceName() string { | ||
return "databricks_cluster" | ||
} |
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
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
Oops, something went wrong.