-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Unity Catalog Registered Models in bundles (#846)
## Changes <!-- Summary of your changes that are easy to understand --> Add UC Registered Models support to Databricks Asset Bundles as new resource `registered_model`. Also added UC Permission support via new resource `grant`. ## Tests <!-- How is this tested? --> Tested via unit tests and manual testing with [example PR](https://github.com/databricks/bundle-examples-internal/pull/80) and [custom Terraform provider](databricks/terraform-provider-databricks#2771). <img width="698" alt="Screenshot 2023-10-08 at 4 57 23 PM" src="https://github.com/databricks/cli/assets/87999496/bcf605a9-7894-443b-865a-f7e240037815"> <img width="1109" alt="Screenshot 2023-10-08 at 4 56 47 PM" src="https://github.com/databricks/cli/assets/87999496/e4d6e424-cd70-4809-8843-6939ed2e172f"> <img width="1091" alt="Screenshot 2023-10-08 at 4 56 57 PM" src="https://github.com/databricks/cli/assets/87999496/88ebaabb-67db-4a11-88a5-df087e2e41c0"> --------- Signed-off-by: Arpit Jasapara <[email protected]> Co-authored-by: Andrew Nester <[email protected]> Co-authored-by: Pieter Noordhuis <[email protected]>
- Loading branch information
1 parent
61cf4fb
commit 24cc675
Showing
14 changed files
with
302 additions
and
4 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 |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
"github.com/databricks/cli/bundle/config/resources" | ||
"github.com/databricks/cli/libs/tags" | ||
sdkconfig "github.com/databricks/databricks-sdk-go/config" | ||
"github.com/databricks/databricks-sdk-go/service/catalog" | ||
"github.com/databricks/databricks-sdk-go/service/iam" | ||
"github.com/databricks/databricks-sdk-go/service/jobs" | ||
"github.com/databricks/databricks-sdk-go/service/ml" | ||
|
@@ -59,6 +60,9 @@ func mockBundle(mode config.Mode) *bundle.Bundle { | |
ModelServingEndpoints: map[string]*resources.ModelServingEndpoint{ | ||
"servingendpoint1": {CreateServingEndpoint: &serving.CreateServingEndpoint{Name: "servingendpoint1"}}, | ||
}, | ||
RegisteredModels: map[string]*resources.RegisteredModel{ | ||
"registeredmodel1": {CreateRegisteredModelRequest: &catalog.CreateRegisteredModelRequest{Name: "registeredmodel1"}}, | ||
}, | ||
}, | ||
}, | ||
// Use AWS implementation for testing. | ||
|
@@ -86,6 +90,7 @@ func TestProcessTargetModeDevelopment(t *testing.T) { | |
// Experiment 1 | ||
assert.Equal(t, "/Users/[email protected]/[dev lennart] experiment1", bundle.Config.Resources.Experiments["experiment1"].Name) | ||
assert.Contains(t, bundle.Config.Resources.Experiments["experiment1"].Experiment.Tags, ml.ExperimentTag{Key: "dev", Value: "lennart"}) | ||
assert.Equal(t, "dev", bundle.Config.Resources.Experiments["experiment1"].Experiment.Tags[0].Key) | ||
|
||
// Experiment 2 | ||
assert.Equal(t, "[dev lennart] experiment2", bundle.Config.Resources.Experiments["experiment2"].Name) | ||
|
@@ -96,7 +101,9 @@ func TestProcessTargetModeDevelopment(t *testing.T) { | |
|
||
// Model serving endpoint 1 | ||
assert.Equal(t, "dev_lennart_servingendpoint1", bundle.Config.Resources.ModelServingEndpoints["servingendpoint1"].Name) | ||
assert.Equal(t, "dev", bundle.Config.Resources.Experiments["experiment1"].Experiment.Tags[0].Key) | ||
|
||
// Registered model 1 | ||
assert.Equal(t, "dev_lennart_registeredmodel1", bundle.Config.Resources.RegisteredModels["registeredmodel1"].Name) | ||
} | ||
|
||
func TestProcessTargetModeDevelopmentTagNormalizationForAws(t *testing.T) { | ||
|
@@ -151,6 +158,7 @@ func TestProcessTargetModeDefault(t *testing.T) { | |
assert.Equal(t, "pipeline1", bundle.Config.Resources.Pipelines["pipeline1"].Name) | ||
assert.False(t, bundle.Config.Resources.Pipelines["pipeline1"].PipelineSpec.Development) | ||
assert.Equal(t, "servingendpoint1", bundle.Config.Resources.ModelServingEndpoints["servingendpoint1"].Name) | ||
assert.Equal(t, "registeredmodel1", bundle.Config.Resources.RegisteredModels["registeredmodel1"].Name) | ||
} | ||
|
||
func TestProcessTargetModeProduction(t *testing.T) { | ||
|
@@ -187,6 +195,7 @@ func TestProcessTargetModeProduction(t *testing.T) { | |
assert.Equal(t, "pipeline1", bundle.Config.Resources.Pipelines["pipeline1"].Name) | ||
assert.False(t, bundle.Config.Resources.Pipelines["pipeline1"].PipelineSpec.Development) | ||
assert.Equal(t, "servingendpoint1", bundle.Config.Resources.ModelServingEndpoints["servingendpoint1"].Name) | ||
assert.Equal(t, "registeredmodel1", bundle.Config.Resources.RegisteredModels["registeredmodel1"].Name) | ||
} | ||
|
||
func TestProcessTargetModeProductionOkForPrincipal(t *testing.T) { | ||
|
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,9 @@ | ||
package resources | ||
|
||
// Grant holds the grant level settings for a single principal in Unity Catalog. | ||
// Multiple of these can be defined on any Unity Catalog resource. | ||
type Grant struct { | ||
Privileges []string `json:"privileges"` | ||
|
||
Principal string `json:"principal"` | ||
} |
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,34 @@ | ||
package resources | ||
|
||
import ( | ||
"github.com/databricks/cli/bundle/config/paths" | ||
"github.com/databricks/databricks-sdk-go/marshal" | ||
"github.com/databricks/databricks-sdk-go/service/catalog" | ||
) | ||
|
||
type RegisteredModel struct { | ||
// This is a resource agnostic implementation of grants. | ||
// Implementation could be different based on the resource type. | ||
Grants []Grant `json:"grants,omitempty"` | ||
|
||
// This represents the id which is the full name of the model | ||
// (catalog_name.schema_name.model_name) that can be used | ||
// as a reference in other resources. This value is returned by terraform. | ||
ID string | ||
|
||
// Path to config file where the resource is defined. All bundle resources | ||
// include this for interpolation purposes. | ||
paths.Paths | ||
|
||
// This represents the input args for terraform, and will get converted | ||
// to a HCL representation for CRUD | ||
*catalog.CreateRegisteredModelRequest | ||
} | ||
|
||
func (s *RegisteredModel) UnmarshalJSON(b []byte) error { | ||
return marshal.Unmarshal(b, s) | ||
} | ||
|
||
func (s RegisteredModel) MarshalJSON() ([]byte, error) { | ||
return marshal.Marshal(s) | ||
} |
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
|
||
"github.com/databricks/cli/bundle/config" | ||
"github.com/databricks/cli/bundle/config/resources" | ||
"github.com/databricks/databricks-sdk-go/service/catalog" | ||
"github.com/databricks/databricks-sdk-go/service/compute" | ||
"github.com/databricks/databricks-sdk-go/service/jobs" | ||
"github.com/databricks/databricks-sdk-go/service/ml" | ||
|
@@ -366,3 +367,58 @@ func TestConvertModelServingPermissions(t *testing.T) { | |
assert.Equal(t, "CAN_VIEW", p.PermissionLevel) | ||
|
||
} | ||
|
||
func TestConvertRegisteredModel(t *testing.T) { | ||
var src = resources.RegisteredModel{ | ||
CreateRegisteredModelRequest: &catalog.CreateRegisteredModelRequest{ | ||
Name: "name", | ||
CatalogName: "catalog", | ||
SchemaName: "schema", | ||
Comment: "comment", | ||
}, | ||
} | ||
|
||
var config = config.Root{ | ||
Resources: config.Resources{ | ||
RegisteredModels: map[string]*resources.RegisteredModel{ | ||
"my_registered_model": &src, | ||
}, | ||
}, | ||
} | ||
|
||
out := BundleToTerraform(&config) | ||
resource := out.Resource.RegisteredModel["my_registered_model"] | ||
assert.Equal(t, "name", resource.Name) | ||
assert.Equal(t, "catalog", resource.CatalogName) | ||
assert.Equal(t, "schema", resource.SchemaName) | ||
assert.Equal(t, "comment", resource.Comment) | ||
assert.Nil(t, out.Data) | ||
} | ||
|
||
func TestConvertRegisteredModelGrants(t *testing.T) { | ||
var src = resources.RegisteredModel{ | ||
Grants: []resources.Grant{ | ||
{ | ||
Privileges: []string{"EXECUTE"}, | ||
Principal: "[email protected]", | ||
}, | ||
}, | ||
} | ||
|
||
var config = config.Root{ | ||
Resources: config.Resources{ | ||
RegisteredModels: map[string]*resources.RegisteredModel{ | ||
"my_registered_model": &src, | ||
}, | ||
}, | ||
} | ||
|
||
out := BundleToTerraform(&config) | ||
assert.NotEmpty(t, out.Resource.Grants["registered_model_my_registered_model"].Function) | ||
assert.Len(t, out.Resource.Grants["registered_model_my_registered_model"].Grant, 1) | ||
|
||
p := out.Resource.Grants["registered_model_my_registered_model"].Grant[0] | ||
assert.Equal(t, "[email protected]", p.Principal) | ||
assert.Equal(t, "EXECUTE", p.Privileges[0]) | ||
|
||
} |
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.