-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathsql_warehouse.go
More file actions
94 lines (81 loc) · 3.6 KB
/
Copy pathsql_warehouse.go
File metadata and controls
94 lines (81 loc) · 3.6 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package dresources
import (
"context"
"github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/cli/libs/log"
"github.com/databricks/cli/libs/utils"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/service/sql"
)
type ResourceSqlWarehouse struct {
client *databricks.WorkspaceClient
}
// New initializes a ResourceSqlWarehouse with the given client.
func (*ResourceSqlWarehouse) New(client *databricks.WorkspaceClient) *ResourceSqlWarehouse {
return &ResourceSqlWarehouse{client: client}
}
// PrepareState converts bundle config to the SDK type.
func (*ResourceSqlWarehouse) PrepareState(input *resources.SqlWarehouse) *sql.CreateWarehouseRequest {
return &input.CreateWarehouseRequest
}
func (*ResourceSqlWarehouse) RemapState(warehouse *sql.GetWarehouseResponse) *sql.CreateWarehouseRequest {
return &sql.CreateWarehouseRequest{
AutoStopMins: warehouse.AutoStopMins,
Channel: warehouse.Channel,
ClusterSize: warehouse.ClusterSize,
CreatorName: warehouse.CreatorName,
EnablePhoton: warehouse.EnablePhoton,
EnableServerlessCompute: warehouse.EnableServerlessCompute,
InstanceProfileArn: warehouse.InstanceProfileArn,
MaxNumClusters: warehouse.MaxNumClusters,
MinNumClusters: warehouse.MinNumClusters,
Name: warehouse.Name,
SpotInstancePolicy: warehouse.SpotInstancePolicy,
Tags: warehouse.Tags,
WarehouseType: sql.CreateWarehouseRequestWarehouseType(warehouse.WarehouseType),
ForceSendFields: utils.FilterFields[sql.CreateWarehouseRequest](warehouse.ForceSendFields),
}
}
// DoRead reads the warehouse by id.
func (r *ResourceSqlWarehouse) DoRead(ctx context.Context, id string) (*sql.GetWarehouseResponse, error) {
return r.client.Warehouses.GetById(ctx, id)
}
// DoCreate creates the warehouse and returns its id.
func (r *ResourceSqlWarehouse) DoCreate(ctx context.Context, config *sql.CreateWarehouseRequest) (string, *sql.GetWarehouseResponse, error) {
waiter, err := r.client.Warehouses.Create(ctx, *config)
if err != nil {
return "", nil, err
}
return waiter.Id, nil, nil
}
// DoUpdate updates the warehouse in place.
func (r *ResourceSqlWarehouse) DoUpdate(ctx context.Context, id string, config *sql.CreateWarehouseRequest, _ *PlanEntry) (*sql.GetWarehouseResponse, error) {
request := sql.EditWarehouseRequest{
AutoStopMins: config.AutoStopMins,
Channel: config.Channel,
ClusterSize: config.ClusterSize,
CreatorName: config.CreatorName,
EnablePhoton: config.EnablePhoton,
EnableServerlessCompute: config.EnableServerlessCompute,
Id: id,
InstanceProfileArn: config.InstanceProfileArn,
MaxNumClusters: config.MaxNumClusters,
MinNumClusters: config.MinNumClusters,
Name: config.Name,
SpotInstancePolicy: config.SpotInstancePolicy,
Tags: config.Tags,
WarehouseType: sql.EditWarehouseRequestWarehouseType(config.WarehouseType),
ForceSendFields: utils.FilterFields[sql.EditWarehouseRequest](config.ForceSendFields),
}
waiter, err := r.client.Warehouses.Edit(ctx, request)
if err != nil {
return nil, err
}
if waiter.Id != id {
log.Warnf(ctx, "sql_warehouses: response contains unexpected id=%#v (expected %#v)", waiter.Id, id)
}
return nil, nil
}
func (r *ResourceSqlWarehouse) DoDelete(ctx context.Context, oldID string, _ *sql.CreateWarehouseRequest) error {
return r.client.Warehouses.DeleteById(ctx, oldID)
}