cloud.google.com/go/aiplatform@v1.106.0/apiv1/index_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 "context" 21 "fmt" 22 "log/slog" 23 "math" 24 "net/url" 25 26 aiplatformpb "cloud.google.com/go/aiplatform/apiv1/aiplatformpb" 27 iampb "cloud.google.com/go/iam/apiv1/iampb" 28 "cloud.google.com/go/longrunning" 29 lroauto "cloud.google.com/go/longrunning/autogen" 30 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" 31 gax "github.com/googleapis/gax-go/v2" 32 "google.golang.org/api/iterator" 33 "google.golang.org/api/option" 34 "google.golang.org/api/option/internaloption" 35 gtransport "google.golang.org/api/transport/grpc" 36 locationpb "google.golang.org/genproto/googleapis/cloud/location" 37 "google.golang.org/grpc" 38 "google.golang.org/protobuf/proto" 39 ) 40 41 var newIndexClientHook clientHook 42 43 // IndexCallOptions contains the retry settings for each method of IndexClient. 44 type IndexCallOptions struct { 45 CreateIndex []gax.CallOption 46 GetIndex []gax.CallOption 47 ListIndexes []gax.CallOption 48 UpdateIndex []gax.CallOption 49 DeleteIndex []gax.CallOption 50 UpsertDatapoints []gax.CallOption 51 RemoveDatapoints []gax.CallOption 52 GetLocation []gax.CallOption 53 ListLocations []gax.CallOption 54 GetIamPolicy []gax.CallOption 55 SetIamPolicy []gax.CallOption 56 TestIamPermissions []gax.CallOption 57 CancelOperation []gax.CallOption 58 DeleteOperation []gax.CallOption 59 GetOperation []gax.CallOption 60 ListOperations []gax.CallOption 61 WaitOperation []gax.CallOption 62 } 63 64 func defaultIndexGRPCClientOptions() []option.ClientOption { 65 return []option.ClientOption{ 66 internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"), 67 internaloption.WithDefaultEndpointTemplate("aiplatform.UNIVERSE_DOMAIN:443"), 68 internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), 69 internaloption.WithDefaultUniverseDomain("googleapis.com"), 70 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 71 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 72 internaloption.EnableJwtWithScope(), 73 internaloption.EnableNewAuthLibrary(), 74 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 75 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 76 } 77 } 78 79 func defaultIndexCallOptions() *IndexCallOptions { 80 return &IndexCallOptions{ 81 CreateIndex: []gax.CallOption{}, 82 GetIndex: []gax.CallOption{}, 83 ListIndexes: []gax.CallOption{}, 84 UpdateIndex: []gax.CallOption{}, 85 DeleteIndex: []gax.CallOption{}, 86 UpsertDatapoints: []gax.CallOption{}, 87 RemoveDatapoints: []gax.CallOption{}, 88 GetLocation: []gax.CallOption{}, 89 ListLocations: []gax.CallOption{}, 90 GetIamPolicy: []gax.CallOption{}, 91 SetIamPolicy: []gax.CallOption{}, 92 TestIamPermissions: []gax.CallOption{}, 93 CancelOperation: []gax.CallOption{}, 94 DeleteOperation: []gax.CallOption{}, 95 GetOperation: []gax.CallOption{}, 96 ListOperations: []gax.CallOption{}, 97 WaitOperation: []gax.CallOption{}, 98 } 99 } 100 101 // internalIndexClient is an interface that defines the methods available from Vertex AI API. 102 type internalIndexClient interface { 103 Close() error 104 setGoogleClientInfo(...string) 105 Connection() *grpc.ClientConn 106 CreateIndex(context.Context, *aiplatformpb.CreateIndexRequest, ...gax.CallOption) (*CreateIndexOperation, error) 107 CreateIndexOperation(name string) *CreateIndexOperation 108 GetIndex(context.Context, *aiplatformpb.GetIndexRequest, ...gax.CallOption) (*aiplatformpb.Index, error) 109 ListIndexes(context.Context, *aiplatformpb.ListIndexesRequest, ...gax.CallOption) *IndexIterator 110 UpdateIndex(context.Context, *aiplatformpb.UpdateIndexRequest, ...gax.CallOption) (*UpdateIndexOperation, error) 111 UpdateIndexOperation(name string) *UpdateIndexOperation 112 DeleteIndex(context.Context, *aiplatformpb.DeleteIndexRequest, ...gax.CallOption) (*DeleteIndexOperation, error) 113 DeleteIndexOperation(name string) *DeleteIndexOperation 114 UpsertDatapoints(context.Context, *aiplatformpb.UpsertDatapointsRequest, ...gax.CallOption) (*aiplatformpb.UpsertDatapointsResponse, error) 115 RemoveDatapoints(context.Context, *aiplatformpb.RemoveDatapointsRequest, ...gax.CallOption) (*aiplatformpb.RemoveDatapointsResponse, error) 116 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error) 117 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator 118 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 119 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 120 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) 121 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error 122 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error 123 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 124 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator 125 WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 126 } 127 128 // IndexClient is a client for interacting with Vertex AI API. 129 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 130 // 131 // A service for creating and managing Vertex AI’s Index resources. 132 type IndexClient struct { 133 // The internal transport-dependent client. 134 internalClient internalIndexClient 135 136 // The call options for this service. 137 CallOptions *IndexCallOptions 138 139 // LROClient is used internally to handle long-running operations. 140 // It is exposed so that its CallOptions can be modified if required. 141 // Users should not Close this client. 142 LROClient *lroauto.OperationsClient 143 } 144 145 // Wrapper methods routed to the internal client. 146 147 // Close closes the connection to the API service. The user should invoke this when 148 // the client is no longer required. 149 func (c *IndexClient) Close() error { 150 return c.internalClient.Close() 151 } 152 153 // setGoogleClientInfo sets the name and version of the application in 154 // the `x-goog-api-client` header passed on each request. Intended for 155 // use by Google-written clients. 156 func (c *IndexClient) setGoogleClientInfo(keyval ...string) { 157 c.internalClient.setGoogleClientInfo(keyval...) 158 } 159 160 // Connection returns a connection to the API service. 161 // 162 // Deprecated: Connections are now pooled so this method does not always 163 // return the same resource. 164 func (c *IndexClient) Connection() *grpc.ClientConn { 165 return c.internalClient.Connection() 166 } 167 168 // CreateIndex creates an Index. 169 func (c *IndexClient) CreateIndex(ctx context.Context, req *aiplatformpb.CreateIndexRequest, opts ...gax.CallOption) (*CreateIndexOperation, error) { 170 return c.internalClient.CreateIndex(ctx, req, opts...) 171 } 172 173 // CreateIndexOperation returns a new CreateIndexOperation from a given name. 174 // The name must be that of a previously created CreateIndexOperation, possibly from a different process. 175 func (c *IndexClient) CreateIndexOperation(name string) *CreateIndexOperation { 176 return c.internalClient.CreateIndexOperation(name) 177 } 178 179 // GetIndex gets an Index. 180 func (c *IndexClient) GetIndex(ctx context.Context, req *aiplatformpb.GetIndexRequest, opts ...gax.CallOption) (*aiplatformpb.Index, error) { 181 return c.internalClient.GetIndex(ctx, req, opts...) 182 } 183 184 // ListIndexes lists Indexes in a Location. 185 func (c *IndexClient) ListIndexes(ctx context.Context, req *aiplatformpb.ListIndexesRequest, opts ...gax.CallOption) *IndexIterator { 186 return c.internalClient.ListIndexes(ctx, req, opts...) 187 } 188 189 // UpdateIndex updates an Index. 190 func (c *IndexClient) UpdateIndex(ctx context.Context, req *aiplatformpb.UpdateIndexRequest, opts ...gax.CallOption) (*UpdateIndexOperation, error) { 191 return c.internalClient.UpdateIndex(ctx, req, opts...) 192 } 193 194 // UpdateIndexOperation returns a new UpdateIndexOperation from a given name. 195 // The name must be that of a previously created UpdateIndexOperation, possibly from a different process. 196 func (c *IndexClient) UpdateIndexOperation(name string) *UpdateIndexOperation { 197 return c.internalClient.UpdateIndexOperation(name) 198 } 199 200 // DeleteIndex deletes an Index. 201 // An Index can only be deleted when all its 202 // DeployedIndexes had 203 // been undeployed. 204 func (c *IndexClient) DeleteIndex(ctx context.Context, req *aiplatformpb.DeleteIndexRequest, opts ...gax.CallOption) (*DeleteIndexOperation, error) { 205 return c.internalClient.DeleteIndex(ctx, req, opts...) 206 } 207 208 // DeleteIndexOperation returns a new DeleteIndexOperation from a given name. 209 // The name must be that of a previously created DeleteIndexOperation, possibly from a different process. 210 func (c *IndexClient) DeleteIndexOperation(name string) *DeleteIndexOperation { 211 return c.internalClient.DeleteIndexOperation(name) 212 } 213 214 // UpsertDatapoints add/update Datapoints into an Index. 215 func (c *IndexClient) UpsertDatapoints(ctx context.Context, req *aiplatformpb.UpsertDatapointsRequest, opts ...gax.CallOption) (*aiplatformpb.UpsertDatapointsResponse, error) { 216 return c.internalClient.UpsertDatapoints(ctx, req, opts...) 217 } 218 219 // RemoveDatapoints remove Datapoints from an Index. 220 func (c *IndexClient) RemoveDatapoints(ctx context.Context, req *aiplatformpb.RemoveDatapointsRequest, opts ...gax.CallOption) (*aiplatformpb.RemoveDatapointsResponse, error) { 221 return c.internalClient.RemoveDatapoints(ctx, req, opts...) 222 } 223 224 // GetLocation gets information about a location. 225 func (c *IndexClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 226 return c.internalClient.GetLocation(ctx, req, opts...) 227 } 228 229 // ListLocations lists information about the supported locations for this service. 230 func (c *IndexClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 231 return c.internalClient.ListLocations(ctx, req, opts...) 232 } 233 234 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 235 // if the resource exists and does not have a policy set. 236 func (c *IndexClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 237 return c.internalClient.GetIamPolicy(ctx, req, opts...) 238 } 239 240 // SetIamPolicy sets the access control policy on the specified resource. Replaces 241 // any existing policy. 242 // 243 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 244 // errors. 245 func (c *IndexClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 246 return c.internalClient.SetIamPolicy(ctx, req, opts...) 247 } 248 249 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 250 // resource does not exist, this will return an empty set of 251 // permissions, not a NOT_FOUND error. 252 // 253 // Note: This operation is designed to be used for building 254 // permission-aware UIs and command-line tools, not for authorization 255 // checking. This operation may “fail open” without warning. 256 func (c *IndexClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 257 return c.internalClient.TestIamPermissions(ctx, req, opts...) 258 } 259 260 // CancelOperation is a utility method from google.longrunning.Operations. 261 func (c *IndexClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 262 return c.internalClient.CancelOperation(ctx, req, opts...) 263 } 264 265 // DeleteOperation is a utility method from google.longrunning.Operations. 266 func (c *IndexClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 267 return c.internalClient.DeleteOperation(ctx, req, opts...) 268 } 269 270 // GetOperation is a utility method from google.longrunning.Operations. 271 func (c *IndexClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 272 return c.internalClient.GetOperation(ctx, req, opts...) 273 } 274 275 // ListOperations is a utility method from google.longrunning.Operations. 276 func (c *IndexClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 277 return c.internalClient.ListOperations(ctx, req, opts...) 278 } 279 280 // WaitOperation is a utility method from google.longrunning.Operations. 281 func (c *IndexClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 282 return c.internalClient.WaitOperation(ctx, req, opts...) 283 } 284 285 // indexGRPCClient is a client for interacting with Vertex AI API over gRPC transport. 286 // 287 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 288 type indexGRPCClient struct { 289 // Connection pool of gRPC connections to the service. 290 connPool gtransport.ConnPool 291 292 // Points back to the CallOptions field of the containing IndexClient 293 CallOptions **IndexCallOptions 294 295 // The gRPC API client. 296 indexClient aiplatformpb.IndexServiceClient 297 298 // LROClient is used internally to handle long-running operations. 299 // It is exposed so that its CallOptions can be modified if required. 300 // Users should not Close this client. 301 LROClient **lroauto.OperationsClient 302 303 operationsClient longrunningpb.OperationsClient 304 305 iamPolicyClient iampb.IAMPolicyClient 306 307 locationsClient locationpb.LocationsClient 308 309 // The x-goog-* metadata to be sent with each request. 310 xGoogHeaders []string 311 312 logger *slog.Logger 313 } 314 315 // NewIndexClient creates a new index service client based on gRPC. 316 // The returned client must be Closed when it is done being used to clean up its underlying connections. 317 // 318 // A service for creating and managing Vertex AI’s Index resources. 319 func NewIndexClient(ctx context.Context, opts ...option.ClientOption) (*IndexClient, error) { 320 clientOpts := defaultIndexGRPCClientOptions() 321 if newIndexClientHook != nil { 322 hookOpts, err := newIndexClientHook(ctx, clientHookParams{}) 323 if err != nil { 324 return nil, err 325 } 326 clientOpts = append(clientOpts, hookOpts...) 327 } 328 329 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 330 if err != nil { 331 return nil, err 332 } 333 client := IndexClient{CallOptions: defaultIndexCallOptions()} 334 335 c := &indexGRPCClient{ 336 connPool: connPool, 337 indexClient: aiplatformpb.NewIndexServiceClient(connPool), 338 CallOptions: &client.CallOptions, 339 logger: internaloption.GetLogger(opts), 340 operationsClient: longrunningpb.NewOperationsClient(connPool), 341 iamPolicyClient: iampb.NewIAMPolicyClient(connPool), 342 locationsClient: locationpb.NewLocationsClient(connPool), 343 } 344 c.setGoogleClientInfo() 345 346 client.internalClient = c 347 348 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) 349 if err != nil { 350 // This error "should not happen", since we are just reusing old connection pool 351 // and never actually need to dial. 352 // If this does happen, we could leak connp. However, we cannot close conn: 353 // If the user invoked the constructor with option.WithGRPCConn, 354 // we would close a connection that's still in use. 355 // TODO: investigate error conditions. 356 return nil, err 357 } 358 c.LROClient = &client.LROClient 359 return &client, nil 360 } 361 362 // Connection returns a connection to the API service. 363 // 364 // Deprecated: Connections are now pooled so this method does not always 365 // return the same resource. 366 func (c *indexGRPCClient) Connection() *grpc.ClientConn { 367 return c.connPool.Conn() 368 } 369 370 // setGoogleClientInfo sets the name and version of the application in 371 // the `x-goog-api-client` header passed on each request. Intended for 372 // use by Google-written clients. 373 func (c *indexGRPCClient) setGoogleClientInfo(keyval ...string) { 374 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 375 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) 376 c.xGoogHeaders = []string{ 377 "x-goog-api-client", gax.XGoogHeader(kv...), 378 } 379 } 380 381 // Close closes the connection to the API service. The user should invoke this when 382 // the client is no longer required. 383 func (c *indexGRPCClient) Close() error { 384 return c.connPool.Close() 385 } 386 387 func (c *indexGRPCClient) CreateIndex(ctx context.Context, req *aiplatformpb.CreateIndexRequest, opts ...gax.CallOption) (*CreateIndexOperation, error) { 388 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 389 390 hds = append(c.xGoogHeaders, hds...) 391 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 392 opts = append((*c.CallOptions).CreateIndex[0:len((*c.CallOptions).CreateIndex):len((*c.CallOptions).CreateIndex)], opts...) 393 var resp *longrunningpb.Operation 394 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 395 var err error 396 resp, err = executeRPC(ctx, c.indexClient.CreateIndex, req, settings.GRPC, c.logger, "CreateIndex") 397 return err 398 }, opts...) 399 if err != nil { 400 return nil, err 401 } 402 return &CreateIndexOperation{ 403 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 404 }, nil 405 } 406 407 func (c *indexGRPCClient) GetIndex(ctx context.Context, req *aiplatformpb.GetIndexRequest, opts ...gax.CallOption) (*aiplatformpb.Index, error) { 408 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 409 410 hds = append(c.xGoogHeaders, hds...) 411 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 412 opts = append((*c.CallOptions).GetIndex[0:len((*c.CallOptions).GetIndex):len((*c.CallOptions).GetIndex)], opts...) 413 var resp *aiplatformpb.Index 414 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 415 var err error 416 resp, err = executeRPC(ctx, c.indexClient.GetIndex, req, settings.GRPC, c.logger, "GetIndex") 417 return err 418 }, opts...) 419 if err != nil { 420 return nil, err 421 } 422 return resp, nil 423 } 424 425 func (c *indexGRPCClient) ListIndexes(ctx context.Context, req *aiplatformpb.ListIndexesRequest, opts ...gax.CallOption) *IndexIterator { 426 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 427 428 hds = append(c.xGoogHeaders, hds...) 429 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 430 opts = append((*c.CallOptions).ListIndexes[0:len((*c.CallOptions).ListIndexes):len((*c.CallOptions).ListIndexes)], opts...) 431 it := &IndexIterator{} 432 req = proto.Clone(req).(*aiplatformpb.ListIndexesRequest) 433 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.Index, string, error) { 434 resp := &aiplatformpb.ListIndexesResponse{} 435 if pageToken != "" { 436 req.PageToken = pageToken 437 } 438 if pageSize > math.MaxInt32 { 439 req.PageSize = math.MaxInt32 440 } else if pageSize != 0 { 441 req.PageSize = int32(pageSize) 442 } 443 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 444 var err error 445 resp, err = executeRPC(ctx, c.indexClient.ListIndexes, req, settings.GRPC, c.logger, "ListIndexes") 446 return err 447 }, opts...) 448 if err != nil { 449 return nil, "", err 450 } 451 452 it.Response = resp 453 return resp.GetIndexes(), resp.GetNextPageToken(), nil 454 } 455 fetch := func(pageSize int, pageToken string) (string, error) { 456 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 457 if err != nil { 458 return "", err 459 } 460 it.items = append(it.items, items...) 461 return nextPageToken, nil 462 } 463 464 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 465 it.pageInfo.MaxSize = int(req.GetPageSize()) 466 it.pageInfo.Token = req.GetPageToken() 467 468 return it 469 } 470 471 func (c *indexGRPCClient) UpdateIndex(ctx context.Context, req *aiplatformpb.UpdateIndexRequest, opts ...gax.CallOption) (*UpdateIndexOperation, error) { 472 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "index.name", url.QueryEscape(req.GetIndex().GetName()))} 473 474 hds = append(c.xGoogHeaders, hds...) 475 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 476 opts = append((*c.CallOptions).UpdateIndex[0:len((*c.CallOptions).UpdateIndex):len((*c.CallOptions).UpdateIndex)], opts...) 477 var resp *longrunningpb.Operation 478 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 479 var err error 480 resp, err = executeRPC(ctx, c.indexClient.UpdateIndex, req, settings.GRPC, c.logger, "UpdateIndex") 481 return err 482 }, opts...) 483 if err != nil { 484 return nil, err 485 } 486 return &UpdateIndexOperation{ 487 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 488 }, nil 489 } 490 491 func (c *indexGRPCClient) DeleteIndex(ctx context.Context, req *aiplatformpb.DeleteIndexRequest, opts ...gax.CallOption) (*DeleteIndexOperation, error) { 492 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 493 494 hds = append(c.xGoogHeaders, hds...) 495 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 496 opts = append((*c.CallOptions).DeleteIndex[0:len((*c.CallOptions).DeleteIndex):len((*c.CallOptions).DeleteIndex)], opts...) 497 var resp *longrunningpb.Operation 498 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 499 var err error 500 resp, err = executeRPC(ctx, c.indexClient.DeleteIndex, req, settings.GRPC, c.logger, "DeleteIndex") 501 return err 502 }, opts...) 503 if err != nil { 504 return nil, err 505 } 506 return &DeleteIndexOperation{ 507 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 508 }, nil 509 } 510 511 func (c *indexGRPCClient) UpsertDatapoints(ctx context.Context, req *aiplatformpb.UpsertDatapointsRequest, opts ...gax.CallOption) (*aiplatformpb.UpsertDatapointsResponse, error) { 512 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "index", url.QueryEscape(req.GetIndex()))} 513 514 hds = append(c.xGoogHeaders, hds...) 515 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 516 opts = append((*c.CallOptions).UpsertDatapoints[0:len((*c.CallOptions).UpsertDatapoints):len((*c.CallOptions).UpsertDatapoints)], opts...) 517 var resp *aiplatformpb.UpsertDatapointsResponse 518 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 519 var err error 520 resp, err = executeRPC(ctx, c.indexClient.UpsertDatapoints, req, settings.GRPC, c.logger, "UpsertDatapoints") 521 return err 522 }, opts...) 523 if err != nil { 524 return nil, err 525 } 526 return resp, nil 527 } 528 529 func (c *indexGRPCClient) RemoveDatapoints(ctx context.Context, req *aiplatformpb.RemoveDatapointsRequest, opts ...gax.CallOption) (*aiplatformpb.RemoveDatapointsResponse, error) { 530 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "index", url.QueryEscape(req.GetIndex()))} 531 532 hds = append(c.xGoogHeaders, hds...) 533 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 534 opts = append((*c.CallOptions).RemoveDatapoints[0:len((*c.CallOptions).RemoveDatapoints):len((*c.CallOptions).RemoveDatapoints)], opts...) 535 var resp *aiplatformpb.RemoveDatapointsResponse 536 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 537 var err error 538 resp, err = executeRPC(ctx, c.indexClient.RemoveDatapoints, req, settings.GRPC, c.logger, "RemoveDatapoints") 539 return err 540 }, opts...) 541 if err != nil { 542 return nil, err 543 } 544 return resp, nil 545 } 546 547 func (c *indexGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 548 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 549 550 hds = append(c.xGoogHeaders, hds...) 551 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 552 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 553 var resp *locationpb.Location 554 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 555 var err error 556 resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation") 557 return err 558 }, opts...) 559 if err != nil { 560 return nil, err 561 } 562 return resp, nil 563 } 564 565 func (c *indexGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 566 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 567 568 hds = append(c.xGoogHeaders, hds...) 569 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 570 opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...) 571 it := &LocationIterator{} 572 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 573 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 574 resp := &locationpb.ListLocationsResponse{} 575 if pageToken != "" { 576 req.PageToken = pageToken 577 } 578 if pageSize > math.MaxInt32 { 579 req.PageSize = math.MaxInt32 580 } else if pageSize != 0 { 581 req.PageSize = int32(pageSize) 582 } 583 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 584 var err error 585 resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations") 586 return err 587 }, opts...) 588 if err != nil { 589 return nil, "", err 590 } 591 592 it.Response = resp 593 return resp.GetLocations(), resp.GetNextPageToken(), nil 594 } 595 fetch := func(pageSize int, pageToken string) (string, error) { 596 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 597 if err != nil { 598 return "", err 599 } 600 it.items = append(it.items, items...) 601 return nextPageToken, nil 602 } 603 604 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 605 it.pageInfo.MaxSize = int(req.GetPageSize()) 606 it.pageInfo.Token = req.GetPageToken() 607 608 return it 609 } 610 611 func (c *indexGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 612 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 613 614 hds = append(c.xGoogHeaders, hds...) 615 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 616 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 617 var resp *iampb.Policy 618 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 619 var err error 620 resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy") 621 return err 622 }, opts...) 623 if err != nil { 624 return nil, err 625 } 626 return resp, nil 627 } 628 629 func (c *indexGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 630 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 631 632 hds = append(c.xGoogHeaders, hds...) 633 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 634 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 635 var resp *iampb.Policy 636 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 637 var err error 638 resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy") 639 return err 640 }, opts...) 641 if err != nil { 642 return nil, err 643 } 644 return resp, nil 645 } 646 647 func (c *indexGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 648 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 649 650 hds = append(c.xGoogHeaders, hds...) 651 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 652 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 653 var resp *iampb.TestIamPermissionsResponse 654 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 655 var err error 656 resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions") 657 return err 658 }, opts...) 659 if err != nil { 660 return nil, err 661 } 662 return resp, nil 663 } 664 665 func (c *indexGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 666 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 667 668 hds = append(c.xGoogHeaders, hds...) 669 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 670 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) 671 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 672 var err error 673 _, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation") 674 return err 675 }, opts...) 676 return err 677 } 678 679 func (c *indexGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 680 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 681 682 hds = append(c.xGoogHeaders, hds...) 683 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 684 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) 685 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 686 var err error 687 _, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation") 688 return err 689 }, opts...) 690 return err 691 } 692 693 func (c *indexGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 694 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 695 696 hds = append(c.xGoogHeaders, hds...) 697 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 698 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 699 var resp *longrunningpb.Operation 700 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 701 var err error 702 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation") 703 return err 704 }, opts...) 705 if err != nil { 706 return nil, err 707 } 708 return resp, nil 709 } 710 711 func (c *indexGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 712 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 713 714 hds = append(c.xGoogHeaders, hds...) 715 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 716 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) 717 it := &OperationIterator{} 718 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 719 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 720 resp := &longrunningpb.ListOperationsResponse{} 721 if pageToken != "" { 722 req.PageToken = pageToken 723 } 724 if pageSize > math.MaxInt32 { 725 req.PageSize = math.MaxInt32 726 } else if pageSize != 0 { 727 req.PageSize = int32(pageSize) 728 } 729 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 730 var err error 731 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations") 732 return err 733 }, opts...) 734 if err != nil { 735 return nil, "", err 736 } 737 738 it.Response = resp 739 return resp.GetOperations(), resp.GetNextPageToken(), nil 740 } 741 fetch := func(pageSize int, pageToken string) (string, error) { 742 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 743 if err != nil { 744 return "", err 745 } 746 it.items = append(it.items, items...) 747 return nextPageToken, nil 748 } 749 750 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 751 it.pageInfo.MaxSize = int(req.GetPageSize()) 752 it.pageInfo.Token = req.GetPageToken() 753 754 return it 755 } 756 757 func (c *indexGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 758 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 759 760 hds = append(c.xGoogHeaders, hds...) 761 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 762 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 763 var resp *longrunningpb.Operation 764 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 765 var err error 766 resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation") 767 return err 768 }, opts...) 769 if err != nil { 770 return nil, err 771 } 772 return resp, nil 773 } 774 775 // CreateIndexOperation returns a new CreateIndexOperation from a given name. 776 // The name must be that of a previously created CreateIndexOperation, possibly from a different process. 777 func (c *indexGRPCClient) CreateIndexOperation(name string) *CreateIndexOperation { 778 return &CreateIndexOperation{ 779 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 780 } 781 } 782 783 // DeleteIndexOperation returns a new DeleteIndexOperation from a given name. 784 // The name must be that of a previously created DeleteIndexOperation, possibly from a different process. 785 func (c *indexGRPCClient) DeleteIndexOperation(name string) *DeleteIndexOperation { 786 return &DeleteIndexOperation{ 787 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 788 } 789 } 790 791 // UpdateIndexOperation returns a new UpdateIndexOperation from a given name. 792 // The name must be that of a previously created UpdateIndexOperation, possibly from a different process. 793 func (c *indexGRPCClient) UpdateIndexOperation(name string) *UpdateIndexOperation { 794 return &UpdateIndexOperation{ 795 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 796 } 797 }