-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathreservation_client.go
executable file
·2941 lines (2634 loc) · 107 KB
/
reservation_client.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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
package reservation
import (
"bytes"
"context"
"fmt"
"log/slog"
"math"
"net/http"
"net/url"
"time"
reservationpb "cloud.google.com/go/bigquery/reservation/apiv1/reservationpb"
gax "github.com/googleapis/gax-go/v2"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
"google.golang.org/api/option/internaloption"
gtransport "google.golang.org/api/transport/grpc"
httptransport "google.golang.org/api/transport/http"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
)
var newClientHook clientHook
// CallOptions contains the retry settings for each method of Client.
type CallOptions struct {
CreateReservation []gax.CallOption
ListReservations []gax.CallOption
GetReservation []gax.CallOption
DeleteReservation []gax.CallOption
UpdateReservation []gax.CallOption
FailoverReservation []gax.CallOption
CreateCapacityCommitment []gax.CallOption
ListCapacityCommitments []gax.CallOption
GetCapacityCommitment []gax.CallOption
DeleteCapacityCommitment []gax.CallOption
UpdateCapacityCommitment []gax.CallOption
SplitCapacityCommitment []gax.CallOption
MergeCapacityCommitments []gax.CallOption
CreateAssignment []gax.CallOption
ListAssignments []gax.CallOption
DeleteAssignment []gax.CallOption
SearchAssignments []gax.CallOption
SearchAllAssignments []gax.CallOption
MoveAssignment []gax.CallOption
UpdateAssignment []gax.CallOption
GetBiReservation []gax.CallOption
UpdateBiReservation []gax.CallOption
}
func defaultGRPCClientOptions() []option.ClientOption {
return []option.ClientOption{
internaloption.WithDefaultEndpoint("bigqueryreservation.googleapis.com:443"),
internaloption.WithDefaultEndpointTemplate("bigqueryreservation.UNIVERSE_DOMAIN:443"),
internaloption.WithDefaultMTLSEndpoint("bigqueryreservation.mtls.googleapis.com:443"),
internaloption.WithDefaultUniverseDomain("googleapis.com"),
internaloption.WithDefaultAudience("https://bigqueryreservation.googleapis.com/"),
internaloption.WithDefaultScopes(DefaultAuthScopes()...),
internaloption.EnableJwtWithScope(),
internaloption.EnableNewAuthLibrary(),
option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(math.MaxInt32))),
}
}
func defaultCallOptions() *CallOptions {
return &CallOptions{
CreateReservation: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
},
ListReservations: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.DeadlineExceeded,
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
})
}),
},
GetReservation: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.DeadlineExceeded,
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
})
}),
},
DeleteReservation: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.DeadlineExceeded,
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
})
}),
},
UpdateReservation: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
},
FailoverReservation: []gax.CallOption{},
CreateCapacityCommitment: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
},
ListCapacityCommitments: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.DeadlineExceeded,
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
})
}),
},
GetCapacityCommitment: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.DeadlineExceeded,
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
})
}),
},
DeleteCapacityCommitment: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.DeadlineExceeded,
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
})
}),
},
UpdateCapacityCommitment: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
},
SplitCapacityCommitment: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
},
MergeCapacityCommitments: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
},
CreateAssignment: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
},
ListAssignments: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.DeadlineExceeded,
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
})
}),
},
DeleteAssignment: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.DeadlineExceeded,
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
})
}),
},
SearchAssignments: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.DeadlineExceeded,
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
})
}),
},
SearchAllAssignments: []gax.CallOption{},
MoveAssignment: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
},
UpdateAssignment: []gax.CallOption{},
GetBiReservation: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.DeadlineExceeded,
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
})
}),
},
UpdateBiReservation: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
},
}
}
func defaultRESTCallOptions() *CallOptions {
return &CallOptions{
CreateReservation: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
},
ListReservations: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnHTTPCodes(gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
},
http.StatusGatewayTimeout,
http.StatusServiceUnavailable)
}),
},
GetReservation: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnHTTPCodes(gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
},
http.StatusGatewayTimeout,
http.StatusServiceUnavailable)
}),
},
DeleteReservation: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnHTTPCodes(gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
},
http.StatusGatewayTimeout,
http.StatusServiceUnavailable)
}),
},
UpdateReservation: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
},
FailoverReservation: []gax.CallOption{},
CreateCapacityCommitment: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
},
ListCapacityCommitments: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnHTTPCodes(gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
},
http.StatusGatewayTimeout,
http.StatusServiceUnavailable)
}),
},
GetCapacityCommitment: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnHTTPCodes(gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
},
http.StatusGatewayTimeout,
http.StatusServiceUnavailable)
}),
},
DeleteCapacityCommitment: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnHTTPCodes(gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
},
http.StatusGatewayTimeout,
http.StatusServiceUnavailable)
}),
},
UpdateCapacityCommitment: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
},
SplitCapacityCommitment: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
},
MergeCapacityCommitments: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
},
CreateAssignment: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
},
ListAssignments: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnHTTPCodes(gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
},
http.StatusGatewayTimeout,
http.StatusServiceUnavailable)
}),
},
DeleteAssignment: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnHTTPCodes(gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
},
http.StatusGatewayTimeout,
http.StatusServiceUnavailable)
}),
},
SearchAssignments: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnHTTPCodes(gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
},
http.StatusGatewayTimeout,
http.StatusServiceUnavailable)
}),
},
SearchAllAssignments: []gax.CallOption{},
MoveAssignment: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
},
UpdateAssignment: []gax.CallOption{},
GetBiReservation: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnHTTPCodes(gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
},
http.StatusGatewayTimeout,
http.StatusServiceUnavailable)
}),
},
UpdateBiReservation: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
},
}
}
// internalClient is an interface that defines the methods available from BigQuery Reservation API.
type internalClient interface {
Close() error
setGoogleClientInfo(...string)
Connection() *grpc.ClientConn
CreateReservation(context.Context, *reservationpb.CreateReservationRequest, ...gax.CallOption) (*reservationpb.Reservation, error)
ListReservations(context.Context, *reservationpb.ListReservationsRequest, ...gax.CallOption) *ReservationIterator
GetReservation(context.Context, *reservationpb.GetReservationRequest, ...gax.CallOption) (*reservationpb.Reservation, error)
DeleteReservation(context.Context, *reservationpb.DeleteReservationRequest, ...gax.CallOption) error
UpdateReservation(context.Context, *reservationpb.UpdateReservationRequest, ...gax.CallOption) (*reservationpb.Reservation, error)
FailoverReservation(context.Context, *reservationpb.FailoverReservationRequest, ...gax.CallOption) (*reservationpb.Reservation, error)
CreateCapacityCommitment(context.Context, *reservationpb.CreateCapacityCommitmentRequest, ...gax.CallOption) (*reservationpb.CapacityCommitment, error)
ListCapacityCommitments(context.Context, *reservationpb.ListCapacityCommitmentsRequest, ...gax.CallOption) *CapacityCommitmentIterator
GetCapacityCommitment(context.Context, *reservationpb.GetCapacityCommitmentRequest, ...gax.CallOption) (*reservationpb.CapacityCommitment, error)
DeleteCapacityCommitment(context.Context, *reservationpb.DeleteCapacityCommitmentRequest, ...gax.CallOption) error
UpdateCapacityCommitment(context.Context, *reservationpb.UpdateCapacityCommitmentRequest, ...gax.CallOption) (*reservationpb.CapacityCommitment, error)
SplitCapacityCommitment(context.Context, *reservationpb.SplitCapacityCommitmentRequest, ...gax.CallOption) (*reservationpb.SplitCapacityCommitmentResponse, error)
MergeCapacityCommitments(context.Context, *reservationpb.MergeCapacityCommitmentsRequest, ...gax.CallOption) (*reservationpb.CapacityCommitment, error)
CreateAssignment(context.Context, *reservationpb.CreateAssignmentRequest, ...gax.CallOption) (*reservationpb.Assignment, error)
ListAssignments(context.Context, *reservationpb.ListAssignmentsRequest, ...gax.CallOption) *AssignmentIterator
DeleteAssignment(context.Context, *reservationpb.DeleteAssignmentRequest, ...gax.CallOption) error
SearchAssignments(context.Context, *reservationpb.SearchAssignmentsRequest, ...gax.CallOption) *AssignmentIterator
SearchAllAssignments(context.Context, *reservationpb.SearchAllAssignmentsRequest, ...gax.CallOption) *AssignmentIterator
MoveAssignment(context.Context, *reservationpb.MoveAssignmentRequest, ...gax.CallOption) (*reservationpb.Assignment, error)
UpdateAssignment(context.Context, *reservationpb.UpdateAssignmentRequest, ...gax.CallOption) (*reservationpb.Assignment, error)
GetBiReservation(context.Context, *reservationpb.GetBiReservationRequest, ...gax.CallOption) (*reservationpb.BiReservation, error)
UpdateBiReservation(context.Context, *reservationpb.UpdateBiReservationRequest, ...gax.CallOption) (*reservationpb.BiReservation, error)
}
// Client is a client for interacting with BigQuery Reservation API.
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
//
// This API allows users to manage their BigQuery reservations.
//
// A reservation provides computational resource guarantees, in the form of
// slots (at https://cloud.google.com/bigquery/docs/slots), to users. A slot is a
// unit of computational power in BigQuery, and serves as the basic unit of
// parallelism. In a scan of a multi-partitioned table, a single slot operates
// on a single partition of the table. A reservation resource exists as a child
// resource of the admin project and location, e.g.:
// projects/myproject/locations/US/reservations/reservationName.
//
// A capacity commitment is a way to purchase compute capacity for BigQuery jobs
// (in the form of slots) with some committed period of usage. A capacity
// commitment resource exists as a child resource of the admin project and
// location, e.g.:
// projects/myproject/locations/US/capacityCommitments/id.
type Client struct {
// The internal transport-dependent client.
internalClient internalClient
// The call options for this service.
CallOptions *CallOptions
}
// Wrapper methods routed to the internal client.
// Close closes the connection to the API service. The user should invoke this when
// the client is no longer required.
func (c *Client) Close() error {
return c.internalClient.Close()
}
// setGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *Client) setGoogleClientInfo(keyval ...string) {
c.internalClient.setGoogleClientInfo(keyval...)
}
// Connection returns a connection to the API service.
//
// Deprecated: Connections are now pooled so this method does not always
// return the same resource.
func (c *Client) Connection() *grpc.ClientConn {
return c.internalClient.Connection()
}
// CreateReservation creates a new reservation resource.
func (c *Client) CreateReservation(ctx context.Context, req *reservationpb.CreateReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) {
return c.internalClient.CreateReservation(ctx, req, opts...)
}
// ListReservations lists all the reservations for the project in the specified location.
func (c *Client) ListReservations(ctx context.Context, req *reservationpb.ListReservationsRequest, opts ...gax.CallOption) *ReservationIterator {
return c.internalClient.ListReservations(ctx, req, opts...)
}
// GetReservation returns information about the reservation.
func (c *Client) GetReservation(ctx context.Context, req *reservationpb.GetReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) {
return c.internalClient.GetReservation(ctx, req, opts...)
}
// DeleteReservation deletes a reservation.
// Returns google.rpc.Code.FAILED_PRECONDITION when reservation has
// assignments.
func (c *Client) DeleteReservation(ctx context.Context, req *reservationpb.DeleteReservationRequest, opts ...gax.CallOption) error {
return c.internalClient.DeleteReservation(ctx, req, opts...)
}
// UpdateReservation updates an existing reservation resource.
func (c *Client) UpdateReservation(ctx context.Context, req *reservationpb.UpdateReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) {
return c.internalClient.UpdateReservation(ctx, req, opts...)
}
// FailoverReservation fail over a reservation to the secondary location. The operation should be
// done in the current secondary location, which will be promoted to the
// new primary location for the reservation.
// Attempting to failover a reservation in the current primary location will
// fail with the error code google.rpc.Code.FAILED_PRECONDITION.
func (c *Client) FailoverReservation(ctx context.Context, req *reservationpb.FailoverReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) {
return c.internalClient.FailoverReservation(ctx, req, opts...)
}
// CreateCapacityCommitment creates a new capacity commitment resource.
func (c *Client) CreateCapacityCommitment(ctx context.Context, req *reservationpb.CreateCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) {
return c.internalClient.CreateCapacityCommitment(ctx, req, opts...)
}
// ListCapacityCommitments lists all the capacity commitments for the admin project.
func (c *Client) ListCapacityCommitments(ctx context.Context, req *reservationpb.ListCapacityCommitmentsRequest, opts ...gax.CallOption) *CapacityCommitmentIterator {
return c.internalClient.ListCapacityCommitments(ctx, req, opts...)
}
// GetCapacityCommitment returns information about the capacity commitment.
func (c *Client) GetCapacityCommitment(ctx context.Context, req *reservationpb.GetCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) {
return c.internalClient.GetCapacityCommitment(ctx, req, opts...)
}
// DeleteCapacityCommitment deletes a capacity commitment. Attempting to delete capacity commitment
// before its commitment_end_time will fail with the error code
// google.rpc.Code.FAILED_PRECONDITION.
func (c *Client) DeleteCapacityCommitment(ctx context.Context, req *reservationpb.DeleteCapacityCommitmentRequest, opts ...gax.CallOption) error {
return c.internalClient.DeleteCapacityCommitment(ctx, req, opts...)
}
// UpdateCapacityCommitment updates an existing capacity commitment.
//
// Only plan and renewal_plan fields can be updated.
//
// Plan can only be changed to a plan of a longer commitment period.
// Attempting to change to a plan with shorter commitment period will fail
// with the error code google.rpc.Code.FAILED_PRECONDITION.
func (c *Client) UpdateCapacityCommitment(ctx context.Context, req *reservationpb.UpdateCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) {
return c.internalClient.UpdateCapacityCommitment(ctx, req, opts...)
}
// SplitCapacityCommitment splits capacity commitment to two commitments of the same plan and
// commitment_end_time.
//
// A common use case is to enable downgrading commitments.
//
// For example, in order to downgrade from 10000 slots to 8000, you might
// split a 10000 capacity commitment into commitments of 2000 and 8000. Then,
// you delete the first one after the commitment end time passes.
func (c *Client) SplitCapacityCommitment(ctx context.Context, req *reservationpb.SplitCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.SplitCapacityCommitmentResponse, error) {
return c.internalClient.SplitCapacityCommitment(ctx, req, opts...)
}
// MergeCapacityCommitments merges capacity commitments of the same plan into a single commitment.
//
// The resulting capacity commitment has the greater commitment_end_time
// out of the to-be-merged capacity commitments.
//
// Attempting to merge capacity commitments of different plan will fail
// with the error code google.rpc.Code.FAILED_PRECONDITION.
func (c *Client) MergeCapacityCommitments(ctx context.Context, req *reservationpb.MergeCapacityCommitmentsRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) {
return c.internalClient.MergeCapacityCommitments(ctx, req, opts...)
}
// CreateAssignment creates an assignment object which allows the given project to submit jobs
// of a certain type using slots from the specified reservation.
//
// Currently a
// resource (project, folder, organization) can only have one assignment per
// each (job_type, location) combination, and that reservation will be used
// for all jobs of the matching type.
//
// Different assignments can be created on different levels of the
// projects, folders or organization hierarchy. During query execution,
// the assignment is looked up at the project, folder and organization levels
// in that order. The first assignment found is applied to the query.
//
// When creating assignments, it does not matter if other assignments exist at
// higher levels.
//
// Example:
//
// The organization organizationA contains two projects, project1
// and project2.
//
// Assignments for all three entities (organizationA, project1, and
// project2) could all be created and mapped to the same or different
// reservations.
//
// “None” assignments represent an absence of the assignment. Projects
// assigned to None use on-demand pricing. To create a “None” assignment, use
// “none” as a reservation_id in the parent. Example parent:
// projects/myproject/locations/US/reservations/none.
//
// Returns google.rpc.Code.PERMISSION_DENIED if user does not have
// ‘bigquery.admin’ permissions on the project using the reservation
// and the project that owns this reservation.
//
// Returns google.rpc.Code.INVALID_ARGUMENT when location of the assignment
// does not match location of the reservation.
func (c *Client) CreateAssignment(ctx context.Context, req *reservationpb.CreateAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) {
return c.internalClient.CreateAssignment(ctx, req, opts...)
}
// ListAssignments lists assignments.
//
// Only explicitly created assignments will be returned.
//
// Example:
//
// Organization organizationA contains two projects, project1 and
// project2.
//
// Reservation res1 exists and was created previously.
//
// CreateAssignment was used previously to define the following
// associations between entities and reservations: <organizationA, res1>
// and <project1, res1>
//
// In this example, ListAssignments will just return the above two assignments
// for reservation res1, and no expansion/merge will happen.
//
// The wildcard “-” can be used for
// reservations in the request. In that case all assignments belongs to the
// specified project and location will be listed.
//
// Note "-" cannot be used for projects nor locations.
func (c *Client) ListAssignments(ctx context.Context, req *reservationpb.ListAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator {
return c.internalClient.ListAssignments(ctx, req, opts...)
}
// DeleteAssignment deletes a assignment. No expansion will happen.
//
// Example:
//
// Organization organizationA contains two projects, project1 and
// project2.
//
// Reservation res1 exists and was created previously.
//
// CreateAssignment was used previously to define the following
// associations between entities and reservations: <organizationA, res1>
// and <project1, res1>
//
// In this example, deletion of the <organizationA, res1> assignment won’t
// affect the other assignment <project1, res1>. After said deletion,
// queries from project1 will still use res1 while queries from
// project2 will switch to use on-demand mode.
func (c *Client) DeleteAssignment(ctx context.Context, req *reservationpb.DeleteAssignmentRequest, opts ...gax.CallOption) error {
return c.internalClient.DeleteAssignment(ctx, req, opts...)
}
// SearchAssignments deprecated: Looks up assignments for a specified resource for a particular
// region. If the request is about a project:
//
// Assignments created on the project will be returned if they exist.
//
// Otherwise assignments created on the closest ancestor will be
// returned.
//
// Assignments for different JobTypes will all be returned.
//
// The same logic applies if the request is about a folder.
//
// If the request is about an organization, then assignments created on the
// organization will be returned (organization doesn’t have ancestors).
//
// Comparing to ListAssignments, there are some behavior
// differences:
//
// permission on the assignee will be verified in this API.
//
// Hierarchy lookup (project->folder->organization) happens in this API.
//
// Parent here is projects/*/locations/*, instead of
// projects/*/locations/*reservations/*.
//
// Note "-" cannot be used for projects
// nor locations.
//
// Deprecated: SearchAssignments may be removed in a future version.
func (c *Client) SearchAssignments(ctx context.Context, req *reservationpb.SearchAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator {
return c.internalClient.SearchAssignments(ctx, req, opts...)
}
// SearchAllAssignments looks up assignments for a specified resource for a particular region.
// If the request is about a project:
//
// Assignments created on the project will be returned if they exist.
//
// Otherwise assignments created on the closest ancestor will be
// returned.
//
// Assignments for different JobTypes will all be returned.
//
// The same logic applies if the request is about a folder.
//
// If the request is about an organization, then assignments created on the
// organization will be returned (organization doesn’t have ancestors).
//
// Comparing to ListAssignments, there are some behavior
// differences:
//
// permission on the assignee will be verified in this API.
//
// Hierarchy lookup (project->folder->organization) happens in this API.
//
// Parent here is projects/*/locations/*, instead of
// projects/*/locations/*reservations/*.
func (c *Client) SearchAllAssignments(ctx context.Context, req *reservationpb.SearchAllAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator {
return c.internalClient.SearchAllAssignments(ctx, req, opts...)
}
// MoveAssignment moves an assignment under a new reservation.
//
// This differs from removing an existing assignment and recreating a new one
// by providing a transactional change that ensures an assignee always has an
// associated reservation.
func (c *Client) MoveAssignment(ctx context.Context, req *reservationpb.MoveAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) {
return c.internalClient.MoveAssignment(ctx, req, opts...)
}
// UpdateAssignment updates an existing assignment.
//
// Only the priority field can be updated.
func (c *Client) UpdateAssignment(ctx context.Context, req *reservationpb.UpdateAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) {
return c.internalClient.UpdateAssignment(ctx, req, opts...)
}
// GetBiReservation retrieves a BI reservation.
func (c *Client) GetBiReservation(ctx context.Context, req *reservationpb.GetBiReservationRequest, opts ...gax.CallOption) (*reservationpb.BiReservation, error) {
return c.internalClient.GetBiReservation(ctx, req, opts...)
}
// UpdateBiReservation updates a BI reservation.
//
// Only fields specified in the field_mask are updated.
//
// A singleton BI reservation always exists with default size 0.
// In order to reserve BI capacity it needs to be updated to an amount
// greater than 0. In order to release BI capacity reservation size
// must be set to 0.
func (c *Client) UpdateBiReservation(ctx context.Context, req *reservationpb.UpdateBiReservationRequest, opts ...gax.CallOption) (*reservationpb.BiReservation, error) {
return c.internalClient.UpdateBiReservation(ctx, req, opts...)
}
// gRPCClient is a client for interacting with BigQuery Reservation API over gRPC transport.
//
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
type gRPCClient struct {
// Connection pool of gRPC connections to the service.
connPool gtransport.ConnPool
// Points back to the CallOptions field of the containing Client
CallOptions **CallOptions
// The gRPC API client.
client reservationpb.ReservationServiceClient
// The x-goog-* metadata to be sent with each request.
xGoogHeaders []string
logger *slog.Logger
}
// NewClient creates a new reservation service client based on gRPC.
// The returned client must be Closed when it is done being used to clean up its underlying connections.
//
// This API allows users to manage their BigQuery reservations.
//
// A reservation provides computational resource guarantees, in the form of
// slots (at https://cloud.google.com/bigquery/docs/slots), to users. A slot is a
// unit of computational power in BigQuery, and serves as the basic unit of
// parallelism. In a scan of a multi-partitioned table, a single slot operates
// on a single partition of the table. A reservation resource exists as a child
// resource of the admin project and location, e.g.:
// projects/myproject/locations/US/reservations/reservationName.
//
// A capacity commitment is a way to purchase compute capacity for BigQuery jobs
// (in the form of slots) with some committed period of usage. A capacity
// commitment resource exists as a child resource of the admin project and
// location, e.g.:
// projects/myproject/locations/US/capacityCommitments/id.
func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
clientOpts := defaultGRPCClientOptions()
if newClientHook != nil {
hookOpts, err := newClientHook(ctx, clientHookParams{})
if err != nil {
return nil, err
}
clientOpts = append(clientOpts, hookOpts...)
}
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
if err != nil {
return nil, err
}
client := Client{CallOptions: defaultCallOptions()}
c := &gRPCClient{
connPool: connPool,
client: reservationpb.NewReservationServiceClient(connPool),
CallOptions: &client.CallOptions,
logger: internaloption.GetLogger(opts),
}
c.setGoogleClientInfo()
client.internalClient = c
return &client, nil
}
// Connection returns a connection to the API service.
//
// Deprecated: Connections are now pooled so this method does not always
// return the same resource.
func (c *gRPCClient) Connection() *grpc.ClientConn {
return c.connPool.Conn()
}
// setGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *gRPCClient) setGoogleClientInfo(keyval ...string) {
kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
c.xGoogHeaders = []string{
"x-goog-api-client", gax.XGoogHeader(kv...),
}
}
// Close closes the connection to the API service. The user should invoke this when
// the client is no longer required.
func (c *gRPCClient) Close() error {
return c.connPool.Close()
}
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
type restClient struct {
// The http endpoint to connect to.
endpoint string
// The http client.
httpClient *http.Client
// The x-goog-* headers to be sent with each request.
xGoogHeaders []string
// Points back to the CallOptions field of the containing Client
CallOptions **CallOptions
logger *slog.Logger
}
// NewRESTClient creates a new reservation service rest client.
//
// This API allows users to manage their BigQuery reservations.
//
// A reservation provides computational resource guarantees, in the form of
// slots (at https://cloud.google.com/bigquery/docs/slots), to users. A slot is a
// unit of computational power in BigQuery, and serves as the basic unit of
// parallelism. In a scan of a multi-partitioned table, a single slot operates
// on a single partition of the table. A reservation resource exists as a child
// resource of the admin project and location, e.g.:
// projects/myproject/locations/US/reservations/reservationName.
//
// A capacity commitment is a way to purchase compute capacity for BigQuery jobs
// (in the form of slots) with some committed period of usage. A capacity
// commitment resource exists as a child resource of the admin project and
// location, e.g.:
// projects/myproject/locations/US/capacityCommitments/id.
func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
clientOpts := append(defaultRESTClientOptions(), opts...)
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
if err != nil {
return nil, err
}
callOpts := defaultRESTCallOptions()
c := &restClient{
endpoint: endpoint,
httpClient: httpClient,
CallOptions: &callOpts,
logger: internaloption.GetLogger(opts),
}
c.setGoogleClientInfo()
return &Client{internalClient: c, CallOptions: callOpts}, nil
}
func defaultRESTClientOptions() []option.ClientOption {
return []option.ClientOption{
internaloption.WithDefaultEndpoint("https://bigqueryreservation.googleapis.com"),
internaloption.WithDefaultEndpointTemplate("https://bigqueryreservation.UNIVERSE_DOMAIN"),
internaloption.WithDefaultMTLSEndpoint("https://bigqueryreservation.mtls.googleapis.com"),
internaloption.WithDefaultUniverseDomain("googleapis.com"),
internaloption.WithDefaultAudience("https://bigqueryreservation.googleapis.com/"),
internaloption.WithDefaultScopes(DefaultAuthScopes()...),
internaloption.EnableNewAuthLibrary(),
}
}
// setGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *restClient) setGoogleClientInfo(keyval ...string) {
kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN")
c.xGoogHeaders = []string{
"x-goog-api-client", gax.XGoogHeader(kv...),
}
}
// Close closes the connection to the API service. The user should invoke this when
// the client is no longer required.
func (c *restClient) Close() error {
// Replace httpClient with nil to force cleanup.
c.httpClient = nil
return nil
}
// Connection returns a connection to the API service.
//
// Deprecated: This method always returns nil.
func (c *restClient) Connection() *grpc.ClientConn {
return nil
}
func (c *gRPCClient) CreateReservation(ctx context.Context, req *reservationpb.CreateReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
opts = append((*c.CallOptions).CreateReservation[0:len((*c.CallOptions).CreateReservation):len((*c.CallOptions).CreateReservation)], opts...)
var resp *reservationpb.Reservation
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = executeRPC(ctx, c.client.CreateReservation, req, settings.GRPC, c.logger, "CreateReservation")
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *gRPCClient) ListReservations(ctx context.Context, req *reservationpb.ListReservationsRequest, opts ...gax.CallOption) *ReservationIterator {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
opts = append((*c.CallOptions).ListReservations[0:len((*c.CallOptions).ListReservations):len((*c.CallOptions).ListReservations)], opts...)
it := &ReservationIterator{}
req = proto.Clone(req).(*reservationpb.ListReservationsRequest)
it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.Reservation, string, error) {
resp := &reservationpb.ListReservationsResponse{}
if pageToken != "" {
req.PageToken = pageToken
}
if pageSize > math.MaxInt32 {
req.PageSize = math.MaxInt32
} else if pageSize != 0 {
req.PageSize = int32(pageSize)
}
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = executeRPC(ctx, c.client.ListReservations, req, settings.GRPC, c.logger, "ListReservations")
return err
}, opts...)
if err != nil {
return nil, "", err
}
it.Response = resp
return resp.GetReservations(), resp.GetNextPageToken(), nil
}
fetch := func(pageSize int, pageToken string) (string, error) {
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
if err != nil {
return "", err
}
it.items = append(it.items, items...)
return nextPageToken, nil
}
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
it.pageInfo.MaxSize = int(req.GetPageSize())
it.pageInfo.Token = req.GetPageToken()
return it
}