mirror of https://github.com/databricks/cli.git
WIP
This commit is contained in:
parent
984c38e03e
commit
1f8f85982d
|
@ -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"`
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package variable
|
||||
|
||||
// TODO: Add tests for alert
|
|
@ -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)
|
||||
}
|
|
@ -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)
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package variable
|
||||
|
||||
// TODO: Add tests for cluster_policy
|
|
@ -0,0 +1,3 @@
|
|||
package variable
|
||||
|
||||
// TODO: Add tests for cluster
|
|
@ -0,0 +1,3 @@
|
|||
package variable
|
||||
|
||||
// TODO: Add implementation for dashboard
|
|
@ -0,0 +1,3 @@
|
|||
package variable
|
||||
|
||||
// TODO: Add tests for dashboard
|
|
@ -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)
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package variable
|
||||
|
||||
// TODO: Add tests for instance_pool
|
|
@ -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)
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package variable
|
||||
|
||||
// TODO: Add tests for job
|
|
@ -0,0 +1,3 @@
|
|||
package variable
|
||||
|
||||
// TODO: Add implementation for metastore
|
|
@ -0,0 +1,3 @@
|
|||
package variable
|
||||
|
||||
// TODO: Add tests for metastore
|
|
@ -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)
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package variable
|
||||
|
||||
// TODO: Add tests for pipeline
|
|
@ -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)
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package variable
|
||||
|
||||
// TODO: Add tests for query
|
|
@ -0,0 +1,3 @@
|
|||
package variable
|
||||
|
||||
// TODO: Add implementation for service_principal
|
|
@ -0,0 +1,3 @@
|
|||
package variable
|
||||
|
||||
// TODO: Add tests for service_principal
|
|
@ -0,0 +1 @@
|
|||
package variable
|
|
@ -0,0 +1,3 @@
|
|||
package variable
|
||||
|
||||
// TODO: Add tests for warehouse
|
Loading…
Reference in New Issue