cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/pipeline_client.go (about) 1 // Copyright 2025 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 17 package aiplatform 18 19 import ( 20 "bytes" 21 "context" 22 "fmt" 23 "log/slog" 24 "math" 25 "net/http" 26 "net/url" 27 "time" 28 29 aiplatformpb "cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb" 30 iampb "cloud.google.com/go/iam/apiv1/iampb" 31 "cloud.google.com/go/longrunning" 32 lroauto "cloud.google.com/go/longrunning/autogen" 33 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" 34 gax "github.com/googleapis/gax-go/v2" 35 "google.golang.org/api/iterator" 36 "google.golang.org/api/option" 37 "google.golang.org/api/option/internaloption" 38 gtransport "google.golang.org/api/transport/grpc" 39 httptransport "google.golang.org/api/transport/http" 40 locationpb "google.golang.org/genproto/googleapis/cloud/location" 41 "google.golang.org/grpc" 42 "google.golang.org/protobuf/encoding/protojson" 43 "google.golang.org/protobuf/proto" 44 ) 45 46 var newPipelineClientHook clientHook 47 48 // PipelineCallOptions contains the retry settings for each method of PipelineClient. 49 type PipelineCallOptions struct { 50 CreateTrainingPipeline []gax.CallOption 51 GetTrainingPipeline []gax.CallOption 52 ListTrainingPipelines []gax.CallOption 53 DeleteTrainingPipeline []gax.CallOption 54 CancelTrainingPipeline []gax.CallOption 55 CreatePipelineJob []gax.CallOption 56 GetPipelineJob []gax.CallOption 57 ListPipelineJobs []gax.CallOption 58 DeletePipelineJob []gax.CallOption 59 BatchDeletePipelineJobs []gax.CallOption 60 CancelPipelineJob []gax.CallOption 61 BatchCancelPipelineJobs []gax.CallOption 62 GetLocation []gax.CallOption 63 ListLocations []gax.CallOption 64 GetIamPolicy []gax.CallOption 65 SetIamPolicy []gax.CallOption 66 TestIamPermissions []gax.CallOption 67 CancelOperation []gax.CallOption 68 DeleteOperation []gax.CallOption 69 GetOperation []gax.CallOption 70 ListOperations []gax.CallOption 71 WaitOperation []gax.CallOption 72 } 73 74 func defaultPipelineGRPCClientOptions() []option.ClientOption { 75 return []option.ClientOption{ 76 internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"), 77 internaloption.WithDefaultEndpointTemplate("aiplatform.UNIVERSE_DOMAIN:443"), 78 internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), 79 internaloption.WithDefaultUniverseDomain("googleapis.com"), 80 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 81 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 82 internaloption.EnableJwtWithScope(), 83 internaloption.EnableNewAuthLibrary(), 84 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 85 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 86 } 87 } 88 89 func defaultPipelineCallOptions() *PipelineCallOptions { 90 return &PipelineCallOptions{ 91 CreateTrainingPipeline: []gax.CallOption{ 92 gax.WithTimeout(5000 * time.Millisecond), 93 }, 94 GetTrainingPipeline: []gax.CallOption{ 95 gax.WithTimeout(5000 * time.Millisecond), 96 }, 97 ListTrainingPipelines: []gax.CallOption{ 98 gax.WithTimeout(5000 * time.Millisecond), 99 }, 100 DeleteTrainingPipeline: []gax.CallOption{ 101 gax.WithTimeout(5000 * time.Millisecond), 102 }, 103 CancelTrainingPipeline: []gax.CallOption{ 104 gax.WithTimeout(5000 * time.Millisecond), 105 }, 106 CreatePipelineJob: []gax.CallOption{}, 107 GetPipelineJob: []gax.CallOption{}, 108 ListPipelineJobs: []gax.CallOption{}, 109 DeletePipelineJob: []gax.CallOption{}, 110 BatchDeletePipelineJobs: []gax.CallOption{}, 111 CancelPipelineJob: []gax.CallOption{}, 112 BatchCancelPipelineJobs: []gax.CallOption{}, 113 GetLocation: []gax.CallOption{}, 114 ListLocations: []gax.CallOption{}, 115 GetIamPolicy: []gax.CallOption{}, 116 SetIamPolicy: []gax.CallOption{}, 117 TestIamPermissions: []gax.CallOption{}, 118 CancelOperation: []gax.CallOption{}, 119 DeleteOperation: []gax.CallOption{}, 120 GetOperation: []gax.CallOption{}, 121 ListOperations: []gax.CallOption{}, 122 WaitOperation: []gax.CallOption{}, 123 } 124 } 125 126 func defaultPipelineRESTCallOptions() *PipelineCallOptions { 127 return &PipelineCallOptions{ 128 CreateTrainingPipeline: []gax.CallOption{ 129 gax.WithTimeout(5000 * time.Millisecond), 130 }, 131 GetTrainingPipeline: []gax.CallOption{ 132 gax.WithTimeout(5000 * time.Millisecond), 133 }, 134 ListTrainingPipelines: []gax.CallOption{ 135 gax.WithTimeout(5000 * time.Millisecond), 136 }, 137 DeleteTrainingPipeline: []gax.CallOption{ 138 gax.WithTimeout(5000 * time.Millisecond), 139 }, 140 CancelTrainingPipeline: []gax.CallOption{ 141 gax.WithTimeout(5000 * time.Millisecond), 142 }, 143 CreatePipelineJob: []gax.CallOption{}, 144 GetPipelineJob: []gax.CallOption{}, 145 ListPipelineJobs: []gax.CallOption{}, 146 DeletePipelineJob: []gax.CallOption{}, 147 BatchDeletePipelineJobs: []gax.CallOption{}, 148 CancelPipelineJob: []gax.CallOption{}, 149 BatchCancelPipelineJobs: []gax.CallOption{}, 150 GetLocation: []gax.CallOption{}, 151 ListLocations: []gax.CallOption{}, 152 GetIamPolicy: []gax.CallOption{}, 153 SetIamPolicy: []gax.CallOption{}, 154 TestIamPermissions: []gax.CallOption{}, 155 CancelOperation: []gax.CallOption{}, 156 DeleteOperation: []gax.CallOption{}, 157 GetOperation: []gax.CallOption{}, 158 ListOperations: []gax.CallOption{}, 159 WaitOperation: []gax.CallOption{}, 160 } 161 } 162 163 // internalPipelineClient is an interface that defines the methods available from Vertex AI API. 164 type internalPipelineClient interface { 165 Close() error 166 setGoogleClientInfo(...string) 167 Connection() *grpc.ClientConn 168 CreateTrainingPipeline(context.Context, *aiplatformpb.CreateTrainingPipelineRequest, ...gax.CallOption) (*aiplatformpb.TrainingPipeline, error) 169 GetTrainingPipeline(context.Context, *aiplatformpb.GetTrainingPipelineRequest, ...gax.CallOption) (*aiplatformpb.TrainingPipeline, error) 170 ListTrainingPipelines(context.Context, *aiplatformpb.ListTrainingPipelinesRequest, ...gax.CallOption) *TrainingPipelineIterator 171 DeleteTrainingPipeline(context.Context, *aiplatformpb.DeleteTrainingPipelineRequest, ...gax.CallOption) (*DeleteTrainingPipelineOperation, error) 172 DeleteTrainingPipelineOperation(name string) *DeleteTrainingPipelineOperation 173 CancelTrainingPipeline(context.Context, *aiplatformpb.CancelTrainingPipelineRequest, ...gax.CallOption) error 174 CreatePipelineJob(context.Context, *aiplatformpb.CreatePipelineJobRequest, ...gax.CallOption) (*aiplatformpb.PipelineJob, error) 175 GetPipelineJob(context.Context, *aiplatformpb.GetPipelineJobRequest, ...gax.CallOption) (*aiplatformpb.PipelineJob, error) 176 ListPipelineJobs(context.Context, *aiplatformpb.ListPipelineJobsRequest, ...gax.CallOption) *PipelineJobIterator 177 DeletePipelineJob(context.Context, *aiplatformpb.DeletePipelineJobRequest, ...gax.CallOption) (*DeletePipelineJobOperation, error) 178 DeletePipelineJobOperation(name string) *DeletePipelineJobOperation 179 BatchDeletePipelineJobs(context.Context, *aiplatformpb.BatchDeletePipelineJobsRequest, ...gax.CallOption) (*BatchDeletePipelineJobsOperation, error) 180 BatchDeletePipelineJobsOperation(name string) *BatchDeletePipelineJobsOperation 181 CancelPipelineJob(context.Context, *aiplatformpb.CancelPipelineJobRequest, ...gax.CallOption) error 182 BatchCancelPipelineJobs(context.Context, *aiplatformpb.BatchCancelPipelineJobsRequest, ...gax.CallOption) (*BatchCancelPipelineJobsOperation, error) 183 BatchCancelPipelineJobsOperation(name string) *BatchCancelPipelineJobsOperation 184 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error) 185 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator 186 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 187 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 188 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) 189 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error 190 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error 191 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 192 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator 193 WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 194 } 195 196 // PipelineClient is a client for interacting with Vertex AI API. 197 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 198 // 199 // A service for creating and managing Vertex AI’s pipelines. This includes both 200 // TrainingPipeline resources (used for AutoML and custom training) and 201 // PipelineJob resources (used for Vertex AI Pipelines). 202 type PipelineClient struct { 203 // The internal transport-dependent client. 204 internalClient internalPipelineClient 205 206 // The call options for this service. 207 CallOptions *PipelineCallOptions 208 209 // LROClient is used internally to handle long-running operations. 210 // It is exposed so that its CallOptions can be modified if required. 211 // Users should not Close this client. 212 LROClient *lroauto.OperationsClient 213 } 214 215 // Wrapper methods routed to the internal client. 216 217 // Close closes the connection to the API service. The user should invoke this when 218 // the client is no longer required. 219 func (c *PipelineClient) Close() error { 220 return c.internalClient.Close() 221 } 222 223 // setGoogleClientInfo sets the name and version of the application in 224 // the `x-goog-api-client` header passed on each request. Intended for 225 // use by Google-written clients. 226 func (c *PipelineClient) setGoogleClientInfo(keyval ...string) { 227 c.internalClient.setGoogleClientInfo(keyval...) 228 } 229 230 // Connection returns a connection to the API service. 231 // 232 // Deprecated: Connections are now pooled so this method does not always 233 // return the same resource. 234 func (c *PipelineClient) Connection() *grpc.ClientConn { 235 return c.internalClient.Connection() 236 } 237 238 // CreateTrainingPipeline creates a TrainingPipeline. A created TrainingPipeline right away will be 239 // attempted to be run. 240 func (c *PipelineClient) CreateTrainingPipeline(ctx context.Context, req *aiplatformpb.CreateTrainingPipelineRequest, opts ...gax.CallOption) (*aiplatformpb.TrainingPipeline, error) { 241 return c.internalClient.CreateTrainingPipeline(ctx, req, opts...) 242 } 243 244 // GetTrainingPipeline gets a TrainingPipeline. 245 func (c *PipelineClient) GetTrainingPipeline(ctx context.Context, req *aiplatformpb.GetTrainingPipelineRequest, opts ...gax.CallOption) (*aiplatformpb.TrainingPipeline, error) { 246 return c.internalClient.GetTrainingPipeline(ctx, req, opts...) 247 } 248 249 // ListTrainingPipelines lists TrainingPipelines in a Location. 250 func (c *PipelineClient) ListTrainingPipelines(ctx context.Context, req *aiplatformpb.ListTrainingPipelinesRequest, opts ...gax.CallOption) *TrainingPipelineIterator { 251 return c.internalClient.ListTrainingPipelines(ctx, req, opts...) 252 } 253 254 // DeleteTrainingPipeline deletes a TrainingPipeline. 255 func (c *PipelineClient) DeleteTrainingPipeline(ctx context.Context, req *aiplatformpb.DeleteTrainingPipelineRequest, opts ...gax.CallOption) (*DeleteTrainingPipelineOperation, error) { 256 return c.internalClient.DeleteTrainingPipeline(ctx, req, opts...) 257 } 258 259 // DeleteTrainingPipelineOperation returns a new DeleteTrainingPipelineOperation from a given name. 260 // The name must be that of a previously created DeleteTrainingPipelineOperation, possibly from a different process. 261 func (c *PipelineClient) DeleteTrainingPipelineOperation(name string) *DeleteTrainingPipelineOperation { 262 return c.internalClient.DeleteTrainingPipelineOperation(name) 263 } 264 265 // CancelTrainingPipeline cancels a TrainingPipeline. 266 // Starts asynchronous cancellation on the TrainingPipeline. The server 267 // makes a best effort to cancel the pipeline, but success is not 268 // guaranteed. Clients can use 269 // PipelineService.GetTrainingPipeline 270 // or other methods to check whether the cancellation succeeded or whether the 271 // pipeline completed despite cancellation. On successful cancellation, 272 // the TrainingPipeline is not deleted; instead it becomes a pipeline with 273 // a 274 // TrainingPipeline.error 275 // value with a google.rpc.Status.code of 1, 276 // corresponding to Code.CANCELLED, and 277 // TrainingPipeline.state 278 // is set to CANCELLED. 279 func (c *PipelineClient) CancelTrainingPipeline(ctx context.Context, req *aiplatformpb.CancelTrainingPipelineRequest, opts ...gax.CallOption) error { 280 return c.internalClient.CancelTrainingPipeline(ctx, req, opts...) 281 } 282 283 // CreatePipelineJob creates a PipelineJob. A PipelineJob will run immediately when created. 284 func (c *PipelineClient) CreatePipelineJob(ctx context.Context, req *aiplatformpb.CreatePipelineJobRequest, opts ...gax.CallOption) (*aiplatformpb.PipelineJob, error) { 285 return c.internalClient.CreatePipelineJob(ctx, req, opts...) 286 } 287 288 // GetPipelineJob gets a PipelineJob. 289 func (c *PipelineClient) GetPipelineJob(ctx context.Context, req *aiplatformpb.GetPipelineJobRequest, opts ...gax.CallOption) (*aiplatformpb.PipelineJob, error) { 290 return c.internalClient.GetPipelineJob(ctx, req, opts...) 291 } 292 293 // ListPipelineJobs lists PipelineJobs in a Location. 294 func (c *PipelineClient) ListPipelineJobs(ctx context.Context, req *aiplatformpb.ListPipelineJobsRequest, opts ...gax.CallOption) *PipelineJobIterator { 295 return c.internalClient.ListPipelineJobs(ctx, req, opts...) 296 } 297 298 // DeletePipelineJob deletes a PipelineJob. 299 func (c *PipelineClient) DeletePipelineJob(ctx context.Context, req *aiplatformpb.DeletePipelineJobRequest, opts ...gax.CallOption) (*DeletePipelineJobOperation, error) { 300 return c.internalClient.DeletePipelineJob(ctx, req, opts...) 301 } 302 303 // DeletePipelineJobOperation returns a new DeletePipelineJobOperation from a given name. 304 // The name must be that of a previously created DeletePipelineJobOperation, possibly from a different process. 305 func (c *PipelineClient) DeletePipelineJobOperation(name string) *DeletePipelineJobOperation { 306 return c.internalClient.DeletePipelineJobOperation(name) 307 } 308 309 // BatchDeletePipelineJobs batch deletes PipelineJobs 310 // The Operation is atomic. If it fails, none of the PipelineJobs are deleted. 311 // If it succeeds, all of the PipelineJobs are deleted. 312 func (c *PipelineClient) BatchDeletePipelineJobs(ctx context.Context, req *aiplatformpb.BatchDeletePipelineJobsRequest, opts ...gax.CallOption) (*BatchDeletePipelineJobsOperation, error) { 313 return c.internalClient.BatchDeletePipelineJobs(ctx, req, opts...) 314 } 315 316 // BatchDeletePipelineJobsOperation returns a new BatchDeletePipelineJobsOperation from a given name. 317 // The name must be that of a previously created BatchDeletePipelineJobsOperation, possibly from a different process. 318 func (c *PipelineClient) BatchDeletePipelineJobsOperation(name string) *BatchDeletePipelineJobsOperation { 319 return c.internalClient.BatchDeletePipelineJobsOperation(name) 320 } 321 322 // CancelPipelineJob cancels a PipelineJob. 323 // Starts asynchronous cancellation on the PipelineJob. The server 324 // makes a best effort to cancel the pipeline, but success is not 325 // guaranteed. Clients can use 326 // PipelineService.GetPipelineJob 327 // or other methods to check whether the cancellation succeeded or whether the 328 // pipeline completed despite cancellation. On successful cancellation, 329 // the PipelineJob is not deleted; instead it becomes a pipeline with 330 // a PipelineJob.error 331 // value with a google.rpc.Status.code of 1, 332 // corresponding to Code.CANCELLED, and 333 // PipelineJob.state is 334 // set to CANCELLED. 335 func (c *PipelineClient) CancelPipelineJob(ctx context.Context, req *aiplatformpb.CancelPipelineJobRequest, opts ...gax.CallOption) error { 336 return c.internalClient.CancelPipelineJob(ctx, req, opts...) 337 } 338 339 // BatchCancelPipelineJobs batch cancel PipelineJobs. 340 // Firstly the server will check if all the jobs are in non-terminal states, 341 // and skip the jobs that are already terminated. 342 // If the operation failed, none of the pipeline jobs are cancelled. 343 // The server will poll the states of all the pipeline jobs periodically 344 // to check the cancellation status. 345 // This operation will return an LRO. 346 func (c *PipelineClient) BatchCancelPipelineJobs(ctx context.Context, req *aiplatformpb.BatchCancelPipelineJobsRequest, opts ...gax.CallOption) (*BatchCancelPipelineJobsOperation, error) { 347 return c.internalClient.BatchCancelPipelineJobs(ctx, req, opts...) 348 } 349 350 // BatchCancelPipelineJobsOperation returns a new BatchCancelPipelineJobsOperation from a given name. 351 // The name must be that of a previously created BatchCancelPipelineJobsOperation, possibly from a different process. 352 func (c *PipelineClient) BatchCancelPipelineJobsOperation(name string) *BatchCancelPipelineJobsOperation { 353 return c.internalClient.BatchCancelPipelineJobsOperation(name) 354 } 355 356 // GetLocation gets information about a location. 357 func (c *PipelineClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 358 return c.internalClient.GetLocation(ctx, req, opts...) 359 } 360 361 // ListLocations lists information about the supported locations for this service. 362 func (c *PipelineClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 363 return c.internalClient.ListLocations(ctx, req, opts...) 364 } 365 366 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 367 // if the resource exists and does not have a policy set. 368 func (c *PipelineClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 369 return c.internalClient.GetIamPolicy(ctx, req, opts...) 370 } 371 372 // SetIamPolicy sets the access control policy on the specified resource. Replaces 373 // any existing policy. 374 // 375 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 376 // errors. 377 func (c *PipelineClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 378 return c.internalClient.SetIamPolicy(ctx, req, opts...) 379 } 380 381 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 382 // resource does not exist, this will return an empty set of 383 // permissions, not a NOT_FOUND error. 384 // 385 // Note: This operation is designed to be used for building 386 // permission-aware UIs and command-line tools, not for authorization 387 // checking. This operation may “fail open” without warning. 388 func (c *PipelineClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 389 return c.internalClient.TestIamPermissions(ctx, req, opts...) 390 } 391 392 // CancelOperation is a utility method from google.longrunning.Operations. 393 func (c *PipelineClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 394 return c.internalClient.CancelOperation(ctx, req, opts...) 395 } 396 397 // DeleteOperation is a utility method from google.longrunning.Operations. 398 func (c *PipelineClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 399 return c.internalClient.DeleteOperation(ctx, req, opts...) 400 } 401 402 // GetOperation is a utility method from google.longrunning.Operations. 403 func (c *PipelineClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 404 return c.internalClient.GetOperation(ctx, req, opts...) 405 } 406 407 // ListOperations is a utility method from google.longrunning.Operations. 408 func (c *PipelineClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 409 return c.internalClient.ListOperations(ctx, req, opts...) 410 } 411 412 // WaitOperation is a utility method from google.longrunning.Operations. 413 func (c *PipelineClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 414 return c.internalClient.WaitOperation(ctx, req, opts...) 415 } 416 417 // pipelineGRPCClient is a client for interacting with Vertex AI API over gRPC transport. 418 // 419 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 420 type pipelineGRPCClient struct { 421 // Connection pool of gRPC connections to the service. 422 connPool gtransport.ConnPool 423 424 // Points back to the CallOptions field of the containing PipelineClient 425 CallOptions **PipelineCallOptions 426 427 // The gRPC API client. 428 pipelineClient aiplatformpb.PipelineServiceClient 429 430 // LROClient is used internally to handle long-running operations. 431 // It is exposed so that its CallOptions can be modified if required. 432 // Users should not Close this client. 433 LROClient **lroauto.OperationsClient 434 435 operationsClient longrunningpb.OperationsClient 436 437 iamPolicyClient iampb.IAMPolicyClient 438 439 locationsClient locationpb.LocationsClient 440 441 // The x-goog-* metadata to be sent with each request. 442 xGoogHeaders []string 443 444 logger *slog.Logger 445 } 446 447 // NewPipelineClient creates a new pipeline service client based on gRPC. 448 // The returned client must be Closed when it is done being used to clean up its underlying connections. 449 // 450 // A service for creating and managing Vertex AI’s pipelines. This includes both 451 // TrainingPipeline resources (used for AutoML and custom training) and 452 // PipelineJob resources (used for Vertex AI Pipelines). 453 func NewPipelineClient(ctx context.Context, opts ...option.ClientOption) (*PipelineClient, error) { 454 clientOpts := defaultPipelineGRPCClientOptions() 455 if newPipelineClientHook != nil { 456 hookOpts, err := newPipelineClientHook(ctx, clientHookParams{}) 457 if err != nil { 458 return nil, err 459 } 460 clientOpts = append(clientOpts, hookOpts...) 461 } 462 463 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 464 if err != nil { 465 return nil, err 466 } 467 client := PipelineClient{CallOptions: defaultPipelineCallOptions()} 468 469 c := &pipelineGRPCClient{ 470 connPool: connPool, 471 pipelineClient: aiplatformpb.NewPipelineServiceClient(connPool), 472 CallOptions: &client.CallOptions, 473 logger: internaloption.GetLogger(opts), 474 operationsClient: longrunningpb.NewOperationsClient(connPool), 475 iamPolicyClient: iampb.NewIAMPolicyClient(connPool), 476 locationsClient: locationpb.NewLocationsClient(connPool), 477 } 478 c.setGoogleClientInfo() 479 480 client.internalClient = c 481 482 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) 483 if err != nil { 484 // This error "should not happen", since we are just reusing old connection pool 485 // and never actually need to dial. 486 // If this does happen, we could leak connp. However, we cannot close conn: 487 // If the user invoked the constructor with option.WithGRPCConn, 488 // we would close a connection that's still in use. 489 // TODO: investigate error conditions. 490 return nil, err 491 } 492 c.LROClient = &client.LROClient 493 return &client, nil 494 } 495 496 // Connection returns a connection to the API service. 497 // 498 // Deprecated: Connections are now pooled so this method does not always 499 // return the same resource. 500 func (c *pipelineGRPCClient) Connection() *grpc.ClientConn { 501 return c.connPool.Conn() 502 } 503 504 // setGoogleClientInfo sets the name and version of the application in 505 // the `x-goog-api-client` header passed on each request. Intended for 506 // use by Google-written clients. 507 func (c *pipelineGRPCClient) setGoogleClientInfo(keyval ...string) { 508 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 509 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) 510 c.xGoogHeaders = []string{ 511 "x-goog-api-client", gax.XGoogHeader(kv...), 512 } 513 } 514 515 // Close closes the connection to the API service. The user should invoke this when 516 // the client is no longer required. 517 func (c *pipelineGRPCClient) Close() error { 518 return c.connPool.Close() 519 } 520 521 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 522 type pipelineRESTClient struct { 523 // The http endpoint to connect to. 524 endpoint string 525 526 // The http client. 527 httpClient *http.Client 528 529 // LROClient is used internally to handle long-running operations. 530 // It is exposed so that its CallOptions can be modified if required. 531 // Users should not Close this client. 532 LROClient **lroauto.OperationsClient 533 534 // The x-goog-* headers to be sent with each request. 535 xGoogHeaders []string 536 537 // Points back to the CallOptions field of the containing PipelineClient 538 CallOptions **PipelineCallOptions 539 540 logger *slog.Logger 541 } 542 543 // NewPipelineRESTClient creates a new pipeline service rest client. 544 // 545 // A service for creating and managing Vertex AI’s pipelines. This includes both 546 // TrainingPipeline resources (used for AutoML and custom training) and 547 // PipelineJob resources (used for Vertex AI Pipelines). 548 func NewPipelineRESTClient(ctx context.Context, opts ...option.ClientOption) (*PipelineClient, error) { 549 clientOpts := append(defaultPipelineRESTClientOptions(), opts...) 550 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) 551 if err != nil { 552 return nil, err 553 } 554 555 callOpts := defaultPipelineRESTCallOptions() 556 c := &pipelineRESTClient{ 557 endpoint: endpoint, 558 httpClient: httpClient, 559 CallOptions: &callOpts, 560 logger: internaloption.GetLogger(opts), 561 } 562 c.setGoogleClientInfo() 563 564 lroOpts := []option.ClientOption{ 565 option.WithHTTPClient(httpClient), 566 option.WithEndpoint(endpoint), 567 } 568 opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...) 569 if err != nil { 570 return nil, err 571 } 572 c.LROClient = &opClient 573 574 return &PipelineClient{internalClient: c, CallOptions: callOpts}, nil 575 } 576 577 func defaultPipelineRESTClientOptions() []option.ClientOption { 578 return []option.ClientOption{ 579 internaloption.WithDefaultEndpoint("https://aiplatform.googleapis.com"), 580 internaloption.WithDefaultEndpointTemplate("https://aiplatform.UNIVERSE_DOMAIN"), 581 internaloption.WithDefaultMTLSEndpoint("https://aiplatform.mtls.googleapis.com"), 582 internaloption.WithDefaultUniverseDomain("googleapis.com"), 583 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 584 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 585 internaloption.EnableNewAuthLibrary(), 586 } 587 } 588 589 // setGoogleClientInfo sets the name and version of the application in 590 // the `x-goog-api-client` header passed on each request. Intended for 591 // use by Google-written clients. 592 func (c *pipelineRESTClient) setGoogleClientInfo(keyval ...string) { 593 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 594 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) 595 c.xGoogHeaders = []string{ 596 "x-goog-api-client", gax.XGoogHeader(kv...), 597 } 598 } 599 600 // Close closes the connection to the API service. The user should invoke this when 601 // the client is no longer required. 602 func (c *pipelineRESTClient) Close() error { 603 // Replace httpClient with nil to force cleanup. 604 c.httpClient = nil 605 return nil 606 } 607 608 // Connection returns a connection to the API service. 609 // 610 // Deprecated: This method always returns nil. 611 func (c *pipelineRESTClient) Connection() *grpc.ClientConn { 612 return nil 613 } 614 func (c *pipelineGRPCClient) CreateTrainingPipeline(ctx context.Context, req *aiplatformpb.CreateTrainingPipelineRequest, opts ...gax.CallOption) (*aiplatformpb.TrainingPipeline, error) { 615 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 616 617 hds = append(c.xGoogHeaders, hds...) 618 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 619 opts = append((*c.CallOptions).CreateTrainingPipeline[0:len((*c.CallOptions).CreateTrainingPipeline):len((*c.CallOptions).CreateTrainingPipeline)], opts...) 620 var resp *aiplatformpb.TrainingPipeline 621 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 622 var err error 623 resp, err = executeRPC(ctx, c.pipelineClient.CreateTrainingPipeline, req, settings.GRPC, c.logger, "CreateTrainingPipeline") 624 return err 625 }, opts...) 626 if err != nil { 627 return nil, err 628 } 629 return resp, nil 630 } 631 632 func (c *pipelineGRPCClient) GetTrainingPipeline(ctx context.Context, req *aiplatformpb.GetTrainingPipelineRequest, opts ...gax.CallOption) (*aiplatformpb.TrainingPipeline, error) { 633 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 634 635 hds = append(c.xGoogHeaders, hds...) 636 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 637 opts = append((*c.CallOptions).GetTrainingPipeline[0:len((*c.CallOptions).GetTrainingPipeline):len((*c.CallOptions).GetTrainingPipeline)], opts...) 638 var resp *aiplatformpb.TrainingPipeline 639 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 640 var err error 641 resp, err = executeRPC(ctx, c.pipelineClient.GetTrainingPipeline, req, settings.GRPC, c.logger, "GetTrainingPipeline") 642 return err 643 }, opts...) 644 if err != nil { 645 return nil, err 646 } 647 return resp, nil 648 } 649 650 func (c *pipelineGRPCClient) ListTrainingPipelines(ctx context.Context, req *aiplatformpb.ListTrainingPipelinesRequest, opts ...gax.CallOption) *TrainingPipelineIterator { 651 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 652 653 hds = append(c.xGoogHeaders, hds...) 654 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 655 opts = append((*c.CallOptions).ListTrainingPipelines[0:len((*c.CallOptions).ListTrainingPipelines):len((*c.CallOptions).ListTrainingPipelines)], opts...) 656 it := &TrainingPipelineIterator{} 657 req = proto.Clone(req).(*aiplatformpb.ListTrainingPipelinesRequest) 658 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.TrainingPipeline, string, error) { 659 resp := &aiplatformpb.ListTrainingPipelinesResponse{} 660 if pageToken != "" { 661 req.PageToken = pageToken 662 } 663 if pageSize > math.MaxInt32 { 664 req.PageSize = math.MaxInt32 665 } else if pageSize != 0 { 666 req.PageSize = int32(pageSize) 667 } 668 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 669 var err error 670 resp, err = executeRPC(ctx, c.pipelineClient.ListTrainingPipelines, req, settings.GRPC, c.logger, "ListTrainingPipelines") 671 return err 672 }, opts...) 673 if err != nil { 674 return nil, "", err 675 } 676 677 it.Response = resp 678 return resp.GetTrainingPipelines(), resp.GetNextPageToken(), nil 679 } 680 fetch := func(pageSize int, pageToken string) (string, error) { 681 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 682 if err != nil { 683 return "", err 684 } 685 it.items = append(it.items, items...) 686 return nextPageToken, nil 687 } 688 689 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 690 it.pageInfo.MaxSize = int(req.GetPageSize()) 691 it.pageInfo.Token = req.GetPageToken() 692 693 return it 694 } 695 696 func (c *pipelineGRPCClient) DeleteTrainingPipeline(ctx context.Context, req *aiplatformpb.DeleteTrainingPipelineRequest, opts ...gax.CallOption) (*DeleteTrainingPipelineOperation, error) { 697 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 698 699 hds = append(c.xGoogHeaders, hds...) 700 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 701 opts = append((*c.CallOptions).DeleteTrainingPipeline[0:len((*c.CallOptions).DeleteTrainingPipeline):len((*c.CallOptions).DeleteTrainingPipeline)], opts...) 702 var resp *longrunningpb.Operation 703 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 704 var err error 705 resp, err = executeRPC(ctx, c.pipelineClient.DeleteTrainingPipeline, req, settings.GRPC, c.logger, "DeleteTrainingPipeline") 706 return err 707 }, opts...) 708 if err != nil { 709 return nil, err 710 } 711 return &DeleteTrainingPipelineOperation{ 712 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 713 }, nil 714 } 715 716 func (c *pipelineGRPCClient) CancelTrainingPipeline(ctx context.Context, req *aiplatformpb.CancelTrainingPipelineRequest, opts ...gax.CallOption) error { 717 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 718 719 hds = append(c.xGoogHeaders, hds...) 720 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 721 opts = append((*c.CallOptions).CancelTrainingPipeline[0:len((*c.CallOptions).CancelTrainingPipeline):len((*c.CallOptions).CancelTrainingPipeline)], opts...) 722 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 723 var err error 724 _, err = executeRPC(ctx, c.pipelineClient.CancelTrainingPipeline, req, settings.GRPC, c.logger, "CancelTrainingPipeline") 725 return err 726 }, opts...) 727 return err 728 } 729 730 func (c *pipelineGRPCClient) CreatePipelineJob(ctx context.Context, req *aiplatformpb.CreatePipelineJobRequest, opts ...gax.CallOption) (*aiplatformpb.PipelineJob, error) { 731 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 732 733 hds = append(c.xGoogHeaders, hds...) 734 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 735 opts = append((*c.CallOptions).CreatePipelineJob[0:len((*c.CallOptions).CreatePipelineJob):len((*c.CallOptions).CreatePipelineJob)], opts...) 736 var resp *aiplatformpb.PipelineJob 737 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 738 var err error 739 resp, err = executeRPC(ctx, c.pipelineClient.CreatePipelineJob, req, settings.GRPC, c.logger, "CreatePipelineJob") 740 return err 741 }, opts...) 742 if err != nil { 743 return nil, err 744 } 745 return resp, nil 746 } 747 748 func (c *pipelineGRPCClient) GetPipelineJob(ctx context.Context, req *aiplatformpb.GetPipelineJobRequest, opts ...gax.CallOption) (*aiplatformpb.PipelineJob, error) { 749 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 750 751 hds = append(c.xGoogHeaders, hds...) 752 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 753 opts = append((*c.CallOptions).GetPipelineJob[0:len((*c.CallOptions).GetPipelineJob):len((*c.CallOptions).GetPipelineJob)], opts...) 754 var resp *aiplatformpb.PipelineJob 755 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 756 var err error 757 resp, err = executeRPC(ctx, c.pipelineClient.GetPipelineJob, req, settings.GRPC, c.logger, "GetPipelineJob") 758 return err 759 }, opts...) 760 if err != nil { 761 return nil, err 762 } 763 return resp, nil 764 } 765 766 func (c *pipelineGRPCClient) ListPipelineJobs(ctx context.Context, req *aiplatformpb.ListPipelineJobsRequest, opts ...gax.CallOption) *PipelineJobIterator { 767 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 768 769 hds = append(c.xGoogHeaders, hds...) 770 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 771 opts = append((*c.CallOptions).ListPipelineJobs[0:len((*c.CallOptions).ListPipelineJobs):len((*c.CallOptions).ListPipelineJobs)], opts...) 772 it := &PipelineJobIterator{} 773 req = proto.Clone(req).(*aiplatformpb.ListPipelineJobsRequest) 774 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.PipelineJob, string, error) { 775 resp := &aiplatformpb.ListPipelineJobsResponse{} 776 if pageToken != "" { 777 req.PageToken = pageToken 778 } 779 if pageSize > math.MaxInt32 { 780 req.PageSize = math.MaxInt32 781 } else if pageSize != 0 { 782 req.PageSize = int32(pageSize) 783 } 784 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 785 var err error 786 resp, err = executeRPC(ctx, c.pipelineClient.ListPipelineJobs, req, settings.GRPC, c.logger, "ListPipelineJobs") 787 return err 788 }, opts...) 789 if err != nil { 790 return nil, "", err 791 } 792 793 it.Response = resp 794 return resp.GetPipelineJobs(), resp.GetNextPageToken(), nil 795 } 796 fetch := func(pageSize int, pageToken string) (string, error) { 797 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 798 if err != nil { 799 return "", err 800 } 801 it.items = append(it.items, items...) 802 return nextPageToken, nil 803 } 804 805 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 806 it.pageInfo.MaxSize = int(req.GetPageSize()) 807 it.pageInfo.Token = req.GetPageToken() 808 809 return it 810 } 811 812 func (c *pipelineGRPCClient) DeletePipelineJob(ctx context.Context, req *aiplatformpb.DeletePipelineJobRequest, opts ...gax.CallOption) (*DeletePipelineJobOperation, error) { 813 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 814 815 hds = append(c.xGoogHeaders, hds...) 816 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 817 opts = append((*c.CallOptions).DeletePipelineJob[0:len((*c.CallOptions).DeletePipelineJob):len((*c.CallOptions).DeletePipelineJob)], opts...) 818 var resp *longrunningpb.Operation 819 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 820 var err error 821 resp, err = executeRPC(ctx, c.pipelineClient.DeletePipelineJob, req, settings.GRPC, c.logger, "DeletePipelineJob") 822 return err 823 }, opts...) 824 if err != nil { 825 return nil, err 826 } 827 return &DeletePipelineJobOperation{ 828 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 829 }, nil 830 } 831 832 func (c *pipelineGRPCClient) BatchDeletePipelineJobs(ctx context.Context, req *aiplatformpb.BatchDeletePipelineJobsRequest, opts ...gax.CallOption) (*BatchDeletePipelineJobsOperation, error) { 833 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 834 835 hds = append(c.xGoogHeaders, hds...) 836 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 837 opts = append((*c.CallOptions).BatchDeletePipelineJobs[0:len((*c.CallOptions).BatchDeletePipelineJobs):len((*c.CallOptions).BatchDeletePipelineJobs)], opts...) 838 var resp *longrunningpb.Operation 839 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 840 var err error 841 resp, err = executeRPC(ctx, c.pipelineClient.BatchDeletePipelineJobs, req, settings.GRPC, c.logger, "BatchDeletePipelineJobs") 842 return err 843 }, opts...) 844 if err != nil { 845 return nil, err 846 } 847 return &BatchDeletePipelineJobsOperation{ 848 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 849 }, nil 850 } 851 852 func (c *pipelineGRPCClient) CancelPipelineJob(ctx context.Context, req *aiplatformpb.CancelPipelineJobRequest, opts ...gax.CallOption) error { 853 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 854 855 hds = append(c.xGoogHeaders, hds...) 856 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 857 opts = append((*c.CallOptions).CancelPipelineJob[0:len((*c.CallOptions).CancelPipelineJob):len((*c.CallOptions).CancelPipelineJob)], opts...) 858 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 859 var err error 860 _, err = executeRPC(ctx, c.pipelineClient.CancelPipelineJob, req, settings.GRPC, c.logger, "CancelPipelineJob") 861 return err 862 }, opts...) 863 return err 864 } 865 866 func (c *pipelineGRPCClient) BatchCancelPipelineJobs(ctx context.Context, req *aiplatformpb.BatchCancelPipelineJobsRequest, opts ...gax.CallOption) (*BatchCancelPipelineJobsOperation, error) { 867 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 868 869 hds = append(c.xGoogHeaders, hds...) 870 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 871 opts = append((*c.CallOptions).BatchCancelPipelineJobs[0:len((*c.CallOptions).BatchCancelPipelineJobs):len((*c.CallOptions).BatchCancelPipelineJobs)], opts...) 872 var resp *longrunningpb.Operation 873 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 874 var err error 875 resp, err = executeRPC(ctx, c.pipelineClient.BatchCancelPipelineJobs, req, settings.GRPC, c.logger, "BatchCancelPipelineJobs") 876 return err 877 }, opts...) 878 if err != nil { 879 return nil, err 880 } 881 return &BatchCancelPipelineJobsOperation{ 882 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 883 }, nil 884 } 885 886 func (c *pipelineGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 887 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 888 889 hds = append(c.xGoogHeaders, hds...) 890 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 891 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 892 var resp *locationpb.Location 893 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 894 var err error 895 resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation") 896 return err 897 }, opts...) 898 if err != nil { 899 return nil, err 900 } 901 return resp, nil 902 } 903 904 func (c *pipelineGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 905 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 906 907 hds = append(c.xGoogHeaders, hds...) 908 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 909 opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...) 910 it := &LocationIterator{} 911 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 912 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 913 resp := &locationpb.ListLocationsResponse{} 914 if pageToken != "" { 915 req.PageToken = pageToken 916 } 917 if pageSize > math.MaxInt32 { 918 req.PageSize = math.MaxInt32 919 } else if pageSize != 0 { 920 req.PageSize = int32(pageSize) 921 } 922 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 923 var err error 924 resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations") 925 return err 926 }, opts...) 927 if err != nil { 928 return nil, "", err 929 } 930 931 it.Response = resp 932 return resp.GetLocations(), resp.GetNextPageToken(), nil 933 } 934 fetch := func(pageSize int, pageToken string) (string, error) { 935 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 936 if err != nil { 937 return "", err 938 } 939 it.items = append(it.items, items...) 940 return nextPageToken, nil 941 } 942 943 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 944 it.pageInfo.MaxSize = int(req.GetPageSize()) 945 it.pageInfo.Token = req.GetPageToken() 946 947 return it 948 } 949 950 func (c *pipelineGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 951 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 952 953 hds = append(c.xGoogHeaders, hds...) 954 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 955 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 956 var resp *iampb.Policy 957 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 958 var err error 959 resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy") 960 return err 961 }, opts...) 962 if err != nil { 963 return nil, err 964 } 965 return resp, nil 966 } 967 968 func (c *pipelineGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 969 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 970 971 hds = append(c.xGoogHeaders, hds...) 972 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 973 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 974 var resp *iampb.Policy 975 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 976 var err error 977 resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy") 978 return err 979 }, opts...) 980 if err != nil { 981 return nil, err 982 } 983 return resp, nil 984 } 985 986 func (c *pipelineGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 987 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 988 989 hds = append(c.xGoogHeaders, hds...) 990 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 991 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 992 var resp *iampb.TestIamPermissionsResponse 993 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 994 var err error 995 resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions") 996 return err 997 }, opts...) 998 if err != nil { 999 return nil, err 1000 } 1001 return resp, nil 1002 } 1003 1004 func (c *pipelineGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 1005 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1006 1007 hds = append(c.xGoogHeaders, hds...) 1008 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 1009 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) 1010 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1011 var err error 1012 _, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation") 1013 return err 1014 }, opts...) 1015 return err 1016 } 1017 1018 func (c *pipelineGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 1019 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1020 1021 hds = append(c.xGoogHeaders, hds...) 1022 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 1023 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) 1024 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1025 var err error 1026 _, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation") 1027 return err 1028 }, opts...) 1029 return err 1030 } 1031 1032 func (c *pipelineGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 1033 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1034 1035 hds = append(c.xGoogHeaders, hds...) 1036 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 1037 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 1038 var resp *longrunningpb.Operation 1039 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1040 var err error 1041 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation") 1042 return err 1043 }, opts...) 1044 if err != nil { 1045 return nil, err 1046 } 1047 return resp, nil 1048 } 1049 1050 func (c *pipelineGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 1051 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1052 1053 hds = append(c.xGoogHeaders, hds...) 1054 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 1055 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) 1056 it := &OperationIterator{} 1057 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 1058 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 1059 resp := &longrunningpb.ListOperationsResponse{} 1060 if pageToken != "" { 1061 req.PageToken = pageToken 1062 } 1063 if pageSize > math.MaxInt32 { 1064 req.PageSize = math.MaxInt32 1065 } else if pageSize != 0 { 1066 req.PageSize = int32(pageSize) 1067 } 1068 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1069 var err error 1070 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations") 1071 return err 1072 }, opts...) 1073 if err != nil { 1074 return nil, "", err 1075 } 1076 1077 it.Response = resp 1078 return resp.GetOperations(), resp.GetNextPageToken(), nil 1079 } 1080 fetch := func(pageSize int, pageToken string) (string, error) { 1081 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1082 if err != nil { 1083 return "", err 1084 } 1085 it.items = append(it.items, items...) 1086 return nextPageToken, nil 1087 } 1088 1089 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1090 it.pageInfo.MaxSize = int(req.GetPageSize()) 1091 it.pageInfo.Token = req.GetPageToken() 1092 1093 return it 1094 } 1095 1096 func (c *pipelineGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 1097 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1098 1099 hds = append(c.xGoogHeaders, hds...) 1100 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 1101 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 1102 var resp *longrunningpb.Operation 1103 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1104 var err error 1105 resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation") 1106 return err 1107 }, opts...) 1108 if err != nil { 1109 return nil, err 1110 } 1111 return resp, nil 1112 } 1113 1114 // CreateTrainingPipeline creates a TrainingPipeline. A created TrainingPipeline right away will be 1115 // attempted to be run. 1116 func (c *pipelineRESTClient) CreateTrainingPipeline(ctx context.Context, req *aiplatformpb.CreateTrainingPipelineRequest, opts ...gax.CallOption) (*aiplatformpb.TrainingPipeline, error) { 1117 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1118 body := req.GetTrainingPipeline() 1119 jsonReq, err := m.Marshal(body) 1120 if err != nil { 1121 return nil, err 1122 } 1123 1124 baseUrl, err := url.Parse(c.endpoint) 1125 if err != nil { 1126 return nil, err 1127 } 1128 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/trainingPipelines", req.GetParent()) 1129 1130 params := url.Values{} 1131 params.Add("$alt", "json;enum-encoding=int") 1132 1133 baseUrl.RawQuery = params.Encode() 1134 1135 // Build HTTP headers from client and context metadata. 1136 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 1137 1138 hds = append(c.xGoogHeaders, hds...) 1139 hds = append(hds, "Content-Type", "application/json") 1140 headers := gax.BuildHeaders(ctx, hds...) 1141 opts = append((*c.CallOptions).CreateTrainingPipeline[0:len((*c.CallOptions).CreateTrainingPipeline):len((*c.CallOptions).CreateTrainingPipeline)], opts...) 1142 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1143 resp := &aiplatformpb.TrainingPipeline{} 1144 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1145 if settings.Path != "" { 1146 baseUrl.Path = settings.Path 1147 } 1148 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1149 if err != nil { 1150 return err 1151 } 1152 httpReq = httpReq.WithContext(ctx) 1153 httpReq.Header = headers 1154 1155 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateTrainingPipeline") 1156 if err != nil { 1157 return err 1158 } 1159 1160 if err := unm.Unmarshal(buf, resp); err != nil { 1161 return err 1162 } 1163 1164 return nil 1165 }, opts...) 1166 if e != nil { 1167 return nil, e 1168 } 1169 return resp, nil 1170 } 1171 1172 // GetTrainingPipeline gets a TrainingPipeline. 1173 func (c *pipelineRESTClient) GetTrainingPipeline(ctx context.Context, req *aiplatformpb.GetTrainingPipelineRequest, opts ...gax.CallOption) (*aiplatformpb.TrainingPipeline, error) { 1174 baseUrl, err := url.Parse(c.endpoint) 1175 if err != nil { 1176 return nil, err 1177 } 1178 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 1179 1180 params := url.Values{} 1181 params.Add("$alt", "json;enum-encoding=int") 1182 1183 baseUrl.RawQuery = params.Encode() 1184 1185 // Build HTTP headers from client and context metadata. 1186 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1187 1188 hds = append(c.xGoogHeaders, hds...) 1189 hds = append(hds, "Content-Type", "application/json") 1190 headers := gax.BuildHeaders(ctx, hds...) 1191 opts = append((*c.CallOptions).GetTrainingPipeline[0:len((*c.CallOptions).GetTrainingPipeline):len((*c.CallOptions).GetTrainingPipeline)], opts...) 1192 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1193 resp := &aiplatformpb.TrainingPipeline{} 1194 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1195 if settings.Path != "" { 1196 baseUrl.Path = settings.Path 1197 } 1198 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1199 if err != nil { 1200 return err 1201 } 1202 httpReq = httpReq.WithContext(ctx) 1203 httpReq.Header = headers 1204 1205 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetTrainingPipeline") 1206 if err != nil { 1207 return err 1208 } 1209 1210 if err := unm.Unmarshal(buf, resp); err != nil { 1211 return err 1212 } 1213 1214 return nil 1215 }, opts...) 1216 if e != nil { 1217 return nil, e 1218 } 1219 return resp, nil 1220 } 1221 1222 // ListTrainingPipelines lists TrainingPipelines in a Location. 1223 func (c *pipelineRESTClient) ListTrainingPipelines(ctx context.Context, req *aiplatformpb.ListTrainingPipelinesRequest, opts ...gax.CallOption) *TrainingPipelineIterator { 1224 it := &TrainingPipelineIterator{} 1225 req = proto.Clone(req).(*aiplatformpb.ListTrainingPipelinesRequest) 1226 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1227 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.TrainingPipeline, string, error) { 1228 resp := &aiplatformpb.ListTrainingPipelinesResponse{} 1229 if pageToken != "" { 1230 req.PageToken = pageToken 1231 } 1232 if pageSize > math.MaxInt32 { 1233 req.PageSize = math.MaxInt32 1234 } else if pageSize != 0 { 1235 req.PageSize = int32(pageSize) 1236 } 1237 baseUrl, err := url.Parse(c.endpoint) 1238 if err != nil { 1239 return nil, "", err 1240 } 1241 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/trainingPipelines", req.GetParent()) 1242 1243 params := url.Values{} 1244 params.Add("$alt", "json;enum-encoding=int") 1245 if req.GetFilter() != "" { 1246 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 1247 } 1248 if req.GetPageSize() != 0 { 1249 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1250 } 1251 if req.GetPageToken() != "" { 1252 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1253 } 1254 if req.GetReadMask() != nil { 1255 field, err := protojson.Marshal(req.GetReadMask()) 1256 if err != nil { 1257 return nil, "", err 1258 } 1259 params.Add("readMask", string(field[1:len(field)-1])) 1260 } 1261 1262 baseUrl.RawQuery = params.Encode() 1263 1264 // Build HTTP headers from client and context metadata. 1265 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1266 headers := gax.BuildHeaders(ctx, hds...) 1267 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1268 if settings.Path != "" { 1269 baseUrl.Path = settings.Path 1270 } 1271 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1272 if err != nil { 1273 return err 1274 } 1275 httpReq.Header = headers 1276 1277 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListTrainingPipelines") 1278 if err != nil { 1279 return err 1280 } 1281 if err := unm.Unmarshal(buf, resp); err != nil { 1282 return err 1283 } 1284 1285 return nil 1286 }, opts...) 1287 if e != nil { 1288 return nil, "", e 1289 } 1290 it.Response = resp 1291 return resp.GetTrainingPipelines(), resp.GetNextPageToken(), nil 1292 } 1293 1294 fetch := func(pageSize int, pageToken string) (string, error) { 1295 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1296 if err != nil { 1297 return "", err 1298 } 1299 it.items = append(it.items, items...) 1300 return nextPageToken, nil 1301 } 1302 1303 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1304 it.pageInfo.MaxSize = int(req.GetPageSize()) 1305 it.pageInfo.Token = req.GetPageToken() 1306 1307 return it 1308 } 1309 1310 // DeleteTrainingPipeline deletes a TrainingPipeline. 1311 func (c *pipelineRESTClient) DeleteTrainingPipeline(ctx context.Context, req *aiplatformpb.DeleteTrainingPipelineRequest, opts ...gax.CallOption) (*DeleteTrainingPipelineOperation, error) { 1312 baseUrl, err := url.Parse(c.endpoint) 1313 if err != nil { 1314 return nil, err 1315 } 1316 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 1317 1318 params := url.Values{} 1319 params.Add("$alt", "json;enum-encoding=int") 1320 1321 baseUrl.RawQuery = params.Encode() 1322 1323 // Build HTTP headers from client and context metadata. 1324 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1325 1326 hds = append(c.xGoogHeaders, hds...) 1327 hds = append(hds, "Content-Type", "application/json") 1328 headers := gax.BuildHeaders(ctx, hds...) 1329 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1330 resp := &longrunningpb.Operation{} 1331 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1332 if settings.Path != "" { 1333 baseUrl.Path = settings.Path 1334 } 1335 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) 1336 if err != nil { 1337 return err 1338 } 1339 httpReq = httpReq.WithContext(ctx) 1340 httpReq.Header = headers 1341 1342 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteTrainingPipeline") 1343 if err != nil { 1344 return err 1345 } 1346 if err := unm.Unmarshal(buf, resp); err != nil { 1347 return err 1348 } 1349 1350 return nil 1351 }, opts...) 1352 if e != nil { 1353 return nil, e 1354 } 1355 1356 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1357 return &DeleteTrainingPipelineOperation{ 1358 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1359 pollPath: override, 1360 }, nil 1361 } 1362 1363 // CancelTrainingPipeline cancels a TrainingPipeline. 1364 // Starts asynchronous cancellation on the TrainingPipeline. The server 1365 // makes a best effort to cancel the pipeline, but success is not 1366 // guaranteed. Clients can use 1367 // PipelineService.GetTrainingPipeline 1368 // or other methods to check whether the cancellation succeeded or whether the 1369 // pipeline completed despite cancellation. On successful cancellation, 1370 // the TrainingPipeline is not deleted; instead it becomes a pipeline with 1371 // a 1372 // TrainingPipeline.error 1373 // value with a google.rpc.Status.code of 1, 1374 // corresponding to Code.CANCELLED, and 1375 // TrainingPipeline.state 1376 // is set to CANCELLED. 1377 func (c *pipelineRESTClient) CancelTrainingPipeline(ctx context.Context, req *aiplatformpb.CancelTrainingPipelineRequest, opts ...gax.CallOption) error { 1378 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1379 jsonReq, err := m.Marshal(req) 1380 if err != nil { 1381 return err 1382 } 1383 1384 baseUrl, err := url.Parse(c.endpoint) 1385 if err != nil { 1386 return err 1387 } 1388 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:cancel", req.GetName()) 1389 1390 params := url.Values{} 1391 params.Add("$alt", "json;enum-encoding=int") 1392 1393 baseUrl.RawQuery = params.Encode() 1394 1395 // Build HTTP headers from client and context metadata. 1396 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1397 1398 hds = append(c.xGoogHeaders, hds...) 1399 hds = append(hds, "Content-Type", "application/json") 1400 headers := gax.BuildHeaders(ctx, hds...) 1401 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1402 if settings.Path != "" { 1403 baseUrl.Path = settings.Path 1404 } 1405 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1406 if err != nil { 1407 return err 1408 } 1409 httpReq = httpReq.WithContext(ctx) 1410 httpReq.Header = headers 1411 1412 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CancelTrainingPipeline") 1413 return err 1414 }, opts...) 1415 } 1416 1417 // CreatePipelineJob creates a PipelineJob. A PipelineJob will run immediately when created. 1418 func (c *pipelineRESTClient) CreatePipelineJob(ctx context.Context, req *aiplatformpb.CreatePipelineJobRequest, opts ...gax.CallOption) (*aiplatformpb.PipelineJob, error) { 1419 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1420 body := req.GetPipelineJob() 1421 jsonReq, err := m.Marshal(body) 1422 if err != nil { 1423 return nil, err 1424 } 1425 1426 baseUrl, err := url.Parse(c.endpoint) 1427 if err != nil { 1428 return nil, err 1429 } 1430 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/pipelineJobs", req.GetParent()) 1431 1432 params := url.Values{} 1433 params.Add("$alt", "json;enum-encoding=int") 1434 if req.GetPipelineJobId() != "" { 1435 params.Add("pipelineJobId", fmt.Sprintf("%v", req.GetPipelineJobId())) 1436 } 1437 1438 baseUrl.RawQuery = params.Encode() 1439 1440 // Build HTTP headers from client and context metadata. 1441 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 1442 1443 hds = append(c.xGoogHeaders, hds...) 1444 hds = append(hds, "Content-Type", "application/json") 1445 headers := gax.BuildHeaders(ctx, hds...) 1446 opts = append((*c.CallOptions).CreatePipelineJob[0:len((*c.CallOptions).CreatePipelineJob):len((*c.CallOptions).CreatePipelineJob)], opts...) 1447 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1448 resp := &aiplatformpb.PipelineJob{} 1449 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1450 if settings.Path != "" { 1451 baseUrl.Path = settings.Path 1452 } 1453 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1454 if err != nil { 1455 return err 1456 } 1457 httpReq = httpReq.WithContext(ctx) 1458 httpReq.Header = headers 1459 1460 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreatePipelineJob") 1461 if err != nil { 1462 return err 1463 } 1464 1465 if err := unm.Unmarshal(buf, resp); err != nil { 1466 return err 1467 } 1468 1469 return nil 1470 }, opts...) 1471 if e != nil { 1472 return nil, e 1473 } 1474 return resp, nil 1475 } 1476 1477 // GetPipelineJob gets a PipelineJob. 1478 func (c *pipelineRESTClient) GetPipelineJob(ctx context.Context, req *aiplatformpb.GetPipelineJobRequest, opts ...gax.CallOption) (*aiplatformpb.PipelineJob, error) { 1479 baseUrl, err := url.Parse(c.endpoint) 1480 if err != nil { 1481 return nil, err 1482 } 1483 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 1484 1485 params := url.Values{} 1486 params.Add("$alt", "json;enum-encoding=int") 1487 1488 baseUrl.RawQuery = params.Encode() 1489 1490 // Build HTTP headers from client and context metadata. 1491 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1492 1493 hds = append(c.xGoogHeaders, hds...) 1494 hds = append(hds, "Content-Type", "application/json") 1495 headers := gax.BuildHeaders(ctx, hds...) 1496 opts = append((*c.CallOptions).GetPipelineJob[0:len((*c.CallOptions).GetPipelineJob):len((*c.CallOptions).GetPipelineJob)], opts...) 1497 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1498 resp := &aiplatformpb.PipelineJob{} 1499 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1500 if settings.Path != "" { 1501 baseUrl.Path = settings.Path 1502 } 1503 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1504 if err != nil { 1505 return err 1506 } 1507 httpReq = httpReq.WithContext(ctx) 1508 httpReq.Header = headers 1509 1510 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetPipelineJob") 1511 if err != nil { 1512 return err 1513 } 1514 1515 if err := unm.Unmarshal(buf, resp); err != nil { 1516 return err 1517 } 1518 1519 return nil 1520 }, opts...) 1521 if e != nil { 1522 return nil, e 1523 } 1524 return resp, nil 1525 } 1526 1527 // ListPipelineJobs lists PipelineJobs in a Location. 1528 func (c *pipelineRESTClient) ListPipelineJobs(ctx context.Context, req *aiplatformpb.ListPipelineJobsRequest, opts ...gax.CallOption) *PipelineJobIterator { 1529 it := &PipelineJobIterator{} 1530 req = proto.Clone(req).(*aiplatformpb.ListPipelineJobsRequest) 1531 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1532 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.PipelineJob, string, error) { 1533 resp := &aiplatformpb.ListPipelineJobsResponse{} 1534 if pageToken != "" { 1535 req.PageToken = pageToken 1536 } 1537 if pageSize > math.MaxInt32 { 1538 req.PageSize = math.MaxInt32 1539 } else if pageSize != 0 { 1540 req.PageSize = int32(pageSize) 1541 } 1542 baseUrl, err := url.Parse(c.endpoint) 1543 if err != nil { 1544 return nil, "", err 1545 } 1546 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/pipelineJobs", req.GetParent()) 1547 1548 params := url.Values{} 1549 params.Add("$alt", "json;enum-encoding=int") 1550 if req.GetFilter() != "" { 1551 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 1552 } 1553 if req.GetOrderBy() != "" { 1554 params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) 1555 } 1556 if req.GetPageSize() != 0 { 1557 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1558 } 1559 if req.GetPageToken() != "" { 1560 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1561 } 1562 if req.GetReadMask() != nil { 1563 field, err := protojson.Marshal(req.GetReadMask()) 1564 if err != nil { 1565 return nil, "", err 1566 } 1567 params.Add("readMask", string(field[1:len(field)-1])) 1568 } 1569 1570 baseUrl.RawQuery = params.Encode() 1571 1572 // Build HTTP headers from client and context metadata. 1573 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1574 headers := gax.BuildHeaders(ctx, hds...) 1575 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1576 if settings.Path != "" { 1577 baseUrl.Path = settings.Path 1578 } 1579 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1580 if err != nil { 1581 return err 1582 } 1583 httpReq.Header = headers 1584 1585 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListPipelineJobs") 1586 if err != nil { 1587 return err 1588 } 1589 if err := unm.Unmarshal(buf, resp); err != nil { 1590 return err 1591 } 1592 1593 return nil 1594 }, opts...) 1595 if e != nil { 1596 return nil, "", e 1597 } 1598 it.Response = resp 1599 return resp.GetPipelineJobs(), resp.GetNextPageToken(), nil 1600 } 1601 1602 fetch := func(pageSize int, pageToken string) (string, error) { 1603 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1604 if err != nil { 1605 return "", err 1606 } 1607 it.items = append(it.items, items...) 1608 return nextPageToken, nil 1609 } 1610 1611 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1612 it.pageInfo.MaxSize = int(req.GetPageSize()) 1613 it.pageInfo.Token = req.GetPageToken() 1614 1615 return it 1616 } 1617 1618 // DeletePipelineJob deletes a PipelineJob. 1619 func (c *pipelineRESTClient) DeletePipelineJob(ctx context.Context, req *aiplatformpb.DeletePipelineJobRequest, opts ...gax.CallOption) (*DeletePipelineJobOperation, error) { 1620 baseUrl, err := url.Parse(c.endpoint) 1621 if err != nil { 1622 return nil, err 1623 } 1624 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 1625 1626 params := url.Values{} 1627 params.Add("$alt", "json;enum-encoding=int") 1628 1629 baseUrl.RawQuery = params.Encode() 1630 1631 // Build HTTP headers from client and context metadata. 1632 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1633 1634 hds = append(c.xGoogHeaders, hds...) 1635 hds = append(hds, "Content-Type", "application/json") 1636 headers := gax.BuildHeaders(ctx, hds...) 1637 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1638 resp := &longrunningpb.Operation{} 1639 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1640 if settings.Path != "" { 1641 baseUrl.Path = settings.Path 1642 } 1643 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) 1644 if err != nil { 1645 return err 1646 } 1647 httpReq = httpReq.WithContext(ctx) 1648 httpReq.Header = headers 1649 1650 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeletePipelineJob") 1651 if err != nil { 1652 return err 1653 } 1654 if err := unm.Unmarshal(buf, resp); err != nil { 1655 return err 1656 } 1657 1658 return nil 1659 }, opts...) 1660 if e != nil { 1661 return nil, e 1662 } 1663 1664 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1665 return &DeletePipelineJobOperation{ 1666 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1667 pollPath: override, 1668 }, nil 1669 } 1670 1671 // BatchDeletePipelineJobs batch deletes PipelineJobs 1672 // The Operation is atomic. If it fails, none of the PipelineJobs are deleted. 1673 // If it succeeds, all of the PipelineJobs are deleted. 1674 func (c *pipelineRESTClient) BatchDeletePipelineJobs(ctx context.Context, req *aiplatformpb.BatchDeletePipelineJobsRequest, opts ...gax.CallOption) (*BatchDeletePipelineJobsOperation, error) { 1675 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1676 jsonReq, err := m.Marshal(req) 1677 if err != nil { 1678 return nil, err 1679 } 1680 1681 baseUrl, err := url.Parse(c.endpoint) 1682 if err != nil { 1683 return nil, err 1684 } 1685 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/pipelineJobs:batchDelete", req.GetParent()) 1686 1687 params := url.Values{} 1688 params.Add("$alt", "json;enum-encoding=int") 1689 1690 baseUrl.RawQuery = params.Encode() 1691 1692 // Build HTTP headers from client and context metadata. 1693 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 1694 1695 hds = append(c.xGoogHeaders, hds...) 1696 hds = append(hds, "Content-Type", "application/json") 1697 headers := gax.BuildHeaders(ctx, hds...) 1698 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1699 resp := &longrunningpb.Operation{} 1700 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1701 if settings.Path != "" { 1702 baseUrl.Path = settings.Path 1703 } 1704 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1705 if err != nil { 1706 return err 1707 } 1708 httpReq = httpReq.WithContext(ctx) 1709 httpReq.Header = headers 1710 1711 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "BatchDeletePipelineJobs") 1712 if err != nil { 1713 return err 1714 } 1715 if err := unm.Unmarshal(buf, resp); err != nil { 1716 return err 1717 } 1718 1719 return nil 1720 }, opts...) 1721 if e != nil { 1722 return nil, e 1723 } 1724 1725 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1726 return &BatchDeletePipelineJobsOperation{ 1727 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1728 pollPath: override, 1729 }, nil 1730 } 1731 1732 // CancelPipelineJob cancels a PipelineJob. 1733 // Starts asynchronous cancellation on the PipelineJob. The server 1734 // makes a best effort to cancel the pipeline, but success is not 1735 // guaranteed. Clients can use 1736 // PipelineService.GetPipelineJob 1737 // or other methods to check whether the cancellation succeeded or whether the 1738 // pipeline completed despite cancellation. On successful cancellation, 1739 // the PipelineJob is not deleted; instead it becomes a pipeline with 1740 // a PipelineJob.error 1741 // value with a google.rpc.Status.code of 1, 1742 // corresponding to Code.CANCELLED, and 1743 // PipelineJob.state is 1744 // set to CANCELLED. 1745 func (c *pipelineRESTClient) CancelPipelineJob(ctx context.Context, req *aiplatformpb.CancelPipelineJobRequest, opts ...gax.CallOption) error { 1746 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1747 jsonReq, err := m.Marshal(req) 1748 if err != nil { 1749 return err 1750 } 1751 1752 baseUrl, err := url.Parse(c.endpoint) 1753 if err != nil { 1754 return err 1755 } 1756 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:cancel", req.GetName()) 1757 1758 params := url.Values{} 1759 params.Add("$alt", "json;enum-encoding=int") 1760 1761 baseUrl.RawQuery = params.Encode() 1762 1763 // Build HTTP headers from client and context metadata. 1764 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1765 1766 hds = append(c.xGoogHeaders, hds...) 1767 hds = append(hds, "Content-Type", "application/json") 1768 headers := gax.BuildHeaders(ctx, hds...) 1769 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1770 if settings.Path != "" { 1771 baseUrl.Path = settings.Path 1772 } 1773 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1774 if err != nil { 1775 return err 1776 } 1777 httpReq = httpReq.WithContext(ctx) 1778 httpReq.Header = headers 1779 1780 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CancelPipelineJob") 1781 return err 1782 }, opts...) 1783 } 1784 1785 // BatchCancelPipelineJobs batch cancel PipelineJobs. 1786 // Firstly the server will check if all the jobs are in non-terminal states, 1787 // and skip the jobs that are already terminated. 1788 // If the operation failed, none of the pipeline jobs are cancelled. 1789 // The server will poll the states of all the pipeline jobs periodically 1790 // to check the cancellation status. 1791 // This operation will return an LRO. 1792 func (c *pipelineRESTClient) BatchCancelPipelineJobs(ctx context.Context, req *aiplatformpb.BatchCancelPipelineJobsRequest, opts ...gax.CallOption) (*BatchCancelPipelineJobsOperation, error) { 1793 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1794 jsonReq, err := m.Marshal(req) 1795 if err != nil { 1796 return nil, err 1797 } 1798 1799 baseUrl, err := url.Parse(c.endpoint) 1800 if err != nil { 1801 return nil, err 1802 } 1803 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/pipelineJobs:batchCancel", req.GetParent()) 1804 1805 params := url.Values{} 1806 params.Add("$alt", "json;enum-encoding=int") 1807 1808 baseUrl.RawQuery = params.Encode() 1809 1810 // Build HTTP headers from client and context metadata. 1811 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 1812 1813 hds = append(c.xGoogHeaders, hds...) 1814 hds = append(hds, "Content-Type", "application/json") 1815 headers := gax.BuildHeaders(ctx, hds...) 1816 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1817 resp := &longrunningpb.Operation{} 1818 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1819 if settings.Path != "" { 1820 baseUrl.Path = settings.Path 1821 } 1822 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1823 if err != nil { 1824 return err 1825 } 1826 httpReq = httpReq.WithContext(ctx) 1827 httpReq.Header = headers 1828 1829 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "BatchCancelPipelineJobs") 1830 if err != nil { 1831 return err 1832 } 1833 if err := unm.Unmarshal(buf, resp); err != nil { 1834 return err 1835 } 1836 1837 return nil 1838 }, opts...) 1839 if e != nil { 1840 return nil, e 1841 } 1842 1843 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1844 return &BatchCancelPipelineJobsOperation{ 1845 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1846 pollPath: override, 1847 }, nil 1848 } 1849 1850 // GetLocation gets information about a location. 1851 func (c *pipelineRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 1852 baseUrl, err := url.Parse(c.endpoint) 1853 if err != nil { 1854 return nil, err 1855 } 1856 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 1857 1858 params := url.Values{} 1859 params.Add("$alt", "json;enum-encoding=int") 1860 1861 baseUrl.RawQuery = params.Encode() 1862 1863 // Build HTTP headers from client and context metadata. 1864 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1865 1866 hds = append(c.xGoogHeaders, hds...) 1867 hds = append(hds, "Content-Type", "application/json") 1868 headers := gax.BuildHeaders(ctx, hds...) 1869 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 1870 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1871 resp := &locationpb.Location{} 1872 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1873 if settings.Path != "" { 1874 baseUrl.Path = settings.Path 1875 } 1876 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1877 if err != nil { 1878 return err 1879 } 1880 httpReq = httpReq.WithContext(ctx) 1881 httpReq.Header = headers 1882 1883 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation") 1884 if err != nil { 1885 return err 1886 } 1887 1888 if err := unm.Unmarshal(buf, resp); err != nil { 1889 return err 1890 } 1891 1892 return nil 1893 }, opts...) 1894 if e != nil { 1895 return nil, e 1896 } 1897 return resp, nil 1898 } 1899 1900 // ListLocations lists information about the supported locations for this service. 1901 func (c *pipelineRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 1902 it := &LocationIterator{} 1903 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 1904 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1905 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 1906 resp := &locationpb.ListLocationsResponse{} 1907 if pageToken != "" { 1908 req.PageToken = pageToken 1909 } 1910 if pageSize > math.MaxInt32 { 1911 req.PageSize = math.MaxInt32 1912 } else if pageSize != 0 { 1913 req.PageSize = int32(pageSize) 1914 } 1915 baseUrl, err := url.Parse(c.endpoint) 1916 if err != nil { 1917 return nil, "", err 1918 } 1919 baseUrl.Path += fmt.Sprintf("/ui/%v/locations", req.GetName()) 1920 1921 params := url.Values{} 1922 params.Add("$alt", "json;enum-encoding=int") 1923 if req.GetFilter() != "" { 1924 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 1925 } 1926 if req.GetPageSize() != 0 { 1927 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1928 } 1929 if req.GetPageToken() != "" { 1930 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1931 } 1932 1933 baseUrl.RawQuery = params.Encode() 1934 1935 // Build HTTP headers from client and context metadata. 1936 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1937 headers := gax.BuildHeaders(ctx, hds...) 1938 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1939 if settings.Path != "" { 1940 baseUrl.Path = settings.Path 1941 } 1942 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1943 if err != nil { 1944 return err 1945 } 1946 httpReq.Header = headers 1947 1948 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations") 1949 if err != nil { 1950 return err 1951 } 1952 if err := unm.Unmarshal(buf, resp); err != nil { 1953 return err 1954 } 1955 1956 return nil 1957 }, opts...) 1958 if e != nil { 1959 return nil, "", e 1960 } 1961 it.Response = resp 1962 return resp.GetLocations(), resp.GetNextPageToken(), nil 1963 } 1964 1965 fetch := func(pageSize int, pageToken string) (string, error) { 1966 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1967 if err != nil { 1968 return "", err 1969 } 1970 it.items = append(it.items, items...) 1971 return nextPageToken, nil 1972 } 1973 1974 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1975 it.pageInfo.MaxSize = int(req.GetPageSize()) 1976 it.pageInfo.Token = req.GetPageToken() 1977 1978 return it 1979 } 1980 1981 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 1982 // if the resource exists and does not have a policy set. 1983 func (c *pipelineRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 1984 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1985 jsonReq, err := m.Marshal(req) 1986 if err != nil { 1987 return nil, err 1988 } 1989 1990 baseUrl, err := url.Parse(c.endpoint) 1991 if err != nil { 1992 return nil, err 1993 } 1994 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:getIamPolicy", req.GetResource()) 1995 1996 params := url.Values{} 1997 params.Add("$alt", "json;enum-encoding=int") 1998 1999 baseUrl.RawQuery = params.Encode() 2000 2001 // Build HTTP headers from client and context metadata. 2002 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 2003 2004 hds = append(c.xGoogHeaders, hds...) 2005 hds = append(hds, "Content-Type", "application/json") 2006 headers := gax.BuildHeaders(ctx, hds...) 2007 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 2008 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 2009 resp := &iampb.Policy{} 2010 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2011 if settings.Path != "" { 2012 baseUrl.Path = settings.Path 2013 } 2014 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 2015 if err != nil { 2016 return err 2017 } 2018 httpReq = httpReq.WithContext(ctx) 2019 httpReq.Header = headers 2020 2021 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "GetIamPolicy") 2022 if err != nil { 2023 return err 2024 } 2025 2026 if err := unm.Unmarshal(buf, resp); err != nil { 2027 return err 2028 } 2029 2030 return nil 2031 }, opts...) 2032 if e != nil { 2033 return nil, e 2034 } 2035 return resp, nil 2036 } 2037 2038 // SetIamPolicy sets the access control policy on the specified resource. Replaces 2039 // any existing policy. 2040 // 2041 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 2042 // errors. 2043 func (c *pipelineRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 2044 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 2045 jsonReq, err := m.Marshal(req) 2046 if err != nil { 2047 return nil, err 2048 } 2049 2050 baseUrl, err := url.Parse(c.endpoint) 2051 if err != nil { 2052 return nil, err 2053 } 2054 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:setIamPolicy", req.GetResource()) 2055 2056 params := url.Values{} 2057 params.Add("$alt", "json;enum-encoding=int") 2058 2059 baseUrl.RawQuery = params.Encode() 2060 2061 // Build HTTP headers from client and context metadata. 2062 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 2063 2064 hds = append(c.xGoogHeaders, hds...) 2065 hds = append(hds, "Content-Type", "application/json") 2066 headers := gax.BuildHeaders(ctx, hds...) 2067 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 2068 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 2069 resp := &iampb.Policy{} 2070 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2071 if settings.Path != "" { 2072 baseUrl.Path = settings.Path 2073 } 2074 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 2075 if err != nil { 2076 return err 2077 } 2078 httpReq = httpReq.WithContext(ctx) 2079 httpReq.Header = headers 2080 2081 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy") 2082 if err != nil { 2083 return err 2084 } 2085 2086 if err := unm.Unmarshal(buf, resp); err != nil { 2087 return err 2088 } 2089 2090 return nil 2091 }, opts...) 2092 if e != nil { 2093 return nil, e 2094 } 2095 return resp, nil 2096 } 2097 2098 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 2099 // resource does not exist, this will return an empty set of 2100 // permissions, not a NOT_FOUND error. 2101 // 2102 // Note: This operation is designed to be used for building 2103 // permission-aware UIs and command-line tools, not for authorization 2104 // checking. This operation may “fail open” without warning. 2105 func (c *pipelineRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 2106 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 2107 jsonReq, err := m.Marshal(req) 2108 if err != nil { 2109 return nil, err 2110 } 2111 2112 baseUrl, err := url.Parse(c.endpoint) 2113 if err != nil { 2114 return nil, err 2115 } 2116 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:testIamPermissions", req.GetResource()) 2117 2118 params := url.Values{} 2119 params.Add("$alt", "json;enum-encoding=int") 2120 2121 baseUrl.RawQuery = params.Encode() 2122 2123 // Build HTTP headers from client and context metadata. 2124 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 2125 2126 hds = append(c.xGoogHeaders, hds...) 2127 hds = append(hds, "Content-Type", "application/json") 2128 headers := gax.BuildHeaders(ctx, hds...) 2129 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 2130 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 2131 resp := &iampb.TestIamPermissionsResponse{} 2132 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2133 if settings.Path != "" { 2134 baseUrl.Path = settings.Path 2135 } 2136 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 2137 if err != nil { 2138 return err 2139 } 2140 httpReq = httpReq.WithContext(ctx) 2141 httpReq.Header = headers 2142 2143 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TestIamPermissions") 2144 if err != nil { 2145 return err 2146 } 2147 2148 if err := unm.Unmarshal(buf, resp); err != nil { 2149 return err 2150 } 2151 2152 return nil 2153 }, opts...) 2154 if e != nil { 2155 return nil, e 2156 } 2157 return resp, nil 2158 } 2159 2160 // CancelOperation is a utility method from google.longrunning.Operations. 2161 func (c *pipelineRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 2162 baseUrl, err := url.Parse(c.endpoint) 2163 if err != nil { 2164 return err 2165 } 2166 baseUrl.Path += fmt.Sprintf("/ui/%v:cancel", req.GetName()) 2167 2168 params := url.Values{} 2169 params.Add("$alt", "json;enum-encoding=int") 2170 2171 baseUrl.RawQuery = params.Encode() 2172 2173 // Build HTTP headers from client and context metadata. 2174 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 2175 2176 hds = append(c.xGoogHeaders, hds...) 2177 hds = append(hds, "Content-Type", "application/json") 2178 headers := gax.BuildHeaders(ctx, hds...) 2179 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2180 if settings.Path != "" { 2181 baseUrl.Path = settings.Path 2182 } 2183 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil) 2184 if err != nil { 2185 return err 2186 } 2187 httpReq = httpReq.WithContext(ctx) 2188 httpReq.Header = headers 2189 2190 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "CancelOperation") 2191 return err 2192 }, opts...) 2193 } 2194 2195 // DeleteOperation is a utility method from google.longrunning.Operations. 2196 func (c *pipelineRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 2197 baseUrl, err := url.Parse(c.endpoint) 2198 if err != nil { 2199 return err 2200 } 2201 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 2202 2203 params := url.Values{} 2204 params.Add("$alt", "json;enum-encoding=int") 2205 2206 baseUrl.RawQuery = params.Encode() 2207 2208 // Build HTTP headers from client and context metadata. 2209 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 2210 2211 hds = append(c.xGoogHeaders, hds...) 2212 hds = append(hds, "Content-Type", "application/json") 2213 headers := gax.BuildHeaders(ctx, hds...) 2214 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2215 if settings.Path != "" { 2216 baseUrl.Path = settings.Path 2217 } 2218 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) 2219 if err != nil { 2220 return err 2221 } 2222 httpReq = httpReq.WithContext(ctx) 2223 httpReq.Header = headers 2224 2225 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation") 2226 return err 2227 }, opts...) 2228 } 2229 2230 // GetOperation is a utility method from google.longrunning.Operations. 2231 func (c *pipelineRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 2232 baseUrl, err := url.Parse(c.endpoint) 2233 if err != nil { 2234 return nil, err 2235 } 2236 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 2237 2238 params := url.Values{} 2239 params.Add("$alt", "json;enum-encoding=int") 2240 2241 baseUrl.RawQuery = params.Encode() 2242 2243 // Build HTTP headers from client and context metadata. 2244 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 2245 2246 hds = append(c.xGoogHeaders, hds...) 2247 hds = append(hds, "Content-Type", "application/json") 2248 headers := gax.BuildHeaders(ctx, hds...) 2249 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 2250 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 2251 resp := &longrunningpb.Operation{} 2252 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2253 if settings.Path != "" { 2254 baseUrl.Path = settings.Path 2255 } 2256 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 2257 if err != nil { 2258 return err 2259 } 2260 httpReq = httpReq.WithContext(ctx) 2261 httpReq.Header = headers 2262 2263 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation") 2264 if err != nil { 2265 return err 2266 } 2267 2268 if err := unm.Unmarshal(buf, resp); err != nil { 2269 return err 2270 } 2271 2272 return nil 2273 }, opts...) 2274 if e != nil { 2275 return nil, e 2276 } 2277 return resp, nil 2278 } 2279 2280 // ListOperations is a utility method from google.longrunning.Operations. 2281 func (c *pipelineRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 2282 it := &OperationIterator{} 2283 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 2284 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 2285 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 2286 resp := &longrunningpb.ListOperationsResponse{} 2287 if pageToken != "" { 2288 req.PageToken = pageToken 2289 } 2290 if pageSize > math.MaxInt32 { 2291 req.PageSize = math.MaxInt32 2292 } else if pageSize != 0 { 2293 req.PageSize = int32(pageSize) 2294 } 2295 baseUrl, err := url.Parse(c.endpoint) 2296 if err != nil { 2297 return nil, "", err 2298 } 2299 baseUrl.Path += fmt.Sprintf("/ui/%v/operations", req.GetName()) 2300 2301 params := url.Values{} 2302 params.Add("$alt", "json;enum-encoding=int") 2303 if req.GetFilter() != "" { 2304 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 2305 } 2306 if req.GetPageSize() != 0 { 2307 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 2308 } 2309 if req.GetPageToken() != "" { 2310 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 2311 } 2312 2313 baseUrl.RawQuery = params.Encode() 2314 2315 // Build HTTP headers from client and context metadata. 2316 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 2317 headers := gax.BuildHeaders(ctx, hds...) 2318 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2319 if settings.Path != "" { 2320 baseUrl.Path = settings.Path 2321 } 2322 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 2323 if err != nil { 2324 return err 2325 } 2326 httpReq.Header = headers 2327 2328 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations") 2329 if err != nil { 2330 return err 2331 } 2332 if err := unm.Unmarshal(buf, resp); err != nil { 2333 return err 2334 } 2335 2336 return nil 2337 }, opts...) 2338 if e != nil { 2339 return nil, "", e 2340 } 2341 it.Response = resp 2342 return resp.GetOperations(), resp.GetNextPageToken(), nil 2343 } 2344 2345 fetch := func(pageSize int, pageToken string) (string, error) { 2346 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 2347 if err != nil { 2348 return "", err 2349 } 2350 it.items = append(it.items, items...) 2351 return nextPageToken, nil 2352 } 2353 2354 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 2355 it.pageInfo.MaxSize = int(req.GetPageSize()) 2356 it.pageInfo.Token = req.GetPageToken() 2357 2358 return it 2359 } 2360 2361 // WaitOperation is a utility method from google.longrunning.Operations. 2362 func (c *pipelineRESTClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 2363 baseUrl, err := url.Parse(c.endpoint) 2364 if err != nil { 2365 return nil, err 2366 } 2367 baseUrl.Path += fmt.Sprintf("/ui/%v:wait", req.GetName()) 2368 2369 params := url.Values{} 2370 params.Add("$alt", "json;enum-encoding=int") 2371 if req.GetTimeout() != nil { 2372 field, err := protojson.Marshal(req.GetTimeout()) 2373 if err != nil { 2374 return nil, err 2375 } 2376 params.Add("timeout", string(field[1:len(field)-1])) 2377 } 2378 2379 baseUrl.RawQuery = params.Encode() 2380 2381 // Build HTTP headers from client and context metadata. 2382 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 2383 2384 hds = append(c.xGoogHeaders, hds...) 2385 hds = append(hds, "Content-Type", "application/json") 2386 headers := gax.BuildHeaders(ctx, hds...) 2387 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 2388 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 2389 resp := &longrunningpb.Operation{} 2390 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2391 if settings.Path != "" { 2392 baseUrl.Path = settings.Path 2393 } 2394 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil) 2395 if err != nil { 2396 return err 2397 } 2398 httpReq = httpReq.WithContext(ctx) 2399 httpReq.Header = headers 2400 2401 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "WaitOperation") 2402 if err != nil { 2403 return err 2404 } 2405 2406 if err := unm.Unmarshal(buf, resp); err != nil { 2407 return err 2408 } 2409 2410 return nil 2411 }, opts...) 2412 if e != nil { 2413 return nil, e 2414 } 2415 return resp, nil 2416 } 2417 2418 // BatchCancelPipelineJobsOperation returns a new BatchCancelPipelineJobsOperation from a given name. 2419 // The name must be that of a previously created BatchCancelPipelineJobsOperation, possibly from a different process. 2420 func (c *pipelineGRPCClient) BatchCancelPipelineJobsOperation(name string) *BatchCancelPipelineJobsOperation { 2421 return &BatchCancelPipelineJobsOperation{ 2422 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2423 } 2424 } 2425 2426 // BatchCancelPipelineJobsOperation returns a new BatchCancelPipelineJobsOperation from a given name. 2427 // The name must be that of a previously created BatchCancelPipelineJobsOperation, possibly from a different process. 2428 func (c *pipelineRESTClient) BatchCancelPipelineJobsOperation(name string) *BatchCancelPipelineJobsOperation { 2429 override := fmt.Sprintf("/ui/%s", name) 2430 return &BatchCancelPipelineJobsOperation{ 2431 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2432 pollPath: override, 2433 } 2434 } 2435 2436 // BatchDeletePipelineJobsOperation returns a new BatchDeletePipelineJobsOperation from a given name. 2437 // The name must be that of a previously created BatchDeletePipelineJobsOperation, possibly from a different process. 2438 func (c *pipelineGRPCClient) BatchDeletePipelineJobsOperation(name string) *BatchDeletePipelineJobsOperation { 2439 return &BatchDeletePipelineJobsOperation{ 2440 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2441 } 2442 } 2443 2444 // BatchDeletePipelineJobsOperation returns a new BatchDeletePipelineJobsOperation from a given name. 2445 // The name must be that of a previously created BatchDeletePipelineJobsOperation, possibly from a different process. 2446 func (c *pipelineRESTClient) BatchDeletePipelineJobsOperation(name string) *BatchDeletePipelineJobsOperation { 2447 override := fmt.Sprintf("/ui/%s", name) 2448 return &BatchDeletePipelineJobsOperation{ 2449 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2450 pollPath: override, 2451 } 2452 } 2453 2454 // DeletePipelineJobOperation returns a new DeletePipelineJobOperation from a given name. 2455 // The name must be that of a previously created DeletePipelineJobOperation, possibly from a different process. 2456 func (c *pipelineGRPCClient) DeletePipelineJobOperation(name string) *DeletePipelineJobOperation { 2457 return &DeletePipelineJobOperation{ 2458 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2459 } 2460 } 2461 2462 // DeletePipelineJobOperation returns a new DeletePipelineJobOperation from a given name. 2463 // The name must be that of a previously created DeletePipelineJobOperation, possibly from a different process. 2464 func (c *pipelineRESTClient) DeletePipelineJobOperation(name string) *DeletePipelineJobOperation { 2465 override := fmt.Sprintf("/ui/%s", name) 2466 return &DeletePipelineJobOperation{ 2467 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2468 pollPath: override, 2469 } 2470 } 2471 2472 // DeleteTrainingPipelineOperation returns a new DeleteTrainingPipelineOperation from a given name. 2473 // The name must be that of a previously created DeleteTrainingPipelineOperation, possibly from a different process. 2474 func (c *pipelineGRPCClient) DeleteTrainingPipelineOperation(name string) *DeleteTrainingPipelineOperation { 2475 return &DeleteTrainingPipelineOperation{ 2476 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2477 } 2478 } 2479 2480 // DeleteTrainingPipelineOperation returns a new DeleteTrainingPipelineOperation from a given name. 2481 // The name must be that of a previously created DeleteTrainingPipelineOperation, possibly from a different process. 2482 func (c *pipelineRESTClient) DeleteTrainingPipelineOperation(name string) *DeleteTrainingPipelineOperation { 2483 override := fmt.Sprintf("/ui/%s", name) 2484 return &DeleteTrainingPipelineOperation{ 2485 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2486 pollPath: override, 2487 } 2488 }