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 aiplatform 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 aiplatformpb "google.golang.org/genproto/googleapis/cloud/aiplatform/v1" 34 longrunningpb "google.golang.org/genproto/googleapis/longrunning" 35 "google.golang.org/grpc" 36 "google.golang.org/grpc/metadata" 37 "google.golang.org/protobuf/proto" 38) 39 40var newJobClientHook clientHook 41 42// JobCallOptions contains the retry settings for each method of JobClient. 43type JobCallOptions struct { 44 CreateCustomJob []gax.CallOption 45 GetCustomJob []gax.CallOption 46 ListCustomJobs []gax.CallOption 47 DeleteCustomJob []gax.CallOption 48 CancelCustomJob []gax.CallOption 49 CreateDataLabelingJob []gax.CallOption 50 GetDataLabelingJob []gax.CallOption 51 ListDataLabelingJobs []gax.CallOption 52 DeleteDataLabelingJob []gax.CallOption 53 CancelDataLabelingJob []gax.CallOption 54 CreateHyperparameterTuningJob []gax.CallOption 55 GetHyperparameterTuningJob []gax.CallOption 56 ListHyperparameterTuningJobs []gax.CallOption 57 DeleteHyperparameterTuningJob []gax.CallOption 58 CancelHyperparameterTuningJob []gax.CallOption 59 CreateBatchPredictionJob []gax.CallOption 60 GetBatchPredictionJob []gax.CallOption 61 ListBatchPredictionJobs []gax.CallOption 62 DeleteBatchPredictionJob []gax.CallOption 63 CancelBatchPredictionJob []gax.CallOption 64} 65 66func defaultJobGRPCClientOptions() []option.ClientOption { 67 return []option.ClientOption{ 68 internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"), 69 internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), 70 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 71 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 72 option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), 73 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 74 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 75 } 76} 77 78func defaultJobCallOptions() *JobCallOptions { 79 return &JobCallOptions{ 80 CreateCustomJob: []gax.CallOption{}, 81 GetCustomJob: []gax.CallOption{}, 82 ListCustomJobs: []gax.CallOption{}, 83 DeleteCustomJob: []gax.CallOption{}, 84 CancelCustomJob: []gax.CallOption{}, 85 CreateDataLabelingJob: []gax.CallOption{}, 86 GetDataLabelingJob: []gax.CallOption{}, 87 ListDataLabelingJobs: []gax.CallOption{}, 88 DeleteDataLabelingJob: []gax.CallOption{}, 89 CancelDataLabelingJob: []gax.CallOption{}, 90 CreateHyperparameterTuningJob: []gax.CallOption{}, 91 GetHyperparameterTuningJob: []gax.CallOption{}, 92 ListHyperparameterTuningJobs: []gax.CallOption{}, 93 DeleteHyperparameterTuningJob: []gax.CallOption{}, 94 CancelHyperparameterTuningJob: []gax.CallOption{}, 95 CreateBatchPredictionJob: []gax.CallOption{}, 96 GetBatchPredictionJob: []gax.CallOption{}, 97 ListBatchPredictionJobs: []gax.CallOption{}, 98 DeleteBatchPredictionJob: []gax.CallOption{}, 99 CancelBatchPredictionJob: []gax.CallOption{}, 100 } 101} 102 103// internalJobClient is an interface that defines the methods availaible from Vertex AI API. 104type internalJobClient interface { 105 Close() error 106 setGoogleClientInfo(...string) 107 Connection() *grpc.ClientConn 108 CreateCustomJob(context.Context, *aiplatformpb.CreateCustomJobRequest, ...gax.CallOption) (*aiplatformpb.CustomJob, error) 109 GetCustomJob(context.Context, *aiplatformpb.GetCustomJobRequest, ...gax.CallOption) (*aiplatformpb.CustomJob, error) 110 ListCustomJobs(context.Context, *aiplatformpb.ListCustomJobsRequest, ...gax.CallOption) *CustomJobIterator 111 DeleteCustomJob(context.Context, *aiplatformpb.DeleteCustomJobRequest, ...gax.CallOption) (*DeleteCustomJobOperation, error) 112 DeleteCustomJobOperation(name string) *DeleteCustomJobOperation 113 CancelCustomJob(context.Context, *aiplatformpb.CancelCustomJobRequest, ...gax.CallOption) error 114 CreateDataLabelingJob(context.Context, *aiplatformpb.CreateDataLabelingJobRequest, ...gax.CallOption) (*aiplatformpb.DataLabelingJob, error) 115 GetDataLabelingJob(context.Context, *aiplatformpb.GetDataLabelingJobRequest, ...gax.CallOption) (*aiplatformpb.DataLabelingJob, error) 116 ListDataLabelingJobs(context.Context, *aiplatformpb.ListDataLabelingJobsRequest, ...gax.CallOption) *DataLabelingJobIterator 117 DeleteDataLabelingJob(context.Context, *aiplatformpb.DeleteDataLabelingJobRequest, ...gax.CallOption) (*DeleteDataLabelingJobOperation, error) 118 DeleteDataLabelingJobOperation(name string) *DeleteDataLabelingJobOperation 119 CancelDataLabelingJob(context.Context, *aiplatformpb.CancelDataLabelingJobRequest, ...gax.CallOption) error 120 CreateHyperparameterTuningJob(context.Context, *aiplatformpb.CreateHyperparameterTuningJobRequest, ...gax.CallOption) (*aiplatformpb.HyperparameterTuningJob, error) 121 GetHyperparameterTuningJob(context.Context, *aiplatformpb.GetHyperparameterTuningJobRequest, ...gax.CallOption) (*aiplatformpb.HyperparameterTuningJob, error) 122 ListHyperparameterTuningJobs(context.Context, *aiplatformpb.ListHyperparameterTuningJobsRequest, ...gax.CallOption) *HyperparameterTuningJobIterator 123 DeleteHyperparameterTuningJob(context.Context, *aiplatformpb.DeleteHyperparameterTuningJobRequest, ...gax.CallOption) (*DeleteHyperparameterTuningJobOperation, error) 124 DeleteHyperparameterTuningJobOperation(name string) *DeleteHyperparameterTuningJobOperation 125 CancelHyperparameterTuningJob(context.Context, *aiplatformpb.CancelHyperparameterTuningJobRequest, ...gax.CallOption) error 126 CreateBatchPredictionJob(context.Context, *aiplatformpb.CreateBatchPredictionJobRequest, ...gax.CallOption) (*aiplatformpb.BatchPredictionJob, error) 127 GetBatchPredictionJob(context.Context, *aiplatformpb.GetBatchPredictionJobRequest, ...gax.CallOption) (*aiplatformpb.BatchPredictionJob, error) 128 ListBatchPredictionJobs(context.Context, *aiplatformpb.ListBatchPredictionJobsRequest, ...gax.CallOption) *BatchPredictionJobIterator 129 DeleteBatchPredictionJob(context.Context, *aiplatformpb.DeleteBatchPredictionJobRequest, ...gax.CallOption) (*DeleteBatchPredictionJobOperation, error) 130 DeleteBatchPredictionJobOperation(name string) *DeleteBatchPredictionJobOperation 131 CancelBatchPredictionJob(context.Context, *aiplatformpb.CancelBatchPredictionJobRequest, ...gax.CallOption) error 132} 133 134// JobClient is a client for interacting with Vertex AI API. 135// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 136// 137// A service for creating and managing Vertex AI’s jobs. 138type JobClient struct { 139 // The internal transport-dependent client. 140 internalClient internalJobClient 141 142 // The call options for this service. 143 CallOptions *JobCallOptions 144 145 // LROClient is used internally to handle long-running operations. 146 // It is exposed so that its CallOptions can be modified if required. 147 // Users should not Close this client. 148 LROClient *lroauto.OperationsClient 149} 150 151// Wrapper methods routed to the internal client. 152 153// Close closes the connection to the API service. The user should invoke this when 154// the client is no longer required. 155func (c *JobClient) Close() error { 156 return c.internalClient.Close() 157} 158 159// setGoogleClientInfo sets the name and version of the application in 160// the `x-goog-api-client` header passed on each request. Intended for 161// use by Google-written clients. 162func (c *JobClient) setGoogleClientInfo(keyval ...string) { 163 c.internalClient.setGoogleClientInfo(keyval...) 164} 165 166// Connection returns a connection to the API service. 167// 168// Deprecated. 169func (c *JobClient) Connection() *grpc.ClientConn { 170 return c.internalClient.Connection() 171} 172 173// CreateCustomJob creates a CustomJob. A created CustomJob right away 174// will be attempted to be run. 175func (c *JobClient) CreateCustomJob(ctx context.Context, req *aiplatformpb.CreateCustomJobRequest, opts ...gax.CallOption) (*aiplatformpb.CustomJob, error) { 176 return c.internalClient.CreateCustomJob(ctx, req, opts...) 177} 178 179// GetCustomJob gets a CustomJob. 180func (c *JobClient) GetCustomJob(ctx context.Context, req *aiplatformpb.GetCustomJobRequest, opts ...gax.CallOption) (*aiplatformpb.CustomJob, error) { 181 return c.internalClient.GetCustomJob(ctx, req, opts...) 182} 183 184// ListCustomJobs lists CustomJobs in a Location. 185func (c *JobClient) ListCustomJobs(ctx context.Context, req *aiplatformpb.ListCustomJobsRequest, opts ...gax.CallOption) *CustomJobIterator { 186 return c.internalClient.ListCustomJobs(ctx, req, opts...) 187} 188 189// DeleteCustomJob deletes a CustomJob. 190func (c *JobClient) DeleteCustomJob(ctx context.Context, req *aiplatformpb.DeleteCustomJobRequest, opts ...gax.CallOption) (*DeleteCustomJobOperation, error) { 191 return c.internalClient.DeleteCustomJob(ctx, req, opts...) 192} 193 194// DeleteCustomJobOperation returns a new DeleteCustomJobOperation from a given name. 195// The name must be that of a previously created DeleteCustomJobOperation, possibly from a different process. 196func (c *JobClient) DeleteCustomJobOperation(name string) *DeleteCustomJobOperation { 197 return c.internalClient.DeleteCustomJobOperation(name) 198} 199 200// CancelCustomJob cancels a CustomJob. 201// Starts asynchronous cancellation on the CustomJob. The server 202// makes a best effort to cancel the job, but success is not 203// guaranteed. Clients can use JobService.GetCustomJob or 204// other methods to check whether the cancellation succeeded or whether the 205// job completed despite cancellation. On successful cancellation, 206// the CustomJob is not deleted; instead it becomes a job with 207// a CustomJob.error value with a google.rpc.Status.code of 1, 208// corresponding to Code.CANCELLED, and CustomJob.state is set to 209// CANCELLED. 210func (c *JobClient) CancelCustomJob(ctx context.Context, req *aiplatformpb.CancelCustomJobRequest, opts ...gax.CallOption) error { 211 return c.internalClient.CancelCustomJob(ctx, req, opts...) 212} 213 214// CreateDataLabelingJob creates a DataLabelingJob. 215func (c *JobClient) CreateDataLabelingJob(ctx context.Context, req *aiplatformpb.CreateDataLabelingJobRequest, opts ...gax.CallOption) (*aiplatformpb.DataLabelingJob, error) { 216 return c.internalClient.CreateDataLabelingJob(ctx, req, opts...) 217} 218 219// GetDataLabelingJob gets a DataLabelingJob. 220func (c *JobClient) GetDataLabelingJob(ctx context.Context, req *aiplatformpb.GetDataLabelingJobRequest, opts ...gax.CallOption) (*aiplatformpb.DataLabelingJob, error) { 221 return c.internalClient.GetDataLabelingJob(ctx, req, opts...) 222} 223 224// ListDataLabelingJobs lists DataLabelingJobs in a Location. 225func (c *JobClient) ListDataLabelingJobs(ctx context.Context, req *aiplatformpb.ListDataLabelingJobsRequest, opts ...gax.CallOption) *DataLabelingJobIterator { 226 return c.internalClient.ListDataLabelingJobs(ctx, req, opts...) 227} 228 229// DeleteDataLabelingJob deletes a DataLabelingJob. 230func (c *JobClient) DeleteDataLabelingJob(ctx context.Context, req *aiplatformpb.DeleteDataLabelingJobRequest, opts ...gax.CallOption) (*DeleteDataLabelingJobOperation, error) { 231 return c.internalClient.DeleteDataLabelingJob(ctx, req, opts...) 232} 233 234// DeleteDataLabelingJobOperation returns a new DeleteDataLabelingJobOperation from a given name. 235// The name must be that of a previously created DeleteDataLabelingJobOperation, possibly from a different process. 236func (c *JobClient) DeleteDataLabelingJobOperation(name string) *DeleteDataLabelingJobOperation { 237 return c.internalClient.DeleteDataLabelingJobOperation(name) 238} 239 240// CancelDataLabelingJob cancels a DataLabelingJob. Success of cancellation is not guaranteed. 241func (c *JobClient) CancelDataLabelingJob(ctx context.Context, req *aiplatformpb.CancelDataLabelingJobRequest, opts ...gax.CallOption) error { 242 return c.internalClient.CancelDataLabelingJob(ctx, req, opts...) 243} 244 245// CreateHyperparameterTuningJob creates a HyperparameterTuningJob 246func (c *JobClient) CreateHyperparameterTuningJob(ctx context.Context, req *aiplatformpb.CreateHyperparameterTuningJobRequest, opts ...gax.CallOption) (*aiplatformpb.HyperparameterTuningJob, error) { 247 return c.internalClient.CreateHyperparameterTuningJob(ctx, req, opts...) 248} 249 250// GetHyperparameterTuningJob gets a HyperparameterTuningJob 251func (c *JobClient) GetHyperparameterTuningJob(ctx context.Context, req *aiplatformpb.GetHyperparameterTuningJobRequest, opts ...gax.CallOption) (*aiplatformpb.HyperparameterTuningJob, error) { 252 return c.internalClient.GetHyperparameterTuningJob(ctx, req, opts...) 253} 254 255// ListHyperparameterTuningJobs lists HyperparameterTuningJobs in a Location. 256func (c *JobClient) ListHyperparameterTuningJobs(ctx context.Context, req *aiplatformpb.ListHyperparameterTuningJobsRequest, opts ...gax.CallOption) *HyperparameterTuningJobIterator { 257 return c.internalClient.ListHyperparameterTuningJobs(ctx, req, opts...) 258} 259 260// DeleteHyperparameterTuningJob deletes a HyperparameterTuningJob. 261func (c *JobClient) DeleteHyperparameterTuningJob(ctx context.Context, req *aiplatformpb.DeleteHyperparameterTuningJobRequest, opts ...gax.CallOption) (*DeleteHyperparameterTuningJobOperation, error) { 262 return c.internalClient.DeleteHyperparameterTuningJob(ctx, req, opts...) 263} 264 265// DeleteHyperparameterTuningJobOperation returns a new DeleteHyperparameterTuningJobOperation from a given name. 266// The name must be that of a previously created DeleteHyperparameterTuningJobOperation, possibly from a different process. 267func (c *JobClient) DeleteHyperparameterTuningJobOperation(name string) *DeleteHyperparameterTuningJobOperation { 268 return c.internalClient.DeleteHyperparameterTuningJobOperation(name) 269} 270 271// CancelHyperparameterTuningJob cancels a HyperparameterTuningJob. 272// Starts asynchronous cancellation on the HyperparameterTuningJob. The server 273// makes a best effort to cancel the job, but success is not 274// guaranteed. Clients can use JobService.GetHyperparameterTuningJob or 275// other methods to check whether the cancellation succeeded or whether the 276// job completed despite cancellation. On successful cancellation, 277// the HyperparameterTuningJob is not deleted; instead it becomes a job with 278// a HyperparameterTuningJob.error value with a google.rpc.Status.code 279// of 1, corresponding to Code.CANCELLED, and 280// HyperparameterTuningJob.state is set to CANCELLED. 281func (c *JobClient) CancelHyperparameterTuningJob(ctx context.Context, req *aiplatformpb.CancelHyperparameterTuningJobRequest, opts ...gax.CallOption) error { 282 return c.internalClient.CancelHyperparameterTuningJob(ctx, req, opts...) 283} 284 285// CreateBatchPredictionJob creates a BatchPredictionJob. A BatchPredictionJob once created will 286// right away be attempted to start. 287func (c *JobClient) CreateBatchPredictionJob(ctx context.Context, req *aiplatformpb.CreateBatchPredictionJobRequest, opts ...gax.CallOption) (*aiplatformpb.BatchPredictionJob, error) { 288 return c.internalClient.CreateBatchPredictionJob(ctx, req, opts...) 289} 290 291// GetBatchPredictionJob gets a BatchPredictionJob 292func (c *JobClient) GetBatchPredictionJob(ctx context.Context, req *aiplatformpb.GetBatchPredictionJobRequest, opts ...gax.CallOption) (*aiplatformpb.BatchPredictionJob, error) { 293 return c.internalClient.GetBatchPredictionJob(ctx, req, opts...) 294} 295 296// ListBatchPredictionJobs lists BatchPredictionJobs in a Location. 297func (c *JobClient) ListBatchPredictionJobs(ctx context.Context, req *aiplatformpb.ListBatchPredictionJobsRequest, opts ...gax.CallOption) *BatchPredictionJobIterator { 298 return c.internalClient.ListBatchPredictionJobs(ctx, req, opts...) 299} 300 301// DeleteBatchPredictionJob deletes a BatchPredictionJob. Can only be called on jobs that already 302// finished. 303func (c *JobClient) DeleteBatchPredictionJob(ctx context.Context, req *aiplatformpb.DeleteBatchPredictionJobRequest, opts ...gax.CallOption) (*DeleteBatchPredictionJobOperation, error) { 304 return c.internalClient.DeleteBatchPredictionJob(ctx, req, opts...) 305} 306 307// DeleteBatchPredictionJobOperation returns a new DeleteBatchPredictionJobOperation from a given name. 308// The name must be that of a previously created DeleteBatchPredictionJobOperation, possibly from a different process. 309func (c *JobClient) DeleteBatchPredictionJobOperation(name string) *DeleteBatchPredictionJobOperation { 310 return c.internalClient.DeleteBatchPredictionJobOperation(name) 311} 312 313// CancelBatchPredictionJob cancels a BatchPredictionJob. 314// 315// Starts asynchronous cancellation on the BatchPredictionJob. The server 316// makes the best effort to cancel the job, but success is not 317// guaranteed. Clients can use JobService.GetBatchPredictionJob or 318// other methods to check whether the cancellation succeeded or whether the 319// job completed despite cancellation. On a successful cancellation, 320// the BatchPredictionJob is not deleted;instead its 321// BatchPredictionJob.state is set to CANCELLED. Any files already 322// outputted by the job are not deleted. 323func (c *JobClient) CancelBatchPredictionJob(ctx context.Context, req *aiplatformpb.CancelBatchPredictionJobRequest, opts ...gax.CallOption) error { 324 return c.internalClient.CancelBatchPredictionJob(ctx, req, opts...) 325} 326 327// jobGRPCClient is a client for interacting with Vertex AI API over gRPC transport. 328// 329// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 330type jobGRPCClient struct { 331 // Connection pool of gRPC connections to the service. 332 connPool gtransport.ConnPool 333 334 // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE 335 disableDeadlines bool 336 337 // Points back to the CallOptions field of the containing JobClient 338 CallOptions **JobCallOptions 339 340 // The gRPC API client. 341 jobClient aiplatformpb.JobServiceClient 342 343 // LROClient is used internally to handle long-running operations. 344 // It is exposed so that its CallOptions can be modified if required. 345 // Users should not Close this client. 346 LROClient **lroauto.OperationsClient 347 348 // The x-goog-* metadata to be sent with each request. 349 xGoogMetadata metadata.MD 350} 351 352// NewJobClient creates a new job service client based on gRPC. 353// The returned client must be Closed when it is done being used to clean up its underlying connections. 354// 355// A service for creating and managing Vertex AI’s jobs. 356func NewJobClient(ctx context.Context, opts ...option.ClientOption) (*JobClient, error) { 357 clientOpts := defaultJobGRPCClientOptions() 358 if newJobClientHook != nil { 359 hookOpts, err := newJobClientHook(ctx, clientHookParams{}) 360 if err != nil { 361 return nil, err 362 } 363 clientOpts = append(clientOpts, hookOpts...) 364 } 365 366 disableDeadlines, err := checkDisableDeadlines() 367 if err != nil { 368 return nil, err 369 } 370 371 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 372 if err != nil { 373 return nil, err 374 } 375 client := JobClient{CallOptions: defaultJobCallOptions()} 376 377 c := &jobGRPCClient{ 378 connPool: connPool, 379 disableDeadlines: disableDeadlines, 380 jobClient: aiplatformpb.NewJobServiceClient(connPool), 381 CallOptions: &client.CallOptions, 382 } 383 c.setGoogleClientInfo() 384 385 client.internalClient = c 386 387 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) 388 if err != nil { 389 // This error "should not happen", since we are just reusing old connection pool 390 // and never actually need to dial. 391 // If this does happen, we could leak connp. However, we cannot close conn: 392 // If the user invoked the constructor with option.WithGRPCConn, 393 // we would close a connection that's still in use. 394 // TODO: investigate error conditions. 395 return nil, err 396 } 397 c.LROClient = &client.LROClient 398 return &client, nil 399} 400 401// Connection returns a connection to the API service. 402// 403// Deprecated. 404func (c *jobGRPCClient) Connection() *grpc.ClientConn { 405 return c.connPool.Conn() 406} 407 408// setGoogleClientInfo sets the name and version of the application in 409// the `x-goog-api-client` header passed on each request. Intended for 410// use by Google-written clients. 411func (c *jobGRPCClient) setGoogleClientInfo(keyval ...string) { 412 kv := append([]string{"gl-go", versionGo()}, keyval...) 413 kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) 414 c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) 415} 416 417// Close closes the connection to the API service. The user should invoke this when 418// the client is no longer required. 419func (c *jobGRPCClient) Close() error { 420 return c.connPool.Close() 421} 422 423func (c *jobGRPCClient) CreateCustomJob(ctx context.Context, req *aiplatformpb.CreateCustomJobRequest, opts ...gax.CallOption) (*aiplatformpb.CustomJob, error) { 424 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 425 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 426 defer cancel() 427 ctx = cctx 428 } 429 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 430 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 431 opts = append((*c.CallOptions).CreateCustomJob[0:len((*c.CallOptions).CreateCustomJob):len((*c.CallOptions).CreateCustomJob)], opts...) 432 var resp *aiplatformpb.CustomJob 433 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 434 var err error 435 resp, err = c.jobClient.CreateCustomJob(ctx, req, settings.GRPC...) 436 return err 437 }, opts...) 438 if err != nil { 439 return nil, err 440 } 441 return resp, nil 442} 443 444func (c *jobGRPCClient) GetCustomJob(ctx context.Context, req *aiplatformpb.GetCustomJobRequest, opts ...gax.CallOption) (*aiplatformpb.CustomJob, error) { 445 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 446 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 447 defer cancel() 448 ctx = cctx 449 } 450 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 451 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 452 opts = append((*c.CallOptions).GetCustomJob[0:len((*c.CallOptions).GetCustomJob):len((*c.CallOptions).GetCustomJob)], opts...) 453 var resp *aiplatformpb.CustomJob 454 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 455 var err error 456 resp, err = c.jobClient.GetCustomJob(ctx, req, settings.GRPC...) 457 return err 458 }, opts...) 459 if err != nil { 460 return nil, err 461 } 462 return resp, nil 463} 464 465func (c *jobGRPCClient) ListCustomJobs(ctx context.Context, req *aiplatformpb.ListCustomJobsRequest, opts ...gax.CallOption) *CustomJobIterator { 466 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 467 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 468 opts = append((*c.CallOptions).ListCustomJobs[0:len((*c.CallOptions).ListCustomJobs):len((*c.CallOptions).ListCustomJobs)], opts...) 469 it := &CustomJobIterator{} 470 req = proto.Clone(req).(*aiplatformpb.ListCustomJobsRequest) 471 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.CustomJob, string, error) { 472 var resp *aiplatformpb.ListCustomJobsResponse 473 req.PageToken = pageToken 474 if pageSize > math.MaxInt32 { 475 req.PageSize = math.MaxInt32 476 } else { 477 req.PageSize = int32(pageSize) 478 } 479 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 480 var err error 481 resp, err = c.jobClient.ListCustomJobs(ctx, req, settings.GRPC...) 482 return err 483 }, opts...) 484 if err != nil { 485 return nil, "", err 486 } 487 488 it.Response = resp 489 return resp.GetCustomJobs(), resp.GetNextPageToken(), nil 490 } 491 fetch := func(pageSize int, pageToken string) (string, error) { 492 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 493 if err != nil { 494 return "", err 495 } 496 it.items = append(it.items, items...) 497 return nextPageToken, nil 498 } 499 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 500 it.pageInfo.MaxSize = int(req.GetPageSize()) 501 it.pageInfo.Token = req.GetPageToken() 502 return it 503} 504 505func (c *jobGRPCClient) DeleteCustomJob(ctx context.Context, req *aiplatformpb.DeleteCustomJobRequest, opts ...gax.CallOption) (*DeleteCustomJobOperation, error) { 506 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 507 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 508 defer cancel() 509 ctx = cctx 510 } 511 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 512 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 513 opts = append((*c.CallOptions).DeleteCustomJob[0:len((*c.CallOptions).DeleteCustomJob):len((*c.CallOptions).DeleteCustomJob)], opts...) 514 var resp *longrunningpb.Operation 515 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 516 var err error 517 resp, err = c.jobClient.DeleteCustomJob(ctx, req, settings.GRPC...) 518 return err 519 }, opts...) 520 if err != nil { 521 return nil, err 522 } 523 return &DeleteCustomJobOperation{ 524 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 525 }, nil 526} 527 528func (c *jobGRPCClient) CancelCustomJob(ctx context.Context, req *aiplatformpb.CancelCustomJobRequest, opts ...gax.CallOption) error { 529 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 530 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 531 defer cancel() 532 ctx = cctx 533 } 534 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 535 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 536 opts = append((*c.CallOptions).CancelCustomJob[0:len((*c.CallOptions).CancelCustomJob):len((*c.CallOptions).CancelCustomJob)], opts...) 537 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 538 var err error 539 _, err = c.jobClient.CancelCustomJob(ctx, req, settings.GRPC...) 540 return err 541 }, opts...) 542 return err 543} 544 545func (c *jobGRPCClient) CreateDataLabelingJob(ctx context.Context, req *aiplatformpb.CreateDataLabelingJobRequest, opts ...gax.CallOption) (*aiplatformpb.DataLabelingJob, error) { 546 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 547 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 548 defer cancel() 549 ctx = cctx 550 } 551 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 552 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 553 opts = append((*c.CallOptions).CreateDataLabelingJob[0:len((*c.CallOptions).CreateDataLabelingJob):len((*c.CallOptions).CreateDataLabelingJob)], opts...) 554 var resp *aiplatformpb.DataLabelingJob 555 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 556 var err error 557 resp, err = c.jobClient.CreateDataLabelingJob(ctx, req, settings.GRPC...) 558 return err 559 }, opts...) 560 if err != nil { 561 return nil, err 562 } 563 return resp, nil 564} 565 566func (c *jobGRPCClient) GetDataLabelingJob(ctx context.Context, req *aiplatformpb.GetDataLabelingJobRequest, opts ...gax.CallOption) (*aiplatformpb.DataLabelingJob, error) { 567 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 568 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 569 defer cancel() 570 ctx = cctx 571 } 572 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 573 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 574 opts = append((*c.CallOptions).GetDataLabelingJob[0:len((*c.CallOptions).GetDataLabelingJob):len((*c.CallOptions).GetDataLabelingJob)], opts...) 575 var resp *aiplatformpb.DataLabelingJob 576 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 577 var err error 578 resp, err = c.jobClient.GetDataLabelingJob(ctx, req, settings.GRPC...) 579 return err 580 }, opts...) 581 if err != nil { 582 return nil, err 583 } 584 return resp, nil 585} 586 587func (c *jobGRPCClient) ListDataLabelingJobs(ctx context.Context, req *aiplatformpb.ListDataLabelingJobsRequest, opts ...gax.CallOption) *DataLabelingJobIterator { 588 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 589 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 590 opts = append((*c.CallOptions).ListDataLabelingJobs[0:len((*c.CallOptions).ListDataLabelingJobs):len((*c.CallOptions).ListDataLabelingJobs)], opts...) 591 it := &DataLabelingJobIterator{} 592 req = proto.Clone(req).(*aiplatformpb.ListDataLabelingJobsRequest) 593 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.DataLabelingJob, string, error) { 594 var resp *aiplatformpb.ListDataLabelingJobsResponse 595 req.PageToken = pageToken 596 if pageSize > math.MaxInt32 { 597 req.PageSize = math.MaxInt32 598 } else { 599 req.PageSize = int32(pageSize) 600 } 601 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 602 var err error 603 resp, err = c.jobClient.ListDataLabelingJobs(ctx, req, settings.GRPC...) 604 return err 605 }, opts...) 606 if err != nil { 607 return nil, "", err 608 } 609 610 it.Response = resp 611 return resp.GetDataLabelingJobs(), resp.GetNextPageToken(), nil 612 } 613 fetch := func(pageSize int, pageToken string) (string, error) { 614 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 615 if err != nil { 616 return "", err 617 } 618 it.items = append(it.items, items...) 619 return nextPageToken, nil 620 } 621 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 622 it.pageInfo.MaxSize = int(req.GetPageSize()) 623 it.pageInfo.Token = req.GetPageToken() 624 return it 625} 626 627func (c *jobGRPCClient) DeleteDataLabelingJob(ctx context.Context, req *aiplatformpb.DeleteDataLabelingJobRequest, opts ...gax.CallOption) (*DeleteDataLabelingJobOperation, error) { 628 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 629 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 630 defer cancel() 631 ctx = cctx 632 } 633 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 634 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 635 opts = append((*c.CallOptions).DeleteDataLabelingJob[0:len((*c.CallOptions).DeleteDataLabelingJob):len((*c.CallOptions).DeleteDataLabelingJob)], opts...) 636 var resp *longrunningpb.Operation 637 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 638 var err error 639 resp, err = c.jobClient.DeleteDataLabelingJob(ctx, req, settings.GRPC...) 640 return err 641 }, opts...) 642 if err != nil { 643 return nil, err 644 } 645 return &DeleteDataLabelingJobOperation{ 646 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 647 }, nil 648} 649 650func (c *jobGRPCClient) CancelDataLabelingJob(ctx context.Context, req *aiplatformpb.CancelDataLabelingJobRequest, opts ...gax.CallOption) error { 651 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 652 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 653 defer cancel() 654 ctx = cctx 655 } 656 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 657 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 658 opts = append((*c.CallOptions).CancelDataLabelingJob[0:len((*c.CallOptions).CancelDataLabelingJob):len((*c.CallOptions).CancelDataLabelingJob)], opts...) 659 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 660 var err error 661 _, err = c.jobClient.CancelDataLabelingJob(ctx, req, settings.GRPC...) 662 return err 663 }, opts...) 664 return err 665} 666 667func (c *jobGRPCClient) CreateHyperparameterTuningJob(ctx context.Context, req *aiplatformpb.CreateHyperparameterTuningJobRequest, opts ...gax.CallOption) (*aiplatformpb.HyperparameterTuningJob, error) { 668 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 669 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 670 defer cancel() 671 ctx = cctx 672 } 673 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 674 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 675 opts = append((*c.CallOptions).CreateHyperparameterTuningJob[0:len((*c.CallOptions).CreateHyperparameterTuningJob):len((*c.CallOptions).CreateHyperparameterTuningJob)], opts...) 676 var resp *aiplatformpb.HyperparameterTuningJob 677 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 678 var err error 679 resp, err = c.jobClient.CreateHyperparameterTuningJob(ctx, req, settings.GRPC...) 680 return err 681 }, opts...) 682 if err != nil { 683 return nil, err 684 } 685 return resp, nil 686} 687 688func (c *jobGRPCClient) GetHyperparameterTuningJob(ctx context.Context, req *aiplatformpb.GetHyperparameterTuningJobRequest, opts ...gax.CallOption) (*aiplatformpb.HyperparameterTuningJob, error) { 689 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 690 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 691 defer cancel() 692 ctx = cctx 693 } 694 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 695 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 696 opts = append((*c.CallOptions).GetHyperparameterTuningJob[0:len((*c.CallOptions).GetHyperparameterTuningJob):len((*c.CallOptions).GetHyperparameterTuningJob)], opts...) 697 var resp *aiplatformpb.HyperparameterTuningJob 698 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 699 var err error 700 resp, err = c.jobClient.GetHyperparameterTuningJob(ctx, req, settings.GRPC...) 701 return err 702 }, opts...) 703 if err != nil { 704 return nil, err 705 } 706 return resp, nil 707} 708 709func (c *jobGRPCClient) ListHyperparameterTuningJobs(ctx context.Context, req *aiplatformpb.ListHyperparameterTuningJobsRequest, opts ...gax.CallOption) *HyperparameterTuningJobIterator { 710 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 711 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 712 opts = append((*c.CallOptions).ListHyperparameterTuningJobs[0:len((*c.CallOptions).ListHyperparameterTuningJobs):len((*c.CallOptions).ListHyperparameterTuningJobs)], opts...) 713 it := &HyperparameterTuningJobIterator{} 714 req = proto.Clone(req).(*aiplatformpb.ListHyperparameterTuningJobsRequest) 715 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.HyperparameterTuningJob, string, error) { 716 var resp *aiplatformpb.ListHyperparameterTuningJobsResponse 717 req.PageToken = pageToken 718 if pageSize > math.MaxInt32 { 719 req.PageSize = math.MaxInt32 720 } else { 721 req.PageSize = int32(pageSize) 722 } 723 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 724 var err error 725 resp, err = c.jobClient.ListHyperparameterTuningJobs(ctx, req, settings.GRPC...) 726 return err 727 }, opts...) 728 if err != nil { 729 return nil, "", err 730 } 731 732 it.Response = resp 733 return resp.GetHyperparameterTuningJobs(), resp.GetNextPageToken(), nil 734 } 735 fetch := func(pageSize int, pageToken string) (string, error) { 736 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 737 if err != nil { 738 return "", err 739 } 740 it.items = append(it.items, items...) 741 return nextPageToken, nil 742 } 743 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 744 it.pageInfo.MaxSize = int(req.GetPageSize()) 745 it.pageInfo.Token = req.GetPageToken() 746 return it 747} 748 749func (c *jobGRPCClient) DeleteHyperparameterTuningJob(ctx context.Context, req *aiplatformpb.DeleteHyperparameterTuningJobRequest, opts ...gax.CallOption) (*DeleteHyperparameterTuningJobOperation, error) { 750 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 751 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 752 defer cancel() 753 ctx = cctx 754 } 755 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 756 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 757 opts = append((*c.CallOptions).DeleteHyperparameterTuningJob[0:len((*c.CallOptions).DeleteHyperparameterTuningJob):len((*c.CallOptions).DeleteHyperparameterTuningJob)], opts...) 758 var resp *longrunningpb.Operation 759 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 760 var err error 761 resp, err = c.jobClient.DeleteHyperparameterTuningJob(ctx, req, settings.GRPC...) 762 return err 763 }, opts...) 764 if err != nil { 765 return nil, err 766 } 767 return &DeleteHyperparameterTuningJobOperation{ 768 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 769 }, nil 770} 771 772func (c *jobGRPCClient) CancelHyperparameterTuningJob(ctx context.Context, req *aiplatformpb.CancelHyperparameterTuningJobRequest, opts ...gax.CallOption) error { 773 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 774 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 775 defer cancel() 776 ctx = cctx 777 } 778 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 779 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 780 opts = append((*c.CallOptions).CancelHyperparameterTuningJob[0:len((*c.CallOptions).CancelHyperparameterTuningJob):len((*c.CallOptions).CancelHyperparameterTuningJob)], opts...) 781 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 782 var err error 783 _, err = c.jobClient.CancelHyperparameterTuningJob(ctx, req, settings.GRPC...) 784 return err 785 }, opts...) 786 return err 787} 788 789func (c *jobGRPCClient) CreateBatchPredictionJob(ctx context.Context, req *aiplatformpb.CreateBatchPredictionJobRequest, opts ...gax.CallOption) (*aiplatformpb.BatchPredictionJob, error) { 790 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 791 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 792 defer cancel() 793 ctx = cctx 794 } 795 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 796 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 797 opts = append((*c.CallOptions).CreateBatchPredictionJob[0:len((*c.CallOptions).CreateBatchPredictionJob):len((*c.CallOptions).CreateBatchPredictionJob)], opts...) 798 var resp *aiplatformpb.BatchPredictionJob 799 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 800 var err error 801 resp, err = c.jobClient.CreateBatchPredictionJob(ctx, req, settings.GRPC...) 802 return err 803 }, opts...) 804 if err != nil { 805 return nil, err 806 } 807 return resp, nil 808} 809 810func (c *jobGRPCClient) GetBatchPredictionJob(ctx context.Context, req *aiplatformpb.GetBatchPredictionJobRequest, opts ...gax.CallOption) (*aiplatformpb.BatchPredictionJob, error) { 811 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 812 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 813 defer cancel() 814 ctx = cctx 815 } 816 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 817 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 818 opts = append((*c.CallOptions).GetBatchPredictionJob[0:len((*c.CallOptions).GetBatchPredictionJob):len((*c.CallOptions).GetBatchPredictionJob)], opts...) 819 var resp *aiplatformpb.BatchPredictionJob 820 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 821 var err error 822 resp, err = c.jobClient.GetBatchPredictionJob(ctx, req, settings.GRPC...) 823 return err 824 }, opts...) 825 if err != nil { 826 return nil, err 827 } 828 return resp, nil 829} 830 831func (c *jobGRPCClient) ListBatchPredictionJobs(ctx context.Context, req *aiplatformpb.ListBatchPredictionJobsRequest, opts ...gax.CallOption) *BatchPredictionJobIterator { 832 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 833 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 834 opts = append((*c.CallOptions).ListBatchPredictionJobs[0:len((*c.CallOptions).ListBatchPredictionJobs):len((*c.CallOptions).ListBatchPredictionJobs)], opts...) 835 it := &BatchPredictionJobIterator{} 836 req = proto.Clone(req).(*aiplatformpb.ListBatchPredictionJobsRequest) 837 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.BatchPredictionJob, string, error) { 838 var resp *aiplatformpb.ListBatchPredictionJobsResponse 839 req.PageToken = pageToken 840 if pageSize > math.MaxInt32 { 841 req.PageSize = math.MaxInt32 842 } else { 843 req.PageSize = int32(pageSize) 844 } 845 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 846 var err error 847 resp, err = c.jobClient.ListBatchPredictionJobs(ctx, req, settings.GRPC...) 848 return err 849 }, opts...) 850 if err != nil { 851 return nil, "", err 852 } 853 854 it.Response = resp 855 return resp.GetBatchPredictionJobs(), resp.GetNextPageToken(), nil 856 } 857 fetch := func(pageSize int, pageToken string) (string, error) { 858 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 859 if err != nil { 860 return "", err 861 } 862 it.items = append(it.items, items...) 863 return nextPageToken, nil 864 } 865 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 866 it.pageInfo.MaxSize = int(req.GetPageSize()) 867 it.pageInfo.Token = req.GetPageToken() 868 return it 869} 870 871func (c *jobGRPCClient) DeleteBatchPredictionJob(ctx context.Context, req *aiplatformpb.DeleteBatchPredictionJobRequest, opts ...gax.CallOption) (*DeleteBatchPredictionJobOperation, error) { 872 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 873 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 874 defer cancel() 875 ctx = cctx 876 } 877 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 878 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 879 opts = append((*c.CallOptions).DeleteBatchPredictionJob[0:len((*c.CallOptions).DeleteBatchPredictionJob):len((*c.CallOptions).DeleteBatchPredictionJob)], opts...) 880 var resp *longrunningpb.Operation 881 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 882 var err error 883 resp, err = c.jobClient.DeleteBatchPredictionJob(ctx, req, settings.GRPC...) 884 return err 885 }, opts...) 886 if err != nil { 887 return nil, err 888 } 889 return &DeleteBatchPredictionJobOperation{ 890 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 891 }, nil 892} 893 894func (c *jobGRPCClient) CancelBatchPredictionJob(ctx context.Context, req *aiplatformpb.CancelBatchPredictionJobRequest, opts ...gax.CallOption) error { 895 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 896 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 897 defer cancel() 898 ctx = cctx 899 } 900 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 901 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 902 opts = append((*c.CallOptions).CancelBatchPredictionJob[0:len((*c.CallOptions).CancelBatchPredictionJob):len((*c.CallOptions).CancelBatchPredictionJob)], opts...) 903 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 904 var err error 905 _, err = c.jobClient.CancelBatchPredictionJob(ctx, req, settings.GRPC...) 906 return err 907 }, opts...) 908 return err 909} 910 911// DeleteBatchPredictionJobOperation manages a long-running operation from DeleteBatchPredictionJob. 912type DeleteBatchPredictionJobOperation struct { 913 lro *longrunning.Operation 914} 915 916// DeleteBatchPredictionJobOperation returns a new DeleteBatchPredictionJobOperation from a given name. 917// The name must be that of a previously created DeleteBatchPredictionJobOperation, possibly from a different process. 918func (c *jobGRPCClient) DeleteBatchPredictionJobOperation(name string) *DeleteBatchPredictionJobOperation { 919 return &DeleteBatchPredictionJobOperation{ 920 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 921 } 922} 923 924// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 925// 926// See documentation of Poll for error-handling information. 927func (op *DeleteBatchPredictionJobOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 928 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 929} 930 931// Poll fetches the latest state of the long-running operation. 932// 933// Poll also fetches the latest metadata, which can be retrieved by Metadata. 934// 935// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 936// the operation has completed with failure, the error is returned and op.Done will return true. 937// If Poll succeeds and the operation has completed successfully, 938// op.Done will return true, and the response of the operation is returned. 939// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 940func (op *DeleteBatchPredictionJobOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 941 return op.lro.Poll(ctx, nil, opts...) 942} 943 944// Metadata returns metadata associated with the long-running operation. 945// Metadata itself does not contact the server, but Poll does. 946// To get the latest metadata, call this method after a successful call to Poll. 947// If the metadata is not available, the returned metadata and error are both nil. 948func (op *DeleteBatchPredictionJobOperation) Metadata() (*aiplatformpb.DeleteOperationMetadata, error) { 949 var meta aiplatformpb.DeleteOperationMetadata 950 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 951 return nil, nil 952 } else if err != nil { 953 return nil, err 954 } 955 return &meta, nil 956} 957 958// Done reports whether the long-running operation has completed. 959func (op *DeleteBatchPredictionJobOperation) Done() bool { 960 return op.lro.Done() 961} 962 963// Name returns the name of the long-running operation. 964// The name is assigned by the server and is unique within the service from which the operation is created. 965func (op *DeleteBatchPredictionJobOperation) Name() string { 966 return op.lro.Name() 967} 968 969// DeleteCustomJobOperation manages a long-running operation from DeleteCustomJob. 970type DeleteCustomJobOperation struct { 971 lro *longrunning.Operation 972} 973 974// DeleteCustomJobOperation returns a new DeleteCustomJobOperation from a given name. 975// The name must be that of a previously created DeleteCustomJobOperation, possibly from a different process. 976func (c *jobGRPCClient) DeleteCustomJobOperation(name string) *DeleteCustomJobOperation { 977 return &DeleteCustomJobOperation{ 978 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 979 } 980} 981 982// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 983// 984// See documentation of Poll for error-handling information. 985func (op *DeleteCustomJobOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 986 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 987} 988 989// Poll fetches the latest state of the long-running operation. 990// 991// Poll also fetches the latest metadata, which can be retrieved by Metadata. 992// 993// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 994// the operation has completed with failure, the error is returned and op.Done will return true. 995// If Poll succeeds and the operation has completed successfully, 996// op.Done will return true, and the response of the operation is returned. 997// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 998func (op *DeleteCustomJobOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 999 return op.lro.Poll(ctx, nil, opts...) 1000} 1001 1002// Metadata returns metadata associated with the long-running operation. 1003// Metadata itself does not contact the server, but Poll does. 1004// To get the latest metadata, call this method after a successful call to Poll. 1005// If the metadata is not available, the returned metadata and error are both nil. 1006func (op *DeleteCustomJobOperation) Metadata() (*aiplatformpb.DeleteOperationMetadata, error) { 1007 var meta aiplatformpb.DeleteOperationMetadata 1008 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 1009 return nil, nil 1010 } else if err != nil { 1011 return nil, err 1012 } 1013 return &meta, nil 1014} 1015 1016// Done reports whether the long-running operation has completed. 1017func (op *DeleteCustomJobOperation) Done() bool { 1018 return op.lro.Done() 1019} 1020 1021// Name returns the name of the long-running operation. 1022// The name is assigned by the server and is unique within the service from which the operation is created. 1023func (op *DeleteCustomJobOperation) Name() string { 1024 return op.lro.Name() 1025} 1026 1027// DeleteDataLabelingJobOperation manages a long-running operation from DeleteDataLabelingJob. 1028type DeleteDataLabelingJobOperation struct { 1029 lro *longrunning.Operation 1030} 1031 1032// DeleteDataLabelingJobOperation returns a new DeleteDataLabelingJobOperation from a given name. 1033// The name must be that of a previously created DeleteDataLabelingJobOperation, possibly from a different process. 1034func (c *jobGRPCClient) DeleteDataLabelingJobOperation(name string) *DeleteDataLabelingJobOperation { 1035 return &DeleteDataLabelingJobOperation{ 1036 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1037 } 1038} 1039 1040// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 1041// 1042// See documentation of Poll for error-handling information. 1043func (op *DeleteDataLabelingJobOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 1044 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 1045} 1046 1047// Poll fetches the latest state of the long-running operation. 1048// 1049// Poll also fetches the latest metadata, which can be retrieved by Metadata. 1050// 1051// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 1052// the operation has completed with failure, the error is returned and op.Done will return true. 1053// If Poll succeeds and the operation has completed successfully, 1054// op.Done will return true, and the response of the operation is returned. 1055// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 1056func (op *DeleteDataLabelingJobOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 1057 return op.lro.Poll(ctx, nil, opts...) 1058} 1059 1060// Metadata returns metadata associated with the long-running operation. 1061// Metadata itself does not contact the server, but Poll does. 1062// To get the latest metadata, call this method after a successful call to Poll. 1063// If the metadata is not available, the returned metadata and error are both nil. 1064func (op *DeleteDataLabelingJobOperation) Metadata() (*aiplatformpb.DeleteOperationMetadata, error) { 1065 var meta aiplatformpb.DeleteOperationMetadata 1066 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 1067 return nil, nil 1068 } else if err != nil { 1069 return nil, err 1070 } 1071 return &meta, nil 1072} 1073 1074// Done reports whether the long-running operation has completed. 1075func (op *DeleteDataLabelingJobOperation) Done() bool { 1076 return op.lro.Done() 1077} 1078 1079// Name returns the name of the long-running operation. 1080// The name is assigned by the server and is unique within the service from which the operation is created. 1081func (op *DeleteDataLabelingJobOperation) Name() string { 1082 return op.lro.Name() 1083} 1084 1085// DeleteHyperparameterTuningJobOperation manages a long-running operation from DeleteHyperparameterTuningJob. 1086type DeleteHyperparameterTuningJobOperation struct { 1087 lro *longrunning.Operation 1088} 1089 1090// DeleteHyperparameterTuningJobOperation returns a new DeleteHyperparameterTuningJobOperation from a given name. 1091// The name must be that of a previously created DeleteHyperparameterTuningJobOperation, possibly from a different process. 1092func (c *jobGRPCClient) DeleteHyperparameterTuningJobOperation(name string) *DeleteHyperparameterTuningJobOperation { 1093 return &DeleteHyperparameterTuningJobOperation{ 1094 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1095 } 1096} 1097 1098// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 1099// 1100// See documentation of Poll for error-handling information. 1101func (op *DeleteHyperparameterTuningJobOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 1102 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 1103} 1104 1105// Poll fetches the latest state of the long-running operation. 1106// 1107// Poll also fetches the latest metadata, which can be retrieved by Metadata. 1108// 1109// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 1110// the operation has completed with failure, the error is returned and op.Done will return true. 1111// If Poll succeeds and the operation has completed successfully, 1112// op.Done will return true, and the response of the operation is returned. 1113// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 1114func (op *DeleteHyperparameterTuningJobOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 1115 return op.lro.Poll(ctx, nil, opts...) 1116} 1117 1118// Metadata returns metadata associated with the long-running operation. 1119// Metadata itself does not contact the server, but Poll does. 1120// To get the latest metadata, call this method after a successful call to Poll. 1121// If the metadata is not available, the returned metadata and error are both nil. 1122func (op *DeleteHyperparameterTuningJobOperation) Metadata() (*aiplatformpb.DeleteOperationMetadata, error) { 1123 var meta aiplatformpb.DeleteOperationMetadata 1124 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 1125 return nil, nil 1126 } else if err != nil { 1127 return nil, err 1128 } 1129 return &meta, nil 1130} 1131 1132// Done reports whether the long-running operation has completed. 1133func (op *DeleteHyperparameterTuningJobOperation) Done() bool { 1134 return op.lro.Done() 1135} 1136 1137// Name returns the name of the long-running operation. 1138// The name is assigned by the server and is unique within the service from which the operation is created. 1139func (op *DeleteHyperparameterTuningJobOperation) Name() string { 1140 return op.lro.Name() 1141} 1142 1143// BatchPredictionJobIterator manages a stream of *aiplatformpb.BatchPredictionJob. 1144type BatchPredictionJobIterator struct { 1145 items []*aiplatformpb.BatchPredictionJob 1146 pageInfo *iterator.PageInfo 1147 nextFunc func() error 1148 1149 // Response is the raw response for the current page. 1150 // It must be cast to the RPC response type. 1151 // Calling Next() or InternalFetch() updates this value. 1152 Response interface{} 1153 1154 // InternalFetch is for use by the Google Cloud Libraries only. 1155 // It is not part of the stable interface of this package. 1156 // 1157 // InternalFetch returns results from a single call to the underlying RPC. 1158 // The number of results is no greater than pageSize. 1159 // If there are no more results, nextPageToken is empty and err is nil. 1160 InternalFetch func(pageSize int, pageToken string) (results []*aiplatformpb.BatchPredictionJob, nextPageToken string, err error) 1161} 1162 1163// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 1164func (it *BatchPredictionJobIterator) PageInfo() *iterator.PageInfo { 1165 return it.pageInfo 1166} 1167 1168// Next returns the next result. Its second return value is iterator.Done if there are no more 1169// results. Once Next returns Done, all subsequent calls will return Done. 1170func (it *BatchPredictionJobIterator) Next() (*aiplatformpb.BatchPredictionJob, error) { 1171 var item *aiplatformpb.BatchPredictionJob 1172 if err := it.nextFunc(); err != nil { 1173 return item, err 1174 } 1175 item = it.items[0] 1176 it.items = it.items[1:] 1177 return item, nil 1178} 1179 1180func (it *BatchPredictionJobIterator) bufLen() int { 1181 return len(it.items) 1182} 1183 1184func (it *BatchPredictionJobIterator) takeBuf() interface{} { 1185 b := it.items 1186 it.items = nil 1187 return b 1188} 1189 1190// CustomJobIterator manages a stream of *aiplatformpb.CustomJob. 1191type CustomJobIterator struct { 1192 items []*aiplatformpb.CustomJob 1193 pageInfo *iterator.PageInfo 1194 nextFunc func() error 1195 1196 // Response is the raw response for the current page. 1197 // It must be cast to the RPC response type. 1198 // Calling Next() or InternalFetch() updates this value. 1199 Response interface{} 1200 1201 // InternalFetch is for use by the Google Cloud Libraries only. 1202 // It is not part of the stable interface of this package. 1203 // 1204 // InternalFetch returns results from a single call to the underlying RPC. 1205 // The number of results is no greater than pageSize. 1206 // If there are no more results, nextPageToken is empty and err is nil. 1207 InternalFetch func(pageSize int, pageToken string) (results []*aiplatformpb.CustomJob, nextPageToken string, err error) 1208} 1209 1210// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 1211func (it *CustomJobIterator) PageInfo() *iterator.PageInfo { 1212 return it.pageInfo 1213} 1214 1215// Next returns the next result. Its second return value is iterator.Done if there are no more 1216// results. Once Next returns Done, all subsequent calls will return Done. 1217func (it *CustomJobIterator) Next() (*aiplatformpb.CustomJob, error) { 1218 var item *aiplatformpb.CustomJob 1219 if err := it.nextFunc(); err != nil { 1220 return item, err 1221 } 1222 item = it.items[0] 1223 it.items = it.items[1:] 1224 return item, nil 1225} 1226 1227func (it *CustomJobIterator) bufLen() int { 1228 return len(it.items) 1229} 1230 1231func (it *CustomJobIterator) takeBuf() interface{} { 1232 b := it.items 1233 it.items = nil 1234 return b 1235} 1236 1237// DataLabelingJobIterator manages a stream of *aiplatformpb.DataLabelingJob. 1238type DataLabelingJobIterator struct { 1239 items []*aiplatformpb.DataLabelingJob 1240 pageInfo *iterator.PageInfo 1241 nextFunc func() error 1242 1243 // Response is the raw response for the current page. 1244 // It must be cast to the RPC response type. 1245 // Calling Next() or InternalFetch() updates this value. 1246 Response interface{} 1247 1248 // InternalFetch is for use by the Google Cloud Libraries only. 1249 // It is not part of the stable interface of this package. 1250 // 1251 // InternalFetch returns results from a single call to the underlying RPC. 1252 // The number of results is no greater than pageSize. 1253 // If there are no more results, nextPageToken is empty and err is nil. 1254 InternalFetch func(pageSize int, pageToken string) (results []*aiplatformpb.DataLabelingJob, nextPageToken string, err error) 1255} 1256 1257// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 1258func (it *DataLabelingJobIterator) PageInfo() *iterator.PageInfo { 1259 return it.pageInfo 1260} 1261 1262// Next returns the next result. Its second return value is iterator.Done if there are no more 1263// results. Once Next returns Done, all subsequent calls will return Done. 1264func (it *DataLabelingJobIterator) Next() (*aiplatformpb.DataLabelingJob, error) { 1265 var item *aiplatformpb.DataLabelingJob 1266 if err := it.nextFunc(); err != nil { 1267 return item, err 1268 } 1269 item = it.items[0] 1270 it.items = it.items[1:] 1271 return item, nil 1272} 1273 1274func (it *DataLabelingJobIterator) bufLen() int { 1275 return len(it.items) 1276} 1277 1278func (it *DataLabelingJobIterator) takeBuf() interface{} { 1279 b := it.items 1280 it.items = nil 1281 return b 1282} 1283 1284// HyperparameterTuningJobIterator manages a stream of *aiplatformpb.HyperparameterTuningJob. 1285type HyperparameterTuningJobIterator struct { 1286 items []*aiplatformpb.HyperparameterTuningJob 1287 pageInfo *iterator.PageInfo 1288 nextFunc func() error 1289 1290 // Response is the raw response for the current page. 1291 // It must be cast to the RPC response type. 1292 // Calling Next() or InternalFetch() updates this value. 1293 Response interface{} 1294 1295 // InternalFetch is for use by the Google Cloud Libraries only. 1296 // It is not part of the stable interface of this package. 1297 // 1298 // InternalFetch returns results from a single call to the underlying RPC. 1299 // The number of results is no greater than pageSize. 1300 // If there are no more results, nextPageToken is empty and err is nil. 1301 InternalFetch func(pageSize int, pageToken string) (results []*aiplatformpb.HyperparameterTuningJob, nextPageToken string, err error) 1302} 1303 1304// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 1305func (it *HyperparameterTuningJobIterator) PageInfo() *iterator.PageInfo { 1306 return it.pageInfo 1307} 1308 1309// Next returns the next result. Its second return value is iterator.Done if there are no more 1310// results. Once Next returns Done, all subsequent calls will return Done. 1311func (it *HyperparameterTuningJobIterator) Next() (*aiplatformpb.HyperparameterTuningJob, error) { 1312 var item *aiplatformpb.HyperparameterTuningJob 1313 if err := it.nextFunc(); err != nil { 1314 return item, err 1315 } 1316 item = it.items[0] 1317 it.items = it.items[1:] 1318 return item, nil 1319} 1320 1321func (it *HyperparameterTuningJobIterator) bufLen() int { 1322 return len(it.items) 1323} 1324 1325func (it *HyperparameterTuningJobIterator) takeBuf() interface{} { 1326 b := it.items 1327 it.items = nil 1328 return b 1329} 1330