cloud.google.com/go/aiplatform@v1.106.0/apiv1/schedule_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 newScheduleClientHook clientHook
    42  
    43  // ScheduleCallOptions contains the retry settings for each method of ScheduleClient.
    44  type ScheduleCallOptions struct {
    45  	CreateSchedule     []gax.CallOption
    46  	DeleteSchedule     []gax.CallOption
    47  	GetSchedule        []gax.CallOption
    48  	ListSchedules      []gax.CallOption
    49  	PauseSchedule      []gax.CallOption
    50  	ResumeSchedule     []gax.CallOption
    51  	UpdateSchedule     []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 defaultScheduleGRPCClientOptions() []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 defaultScheduleCallOptions() *ScheduleCallOptions {
    80  	return &ScheduleCallOptions{
    81  		CreateSchedule:     []gax.CallOption{},
    82  		DeleteSchedule:     []gax.CallOption{},
    83  		GetSchedule:        []gax.CallOption{},
    84  		ListSchedules:      []gax.CallOption{},
    85  		PauseSchedule:      []gax.CallOption{},
    86  		ResumeSchedule:     []gax.CallOption{},
    87  		UpdateSchedule:     []gax.CallOption{},
    88  		GetLocation:        []gax.CallOption{},
    89  		ListLocations:      []gax.CallOption{},
    90  		GetIamPolicy:       []gax.CallOption{},
    91  		SetIamPolicy:       []gax.CallOption{},
    92  		TestIamPermissions: []gax.CallOption{},
    93  		CancelOperation:    []gax.CallOption{},
    94  		DeleteOperation:    []gax.CallOption{},
    95  		GetOperation:       []gax.CallOption{},
    96  		ListOperations:     []gax.CallOption{},
    97  		WaitOperation:      []gax.CallOption{},
    98  	}
    99  }
   100  
   101  // internalScheduleClient is an interface that defines the methods available from Vertex AI API.
   102  type internalScheduleClient interface {
   103  	Close() error
   104  	setGoogleClientInfo(...string)
   105  	Connection() *grpc.ClientConn
   106  	CreateSchedule(context.Context, *aiplatformpb.CreateScheduleRequest, ...gax.CallOption) (*aiplatformpb.Schedule, error)
   107  	DeleteSchedule(context.Context, *aiplatformpb.DeleteScheduleRequest, ...gax.CallOption) (*DeleteScheduleOperation, error)
   108  	DeleteScheduleOperation(name string) *DeleteScheduleOperation
   109  	GetSchedule(context.Context, *aiplatformpb.GetScheduleRequest, ...gax.CallOption) (*aiplatformpb.Schedule, error)
   110  	ListSchedules(context.Context, *aiplatformpb.ListSchedulesRequest, ...gax.CallOption) *ScheduleIterator
   111  	PauseSchedule(context.Context, *aiplatformpb.PauseScheduleRequest, ...gax.CallOption) error
   112  	ResumeSchedule(context.Context, *aiplatformpb.ResumeScheduleRequest, ...gax.CallOption) error
   113  	UpdateSchedule(context.Context, *aiplatformpb.UpdateScheduleRequest, ...gax.CallOption) (*aiplatformpb.Schedule, error)
   114  	GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error)
   115  	ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator
   116  	GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   117  	SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   118  	TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
   119  	CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
   120  	DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error
   121  	GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
   122  	ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
   123  	WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
   124  }
   125  
   126  // ScheduleClient is a client for interacting with Vertex AI API.
   127  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   128  //
   129  // A service for creating and managing Vertex AI’s Schedule resources to
   130  // periodically launch shceudled runs to make API calls.
   131  type ScheduleClient struct {
   132  	// The internal transport-dependent client.
   133  	internalClient internalScheduleClient
   134  
   135  	// The call options for this service.
   136  	CallOptions *ScheduleCallOptions
   137  
   138  	// LROClient is used internally to handle long-running operations.
   139  	// It is exposed so that its CallOptions can be modified if required.
   140  	// Users should not Close this client.
   141  	LROClient *lroauto.OperationsClient
   142  }
   143  
   144  // Wrapper methods routed to the internal client.
   145  
   146  // Close closes the connection to the API service. The user should invoke this when
   147  // the client is no longer required.
   148  func (c *ScheduleClient) Close() error {
   149  	return c.internalClient.Close()
   150  }
   151  
   152  // setGoogleClientInfo sets the name and version of the application in
   153  // the `x-goog-api-client` header passed on each request. Intended for
   154  // use by Google-written clients.
   155  func (c *ScheduleClient) setGoogleClientInfo(keyval ...string) {
   156  	c.internalClient.setGoogleClientInfo(keyval...)
   157  }
   158  
   159  // Connection returns a connection to the API service.
   160  //
   161  // Deprecated: Connections are now pooled so this method does not always
   162  // return the same resource.
   163  func (c *ScheduleClient) Connection() *grpc.ClientConn {
   164  	return c.internalClient.Connection()
   165  }
   166  
   167  // CreateSchedule creates a Schedule.
   168  func (c *ScheduleClient) CreateSchedule(ctx context.Context, req *aiplatformpb.CreateScheduleRequest, opts ...gax.CallOption) (*aiplatformpb.Schedule, error) {
   169  	return c.internalClient.CreateSchedule(ctx, req, opts...)
   170  }
   171  
   172  // DeleteSchedule deletes a Schedule.
   173  func (c *ScheduleClient) DeleteSchedule(ctx context.Context, req *aiplatformpb.DeleteScheduleRequest, opts ...gax.CallOption) (*DeleteScheduleOperation, error) {
   174  	return c.internalClient.DeleteSchedule(ctx, req, opts...)
   175  }
   176  
   177  // DeleteScheduleOperation returns a new DeleteScheduleOperation from a given name.
   178  // The name must be that of a previously created DeleteScheduleOperation, possibly from a different process.
   179  func (c *ScheduleClient) DeleteScheduleOperation(name string) *DeleteScheduleOperation {
   180  	return c.internalClient.DeleteScheduleOperation(name)
   181  }
   182  
   183  // GetSchedule gets a Schedule.
   184  func (c *ScheduleClient) GetSchedule(ctx context.Context, req *aiplatformpb.GetScheduleRequest, opts ...gax.CallOption) (*aiplatformpb.Schedule, error) {
   185  	return c.internalClient.GetSchedule(ctx, req, opts...)
   186  }
   187  
   188  // ListSchedules lists Schedules in a Location.
   189  func (c *ScheduleClient) ListSchedules(ctx context.Context, req *aiplatformpb.ListSchedulesRequest, opts ...gax.CallOption) *ScheduleIterator {
   190  	return c.internalClient.ListSchedules(ctx, req, opts...)
   191  }
   192  
   193  // PauseSchedule pauses a Schedule. Will mark
   194  // Schedule.state to ‘PAUSED’. If
   195  // the schedule is paused, no new runs will be created. Already created runs
   196  // will NOT be paused or canceled.
   197  func (c *ScheduleClient) PauseSchedule(ctx context.Context, req *aiplatformpb.PauseScheduleRequest, opts ...gax.CallOption) error {
   198  	return c.internalClient.PauseSchedule(ctx, req, opts...)
   199  }
   200  
   201  // ResumeSchedule resumes a paused Schedule to start scheduling new runs. Will mark
   202  // Schedule.state to ‘ACTIVE’.
   203  // Only paused Schedule can be resumed.
   204  //
   205  // When the Schedule is resumed, new runs will be scheduled starting from the
   206  // next execution time after the current time based on the time_specification
   207  // in the Schedule. If
   208  // Schedule.catch_up is set up
   209  // true, all missed runs will be scheduled for backfill first.
   210  func (c *ScheduleClient) ResumeSchedule(ctx context.Context, req *aiplatformpb.ResumeScheduleRequest, opts ...gax.CallOption) error {
   211  	return c.internalClient.ResumeSchedule(ctx, req, opts...)
   212  }
   213  
   214  // UpdateSchedule updates an active or paused Schedule.
   215  //
   216  // When the Schedule is updated, new runs will be scheduled starting from the
   217  // updated next execution time after the update time based on the
   218  // time_specification in the updated Schedule. All unstarted runs before the
   219  // update time will be skipped while already created runs will NOT be paused
   220  // or canceled.
   221  func (c *ScheduleClient) UpdateSchedule(ctx context.Context, req *aiplatformpb.UpdateScheduleRequest, opts ...gax.CallOption) (*aiplatformpb.Schedule, error) {
   222  	return c.internalClient.UpdateSchedule(ctx, req, opts...)
   223  }
   224  
   225  // GetLocation gets information about a location.
   226  func (c *ScheduleClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
   227  	return c.internalClient.GetLocation(ctx, req, opts...)
   228  }
   229  
   230  // ListLocations lists information about the supported locations for this service.
   231  func (c *ScheduleClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
   232  	return c.internalClient.ListLocations(ctx, req, opts...)
   233  }
   234  
   235  // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
   236  // if the resource exists and does not have a policy set.
   237  func (c *ScheduleClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   238  	return c.internalClient.GetIamPolicy(ctx, req, opts...)
   239  }
   240  
   241  // SetIamPolicy sets the access control policy on the specified resource. Replaces
   242  // any existing policy.
   243  //
   244  // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
   245  // errors.
   246  func (c *ScheduleClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   247  	return c.internalClient.SetIamPolicy(ctx, req, opts...)
   248  }
   249  
   250  // TestIamPermissions returns permissions that a caller has on the specified resource. If the
   251  // resource does not exist, this will return an empty set of
   252  // permissions, not a NOT_FOUND error.
   253  //
   254  // Note: This operation is designed to be used for building
   255  // permission-aware UIs and command-line tools, not for authorization
   256  // checking. This operation may “fail open” without warning.
   257  func (c *ScheduleClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   258  	return c.internalClient.TestIamPermissions(ctx, req, opts...)
   259  }
   260  
   261  // CancelOperation is a utility method from google.longrunning.Operations.
   262  func (c *ScheduleClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
   263  	return c.internalClient.CancelOperation(ctx, req, opts...)
   264  }
   265  
   266  // DeleteOperation is a utility method from google.longrunning.Operations.
   267  func (c *ScheduleClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
   268  	return c.internalClient.DeleteOperation(ctx, req, opts...)
   269  }
   270  
   271  // GetOperation is a utility method from google.longrunning.Operations.
   272  func (c *ScheduleClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   273  	return c.internalClient.GetOperation(ctx, req, opts...)
   274  }
   275  
   276  // ListOperations is a utility method from google.longrunning.Operations.
   277  func (c *ScheduleClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
   278  	return c.internalClient.ListOperations(ctx, req, opts...)
   279  }
   280  
   281  // WaitOperation is a utility method from google.longrunning.Operations.
   282  func (c *ScheduleClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   283  	return c.internalClient.WaitOperation(ctx, req, opts...)
   284  }
   285  
   286  // scheduleGRPCClient is a client for interacting with Vertex AI API over gRPC transport.
   287  //
   288  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   289  type scheduleGRPCClient struct {
   290  	// Connection pool of gRPC connections to the service.
   291  	connPool gtransport.ConnPool
   292  
   293  	// Points back to the CallOptions field of the containing ScheduleClient
   294  	CallOptions **ScheduleCallOptions
   295  
   296  	// The gRPC API client.
   297  	scheduleClient aiplatformpb.ScheduleServiceClient
   298  
   299  	// LROClient is used internally to handle long-running operations.
   300  	// It is exposed so that its CallOptions can be modified if required.
   301  	// Users should not Close this client.
   302  	LROClient **lroauto.OperationsClient
   303  
   304  	operationsClient longrunningpb.OperationsClient
   305  
   306  	iamPolicyClient iampb.IAMPolicyClient
   307  
   308  	locationsClient locationpb.LocationsClient
   309  
   310  	// The x-goog-* metadata to be sent with each request.
   311  	xGoogHeaders []string
   312  
   313  	logger *slog.Logger
   314  }
   315  
   316  // NewScheduleClient creates a new schedule service client based on gRPC.
   317  // The returned client must be Closed when it is done being used to clean up its underlying connections.
   318  //
   319  // A service for creating and managing Vertex AI’s Schedule resources to
   320  // periodically launch shceudled runs to make API calls.
   321  func NewScheduleClient(ctx context.Context, opts ...option.ClientOption) (*ScheduleClient, error) {
   322  	clientOpts := defaultScheduleGRPCClientOptions()
   323  	if newScheduleClientHook != nil {
   324  		hookOpts, err := newScheduleClientHook(ctx, clientHookParams{})
   325  		if err != nil {
   326  			return nil, err
   327  		}
   328  		clientOpts = append(clientOpts, hookOpts...)
   329  	}
   330  
   331  	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
   332  	if err != nil {
   333  		return nil, err
   334  	}
   335  	client := ScheduleClient{CallOptions: defaultScheduleCallOptions()}
   336  
   337  	c := &scheduleGRPCClient{
   338  		connPool:         connPool,
   339  		scheduleClient:   aiplatformpb.NewScheduleServiceClient(connPool),
   340  		CallOptions:      &client.CallOptions,
   341  		logger:           internaloption.GetLogger(opts),
   342  		operationsClient: longrunningpb.NewOperationsClient(connPool),
   343  		iamPolicyClient:  iampb.NewIAMPolicyClient(connPool),
   344  		locationsClient:  locationpb.NewLocationsClient(connPool),
   345  	}
   346  	c.setGoogleClientInfo()
   347  
   348  	client.internalClient = c
   349  
   350  	client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
   351  	if err != nil {
   352  		// This error "should not happen", since we are just reusing old connection pool
   353  		// and never actually need to dial.
   354  		// If this does happen, we could leak connp. However, we cannot close conn:
   355  		// If the user invoked the constructor with option.WithGRPCConn,
   356  		// we would close a connection that's still in use.
   357  		// TODO: investigate error conditions.
   358  		return nil, err
   359  	}
   360  	c.LROClient = &client.LROClient
   361  	return &client, nil
   362  }
   363  
   364  // Connection returns a connection to the API service.
   365  //
   366  // Deprecated: Connections are now pooled so this method does not always
   367  // return the same resource.
   368  func (c *scheduleGRPCClient) Connection() *grpc.ClientConn {
   369  	return c.connPool.Conn()
   370  }
   371  
   372  // setGoogleClientInfo sets the name and version of the application in
   373  // the `x-goog-api-client` header passed on each request. Intended for
   374  // use by Google-written clients.
   375  func (c *scheduleGRPCClient) setGoogleClientInfo(keyval ...string) {
   376  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   377  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
   378  	c.xGoogHeaders = []string{
   379  		"x-goog-api-client", gax.XGoogHeader(kv...),
   380  	}
   381  }
   382  
   383  // Close closes the connection to the API service. The user should invoke this when
   384  // the client is no longer required.
   385  func (c *scheduleGRPCClient) Close() error {
   386  	return c.connPool.Close()
   387  }
   388  
   389  func (c *scheduleGRPCClient) CreateSchedule(ctx context.Context, req *aiplatformpb.CreateScheduleRequest, opts ...gax.CallOption) (*aiplatformpb.Schedule, error) {
   390  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   391  
   392  	hds = append(c.xGoogHeaders, hds...)
   393  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   394  	opts = append((*c.CallOptions).CreateSchedule[0:len((*c.CallOptions).CreateSchedule):len((*c.CallOptions).CreateSchedule)], opts...)
   395  	var resp *aiplatformpb.Schedule
   396  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   397  		var err error
   398  		resp, err = executeRPC(ctx, c.scheduleClient.CreateSchedule, req, settings.GRPC, c.logger, "CreateSchedule")
   399  		return err
   400  	}, opts...)
   401  	if err != nil {
   402  		return nil, err
   403  	}
   404  	return resp, nil
   405  }
   406  
   407  func (c *scheduleGRPCClient) DeleteSchedule(ctx context.Context, req *aiplatformpb.DeleteScheduleRequest, opts ...gax.CallOption) (*DeleteScheduleOperation, error) {
   408  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   409  
   410  	hds = append(c.xGoogHeaders, hds...)
   411  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   412  	opts = append((*c.CallOptions).DeleteSchedule[0:len((*c.CallOptions).DeleteSchedule):len((*c.CallOptions).DeleteSchedule)], opts...)
   413  	var resp *longrunningpb.Operation
   414  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   415  		var err error
   416  		resp, err = executeRPC(ctx, c.scheduleClient.DeleteSchedule, req, settings.GRPC, c.logger, "DeleteSchedule")
   417  		return err
   418  	}, opts...)
   419  	if err != nil {
   420  		return nil, err
   421  	}
   422  	return &DeleteScheduleOperation{
   423  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   424  	}, nil
   425  }
   426  
   427  func (c *scheduleGRPCClient) GetSchedule(ctx context.Context, req *aiplatformpb.GetScheduleRequest, opts ...gax.CallOption) (*aiplatformpb.Schedule, error) {
   428  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   429  
   430  	hds = append(c.xGoogHeaders, hds...)
   431  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   432  	opts = append((*c.CallOptions).GetSchedule[0:len((*c.CallOptions).GetSchedule):len((*c.CallOptions).GetSchedule)], opts...)
   433  	var resp *aiplatformpb.Schedule
   434  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   435  		var err error
   436  		resp, err = executeRPC(ctx, c.scheduleClient.GetSchedule, req, settings.GRPC, c.logger, "GetSchedule")
   437  		return err
   438  	}, opts...)
   439  	if err != nil {
   440  		return nil, err
   441  	}
   442  	return resp, nil
   443  }
   444  
   445  func (c *scheduleGRPCClient) ListSchedules(ctx context.Context, req *aiplatformpb.ListSchedulesRequest, opts ...gax.CallOption) *ScheduleIterator {
   446  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   447  
   448  	hds = append(c.xGoogHeaders, hds...)
   449  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   450  	opts = append((*c.CallOptions).ListSchedules[0:len((*c.CallOptions).ListSchedules):len((*c.CallOptions).ListSchedules)], opts...)
   451  	it := &ScheduleIterator{}
   452  	req = proto.Clone(req).(*aiplatformpb.ListSchedulesRequest)
   453  	it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.Schedule, string, error) {
   454  		resp := &aiplatformpb.ListSchedulesResponse{}
   455  		if pageToken != "" {
   456  			req.PageToken = pageToken
   457  		}
   458  		if pageSize > math.MaxInt32 {
   459  			req.PageSize = math.MaxInt32
   460  		} else if pageSize != 0 {
   461  			req.PageSize = int32(pageSize)
   462  		}
   463  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   464  			var err error
   465  			resp, err = executeRPC(ctx, c.scheduleClient.ListSchedules, req, settings.GRPC, c.logger, "ListSchedules")
   466  			return err
   467  		}, opts...)
   468  		if err != nil {
   469  			return nil, "", err
   470  		}
   471  
   472  		it.Response = resp
   473  		return resp.GetSchedules(), resp.GetNextPageToken(), nil
   474  	}
   475  	fetch := func(pageSize int, pageToken string) (string, error) {
   476  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   477  		if err != nil {
   478  			return "", err
   479  		}
   480  		it.items = append(it.items, items...)
   481  		return nextPageToken, nil
   482  	}
   483  
   484  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   485  	it.pageInfo.MaxSize = int(req.GetPageSize())
   486  	it.pageInfo.Token = req.GetPageToken()
   487  
   488  	return it
   489  }
   490  
   491  func (c *scheduleGRPCClient) PauseSchedule(ctx context.Context, req *aiplatformpb.PauseScheduleRequest, opts ...gax.CallOption) error {
   492  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   493  
   494  	hds = append(c.xGoogHeaders, hds...)
   495  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   496  	opts = append((*c.CallOptions).PauseSchedule[0:len((*c.CallOptions).PauseSchedule):len((*c.CallOptions).PauseSchedule)], opts...)
   497  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   498  		var err error
   499  		_, err = executeRPC(ctx, c.scheduleClient.PauseSchedule, req, settings.GRPC, c.logger, "PauseSchedule")
   500  		return err
   501  	}, opts...)
   502  	return err
   503  }
   504  
   505  func (c *scheduleGRPCClient) ResumeSchedule(ctx context.Context, req *aiplatformpb.ResumeScheduleRequest, opts ...gax.CallOption) error {
   506  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   507  
   508  	hds = append(c.xGoogHeaders, hds...)
   509  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   510  	opts = append((*c.CallOptions).ResumeSchedule[0:len((*c.CallOptions).ResumeSchedule):len((*c.CallOptions).ResumeSchedule)], opts...)
   511  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   512  		var err error
   513  		_, err = executeRPC(ctx, c.scheduleClient.ResumeSchedule, req, settings.GRPC, c.logger, "ResumeSchedule")
   514  		return err
   515  	}, opts...)
   516  	return err
   517  }
   518  
   519  func (c *scheduleGRPCClient) UpdateSchedule(ctx context.Context, req *aiplatformpb.UpdateScheduleRequest, opts ...gax.CallOption) (*aiplatformpb.Schedule, error) {
   520  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "schedule.name", url.QueryEscape(req.GetSchedule().GetName()))}
   521  
   522  	hds = append(c.xGoogHeaders, hds...)
   523  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   524  	opts = append((*c.CallOptions).UpdateSchedule[0:len((*c.CallOptions).UpdateSchedule):len((*c.CallOptions).UpdateSchedule)], opts...)
   525  	var resp *aiplatformpb.Schedule
   526  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   527  		var err error
   528  		resp, err = executeRPC(ctx, c.scheduleClient.UpdateSchedule, req, settings.GRPC, c.logger, "UpdateSchedule")
   529  		return err
   530  	}, opts...)
   531  	if err != nil {
   532  		return nil, err
   533  	}
   534  	return resp, nil
   535  }
   536  
   537  func (c *scheduleGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
   538  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   539  
   540  	hds = append(c.xGoogHeaders, hds...)
   541  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   542  	opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
   543  	var resp *locationpb.Location
   544  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   545  		var err error
   546  		resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation")
   547  		return err
   548  	}, opts...)
   549  	if err != nil {
   550  		return nil, err
   551  	}
   552  	return resp, nil
   553  }
   554  
   555  func (c *scheduleGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
   556  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   557  
   558  	hds = append(c.xGoogHeaders, hds...)
   559  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   560  	opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...)
   561  	it := &LocationIterator{}
   562  	req = proto.Clone(req).(*locationpb.ListLocationsRequest)
   563  	it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
   564  		resp := &locationpb.ListLocationsResponse{}
   565  		if pageToken != "" {
   566  			req.PageToken = pageToken
   567  		}
   568  		if pageSize > math.MaxInt32 {
   569  			req.PageSize = math.MaxInt32
   570  		} else if pageSize != 0 {
   571  			req.PageSize = int32(pageSize)
   572  		}
   573  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   574  			var err error
   575  			resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations")
   576  			return err
   577  		}, opts...)
   578  		if err != nil {
   579  			return nil, "", err
   580  		}
   581  
   582  		it.Response = resp
   583  		return resp.GetLocations(), resp.GetNextPageToken(), nil
   584  	}
   585  	fetch := func(pageSize int, pageToken string) (string, error) {
   586  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   587  		if err != nil {
   588  			return "", err
   589  		}
   590  		it.items = append(it.items, items...)
   591  		return nextPageToken, nil
   592  	}
   593  
   594  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   595  	it.pageInfo.MaxSize = int(req.GetPageSize())
   596  	it.pageInfo.Token = req.GetPageToken()
   597  
   598  	return it
   599  }
   600  
   601  func (c *scheduleGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   602  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   603  
   604  	hds = append(c.xGoogHeaders, hds...)
   605  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   606  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
   607  	var resp *iampb.Policy
   608  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   609  		var err error
   610  		resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy")
   611  		return err
   612  	}, opts...)
   613  	if err != nil {
   614  		return nil, err
   615  	}
   616  	return resp, nil
   617  }
   618  
   619  func (c *scheduleGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   620  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   621  
   622  	hds = append(c.xGoogHeaders, hds...)
   623  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   624  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
   625  	var resp *iampb.Policy
   626  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   627  		var err error
   628  		resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy")
   629  		return err
   630  	}, opts...)
   631  	if err != nil {
   632  		return nil, err
   633  	}
   634  	return resp, nil
   635  }
   636  
   637  func (c *scheduleGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   638  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   639  
   640  	hds = append(c.xGoogHeaders, hds...)
   641  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   642  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
   643  	var resp *iampb.TestIamPermissionsResponse
   644  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   645  		var err error
   646  		resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions")
   647  		return err
   648  	}, opts...)
   649  	if err != nil {
   650  		return nil, err
   651  	}
   652  	return resp, nil
   653  }
   654  
   655  func (c *scheduleGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
   656  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   657  
   658  	hds = append(c.xGoogHeaders, hds...)
   659  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   660  	opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
   661  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   662  		var err error
   663  		_, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation")
   664  		return err
   665  	}, opts...)
   666  	return err
   667  }
   668  
   669  func (c *scheduleGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
   670  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   671  
   672  	hds = append(c.xGoogHeaders, hds...)
   673  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   674  	opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...)
   675  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   676  		var err error
   677  		_, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation")
   678  		return err
   679  	}, opts...)
   680  	return err
   681  }
   682  
   683  func (c *scheduleGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   684  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   685  
   686  	hds = append(c.xGoogHeaders, hds...)
   687  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   688  	opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
   689  	var resp *longrunningpb.Operation
   690  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   691  		var err error
   692  		resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
   693  		return err
   694  	}, opts...)
   695  	if err != nil {
   696  		return nil, err
   697  	}
   698  	return resp, nil
   699  }
   700  
   701  func (c *scheduleGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
   702  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   703  
   704  	hds = append(c.xGoogHeaders, hds...)
   705  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   706  	opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
   707  	it := &OperationIterator{}
   708  	req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
   709  	it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
   710  		resp := &longrunningpb.ListOperationsResponse{}
   711  		if pageToken != "" {
   712  			req.PageToken = pageToken
   713  		}
   714  		if pageSize > math.MaxInt32 {
   715  			req.PageSize = math.MaxInt32
   716  		} else if pageSize != 0 {
   717  			req.PageSize = int32(pageSize)
   718  		}
   719  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   720  			var err error
   721  			resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations")
   722  			return err
   723  		}, opts...)
   724  		if err != nil {
   725  			return nil, "", err
   726  		}
   727  
   728  		it.Response = resp
   729  		return resp.GetOperations(), resp.GetNextPageToken(), nil
   730  	}
   731  	fetch := func(pageSize int, pageToken string) (string, error) {
   732  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   733  		if err != nil {
   734  			return "", err
   735  		}
   736  		it.items = append(it.items, items...)
   737  		return nextPageToken, nil
   738  	}
   739  
   740  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   741  	it.pageInfo.MaxSize = int(req.GetPageSize())
   742  	it.pageInfo.Token = req.GetPageToken()
   743  
   744  	return it
   745  }
   746  
   747  func (c *scheduleGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   748  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   749  
   750  	hds = append(c.xGoogHeaders, hds...)
   751  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   752  	opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...)
   753  	var resp *longrunningpb.Operation
   754  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   755  		var err error
   756  		resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation")
   757  		return err
   758  	}, opts...)
   759  	if err != nil {
   760  		return nil, err
   761  	}
   762  	return resp, nil
   763  }
   764  
   765  // DeleteScheduleOperation returns a new DeleteScheduleOperation from a given name.
   766  // The name must be that of a previously created DeleteScheduleOperation, possibly from a different process.
   767  func (c *scheduleGRPCClient) DeleteScheduleOperation(name string) *DeleteScheduleOperation {
   768  	return &DeleteScheduleOperation{
   769  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
   770  	}
   771  }