cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/endpoint_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 newEndpointClientHook clientHook 47 48 // EndpointCallOptions contains the retry settings for each method of EndpointClient. 49 type EndpointCallOptions struct { 50 CreateEndpoint []gax.CallOption 51 GetEndpoint []gax.CallOption 52 ListEndpoints []gax.CallOption 53 UpdateEndpoint []gax.CallOption 54 UpdateEndpointLongRunning []gax.CallOption 55 DeleteEndpoint []gax.CallOption 56 DeployModel []gax.CallOption 57 UndeployModel []gax.CallOption 58 MutateDeployedModel []gax.CallOption 59 SetPublisherModelConfig []gax.CallOption 60 FetchPublisherModelConfig []gax.CallOption 61 GetLocation []gax.CallOption 62 ListLocations []gax.CallOption 63 GetIamPolicy []gax.CallOption 64 SetIamPolicy []gax.CallOption 65 TestIamPermissions []gax.CallOption 66 CancelOperation []gax.CallOption 67 DeleteOperation []gax.CallOption 68 GetOperation []gax.CallOption 69 ListOperations []gax.CallOption 70 WaitOperation []gax.CallOption 71 } 72 73 func defaultEndpointGRPCClientOptions() []option.ClientOption { 74 return []option.ClientOption{ 75 internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"), 76 internaloption.WithDefaultEndpointTemplate("aiplatform.UNIVERSE_DOMAIN:443"), 77 internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), 78 internaloption.WithDefaultUniverseDomain("googleapis.com"), 79 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 80 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 81 internaloption.EnableJwtWithScope(), 82 internaloption.EnableNewAuthLibrary(), 83 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 84 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 85 } 86 } 87 88 func defaultEndpointCallOptions() *EndpointCallOptions { 89 return &EndpointCallOptions{ 90 CreateEndpoint: []gax.CallOption{ 91 gax.WithTimeout(5000 * time.Millisecond), 92 }, 93 GetEndpoint: []gax.CallOption{ 94 gax.WithTimeout(5000 * time.Millisecond), 95 }, 96 ListEndpoints: []gax.CallOption{ 97 gax.WithTimeout(5000 * time.Millisecond), 98 }, 99 UpdateEndpoint: []gax.CallOption{ 100 gax.WithTimeout(5000 * time.Millisecond), 101 }, 102 UpdateEndpointLongRunning: []gax.CallOption{}, 103 DeleteEndpoint: []gax.CallOption{ 104 gax.WithTimeout(5000 * time.Millisecond), 105 }, 106 DeployModel: []gax.CallOption{ 107 gax.WithTimeout(5000 * time.Millisecond), 108 }, 109 UndeployModel: []gax.CallOption{ 110 gax.WithTimeout(5000 * time.Millisecond), 111 }, 112 MutateDeployedModel: []gax.CallOption{}, 113 SetPublisherModelConfig: []gax.CallOption{}, 114 FetchPublisherModelConfig: []gax.CallOption{}, 115 GetLocation: []gax.CallOption{}, 116 ListLocations: []gax.CallOption{}, 117 GetIamPolicy: []gax.CallOption{}, 118 SetIamPolicy: []gax.CallOption{}, 119 TestIamPermissions: []gax.CallOption{}, 120 CancelOperation: []gax.CallOption{}, 121 DeleteOperation: []gax.CallOption{}, 122 GetOperation: []gax.CallOption{}, 123 ListOperations: []gax.CallOption{}, 124 WaitOperation: []gax.CallOption{}, 125 } 126 } 127 128 func defaultEndpointRESTCallOptions() *EndpointCallOptions { 129 return &EndpointCallOptions{ 130 CreateEndpoint: []gax.CallOption{ 131 gax.WithTimeout(5000 * time.Millisecond), 132 }, 133 GetEndpoint: []gax.CallOption{ 134 gax.WithTimeout(5000 * time.Millisecond), 135 }, 136 ListEndpoints: []gax.CallOption{ 137 gax.WithTimeout(5000 * time.Millisecond), 138 }, 139 UpdateEndpoint: []gax.CallOption{ 140 gax.WithTimeout(5000 * time.Millisecond), 141 }, 142 UpdateEndpointLongRunning: []gax.CallOption{}, 143 DeleteEndpoint: []gax.CallOption{ 144 gax.WithTimeout(5000 * time.Millisecond), 145 }, 146 DeployModel: []gax.CallOption{ 147 gax.WithTimeout(5000 * time.Millisecond), 148 }, 149 UndeployModel: []gax.CallOption{ 150 gax.WithTimeout(5000 * time.Millisecond), 151 }, 152 MutateDeployedModel: []gax.CallOption{}, 153 SetPublisherModelConfig: []gax.CallOption{}, 154 FetchPublisherModelConfig: []gax.CallOption{}, 155 GetLocation: []gax.CallOption{}, 156 ListLocations: []gax.CallOption{}, 157 GetIamPolicy: []gax.CallOption{}, 158 SetIamPolicy: []gax.CallOption{}, 159 TestIamPermissions: []gax.CallOption{}, 160 CancelOperation: []gax.CallOption{}, 161 DeleteOperation: []gax.CallOption{}, 162 GetOperation: []gax.CallOption{}, 163 ListOperations: []gax.CallOption{}, 164 WaitOperation: []gax.CallOption{}, 165 } 166 } 167 168 // internalEndpointClient is an interface that defines the methods available from Vertex AI API. 169 type internalEndpointClient interface { 170 Close() error 171 setGoogleClientInfo(...string) 172 Connection() *grpc.ClientConn 173 CreateEndpoint(context.Context, *aiplatformpb.CreateEndpointRequest, ...gax.CallOption) (*CreateEndpointOperation, error) 174 CreateEndpointOperation(name string) *CreateEndpointOperation 175 GetEndpoint(context.Context, *aiplatformpb.GetEndpointRequest, ...gax.CallOption) (*aiplatformpb.Endpoint, error) 176 ListEndpoints(context.Context, *aiplatformpb.ListEndpointsRequest, ...gax.CallOption) *EndpointIterator 177 UpdateEndpoint(context.Context, *aiplatformpb.UpdateEndpointRequest, ...gax.CallOption) (*aiplatformpb.Endpoint, error) 178 UpdateEndpointLongRunning(context.Context, *aiplatformpb.UpdateEndpointLongRunningRequest, ...gax.CallOption) (*UpdateEndpointLongRunningOperation, error) 179 UpdateEndpointLongRunningOperation(name string) *UpdateEndpointLongRunningOperation 180 DeleteEndpoint(context.Context, *aiplatformpb.DeleteEndpointRequest, ...gax.CallOption) (*DeleteEndpointOperation, error) 181 DeleteEndpointOperation(name string) *DeleteEndpointOperation 182 DeployModel(context.Context, *aiplatformpb.DeployModelRequest, ...gax.CallOption) (*DeployModelOperation, error) 183 DeployModelOperation(name string) *DeployModelOperation 184 UndeployModel(context.Context, *aiplatformpb.UndeployModelRequest, ...gax.CallOption) (*UndeployModelOperation, error) 185 UndeployModelOperation(name string) *UndeployModelOperation 186 MutateDeployedModel(context.Context, *aiplatformpb.MutateDeployedModelRequest, ...gax.CallOption) (*MutateDeployedModelOperation, error) 187 MutateDeployedModelOperation(name string) *MutateDeployedModelOperation 188 SetPublisherModelConfig(context.Context, *aiplatformpb.SetPublisherModelConfigRequest, ...gax.CallOption) (*SetPublisherModelConfigOperation, error) 189 SetPublisherModelConfigOperation(name string) *SetPublisherModelConfigOperation 190 FetchPublisherModelConfig(context.Context, *aiplatformpb.FetchPublisherModelConfigRequest, ...gax.CallOption) (*aiplatformpb.PublisherModelConfig, error) 191 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error) 192 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator 193 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 194 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 195 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) 196 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error 197 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error 198 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 199 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator 200 WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 201 } 202 203 // EndpointClient is a client for interacting with Vertex AI API. 204 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 205 // 206 // A service for managing Vertex AI’s Endpoints. 207 type EndpointClient struct { 208 // The internal transport-dependent client. 209 internalClient internalEndpointClient 210 211 // The call options for this service. 212 CallOptions *EndpointCallOptions 213 214 // LROClient is used internally to handle long-running operations. 215 // It is exposed so that its CallOptions can be modified if required. 216 // Users should not Close this client. 217 LROClient *lroauto.OperationsClient 218 } 219 220 // Wrapper methods routed to the internal client. 221 222 // Close closes the connection to the API service. The user should invoke this when 223 // the client is no longer required. 224 func (c *EndpointClient) Close() error { 225 return c.internalClient.Close() 226 } 227 228 // setGoogleClientInfo sets the name and version of the application in 229 // the `x-goog-api-client` header passed on each request. Intended for 230 // use by Google-written clients. 231 func (c *EndpointClient) setGoogleClientInfo(keyval ...string) { 232 c.internalClient.setGoogleClientInfo(keyval...) 233 } 234 235 // Connection returns a connection to the API service. 236 // 237 // Deprecated: Connections are now pooled so this method does not always 238 // return the same resource. 239 func (c *EndpointClient) Connection() *grpc.ClientConn { 240 return c.internalClient.Connection() 241 } 242 243 // CreateEndpoint creates an Endpoint. 244 func (c *EndpointClient) CreateEndpoint(ctx context.Context, req *aiplatformpb.CreateEndpointRequest, opts ...gax.CallOption) (*CreateEndpointOperation, error) { 245 return c.internalClient.CreateEndpoint(ctx, req, opts...) 246 } 247 248 // CreateEndpointOperation returns a new CreateEndpointOperation from a given name. 249 // The name must be that of a previously created CreateEndpointOperation, possibly from a different process. 250 func (c *EndpointClient) CreateEndpointOperation(name string) *CreateEndpointOperation { 251 return c.internalClient.CreateEndpointOperation(name) 252 } 253 254 // GetEndpoint gets an Endpoint. 255 func (c *EndpointClient) GetEndpoint(ctx context.Context, req *aiplatformpb.GetEndpointRequest, opts ...gax.CallOption) (*aiplatformpb.Endpoint, error) { 256 return c.internalClient.GetEndpoint(ctx, req, opts...) 257 } 258 259 // ListEndpoints lists Endpoints in a Location. 260 func (c *EndpointClient) ListEndpoints(ctx context.Context, req *aiplatformpb.ListEndpointsRequest, opts ...gax.CallOption) *EndpointIterator { 261 return c.internalClient.ListEndpoints(ctx, req, opts...) 262 } 263 264 // UpdateEndpoint updates an Endpoint. 265 func (c *EndpointClient) UpdateEndpoint(ctx context.Context, req *aiplatformpb.UpdateEndpointRequest, opts ...gax.CallOption) (*aiplatformpb.Endpoint, error) { 266 return c.internalClient.UpdateEndpoint(ctx, req, opts...) 267 } 268 269 // UpdateEndpointLongRunning updates an Endpoint with a long running operation. 270 func (c *EndpointClient) UpdateEndpointLongRunning(ctx context.Context, req *aiplatformpb.UpdateEndpointLongRunningRequest, opts ...gax.CallOption) (*UpdateEndpointLongRunningOperation, error) { 271 return c.internalClient.UpdateEndpointLongRunning(ctx, req, opts...) 272 } 273 274 // UpdateEndpointLongRunningOperation returns a new UpdateEndpointLongRunningOperation from a given name. 275 // The name must be that of a previously created UpdateEndpointLongRunningOperation, possibly from a different process. 276 func (c *EndpointClient) UpdateEndpointLongRunningOperation(name string) *UpdateEndpointLongRunningOperation { 277 return c.internalClient.UpdateEndpointLongRunningOperation(name) 278 } 279 280 // DeleteEndpoint deletes an Endpoint. 281 func (c *EndpointClient) DeleteEndpoint(ctx context.Context, req *aiplatformpb.DeleteEndpointRequest, opts ...gax.CallOption) (*DeleteEndpointOperation, error) { 282 return c.internalClient.DeleteEndpoint(ctx, req, opts...) 283 } 284 285 // DeleteEndpointOperation returns a new DeleteEndpointOperation from a given name. 286 // The name must be that of a previously created DeleteEndpointOperation, possibly from a different process. 287 func (c *EndpointClient) DeleteEndpointOperation(name string) *DeleteEndpointOperation { 288 return c.internalClient.DeleteEndpointOperation(name) 289 } 290 291 // DeployModel deploys a Model into this Endpoint, creating a DeployedModel within it. 292 func (c *EndpointClient) DeployModel(ctx context.Context, req *aiplatformpb.DeployModelRequest, opts ...gax.CallOption) (*DeployModelOperation, error) { 293 return c.internalClient.DeployModel(ctx, req, opts...) 294 } 295 296 // DeployModelOperation returns a new DeployModelOperation from a given name. 297 // The name must be that of a previously created DeployModelOperation, possibly from a different process. 298 func (c *EndpointClient) DeployModelOperation(name string) *DeployModelOperation { 299 return c.internalClient.DeployModelOperation(name) 300 } 301 302 // UndeployModel undeploys a Model from an Endpoint, removing a DeployedModel from it, and 303 // freeing all resources it’s using. 304 func (c *EndpointClient) UndeployModel(ctx context.Context, req *aiplatformpb.UndeployModelRequest, opts ...gax.CallOption) (*UndeployModelOperation, error) { 305 return c.internalClient.UndeployModel(ctx, req, opts...) 306 } 307 308 // UndeployModelOperation returns a new UndeployModelOperation from a given name. 309 // The name must be that of a previously created UndeployModelOperation, possibly from a different process. 310 func (c *EndpointClient) UndeployModelOperation(name string) *UndeployModelOperation { 311 return c.internalClient.UndeployModelOperation(name) 312 } 313 314 // MutateDeployedModel updates an existing deployed model. Updatable fields include 315 // min_replica_count, max_replica_count, required_replica_count, 316 // autoscaling_metric_specs, disable_container_logging (v1 only), and 317 // enable_container_logging (v1beta1 only). 318 func (c *EndpointClient) MutateDeployedModel(ctx context.Context, req *aiplatformpb.MutateDeployedModelRequest, opts ...gax.CallOption) (*MutateDeployedModelOperation, error) { 319 return c.internalClient.MutateDeployedModel(ctx, req, opts...) 320 } 321 322 // MutateDeployedModelOperation returns a new MutateDeployedModelOperation from a given name. 323 // The name must be that of a previously created MutateDeployedModelOperation, possibly from a different process. 324 func (c *EndpointClient) MutateDeployedModelOperation(name string) *MutateDeployedModelOperation { 325 return c.internalClient.MutateDeployedModelOperation(name) 326 } 327 328 // SetPublisherModelConfig sets (creates or updates) configs of publisher models. For example, sets 329 // the request/response logging config. 330 func (c *EndpointClient) SetPublisherModelConfig(ctx context.Context, req *aiplatformpb.SetPublisherModelConfigRequest, opts ...gax.CallOption) (*SetPublisherModelConfigOperation, error) { 331 return c.internalClient.SetPublisherModelConfig(ctx, req, opts...) 332 } 333 334 // SetPublisherModelConfigOperation returns a new SetPublisherModelConfigOperation from a given name. 335 // The name must be that of a previously created SetPublisherModelConfigOperation, possibly from a different process. 336 func (c *EndpointClient) SetPublisherModelConfigOperation(name string) *SetPublisherModelConfigOperation { 337 return c.internalClient.SetPublisherModelConfigOperation(name) 338 } 339 340 // FetchPublisherModelConfig fetches the configs of publisher models. 341 func (c *EndpointClient) FetchPublisherModelConfig(ctx context.Context, req *aiplatformpb.FetchPublisherModelConfigRequest, opts ...gax.CallOption) (*aiplatformpb.PublisherModelConfig, error) { 342 return c.internalClient.FetchPublisherModelConfig(ctx, req, opts...) 343 } 344 345 // GetLocation gets information about a location. 346 func (c *EndpointClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 347 return c.internalClient.GetLocation(ctx, req, opts...) 348 } 349 350 // ListLocations lists information about the supported locations for this service. 351 func (c *EndpointClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 352 return c.internalClient.ListLocations(ctx, req, opts...) 353 } 354 355 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 356 // if the resource exists and does not have a policy set. 357 func (c *EndpointClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 358 return c.internalClient.GetIamPolicy(ctx, req, opts...) 359 } 360 361 // SetIamPolicy sets the access control policy on the specified resource. Replaces 362 // any existing policy. 363 // 364 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 365 // errors. 366 func (c *EndpointClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 367 return c.internalClient.SetIamPolicy(ctx, req, opts...) 368 } 369 370 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 371 // resource does not exist, this will return an empty set of 372 // permissions, not a NOT_FOUND error. 373 // 374 // Note: This operation is designed to be used for building 375 // permission-aware UIs and command-line tools, not for authorization 376 // checking. This operation may “fail open” without warning. 377 func (c *EndpointClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 378 return c.internalClient.TestIamPermissions(ctx, req, opts...) 379 } 380 381 // CancelOperation is a utility method from google.longrunning.Operations. 382 func (c *EndpointClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 383 return c.internalClient.CancelOperation(ctx, req, opts...) 384 } 385 386 // DeleteOperation is a utility method from google.longrunning.Operations. 387 func (c *EndpointClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 388 return c.internalClient.DeleteOperation(ctx, req, opts...) 389 } 390 391 // GetOperation is a utility method from google.longrunning.Operations. 392 func (c *EndpointClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 393 return c.internalClient.GetOperation(ctx, req, opts...) 394 } 395 396 // ListOperations is a utility method from google.longrunning.Operations. 397 func (c *EndpointClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 398 return c.internalClient.ListOperations(ctx, req, opts...) 399 } 400 401 // WaitOperation is a utility method from google.longrunning.Operations. 402 func (c *EndpointClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 403 return c.internalClient.WaitOperation(ctx, req, opts...) 404 } 405 406 // endpointGRPCClient is a client for interacting with Vertex AI API over gRPC transport. 407 // 408 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 409 type endpointGRPCClient struct { 410 // Connection pool of gRPC connections to the service. 411 connPool gtransport.ConnPool 412 413 // Points back to the CallOptions field of the containing EndpointClient 414 CallOptions **EndpointCallOptions 415 416 // The gRPC API client. 417 endpointClient aiplatformpb.EndpointServiceClient 418 419 // LROClient is used internally to handle long-running operations. 420 // It is exposed so that its CallOptions can be modified if required. 421 // Users should not Close this client. 422 LROClient **lroauto.OperationsClient 423 424 operationsClient longrunningpb.OperationsClient 425 426 iamPolicyClient iampb.IAMPolicyClient 427 428 locationsClient locationpb.LocationsClient 429 430 // The x-goog-* metadata to be sent with each request. 431 xGoogHeaders []string 432 433 logger *slog.Logger 434 } 435 436 // NewEndpointClient creates a new endpoint service client based on gRPC. 437 // The returned client must be Closed when it is done being used to clean up its underlying connections. 438 // 439 // A service for managing Vertex AI’s Endpoints. 440 func NewEndpointClient(ctx context.Context, opts ...option.ClientOption) (*EndpointClient, error) { 441 clientOpts := defaultEndpointGRPCClientOptions() 442 if newEndpointClientHook != nil { 443 hookOpts, err := newEndpointClientHook(ctx, clientHookParams{}) 444 if err != nil { 445 return nil, err 446 } 447 clientOpts = append(clientOpts, hookOpts...) 448 } 449 450 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 451 if err != nil { 452 return nil, err 453 } 454 client := EndpointClient{CallOptions: defaultEndpointCallOptions()} 455 456 c := &endpointGRPCClient{ 457 connPool: connPool, 458 endpointClient: aiplatformpb.NewEndpointServiceClient(connPool), 459 CallOptions: &client.CallOptions, 460 logger: internaloption.GetLogger(opts), 461 operationsClient: longrunningpb.NewOperationsClient(connPool), 462 iamPolicyClient: iampb.NewIAMPolicyClient(connPool), 463 locationsClient: locationpb.NewLocationsClient(connPool), 464 } 465 c.setGoogleClientInfo() 466 467 client.internalClient = c 468 469 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) 470 if err != nil { 471 // This error "should not happen", since we are just reusing old connection pool 472 // and never actually need to dial. 473 // If this does happen, we could leak connp. However, we cannot close conn: 474 // If the user invoked the constructor with option.WithGRPCConn, 475 // we would close a connection that's still in use. 476 // TODO: investigate error conditions. 477 return nil, err 478 } 479 c.LROClient = &client.LROClient 480 return &client, nil 481 } 482 483 // Connection returns a connection to the API service. 484 // 485 // Deprecated: Connections are now pooled so this method does not always 486 // return the same resource. 487 func (c *endpointGRPCClient) Connection() *grpc.ClientConn { 488 return c.connPool.Conn() 489 } 490 491 // setGoogleClientInfo sets the name and version of the application in 492 // the `x-goog-api-client` header passed on each request. Intended for 493 // use by Google-written clients. 494 func (c *endpointGRPCClient) setGoogleClientInfo(keyval ...string) { 495 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 496 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) 497 c.xGoogHeaders = []string{ 498 "x-goog-api-client", gax.XGoogHeader(kv...), 499 } 500 } 501 502 // Close closes the connection to the API service. The user should invoke this when 503 // the client is no longer required. 504 func (c *endpointGRPCClient) Close() error { 505 return c.connPool.Close() 506 } 507 508 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 509 type endpointRESTClient struct { 510 // The http endpoint to connect to. 511 endpoint string 512 513 // The http client. 514 httpClient *http.Client 515 516 // LROClient is used internally to handle long-running operations. 517 // It is exposed so that its CallOptions can be modified if required. 518 // Users should not Close this client. 519 LROClient **lroauto.OperationsClient 520 521 // The x-goog-* headers to be sent with each request. 522 xGoogHeaders []string 523 524 // Points back to the CallOptions field of the containing EndpointClient 525 CallOptions **EndpointCallOptions 526 527 logger *slog.Logger 528 } 529 530 // NewEndpointRESTClient creates a new endpoint service rest client. 531 // 532 // A service for managing Vertex AI’s Endpoints. 533 func NewEndpointRESTClient(ctx context.Context, opts ...option.ClientOption) (*EndpointClient, error) { 534 clientOpts := append(defaultEndpointRESTClientOptions(), opts...) 535 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) 536 if err != nil { 537 return nil, err 538 } 539 540 callOpts := defaultEndpointRESTCallOptions() 541 c := &endpointRESTClient{ 542 endpoint: endpoint, 543 httpClient: httpClient, 544 CallOptions: &callOpts, 545 logger: internaloption.GetLogger(opts), 546 } 547 c.setGoogleClientInfo() 548 549 lroOpts := []option.ClientOption{ 550 option.WithHTTPClient(httpClient), 551 option.WithEndpoint(endpoint), 552 } 553 opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...) 554 if err != nil { 555 return nil, err 556 } 557 c.LROClient = &opClient 558 559 return &EndpointClient{internalClient: c, CallOptions: callOpts}, nil 560 } 561 562 func defaultEndpointRESTClientOptions() []option.ClientOption { 563 return []option.ClientOption{ 564 internaloption.WithDefaultEndpoint("https://aiplatform.googleapis.com"), 565 internaloption.WithDefaultEndpointTemplate("https://aiplatform.UNIVERSE_DOMAIN"), 566 internaloption.WithDefaultMTLSEndpoint("https://aiplatform.mtls.googleapis.com"), 567 internaloption.WithDefaultUniverseDomain("googleapis.com"), 568 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 569 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 570 internaloption.EnableNewAuthLibrary(), 571 } 572 } 573 574 // setGoogleClientInfo sets the name and version of the application in 575 // the `x-goog-api-client` header passed on each request. Intended for 576 // use by Google-written clients. 577 func (c *endpointRESTClient) setGoogleClientInfo(keyval ...string) { 578 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 579 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) 580 c.xGoogHeaders = []string{ 581 "x-goog-api-client", gax.XGoogHeader(kv...), 582 } 583 } 584 585 // Close closes the connection to the API service. The user should invoke this when 586 // the client is no longer required. 587 func (c *endpointRESTClient) Close() error { 588 // Replace httpClient with nil to force cleanup. 589 c.httpClient = nil 590 return nil 591 } 592 593 // Connection returns a connection to the API service. 594 // 595 // Deprecated: This method always returns nil. 596 func (c *endpointRESTClient) Connection() *grpc.ClientConn { 597 return nil 598 } 599 func (c *endpointGRPCClient) CreateEndpoint(ctx context.Context, req *aiplatformpb.CreateEndpointRequest, opts ...gax.CallOption) (*CreateEndpointOperation, error) { 600 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 601 602 hds = append(c.xGoogHeaders, hds...) 603 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 604 opts = append((*c.CallOptions).CreateEndpoint[0:len((*c.CallOptions).CreateEndpoint):len((*c.CallOptions).CreateEndpoint)], opts...) 605 var resp *longrunningpb.Operation 606 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 607 var err error 608 resp, err = executeRPC(ctx, c.endpointClient.CreateEndpoint, req, settings.GRPC, c.logger, "CreateEndpoint") 609 return err 610 }, opts...) 611 if err != nil { 612 return nil, err 613 } 614 return &CreateEndpointOperation{ 615 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 616 }, nil 617 } 618 619 func (c *endpointGRPCClient) GetEndpoint(ctx context.Context, req *aiplatformpb.GetEndpointRequest, opts ...gax.CallOption) (*aiplatformpb.Endpoint, error) { 620 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 621 622 hds = append(c.xGoogHeaders, hds...) 623 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 624 opts = append((*c.CallOptions).GetEndpoint[0:len((*c.CallOptions).GetEndpoint):len((*c.CallOptions).GetEndpoint)], opts...) 625 var resp *aiplatformpb.Endpoint 626 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 627 var err error 628 resp, err = executeRPC(ctx, c.endpointClient.GetEndpoint, req, settings.GRPC, c.logger, "GetEndpoint") 629 return err 630 }, opts...) 631 if err != nil { 632 return nil, err 633 } 634 return resp, nil 635 } 636 637 func (c *endpointGRPCClient) ListEndpoints(ctx context.Context, req *aiplatformpb.ListEndpointsRequest, opts ...gax.CallOption) *EndpointIterator { 638 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 639 640 hds = append(c.xGoogHeaders, hds...) 641 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 642 opts = append((*c.CallOptions).ListEndpoints[0:len((*c.CallOptions).ListEndpoints):len((*c.CallOptions).ListEndpoints)], opts...) 643 it := &EndpointIterator{} 644 req = proto.Clone(req).(*aiplatformpb.ListEndpointsRequest) 645 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.Endpoint, string, error) { 646 resp := &aiplatformpb.ListEndpointsResponse{} 647 if pageToken != "" { 648 req.PageToken = pageToken 649 } 650 if pageSize > math.MaxInt32 { 651 req.PageSize = math.MaxInt32 652 } else if pageSize != 0 { 653 req.PageSize = int32(pageSize) 654 } 655 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 656 var err error 657 resp, err = executeRPC(ctx, c.endpointClient.ListEndpoints, req, settings.GRPC, c.logger, "ListEndpoints") 658 return err 659 }, opts...) 660 if err != nil { 661 return nil, "", err 662 } 663 664 it.Response = resp 665 return resp.GetEndpoints(), resp.GetNextPageToken(), nil 666 } 667 fetch := func(pageSize int, pageToken string) (string, error) { 668 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 669 if err != nil { 670 return "", err 671 } 672 it.items = append(it.items, items...) 673 return nextPageToken, nil 674 } 675 676 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 677 it.pageInfo.MaxSize = int(req.GetPageSize()) 678 it.pageInfo.Token = req.GetPageToken() 679 680 return it 681 } 682 683 func (c *endpointGRPCClient) UpdateEndpoint(ctx context.Context, req *aiplatformpb.UpdateEndpointRequest, opts ...gax.CallOption) (*aiplatformpb.Endpoint, error) { 684 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "endpoint.name", url.QueryEscape(req.GetEndpoint().GetName()))} 685 686 hds = append(c.xGoogHeaders, hds...) 687 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 688 opts = append((*c.CallOptions).UpdateEndpoint[0:len((*c.CallOptions).UpdateEndpoint):len((*c.CallOptions).UpdateEndpoint)], opts...) 689 var resp *aiplatformpb.Endpoint 690 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 691 var err error 692 resp, err = executeRPC(ctx, c.endpointClient.UpdateEndpoint, req, settings.GRPC, c.logger, "UpdateEndpoint") 693 return err 694 }, opts...) 695 if err != nil { 696 return nil, err 697 } 698 return resp, nil 699 } 700 701 func (c *endpointGRPCClient) UpdateEndpointLongRunning(ctx context.Context, req *aiplatformpb.UpdateEndpointLongRunningRequest, opts ...gax.CallOption) (*UpdateEndpointLongRunningOperation, error) { 702 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "endpoint.name", url.QueryEscape(req.GetEndpoint().GetName()))} 703 704 hds = append(c.xGoogHeaders, hds...) 705 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 706 opts = append((*c.CallOptions).UpdateEndpointLongRunning[0:len((*c.CallOptions).UpdateEndpointLongRunning):len((*c.CallOptions).UpdateEndpointLongRunning)], opts...) 707 var resp *longrunningpb.Operation 708 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 709 var err error 710 resp, err = executeRPC(ctx, c.endpointClient.UpdateEndpointLongRunning, req, settings.GRPC, c.logger, "UpdateEndpointLongRunning") 711 return err 712 }, opts...) 713 if err != nil { 714 return nil, err 715 } 716 return &UpdateEndpointLongRunningOperation{ 717 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 718 }, nil 719 } 720 721 func (c *endpointGRPCClient) DeleteEndpoint(ctx context.Context, req *aiplatformpb.DeleteEndpointRequest, opts ...gax.CallOption) (*DeleteEndpointOperation, error) { 722 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 723 724 hds = append(c.xGoogHeaders, hds...) 725 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 726 opts = append((*c.CallOptions).DeleteEndpoint[0:len((*c.CallOptions).DeleteEndpoint):len((*c.CallOptions).DeleteEndpoint)], opts...) 727 var resp *longrunningpb.Operation 728 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 729 var err error 730 resp, err = executeRPC(ctx, c.endpointClient.DeleteEndpoint, req, settings.GRPC, c.logger, "DeleteEndpoint") 731 return err 732 }, opts...) 733 if err != nil { 734 return nil, err 735 } 736 return &DeleteEndpointOperation{ 737 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 738 }, nil 739 } 740 741 func (c *endpointGRPCClient) DeployModel(ctx context.Context, req *aiplatformpb.DeployModelRequest, opts ...gax.CallOption) (*DeployModelOperation, error) { 742 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "endpoint", url.QueryEscape(req.GetEndpoint()))} 743 744 hds = append(c.xGoogHeaders, hds...) 745 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 746 opts = append((*c.CallOptions).DeployModel[0:len((*c.CallOptions).DeployModel):len((*c.CallOptions).DeployModel)], opts...) 747 var resp *longrunningpb.Operation 748 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 749 var err error 750 resp, err = executeRPC(ctx, c.endpointClient.DeployModel, req, settings.GRPC, c.logger, "DeployModel") 751 return err 752 }, opts...) 753 if err != nil { 754 return nil, err 755 } 756 return &DeployModelOperation{ 757 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 758 }, nil 759 } 760 761 func (c *endpointGRPCClient) UndeployModel(ctx context.Context, req *aiplatformpb.UndeployModelRequest, opts ...gax.CallOption) (*UndeployModelOperation, error) { 762 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "endpoint", url.QueryEscape(req.GetEndpoint()))} 763 764 hds = append(c.xGoogHeaders, hds...) 765 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 766 opts = append((*c.CallOptions).UndeployModel[0:len((*c.CallOptions).UndeployModel):len((*c.CallOptions).UndeployModel)], opts...) 767 var resp *longrunningpb.Operation 768 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 769 var err error 770 resp, err = executeRPC(ctx, c.endpointClient.UndeployModel, req, settings.GRPC, c.logger, "UndeployModel") 771 return err 772 }, opts...) 773 if err != nil { 774 return nil, err 775 } 776 return &UndeployModelOperation{ 777 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 778 }, nil 779 } 780 781 func (c *endpointGRPCClient) MutateDeployedModel(ctx context.Context, req *aiplatformpb.MutateDeployedModelRequest, opts ...gax.CallOption) (*MutateDeployedModelOperation, error) { 782 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "endpoint", url.QueryEscape(req.GetEndpoint()))} 783 784 hds = append(c.xGoogHeaders, hds...) 785 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 786 opts = append((*c.CallOptions).MutateDeployedModel[0:len((*c.CallOptions).MutateDeployedModel):len((*c.CallOptions).MutateDeployedModel)], opts...) 787 var resp *longrunningpb.Operation 788 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 789 var err error 790 resp, err = executeRPC(ctx, c.endpointClient.MutateDeployedModel, req, settings.GRPC, c.logger, "MutateDeployedModel") 791 return err 792 }, opts...) 793 if err != nil { 794 return nil, err 795 } 796 return &MutateDeployedModelOperation{ 797 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 798 }, nil 799 } 800 801 func (c *endpointGRPCClient) SetPublisherModelConfig(ctx context.Context, req *aiplatformpb.SetPublisherModelConfigRequest, opts ...gax.CallOption) (*SetPublisherModelConfigOperation, error) { 802 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 803 804 hds = append(c.xGoogHeaders, hds...) 805 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 806 opts = append((*c.CallOptions).SetPublisherModelConfig[0:len((*c.CallOptions).SetPublisherModelConfig):len((*c.CallOptions).SetPublisherModelConfig)], opts...) 807 var resp *longrunningpb.Operation 808 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 809 var err error 810 resp, err = executeRPC(ctx, c.endpointClient.SetPublisherModelConfig, req, settings.GRPC, c.logger, "SetPublisherModelConfig") 811 return err 812 }, opts...) 813 if err != nil { 814 return nil, err 815 } 816 return &SetPublisherModelConfigOperation{ 817 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 818 }, nil 819 } 820 821 func (c *endpointGRPCClient) FetchPublisherModelConfig(ctx context.Context, req *aiplatformpb.FetchPublisherModelConfigRequest, opts ...gax.CallOption) (*aiplatformpb.PublisherModelConfig, error) { 822 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 823 824 hds = append(c.xGoogHeaders, hds...) 825 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 826 opts = append((*c.CallOptions).FetchPublisherModelConfig[0:len((*c.CallOptions).FetchPublisherModelConfig):len((*c.CallOptions).FetchPublisherModelConfig)], opts...) 827 var resp *aiplatformpb.PublisherModelConfig 828 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 829 var err error 830 resp, err = executeRPC(ctx, c.endpointClient.FetchPublisherModelConfig, req, settings.GRPC, c.logger, "FetchPublisherModelConfig") 831 return err 832 }, opts...) 833 if err != nil { 834 return nil, err 835 } 836 return resp, nil 837 } 838 839 func (c *endpointGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 840 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 841 842 hds = append(c.xGoogHeaders, hds...) 843 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 844 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 845 var resp *locationpb.Location 846 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 847 var err error 848 resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation") 849 return err 850 }, opts...) 851 if err != nil { 852 return nil, err 853 } 854 return resp, nil 855 } 856 857 func (c *endpointGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 858 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 859 860 hds = append(c.xGoogHeaders, hds...) 861 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 862 opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...) 863 it := &LocationIterator{} 864 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 865 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 866 resp := &locationpb.ListLocationsResponse{} 867 if pageToken != "" { 868 req.PageToken = pageToken 869 } 870 if pageSize > math.MaxInt32 { 871 req.PageSize = math.MaxInt32 872 } else if pageSize != 0 { 873 req.PageSize = int32(pageSize) 874 } 875 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 876 var err error 877 resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations") 878 return err 879 }, opts...) 880 if err != nil { 881 return nil, "", err 882 } 883 884 it.Response = resp 885 return resp.GetLocations(), resp.GetNextPageToken(), nil 886 } 887 fetch := func(pageSize int, pageToken string) (string, error) { 888 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 889 if err != nil { 890 return "", err 891 } 892 it.items = append(it.items, items...) 893 return nextPageToken, nil 894 } 895 896 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 897 it.pageInfo.MaxSize = int(req.GetPageSize()) 898 it.pageInfo.Token = req.GetPageToken() 899 900 return it 901 } 902 903 func (c *endpointGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 904 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 905 906 hds = append(c.xGoogHeaders, hds...) 907 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 908 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 909 var resp *iampb.Policy 910 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 911 var err error 912 resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy") 913 return err 914 }, opts...) 915 if err != nil { 916 return nil, err 917 } 918 return resp, nil 919 } 920 921 func (c *endpointGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 922 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 923 924 hds = append(c.xGoogHeaders, hds...) 925 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 926 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 927 var resp *iampb.Policy 928 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 929 var err error 930 resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy") 931 return err 932 }, opts...) 933 if err != nil { 934 return nil, err 935 } 936 return resp, nil 937 } 938 939 func (c *endpointGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 940 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 941 942 hds = append(c.xGoogHeaders, hds...) 943 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 944 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 945 var resp *iampb.TestIamPermissionsResponse 946 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 947 var err error 948 resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions") 949 return err 950 }, opts...) 951 if err != nil { 952 return nil, err 953 } 954 return resp, nil 955 } 956 957 func (c *endpointGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 958 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 959 960 hds = append(c.xGoogHeaders, hds...) 961 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 962 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) 963 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 964 var err error 965 _, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation") 966 return err 967 }, opts...) 968 return err 969 } 970 971 func (c *endpointGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 972 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 973 974 hds = append(c.xGoogHeaders, hds...) 975 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 976 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) 977 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 978 var err error 979 _, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation") 980 return err 981 }, opts...) 982 return err 983 } 984 985 func (c *endpointGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 986 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 987 988 hds = append(c.xGoogHeaders, hds...) 989 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 990 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 991 var resp *longrunningpb.Operation 992 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 993 var err error 994 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation") 995 return err 996 }, opts...) 997 if err != nil { 998 return nil, err 999 } 1000 return resp, nil 1001 } 1002 1003 func (c *endpointGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 1004 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1005 1006 hds = append(c.xGoogHeaders, hds...) 1007 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 1008 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) 1009 it := &OperationIterator{} 1010 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 1011 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 1012 resp := &longrunningpb.ListOperationsResponse{} 1013 if pageToken != "" { 1014 req.PageToken = pageToken 1015 } 1016 if pageSize > math.MaxInt32 { 1017 req.PageSize = math.MaxInt32 1018 } else if pageSize != 0 { 1019 req.PageSize = int32(pageSize) 1020 } 1021 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1022 var err error 1023 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations") 1024 return err 1025 }, opts...) 1026 if err != nil { 1027 return nil, "", err 1028 } 1029 1030 it.Response = resp 1031 return resp.GetOperations(), resp.GetNextPageToken(), nil 1032 } 1033 fetch := func(pageSize int, pageToken string) (string, error) { 1034 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1035 if err != nil { 1036 return "", err 1037 } 1038 it.items = append(it.items, items...) 1039 return nextPageToken, nil 1040 } 1041 1042 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1043 it.pageInfo.MaxSize = int(req.GetPageSize()) 1044 it.pageInfo.Token = req.GetPageToken() 1045 1046 return it 1047 } 1048 1049 func (c *endpointGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 1050 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1051 1052 hds = append(c.xGoogHeaders, hds...) 1053 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 1054 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 1055 var resp *longrunningpb.Operation 1056 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1057 var err error 1058 resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation") 1059 return err 1060 }, opts...) 1061 if err != nil { 1062 return nil, err 1063 } 1064 return resp, nil 1065 } 1066 1067 // CreateEndpoint creates an Endpoint. 1068 func (c *endpointRESTClient) CreateEndpoint(ctx context.Context, req *aiplatformpb.CreateEndpointRequest, opts ...gax.CallOption) (*CreateEndpointOperation, error) { 1069 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1070 body := req.GetEndpoint() 1071 jsonReq, err := m.Marshal(body) 1072 if err != nil { 1073 return nil, err 1074 } 1075 1076 baseUrl, err := url.Parse(c.endpoint) 1077 if err != nil { 1078 return nil, err 1079 } 1080 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/endpoints", req.GetParent()) 1081 1082 params := url.Values{} 1083 params.Add("$alt", "json;enum-encoding=int") 1084 if req.GetEndpointId() != "" { 1085 params.Add("endpointId", fmt.Sprintf("%v", req.GetEndpointId())) 1086 } 1087 1088 baseUrl.RawQuery = params.Encode() 1089 1090 // Build HTTP headers from client and context metadata. 1091 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 1092 1093 hds = append(c.xGoogHeaders, hds...) 1094 hds = append(hds, "Content-Type", "application/json") 1095 headers := gax.BuildHeaders(ctx, hds...) 1096 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1097 resp := &longrunningpb.Operation{} 1098 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1099 if settings.Path != "" { 1100 baseUrl.Path = settings.Path 1101 } 1102 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1103 if err != nil { 1104 return err 1105 } 1106 httpReq = httpReq.WithContext(ctx) 1107 httpReq.Header = headers 1108 1109 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateEndpoint") 1110 if err != nil { 1111 return err 1112 } 1113 if err := unm.Unmarshal(buf, resp); err != nil { 1114 return err 1115 } 1116 1117 return nil 1118 }, opts...) 1119 if e != nil { 1120 return nil, e 1121 } 1122 1123 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1124 return &CreateEndpointOperation{ 1125 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1126 pollPath: override, 1127 }, nil 1128 } 1129 1130 // GetEndpoint gets an Endpoint. 1131 func (c *endpointRESTClient) GetEndpoint(ctx context.Context, req *aiplatformpb.GetEndpointRequest, opts ...gax.CallOption) (*aiplatformpb.Endpoint, error) { 1132 baseUrl, err := url.Parse(c.endpoint) 1133 if err != nil { 1134 return nil, err 1135 } 1136 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 1137 1138 params := url.Values{} 1139 params.Add("$alt", "json;enum-encoding=int") 1140 1141 baseUrl.RawQuery = params.Encode() 1142 1143 // Build HTTP headers from client and context metadata. 1144 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1145 1146 hds = append(c.xGoogHeaders, hds...) 1147 hds = append(hds, "Content-Type", "application/json") 1148 headers := gax.BuildHeaders(ctx, hds...) 1149 opts = append((*c.CallOptions).GetEndpoint[0:len((*c.CallOptions).GetEndpoint):len((*c.CallOptions).GetEndpoint)], opts...) 1150 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1151 resp := &aiplatformpb.Endpoint{} 1152 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1153 if settings.Path != "" { 1154 baseUrl.Path = settings.Path 1155 } 1156 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1157 if err != nil { 1158 return err 1159 } 1160 httpReq = httpReq.WithContext(ctx) 1161 httpReq.Header = headers 1162 1163 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetEndpoint") 1164 if err != nil { 1165 return err 1166 } 1167 1168 if err := unm.Unmarshal(buf, resp); err != nil { 1169 return err 1170 } 1171 1172 return nil 1173 }, opts...) 1174 if e != nil { 1175 return nil, e 1176 } 1177 return resp, nil 1178 } 1179 1180 // ListEndpoints lists Endpoints in a Location. 1181 func (c *endpointRESTClient) ListEndpoints(ctx context.Context, req *aiplatformpb.ListEndpointsRequest, opts ...gax.CallOption) *EndpointIterator { 1182 it := &EndpointIterator{} 1183 req = proto.Clone(req).(*aiplatformpb.ListEndpointsRequest) 1184 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1185 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.Endpoint, string, error) { 1186 resp := &aiplatformpb.ListEndpointsResponse{} 1187 if pageToken != "" { 1188 req.PageToken = pageToken 1189 } 1190 if pageSize > math.MaxInt32 { 1191 req.PageSize = math.MaxInt32 1192 } else if pageSize != 0 { 1193 req.PageSize = int32(pageSize) 1194 } 1195 baseUrl, err := url.Parse(c.endpoint) 1196 if err != nil { 1197 return nil, "", err 1198 } 1199 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/endpoints", req.GetParent()) 1200 1201 params := url.Values{} 1202 params.Add("$alt", "json;enum-encoding=int") 1203 if req.GetFilter() != "" { 1204 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 1205 } 1206 if req.GetPageSize() != 0 { 1207 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1208 } 1209 if req.GetPageToken() != "" { 1210 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1211 } 1212 if req.GetReadMask() != nil { 1213 field, err := protojson.Marshal(req.GetReadMask()) 1214 if err != nil { 1215 return nil, "", err 1216 } 1217 params.Add("readMask", string(field[1:len(field)-1])) 1218 } 1219 1220 baseUrl.RawQuery = params.Encode() 1221 1222 // Build HTTP headers from client and context metadata. 1223 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1224 headers := gax.BuildHeaders(ctx, hds...) 1225 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1226 if settings.Path != "" { 1227 baseUrl.Path = settings.Path 1228 } 1229 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1230 if err != nil { 1231 return err 1232 } 1233 httpReq.Header = headers 1234 1235 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListEndpoints") 1236 if err != nil { 1237 return err 1238 } 1239 if err := unm.Unmarshal(buf, resp); err != nil { 1240 return err 1241 } 1242 1243 return nil 1244 }, opts...) 1245 if e != nil { 1246 return nil, "", e 1247 } 1248 it.Response = resp 1249 return resp.GetEndpoints(), resp.GetNextPageToken(), nil 1250 } 1251 1252 fetch := func(pageSize int, pageToken string) (string, error) { 1253 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1254 if err != nil { 1255 return "", err 1256 } 1257 it.items = append(it.items, items...) 1258 return nextPageToken, nil 1259 } 1260 1261 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1262 it.pageInfo.MaxSize = int(req.GetPageSize()) 1263 it.pageInfo.Token = req.GetPageToken() 1264 1265 return it 1266 } 1267 1268 // UpdateEndpoint updates an Endpoint. 1269 func (c *endpointRESTClient) UpdateEndpoint(ctx context.Context, req *aiplatformpb.UpdateEndpointRequest, opts ...gax.CallOption) (*aiplatformpb.Endpoint, error) { 1270 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1271 body := req.GetEndpoint() 1272 jsonReq, err := m.Marshal(body) 1273 if err != nil { 1274 return nil, err 1275 } 1276 1277 baseUrl, err := url.Parse(c.endpoint) 1278 if err != nil { 1279 return nil, err 1280 } 1281 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetEndpoint().GetName()) 1282 1283 params := url.Values{} 1284 params.Add("$alt", "json;enum-encoding=int") 1285 if req.GetUpdateMask() != nil { 1286 field, err := protojson.Marshal(req.GetUpdateMask()) 1287 if err != nil { 1288 return nil, err 1289 } 1290 params.Add("updateMask", string(field[1:len(field)-1])) 1291 } 1292 1293 baseUrl.RawQuery = params.Encode() 1294 1295 // Build HTTP headers from client and context metadata. 1296 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "endpoint.name", url.QueryEscape(req.GetEndpoint().GetName()))} 1297 1298 hds = append(c.xGoogHeaders, hds...) 1299 hds = append(hds, "Content-Type", "application/json") 1300 headers := gax.BuildHeaders(ctx, hds...) 1301 opts = append((*c.CallOptions).UpdateEndpoint[0:len((*c.CallOptions).UpdateEndpoint):len((*c.CallOptions).UpdateEndpoint)], opts...) 1302 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1303 resp := &aiplatformpb.Endpoint{} 1304 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1305 if settings.Path != "" { 1306 baseUrl.Path = settings.Path 1307 } 1308 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) 1309 if err != nil { 1310 return err 1311 } 1312 httpReq = httpReq.WithContext(ctx) 1313 httpReq.Header = headers 1314 1315 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateEndpoint") 1316 if err != nil { 1317 return err 1318 } 1319 1320 if err := unm.Unmarshal(buf, resp); err != nil { 1321 return err 1322 } 1323 1324 return nil 1325 }, opts...) 1326 if e != nil { 1327 return nil, e 1328 } 1329 return resp, nil 1330 } 1331 1332 // UpdateEndpointLongRunning updates an Endpoint with a long running operation. 1333 func (c *endpointRESTClient) UpdateEndpointLongRunning(ctx context.Context, req *aiplatformpb.UpdateEndpointLongRunningRequest, opts ...gax.CallOption) (*UpdateEndpointLongRunningOperation, error) { 1334 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1335 jsonReq, err := m.Marshal(req) 1336 if err != nil { 1337 return nil, err 1338 } 1339 1340 baseUrl, err := url.Parse(c.endpoint) 1341 if err != nil { 1342 return nil, err 1343 } 1344 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:update", req.GetEndpoint().GetName()) 1345 1346 params := url.Values{} 1347 params.Add("$alt", "json;enum-encoding=int") 1348 1349 baseUrl.RawQuery = params.Encode() 1350 1351 // Build HTTP headers from client and context metadata. 1352 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "endpoint.name", url.QueryEscape(req.GetEndpoint().GetName()))} 1353 1354 hds = append(c.xGoogHeaders, hds...) 1355 hds = append(hds, "Content-Type", "application/json") 1356 headers := gax.BuildHeaders(ctx, hds...) 1357 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1358 resp := &longrunningpb.Operation{} 1359 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1360 if settings.Path != "" { 1361 baseUrl.Path = settings.Path 1362 } 1363 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1364 if err != nil { 1365 return err 1366 } 1367 httpReq = httpReq.WithContext(ctx) 1368 httpReq.Header = headers 1369 1370 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateEndpointLongRunning") 1371 if err != nil { 1372 return err 1373 } 1374 if err := unm.Unmarshal(buf, resp); err != nil { 1375 return err 1376 } 1377 1378 return nil 1379 }, opts...) 1380 if e != nil { 1381 return nil, e 1382 } 1383 1384 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1385 return &UpdateEndpointLongRunningOperation{ 1386 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1387 pollPath: override, 1388 }, nil 1389 } 1390 1391 // DeleteEndpoint deletes an Endpoint. 1392 func (c *endpointRESTClient) DeleteEndpoint(ctx context.Context, req *aiplatformpb.DeleteEndpointRequest, opts ...gax.CallOption) (*DeleteEndpointOperation, error) { 1393 baseUrl, err := url.Parse(c.endpoint) 1394 if err != nil { 1395 return nil, err 1396 } 1397 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 1398 1399 params := url.Values{} 1400 params.Add("$alt", "json;enum-encoding=int") 1401 1402 baseUrl.RawQuery = params.Encode() 1403 1404 // Build HTTP headers from client and context metadata. 1405 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1406 1407 hds = append(c.xGoogHeaders, hds...) 1408 hds = append(hds, "Content-Type", "application/json") 1409 headers := gax.BuildHeaders(ctx, hds...) 1410 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1411 resp := &longrunningpb.Operation{} 1412 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1413 if settings.Path != "" { 1414 baseUrl.Path = settings.Path 1415 } 1416 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) 1417 if err != nil { 1418 return err 1419 } 1420 httpReq = httpReq.WithContext(ctx) 1421 httpReq.Header = headers 1422 1423 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteEndpoint") 1424 if err != nil { 1425 return err 1426 } 1427 if err := unm.Unmarshal(buf, resp); err != nil { 1428 return err 1429 } 1430 1431 return nil 1432 }, opts...) 1433 if e != nil { 1434 return nil, e 1435 } 1436 1437 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1438 return &DeleteEndpointOperation{ 1439 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1440 pollPath: override, 1441 }, nil 1442 } 1443 1444 // DeployModel deploys a Model into this Endpoint, creating a DeployedModel within it. 1445 func (c *endpointRESTClient) DeployModel(ctx context.Context, req *aiplatformpb.DeployModelRequest, opts ...gax.CallOption) (*DeployModelOperation, error) { 1446 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1447 jsonReq, err := m.Marshal(req) 1448 if err != nil { 1449 return nil, err 1450 } 1451 1452 baseUrl, err := url.Parse(c.endpoint) 1453 if err != nil { 1454 return nil, err 1455 } 1456 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:deployModel", req.GetEndpoint()) 1457 1458 params := url.Values{} 1459 params.Add("$alt", "json;enum-encoding=int") 1460 1461 baseUrl.RawQuery = params.Encode() 1462 1463 // Build HTTP headers from client and context metadata. 1464 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "endpoint", url.QueryEscape(req.GetEndpoint()))} 1465 1466 hds = append(c.xGoogHeaders, hds...) 1467 hds = append(hds, "Content-Type", "application/json") 1468 headers := gax.BuildHeaders(ctx, hds...) 1469 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1470 resp := &longrunningpb.Operation{} 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, "DeployModel") 1483 if err != nil { 1484 return err 1485 } 1486 if err := unm.Unmarshal(buf, resp); err != nil { 1487 return err 1488 } 1489 1490 return nil 1491 }, opts...) 1492 if e != nil { 1493 return nil, e 1494 } 1495 1496 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1497 return &DeployModelOperation{ 1498 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1499 pollPath: override, 1500 }, nil 1501 } 1502 1503 // UndeployModel undeploys a Model from an Endpoint, removing a DeployedModel from it, and 1504 // freeing all resources it’s using. 1505 func (c *endpointRESTClient) UndeployModel(ctx context.Context, req *aiplatformpb.UndeployModelRequest, opts ...gax.CallOption) (*UndeployModelOperation, error) { 1506 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1507 jsonReq, err := m.Marshal(req) 1508 if err != nil { 1509 return nil, err 1510 } 1511 1512 baseUrl, err := url.Parse(c.endpoint) 1513 if err != nil { 1514 return nil, err 1515 } 1516 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:undeployModel", req.GetEndpoint()) 1517 1518 params := url.Values{} 1519 params.Add("$alt", "json;enum-encoding=int") 1520 1521 baseUrl.RawQuery = params.Encode() 1522 1523 // Build HTTP headers from client and context metadata. 1524 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "endpoint", url.QueryEscape(req.GetEndpoint()))} 1525 1526 hds = append(c.xGoogHeaders, hds...) 1527 hds = append(hds, "Content-Type", "application/json") 1528 headers := gax.BuildHeaders(ctx, hds...) 1529 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1530 resp := &longrunningpb.Operation{} 1531 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1532 if settings.Path != "" { 1533 baseUrl.Path = settings.Path 1534 } 1535 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1536 if err != nil { 1537 return err 1538 } 1539 httpReq = httpReq.WithContext(ctx) 1540 httpReq.Header = headers 1541 1542 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UndeployModel") 1543 if err != nil { 1544 return err 1545 } 1546 if err := unm.Unmarshal(buf, resp); err != nil { 1547 return err 1548 } 1549 1550 return nil 1551 }, opts...) 1552 if e != nil { 1553 return nil, e 1554 } 1555 1556 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1557 return &UndeployModelOperation{ 1558 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1559 pollPath: override, 1560 }, nil 1561 } 1562 1563 // MutateDeployedModel updates an existing deployed model. Updatable fields include 1564 // min_replica_count, max_replica_count, required_replica_count, 1565 // autoscaling_metric_specs, disable_container_logging (v1 only), and 1566 // enable_container_logging (v1beta1 only). 1567 func (c *endpointRESTClient) MutateDeployedModel(ctx context.Context, req *aiplatformpb.MutateDeployedModelRequest, opts ...gax.CallOption) (*MutateDeployedModelOperation, error) { 1568 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1569 jsonReq, err := m.Marshal(req) 1570 if err != nil { 1571 return nil, err 1572 } 1573 1574 baseUrl, err := url.Parse(c.endpoint) 1575 if err != nil { 1576 return nil, err 1577 } 1578 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:mutateDeployedModel", req.GetEndpoint()) 1579 1580 params := url.Values{} 1581 params.Add("$alt", "json;enum-encoding=int") 1582 1583 baseUrl.RawQuery = params.Encode() 1584 1585 // Build HTTP headers from client and context metadata. 1586 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "endpoint", url.QueryEscape(req.GetEndpoint()))} 1587 1588 hds = append(c.xGoogHeaders, hds...) 1589 hds = append(hds, "Content-Type", "application/json") 1590 headers := gax.BuildHeaders(ctx, hds...) 1591 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1592 resp := &longrunningpb.Operation{} 1593 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1594 if settings.Path != "" { 1595 baseUrl.Path = settings.Path 1596 } 1597 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1598 if err != nil { 1599 return err 1600 } 1601 httpReq = httpReq.WithContext(ctx) 1602 httpReq.Header = headers 1603 1604 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "MutateDeployedModel") 1605 if err != nil { 1606 return err 1607 } 1608 if err := unm.Unmarshal(buf, resp); err != nil { 1609 return err 1610 } 1611 1612 return nil 1613 }, opts...) 1614 if e != nil { 1615 return nil, e 1616 } 1617 1618 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1619 return &MutateDeployedModelOperation{ 1620 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1621 pollPath: override, 1622 }, nil 1623 } 1624 1625 // SetPublisherModelConfig sets (creates or updates) configs of publisher models. For example, sets 1626 // the request/response logging config. 1627 func (c *endpointRESTClient) SetPublisherModelConfig(ctx context.Context, req *aiplatformpb.SetPublisherModelConfigRequest, opts ...gax.CallOption) (*SetPublisherModelConfigOperation, error) { 1628 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1629 jsonReq, err := m.Marshal(req) 1630 if err != nil { 1631 return nil, err 1632 } 1633 1634 baseUrl, err := url.Parse(c.endpoint) 1635 if err != nil { 1636 return nil, err 1637 } 1638 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:setPublisherModelConfig", req.GetName()) 1639 1640 params := url.Values{} 1641 params.Add("$alt", "json;enum-encoding=int") 1642 1643 baseUrl.RawQuery = params.Encode() 1644 1645 // Build HTTP headers from client and context metadata. 1646 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1647 1648 hds = append(c.xGoogHeaders, hds...) 1649 hds = append(hds, "Content-Type", "application/json") 1650 headers := gax.BuildHeaders(ctx, hds...) 1651 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1652 resp := &longrunningpb.Operation{} 1653 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1654 if settings.Path != "" { 1655 baseUrl.Path = settings.Path 1656 } 1657 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1658 if err != nil { 1659 return err 1660 } 1661 httpReq = httpReq.WithContext(ctx) 1662 httpReq.Header = headers 1663 1664 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetPublisherModelConfig") 1665 if err != nil { 1666 return err 1667 } 1668 if err := unm.Unmarshal(buf, resp); err != nil { 1669 return err 1670 } 1671 1672 return nil 1673 }, opts...) 1674 if e != nil { 1675 return nil, e 1676 } 1677 1678 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1679 return &SetPublisherModelConfigOperation{ 1680 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1681 pollPath: override, 1682 }, nil 1683 } 1684 1685 // FetchPublisherModelConfig fetches the configs of publisher models. 1686 func (c *endpointRESTClient) FetchPublisherModelConfig(ctx context.Context, req *aiplatformpb.FetchPublisherModelConfigRequest, opts ...gax.CallOption) (*aiplatformpb.PublisherModelConfig, error) { 1687 baseUrl, err := url.Parse(c.endpoint) 1688 if err != nil { 1689 return nil, err 1690 } 1691 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:fetchPublisherModelConfig", req.GetName()) 1692 1693 params := url.Values{} 1694 params.Add("$alt", "json;enum-encoding=int") 1695 1696 baseUrl.RawQuery = params.Encode() 1697 1698 // Build HTTP headers from client and context metadata. 1699 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1700 1701 hds = append(c.xGoogHeaders, hds...) 1702 hds = append(hds, "Content-Type", "application/json") 1703 headers := gax.BuildHeaders(ctx, hds...) 1704 opts = append((*c.CallOptions).FetchPublisherModelConfig[0:len((*c.CallOptions).FetchPublisherModelConfig):len((*c.CallOptions).FetchPublisherModelConfig)], opts...) 1705 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1706 resp := &aiplatformpb.PublisherModelConfig{} 1707 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1708 if settings.Path != "" { 1709 baseUrl.Path = settings.Path 1710 } 1711 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1712 if err != nil { 1713 return err 1714 } 1715 httpReq = httpReq.WithContext(ctx) 1716 httpReq.Header = headers 1717 1718 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "FetchPublisherModelConfig") 1719 if err != nil { 1720 return err 1721 } 1722 1723 if err := unm.Unmarshal(buf, resp); err != nil { 1724 return err 1725 } 1726 1727 return nil 1728 }, opts...) 1729 if e != nil { 1730 return nil, e 1731 } 1732 return resp, nil 1733 } 1734 1735 // GetLocation gets information about a location. 1736 func (c *endpointRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 1737 baseUrl, err := url.Parse(c.endpoint) 1738 if err != nil { 1739 return nil, err 1740 } 1741 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 1742 1743 params := url.Values{} 1744 params.Add("$alt", "json;enum-encoding=int") 1745 1746 baseUrl.RawQuery = params.Encode() 1747 1748 // Build HTTP headers from client and context metadata. 1749 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1750 1751 hds = append(c.xGoogHeaders, hds...) 1752 hds = append(hds, "Content-Type", "application/json") 1753 headers := gax.BuildHeaders(ctx, hds...) 1754 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 1755 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1756 resp := &locationpb.Location{} 1757 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1758 if settings.Path != "" { 1759 baseUrl.Path = settings.Path 1760 } 1761 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1762 if err != nil { 1763 return err 1764 } 1765 httpReq = httpReq.WithContext(ctx) 1766 httpReq.Header = headers 1767 1768 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation") 1769 if err != nil { 1770 return err 1771 } 1772 1773 if err := unm.Unmarshal(buf, resp); err != nil { 1774 return err 1775 } 1776 1777 return nil 1778 }, opts...) 1779 if e != nil { 1780 return nil, e 1781 } 1782 return resp, nil 1783 } 1784 1785 // ListLocations lists information about the supported locations for this service. 1786 func (c *endpointRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 1787 it := &LocationIterator{} 1788 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 1789 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1790 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 1791 resp := &locationpb.ListLocationsResponse{} 1792 if pageToken != "" { 1793 req.PageToken = pageToken 1794 } 1795 if pageSize > math.MaxInt32 { 1796 req.PageSize = math.MaxInt32 1797 } else if pageSize != 0 { 1798 req.PageSize = int32(pageSize) 1799 } 1800 baseUrl, err := url.Parse(c.endpoint) 1801 if err != nil { 1802 return nil, "", err 1803 } 1804 baseUrl.Path += fmt.Sprintf("/ui/%v/locations", req.GetName()) 1805 1806 params := url.Values{} 1807 params.Add("$alt", "json;enum-encoding=int") 1808 if req.GetFilter() != "" { 1809 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 1810 } 1811 if req.GetPageSize() != 0 { 1812 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1813 } 1814 if req.GetPageToken() != "" { 1815 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1816 } 1817 1818 baseUrl.RawQuery = params.Encode() 1819 1820 // Build HTTP headers from client and context metadata. 1821 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1822 headers := gax.BuildHeaders(ctx, hds...) 1823 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1824 if settings.Path != "" { 1825 baseUrl.Path = settings.Path 1826 } 1827 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1828 if err != nil { 1829 return err 1830 } 1831 httpReq.Header = headers 1832 1833 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations") 1834 if err != nil { 1835 return err 1836 } 1837 if err := unm.Unmarshal(buf, resp); err != nil { 1838 return err 1839 } 1840 1841 return nil 1842 }, opts...) 1843 if e != nil { 1844 return nil, "", e 1845 } 1846 it.Response = resp 1847 return resp.GetLocations(), resp.GetNextPageToken(), nil 1848 } 1849 1850 fetch := func(pageSize int, pageToken string) (string, error) { 1851 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1852 if err != nil { 1853 return "", err 1854 } 1855 it.items = append(it.items, items...) 1856 return nextPageToken, nil 1857 } 1858 1859 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1860 it.pageInfo.MaxSize = int(req.GetPageSize()) 1861 it.pageInfo.Token = req.GetPageToken() 1862 1863 return it 1864 } 1865 1866 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 1867 // if the resource exists and does not have a policy set. 1868 func (c *endpointRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 1869 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1870 jsonReq, err := m.Marshal(req) 1871 if err != nil { 1872 return nil, err 1873 } 1874 1875 baseUrl, err := url.Parse(c.endpoint) 1876 if err != nil { 1877 return nil, err 1878 } 1879 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:getIamPolicy", req.GetResource()) 1880 1881 params := url.Values{} 1882 params.Add("$alt", "json;enum-encoding=int") 1883 1884 baseUrl.RawQuery = params.Encode() 1885 1886 // Build HTTP headers from client and context metadata. 1887 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 1888 1889 hds = append(c.xGoogHeaders, hds...) 1890 hds = append(hds, "Content-Type", "application/json") 1891 headers := gax.BuildHeaders(ctx, hds...) 1892 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 1893 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1894 resp := &iampb.Policy{} 1895 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1896 if settings.Path != "" { 1897 baseUrl.Path = settings.Path 1898 } 1899 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1900 if err != nil { 1901 return err 1902 } 1903 httpReq = httpReq.WithContext(ctx) 1904 httpReq.Header = headers 1905 1906 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "GetIamPolicy") 1907 if err != nil { 1908 return err 1909 } 1910 1911 if err := unm.Unmarshal(buf, resp); err != nil { 1912 return err 1913 } 1914 1915 return nil 1916 }, opts...) 1917 if e != nil { 1918 return nil, e 1919 } 1920 return resp, nil 1921 } 1922 1923 // SetIamPolicy sets the access control policy on the specified resource. Replaces 1924 // any existing policy. 1925 // 1926 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 1927 // errors. 1928 func (c *endpointRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 1929 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1930 jsonReq, err := m.Marshal(req) 1931 if err != nil { 1932 return nil, err 1933 } 1934 1935 baseUrl, err := url.Parse(c.endpoint) 1936 if err != nil { 1937 return nil, err 1938 } 1939 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:setIamPolicy", req.GetResource()) 1940 1941 params := url.Values{} 1942 params.Add("$alt", "json;enum-encoding=int") 1943 1944 baseUrl.RawQuery = params.Encode() 1945 1946 // Build HTTP headers from client and context metadata. 1947 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 1948 1949 hds = append(c.xGoogHeaders, hds...) 1950 hds = append(hds, "Content-Type", "application/json") 1951 headers := gax.BuildHeaders(ctx, hds...) 1952 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 1953 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1954 resp := &iampb.Policy{} 1955 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1956 if settings.Path != "" { 1957 baseUrl.Path = settings.Path 1958 } 1959 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1960 if err != nil { 1961 return err 1962 } 1963 httpReq = httpReq.WithContext(ctx) 1964 httpReq.Header = headers 1965 1966 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy") 1967 if err != nil { 1968 return err 1969 } 1970 1971 if err := unm.Unmarshal(buf, resp); err != nil { 1972 return err 1973 } 1974 1975 return nil 1976 }, opts...) 1977 if e != nil { 1978 return nil, e 1979 } 1980 return resp, nil 1981 } 1982 1983 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 1984 // resource does not exist, this will return an empty set of 1985 // permissions, not a NOT_FOUND error. 1986 // 1987 // Note: This operation is designed to be used for building 1988 // permission-aware UIs and command-line tools, not for authorization 1989 // checking. This operation may “fail open” without warning. 1990 func (c *endpointRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 1991 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1992 jsonReq, err := m.Marshal(req) 1993 if err != nil { 1994 return nil, err 1995 } 1996 1997 baseUrl, err := url.Parse(c.endpoint) 1998 if err != nil { 1999 return nil, err 2000 } 2001 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:testIamPermissions", req.GetResource()) 2002 2003 params := url.Values{} 2004 params.Add("$alt", "json;enum-encoding=int") 2005 2006 baseUrl.RawQuery = params.Encode() 2007 2008 // Build HTTP headers from client and context metadata. 2009 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 2010 2011 hds = append(c.xGoogHeaders, hds...) 2012 hds = append(hds, "Content-Type", "application/json") 2013 headers := gax.BuildHeaders(ctx, hds...) 2014 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 2015 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 2016 resp := &iampb.TestIamPermissionsResponse{} 2017 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2018 if settings.Path != "" { 2019 baseUrl.Path = settings.Path 2020 } 2021 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 2022 if err != nil { 2023 return err 2024 } 2025 httpReq = httpReq.WithContext(ctx) 2026 httpReq.Header = headers 2027 2028 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TestIamPermissions") 2029 if err != nil { 2030 return err 2031 } 2032 2033 if err := unm.Unmarshal(buf, resp); err != nil { 2034 return err 2035 } 2036 2037 return nil 2038 }, opts...) 2039 if e != nil { 2040 return nil, e 2041 } 2042 return resp, nil 2043 } 2044 2045 // CancelOperation is a utility method from google.longrunning.Operations. 2046 func (c *endpointRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 2047 baseUrl, err := url.Parse(c.endpoint) 2048 if err != nil { 2049 return err 2050 } 2051 baseUrl.Path += fmt.Sprintf("/ui/%v:cancel", req.GetName()) 2052 2053 params := url.Values{} 2054 params.Add("$alt", "json;enum-encoding=int") 2055 2056 baseUrl.RawQuery = params.Encode() 2057 2058 // Build HTTP headers from client and context metadata. 2059 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 2060 2061 hds = append(c.xGoogHeaders, hds...) 2062 hds = append(hds, "Content-Type", "application/json") 2063 headers := gax.BuildHeaders(ctx, hds...) 2064 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2065 if settings.Path != "" { 2066 baseUrl.Path = settings.Path 2067 } 2068 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil) 2069 if err != nil { 2070 return err 2071 } 2072 httpReq = httpReq.WithContext(ctx) 2073 httpReq.Header = headers 2074 2075 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "CancelOperation") 2076 return err 2077 }, opts...) 2078 } 2079 2080 // DeleteOperation is a utility method from google.longrunning.Operations. 2081 func (c *endpointRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 2082 baseUrl, err := url.Parse(c.endpoint) 2083 if err != nil { 2084 return err 2085 } 2086 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 2087 2088 params := url.Values{} 2089 params.Add("$alt", "json;enum-encoding=int") 2090 2091 baseUrl.RawQuery = params.Encode() 2092 2093 // Build HTTP headers from client and context metadata. 2094 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 2095 2096 hds = append(c.xGoogHeaders, hds...) 2097 hds = append(hds, "Content-Type", "application/json") 2098 headers := gax.BuildHeaders(ctx, hds...) 2099 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2100 if settings.Path != "" { 2101 baseUrl.Path = settings.Path 2102 } 2103 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) 2104 if err != nil { 2105 return err 2106 } 2107 httpReq = httpReq.WithContext(ctx) 2108 httpReq.Header = headers 2109 2110 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation") 2111 return err 2112 }, opts...) 2113 } 2114 2115 // GetOperation is a utility method from google.longrunning.Operations. 2116 func (c *endpointRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 2117 baseUrl, err := url.Parse(c.endpoint) 2118 if err != nil { 2119 return nil, err 2120 } 2121 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 2122 2123 params := url.Values{} 2124 params.Add("$alt", "json;enum-encoding=int") 2125 2126 baseUrl.RawQuery = params.Encode() 2127 2128 // Build HTTP headers from client and context metadata. 2129 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 2130 2131 hds = append(c.xGoogHeaders, hds...) 2132 hds = append(hds, "Content-Type", "application/json") 2133 headers := gax.BuildHeaders(ctx, hds...) 2134 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 2135 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 2136 resp := &longrunningpb.Operation{} 2137 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2138 if settings.Path != "" { 2139 baseUrl.Path = settings.Path 2140 } 2141 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 2142 if err != nil { 2143 return err 2144 } 2145 httpReq = httpReq.WithContext(ctx) 2146 httpReq.Header = headers 2147 2148 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation") 2149 if err != nil { 2150 return err 2151 } 2152 2153 if err := unm.Unmarshal(buf, resp); err != nil { 2154 return err 2155 } 2156 2157 return nil 2158 }, opts...) 2159 if e != nil { 2160 return nil, e 2161 } 2162 return resp, nil 2163 } 2164 2165 // ListOperations is a utility method from google.longrunning.Operations. 2166 func (c *endpointRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 2167 it := &OperationIterator{} 2168 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 2169 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 2170 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 2171 resp := &longrunningpb.ListOperationsResponse{} 2172 if pageToken != "" { 2173 req.PageToken = pageToken 2174 } 2175 if pageSize > math.MaxInt32 { 2176 req.PageSize = math.MaxInt32 2177 } else if pageSize != 0 { 2178 req.PageSize = int32(pageSize) 2179 } 2180 baseUrl, err := url.Parse(c.endpoint) 2181 if err != nil { 2182 return nil, "", err 2183 } 2184 baseUrl.Path += fmt.Sprintf("/ui/%v/operations", req.GetName()) 2185 2186 params := url.Values{} 2187 params.Add("$alt", "json;enum-encoding=int") 2188 if req.GetFilter() != "" { 2189 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 2190 } 2191 if req.GetPageSize() != 0 { 2192 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 2193 } 2194 if req.GetPageToken() != "" { 2195 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 2196 } 2197 2198 baseUrl.RawQuery = params.Encode() 2199 2200 // Build HTTP headers from client and context metadata. 2201 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 2202 headers := gax.BuildHeaders(ctx, hds...) 2203 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2204 if settings.Path != "" { 2205 baseUrl.Path = settings.Path 2206 } 2207 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 2208 if err != nil { 2209 return err 2210 } 2211 httpReq.Header = headers 2212 2213 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations") 2214 if err != nil { 2215 return err 2216 } 2217 if err := unm.Unmarshal(buf, resp); err != nil { 2218 return err 2219 } 2220 2221 return nil 2222 }, opts...) 2223 if e != nil { 2224 return nil, "", e 2225 } 2226 it.Response = resp 2227 return resp.GetOperations(), resp.GetNextPageToken(), nil 2228 } 2229 2230 fetch := func(pageSize int, pageToken string) (string, error) { 2231 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 2232 if err != nil { 2233 return "", err 2234 } 2235 it.items = append(it.items, items...) 2236 return nextPageToken, nil 2237 } 2238 2239 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 2240 it.pageInfo.MaxSize = int(req.GetPageSize()) 2241 it.pageInfo.Token = req.GetPageToken() 2242 2243 return it 2244 } 2245 2246 // WaitOperation is a utility method from google.longrunning.Operations. 2247 func (c *endpointRESTClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 2248 baseUrl, err := url.Parse(c.endpoint) 2249 if err != nil { 2250 return nil, err 2251 } 2252 baseUrl.Path += fmt.Sprintf("/ui/%v:wait", req.GetName()) 2253 2254 params := url.Values{} 2255 params.Add("$alt", "json;enum-encoding=int") 2256 if req.GetTimeout() != nil { 2257 field, err := protojson.Marshal(req.GetTimeout()) 2258 if err != nil { 2259 return nil, err 2260 } 2261 params.Add("timeout", string(field[1:len(field)-1])) 2262 } 2263 2264 baseUrl.RawQuery = params.Encode() 2265 2266 // Build HTTP headers from client and context metadata. 2267 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 2268 2269 hds = append(c.xGoogHeaders, hds...) 2270 hds = append(hds, "Content-Type", "application/json") 2271 headers := gax.BuildHeaders(ctx, hds...) 2272 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 2273 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 2274 resp := &longrunningpb.Operation{} 2275 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2276 if settings.Path != "" { 2277 baseUrl.Path = settings.Path 2278 } 2279 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil) 2280 if err != nil { 2281 return err 2282 } 2283 httpReq = httpReq.WithContext(ctx) 2284 httpReq.Header = headers 2285 2286 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "WaitOperation") 2287 if err != nil { 2288 return err 2289 } 2290 2291 if err := unm.Unmarshal(buf, resp); err != nil { 2292 return err 2293 } 2294 2295 return nil 2296 }, opts...) 2297 if e != nil { 2298 return nil, e 2299 } 2300 return resp, nil 2301 } 2302 2303 // CreateEndpointOperation returns a new CreateEndpointOperation from a given name. 2304 // The name must be that of a previously created CreateEndpointOperation, possibly from a different process. 2305 func (c *endpointGRPCClient) CreateEndpointOperation(name string) *CreateEndpointOperation { 2306 return &CreateEndpointOperation{ 2307 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2308 } 2309 } 2310 2311 // CreateEndpointOperation returns a new CreateEndpointOperation from a given name. 2312 // The name must be that of a previously created CreateEndpointOperation, possibly from a different process. 2313 func (c *endpointRESTClient) CreateEndpointOperation(name string) *CreateEndpointOperation { 2314 override := fmt.Sprintf("/ui/%s", name) 2315 return &CreateEndpointOperation{ 2316 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2317 pollPath: override, 2318 } 2319 } 2320 2321 // DeleteEndpointOperation returns a new DeleteEndpointOperation from a given name. 2322 // The name must be that of a previously created DeleteEndpointOperation, possibly from a different process. 2323 func (c *endpointGRPCClient) DeleteEndpointOperation(name string) *DeleteEndpointOperation { 2324 return &DeleteEndpointOperation{ 2325 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2326 } 2327 } 2328 2329 // DeleteEndpointOperation returns a new DeleteEndpointOperation from a given name. 2330 // The name must be that of a previously created DeleteEndpointOperation, possibly from a different process. 2331 func (c *endpointRESTClient) DeleteEndpointOperation(name string) *DeleteEndpointOperation { 2332 override := fmt.Sprintf("/ui/%s", name) 2333 return &DeleteEndpointOperation{ 2334 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2335 pollPath: override, 2336 } 2337 } 2338 2339 // DeployModelOperation returns a new DeployModelOperation from a given name. 2340 // The name must be that of a previously created DeployModelOperation, possibly from a different process. 2341 func (c *endpointGRPCClient) DeployModelOperation(name string) *DeployModelOperation { 2342 return &DeployModelOperation{ 2343 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2344 } 2345 } 2346 2347 // DeployModelOperation returns a new DeployModelOperation from a given name. 2348 // The name must be that of a previously created DeployModelOperation, possibly from a different process. 2349 func (c *endpointRESTClient) DeployModelOperation(name string) *DeployModelOperation { 2350 override := fmt.Sprintf("/ui/%s", name) 2351 return &DeployModelOperation{ 2352 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2353 pollPath: override, 2354 } 2355 } 2356 2357 // MutateDeployedModelOperation returns a new MutateDeployedModelOperation from a given name. 2358 // The name must be that of a previously created MutateDeployedModelOperation, possibly from a different process. 2359 func (c *endpointGRPCClient) MutateDeployedModelOperation(name string) *MutateDeployedModelOperation { 2360 return &MutateDeployedModelOperation{ 2361 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2362 } 2363 } 2364 2365 // MutateDeployedModelOperation returns a new MutateDeployedModelOperation from a given name. 2366 // The name must be that of a previously created MutateDeployedModelOperation, possibly from a different process. 2367 func (c *endpointRESTClient) MutateDeployedModelOperation(name string) *MutateDeployedModelOperation { 2368 override := fmt.Sprintf("/ui/%s", name) 2369 return &MutateDeployedModelOperation{ 2370 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2371 pollPath: override, 2372 } 2373 } 2374 2375 // SetPublisherModelConfigOperation returns a new SetPublisherModelConfigOperation from a given name. 2376 // The name must be that of a previously created SetPublisherModelConfigOperation, possibly from a different process. 2377 func (c *endpointGRPCClient) SetPublisherModelConfigOperation(name string) *SetPublisherModelConfigOperation { 2378 return &SetPublisherModelConfigOperation{ 2379 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2380 } 2381 } 2382 2383 // SetPublisherModelConfigOperation returns a new SetPublisherModelConfigOperation from a given name. 2384 // The name must be that of a previously created SetPublisherModelConfigOperation, possibly from a different process. 2385 func (c *endpointRESTClient) SetPublisherModelConfigOperation(name string) *SetPublisherModelConfigOperation { 2386 override := fmt.Sprintf("/ui/%s", name) 2387 return &SetPublisherModelConfigOperation{ 2388 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2389 pollPath: override, 2390 } 2391 } 2392 2393 // UndeployModelOperation returns a new UndeployModelOperation from a given name. 2394 // The name must be that of a previously created UndeployModelOperation, possibly from a different process. 2395 func (c *endpointGRPCClient) UndeployModelOperation(name string) *UndeployModelOperation { 2396 return &UndeployModelOperation{ 2397 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2398 } 2399 } 2400 2401 // UndeployModelOperation returns a new UndeployModelOperation from a given name. 2402 // The name must be that of a previously created UndeployModelOperation, possibly from a different process. 2403 func (c *endpointRESTClient) UndeployModelOperation(name string) *UndeployModelOperation { 2404 override := fmt.Sprintf("/ui/%s", name) 2405 return &UndeployModelOperation{ 2406 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2407 pollPath: override, 2408 } 2409 } 2410 2411 // UpdateEndpointLongRunningOperation returns a new UpdateEndpointLongRunningOperation from a given name. 2412 // The name must be that of a previously created UpdateEndpointLongRunningOperation, possibly from a different process. 2413 func (c *endpointGRPCClient) UpdateEndpointLongRunningOperation(name string) *UpdateEndpointLongRunningOperation { 2414 return &UpdateEndpointLongRunningOperation{ 2415 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2416 } 2417 } 2418 2419 // UpdateEndpointLongRunningOperation returns a new UpdateEndpointLongRunningOperation from a given name. 2420 // The name must be that of a previously created UpdateEndpointLongRunningOperation, possibly from a different process. 2421 func (c *endpointRESTClient) UpdateEndpointLongRunningOperation(name string) *UpdateEndpointLongRunningOperation { 2422 override := fmt.Sprintf("/ui/%s", name) 2423 return &UpdateEndpointLongRunningOperation{ 2424 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2425 pollPath: override, 2426 } 2427 }