1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package reservation
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "io"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 reservationpb "cloud.google.com/go/bigquery/reservation/apiv1/reservationpb"
30 gax "github.com/googleapis/gax-go/v2"
31 "google.golang.org/api/googleapi"
32 "google.golang.org/api/iterator"
33 "google.golang.org/api/option"
34 "google.golang.org/api/option/internaloption"
35 gtransport "google.golang.org/api/transport/grpc"
36 httptransport "google.golang.org/api/transport/http"
37 "google.golang.org/grpc"
38 "google.golang.org/grpc/codes"
39 "google.golang.org/protobuf/encoding/protojson"
40 "google.golang.org/protobuf/proto"
41 )
42
43 var newClientHook clientHook
44
45
46 type CallOptions struct {
47 CreateReservation []gax.CallOption
48 ListReservations []gax.CallOption
49 GetReservation []gax.CallOption
50 DeleteReservation []gax.CallOption
51 UpdateReservation []gax.CallOption
52 CreateCapacityCommitment []gax.CallOption
53 ListCapacityCommitments []gax.CallOption
54 GetCapacityCommitment []gax.CallOption
55 DeleteCapacityCommitment []gax.CallOption
56 UpdateCapacityCommitment []gax.CallOption
57 SplitCapacityCommitment []gax.CallOption
58 MergeCapacityCommitments []gax.CallOption
59 CreateAssignment []gax.CallOption
60 ListAssignments []gax.CallOption
61 DeleteAssignment []gax.CallOption
62 SearchAssignments []gax.CallOption
63 SearchAllAssignments []gax.CallOption
64 MoveAssignment []gax.CallOption
65 UpdateAssignment []gax.CallOption
66 GetBiReservation []gax.CallOption
67 UpdateBiReservation []gax.CallOption
68 }
69
70 func defaultGRPCClientOptions() []option.ClientOption {
71 return []option.ClientOption{
72 internaloption.WithDefaultEndpoint("bigqueryreservation.googleapis.com:443"),
73 internaloption.WithDefaultEndpointTemplate("bigqueryreservation.UNIVERSE_DOMAIN:443"),
74 internaloption.WithDefaultMTLSEndpoint("bigqueryreservation.mtls.googleapis.com:443"),
75 internaloption.WithDefaultUniverseDomain("googleapis.com"),
76 internaloption.WithDefaultAudience("https://bigqueryreservation.googleapis.com/"),
77 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
78 internaloption.EnableJwtWithScope(),
79 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
80 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
81 }
82 }
83
84 func defaultCallOptions() *CallOptions {
85 return &CallOptions{
86 CreateReservation: []gax.CallOption{
87 gax.WithTimeout(300000 * time.Millisecond),
88 },
89 ListReservations: []gax.CallOption{
90 gax.WithTimeout(300000 * time.Millisecond),
91 gax.WithRetry(func() gax.Retryer {
92 return gax.OnCodes([]codes.Code{
93 codes.DeadlineExceeded,
94 codes.Unavailable,
95 }, gax.Backoff{
96 Initial: 100 * time.Millisecond,
97 Max: 60000 * time.Millisecond,
98 Multiplier: 1.30,
99 })
100 }),
101 },
102 GetReservation: []gax.CallOption{
103 gax.WithTimeout(300000 * time.Millisecond),
104 gax.WithRetry(func() gax.Retryer {
105 return gax.OnCodes([]codes.Code{
106 codes.DeadlineExceeded,
107 codes.Unavailable,
108 }, gax.Backoff{
109 Initial: 100 * time.Millisecond,
110 Max: 60000 * time.Millisecond,
111 Multiplier: 1.30,
112 })
113 }),
114 },
115 DeleteReservation: []gax.CallOption{
116 gax.WithTimeout(300000 * time.Millisecond),
117 gax.WithRetry(func() gax.Retryer {
118 return gax.OnCodes([]codes.Code{
119 codes.DeadlineExceeded,
120 codes.Unavailable,
121 }, gax.Backoff{
122 Initial: 100 * time.Millisecond,
123 Max: 60000 * time.Millisecond,
124 Multiplier: 1.30,
125 })
126 }),
127 },
128 UpdateReservation: []gax.CallOption{
129 gax.WithTimeout(300000 * time.Millisecond),
130 },
131 CreateCapacityCommitment: []gax.CallOption{
132 gax.WithTimeout(300000 * time.Millisecond),
133 },
134 ListCapacityCommitments: []gax.CallOption{
135 gax.WithTimeout(300000 * time.Millisecond),
136 gax.WithRetry(func() gax.Retryer {
137 return gax.OnCodes([]codes.Code{
138 codes.DeadlineExceeded,
139 codes.Unavailable,
140 }, gax.Backoff{
141 Initial: 100 * time.Millisecond,
142 Max: 60000 * time.Millisecond,
143 Multiplier: 1.30,
144 })
145 }),
146 },
147 GetCapacityCommitment: []gax.CallOption{
148 gax.WithTimeout(300000 * time.Millisecond),
149 gax.WithRetry(func() gax.Retryer {
150 return gax.OnCodes([]codes.Code{
151 codes.DeadlineExceeded,
152 codes.Unavailable,
153 }, gax.Backoff{
154 Initial: 100 * time.Millisecond,
155 Max: 60000 * time.Millisecond,
156 Multiplier: 1.30,
157 })
158 }),
159 },
160 DeleteCapacityCommitment: []gax.CallOption{
161 gax.WithTimeout(300000 * time.Millisecond),
162 gax.WithRetry(func() gax.Retryer {
163 return gax.OnCodes([]codes.Code{
164 codes.DeadlineExceeded,
165 codes.Unavailable,
166 }, gax.Backoff{
167 Initial: 100 * time.Millisecond,
168 Max: 60000 * time.Millisecond,
169 Multiplier: 1.30,
170 })
171 }),
172 },
173 UpdateCapacityCommitment: []gax.CallOption{
174 gax.WithTimeout(300000 * time.Millisecond),
175 },
176 SplitCapacityCommitment: []gax.CallOption{
177 gax.WithTimeout(300000 * time.Millisecond),
178 },
179 MergeCapacityCommitments: []gax.CallOption{
180 gax.WithTimeout(300000 * time.Millisecond),
181 },
182 CreateAssignment: []gax.CallOption{
183 gax.WithTimeout(300000 * time.Millisecond),
184 },
185 ListAssignments: []gax.CallOption{
186 gax.WithTimeout(300000 * time.Millisecond),
187 gax.WithRetry(func() gax.Retryer {
188 return gax.OnCodes([]codes.Code{
189 codes.DeadlineExceeded,
190 codes.Unavailable,
191 }, gax.Backoff{
192 Initial: 100 * time.Millisecond,
193 Max: 60000 * time.Millisecond,
194 Multiplier: 1.30,
195 })
196 }),
197 },
198 DeleteAssignment: []gax.CallOption{
199 gax.WithTimeout(300000 * time.Millisecond),
200 gax.WithRetry(func() gax.Retryer {
201 return gax.OnCodes([]codes.Code{
202 codes.DeadlineExceeded,
203 codes.Unavailable,
204 }, gax.Backoff{
205 Initial: 100 * time.Millisecond,
206 Max: 60000 * time.Millisecond,
207 Multiplier: 1.30,
208 })
209 }),
210 },
211 SearchAssignments: []gax.CallOption{
212 gax.WithTimeout(300000 * time.Millisecond),
213 gax.WithRetry(func() gax.Retryer {
214 return gax.OnCodes([]codes.Code{
215 codes.DeadlineExceeded,
216 codes.Unavailable,
217 }, gax.Backoff{
218 Initial: 100 * time.Millisecond,
219 Max: 60000 * time.Millisecond,
220 Multiplier: 1.30,
221 })
222 }),
223 },
224 SearchAllAssignments: []gax.CallOption{},
225 MoveAssignment: []gax.CallOption{
226 gax.WithTimeout(300000 * time.Millisecond),
227 },
228 UpdateAssignment: []gax.CallOption{},
229 GetBiReservation: []gax.CallOption{
230 gax.WithTimeout(300000 * time.Millisecond),
231 gax.WithRetry(func() gax.Retryer {
232 return gax.OnCodes([]codes.Code{
233 codes.DeadlineExceeded,
234 codes.Unavailable,
235 }, gax.Backoff{
236 Initial: 100 * time.Millisecond,
237 Max: 60000 * time.Millisecond,
238 Multiplier: 1.30,
239 })
240 }),
241 },
242 UpdateBiReservation: []gax.CallOption{
243 gax.WithTimeout(300000 * time.Millisecond),
244 },
245 }
246 }
247
248 func defaultRESTCallOptions() *CallOptions {
249 return &CallOptions{
250 CreateReservation: []gax.CallOption{
251 gax.WithTimeout(300000 * time.Millisecond),
252 },
253 ListReservations: []gax.CallOption{
254 gax.WithTimeout(300000 * time.Millisecond),
255 gax.WithRetry(func() gax.Retryer {
256 return gax.OnHTTPCodes(gax.Backoff{
257 Initial: 100 * time.Millisecond,
258 Max: 60000 * time.Millisecond,
259 Multiplier: 1.30,
260 },
261 http.StatusGatewayTimeout,
262 http.StatusServiceUnavailable)
263 }),
264 },
265 GetReservation: []gax.CallOption{
266 gax.WithTimeout(300000 * time.Millisecond),
267 gax.WithRetry(func() gax.Retryer {
268 return gax.OnHTTPCodes(gax.Backoff{
269 Initial: 100 * time.Millisecond,
270 Max: 60000 * time.Millisecond,
271 Multiplier: 1.30,
272 },
273 http.StatusGatewayTimeout,
274 http.StatusServiceUnavailable)
275 }),
276 },
277 DeleteReservation: []gax.CallOption{
278 gax.WithTimeout(300000 * time.Millisecond),
279 gax.WithRetry(func() gax.Retryer {
280 return gax.OnHTTPCodes(gax.Backoff{
281 Initial: 100 * time.Millisecond,
282 Max: 60000 * time.Millisecond,
283 Multiplier: 1.30,
284 },
285 http.StatusGatewayTimeout,
286 http.StatusServiceUnavailable)
287 }),
288 },
289 UpdateReservation: []gax.CallOption{
290 gax.WithTimeout(300000 * time.Millisecond),
291 },
292 CreateCapacityCommitment: []gax.CallOption{
293 gax.WithTimeout(300000 * time.Millisecond),
294 },
295 ListCapacityCommitments: []gax.CallOption{
296 gax.WithTimeout(300000 * time.Millisecond),
297 gax.WithRetry(func() gax.Retryer {
298 return gax.OnHTTPCodes(gax.Backoff{
299 Initial: 100 * time.Millisecond,
300 Max: 60000 * time.Millisecond,
301 Multiplier: 1.30,
302 },
303 http.StatusGatewayTimeout,
304 http.StatusServiceUnavailable)
305 }),
306 },
307 GetCapacityCommitment: []gax.CallOption{
308 gax.WithTimeout(300000 * time.Millisecond),
309 gax.WithRetry(func() gax.Retryer {
310 return gax.OnHTTPCodes(gax.Backoff{
311 Initial: 100 * time.Millisecond,
312 Max: 60000 * time.Millisecond,
313 Multiplier: 1.30,
314 },
315 http.StatusGatewayTimeout,
316 http.StatusServiceUnavailable)
317 }),
318 },
319 DeleteCapacityCommitment: []gax.CallOption{
320 gax.WithTimeout(300000 * time.Millisecond),
321 gax.WithRetry(func() gax.Retryer {
322 return gax.OnHTTPCodes(gax.Backoff{
323 Initial: 100 * time.Millisecond,
324 Max: 60000 * time.Millisecond,
325 Multiplier: 1.30,
326 },
327 http.StatusGatewayTimeout,
328 http.StatusServiceUnavailable)
329 }),
330 },
331 UpdateCapacityCommitment: []gax.CallOption{
332 gax.WithTimeout(300000 * time.Millisecond),
333 },
334 SplitCapacityCommitment: []gax.CallOption{
335 gax.WithTimeout(300000 * time.Millisecond),
336 },
337 MergeCapacityCommitments: []gax.CallOption{
338 gax.WithTimeout(300000 * time.Millisecond),
339 },
340 CreateAssignment: []gax.CallOption{
341 gax.WithTimeout(300000 * time.Millisecond),
342 },
343 ListAssignments: []gax.CallOption{
344 gax.WithTimeout(300000 * time.Millisecond),
345 gax.WithRetry(func() gax.Retryer {
346 return gax.OnHTTPCodes(gax.Backoff{
347 Initial: 100 * time.Millisecond,
348 Max: 60000 * time.Millisecond,
349 Multiplier: 1.30,
350 },
351 http.StatusGatewayTimeout,
352 http.StatusServiceUnavailable)
353 }),
354 },
355 DeleteAssignment: []gax.CallOption{
356 gax.WithTimeout(300000 * time.Millisecond),
357 gax.WithRetry(func() gax.Retryer {
358 return gax.OnHTTPCodes(gax.Backoff{
359 Initial: 100 * time.Millisecond,
360 Max: 60000 * time.Millisecond,
361 Multiplier: 1.30,
362 },
363 http.StatusGatewayTimeout,
364 http.StatusServiceUnavailable)
365 }),
366 },
367 SearchAssignments: []gax.CallOption{
368 gax.WithTimeout(300000 * time.Millisecond),
369 gax.WithRetry(func() gax.Retryer {
370 return gax.OnHTTPCodes(gax.Backoff{
371 Initial: 100 * time.Millisecond,
372 Max: 60000 * time.Millisecond,
373 Multiplier: 1.30,
374 },
375 http.StatusGatewayTimeout,
376 http.StatusServiceUnavailable)
377 }),
378 },
379 SearchAllAssignments: []gax.CallOption{},
380 MoveAssignment: []gax.CallOption{
381 gax.WithTimeout(300000 * time.Millisecond),
382 },
383 UpdateAssignment: []gax.CallOption{},
384 GetBiReservation: []gax.CallOption{
385 gax.WithTimeout(300000 * time.Millisecond),
386 gax.WithRetry(func() gax.Retryer {
387 return gax.OnHTTPCodes(gax.Backoff{
388 Initial: 100 * time.Millisecond,
389 Max: 60000 * time.Millisecond,
390 Multiplier: 1.30,
391 },
392 http.StatusGatewayTimeout,
393 http.StatusServiceUnavailable)
394 }),
395 },
396 UpdateBiReservation: []gax.CallOption{
397 gax.WithTimeout(300000 * time.Millisecond),
398 },
399 }
400 }
401
402
403 type internalClient interface {
404 Close() error
405 setGoogleClientInfo(...string)
406 Connection() *grpc.ClientConn
407 CreateReservation(context.Context, *reservationpb.CreateReservationRequest, ...gax.CallOption) (*reservationpb.Reservation, error)
408 ListReservations(context.Context, *reservationpb.ListReservationsRequest, ...gax.CallOption) *ReservationIterator
409 GetReservation(context.Context, *reservationpb.GetReservationRequest, ...gax.CallOption) (*reservationpb.Reservation, error)
410 DeleteReservation(context.Context, *reservationpb.DeleteReservationRequest, ...gax.CallOption) error
411 UpdateReservation(context.Context, *reservationpb.UpdateReservationRequest, ...gax.CallOption) (*reservationpb.Reservation, error)
412 CreateCapacityCommitment(context.Context, *reservationpb.CreateCapacityCommitmentRequest, ...gax.CallOption) (*reservationpb.CapacityCommitment, error)
413 ListCapacityCommitments(context.Context, *reservationpb.ListCapacityCommitmentsRequest, ...gax.CallOption) *CapacityCommitmentIterator
414 GetCapacityCommitment(context.Context, *reservationpb.GetCapacityCommitmentRequest, ...gax.CallOption) (*reservationpb.CapacityCommitment, error)
415 DeleteCapacityCommitment(context.Context, *reservationpb.DeleteCapacityCommitmentRequest, ...gax.CallOption) error
416 UpdateCapacityCommitment(context.Context, *reservationpb.UpdateCapacityCommitmentRequest, ...gax.CallOption) (*reservationpb.CapacityCommitment, error)
417 SplitCapacityCommitment(context.Context, *reservationpb.SplitCapacityCommitmentRequest, ...gax.CallOption) (*reservationpb.SplitCapacityCommitmentResponse, error)
418 MergeCapacityCommitments(context.Context, *reservationpb.MergeCapacityCommitmentsRequest, ...gax.CallOption) (*reservationpb.CapacityCommitment, error)
419 CreateAssignment(context.Context, *reservationpb.CreateAssignmentRequest, ...gax.CallOption) (*reservationpb.Assignment, error)
420 ListAssignments(context.Context, *reservationpb.ListAssignmentsRequest, ...gax.CallOption) *AssignmentIterator
421 DeleteAssignment(context.Context, *reservationpb.DeleteAssignmentRequest, ...gax.CallOption) error
422 SearchAssignments(context.Context, *reservationpb.SearchAssignmentsRequest, ...gax.CallOption) *AssignmentIterator
423 SearchAllAssignments(context.Context, *reservationpb.SearchAllAssignmentsRequest, ...gax.CallOption) *AssignmentIterator
424 MoveAssignment(context.Context, *reservationpb.MoveAssignmentRequest, ...gax.CallOption) (*reservationpb.Assignment, error)
425 UpdateAssignment(context.Context, *reservationpb.UpdateAssignmentRequest, ...gax.CallOption) (*reservationpb.Assignment, error)
426 GetBiReservation(context.Context, *reservationpb.GetBiReservationRequest, ...gax.CallOption) (*reservationpb.BiReservation, error)
427 UpdateBiReservation(context.Context, *reservationpb.UpdateBiReservationRequest, ...gax.CallOption) (*reservationpb.BiReservation, error)
428 }
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448 type Client struct {
449
450 internalClient internalClient
451
452
453 CallOptions *CallOptions
454 }
455
456
457
458
459
460 func (c *Client) Close() error {
461 return c.internalClient.Close()
462 }
463
464
465
466
467 func (c *Client) setGoogleClientInfo(keyval ...string) {
468 c.internalClient.setGoogleClientInfo(keyval...)
469 }
470
471
472
473
474
475 func (c *Client) Connection() *grpc.ClientConn {
476 return c.internalClient.Connection()
477 }
478
479
480 func (c *Client) CreateReservation(ctx context.Context, req *reservationpb.CreateReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) {
481 return c.internalClient.CreateReservation(ctx, req, opts...)
482 }
483
484
485 func (c *Client) ListReservations(ctx context.Context, req *reservationpb.ListReservationsRequest, opts ...gax.CallOption) *ReservationIterator {
486 return c.internalClient.ListReservations(ctx, req, opts...)
487 }
488
489
490 func (c *Client) GetReservation(ctx context.Context, req *reservationpb.GetReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) {
491 return c.internalClient.GetReservation(ctx, req, opts...)
492 }
493
494
495
496
497 func (c *Client) DeleteReservation(ctx context.Context, req *reservationpb.DeleteReservationRequest, opts ...gax.CallOption) error {
498 return c.internalClient.DeleteReservation(ctx, req, opts...)
499 }
500
501
502 func (c *Client) UpdateReservation(ctx context.Context, req *reservationpb.UpdateReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) {
503 return c.internalClient.UpdateReservation(ctx, req, opts...)
504 }
505
506
507 func (c *Client) CreateCapacityCommitment(ctx context.Context, req *reservationpb.CreateCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) {
508 return c.internalClient.CreateCapacityCommitment(ctx, req, opts...)
509 }
510
511
512 func (c *Client) ListCapacityCommitments(ctx context.Context, req *reservationpb.ListCapacityCommitmentsRequest, opts ...gax.CallOption) *CapacityCommitmentIterator {
513 return c.internalClient.ListCapacityCommitments(ctx, req, opts...)
514 }
515
516
517 func (c *Client) GetCapacityCommitment(ctx context.Context, req *reservationpb.GetCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) {
518 return c.internalClient.GetCapacityCommitment(ctx, req, opts...)
519 }
520
521
522
523
524 func (c *Client) DeleteCapacityCommitment(ctx context.Context, req *reservationpb.DeleteCapacityCommitmentRequest, opts ...gax.CallOption) error {
525 return c.internalClient.DeleteCapacityCommitment(ctx, req, opts...)
526 }
527
528
529
530
531
532
533
534
535 func (c *Client) UpdateCapacityCommitment(ctx context.Context, req *reservationpb.UpdateCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) {
536 return c.internalClient.UpdateCapacityCommitment(ctx, req, opts...)
537 }
538
539
540
541
542
543
544
545
546
547 func (c *Client) SplitCapacityCommitment(ctx context.Context, req *reservationpb.SplitCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.SplitCapacityCommitmentResponse, error) {
548 return c.internalClient.SplitCapacityCommitment(ctx, req, opts...)
549 }
550
551
552
553
554
555
556
557
558 func (c *Client) MergeCapacityCommitments(ctx context.Context, req *reservationpb.MergeCapacityCommitmentsRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) {
559 return c.internalClient.MergeCapacityCommitments(ctx, req, opts...)
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 func (c *Client) CreateAssignment(ctx context.Context, req *reservationpb.CreateAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) {
599 return c.internalClient.CreateAssignment(ctx, req, opts...)
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 func (c *Client) ListAssignments(ctx context.Context, req *reservationpb.ListAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator {
626 return c.internalClient.ListAssignments(ctx, req, opts...)
627 }
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646 func (c *Client) DeleteAssignment(ctx context.Context, req *reservationpb.DeleteAssignmentRequest, opts ...gax.CallOption) error {
647 return c.internalClient.DeleteAssignment(ctx, req, opts...)
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 func (c *Client) SearchAssignments(ctx context.Context, req *reservationpb.SearchAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator {
680 return c.internalClient.SearchAssignments(ctx, req, opts...)
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 func (c *Client) SearchAllAssignments(ctx context.Context, req *reservationpb.SearchAllAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator {
708 return c.internalClient.SearchAllAssignments(ctx, req, opts...)
709 }
710
711
712
713
714
715
716 func (c *Client) MoveAssignment(ctx context.Context, req *reservationpb.MoveAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) {
717 return c.internalClient.MoveAssignment(ctx, req, opts...)
718 }
719
720
721
722
723 func (c *Client) UpdateAssignment(ctx context.Context, req *reservationpb.UpdateAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) {
724 return c.internalClient.UpdateAssignment(ctx, req, opts...)
725 }
726
727
728 func (c *Client) GetBiReservation(ctx context.Context, req *reservationpb.GetBiReservationRequest, opts ...gax.CallOption) (*reservationpb.BiReservation, error) {
729 return c.internalClient.GetBiReservation(ctx, req, opts...)
730 }
731
732
733
734
735
736
737
738
739
740 func (c *Client) UpdateBiReservation(ctx context.Context, req *reservationpb.UpdateBiReservationRequest, opts ...gax.CallOption) (*reservationpb.BiReservation, error) {
741 return c.internalClient.UpdateBiReservation(ctx, req, opts...)
742 }
743
744
745
746
747 type gRPCClient struct {
748
749 connPool gtransport.ConnPool
750
751
752 CallOptions **CallOptions
753
754
755 client reservationpb.ReservationServiceClient
756
757
758 xGoogHeaders []string
759 }
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779 func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
780 clientOpts := defaultGRPCClientOptions()
781 if newClientHook != nil {
782 hookOpts, err := newClientHook(ctx, clientHookParams{})
783 if err != nil {
784 return nil, err
785 }
786 clientOpts = append(clientOpts, hookOpts...)
787 }
788
789 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
790 if err != nil {
791 return nil, err
792 }
793 client := Client{CallOptions: defaultCallOptions()}
794
795 c := &gRPCClient{
796 connPool: connPool,
797 client: reservationpb.NewReservationServiceClient(connPool),
798 CallOptions: &client.CallOptions,
799 }
800 c.setGoogleClientInfo()
801
802 client.internalClient = c
803
804 return &client, nil
805 }
806
807
808
809
810
811 func (c *gRPCClient) Connection() *grpc.ClientConn {
812 return c.connPool.Conn()
813 }
814
815
816
817
818 func (c *gRPCClient) setGoogleClientInfo(keyval ...string) {
819 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
820 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
821 c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
822 }
823
824
825
826 func (c *gRPCClient) Close() error {
827 return c.connPool.Close()
828 }
829
830
831 type restClient struct {
832
833 endpoint string
834
835
836 httpClient *http.Client
837
838
839 xGoogHeaders []string
840
841
842 CallOptions **CallOptions
843 }
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862 func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
863 clientOpts := append(defaultRESTClientOptions(), opts...)
864 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
865 if err != nil {
866 return nil, err
867 }
868
869 callOpts := defaultRESTCallOptions()
870 c := &restClient{
871 endpoint: endpoint,
872 httpClient: httpClient,
873 CallOptions: &callOpts,
874 }
875 c.setGoogleClientInfo()
876
877 return &Client{internalClient: c, CallOptions: callOpts}, nil
878 }
879
880 func defaultRESTClientOptions() []option.ClientOption {
881 return []option.ClientOption{
882 internaloption.WithDefaultEndpoint("https://bigqueryreservation.googleapis.com"),
883 internaloption.WithDefaultEndpointTemplate("https://bigqueryreservation.UNIVERSE_DOMAIN"),
884 internaloption.WithDefaultMTLSEndpoint("https://bigqueryreservation.mtls.googleapis.com"),
885 internaloption.WithDefaultUniverseDomain("googleapis.com"),
886 internaloption.WithDefaultAudience("https://bigqueryreservation.googleapis.com/"),
887 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
888 }
889 }
890
891
892
893
894 func (c *restClient) setGoogleClientInfo(keyval ...string) {
895 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
896 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN")
897 c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
898 }
899
900
901
902 func (c *restClient) Close() error {
903
904 c.httpClient = nil
905 return nil
906 }
907
908
909
910
911 func (c *restClient) Connection() *grpc.ClientConn {
912 return nil
913 }
914 func (c *gRPCClient) CreateReservation(ctx context.Context, req *reservationpb.CreateReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) {
915 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
916
917 hds = append(c.xGoogHeaders, hds...)
918 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
919 opts = append((*c.CallOptions).CreateReservation[0:len((*c.CallOptions).CreateReservation):len((*c.CallOptions).CreateReservation)], opts...)
920 var resp *reservationpb.Reservation
921 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
922 var err error
923 resp, err = c.client.CreateReservation(ctx, req, settings.GRPC...)
924 return err
925 }, opts...)
926 if err != nil {
927 return nil, err
928 }
929 return resp, nil
930 }
931
932 func (c *gRPCClient) ListReservations(ctx context.Context, req *reservationpb.ListReservationsRequest, opts ...gax.CallOption) *ReservationIterator {
933 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
934
935 hds = append(c.xGoogHeaders, hds...)
936 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
937 opts = append((*c.CallOptions).ListReservations[0:len((*c.CallOptions).ListReservations):len((*c.CallOptions).ListReservations)], opts...)
938 it := &ReservationIterator{}
939 req = proto.Clone(req).(*reservationpb.ListReservationsRequest)
940 it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.Reservation, string, error) {
941 resp := &reservationpb.ListReservationsResponse{}
942 if pageToken != "" {
943 req.PageToken = pageToken
944 }
945 if pageSize > math.MaxInt32 {
946 req.PageSize = math.MaxInt32
947 } else if pageSize != 0 {
948 req.PageSize = int32(pageSize)
949 }
950 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
951 var err error
952 resp, err = c.client.ListReservations(ctx, req, settings.GRPC...)
953 return err
954 }, opts...)
955 if err != nil {
956 return nil, "", err
957 }
958
959 it.Response = resp
960 return resp.GetReservations(), resp.GetNextPageToken(), nil
961 }
962 fetch := func(pageSize int, pageToken string) (string, error) {
963 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
964 if err != nil {
965 return "", err
966 }
967 it.items = append(it.items, items...)
968 return nextPageToken, nil
969 }
970
971 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
972 it.pageInfo.MaxSize = int(req.GetPageSize())
973 it.pageInfo.Token = req.GetPageToken()
974
975 return it
976 }
977
978 func (c *gRPCClient) GetReservation(ctx context.Context, req *reservationpb.GetReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) {
979 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
980
981 hds = append(c.xGoogHeaders, hds...)
982 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
983 opts = append((*c.CallOptions).GetReservation[0:len((*c.CallOptions).GetReservation):len((*c.CallOptions).GetReservation)], opts...)
984 var resp *reservationpb.Reservation
985 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
986 var err error
987 resp, err = c.client.GetReservation(ctx, req, settings.GRPC...)
988 return err
989 }, opts...)
990 if err != nil {
991 return nil, err
992 }
993 return resp, nil
994 }
995
996 func (c *gRPCClient) DeleteReservation(ctx context.Context, req *reservationpb.DeleteReservationRequest, opts ...gax.CallOption) error {
997 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
998
999 hds = append(c.xGoogHeaders, hds...)
1000 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1001 opts = append((*c.CallOptions).DeleteReservation[0:len((*c.CallOptions).DeleteReservation):len((*c.CallOptions).DeleteReservation)], opts...)
1002 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1003 var err error
1004 _, err = c.client.DeleteReservation(ctx, req, settings.GRPC...)
1005 return err
1006 }, opts...)
1007 return err
1008 }
1009
1010 func (c *gRPCClient) UpdateReservation(ctx context.Context, req *reservationpb.UpdateReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) {
1011 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "reservation.name", url.QueryEscape(req.GetReservation().GetName()))}
1012
1013 hds = append(c.xGoogHeaders, hds...)
1014 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1015 opts = append((*c.CallOptions).UpdateReservation[0:len((*c.CallOptions).UpdateReservation):len((*c.CallOptions).UpdateReservation)], opts...)
1016 var resp *reservationpb.Reservation
1017 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1018 var err error
1019 resp, err = c.client.UpdateReservation(ctx, req, settings.GRPC...)
1020 return err
1021 }, opts...)
1022 if err != nil {
1023 return nil, err
1024 }
1025 return resp, nil
1026 }
1027
1028 func (c *gRPCClient) CreateCapacityCommitment(ctx context.Context, req *reservationpb.CreateCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) {
1029 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1030
1031 hds = append(c.xGoogHeaders, hds...)
1032 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1033 opts = append((*c.CallOptions).CreateCapacityCommitment[0:len((*c.CallOptions).CreateCapacityCommitment):len((*c.CallOptions).CreateCapacityCommitment)], opts...)
1034 var resp *reservationpb.CapacityCommitment
1035 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1036 var err error
1037 resp, err = c.client.CreateCapacityCommitment(ctx, req, settings.GRPC...)
1038 return err
1039 }, opts...)
1040 if err != nil {
1041 return nil, err
1042 }
1043 return resp, nil
1044 }
1045
1046 func (c *gRPCClient) ListCapacityCommitments(ctx context.Context, req *reservationpb.ListCapacityCommitmentsRequest, opts ...gax.CallOption) *CapacityCommitmentIterator {
1047 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1048
1049 hds = append(c.xGoogHeaders, hds...)
1050 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1051 opts = append((*c.CallOptions).ListCapacityCommitments[0:len((*c.CallOptions).ListCapacityCommitments):len((*c.CallOptions).ListCapacityCommitments)], opts...)
1052 it := &CapacityCommitmentIterator{}
1053 req = proto.Clone(req).(*reservationpb.ListCapacityCommitmentsRequest)
1054 it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.CapacityCommitment, string, error) {
1055 resp := &reservationpb.ListCapacityCommitmentsResponse{}
1056 if pageToken != "" {
1057 req.PageToken = pageToken
1058 }
1059 if pageSize > math.MaxInt32 {
1060 req.PageSize = math.MaxInt32
1061 } else if pageSize != 0 {
1062 req.PageSize = int32(pageSize)
1063 }
1064 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1065 var err error
1066 resp, err = c.client.ListCapacityCommitments(ctx, req, settings.GRPC...)
1067 return err
1068 }, opts...)
1069 if err != nil {
1070 return nil, "", err
1071 }
1072
1073 it.Response = resp
1074 return resp.GetCapacityCommitments(), resp.GetNextPageToken(), nil
1075 }
1076 fetch := func(pageSize int, pageToken string) (string, error) {
1077 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1078 if err != nil {
1079 return "", err
1080 }
1081 it.items = append(it.items, items...)
1082 return nextPageToken, nil
1083 }
1084
1085 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1086 it.pageInfo.MaxSize = int(req.GetPageSize())
1087 it.pageInfo.Token = req.GetPageToken()
1088
1089 return it
1090 }
1091
1092 func (c *gRPCClient) GetCapacityCommitment(ctx context.Context, req *reservationpb.GetCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) {
1093 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1094
1095 hds = append(c.xGoogHeaders, hds...)
1096 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1097 opts = append((*c.CallOptions).GetCapacityCommitment[0:len((*c.CallOptions).GetCapacityCommitment):len((*c.CallOptions).GetCapacityCommitment)], opts...)
1098 var resp *reservationpb.CapacityCommitment
1099 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1100 var err error
1101 resp, err = c.client.GetCapacityCommitment(ctx, req, settings.GRPC...)
1102 return err
1103 }, opts...)
1104 if err != nil {
1105 return nil, err
1106 }
1107 return resp, nil
1108 }
1109
1110 func (c *gRPCClient) DeleteCapacityCommitment(ctx context.Context, req *reservationpb.DeleteCapacityCommitmentRequest, opts ...gax.CallOption) error {
1111 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1112
1113 hds = append(c.xGoogHeaders, hds...)
1114 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1115 opts = append((*c.CallOptions).DeleteCapacityCommitment[0:len((*c.CallOptions).DeleteCapacityCommitment):len((*c.CallOptions).DeleteCapacityCommitment)], opts...)
1116 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1117 var err error
1118 _, err = c.client.DeleteCapacityCommitment(ctx, req, settings.GRPC...)
1119 return err
1120 }, opts...)
1121 return err
1122 }
1123
1124 func (c *gRPCClient) UpdateCapacityCommitment(ctx context.Context, req *reservationpb.UpdateCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) {
1125 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "capacity_commitment.name", url.QueryEscape(req.GetCapacityCommitment().GetName()))}
1126
1127 hds = append(c.xGoogHeaders, hds...)
1128 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1129 opts = append((*c.CallOptions).UpdateCapacityCommitment[0:len((*c.CallOptions).UpdateCapacityCommitment):len((*c.CallOptions).UpdateCapacityCommitment)], opts...)
1130 var resp *reservationpb.CapacityCommitment
1131 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1132 var err error
1133 resp, err = c.client.UpdateCapacityCommitment(ctx, req, settings.GRPC...)
1134 return err
1135 }, opts...)
1136 if err != nil {
1137 return nil, err
1138 }
1139 return resp, nil
1140 }
1141
1142 func (c *gRPCClient) SplitCapacityCommitment(ctx context.Context, req *reservationpb.SplitCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.SplitCapacityCommitmentResponse, error) {
1143 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1144
1145 hds = append(c.xGoogHeaders, hds...)
1146 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1147 opts = append((*c.CallOptions).SplitCapacityCommitment[0:len((*c.CallOptions).SplitCapacityCommitment):len((*c.CallOptions).SplitCapacityCommitment)], opts...)
1148 var resp *reservationpb.SplitCapacityCommitmentResponse
1149 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1150 var err error
1151 resp, err = c.client.SplitCapacityCommitment(ctx, req, settings.GRPC...)
1152 return err
1153 }, opts...)
1154 if err != nil {
1155 return nil, err
1156 }
1157 return resp, nil
1158 }
1159
1160 func (c *gRPCClient) MergeCapacityCommitments(ctx context.Context, req *reservationpb.MergeCapacityCommitmentsRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) {
1161 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1162
1163 hds = append(c.xGoogHeaders, hds...)
1164 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1165 opts = append((*c.CallOptions).MergeCapacityCommitments[0:len((*c.CallOptions).MergeCapacityCommitments):len((*c.CallOptions).MergeCapacityCommitments)], opts...)
1166 var resp *reservationpb.CapacityCommitment
1167 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1168 var err error
1169 resp, err = c.client.MergeCapacityCommitments(ctx, req, settings.GRPC...)
1170 return err
1171 }, opts...)
1172 if err != nil {
1173 return nil, err
1174 }
1175 return resp, nil
1176 }
1177
1178 func (c *gRPCClient) CreateAssignment(ctx context.Context, req *reservationpb.CreateAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) {
1179 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1180
1181 hds = append(c.xGoogHeaders, hds...)
1182 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1183 opts = append((*c.CallOptions).CreateAssignment[0:len((*c.CallOptions).CreateAssignment):len((*c.CallOptions).CreateAssignment)], opts...)
1184 var resp *reservationpb.Assignment
1185 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1186 var err error
1187 resp, err = c.client.CreateAssignment(ctx, req, settings.GRPC...)
1188 return err
1189 }, opts...)
1190 if err != nil {
1191 return nil, err
1192 }
1193 return resp, nil
1194 }
1195
1196 func (c *gRPCClient) ListAssignments(ctx context.Context, req *reservationpb.ListAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator {
1197 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1198
1199 hds = append(c.xGoogHeaders, hds...)
1200 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1201 opts = append((*c.CallOptions).ListAssignments[0:len((*c.CallOptions).ListAssignments):len((*c.CallOptions).ListAssignments)], opts...)
1202 it := &AssignmentIterator{}
1203 req = proto.Clone(req).(*reservationpb.ListAssignmentsRequest)
1204 it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.Assignment, string, error) {
1205 resp := &reservationpb.ListAssignmentsResponse{}
1206 if pageToken != "" {
1207 req.PageToken = pageToken
1208 }
1209 if pageSize > math.MaxInt32 {
1210 req.PageSize = math.MaxInt32
1211 } else if pageSize != 0 {
1212 req.PageSize = int32(pageSize)
1213 }
1214 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1215 var err error
1216 resp, err = c.client.ListAssignments(ctx, req, settings.GRPC...)
1217 return err
1218 }, opts...)
1219 if err != nil {
1220 return nil, "", err
1221 }
1222
1223 it.Response = resp
1224 return resp.GetAssignments(), resp.GetNextPageToken(), nil
1225 }
1226 fetch := func(pageSize int, pageToken string) (string, error) {
1227 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1228 if err != nil {
1229 return "", err
1230 }
1231 it.items = append(it.items, items...)
1232 return nextPageToken, nil
1233 }
1234
1235 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1236 it.pageInfo.MaxSize = int(req.GetPageSize())
1237 it.pageInfo.Token = req.GetPageToken()
1238
1239 return it
1240 }
1241
1242 func (c *gRPCClient) DeleteAssignment(ctx context.Context, req *reservationpb.DeleteAssignmentRequest, opts ...gax.CallOption) error {
1243 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1244
1245 hds = append(c.xGoogHeaders, hds...)
1246 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1247 opts = append((*c.CallOptions).DeleteAssignment[0:len((*c.CallOptions).DeleteAssignment):len((*c.CallOptions).DeleteAssignment)], opts...)
1248 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1249 var err error
1250 _, err = c.client.DeleteAssignment(ctx, req, settings.GRPC...)
1251 return err
1252 }, opts...)
1253 return err
1254 }
1255
1256 func (c *gRPCClient) SearchAssignments(ctx context.Context, req *reservationpb.SearchAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator {
1257 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1258
1259 hds = append(c.xGoogHeaders, hds...)
1260 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1261 opts = append((*c.CallOptions).SearchAssignments[0:len((*c.CallOptions).SearchAssignments):len((*c.CallOptions).SearchAssignments)], opts...)
1262 it := &AssignmentIterator{}
1263 req = proto.Clone(req).(*reservationpb.SearchAssignmentsRequest)
1264 it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.Assignment, string, error) {
1265 resp := &reservationpb.SearchAssignmentsResponse{}
1266 if pageToken != "" {
1267 req.PageToken = pageToken
1268 }
1269 if pageSize > math.MaxInt32 {
1270 req.PageSize = math.MaxInt32
1271 } else if pageSize != 0 {
1272 req.PageSize = int32(pageSize)
1273 }
1274 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1275 var err error
1276 resp, err = c.client.SearchAssignments(ctx, req, settings.GRPC...)
1277 return err
1278 }, opts...)
1279 if err != nil {
1280 return nil, "", err
1281 }
1282
1283 it.Response = resp
1284 return resp.GetAssignments(), resp.GetNextPageToken(), nil
1285 }
1286 fetch := func(pageSize int, pageToken string) (string, error) {
1287 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1288 if err != nil {
1289 return "", err
1290 }
1291 it.items = append(it.items, items...)
1292 return nextPageToken, nil
1293 }
1294
1295 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1296 it.pageInfo.MaxSize = int(req.GetPageSize())
1297 it.pageInfo.Token = req.GetPageToken()
1298
1299 return it
1300 }
1301
1302 func (c *gRPCClient) SearchAllAssignments(ctx context.Context, req *reservationpb.SearchAllAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator {
1303 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1304
1305 hds = append(c.xGoogHeaders, hds...)
1306 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1307 opts = append((*c.CallOptions).SearchAllAssignments[0:len((*c.CallOptions).SearchAllAssignments):len((*c.CallOptions).SearchAllAssignments)], opts...)
1308 it := &AssignmentIterator{}
1309 req = proto.Clone(req).(*reservationpb.SearchAllAssignmentsRequest)
1310 it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.Assignment, string, error) {
1311 resp := &reservationpb.SearchAllAssignmentsResponse{}
1312 if pageToken != "" {
1313 req.PageToken = pageToken
1314 }
1315 if pageSize > math.MaxInt32 {
1316 req.PageSize = math.MaxInt32
1317 } else if pageSize != 0 {
1318 req.PageSize = int32(pageSize)
1319 }
1320 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1321 var err error
1322 resp, err = c.client.SearchAllAssignments(ctx, req, settings.GRPC...)
1323 return err
1324 }, opts...)
1325 if err != nil {
1326 return nil, "", err
1327 }
1328
1329 it.Response = resp
1330 return resp.GetAssignments(), resp.GetNextPageToken(), nil
1331 }
1332 fetch := func(pageSize int, pageToken string) (string, error) {
1333 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1334 if err != nil {
1335 return "", err
1336 }
1337 it.items = append(it.items, items...)
1338 return nextPageToken, nil
1339 }
1340
1341 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1342 it.pageInfo.MaxSize = int(req.GetPageSize())
1343 it.pageInfo.Token = req.GetPageToken()
1344
1345 return it
1346 }
1347
1348 func (c *gRPCClient) MoveAssignment(ctx context.Context, req *reservationpb.MoveAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) {
1349 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1350
1351 hds = append(c.xGoogHeaders, hds...)
1352 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1353 opts = append((*c.CallOptions).MoveAssignment[0:len((*c.CallOptions).MoveAssignment):len((*c.CallOptions).MoveAssignment)], opts...)
1354 var resp *reservationpb.Assignment
1355 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1356 var err error
1357 resp, err = c.client.MoveAssignment(ctx, req, settings.GRPC...)
1358 return err
1359 }, opts...)
1360 if err != nil {
1361 return nil, err
1362 }
1363 return resp, nil
1364 }
1365
1366 func (c *gRPCClient) UpdateAssignment(ctx context.Context, req *reservationpb.UpdateAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) {
1367 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "assignment.name", url.QueryEscape(req.GetAssignment().GetName()))}
1368
1369 hds = append(c.xGoogHeaders, hds...)
1370 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1371 opts = append((*c.CallOptions).UpdateAssignment[0:len((*c.CallOptions).UpdateAssignment):len((*c.CallOptions).UpdateAssignment)], opts...)
1372 var resp *reservationpb.Assignment
1373 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1374 var err error
1375 resp, err = c.client.UpdateAssignment(ctx, req, settings.GRPC...)
1376 return err
1377 }, opts...)
1378 if err != nil {
1379 return nil, err
1380 }
1381 return resp, nil
1382 }
1383
1384 func (c *gRPCClient) GetBiReservation(ctx context.Context, req *reservationpb.GetBiReservationRequest, opts ...gax.CallOption) (*reservationpb.BiReservation, error) {
1385 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1386
1387 hds = append(c.xGoogHeaders, hds...)
1388 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1389 opts = append((*c.CallOptions).GetBiReservation[0:len((*c.CallOptions).GetBiReservation):len((*c.CallOptions).GetBiReservation)], opts...)
1390 var resp *reservationpb.BiReservation
1391 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1392 var err error
1393 resp, err = c.client.GetBiReservation(ctx, req, settings.GRPC...)
1394 return err
1395 }, opts...)
1396 if err != nil {
1397 return nil, err
1398 }
1399 return resp, nil
1400 }
1401
1402 func (c *gRPCClient) UpdateBiReservation(ctx context.Context, req *reservationpb.UpdateBiReservationRequest, opts ...gax.CallOption) (*reservationpb.BiReservation, error) {
1403 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "bi_reservation.name", url.QueryEscape(req.GetBiReservation().GetName()))}
1404
1405 hds = append(c.xGoogHeaders, hds...)
1406 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1407 opts = append((*c.CallOptions).UpdateBiReservation[0:len((*c.CallOptions).UpdateBiReservation):len((*c.CallOptions).UpdateBiReservation)], opts...)
1408 var resp *reservationpb.BiReservation
1409 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1410 var err error
1411 resp, err = c.client.UpdateBiReservation(ctx, req, settings.GRPC...)
1412 return err
1413 }, opts...)
1414 if err != nil {
1415 return nil, err
1416 }
1417 return resp, nil
1418 }
1419
1420
1421 func (c *restClient) CreateReservation(ctx context.Context, req *reservationpb.CreateReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) {
1422 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1423 body := req.GetReservation()
1424 jsonReq, err := m.Marshal(body)
1425 if err != nil {
1426 return nil, err
1427 }
1428
1429 baseUrl, err := url.Parse(c.endpoint)
1430 if err != nil {
1431 return nil, err
1432 }
1433 baseUrl.Path += fmt.Sprintf("/v1/%v/reservations", req.GetParent())
1434
1435 params := url.Values{}
1436 params.Add("$alt", "json;enum-encoding=int")
1437 if req.GetReservationId() != "" {
1438 params.Add("reservationId", fmt.Sprintf("%v", req.GetReservationId()))
1439 }
1440
1441 baseUrl.RawQuery = params.Encode()
1442
1443
1444 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1445
1446 hds = append(c.xGoogHeaders, hds...)
1447 hds = append(hds, "Content-Type", "application/json")
1448 headers := gax.BuildHeaders(ctx, hds...)
1449 opts = append((*c.CallOptions).CreateReservation[0:len((*c.CallOptions).CreateReservation):len((*c.CallOptions).CreateReservation)], opts...)
1450 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1451 resp := &reservationpb.Reservation{}
1452 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1453 if settings.Path != "" {
1454 baseUrl.Path = settings.Path
1455 }
1456 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1457 if err != nil {
1458 return err
1459 }
1460 httpReq = httpReq.WithContext(ctx)
1461 httpReq.Header = headers
1462
1463 httpRsp, err := c.httpClient.Do(httpReq)
1464 if err != nil {
1465 return err
1466 }
1467 defer httpRsp.Body.Close()
1468
1469 if err = googleapi.CheckResponse(httpRsp); err != nil {
1470 return err
1471 }
1472
1473 buf, err := io.ReadAll(httpRsp.Body)
1474 if err != nil {
1475 return err
1476 }
1477
1478 if err := unm.Unmarshal(buf, resp); err != nil {
1479 return err
1480 }
1481
1482 return nil
1483 }, opts...)
1484 if e != nil {
1485 return nil, e
1486 }
1487 return resp, nil
1488 }
1489
1490
1491 func (c *restClient) ListReservations(ctx context.Context, req *reservationpb.ListReservationsRequest, opts ...gax.CallOption) *ReservationIterator {
1492 it := &ReservationIterator{}
1493 req = proto.Clone(req).(*reservationpb.ListReservationsRequest)
1494 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1495 it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.Reservation, string, error) {
1496 resp := &reservationpb.ListReservationsResponse{}
1497 if pageToken != "" {
1498 req.PageToken = pageToken
1499 }
1500 if pageSize > math.MaxInt32 {
1501 req.PageSize = math.MaxInt32
1502 } else if pageSize != 0 {
1503 req.PageSize = int32(pageSize)
1504 }
1505 baseUrl, err := url.Parse(c.endpoint)
1506 if err != nil {
1507 return nil, "", err
1508 }
1509 baseUrl.Path += fmt.Sprintf("/v1/%v/reservations", req.GetParent())
1510
1511 params := url.Values{}
1512 params.Add("$alt", "json;enum-encoding=int")
1513 if req.GetPageSize() != 0 {
1514 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1515 }
1516 if req.GetPageToken() != "" {
1517 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1518 }
1519
1520 baseUrl.RawQuery = params.Encode()
1521
1522
1523 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1524 headers := gax.BuildHeaders(ctx, hds...)
1525 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1526 if settings.Path != "" {
1527 baseUrl.Path = settings.Path
1528 }
1529 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1530 if err != nil {
1531 return err
1532 }
1533 httpReq.Header = headers
1534
1535 httpRsp, err := c.httpClient.Do(httpReq)
1536 if err != nil {
1537 return err
1538 }
1539 defer httpRsp.Body.Close()
1540
1541 if err = googleapi.CheckResponse(httpRsp); err != nil {
1542 return err
1543 }
1544
1545 buf, err := io.ReadAll(httpRsp.Body)
1546 if err != nil {
1547 return err
1548 }
1549
1550 if err := unm.Unmarshal(buf, resp); err != nil {
1551 return err
1552 }
1553
1554 return nil
1555 }, opts...)
1556 if e != nil {
1557 return nil, "", e
1558 }
1559 it.Response = resp
1560 return resp.GetReservations(), resp.GetNextPageToken(), nil
1561 }
1562
1563 fetch := func(pageSize int, pageToken string) (string, error) {
1564 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1565 if err != nil {
1566 return "", err
1567 }
1568 it.items = append(it.items, items...)
1569 return nextPageToken, nil
1570 }
1571
1572 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1573 it.pageInfo.MaxSize = int(req.GetPageSize())
1574 it.pageInfo.Token = req.GetPageToken()
1575
1576 return it
1577 }
1578
1579
1580 func (c *restClient) GetReservation(ctx context.Context, req *reservationpb.GetReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) {
1581 baseUrl, err := url.Parse(c.endpoint)
1582 if err != nil {
1583 return nil, err
1584 }
1585 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
1586
1587 params := url.Values{}
1588 params.Add("$alt", "json;enum-encoding=int")
1589
1590 baseUrl.RawQuery = params.Encode()
1591
1592
1593 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1594
1595 hds = append(c.xGoogHeaders, hds...)
1596 hds = append(hds, "Content-Type", "application/json")
1597 headers := gax.BuildHeaders(ctx, hds...)
1598 opts = append((*c.CallOptions).GetReservation[0:len((*c.CallOptions).GetReservation):len((*c.CallOptions).GetReservation)], opts...)
1599 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1600 resp := &reservationpb.Reservation{}
1601 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1602 if settings.Path != "" {
1603 baseUrl.Path = settings.Path
1604 }
1605 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1606 if err != nil {
1607 return err
1608 }
1609 httpReq = httpReq.WithContext(ctx)
1610 httpReq.Header = headers
1611
1612 httpRsp, err := c.httpClient.Do(httpReq)
1613 if err != nil {
1614 return err
1615 }
1616 defer httpRsp.Body.Close()
1617
1618 if err = googleapi.CheckResponse(httpRsp); err != nil {
1619 return err
1620 }
1621
1622 buf, err := io.ReadAll(httpRsp.Body)
1623 if err != nil {
1624 return err
1625 }
1626
1627 if err := unm.Unmarshal(buf, resp); err != nil {
1628 return err
1629 }
1630
1631 return nil
1632 }, opts...)
1633 if e != nil {
1634 return nil, e
1635 }
1636 return resp, nil
1637 }
1638
1639
1640
1641
1642 func (c *restClient) DeleteReservation(ctx context.Context, req *reservationpb.DeleteReservationRequest, opts ...gax.CallOption) error {
1643 baseUrl, err := url.Parse(c.endpoint)
1644 if err != nil {
1645 return err
1646 }
1647 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
1648
1649 params := url.Values{}
1650 params.Add("$alt", "json;enum-encoding=int")
1651
1652 baseUrl.RawQuery = params.Encode()
1653
1654
1655 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1656
1657 hds = append(c.xGoogHeaders, hds...)
1658 hds = append(hds, "Content-Type", "application/json")
1659 headers := gax.BuildHeaders(ctx, hds...)
1660 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1661 if settings.Path != "" {
1662 baseUrl.Path = settings.Path
1663 }
1664 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
1665 if err != nil {
1666 return err
1667 }
1668 httpReq = httpReq.WithContext(ctx)
1669 httpReq.Header = headers
1670
1671 httpRsp, err := c.httpClient.Do(httpReq)
1672 if err != nil {
1673 return err
1674 }
1675 defer httpRsp.Body.Close()
1676
1677
1678
1679 return googleapi.CheckResponse(httpRsp)
1680 }, opts...)
1681 }
1682
1683
1684 func (c *restClient) UpdateReservation(ctx context.Context, req *reservationpb.UpdateReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) {
1685 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1686 body := req.GetReservation()
1687 jsonReq, err := m.Marshal(body)
1688 if err != nil {
1689 return nil, err
1690 }
1691
1692 baseUrl, err := url.Parse(c.endpoint)
1693 if err != nil {
1694 return nil, err
1695 }
1696 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetReservation().GetName())
1697
1698 params := url.Values{}
1699 params.Add("$alt", "json;enum-encoding=int")
1700 if req.GetUpdateMask() != nil {
1701 updateMask, err := protojson.Marshal(req.GetUpdateMask())
1702 if err != nil {
1703 return nil, err
1704 }
1705 params.Add("updateMask", string(updateMask[1:len(updateMask)-1]))
1706 }
1707
1708 baseUrl.RawQuery = params.Encode()
1709
1710
1711 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "reservation.name", url.QueryEscape(req.GetReservation().GetName()))}
1712
1713 hds = append(c.xGoogHeaders, hds...)
1714 hds = append(hds, "Content-Type", "application/json")
1715 headers := gax.BuildHeaders(ctx, hds...)
1716 opts = append((*c.CallOptions).UpdateReservation[0:len((*c.CallOptions).UpdateReservation):len((*c.CallOptions).UpdateReservation)], opts...)
1717 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1718 resp := &reservationpb.Reservation{}
1719 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1720 if settings.Path != "" {
1721 baseUrl.Path = settings.Path
1722 }
1723 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
1724 if err != nil {
1725 return err
1726 }
1727 httpReq = httpReq.WithContext(ctx)
1728 httpReq.Header = headers
1729
1730 httpRsp, err := c.httpClient.Do(httpReq)
1731 if err != nil {
1732 return err
1733 }
1734 defer httpRsp.Body.Close()
1735
1736 if err = googleapi.CheckResponse(httpRsp); err != nil {
1737 return err
1738 }
1739
1740 buf, err := io.ReadAll(httpRsp.Body)
1741 if err != nil {
1742 return err
1743 }
1744
1745 if err := unm.Unmarshal(buf, resp); err != nil {
1746 return err
1747 }
1748
1749 return nil
1750 }, opts...)
1751 if e != nil {
1752 return nil, e
1753 }
1754 return resp, nil
1755 }
1756
1757
1758 func (c *restClient) CreateCapacityCommitment(ctx context.Context, req *reservationpb.CreateCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) {
1759 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1760 body := req.GetCapacityCommitment()
1761 jsonReq, err := m.Marshal(body)
1762 if err != nil {
1763 return nil, err
1764 }
1765
1766 baseUrl, err := url.Parse(c.endpoint)
1767 if err != nil {
1768 return nil, err
1769 }
1770 baseUrl.Path += fmt.Sprintf("/v1/%v/capacityCommitments", req.GetParent())
1771
1772 params := url.Values{}
1773 params.Add("$alt", "json;enum-encoding=int")
1774 if req.GetCapacityCommitmentId() != "" {
1775 params.Add("capacityCommitmentId", fmt.Sprintf("%v", req.GetCapacityCommitmentId()))
1776 }
1777 if req.GetEnforceSingleAdminProjectPerOrg() {
1778 params.Add("enforceSingleAdminProjectPerOrg", fmt.Sprintf("%v", req.GetEnforceSingleAdminProjectPerOrg()))
1779 }
1780
1781 baseUrl.RawQuery = params.Encode()
1782
1783
1784 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1785
1786 hds = append(c.xGoogHeaders, hds...)
1787 hds = append(hds, "Content-Type", "application/json")
1788 headers := gax.BuildHeaders(ctx, hds...)
1789 opts = append((*c.CallOptions).CreateCapacityCommitment[0:len((*c.CallOptions).CreateCapacityCommitment):len((*c.CallOptions).CreateCapacityCommitment)], opts...)
1790 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1791 resp := &reservationpb.CapacityCommitment{}
1792 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1793 if settings.Path != "" {
1794 baseUrl.Path = settings.Path
1795 }
1796 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1797 if err != nil {
1798 return err
1799 }
1800 httpReq = httpReq.WithContext(ctx)
1801 httpReq.Header = headers
1802
1803 httpRsp, err := c.httpClient.Do(httpReq)
1804 if err != nil {
1805 return err
1806 }
1807 defer httpRsp.Body.Close()
1808
1809 if err = googleapi.CheckResponse(httpRsp); err != nil {
1810 return err
1811 }
1812
1813 buf, err := io.ReadAll(httpRsp.Body)
1814 if err != nil {
1815 return err
1816 }
1817
1818 if err := unm.Unmarshal(buf, resp); err != nil {
1819 return err
1820 }
1821
1822 return nil
1823 }, opts...)
1824 if e != nil {
1825 return nil, e
1826 }
1827 return resp, nil
1828 }
1829
1830
1831 func (c *restClient) ListCapacityCommitments(ctx context.Context, req *reservationpb.ListCapacityCommitmentsRequest, opts ...gax.CallOption) *CapacityCommitmentIterator {
1832 it := &CapacityCommitmentIterator{}
1833 req = proto.Clone(req).(*reservationpb.ListCapacityCommitmentsRequest)
1834 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1835 it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.CapacityCommitment, string, error) {
1836 resp := &reservationpb.ListCapacityCommitmentsResponse{}
1837 if pageToken != "" {
1838 req.PageToken = pageToken
1839 }
1840 if pageSize > math.MaxInt32 {
1841 req.PageSize = math.MaxInt32
1842 } else if pageSize != 0 {
1843 req.PageSize = int32(pageSize)
1844 }
1845 baseUrl, err := url.Parse(c.endpoint)
1846 if err != nil {
1847 return nil, "", err
1848 }
1849 baseUrl.Path += fmt.Sprintf("/v1/%v/capacityCommitments", req.GetParent())
1850
1851 params := url.Values{}
1852 params.Add("$alt", "json;enum-encoding=int")
1853 if req.GetPageSize() != 0 {
1854 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1855 }
1856 if req.GetPageToken() != "" {
1857 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1858 }
1859
1860 baseUrl.RawQuery = params.Encode()
1861
1862
1863 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1864 headers := gax.BuildHeaders(ctx, hds...)
1865 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1866 if settings.Path != "" {
1867 baseUrl.Path = settings.Path
1868 }
1869 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1870 if err != nil {
1871 return err
1872 }
1873 httpReq.Header = headers
1874
1875 httpRsp, err := c.httpClient.Do(httpReq)
1876 if err != nil {
1877 return err
1878 }
1879 defer httpRsp.Body.Close()
1880
1881 if err = googleapi.CheckResponse(httpRsp); err != nil {
1882 return err
1883 }
1884
1885 buf, err := io.ReadAll(httpRsp.Body)
1886 if err != nil {
1887 return err
1888 }
1889
1890 if err := unm.Unmarshal(buf, resp); err != nil {
1891 return err
1892 }
1893
1894 return nil
1895 }, opts...)
1896 if e != nil {
1897 return nil, "", e
1898 }
1899 it.Response = resp
1900 return resp.GetCapacityCommitments(), resp.GetNextPageToken(), nil
1901 }
1902
1903 fetch := func(pageSize int, pageToken string) (string, error) {
1904 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1905 if err != nil {
1906 return "", err
1907 }
1908 it.items = append(it.items, items...)
1909 return nextPageToken, nil
1910 }
1911
1912 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1913 it.pageInfo.MaxSize = int(req.GetPageSize())
1914 it.pageInfo.Token = req.GetPageToken()
1915
1916 return it
1917 }
1918
1919
1920 func (c *restClient) GetCapacityCommitment(ctx context.Context, req *reservationpb.GetCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) {
1921 baseUrl, err := url.Parse(c.endpoint)
1922 if err != nil {
1923 return nil, err
1924 }
1925 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
1926
1927 params := url.Values{}
1928 params.Add("$alt", "json;enum-encoding=int")
1929
1930 baseUrl.RawQuery = params.Encode()
1931
1932
1933 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1934
1935 hds = append(c.xGoogHeaders, hds...)
1936 hds = append(hds, "Content-Type", "application/json")
1937 headers := gax.BuildHeaders(ctx, hds...)
1938 opts = append((*c.CallOptions).GetCapacityCommitment[0:len((*c.CallOptions).GetCapacityCommitment):len((*c.CallOptions).GetCapacityCommitment)], opts...)
1939 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1940 resp := &reservationpb.CapacityCommitment{}
1941 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1942 if settings.Path != "" {
1943 baseUrl.Path = settings.Path
1944 }
1945 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1946 if err != nil {
1947 return err
1948 }
1949 httpReq = httpReq.WithContext(ctx)
1950 httpReq.Header = headers
1951
1952 httpRsp, err := c.httpClient.Do(httpReq)
1953 if err != nil {
1954 return err
1955 }
1956 defer httpRsp.Body.Close()
1957
1958 if err = googleapi.CheckResponse(httpRsp); err != nil {
1959 return err
1960 }
1961
1962 buf, err := io.ReadAll(httpRsp.Body)
1963 if err != nil {
1964 return err
1965 }
1966
1967 if err := unm.Unmarshal(buf, resp); err != nil {
1968 return err
1969 }
1970
1971 return nil
1972 }, opts...)
1973 if e != nil {
1974 return nil, e
1975 }
1976 return resp, nil
1977 }
1978
1979
1980
1981
1982 func (c *restClient) DeleteCapacityCommitment(ctx context.Context, req *reservationpb.DeleteCapacityCommitmentRequest, opts ...gax.CallOption) error {
1983 baseUrl, err := url.Parse(c.endpoint)
1984 if err != nil {
1985 return err
1986 }
1987 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
1988
1989 params := url.Values{}
1990 params.Add("$alt", "json;enum-encoding=int")
1991 if req.GetForce() {
1992 params.Add("force", fmt.Sprintf("%v", req.GetForce()))
1993 }
1994
1995 baseUrl.RawQuery = params.Encode()
1996
1997
1998 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1999
2000 hds = append(c.xGoogHeaders, hds...)
2001 hds = append(hds, "Content-Type", "application/json")
2002 headers := gax.BuildHeaders(ctx, hds...)
2003 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2004 if settings.Path != "" {
2005 baseUrl.Path = settings.Path
2006 }
2007 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
2008 if err != nil {
2009 return err
2010 }
2011 httpReq = httpReq.WithContext(ctx)
2012 httpReq.Header = headers
2013
2014 httpRsp, err := c.httpClient.Do(httpReq)
2015 if err != nil {
2016 return err
2017 }
2018 defer httpRsp.Body.Close()
2019
2020
2021
2022 return googleapi.CheckResponse(httpRsp)
2023 }, opts...)
2024 }
2025
2026
2027
2028
2029
2030
2031
2032
2033 func (c *restClient) UpdateCapacityCommitment(ctx context.Context, req *reservationpb.UpdateCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) {
2034 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2035 body := req.GetCapacityCommitment()
2036 jsonReq, err := m.Marshal(body)
2037 if err != nil {
2038 return nil, err
2039 }
2040
2041 baseUrl, err := url.Parse(c.endpoint)
2042 if err != nil {
2043 return nil, err
2044 }
2045 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetCapacityCommitment().GetName())
2046
2047 params := url.Values{}
2048 params.Add("$alt", "json;enum-encoding=int")
2049 if req.GetUpdateMask() != nil {
2050 updateMask, err := protojson.Marshal(req.GetUpdateMask())
2051 if err != nil {
2052 return nil, err
2053 }
2054 params.Add("updateMask", string(updateMask[1:len(updateMask)-1]))
2055 }
2056
2057 baseUrl.RawQuery = params.Encode()
2058
2059
2060 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "capacity_commitment.name", url.QueryEscape(req.GetCapacityCommitment().GetName()))}
2061
2062 hds = append(c.xGoogHeaders, hds...)
2063 hds = append(hds, "Content-Type", "application/json")
2064 headers := gax.BuildHeaders(ctx, hds...)
2065 opts = append((*c.CallOptions).UpdateCapacityCommitment[0:len((*c.CallOptions).UpdateCapacityCommitment):len((*c.CallOptions).UpdateCapacityCommitment)], opts...)
2066 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2067 resp := &reservationpb.CapacityCommitment{}
2068 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2069 if settings.Path != "" {
2070 baseUrl.Path = settings.Path
2071 }
2072 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
2073 if err != nil {
2074 return err
2075 }
2076 httpReq = httpReq.WithContext(ctx)
2077 httpReq.Header = headers
2078
2079 httpRsp, err := c.httpClient.Do(httpReq)
2080 if err != nil {
2081 return err
2082 }
2083 defer httpRsp.Body.Close()
2084
2085 if err = googleapi.CheckResponse(httpRsp); err != nil {
2086 return err
2087 }
2088
2089 buf, err := io.ReadAll(httpRsp.Body)
2090 if err != nil {
2091 return err
2092 }
2093
2094 if err := unm.Unmarshal(buf, resp); err != nil {
2095 return err
2096 }
2097
2098 return nil
2099 }, opts...)
2100 if e != nil {
2101 return nil, e
2102 }
2103 return resp, nil
2104 }
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114 func (c *restClient) SplitCapacityCommitment(ctx context.Context, req *reservationpb.SplitCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.SplitCapacityCommitmentResponse, error) {
2115 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2116 jsonReq, err := m.Marshal(req)
2117 if err != nil {
2118 return nil, err
2119 }
2120
2121 baseUrl, err := url.Parse(c.endpoint)
2122 if err != nil {
2123 return nil, err
2124 }
2125 baseUrl.Path += fmt.Sprintf("/v1/%v:split", req.GetName())
2126
2127 params := url.Values{}
2128 params.Add("$alt", "json;enum-encoding=int")
2129
2130 baseUrl.RawQuery = params.Encode()
2131
2132
2133 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2134
2135 hds = append(c.xGoogHeaders, hds...)
2136 hds = append(hds, "Content-Type", "application/json")
2137 headers := gax.BuildHeaders(ctx, hds...)
2138 opts = append((*c.CallOptions).SplitCapacityCommitment[0:len((*c.CallOptions).SplitCapacityCommitment):len((*c.CallOptions).SplitCapacityCommitment)], opts...)
2139 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2140 resp := &reservationpb.SplitCapacityCommitmentResponse{}
2141 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2142 if settings.Path != "" {
2143 baseUrl.Path = settings.Path
2144 }
2145 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2146 if err != nil {
2147 return err
2148 }
2149 httpReq = httpReq.WithContext(ctx)
2150 httpReq.Header = headers
2151
2152 httpRsp, err := c.httpClient.Do(httpReq)
2153 if err != nil {
2154 return err
2155 }
2156 defer httpRsp.Body.Close()
2157
2158 if err = googleapi.CheckResponse(httpRsp); err != nil {
2159 return err
2160 }
2161
2162 buf, err := io.ReadAll(httpRsp.Body)
2163 if err != nil {
2164 return err
2165 }
2166
2167 if err := unm.Unmarshal(buf, resp); err != nil {
2168 return err
2169 }
2170
2171 return nil
2172 }, opts...)
2173 if e != nil {
2174 return nil, e
2175 }
2176 return resp, nil
2177 }
2178
2179
2180
2181
2182
2183
2184
2185
2186 func (c *restClient) MergeCapacityCommitments(ctx context.Context, req *reservationpb.MergeCapacityCommitmentsRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) {
2187 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2188 jsonReq, err := m.Marshal(req)
2189 if err != nil {
2190 return nil, err
2191 }
2192
2193 baseUrl, err := url.Parse(c.endpoint)
2194 if err != nil {
2195 return nil, err
2196 }
2197 baseUrl.Path += fmt.Sprintf("/v1/%v/capacityCommitments:merge", req.GetParent())
2198
2199 params := url.Values{}
2200 params.Add("$alt", "json;enum-encoding=int")
2201
2202 baseUrl.RawQuery = params.Encode()
2203
2204
2205 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
2206
2207 hds = append(c.xGoogHeaders, hds...)
2208 hds = append(hds, "Content-Type", "application/json")
2209 headers := gax.BuildHeaders(ctx, hds...)
2210 opts = append((*c.CallOptions).MergeCapacityCommitments[0:len((*c.CallOptions).MergeCapacityCommitments):len((*c.CallOptions).MergeCapacityCommitments)], opts...)
2211 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2212 resp := &reservationpb.CapacityCommitment{}
2213 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2214 if settings.Path != "" {
2215 baseUrl.Path = settings.Path
2216 }
2217 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2218 if err != nil {
2219 return err
2220 }
2221 httpReq = httpReq.WithContext(ctx)
2222 httpReq.Header = headers
2223
2224 httpRsp, err := c.httpClient.Do(httpReq)
2225 if err != nil {
2226 return err
2227 }
2228 defer httpRsp.Body.Close()
2229
2230 if err = googleapi.CheckResponse(httpRsp); err != nil {
2231 return err
2232 }
2233
2234 buf, err := io.ReadAll(httpRsp.Body)
2235 if err != nil {
2236 return err
2237 }
2238
2239 if err := unm.Unmarshal(buf, resp); err != nil {
2240 return err
2241 }
2242
2243 return nil
2244 }, opts...)
2245 if e != nil {
2246 return nil, e
2247 }
2248 return resp, nil
2249 }
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287 func (c *restClient) CreateAssignment(ctx context.Context, req *reservationpb.CreateAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) {
2288 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2289 body := req.GetAssignment()
2290 jsonReq, err := m.Marshal(body)
2291 if err != nil {
2292 return nil, err
2293 }
2294
2295 baseUrl, err := url.Parse(c.endpoint)
2296 if err != nil {
2297 return nil, err
2298 }
2299 baseUrl.Path += fmt.Sprintf("/v1/%v/assignments", req.GetParent())
2300
2301 params := url.Values{}
2302 params.Add("$alt", "json;enum-encoding=int")
2303 if req.GetAssignmentId() != "" {
2304 params.Add("assignmentId", fmt.Sprintf("%v", req.GetAssignmentId()))
2305 }
2306
2307 baseUrl.RawQuery = params.Encode()
2308
2309
2310 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
2311
2312 hds = append(c.xGoogHeaders, hds...)
2313 hds = append(hds, "Content-Type", "application/json")
2314 headers := gax.BuildHeaders(ctx, hds...)
2315 opts = append((*c.CallOptions).CreateAssignment[0:len((*c.CallOptions).CreateAssignment):len((*c.CallOptions).CreateAssignment)], opts...)
2316 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2317 resp := &reservationpb.Assignment{}
2318 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2319 if settings.Path != "" {
2320 baseUrl.Path = settings.Path
2321 }
2322 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2323 if err != nil {
2324 return err
2325 }
2326 httpReq = httpReq.WithContext(ctx)
2327 httpReq.Header = headers
2328
2329 httpRsp, err := c.httpClient.Do(httpReq)
2330 if err != nil {
2331 return err
2332 }
2333 defer httpRsp.Body.Close()
2334
2335 if err = googleapi.CheckResponse(httpRsp); err != nil {
2336 return err
2337 }
2338
2339 buf, err := io.ReadAll(httpRsp.Body)
2340 if err != nil {
2341 return err
2342 }
2343
2344 if err := unm.Unmarshal(buf, resp); err != nil {
2345 return err
2346 }
2347
2348 return nil
2349 }, opts...)
2350 if e != nil {
2351 return nil, e
2352 }
2353 return resp, nil
2354 }
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379 func (c *restClient) ListAssignments(ctx context.Context, req *reservationpb.ListAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator {
2380 it := &AssignmentIterator{}
2381 req = proto.Clone(req).(*reservationpb.ListAssignmentsRequest)
2382 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2383 it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.Assignment, string, error) {
2384 resp := &reservationpb.ListAssignmentsResponse{}
2385 if pageToken != "" {
2386 req.PageToken = pageToken
2387 }
2388 if pageSize > math.MaxInt32 {
2389 req.PageSize = math.MaxInt32
2390 } else if pageSize != 0 {
2391 req.PageSize = int32(pageSize)
2392 }
2393 baseUrl, err := url.Parse(c.endpoint)
2394 if err != nil {
2395 return nil, "", err
2396 }
2397 baseUrl.Path += fmt.Sprintf("/v1/%v/assignments", req.GetParent())
2398
2399 params := url.Values{}
2400 params.Add("$alt", "json;enum-encoding=int")
2401 if req.GetPageSize() != 0 {
2402 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
2403 }
2404 if req.GetPageToken() != "" {
2405 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
2406 }
2407
2408 baseUrl.RawQuery = params.Encode()
2409
2410
2411 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
2412 headers := gax.BuildHeaders(ctx, hds...)
2413 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2414 if settings.Path != "" {
2415 baseUrl.Path = settings.Path
2416 }
2417 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2418 if err != nil {
2419 return err
2420 }
2421 httpReq.Header = headers
2422
2423 httpRsp, err := c.httpClient.Do(httpReq)
2424 if err != nil {
2425 return err
2426 }
2427 defer httpRsp.Body.Close()
2428
2429 if err = googleapi.CheckResponse(httpRsp); err != nil {
2430 return err
2431 }
2432
2433 buf, err := io.ReadAll(httpRsp.Body)
2434 if err != nil {
2435 return err
2436 }
2437
2438 if err := unm.Unmarshal(buf, resp); err != nil {
2439 return err
2440 }
2441
2442 return nil
2443 }, opts...)
2444 if e != nil {
2445 return nil, "", e
2446 }
2447 it.Response = resp
2448 return resp.GetAssignments(), resp.GetNextPageToken(), nil
2449 }
2450
2451 fetch := func(pageSize int, pageToken string) (string, error) {
2452 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
2453 if err != nil {
2454 return "", err
2455 }
2456 it.items = append(it.items, items...)
2457 return nextPageToken, nil
2458 }
2459
2460 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
2461 it.pageInfo.MaxSize = int(req.GetPageSize())
2462 it.pageInfo.Token = req.GetPageToken()
2463
2464 return it
2465 }
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484 func (c *restClient) DeleteAssignment(ctx context.Context, req *reservationpb.DeleteAssignmentRequest, opts ...gax.CallOption) error {
2485 baseUrl, err := url.Parse(c.endpoint)
2486 if err != nil {
2487 return err
2488 }
2489 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
2490
2491 params := url.Values{}
2492 params.Add("$alt", "json;enum-encoding=int")
2493
2494 baseUrl.RawQuery = params.Encode()
2495
2496
2497 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2498
2499 hds = append(c.xGoogHeaders, hds...)
2500 hds = append(hds, "Content-Type", "application/json")
2501 headers := gax.BuildHeaders(ctx, hds...)
2502 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2503 if settings.Path != "" {
2504 baseUrl.Path = settings.Path
2505 }
2506 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
2507 if err != nil {
2508 return err
2509 }
2510 httpReq = httpReq.WithContext(ctx)
2511 httpReq.Header = headers
2512
2513 httpRsp, err := c.httpClient.Do(httpReq)
2514 if err != nil {
2515 return err
2516 }
2517 defer httpRsp.Body.Close()
2518
2519
2520
2521 return googleapi.CheckResponse(httpRsp)
2522 }, opts...)
2523 }
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554 func (c *restClient) SearchAssignments(ctx context.Context, req *reservationpb.SearchAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator {
2555 it := &AssignmentIterator{}
2556 req = proto.Clone(req).(*reservationpb.SearchAssignmentsRequest)
2557 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2558 it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.Assignment, string, error) {
2559 resp := &reservationpb.SearchAssignmentsResponse{}
2560 if pageToken != "" {
2561 req.PageToken = pageToken
2562 }
2563 if pageSize > math.MaxInt32 {
2564 req.PageSize = math.MaxInt32
2565 } else if pageSize != 0 {
2566 req.PageSize = int32(pageSize)
2567 }
2568 baseUrl, err := url.Parse(c.endpoint)
2569 if err != nil {
2570 return nil, "", err
2571 }
2572 baseUrl.Path += fmt.Sprintf("/v1/%v:searchAssignments", req.GetParent())
2573
2574 params := url.Values{}
2575 params.Add("$alt", "json;enum-encoding=int")
2576 if req.GetPageSize() != 0 {
2577 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
2578 }
2579 if req.GetPageToken() != "" {
2580 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
2581 }
2582 if req.GetQuery() != "" {
2583 params.Add("query", fmt.Sprintf("%v", req.GetQuery()))
2584 }
2585
2586 baseUrl.RawQuery = params.Encode()
2587
2588
2589 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
2590 headers := gax.BuildHeaders(ctx, hds...)
2591 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2592 if settings.Path != "" {
2593 baseUrl.Path = settings.Path
2594 }
2595 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2596 if err != nil {
2597 return err
2598 }
2599 httpReq.Header = headers
2600
2601 httpRsp, err := c.httpClient.Do(httpReq)
2602 if err != nil {
2603 return err
2604 }
2605 defer httpRsp.Body.Close()
2606
2607 if err = googleapi.CheckResponse(httpRsp); err != nil {
2608 return err
2609 }
2610
2611 buf, err := io.ReadAll(httpRsp.Body)
2612 if err != nil {
2613 return err
2614 }
2615
2616 if err := unm.Unmarshal(buf, resp); err != nil {
2617 return err
2618 }
2619
2620 return nil
2621 }, opts...)
2622 if e != nil {
2623 return nil, "", e
2624 }
2625 it.Response = resp
2626 return resp.GetAssignments(), resp.GetNextPageToken(), nil
2627 }
2628
2629 fetch := func(pageSize int, pageToken string) (string, error) {
2630 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
2631 if err != nil {
2632 return "", err
2633 }
2634 it.items = append(it.items, items...)
2635 return nextPageToken, nil
2636 }
2637
2638 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
2639 it.pageInfo.MaxSize = int(req.GetPageSize())
2640 it.pageInfo.Token = req.GetPageToken()
2641
2642 return it
2643 }
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669 func (c *restClient) SearchAllAssignments(ctx context.Context, req *reservationpb.SearchAllAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator {
2670 it := &AssignmentIterator{}
2671 req = proto.Clone(req).(*reservationpb.SearchAllAssignmentsRequest)
2672 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2673 it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.Assignment, string, error) {
2674 resp := &reservationpb.SearchAllAssignmentsResponse{}
2675 if pageToken != "" {
2676 req.PageToken = pageToken
2677 }
2678 if pageSize > math.MaxInt32 {
2679 req.PageSize = math.MaxInt32
2680 } else if pageSize != 0 {
2681 req.PageSize = int32(pageSize)
2682 }
2683 baseUrl, err := url.Parse(c.endpoint)
2684 if err != nil {
2685 return nil, "", err
2686 }
2687 baseUrl.Path += fmt.Sprintf("/v1/%v:searchAllAssignments", req.GetParent())
2688
2689 params := url.Values{}
2690 params.Add("$alt", "json;enum-encoding=int")
2691 if req.GetPageSize() != 0 {
2692 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
2693 }
2694 if req.GetPageToken() != "" {
2695 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
2696 }
2697 if req.GetQuery() != "" {
2698 params.Add("query", fmt.Sprintf("%v", req.GetQuery()))
2699 }
2700
2701 baseUrl.RawQuery = params.Encode()
2702
2703
2704 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
2705 headers := gax.BuildHeaders(ctx, hds...)
2706 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2707 if settings.Path != "" {
2708 baseUrl.Path = settings.Path
2709 }
2710 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2711 if err != nil {
2712 return err
2713 }
2714 httpReq.Header = headers
2715
2716 httpRsp, err := c.httpClient.Do(httpReq)
2717 if err != nil {
2718 return err
2719 }
2720 defer httpRsp.Body.Close()
2721
2722 if err = googleapi.CheckResponse(httpRsp); err != nil {
2723 return err
2724 }
2725
2726 buf, err := io.ReadAll(httpRsp.Body)
2727 if err != nil {
2728 return err
2729 }
2730
2731 if err := unm.Unmarshal(buf, resp); err != nil {
2732 return err
2733 }
2734
2735 return nil
2736 }, opts...)
2737 if e != nil {
2738 return nil, "", e
2739 }
2740 it.Response = resp
2741 return resp.GetAssignments(), resp.GetNextPageToken(), nil
2742 }
2743
2744 fetch := func(pageSize int, pageToken string) (string, error) {
2745 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
2746 if err != nil {
2747 return "", err
2748 }
2749 it.items = append(it.items, items...)
2750 return nextPageToken, nil
2751 }
2752
2753 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
2754 it.pageInfo.MaxSize = int(req.GetPageSize())
2755 it.pageInfo.Token = req.GetPageToken()
2756
2757 return it
2758 }
2759
2760
2761
2762
2763
2764
2765 func (c *restClient) MoveAssignment(ctx context.Context, req *reservationpb.MoveAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) {
2766 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2767 jsonReq, err := m.Marshal(req)
2768 if err != nil {
2769 return nil, err
2770 }
2771
2772 baseUrl, err := url.Parse(c.endpoint)
2773 if err != nil {
2774 return nil, err
2775 }
2776 baseUrl.Path += fmt.Sprintf("/v1/%v:move", req.GetName())
2777
2778 params := url.Values{}
2779 params.Add("$alt", "json;enum-encoding=int")
2780
2781 baseUrl.RawQuery = params.Encode()
2782
2783
2784 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2785
2786 hds = append(c.xGoogHeaders, hds...)
2787 hds = append(hds, "Content-Type", "application/json")
2788 headers := gax.BuildHeaders(ctx, hds...)
2789 opts = append((*c.CallOptions).MoveAssignment[0:len((*c.CallOptions).MoveAssignment):len((*c.CallOptions).MoveAssignment)], opts...)
2790 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2791 resp := &reservationpb.Assignment{}
2792 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2793 if settings.Path != "" {
2794 baseUrl.Path = settings.Path
2795 }
2796 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2797 if err != nil {
2798 return err
2799 }
2800 httpReq = httpReq.WithContext(ctx)
2801 httpReq.Header = headers
2802
2803 httpRsp, err := c.httpClient.Do(httpReq)
2804 if err != nil {
2805 return err
2806 }
2807 defer httpRsp.Body.Close()
2808
2809 if err = googleapi.CheckResponse(httpRsp); err != nil {
2810 return err
2811 }
2812
2813 buf, err := io.ReadAll(httpRsp.Body)
2814 if err != nil {
2815 return err
2816 }
2817
2818 if err := unm.Unmarshal(buf, resp); err != nil {
2819 return err
2820 }
2821
2822 return nil
2823 }, opts...)
2824 if e != nil {
2825 return nil, e
2826 }
2827 return resp, nil
2828 }
2829
2830
2831
2832
2833 func (c *restClient) UpdateAssignment(ctx context.Context, req *reservationpb.UpdateAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) {
2834 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2835 body := req.GetAssignment()
2836 jsonReq, err := m.Marshal(body)
2837 if err != nil {
2838 return nil, err
2839 }
2840
2841 baseUrl, err := url.Parse(c.endpoint)
2842 if err != nil {
2843 return nil, err
2844 }
2845 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetAssignment().GetName())
2846
2847 params := url.Values{}
2848 params.Add("$alt", "json;enum-encoding=int")
2849 if req.GetUpdateMask() != nil {
2850 updateMask, err := protojson.Marshal(req.GetUpdateMask())
2851 if err != nil {
2852 return nil, err
2853 }
2854 params.Add("updateMask", string(updateMask[1:len(updateMask)-1]))
2855 }
2856
2857 baseUrl.RawQuery = params.Encode()
2858
2859
2860 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "assignment.name", url.QueryEscape(req.GetAssignment().GetName()))}
2861
2862 hds = append(c.xGoogHeaders, hds...)
2863 hds = append(hds, "Content-Type", "application/json")
2864 headers := gax.BuildHeaders(ctx, hds...)
2865 opts = append((*c.CallOptions).UpdateAssignment[0:len((*c.CallOptions).UpdateAssignment):len((*c.CallOptions).UpdateAssignment)], opts...)
2866 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2867 resp := &reservationpb.Assignment{}
2868 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2869 if settings.Path != "" {
2870 baseUrl.Path = settings.Path
2871 }
2872 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
2873 if err != nil {
2874 return err
2875 }
2876 httpReq = httpReq.WithContext(ctx)
2877 httpReq.Header = headers
2878
2879 httpRsp, err := c.httpClient.Do(httpReq)
2880 if err != nil {
2881 return err
2882 }
2883 defer httpRsp.Body.Close()
2884
2885 if err = googleapi.CheckResponse(httpRsp); err != nil {
2886 return err
2887 }
2888
2889 buf, err := io.ReadAll(httpRsp.Body)
2890 if err != nil {
2891 return err
2892 }
2893
2894 if err := unm.Unmarshal(buf, resp); err != nil {
2895 return err
2896 }
2897
2898 return nil
2899 }, opts...)
2900 if e != nil {
2901 return nil, e
2902 }
2903 return resp, nil
2904 }
2905
2906
2907 func (c *restClient) GetBiReservation(ctx context.Context, req *reservationpb.GetBiReservationRequest, opts ...gax.CallOption) (*reservationpb.BiReservation, error) {
2908 baseUrl, err := url.Parse(c.endpoint)
2909 if err != nil {
2910 return nil, err
2911 }
2912 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
2913
2914 params := url.Values{}
2915 params.Add("$alt", "json;enum-encoding=int")
2916
2917 baseUrl.RawQuery = params.Encode()
2918
2919
2920 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2921
2922 hds = append(c.xGoogHeaders, hds...)
2923 hds = append(hds, "Content-Type", "application/json")
2924 headers := gax.BuildHeaders(ctx, hds...)
2925 opts = append((*c.CallOptions).GetBiReservation[0:len((*c.CallOptions).GetBiReservation):len((*c.CallOptions).GetBiReservation)], opts...)
2926 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2927 resp := &reservationpb.BiReservation{}
2928 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2929 if settings.Path != "" {
2930 baseUrl.Path = settings.Path
2931 }
2932 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2933 if err != nil {
2934 return err
2935 }
2936 httpReq = httpReq.WithContext(ctx)
2937 httpReq.Header = headers
2938
2939 httpRsp, err := c.httpClient.Do(httpReq)
2940 if err != nil {
2941 return err
2942 }
2943 defer httpRsp.Body.Close()
2944
2945 if err = googleapi.CheckResponse(httpRsp); err != nil {
2946 return err
2947 }
2948
2949 buf, err := io.ReadAll(httpRsp.Body)
2950 if err != nil {
2951 return err
2952 }
2953
2954 if err := unm.Unmarshal(buf, resp); err != nil {
2955 return err
2956 }
2957
2958 return nil
2959 }, opts...)
2960 if e != nil {
2961 return nil, e
2962 }
2963 return resp, nil
2964 }
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974 func (c *restClient) UpdateBiReservation(ctx context.Context, req *reservationpb.UpdateBiReservationRequest, opts ...gax.CallOption) (*reservationpb.BiReservation, error) {
2975 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2976 body := req.GetBiReservation()
2977 jsonReq, err := m.Marshal(body)
2978 if err != nil {
2979 return nil, err
2980 }
2981
2982 baseUrl, err := url.Parse(c.endpoint)
2983 if err != nil {
2984 return nil, err
2985 }
2986 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetBiReservation().GetName())
2987
2988 params := url.Values{}
2989 params.Add("$alt", "json;enum-encoding=int")
2990 if req.GetUpdateMask() != nil {
2991 updateMask, err := protojson.Marshal(req.GetUpdateMask())
2992 if err != nil {
2993 return nil, err
2994 }
2995 params.Add("updateMask", string(updateMask[1:len(updateMask)-1]))
2996 }
2997
2998 baseUrl.RawQuery = params.Encode()
2999
3000
3001 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "bi_reservation.name", url.QueryEscape(req.GetBiReservation().GetName()))}
3002
3003 hds = append(c.xGoogHeaders, hds...)
3004 hds = append(hds, "Content-Type", "application/json")
3005 headers := gax.BuildHeaders(ctx, hds...)
3006 opts = append((*c.CallOptions).UpdateBiReservation[0:len((*c.CallOptions).UpdateBiReservation):len((*c.CallOptions).UpdateBiReservation)], opts...)
3007 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3008 resp := &reservationpb.BiReservation{}
3009 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3010 if settings.Path != "" {
3011 baseUrl.Path = settings.Path
3012 }
3013 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
3014 if err != nil {
3015 return err
3016 }
3017 httpReq = httpReq.WithContext(ctx)
3018 httpReq.Header = headers
3019
3020 httpRsp, err := c.httpClient.Do(httpReq)
3021 if err != nil {
3022 return err
3023 }
3024 defer httpRsp.Body.Close()
3025
3026 if err = googleapi.CheckResponse(httpRsp); err != nil {
3027 return err
3028 }
3029
3030 buf, err := io.ReadAll(httpRsp.Body)
3031 if err != nil {
3032 return err
3033 }
3034
3035 if err := unm.Unmarshal(buf, resp); err != nil {
3036 return err
3037 }
3038
3039 return nil
3040 }, opts...)
3041 if e != nil {
3042 return nil, e
3043 }
3044 return resp, nil
3045 }
3046
View as plain text