1// Copyright 2021 Google LLC 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15// Code generated by protoc-gen-go_gapic. DO NOT EDIT. 16 17package dataproc 18 19import ( 20 "context" 21 "fmt" 22 "math" 23 "net/url" 24 "time" 25 26 "cloud.google.com/go/longrunning" 27 lroauto "cloud.google.com/go/longrunning/autogen" 28 gax "github.com/googleapis/gax-go/v2" 29 "google.golang.org/api/iterator" 30 "google.golang.org/api/option" 31 "google.golang.org/api/option/internaloption" 32 gtransport "google.golang.org/api/transport/grpc" 33 dataprocpb "google.golang.org/genproto/googleapis/cloud/dataproc/v1beta2" 34 longrunningpb "google.golang.org/genproto/googleapis/longrunning" 35 "google.golang.org/grpc" 36 "google.golang.org/grpc/codes" 37 "google.golang.org/grpc/metadata" 38 "google.golang.org/protobuf/proto" 39) 40 41var newWorkflowTemplateClientHook clientHook 42 43// WorkflowTemplateCallOptions contains the retry settings for each method of WorkflowTemplateClient. 44type WorkflowTemplateCallOptions struct { 45 CreateWorkflowTemplate []gax.CallOption 46 GetWorkflowTemplate []gax.CallOption 47 InstantiateWorkflowTemplate []gax.CallOption 48 InstantiateInlineWorkflowTemplate []gax.CallOption 49 UpdateWorkflowTemplate []gax.CallOption 50 ListWorkflowTemplates []gax.CallOption 51 DeleteWorkflowTemplate []gax.CallOption 52} 53 54func defaultWorkflowTemplateGRPCClientOptions() []option.ClientOption { 55 return []option.ClientOption{ 56 internaloption.WithDefaultEndpoint("dataproc.googleapis.com:443"), 57 internaloption.WithDefaultMTLSEndpoint("dataproc.mtls.googleapis.com:443"), 58 internaloption.WithDefaultAudience("https://dataproc.googleapis.com/"), 59 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 60 internaloption.EnableJwtWithScope(), 61 option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), 62 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 63 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 64 } 65} 66 67func defaultWorkflowTemplateCallOptions() *WorkflowTemplateCallOptions { 68 return &WorkflowTemplateCallOptions{ 69 CreateWorkflowTemplate: []gax.CallOption{ 70 gax.WithRetry(func() gax.Retryer { 71 return gax.OnCodes([]codes.Code{ 72 codes.Unavailable, 73 }, gax.Backoff{ 74 Initial: 100 * time.Millisecond, 75 Max: 60000 * time.Millisecond, 76 Multiplier: 1.30, 77 }) 78 }), 79 }, 80 GetWorkflowTemplate: []gax.CallOption{ 81 gax.WithRetry(func() gax.Retryer { 82 return gax.OnCodes([]codes.Code{ 83 codes.DeadlineExceeded, 84 codes.Internal, 85 codes.Unavailable, 86 }, gax.Backoff{ 87 Initial: 100 * time.Millisecond, 88 Max: 60000 * time.Millisecond, 89 Multiplier: 1.30, 90 }) 91 }), 92 }, 93 InstantiateWorkflowTemplate: []gax.CallOption{ 94 gax.WithRetry(func() gax.Retryer { 95 return gax.OnCodes([]codes.Code{ 96 codes.Unavailable, 97 }, gax.Backoff{ 98 Initial: 100 * time.Millisecond, 99 Max: 60000 * time.Millisecond, 100 Multiplier: 1.30, 101 }) 102 }), 103 }, 104 InstantiateInlineWorkflowTemplate: []gax.CallOption{ 105 gax.WithRetry(func() gax.Retryer { 106 return gax.OnCodes([]codes.Code{ 107 codes.Unavailable, 108 }, gax.Backoff{ 109 Initial: 100 * time.Millisecond, 110 Max: 60000 * time.Millisecond, 111 Multiplier: 1.30, 112 }) 113 }), 114 }, 115 UpdateWorkflowTemplate: []gax.CallOption{ 116 gax.WithRetry(func() gax.Retryer { 117 return gax.OnCodes([]codes.Code{ 118 codes.Unavailable, 119 }, gax.Backoff{ 120 Initial: 100 * time.Millisecond, 121 Max: 60000 * time.Millisecond, 122 Multiplier: 1.30, 123 }) 124 }), 125 }, 126 ListWorkflowTemplates: []gax.CallOption{ 127 gax.WithRetry(func() gax.Retryer { 128 return gax.OnCodes([]codes.Code{ 129 codes.DeadlineExceeded, 130 codes.Internal, 131 codes.Unavailable, 132 }, gax.Backoff{ 133 Initial: 100 * time.Millisecond, 134 Max: 60000 * time.Millisecond, 135 Multiplier: 1.30, 136 }) 137 }), 138 }, 139 DeleteWorkflowTemplate: []gax.CallOption{ 140 gax.WithRetry(func() gax.Retryer { 141 return gax.OnCodes([]codes.Code{ 142 codes.Unavailable, 143 }, gax.Backoff{ 144 Initial: 100 * time.Millisecond, 145 Max: 60000 * time.Millisecond, 146 Multiplier: 1.30, 147 }) 148 }), 149 }, 150 } 151} 152 153// internalWorkflowTemplateClient is an interface that defines the methods availaible from Cloud Dataproc API. 154type internalWorkflowTemplateClient interface { 155 Close() error 156 setGoogleClientInfo(...string) 157 Connection() *grpc.ClientConn 158 CreateWorkflowTemplate(context.Context, *dataprocpb.CreateWorkflowTemplateRequest, ...gax.CallOption) (*dataprocpb.WorkflowTemplate, error) 159 GetWorkflowTemplate(context.Context, *dataprocpb.GetWorkflowTemplateRequest, ...gax.CallOption) (*dataprocpb.WorkflowTemplate, error) 160 InstantiateWorkflowTemplate(context.Context, *dataprocpb.InstantiateWorkflowTemplateRequest, ...gax.CallOption) (*InstantiateWorkflowTemplateOperation, error) 161 InstantiateWorkflowTemplateOperation(name string) *InstantiateWorkflowTemplateOperation 162 InstantiateInlineWorkflowTemplate(context.Context, *dataprocpb.InstantiateInlineWorkflowTemplateRequest, ...gax.CallOption) (*InstantiateInlineWorkflowTemplateOperation, error) 163 InstantiateInlineWorkflowTemplateOperation(name string) *InstantiateInlineWorkflowTemplateOperation 164 UpdateWorkflowTemplate(context.Context, *dataprocpb.UpdateWorkflowTemplateRequest, ...gax.CallOption) (*dataprocpb.WorkflowTemplate, error) 165 ListWorkflowTemplates(context.Context, *dataprocpb.ListWorkflowTemplatesRequest, ...gax.CallOption) *WorkflowTemplateIterator 166 DeleteWorkflowTemplate(context.Context, *dataprocpb.DeleteWorkflowTemplateRequest, ...gax.CallOption) error 167} 168 169// WorkflowTemplateClient is a client for interacting with Cloud Dataproc API. 170// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 171// 172// The API interface for managing Workflow Templates in the 173// Dataproc API. 174type WorkflowTemplateClient struct { 175 // The internal transport-dependent client. 176 internalClient internalWorkflowTemplateClient 177 178 // The call options for this service. 179 CallOptions *WorkflowTemplateCallOptions 180 181 // LROClient is used internally to handle long-running operations. 182 // It is exposed so that its CallOptions can be modified if required. 183 // Users should not Close this client. 184 LROClient *lroauto.OperationsClient 185} 186 187// Wrapper methods routed to the internal client. 188 189// Close closes the connection to the API service. The user should invoke this when 190// the client is no longer required. 191func (c *WorkflowTemplateClient) Close() error { 192 return c.internalClient.Close() 193} 194 195// setGoogleClientInfo sets the name and version of the application in 196// the `x-goog-api-client` header passed on each request. Intended for 197// use by Google-written clients. 198func (c *WorkflowTemplateClient) setGoogleClientInfo(keyval ...string) { 199 c.internalClient.setGoogleClientInfo(keyval...) 200} 201 202// Connection returns a connection to the API service. 203// 204// Deprecated. 205func (c *WorkflowTemplateClient) Connection() *grpc.ClientConn { 206 return c.internalClient.Connection() 207} 208 209// CreateWorkflowTemplate creates new workflow template. 210func (c *WorkflowTemplateClient) CreateWorkflowTemplate(ctx context.Context, req *dataprocpb.CreateWorkflowTemplateRequest, opts ...gax.CallOption) (*dataprocpb.WorkflowTemplate, error) { 211 return c.internalClient.CreateWorkflowTemplate(ctx, req, opts...) 212} 213 214// GetWorkflowTemplate retrieves the latest workflow template. 215// 216// Can retrieve previously instantiated template by specifying optional 217// version parameter. 218func (c *WorkflowTemplateClient) GetWorkflowTemplate(ctx context.Context, req *dataprocpb.GetWorkflowTemplateRequest, opts ...gax.CallOption) (*dataprocpb.WorkflowTemplate, error) { 219 return c.internalClient.GetWorkflowTemplate(ctx, req, opts...) 220} 221 222// InstantiateWorkflowTemplate instantiates a template and begins execution. 223// 224// The returned Operation can be used to track execution of 225// workflow by polling 226// operations.get. 227// The Operation will complete when entire workflow is finished. 228// 229// The running workflow can be aborted via 230// operations.cancel. 231// This will cause any inflight jobs to be cancelled and workflow-owned 232// clusters to be deleted. 233// 234// The Operation.metadata will be 235// WorkflowMetadata. 236// Also see Using 237// WorkflowMetadata (at https://cloud.google.com/dataproc/docs/concepts/workflows/debugging#using_workflowmetadata). 238// 239// On successful completion, 240// Operation.response will be 241// Empty. 242func (c *WorkflowTemplateClient) InstantiateWorkflowTemplate(ctx context.Context, req *dataprocpb.InstantiateWorkflowTemplateRequest, opts ...gax.CallOption) (*InstantiateWorkflowTemplateOperation, error) { 243 return c.internalClient.InstantiateWorkflowTemplate(ctx, req, opts...) 244} 245 246// InstantiateWorkflowTemplateOperation returns a new InstantiateWorkflowTemplateOperation from a given name. 247// The name must be that of a previously created InstantiateWorkflowTemplateOperation, possibly from a different process. 248func (c *WorkflowTemplateClient) InstantiateWorkflowTemplateOperation(name string) *InstantiateWorkflowTemplateOperation { 249 return c.internalClient.InstantiateWorkflowTemplateOperation(name) 250} 251 252// InstantiateInlineWorkflowTemplate instantiates a template and begins execution. 253// 254// This method is equivalent to executing the sequence 255// CreateWorkflowTemplate, 256// InstantiateWorkflowTemplate, 257// DeleteWorkflowTemplate. 258// 259// The returned Operation can be used to track execution of 260// workflow by polling 261// operations.get. 262// The Operation will complete when entire workflow is finished. 263// 264// The running workflow can be aborted via 265// operations.cancel. 266// This will cause any inflight jobs to be cancelled and workflow-owned 267// clusters to be deleted. 268// 269// The Operation.metadata will be 270// WorkflowMetadata (at https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#workflowmetadata). 271// Also see Using 272// WorkflowMetadata (at https://cloud.google.com/dataproc/docs/concepts/workflows/debugging#using_workflowmetadata). 273// 274// On successful completion, 275// Operation.response will be 276// Empty. 277func (c *WorkflowTemplateClient) InstantiateInlineWorkflowTemplate(ctx context.Context, req *dataprocpb.InstantiateInlineWorkflowTemplateRequest, opts ...gax.CallOption) (*InstantiateInlineWorkflowTemplateOperation, error) { 278 return c.internalClient.InstantiateInlineWorkflowTemplate(ctx, req, opts...) 279} 280 281// InstantiateInlineWorkflowTemplateOperation returns a new InstantiateInlineWorkflowTemplateOperation from a given name. 282// The name must be that of a previously created InstantiateInlineWorkflowTemplateOperation, possibly from a different process. 283func (c *WorkflowTemplateClient) InstantiateInlineWorkflowTemplateOperation(name string) *InstantiateInlineWorkflowTemplateOperation { 284 return c.internalClient.InstantiateInlineWorkflowTemplateOperation(name) 285} 286 287// UpdateWorkflowTemplate updates (replaces) workflow template. The updated template 288// must contain version that matches the current server version. 289func (c *WorkflowTemplateClient) UpdateWorkflowTemplate(ctx context.Context, req *dataprocpb.UpdateWorkflowTemplateRequest, opts ...gax.CallOption) (*dataprocpb.WorkflowTemplate, error) { 290 return c.internalClient.UpdateWorkflowTemplate(ctx, req, opts...) 291} 292 293// ListWorkflowTemplates lists workflows that match the specified filter in the request. 294func (c *WorkflowTemplateClient) ListWorkflowTemplates(ctx context.Context, req *dataprocpb.ListWorkflowTemplatesRequest, opts ...gax.CallOption) *WorkflowTemplateIterator { 295 return c.internalClient.ListWorkflowTemplates(ctx, req, opts...) 296} 297 298// DeleteWorkflowTemplate deletes a workflow template. It does not cancel in-progress workflows. 299func (c *WorkflowTemplateClient) DeleteWorkflowTemplate(ctx context.Context, req *dataprocpb.DeleteWorkflowTemplateRequest, opts ...gax.CallOption) error { 300 return c.internalClient.DeleteWorkflowTemplate(ctx, req, opts...) 301} 302 303// workflowTemplateGRPCClient is a client for interacting with Cloud Dataproc API over gRPC transport. 304// 305// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 306type workflowTemplateGRPCClient struct { 307 // Connection pool of gRPC connections to the service. 308 connPool gtransport.ConnPool 309 310 // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE 311 disableDeadlines bool 312 313 // Points back to the CallOptions field of the containing WorkflowTemplateClient 314 CallOptions **WorkflowTemplateCallOptions 315 316 // The gRPC API client. 317 workflowTemplateClient dataprocpb.WorkflowTemplateServiceClient 318 319 // LROClient is used internally to handle long-running operations. 320 // It is exposed so that its CallOptions can be modified if required. 321 // Users should not Close this client. 322 LROClient **lroauto.OperationsClient 323 324 // The x-goog-* metadata to be sent with each request. 325 xGoogMetadata metadata.MD 326} 327 328// NewWorkflowTemplateClient creates a new workflow template service client based on gRPC. 329// The returned client must be Closed when it is done being used to clean up its underlying connections. 330// 331// The API interface for managing Workflow Templates in the 332// Dataproc API. 333func NewWorkflowTemplateClient(ctx context.Context, opts ...option.ClientOption) (*WorkflowTemplateClient, error) { 334 clientOpts := defaultWorkflowTemplateGRPCClientOptions() 335 if newWorkflowTemplateClientHook != nil { 336 hookOpts, err := newWorkflowTemplateClientHook(ctx, clientHookParams{}) 337 if err != nil { 338 return nil, err 339 } 340 clientOpts = append(clientOpts, hookOpts...) 341 } 342 343 disableDeadlines, err := checkDisableDeadlines() 344 if err != nil { 345 return nil, err 346 } 347 348 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 349 if err != nil { 350 return nil, err 351 } 352 client := WorkflowTemplateClient{CallOptions: defaultWorkflowTemplateCallOptions()} 353 354 c := &workflowTemplateGRPCClient{ 355 connPool: connPool, 356 disableDeadlines: disableDeadlines, 357 workflowTemplateClient: dataprocpb.NewWorkflowTemplateServiceClient(connPool), 358 CallOptions: &client.CallOptions, 359 } 360 c.setGoogleClientInfo() 361 362 client.internalClient = c 363 364 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) 365 if err != nil { 366 // This error "should not happen", since we are just reusing old connection pool 367 // and never actually need to dial. 368 // If this does happen, we could leak connp. However, we cannot close conn: 369 // If the user invoked the constructor with option.WithGRPCConn, 370 // we would close a connection that's still in use. 371 // TODO: investigate error conditions. 372 return nil, err 373 } 374 c.LROClient = &client.LROClient 375 return &client, nil 376} 377 378// Connection returns a connection to the API service. 379// 380// Deprecated. 381func (c *workflowTemplateGRPCClient) Connection() *grpc.ClientConn { 382 return c.connPool.Conn() 383} 384 385// setGoogleClientInfo sets the name and version of the application in 386// the `x-goog-api-client` header passed on each request. Intended for 387// use by Google-written clients. 388func (c *workflowTemplateGRPCClient) setGoogleClientInfo(keyval ...string) { 389 kv := append([]string{"gl-go", versionGo()}, keyval...) 390 kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) 391 c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) 392} 393 394// Close closes the connection to the API service. The user should invoke this when 395// the client is no longer required. 396func (c *workflowTemplateGRPCClient) Close() error { 397 return c.connPool.Close() 398} 399 400func (c *workflowTemplateGRPCClient) CreateWorkflowTemplate(ctx context.Context, req *dataprocpb.CreateWorkflowTemplateRequest, opts ...gax.CallOption) (*dataprocpb.WorkflowTemplate, error) { 401 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 402 cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond) 403 defer cancel() 404 ctx = cctx 405 } 406 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 407 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 408 opts = append((*c.CallOptions).CreateWorkflowTemplate[0:len((*c.CallOptions).CreateWorkflowTemplate):len((*c.CallOptions).CreateWorkflowTemplate)], opts...) 409 var resp *dataprocpb.WorkflowTemplate 410 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 411 var err error 412 resp, err = c.workflowTemplateClient.CreateWorkflowTemplate(ctx, req, settings.GRPC...) 413 return err 414 }, opts...) 415 if err != nil { 416 return nil, err 417 } 418 return resp, nil 419} 420 421func (c *workflowTemplateGRPCClient) GetWorkflowTemplate(ctx context.Context, req *dataprocpb.GetWorkflowTemplateRequest, opts ...gax.CallOption) (*dataprocpb.WorkflowTemplate, error) { 422 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 423 cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond) 424 defer cancel() 425 ctx = cctx 426 } 427 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 428 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 429 opts = append((*c.CallOptions).GetWorkflowTemplate[0:len((*c.CallOptions).GetWorkflowTemplate):len((*c.CallOptions).GetWorkflowTemplate)], opts...) 430 var resp *dataprocpb.WorkflowTemplate 431 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 432 var err error 433 resp, err = c.workflowTemplateClient.GetWorkflowTemplate(ctx, req, settings.GRPC...) 434 return err 435 }, opts...) 436 if err != nil { 437 return nil, err 438 } 439 return resp, nil 440} 441 442func (c *workflowTemplateGRPCClient) InstantiateWorkflowTemplate(ctx context.Context, req *dataprocpb.InstantiateWorkflowTemplateRequest, opts ...gax.CallOption) (*InstantiateWorkflowTemplateOperation, error) { 443 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 444 cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond) 445 defer cancel() 446 ctx = cctx 447 } 448 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 449 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 450 opts = append((*c.CallOptions).InstantiateWorkflowTemplate[0:len((*c.CallOptions).InstantiateWorkflowTemplate):len((*c.CallOptions).InstantiateWorkflowTemplate)], opts...) 451 var resp *longrunningpb.Operation 452 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 453 var err error 454 resp, err = c.workflowTemplateClient.InstantiateWorkflowTemplate(ctx, req, settings.GRPC...) 455 return err 456 }, opts...) 457 if err != nil { 458 return nil, err 459 } 460 return &InstantiateWorkflowTemplateOperation{ 461 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 462 }, nil 463} 464 465func (c *workflowTemplateGRPCClient) InstantiateInlineWorkflowTemplate(ctx context.Context, req *dataprocpb.InstantiateInlineWorkflowTemplateRequest, opts ...gax.CallOption) (*InstantiateInlineWorkflowTemplateOperation, error) { 466 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 467 cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond) 468 defer cancel() 469 ctx = cctx 470 } 471 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 472 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 473 opts = append((*c.CallOptions).InstantiateInlineWorkflowTemplate[0:len((*c.CallOptions).InstantiateInlineWorkflowTemplate):len((*c.CallOptions).InstantiateInlineWorkflowTemplate)], opts...) 474 var resp *longrunningpb.Operation 475 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 476 var err error 477 resp, err = c.workflowTemplateClient.InstantiateInlineWorkflowTemplate(ctx, req, settings.GRPC...) 478 return err 479 }, opts...) 480 if err != nil { 481 return nil, err 482 } 483 return &InstantiateInlineWorkflowTemplateOperation{ 484 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 485 }, nil 486} 487 488func (c *workflowTemplateGRPCClient) UpdateWorkflowTemplate(ctx context.Context, req *dataprocpb.UpdateWorkflowTemplateRequest, opts ...gax.CallOption) (*dataprocpb.WorkflowTemplate, error) { 489 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 490 cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond) 491 defer cancel() 492 ctx = cctx 493 } 494 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "template.name", url.QueryEscape(req.GetTemplate().GetName()))) 495 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 496 opts = append((*c.CallOptions).UpdateWorkflowTemplate[0:len((*c.CallOptions).UpdateWorkflowTemplate):len((*c.CallOptions).UpdateWorkflowTemplate)], opts...) 497 var resp *dataprocpb.WorkflowTemplate 498 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 499 var err error 500 resp, err = c.workflowTemplateClient.UpdateWorkflowTemplate(ctx, req, settings.GRPC...) 501 return err 502 }, opts...) 503 if err != nil { 504 return nil, err 505 } 506 return resp, nil 507} 508 509func (c *workflowTemplateGRPCClient) ListWorkflowTemplates(ctx context.Context, req *dataprocpb.ListWorkflowTemplatesRequest, opts ...gax.CallOption) *WorkflowTemplateIterator { 510 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 511 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 512 opts = append((*c.CallOptions).ListWorkflowTemplates[0:len((*c.CallOptions).ListWorkflowTemplates):len((*c.CallOptions).ListWorkflowTemplates)], opts...) 513 it := &WorkflowTemplateIterator{} 514 req = proto.Clone(req).(*dataprocpb.ListWorkflowTemplatesRequest) 515 it.InternalFetch = func(pageSize int, pageToken string) ([]*dataprocpb.WorkflowTemplate, string, error) { 516 resp := &dataprocpb.ListWorkflowTemplatesResponse{} 517 if pageToken != "" { 518 req.PageToken = pageToken 519 } 520 if pageSize > math.MaxInt32 { 521 req.PageSize = math.MaxInt32 522 } else if pageSize != 0 { 523 req.PageSize = int32(pageSize) 524 } 525 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 526 var err error 527 resp, err = c.workflowTemplateClient.ListWorkflowTemplates(ctx, req, settings.GRPC...) 528 return err 529 }, opts...) 530 if err != nil { 531 return nil, "", err 532 } 533 534 it.Response = resp 535 return resp.GetTemplates(), resp.GetNextPageToken(), nil 536 } 537 fetch := func(pageSize int, pageToken string) (string, error) { 538 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 539 if err != nil { 540 return "", err 541 } 542 it.items = append(it.items, items...) 543 return nextPageToken, nil 544 } 545 546 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 547 it.pageInfo.MaxSize = int(req.GetPageSize()) 548 it.pageInfo.Token = req.GetPageToken() 549 550 return it 551} 552 553func (c *workflowTemplateGRPCClient) DeleteWorkflowTemplate(ctx context.Context, req *dataprocpb.DeleteWorkflowTemplateRequest, opts ...gax.CallOption) error { 554 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 555 cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond) 556 defer cancel() 557 ctx = cctx 558 } 559 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 560 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 561 opts = append((*c.CallOptions).DeleteWorkflowTemplate[0:len((*c.CallOptions).DeleteWorkflowTemplate):len((*c.CallOptions).DeleteWorkflowTemplate)], opts...) 562 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 563 var err error 564 _, err = c.workflowTemplateClient.DeleteWorkflowTemplate(ctx, req, settings.GRPC...) 565 return err 566 }, opts...) 567 return err 568} 569 570// InstantiateInlineWorkflowTemplateOperation manages a long-running operation from InstantiateInlineWorkflowTemplate. 571type InstantiateInlineWorkflowTemplateOperation struct { 572 lro *longrunning.Operation 573} 574 575// InstantiateInlineWorkflowTemplateOperation returns a new InstantiateInlineWorkflowTemplateOperation from a given name. 576// The name must be that of a previously created InstantiateInlineWorkflowTemplateOperation, possibly from a different process. 577func (c *workflowTemplateGRPCClient) InstantiateInlineWorkflowTemplateOperation(name string) *InstantiateInlineWorkflowTemplateOperation { 578 return &InstantiateInlineWorkflowTemplateOperation{ 579 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 580 } 581} 582 583// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 584// 585// See documentation of Poll for error-handling information. 586func (op *InstantiateInlineWorkflowTemplateOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 587 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 588} 589 590// Poll fetches the latest state of the long-running operation. 591// 592// Poll also fetches the latest metadata, which can be retrieved by Metadata. 593// 594// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 595// the operation has completed with failure, the error is returned and op.Done will return true. 596// If Poll succeeds and the operation has completed successfully, 597// op.Done will return true, and the response of the operation is returned. 598// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 599func (op *InstantiateInlineWorkflowTemplateOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 600 return op.lro.Poll(ctx, nil, opts...) 601} 602 603// Metadata returns metadata associated with the long-running operation. 604// Metadata itself does not contact the server, but Poll does. 605// To get the latest metadata, call this method after a successful call to Poll. 606// If the metadata is not available, the returned metadata and error are both nil. 607func (op *InstantiateInlineWorkflowTemplateOperation) Metadata() (*dataprocpb.WorkflowMetadata, error) { 608 var meta dataprocpb.WorkflowMetadata 609 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 610 return nil, nil 611 } else if err != nil { 612 return nil, err 613 } 614 return &meta, nil 615} 616 617// Done reports whether the long-running operation has completed. 618func (op *InstantiateInlineWorkflowTemplateOperation) Done() bool { 619 return op.lro.Done() 620} 621 622// Name returns the name of the long-running operation. 623// The name is assigned by the server and is unique within the service from which the operation is created. 624func (op *InstantiateInlineWorkflowTemplateOperation) Name() string { 625 return op.lro.Name() 626} 627 628// InstantiateWorkflowTemplateOperation manages a long-running operation from InstantiateWorkflowTemplate. 629type InstantiateWorkflowTemplateOperation struct { 630 lro *longrunning.Operation 631} 632 633// InstantiateWorkflowTemplateOperation returns a new InstantiateWorkflowTemplateOperation from a given name. 634// The name must be that of a previously created InstantiateWorkflowTemplateOperation, possibly from a different process. 635func (c *workflowTemplateGRPCClient) InstantiateWorkflowTemplateOperation(name string) *InstantiateWorkflowTemplateOperation { 636 return &InstantiateWorkflowTemplateOperation{ 637 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 638 } 639} 640 641// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 642// 643// See documentation of Poll for error-handling information. 644func (op *InstantiateWorkflowTemplateOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 645 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 646} 647 648// Poll fetches the latest state of the long-running operation. 649// 650// Poll also fetches the latest metadata, which can be retrieved by Metadata. 651// 652// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 653// the operation has completed with failure, the error is returned and op.Done will return true. 654// If Poll succeeds and the operation has completed successfully, 655// op.Done will return true, and the response of the operation is returned. 656// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 657func (op *InstantiateWorkflowTemplateOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 658 return op.lro.Poll(ctx, nil, opts...) 659} 660 661// Metadata returns metadata associated with the long-running operation. 662// Metadata itself does not contact the server, but Poll does. 663// To get the latest metadata, call this method after a successful call to Poll. 664// If the metadata is not available, the returned metadata and error are both nil. 665func (op *InstantiateWorkflowTemplateOperation) Metadata() (*dataprocpb.WorkflowMetadata, error) { 666 var meta dataprocpb.WorkflowMetadata 667 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 668 return nil, nil 669 } else if err != nil { 670 return nil, err 671 } 672 return &meta, nil 673} 674 675// Done reports whether the long-running operation has completed. 676func (op *InstantiateWorkflowTemplateOperation) Done() bool { 677 return op.lro.Done() 678} 679 680// Name returns the name of the long-running operation. 681// The name is assigned by the server and is unique within the service from which the operation is created. 682func (op *InstantiateWorkflowTemplateOperation) Name() string { 683 return op.lro.Name() 684} 685 686// WorkflowTemplateIterator manages a stream of *dataprocpb.WorkflowTemplate. 687type WorkflowTemplateIterator struct { 688 items []*dataprocpb.WorkflowTemplate 689 pageInfo *iterator.PageInfo 690 nextFunc func() error 691 692 // Response is the raw response for the current page. 693 // It must be cast to the RPC response type. 694 // Calling Next() or InternalFetch() updates this value. 695 Response interface{} 696 697 // InternalFetch is for use by the Google Cloud Libraries only. 698 // It is not part of the stable interface of this package. 699 // 700 // InternalFetch returns results from a single call to the underlying RPC. 701 // The number of results is no greater than pageSize. 702 // If there are no more results, nextPageToken is empty and err is nil. 703 InternalFetch func(pageSize int, pageToken string) (results []*dataprocpb.WorkflowTemplate, nextPageToken string, err error) 704} 705 706// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 707func (it *WorkflowTemplateIterator) PageInfo() *iterator.PageInfo { 708 return it.pageInfo 709} 710 711// Next returns the next result. Its second return value is iterator.Done if there are no more 712// results. Once Next returns Done, all subsequent calls will return Done. 713func (it *WorkflowTemplateIterator) Next() (*dataprocpb.WorkflowTemplate, error) { 714 var item *dataprocpb.WorkflowTemplate 715 if err := it.nextFunc(); err != nil { 716 return item, err 717 } 718 item = it.items[0] 719 it.items = it.items[1:] 720 return item, nil 721} 722 723func (it *WorkflowTemplateIterator) bufLen() int { 724 return len(it.items) 725} 726 727func (it *WorkflowTemplateIterator) takeBuf() interface{} { 728 b := it.items 729 it.items = nil 730 return b 731} 732