forked from databricks/databricks-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (56 loc) · 1.45 KB
/
main.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"context"
"fmt"
"github.com/xuxiaoshuo/databricks-sdk-go"
"github.com/xuxiaoshuo/databricks-sdk-go/service/compute"
"github.com/xuxiaoshuo/databricks-sdk-go/service/jobs"
)
func main() {
w := databricks.Must(databricks.NewWorkspaceClient())
ctx := context.Background()
// Fetch list of spark runtime versions
sparkVersions, err := w.Clusters.SparkVersions(ctx)
if err != nil {
panic(err)
}
// Select the latest LTS version
latestLTS, err := sparkVersions.Select(compute.SparkVersionRequest{
Latest: true,
LongTermSupport: true,
})
if err != nil {
panic(err)
}
// Fetch list of available node types
nodeTypes, err := w.Clusters.ListNodeTypes(ctx)
if err != nil {
panic(err)
}
// Select the smallest node type id
smallestWithDisk, err := nodeTypes.Smallest(compute.NodeTypeRequest{
LocalDisk: true,
})
if err != nil {
panic(err)
}
allRuns, err := w.Jobs.ListRunsAll(ctx, jobs.ListRunsRequest{})
if err != nil {
panic(err)
}
for _, run := range allRuns {
println(run.RunId)
}
runningCluster, err := w.Clusters.CreateAndWait(ctx, compute.CreateCluster{
ClusterName: "Test cluster from SDK",
SparkVersion: latestLTS,
NodeTypeId: smallestWithDisk,
AutoterminationMinutes: 15,
NumWorkers: 1,
})
if err != nil {
panic(err)
}
fmt.Printf("Cluster is ready: %s#setting/clusters/%s/configuration\n",
w.Config.Host, runningCluster.ClusterId)
}