cloud.google.com/go/aiplatform@v1.106.0/apiv1/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  	"context"
    21  	"fmt"
    22  	"log/slog"
    23  	"math"
    24  	"net/url"
    25  
    26  	aiplatformpb "cloud.google.com/go/aiplatform/apiv1/aiplatformpb"
    27  	iampb "cloud.google.com/go/iam/apiv1/iampb"
    28  	"cloud.google.com/go/longrunning"
    29  	lroauto "cloud.google.com/go/longrunning/autogen"
    30  	longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
    31  	gax "github.com/googleapis/gax-go/v2"
    32  	"google.golang.org/api/iterator"
    33  	"google.golang.org/api/option"
    34  	"google.golang.org/api/option/internaloption"
    35  	gtransport "google.golang.org/api/transport/grpc"
    36  	locationpb "google.golang.org/genproto/googleapis/cloud/location"
    37  	"google.golang.org/grpc"
    38  	"google.golang.org/protobuf/proto"
    39  )
    40  
    41  var newVizierClientHook clientHook
    42  
    43  // VizierCallOptions contains the retry settings for each method of VizierClient.
    44  type VizierCallOptions struct {
    45  	CreateStudy                  []gax.CallOption
    46  	GetStudy                     []gax.CallOption
    47  	ListStudies                  []gax.CallOption
    48  	DeleteStudy                  []gax.CallOption
    49  	LookupStudy                  []gax.CallOption
    50  	SuggestTrials                []gax.CallOption
    51  	CreateTrial                  []gax.CallOption
    52  	GetTrial                     []gax.CallOption
    53  	ListTrials                   []gax.CallOption
    54  	AddTrialMeasurement          []gax.CallOption
    55  	CompleteTrial                []gax.CallOption
    56  	DeleteTrial                  []gax.CallOption
    57  	CheckTrialEarlyStoppingState []gax.CallOption
    58  	StopTrial                    []gax.CallOption
    59  	ListOptimalTrials            []gax.CallOption
    60  	GetLocation                  []gax.CallOption
    61  	ListLocations                []gax.CallOption
    62  	GetIamPolicy                 []gax.CallOption
    63  	SetIamPolicy                 []gax.CallOption
    64  	TestIamPermissions           []gax.CallOption
    65  	CancelOperation              []gax.CallOption
    66  	DeleteOperation              []gax.CallOption
    67  	GetOperation                 []gax.CallOption
    68  	ListOperations               []gax.CallOption
    69  	WaitOperation                []gax.CallOption
    70  }
    71  
    72  func defaultVizierGRPCClientOptions() []option.ClientOption {
    73  	return []option.ClientOption{
    74  		internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"),
    75  		internaloption.WithDefaultEndpointTemplate("aiplatform.UNIVERSE_DOMAIN:443"),
    76  		internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"),
    77  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
    78  		internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"),
    79  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
    80  		internaloption.EnableJwtWithScope(),
    81  		internaloption.EnableNewAuthLibrary(),
    82  		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
    83  			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
    84  	}
    85  }
    86  
    87  func defaultVizierCallOptions() *VizierCallOptions {
    88  	return &VizierCallOptions{
    89  		CreateStudy:                  []gax.CallOption{},
    90  		GetStudy:                     []gax.CallOption{},
    91  		ListStudies:                  []gax.CallOption{},
    92  		DeleteStudy:                  []gax.CallOption{},
    93  		LookupStudy:                  []gax.CallOption{},
    94  		SuggestTrials:                []gax.CallOption{},
    95  		CreateTrial:                  []gax.CallOption{},
    96  		GetTrial:                     []gax.CallOption{},
    97  		ListTrials:                   []gax.CallOption{},
    98  		AddTrialMeasurement:          []gax.CallOption{},
    99  		CompleteTrial:                []gax.CallOption{},
   100  		DeleteTrial:                  []gax.CallOption{},
   101  		CheckTrialEarlyStoppingState: []gax.CallOption{},
   102  		StopTrial:                    []gax.CallOption{},
   103  		ListOptimalTrials:            []gax.CallOption{},
   104  		GetLocation:                  []gax.CallOption{},
   105  		ListLocations:                []gax.CallOption{},
   106  		GetIamPolicy:                 []gax.CallOption{},
   107  		SetIamPolicy:                 []gax.CallOption{},
   108  		TestIamPermissions:           []gax.CallOption{},
   109  		CancelOperation:              []gax.CallOption{},
   110  		DeleteOperation:              []gax.CallOption{},
   111  		GetOperation:                 []gax.CallOption{},
   112  		ListOperations:               []gax.CallOption{},
   113  		WaitOperation:                []gax.CallOption{},
   114  	}
   115  }
   116  
   117  // internalVizierClient is an interface that defines the methods available from Vertex AI API.
   118  type internalVizierClient interface {
   119  	Close() error
   120  	setGoogleClientInfo(...string)
   121  	Connection() *grpc.ClientConn
   122  	CreateStudy(context.Context, *aiplatformpb.CreateStudyRequest, ...gax.CallOption) (*aiplatformpb.Study, error)
   123  	GetStudy(context.Context, *aiplatformpb.GetStudyRequest, ...gax.CallOption) (*aiplatformpb.Study, error)
   124  	ListStudies(context.Context, *aiplatformpb.ListStudiesRequest, ...gax.CallOption) *StudyIterator
   125  	DeleteStudy(context.Context, *aiplatformpb.DeleteStudyRequest, ...gax.CallOption) error
   126  	LookupStudy(context.Context, *aiplatformpb.LookupStudyRequest, ...gax.CallOption) (*aiplatformpb.Study, error)
   127  	SuggestTrials(context.Context, *aiplatformpb.SuggestTrialsRequest, ...gax.CallOption) (*SuggestTrialsOperation, error)
   128  	SuggestTrialsOperation(name string) *SuggestTrialsOperation
   129  	CreateTrial(context.Context, *aiplatformpb.CreateTrialRequest, ...gax.CallOption) (*aiplatformpb.Trial, error)
   130  	GetTrial(context.Context, *aiplatformpb.GetTrialRequest, ...gax.CallOption) (*aiplatformpb.Trial, error)
   131  	ListTrials(context.Context, *aiplatformpb.ListTrialsRequest, ...gax.CallOption) *TrialIterator
   132  	AddTrialMeasurement(context.Context, *aiplatformpb.AddTrialMeasurementRequest, ...gax.CallOption) (*aiplatformpb.Trial, error)
   133  	CompleteTrial(context.Context, *aiplatformpb.CompleteTrialRequest, ...gax.CallOption) (*aiplatformpb.Trial, error)
   134  	DeleteTrial(context.Context, *aiplatformpb.DeleteTrialRequest, ...gax.CallOption) error
   135  	CheckTrialEarlyStoppingState(context.Context, *aiplatformpb.CheckTrialEarlyStoppingStateRequest, ...gax.CallOption) (*CheckTrialEarlyStoppingStateOperation, error)
   136  	CheckTrialEarlyStoppingStateOperation(name string) *CheckTrialEarlyStoppingStateOperation
   137  	StopTrial(context.Context, *aiplatformpb.StopTrialRequest, ...gax.CallOption) (*aiplatformpb.Trial, error)
   138  	ListOptimalTrials(context.Context, *aiplatformpb.ListOptimalTrialsRequest, ...gax.CallOption) (*aiplatformpb.ListOptimalTrialsResponse, error)
   139  	GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error)
   140  	ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator
   141  	GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   142  	SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   143  	TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
   144  	CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
   145  	DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error
   146  	GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
   147  	ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
   148  	WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
   149  }
   150  
   151  // VizierClient is a client for interacting with Vertex AI API.
   152  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   153  //
   154  // Vertex AI Vizier API.
   155  //
   156  // Vertex AI Vizier is a service to solve blackbox optimization problems,
   157  // such as tuning machine learning hyperparameters and searching over deep
   158  // learning architectures.
   159  type VizierClient struct {
   160  	// The internal transport-dependent client.
   161  	internalClient internalVizierClient
   162  
   163  	// The call options for this service.
   164  	CallOptions *VizierCallOptions
   165  
   166  	// LROClient is used internally to handle long-running operations.
   167  	// It is exposed so that its CallOptions can be modified if required.
   168  	// Users should not Close this client.
   169  	LROClient *lroauto.OperationsClient
   170  }
   171  
   172  // Wrapper methods routed to the internal client.
   173  
   174  // Close closes the connection to the API service. The user should invoke this when
   175  // the client is no longer required.
   176  func (c *VizierClient) Close() error {
   177  	return c.internalClient.Close()
   178  }
   179  
   180  // setGoogleClientInfo sets the name and version of the application in
   181  // the `x-goog-api-client` header passed on each request. Intended for
   182  // use by Google-written clients.
   183  func (c *VizierClient) setGoogleClientInfo(keyval ...string) {
   184  	c.internalClient.setGoogleClientInfo(keyval...)
   185  }
   186  
   187  // Connection returns a connection to the API service.
   188  //
   189  // Deprecated: Connections are now pooled so this method does not always
   190  // return the same resource.
   191  func (c *VizierClient) Connection() *grpc.ClientConn {
   192  	return c.internalClient.Connection()
   193  }
   194  
   195  // CreateStudy creates a Study. A resource name will be generated after creation of the
   196  // Study.
   197  func (c *VizierClient) CreateStudy(ctx context.Context, req *aiplatformpb.CreateStudyRequest, opts ...gax.CallOption) (*aiplatformpb.Study, error) {
   198  	return c.internalClient.CreateStudy(ctx, req, opts...)
   199  }
   200  
   201  // GetStudy gets a Study by name.
   202  func (c *VizierClient) GetStudy(ctx context.Context, req *aiplatformpb.GetStudyRequest, opts ...gax.CallOption) (*aiplatformpb.Study, error) {
   203  	return c.internalClient.GetStudy(ctx, req, opts...)
   204  }
   205  
   206  // ListStudies lists all the studies in a region for an associated project.
   207  func (c *VizierClient) ListStudies(ctx context.Context, req *aiplatformpb.ListStudiesRequest, opts ...gax.CallOption) *StudyIterator {
   208  	return c.internalClient.ListStudies(ctx, req, opts...)
   209  }
   210  
   211  // DeleteStudy deletes a Study.
   212  func (c *VizierClient) DeleteStudy(ctx context.Context, req *aiplatformpb.DeleteStudyRequest, opts ...gax.CallOption) error {
   213  	return c.internalClient.DeleteStudy(ctx, req, opts...)
   214  }
   215  
   216  // LookupStudy looks a study up using the user-defined display_name field instead of the
   217  // fully qualified resource name.
   218  func (c *VizierClient) LookupStudy(ctx context.Context, req *aiplatformpb.LookupStudyRequest, opts ...gax.CallOption) (*aiplatformpb.Study, error) {
   219  	return c.internalClient.LookupStudy(ctx, req, opts...)
   220  }
   221  
   222  // SuggestTrials adds one or more Trials to a Study, with parameter values
   223  // suggested by Vertex AI Vizier. Returns a long-running
   224  // operation associated with the generation of Trial suggestions.
   225  // When this long-running operation succeeds, it will contain
   226  // a
   227  // SuggestTrialsResponse.
   228  func (c *VizierClient) SuggestTrials(ctx context.Context, req *aiplatformpb.SuggestTrialsRequest, opts ...gax.CallOption) (*SuggestTrialsOperation, error) {
   229  	return c.internalClient.SuggestTrials(ctx, req, opts...)
   230  }
   231  
   232  // SuggestTrialsOperation returns a new SuggestTrialsOperation from a given name.
   233  // The name must be that of a previously created SuggestTrialsOperation, possibly from a different process.
   234  func (c *VizierClient) SuggestTrialsOperation(name string) *SuggestTrialsOperation {
   235  	return c.internalClient.SuggestTrialsOperation(name)
   236  }
   237  
   238  // CreateTrial adds a user provided Trial to a Study.
   239  func (c *VizierClient) CreateTrial(ctx context.Context, req *aiplatformpb.CreateTrialRequest, opts ...gax.CallOption) (*aiplatformpb.Trial, error) {
   240  	return c.internalClient.CreateTrial(ctx, req, opts...)
   241  }
   242  
   243  // GetTrial gets a Trial.
   244  func (c *VizierClient) GetTrial(ctx context.Context, req *aiplatformpb.GetTrialRequest, opts ...gax.CallOption) (*aiplatformpb.Trial, error) {
   245  	return c.internalClient.GetTrial(ctx, req, opts...)
   246  }
   247  
   248  // ListTrials lists the Trials associated with a Study.
   249  func (c *VizierClient) ListTrials(ctx context.Context, req *aiplatformpb.ListTrialsRequest, opts ...gax.CallOption) *TrialIterator {
   250  	return c.internalClient.ListTrials(ctx, req, opts...)
   251  }
   252  
   253  // AddTrialMeasurement adds a measurement of the objective metrics to a Trial. This measurement
   254  // is assumed to have been taken before the Trial is complete.
   255  func (c *VizierClient) AddTrialMeasurement(ctx context.Context, req *aiplatformpb.AddTrialMeasurementRequest, opts ...gax.CallOption) (*aiplatformpb.Trial, error) {
   256  	return c.internalClient.AddTrialMeasurement(ctx, req, opts...)
   257  }
   258  
   259  // CompleteTrial marks a Trial as complete.
   260  func (c *VizierClient) CompleteTrial(ctx context.Context, req *aiplatformpb.CompleteTrialRequest, opts ...gax.CallOption) (*aiplatformpb.Trial, error) {
   261  	return c.internalClient.CompleteTrial(ctx, req, opts...)
   262  }
   263  
   264  // DeleteTrial deletes a Trial.
   265  func (c *VizierClient) DeleteTrial(ctx context.Context, req *aiplatformpb.DeleteTrialRequest, opts ...gax.CallOption) error {
   266  	return c.internalClient.DeleteTrial(ctx, req, opts...)
   267  }
   268  
   269  // CheckTrialEarlyStoppingState checks  whether a Trial should stop or not. Returns a
   270  // long-running operation. When the operation is successful,
   271  // it will contain a
   272  // CheckTrialEarlyStoppingStateResponse.
   273  func (c *VizierClient) CheckTrialEarlyStoppingState(ctx context.Context, req *aiplatformpb.CheckTrialEarlyStoppingStateRequest, opts ...gax.CallOption) (*CheckTrialEarlyStoppingStateOperation, error) {
   274  	return c.internalClient.CheckTrialEarlyStoppingState(ctx, req, opts...)
   275  }
   276  
   277  // CheckTrialEarlyStoppingStateOperation returns a new CheckTrialEarlyStoppingStateOperation from a given name.
   278  // The name must be that of a previously created CheckTrialEarlyStoppingStateOperation, possibly from a different process.
   279  func (c *VizierClient) CheckTrialEarlyStoppingStateOperation(name string) *CheckTrialEarlyStoppingStateOperation {
   280  	return c.internalClient.CheckTrialEarlyStoppingStateOperation(name)
   281  }
   282  
   283  // StopTrial stops a Trial.
   284  func (c *VizierClient) StopTrial(ctx context.Context, req *aiplatformpb.StopTrialRequest, opts ...gax.CallOption) (*aiplatformpb.Trial, error) {
   285  	return c.internalClient.StopTrial(ctx, req, opts...)
   286  }
   287  
   288  // ListOptimalTrials lists the pareto-optimal Trials for multi-objective Study or the
   289  // optimal Trials for single-objective Study. The definition of
   290  // pareto-optimal can be checked in wiki page.
   291  // https://en.wikipedia.org/wiki/Pareto_efficiency (at https://en.wikipedia.org/wiki/Pareto_efficiency)
   292  func (c *VizierClient) ListOptimalTrials(ctx context.Context, req *aiplatformpb.ListOptimalTrialsRequest, opts ...gax.CallOption) (*aiplatformpb.ListOptimalTrialsResponse, error) {
   293  	return c.internalClient.ListOptimalTrials(ctx, req, opts...)
   294  }
   295  
   296  // GetLocation gets information about a location.
   297  func (c *VizierClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
   298  	return c.internalClient.GetLocation(ctx, req, opts...)
   299  }
   300  
   301  // ListLocations lists information about the supported locations for this service.
   302  func (c *VizierClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
   303  	return c.internalClient.ListLocations(ctx, req, opts...)
   304  }
   305  
   306  // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
   307  // if the resource exists and does not have a policy set.
   308  func (c *VizierClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   309  	return c.internalClient.GetIamPolicy(ctx, req, opts...)
   310  }
   311  
   312  // SetIamPolicy sets the access control policy on the specified resource. Replaces
   313  // any existing policy.
   314  //
   315  // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
   316  // errors.
   317  func (c *VizierClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   318  	return c.internalClient.SetIamPolicy(ctx, req, opts...)
   319  }
   320  
   321  // TestIamPermissions returns permissions that a caller has on the specified resource. If the
   322  // resource does not exist, this will return an empty set of
   323  // permissions, not a NOT_FOUND error.
   324  //
   325  // Note: This operation is designed to be used for building
   326  // permission-aware UIs and command-line tools, not for authorization
   327  // checking. This operation may “fail open” without warning.
   328  func (c *VizierClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   329  	return c.internalClient.TestIamPermissions(ctx, req, opts...)
   330  }
   331  
   332  // CancelOperation is a utility method from google.longrunning.Operations.
   333  func (c *VizierClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
   334  	return c.internalClient.CancelOperation(ctx, req, opts...)
   335  }
   336  
   337  // DeleteOperation is a utility method from google.longrunning.Operations.
   338  func (c *VizierClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
   339  	return c.internalClient.DeleteOperation(ctx, req, opts...)
   340  }
   341  
   342  // GetOperation is a utility method from google.longrunning.Operations.
   343  func (c *VizierClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   344  	return c.internalClient.GetOperation(ctx, req, opts...)
   345  }
   346  
   347  // ListOperations is a utility method from google.longrunning.Operations.
   348  func (c *VizierClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
   349  	return c.internalClient.ListOperations(ctx, req, opts...)
   350  }
   351  
   352  // WaitOperation is a utility method from google.longrunning.Operations.
   353  func (c *VizierClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   354  	return c.internalClient.WaitOperation(ctx, req, opts...)
   355  }
   356  
   357  // vizierGRPCClient is a client for interacting with Vertex AI API over gRPC transport.
   358  //
   359  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   360  type vizierGRPCClient struct {
   361  	// Connection pool of gRPC connections to the service.
   362  	connPool gtransport.ConnPool
   363  
   364  	// Points back to the CallOptions field of the containing VizierClient
   365  	CallOptions **VizierCallOptions
   366  
   367  	// The gRPC API client.
   368  	vizierClient aiplatformpb.VizierServiceClient
   369  
   370  	// LROClient is used internally to handle long-running operations.
   371  	// It is exposed so that its CallOptions can be modified if required.
   372  	// Users should not Close this client.
   373  	LROClient **lroauto.OperationsClient
   374  
   375  	operationsClient longrunningpb.OperationsClient
   376  
   377  	iamPolicyClient iampb.IAMPolicyClient
   378  
   379  	locationsClient locationpb.LocationsClient
   380  
   381  	// The x-goog-* metadata to be sent with each request.
   382  	xGoogHeaders []string
   383  
   384  	logger *slog.Logger
   385  }
   386  
   387  // NewVizierClient creates a new vizier service client based on gRPC.
   388  // The returned client must be Closed when it is done being used to clean up its underlying connections.
   389  //
   390  // Vertex AI Vizier API.
   391  //
   392  // Vertex AI Vizier is a service to solve blackbox optimization problems,
   393  // such as tuning machine learning hyperparameters and searching over deep
   394  // learning architectures.
   395  func NewVizierClient(ctx context.Context, opts ...option.ClientOption) (*VizierClient, error) {
   396  	clientOpts := defaultVizierGRPCClientOptions()
   397  	if newVizierClientHook != nil {
   398  		hookOpts, err := newVizierClientHook(ctx, clientHookParams{})
   399  		if err != nil {
   400  			return nil, err
   401  		}
   402  		clientOpts = append(clientOpts, hookOpts...)
   403  	}
   404  
   405  	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
   406  	if err != nil {
   407  		return nil, err
   408  	}
   409  	client := VizierClient{CallOptions: defaultVizierCallOptions()}
   410  
   411  	c := &vizierGRPCClient{
   412  		connPool:         connPool,
   413  		vizierClient:     aiplatformpb.NewVizierServiceClient(connPool),
   414  		CallOptions:      &client.CallOptions,
   415  		logger:           internaloption.GetLogger(opts),
   416  		operationsClient: longrunningpb.NewOperationsClient(connPool),
   417  		iamPolicyClient:  iampb.NewIAMPolicyClient(connPool),
   418  		locationsClient:  locationpb.NewLocationsClient(connPool),
   419  	}
   420  	c.setGoogleClientInfo()
   421  
   422  	client.internalClient = c
   423  
   424  	client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
   425  	if err != nil {
   426  		// This error "should not happen", since we are just reusing old connection pool
   427  		// and never actually need to dial.
   428  		// If this does happen, we could leak connp. However, we cannot close conn:
   429  		// If the user invoked the constructor with option.WithGRPCConn,
   430  		// we would close a connection that's still in use.
   431  		// TODO: investigate error conditions.
   432  		return nil, err
   433  	}
   434  	c.LROClient = &client.LROClient
   435  	return &client, nil
   436  }
   437  
   438  // Connection returns a connection to the API service.
   439  //
   440  // Deprecated: Connections are now pooled so this method does not always
   441  // return the same resource.
   442  func (c *vizierGRPCClient) Connection() *grpc.ClientConn {
   443  	return c.connPool.Conn()
   444  }
   445  
   446  // setGoogleClientInfo sets the name and version of the application in
   447  // the `x-goog-api-client` header passed on each request. Intended for
   448  // use by Google-written clients.
   449  func (c *vizierGRPCClient) setGoogleClientInfo(keyval ...string) {
   450  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   451  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
   452  	c.xGoogHeaders = []string{
   453  		"x-goog-api-client", gax.XGoogHeader(kv...),
   454  	}
   455  }
   456  
   457  // Close closes the connection to the API service. The user should invoke this when
   458  // the client is no longer required.
   459  func (c *vizierGRPCClient) Close() error {
   460  	return c.connPool.Close()
   461  }
   462  
   463  func (c *vizierGRPCClient) CreateStudy(ctx context.Context, req *aiplatformpb.CreateStudyRequest, opts ...gax.CallOption) (*aiplatformpb.Study, error) {
   464  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   465  
   466  	hds = append(c.xGoogHeaders, hds...)
   467  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   468  	opts = append((*c.CallOptions).CreateStudy[0:len((*c.CallOptions).CreateStudy):len((*c.CallOptions).CreateStudy)], opts...)
   469  	var resp *aiplatformpb.Study
   470  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   471  		var err error
   472  		resp, err = executeRPC(ctx, c.vizierClient.CreateStudy, req, settings.GRPC, c.logger, "CreateStudy")
   473  		return err
   474  	}, opts...)
   475  	if err != nil {
   476  		return nil, err
   477  	}
   478  	return resp, nil
   479  }
   480  
   481  func (c *vizierGRPCClient) GetStudy(ctx context.Context, req *aiplatformpb.GetStudyRequest, opts ...gax.CallOption) (*aiplatformpb.Study, error) {
   482  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   483  
   484  	hds = append(c.xGoogHeaders, hds...)
   485  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   486  	opts = append((*c.CallOptions).GetStudy[0:len((*c.CallOptions).GetStudy):len((*c.CallOptions).GetStudy)], opts...)
   487  	var resp *aiplatformpb.Study
   488  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   489  		var err error
   490  		resp, err = executeRPC(ctx, c.vizierClient.GetStudy, req, settings.GRPC, c.logger, "GetStudy")
   491  		return err
   492  	}, opts...)
   493  	if err != nil {
   494  		return nil, err
   495  	}
   496  	return resp, nil
   497  }
   498  
   499  func (c *vizierGRPCClient) ListStudies(ctx context.Context, req *aiplatformpb.ListStudiesRequest, opts ...gax.CallOption) *StudyIterator {
   500  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   501  
   502  	hds = append(c.xGoogHeaders, hds...)
   503  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   504  	opts = append((*c.CallOptions).ListStudies[0:len((*c.CallOptions).ListStudies):len((*c.CallOptions).ListStudies)], opts...)
   505  	it := &StudyIterator{}
   506  	req = proto.Clone(req).(*aiplatformpb.ListStudiesRequest)
   507  	it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.Study, string, error) {
   508  		resp := &aiplatformpb.ListStudiesResponse{}
   509  		if pageToken != "" {
   510  			req.PageToken = pageToken
   511  		}
   512  		if pageSize > math.MaxInt32 {
   513  			req.PageSize = math.MaxInt32
   514  		} else if pageSize != 0 {
   515  			req.PageSize = int32(pageSize)
   516  		}
   517  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   518  			var err error
   519  			resp, err = executeRPC(ctx, c.vizierClient.ListStudies, req, settings.GRPC, c.logger, "ListStudies")
   520  			return err
   521  		}, opts...)
   522  		if err != nil {
   523  			return nil, "", err
   524  		}
   525  
   526  		it.Response = resp
   527  		return resp.GetStudies(), resp.GetNextPageToken(), nil
   528  	}
   529  	fetch := func(pageSize int, pageToken string) (string, error) {
   530  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   531  		if err != nil {
   532  			return "", err
   533  		}
   534  		it.items = append(it.items, items...)
   535  		return nextPageToken, nil
   536  	}
   537  
   538  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   539  	it.pageInfo.MaxSize = int(req.GetPageSize())
   540  	it.pageInfo.Token = req.GetPageToken()
   541  
   542  	return it
   543  }
   544  
   545  func (c *vizierGRPCClient) DeleteStudy(ctx context.Context, req *aiplatformpb.DeleteStudyRequest, opts ...gax.CallOption) error {
   546  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   547  
   548  	hds = append(c.xGoogHeaders, hds...)
   549  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   550  	opts = append((*c.CallOptions).DeleteStudy[0:len((*c.CallOptions).DeleteStudy):len((*c.CallOptions).DeleteStudy)], opts...)
   551  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   552  		var err error
   553  		_, err = executeRPC(ctx, c.vizierClient.DeleteStudy, req, settings.GRPC, c.logger, "DeleteStudy")
   554  		return err
   555  	}, opts...)
   556  	return err
   557  }
   558  
   559  func (c *vizierGRPCClient) LookupStudy(ctx context.Context, req *aiplatformpb.LookupStudyRequest, opts ...gax.CallOption) (*aiplatformpb.Study, error) {
   560  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   561  
   562  	hds = append(c.xGoogHeaders, hds...)
   563  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   564  	opts = append((*c.CallOptions).LookupStudy[0:len((*c.CallOptions).LookupStudy):len((*c.CallOptions).LookupStudy)], opts...)
   565  	var resp *aiplatformpb.Study
   566  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   567  		var err error
   568  		resp, err = executeRPC(ctx, c.vizierClient.LookupStudy, req, settings.GRPC, c.logger, "LookupStudy")
   569  		return err
   570  	}, opts...)
   571  	if err != nil {
   572  		return nil, err
   573  	}
   574  	return resp, nil
   575  }
   576  
   577  func (c *vizierGRPCClient) SuggestTrials(ctx context.Context, req *aiplatformpb.SuggestTrialsRequest, opts ...gax.CallOption) (*SuggestTrialsOperation, error) {
   578  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   579  
   580  	hds = append(c.xGoogHeaders, hds...)
   581  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   582  	opts = append((*c.CallOptions).SuggestTrials[0:len((*c.CallOptions).SuggestTrials):len((*c.CallOptions).SuggestTrials)], opts...)
   583  	var resp *longrunningpb.Operation
   584  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   585  		var err error
   586  		resp, err = executeRPC(ctx, c.vizierClient.SuggestTrials, req, settings.GRPC, c.logger, "SuggestTrials")
   587  		return err
   588  	}, opts...)
   589  	if err != nil {
   590  		return nil, err
   591  	}
   592  	return &SuggestTrialsOperation{
   593  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   594  	}, nil
   595  }
   596  
   597  func (c *vizierGRPCClient) CreateTrial(ctx context.Context, req *aiplatformpb.CreateTrialRequest, opts ...gax.CallOption) (*aiplatformpb.Trial, error) {
   598  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   599  
   600  	hds = append(c.xGoogHeaders, hds...)
   601  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   602  	opts = append((*c.CallOptions).CreateTrial[0:len((*c.CallOptions).CreateTrial):len((*c.CallOptions).CreateTrial)], opts...)
   603  	var resp *aiplatformpb.Trial
   604  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   605  		var err error
   606  		resp, err = executeRPC(ctx, c.vizierClient.CreateTrial, req, settings.GRPC, c.logger, "CreateTrial")
   607  		return err
   608  	}, opts...)
   609  	if err != nil {
   610  		return nil, err
   611  	}
   612  	return resp, nil
   613  }
   614  
   615  func (c *vizierGRPCClient) GetTrial(ctx context.Context, req *aiplatformpb.GetTrialRequest, opts ...gax.CallOption) (*aiplatformpb.Trial, error) {
   616  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   617  
   618  	hds = append(c.xGoogHeaders, hds...)
   619  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   620  	opts = append((*c.CallOptions).GetTrial[0:len((*c.CallOptions).GetTrial):len((*c.CallOptions).GetTrial)], opts...)
   621  	var resp *aiplatformpb.Trial
   622  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   623  		var err error
   624  		resp, err = executeRPC(ctx, c.vizierClient.GetTrial, req, settings.GRPC, c.logger, "GetTrial")
   625  		return err
   626  	}, opts...)
   627  	if err != nil {
   628  		return nil, err
   629  	}
   630  	return resp, nil
   631  }
   632  
   633  func (c *vizierGRPCClient) ListTrials(ctx context.Context, req *aiplatformpb.ListTrialsRequest, opts ...gax.CallOption) *TrialIterator {
   634  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   635  
   636  	hds = append(c.xGoogHeaders, hds...)
   637  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   638  	opts = append((*c.CallOptions).ListTrials[0:len((*c.CallOptions).ListTrials):len((*c.CallOptions).ListTrials)], opts...)
   639  	it := &TrialIterator{}
   640  	req = proto.Clone(req).(*aiplatformpb.ListTrialsRequest)
   641  	it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.Trial, string, error) {
   642  		resp := &aiplatformpb.ListTrialsResponse{}
   643  		if pageToken != "" {
   644  			req.PageToken = pageToken
   645  		}
   646  		if pageSize > math.MaxInt32 {
   647  			req.PageSize = math.MaxInt32
   648  		} else if pageSize != 0 {
   649  			req.PageSize = int32(pageSize)
   650  		}
   651  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   652  			var err error
   653  			resp, err = executeRPC(ctx, c.vizierClient.ListTrials, req, settings.GRPC, c.logger, "ListTrials")
   654  			return err
   655  		}, opts...)
   656  		if err != nil {
   657  			return nil, "", err
   658  		}
   659  
   660  		it.Response = resp
   661  		return resp.GetTrials(), resp.GetNextPageToken(), nil
   662  	}
   663  	fetch := func(pageSize int, pageToken string) (string, error) {
   664  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   665  		if err != nil {
   666  			return "", err
   667  		}
   668  		it.items = append(it.items, items...)
   669  		return nextPageToken, nil
   670  	}
   671  
   672  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   673  	it.pageInfo.MaxSize = int(req.GetPageSize())
   674  	it.pageInfo.Token = req.GetPageToken()
   675  
   676  	return it
   677  }
   678  
   679  func (c *vizierGRPCClient) AddTrialMeasurement(ctx context.Context, req *aiplatformpb.AddTrialMeasurementRequest, opts ...gax.CallOption) (*aiplatformpb.Trial, error) {
   680  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "trial_name", url.QueryEscape(req.GetTrialName()))}
   681  
   682  	hds = append(c.xGoogHeaders, hds...)
   683  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   684  	opts = append((*c.CallOptions).AddTrialMeasurement[0:len((*c.CallOptions).AddTrialMeasurement):len((*c.CallOptions).AddTrialMeasurement)], opts...)
   685  	var resp *aiplatformpb.Trial
   686  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   687  		var err error
   688  		resp, err = executeRPC(ctx, c.vizierClient.AddTrialMeasurement, req, settings.GRPC, c.logger, "AddTrialMeasurement")
   689  		return err
   690  	}, opts...)
   691  	if err != nil {
   692  		return nil, err
   693  	}
   694  	return resp, nil
   695  }
   696  
   697  func (c *vizierGRPCClient) CompleteTrial(ctx context.Context, req *aiplatformpb.CompleteTrialRequest, opts ...gax.CallOption) (*aiplatformpb.Trial, error) {
   698  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   699  
   700  	hds = append(c.xGoogHeaders, hds...)
   701  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   702  	opts = append((*c.CallOptions).CompleteTrial[0:len((*c.CallOptions).CompleteTrial):len((*c.CallOptions).CompleteTrial)], opts...)
   703  	var resp *aiplatformpb.Trial
   704  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   705  		var err error
   706  		resp, err = executeRPC(ctx, c.vizierClient.CompleteTrial, req, settings.GRPC, c.logger, "CompleteTrial")
   707  		return err
   708  	}, opts...)
   709  	if err != nil {
   710  		return nil, err
   711  	}
   712  	return resp, nil
   713  }
   714  
   715  func (c *vizierGRPCClient) DeleteTrial(ctx context.Context, req *aiplatformpb.DeleteTrialRequest, opts ...gax.CallOption) error {
   716  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   717  
   718  	hds = append(c.xGoogHeaders, hds...)
   719  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   720  	opts = append((*c.CallOptions).DeleteTrial[0:len((*c.CallOptions).DeleteTrial):len((*c.CallOptions).DeleteTrial)], opts...)
   721  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   722  		var err error
   723  		_, err = executeRPC(ctx, c.vizierClient.DeleteTrial, req, settings.GRPC, c.logger, "DeleteTrial")
   724  		return err
   725  	}, opts...)
   726  	return err
   727  }
   728  
   729  func (c *vizierGRPCClient) CheckTrialEarlyStoppingState(ctx context.Context, req *aiplatformpb.CheckTrialEarlyStoppingStateRequest, opts ...gax.CallOption) (*CheckTrialEarlyStoppingStateOperation, error) {
   730  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "trial_name", url.QueryEscape(req.GetTrialName()))}
   731  
   732  	hds = append(c.xGoogHeaders, hds...)
   733  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   734  	opts = append((*c.CallOptions).CheckTrialEarlyStoppingState[0:len((*c.CallOptions).CheckTrialEarlyStoppingState):len((*c.CallOptions).CheckTrialEarlyStoppingState)], opts...)
   735  	var resp *longrunningpb.Operation
   736  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   737  		var err error
   738  		resp, err = executeRPC(ctx, c.vizierClient.CheckTrialEarlyStoppingState, req, settings.GRPC, c.logger, "CheckTrialEarlyStoppingState")
   739  		return err
   740  	}, opts...)
   741  	if err != nil {
   742  		return nil, err
   743  	}
   744  	return &CheckTrialEarlyStoppingStateOperation{
   745  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   746  	}, nil
   747  }
   748  
   749  func (c *vizierGRPCClient) StopTrial(ctx context.Context, req *aiplatformpb.StopTrialRequest, opts ...gax.CallOption) (*aiplatformpb.Trial, error) {
   750  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   751  
   752  	hds = append(c.xGoogHeaders, hds...)
   753  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   754  	opts = append((*c.CallOptions).StopTrial[0:len((*c.CallOptions).StopTrial):len((*c.CallOptions).StopTrial)], opts...)
   755  	var resp *aiplatformpb.Trial
   756  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   757  		var err error
   758  		resp, err = executeRPC(ctx, c.vizierClient.StopTrial, req, settings.GRPC, c.logger, "StopTrial")
   759  		return err
   760  	}, opts...)
   761  	if err != nil {
   762  		return nil, err
   763  	}
   764  	return resp, nil
   765  }
   766  
   767  func (c *vizierGRPCClient) ListOptimalTrials(ctx context.Context, req *aiplatformpb.ListOptimalTrialsRequest, opts ...gax.CallOption) (*aiplatformpb.ListOptimalTrialsResponse, 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).ListOptimalTrials[0:len((*c.CallOptions).ListOptimalTrials):len((*c.CallOptions).ListOptimalTrials)], opts...)
   773  	var resp *aiplatformpb.ListOptimalTrialsResponse
   774  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   775  		var err error
   776  		resp, err = executeRPC(ctx, c.vizierClient.ListOptimalTrials, req, settings.GRPC, c.logger, "ListOptimalTrials")
   777  		return err
   778  	}, opts...)
   779  	if err != nil {
   780  		return nil, err
   781  	}
   782  	return resp, nil
   783  }
   784  
   785  func (c *vizierGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
   786  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   787  
   788  	hds = append(c.xGoogHeaders, hds...)
   789  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   790  	opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
   791  	var resp *locationpb.Location
   792  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   793  		var err error
   794  		resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation")
   795  		return err
   796  	}, opts...)
   797  	if err != nil {
   798  		return nil, err
   799  	}
   800  	return resp, nil
   801  }
   802  
   803  func (c *vizierGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
   804  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   805  
   806  	hds = append(c.xGoogHeaders, hds...)
   807  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   808  	opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...)
   809  	it := &LocationIterator{}
   810  	req = proto.Clone(req).(*locationpb.ListLocationsRequest)
   811  	it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
   812  		resp := &locationpb.ListLocationsResponse{}
   813  		if pageToken != "" {
   814  			req.PageToken = pageToken
   815  		}
   816  		if pageSize > math.MaxInt32 {
   817  			req.PageSize = math.MaxInt32
   818  		} else if pageSize != 0 {
   819  			req.PageSize = int32(pageSize)
   820  		}
   821  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   822  			var err error
   823  			resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations")
   824  			return err
   825  		}, opts...)
   826  		if err != nil {
   827  			return nil, "", err
   828  		}
   829  
   830  		it.Response = resp
   831  		return resp.GetLocations(), resp.GetNextPageToken(), nil
   832  	}
   833  	fetch := func(pageSize int, pageToken string) (string, error) {
   834  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   835  		if err != nil {
   836  			return "", err
   837  		}
   838  		it.items = append(it.items, items...)
   839  		return nextPageToken, nil
   840  	}
   841  
   842  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   843  	it.pageInfo.MaxSize = int(req.GetPageSize())
   844  	it.pageInfo.Token = req.GetPageToken()
   845  
   846  	return it
   847  }
   848  
   849  func (c *vizierGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   850  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   851  
   852  	hds = append(c.xGoogHeaders, hds...)
   853  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   854  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
   855  	var resp *iampb.Policy
   856  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   857  		var err error
   858  		resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy")
   859  		return err
   860  	}, opts...)
   861  	if err != nil {
   862  		return nil, err
   863  	}
   864  	return resp, nil
   865  }
   866  
   867  func (c *vizierGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   868  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   869  
   870  	hds = append(c.xGoogHeaders, hds...)
   871  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   872  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
   873  	var resp *iampb.Policy
   874  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   875  		var err error
   876  		resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy")
   877  		return err
   878  	}, opts...)
   879  	if err != nil {
   880  		return nil, err
   881  	}
   882  	return resp, nil
   883  }
   884  
   885  func (c *vizierGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   886  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   887  
   888  	hds = append(c.xGoogHeaders, hds...)
   889  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   890  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
   891  	var resp *iampb.TestIamPermissionsResponse
   892  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   893  		var err error
   894  		resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions")
   895  		return err
   896  	}, opts...)
   897  	if err != nil {
   898  		return nil, err
   899  	}
   900  	return resp, nil
   901  }
   902  
   903  func (c *vizierGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
   904  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   905  
   906  	hds = append(c.xGoogHeaders, hds...)
   907  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   908  	opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
   909  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   910  		var err error
   911  		_, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation")
   912  		return err
   913  	}, opts...)
   914  	return err
   915  }
   916  
   917  func (c *vizierGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
   918  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   919  
   920  	hds = append(c.xGoogHeaders, hds...)
   921  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   922  	opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...)
   923  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   924  		var err error
   925  		_, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation")
   926  		return err
   927  	}, opts...)
   928  	return err
   929  }
   930  
   931  func (c *vizierGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   932  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   933  
   934  	hds = append(c.xGoogHeaders, hds...)
   935  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   936  	opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
   937  	var resp *longrunningpb.Operation
   938  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   939  		var err error
   940  		resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
   941  		return err
   942  	}, opts...)
   943  	if err != nil {
   944  		return nil, err
   945  	}
   946  	return resp, nil
   947  }
   948  
   949  func (c *vizierGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
   950  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   951  
   952  	hds = append(c.xGoogHeaders, hds...)
   953  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   954  	opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
   955  	it := &OperationIterator{}
   956  	req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
   957  	it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
   958  		resp := &longrunningpb.ListOperationsResponse{}
   959  		if pageToken != "" {
   960  			req.PageToken = pageToken
   961  		}
   962  		if pageSize > math.MaxInt32 {
   963  			req.PageSize = math.MaxInt32
   964  		} else if pageSize != 0 {
   965  			req.PageSize = int32(pageSize)
   966  		}
   967  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   968  			var err error
   969  			resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations")
   970  			return err
   971  		}, opts...)
   972  		if err != nil {
   973  			return nil, "", err
   974  		}
   975  
   976  		it.Response = resp
   977  		return resp.GetOperations(), resp.GetNextPageToken(), nil
   978  	}
   979  	fetch := func(pageSize int, pageToken string) (string, error) {
   980  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   981  		if err != nil {
   982  			return "", err
   983  		}
   984  		it.items = append(it.items, items...)
   985  		return nextPageToken, nil
   986  	}
   987  
   988  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   989  	it.pageInfo.MaxSize = int(req.GetPageSize())
   990  	it.pageInfo.Token = req.GetPageToken()
   991  
   992  	return it
   993  }
   994  
   995  func (c *vizierGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   996  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   997  
   998  	hds = append(c.xGoogHeaders, hds...)
   999  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1000  	opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...)
  1001  	var resp *longrunningpb.Operation
  1002  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1003  		var err error
  1004  		resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation")
  1005  		return err
  1006  	}, opts...)
  1007  	if err != nil {
  1008  		return nil, err
  1009  	}
  1010  	return resp, nil
  1011  }
  1012  
  1013  // CheckTrialEarlyStoppingStateOperation returns a new CheckTrialEarlyStoppingStateOperation from a given name.
  1014  // The name must be that of a previously created CheckTrialEarlyStoppingStateOperation, possibly from a different process.
  1015  func (c *vizierGRPCClient) CheckTrialEarlyStoppingStateOperation(name string) *CheckTrialEarlyStoppingStateOperation {
  1016  	return &CheckTrialEarlyStoppingStateOperation{
  1017  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1018  	}
  1019  }
  1020  
  1021  // SuggestTrialsOperation returns a new SuggestTrialsOperation from a given name.
  1022  // The name must be that of a previously created SuggestTrialsOperation, possibly from a different process.
  1023  func (c *vizierGRPCClient) SuggestTrialsOperation(name string) *SuggestTrialsOperation {
  1024  	return &SuggestTrialsOperation{
  1025  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1026  	}
  1027  }