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 dataflow 18 19import ( 20 "context" 21 "math" 22 "time" 23 24 gax "github.com/googleapis/gax-go/v2" 25 "google.golang.org/api/iterator" 26 "google.golang.org/api/option" 27 "google.golang.org/api/option/internaloption" 28 gtransport "google.golang.org/api/transport/grpc" 29 dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" 30 "google.golang.org/grpc" 31 "google.golang.org/grpc/metadata" 32 "google.golang.org/protobuf/proto" 33) 34 35var newJobsV1Beta3ClientHook clientHook 36 37// JobsV1Beta3CallOptions contains the retry settings for each method of JobsV1Beta3Client. 38type JobsV1Beta3CallOptions struct { 39 CreateJob []gax.CallOption 40 GetJob []gax.CallOption 41 UpdateJob []gax.CallOption 42 ListJobs []gax.CallOption 43 AggregatedListJobs []gax.CallOption 44 CheckActiveJobs []gax.CallOption 45 SnapshotJob []gax.CallOption 46} 47 48func defaultJobsV1Beta3GRPCClientOptions() []option.ClientOption { 49 return []option.ClientOption{ 50 internaloption.WithDefaultEndpoint("dataflow.googleapis.com:443"), 51 internaloption.WithDefaultMTLSEndpoint("dataflow.mtls.googleapis.com:443"), 52 internaloption.WithDefaultAudience("https://dataflow.googleapis.com/"), 53 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 54 internaloption.EnableJwtWithScope(), 55 option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), 56 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 57 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 58 } 59} 60 61func defaultJobsV1Beta3CallOptions() *JobsV1Beta3CallOptions { 62 return &JobsV1Beta3CallOptions{ 63 CreateJob: []gax.CallOption{}, 64 GetJob: []gax.CallOption{}, 65 UpdateJob: []gax.CallOption{}, 66 ListJobs: []gax.CallOption{}, 67 AggregatedListJobs: []gax.CallOption{}, 68 CheckActiveJobs: []gax.CallOption{}, 69 SnapshotJob: []gax.CallOption{}, 70 } 71} 72 73// internalJobsV1Beta3Client is an interface that defines the methods availaible from Dataflow API. 74type internalJobsV1Beta3Client interface { 75 Close() error 76 setGoogleClientInfo(...string) 77 Connection() *grpc.ClientConn 78 CreateJob(context.Context, *dataflowpb.CreateJobRequest, ...gax.CallOption) (*dataflowpb.Job, error) 79 GetJob(context.Context, *dataflowpb.GetJobRequest, ...gax.CallOption) (*dataflowpb.Job, error) 80 UpdateJob(context.Context, *dataflowpb.UpdateJobRequest, ...gax.CallOption) (*dataflowpb.Job, error) 81 ListJobs(context.Context, *dataflowpb.ListJobsRequest, ...gax.CallOption) *JobIterator 82 AggregatedListJobs(context.Context, *dataflowpb.ListJobsRequest, ...gax.CallOption) *JobIterator 83 CheckActiveJobs(context.Context, *dataflowpb.CheckActiveJobsRequest, ...gax.CallOption) (*dataflowpb.CheckActiveJobsResponse, error) 84 SnapshotJob(context.Context, *dataflowpb.SnapshotJobRequest, ...gax.CallOption) (*dataflowpb.Snapshot, error) 85} 86 87// JobsV1Beta3Client is a client for interacting with Dataflow API. 88// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 89// 90// Provides a method to create and modify Google Cloud Dataflow jobs. 91// A Job is a multi-stage computation graph run by the Cloud Dataflow service. 92type JobsV1Beta3Client struct { 93 // The internal transport-dependent client. 94 internalClient internalJobsV1Beta3Client 95 96 // The call options for this service. 97 CallOptions *JobsV1Beta3CallOptions 98} 99 100// Wrapper methods routed to the internal client. 101 102// Close closes the connection to the API service. The user should invoke this when 103// the client is no longer required. 104func (c *JobsV1Beta3Client) Close() error { 105 return c.internalClient.Close() 106} 107 108// setGoogleClientInfo sets the name and version of the application in 109// the `x-goog-api-client` header passed on each request. Intended for 110// use by Google-written clients. 111func (c *JobsV1Beta3Client) setGoogleClientInfo(keyval ...string) { 112 c.internalClient.setGoogleClientInfo(keyval...) 113} 114 115// Connection returns a connection to the API service. 116// 117// Deprecated. 118func (c *JobsV1Beta3Client) Connection() *grpc.ClientConn { 119 return c.internalClient.Connection() 120} 121 122// CreateJob creates a Cloud Dataflow job. 123// 124// To create a job, we recommend using projects.locations.jobs.create with a 125// [regional endpoint] 126// (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints (at https://cloud.google.com/dataflow/docs/concepts/regional-endpoints)). Using 127// projects.jobs.create is not recommended, as your job will always start 128// in us-central1. 129func (c *JobsV1Beta3Client) CreateJob(ctx context.Context, req *dataflowpb.CreateJobRequest, opts ...gax.CallOption) (*dataflowpb.Job, error) { 130 return c.internalClient.CreateJob(ctx, req, opts...) 131} 132 133// GetJob gets the state of the specified Cloud Dataflow job. 134// 135// To get the state of a job, we recommend using projects.locations.jobs.get 136// with a [regional endpoint] 137// (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints (at https://cloud.google.com/dataflow/docs/concepts/regional-endpoints)). Using 138// projects.jobs.get is not recommended, as you can only get the state of 139// jobs that are running in us-central1. 140func (c *JobsV1Beta3Client) GetJob(ctx context.Context, req *dataflowpb.GetJobRequest, opts ...gax.CallOption) (*dataflowpb.Job, error) { 141 return c.internalClient.GetJob(ctx, req, opts...) 142} 143 144// UpdateJob updates the state of an existing Cloud Dataflow job. 145// 146// To update the state of an existing job, we recommend using 147// projects.locations.jobs.update with a [regional endpoint] 148// (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints (at https://cloud.google.com/dataflow/docs/concepts/regional-endpoints)). Using 149// projects.jobs.update is not recommended, as you can only update the state 150// of jobs that are running in us-central1. 151func (c *JobsV1Beta3Client) UpdateJob(ctx context.Context, req *dataflowpb.UpdateJobRequest, opts ...gax.CallOption) (*dataflowpb.Job, error) { 152 return c.internalClient.UpdateJob(ctx, req, opts...) 153} 154 155// ListJobs list the jobs of a project. 156// 157// To list the jobs of a project in a region, we recommend using 158// projects.locations.jobs.list with a [regional endpoint] 159// (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints (at https://cloud.google.com/dataflow/docs/concepts/regional-endpoints)). To 160// list the all jobs across all regions, use projects.jobs.aggregated. Using 161// projects.jobs.list is not recommended, as you can only get the list of 162// jobs that are running in us-central1. 163func (c *JobsV1Beta3Client) ListJobs(ctx context.Context, req *dataflowpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator { 164 return c.internalClient.ListJobs(ctx, req, opts...) 165} 166 167// AggregatedListJobs list the jobs of a project across all regions. 168func (c *JobsV1Beta3Client) AggregatedListJobs(ctx context.Context, req *dataflowpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator { 169 return c.internalClient.AggregatedListJobs(ctx, req, opts...) 170} 171 172// CheckActiveJobs check for existence of active jobs in the given project across all regions. 173func (c *JobsV1Beta3Client) CheckActiveJobs(ctx context.Context, req *dataflowpb.CheckActiveJobsRequest, opts ...gax.CallOption) (*dataflowpb.CheckActiveJobsResponse, error) { 174 return c.internalClient.CheckActiveJobs(ctx, req, opts...) 175} 176 177// SnapshotJob snapshot the state of a streaming job. 178func (c *JobsV1Beta3Client) SnapshotJob(ctx context.Context, req *dataflowpb.SnapshotJobRequest, opts ...gax.CallOption) (*dataflowpb.Snapshot, error) { 179 return c.internalClient.SnapshotJob(ctx, req, opts...) 180} 181 182// jobsV1Beta3GRPCClient is a client for interacting with Dataflow API over gRPC transport. 183// 184// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 185type jobsV1Beta3GRPCClient struct { 186 // Connection pool of gRPC connections to the service. 187 connPool gtransport.ConnPool 188 189 // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE 190 disableDeadlines bool 191 192 // Points back to the CallOptions field of the containing JobsV1Beta3Client 193 CallOptions **JobsV1Beta3CallOptions 194 195 // The gRPC API client. 196 jobsV1Beta3Client dataflowpb.JobsV1Beta3Client 197 198 // The x-goog-* metadata to be sent with each request. 199 xGoogMetadata metadata.MD 200} 201 202// NewJobsV1Beta3Client creates a new jobs v1 beta3 client based on gRPC. 203// The returned client must be Closed when it is done being used to clean up its underlying connections. 204// 205// Provides a method to create and modify Google Cloud Dataflow jobs. 206// A Job is a multi-stage computation graph run by the Cloud Dataflow service. 207func NewJobsV1Beta3Client(ctx context.Context, opts ...option.ClientOption) (*JobsV1Beta3Client, error) { 208 clientOpts := defaultJobsV1Beta3GRPCClientOptions() 209 if newJobsV1Beta3ClientHook != nil { 210 hookOpts, err := newJobsV1Beta3ClientHook(ctx, clientHookParams{}) 211 if err != nil { 212 return nil, err 213 } 214 clientOpts = append(clientOpts, hookOpts...) 215 } 216 217 disableDeadlines, err := checkDisableDeadlines() 218 if err != nil { 219 return nil, err 220 } 221 222 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 223 if err != nil { 224 return nil, err 225 } 226 client := JobsV1Beta3Client{CallOptions: defaultJobsV1Beta3CallOptions()} 227 228 c := &jobsV1Beta3GRPCClient{ 229 connPool: connPool, 230 disableDeadlines: disableDeadlines, 231 jobsV1Beta3Client: dataflowpb.NewJobsV1Beta3Client(connPool), 232 CallOptions: &client.CallOptions, 233 } 234 c.setGoogleClientInfo() 235 236 client.internalClient = c 237 238 return &client, nil 239} 240 241// Connection returns a connection to the API service. 242// 243// Deprecated. 244func (c *jobsV1Beta3GRPCClient) Connection() *grpc.ClientConn { 245 return c.connPool.Conn() 246} 247 248// setGoogleClientInfo sets the name and version of the application in 249// the `x-goog-api-client` header passed on each request. Intended for 250// use by Google-written clients. 251func (c *jobsV1Beta3GRPCClient) setGoogleClientInfo(keyval ...string) { 252 kv := append([]string{"gl-go", versionGo()}, keyval...) 253 kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) 254 c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) 255} 256 257// Close closes the connection to the API service. The user should invoke this when 258// the client is no longer required. 259func (c *jobsV1Beta3GRPCClient) Close() error { 260 return c.connPool.Close() 261} 262 263func (c *jobsV1Beta3GRPCClient) CreateJob(ctx context.Context, req *dataflowpb.CreateJobRequest, opts ...gax.CallOption) (*dataflowpb.Job, error) { 264 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 265 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 266 defer cancel() 267 ctx = cctx 268 } 269 ctx = insertMetadata(ctx, c.xGoogMetadata) 270 opts = append((*c.CallOptions).CreateJob[0:len((*c.CallOptions).CreateJob):len((*c.CallOptions).CreateJob)], opts...) 271 var resp *dataflowpb.Job 272 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 273 var err error 274 resp, err = c.jobsV1Beta3Client.CreateJob(ctx, req, settings.GRPC...) 275 return err 276 }, opts...) 277 if err != nil { 278 return nil, err 279 } 280 return resp, nil 281} 282 283func (c *jobsV1Beta3GRPCClient) GetJob(ctx context.Context, req *dataflowpb.GetJobRequest, opts ...gax.CallOption) (*dataflowpb.Job, error) { 284 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 285 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 286 defer cancel() 287 ctx = cctx 288 } 289 ctx = insertMetadata(ctx, c.xGoogMetadata) 290 opts = append((*c.CallOptions).GetJob[0:len((*c.CallOptions).GetJob):len((*c.CallOptions).GetJob)], opts...) 291 var resp *dataflowpb.Job 292 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 293 var err error 294 resp, err = c.jobsV1Beta3Client.GetJob(ctx, req, settings.GRPC...) 295 return err 296 }, opts...) 297 if err != nil { 298 return nil, err 299 } 300 return resp, nil 301} 302 303func (c *jobsV1Beta3GRPCClient) UpdateJob(ctx context.Context, req *dataflowpb.UpdateJobRequest, opts ...gax.CallOption) (*dataflowpb.Job, error) { 304 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 305 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 306 defer cancel() 307 ctx = cctx 308 } 309 ctx = insertMetadata(ctx, c.xGoogMetadata) 310 opts = append((*c.CallOptions).UpdateJob[0:len((*c.CallOptions).UpdateJob):len((*c.CallOptions).UpdateJob)], opts...) 311 var resp *dataflowpb.Job 312 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 313 var err error 314 resp, err = c.jobsV1Beta3Client.UpdateJob(ctx, req, settings.GRPC...) 315 return err 316 }, opts...) 317 if err != nil { 318 return nil, err 319 } 320 return resp, nil 321} 322 323func (c *jobsV1Beta3GRPCClient) ListJobs(ctx context.Context, req *dataflowpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator { 324 ctx = insertMetadata(ctx, c.xGoogMetadata) 325 opts = append((*c.CallOptions).ListJobs[0:len((*c.CallOptions).ListJobs):len((*c.CallOptions).ListJobs)], opts...) 326 it := &JobIterator{} 327 req = proto.Clone(req).(*dataflowpb.ListJobsRequest) 328 it.InternalFetch = func(pageSize int, pageToken string) ([]*dataflowpb.Job, string, error) { 329 resp := &dataflowpb.ListJobsResponse{} 330 if pageToken != "" { 331 req.PageToken = pageToken 332 } 333 if pageSize > math.MaxInt32 { 334 req.PageSize = math.MaxInt32 335 } else if pageSize != 0 { 336 req.PageSize = int32(pageSize) 337 } 338 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 339 var err error 340 resp, err = c.jobsV1Beta3Client.ListJobs(ctx, req, settings.GRPC...) 341 return err 342 }, opts...) 343 if err != nil { 344 return nil, "", err 345 } 346 347 it.Response = resp 348 return resp.GetJobs(), resp.GetNextPageToken(), nil 349 } 350 fetch := func(pageSize int, pageToken string) (string, error) { 351 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 352 if err != nil { 353 return "", err 354 } 355 it.items = append(it.items, items...) 356 return nextPageToken, nil 357 } 358 359 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 360 it.pageInfo.MaxSize = int(req.GetPageSize()) 361 it.pageInfo.Token = req.GetPageToken() 362 363 return it 364} 365 366func (c *jobsV1Beta3GRPCClient) AggregatedListJobs(ctx context.Context, req *dataflowpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator { 367 ctx = insertMetadata(ctx, c.xGoogMetadata) 368 opts = append((*c.CallOptions).AggregatedListJobs[0:len((*c.CallOptions).AggregatedListJobs):len((*c.CallOptions).AggregatedListJobs)], opts...) 369 it := &JobIterator{} 370 req = proto.Clone(req).(*dataflowpb.ListJobsRequest) 371 it.InternalFetch = func(pageSize int, pageToken string) ([]*dataflowpb.Job, string, error) { 372 resp := &dataflowpb.ListJobsResponse{} 373 if pageToken != "" { 374 req.PageToken = pageToken 375 } 376 if pageSize > math.MaxInt32 { 377 req.PageSize = math.MaxInt32 378 } else if pageSize != 0 { 379 req.PageSize = int32(pageSize) 380 } 381 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 382 var err error 383 resp, err = c.jobsV1Beta3Client.AggregatedListJobs(ctx, req, settings.GRPC...) 384 return err 385 }, opts...) 386 if err != nil { 387 return nil, "", err 388 } 389 390 it.Response = resp 391 return resp.GetJobs(), resp.GetNextPageToken(), nil 392 } 393 fetch := func(pageSize int, pageToken string) (string, error) { 394 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 395 if err != nil { 396 return "", err 397 } 398 it.items = append(it.items, items...) 399 return nextPageToken, nil 400 } 401 402 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 403 it.pageInfo.MaxSize = int(req.GetPageSize()) 404 it.pageInfo.Token = req.GetPageToken() 405 406 return it 407} 408 409func (c *jobsV1Beta3GRPCClient) CheckActiveJobs(ctx context.Context, req *dataflowpb.CheckActiveJobsRequest, opts ...gax.CallOption) (*dataflowpb.CheckActiveJobsResponse, error) { 410 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 411 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 412 defer cancel() 413 ctx = cctx 414 } 415 ctx = insertMetadata(ctx, c.xGoogMetadata) 416 opts = append((*c.CallOptions).CheckActiveJobs[0:len((*c.CallOptions).CheckActiveJobs):len((*c.CallOptions).CheckActiveJobs)], opts...) 417 var resp *dataflowpb.CheckActiveJobsResponse 418 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 419 var err error 420 resp, err = c.jobsV1Beta3Client.CheckActiveJobs(ctx, req, settings.GRPC...) 421 return err 422 }, opts...) 423 if err != nil { 424 return nil, err 425 } 426 return resp, nil 427} 428 429func (c *jobsV1Beta3GRPCClient) SnapshotJob(ctx context.Context, req *dataflowpb.SnapshotJobRequest, opts ...gax.CallOption) (*dataflowpb.Snapshot, error) { 430 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 431 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 432 defer cancel() 433 ctx = cctx 434 } 435 ctx = insertMetadata(ctx, c.xGoogMetadata) 436 opts = append((*c.CallOptions).SnapshotJob[0:len((*c.CallOptions).SnapshotJob):len((*c.CallOptions).SnapshotJob)], opts...) 437 var resp *dataflowpb.Snapshot 438 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 439 var err error 440 resp, err = c.jobsV1Beta3Client.SnapshotJob(ctx, req, settings.GRPC...) 441 return err 442 }, opts...) 443 if err != nil { 444 return nil, err 445 } 446 return resp, nil 447} 448 449// JobIterator manages a stream of *dataflowpb.Job. 450type JobIterator struct { 451 items []*dataflowpb.Job 452 pageInfo *iterator.PageInfo 453 nextFunc func() error 454 455 // Response is the raw response for the current page. 456 // It must be cast to the RPC response type. 457 // Calling Next() or InternalFetch() updates this value. 458 Response interface{} 459 460 // InternalFetch is for use by the Google Cloud Libraries only. 461 // It is not part of the stable interface of this package. 462 // 463 // InternalFetch returns results from a single call to the underlying RPC. 464 // The number of results is no greater than pageSize. 465 // If there are no more results, nextPageToken is empty and err is nil. 466 InternalFetch func(pageSize int, pageToken string) (results []*dataflowpb.Job, nextPageToken string, err error) 467} 468 469// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 470func (it *JobIterator) PageInfo() *iterator.PageInfo { 471 return it.pageInfo 472} 473 474// Next returns the next result. Its second return value is iterator.Done if there are no more 475// results. Once Next returns Done, all subsequent calls will return Done. 476func (it *JobIterator) Next() (*dataflowpb.Job, error) { 477 var item *dataflowpb.Job 478 if err := it.nextFunc(); err != nil { 479 return item, err 480 } 481 item = it.items[0] 482 it.items = it.items[1:] 483 return item, nil 484} 485 486func (it *JobIterator) bufLen() int { 487 return len(it.items) 488} 489 490func (it *JobIterator) takeBuf() interface{} { 491 b := it.items 492 it.items = nil 493 return b 494} 495