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