diff --git a/bundle/config/variable/lookup.go b/bundle/config/variable/lookup.go index e40b0ef7a..da3856ca6 100755 --- a/bundle/config/variable/lookup.go +++ b/bundle/config/variable/lookup.go @@ -10,6 +10,12 @@ import ( "github.com/databricks/databricks-sdk-go" ) +type Resolver interface { + Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) + + String() string +} + type Lookup struct { Alert string `json:"alert,omitempty"` diff --git a/bundle/config/variable/lookup_alert.go b/bundle/config/variable/lookup_alert.go new file mode 100644 index 000000000..768e3b736 --- /dev/null +++ b/bundle/config/variable/lookup_alert.go @@ -0,0 +1,24 @@ +package variable + +import ( + "context" + "fmt" + + "github.com/databricks/databricks-sdk-go" +) + +type lookupAlert struct { + name string +} + +func (l *lookupAlert) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { + entity, err := w.Alerts.GetByDisplayName(ctx, l.name) + if err != nil { + return "", err + } + return fmt.Sprint(entity.Id), nil +} + +func (l *lookupAlert) String() string { + return fmt.Sprintf("alert: %s", l.name) +} diff --git a/bundle/config/variable/lookup_alert_test.go b/bundle/config/variable/lookup_alert_test.go new file mode 100644 index 000000000..212c7e993 --- /dev/null +++ b/bundle/config/variable/lookup_alert_test.go @@ -0,0 +1,3 @@ +package variable + +// TODO: Add tests for alert diff --git a/bundle/config/variable/lookup_overrides.go b/bundle/config/variable/lookup_cluster.go similarity index 81% rename from bundle/config/variable/lookup_overrides.go rename to bundle/config/variable/lookup_cluster.go index 1be373dc6..f7778523f 100644 --- a/bundle/config/variable/lookup_overrides.go +++ b/bundle/config/variable/lookup_cluster.go @@ -8,13 +8,13 @@ import ( "github.com/databricks/databricks-sdk-go/service/compute" ) -var lookupOverrides = map[string]resolverFunc{ - "Cluster": resolveCluster, +type lookupCluster struct { + name string } // We added a custom resolver for the cluster to add filtering for the cluster source when we list all clusters. // Without the filtering listing could take a very long time (5-10 mins) which leads to lookup timeouts. -func resolveCluster(ctx context.Context, w *databricks.WorkspaceClient, name string) (string, error) { +func (l *lookupCluster) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { result, err := w.Clusters.ListAll(ctx, compute.ListClustersRequest{ FilterBy: &compute.ListClustersFilterBy{ ClusterSources: []compute.ClusterSource{compute.ClusterSourceApi, compute.ClusterSourceUi}, @@ -30,6 +30,8 @@ func resolveCluster(ctx context.Context, w *databricks.WorkspaceClient, name str key := v.ClusterName tmp[key] = append(tmp[key], v) } + + name := l.name alternatives, ok := tmp[name] if !ok || len(alternatives) == 0 { return "", fmt.Errorf("cluster named '%s' does not exist", name) @@ -38,4 +40,9 @@ func resolveCluster(ctx context.Context, w *databricks.WorkspaceClient, name str return "", fmt.Errorf("there are %d instances of clusters named '%s'", len(alternatives), name) } return alternatives[0].ClusterId, nil + +} + +func (l *lookupCluster) String() string { + return fmt.Sprintf("cluster: %s", l.name) } diff --git a/bundle/config/variable/lookup_cluster_policy.go b/bundle/config/variable/lookup_cluster_policy.go new file mode 100644 index 000000000..54eefd696 --- /dev/null +++ b/bundle/config/variable/lookup_cluster_policy.go @@ -0,0 +1,24 @@ +package variable + +import ( + "context" + "fmt" + + "github.com/databricks/databricks-sdk-go" +) + +type lookupClusterPolicy struct { + name string +} + +func (l *lookupClusterPolicy) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { + entity, err := w.ClusterPolicies.GetByName(ctx, l.name) + if err != nil { + return "", err + } + return fmt.Sprint(entity.PolicyId), nil +} + +func (l *lookupClusterPolicy) String() string { + return fmt.Sprintf("cluster-policy: %s", l.name) +} diff --git a/bundle/config/variable/lookup_cluster_policy_test.go b/bundle/config/variable/lookup_cluster_policy_test.go new file mode 100644 index 000000000..d922995a5 --- /dev/null +++ b/bundle/config/variable/lookup_cluster_policy_test.go @@ -0,0 +1,3 @@ +package variable + +// TODO: Add tests for cluster_policy diff --git a/bundle/config/variable/lookup_cluster_test.go b/bundle/config/variable/lookup_cluster_test.go new file mode 100644 index 000000000..16093b0d0 --- /dev/null +++ b/bundle/config/variable/lookup_cluster_test.go @@ -0,0 +1,3 @@ +package variable + +// TODO: Add tests for cluster diff --git a/bundle/config/variable/lookup_dashboard.go b/bundle/config/variable/lookup_dashboard.go new file mode 100644 index 000000000..7a4d97fb9 --- /dev/null +++ b/bundle/config/variable/lookup_dashboard.go @@ -0,0 +1,3 @@ +package variable + +// TODO: Add implementation for dashboard diff --git a/bundle/config/variable/lookup_dashboard_test.go b/bundle/config/variable/lookup_dashboard_test.go new file mode 100644 index 000000000..98662c288 --- /dev/null +++ b/bundle/config/variable/lookup_dashboard_test.go @@ -0,0 +1,3 @@ +package variable + +// TODO: Add tests for dashboard diff --git a/bundle/config/variable/lookup_instance_pool.go b/bundle/config/variable/lookup_instance_pool.go new file mode 100644 index 000000000..f567d3451 --- /dev/null +++ b/bundle/config/variable/lookup_instance_pool.go @@ -0,0 +1,24 @@ +package variable + +import ( + "context" + "fmt" + + "github.com/databricks/databricks-sdk-go" +) + +type lookupInstancePool struct { + name string +} + +func (l *lookupInstancePool) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { + entity, err := w.InstancePools.GetByInstancePoolName(ctx, l.name) + if err != nil { + return "", err + } + return fmt.Sprint(entity.InstancePoolId), nil +} + +func (l *lookupInstancePool) String() string { + return fmt.Sprintf("instance-pool: %s", l.name) +} diff --git a/bundle/config/variable/lookup_instance_pool_test.go b/bundle/config/variable/lookup_instance_pool_test.go new file mode 100644 index 000000000..20b376098 --- /dev/null +++ b/bundle/config/variable/lookup_instance_pool_test.go @@ -0,0 +1,3 @@ +package variable + +// TODO: Add tests for instance_pool diff --git a/bundle/config/variable/lookup_job.go b/bundle/config/variable/lookup_job.go new file mode 100644 index 000000000..dbf1e9da9 --- /dev/null +++ b/bundle/config/variable/lookup_job.go @@ -0,0 +1,24 @@ +package variable + +import ( + "context" + "fmt" + + "github.com/databricks/databricks-sdk-go" +) + +type lookupJob struct { + name string +} + +func (l *lookupJob) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { + entity, err := w.Jobs.GetBySettingsName(ctx, l.name) + if err != nil { + return "", err + } + return fmt.Sprint(entity.JobId), nil +} + +func (l *lookupJob) String() string { + return fmt.Sprintf("job: %s", l.name) +} diff --git a/bundle/config/variable/lookup_job_test.go b/bundle/config/variable/lookup_job_test.go new file mode 100644 index 000000000..b2db23a8e --- /dev/null +++ b/bundle/config/variable/lookup_job_test.go @@ -0,0 +1,3 @@ +package variable + +// TODO: Add tests for job diff --git a/bundle/config/variable/lookup_metastore.go b/bundle/config/variable/lookup_metastore.go new file mode 100644 index 000000000..8b038bbc0 --- /dev/null +++ b/bundle/config/variable/lookup_metastore.go @@ -0,0 +1,3 @@ +package variable + +// TODO: Add implementation for metastore diff --git a/bundle/config/variable/lookup_metastore_test.go b/bundle/config/variable/lookup_metastore_test.go new file mode 100644 index 000000000..e73a4d610 --- /dev/null +++ b/bundle/config/variable/lookup_metastore_test.go @@ -0,0 +1,3 @@ +package variable + +// TODO: Add tests for metastore diff --git a/bundle/config/variable/lookup_pipeline.go b/bundle/config/variable/lookup_pipeline.go new file mode 100644 index 000000000..1141e2486 --- /dev/null +++ b/bundle/config/variable/lookup_pipeline.go @@ -0,0 +1,24 @@ +package variable + +import ( + "context" + "fmt" + + "github.com/databricks/databricks-sdk-go" +) + +type lookupPipeline struct { + name string +} + +func (l *lookupPipeline) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { + entity, err := w.Pipelines.GetByName(ctx, l.name) + if err != nil { + return "", err + } + return fmt.Sprint(entity.PipelineId), nil +} + +func (l *lookupPipeline) String() string { + return fmt.Sprintf("pipeline: %s", l.name) +} diff --git a/bundle/config/variable/lookup_pipeline_test.go b/bundle/config/variable/lookup_pipeline_test.go new file mode 100644 index 000000000..21ce6224d --- /dev/null +++ b/bundle/config/variable/lookup_pipeline_test.go @@ -0,0 +1,3 @@ +package variable + +// TODO: Add tests for pipeline diff --git a/bundle/config/variable/lookup_query.go b/bundle/config/variable/lookup_query.go new file mode 100644 index 000000000..cc1d8133f --- /dev/null +++ b/bundle/config/variable/lookup_query.go @@ -0,0 +1,24 @@ +package variable + +import ( + "context" + "fmt" + + "github.com/databricks/databricks-sdk-go" +) + +type lookupQuery struct { + name string +} + +func (l *lookupQuery) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { + entity, err := w.Queries.GetByDisplayName(ctx, l.name) + if err != nil { + return "", err + } + return fmt.Sprint(entity.Id), nil +} + +func (l *lookupQuery) String() string { + return fmt.Sprintf("query: %s", l.name) +} diff --git a/bundle/config/variable/lookup_query_test.go b/bundle/config/variable/lookup_query_test.go new file mode 100644 index 000000000..58a153314 --- /dev/null +++ b/bundle/config/variable/lookup_query_test.go @@ -0,0 +1,3 @@ +package variable + +// TODO: Add tests for query diff --git a/bundle/config/variable/lookup_service_principal.go b/bundle/config/variable/lookup_service_principal.go new file mode 100644 index 000000000..11705ef07 --- /dev/null +++ b/bundle/config/variable/lookup_service_principal.go @@ -0,0 +1,3 @@ +package variable + +// TODO: Add implementation for service_principal diff --git a/bundle/config/variable/lookup_service_principal_test.go b/bundle/config/variable/lookup_service_principal_test.go new file mode 100644 index 000000000..9dd42b188 --- /dev/null +++ b/bundle/config/variable/lookup_service_principal_test.go @@ -0,0 +1,3 @@ +package variable + +// TODO: Add tests for service_principal diff --git a/bundle/config/variable/lookup_warehouse.go b/bundle/config/variable/lookup_warehouse.go new file mode 100644 index 000000000..abd4345f8 --- /dev/null +++ b/bundle/config/variable/lookup_warehouse.go @@ -0,0 +1 @@ +package variable diff --git a/bundle/config/variable/lookup_warehouse_test.go b/bundle/config/variable/lookup_warehouse_test.go new file mode 100644 index 000000000..6aad3e9ad --- /dev/null +++ b/bundle/config/variable/lookup_warehouse_test.go @@ -0,0 +1,3 @@ +package variable + +// TODO: Add tests for warehouse