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