1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package migration
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "io"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 migrationpb "cloud.google.com/go/bigquery/migration/apiv2alpha/migrationpb"
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 CreateMigrationWorkflow []gax.CallOption
48 GetMigrationWorkflow []gax.CallOption
49 ListMigrationWorkflows []gax.CallOption
50 DeleteMigrationWorkflow []gax.CallOption
51 StartMigrationWorkflow []gax.CallOption
52 GetMigrationSubtask []gax.CallOption
53 ListMigrationSubtasks []gax.CallOption
54 }
55
56 func defaultGRPCClientOptions() []option.ClientOption {
57 return []option.ClientOption{
58 internaloption.WithDefaultEndpoint("bigquerymigration.googleapis.com:443"),
59 internaloption.WithDefaultEndpointTemplate("bigquerymigration.UNIVERSE_DOMAIN:443"),
60 internaloption.WithDefaultMTLSEndpoint("bigquerymigration.mtls.googleapis.com:443"),
61 internaloption.WithDefaultUniverseDomain("googleapis.com"),
62 internaloption.WithDefaultAudience("https://bigquerymigration.googleapis.com/"),
63 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
64 internaloption.EnableJwtWithScope(),
65 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
66 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
67 }
68 }
69
70 func defaultCallOptions() *CallOptions {
71 return &CallOptions{
72 CreateMigrationWorkflow: []gax.CallOption{
73 gax.WithTimeout(60000 * time.Millisecond),
74 },
75 GetMigrationWorkflow: []gax.CallOption{
76 gax.WithTimeout(120000 * time.Millisecond),
77 gax.WithRetry(func() gax.Retryer {
78 return gax.OnCodes([]codes.Code{
79 codes.Unavailable,
80 }, gax.Backoff{
81 Initial: 1000 * time.Millisecond,
82 Max: 10000 * time.Millisecond,
83 Multiplier: 1.30,
84 })
85 }),
86 },
87 ListMigrationWorkflows: []gax.CallOption{
88 gax.WithTimeout(120000 * time.Millisecond),
89 gax.WithRetry(func() gax.Retryer {
90 return gax.OnCodes([]codes.Code{
91 codes.Unavailable,
92 }, gax.Backoff{
93 Initial: 1000 * time.Millisecond,
94 Max: 10000 * time.Millisecond,
95 Multiplier: 1.30,
96 })
97 }),
98 },
99 DeleteMigrationWorkflow: []gax.CallOption{
100 gax.WithTimeout(60000 * time.Millisecond),
101 },
102 StartMigrationWorkflow: []gax.CallOption{
103 gax.WithTimeout(120000 * time.Millisecond),
104 gax.WithRetry(func() gax.Retryer {
105 return gax.OnCodes([]codes.Code{
106 codes.Unavailable,
107 }, gax.Backoff{
108 Initial: 1000 * time.Millisecond,
109 Max: 10000 * time.Millisecond,
110 Multiplier: 1.30,
111 })
112 }),
113 },
114 GetMigrationSubtask: []gax.CallOption{
115 gax.WithTimeout(120000 * time.Millisecond),
116 gax.WithRetry(func() gax.Retryer {
117 return gax.OnCodes([]codes.Code{
118 codes.Unavailable,
119 }, gax.Backoff{
120 Initial: 1000 * time.Millisecond,
121 Max: 10000 * time.Millisecond,
122 Multiplier: 1.30,
123 })
124 }),
125 },
126 ListMigrationSubtasks: []gax.CallOption{
127 gax.WithTimeout(120000 * time.Millisecond),
128 gax.WithRetry(func() gax.Retryer {
129 return gax.OnCodes([]codes.Code{
130 codes.Unavailable,
131 }, gax.Backoff{
132 Initial: 1000 * time.Millisecond,
133 Max: 10000 * time.Millisecond,
134 Multiplier: 1.30,
135 })
136 }),
137 },
138 }
139 }
140
141 func defaultRESTCallOptions() *CallOptions {
142 return &CallOptions{
143 CreateMigrationWorkflow: []gax.CallOption{
144 gax.WithTimeout(60000 * time.Millisecond),
145 },
146 GetMigrationWorkflow: []gax.CallOption{
147 gax.WithTimeout(120000 * time.Millisecond),
148 gax.WithRetry(func() gax.Retryer {
149 return gax.OnHTTPCodes(gax.Backoff{
150 Initial: 1000 * time.Millisecond,
151 Max: 10000 * time.Millisecond,
152 Multiplier: 1.30,
153 },
154 http.StatusServiceUnavailable)
155 }),
156 },
157 ListMigrationWorkflows: []gax.CallOption{
158 gax.WithTimeout(120000 * time.Millisecond),
159 gax.WithRetry(func() gax.Retryer {
160 return gax.OnHTTPCodes(gax.Backoff{
161 Initial: 1000 * time.Millisecond,
162 Max: 10000 * time.Millisecond,
163 Multiplier: 1.30,
164 },
165 http.StatusServiceUnavailable)
166 }),
167 },
168 DeleteMigrationWorkflow: []gax.CallOption{
169 gax.WithTimeout(60000 * time.Millisecond),
170 },
171 StartMigrationWorkflow: []gax.CallOption{
172 gax.WithTimeout(120000 * time.Millisecond),
173 gax.WithRetry(func() gax.Retryer {
174 return gax.OnHTTPCodes(gax.Backoff{
175 Initial: 1000 * time.Millisecond,
176 Max: 10000 * time.Millisecond,
177 Multiplier: 1.30,
178 },
179 http.StatusServiceUnavailable)
180 }),
181 },
182 GetMigrationSubtask: []gax.CallOption{
183 gax.WithTimeout(120000 * time.Millisecond),
184 gax.WithRetry(func() gax.Retryer {
185 return gax.OnHTTPCodes(gax.Backoff{
186 Initial: 1000 * time.Millisecond,
187 Max: 10000 * time.Millisecond,
188 Multiplier: 1.30,
189 },
190 http.StatusServiceUnavailable)
191 }),
192 },
193 ListMigrationSubtasks: []gax.CallOption{
194 gax.WithTimeout(120000 * time.Millisecond),
195 gax.WithRetry(func() gax.Retryer {
196 return gax.OnHTTPCodes(gax.Backoff{
197 Initial: 1000 * time.Millisecond,
198 Max: 10000 * time.Millisecond,
199 Multiplier: 1.30,
200 },
201 http.StatusServiceUnavailable)
202 }),
203 },
204 }
205 }
206
207
208 type internalClient interface {
209 Close() error
210 setGoogleClientInfo(...string)
211 Connection() *grpc.ClientConn
212 CreateMigrationWorkflow(context.Context, *migrationpb.CreateMigrationWorkflowRequest, ...gax.CallOption) (*migrationpb.MigrationWorkflow, error)
213 GetMigrationWorkflow(context.Context, *migrationpb.GetMigrationWorkflowRequest, ...gax.CallOption) (*migrationpb.MigrationWorkflow, error)
214 ListMigrationWorkflows(context.Context, *migrationpb.ListMigrationWorkflowsRequest, ...gax.CallOption) *MigrationWorkflowIterator
215 DeleteMigrationWorkflow(context.Context, *migrationpb.DeleteMigrationWorkflowRequest, ...gax.CallOption) error
216 StartMigrationWorkflow(context.Context, *migrationpb.StartMigrationWorkflowRequest, ...gax.CallOption) error
217 GetMigrationSubtask(context.Context, *migrationpb.GetMigrationSubtaskRequest, ...gax.CallOption) (*migrationpb.MigrationSubtask, error)
218 ListMigrationSubtasks(context.Context, *migrationpb.ListMigrationSubtasksRequest, ...gax.CallOption) *MigrationSubtaskIterator
219 }
220
221
222
223
224
225 type Client struct {
226
227 internalClient internalClient
228
229
230 CallOptions *CallOptions
231 }
232
233
234
235
236
237 func (c *Client) Close() error {
238 return c.internalClient.Close()
239 }
240
241
242
243
244 func (c *Client) setGoogleClientInfo(keyval ...string) {
245 c.internalClient.setGoogleClientInfo(keyval...)
246 }
247
248
249
250
251
252 func (c *Client) Connection() *grpc.ClientConn {
253 return c.internalClient.Connection()
254 }
255
256
257 func (c *Client) CreateMigrationWorkflow(ctx context.Context, req *migrationpb.CreateMigrationWorkflowRequest, opts ...gax.CallOption) (*migrationpb.MigrationWorkflow, error) {
258 return c.internalClient.CreateMigrationWorkflow(ctx, req, opts...)
259 }
260
261
262 func (c *Client) GetMigrationWorkflow(ctx context.Context, req *migrationpb.GetMigrationWorkflowRequest, opts ...gax.CallOption) (*migrationpb.MigrationWorkflow, error) {
263 return c.internalClient.GetMigrationWorkflow(ctx, req, opts...)
264 }
265
266
267 func (c *Client) ListMigrationWorkflows(ctx context.Context, req *migrationpb.ListMigrationWorkflowsRequest, opts ...gax.CallOption) *MigrationWorkflowIterator {
268 return c.internalClient.ListMigrationWorkflows(ctx, req, opts...)
269 }
270
271
272 func (c *Client) DeleteMigrationWorkflow(ctx context.Context, req *migrationpb.DeleteMigrationWorkflowRequest, opts ...gax.CallOption) error {
273 return c.internalClient.DeleteMigrationWorkflow(ctx, req, opts...)
274 }
275
276
277
278
279
280 func (c *Client) StartMigrationWorkflow(ctx context.Context, req *migrationpb.StartMigrationWorkflowRequest, opts ...gax.CallOption) error {
281 return c.internalClient.StartMigrationWorkflow(ctx, req, opts...)
282 }
283
284
285 func (c *Client) GetMigrationSubtask(ctx context.Context, req *migrationpb.GetMigrationSubtaskRequest, opts ...gax.CallOption) (*migrationpb.MigrationSubtask, error) {
286 return c.internalClient.GetMigrationSubtask(ctx, req, opts...)
287 }
288
289
290 func (c *Client) ListMigrationSubtasks(ctx context.Context, req *migrationpb.ListMigrationSubtasksRequest, opts ...gax.CallOption) *MigrationSubtaskIterator {
291 return c.internalClient.ListMigrationSubtasks(ctx, req, opts...)
292 }
293
294
295
296
297 type gRPCClient struct {
298
299 connPool gtransport.ConnPool
300
301
302 CallOptions **CallOptions
303
304
305 client migrationpb.MigrationServiceClient
306
307
308 xGoogHeaders []string
309 }
310
311
312
313
314
315 func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
316 clientOpts := defaultGRPCClientOptions()
317 if newClientHook != nil {
318 hookOpts, err := newClientHook(ctx, clientHookParams{})
319 if err != nil {
320 return nil, err
321 }
322 clientOpts = append(clientOpts, hookOpts...)
323 }
324
325 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
326 if err != nil {
327 return nil, err
328 }
329 client := Client{CallOptions: defaultCallOptions()}
330
331 c := &gRPCClient{
332 connPool: connPool,
333 client: migrationpb.NewMigrationServiceClient(connPool),
334 CallOptions: &client.CallOptions,
335 }
336 c.setGoogleClientInfo()
337
338 client.internalClient = c
339
340 return &client, nil
341 }
342
343
344
345
346
347 func (c *gRPCClient) Connection() *grpc.ClientConn {
348 return c.connPool.Conn()
349 }
350
351
352
353
354 func (c *gRPCClient) setGoogleClientInfo(keyval ...string) {
355 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
356 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
357 c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
358 }
359
360
361
362 func (c *gRPCClient) Close() error {
363 return c.connPool.Close()
364 }
365
366
367 type restClient struct {
368
369 endpoint string
370
371
372 httpClient *http.Client
373
374
375 xGoogHeaders []string
376
377
378 CallOptions **CallOptions
379 }
380
381
382
383
384 func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
385 clientOpts := append(defaultRESTClientOptions(), opts...)
386 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
387 if err != nil {
388 return nil, err
389 }
390
391 callOpts := defaultRESTCallOptions()
392 c := &restClient{
393 endpoint: endpoint,
394 httpClient: httpClient,
395 CallOptions: &callOpts,
396 }
397 c.setGoogleClientInfo()
398
399 return &Client{internalClient: c, CallOptions: callOpts}, nil
400 }
401
402 func defaultRESTClientOptions() []option.ClientOption {
403 return []option.ClientOption{
404 internaloption.WithDefaultEndpoint("https://bigquerymigration.googleapis.com"),
405 internaloption.WithDefaultEndpointTemplate("https://bigquerymigration.UNIVERSE_DOMAIN"),
406 internaloption.WithDefaultMTLSEndpoint("https://bigquerymigration.mtls.googleapis.com"),
407 internaloption.WithDefaultUniverseDomain("googleapis.com"),
408 internaloption.WithDefaultAudience("https://bigquerymigration.googleapis.com/"),
409 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
410 }
411 }
412
413
414
415
416 func (c *restClient) setGoogleClientInfo(keyval ...string) {
417 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
418 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN")
419 c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
420 }
421
422
423
424 func (c *restClient) Close() error {
425
426 c.httpClient = nil
427 return nil
428 }
429
430
431
432
433 func (c *restClient) Connection() *grpc.ClientConn {
434 return nil
435 }
436 func (c *gRPCClient) CreateMigrationWorkflow(ctx context.Context, req *migrationpb.CreateMigrationWorkflowRequest, opts ...gax.CallOption) (*migrationpb.MigrationWorkflow, error) {
437 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
438
439 hds = append(c.xGoogHeaders, hds...)
440 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
441 opts = append((*c.CallOptions).CreateMigrationWorkflow[0:len((*c.CallOptions).CreateMigrationWorkflow):len((*c.CallOptions).CreateMigrationWorkflow)], opts...)
442 var resp *migrationpb.MigrationWorkflow
443 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
444 var err error
445 resp, err = c.client.CreateMigrationWorkflow(ctx, req, settings.GRPC...)
446 return err
447 }, opts...)
448 if err != nil {
449 return nil, err
450 }
451 return resp, nil
452 }
453
454 func (c *gRPCClient) GetMigrationWorkflow(ctx context.Context, req *migrationpb.GetMigrationWorkflowRequest, opts ...gax.CallOption) (*migrationpb.MigrationWorkflow, error) {
455 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
456
457 hds = append(c.xGoogHeaders, hds...)
458 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
459 opts = append((*c.CallOptions).GetMigrationWorkflow[0:len((*c.CallOptions).GetMigrationWorkflow):len((*c.CallOptions).GetMigrationWorkflow)], opts...)
460 var resp *migrationpb.MigrationWorkflow
461 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
462 var err error
463 resp, err = c.client.GetMigrationWorkflow(ctx, req, settings.GRPC...)
464 return err
465 }, opts...)
466 if err != nil {
467 return nil, err
468 }
469 return resp, nil
470 }
471
472 func (c *gRPCClient) ListMigrationWorkflows(ctx context.Context, req *migrationpb.ListMigrationWorkflowsRequest, opts ...gax.CallOption) *MigrationWorkflowIterator {
473 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
474
475 hds = append(c.xGoogHeaders, hds...)
476 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
477 opts = append((*c.CallOptions).ListMigrationWorkflows[0:len((*c.CallOptions).ListMigrationWorkflows):len((*c.CallOptions).ListMigrationWorkflows)], opts...)
478 it := &MigrationWorkflowIterator{}
479 req = proto.Clone(req).(*migrationpb.ListMigrationWorkflowsRequest)
480 it.InternalFetch = func(pageSize int, pageToken string) ([]*migrationpb.MigrationWorkflow, string, error) {
481 resp := &migrationpb.ListMigrationWorkflowsResponse{}
482 if pageToken != "" {
483 req.PageToken = pageToken
484 }
485 if pageSize > math.MaxInt32 {
486 req.PageSize = math.MaxInt32
487 } else if pageSize != 0 {
488 req.PageSize = int32(pageSize)
489 }
490 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
491 var err error
492 resp, err = c.client.ListMigrationWorkflows(ctx, req, settings.GRPC...)
493 return err
494 }, opts...)
495 if err != nil {
496 return nil, "", err
497 }
498
499 it.Response = resp
500 return resp.GetMigrationWorkflows(), resp.GetNextPageToken(), nil
501 }
502 fetch := func(pageSize int, pageToken string) (string, error) {
503 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
504 if err != nil {
505 return "", err
506 }
507 it.items = append(it.items, items...)
508 return nextPageToken, nil
509 }
510
511 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
512 it.pageInfo.MaxSize = int(req.GetPageSize())
513 it.pageInfo.Token = req.GetPageToken()
514
515 return it
516 }
517
518 func (c *gRPCClient) DeleteMigrationWorkflow(ctx context.Context, req *migrationpb.DeleteMigrationWorkflowRequest, opts ...gax.CallOption) error {
519 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
520
521 hds = append(c.xGoogHeaders, hds...)
522 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
523 opts = append((*c.CallOptions).DeleteMigrationWorkflow[0:len((*c.CallOptions).DeleteMigrationWorkflow):len((*c.CallOptions).DeleteMigrationWorkflow)], opts...)
524 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
525 var err error
526 _, err = c.client.DeleteMigrationWorkflow(ctx, req, settings.GRPC...)
527 return err
528 }, opts...)
529 return err
530 }
531
532 func (c *gRPCClient) StartMigrationWorkflow(ctx context.Context, req *migrationpb.StartMigrationWorkflowRequest, opts ...gax.CallOption) error {
533 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
534
535 hds = append(c.xGoogHeaders, hds...)
536 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
537 opts = append((*c.CallOptions).StartMigrationWorkflow[0:len((*c.CallOptions).StartMigrationWorkflow):len((*c.CallOptions).StartMigrationWorkflow)], opts...)
538 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
539 var err error
540 _, err = c.client.StartMigrationWorkflow(ctx, req, settings.GRPC...)
541 return err
542 }, opts...)
543 return err
544 }
545
546 func (c *gRPCClient) GetMigrationSubtask(ctx context.Context, req *migrationpb.GetMigrationSubtaskRequest, opts ...gax.CallOption) (*migrationpb.MigrationSubtask, error) {
547 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
548
549 hds = append(c.xGoogHeaders, hds...)
550 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
551 opts = append((*c.CallOptions).GetMigrationSubtask[0:len((*c.CallOptions).GetMigrationSubtask):len((*c.CallOptions).GetMigrationSubtask)], opts...)
552 var resp *migrationpb.MigrationSubtask
553 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
554 var err error
555 resp, err = c.client.GetMigrationSubtask(ctx, req, settings.GRPC...)
556 return err
557 }, opts...)
558 if err != nil {
559 return nil, err
560 }
561 return resp, nil
562 }
563
564 func (c *gRPCClient) ListMigrationSubtasks(ctx context.Context, req *migrationpb.ListMigrationSubtasksRequest, opts ...gax.CallOption) *MigrationSubtaskIterator {
565 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
566
567 hds = append(c.xGoogHeaders, hds...)
568 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
569 opts = append((*c.CallOptions).ListMigrationSubtasks[0:len((*c.CallOptions).ListMigrationSubtasks):len((*c.CallOptions).ListMigrationSubtasks)], opts...)
570 it := &MigrationSubtaskIterator{}
571 req = proto.Clone(req).(*migrationpb.ListMigrationSubtasksRequest)
572 it.InternalFetch = func(pageSize int, pageToken string) ([]*migrationpb.MigrationSubtask, string, error) {
573 resp := &migrationpb.ListMigrationSubtasksResponse{}
574 if pageToken != "" {
575 req.PageToken = pageToken
576 }
577 if pageSize > math.MaxInt32 {
578 req.PageSize = math.MaxInt32
579 } else if pageSize != 0 {
580 req.PageSize = int32(pageSize)
581 }
582 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
583 var err error
584 resp, err = c.client.ListMigrationSubtasks(ctx, req, settings.GRPC...)
585 return err
586 }, opts...)
587 if err != nil {
588 return nil, "", err
589 }
590
591 it.Response = resp
592 return resp.GetMigrationSubtasks(), resp.GetNextPageToken(), nil
593 }
594 fetch := func(pageSize int, pageToken string) (string, error) {
595 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
596 if err != nil {
597 return "", err
598 }
599 it.items = append(it.items, items...)
600 return nextPageToken, nil
601 }
602
603 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
604 it.pageInfo.MaxSize = int(req.GetPageSize())
605 it.pageInfo.Token = req.GetPageToken()
606
607 return it
608 }
609
610
611 func (c *restClient) CreateMigrationWorkflow(ctx context.Context, req *migrationpb.CreateMigrationWorkflowRequest, opts ...gax.CallOption) (*migrationpb.MigrationWorkflow, error) {
612 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
613 body := req.GetMigrationWorkflow()
614 jsonReq, err := m.Marshal(body)
615 if err != nil {
616 return nil, err
617 }
618
619 baseUrl, err := url.Parse(c.endpoint)
620 if err != nil {
621 return nil, err
622 }
623 baseUrl.Path += fmt.Sprintf("/v2alpha/%v/workflows", req.GetParent())
624
625
626 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
627
628 hds = append(c.xGoogHeaders, hds...)
629 hds = append(hds, "Content-Type", "application/json")
630 headers := gax.BuildHeaders(ctx, hds...)
631 opts = append((*c.CallOptions).CreateMigrationWorkflow[0:len((*c.CallOptions).CreateMigrationWorkflow):len((*c.CallOptions).CreateMigrationWorkflow)], opts...)
632 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
633 resp := &migrationpb.MigrationWorkflow{}
634 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
635 if settings.Path != "" {
636 baseUrl.Path = settings.Path
637 }
638 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
639 if err != nil {
640 return err
641 }
642 httpReq = httpReq.WithContext(ctx)
643 httpReq.Header = headers
644
645 httpRsp, err := c.httpClient.Do(httpReq)
646 if err != nil {
647 return err
648 }
649 defer httpRsp.Body.Close()
650
651 if err = googleapi.CheckResponse(httpRsp); err != nil {
652 return err
653 }
654
655 buf, err := io.ReadAll(httpRsp.Body)
656 if err != nil {
657 return err
658 }
659
660 if err := unm.Unmarshal(buf, resp); err != nil {
661 return err
662 }
663
664 return nil
665 }, opts...)
666 if e != nil {
667 return nil, e
668 }
669 return resp, nil
670 }
671
672
673 func (c *restClient) GetMigrationWorkflow(ctx context.Context, req *migrationpb.GetMigrationWorkflowRequest, opts ...gax.CallOption) (*migrationpb.MigrationWorkflow, error) {
674 baseUrl, err := url.Parse(c.endpoint)
675 if err != nil {
676 return nil, err
677 }
678 baseUrl.Path += fmt.Sprintf("/v2alpha/%v", req.GetName())
679
680 params := url.Values{}
681 if req.GetReadMask() != nil {
682 readMask, err := protojson.Marshal(req.GetReadMask())
683 if err != nil {
684 return nil, err
685 }
686 params.Add("readMask", string(readMask[1:len(readMask)-1]))
687 }
688
689 baseUrl.RawQuery = params.Encode()
690
691
692 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
693
694 hds = append(c.xGoogHeaders, hds...)
695 hds = append(hds, "Content-Type", "application/json")
696 headers := gax.BuildHeaders(ctx, hds...)
697 opts = append((*c.CallOptions).GetMigrationWorkflow[0:len((*c.CallOptions).GetMigrationWorkflow):len((*c.CallOptions).GetMigrationWorkflow)], opts...)
698 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
699 resp := &migrationpb.MigrationWorkflow{}
700 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
701 if settings.Path != "" {
702 baseUrl.Path = settings.Path
703 }
704 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
705 if err != nil {
706 return err
707 }
708 httpReq = httpReq.WithContext(ctx)
709 httpReq.Header = headers
710
711 httpRsp, err := c.httpClient.Do(httpReq)
712 if err != nil {
713 return err
714 }
715 defer httpRsp.Body.Close()
716
717 if err = googleapi.CheckResponse(httpRsp); err != nil {
718 return err
719 }
720
721 buf, err := io.ReadAll(httpRsp.Body)
722 if err != nil {
723 return err
724 }
725
726 if err := unm.Unmarshal(buf, resp); err != nil {
727 return err
728 }
729
730 return nil
731 }, opts...)
732 if e != nil {
733 return nil, e
734 }
735 return resp, nil
736 }
737
738
739 func (c *restClient) ListMigrationWorkflows(ctx context.Context, req *migrationpb.ListMigrationWorkflowsRequest, opts ...gax.CallOption) *MigrationWorkflowIterator {
740 it := &MigrationWorkflowIterator{}
741 req = proto.Clone(req).(*migrationpb.ListMigrationWorkflowsRequest)
742 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
743 it.InternalFetch = func(pageSize int, pageToken string) ([]*migrationpb.MigrationWorkflow, string, error) {
744 resp := &migrationpb.ListMigrationWorkflowsResponse{}
745 if pageToken != "" {
746 req.PageToken = pageToken
747 }
748 if pageSize > math.MaxInt32 {
749 req.PageSize = math.MaxInt32
750 } else if pageSize != 0 {
751 req.PageSize = int32(pageSize)
752 }
753 baseUrl, err := url.Parse(c.endpoint)
754 if err != nil {
755 return nil, "", err
756 }
757 baseUrl.Path += fmt.Sprintf("/v2alpha/%v/workflows", req.GetParent())
758
759 params := url.Values{}
760 if req.GetPageSize() != 0 {
761 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
762 }
763 if req.GetPageToken() != "" {
764 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
765 }
766 if req.GetReadMask() != nil {
767 readMask, err := protojson.Marshal(req.GetReadMask())
768 if err != nil {
769 return nil, "", err
770 }
771 params.Add("readMask", string(readMask[1:len(readMask)-1]))
772 }
773
774 baseUrl.RawQuery = params.Encode()
775
776
777 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
778 headers := gax.BuildHeaders(ctx, hds...)
779 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
780 if settings.Path != "" {
781 baseUrl.Path = settings.Path
782 }
783 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
784 if err != nil {
785 return err
786 }
787 httpReq.Header = headers
788
789 httpRsp, err := c.httpClient.Do(httpReq)
790 if err != nil {
791 return err
792 }
793 defer httpRsp.Body.Close()
794
795 if err = googleapi.CheckResponse(httpRsp); err != nil {
796 return err
797 }
798
799 buf, err := io.ReadAll(httpRsp.Body)
800 if err != nil {
801 return err
802 }
803
804 if err := unm.Unmarshal(buf, resp); err != nil {
805 return err
806 }
807
808 return nil
809 }, opts...)
810 if e != nil {
811 return nil, "", e
812 }
813 it.Response = resp
814 return resp.GetMigrationWorkflows(), resp.GetNextPageToken(), nil
815 }
816
817 fetch := func(pageSize int, pageToken string) (string, error) {
818 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
819 if err != nil {
820 return "", err
821 }
822 it.items = append(it.items, items...)
823 return nextPageToken, nil
824 }
825
826 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
827 it.pageInfo.MaxSize = int(req.GetPageSize())
828 it.pageInfo.Token = req.GetPageToken()
829
830 return it
831 }
832
833
834 func (c *restClient) DeleteMigrationWorkflow(ctx context.Context, req *migrationpb.DeleteMigrationWorkflowRequest, opts ...gax.CallOption) error {
835 baseUrl, err := url.Parse(c.endpoint)
836 if err != nil {
837 return err
838 }
839 baseUrl.Path += fmt.Sprintf("/v2alpha/%v", req.GetName())
840
841
842 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
843
844 hds = append(c.xGoogHeaders, hds...)
845 hds = append(hds, "Content-Type", "application/json")
846 headers := gax.BuildHeaders(ctx, hds...)
847 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
848 if settings.Path != "" {
849 baseUrl.Path = settings.Path
850 }
851 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
852 if err != nil {
853 return err
854 }
855 httpReq = httpReq.WithContext(ctx)
856 httpReq.Header = headers
857
858 httpRsp, err := c.httpClient.Do(httpReq)
859 if err != nil {
860 return err
861 }
862 defer httpRsp.Body.Close()
863
864
865
866 return googleapi.CheckResponse(httpRsp)
867 }, opts...)
868 }
869
870
871
872
873
874 func (c *restClient) StartMigrationWorkflow(ctx context.Context, req *migrationpb.StartMigrationWorkflowRequest, opts ...gax.CallOption) error {
875 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
876 jsonReq, err := m.Marshal(req)
877 if err != nil {
878 return err
879 }
880
881 baseUrl, err := url.Parse(c.endpoint)
882 if err != nil {
883 return err
884 }
885 baseUrl.Path += fmt.Sprintf("/v2alpha/%v:start", req.GetName())
886
887
888 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
889
890 hds = append(c.xGoogHeaders, hds...)
891 hds = append(hds, "Content-Type", "application/json")
892 headers := gax.BuildHeaders(ctx, hds...)
893 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
894 if settings.Path != "" {
895 baseUrl.Path = settings.Path
896 }
897 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
898 if err != nil {
899 return err
900 }
901 httpReq = httpReq.WithContext(ctx)
902 httpReq.Header = headers
903
904 httpRsp, err := c.httpClient.Do(httpReq)
905 if err != nil {
906 return err
907 }
908 defer httpRsp.Body.Close()
909
910
911
912 return googleapi.CheckResponse(httpRsp)
913 }, opts...)
914 }
915
916
917 func (c *restClient) GetMigrationSubtask(ctx context.Context, req *migrationpb.GetMigrationSubtaskRequest, opts ...gax.CallOption) (*migrationpb.MigrationSubtask, error) {
918 baseUrl, err := url.Parse(c.endpoint)
919 if err != nil {
920 return nil, err
921 }
922 baseUrl.Path += fmt.Sprintf("/v2alpha/%v", req.GetName())
923
924 params := url.Values{}
925 if req.GetReadMask() != nil {
926 readMask, err := protojson.Marshal(req.GetReadMask())
927 if err != nil {
928 return nil, err
929 }
930 params.Add("readMask", string(readMask[1:len(readMask)-1]))
931 }
932
933 baseUrl.RawQuery = params.Encode()
934
935
936 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
937
938 hds = append(c.xGoogHeaders, hds...)
939 hds = append(hds, "Content-Type", "application/json")
940 headers := gax.BuildHeaders(ctx, hds...)
941 opts = append((*c.CallOptions).GetMigrationSubtask[0:len((*c.CallOptions).GetMigrationSubtask):len((*c.CallOptions).GetMigrationSubtask)], opts...)
942 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
943 resp := &migrationpb.MigrationSubtask{}
944 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
945 if settings.Path != "" {
946 baseUrl.Path = settings.Path
947 }
948 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
949 if err != nil {
950 return err
951 }
952 httpReq = httpReq.WithContext(ctx)
953 httpReq.Header = headers
954
955 httpRsp, err := c.httpClient.Do(httpReq)
956 if err != nil {
957 return err
958 }
959 defer httpRsp.Body.Close()
960
961 if err = googleapi.CheckResponse(httpRsp); err != nil {
962 return err
963 }
964
965 buf, err := io.ReadAll(httpRsp.Body)
966 if err != nil {
967 return err
968 }
969
970 if err := unm.Unmarshal(buf, resp); err != nil {
971 return err
972 }
973
974 return nil
975 }, opts...)
976 if e != nil {
977 return nil, e
978 }
979 return resp, nil
980 }
981
982
983 func (c *restClient) ListMigrationSubtasks(ctx context.Context, req *migrationpb.ListMigrationSubtasksRequest, opts ...gax.CallOption) *MigrationSubtaskIterator {
984 it := &MigrationSubtaskIterator{}
985 req = proto.Clone(req).(*migrationpb.ListMigrationSubtasksRequest)
986 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
987 it.InternalFetch = func(pageSize int, pageToken string) ([]*migrationpb.MigrationSubtask, string, error) {
988 resp := &migrationpb.ListMigrationSubtasksResponse{}
989 if pageToken != "" {
990 req.PageToken = pageToken
991 }
992 if pageSize > math.MaxInt32 {
993 req.PageSize = math.MaxInt32
994 } else if pageSize != 0 {
995 req.PageSize = int32(pageSize)
996 }
997 baseUrl, err := url.Parse(c.endpoint)
998 if err != nil {
999 return nil, "", err
1000 }
1001 baseUrl.Path += fmt.Sprintf("/v2alpha/%v/subtasks", req.GetParent())
1002
1003 params := url.Values{}
1004 if req.GetFilter() != "" {
1005 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
1006 }
1007 if req.GetPageSize() != 0 {
1008 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1009 }
1010 if req.GetPageToken() != "" {
1011 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1012 }
1013 if req.GetReadMask() != nil {
1014 readMask, err := protojson.Marshal(req.GetReadMask())
1015 if err != nil {
1016 return nil, "", err
1017 }
1018 params.Add("readMask", string(readMask[1:len(readMask)-1]))
1019 }
1020
1021 baseUrl.RawQuery = params.Encode()
1022
1023
1024 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1025 headers := gax.BuildHeaders(ctx, hds...)
1026 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1027 if settings.Path != "" {
1028 baseUrl.Path = settings.Path
1029 }
1030 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1031 if err != nil {
1032 return err
1033 }
1034 httpReq.Header = headers
1035
1036 httpRsp, err := c.httpClient.Do(httpReq)
1037 if err != nil {
1038 return err
1039 }
1040 defer httpRsp.Body.Close()
1041
1042 if err = googleapi.CheckResponse(httpRsp); err != nil {
1043 return err
1044 }
1045
1046 buf, err := io.ReadAll(httpRsp.Body)
1047 if err != nil {
1048 return err
1049 }
1050
1051 if err := unm.Unmarshal(buf, resp); err != nil {
1052 return err
1053 }
1054
1055 return nil
1056 }, opts...)
1057 if e != nil {
1058 return nil, "", e
1059 }
1060 it.Response = resp
1061 return resp.GetMigrationSubtasks(), resp.GetNextPageToken(), nil
1062 }
1063
1064 fetch := func(pageSize int, pageToken string) (string, error) {
1065 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1066 if err != nil {
1067 return "", err
1068 }
1069 it.items = append(it.items, items...)
1070 return nextPageToken, nil
1071 }
1072
1073 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1074 it.pageInfo.MaxSize = int(req.GetPageSize())
1075 it.pageInfo.Token = req.GetPageToken()
1076
1077 return it
1078 }
1079
View as plain text