This repository was archived by the owner on Jan 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster.go
348 lines (313 loc) · 14.6 KB
/
cluster.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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
package databricks
// ClusterCreateRequest is a Create request for a Cluster.
type ClusterCreateRequest struct {
NumWorkers *int32 `json:"num_workers,omitempty"`
Autoscale *Autoscale `json:"autoscale,omitempty"`
ClusterID string `json:"cluster_id"`
ClusterName string `json:"cluster_name"`
SparkVersion string `json:"spark_version"`
SparkConf *S3StorageInfo `json:"spark_conf,omitempty"`
AWSAttributes *AWSAttributes `json:"aws_attributes,omitempty"`
NodeTypeID string `json:"node_type_id"`
DriverNodeTypeID string `json:"driver_node_type_id"`
SSHPublicKeys []string `json:"ssh_public_keys"`
CustomTags []ClusterTag `json:"custom_tags"`
ClusterLogConf *ClusterLogConf `json:"cluster_log_conf,omitempty"`
InitScripts []InitScriptInfo `json:"init_scripts"`
SparkEnvVars map[string]string `json:"spark_env_vars,omitempty"`
AutoterminationMinutes int32 `json:"autotermination_minutes"`
EnableElasticDisk bool `json:"enable_elastic_disk"`
}
// ClusterEditRequest is a Edit request for a Cluster.
type ClusterEditRequest struct {
NumWorkers *int32 `json:"num_workers,omitempty"`
Autoscale *Autoscale `json:"autoscale,omitempty"`
ClusterID string `json:"cluster_id"`
ClusterName string `json:"cluster_name"`
SparkVersion string `json:"spark_version"`
SparkConf *S3StorageInfo `json:"spark_conf,omitempty"`
AWSAttributes *AWSAttributes `json:"aws_attributes,omitempty"`
NodeTypeID string `json:"node_type_id"`
DriverNodeTypeID string `json:"driver_node_type_id"`
SSHPublicKeys []string `json:"ssh_public_keys,omitempty"`
CustomTags []ClusterTag `json:"custom_tags,omitempty"`
ClusterLogConf ClusterLogConf `json:"cluster_log_conf"`
InitScripts []InitScriptInfo `json:"init_scripts,omitempty"`
SparkEnvVars map[string]string `json:"spark_env_vars,omitempty"`
AutoterminationMinutes int32 `json:"autotermination_minutes"`
EnableElasticDisk bool `json:"enable_elastic_disk"`
}
// ClusterGetResponse is a response for a Cluster Get request.
type ClusterGetResponse struct {
NumWorkers *int32 `json:"num_workers,omitempty"`
Autoscale *Autoscale `json:"autoscale,omitempty"`
ClusterID string `json:"cluster_id"`
CreatorUserName string `json:"creator_user_name"`
Driver *SparkNode `json:"driver"`
Executors []SparkNode `json:"executors"`
SparkContextID int64 `json:"spark_context_id"`
JDBCPort int32 `json:"jdbc_port"`
ClusterName string `json:"cluster_name"`
SparkVersion string `json:"spark_version"`
SparkConf map[string]string `json:"spark_conf"`
AWSAttributes AWSAttributes `json:"aws_attributes"`
NodeTypeID string `json:"node_type_id"`
DriverNodeTypeID string `json:"driver_node_type_id"`
SSHPublicKeys []string `json:"ssh_public_keys"`
CustomTags map[string]string `json:"custom_tags"`
ClusterLogConf *ClusterLogConf `json:"cluster_log_conf"`
InitScripts []InitScriptInfo `json:"init_scripts"`
SparkEnvVars map[string]string `json:"spark_env_vars"`
AutoterminationMinutes int32 `json:"autotermination_minutes"`
EnableElasticDisk bool `json:"enable_elastic_disk"`
ClusterSource *AWSAvailability `json:"cluster_source"`
State ClusterState `json:"state"`
StateMessage string `json:"state_message"`
StartTime int64 `json:"start_time"`
TerminatedTime int64 `json:"terminated_time"`
LastStateLossTime int64 `json:"last_state_loss_time"`
LastActivityTime int64 `json:"last_activity_time"`
ClusterMemoryMB int64 `json:"cluster_memory_mb"`
ClusterCores float32 `json:"cluster_cores"`
DefaultTags map[string]string `json:"default_tags"`
}
// Autoscale is used to set the bounds on autoscaling a Cluster.
type Autoscale struct {
Min int32 `json:"min_workers"`
Max int32 `json:"max_workers"`
}
// ParameterPair is a termination parameter.
type ParameterPair struct {
Key string `json:"key"`
Value string `json:"value"`
}
// AWSAvailability is used to configure AWS availability.
type AWSAvailability string
const (
Spot AWSAvailability = "SPOT"
OnDemand = "ON_DEMAND"
SpotWithFallBack = "SPOT_WITH_FALLBACK"
)
// EBSVolumeType EBS volume types that Databricks supports. See Amazon EBS
// Product Details for details.
type EBSVolumeType string
const (
SSD EBSVolumeType = "GENERAL_PURPOSE_SSD"
HDD = "THROUGHPUT_OPTIMIZED_HDD"
)
// ClusterSource is the service that created the cluster.
type ClusterSource string
const (
UI ClusterSource = "UI"
ClusterJob = "JOB"
API = "API"
)
// ClusterState is the state of a cluster. The current allowable state
// transitions are as follows:
//
// PENDING -> RUNNING
// PENDING -> TERMINATING
// RUNNING -> RESIZING
// RUNNING -> RESTARTING
// RUNNING -> TERMINATING
// RESTARTING -> RUNNING
// RESTARTING -> TERMINATING
// RESIZING -> RUNNING
// RESIZING -> TERMINATING
// TERMINATING -> TERMINATED
type ClusterState string
const (
Pending ClusterState = "PENDING"
Running = "RUNNING"
Terminating = "TERMINATING"
Resizing = "RESIZING"
Restarting = "RESTARTING"
Terminated = "TERMINATED"
)
// TerminationReason is the reason why a Cluster terminated.
type TerminationReason struct {
Code EBSVolumeType `json:"code"`
Parameters map[string]string `json:"parameters"`
}
// S3StorageInfo is S3 storage information.
type S3StorageInfo struct {
Destination string `json:"destination"`
Region string `json:"region"`
Endpoint string `json:"endpoint"`
EnableEncryption bool `json:"enable_encryption"`
EncryptionType string `json:"encryption_type"`
KMSKey string `json:"kms_key"`
CannedACL string `json:"canned_acl"`
}
// DbfsStorageInfo is DBFS storage info.
type DbfsStorageInfo struct {
Destination string `json:"destination"`
}
// SparkVersion represents a Databricks Spark version.
type SparkVersion struct {
Key string `json:"key"`
Name string `json:"name"`
}
// SparkConfPair are Spark configuration key-value pairs.
type SparkConfPair struct {
Key string `json:"key"`
Value string `json:"value"`
}
// SparkEnvPair are Spark environment variable key-value pairs.
type SparkEnvPair struct {
Key string `json:"key"`
Value string `json:"value"`
}
// SparkNodeAwsAttributes are attributes specific to AWS for a Spark node.
type SparkNodeAwsAttributes struct {
IsSpot bool `json:"is_spot"`
}
// SparkNode is a Spark Node.
type SparkNode struct {
PrivateIP string `json:"private_ip"`
PublicDNS string `json:"public_dns"`
NodeID string `json:"node_id"`
InstanceID string `json:"instance_id"`
StartTimestamp int64 `json:"start_timestamp"`
NodeAWSAttributes SparkNodeAwsAttributes `json:"node_aws_attributes"`
HostPrivateIP string `json:"host_private_ip"`
}
// NodeType is a AWS node type.
type NodeType struct {
NodeTypeID string `json:"node_type_id"`
MemoryMB int32 `json:"memory_mb"`
NumCores float32 `json:"num_cores"`
Description string `json:"description"`
InstanceTypeID string `json:"instance_type_id"`
IsDeprecated bool `json:"is_deprecated"`
}
// AWSAttributes is used to set AWS attributes.
type AWSAttributes struct {
FirstOnDemand int32 `json:"first_on_demand"`
Availability AWSAvailability `json:"availability"`
ZoneID string `json:"zone_id"`
InstanceProfileARN *string `json:"instance_profile_arn,omitempty"`
SpotBidPricePercent *int32 `json:"spot_bid_price_percent,omitempty"`
EBSVolumeType *EBSVolumeType `json:"ebs_volume_type,omitempty"`
EBSVolumeCount *int32 `json:"ebs_volume_count,omitempty"`
EBSVolumeSize *int32 `json:"ebs_volume_size,omitempty"`
}
// ClusterTag is a key value pair of cluster tags.
type ClusterTag struct {
Key string `json:"key"`
Value string `json:"value"`
}
// ClusterLogConf is used to configure Cluster logging.
type ClusterLogConf struct {
DBFS *DbfsStorageInfo `json:"dbfs"`
S3 *S3StorageInfo `json:"s3"`
}
// InitScriptInfo is info for an init script.
type InitScriptInfo struct {
DBFS *DbfsStorageInfo `json:"dbfs"`
S3 *S3StorageInfo `json:"s3"`
}
// LogSyncStatus is the statu of log synchronization
type LogSyncStatus struct {
LastAttempted int64 `json:"last_attempted"`
LastException string `json:"last_exception"`
}
// ClusterInfo describes all of the metadata about a single Spark cluster in
// Databricks.
type ClusterInfo struct {
NumWorkers *int32 `json:"num_workers"`
Autoscale *Autoscale `json:"autoscale"`
ClusterID string `json:"cluster_id"`
CreatorUserName string `json:"creator_user_name"`
Driver SparkNode `json:"driver"`
Executors []SparkNode `json:"executors"`
SparkContextID int64 `json:"spark_context_id"`
JDBCPort int32 `json:"jdbc_port"`
ClusterName string `json:"cluster_name"`
SparkVersion string `json:"spark_version"`
SparkConf S3StorageInfo `json:"spark_conf"` //Example Spark confs: {"spark.speculation": true, "spark.streaming.ui.retainedBatches": 5} or {"spark.driver.extraJavaOptions": "-verbose:gc -XX:+PrintGCDetails"}
AWSAttributes AWSAttributes `json:"aws_attributes"`
NodeTypeID string `json:"node_type_id"`
DriverNodeTypeID string `json:"driver_node_type_id"`
SSHPublicKeys []string `json:"ssh_public_keys"`
CustomTags []ClusterTag `json:"custom_tags"`
ClusterLogConf ClusterLogConf `json:"cluster_log_conf"`
InitScripts []InitScriptInfo `json:"init_scripts"`
SparkEnvVars SparkEnvPair `json:"spark_env_vars"`
AutoterminationMinutes int32 `json:"autotermination_minutes"`
EnableElasticDisk bool `json:"enable_elastic_disk"`
ClusterSource AWSAvailability `json:"cluster_source"`
State ClusterState `json:"state"`
StateMessage string `json:"state_message"`
Start int64 `json:"start"`
TerminatedTime int64 `json:"terminated_time"`
LastStateLossTime int64 `json:"last_state_loss_time"`
LastActivityTime int64 `json:"last_activity_time"`
ClusterMemoryMB int64 `json:"cluster_memory_mb"`
ClusterCores float32 `json:"cluster_cores"`
DefaultTags map[string]string `json:"default_tags"`
ClusterLogStatus LogSyncStatus `json:"cluster_log_status"`
TerminationReason TerminationReason `json:"termination_reason"`
}
// ClusterAttributes are cluster attributes.
type ClusterAttributes struct {
ClusterName string `json:"cluster_name"`
SparkVersion string `json:"spark_version"`
SparkConf S3StorageInfo `json:"spark_conf"`
AWSAttributes AWSAttributes `json:"aws_attributes"`
NodeTypeID string `json:"node_type_id"`
DriverNodeTypeID string `json:"driver_node_type_id"`
SSHPublicKeys []string `json:"ssh_public_keys"`
CustomTags []ClusterTag `json:"custom_tags"`
ClusterLogConf ClusterLogConf `json:"cluster_log_conf"`
InitScripts []InitScriptInfo `json:"init_scripts"`
SparkEnvVars SparkEnvPair `json:"spark_env_vars"`
AutoterminationMinutes int32 `json:"autotermination_minutes"`
EnableElasticDisk bool `json:"enable_elastic_disk"`
ClusterSource AWSAvailability `json:"cluster_source"`
}
// ClusterSize is a Cluster's size.
type ClusterSize struct {
NumWorkers *int32 `json:"num_workers"`
Autoscale *Autoscale `json:"autoscale"`
}
// EventDetails is the details of an Event.
type EventDetails struct {
CurrentNumWorkers int32 `json:"current_num_workers"`
TargetNumWorkers int32 `json:"target_num_workers"`
PreviousAttributes ClusterAttributes `json:"previous_attributes"`
Attributes ClusterAttributes `json:"attributes"`
PreviousClusterSize ClusterSize `json:"previous_cluster_size"`
ClusterSize ClusterSize `json:"cluster_size"`
Cause string `json:"cause"`
Reason TerminationReason `json:"reason"`
User string `json:"user"`
}
// ClusterEvent is an event that occured on a Cluster.
type ClusterEvent struct {
ClusterID string `json:"cluster_id"`
Timestamp int64 `json:"timestamp"`
Type string `json:"type"` // TODO(daniel): make this a type?
Details EventDetails `json:"details"`
}
// ClusterZoneResponse is a reponse for a Cluser zone request.
type ClusterZoneResponse struct {
Zones []string `json:"zones"`
DefaultZone string `json:"default_zone"`
}
// ClusterEventRequest retrieves events pertaining to a specific cluster.
type ClusterEventRequest struct {
ClusterID string `json:"cluster_id"`
StartTime *int64 `json:"start_time"`
EndTime *int64 `json:"end_time"`
Order *ListOrder `json:"order"`
EventTypes []string `json:"event_types"` // TODO(daniel): https://docs.databricks.com/api/latest/clusters.html#clustereventtype
Offset int64 `json:"offset"`
Limit int64 `json:"limit"`
}
// ClusterEventResponse is a reponse for a ClusterEventRequest.
type ClusterEventResponse struct {
Events []string `json:"events"`
NextPage *ClusterEventRequest `json:"next_page"`
TotalCount int64 `json:"total_count"`
}