Skip to content

Commit 01c5671

Browse files
authored
Add new node type selector to databricks_node_type data source (#1957)
* add new node type selector to `databricks_node_type` data source * address code review comments
1 parent e6546fc commit 01c5671

File tree

2 files changed

+130
-5
lines changed

2 files changed

+130
-5
lines changed

clusters/data_node_type.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type NodeTypeRequest struct {
2424
IsIOCacheEnabled bool `json:"is_io_cache_enabled,omitempty"`
2525
SupportPortForwarding bool `json:"support_port_forwarding,omitempty"`
2626
VCPU bool `json:"vcpu,omitempty"`
27+
Fleet bool `json:"fleet,omitempty"`
2728
}
2829

2930
// NodeTypeList contains a list of node types
@@ -133,9 +134,12 @@ func (a ClustersAPI) GetSmallestNodeType(r NodeTypeRequest) string {
133134
// error is explicitly ingored here, because Azure returns
134135
// apparently too big of a JSON for Go to parse
135136
if len(list.NodeTypes) == 0 {
136-
if r.VCPU {
137+
if r.VCPU && a.client.IsAws() {
137138
return "vcpu-worker"
138139
}
140+
if r.Fleet && a.client.IsAws() {
141+
return "md-fleet.xlarge"
142+
}
139143
return a.defaultSmallestNodeType()
140144
}
141145
list.Sort()
@@ -144,10 +148,10 @@ func (a ClustersAPI) GetSmallestNodeType(r NodeTypeRequest) string {
144148
continue
145149
}
146150
gbs := (nt.MemoryMB / 1024)
147-
if r.VCPU && !strings.HasPrefix(nt.NodeTypeID, "vcpu") {
151+
if r.VCPU != strings.HasPrefix(nt.NodeTypeID, "vcpu") {
148152
continue
149153
}
150-
if !r.VCPU && strings.HasPrefix(nt.NodeTypeID, "vcpu") {
154+
if r.Fleet != strings.Contains(nt.NodeTypeID, "-fleet.") {
151155
continue
152156
}
153157
if r.MinMemoryGB > 0 && gbs < r.MinMemoryGB {

clusters/data_node_type_test.go

Lines changed: 123 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ func TestNodeType(t *testing.T) {
2323
MemoryMB: 0,
2424
NumCores: 0,
2525
},
26+
{
27+
NodeTypeID: "m-fleet.xlarge",
28+
InstanceTypeID: "m-fleet.xlarge",
29+
MemoryMB: 16384,
30+
NumCores: 4,
31+
},
2632
{
2733
NodeTypeID: "Random_05",
2834
InstanceTypeID: "Random_05",
@@ -183,7 +189,7 @@ func TestNodeTypeVCPU(t *testing.T) {
183189
NodeTypeID: "Random_05",
184190
InstanceTypeID: "Random_05",
185191
MemoryMB: 1024,
186-
NumCores: 32,
192+
NumCores: 2,
187193
NodeInstanceType: &NodeInstanceType{
188194
LocalDisks: 3,
189195
LocalDiskSizeGB: 100,
@@ -193,7 +199,7 @@ func TestNodeTypeVCPU(t *testing.T) {
193199
NodeTypeID: "vcpu-worker",
194200
InstanceTypeID: "vcpu-worker",
195201
MemoryMB: 0,
196-
NumCores: 0,
202+
NumCores: 4,
197203
},
198204
},
199205
},
@@ -223,6 +229,12 @@ func TestSmallestNodeTypeClouds(t *testing.T) {
223229
Host: "foo.gcp.databricks.com",
224230
},
225231
}.defaultSmallestNodeType())
232+
233+
assert.Equal(t, "i3.xlarge", ClustersAPI{
234+
client: &common.DatabricksClient{
235+
Host: "foo.cloud.databricks.com",
236+
},
237+
}.defaultSmallestNodeType())
226238
}
227239

228240
func TestNodeTypeCategoryNotAvailable(t *testing.T) {
@@ -304,3 +316,112 @@ func TestNodeTypeShouldBeSkipped(t *testing.T) {
304316
assert.Equal(t, true, toBeSkipped.shouldBeSkipped())
305317
assert.Equal(t, false, NodeType{}.shouldBeSkipped())
306318
}
319+
320+
func TestNodeTypeFleet(t *testing.T) {
321+
d, err := qa.ResourceFixture{
322+
Fixtures: []qa.HTTPFixture{
323+
{
324+
Method: "GET",
325+
ReuseRequest: true,
326+
Resource: "/api/2.0/clusters/list-node-types",
327+
Response: NodeTypeList{
328+
[]NodeType{
329+
{
330+
NodeTypeID: "Random_05",
331+
InstanceTypeID: "Random_05",
332+
MemoryMB: 1024,
333+
NumCores: 4,
334+
},
335+
{
336+
NodeTypeID: "m-fleet.xlarge",
337+
InstanceTypeID: "m-fleet.xlarge",
338+
MemoryMB: 16384,
339+
NumCores: 4,
340+
},
341+
{
342+
NodeTypeID: "m-fleet.2xlarge",
343+
InstanceTypeID: "m-fleet.2xlarge",
344+
MemoryMB: 32768,
345+
NumCores: 8,
346+
},
347+
},
348+
},
349+
},
350+
},
351+
Read: true,
352+
Resource: DataSourceNodeType(),
353+
NonWritable: true,
354+
State: map[string]any{
355+
"fleet": true,
356+
"min_cores": 8,
357+
},
358+
ID: ".",
359+
}.Apply(t)
360+
assert.NoError(t, err)
361+
assert.Equal(t, "m-fleet.2xlarge", d.Id())
362+
}
363+
364+
func TestNodeTypeEmptyList(t *testing.T) {
365+
d, err := qa.ResourceFixture{
366+
Fixtures: []qa.HTTPFixture{
367+
{
368+
Method: "GET",
369+
ReuseRequest: true,
370+
Resource: "/api/2.0/clusters/list-node-types",
371+
Response: NodeTypeList{},
372+
},
373+
},
374+
Read: true,
375+
Resource: DataSourceNodeType(),
376+
NonWritable: true,
377+
Azure: true,
378+
State: map[string]any{},
379+
ID: ".",
380+
}.Apply(t)
381+
assert.NoError(t, err)
382+
assert.Equal(t, "Standard_D3_v2", d.Id())
383+
}
384+
385+
func TestNodeTypeFleetEmptyList(t *testing.T) {
386+
d, err := qa.ResourceFixture{
387+
Fixtures: []qa.HTTPFixture{
388+
{
389+
Method: "GET",
390+
ReuseRequest: true,
391+
Resource: "/api/2.0/clusters/list-node-types",
392+
Response: NodeTypeList{},
393+
},
394+
},
395+
Read: true,
396+
Resource: DataSourceNodeType(),
397+
NonWritable: true,
398+
State: map[string]any{
399+
"fleet": true,
400+
},
401+
ID: ".",
402+
}.Apply(t)
403+
assert.NoError(t, err)
404+
assert.Equal(t, "md-fleet.xlarge", d.Id())
405+
}
406+
407+
func TestNodeTypeVCPUEmptyList(t *testing.T) {
408+
d, err := qa.ResourceFixture{
409+
Fixtures: []qa.HTTPFixture{
410+
{
411+
Method: "GET",
412+
ReuseRequest: true,
413+
Resource: "/api/2.0/clusters/list-node-types",
414+
Response: NodeTypeList{},
415+
},
416+
},
417+
Read: true,
418+
Resource: DataSourceNodeType(),
419+
NonWritable: true,
420+
State: map[string]any{
421+
"vcpu": true,
422+
},
423+
ID: ".",
424+
}.Apply(t)
425+
assert.NoError(t, err)
426+
assert.Equal(t, "vcpu-worker", d.Id())
427+
}

0 commit comments

Comments
 (0)