Skip to content

Commit 4528b20

Browse files
committed
Fixed #637 - Recreate mounting clusters when they are deleted
1 parent c45174d commit 4528b20

File tree

2 files changed

+120
-27
lines changed

2 files changed

+120
-27
lines changed

storage/mounts.go

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -107,38 +107,43 @@ func NewMountPoint(executor common.CommandExecutor, name, clusterID string) Moun
107107
}
108108
}
109109

110+
func getOrCreateMountingCluster(clustersAPI compute.ClustersAPI) (string, error) {
111+
cluster, err := clustersAPI.GetOrCreateRunningCluster("terraform-mount", compute.Cluster{
112+
NumWorkers: 0,
113+
ClusterName: "terraform-mount",
114+
SparkVersion: clustersAPI.LatestSparkVersionOrDefault(
115+
compute.SparkVersionRequest{
116+
Latest: true,
117+
LongTermSupport: true,
118+
}),
119+
NodeTypeID: clustersAPI.GetSmallestNodeType(
120+
compute.NodeTypeRequest{
121+
LocalDisk: true,
122+
}),
123+
AutoterminationMinutes: 10,
124+
SparkConf: map[string]string{
125+
"spark.master": "local[*]",
126+
"spark.databricks.cluster.profile": "singleNode",
127+
},
128+
CustomTags: map[string]string{
129+
"ResourceClass": "SingleNode",
130+
},
131+
})
132+
if err != nil {
133+
return "", err
134+
}
135+
return cluster.ClusterID, nil
136+
}
137+
110138
func getMountingClusterID(ctx context.Context, client *common.DatabricksClient, clusterID string) (string, error) {
111139
clustersAPI := compute.NewClustersAPI(ctx, client)
112140
if clusterID == "" {
113-
r := compute.Cluster{
114-
NumWorkers: 0,
115-
ClusterName: "terraform-mount",
116-
SparkVersion: clustersAPI.LatestSparkVersionOrDefault(
117-
compute.SparkVersionRequest{
118-
Latest: true,
119-
LongTermSupport: true,
120-
}),
121-
NodeTypeID: clustersAPI.GetSmallestNodeType(
122-
compute.NodeTypeRequest{
123-
LocalDisk: true,
124-
}),
125-
126-
AutoterminationMinutes: 10,
127-
SparkConf: map[string]string{
128-
"spark.master": "local[*]",
129-
"spark.databricks.cluster.profile": "singleNode",
130-
},
131-
CustomTags: map[string]string{
132-
"ResourceClass": "SingleNode",
133-
},
134-
}
135-
cluster, err := clustersAPI.GetOrCreateRunningCluster("terraform-mount", r)
136-
if err != nil {
137-
return "", err
138-
}
139-
return cluster.ClusterID, nil
141+
return getOrCreateMountingCluster(clustersAPI)
140142
}
141143
clusterInfo, err := clustersAPI.Get(clusterID)
144+
if e, ok := err.(common.APIError); ok && e.IsMissing() {
145+
return getOrCreateMountingCluster(clustersAPI)
146+
}
142147
if err != nil {
143148
return "", err
144149
}

storage/mounts_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,91 @@ func TestMountPoint_Delete(t *testing.T) {
213213
return expectedCommandResp, mp.Delete()
214214
}, nil, mountName, expectedCommand)
215215
}
216+
217+
func TestDeletedMountClusterRecreates(t *testing.T) {
218+
qa.HTTPFixturesApply(t, []qa.HTTPFixture{
219+
{
220+
Method: "GET",
221+
Resource: "/api/2.0/clusters/get?cluster_id=abc",
222+
Status: 404,
223+
},
224+
{
225+
Method: "GET",
226+
ReuseRequest: true,
227+
Resource: "/api/2.0/clusters/list",
228+
Response: map[string]interface{}{},
229+
},
230+
{
231+
Method: "GET",
232+
ReuseRequest: true,
233+
Resource: "/api/2.0/clusters/spark-versions",
234+
Response: compute.SparkVersionsList{
235+
SparkVersions: []compute.SparkVersion{
236+
{
237+
Version: "7.1.x-cpu-ml-scala2.12",
238+
Description: "7.1 ML (includes Apache Spark 3.0.0, Scala 2.12)",
239+
},
240+
},
241+
},
242+
},
243+
{
244+
Method: "GET",
245+
ReuseRequest: true,
246+
Resource: "/api/2.0/clusters/list-node-types",
247+
Response: compute.NodeTypeList{
248+
NodeTypes: []compute.NodeType{
249+
{
250+
NodeTypeID: "Standard_F4s",
251+
InstanceTypeID: "Standard_F4s",
252+
MemoryMB: 8192,
253+
NumCores: 4,
254+
NodeInstanceType: &compute.NodeInstanceType{
255+
LocalDisks: 1,
256+
InstanceTypeID: "Standard_F4s",
257+
LocalDiskSizeGB: 16,
258+
LocalNVMeDisks: 0,
259+
},
260+
},
261+
},
262+
},
263+
},
264+
{
265+
Method: "POST",
266+
ReuseRequest: true,
267+
Resource: "/api/2.0/clusters/create",
268+
ExpectedRequest: compute.Cluster{
269+
AutoterminationMinutes: 10,
270+
ClusterName: "terraform-mount",
271+
NodeTypeID: "Standard_F4s",
272+
SparkVersion: "7.3.x-scala2.12",
273+
CustomTags: map[string]string{
274+
"ResourceClass": "SingleNode",
275+
},
276+
SparkConf: map[string]string{
277+
"spark.databricks.cluster.profile": "singleNode",
278+
"spark.master": "local[*]",
279+
},
280+
},
281+
Response: compute.ClusterID{
282+
ClusterID: "bcd",
283+
},
284+
},
285+
{
286+
Method: "GET",
287+
ReuseRequest: true,
288+
Resource: "/api/2.0/clusters/get?cluster_id=bcd",
289+
Response: compute.ClusterInfo{
290+
ClusterID: "bcd",
291+
State: "RUNNING",
292+
SparkConf: map[string]string{
293+
"spark.databricks.acl.dfAclsEnabled": "true",
294+
"spark.databricks.cluster.profile": "singleNode",
295+
},
296+
},
297+
},
298+
}, func(ctx context.Context, client *common.DatabricksClient) {
299+
clusterID, err := getMountingClusterID(ctx, client, "abc")
300+
assert.NoError(t, err)
301+
assert.Equal(t, "bcd", clusterID)
302+
})
303+
}

0 commit comments

Comments
 (0)