cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/evaluation_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 newEvaluationClientHook clientHook
    47  
    48  // EvaluationCallOptions contains the retry settings for each method of EvaluationClient.
    49  type EvaluationCallOptions struct {
    50  	EvaluateInstances  []gax.CallOption
    51  	EvaluateDataset    []gax.CallOption
    52  	GetLocation        []gax.CallOption
    53  	ListLocations      []gax.CallOption
    54  	GetIamPolicy       []gax.CallOption
    55  	SetIamPolicy       []gax.CallOption
    56  	TestIamPermissions []gax.CallOption
    57  	CancelOperation    []gax.CallOption
    58  	DeleteOperation    []gax.CallOption
    59  	GetOperation       []gax.CallOption
    60  	ListOperations     []gax.CallOption
    61  	WaitOperation      []gax.CallOption
    62  }
    63  
    64  func defaultEvaluationGRPCClientOptions() []option.ClientOption {
    65  	return []option.ClientOption{
    66  		internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"),
    67  		internaloption.WithDefaultEndpointTemplate("aiplatform.UNIVERSE_DOMAIN:443"),
    68  		internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"),
    69  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
    70  		internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"),
    71  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
    72  		internaloption.EnableJwtWithScope(),
    73  		internaloption.EnableNewAuthLibrary(),
    74  		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
    75  			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
    76  	}
    77  }
    78  
    79  func defaultEvaluationCallOptions() *EvaluationCallOptions {
    80  	return &EvaluationCallOptions{
    81  		EvaluateInstances: []gax.CallOption{
    82  			gax.WithTimeout(60000 * time.Millisecond),
    83  		},
    84  		EvaluateDataset:    []gax.CallOption{},
    85  		GetLocation:        []gax.CallOption{},
    86  		ListLocations:      []gax.CallOption{},
    87  		GetIamPolicy:       []gax.CallOption{},
    88  		SetIamPolicy:       []gax.CallOption{},
    89  		TestIamPermissions: []gax.CallOption{},
    90  		CancelOperation:    []gax.CallOption{},
    91  		DeleteOperation:    []gax.CallOption{},
    92  		GetOperation:       []gax.CallOption{},
    93  		ListOperations:     []gax.CallOption{},
    94  		WaitOperation:      []gax.CallOption{},
    95  	}
    96  }
    97  
    98  func defaultEvaluationRESTCallOptions() *EvaluationCallOptions {
    99  	return &EvaluationCallOptions{
   100  		EvaluateInstances: []gax.CallOption{
   101  			gax.WithTimeout(60000 * time.Millisecond),
   102  		},
   103  		EvaluateDataset:    []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  // internalEvaluationClient is an interface that defines the methods available from Vertex AI API.
   118  type internalEvaluationClient interface {
   119  	Close() error
   120  	setGoogleClientInfo(...string)
   121  	Connection() *grpc.ClientConn
   122  	EvaluateInstances(context.Context, *aiplatformpb.EvaluateInstancesRequest, ...gax.CallOption) (*aiplatformpb.EvaluateInstancesResponse, error)
   123  	EvaluateDataset(context.Context, *aiplatformpb.EvaluateDatasetRequest, ...gax.CallOption) (*EvaluateDatasetOperation, error)
   124  	EvaluateDatasetOperation(name string) *EvaluateDatasetOperation
   125  	GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error)
   126  	ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator
   127  	GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   128  	SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   129  	TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
   130  	CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
   131  	DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error
   132  	GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
   133  	ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
   134  	WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
   135  }
   136  
   137  // EvaluationClient is a client for interacting with Vertex AI API.
   138  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   139  //
   140  // Vertex AI Online Evaluation Service.
   141  type EvaluationClient struct {
   142  	// The internal transport-dependent client.
   143  	internalClient internalEvaluationClient
   144  
   145  	// The call options for this service.
   146  	CallOptions *EvaluationCallOptions
   147  
   148  	// LROClient is used internally to handle long-running operations.
   149  	// It is exposed so that its CallOptions can be modified if required.
   150  	// Users should not Close this client.
   151  	LROClient *lroauto.OperationsClient
   152  }
   153  
   154  // Wrapper methods routed to the internal client.
   155  
   156  // Close closes the connection to the API service. The user should invoke this when
   157  // the client is no longer required.
   158  func (c *EvaluationClient) Close() error {
   159  	return c.internalClient.Close()
   160  }
   161  
   162  // setGoogleClientInfo sets the name and version of the application in
   163  // the `x-goog-api-client` header passed on each request. Intended for
   164  // use by Google-written clients.
   165  func (c *EvaluationClient) setGoogleClientInfo(keyval ...string) {
   166  	c.internalClient.setGoogleClientInfo(keyval...)
   167  }
   168  
   169  // Connection returns a connection to the API service.
   170  //
   171  // Deprecated: Connections are now pooled so this method does not always
   172  // return the same resource.
   173  func (c *EvaluationClient) Connection() *grpc.ClientConn {
   174  	return c.internalClient.Connection()
   175  }
   176  
   177  // EvaluateInstances evaluates instances based on a given metric.
   178  func (c *EvaluationClient) EvaluateInstances(ctx context.Context, req *aiplatformpb.EvaluateInstancesRequest, opts ...gax.CallOption) (*aiplatformpb.EvaluateInstancesResponse, error) {
   179  	return c.internalClient.EvaluateInstances(ctx, req, opts...)
   180  }
   181  
   182  // EvaluateDataset evaluates a dataset based on a set of given metrics.
   183  func (c *EvaluationClient) EvaluateDataset(ctx context.Context, req *aiplatformpb.EvaluateDatasetRequest, opts ...gax.CallOption) (*EvaluateDatasetOperation, error) {
   184  	return c.internalClient.EvaluateDataset(ctx, req, opts...)
   185  }
   186  
   187  // EvaluateDatasetOperation returns a new EvaluateDatasetOperation from a given name.
   188  // The name must be that of a previously created EvaluateDatasetOperation, possibly from a different process.
   189  func (c *EvaluationClient) EvaluateDatasetOperation(name string) *EvaluateDatasetOperation {
   190  	return c.internalClient.EvaluateDatasetOperation(name)
   191  }
   192  
   193  // GetLocation gets information about a location.
   194  func (c *EvaluationClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
   195  	return c.internalClient.GetLocation(ctx, req, opts...)
   196  }
   197  
   198  // ListLocations lists information about the supported locations for this service.
   199  func (c *EvaluationClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
   200  	return c.internalClient.ListLocations(ctx, req, opts...)
   201  }
   202  
   203  // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
   204  // if the resource exists and does not have a policy set.
   205  func (c *EvaluationClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   206  	return c.internalClient.GetIamPolicy(ctx, req, opts...)
   207  }
   208  
   209  // SetIamPolicy sets the access control policy on the specified resource. Replaces
   210  // any existing policy.
   211  //
   212  // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
   213  // errors.
   214  func (c *EvaluationClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   215  	return c.internalClient.SetIamPolicy(ctx, req, opts...)
   216  }
   217  
   218  // TestIamPermissions returns permissions that a caller has on the specified resource. If the
   219  // resource does not exist, this will return an empty set of
   220  // permissions, not a NOT_FOUND error.
   221  //
   222  // Note: This operation is designed to be used for building
   223  // permission-aware UIs and command-line tools, not for authorization
   224  // checking. This operation may “fail open” without warning.
   225  func (c *EvaluationClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   226  	return c.internalClient.TestIamPermissions(ctx, req, opts...)
   227  }
   228  
   229  // CancelOperation is a utility method from google.longrunning.Operations.
   230  func (c *EvaluationClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
   231  	return c.internalClient.CancelOperation(ctx, req, opts...)
   232  }
   233  
   234  // DeleteOperation is a utility method from google.longrunning.Operations.
   235  func (c *EvaluationClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
   236  	return c.internalClient.DeleteOperation(ctx, req, opts...)
   237  }
   238  
   239  // GetOperation is a utility method from google.longrunning.Operations.
   240  func (c *EvaluationClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   241  	return c.internalClient.GetOperation(ctx, req, opts...)
   242  }
   243  
   244  // ListOperations is a utility method from google.longrunning.Operations.
   245  func (c *EvaluationClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
   246  	return c.internalClient.ListOperations(ctx, req, opts...)
   247  }
   248  
   249  // WaitOperation is a utility method from google.longrunning.Operations.
   250  func (c *EvaluationClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   251  	return c.internalClient.WaitOperation(ctx, req, opts...)
   252  }
   253  
   254  // evaluationGRPCClient is a client for interacting with Vertex AI API over gRPC transport.
   255  //
   256  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   257  type evaluationGRPCClient struct {
   258  	// Connection pool of gRPC connections to the service.
   259  	connPool gtransport.ConnPool
   260  
   261  	// Points back to the CallOptions field of the containing EvaluationClient
   262  	CallOptions **EvaluationCallOptions
   263  
   264  	// The gRPC API client.
   265  	evaluationClient aiplatformpb.EvaluationServiceClient
   266  
   267  	// LROClient is used internally to handle long-running operations.
   268  	// It is exposed so that its CallOptions can be modified if required.
   269  	// Users should not Close this client.
   270  	LROClient **lroauto.OperationsClient
   271  
   272  	operationsClient longrunningpb.OperationsClient
   273  
   274  	iamPolicyClient iampb.IAMPolicyClient
   275  
   276  	locationsClient locationpb.LocationsClient
   277  
   278  	// The x-goog-* metadata to be sent with each request.
   279  	xGoogHeaders []string
   280  
   281  	logger *slog.Logger
   282  }
   283  
   284  // NewEvaluationClient creates a new evaluation service client based on gRPC.
   285  // The returned client must be Closed when it is done being used to clean up its underlying connections.
   286  //
   287  // Vertex AI Online Evaluation Service.
   288  func NewEvaluationClient(ctx context.Context, opts ...option.ClientOption) (*EvaluationClient, error) {
   289  	clientOpts := defaultEvaluationGRPCClientOptions()
   290  	if newEvaluationClientHook != nil {
   291  		hookOpts, err := newEvaluationClientHook(ctx, clientHookParams{})
   292  		if err != nil {
   293  			return nil, err
   294  		}
   295  		clientOpts = append(clientOpts, hookOpts...)
   296  	}
   297  
   298  	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
   299  	if err != nil {
   300  		return nil, err
   301  	}
   302  	client := EvaluationClient{CallOptions: defaultEvaluationCallOptions()}
   303  
   304  	c := &evaluationGRPCClient{
   305  		connPool:         connPool,
   306  		evaluationClient: aiplatformpb.NewEvaluationServiceClient(connPool),
   307  		CallOptions:      &client.CallOptions,
   308  		logger:           internaloption.GetLogger(opts),
   309  		operationsClient: longrunningpb.NewOperationsClient(connPool),
   310  		iamPolicyClient:  iampb.NewIAMPolicyClient(connPool),
   311  		locationsClient:  locationpb.NewLocationsClient(connPool),
   312  	}
   313  	c.setGoogleClientInfo()
   314  
   315  	client.internalClient = c
   316  
   317  	client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
   318  	if err != nil {
   319  		// This error "should not happen", since we are just reusing old connection pool
   320  		// and never actually need to dial.
   321  		// If this does happen, we could leak connp. However, we cannot close conn:
   322  		// If the user invoked the constructor with option.WithGRPCConn,
   323  		// we would close a connection that's still in use.
   324  		// TODO: investigate error conditions.
   325  		return nil, err
   326  	}
   327  	c.LROClient = &client.LROClient
   328  	return &client, nil
   329  }
   330  
   331  // Connection returns a connection to the API service.
   332  //
   333  // Deprecated: Connections are now pooled so this method does not always
   334  // return the same resource.
   335  func (c *evaluationGRPCClient) Connection() *grpc.ClientConn {
   336  	return c.connPool.Conn()
   337  }
   338  
   339  // setGoogleClientInfo sets the name and version of the application in
   340  // the `x-goog-api-client` header passed on each request. Intended for
   341  // use by Google-written clients.
   342  func (c *evaluationGRPCClient) setGoogleClientInfo(keyval ...string) {
   343  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   344  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
   345  	c.xGoogHeaders = []string{
   346  		"x-goog-api-client", gax.XGoogHeader(kv...),
   347  	}
   348  }
   349  
   350  // Close closes the connection to the API service. The user should invoke this when
   351  // the client is no longer required.
   352  func (c *evaluationGRPCClient) Close() error {
   353  	return c.connPool.Close()
   354  }
   355  
   356  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   357  type evaluationRESTClient struct {
   358  	// The http endpoint to connect to.
   359  	endpoint string
   360  
   361  	// The http client.
   362  	httpClient *http.Client
   363  
   364  	// LROClient is used internally to handle long-running operations.
   365  	// It is exposed so that its CallOptions can be modified if required.
   366  	// Users should not Close this client.
   367  	LROClient **lroauto.OperationsClient
   368  
   369  	// The x-goog-* headers to be sent with each request.
   370  	xGoogHeaders []string
   371  
   372  	// Points back to the CallOptions field of the containing EvaluationClient
   373  	CallOptions **EvaluationCallOptions
   374  
   375  	logger *slog.Logger
   376  }
   377  
   378  // NewEvaluationRESTClient creates a new evaluation service rest client.
   379  //
   380  // Vertex AI Online Evaluation Service.
   381  func NewEvaluationRESTClient(ctx context.Context, opts ...option.ClientOption) (*EvaluationClient, error) {
   382  	clientOpts := append(defaultEvaluationRESTClientOptions(), opts...)
   383  	httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
   384  	if err != nil {
   385  		return nil, err
   386  	}
   387  
   388  	callOpts := defaultEvaluationRESTCallOptions()
   389  	c := &evaluationRESTClient{
   390  		endpoint:    endpoint,
   391  		httpClient:  httpClient,
   392  		CallOptions: &callOpts,
   393  		logger:      internaloption.GetLogger(opts),
   394  	}
   395  	c.setGoogleClientInfo()
   396  
   397  	lroOpts := []option.ClientOption{
   398  		option.WithHTTPClient(httpClient),
   399  		option.WithEndpoint(endpoint),
   400  	}
   401  	opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...)
   402  	if err != nil {
   403  		return nil, err
   404  	}
   405  	c.LROClient = &opClient
   406  
   407  	return &EvaluationClient{internalClient: c, CallOptions: callOpts}, nil
   408  }
   409  
   410  func defaultEvaluationRESTClientOptions() []option.ClientOption {
   411  	return []option.ClientOption{
   412  		internaloption.WithDefaultEndpoint("https://aiplatform.googleapis.com"),
   413  		internaloption.WithDefaultEndpointTemplate("https://aiplatform.UNIVERSE_DOMAIN"),
   414  		internaloption.WithDefaultMTLSEndpoint("https://aiplatform.mtls.googleapis.com"),
   415  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
   416  		internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"),
   417  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
   418  		internaloption.EnableNewAuthLibrary(),
   419  	}
   420  }
   421  
   422  // setGoogleClientInfo sets the name and version of the application in
   423  // the `x-goog-api-client` header passed on each request. Intended for
   424  // use by Google-written clients.
   425  func (c *evaluationRESTClient) setGoogleClientInfo(keyval ...string) {
   426  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   427  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
   428  	c.xGoogHeaders = []string{
   429  		"x-goog-api-client", gax.XGoogHeader(kv...),
   430  	}
   431  }
   432  
   433  // Close closes the connection to the API service. The user should invoke this when
   434  // the client is no longer required.
   435  func (c *evaluationRESTClient) Close() error {
   436  	// Replace httpClient with nil to force cleanup.
   437  	c.httpClient = nil
   438  	return nil
   439  }
   440  
   441  // Connection returns a connection to the API service.
   442  //
   443  // Deprecated: This method always returns nil.
   444  func (c *evaluationRESTClient) Connection() *grpc.ClientConn {
   445  	return nil
   446  }
   447  func (c *evaluationGRPCClient) EvaluateInstances(ctx context.Context, req *aiplatformpb.EvaluateInstancesRequest, opts ...gax.CallOption) (*aiplatformpb.EvaluateInstancesResponse, error) {
   448  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "location", url.QueryEscape(req.GetLocation()))}
   449  
   450  	hds = append(c.xGoogHeaders, hds...)
   451  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   452  	opts = append((*c.CallOptions).EvaluateInstances[0:len((*c.CallOptions).EvaluateInstances):len((*c.CallOptions).EvaluateInstances)], opts...)
   453  	var resp *aiplatformpb.EvaluateInstancesResponse
   454  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   455  		var err error
   456  		resp, err = executeRPC(ctx, c.evaluationClient.EvaluateInstances, req, settings.GRPC, c.logger, "EvaluateInstances")
   457  		return err
   458  	}, opts...)
   459  	if err != nil {
   460  		return nil, err
   461  	}
   462  	return resp, nil
   463  }
   464  
   465  func (c *evaluationGRPCClient) EvaluateDataset(ctx context.Context, req *aiplatformpb.EvaluateDatasetRequest, opts ...gax.CallOption) (*EvaluateDatasetOperation, error) {
   466  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "location", url.QueryEscape(req.GetLocation()))}
   467  
   468  	hds = append(c.xGoogHeaders, hds...)
   469  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   470  	opts = append((*c.CallOptions).EvaluateDataset[0:len((*c.CallOptions).EvaluateDataset):len((*c.CallOptions).EvaluateDataset)], opts...)
   471  	var resp *longrunningpb.Operation
   472  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   473  		var err error
   474  		resp, err = executeRPC(ctx, c.evaluationClient.EvaluateDataset, req, settings.GRPC, c.logger, "EvaluateDataset")
   475  		return err
   476  	}, opts...)
   477  	if err != nil {
   478  		return nil, err
   479  	}
   480  	return &EvaluateDatasetOperation{
   481  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   482  	}, nil
   483  }
   484  
   485  func (c *evaluationGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
   486  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   487  
   488  	hds = append(c.xGoogHeaders, hds...)
   489  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   490  	opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
   491  	var resp *locationpb.Location
   492  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   493  		var err error
   494  		resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation")
   495  		return err
   496  	}, opts...)
   497  	if err != nil {
   498  		return nil, err
   499  	}
   500  	return resp, nil
   501  }
   502  
   503  func (c *evaluationGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
   504  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   505  
   506  	hds = append(c.xGoogHeaders, hds...)
   507  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   508  	opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...)
   509  	it := &LocationIterator{}
   510  	req = proto.Clone(req).(*locationpb.ListLocationsRequest)
   511  	it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
   512  		resp := &locationpb.ListLocationsResponse{}
   513  		if pageToken != "" {
   514  			req.PageToken = pageToken
   515  		}
   516  		if pageSize > math.MaxInt32 {
   517  			req.PageSize = math.MaxInt32
   518  		} else if pageSize != 0 {
   519  			req.PageSize = int32(pageSize)
   520  		}
   521  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   522  			var err error
   523  			resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations")
   524  			return err
   525  		}, opts...)
   526  		if err != nil {
   527  			return nil, "", err
   528  		}
   529  
   530  		it.Response = resp
   531  		return resp.GetLocations(), resp.GetNextPageToken(), nil
   532  	}
   533  	fetch := func(pageSize int, pageToken string) (string, error) {
   534  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   535  		if err != nil {
   536  			return "", err
   537  		}
   538  		it.items = append(it.items, items...)
   539  		return nextPageToken, nil
   540  	}
   541  
   542  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   543  	it.pageInfo.MaxSize = int(req.GetPageSize())
   544  	it.pageInfo.Token = req.GetPageToken()
   545  
   546  	return it
   547  }
   548  
   549  func (c *evaluationGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   550  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   551  
   552  	hds = append(c.xGoogHeaders, hds...)
   553  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   554  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
   555  	var resp *iampb.Policy
   556  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   557  		var err error
   558  		resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy")
   559  		return err
   560  	}, opts...)
   561  	if err != nil {
   562  		return nil, err
   563  	}
   564  	return resp, nil
   565  }
   566  
   567  func (c *evaluationGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   568  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   569  
   570  	hds = append(c.xGoogHeaders, hds...)
   571  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   572  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
   573  	var resp *iampb.Policy
   574  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   575  		var err error
   576  		resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy")
   577  		return err
   578  	}, opts...)
   579  	if err != nil {
   580  		return nil, err
   581  	}
   582  	return resp, nil
   583  }
   584  
   585  func (c *evaluationGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   586  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   587  
   588  	hds = append(c.xGoogHeaders, hds...)
   589  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   590  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
   591  	var resp *iampb.TestIamPermissionsResponse
   592  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   593  		var err error
   594  		resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions")
   595  		return err
   596  	}, opts...)
   597  	if err != nil {
   598  		return nil, err
   599  	}
   600  	return resp, nil
   601  }
   602  
   603  func (c *evaluationGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
   604  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   605  
   606  	hds = append(c.xGoogHeaders, hds...)
   607  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   608  	opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
   609  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   610  		var err error
   611  		_, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation")
   612  		return err
   613  	}, opts...)
   614  	return err
   615  }
   616  
   617  func (c *evaluationGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
   618  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   619  
   620  	hds = append(c.xGoogHeaders, hds...)
   621  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   622  	opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...)
   623  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   624  		var err error
   625  		_, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation")
   626  		return err
   627  	}, opts...)
   628  	return err
   629  }
   630  
   631  func (c *evaluationGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   632  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   633  
   634  	hds = append(c.xGoogHeaders, hds...)
   635  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   636  	opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
   637  	var resp *longrunningpb.Operation
   638  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   639  		var err error
   640  		resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
   641  		return err
   642  	}, opts...)
   643  	if err != nil {
   644  		return nil, err
   645  	}
   646  	return resp, nil
   647  }
   648  
   649  func (c *evaluationGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
   650  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   651  
   652  	hds = append(c.xGoogHeaders, hds...)
   653  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   654  	opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
   655  	it := &OperationIterator{}
   656  	req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
   657  	it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
   658  		resp := &longrunningpb.ListOperationsResponse{}
   659  		if pageToken != "" {
   660  			req.PageToken = pageToken
   661  		}
   662  		if pageSize > math.MaxInt32 {
   663  			req.PageSize = math.MaxInt32
   664  		} else if pageSize != 0 {
   665  			req.PageSize = int32(pageSize)
   666  		}
   667  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   668  			var err error
   669  			resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations")
   670  			return err
   671  		}, opts...)
   672  		if err != nil {
   673  			return nil, "", err
   674  		}
   675  
   676  		it.Response = resp
   677  		return resp.GetOperations(), resp.GetNextPageToken(), nil
   678  	}
   679  	fetch := func(pageSize int, pageToken string) (string, error) {
   680  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   681  		if err != nil {
   682  			return "", err
   683  		}
   684  		it.items = append(it.items, items...)
   685  		return nextPageToken, nil
   686  	}
   687  
   688  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   689  	it.pageInfo.MaxSize = int(req.GetPageSize())
   690  	it.pageInfo.Token = req.GetPageToken()
   691  
   692  	return it
   693  }
   694  
   695  func (c *evaluationGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   696  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   697  
   698  	hds = append(c.xGoogHeaders, hds...)
   699  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   700  	opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...)
   701  	var resp *longrunningpb.Operation
   702  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   703  		var err error
   704  		resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation")
   705  		return err
   706  	}, opts...)
   707  	if err != nil {
   708  		return nil, err
   709  	}
   710  	return resp, nil
   711  }
   712  
   713  // EvaluateInstances evaluates instances based on a given metric.
   714  func (c *evaluationRESTClient) EvaluateInstances(ctx context.Context, req *aiplatformpb.EvaluateInstancesRequest, opts ...gax.CallOption) (*aiplatformpb.EvaluateInstancesResponse, error) {
   715  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   716  	jsonReq, err := m.Marshal(req)
   717  	if err != nil {
   718  		return nil, err
   719  	}
   720  
   721  	baseUrl, err := url.Parse(c.endpoint)
   722  	if err != nil {
   723  		return nil, err
   724  	}
   725  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:evaluateInstances", req.GetLocation())
   726  
   727  	params := url.Values{}
   728  	params.Add("$alt", "json;enum-encoding=int")
   729  
   730  	baseUrl.RawQuery = params.Encode()
   731  
   732  	// Build HTTP headers from client and context metadata.
   733  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "location", url.QueryEscape(req.GetLocation()))}
   734  
   735  	hds = append(c.xGoogHeaders, hds...)
   736  	hds = append(hds, "Content-Type", "application/json")
   737  	headers := gax.BuildHeaders(ctx, hds...)
   738  	opts = append((*c.CallOptions).EvaluateInstances[0:len((*c.CallOptions).EvaluateInstances):len((*c.CallOptions).EvaluateInstances)], opts...)
   739  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   740  	resp := &aiplatformpb.EvaluateInstancesResponse{}
   741  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   742  		if settings.Path != "" {
   743  			baseUrl.Path = settings.Path
   744  		}
   745  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
   746  		if err != nil {
   747  			return err
   748  		}
   749  		httpReq = httpReq.WithContext(ctx)
   750  		httpReq.Header = headers
   751  
   752  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "EvaluateInstances")
   753  		if err != nil {
   754  			return err
   755  		}
   756  
   757  		if err := unm.Unmarshal(buf, resp); err != nil {
   758  			return err
   759  		}
   760  
   761  		return nil
   762  	}, opts...)
   763  	if e != nil {
   764  		return nil, e
   765  	}
   766  	return resp, nil
   767  }
   768  
   769  // EvaluateDataset evaluates a dataset based on a set of given metrics.
   770  func (c *evaluationRESTClient) EvaluateDataset(ctx context.Context, req *aiplatformpb.EvaluateDatasetRequest, opts ...gax.CallOption) (*EvaluateDatasetOperation, error) {
   771  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   772  	jsonReq, err := m.Marshal(req)
   773  	if err != nil {
   774  		return nil, err
   775  	}
   776  
   777  	baseUrl, err := url.Parse(c.endpoint)
   778  	if err != nil {
   779  		return nil, err
   780  	}
   781  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:evaluateDataset", req.GetLocation())
   782  
   783  	params := url.Values{}
   784  	params.Add("$alt", "json;enum-encoding=int")
   785  
   786  	baseUrl.RawQuery = params.Encode()
   787  
   788  	// Build HTTP headers from client and context metadata.
   789  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "location", url.QueryEscape(req.GetLocation()))}
   790  
   791  	hds = append(c.xGoogHeaders, hds...)
   792  	hds = append(hds, "Content-Type", "application/json")
   793  	headers := gax.BuildHeaders(ctx, hds...)
   794  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   795  	resp := &longrunningpb.Operation{}
   796  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   797  		if settings.Path != "" {
   798  			baseUrl.Path = settings.Path
   799  		}
   800  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
   801  		if err != nil {
   802  			return err
   803  		}
   804  		httpReq = httpReq.WithContext(ctx)
   805  		httpReq.Header = headers
   806  
   807  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "EvaluateDataset")
   808  		if err != nil {
   809  			return err
   810  		}
   811  		if err := unm.Unmarshal(buf, resp); err != nil {
   812  			return err
   813  		}
   814  
   815  		return nil
   816  	}, opts...)
   817  	if e != nil {
   818  		return nil, e
   819  	}
   820  
   821  	override := fmt.Sprintf("/ui/%s", resp.GetName())
   822  	return &EvaluateDatasetOperation{
   823  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
   824  		pollPath: override,
   825  	}, nil
   826  }
   827  
   828  // GetLocation gets information about a location.
   829  func (c *evaluationRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
   830  	baseUrl, err := url.Parse(c.endpoint)
   831  	if err != nil {
   832  		return nil, err
   833  	}
   834  	baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName())
   835  
   836  	params := url.Values{}
   837  	params.Add("$alt", "json;enum-encoding=int")
   838  
   839  	baseUrl.RawQuery = params.Encode()
   840  
   841  	// Build HTTP headers from client and context metadata.
   842  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   843  
   844  	hds = append(c.xGoogHeaders, hds...)
   845  	hds = append(hds, "Content-Type", "application/json")
   846  	headers := gax.BuildHeaders(ctx, hds...)
   847  	opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
   848  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   849  	resp := &locationpb.Location{}
   850  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   851  		if settings.Path != "" {
   852  			baseUrl.Path = settings.Path
   853  		}
   854  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
   855  		if err != nil {
   856  			return err
   857  		}
   858  		httpReq = httpReq.WithContext(ctx)
   859  		httpReq.Header = headers
   860  
   861  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation")
   862  		if err != nil {
   863  			return err
   864  		}
   865  
   866  		if err := unm.Unmarshal(buf, resp); err != nil {
   867  			return err
   868  		}
   869  
   870  		return nil
   871  	}, opts...)
   872  	if e != nil {
   873  		return nil, e
   874  	}
   875  	return resp, nil
   876  }
   877  
   878  // ListLocations lists information about the supported locations for this service.
   879  func (c *evaluationRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
   880  	it := &LocationIterator{}
   881  	req = proto.Clone(req).(*locationpb.ListLocationsRequest)
   882  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   883  	it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
   884  		resp := &locationpb.ListLocationsResponse{}
   885  		if pageToken != "" {
   886  			req.PageToken = pageToken
   887  		}
   888  		if pageSize > math.MaxInt32 {
   889  			req.PageSize = math.MaxInt32
   890  		} else if pageSize != 0 {
   891  			req.PageSize = int32(pageSize)
   892  		}
   893  		baseUrl, err := url.Parse(c.endpoint)
   894  		if err != nil {
   895  			return nil, "", err
   896  		}
   897  		baseUrl.Path += fmt.Sprintf("/ui/%v/locations", req.GetName())
   898  
   899  		params := url.Values{}
   900  		params.Add("$alt", "json;enum-encoding=int")
   901  		if req.GetFilter() != "" {
   902  			params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
   903  		}
   904  		if req.GetPageSize() != 0 {
   905  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
   906  		}
   907  		if req.GetPageToken() != "" {
   908  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
   909  		}
   910  
   911  		baseUrl.RawQuery = params.Encode()
   912  
   913  		// Build HTTP headers from client and context metadata.
   914  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
   915  		headers := gax.BuildHeaders(ctx, hds...)
   916  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   917  			if settings.Path != "" {
   918  				baseUrl.Path = settings.Path
   919  			}
   920  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
   921  			if err != nil {
   922  				return err
   923  			}
   924  			httpReq.Header = headers
   925  
   926  			buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations")
   927  			if err != nil {
   928  				return err
   929  			}
   930  			if err := unm.Unmarshal(buf, resp); err != nil {
   931  				return err
   932  			}
   933  
   934  			return nil
   935  		}, opts...)
   936  		if e != nil {
   937  			return nil, "", e
   938  		}
   939  		it.Response = resp
   940  		return resp.GetLocations(), resp.GetNextPageToken(), nil
   941  	}
   942  
   943  	fetch := func(pageSize int, pageToken string) (string, error) {
   944  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   945  		if err != nil {
   946  			return "", err
   947  		}
   948  		it.items = append(it.items, items...)
   949  		return nextPageToken, nil
   950  	}
   951  
   952  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   953  	it.pageInfo.MaxSize = int(req.GetPageSize())
   954  	it.pageInfo.Token = req.GetPageToken()
   955  
   956  	return it
   957  }
   958  
   959  // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
   960  // if the resource exists and does not have a policy set.
   961  func (c *evaluationRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   962  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   963  	jsonReq, err := m.Marshal(req)
   964  	if err != nil {
   965  		return nil, err
   966  	}
   967  
   968  	baseUrl, err := url.Parse(c.endpoint)
   969  	if err != nil {
   970  		return nil, err
   971  	}
   972  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:getIamPolicy", req.GetResource())
   973  
   974  	params := url.Values{}
   975  	params.Add("$alt", "json;enum-encoding=int")
   976  
   977  	baseUrl.RawQuery = params.Encode()
   978  
   979  	// Build HTTP headers from client and context metadata.
   980  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   981  
   982  	hds = append(c.xGoogHeaders, hds...)
   983  	hds = append(hds, "Content-Type", "application/json")
   984  	headers := gax.BuildHeaders(ctx, hds...)
   985  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
   986  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   987  	resp := &iampb.Policy{}
   988  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   989  		if settings.Path != "" {
   990  			baseUrl.Path = settings.Path
   991  		}
   992  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
   993  		if err != nil {
   994  			return err
   995  		}
   996  		httpReq = httpReq.WithContext(ctx)
   997  		httpReq.Header = headers
   998  
   999  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "GetIamPolicy")
  1000  		if err != nil {
  1001  			return err
  1002  		}
  1003  
  1004  		if err := unm.Unmarshal(buf, resp); err != nil {
  1005  			return err
  1006  		}
  1007  
  1008  		return nil
  1009  	}, opts...)
  1010  	if e != nil {
  1011  		return nil, e
  1012  	}
  1013  	return resp, nil
  1014  }
  1015  
  1016  // SetIamPolicy sets the access control policy on the specified resource. Replaces
  1017  // any existing policy.
  1018  //
  1019  // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
  1020  // errors.
  1021  func (c *evaluationRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
  1022  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1023  	jsonReq, err := m.Marshal(req)
  1024  	if err != nil {
  1025  		return nil, err
  1026  	}
  1027  
  1028  	baseUrl, err := url.Parse(c.endpoint)
  1029  	if err != nil {
  1030  		return nil, err
  1031  	}
  1032  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:setIamPolicy", req.GetResource())
  1033  
  1034  	params := url.Values{}
  1035  	params.Add("$alt", "json;enum-encoding=int")
  1036  
  1037  	baseUrl.RawQuery = params.Encode()
  1038  
  1039  	// Build HTTP headers from client and context metadata.
  1040  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1041  
  1042  	hds = append(c.xGoogHeaders, hds...)
  1043  	hds = append(hds, "Content-Type", "application/json")
  1044  	headers := gax.BuildHeaders(ctx, hds...)
  1045  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
  1046  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1047  	resp := &iampb.Policy{}
  1048  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1049  		if settings.Path != "" {
  1050  			baseUrl.Path = settings.Path
  1051  		}
  1052  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1053  		if err != nil {
  1054  			return err
  1055  		}
  1056  		httpReq = httpReq.WithContext(ctx)
  1057  		httpReq.Header = headers
  1058  
  1059  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy")
  1060  		if err != nil {
  1061  			return err
  1062  		}
  1063  
  1064  		if err := unm.Unmarshal(buf, resp); err != nil {
  1065  			return err
  1066  		}
  1067  
  1068  		return nil
  1069  	}, opts...)
  1070  	if e != nil {
  1071  		return nil, e
  1072  	}
  1073  	return resp, nil
  1074  }
  1075  
  1076  // TestIamPermissions returns permissions that a caller has on the specified resource. If the
  1077  // resource does not exist, this will return an empty set of
  1078  // permissions, not a NOT_FOUND error.
  1079  //
  1080  // Note: This operation is designed to be used for building
  1081  // permission-aware UIs and command-line tools, not for authorization
  1082  // checking. This operation may “fail open” without warning.
  1083  func (c *evaluationRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
  1084  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1085  	jsonReq, err := m.Marshal(req)
  1086  	if err != nil {
  1087  		return nil, err
  1088  	}
  1089  
  1090  	baseUrl, err := url.Parse(c.endpoint)
  1091  	if err != nil {
  1092  		return nil, err
  1093  	}
  1094  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:testIamPermissions", req.GetResource())
  1095  
  1096  	params := url.Values{}
  1097  	params.Add("$alt", "json;enum-encoding=int")
  1098  
  1099  	baseUrl.RawQuery = params.Encode()
  1100  
  1101  	// Build HTTP headers from client and context metadata.
  1102  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1103  
  1104  	hds = append(c.xGoogHeaders, hds...)
  1105  	hds = append(hds, "Content-Type", "application/json")
  1106  	headers := gax.BuildHeaders(ctx, hds...)
  1107  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
  1108  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1109  	resp := &iampb.TestIamPermissionsResponse{}
  1110  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1111  		if settings.Path != "" {
  1112  			baseUrl.Path = settings.Path
  1113  		}
  1114  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1115  		if err != nil {
  1116  			return err
  1117  		}
  1118  		httpReq = httpReq.WithContext(ctx)
  1119  		httpReq.Header = headers
  1120  
  1121  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TestIamPermissions")
  1122  		if err != nil {
  1123  			return err
  1124  		}
  1125  
  1126  		if err := unm.Unmarshal(buf, resp); err != nil {
  1127  			return err
  1128  		}
  1129  
  1130  		return nil
  1131  	}, opts...)
  1132  	if e != nil {
  1133  		return nil, e
  1134  	}
  1135  	return resp, nil
  1136  }
  1137  
  1138  // CancelOperation is a utility method from google.longrunning.Operations.
  1139  func (c *evaluationRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
  1140  	baseUrl, err := url.Parse(c.endpoint)
  1141  	if err != nil {
  1142  		return err
  1143  	}
  1144  	baseUrl.Path += fmt.Sprintf("/ui/%v:cancel", req.GetName())
  1145  
  1146  	params := url.Values{}
  1147  	params.Add("$alt", "json;enum-encoding=int")
  1148  
  1149  	baseUrl.RawQuery = params.Encode()
  1150  
  1151  	// Build HTTP headers from client and context metadata.
  1152  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1153  
  1154  	hds = append(c.xGoogHeaders, hds...)
  1155  	hds = append(hds, "Content-Type", "application/json")
  1156  	headers := gax.BuildHeaders(ctx, hds...)
  1157  	return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1158  		if settings.Path != "" {
  1159  			baseUrl.Path = settings.Path
  1160  		}
  1161  		httpReq, err := http.NewRequest("POST", baseUrl.String(), nil)
  1162  		if err != nil {
  1163  			return err
  1164  		}
  1165  		httpReq = httpReq.WithContext(ctx)
  1166  		httpReq.Header = headers
  1167  
  1168  		_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "CancelOperation")
  1169  		return err
  1170  	}, opts...)
  1171  }
  1172  
  1173  // DeleteOperation is a utility method from google.longrunning.Operations.
  1174  func (c *evaluationRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
  1175  	baseUrl, err := url.Parse(c.endpoint)
  1176  	if err != nil {
  1177  		return err
  1178  	}
  1179  	baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName())
  1180  
  1181  	params := url.Values{}
  1182  	params.Add("$alt", "json;enum-encoding=int")
  1183  
  1184  	baseUrl.RawQuery = params.Encode()
  1185  
  1186  	// Build HTTP headers from client and context metadata.
  1187  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1188  
  1189  	hds = append(c.xGoogHeaders, hds...)
  1190  	hds = append(hds, "Content-Type", "application/json")
  1191  	headers := gax.BuildHeaders(ctx, hds...)
  1192  	return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1193  		if settings.Path != "" {
  1194  			baseUrl.Path = settings.Path
  1195  		}
  1196  		httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
  1197  		if err != nil {
  1198  			return err
  1199  		}
  1200  		httpReq = httpReq.WithContext(ctx)
  1201  		httpReq.Header = headers
  1202  
  1203  		_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation")
  1204  		return err
  1205  	}, opts...)
  1206  }
  1207  
  1208  // GetOperation is a utility method from google.longrunning.Operations.
  1209  func (c *evaluationRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
  1210  	baseUrl, err := url.Parse(c.endpoint)
  1211  	if err != nil {
  1212  		return nil, err
  1213  	}
  1214  	baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName())
  1215  
  1216  	params := url.Values{}
  1217  	params.Add("$alt", "json;enum-encoding=int")
  1218  
  1219  	baseUrl.RawQuery = params.Encode()
  1220  
  1221  	// Build HTTP headers from client and context metadata.
  1222  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1223  
  1224  	hds = append(c.xGoogHeaders, hds...)
  1225  	hds = append(hds, "Content-Type", "application/json")
  1226  	headers := gax.BuildHeaders(ctx, hds...)
  1227  	opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
  1228  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1229  	resp := &longrunningpb.Operation{}
  1230  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1231  		if settings.Path != "" {
  1232  			baseUrl.Path = settings.Path
  1233  		}
  1234  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1235  		if err != nil {
  1236  			return err
  1237  		}
  1238  		httpReq = httpReq.WithContext(ctx)
  1239  		httpReq.Header = headers
  1240  
  1241  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
  1242  		if err != nil {
  1243  			return err
  1244  		}
  1245  
  1246  		if err := unm.Unmarshal(buf, resp); err != nil {
  1247  			return err
  1248  		}
  1249  
  1250  		return nil
  1251  	}, opts...)
  1252  	if e != nil {
  1253  		return nil, e
  1254  	}
  1255  	return resp, nil
  1256  }
  1257  
  1258  // ListOperations is a utility method from google.longrunning.Operations.
  1259  func (c *evaluationRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
  1260  	it := &OperationIterator{}
  1261  	req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
  1262  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1263  	it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
  1264  		resp := &longrunningpb.ListOperationsResponse{}
  1265  		if pageToken != "" {
  1266  			req.PageToken = pageToken
  1267  		}
  1268  		if pageSize > math.MaxInt32 {
  1269  			req.PageSize = math.MaxInt32
  1270  		} else if pageSize != 0 {
  1271  			req.PageSize = int32(pageSize)
  1272  		}
  1273  		baseUrl, err := url.Parse(c.endpoint)
  1274  		if err != nil {
  1275  			return nil, "", err
  1276  		}
  1277  		baseUrl.Path += fmt.Sprintf("/ui/%v/operations", req.GetName())
  1278  
  1279  		params := url.Values{}
  1280  		params.Add("$alt", "json;enum-encoding=int")
  1281  		if req.GetFilter() != "" {
  1282  			params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
  1283  		}
  1284  		if req.GetPageSize() != 0 {
  1285  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
  1286  		}
  1287  		if req.GetPageToken() != "" {
  1288  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
  1289  		}
  1290  
  1291  		baseUrl.RawQuery = params.Encode()
  1292  
  1293  		// Build HTTP headers from client and context metadata.
  1294  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  1295  		headers := gax.BuildHeaders(ctx, hds...)
  1296  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1297  			if settings.Path != "" {
  1298  				baseUrl.Path = settings.Path
  1299  			}
  1300  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1301  			if err != nil {
  1302  				return err
  1303  			}
  1304  			httpReq.Header = headers
  1305  
  1306  			buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations")
  1307  			if err != nil {
  1308  				return err
  1309  			}
  1310  			if err := unm.Unmarshal(buf, resp); err != nil {
  1311  				return err
  1312  			}
  1313  
  1314  			return nil
  1315  		}, opts...)
  1316  		if e != nil {
  1317  			return nil, "", e
  1318  		}
  1319  		it.Response = resp
  1320  		return resp.GetOperations(), resp.GetNextPageToken(), nil
  1321  	}
  1322  
  1323  	fetch := func(pageSize int, pageToken string) (string, error) {
  1324  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1325  		if err != nil {
  1326  			return "", err
  1327  		}
  1328  		it.items = append(it.items, items...)
  1329  		return nextPageToken, nil
  1330  	}
  1331  
  1332  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1333  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1334  	it.pageInfo.Token = req.GetPageToken()
  1335  
  1336  	return it
  1337  }
  1338  
  1339  // WaitOperation is a utility method from google.longrunning.Operations.
  1340  func (c *evaluationRESTClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
  1341  	baseUrl, err := url.Parse(c.endpoint)
  1342  	if err != nil {
  1343  		return nil, err
  1344  	}
  1345  	baseUrl.Path += fmt.Sprintf("/ui/%v:wait", req.GetName())
  1346  
  1347  	params := url.Values{}
  1348  	params.Add("$alt", "json;enum-encoding=int")
  1349  	if req.GetTimeout() != nil {
  1350  		field, err := protojson.Marshal(req.GetTimeout())
  1351  		if err != nil {
  1352  			return nil, err
  1353  		}
  1354  		params.Add("timeout", string(field[1:len(field)-1]))
  1355  	}
  1356  
  1357  	baseUrl.RawQuery = params.Encode()
  1358  
  1359  	// Build HTTP headers from client and context metadata.
  1360  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1361  
  1362  	hds = append(c.xGoogHeaders, hds...)
  1363  	hds = append(hds, "Content-Type", "application/json")
  1364  	headers := gax.BuildHeaders(ctx, hds...)
  1365  	opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...)
  1366  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1367  	resp := &longrunningpb.Operation{}
  1368  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1369  		if settings.Path != "" {
  1370  			baseUrl.Path = settings.Path
  1371  		}
  1372  		httpReq, err := http.NewRequest("POST", baseUrl.String(), nil)
  1373  		if err != nil {
  1374  			return err
  1375  		}
  1376  		httpReq = httpReq.WithContext(ctx)
  1377  		httpReq.Header = headers
  1378  
  1379  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "WaitOperation")
  1380  		if err != nil {
  1381  			return err
  1382  		}
  1383  
  1384  		if err := unm.Unmarshal(buf, resp); err != nil {
  1385  			return err
  1386  		}
  1387  
  1388  		return nil
  1389  	}, opts...)
  1390  	if e != nil {
  1391  		return nil, e
  1392  	}
  1393  	return resp, nil
  1394  }
  1395  
  1396  // EvaluateDatasetOperation returns a new EvaluateDatasetOperation from a given name.
  1397  // The name must be that of a previously created EvaluateDatasetOperation, possibly from a different process.
  1398  func (c *evaluationGRPCClient) EvaluateDatasetOperation(name string) *EvaluateDatasetOperation {
  1399  	return &EvaluateDatasetOperation{
  1400  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1401  	}
  1402  }
  1403  
  1404  // EvaluateDatasetOperation returns a new EvaluateDatasetOperation from a given name.
  1405  // The name must be that of a previously created EvaluateDatasetOperation, possibly from a different process.
  1406  func (c *evaluationRESTClient) EvaluateDatasetOperation(name string) *EvaluateDatasetOperation {
  1407  	override := fmt.Sprintf("/ui/%s", name)
  1408  	return &EvaluateDatasetOperation{
  1409  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1410  		pollPath: override,
  1411  	}
  1412  }