@databricks/sdk-warehouses 0.1.0-dev.3 → 0.1.0-dev.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/v1/client.ts DELETED
@@ -1,946 +0,0 @@
1
- // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
-
3
- import {VERSION as AUTH_VERSION} from '@databricks/sdk-auth';
4
- import {createDefault} from '@databricks/sdk-core/clientinfo';
5
- import type {Logger} from '@databricks/sdk-core/logger';
6
- import {NoOpLogger} from '@databricks/sdk-core/logger';
7
- import type {CallOptions} from '@databricks/sdk-options/call';
8
- import type {ClientOptions} from '@databricks/sdk-options/client';
9
- import type {LroOptions} from '@databricks/sdk-options/lro';
10
- import type {HttpClient} from '@databricks/sdk-core/http';
11
- import {newHttpClient} from './transport';
12
- import {
13
- buildHttpRequest,
14
- executeCall,
15
- executeHttpCall,
16
- marshalRequest,
17
- parseResponse,
18
- executeWait,
19
- StillRunningError,
20
- } from './utils';
21
- import pkgJson from '../../package.json' with {type: 'json'};
22
- import type {
23
- CreateDefaultWarehouseOverrideRequest,
24
- CreateWarehouseRequest,
25
- CreateWarehouseResponse,
26
- DefaultWarehouseOverride,
27
- DeleteDefaultWarehouseOverrideRequest,
28
- DeleteWarehouseRequest,
29
- DeleteWarehouseResponse,
30
- EditWarehouseRequest,
31
- EditWarehouseResponse,
32
- EndpointInfo,
33
- GetDefaultWarehouseOverrideRequest,
34
- GetWarehouseRequest,
35
- GetWarehouseResponse,
36
- GetWorkspaceWarehouseConfigRequest,
37
- GetWorkspaceWarehouseConfigResponse,
38
- ListDefaultWarehouseOverridesRequest,
39
- ListDefaultWarehouseOverridesResponse,
40
- ListWarehousesRequest,
41
- ListWarehousesResponse,
42
- SetWorkspaceWarehouseConfigRequest,
43
- SetWorkspaceWarehouseConfigResponse,
44
- StartRequest,
45
- StartResponse,
46
- StopRequest,
47
- StopResponse,
48
- UpdateDefaultWarehouseOverrideRequest,
49
- } from './model';
50
- import {
51
- EndpointState,
52
- marshalCreateWarehouseRequestSchema,
53
- marshalDefaultWarehouseOverrideSchema,
54
- marshalEditWarehouseRequestSchema,
55
- marshalSetWorkspaceWarehouseConfigRequestSchema,
56
- marshalStartRequestSchema,
57
- marshalStopRequestSchema,
58
- unmarshalCreateWarehouseResponseSchema,
59
- unmarshalDefaultWarehouseOverrideSchema,
60
- unmarshalDeleteWarehouseResponseSchema,
61
- unmarshalEditWarehouseResponseSchema,
62
- unmarshalGetWarehouseResponseSchema,
63
- unmarshalGetWorkspaceWarehouseConfigResponseSchema,
64
- unmarshalListDefaultWarehouseOverridesResponseSchema,
65
- unmarshalListWarehousesResponseSchema,
66
- unmarshalSetWorkspaceWarehouseConfigResponseSchema,
67
- unmarshalStartResponseSchema,
68
- unmarshalStopResponseSchema,
69
- } from './model';
70
-
71
- // Package identity segment for this client to be used in the User-Agent header.
72
- const PACKAGE_SEGMENT = {
73
- key: 'sdk-js-' + pkgJson.name.replace(/^@[^/]+\/sdk-/, ''),
74
- value: pkgJson.version,
75
- };
76
-
77
- export class WarehousesClient {
78
- private readonly host: string;
79
- // Workspace ID used to route workspace-level calls on unified hosts (SPOG).
80
- // When set, workspace-level methods send X-Databricks-Org-Id on every
81
- // request.
82
- private readonly workspaceId: string | undefined;
83
- private readonly httpClient: HttpClient;
84
- private readonly logger: Logger;
85
- // User-Agent header value. Composed once at construction from
86
- // createDefault() merged with this package's identity and the active
87
- // credential's name.
88
- private readonly userAgent: string;
89
-
90
- constructor(options: ClientOptions) {
91
- if (options.host === undefined) {
92
- throw new Error('Host is required.');
93
- }
94
- this.host = options.host.replace(/\/$/, '');
95
- this.workspaceId = options.workspaceId;
96
- this.logger = options.logger ?? new NoOpLogger();
97
- const info = createDefault()
98
- .with(PACKAGE_SEGMENT)
99
- .with({key: 'sdk-js-auth', value: AUTH_VERSION})
100
- .with({key: 'auth', value: options.credentials?.name() ?? 'default'});
101
- this.userAgent = info.toString();
102
- this.httpClient = newHttpClient(options);
103
- }
104
-
105
- /**
106
- * Creates a new default warehouse override for a user.
107
- * Users can create their own override. Admins can create overrides for any user.
108
- */
109
- async createDefaultWarehouseOverride(
110
- req: CreateDefaultWarehouseOverrideRequest,
111
- options?: CallOptions
112
- ): Promise<DefaultWarehouseOverride> {
113
- const url = `${this.host}/api/warehouses/v1/default-warehouse-overrides`;
114
- const params = new URLSearchParams();
115
- if (req.defaultWarehouseOverrideId !== undefined) {
116
- params.append(
117
- 'default_warehouse_override_id',
118
- req.defaultWarehouseOverrideId
119
- );
120
- }
121
- const query = params.toString();
122
- const fullUrl = query !== '' ? `${url}?${query}` : url;
123
- const body = marshalRequest(
124
- req.defaultWarehouseOverride,
125
- marshalDefaultWarehouseOverrideSchema
126
- );
127
- let resp: DefaultWarehouseOverride | undefined;
128
- const call = async (callSignal?: AbortSignal): Promise<void> => {
129
- const headers = new Headers({'Content-Type': 'application/json'});
130
- if (this.workspaceId !== undefined) {
131
- headers.set('X-Databricks-Org-Id', this.workspaceId);
132
- }
133
- headers.set('User-Agent', this.userAgent);
134
- const httpReq = buildHttpRequest(
135
- 'POST',
136
- fullUrl,
137
- headers,
138
- callSignal,
139
- body
140
- );
141
- const respBody = await executeHttpCall({
142
- request: httpReq,
143
- httpClient: this.httpClient,
144
- logger: this.logger,
145
- });
146
- resp = parseResponse(respBody, unmarshalDefaultWarehouseOverrideSchema);
147
- };
148
- await executeCall(call, options);
149
- if (resp === undefined) {
150
- throw new Error('operation completed without a result.');
151
- }
152
- return resp;
153
- }
154
-
155
- /** Creates a new SQL warehouse. */
156
- private async createWarehouse(
157
- req: CreateWarehouseRequest,
158
- options?: CallOptions
159
- ): Promise<CreateWarehouseResponse> {
160
- const url = `${this.host}/api/2.0/sql/warehouses`;
161
- const body = marshalRequest(req, marshalCreateWarehouseRequestSchema);
162
- let resp: CreateWarehouseResponse | undefined;
163
- const call = async (callSignal?: AbortSignal): Promise<void> => {
164
- const headers = new Headers({'Content-Type': 'application/json'});
165
- if (this.workspaceId !== undefined) {
166
- headers.set('X-Databricks-Org-Id', this.workspaceId);
167
- }
168
- headers.set('User-Agent', this.userAgent);
169
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
170
- const respBody = await executeHttpCall({
171
- request: httpReq,
172
- httpClient: this.httpClient,
173
- logger: this.logger,
174
- });
175
- resp = parseResponse(respBody, unmarshalCreateWarehouseResponseSchema);
176
- };
177
- await executeCall(call, options);
178
- if (resp === undefined) {
179
- throw new Error('operation completed without a result.');
180
- }
181
- return resp;
182
- }
183
-
184
- async createWarehouseWaiter(
185
- req: CreateWarehouseRequest,
186
- options?: CallOptions
187
- ): Promise<CreateWarehouseWaiter> {
188
- const resp = await this.createWarehouse(req, options);
189
- if (resp.id === undefined) {
190
- throw new Error('response field id required for polling is missing');
191
- }
192
- return new CreateWarehouseWaiter(this, resp.id);
193
- }
194
-
195
- /**
196
- * Deletes the default warehouse override for a user.
197
- * Users can delete their own override. Admins can delete overrides for any user.
198
- * After deletion, the workspace default warehouse will be used.
199
- */
200
- async deleteDefaultWarehouseOverride(
201
- req: DeleteDefaultWarehouseOverrideRequest,
202
- options?: CallOptions
203
- ): Promise<void> {
204
- const url = `${this.host}/api/warehouses/v1/${req.name ?? ''}`;
205
- const call = async (callSignal?: AbortSignal): Promise<void> => {
206
- const headers = new Headers();
207
- if (this.workspaceId !== undefined) {
208
- headers.set('X-Databricks-Org-Id', this.workspaceId);
209
- }
210
- headers.set('User-Agent', this.userAgent);
211
- const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
212
- await executeHttpCall({
213
- request: httpReq,
214
- httpClient: this.httpClient,
215
- logger: this.logger,
216
- });
217
- };
218
- await executeCall(call, options);
219
- }
220
-
221
- /** Deletes a SQL warehouse. */
222
- async deleteWarehouse(
223
- req: DeleteWarehouseRequest,
224
- options?: CallOptions
225
- ): Promise<DeleteWarehouseResponse> {
226
- const url = `${this.host}/api/2.0/sql/warehouses/${req.id ?? ''}`;
227
- let resp: DeleteWarehouseResponse | undefined;
228
- const call = async (callSignal?: AbortSignal): Promise<void> => {
229
- const headers = new Headers();
230
- if (this.workspaceId !== undefined) {
231
- headers.set('X-Databricks-Org-Id', this.workspaceId);
232
- }
233
- headers.set('User-Agent', this.userAgent);
234
- const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
235
- const respBody = await executeHttpCall({
236
- request: httpReq,
237
- httpClient: this.httpClient,
238
- logger: this.logger,
239
- });
240
- resp = parseResponse(respBody, unmarshalDeleteWarehouseResponseSchema);
241
- };
242
- await executeCall(call, options);
243
- if (resp === undefined) {
244
- throw new Error('operation completed without a result.');
245
- }
246
- return resp;
247
- }
248
-
249
- /** Updates the configuration for a SQL warehouse. */
250
- private async editWarehouse(
251
- req: EditWarehouseRequest,
252
- options?: CallOptions
253
- ): Promise<EditWarehouseResponse> {
254
- const url = `${this.host}/api/2.0/sql/warehouses/${req.id ?? ''}/edit`;
255
- const body = marshalRequest(req, marshalEditWarehouseRequestSchema);
256
- let resp: EditWarehouseResponse | undefined;
257
- const call = async (callSignal?: AbortSignal): Promise<void> => {
258
- const headers = new Headers({'Content-Type': 'application/json'});
259
- if (this.workspaceId !== undefined) {
260
- headers.set('X-Databricks-Org-Id', this.workspaceId);
261
- }
262
- headers.set('User-Agent', this.userAgent);
263
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
264
- const respBody = await executeHttpCall({
265
- request: httpReq,
266
- httpClient: this.httpClient,
267
- logger: this.logger,
268
- });
269
- resp = parseResponse(respBody, unmarshalEditWarehouseResponseSchema);
270
- };
271
- await executeCall(call, options);
272
- if (resp === undefined) {
273
- throw new Error('operation completed without a result.');
274
- }
275
- return resp;
276
- }
277
-
278
- async editWarehouseWaiter(
279
- req: EditWarehouseRequest,
280
- options?: CallOptions
281
- ): Promise<EditWarehouseWaiter> {
282
- await this.editWarehouse(req, options);
283
- if (req.id === undefined) {
284
- throw new Error('request field id required for polling is missing');
285
- }
286
- return new EditWarehouseWaiter(this, req.id);
287
- }
288
-
289
- /**
290
- * Returns the default warehouse override for a user.
291
- * Users can fetch their own override. Admins can fetch overrides for any user.
292
- * If no override exists, the UI will fallback to the workspace default warehouse.
293
- */
294
- async getDefaultWarehouseOverride(
295
- req: GetDefaultWarehouseOverrideRequest,
296
- options?: CallOptions
297
- ): Promise<DefaultWarehouseOverride> {
298
- const url = `${this.host}/api/warehouses/v1/${req.name ?? ''}`;
299
- let resp: DefaultWarehouseOverride | undefined;
300
- const call = async (callSignal?: AbortSignal): Promise<void> => {
301
- const headers = new Headers();
302
- if (this.workspaceId !== undefined) {
303
- headers.set('X-Databricks-Org-Id', this.workspaceId);
304
- }
305
- headers.set('User-Agent', this.userAgent);
306
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
307
- const respBody = await executeHttpCall({
308
- request: httpReq,
309
- httpClient: this.httpClient,
310
- logger: this.logger,
311
- });
312
- resp = parseResponse(respBody, unmarshalDefaultWarehouseOverrideSchema);
313
- };
314
- await executeCall(call, options);
315
- if (resp === undefined) {
316
- throw new Error('operation completed without a result.');
317
- }
318
- return resp;
319
- }
320
-
321
- /** Gets the information for a single SQL warehouse. */
322
- async getWarehouse(
323
- req: GetWarehouseRequest,
324
- options?: CallOptions
325
- ): Promise<GetWarehouseResponse> {
326
- const url = `${this.host}/api/2.0/sql/warehouses/${req.id ?? ''}`;
327
- let resp: GetWarehouseResponse | undefined;
328
- const call = async (callSignal?: AbortSignal): Promise<void> => {
329
- const headers = new Headers();
330
- if (this.workspaceId !== undefined) {
331
- headers.set('X-Databricks-Org-Id', this.workspaceId);
332
- }
333
- headers.set('User-Agent', this.userAgent);
334
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
335
- const respBody = await executeHttpCall({
336
- request: httpReq,
337
- httpClient: this.httpClient,
338
- logger: this.logger,
339
- });
340
- resp = parseResponse(respBody, unmarshalGetWarehouseResponseSchema);
341
- };
342
- await executeCall(call, options);
343
- if (resp === undefined) {
344
- throw new Error('operation completed without a result.');
345
- }
346
- return resp;
347
- }
348
-
349
- /** Gets the workspace level configuration that is shared by all SQL warehouses in a workspace. */
350
- async getWorkspaceWarehouseConfig(
351
- _req: GetWorkspaceWarehouseConfigRequest,
352
- options?: CallOptions
353
- ): Promise<GetWorkspaceWarehouseConfigResponse> {
354
- const url = `${this.host}/api/2.0/sql/config/warehouses`;
355
- let resp: GetWorkspaceWarehouseConfigResponse | undefined;
356
- const call = async (callSignal?: AbortSignal): Promise<void> => {
357
- const headers = new Headers();
358
- if (this.workspaceId !== undefined) {
359
- headers.set('X-Databricks-Org-Id', this.workspaceId);
360
- }
361
- headers.set('User-Agent', this.userAgent);
362
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
363
- const respBody = await executeHttpCall({
364
- request: httpReq,
365
- httpClient: this.httpClient,
366
- logger: this.logger,
367
- });
368
- resp = parseResponse(
369
- respBody,
370
- unmarshalGetWorkspaceWarehouseConfigResponseSchema
371
- );
372
- };
373
- await executeCall(call, options);
374
- if (resp === undefined) {
375
- throw new Error('operation completed without a result.');
376
- }
377
- return resp;
378
- }
379
-
380
- /**
381
- * Lists all default warehouse overrides in the workspace.
382
- * Only workspace administrators can list all overrides.
383
- */
384
- async listDefaultWarehouseOverrides(
385
- req: ListDefaultWarehouseOverridesRequest,
386
- options?: CallOptions
387
- ): Promise<ListDefaultWarehouseOverridesResponse> {
388
- const url = `${this.host}/api/warehouses/v1/default-warehouse-overrides`;
389
- const params = new URLSearchParams();
390
- if (req.pageSize !== undefined) {
391
- params.append('page_size', String(req.pageSize));
392
- }
393
- if (req.pageToken !== undefined) {
394
- params.append('page_token', req.pageToken);
395
- }
396
- const query = params.toString();
397
- const fullUrl = query !== '' ? `${url}?${query}` : url;
398
- let resp: ListDefaultWarehouseOverridesResponse | undefined;
399
- const call = async (callSignal?: AbortSignal): Promise<void> => {
400
- const headers = new Headers();
401
- if (this.workspaceId !== undefined) {
402
- headers.set('X-Databricks-Org-Id', this.workspaceId);
403
- }
404
- headers.set('User-Agent', this.userAgent);
405
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
406
- const respBody = await executeHttpCall({
407
- request: httpReq,
408
- httpClient: this.httpClient,
409
- logger: this.logger,
410
- });
411
- resp = parseResponse(
412
- respBody,
413
- unmarshalListDefaultWarehouseOverridesResponseSchema
414
- );
415
- };
416
- await executeCall(call, options);
417
- if (resp === undefined) {
418
- throw new Error('operation completed without a result.');
419
- }
420
- return resp;
421
- }
422
-
423
- async *listDefaultWarehouseOverridesIter(
424
- req: ListDefaultWarehouseOverridesRequest,
425
- options?: CallOptions
426
- ): AsyncGenerator<DefaultWarehouseOverride> {
427
- const pageReq: ListDefaultWarehouseOverridesRequest = {...req};
428
- for (;;) {
429
- const resp = await this.listDefaultWarehouseOverrides(pageReq, options);
430
- for (const item of resp.defaultWarehouseOverrides ?? []) {
431
- yield item;
432
- }
433
- if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
434
- return;
435
- }
436
- pageReq.pageToken = resp.nextPageToken;
437
- }
438
- }
439
-
440
- /** Lists all SQL warehouses that a user has access to. */
441
- async listWarehouses(
442
- req: ListWarehousesRequest,
443
- options?: CallOptions
444
- ): Promise<ListWarehousesResponse> {
445
- const url = `${this.host}/api/2.0/sql/warehouses`;
446
- const params = new URLSearchParams();
447
- if (req.runAsUserId !== undefined) {
448
- params.append('run_as_user_id', String(req.runAsUserId));
449
- }
450
- if (req.pageSize !== undefined) {
451
- params.append('page_size', String(req.pageSize));
452
- }
453
- if (req.pageToken !== undefined) {
454
- params.append('page_token', req.pageToken);
455
- }
456
- const query = params.toString();
457
- const fullUrl = query !== '' ? `${url}?${query}` : url;
458
- let resp: ListWarehousesResponse | undefined;
459
- const call = async (callSignal?: AbortSignal): Promise<void> => {
460
- const headers = new Headers();
461
- if (this.workspaceId !== undefined) {
462
- headers.set('X-Databricks-Org-Id', this.workspaceId);
463
- }
464
- headers.set('User-Agent', this.userAgent);
465
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
466
- const respBody = await executeHttpCall({
467
- request: httpReq,
468
- httpClient: this.httpClient,
469
- logger: this.logger,
470
- });
471
- resp = parseResponse(respBody, unmarshalListWarehousesResponseSchema);
472
- };
473
- await executeCall(call, options);
474
- if (resp === undefined) {
475
- throw new Error('operation completed without a result.');
476
- }
477
- return resp;
478
- }
479
-
480
- async *listWarehousesIter(
481
- req: ListWarehousesRequest,
482
- options?: CallOptions
483
- ): AsyncGenerator<EndpointInfo> {
484
- const pageReq: ListWarehousesRequest = {...req};
485
- for (;;) {
486
- const resp = await this.listWarehouses(pageReq, options);
487
- for (const item of resp.warehouses ?? []) {
488
- yield item;
489
- }
490
- if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
491
- return;
492
- }
493
- pageReq.pageToken = resp.nextPageToken;
494
- }
495
- }
496
-
497
- /** Sets the workspace level configuration that is shared by all SQL warehouses in a workspace. */
498
- async setWorkspaceWarehouseConfig(
499
- req: SetWorkspaceWarehouseConfigRequest,
500
- options?: CallOptions
501
- ): Promise<SetWorkspaceWarehouseConfigResponse> {
502
- const url = `${this.host}/api/2.0/sql/config/warehouses`;
503
- const body = marshalRequest(
504
- req,
505
- marshalSetWorkspaceWarehouseConfigRequestSchema
506
- );
507
- let resp: SetWorkspaceWarehouseConfigResponse | undefined;
508
- const call = async (callSignal?: AbortSignal): Promise<void> => {
509
- const headers = new Headers({'Content-Type': 'application/json'});
510
- if (this.workspaceId !== undefined) {
511
- headers.set('X-Databricks-Org-Id', this.workspaceId);
512
- }
513
- headers.set('User-Agent', this.userAgent);
514
- const httpReq = buildHttpRequest('PUT', url, headers, callSignal, body);
515
- const respBody = await executeHttpCall({
516
- request: httpReq,
517
- httpClient: this.httpClient,
518
- logger: this.logger,
519
- });
520
- resp = parseResponse(
521
- respBody,
522
- unmarshalSetWorkspaceWarehouseConfigResponseSchema
523
- );
524
- };
525
- await executeCall(call, options);
526
- if (resp === undefined) {
527
- throw new Error('operation completed without a result.');
528
- }
529
- return resp;
530
- }
531
-
532
- /** Starts a SQL warehouse. */
533
- private async startWarehouse(
534
- req: StartRequest,
535
- options?: CallOptions
536
- ): Promise<StartResponse> {
537
- const url = `${this.host}/api/2.0/sql/warehouses/${req.id ?? ''}/start`;
538
- const body = marshalRequest(req, marshalStartRequestSchema);
539
- let resp: StartResponse | undefined;
540
- const call = async (callSignal?: AbortSignal): Promise<void> => {
541
- const headers = new Headers({'Content-Type': 'application/json'});
542
- if (this.workspaceId !== undefined) {
543
- headers.set('X-Databricks-Org-Id', this.workspaceId);
544
- }
545
- headers.set('User-Agent', this.userAgent);
546
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
547
- const respBody = await executeHttpCall({
548
- request: httpReq,
549
- httpClient: this.httpClient,
550
- logger: this.logger,
551
- });
552
- resp = parseResponse(respBody, unmarshalStartResponseSchema);
553
- };
554
- await executeCall(call, options);
555
- if (resp === undefined) {
556
- throw new Error('operation completed without a result.');
557
- }
558
- return resp;
559
- }
560
-
561
- async startWarehouseWaiter(
562
- req: StartRequest,
563
- options?: CallOptions
564
- ): Promise<StartWarehouseWaiter> {
565
- await this.startWarehouse(req, options);
566
- if (req.id === undefined) {
567
- throw new Error('request field id required for polling is missing');
568
- }
569
- return new StartWarehouseWaiter(this, req.id);
570
- }
571
-
572
- /** Stops a SQL warehouse. */
573
- private async stopWarehouse(
574
- req: StopRequest,
575
- options?: CallOptions
576
- ): Promise<StopResponse> {
577
- const url = `${this.host}/api/2.0/sql/warehouses/${req.id ?? ''}/stop`;
578
- const body = marshalRequest(req, marshalStopRequestSchema);
579
- let resp: StopResponse | undefined;
580
- const call = async (callSignal?: AbortSignal): Promise<void> => {
581
- const headers = new Headers({'Content-Type': 'application/json'});
582
- if (this.workspaceId !== undefined) {
583
- headers.set('X-Databricks-Org-Id', this.workspaceId);
584
- }
585
- headers.set('User-Agent', this.userAgent);
586
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
587
- const respBody = await executeHttpCall({
588
- request: httpReq,
589
- httpClient: this.httpClient,
590
- logger: this.logger,
591
- });
592
- resp = parseResponse(respBody, unmarshalStopResponseSchema);
593
- };
594
- await executeCall(call, options);
595
- if (resp === undefined) {
596
- throw new Error('operation completed without a result.');
597
- }
598
- return resp;
599
- }
600
-
601
- async stopWarehouseWaiter(
602
- req: StopRequest,
603
- options?: CallOptions
604
- ): Promise<StopWarehouseWaiter> {
605
- await this.stopWarehouse(req, options);
606
- if (req.id === undefined) {
607
- throw new Error('request field id required for polling is missing');
608
- }
609
- return new StopWarehouseWaiter(this, req.id);
610
- }
611
-
612
- /**
613
- * Updates an existing default warehouse override for a user.
614
- * Users can update their own override. Admins can update overrides for any user.
615
- */
616
- async updateDefaultWarehouseOverride(
617
- req: UpdateDefaultWarehouseOverrideRequest,
618
- options?: CallOptions
619
- ): Promise<DefaultWarehouseOverride> {
620
- const url = `${this.host}/api/warehouses/v1/${req.defaultWarehouseOverride?.name ?? ''}`;
621
- const params = new URLSearchParams();
622
- if (req.updateMask !== undefined) {
623
- params.append('update_mask', req.updateMask.toString());
624
- }
625
- if (req.allowMissing !== undefined) {
626
- params.append('allow_missing', String(req.allowMissing));
627
- }
628
- const query = params.toString();
629
- const fullUrl = query !== '' ? `${url}?${query}` : url;
630
- const body = marshalRequest(
631
- req.defaultWarehouseOverride,
632
- marshalDefaultWarehouseOverrideSchema
633
- );
634
- let resp: DefaultWarehouseOverride | undefined;
635
- const call = async (callSignal?: AbortSignal): Promise<void> => {
636
- const headers = new Headers({'Content-Type': 'application/json'});
637
- if (this.workspaceId !== undefined) {
638
- headers.set('X-Databricks-Org-Id', this.workspaceId);
639
- }
640
- headers.set('User-Agent', this.userAgent);
641
- const httpReq = buildHttpRequest(
642
- 'PATCH',
643
- fullUrl,
644
- headers,
645
- callSignal,
646
- body
647
- );
648
- const respBody = await executeHttpCall({
649
- request: httpReq,
650
- httpClient: this.httpClient,
651
- logger: this.logger,
652
- });
653
- resp = parseResponse(respBody, unmarshalDefaultWarehouseOverrideSchema);
654
- };
655
- await executeCall(call, options);
656
- if (resp === undefined) {
657
- throw new Error('operation completed without a result.');
658
- }
659
- return resp;
660
- }
661
- }
662
-
663
- export class CreateWarehouseWaiter {
664
- constructor(
665
- private readonly client: WarehousesClient,
666
- readonly id: string
667
- ) {}
668
-
669
- /**
670
- * Polls until the operation reaches a terminal state.
671
- *
672
- * Throws if a failure state is reached.
673
- */
674
- async wait(options?: LroOptions): Promise<GetWarehouseResponse> {
675
- let result: GetWarehouseResponse | undefined;
676
-
677
- const call = async (callSignal?: AbortSignal): Promise<void> => {
678
- const pollResp = await this.client.getWarehouse(
679
- {
680
- id: this.id,
681
- },
682
- callSignal !== undefined ? {signal: callSignal} : undefined
683
- );
684
-
685
- const status = pollResp.state;
686
- if (status === undefined) {
687
- throw new Error('response missing required status field');
688
- }
689
-
690
- switch (status) {
691
- case EndpointState.RUNNING:
692
- result = pollResp;
693
- return;
694
- case EndpointState.STOPPED:
695
- case EndpointState.DELETED: {
696
- const msg = pollResp.health?.summary ?? '(no message)';
697
- throw new Error(`terminal state ${status}: ${msg}`);
698
- }
699
- default:
700
- throw new StillRunningError();
701
- }
702
- };
703
-
704
- await executeWait(call, options);
705
- if (result === undefined) {
706
- throw new Error('operation completed without a result.');
707
- }
708
- return result;
709
- }
710
-
711
- /** Checks whether the operation has reached a terminal state. */
712
- async done(options?: CallOptions): Promise<boolean> {
713
- const pollResp = await this.client.getWarehouse(
714
- {
715
- id: this.id,
716
- },
717
- options
718
- );
719
-
720
- const status = pollResp.state;
721
- if (status === undefined) {
722
- throw new Error('response missing required status field');
723
- }
724
-
725
- switch (status) {
726
- case EndpointState.RUNNING:
727
- case EndpointState.STOPPED:
728
- case EndpointState.DELETED:
729
- return true;
730
- default:
731
- return false;
732
- }
733
- }
734
- }
735
-
736
- export class EditWarehouseWaiter {
737
- constructor(
738
- private readonly client: WarehousesClient,
739
- readonly id: string
740
- ) {}
741
-
742
- /**
743
- * Polls until the operation reaches a terminal state.
744
- *
745
- * Throws if a failure state is reached.
746
- */
747
- async wait(options?: LroOptions): Promise<GetWarehouseResponse> {
748
- let result: GetWarehouseResponse | undefined;
749
-
750
- const call = async (callSignal?: AbortSignal): Promise<void> => {
751
- const pollResp = await this.client.getWarehouse(
752
- {
753
- id: this.id,
754
- },
755
- callSignal !== undefined ? {signal: callSignal} : undefined
756
- );
757
-
758
- const status = pollResp.state;
759
- if (status === undefined) {
760
- throw new Error('response missing required status field');
761
- }
762
-
763
- switch (status) {
764
- case EndpointState.RUNNING:
765
- result = pollResp;
766
- return;
767
- case EndpointState.STOPPED:
768
- case EndpointState.DELETED: {
769
- const msg = pollResp.health?.summary ?? '(no message)';
770
- throw new Error(`terminal state ${status}: ${msg}`);
771
- }
772
- default:
773
- throw new StillRunningError();
774
- }
775
- };
776
-
777
- await executeWait(call, options);
778
- if (result === undefined) {
779
- throw new Error('operation completed without a result.');
780
- }
781
- return result;
782
- }
783
-
784
- /** Checks whether the operation has reached a terminal state. */
785
- async done(options?: CallOptions): Promise<boolean> {
786
- const pollResp = await this.client.getWarehouse(
787
- {
788
- id: this.id,
789
- },
790
- options
791
- );
792
-
793
- const status = pollResp.state;
794
- if (status === undefined) {
795
- throw new Error('response missing required status field');
796
- }
797
-
798
- switch (status) {
799
- case EndpointState.RUNNING:
800
- case EndpointState.STOPPED:
801
- case EndpointState.DELETED:
802
- return true;
803
- default:
804
- return false;
805
- }
806
- }
807
- }
808
-
809
- export class StartWarehouseWaiter {
810
- constructor(
811
- private readonly client: WarehousesClient,
812
- readonly id: string
813
- ) {}
814
-
815
- /**
816
- * Polls until the operation reaches a terminal state.
817
- *
818
- * Throws if a failure state is reached.
819
- */
820
- async wait(options?: LroOptions): Promise<GetWarehouseResponse> {
821
- let result: GetWarehouseResponse | undefined;
822
-
823
- const call = async (callSignal?: AbortSignal): Promise<void> => {
824
- const pollResp = await this.client.getWarehouse(
825
- {
826
- id: this.id,
827
- },
828
- callSignal !== undefined ? {signal: callSignal} : undefined
829
- );
830
-
831
- const status = pollResp.state;
832
- if (status === undefined) {
833
- throw new Error('response missing required status field');
834
- }
835
-
836
- switch (status) {
837
- case EndpointState.RUNNING:
838
- result = pollResp;
839
- return;
840
- case EndpointState.STOPPED:
841
- case EndpointState.DELETED: {
842
- const msg = pollResp.health?.summary ?? '(no message)';
843
- throw new Error(`terminal state ${status}: ${msg}`);
844
- }
845
- default:
846
- throw new StillRunningError();
847
- }
848
- };
849
-
850
- await executeWait(call, options);
851
- if (result === undefined) {
852
- throw new Error('operation completed without a result.');
853
- }
854
- return result;
855
- }
856
-
857
- /** Checks whether the operation has reached a terminal state. */
858
- async done(options?: CallOptions): Promise<boolean> {
859
- const pollResp = await this.client.getWarehouse(
860
- {
861
- id: this.id,
862
- },
863
- options
864
- );
865
-
866
- const status = pollResp.state;
867
- if (status === undefined) {
868
- throw new Error('response missing required status field');
869
- }
870
-
871
- switch (status) {
872
- case EndpointState.RUNNING:
873
- case EndpointState.STOPPED:
874
- case EndpointState.DELETED:
875
- return true;
876
- default:
877
- return false;
878
- }
879
- }
880
- }
881
-
882
- export class StopWarehouseWaiter {
883
- constructor(
884
- private readonly client: WarehousesClient,
885
- readonly id: string
886
- ) {}
887
-
888
- /**
889
- * Polls until the operation reaches a terminal state.
890
- *
891
- * Throws if a failure state is reached.
892
- */
893
- async wait(options?: LroOptions): Promise<GetWarehouseResponse> {
894
- let result: GetWarehouseResponse | undefined;
895
-
896
- const call = async (callSignal?: AbortSignal): Promise<void> => {
897
- const pollResp = await this.client.getWarehouse(
898
- {
899
- id: this.id,
900
- },
901
- callSignal !== undefined ? {signal: callSignal} : undefined
902
- );
903
-
904
- const status = pollResp.state;
905
- if (status === undefined) {
906
- throw new Error('response missing required status field');
907
- }
908
-
909
- switch (status) {
910
- case EndpointState.STOPPED:
911
- result = pollResp;
912
- return;
913
- default:
914
- throw new StillRunningError();
915
- }
916
- };
917
-
918
- await executeWait(call, options);
919
- if (result === undefined) {
920
- throw new Error('operation completed without a result.');
921
- }
922
- return result;
923
- }
924
-
925
- /** Checks whether the operation has reached a terminal state. */
926
- async done(options?: CallOptions): Promise<boolean> {
927
- const pollResp = await this.client.getWarehouse(
928
- {
929
- id: this.id,
930
- },
931
- options
932
- );
933
-
934
- const status = pollResp.state;
935
- if (status === undefined) {
936
- throw new Error('response missing required status field');
937
- }
938
-
939
- switch (status) {
940
- case EndpointState.STOPPED:
941
- return true;
942
- default:
943
- return false;
944
- }
945
- }
946
- }