-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathresolve_metastore.go
More file actions
42 lines (35 loc) · 998 Bytes
/
resolve_metastore.go
File metadata and controls
42 lines (35 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package variable
import (
"context"
"fmt"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/service/catalog"
)
type resolveMetastore struct {
name string
}
func (l resolveMetastore) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
result, err := w.Metastores.ListAll(ctx, catalog.ListMetastoresRequest{})
if err != nil {
return "", err
}
// Collect all metastores with the given name.
var entities []catalog.MetastoreInfo
for _, entity := range result {
if entity.Name == l.name {
entities = append(entities, entity)
}
}
// Return the ID of the first matching metastore.
switch len(entities) {
case 0:
return "", fmt.Errorf("metastoren named %q does not exist", l.name)
case 1:
return entities[0].MetastoreId, nil
default:
return "", fmt.Errorf("there are %d instances of clusters named %q", len(entities), l.name)
}
}
func (l resolveMetastore) String() string {
return "metastore: " + l.name
}