mirror of https://github.com/databricks/cli.git
Use plural title resource header
This commit is contained in:
parent
2c8bb75bc4
commit
85bc79f7a7
|
@ -48,8 +48,8 @@ func initializeForWorkspace(b *bundle.Bundle, orgId string, urlPrefix string) {
|
|||
urlSuffix = "?o=" + orgId
|
||||
}
|
||||
|
||||
for _, rs := range b.Config.Resources.AllResources() {
|
||||
for _, r := range rs {
|
||||
for _, group := range b.Config.Resources.AllResources() {
|
||||
for _, r := range group.Resources {
|
||||
r.InitializeURL(urlPrefix, urlSuffix)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,8 +93,8 @@ func TestInitializeURLs(t *testing.T) {
|
|||
|
||||
initializeForWorkspace(b, "123456", "https://mycompany.databricks.com/")
|
||||
|
||||
for _, rs := range b.Config.Resources.AllResources() {
|
||||
for key, r := range rs {
|
||||
for _, group := range b.Config.Resources.AllResources() {
|
||||
for key, r := range group.Resources {
|
||||
require.Equal(t, expectedURLs[key], r.GetURL(), "Unexpected URL for "+key)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,64 +41,42 @@ type ConfigResource interface {
|
|||
InitializeURL(urlPrefix string, urlSuffix string)
|
||||
}
|
||||
|
||||
func (r *Resources) AllResources() map[string]map[string]ConfigResource {
|
||||
result := make(map[string]map[string]ConfigResource)
|
||||
// ResourceGroup represents a group of resources of the same type.
|
||||
// It includes a description of the resource type and a map of resources.
|
||||
type ResourceGroup struct {
|
||||
Description ResourceDescription
|
||||
Resources map[string]ConfigResource
|
||||
}
|
||||
|
||||
jobResources := make(map[string]ConfigResource)
|
||||
for key, job := range r.Jobs {
|
||||
jobResources[key] = job
|
||||
// collectResourceMap collects resources of a specific type into a ResourceGroup.
|
||||
func collectResourceMap[T ConfigResource](
|
||||
description ResourceDescription,
|
||||
input map[string]T,
|
||||
) ResourceGroup {
|
||||
resources := make(map[string]ConfigResource)
|
||||
for key, resource := range input {
|
||||
resources[key] = resource
|
||||
}
|
||||
result["jobs"] = jobResources
|
||||
|
||||
pipelineResources := make(map[string]ConfigResource)
|
||||
for key, pipeline := range r.Pipelines {
|
||||
pipelineResources[key] = pipeline
|
||||
return ResourceGroup{
|
||||
Description: description,
|
||||
Resources: resources,
|
||||
}
|
||||
result["pipelines"] = pipelineResources
|
||||
}
|
||||
|
||||
modelResources := make(map[string]ConfigResource)
|
||||
for key, model := range r.Models {
|
||||
modelResources[key] = model
|
||||
// AllResources returns all resources in the bundle grouped by their resource type.
|
||||
func (r *Resources) AllResources() []ResourceGroup {
|
||||
descriptions := SupportedResources()
|
||||
return []ResourceGroup{
|
||||
collectResourceMap(descriptions["jobs"], r.Jobs),
|
||||
collectResourceMap(descriptions["pipelines"], r.Pipelines),
|
||||
collectResourceMap(descriptions["models"], r.Models),
|
||||
collectResourceMap(descriptions["experiments"], r.Experiments),
|
||||
collectResourceMap(descriptions["model_serving_endpoints"], r.ModelServingEndpoints),
|
||||
collectResourceMap(descriptions["registered_models"], r.RegisteredModels),
|
||||
collectResourceMap(descriptions["quality_monitors"], r.QualityMonitors),
|
||||
collectResourceMap(descriptions["schemas"], r.Schemas),
|
||||
collectResourceMap(descriptions["clusters"], r.Clusters),
|
||||
}
|
||||
result["models"] = modelResources
|
||||
|
||||
experimentResources := make(map[string]ConfigResource)
|
||||
for key, experiment := range r.Experiments {
|
||||
experimentResources[key] = experiment
|
||||
}
|
||||
result["experiments"] = experimentResources
|
||||
|
||||
modelServingEndpointResources := make(map[string]ConfigResource)
|
||||
for key, endpoint := range r.ModelServingEndpoints {
|
||||
modelServingEndpointResources[key] = endpoint
|
||||
}
|
||||
result["model_serving_endpoints"] = modelServingEndpointResources
|
||||
|
||||
registeredModelResources := make(map[string]ConfigResource)
|
||||
for key, registeredModel := range r.RegisteredModels {
|
||||
registeredModelResources[key] = registeredModel
|
||||
}
|
||||
result["registered_models"] = registeredModelResources
|
||||
|
||||
qualityMonitorResources := make(map[string]ConfigResource)
|
||||
for key, qualityMonitor := range r.QualityMonitors {
|
||||
qualityMonitorResources[key] = qualityMonitor
|
||||
}
|
||||
result["quality_monitors"] = qualityMonitorResources
|
||||
|
||||
schemaResources := make(map[string]ConfigResource)
|
||||
for key, schema := range r.Schemas {
|
||||
schemaResources[key] = schema
|
||||
}
|
||||
result["schemas"] = schemaResources
|
||||
|
||||
clusterResources := make(map[string]ConfigResource)
|
||||
for key, schema := range r.Clusters {
|
||||
clusterResources[key] = schema
|
||||
}
|
||||
result["clusters"] = clusterResources
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (r *Resources) FindResourceByConfigKey(key string) (ConfigResource, error) {
|
||||
|
|
|
@ -67,7 +67,11 @@ func TestResourcesAllResourcesCompleteness(t *testing.T) {
|
|||
r := Resources{}
|
||||
rt := reflect.TypeOf(r)
|
||||
|
||||
result := r.AllResources()
|
||||
// Collect set of includes resource types
|
||||
var types []string
|
||||
for _, group := range r.AllResources() {
|
||||
types = append(types, group.Description.PluralName)
|
||||
}
|
||||
|
||||
for i := 0; i < rt.NumField(); i++ {
|
||||
field := rt.Field(i)
|
||||
|
@ -77,8 +81,7 @@ func TestResourcesAllResourcesCompleteness(t *testing.T) {
|
|||
jsonTag = jsonTag[:idx]
|
||||
}
|
||||
|
||||
_, exists := result[jsonTag]
|
||||
assert.True(t, exists, "Field %s is missing in AllResources map", field.Name)
|
||||
assert.Contains(t, types, jsonTag, "Field %s is missing in AllResources", field.Name)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -187,9 +187,9 @@ func RenderSummary(ctx context.Context, out io.Writer, b *bundle.Bundle) error {
|
|||
|
||||
var resourceGroups []ResourceGroup
|
||||
|
||||
for group, r := range b.Config.Resources.AllResources() {
|
||||
resources := make([]ResourceInfo, 0, len(r))
|
||||
for key, resource := range r {
|
||||
for _, group := range b.Config.Resources.AllResources() {
|
||||
resources := make([]ResourceInfo, 0, len(group.Resources))
|
||||
for key, resource := range group.Resources {
|
||||
resources = append(resources, ResourceInfo{
|
||||
Key: key,
|
||||
Name: resource.GetName(),
|
||||
|
@ -198,9 +198,8 @@ func RenderSummary(ctx context.Context, out io.Writer, b *bundle.Bundle) error {
|
|||
}
|
||||
|
||||
if len(resources) > 0 {
|
||||
capitalizedGroup := strings.ToUpper(group[:1]) + group[1:]
|
||||
resourceGroups = append(resourceGroups, ResourceGroup{
|
||||
GroupName: capitalizedGroup,
|
||||
GroupName: group.Description.PluralTitle,
|
||||
Resources: resources,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/databricks/databricks-sdk-go/service/iam"
|
||||
"github.com/databricks/databricks-sdk-go/service/jobs"
|
||||
"github.com/databricks/databricks-sdk-go/service/pipelines"
|
||||
"github.com/databricks/databricks-sdk-go/service/serving"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -539,6 +540,15 @@ func TestRenderSummary(t *testing.T) {
|
|||
// no URL
|
||||
},
|
||||
},
|
||||
ModelServingEndpoints: map[string]*resources.ModelServingEndpoint{
|
||||
"endpoint1": {
|
||||
ID: "7",
|
||||
CreateServingEndpoint: &serving.CreateServingEndpoint{
|
||||
Name: "my_serving_endpoint",
|
||||
},
|
||||
URL: "https://url4",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -559,6 +569,10 @@ Resources:
|
|||
job2:
|
||||
Name: job2-name
|
||||
URL: https://url2
|
||||
Model Serving Endpoints:
|
||||
endpoint1:
|
||||
Name: my_serving_endpoint
|
||||
URL: https://url4
|
||||
Pipelines:
|
||||
pipeline1:
|
||||
Name: pipeline1-name
|
||||
|
|
Loading…
Reference in New Issue