cloud.google.com/go/aiplatform@v1.106.0/apiv1/migration_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 newMigrationClientHook clientHook 42 43 // MigrationCallOptions contains the retry settings for each method of MigrationClient. 44 type MigrationCallOptions struct { 45 SearchMigratableResources []gax.CallOption 46 BatchMigrateResources []gax.CallOption 47 GetLocation []gax.CallOption 48 ListLocations []gax.CallOption 49 GetIamPolicy []gax.CallOption 50 SetIamPolicy []gax.CallOption 51 TestIamPermissions []gax.CallOption 52 CancelOperation []gax.CallOption 53 DeleteOperation []gax.CallOption 54 GetOperation []gax.CallOption 55 ListOperations []gax.CallOption 56 WaitOperation []gax.CallOption 57 } 58 59 func defaultMigrationGRPCClientOptions() []option.ClientOption { 60 return []option.ClientOption{ 61 internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"), 62 internaloption.WithDefaultEndpointTemplate("aiplatform.UNIVERSE_DOMAIN:443"), 63 internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), 64 internaloption.WithDefaultUniverseDomain("googleapis.com"), 65 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 66 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 67 internaloption.EnableJwtWithScope(), 68 internaloption.EnableNewAuthLibrary(), 69 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 70 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 71 } 72 } 73 74 func defaultMigrationCallOptions() *MigrationCallOptions { 75 return &MigrationCallOptions{ 76 SearchMigratableResources: []gax.CallOption{}, 77 BatchMigrateResources: []gax.CallOption{}, 78 GetLocation: []gax.CallOption{}, 79 ListLocations: []gax.CallOption{}, 80 GetIamPolicy: []gax.CallOption{}, 81 SetIamPolicy: []gax.CallOption{}, 82 TestIamPermissions: []gax.CallOption{}, 83 CancelOperation: []gax.CallOption{}, 84 DeleteOperation: []gax.CallOption{}, 85 GetOperation: []gax.CallOption{}, 86 ListOperations: []gax.CallOption{}, 87 WaitOperation: []gax.CallOption{}, 88 } 89 } 90 91 // internalMigrationClient is an interface that defines the methods available from Vertex AI API. 92 type internalMigrationClient interface { 93 Close() error 94 setGoogleClientInfo(...string) 95 Connection() *grpc.ClientConn 96 SearchMigratableResources(context.Context, *aiplatformpb.SearchMigratableResourcesRequest, ...gax.CallOption) *MigratableResourceIterator 97 BatchMigrateResources(context.Context, *aiplatformpb.BatchMigrateResourcesRequest, ...gax.CallOption) (*BatchMigrateResourcesOperation, error) 98 BatchMigrateResourcesOperation(name string) *BatchMigrateResourcesOperation 99 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error) 100 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator 101 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 102 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 103 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) 104 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error 105 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error 106 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 107 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator 108 WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 109 } 110 111 // MigrationClient is a client for interacting with Vertex AI API. 112 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 113 // 114 // A service that migrates resources from automl.googleapis.com (at http://automl.googleapis.com), 115 // datalabeling.googleapis.com (at http://datalabeling.googleapis.com) and ml.googleapis.com (at http://ml.googleapis.com) to Vertex AI. 116 type MigrationClient struct { 117 // The internal transport-dependent client. 118 internalClient internalMigrationClient 119 120 // The call options for this service. 121 CallOptions *MigrationCallOptions 122 123 // LROClient is used internally to handle long-running operations. 124 // It is exposed so that its CallOptions can be modified if required. 125 // Users should not Close this client. 126 LROClient *lroauto.OperationsClient 127 } 128 129 // Wrapper methods routed to the internal client. 130 131 // Close closes the connection to the API service. The user should invoke this when 132 // the client is no longer required. 133 func (c *MigrationClient) Close() error { 134 return c.internalClient.Close() 135 } 136 137 // setGoogleClientInfo sets the name and version of the application in 138 // the `x-goog-api-client` header passed on each request. Intended for 139 // use by Google-written clients. 140 func (c *MigrationClient) setGoogleClientInfo(keyval ...string) { 141 c.internalClient.setGoogleClientInfo(keyval...) 142 } 143 144 // Connection returns a connection to the API service. 145 // 146 // Deprecated: Connections are now pooled so this method does not always 147 // return the same resource. 148 func (c *MigrationClient) Connection() *grpc.ClientConn { 149 return c.internalClient.Connection() 150 } 151 152 // SearchMigratableResources searches all of the resources in automl.googleapis.com (at http://automl.googleapis.com), 153 // datalabeling.googleapis.com (at http://datalabeling.googleapis.com) and ml.googleapis.com (at http://ml.googleapis.com) that can be migrated to 154 // Vertex AI’s given location. 155 func (c *MigrationClient) SearchMigratableResources(ctx context.Context, req *aiplatformpb.SearchMigratableResourcesRequest, opts ...gax.CallOption) *MigratableResourceIterator { 156 return c.internalClient.SearchMigratableResources(ctx, req, opts...) 157 } 158 159 // BatchMigrateResources batch migrates resources from ml.googleapis.com (at http://ml.googleapis.com), automl.googleapis.com (at http://automl.googleapis.com), 160 // and datalabeling.googleapis.com (at http://datalabeling.googleapis.com) to Vertex AI. 161 func (c *MigrationClient) BatchMigrateResources(ctx context.Context, req *aiplatformpb.BatchMigrateResourcesRequest, opts ...gax.CallOption) (*BatchMigrateResourcesOperation, error) { 162 return c.internalClient.BatchMigrateResources(ctx, req, opts...) 163 } 164 165 // BatchMigrateResourcesOperation returns a new BatchMigrateResourcesOperation from a given name. 166 // The name must be that of a previously created BatchMigrateResourcesOperation, possibly from a different process. 167 func (c *MigrationClient) BatchMigrateResourcesOperation(name string) *BatchMigrateResourcesOperation { 168 return c.internalClient.BatchMigrateResourcesOperation(name) 169 } 170 171 // GetLocation gets information about a location. 172 func (c *MigrationClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 173 return c.internalClient.GetLocation(ctx, req, opts...) 174 } 175 176 // ListLocations lists information about the supported locations for this service. 177 func (c *MigrationClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 178 return c.internalClient.ListLocations(ctx, req, opts...) 179 } 180 181 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 182 // if the resource exists and does not have a policy set. 183 func (c *MigrationClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 184 return c.internalClient.GetIamPolicy(ctx, req, opts...) 185 } 186 187 // SetIamPolicy sets the access control policy on the specified resource. Replaces 188 // any existing policy. 189 // 190 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 191 // errors. 192 func (c *MigrationClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 193 return c.internalClient.SetIamPolicy(ctx, req, opts...) 194 } 195 196 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 197 // resource does not exist, this will return an empty set of 198 // permissions, not a NOT_FOUND error. 199 // 200 // Note: This operation is designed to be used for building 201 // permission-aware UIs and command-line tools, not for authorization 202 // checking. This operation may “fail open” without warning. 203 func (c *MigrationClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 204 return c.internalClient.TestIamPermissions(ctx, req, opts...) 205 } 206 207 // CancelOperation is a utility method from google.longrunning.Operations. 208 func (c *MigrationClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 209 return c.internalClient.CancelOperation(ctx, req, opts...) 210 } 211 212 // DeleteOperation is a utility method from google.longrunning.Operations. 213 func (c *MigrationClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 214 return c.internalClient.DeleteOperation(ctx, req, opts...) 215 } 216 217 // GetOperation is a utility method from google.longrunning.Operations. 218 func (c *MigrationClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 219 return c.internalClient.GetOperation(ctx, req, opts...) 220 } 221 222 // ListOperations is a utility method from google.longrunning.Operations. 223 func (c *MigrationClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 224 return c.internalClient.ListOperations(ctx, req, opts...) 225 } 226 227 // WaitOperation is a utility method from google.longrunning.Operations. 228 func (c *MigrationClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 229 return c.internalClient.WaitOperation(ctx, req, opts...) 230 } 231 232 // migrationGRPCClient is a client for interacting with Vertex AI API over gRPC transport. 233 // 234 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 235 type migrationGRPCClient struct { 236 // Connection pool of gRPC connections to the service. 237 connPool gtransport.ConnPool 238 239 // Points back to the CallOptions field of the containing MigrationClient 240 CallOptions **MigrationCallOptions 241 242 // The gRPC API client. 243 migrationClient aiplatformpb.MigrationServiceClient 244 245 // LROClient is used internally to handle long-running operations. 246 // It is exposed so that its CallOptions can be modified if required. 247 // Users should not Close this client. 248 LROClient **lroauto.OperationsClient 249 250 operationsClient longrunningpb.OperationsClient 251 252 iamPolicyClient iampb.IAMPolicyClient 253 254 locationsClient locationpb.LocationsClient 255 256 // The x-goog-* metadata to be sent with each request. 257 xGoogHeaders []string 258 259 logger *slog.Logger 260 } 261 262 // NewMigrationClient creates a new migration service client based on gRPC. 263 // The returned client must be Closed when it is done being used to clean up its underlying connections. 264 // 265 // A service that migrates resources from automl.googleapis.com (at http://automl.googleapis.com), 266 // datalabeling.googleapis.com (at http://datalabeling.googleapis.com) and ml.googleapis.com (at http://ml.googleapis.com) to Vertex AI. 267 func NewMigrationClient(ctx context.Context, opts ...option.ClientOption) (*MigrationClient, error) { 268 clientOpts := defaultMigrationGRPCClientOptions() 269 if newMigrationClientHook != nil { 270 hookOpts, err := newMigrationClientHook(ctx, clientHookParams{}) 271 if err != nil { 272 return nil, err 273 } 274 clientOpts = append(clientOpts, hookOpts...) 275 } 276 277 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 278 if err != nil { 279 return nil, err 280 } 281 client := MigrationClient{CallOptions: defaultMigrationCallOptions()} 282 283 c := &migrationGRPCClient{ 284 connPool: connPool, 285 migrationClient: aiplatformpb.NewMigrationServiceClient(connPool), 286 CallOptions: &client.CallOptions, 287 logger: internaloption.GetLogger(opts), 288 operationsClient: longrunningpb.NewOperationsClient(connPool), 289 iamPolicyClient: iampb.NewIAMPolicyClient(connPool), 290 locationsClient: locationpb.NewLocationsClient(connPool), 291 } 292 c.setGoogleClientInfo() 293 294 client.internalClient = c 295 296 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) 297 if err != nil { 298 // This error "should not happen", since we are just reusing old connection pool 299 // and never actually need to dial. 300 // If this does happen, we could leak connp. However, we cannot close conn: 301 // If the user invoked the constructor with option.WithGRPCConn, 302 // we would close a connection that's still in use. 303 // TODO: investigate error conditions. 304 return nil, err 305 } 306 c.LROClient = &client.LROClient 307 return &client, nil 308 } 309 310 // Connection returns a connection to the API service. 311 // 312 // Deprecated: Connections are now pooled so this method does not always 313 // return the same resource. 314 func (c *migrationGRPCClient) Connection() *grpc.ClientConn { 315 return c.connPool.Conn() 316 } 317 318 // setGoogleClientInfo sets the name and version of the application in 319 // the `x-goog-api-client` header passed on each request. Intended for 320 // use by Google-written clients. 321 func (c *migrationGRPCClient) setGoogleClientInfo(keyval ...string) { 322 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 323 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) 324 c.xGoogHeaders = []string{ 325 "x-goog-api-client", gax.XGoogHeader(kv...), 326 } 327 } 328 329 // Close closes the connection to the API service. The user should invoke this when 330 // the client is no longer required. 331 func (c *migrationGRPCClient) Close() error { 332 return c.connPool.Close() 333 } 334 335 func (c *migrationGRPCClient) SearchMigratableResources(ctx context.Context, req *aiplatformpb.SearchMigratableResourcesRequest, opts ...gax.CallOption) *MigratableResourceIterator { 336 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 337 338 hds = append(c.xGoogHeaders, hds...) 339 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 340 opts = append((*c.CallOptions).SearchMigratableResources[0:len((*c.CallOptions).SearchMigratableResources):len((*c.CallOptions).SearchMigratableResources)], opts...) 341 it := &MigratableResourceIterator{} 342 req = proto.Clone(req).(*aiplatformpb.SearchMigratableResourcesRequest) 343 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.MigratableResource, string, error) { 344 resp := &aiplatformpb.SearchMigratableResourcesResponse{} 345 if pageToken != "" { 346 req.PageToken = pageToken 347 } 348 if pageSize > math.MaxInt32 { 349 req.PageSize = math.MaxInt32 350 } else if pageSize != 0 { 351 req.PageSize = int32(pageSize) 352 } 353 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 354 var err error 355 resp, err = executeRPC(ctx, c.migrationClient.SearchMigratableResources, req, settings.GRPC, c.logger, "SearchMigratableResources") 356 return err 357 }, opts...) 358 if err != nil { 359 return nil, "", err 360 } 361 362 it.Response = resp 363 return resp.GetMigratableResources(), resp.GetNextPageToken(), nil 364 } 365 fetch := func(pageSize int, pageToken string) (string, error) { 366 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 367 if err != nil { 368 return "", err 369 } 370 it.items = append(it.items, items...) 371 return nextPageToken, nil 372 } 373 374 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 375 it.pageInfo.MaxSize = int(req.GetPageSize()) 376 it.pageInfo.Token = req.GetPageToken() 377 378 return it 379 } 380 381 func (c *migrationGRPCClient) BatchMigrateResources(ctx context.Context, req *aiplatformpb.BatchMigrateResourcesRequest, opts ...gax.CallOption) (*BatchMigrateResourcesOperation, error) { 382 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 383 384 hds = append(c.xGoogHeaders, hds...) 385 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 386 opts = append((*c.CallOptions).BatchMigrateResources[0:len((*c.CallOptions).BatchMigrateResources):len((*c.CallOptions).BatchMigrateResources)], opts...) 387 var resp *longrunningpb.Operation 388 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 389 var err error 390 resp, err = executeRPC(ctx, c.migrationClient.BatchMigrateResources, req, settings.GRPC, c.logger, "BatchMigrateResources") 391 return err 392 }, opts...) 393 if err != nil { 394 return nil, err 395 } 396 return &BatchMigrateResourcesOperation{ 397 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 398 }, nil 399 } 400 401 func (c *migrationGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 402 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 403 404 hds = append(c.xGoogHeaders, hds...) 405 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 406 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 407 var resp *locationpb.Location 408 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 409 var err error 410 resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation") 411 return err 412 }, opts...) 413 if err != nil { 414 return nil, err 415 } 416 return resp, nil 417 } 418 419 func (c *migrationGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 420 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 421 422 hds = append(c.xGoogHeaders, hds...) 423 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 424 opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...) 425 it := &LocationIterator{} 426 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 427 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 428 resp := &locationpb.ListLocationsResponse{} 429 if pageToken != "" { 430 req.PageToken = pageToken 431 } 432 if pageSize > math.MaxInt32 { 433 req.PageSize = math.MaxInt32 434 } else if pageSize != 0 { 435 req.PageSize = int32(pageSize) 436 } 437 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 438 var err error 439 resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations") 440 return err 441 }, opts...) 442 if err != nil { 443 return nil, "", err 444 } 445 446 it.Response = resp 447 return resp.GetLocations(), resp.GetNextPageToken(), nil 448 } 449 fetch := func(pageSize int, pageToken string) (string, error) { 450 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 451 if err != nil { 452 return "", err 453 } 454 it.items = append(it.items, items...) 455 return nextPageToken, nil 456 } 457 458 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 459 it.pageInfo.MaxSize = int(req.GetPageSize()) 460 it.pageInfo.Token = req.GetPageToken() 461 462 return it 463 } 464 465 func (c *migrationGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 466 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 467 468 hds = append(c.xGoogHeaders, hds...) 469 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 470 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 471 var resp *iampb.Policy 472 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 473 var err error 474 resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy") 475 return err 476 }, opts...) 477 if err != nil { 478 return nil, err 479 } 480 return resp, nil 481 } 482 483 func (c *migrationGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 484 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 485 486 hds = append(c.xGoogHeaders, hds...) 487 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 488 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 489 var resp *iampb.Policy 490 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 491 var err error 492 resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy") 493 return err 494 }, opts...) 495 if err != nil { 496 return nil, err 497 } 498 return resp, nil 499 } 500 501 func (c *migrationGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 502 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 503 504 hds = append(c.xGoogHeaders, hds...) 505 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 506 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 507 var resp *iampb.TestIamPermissionsResponse 508 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 509 var err error 510 resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions") 511 return err 512 }, opts...) 513 if err != nil { 514 return nil, err 515 } 516 return resp, nil 517 } 518 519 func (c *migrationGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 520 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 521 522 hds = append(c.xGoogHeaders, hds...) 523 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 524 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) 525 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 526 var err error 527 _, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation") 528 return err 529 }, opts...) 530 return err 531 } 532 533 func (c *migrationGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 534 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 535 536 hds = append(c.xGoogHeaders, hds...) 537 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 538 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) 539 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 540 var err error 541 _, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation") 542 return err 543 }, opts...) 544 return err 545 } 546 547 func (c *migrationGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, 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).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 553 var resp *longrunningpb.Operation 554 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 555 var err error 556 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation") 557 return err 558 }, opts...) 559 if err != nil { 560 return nil, err 561 } 562 return resp, nil 563 } 564 565 func (c *migrationGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 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).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) 571 it := &OperationIterator{} 572 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 573 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 574 resp := &longrunningpb.ListOperationsResponse{} 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.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations") 586 return err 587 }, opts...) 588 if err != nil { 589 return nil, "", err 590 } 591 592 it.Response = resp 593 return resp.GetOperations(), 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 *migrationGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 612 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 613 614 hds = append(c.xGoogHeaders, hds...) 615 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 616 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 617 var resp *longrunningpb.Operation 618 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 619 var err error 620 resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation") 621 return err 622 }, opts...) 623 if err != nil { 624 return nil, err 625 } 626 return resp, nil 627 } 628 629 // BatchMigrateResourcesOperation returns a new BatchMigrateResourcesOperation from a given name. 630 // The name must be that of a previously created BatchMigrateResourcesOperation, possibly from a different process. 631 func (c *migrationGRPCClient) BatchMigrateResourcesOperation(name string) *BatchMigrateResourcesOperation { 632 return &BatchMigrateResourcesOperation{ 633 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 634 } 635 }