This commit is contained in:
Pieter Noordhuis 2024-11-20 22:40:33 +01:00
parent 984c38e03e
commit 1f8f85982d
No known key found for this signature in database
GPG Key ID: 12ACCCC104CF2930
23 changed files with 203 additions and 3 deletions

View File

@ -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"`

View File

@ -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)
}

View File

@ -0,0 +1,3 @@
package variable
// TODO: Add tests for alert

View File

@ -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)
}

View File

@ -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)
}

View File

@ -0,0 +1,3 @@
package variable
// TODO: Add tests for cluster_policy

View File

@ -0,0 +1,3 @@
package variable
// TODO: Add tests for cluster

View File

@ -0,0 +1,3 @@
package variable
// TODO: Add implementation for dashboard

View File

@ -0,0 +1,3 @@
package variable
// TODO: Add tests for dashboard

View File

@ -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)
}

View File

@ -0,0 +1,3 @@
package variable
// TODO: Add tests for instance_pool

View File

@ -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)
}

View File

@ -0,0 +1,3 @@
package variable
// TODO: Add tests for job

View File

@ -0,0 +1,3 @@
package variable
// TODO: Add implementation for metastore

View File

@ -0,0 +1,3 @@
package variable
// TODO: Add tests for metastore

View File

@ -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)
}

View File

@ -0,0 +1,3 @@
package variable
// TODO: Add tests for pipeline

View File

@ -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)
}

View File

@ -0,0 +1,3 @@
package variable
// TODO: Add tests for query

View File

@ -0,0 +1,3 @@
package variable
// TODO: Add implementation for service_principal

View File

@ -0,0 +1,3 @@
package variable
// TODO: Add tests for service_principal

View File

@ -0,0 +1 @@
package variable

View File

@ -0,0 +1,3 @@
package variable
// TODO: Add tests for warehouse