cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/specialist_pool_client.go (about) 1 // Copyright 2025 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Code generated by protoc-gen-go_gapic. DO NOT EDIT. 16 17 package aiplatform 18 19 import ( 20 "bytes" 21 "context" 22 "fmt" 23 "log/slog" 24 "math" 25 "net/http" 26 "net/url" 27 "time" 28 29 aiplatformpb "cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb" 30 iampb "cloud.google.com/go/iam/apiv1/iampb" 31 "cloud.google.com/go/longrunning" 32 lroauto "cloud.google.com/go/longrunning/autogen" 33 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" 34 gax "github.com/googleapis/gax-go/v2" 35 "google.golang.org/api/iterator" 36 "google.golang.org/api/option" 37 "google.golang.org/api/option/internaloption" 38 gtransport "google.golang.org/api/transport/grpc" 39 httptransport "google.golang.org/api/transport/http" 40 locationpb "google.golang.org/genproto/googleapis/cloud/location" 41 "google.golang.org/grpc" 42 "google.golang.org/protobuf/encoding/protojson" 43 "google.golang.org/protobuf/proto" 44 ) 45 46 var newSpecialistPoolClientHook clientHook 47 48 // SpecialistPoolCallOptions contains the retry settings for each method of SpecialistPoolClient. 49 type SpecialistPoolCallOptions struct { 50 CreateSpecialistPool []gax.CallOption 51 GetSpecialistPool []gax.CallOption 52 ListSpecialistPools []gax.CallOption 53 DeleteSpecialistPool []gax.CallOption 54 UpdateSpecialistPool []gax.CallOption 55 GetLocation []gax.CallOption 56 ListLocations []gax.CallOption 57 GetIamPolicy []gax.CallOption 58 SetIamPolicy []gax.CallOption 59 TestIamPermissions []gax.CallOption 60 CancelOperation []gax.CallOption 61 DeleteOperation []gax.CallOption 62 GetOperation []gax.CallOption 63 ListOperations []gax.CallOption 64 WaitOperation []gax.CallOption 65 } 66 67 func defaultSpecialistPoolGRPCClientOptions() []option.ClientOption { 68 return []option.ClientOption{ 69 internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"), 70 internaloption.WithDefaultEndpointTemplate("aiplatform.UNIVERSE_DOMAIN:443"), 71 internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), 72 internaloption.WithDefaultUniverseDomain("googleapis.com"), 73 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 74 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 75 internaloption.EnableJwtWithScope(), 76 internaloption.EnableNewAuthLibrary(), 77 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 78 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 79 } 80 } 81 82 func defaultSpecialistPoolCallOptions() *SpecialistPoolCallOptions { 83 return &SpecialistPoolCallOptions{ 84 CreateSpecialistPool: []gax.CallOption{ 85 gax.WithTimeout(5000 * time.Millisecond), 86 }, 87 GetSpecialistPool: []gax.CallOption{ 88 gax.WithTimeout(5000 * time.Millisecond), 89 }, 90 ListSpecialistPools: []gax.CallOption{ 91 gax.WithTimeout(5000 * time.Millisecond), 92 }, 93 DeleteSpecialistPool: []gax.CallOption{ 94 gax.WithTimeout(5000 * time.Millisecond), 95 }, 96 UpdateSpecialistPool: []gax.CallOption{ 97 gax.WithTimeout(5000 * time.Millisecond), 98 }, 99 GetLocation: []gax.CallOption{}, 100 ListLocations: []gax.CallOption{}, 101 GetIamPolicy: []gax.CallOption{}, 102 SetIamPolicy: []gax.CallOption{}, 103 TestIamPermissions: []gax.CallOption{}, 104 CancelOperation: []gax.CallOption{}, 105 DeleteOperation: []gax.CallOption{}, 106 GetOperation: []gax.CallOption{}, 107 ListOperations: []gax.CallOption{}, 108 WaitOperation: []gax.CallOption{}, 109 } 110 } 111 112 func defaultSpecialistPoolRESTCallOptions() *SpecialistPoolCallOptions { 113 return &SpecialistPoolCallOptions{ 114 CreateSpecialistPool: []gax.CallOption{ 115 gax.WithTimeout(5000 * time.Millisecond), 116 }, 117 GetSpecialistPool: []gax.CallOption{ 118 gax.WithTimeout(5000 * time.Millisecond), 119 }, 120 ListSpecialistPools: []gax.CallOption{ 121 gax.WithTimeout(5000 * time.Millisecond), 122 }, 123 DeleteSpecialistPool: []gax.CallOption{ 124 gax.WithTimeout(5000 * time.Millisecond), 125 }, 126 UpdateSpecialistPool: []gax.CallOption{ 127 gax.WithTimeout(5000 * time.Millisecond), 128 }, 129 GetLocation: []gax.CallOption{}, 130 ListLocations: []gax.CallOption{}, 131 GetIamPolicy: []gax.CallOption{}, 132 SetIamPolicy: []gax.CallOption{}, 133 TestIamPermissions: []gax.CallOption{}, 134 CancelOperation: []gax.CallOption{}, 135 DeleteOperation: []gax.CallOption{}, 136 GetOperation: []gax.CallOption{}, 137 ListOperations: []gax.CallOption{}, 138 WaitOperation: []gax.CallOption{}, 139 } 140 } 141 142 // internalSpecialistPoolClient is an interface that defines the methods available from Vertex AI API. 143 type internalSpecialistPoolClient interface { 144 Close() error 145 setGoogleClientInfo(...string) 146 Connection() *grpc.ClientConn 147 CreateSpecialistPool(context.Context, *aiplatformpb.CreateSpecialistPoolRequest, ...gax.CallOption) (*CreateSpecialistPoolOperation, error) 148 CreateSpecialistPoolOperation(name string) *CreateSpecialistPoolOperation 149 GetSpecialistPool(context.Context, *aiplatformpb.GetSpecialistPoolRequest, ...gax.CallOption) (*aiplatformpb.SpecialistPool, error) 150 ListSpecialistPools(context.Context, *aiplatformpb.ListSpecialistPoolsRequest, ...gax.CallOption) *SpecialistPoolIterator 151 DeleteSpecialistPool(context.Context, *aiplatformpb.DeleteSpecialistPoolRequest, ...gax.CallOption) (*DeleteSpecialistPoolOperation, error) 152 DeleteSpecialistPoolOperation(name string) *DeleteSpecialistPoolOperation 153 UpdateSpecialistPool(context.Context, *aiplatformpb.UpdateSpecialistPoolRequest, ...gax.CallOption) (*UpdateSpecialistPoolOperation, error) 154 UpdateSpecialistPoolOperation(name string) *UpdateSpecialistPoolOperation 155 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error) 156 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator 157 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 158 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 159 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) 160 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error 161 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error 162 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 163 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator 164 WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 165 } 166 167 // SpecialistPoolClient is a client for interacting with Vertex AI API. 168 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 169 // 170 // A service for creating and managing Customer SpecialistPools. 171 // When customers start Data Labeling jobs, they can reuse/create Specialist 172 // Pools to bring their own Specialists to label the data. 173 // Customers can add/remove Managers for the Specialist Pool on Cloud console, 174 // then Managers will get email notifications to manage Specialists and tasks on 175 // CrowdCompute console. 176 type SpecialistPoolClient struct { 177 // The internal transport-dependent client. 178 internalClient internalSpecialistPoolClient 179 180 // The call options for this service. 181 CallOptions *SpecialistPoolCallOptions 182 183 // LROClient is used internally to handle long-running operations. 184 // It is exposed so that its CallOptions can be modified if required. 185 // Users should not Close this client. 186 LROClient *lroauto.OperationsClient 187 } 188 189 // Wrapper methods routed to the internal client. 190 191 // Close closes the connection to the API service. The user should invoke this when 192 // the client is no longer required. 193 func (c *SpecialistPoolClient) Close() error { 194 return c.internalClient.Close() 195 } 196 197 // setGoogleClientInfo sets the name and version of the application in 198 // the `x-goog-api-client` header passed on each request. Intended for 199 // use by Google-written clients. 200 func (c *SpecialistPoolClient) setGoogleClientInfo(keyval ...string) { 201 c.internalClient.setGoogleClientInfo(keyval...) 202 } 203 204 // Connection returns a connection to the API service. 205 // 206 // Deprecated: Connections are now pooled so this method does not always 207 // return the same resource. 208 func (c *SpecialistPoolClient) Connection() *grpc.ClientConn { 209 return c.internalClient.Connection() 210 } 211 212 // CreateSpecialistPool creates a SpecialistPool. 213 func (c *SpecialistPoolClient) CreateSpecialistPool(ctx context.Context, req *aiplatformpb.CreateSpecialistPoolRequest, opts ...gax.CallOption) (*CreateSpecialistPoolOperation, error) { 214 return c.internalClient.CreateSpecialistPool(ctx, req, opts...) 215 } 216 217 // CreateSpecialistPoolOperation returns a new CreateSpecialistPoolOperation from a given name. 218 // The name must be that of a previously created CreateSpecialistPoolOperation, possibly from a different process. 219 func (c *SpecialistPoolClient) CreateSpecialistPoolOperation(name string) *CreateSpecialistPoolOperation { 220 return c.internalClient.CreateSpecialistPoolOperation(name) 221 } 222 223 // GetSpecialistPool gets a SpecialistPool. 224 func (c *SpecialistPoolClient) GetSpecialistPool(ctx context.Context, req *aiplatformpb.GetSpecialistPoolRequest, opts ...gax.CallOption) (*aiplatformpb.SpecialistPool, error) { 225 return c.internalClient.GetSpecialistPool(ctx, req, opts...) 226 } 227 228 // ListSpecialistPools lists SpecialistPools in a Location. 229 func (c *SpecialistPoolClient) ListSpecialistPools(ctx context.Context, req *aiplatformpb.ListSpecialistPoolsRequest, opts ...gax.CallOption) *SpecialistPoolIterator { 230 return c.internalClient.ListSpecialistPools(ctx, req, opts...) 231 } 232 233 // DeleteSpecialistPool deletes a SpecialistPool as well as all Specialists in the pool. 234 func (c *SpecialistPoolClient) DeleteSpecialistPool(ctx context.Context, req *aiplatformpb.DeleteSpecialistPoolRequest, opts ...gax.CallOption) (*DeleteSpecialistPoolOperation, error) { 235 return c.internalClient.DeleteSpecialistPool(ctx, req, opts...) 236 } 237 238 // DeleteSpecialistPoolOperation returns a new DeleteSpecialistPoolOperation from a given name. 239 // The name must be that of a previously created DeleteSpecialistPoolOperation, possibly from a different process. 240 func (c *SpecialistPoolClient) DeleteSpecialistPoolOperation(name string) *DeleteSpecialistPoolOperation { 241 return c.internalClient.DeleteSpecialistPoolOperation(name) 242 } 243 244 // UpdateSpecialistPool updates a SpecialistPool. 245 func (c *SpecialistPoolClient) UpdateSpecialistPool(ctx context.Context, req *aiplatformpb.UpdateSpecialistPoolRequest, opts ...gax.CallOption) (*UpdateSpecialistPoolOperation, error) { 246 return c.internalClient.UpdateSpecialistPool(ctx, req, opts...) 247 } 248 249 // UpdateSpecialistPoolOperation returns a new UpdateSpecialistPoolOperation from a given name. 250 // The name must be that of a previously created UpdateSpecialistPoolOperation, possibly from a different process. 251 func (c *SpecialistPoolClient) UpdateSpecialistPoolOperation(name string) *UpdateSpecialistPoolOperation { 252 return c.internalClient.UpdateSpecialistPoolOperation(name) 253 } 254 255 // GetLocation gets information about a location. 256 func (c *SpecialistPoolClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 257 return c.internalClient.GetLocation(ctx, req, opts...) 258 } 259 260 // ListLocations lists information about the supported locations for this service. 261 func (c *SpecialistPoolClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 262 return c.internalClient.ListLocations(ctx, req, opts...) 263 } 264 265 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 266 // if the resource exists and does not have a policy set. 267 func (c *SpecialistPoolClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 268 return c.internalClient.GetIamPolicy(ctx, req, opts...) 269 } 270 271 // SetIamPolicy sets the access control policy on the specified resource. Replaces 272 // any existing policy. 273 // 274 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 275 // errors. 276 func (c *SpecialistPoolClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 277 return c.internalClient.SetIamPolicy(ctx, req, opts...) 278 } 279 280 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 281 // resource does not exist, this will return an empty set of 282 // permissions, not a NOT_FOUND error. 283 // 284 // Note: This operation is designed to be used for building 285 // permission-aware UIs and command-line tools, not for authorization 286 // checking. This operation may “fail open” without warning. 287 func (c *SpecialistPoolClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 288 return c.internalClient.TestIamPermissions(ctx, req, opts...) 289 } 290 291 // CancelOperation is a utility method from google.longrunning.Operations. 292 func (c *SpecialistPoolClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 293 return c.internalClient.CancelOperation(ctx, req, opts...) 294 } 295 296 // DeleteOperation is a utility method from google.longrunning.Operations. 297 func (c *SpecialistPoolClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 298 return c.internalClient.DeleteOperation(ctx, req, opts...) 299 } 300 301 // GetOperation is a utility method from google.longrunning.Operations. 302 func (c *SpecialistPoolClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 303 return c.internalClient.GetOperation(ctx, req, opts...) 304 } 305 306 // ListOperations is a utility method from google.longrunning.Operations. 307 func (c *SpecialistPoolClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 308 return c.internalClient.ListOperations(ctx, req, opts...) 309 } 310 311 // WaitOperation is a utility method from google.longrunning.Operations. 312 func (c *SpecialistPoolClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 313 return c.internalClient.WaitOperation(ctx, req, opts...) 314 } 315 316 // specialistPoolGRPCClient is a client for interacting with Vertex AI API over gRPC transport. 317 // 318 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 319 type specialistPoolGRPCClient struct { 320 // Connection pool of gRPC connections to the service. 321 connPool gtransport.ConnPool 322 323 // Points back to the CallOptions field of the containing SpecialistPoolClient 324 CallOptions **SpecialistPoolCallOptions 325 326 // The gRPC API client. 327 specialistPoolClient aiplatformpb.SpecialistPoolServiceClient 328 329 // LROClient is used internally to handle long-running operations. 330 // It is exposed so that its CallOptions can be modified if required. 331 // Users should not Close this client. 332 LROClient **lroauto.OperationsClient 333 334 operationsClient longrunningpb.OperationsClient 335 336 iamPolicyClient iampb.IAMPolicyClient 337 338 locationsClient locationpb.LocationsClient 339 340 // The x-goog-* metadata to be sent with each request. 341 xGoogHeaders []string 342 343 logger *slog.Logger 344 } 345 346 // NewSpecialistPoolClient creates a new specialist pool service client based on gRPC. 347 // The returned client must be Closed when it is done being used to clean up its underlying connections. 348 // 349 // A service for creating and managing Customer SpecialistPools. 350 // When customers start Data Labeling jobs, they can reuse/create Specialist 351 // Pools to bring their own Specialists to label the data. 352 // Customers can add/remove Managers for the Specialist Pool on Cloud console, 353 // then Managers will get email notifications to manage Specialists and tasks on 354 // CrowdCompute console. 355 func NewSpecialistPoolClient(ctx context.Context, opts ...option.ClientOption) (*SpecialistPoolClient, error) { 356 clientOpts := defaultSpecialistPoolGRPCClientOptions() 357 if newSpecialistPoolClientHook != nil { 358 hookOpts, err := newSpecialistPoolClientHook(ctx, clientHookParams{}) 359 if err != nil { 360 return nil, err 361 } 362 clientOpts = append(clientOpts, hookOpts...) 363 } 364 365 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 366 if err != nil { 367 return nil, err 368 } 369 client := SpecialistPoolClient{CallOptions: defaultSpecialistPoolCallOptions()} 370 371 c := &specialistPoolGRPCClient{ 372 connPool: connPool, 373 specialistPoolClient: aiplatformpb.NewSpecialistPoolServiceClient(connPool), 374 CallOptions: &client.CallOptions, 375 logger: internaloption.GetLogger(opts), 376 operationsClient: longrunningpb.NewOperationsClient(connPool), 377 iamPolicyClient: iampb.NewIAMPolicyClient(connPool), 378 locationsClient: locationpb.NewLocationsClient(connPool), 379 } 380 c.setGoogleClientInfo() 381 382 client.internalClient = c 383 384 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) 385 if err != nil { 386 // This error "should not happen", since we are just reusing old connection pool 387 // and never actually need to dial. 388 // If this does happen, we could leak connp. However, we cannot close conn: 389 // If the user invoked the constructor with option.WithGRPCConn, 390 // we would close a connection that's still in use. 391 // TODO: investigate error conditions. 392 return nil, err 393 } 394 c.LROClient = &client.LROClient 395 return &client, nil 396 } 397 398 // Connection returns a connection to the API service. 399 // 400 // Deprecated: Connections are now pooled so this method does not always 401 // return the same resource. 402 func (c *specialistPoolGRPCClient) Connection() *grpc.ClientConn { 403 return c.connPool.Conn() 404 } 405 406 // setGoogleClientInfo sets the name and version of the application in 407 // the `x-goog-api-client` header passed on each request. Intended for 408 // use by Google-written clients. 409 func (c *specialistPoolGRPCClient) setGoogleClientInfo(keyval ...string) { 410 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 411 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) 412 c.xGoogHeaders = []string{ 413 "x-goog-api-client", gax.XGoogHeader(kv...), 414 } 415 } 416 417 // Close closes the connection to the API service. The user should invoke this when 418 // the client is no longer required. 419 func (c *specialistPoolGRPCClient) Close() error { 420 return c.connPool.Close() 421 } 422 423 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 424 type specialistPoolRESTClient struct { 425 // The http endpoint to connect to. 426 endpoint string 427 428 // The http client. 429 httpClient *http.Client 430 431 // LROClient is used internally to handle long-running operations. 432 // It is exposed so that its CallOptions can be modified if required. 433 // Users should not Close this client. 434 LROClient **lroauto.OperationsClient 435 436 // The x-goog-* headers to be sent with each request. 437 xGoogHeaders []string 438 439 // Points back to the CallOptions field of the containing SpecialistPoolClient 440 CallOptions **SpecialistPoolCallOptions 441 442 logger *slog.Logger 443 } 444 445 // NewSpecialistPoolRESTClient creates a new specialist pool service rest client. 446 // 447 // A service for creating and managing Customer SpecialistPools. 448 // When customers start Data Labeling jobs, they can reuse/create Specialist 449 // Pools to bring their own Specialists to label the data. 450 // Customers can add/remove Managers for the Specialist Pool on Cloud console, 451 // then Managers will get email notifications to manage Specialists and tasks on 452 // CrowdCompute console. 453 func NewSpecialistPoolRESTClient(ctx context.Context, opts ...option.ClientOption) (*SpecialistPoolClient, error) { 454 clientOpts := append(defaultSpecialistPoolRESTClientOptions(), opts...) 455 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) 456 if err != nil { 457 return nil, err 458 } 459 460 callOpts := defaultSpecialistPoolRESTCallOptions() 461 c := &specialistPoolRESTClient{ 462 endpoint: endpoint, 463 httpClient: httpClient, 464 CallOptions: &callOpts, 465 logger: internaloption.GetLogger(opts), 466 } 467 c.setGoogleClientInfo() 468 469 lroOpts := []option.ClientOption{ 470 option.WithHTTPClient(httpClient), 471 option.WithEndpoint(endpoint), 472 } 473 opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...) 474 if err != nil { 475 return nil, err 476 } 477 c.LROClient = &opClient 478 479 return &SpecialistPoolClient{internalClient: c, CallOptions: callOpts}, nil 480 } 481 482 func defaultSpecialistPoolRESTClientOptions() []option.ClientOption { 483 return []option.ClientOption{ 484 internaloption.WithDefaultEndpoint("https://aiplatform.googleapis.com"), 485 internaloption.WithDefaultEndpointTemplate("https://aiplatform.UNIVERSE_DOMAIN"), 486 internaloption.WithDefaultMTLSEndpoint("https://aiplatform.mtls.googleapis.com"), 487 internaloption.WithDefaultUniverseDomain("googleapis.com"), 488 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 489 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 490 internaloption.EnableNewAuthLibrary(), 491 } 492 } 493 494 // setGoogleClientInfo sets the name and version of the application in 495 // the `x-goog-api-client` header passed on each request. Intended for 496 // use by Google-written clients. 497 func (c *specialistPoolRESTClient) setGoogleClientInfo(keyval ...string) { 498 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 499 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) 500 c.xGoogHeaders = []string{ 501 "x-goog-api-client", gax.XGoogHeader(kv...), 502 } 503 } 504 505 // Close closes the connection to the API service. The user should invoke this when 506 // the client is no longer required. 507 func (c *specialistPoolRESTClient) Close() error { 508 // Replace httpClient with nil to force cleanup. 509 c.httpClient = nil 510 return nil 511 } 512 513 // Connection returns a connection to the API service. 514 // 515 // Deprecated: This method always returns nil. 516 func (c *specialistPoolRESTClient) Connection() *grpc.ClientConn { 517 return nil 518 } 519 func (c *specialistPoolGRPCClient) CreateSpecialistPool(ctx context.Context, req *aiplatformpb.CreateSpecialistPoolRequest, opts ...gax.CallOption) (*CreateSpecialistPoolOperation, error) { 520 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 521 522 hds = append(c.xGoogHeaders, hds...) 523 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 524 opts = append((*c.CallOptions).CreateSpecialistPool[0:len((*c.CallOptions).CreateSpecialistPool):len((*c.CallOptions).CreateSpecialistPool)], opts...) 525 var resp *longrunningpb.Operation 526 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 527 var err error 528 resp, err = executeRPC(ctx, c.specialistPoolClient.CreateSpecialistPool, req, settings.GRPC, c.logger, "CreateSpecialistPool") 529 return err 530 }, opts...) 531 if err != nil { 532 return nil, err 533 } 534 return &CreateSpecialistPoolOperation{ 535 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 536 }, nil 537 } 538 539 func (c *specialistPoolGRPCClient) GetSpecialistPool(ctx context.Context, req *aiplatformpb.GetSpecialistPoolRequest, opts ...gax.CallOption) (*aiplatformpb.SpecialistPool, error) { 540 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 541 542 hds = append(c.xGoogHeaders, hds...) 543 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 544 opts = append((*c.CallOptions).GetSpecialistPool[0:len((*c.CallOptions).GetSpecialistPool):len((*c.CallOptions).GetSpecialistPool)], opts...) 545 var resp *aiplatformpb.SpecialistPool 546 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 547 var err error 548 resp, err = executeRPC(ctx, c.specialistPoolClient.GetSpecialistPool, req, settings.GRPC, c.logger, "GetSpecialistPool") 549 return err 550 }, opts...) 551 if err != nil { 552 return nil, err 553 } 554 return resp, nil 555 } 556 557 func (c *specialistPoolGRPCClient) ListSpecialistPools(ctx context.Context, req *aiplatformpb.ListSpecialistPoolsRequest, opts ...gax.CallOption) *SpecialistPoolIterator { 558 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 559 560 hds = append(c.xGoogHeaders, hds...) 561 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 562 opts = append((*c.CallOptions).ListSpecialistPools[0:len((*c.CallOptions).ListSpecialistPools):len((*c.CallOptions).ListSpecialistPools)], opts...) 563 it := &SpecialistPoolIterator{} 564 req = proto.Clone(req).(*aiplatformpb.ListSpecialistPoolsRequest) 565 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.SpecialistPool, string, error) { 566 resp := &aiplatformpb.ListSpecialistPoolsResponse{} 567 if pageToken != "" { 568 req.PageToken = pageToken 569 } 570 if pageSize > math.MaxInt32 { 571 req.PageSize = math.MaxInt32 572 } else if pageSize != 0 { 573 req.PageSize = int32(pageSize) 574 } 575 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 576 var err error 577 resp, err = executeRPC(ctx, c.specialistPoolClient.ListSpecialistPools, req, settings.GRPC, c.logger, "ListSpecialistPools") 578 return err 579 }, opts...) 580 if err != nil { 581 return nil, "", err 582 } 583 584 it.Response = resp 585 return resp.GetSpecialistPools(), resp.GetNextPageToken(), nil 586 } 587 fetch := func(pageSize int, pageToken string) (string, error) { 588 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 589 if err != nil { 590 return "", err 591 } 592 it.items = append(it.items, items...) 593 return nextPageToken, nil 594 } 595 596 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 597 it.pageInfo.MaxSize = int(req.GetPageSize()) 598 it.pageInfo.Token = req.GetPageToken() 599 600 return it 601 } 602 603 func (c *specialistPoolGRPCClient) DeleteSpecialistPool(ctx context.Context, req *aiplatformpb.DeleteSpecialistPoolRequest, opts ...gax.CallOption) (*DeleteSpecialistPoolOperation, error) { 604 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 605 606 hds = append(c.xGoogHeaders, hds...) 607 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 608 opts = append((*c.CallOptions).DeleteSpecialistPool[0:len((*c.CallOptions).DeleteSpecialistPool):len((*c.CallOptions).DeleteSpecialistPool)], opts...) 609 var resp *longrunningpb.Operation 610 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 611 var err error 612 resp, err = executeRPC(ctx, c.specialistPoolClient.DeleteSpecialistPool, req, settings.GRPC, c.logger, "DeleteSpecialistPool") 613 return err 614 }, opts...) 615 if err != nil { 616 return nil, err 617 } 618 return &DeleteSpecialistPoolOperation{ 619 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 620 }, nil 621 } 622 623 func (c *specialistPoolGRPCClient) UpdateSpecialistPool(ctx context.Context, req *aiplatformpb.UpdateSpecialistPoolRequest, opts ...gax.CallOption) (*UpdateSpecialistPoolOperation, error) { 624 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "specialist_pool.name", url.QueryEscape(req.GetSpecialistPool().GetName()))} 625 626 hds = append(c.xGoogHeaders, hds...) 627 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 628 opts = append((*c.CallOptions).UpdateSpecialistPool[0:len((*c.CallOptions).UpdateSpecialistPool):len((*c.CallOptions).UpdateSpecialistPool)], opts...) 629 var resp *longrunningpb.Operation 630 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 631 var err error 632 resp, err = executeRPC(ctx, c.specialistPoolClient.UpdateSpecialistPool, req, settings.GRPC, c.logger, "UpdateSpecialistPool") 633 return err 634 }, opts...) 635 if err != nil { 636 return nil, err 637 } 638 return &UpdateSpecialistPoolOperation{ 639 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 640 }, nil 641 } 642 643 func (c *specialistPoolGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 644 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 645 646 hds = append(c.xGoogHeaders, hds...) 647 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 648 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 649 var resp *locationpb.Location 650 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 651 var err error 652 resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation") 653 return err 654 }, opts...) 655 if err != nil { 656 return nil, err 657 } 658 return resp, nil 659 } 660 661 func (c *specialistPoolGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 662 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 663 664 hds = append(c.xGoogHeaders, hds...) 665 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 666 opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...) 667 it := &LocationIterator{} 668 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 669 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 670 resp := &locationpb.ListLocationsResponse{} 671 if pageToken != "" { 672 req.PageToken = pageToken 673 } 674 if pageSize > math.MaxInt32 { 675 req.PageSize = math.MaxInt32 676 } else if pageSize != 0 { 677 req.PageSize = int32(pageSize) 678 } 679 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 680 var err error 681 resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations") 682 return err 683 }, opts...) 684 if err != nil { 685 return nil, "", err 686 } 687 688 it.Response = resp 689 return resp.GetLocations(), resp.GetNextPageToken(), nil 690 } 691 fetch := func(pageSize int, pageToken string) (string, error) { 692 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 693 if err != nil { 694 return "", err 695 } 696 it.items = append(it.items, items...) 697 return nextPageToken, nil 698 } 699 700 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 701 it.pageInfo.MaxSize = int(req.GetPageSize()) 702 it.pageInfo.Token = req.GetPageToken() 703 704 return it 705 } 706 707 func (c *specialistPoolGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 708 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 709 710 hds = append(c.xGoogHeaders, hds...) 711 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 712 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 713 var resp *iampb.Policy 714 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 715 var err error 716 resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy") 717 return err 718 }, opts...) 719 if err != nil { 720 return nil, err 721 } 722 return resp, nil 723 } 724 725 func (c *specialistPoolGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 726 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 727 728 hds = append(c.xGoogHeaders, hds...) 729 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 730 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 731 var resp *iampb.Policy 732 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 733 var err error 734 resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy") 735 return err 736 }, opts...) 737 if err != nil { 738 return nil, err 739 } 740 return resp, nil 741 } 742 743 func (c *specialistPoolGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 744 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 745 746 hds = append(c.xGoogHeaders, hds...) 747 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 748 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 749 var resp *iampb.TestIamPermissionsResponse 750 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 751 var err error 752 resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions") 753 return err 754 }, opts...) 755 if err != nil { 756 return nil, err 757 } 758 return resp, nil 759 } 760 761 func (c *specialistPoolGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 762 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 763 764 hds = append(c.xGoogHeaders, hds...) 765 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 766 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) 767 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 768 var err error 769 _, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation") 770 return err 771 }, opts...) 772 return err 773 } 774 775 func (c *specialistPoolGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 776 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 777 778 hds = append(c.xGoogHeaders, hds...) 779 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 780 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) 781 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 782 var err error 783 _, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation") 784 return err 785 }, opts...) 786 return err 787 } 788 789 func (c *specialistPoolGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 790 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 791 792 hds = append(c.xGoogHeaders, hds...) 793 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 794 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 795 var resp *longrunningpb.Operation 796 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 797 var err error 798 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation") 799 return err 800 }, opts...) 801 if err != nil { 802 return nil, err 803 } 804 return resp, nil 805 } 806 807 func (c *specialistPoolGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 808 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 809 810 hds = append(c.xGoogHeaders, hds...) 811 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 812 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) 813 it := &OperationIterator{} 814 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 815 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 816 resp := &longrunningpb.ListOperationsResponse{} 817 if pageToken != "" { 818 req.PageToken = pageToken 819 } 820 if pageSize > math.MaxInt32 { 821 req.PageSize = math.MaxInt32 822 } else if pageSize != 0 { 823 req.PageSize = int32(pageSize) 824 } 825 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 826 var err error 827 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations") 828 return err 829 }, opts...) 830 if err != nil { 831 return nil, "", err 832 } 833 834 it.Response = resp 835 return resp.GetOperations(), resp.GetNextPageToken(), nil 836 } 837 fetch := func(pageSize int, pageToken string) (string, error) { 838 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 839 if err != nil { 840 return "", err 841 } 842 it.items = append(it.items, items...) 843 return nextPageToken, nil 844 } 845 846 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 847 it.pageInfo.MaxSize = int(req.GetPageSize()) 848 it.pageInfo.Token = req.GetPageToken() 849 850 return it 851 } 852 853 func (c *specialistPoolGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 854 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 855 856 hds = append(c.xGoogHeaders, hds...) 857 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 858 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 859 var resp *longrunningpb.Operation 860 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 861 var err error 862 resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation") 863 return err 864 }, opts...) 865 if err != nil { 866 return nil, err 867 } 868 return resp, nil 869 } 870 871 // CreateSpecialistPool creates a SpecialistPool. 872 func (c *specialistPoolRESTClient) CreateSpecialistPool(ctx context.Context, req *aiplatformpb.CreateSpecialistPoolRequest, opts ...gax.CallOption) (*CreateSpecialistPoolOperation, error) { 873 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 874 body := req.GetSpecialistPool() 875 jsonReq, err := m.Marshal(body) 876 if err != nil { 877 return nil, err 878 } 879 880 baseUrl, err := url.Parse(c.endpoint) 881 if err != nil { 882 return nil, err 883 } 884 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/specialistPools", req.GetParent()) 885 886 params := url.Values{} 887 params.Add("$alt", "json;enum-encoding=int") 888 889 baseUrl.RawQuery = params.Encode() 890 891 // Build HTTP headers from client and context metadata. 892 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 893 894 hds = append(c.xGoogHeaders, hds...) 895 hds = append(hds, "Content-Type", "application/json") 896 headers := gax.BuildHeaders(ctx, hds...) 897 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 898 resp := &longrunningpb.Operation{} 899 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 900 if settings.Path != "" { 901 baseUrl.Path = settings.Path 902 } 903 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 904 if err != nil { 905 return err 906 } 907 httpReq = httpReq.WithContext(ctx) 908 httpReq.Header = headers 909 910 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateSpecialistPool") 911 if err != nil { 912 return err 913 } 914 if err := unm.Unmarshal(buf, resp); err != nil { 915 return err 916 } 917 918 return nil 919 }, opts...) 920 if e != nil { 921 return nil, e 922 } 923 924 override := fmt.Sprintf("/ui/%s", resp.GetName()) 925 return &CreateSpecialistPoolOperation{ 926 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 927 pollPath: override, 928 }, nil 929 } 930 931 // GetSpecialistPool gets a SpecialistPool. 932 func (c *specialistPoolRESTClient) GetSpecialistPool(ctx context.Context, req *aiplatformpb.GetSpecialistPoolRequest, opts ...gax.CallOption) (*aiplatformpb.SpecialistPool, error) { 933 baseUrl, err := url.Parse(c.endpoint) 934 if err != nil { 935 return nil, err 936 } 937 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 938 939 params := url.Values{} 940 params.Add("$alt", "json;enum-encoding=int") 941 942 baseUrl.RawQuery = params.Encode() 943 944 // Build HTTP headers from client and context metadata. 945 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 946 947 hds = append(c.xGoogHeaders, hds...) 948 hds = append(hds, "Content-Type", "application/json") 949 headers := gax.BuildHeaders(ctx, hds...) 950 opts = append((*c.CallOptions).GetSpecialistPool[0:len((*c.CallOptions).GetSpecialistPool):len((*c.CallOptions).GetSpecialistPool)], opts...) 951 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 952 resp := &aiplatformpb.SpecialistPool{} 953 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 954 if settings.Path != "" { 955 baseUrl.Path = settings.Path 956 } 957 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 958 if err != nil { 959 return err 960 } 961 httpReq = httpReq.WithContext(ctx) 962 httpReq.Header = headers 963 964 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetSpecialistPool") 965 if err != nil { 966 return err 967 } 968 969 if err := unm.Unmarshal(buf, resp); err != nil { 970 return err 971 } 972 973 return nil 974 }, opts...) 975 if e != nil { 976 return nil, e 977 } 978 return resp, nil 979 } 980 981 // ListSpecialistPools lists SpecialistPools in a Location. 982 func (c *specialistPoolRESTClient) ListSpecialistPools(ctx context.Context, req *aiplatformpb.ListSpecialistPoolsRequest, opts ...gax.CallOption) *SpecialistPoolIterator { 983 it := &SpecialistPoolIterator{} 984 req = proto.Clone(req).(*aiplatformpb.ListSpecialistPoolsRequest) 985 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 986 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.SpecialistPool, string, error) { 987 resp := &aiplatformpb.ListSpecialistPoolsResponse{} 988 if pageToken != "" { 989 req.PageToken = pageToken 990 } 991 if pageSize > math.MaxInt32 { 992 req.PageSize = math.MaxInt32 993 } else if pageSize != 0 { 994 req.PageSize = int32(pageSize) 995 } 996 baseUrl, err := url.Parse(c.endpoint) 997 if err != nil { 998 return nil, "", err 999 } 1000 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/specialistPools", req.GetParent()) 1001 1002 params := url.Values{} 1003 params.Add("$alt", "json;enum-encoding=int") 1004 if req.GetPageSize() != 0 { 1005 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1006 } 1007 if req.GetPageToken() != "" { 1008 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1009 } 1010 if req.GetReadMask() != nil { 1011 field, err := protojson.Marshal(req.GetReadMask()) 1012 if err != nil { 1013 return nil, "", err 1014 } 1015 params.Add("readMask", string(field[1:len(field)-1])) 1016 } 1017 1018 baseUrl.RawQuery = params.Encode() 1019 1020 // Build HTTP headers from client and context metadata. 1021 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1022 headers := gax.BuildHeaders(ctx, hds...) 1023 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1024 if settings.Path != "" { 1025 baseUrl.Path = settings.Path 1026 } 1027 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1028 if err != nil { 1029 return err 1030 } 1031 httpReq.Header = headers 1032 1033 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListSpecialistPools") 1034 if err != nil { 1035 return err 1036 } 1037 if err := unm.Unmarshal(buf, resp); err != nil { 1038 return err 1039 } 1040 1041 return nil 1042 }, opts...) 1043 if e != nil { 1044 return nil, "", e 1045 } 1046 it.Response = resp 1047 return resp.GetSpecialistPools(), resp.GetNextPageToken(), nil 1048 } 1049 1050 fetch := func(pageSize int, pageToken string) (string, error) { 1051 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1052 if err != nil { 1053 return "", err 1054 } 1055 it.items = append(it.items, items...) 1056 return nextPageToken, nil 1057 } 1058 1059 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1060 it.pageInfo.MaxSize = int(req.GetPageSize()) 1061 it.pageInfo.Token = req.GetPageToken() 1062 1063 return it 1064 } 1065 1066 // DeleteSpecialistPool deletes a SpecialistPool as well as all Specialists in the pool. 1067 func (c *specialistPoolRESTClient) DeleteSpecialistPool(ctx context.Context, req *aiplatformpb.DeleteSpecialistPoolRequest, opts ...gax.CallOption) (*DeleteSpecialistPoolOperation, error) { 1068 baseUrl, err := url.Parse(c.endpoint) 1069 if err != nil { 1070 return nil, err 1071 } 1072 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 1073 1074 params := url.Values{} 1075 params.Add("$alt", "json;enum-encoding=int") 1076 if req.GetForce() { 1077 params.Add("force", fmt.Sprintf("%v", req.GetForce())) 1078 } 1079 1080 baseUrl.RawQuery = params.Encode() 1081 1082 // Build HTTP headers from client and context metadata. 1083 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1084 1085 hds = append(c.xGoogHeaders, hds...) 1086 hds = append(hds, "Content-Type", "application/json") 1087 headers := gax.BuildHeaders(ctx, hds...) 1088 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1089 resp := &longrunningpb.Operation{} 1090 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1091 if settings.Path != "" { 1092 baseUrl.Path = settings.Path 1093 } 1094 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) 1095 if err != nil { 1096 return err 1097 } 1098 httpReq = httpReq.WithContext(ctx) 1099 httpReq.Header = headers 1100 1101 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteSpecialistPool") 1102 if err != nil { 1103 return err 1104 } 1105 if err := unm.Unmarshal(buf, resp); err != nil { 1106 return err 1107 } 1108 1109 return nil 1110 }, opts...) 1111 if e != nil { 1112 return nil, e 1113 } 1114 1115 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1116 return &DeleteSpecialistPoolOperation{ 1117 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1118 pollPath: override, 1119 }, nil 1120 } 1121 1122 // UpdateSpecialistPool updates a SpecialistPool. 1123 func (c *specialistPoolRESTClient) UpdateSpecialistPool(ctx context.Context, req *aiplatformpb.UpdateSpecialistPoolRequest, opts ...gax.CallOption) (*UpdateSpecialistPoolOperation, error) { 1124 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1125 body := req.GetSpecialistPool() 1126 jsonReq, err := m.Marshal(body) 1127 if err != nil { 1128 return nil, err 1129 } 1130 1131 baseUrl, err := url.Parse(c.endpoint) 1132 if err != nil { 1133 return nil, err 1134 } 1135 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetSpecialistPool().GetName()) 1136 1137 params := url.Values{} 1138 params.Add("$alt", "json;enum-encoding=int") 1139 if req.GetUpdateMask() != nil { 1140 field, err := protojson.Marshal(req.GetUpdateMask()) 1141 if err != nil { 1142 return nil, err 1143 } 1144 params.Add("updateMask", string(field[1:len(field)-1])) 1145 } 1146 1147 baseUrl.RawQuery = params.Encode() 1148 1149 // Build HTTP headers from client and context metadata. 1150 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "specialist_pool.name", url.QueryEscape(req.GetSpecialistPool().GetName()))} 1151 1152 hds = append(c.xGoogHeaders, hds...) 1153 hds = append(hds, "Content-Type", "application/json") 1154 headers := gax.BuildHeaders(ctx, hds...) 1155 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1156 resp := &longrunningpb.Operation{} 1157 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1158 if settings.Path != "" { 1159 baseUrl.Path = settings.Path 1160 } 1161 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) 1162 if err != nil { 1163 return err 1164 } 1165 httpReq = httpReq.WithContext(ctx) 1166 httpReq.Header = headers 1167 1168 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateSpecialistPool") 1169 if err != nil { 1170 return err 1171 } 1172 if err := unm.Unmarshal(buf, resp); err != nil { 1173 return err 1174 } 1175 1176 return nil 1177 }, opts...) 1178 if e != nil { 1179 return nil, e 1180 } 1181 1182 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1183 return &UpdateSpecialistPoolOperation{ 1184 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1185 pollPath: override, 1186 }, nil 1187 } 1188 1189 // GetLocation gets information about a location. 1190 func (c *specialistPoolRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 1191 baseUrl, err := url.Parse(c.endpoint) 1192 if err != nil { 1193 return nil, err 1194 } 1195 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 1196 1197 params := url.Values{} 1198 params.Add("$alt", "json;enum-encoding=int") 1199 1200 baseUrl.RawQuery = params.Encode() 1201 1202 // Build HTTP headers from client and context metadata. 1203 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1204 1205 hds = append(c.xGoogHeaders, hds...) 1206 hds = append(hds, "Content-Type", "application/json") 1207 headers := gax.BuildHeaders(ctx, hds...) 1208 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 1209 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1210 resp := &locationpb.Location{} 1211 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1212 if settings.Path != "" { 1213 baseUrl.Path = settings.Path 1214 } 1215 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1216 if err != nil { 1217 return err 1218 } 1219 httpReq = httpReq.WithContext(ctx) 1220 httpReq.Header = headers 1221 1222 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation") 1223 if err != nil { 1224 return err 1225 } 1226 1227 if err := unm.Unmarshal(buf, resp); err != nil { 1228 return err 1229 } 1230 1231 return nil 1232 }, opts...) 1233 if e != nil { 1234 return nil, e 1235 } 1236 return resp, nil 1237 } 1238 1239 // ListLocations lists information about the supported locations for this service. 1240 func (c *specialistPoolRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 1241 it := &LocationIterator{} 1242 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 1243 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1244 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 1245 resp := &locationpb.ListLocationsResponse{} 1246 if pageToken != "" { 1247 req.PageToken = pageToken 1248 } 1249 if pageSize > math.MaxInt32 { 1250 req.PageSize = math.MaxInt32 1251 } else if pageSize != 0 { 1252 req.PageSize = int32(pageSize) 1253 } 1254 baseUrl, err := url.Parse(c.endpoint) 1255 if err != nil { 1256 return nil, "", err 1257 } 1258 baseUrl.Path += fmt.Sprintf("/ui/%v/locations", req.GetName()) 1259 1260 params := url.Values{} 1261 params.Add("$alt", "json;enum-encoding=int") 1262 if req.GetFilter() != "" { 1263 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 1264 } 1265 if req.GetPageSize() != 0 { 1266 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1267 } 1268 if req.GetPageToken() != "" { 1269 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1270 } 1271 1272 baseUrl.RawQuery = params.Encode() 1273 1274 // Build HTTP headers from client and context metadata. 1275 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1276 headers := gax.BuildHeaders(ctx, hds...) 1277 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1278 if settings.Path != "" { 1279 baseUrl.Path = settings.Path 1280 } 1281 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1282 if err != nil { 1283 return err 1284 } 1285 httpReq.Header = headers 1286 1287 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations") 1288 if err != nil { 1289 return err 1290 } 1291 if err := unm.Unmarshal(buf, resp); err != nil { 1292 return err 1293 } 1294 1295 return nil 1296 }, opts...) 1297 if e != nil { 1298 return nil, "", e 1299 } 1300 it.Response = resp 1301 return resp.GetLocations(), resp.GetNextPageToken(), nil 1302 } 1303 1304 fetch := func(pageSize int, pageToken string) (string, error) { 1305 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1306 if err != nil { 1307 return "", err 1308 } 1309 it.items = append(it.items, items...) 1310 return nextPageToken, nil 1311 } 1312 1313 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1314 it.pageInfo.MaxSize = int(req.GetPageSize()) 1315 it.pageInfo.Token = req.GetPageToken() 1316 1317 return it 1318 } 1319 1320 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 1321 // if the resource exists and does not have a policy set. 1322 func (c *specialistPoolRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 1323 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1324 jsonReq, err := m.Marshal(req) 1325 if err != nil { 1326 return nil, err 1327 } 1328 1329 baseUrl, err := url.Parse(c.endpoint) 1330 if err != nil { 1331 return nil, err 1332 } 1333 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:getIamPolicy", req.GetResource()) 1334 1335 params := url.Values{} 1336 params.Add("$alt", "json;enum-encoding=int") 1337 1338 baseUrl.RawQuery = params.Encode() 1339 1340 // Build HTTP headers from client and context metadata. 1341 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 1342 1343 hds = append(c.xGoogHeaders, hds...) 1344 hds = append(hds, "Content-Type", "application/json") 1345 headers := gax.BuildHeaders(ctx, hds...) 1346 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 1347 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1348 resp := &iampb.Policy{} 1349 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1350 if settings.Path != "" { 1351 baseUrl.Path = settings.Path 1352 } 1353 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1354 if err != nil { 1355 return err 1356 } 1357 httpReq = httpReq.WithContext(ctx) 1358 httpReq.Header = headers 1359 1360 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "GetIamPolicy") 1361 if err != nil { 1362 return err 1363 } 1364 1365 if err := unm.Unmarshal(buf, resp); err != nil { 1366 return err 1367 } 1368 1369 return nil 1370 }, opts...) 1371 if e != nil { 1372 return nil, e 1373 } 1374 return resp, nil 1375 } 1376 1377 // SetIamPolicy sets the access control policy on the specified resource. Replaces 1378 // any existing policy. 1379 // 1380 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 1381 // errors. 1382 func (c *specialistPoolRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 1383 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1384 jsonReq, err := m.Marshal(req) 1385 if err != nil { 1386 return nil, err 1387 } 1388 1389 baseUrl, err := url.Parse(c.endpoint) 1390 if err != nil { 1391 return nil, err 1392 } 1393 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:setIamPolicy", req.GetResource()) 1394 1395 params := url.Values{} 1396 params.Add("$alt", "json;enum-encoding=int") 1397 1398 baseUrl.RawQuery = params.Encode() 1399 1400 // Build HTTP headers from client and context metadata. 1401 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 1402 1403 hds = append(c.xGoogHeaders, hds...) 1404 hds = append(hds, "Content-Type", "application/json") 1405 headers := gax.BuildHeaders(ctx, hds...) 1406 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 1407 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1408 resp := &iampb.Policy{} 1409 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1410 if settings.Path != "" { 1411 baseUrl.Path = settings.Path 1412 } 1413 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1414 if err != nil { 1415 return err 1416 } 1417 httpReq = httpReq.WithContext(ctx) 1418 httpReq.Header = headers 1419 1420 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy") 1421 if err != nil { 1422 return err 1423 } 1424 1425 if err := unm.Unmarshal(buf, resp); err != nil { 1426 return err 1427 } 1428 1429 return nil 1430 }, opts...) 1431 if e != nil { 1432 return nil, e 1433 } 1434 return resp, nil 1435 } 1436 1437 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 1438 // resource does not exist, this will return an empty set of 1439 // permissions, not a NOT_FOUND error. 1440 // 1441 // Note: This operation is designed to be used for building 1442 // permission-aware UIs and command-line tools, not for authorization 1443 // checking. This operation may “fail open” without warning. 1444 func (c *specialistPoolRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 1445 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1446 jsonReq, err := m.Marshal(req) 1447 if err != nil { 1448 return nil, err 1449 } 1450 1451 baseUrl, err := url.Parse(c.endpoint) 1452 if err != nil { 1453 return nil, err 1454 } 1455 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:testIamPermissions", req.GetResource()) 1456 1457 params := url.Values{} 1458 params.Add("$alt", "json;enum-encoding=int") 1459 1460 baseUrl.RawQuery = params.Encode() 1461 1462 // Build HTTP headers from client and context metadata. 1463 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 1464 1465 hds = append(c.xGoogHeaders, hds...) 1466 hds = append(hds, "Content-Type", "application/json") 1467 headers := gax.BuildHeaders(ctx, hds...) 1468 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 1469 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1470 resp := &iampb.TestIamPermissionsResponse{} 1471 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1472 if settings.Path != "" { 1473 baseUrl.Path = settings.Path 1474 } 1475 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1476 if err != nil { 1477 return err 1478 } 1479 httpReq = httpReq.WithContext(ctx) 1480 httpReq.Header = headers 1481 1482 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TestIamPermissions") 1483 if err != nil { 1484 return err 1485 } 1486 1487 if err := unm.Unmarshal(buf, resp); err != nil { 1488 return err 1489 } 1490 1491 return nil 1492 }, opts...) 1493 if e != nil { 1494 return nil, e 1495 } 1496 return resp, nil 1497 } 1498 1499 // CancelOperation is a utility method from google.longrunning.Operations. 1500 func (c *specialistPoolRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 1501 baseUrl, err := url.Parse(c.endpoint) 1502 if err != nil { 1503 return err 1504 } 1505 baseUrl.Path += fmt.Sprintf("/ui/%v:cancel", req.GetName()) 1506 1507 params := url.Values{} 1508 params.Add("$alt", "json;enum-encoding=int") 1509 1510 baseUrl.RawQuery = params.Encode() 1511 1512 // Build HTTP headers from client and context metadata. 1513 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1514 1515 hds = append(c.xGoogHeaders, hds...) 1516 hds = append(hds, "Content-Type", "application/json") 1517 headers := gax.BuildHeaders(ctx, hds...) 1518 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1519 if settings.Path != "" { 1520 baseUrl.Path = settings.Path 1521 } 1522 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil) 1523 if err != nil { 1524 return err 1525 } 1526 httpReq = httpReq.WithContext(ctx) 1527 httpReq.Header = headers 1528 1529 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "CancelOperation") 1530 return err 1531 }, opts...) 1532 } 1533 1534 // DeleteOperation is a utility method from google.longrunning.Operations. 1535 func (c *specialistPoolRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 1536 baseUrl, err := url.Parse(c.endpoint) 1537 if err != nil { 1538 return err 1539 } 1540 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 1541 1542 params := url.Values{} 1543 params.Add("$alt", "json;enum-encoding=int") 1544 1545 baseUrl.RawQuery = params.Encode() 1546 1547 // Build HTTP headers from client and context metadata. 1548 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1549 1550 hds = append(c.xGoogHeaders, hds...) 1551 hds = append(hds, "Content-Type", "application/json") 1552 headers := gax.BuildHeaders(ctx, hds...) 1553 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1554 if settings.Path != "" { 1555 baseUrl.Path = settings.Path 1556 } 1557 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) 1558 if err != nil { 1559 return err 1560 } 1561 httpReq = httpReq.WithContext(ctx) 1562 httpReq.Header = headers 1563 1564 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation") 1565 return err 1566 }, opts...) 1567 } 1568 1569 // GetOperation is a utility method from google.longrunning.Operations. 1570 func (c *specialistPoolRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 1571 baseUrl, err := url.Parse(c.endpoint) 1572 if err != nil { 1573 return nil, err 1574 } 1575 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 1576 1577 params := url.Values{} 1578 params.Add("$alt", "json;enum-encoding=int") 1579 1580 baseUrl.RawQuery = params.Encode() 1581 1582 // Build HTTP headers from client and context metadata. 1583 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1584 1585 hds = append(c.xGoogHeaders, hds...) 1586 hds = append(hds, "Content-Type", "application/json") 1587 headers := gax.BuildHeaders(ctx, hds...) 1588 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 1589 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1590 resp := &longrunningpb.Operation{} 1591 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1592 if settings.Path != "" { 1593 baseUrl.Path = settings.Path 1594 } 1595 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1596 if err != nil { 1597 return err 1598 } 1599 httpReq = httpReq.WithContext(ctx) 1600 httpReq.Header = headers 1601 1602 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation") 1603 if err != nil { 1604 return err 1605 } 1606 1607 if err := unm.Unmarshal(buf, resp); err != nil { 1608 return err 1609 } 1610 1611 return nil 1612 }, opts...) 1613 if e != nil { 1614 return nil, e 1615 } 1616 return resp, nil 1617 } 1618 1619 // ListOperations is a utility method from google.longrunning.Operations. 1620 func (c *specialistPoolRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 1621 it := &OperationIterator{} 1622 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 1623 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1624 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 1625 resp := &longrunningpb.ListOperationsResponse{} 1626 if pageToken != "" { 1627 req.PageToken = pageToken 1628 } 1629 if pageSize > math.MaxInt32 { 1630 req.PageSize = math.MaxInt32 1631 } else if pageSize != 0 { 1632 req.PageSize = int32(pageSize) 1633 } 1634 baseUrl, err := url.Parse(c.endpoint) 1635 if err != nil { 1636 return nil, "", err 1637 } 1638 baseUrl.Path += fmt.Sprintf("/ui/%v/operations", req.GetName()) 1639 1640 params := url.Values{} 1641 params.Add("$alt", "json;enum-encoding=int") 1642 if req.GetFilter() != "" { 1643 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 1644 } 1645 if req.GetPageSize() != 0 { 1646 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1647 } 1648 if req.GetPageToken() != "" { 1649 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1650 } 1651 1652 baseUrl.RawQuery = params.Encode() 1653 1654 // Build HTTP headers from client and context metadata. 1655 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1656 headers := gax.BuildHeaders(ctx, hds...) 1657 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1658 if settings.Path != "" { 1659 baseUrl.Path = settings.Path 1660 } 1661 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1662 if err != nil { 1663 return err 1664 } 1665 httpReq.Header = headers 1666 1667 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations") 1668 if err != nil { 1669 return err 1670 } 1671 if err := unm.Unmarshal(buf, resp); err != nil { 1672 return err 1673 } 1674 1675 return nil 1676 }, opts...) 1677 if e != nil { 1678 return nil, "", e 1679 } 1680 it.Response = resp 1681 return resp.GetOperations(), resp.GetNextPageToken(), nil 1682 } 1683 1684 fetch := func(pageSize int, pageToken string) (string, error) { 1685 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1686 if err != nil { 1687 return "", err 1688 } 1689 it.items = append(it.items, items...) 1690 return nextPageToken, nil 1691 } 1692 1693 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1694 it.pageInfo.MaxSize = int(req.GetPageSize()) 1695 it.pageInfo.Token = req.GetPageToken() 1696 1697 return it 1698 } 1699 1700 // WaitOperation is a utility method from google.longrunning.Operations. 1701 func (c *specialistPoolRESTClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 1702 baseUrl, err := url.Parse(c.endpoint) 1703 if err != nil { 1704 return nil, err 1705 } 1706 baseUrl.Path += fmt.Sprintf("/ui/%v:wait", req.GetName()) 1707 1708 params := url.Values{} 1709 params.Add("$alt", "json;enum-encoding=int") 1710 if req.GetTimeout() != nil { 1711 field, err := protojson.Marshal(req.GetTimeout()) 1712 if err != nil { 1713 return nil, err 1714 } 1715 params.Add("timeout", string(field[1:len(field)-1])) 1716 } 1717 1718 baseUrl.RawQuery = params.Encode() 1719 1720 // Build HTTP headers from client and context metadata. 1721 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1722 1723 hds = append(c.xGoogHeaders, hds...) 1724 hds = append(hds, "Content-Type", "application/json") 1725 headers := gax.BuildHeaders(ctx, hds...) 1726 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 1727 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1728 resp := &longrunningpb.Operation{} 1729 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1730 if settings.Path != "" { 1731 baseUrl.Path = settings.Path 1732 } 1733 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil) 1734 if err != nil { 1735 return err 1736 } 1737 httpReq = httpReq.WithContext(ctx) 1738 httpReq.Header = headers 1739 1740 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "WaitOperation") 1741 if err != nil { 1742 return err 1743 } 1744 1745 if err := unm.Unmarshal(buf, resp); err != nil { 1746 return err 1747 } 1748 1749 return nil 1750 }, opts...) 1751 if e != nil { 1752 return nil, e 1753 } 1754 return resp, nil 1755 } 1756 1757 // CreateSpecialistPoolOperation returns a new CreateSpecialistPoolOperation from a given name. 1758 // The name must be that of a previously created CreateSpecialistPoolOperation, possibly from a different process. 1759 func (c *specialistPoolGRPCClient) CreateSpecialistPoolOperation(name string) *CreateSpecialistPoolOperation { 1760 return &CreateSpecialistPoolOperation{ 1761 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1762 } 1763 } 1764 1765 // CreateSpecialistPoolOperation returns a new CreateSpecialistPoolOperation from a given name. 1766 // The name must be that of a previously created CreateSpecialistPoolOperation, possibly from a different process. 1767 func (c *specialistPoolRESTClient) CreateSpecialistPoolOperation(name string) *CreateSpecialistPoolOperation { 1768 override := fmt.Sprintf("/ui/%s", name) 1769 return &CreateSpecialistPoolOperation{ 1770 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1771 pollPath: override, 1772 } 1773 } 1774 1775 // DeleteSpecialistPoolOperation returns a new DeleteSpecialistPoolOperation from a given name. 1776 // The name must be that of a previously created DeleteSpecialistPoolOperation, possibly from a different process. 1777 func (c *specialistPoolGRPCClient) DeleteSpecialistPoolOperation(name string) *DeleteSpecialistPoolOperation { 1778 return &DeleteSpecialistPoolOperation{ 1779 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1780 } 1781 } 1782 1783 // DeleteSpecialistPoolOperation returns a new DeleteSpecialistPoolOperation from a given name. 1784 // The name must be that of a previously created DeleteSpecialistPoolOperation, possibly from a different process. 1785 func (c *specialistPoolRESTClient) DeleteSpecialistPoolOperation(name string) *DeleteSpecialistPoolOperation { 1786 override := fmt.Sprintf("/ui/%s", name) 1787 return &DeleteSpecialistPoolOperation{ 1788 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1789 pollPath: override, 1790 } 1791 } 1792 1793 // UpdateSpecialistPoolOperation returns a new UpdateSpecialistPoolOperation from a given name. 1794 // The name must be that of a previously created UpdateSpecialistPoolOperation, possibly from a different process. 1795 func (c *specialistPoolGRPCClient) UpdateSpecialistPoolOperation(name string) *UpdateSpecialistPoolOperation { 1796 return &UpdateSpecialistPoolOperation{ 1797 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1798 } 1799 } 1800 1801 // UpdateSpecialistPoolOperation returns a new UpdateSpecialistPoolOperation from a given name. 1802 // The name must be that of a previously created UpdateSpecialistPoolOperation, possibly from a different process. 1803 func (c *specialistPoolRESTClient) UpdateSpecialistPoolOperation(name string) *UpdateSpecialistPoolOperation { 1804 override := fmt.Sprintf("/ui/%s", name) 1805 return &UpdateSpecialistPoolOperation{ 1806 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1807 pollPath: override, 1808 } 1809 }