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