Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port databricks_node_type data source to Go SDK #2070

Merged
merged 3 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion access/resource_sql_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/databricks/databricks-sdk-go/apierr"
clustersApi "github.com/databricks/databricks-sdk-go/service/clusters"
"github.com/databricks/terraform-provider-databricks/clusters"
"github.com/databricks/terraform-provider-databricks/common"

Expand Down Expand Up @@ -274,7 +275,7 @@ func (ta *SqlPermissions) getOrCreateCluster(clustersAPI clusters.ClustersAPI) (
sparkVersion := clustersAPI.LatestSparkVersionOrDefault(clusters.SparkVersionRequest{
Latest: true,
})
nodeType := clustersAPI.GetSmallestNodeType(clusters.NodeTypeRequest{LocalDisk: true})
nodeType := clustersAPI.GetSmallestNodeType(clustersApi.NodeTypeRequest{LocalDisk: true})
aclCluster, err := clustersAPI.GetOrCreateRunningCluster(
"terraform-table-acl", clusters.Cluster{
ClusterName: "terraform-table-acl",
Expand Down
18 changes: 9 additions & 9 deletions access/resource_sql_permissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"testing"

clustersApi "github.com/databricks/databricks-sdk-go/service/clusters"
"github.com/databricks/terraform-provider-databricks/clusters"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/databricks/terraform-provider-databricks/qa"
Expand Down Expand Up @@ -197,18 +198,17 @@ var createHighConcurrencyCluster = []qa.HTTPFixture{
Method: "GET",
ReuseRequest: true,
Resource: "/api/2.0/clusters/list-node-types",
Response: clusters.NodeTypeList{
NodeTypes: []clusters.NodeType{
Response: clustersApi.ListNodeTypesResponse{
NodeTypes: []clustersApi.NodeType{
{
NodeTypeID: "Standard_F4s",
InstanceTypeID: "Standard_F4s",
MemoryMB: 8192,
NodeTypeId: "Standard_F4s",
InstanceTypeId: "Standard_F4s",
MemoryMb: 8192,
NumCores: 4,
NodeInstanceType: &clusters.NodeInstanceType{
NodeInstanceType: &clustersApi.NodeInstanceType{
LocalDisks: 1,
InstanceTypeID: "Standard_F4s",
LocalDiskSizeGB: 16,
LocalNVMeDisks: 0,
InstanceTypeId: "Standard_F4s",
LocalDiskSizeGb: 16,
},
},
},
Expand Down
4 changes: 3 additions & 1 deletion clusters/clusters_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"time"

"github.com/databricks/databricks-sdk-go/apierr"
clustersApi "github.com/databricks/databricks-sdk-go/service/clusters"

"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
Expand Down Expand Up @@ -865,7 +867,7 @@ func (a ClustersAPI) GetOrCreateRunningCluster(name string, custom ...Cluster) (
}
}
}
smallestNodeType := a.GetSmallestNodeType(NodeTypeRequest{
smallestNodeType := a.GetSmallestNodeType(clustersApi.NodeTypeRequest{
LocalDisk: true,
})
log.Printf("[INFO] Creating an autoterminating cluster with node type %s", smallestNodeType)
Expand Down
85 changes: 17 additions & 68 deletions clusters/clusters_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

"github.com/databricks/databricks-sdk-go/apierr"
"github.com/databricks/databricks-sdk-go/service/clusters"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/databricks/terraform-provider-databricks/qa"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -52,30 +53,30 @@ func TestGetOrCreateRunningCluster_AzureAuth(t *testing.T) {
Method: "GET",
ReuseRequest: true,
Resource: "/api/2.0/clusters/list-node-types",
Response: NodeTypeList{
[]NodeType{
Response: clusters.ListNodeTypesResponse{
[]clusters.NodeType{
{
NodeTypeID: "Standard_F4s",
InstanceTypeID: "Standard_F4s",
MemoryMB: 8192,
NodeTypeId: "Standard_F4s",
InstanceTypeId: "Standard_F4s",
MemoryMb: 8192,
NumCores: 4,
NodeInstanceType: &NodeInstanceType{
NodeInstanceType: &clusters.NodeInstanceType{
LocalDisks: 1,
InstanceTypeID: "Standard_F4s",
LocalDiskSizeGB: 16,
LocalNVMeDisks: 0,
InstanceTypeId: "Standard_F4s",
LocalDiskSizeGb: 16,
LocalNvmeDisks: 0,
},
},
{
NodeTypeID: "Standard_L80s_v2",
InstanceTypeID: "Standard_L80s_v2",
MemoryMB: 655360,
NodeTypeId: "Standard_L80s_v2",
InstanceTypeId: "Standard_L80s_v2",
MemoryMb: 655360,
NumCores: 80,
NodeInstanceType: &NodeInstanceType{
NodeInstanceType: &clusters.NodeInstanceType{
LocalDisks: 2,
InstanceTypeID: "Standard_L80s_v2",
LocalDiskSizeGB: 160,
LocalNVMeDisks: 1,
InstanceTypeId: "Standard_L80s_v2",
LocalDiskSizeGb: 160,
LocalNvmeDisks: 1,
},
},
},
Expand Down Expand Up @@ -1128,58 +1129,6 @@ func TestGetLatestSparkVersion(t *testing.T) {
require.Equal(t, true, strings.Contains(err.Error(), "query returned no results"))
}

func TestListNodeTypes(t *testing.T) {
client, server, err := qa.HttpFixtureClient(t, []qa.HTTPFixture{
{
Method: "GET",
ReuseRequest: true,
Resource: "/api/2.0/clusters/list-node-types",
Response: NodeTypeList{
[]NodeType{
{
NodeTypeID: "Standard_F4s",
InstanceTypeID: "Standard_F4s",
MemoryMB: 8192,
NumCores: 4,
NodeInstanceType: &NodeInstanceType{
LocalDisks: 1,
InstanceTypeID: "Standard_F4s",
LocalDiskSizeGB: 16,
LocalNVMeDisks: 0,
},
},
{
NodeTypeID: "Standard_L80s_v2",
InstanceTypeID: "Standard_L80s_v2",
MemoryMB: 655360,
NumCores: 80,
NodeInstanceType: &NodeInstanceType{
LocalDisks: 2,
InstanceTypeID: "Standard_L80s_v2",
LocalDiskSizeGB: 160,
LocalNVMeDisks: 1,
},
},
},
},
},
})
defer server.Close()
require.NoError(t, err)

ctx := context.Background()
api := NewClustersAPI(ctx, client)
assert.Equal(t, api.GetSmallestNodeType(NodeTypeRequest{SupportPortForwarding: true}), api.defaultSmallestNodeType())
assert.Equal(t, api.GetSmallestNodeType(NodeTypeRequest{PhotonWorkerCapable: true}), api.defaultSmallestNodeType())
assert.Equal(t, api.GetSmallestNodeType(NodeTypeRequest{PhotonDriverCapable: true}), api.defaultSmallestNodeType())
assert.Equal(t, api.GetSmallestNodeType(NodeTypeRequest{IsIOCacheEnabled: true}), api.defaultSmallestNodeType())
assert.Equal(t, api.GetSmallestNodeType(NodeTypeRequest{Category: "Storage Optimized"}), api.defaultSmallestNodeType())
assert.Equal(t, api.GetSmallestNodeType(NodeTypeRequest{MinMemoryGB: 100500}), api.defaultSmallestNodeType())
assert.Equal(t, api.GetSmallestNodeType(NodeTypeRequest{GBPerCore: 100500}), api.defaultSmallestNodeType())
assert.Equal(t, api.GetSmallestNodeType(NodeTypeRequest{MinCores: 100500}), api.defaultSmallestNodeType())
assert.Equal(t, api.GetSmallestNodeType(NodeTypeRequest{LocalDisk: true}), "Standard_F4s")
}

func TestClusterState_CanReach(t *testing.T) {
tests := []struct {
from ClusterState
Expand Down
Loading