cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/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 "bytes" 21 "context" 22 "fmt" 23 "log/slog" 24 "math" 25 "net/http" 26 "net/url" 27 28 aiplatformpb "cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb" 29 iampb "cloud.google.com/go/iam/apiv1/iampb" 30 "cloud.google.com/go/longrunning" 31 lroauto "cloud.google.com/go/longrunning/autogen" 32 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" 33 gax "github.com/googleapis/gax-go/v2" 34 "google.golang.org/api/iterator" 35 "google.golang.org/api/option" 36 "google.golang.org/api/option/internaloption" 37 gtransport "google.golang.org/api/transport/grpc" 38 httptransport "google.golang.org/api/transport/http" 39 locationpb "google.golang.org/genproto/googleapis/cloud/location" 40 "google.golang.org/grpc" 41 "google.golang.org/protobuf/encoding/protojson" 42 "google.golang.org/protobuf/proto" 43 ) 44 45 var newScheduleClientHook clientHook 46 47 // ScheduleCallOptions contains the retry settings for each method of ScheduleClient. 48 type ScheduleCallOptions struct { 49 CreateSchedule []gax.CallOption 50 DeleteSchedule []gax.CallOption 51 GetSchedule []gax.CallOption 52 ListSchedules []gax.CallOption 53 PauseSchedule []gax.CallOption 54 ResumeSchedule []gax.CallOption 55 UpdateSchedule []gax.CallOption 56 GetLocation []gax.CallOption 57 ListLocations []gax.CallOption 58 GetIamPolicy []gax.CallOption 59 SetIamPolicy []gax.CallOption 60 TestIamPermissions []gax.CallOption 61 CancelOperation []gax.CallOption 62 DeleteOperation []gax.CallOption 63 GetOperation []gax.CallOption 64 ListOperations []gax.CallOption 65 WaitOperation []gax.CallOption 66 } 67 68 func defaultScheduleGRPCClientOptions() []option.ClientOption { 69 return []option.ClientOption{ 70 internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"), 71 internaloption.WithDefaultEndpointTemplate("aiplatform.UNIVERSE_DOMAIN:443"), 72 internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), 73 internaloption.WithDefaultUniverseDomain("googleapis.com"), 74 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 75 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 76 internaloption.EnableJwtWithScope(), 77 internaloption.EnableNewAuthLibrary(), 78 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 79 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 80 } 81 } 82 83 func defaultScheduleCallOptions() *ScheduleCallOptions { 84 return &ScheduleCallOptions{ 85 CreateSchedule: []gax.CallOption{}, 86 DeleteSchedule: []gax.CallOption{}, 87 GetSchedule: []gax.CallOption{}, 88 ListSchedules: []gax.CallOption{}, 89 PauseSchedule: []gax.CallOption{}, 90 ResumeSchedule: []gax.CallOption{}, 91 UpdateSchedule: []gax.CallOption{}, 92 GetLocation: []gax.CallOption{}, 93 ListLocations: []gax.CallOption{}, 94 GetIamPolicy: []gax.CallOption{}, 95 SetIamPolicy: []gax.CallOption{}, 96 TestIamPermissions: []gax.CallOption{}, 97 CancelOperation: []gax.CallOption{}, 98 DeleteOperation: []gax.CallOption{}, 99 GetOperation: []gax.CallOption{}, 100 ListOperations: []gax.CallOption{}, 101 WaitOperation: []gax.CallOption{}, 102 } 103 } 104 105 func defaultScheduleRESTCallOptions() *ScheduleCallOptions { 106 return &ScheduleCallOptions{ 107 CreateSchedule: []gax.CallOption{}, 108 DeleteSchedule: []gax.CallOption{}, 109 GetSchedule: []gax.CallOption{}, 110 ListSchedules: []gax.CallOption{}, 111 PauseSchedule: []gax.CallOption{}, 112 ResumeSchedule: []gax.CallOption{}, 113 UpdateSchedule: []gax.CallOption{}, 114 GetLocation: []gax.CallOption{}, 115 ListLocations: []gax.CallOption{}, 116 GetIamPolicy: []gax.CallOption{}, 117 SetIamPolicy: []gax.CallOption{}, 118 TestIamPermissions: []gax.CallOption{}, 119 CancelOperation: []gax.CallOption{}, 120 DeleteOperation: []gax.CallOption{}, 121 GetOperation: []gax.CallOption{}, 122 ListOperations: []gax.CallOption{}, 123 WaitOperation: []gax.CallOption{}, 124 } 125 } 126 127 // internalScheduleClient is an interface that defines the methods available from Vertex AI API. 128 type internalScheduleClient interface { 129 Close() error 130 setGoogleClientInfo(...string) 131 Connection() *grpc.ClientConn 132 CreateSchedule(context.Context, *aiplatformpb.CreateScheduleRequest, ...gax.CallOption) (*aiplatformpb.Schedule, error) 133 DeleteSchedule(context.Context, *aiplatformpb.DeleteScheduleRequest, ...gax.CallOption) (*DeleteScheduleOperation, error) 134 DeleteScheduleOperation(name string) *DeleteScheduleOperation 135 GetSchedule(context.Context, *aiplatformpb.GetScheduleRequest, ...gax.CallOption) (*aiplatformpb.Schedule, error) 136 ListSchedules(context.Context, *aiplatformpb.ListSchedulesRequest, ...gax.CallOption) *ScheduleIterator 137 PauseSchedule(context.Context, *aiplatformpb.PauseScheduleRequest, ...gax.CallOption) error 138 ResumeSchedule(context.Context, *aiplatformpb.ResumeScheduleRequest, ...gax.CallOption) error 139 UpdateSchedule(context.Context, *aiplatformpb.UpdateScheduleRequest, ...gax.CallOption) (*aiplatformpb.Schedule, error) 140 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error) 141 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator 142 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 143 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 144 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) 145 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error 146 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error 147 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 148 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator 149 WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 150 } 151 152 // ScheduleClient is a client for interacting with Vertex AI API. 153 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 154 // 155 // A service for creating and managing Vertex AI’s Schedule resources to 156 // periodically launch shceudled runs to make API calls. 157 type ScheduleClient struct { 158 // The internal transport-dependent client. 159 internalClient internalScheduleClient 160 161 // The call options for this service. 162 CallOptions *ScheduleCallOptions 163 164 // LROClient is used internally to handle long-running operations. 165 // It is exposed so that its CallOptions can be modified if required. 166 // Users should not Close this client. 167 LROClient *lroauto.OperationsClient 168 } 169 170 // Wrapper methods routed to the internal client. 171 172 // Close closes the connection to the API service. The user should invoke this when 173 // the client is no longer required. 174 func (c *ScheduleClient) Close() error { 175 return c.internalClient.Close() 176 } 177 178 // setGoogleClientInfo sets the name and version of the application in 179 // the `x-goog-api-client` header passed on each request. Intended for 180 // use by Google-written clients. 181 func (c *ScheduleClient) setGoogleClientInfo(keyval ...string) { 182 c.internalClient.setGoogleClientInfo(keyval...) 183 } 184 185 // Connection returns a connection to the API service. 186 // 187 // Deprecated: Connections are now pooled so this method does not always 188 // return the same resource. 189 func (c *ScheduleClient) Connection() *grpc.ClientConn { 190 return c.internalClient.Connection() 191 } 192 193 // CreateSchedule creates a Schedule. 194 func (c *ScheduleClient) CreateSchedule(ctx context.Context, req *aiplatformpb.CreateScheduleRequest, opts ...gax.CallOption) (*aiplatformpb.Schedule, error) { 195 return c.internalClient.CreateSchedule(ctx, req, opts...) 196 } 197 198 // DeleteSchedule deletes a Schedule. 199 func (c *ScheduleClient) DeleteSchedule(ctx context.Context, req *aiplatformpb.DeleteScheduleRequest, opts ...gax.CallOption) (*DeleteScheduleOperation, error) { 200 return c.internalClient.DeleteSchedule(ctx, req, opts...) 201 } 202 203 // DeleteScheduleOperation returns a new DeleteScheduleOperation from a given name. 204 // The name must be that of a previously created DeleteScheduleOperation, possibly from a different process. 205 func (c *ScheduleClient) DeleteScheduleOperation(name string) *DeleteScheduleOperation { 206 return c.internalClient.DeleteScheduleOperation(name) 207 } 208 209 // GetSchedule gets a Schedule. 210 func (c *ScheduleClient) GetSchedule(ctx context.Context, req *aiplatformpb.GetScheduleRequest, opts ...gax.CallOption) (*aiplatformpb.Schedule, error) { 211 return c.internalClient.GetSchedule(ctx, req, opts...) 212 } 213 214 // ListSchedules lists Schedules in a Location. 215 func (c *ScheduleClient) ListSchedules(ctx context.Context, req *aiplatformpb.ListSchedulesRequest, opts ...gax.CallOption) *ScheduleIterator { 216 return c.internalClient.ListSchedules(ctx, req, opts...) 217 } 218 219 // PauseSchedule pauses a Schedule. Will mark 220 // Schedule.state to 221 // ‘PAUSED’. If the schedule is paused, no new runs will be created. Already 222 // created runs will NOT be paused or canceled. 223 func (c *ScheduleClient) PauseSchedule(ctx context.Context, req *aiplatformpb.PauseScheduleRequest, opts ...gax.CallOption) error { 224 return c.internalClient.PauseSchedule(ctx, req, opts...) 225 } 226 227 // ResumeSchedule resumes a paused Schedule to start scheduling new runs. Will mark 228 // Schedule.state to 229 // ‘ACTIVE’. Only paused Schedule can be resumed. 230 // 231 // When the Schedule is resumed, new runs will be scheduled starting from the 232 // next execution time after the current time based on the time_specification 233 // in the Schedule. If Schedule.catchUp is set up true, all 234 // missed runs will be scheduled for backfill first. 235 func (c *ScheduleClient) ResumeSchedule(ctx context.Context, req *aiplatformpb.ResumeScheduleRequest, opts ...gax.CallOption) error { 236 return c.internalClient.ResumeSchedule(ctx, req, opts...) 237 } 238 239 // UpdateSchedule updates an active or paused Schedule. 240 // 241 // When the Schedule is updated, new runs will be scheduled starting from the 242 // updated next execution time after the update time based on the 243 // time_specification in the updated Schedule. All unstarted runs before the 244 // update time will be skipped while already created runs will NOT be paused 245 // or canceled. 246 func (c *ScheduleClient) UpdateSchedule(ctx context.Context, req *aiplatformpb.UpdateScheduleRequest, opts ...gax.CallOption) (*aiplatformpb.Schedule, error) { 247 return c.internalClient.UpdateSchedule(ctx, req, opts...) 248 } 249 250 // GetLocation gets information about a location. 251 func (c *ScheduleClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 252 return c.internalClient.GetLocation(ctx, req, opts...) 253 } 254 255 // ListLocations lists information about the supported locations for this service. 256 func (c *ScheduleClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 257 return c.internalClient.ListLocations(ctx, req, opts...) 258 } 259 260 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 261 // if the resource exists and does not have a policy set. 262 func (c *ScheduleClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 263 return c.internalClient.GetIamPolicy(ctx, req, opts...) 264 } 265 266 // SetIamPolicy sets the access control policy on the specified resource. Replaces 267 // any existing policy. 268 // 269 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 270 // errors. 271 func (c *ScheduleClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 272 return c.internalClient.SetIamPolicy(ctx, req, opts...) 273 } 274 275 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 276 // resource does not exist, this will return an empty set of 277 // permissions, not a NOT_FOUND error. 278 // 279 // Note: This operation is designed to be used for building 280 // permission-aware UIs and command-line tools, not for authorization 281 // checking. This operation may “fail open” without warning. 282 func (c *ScheduleClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 283 return c.internalClient.TestIamPermissions(ctx, req, opts...) 284 } 285 286 // CancelOperation is a utility method from google.longrunning.Operations. 287 func (c *ScheduleClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 288 return c.internalClient.CancelOperation(ctx, req, opts...) 289 } 290 291 // DeleteOperation is a utility method from google.longrunning.Operations. 292 func (c *ScheduleClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 293 return c.internalClient.DeleteOperation(ctx, req, opts...) 294 } 295 296 // GetOperation is a utility method from google.longrunning.Operations. 297 func (c *ScheduleClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 298 return c.internalClient.GetOperation(ctx, req, opts...) 299 } 300 301 // ListOperations is a utility method from google.longrunning.Operations. 302 func (c *ScheduleClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 303 return c.internalClient.ListOperations(ctx, req, opts...) 304 } 305 306 // WaitOperation is a utility method from google.longrunning.Operations. 307 func (c *ScheduleClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 308 return c.internalClient.WaitOperation(ctx, req, opts...) 309 } 310 311 // scheduleGRPCClient is a client for interacting with Vertex AI API over gRPC transport. 312 // 313 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 314 type scheduleGRPCClient struct { 315 // Connection pool of gRPC connections to the service. 316 connPool gtransport.ConnPool 317 318 // Points back to the CallOptions field of the containing ScheduleClient 319 CallOptions **ScheduleCallOptions 320 321 // The gRPC API client. 322 scheduleClient aiplatformpb.ScheduleServiceClient 323 324 // LROClient is used internally to handle long-running operations. 325 // It is exposed so that its CallOptions can be modified if required. 326 // Users should not Close this client. 327 LROClient **lroauto.OperationsClient 328 329 operationsClient longrunningpb.OperationsClient 330 331 iamPolicyClient iampb.IAMPolicyClient 332 333 locationsClient locationpb.LocationsClient 334 335 // The x-goog-* metadata to be sent with each request. 336 xGoogHeaders []string 337 338 logger *slog.Logger 339 } 340 341 // NewScheduleClient creates a new schedule service client based on gRPC. 342 // The returned client must be Closed when it is done being used to clean up its underlying connections. 343 // 344 // A service for creating and managing Vertex AI’s Schedule resources to 345 // periodically launch shceudled runs to make API calls. 346 func NewScheduleClient(ctx context.Context, opts ...option.ClientOption) (*ScheduleClient, error) { 347 clientOpts := defaultScheduleGRPCClientOptions() 348 if newScheduleClientHook != nil { 349 hookOpts, err := newScheduleClientHook(ctx, clientHookParams{}) 350 if err != nil { 351 return nil, err 352 } 353 clientOpts = append(clientOpts, hookOpts...) 354 } 355 356 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 357 if err != nil { 358 return nil, err 359 } 360 client := ScheduleClient{CallOptions: defaultScheduleCallOptions()} 361 362 c := &scheduleGRPCClient{ 363 connPool: connPool, 364 scheduleClient: aiplatformpb.NewScheduleServiceClient(connPool), 365 CallOptions: &client.CallOptions, 366 logger: internaloption.GetLogger(opts), 367 operationsClient: longrunningpb.NewOperationsClient(connPool), 368 iamPolicyClient: iampb.NewIAMPolicyClient(connPool), 369 locationsClient: locationpb.NewLocationsClient(connPool), 370 } 371 c.setGoogleClientInfo() 372 373 client.internalClient = c 374 375 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) 376 if err != nil { 377 // This error "should not happen", since we are just reusing old connection pool 378 // and never actually need to dial. 379 // If this does happen, we could leak connp. However, we cannot close conn: 380 // If the user invoked the constructor with option.WithGRPCConn, 381 // we would close a connection that's still in use. 382 // TODO: investigate error conditions. 383 return nil, err 384 } 385 c.LROClient = &client.LROClient 386 return &client, nil 387 } 388 389 // Connection returns a connection to the API service. 390 // 391 // Deprecated: Connections are now pooled so this method does not always 392 // return the same resource. 393 func (c *scheduleGRPCClient) Connection() *grpc.ClientConn { 394 return c.connPool.Conn() 395 } 396 397 // setGoogleClientInfo sets the name and version of the application in 398 // the `x-goog-api-client` header passed on each request. Intended for 399 // use by Google-written clients. 400 func (c *scheduleGRPCClient) setGoogleClientInfo(keyval ...string) { 401 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 402 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) 403 c.xGoogHeaders = []string{ 404 "x-goog-api-client", gax.XGoogHeader(kv...), 405 } 406 } 407 408 // Close closes the connection to the API service. The user should invoke this when 409 // the client is no longer required. 410 func (c *scheduleGRPCClient) Close() error { 411 return c.connPool.Close() 412 } 413 414 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 415 type scheduleRESTClient struct { 416 // The http endpoint to connect to. 417 endpoint string 418 419 // The http client. 420 httpClient *http.Client 421 422 // LROClient is used internally to handle long-running operations. 423 // It is exposed so that its CallOptions can be modified if required. 424 // Users should not Close this client. 425 LROClient **lroauto.OperationsClient 426 427 // The x-goog-* headers to be sent with each request. 428 xGoogHeaders []string 429 430 // Points back to the CallOptions field of the containing ScheduleClient 431 CallOptions **ScheduleCallOptions 432 433 logger *slog.Logger 434 } 435 436 // NewScheduleRESTClient creates a new schedule service rest client. 437 // 438 // A service for creating and managing Vertex AI’s Schedule resources to 439 // periodically launch shceudled runs to make API calls. 440 func NewScheduleRESTClient(ctx context.Context, opts ...option.ClientOption) (*ScheduleClient, error) { 441 clientOpts := append(defaultScheduleRESTClientOptions(), opts...) 442 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) 443 if err != nil { 444 return nil, err 445 } 446 447 callOpts := defaultScheduleRESTCallOptions() 448 c := &scheduleRESTClient{ 449 endpoint: endpoint, 450 httpClient: httpClient, 451 CallOptions: &callOpts, 452 logger: internaloption.GetLogger(opts), 453 } 454 c.setGoogleClientInfo() 455 456 lroOpts := []option.ClientOption{ 457 option.WithHTTPClient(httpClient), 458 option.WithEndpoint(endpoint), 459 } 460 opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...) 461 if err != nil { 462 return nil, err 463 } 464 c.LROClient = &opClient 465 466 return &ScheduleClient{internalClient: c, CallOptions: callOpts}, nil 467 } 468 469 func defaultScheduleRESTClientOptions() []option.ClientOption { 470 return []option.ClientOption{ 471 internaloption.WithDefaultEndpoint("https://aiplatform.googleapis.com"), 472 internaloption.WithDefaultEndpointTemplate("https://aiplatform.UNIVERSE_DOMAIN"), 473 internaloption.WithDefaultMTLSEndpoint("https://aiplatform.mtls.googleapis.com"), 474 internaloption.WithDefaultUniverseDomain("googleapis.com"), 475 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 476 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 477 internaloption.EnableNewAuthLibrary(), 478 } 479 } 480 481 // setGoogleClientInfo sets the name and version of the application in 482 // the `x-goog-api-client` header passed on each request. Intended for 483 // use by Google-written clients. 484 func (c *scheduleRESTClient) setGoogleClientInfo(keyval ...string) { 485 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 486 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) 487 c.xGoogHeaders = []string{ 488 "x-goog-api-client", gax.XGoogHeader(kv...), 489 } 490 } 491 492 // Close closes the connection to the API service. The user should invoke this when 493 // the client is no longer required. 494 func (c *scheduleRESTClient) Close() error { 495 // Replace httpClient with nil to force cleanup. 496 c.httpClient = nil 497 return nil 498 } 499 500 // Connection returns a connection to the API service. 501 // 502 // Deprecated: This method always returns nil. 503 func (c *scheduleRESTClient) Connection() *grpc.ClientConn { 504 return nil 505 } 506 func (c *scheduleGRPCClient) CreateSchedule(ctx context.Context, req *aiplatformpb.CreateScheduleRequest, opts ...gax.CallOption) (*aiplatformpb.Schedule, error) { 507 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 508 509 hds = append(c.xGoogHeaders, hds...) 510 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 511 opts = append((*c.CallOptions).CreateSchedule[0:len((*c.CallOptions).CreateSchedule):len((*c.CallOptions).CreateSchedule)], opts...) 512 var resp *aiplatformpb.Schedule 513 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 514 var err error 515 resp, err = executeRPC(ctx, c.scheduleClient.CreateSchedule, req, settings.GRPC, c.logger, "CreateSchedule") 516 return err 517 }, opts...) 518 if err != nil { 519 return nil, err 520 } 521 return resp, nil 522 } 523 524 func (c *scheduleGRPCClient) DeleteSchedule(ctx context.Context, req *aiplatformpb.DeleteScheduleRequest, opts ...gax.CallOption) (*DeleteScheduleOperation, error) { 525 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 526 527 hds = append(c.xGoogHeaders, hds...) 528 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 529 opts = append((*c.CallOptions).DeleteSchedule[0:len((*c.CallOptions).DeleteSchedule):len((*c.CallOptions).DeleteSchedule)], opts...) 530 var resp *longrunningpb.Operation 531 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 532 var err error 533 resp, err = executeRPC(ctx, c.scheduleClient.DeleteSchedule, req, settings.GRPC, c.logger, "DeleteSchedule") 534 return err 535 }, opts...) 536 if err != nil { 537 return nil, err 538 } 539 return &DeleteScheduleOperation{ 540 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 541 }, nil 542 } 543 544 func (c *scheduleGRPCClient) GetSchedule(ctx context.Context, req *aiplatformpb.GetScheduleRequest, opts ...gax.CallOption) (*aiplatformpb.Schedule, error) { 545 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 546 547 hds = append(c.xGoogHeaders, hds...) 548 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 549 opts = append((*c.CallOptions).GetSchedule[0:len((*c.CallOptions).GetSchedule):len((*c.CallOptions).GetSchedule)], opts...) 550 var resp *aiplatformpb.Schedule 551 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 552 var err error 553 resp, err = executeRPC(ctx, c.scheduleClient.GetSchedule, req, settings.GRPC, c.logger, "GetSchedule") 554 return err 555 }, opts...) 556 if err != nil { 557 return nil, err 558 } 559 return resp, nil 560 } 561 562 func (c *scheduleGRPCClient) ListSchedules(ctx context.Context, req *aiplatformpb.ListSchedulesRequest, opts ...gax.CallOption) *ScheduleIterator { 563 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 564 565 hds = append(c.xGoogHeaders, hds...) 566 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 567 opts = append((*c.CallOptions).ListSchedules[0:len((*c.CallOptions).ListSchedules):len((*c.CallOptions).ListSchedules)], opts...) 568 it := &ScheduleIterator{} 569 req = proto.Clone(req).(*aiplatformpb.ListSchedulesRequest) 570 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.Schedule, string, error) { 571 resp := &aiplatformpb.ListSchedulesResponse{} 572 if pageToken != "" { 573 req.PageToken = pageToken 574 } 575 if pageSize > math.MaxInt32 { 576 req.PageSize = math.MaxInt32 577 } else if pageSize != 0 { 578 req.PageSize = int32(pageSize) 579 } 580 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 581 var err error 582 resp, err = executeRPC(ctx, c.scheduleClient.ListSchedules, req, settings.GRPC, c.logger, "ListSchedules") 583 return err 584 }, opts...) 585 if err != nil { 586 return nil, "", err 587 } 588 589 it.Response = resp 590 return resp.GetSchedules(), resp.GetNextPageToken(), nil 591 } 592 fetch := func(pageSize int, pageToken string) (string, error) { 593 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 594 if err != nil { 595 return "", err 596 } 597 it.items = append(it.items, items...) 598 return nextPageToken, nil 599 } 600 601 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 602 it.pageInfo.MaxSize = int(req.GetPageSize()) 603 it.pageInfo.Token = req.GetPageToken() 604 605 return it 606 } 607 608 func (c *scheduleGRPCClient) PauseSchedule(ctx context.Context, req *aiplatformpb.PauseScheduleRequest, opts ...gax.CallOption) error { 609 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 610 611 hds = append(c.xGoogHeaders, hds...) 612 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 613 opts = append((*c.CallOptions).PauseSchedule[0:len((*c.CallOptions).PauseSchedule):len((*c.CallOptions).PauseSchedule)], opts...) 614 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 615 var err error 616 _, err = executeRPC(ctx, c.scheduleClient.PauseSchedule, req, settings.GRPC, c.logger, "PauseSchedule") 617 return err 618 }, opts...) 619 return err 620 } 621 622 func (c *scheduleGRPCClient) ResumeSchedule(ctx context.Context, req *aiplatformpb.ResumeScheduleRequest, opts ...gax.CallOption) error { 623 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 624 625 hds = append(c.xGoogHeaders, hds...) 626 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 627 opts = append((*c.CallOptions).ResumeSchedule[0:len((*c.CallOptions).ResumeSchedule):len((*c.CallOptions).ResumeSchedule)], opts...) 628 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 629 var err error 630 _, err = executeRPC(ctx, c.scheduleClient.ResumeSchedule, req, settings.GRPC, c.logger, "ResumeSchedule") 631 return err 632 }, opts...) 633 return err 634 } 635 636 func (c *scheduleGRPCClient) UpdateSchedule(ctx context.Context, req *aiplatformpb.UpdateScheduleRequest, opts ...gax.CallOption) (*aiplatformpb.Schedule, error) { 637 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "schedule.name", url.QueryEscape(req.GetSchedule().GetName()))} 638 639 hds = append(c.xGoogHeaders, hds...) 640 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 641 opts = append((*c.CallOptions).UpdateSchedule[0:len((*c.CallOptions).UpdateSchedule):len((*c.CallOptions).UpdateSchedule)], opts...) 642 var resp *aiplatformpb.Schedule 643 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 644 var err error 645 resp, err = executeRPC(ctx, c.scheduleClient.UpdateSchedule, req, settings.GRPC, c.logger, "UpdateSchedule") 646 return err 647 }, opts...) 648 if err != nil { 649 return nil, err 650 } 651 return resp, nil 652 } 653 654 func (c *scheduleGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 655 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 656 657 hds = append(c.xGoogHeaders, hds...) 658 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 659 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 660 var resp *locationpb.Location 661 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 662 var err error 663 resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation") 664 return err 665 }, opts...) 666 if err != nil { 667 return nil, err 668 } 669 return resp, nil 670 } 671 672 func (c *scheduleGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 673 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 674 675 hds = append(c.xGoogHeaders, hds...) 676 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 677 opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...) 678 it := &LocationIterator{} 679 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 680 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 681 resp := &locationpb.ListLocationsResponse{} 682 if pageToken != "" { 683 req.PageToken = pageToken 684 } 685 if pageSize > math.MaxInt32 { 686 req.PageSize = math.MaxInt32 687 } else if pageSize != 0 { 688 req.PageSize = int32(pageSize) 689 } 690 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 691 var err error 692 resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations") 693 return err 694 }, opts...) 695 if err != nil { 696 return nil, "", err 697 } 698 699 it.Response = resp 700 return resp.GetLocations(), resp.GetNextPageToken(), nil 701 } 702 fetch := func(pageSize int, pageToken string) (string, error) { 703 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 704 if err != nil { 705 return "", err 706 } 707 it.items = append(it.items, items...) 708 return nextPageToken, nil 709 } 710 711 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 712 it.pageInfo.MaxSize = int(req.GetPageSize()) 713 it.pageInfo.Token = req.GetPageToken() 714 715 return it 716 } 717 718 func (c *scheduleGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 719 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 720 721 hds = append(c.xGoogHeaders, hds...) 722 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 723 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 724 var resp *iampb.Policy 725 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 726 var err error 727 resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy") 728 return err 729 }, opts...) 730 if err != nil { 731 return nil, err 732 } 733 return resp, nil 734 } 735 736 func (c *scheduleGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 737 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 738 739 hds = append(c.xGoogHeaders, hds...) 740 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 741 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 742 var resp *iampb.Policy 743 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 744 var err error 745 resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy") 746 return err 747 }, opts...) 748 if err != nil { 749 return nil, err 750 } 751 return resp, nil 752 } 753 754 func (c *scheduleGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 755 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 756 757 hds = append(c.xGoogHeaders, hds...) 758 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 759 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 760 var resp *iampb.TestIamPermissionsResponse 761 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 762 var err error 763 resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions") 764 return err 765 }, opts...) 766 if err != nil { 767 return nil, err 768 } 769 return resp, nil 770 } 771 772 func (c *scheduleGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 773 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 774 775 hds = append(c.xGoogHeaders, hds...) 776 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 777 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) 778 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 779 var err error 780 _, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation") 781 return err 782 }, opts...) 783 return err 784 } 785 786 func (c *scheduleGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 787 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 788 789 hds = append(c.xGoogHeaders, hds...) 790 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 791 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) 792 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 793 var err error 794 _, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation") 795 return err 796 }, opts...) 797 return err 798 } 799 800 func (c *scheduleGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 801 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 802 803 hds = append(c.xGoogHeaders, hds...) 804 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 805 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 806 var resp *longrunningpb.Operation 807 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 808 var err error 809 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation") 810 return err 811 }, opts...) 812 if err != nil { 813 return nil, err 814 } 815 return resp, nil 816 } 817 818 func (c *scheduleGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 819 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 820 821 hds = append(c.xGoogHeaders, hds...) 822 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 823 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) 824 it := &OperationIterator{} 825 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 826 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 827 resp := &longrunningpb.ListOperationsResponse{} 828 if pageToken != "" { 829 req.PageToken = pageToken 830 } 831 if pageSize > math.MaxInt32 { 832 req.PageSize = math.MaxInt32 833 } else if pageSize != 0 { 834 req.PageSize = int32(pageSize) 835 } 836 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 837 var err error 838 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations") 839 return err 840 }, opts...) 841 if err != nil { 842 return nil, "", err 843 } 844 845 it.Response = resp 846 return resp.GetOperations(), resp.GetNextPageToken(), nil 847 } 848 fetch := func(pageSize int, pageToken string) (string, error) { 849 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 850 if err != nil { 851 return "", err 852 } 853 it.items = append(it.items, items...) 854 return nextPageToken, nil 855 } 856 857 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 858 it.pageInfo.MaxSize = int(req.GetPageSize()) 859 it.pageInfo.Token = req.GetPageToken() 860 861 return it 862 } 863 864 func (c *scheduleGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 865 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 866 867 hds = append(c.xGoogHeaders, hds...) 868 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 869 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 870 var resp *longrunningpb.Operation 871 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 872 var err error 873 resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation") 874 return err 875 }, opts...) 876 if err != nil { 877 return nil, err 878 } 879 return resp, nil 880 } 881 882 // CreateSchedule creates a Schedule. 883 func (c *scheduleRESTClient) CreateSchedule(ctx context.Context, req *aiplatformpb.CreateScheduleRequest, opts ...gax.CallOption) (*aiplatformpb.Schedule, error) { 884 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 885 body := req.GetSchedule() 886 jsonReq, err := m.Marshal(body) 887 if err != nil { 888 return nil, err 889 } 890 891 baseUrl, err := url.Parse(c.endpoint) 892 if err != nil { 893 return nil, err 894 } 895 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/schedules", req.GetParent()) 896 897 params := url.Values{} 898 params.Add("$alt", "json;enum-encoding=int") 899 900 baseUrl.RawQuery = params.Encode() 901 902 // Build HTTP headers from client and context metadata. 903 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 904 905 hds = append(c.xGoogHeaders, hds...) 906 hds = append(hds, "Content-Type", "application/json") 907 headers := gax.BuildHeaders(ctx, hds...) 908 opts = append((*c.CallOptions).CreateSchedule[0:len((*c.CallOptions).CreateSchedule):len((*c.CallOptions).CreateSchedule)], opts...) 909 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 910 resp := &aiplatformpb.Schedule{} 911 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 912 if settings.Path != "" { 913 baseUrl.Path = settings.Path 914 } 915 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 916 if err != nil { 917 return err 918 } 919 httpReq = httpReq.WithContext(ctx) 920 httpReq.Header = headers 921 922 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateSchedule") 923 if err != nil { 924 return err 925 } 926 927 if err := unm.Unmarshal(buf, resp); err != nil { 928 return err 929 } 930 931 return nil 932 }, opts...) 933 if e != nil { 934 return nil, e 935 } 936 return resp, nil 937 } 938 939 // DeleteSchedule deletes a Schedule. 940 func (c *scheduleRESTClient) DeleteSchedule(ctx context.Context, req *aiplatformpb.DeleteScheduleRequest, opts ...gax.CallOption) (*DeleteScheduleOperation, error) { 941 baseUrl, err := url.Parse(c.endpoint) 942 if err != nil { 943 return nil, err 944 } 945 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 946 947 params := url.Values{} 948 params.Add("$alt", "json;enum-encoding=int") 949 950 baseUrl.RawQuery = params.Encode() 951 952 // Build HTTP headers from client and context metadata. 953 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 954 955 hds = append(c.xGoogHeaders, hds...) 956 hds = append(hds, "Content-Type", "application/json") 957 headers := gax.BuildHeaders(ctx, hds...) 958 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 959 resp := &longrunningpb.Operation{} 960 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 961 if settings.Path != "" { 962 baseUrl.Path = settings.Path 963 } 964 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) 965 if err != nil { 966 return err 967 } 968 httpReq = httpReq.WithContext(ctx) 969 httpReq.Header = headers 970 971 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteSchedule") 972 if err != nil { 973 return err 974 } 975 if err := unm.Unmarshal(buf, resp); err != nil { 976 return err 977 } 978 979 return nil 980 }, opts...) 981 if e != nil { 982 return nil, e 983 } 984 985 override := fmt.Sprintf("/ui/%s", resp.GetName()) 986 return &DeleteScheduleOperation{ 987 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 988 pollPath: override, 989 }, nil 990 } 991 992 // GetSchedule gets a Schedule. 993 func (c *scheduleRESTClient) GetSchedule(ctx context.Context, req *aiplatformpb.GetScheduleRequest, opts ...gax.CallOption) (*aiplatformpb.Schedule, error) { 994 baseUrl, err := url.Parse(c.endpoint) 995 if err != nil { 996 return nil, err 997 } 998 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 999 1000 params := url.Values{} 1001 params.Add("$alt", "json;enum-encoding=int") 1002 1003 baseUrl.RawQuery = params.Encode() 1004 1005 // Build HTTP headers from client and context metadata. 1006 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1007 1008 hds = append(c.xGoogHeaders, hds...) 1009 hds = append(hds, "Content-Type", "application/json") 1010 headers := gax.BuildHeaders(ctx, hds...) 1011 opts = append((*c.CallOptions).GetSchedule[0:len((*c.CallOptions).GetSchedule):len((*c.CallOptions).GetSchedule)], opts...) 1012 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1013 resp := &aiplatformpb.Schedule{} 1014 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1015 if settings.Path != "" { 1016 baseUrl.Path = settings.Path 1017 } 1018 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1019 if err != nil { 1020 return err 1021 } 1022 httpReq = httpReq.WithContext(ctx) 1023 httpReq.Header = headers 1024 1025 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetSchedule") 1026 if err != nil { 1027 return err 1028 } 1029 1030 if err := unm.Unmarshal(buf, resp); err != nil { 1031 return err 1032 } 1033 1034 return nil 1035 }, opts...) 1036 if e != nil { 1037 return nil, e 1038 } 1039 return resp, nil 1040 } 1041 1042 // ListSchedules lists Schedules in a Location. 1043 func (c *scheduleRESTClient) ListSchedules(ctx context.Context, req *aiplatformpb.ListSchedulesRequest, opts ...gax.CallOption) *ScheduleIterator { 1044 it := &ScheduleIterator{} 1045 req = proto.Clone(req).(*aiplatformpb.ListSchedulesRequest) 1046 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1047 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.Schedule, string, error) { 1048 resp := &aiplatformpb.ListSchedulesResponse{} 1049 if pageToken != "" { 1050 req.PageToken = pageToken 1051 } 1052 if pageSize > math.MaxInt32 { 1053 req.PageSize = math.MaxInt32 1054 } else if pageSize != 0 { 1055 req.PageSize = int32(pageSize) 1056 } 1057 baseUrl, err := url.Parse(c.endpoint) 1058 if err != nil { 1059 return nil, "", err 1060 } 1061 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/schedules", req.GetParent()) 1062 1063 params := url.Values{} 1064 params.Add("$alt", "json;enum-encoding=int") 1065 if req.GetFilter() != "" { 1066 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 1067 } 1068 if req.GetOrderBy() != "" { 1069 params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) 1070 } 1071 if req.GetPageSize() != 0 { 1072 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1073 } 1074 if req.GetPageToken() != "" { 1075 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1076 } 1077 1078 baseUrl.RawQuery = params.Encode() 1079 1080 // Build HTTP headers from client and context metadata. 1081 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1082 headers := gax.BuildHeaders(ctx, hds...) 1083 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1084 if settings.Path != "" { 1085 baseUrl.Path = settings.Path 1086 } 1087 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1088 if err != nil { 1089 return err 1090 } 1091 httpReq.Header = headers 1092 1093 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListSchedules") 1094 if err != nil { 1095 return err 1096 } 1097 if err := unm.Unmarshal(buf, resp); err != nil { 1098 return err 1099 } 1100 1101 return nil 1102 }, opts...) 1103 if e != nil { 1104 return nil, "", e 1105 } 1106 it.Response = resp 1107 return resp.GetSchedules(), resp.GetNextPageToken(), nil 1108 } 1109 1110 fetch := func(pageSize int, pageToken string) (string, error) { 1111 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1112 if err != nil { 1113 return "", err 1114 } 1115 it.items = append(it.items, items...) 1116 return nextPageToken, nil 1117 } 1118 1119 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1120 it.pageInfo.MaxSize = int(req.GetPageSize()) 1121 it.pageInfo.Token = req.GetPageToken() 1122 1123 return it 1124 } 1125 1126 // PauseSchedule pauses a Schedule. Will mark 1127 // Schedule.state to 1128 // ‘PAUSED’. If the schedule is paused, no new runs will be created. Already 1129 // created runs will NOT be paused or canceled. 1130 func (c *scheduleRESTClient) PauseSchedule(ctx context.Context, req *aiplatformpb.PauseScheduleRequest, opts ...gax.CallOption) error { 1131 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1132 jsonReq, err := m.Marshal(req) 1133 if err != nil { 1134 return err 1135 } 1136 1137 baseUrl, err := url.Parse(c.endpoint) 1138 if err != nil { 1139 return err 1140 } 1141 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:pause", req.GetName()) 1142 1143 params := url.Values{} 1144 params.Add("$alt", "json;enum-encoding=int") 1145 1146 baseUrl.RawQuery = params.Encode() 1147 1148 // Build HTTP headers from client and context metadata. 1149 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1150 1151 hds = append(c.xGoogHeaders, hds...) 1152 hds = append(hds, "Content-Type", "application/json") 1153 headers := gax.BuildHeaders(ctx, hds...) 1154 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1155 if settings.Path != "" { 1156 baseUrl.Path = settings.Path 1157 } 1158 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1159 if err != nil { 1160 return err 1161 } 1162 httpReq = httpReq.WithContext(ctx) 1163 httpReq.Header = headers 1164 1165 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "PauseSchedule") 1166 return err 1167 }, opts...) 1168 } 1169 1170 // ResumeSchedule resumes a paused Schedule to start scheduling new runs. Will mark 1171 // Schedule.state to 1172 // ‘ACTIVE’. Only paused Schedule can be resumed. 1173 // 1174 // When the Schedule is resumed, new runs will be scheduled starting from the 1175 // next execution time after the current time based on the time_specification 1176 // in the Schedule. If Schedule.catchUp is set up true, all 1177 // missed runs will be scheduled for backfill first. 1178 func (c *scheduleRESTClient) ResumeSchedule(ctx context.Context, req *aiplatformpb.ResumeScheduleRequest, opts ...gax.CallOption) error { 1179 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1180 jsonReq, err := m.Marshal(req) 1181 if err != nil { 1182 return err 1183 } 1184 1185 baseUrl, err := url.Parse(c.endpoint) 1186 if err != nil { 1187 return err 1188 } 1189 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:resume", req.GetName()) 1190 1191 params := url.Values{} 1192 params.Add("$alt", "json;enum-encoding=int") 1193 1194 baseUrl.RawQuery = params.Encode() 1195 1196 // Build HTTP headers from client and context metadata. 1197 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1198 1199 hds = append(c.xGoogHeaders, hds...) 1200 hds = append(hds, "Content-Type", "application/json") 1201 headers := gax.BuildHeaders(ctx, hds...) 1202 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1203 if settings.Path != "" { 1204 baseUrl.Path = settings.Path 1205 } 1206 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1207 if err != nil { 1208 return err 1209 } 1210 httpReq = httpReq.WithContext(ctx) 1211 httpReq.Header = headers 1212 1213 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ResumeSchedule") 1214 return err 1215 }, opts...) 1216 } 1217 1218 // UpdateSchedule updates an active or paused Schedule. 1219 // 1220 // When the Schedule is updated, new runs will be scheduled starting from the 1221 // updated next execution time after the update time based on the 1222 // time_specification in the updated Schedule. All unstarted runs before the 1223 // update time will be skipped while already created runs will NOT be paused 1224 // or canceled. 1225 func (c *scheduleRESTClient) UpdateSchedule(ctx context.Context, req *aiplatformpb.UpdateScheduleRequest, opts ...gax.CallOption) (*aiplatformpb.Schedule, error) { 1226 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1227 body := req.GetSchedule() 1228 jsonReq, err := m.Marshal(body) 1229 if err != nil { 1230 return nil, err 1231 } 1232 1233 baseUrl, err := url.Parse(c.endpoint) 1234 if err != nil { 1235 return nil, err 1236 } 1237 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetSchedule().GetName()) 1238 1239 params := url.Values{} 1240 params.Add("$alt", "json;enum-encoding=int") 1241 if req.GetUpdateMask() != nil { 1242 field, err := protojson.Marshal(req.GetUpdateMask()) 1243 if err != nil { 1244 return nil, err 1245 } 1246 params.Add("updateMask", string(field[1:len(field)-1])) 1247 } 1248 1249 baseUrl.RawQuery = params.Encode() 1250 1251 // Build HTTP headers from client and context metadata. 1252 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "schedule.name", url.QueryEscape(req.GetSchedule().GetName()))} 1253 1254 hds = append(c.xGoogHeaders, hds...) 1255 hds = append(hds, "Content-Type", "application/json") 1256 headers := gax.BuildHeaders(ctx, hds...) 1257 opts = append((*c.CallOptions).UpdateSchedule[0:len((*c.CallOptions).UpdateSchedule):len((*c.CallOptions).UpdateSchedule)], opts...) 1258 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1259 resp := &aiplatformpb.Schedule{} 1260 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1261 if settings.Path != "" { 1262 baseUrl.Path = settings.Path 1263 } 1264 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) 1265 if err != nil { 1266 return err 1267 } 1268 httpReq = httpReq.WithContext(ctx) 1269 httpReq.Header = headers 1270 1271 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateSchedule") 1272 if err != nil { 1273 return err 1274 } 1275 1276 if err := unm.Unmarshal(buf, resp); err != nil { 1277 return err 1278 } 1279 1280 return nil 1281 }, opts...) 1282 if e != nil { 1283 return nil, e 1284 } 1285 return resp, nil 1286 } 1287 1288 // GetLocation gets information about a location. 1289 func (c *scheduleRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 1290 baseUrl, err := url.Parse(c.endpoint) 1291 if err != nil { 1292 return nil, err 1293 } 1294 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 1295 1296 params := url.Values{} 1297 params.Add("$alt", "json;enum-encoding=int") 1298 1299 baseUrl.RawQuery = params.Encode() 1300 1301 // Build HTTP headers from client and context metadata. 1302 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1303 1304 hds = append(c.xGoogHeaders, hds...) 1305 hds = append(hds, "Content-Type", "application/json") 1306 headers := gax.BuildHeaders(ctx, hds...) 1307 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 1308 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1309 resp := &locationpb.Location{} 1310 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1311 if settings.Path != "" { 1312 baseUrl.Path = settings.Path 1313 } 1314 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1315 if err != nil { 1316 return err 1317 } 1318 httpReq = httpReq.WithContext(ctx) 1319 httpReq.Header = headers 1320 1321 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation") 1322 if err != nil { 1323 return err 1324 } 1325 1326 if err := unm.Unmarshal(buf, resp); err != nil { 1327 return err 1328 } 1329 1330 return nil 1331 }, opts...) 1332 if e != nil { 1333 return nil, e 1334 } 1335 return resp, nil 1336 } 1337 1338 // ListLocations lists information about the supported locations for this service. 1339 func (c *scheduleRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 1340 it := &LocationIterator{} 1341 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 1342 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1343 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 1344 resp := &locationpb.ListLocationsResponse{} 1345 if pageToken != "" { 1346 req.PageToken = pageToken 1347 } 1348 if pageSize > math.MaxInt32 { 1349 req.PageSize = math.MaxInt32 1350 } else if pageSize != 0 { 1351 req.PageSize = int32(pageSize) 1352 } 1353 baseUrl, err := url.Parse(c.endpoint) 1354 if err != nil { 1355 return nil, "", err 1356 } 1357 baseUrl.Path += fmt.Sprintf("/ui/%v/locations", req.GetName()) 1358 1359 params := url.Values{} 1360 params.Add("$alt", "json;enum-encoding=int") 1361 if req.GetFilter() != "" { 1362 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 1363 } 1364 if req.GetPageSize() != 0 { 1365 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1366 } 1367 if req.GetPageToken() != "" { 1368 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1369 } 1370 1371 baseUrl.RawQuery = params.Encode() 1372 1373 // Build HTTP headers from client and context metadata. 1374 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1375 headers := gax.BuildHeaders(ctx, hds...) 1376 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1377 if settings.Path != "" { 1378 baseUrl.Path = settings.Path 1379 } 1380 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1381 if err != nil { 1382 return err 1383 } 1384 httpReq.Header = headers 1385 1386 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations") 1387 if err != nil { 1388 return err 1389 } 1390 if err := unm.Unmarshal(buf, resp); err != nil { 1391 return err 1392 } 1393 1394 return nil 1395 }, opts...) 1396 if e != nil { 1397 return nil, "", e 1398 } 1399 it.Response = resp 1400 return resp.GetLocations(), resp.GetNextPageToken(), nil 1401 } 1402 1403 fetch := func(pageSize int, pageToken string) (string, error) { 1404 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1405 if err != nil { 1406 return "", err 1407 } 1408 it.items = append(it.items, items...) 1409 return nextPageToken, nil 1410 } 1411 1412 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1413 it.pageInfo.MaxSize = int(req.GetPageSize()) 1414 it.pageInfo.Token = req.GetPageToken() 1415 1416 return it 1417 } 1418 1419 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 1420 // if the resource exists and does not have a policy set. 1421 func (c *scheduleRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 1422 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1423 jsonReq, err := m.Marshal(req) 1424 if err != nil { 1425 return nil, err 1426 } 1427 1428 baseUrl, err := url.Parse(c.endpoint) 1429 if err != nil { 1430 return nil, err 1431 } 1432 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:getIamPolicy", req.GetResource()) 1433 1434 params := url.Values{} 1435 params.Add("$alt", "json;enum-encoding=int") 1436 1437 baseUrl.RawQuery = params.Encode() 1438 1439 // Build HTTP headers from client and context metadata. 1440 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 1441 1442 hds = append(c.xGoogHeaders, hds...) 1443 hds = append(hds, "Content-Type", "application/json") 1444 headers := gax.BuildHeaders(ctx, hds...) 1445 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 1446 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1447 resp := &iampb.Policy{} 1448 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1449 if settings.Path != "" { 1450 baseUrl.Path = settings.Path 1451 } 1452 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1453 if err != nil { 1454 return err 1455 } 1456 httpReq = httpReq.WithContext(ctx) 1457 httpReq.Header = headers 1458 1459 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "GetIamPolicy") 1460 if err != nil { 1461 return err 1462 } 1463 1464 if err := unm.Unmarshal(buf, resp); err != nil { 1465 return err 1466 } 1467 1468 return nil 1469 }, opts...) 1470 if e != nil { 1471 return nil, e 1472 } 1473 return resp, nil 1474 } 1475 1476 // SetIamPolicy sets the access control policy on the specified resource. Replaces 1477 // any existing policy. 1478 // 1479 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 1480 // errors. 1481 func (c *scheduleRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 1482 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1483 jsonReq, err := m.Marshal(req) 1484 if err != nil { 1485 return nil, err 1486 } 1487 1488 baseUrl, err := url.Parse(c.endpoint) 1489 if err != nil { 1490 return nil, err 1491 } 1492 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:setIamPolicy", req.GetResource()) 1493 1494 params := url.Values{} 1495 params.Add("$alt", "json;enum-encoding=int") 1496 1497 baseUrl.RawQuery = params.Encode() 1498 1499 // Build HTTP headers from client and context metadata. 1500 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 1501 1502 hds = append(c.xGoogHeaders, hds...) 1503 hds = append(hds, "Content-Type", "application/json") 1504 headers := gax.BuildHeaders(ctx, hds...) 1505 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 1506 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1507 resp := &iampb.Policy{} 1508 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1509 if settings.Path != "" { 1510 baseUrl.Path = settings.Path 1511 } 1512 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1513 if err != nil { 1514 return err 1515 } 1516 httpReq = httpReq.WithContext(ctx) 1517 httpReq.Header = headers 1518 1519 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy") 1520 if err != nil { 1521 return err 1522 } 1523 1524 if err := unm.Unmarshal(buf, resp); err != nil { 1525 return err 1526 } 1527 1528 return nil 1529 }, opts...) 1530 if e != nil { 1531 return nil, e 1532 } 1533 return resp, nil 1534 } 1535 1536 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 1537 // resource does not exist, this will return an empty set of 1538 // permissions, not a NOT_FOUND error. 1539 // 1540 // Note: This operation is designed to be used for building 1541 // permission-aware UIs and command-line tools, not for authorization 1542 // checking. This operation may “fail open” without warning. 1543 func (c *scheduleRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 1544 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1545 jsonReq, err := m.Marshal(req) 1546 if err != nil { 1547 return nil, err 1548 } 1549 1550 baseUrl, err := url.Parse(c.endpoint) 1551 if err != nil { 1552 return nil, err 1553 } 1554 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:testIamPermissions", req.GetResource()) 1555 1556 params := url.Values{} 1557 params.Add("$alt", "json;enum-encoding=int") 1558 1559 baseUrl.RawQuery = params.Encode() 1560 1561 // Build HTTP headers from client and context metadata. 1562 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 1563 1564 hds = append(c.xGoogHeaders, hds...) 1565 hds = append(hds, "Content-Type", "application/json") 1566 headers := gax.BuildHeaders(ctx, hds...) 1567 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 1568 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1569 resp := &iampb.TestIamPermissionsResponse{} 1570 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1571 if settings.Path != "" { 1572 baseUrl.Path = settings.Path 1573 } 1574 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1575 if err != nil { 1576 return err 1577 } 1578 httpReq = httpReq.WithContext(ctx) 1579 httpReq.Header = headers 1580 1581 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TestIamPermissions") 1582 if err != nil { 1583 return err 1584 } 1585 1586 if err := unm.Unmarshal(buf, resp); err != nil { 1587 return err 1588 } 1589 1590 return nil 1591 }, opts...) 1592 if e != nil { 1593 return nil, e 1594 } 1595 return resp, nil 1596 } 1597 1598 // CancelOperation is a utility method from google.longrunning.Operations. 1599 func (c *scheduleRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 1600 baseUrl, err := url.Parse(c.endpoint) 1601 if err != nil { 1602 return err 1603 } 1604 baseUrl.Path += fmt.Sprintf("/ui/%v:cancel", req.GetName()) 1605 1606 params := url.Values{} 1607 params.Add("$alt", "json;enum-encoding=int") 1608 1609 baseUrl.RawQuery = params.Encode() 1610 1611 // Build HTTP headers from client and context metadata. 1612 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1613 1614 hds = append(c.xGoogHeaders, hds...) 1615 hds = append(hds, "Content-Type", "application/json") 1616 headers := gax.BuildHeaders(ctx, hds...) 1617 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1618 if settings.Path != "" { 1619 baseUrl.Path = settings.Path 1620 } 1621 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil) 1622 if err != nil { 1623 return err 1624 } 1625 httpReq = httpReq.WithContext(ctx) 1626 httpReq.Header = headers 1627 1628 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "CancelOperation") 1629 return err 1630 }, opts...) 1631 } 1632 1633 // DeleteOperation is a utility method from google.longrunning.Operations. 1634 func (c *scheduleRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 1635 baseUrl, err := url.Parse(c.endpoint) 1636 if err != nil { 1637 return err 1638 } 1639 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 1640 1641 params := url.Values{} 1642 params.Add("$alt", "json;enum-encoding=int") 1643 1644 baseUrl.RawQuery = params.Encode() 1645 1646 // Build HTTP headers from client and context metadata. 1647 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1648 1649 hds = append(c.xGoogHeaders, hds...) 1650 hds = append(hds, "Content-Type", "application/json") 1651 headers := gax.BuildHeaders(ctx, hds...) 1652 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1653 if settings.Path != "" { 1654 baseUrl.Path = settings.Path 1655 } 1656 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) 1657 if err != nil { 1658 return err 1659 } 1660 httpReq = httpReq.WithContext(ctx) 1661 httpReq.Header = headers 1662 1663 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation") 1664 return err 1665 }, opts...) 1666 } 1667 1668 // GetOperation is a utility method from google.longrunning.Operations. 1669 func (c *scheduleRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 1670 baseUrl, err := url.Parse(c.endpoint) 1671 if err != nil { 1672 return nil, err 1673 } 1674 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 1675 1676 params := url.Values{} 1677 params.Add("$alt", "json;enum-encoding=int") 1678 1679 baseUrl.RawQuery = params.Encode() 1680 1681 // Build HTTP headers from client and context metadata. 1682 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1683 1684 hds = append(c.xGoogHeaders, hds...) 1685 hds = append(hds, "Content-Type", "application/json") 1686 headers := gax.BuildHeaders(ctx, hds...) 1687 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 1688 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1689 resp := &longrunningpb.Operation{} 1690 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1691 if settings.Path != "" { 1692 baseUrl.Path = settings.Path 1693 } 1694 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1695 if err != nil { 1696 return err 1697 } 1698 httpReq = httpReq.WithContext(ctx) 1699 httpReq.Header = headers 1700 1701 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation") 1702 if err != nil { 1703 return err 1704 } 1705 1706 if err := unm.Unmarshal(buf, resp); err != nil { 1707 return err 1708 } 1709 1710 return nil 1711 }, opts...) 1712 if e != nil { 1713 return nil, e 1714 } 1715 return resp, nil 1716 } 1717 1718 // ListOperations is a utility method from google.longrunning.Operations. 1719 func (c *scheduleRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 1720 it := &OperationIterator{} 1721 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 1722 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1723 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 1724 resp := &longrunningpb.ListOperationsResponse{} 1725 if pageToken != "" { 1726 req.PageToken = pageToken 1727 } 1728 if pageSize > math.MaxInt32 { 1729 req.PageSize = math.MaxInt32 1730 } else if pageSize != 0 { 1731 req.PageSize = int32(pageSize) 1732 } 1733 baseUrl, err := url.Parse(c.endpoint) 1734 if err != nil { 1735 return nil, "", err 1736 } 1737 baseUrl.Path += fmt.Sprintf("/ui/%v/operations", req.GetName()) 1738 1739 params := url.Values{} 1740 params.Add("$alt", "json;enum-encoding=int") 1741 if req.GetFilter() != "" { 1742 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 1743 } 1744 if req.GetPageSize() != 0 { 1745 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1746 } 1747 if req.GetPageToken() != "" { 1748 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1749 } 1750 1751 baseUrl.RawQuery = params.Encode() 1752 1753 // Build HTTP headers from client and context metadata. 1754 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1755 headers := gax.BuildHeaders(ctx, hds...) 1756 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1757 if settings.Path != "" { 1758 baseUrl.Path = settings.Path 1759 } 1760 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1761 if err != nil { 1762 return err 1763 } 1764 httpReq.Header = headers 1765 1766 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations") 1767 if err != nil { 1768 return err 1769 } 1770 if err := unm.Unmarshal(buf, resp); err != nil { 1771 return err 1772 } 1773 1774 return nil 1775 }, opts...) 1776 if e != nil { 1777 return nil, "", e 1778 } 1779 it.Response = resp 1780 return resp.GetOperations(), resp.GetNextPageToken(), nil 1781 } 1782 1783 fetch := func(pageSize int, pageToken string) (string, error) { 1784 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1785 if err != nil { 1786 return "", err 1787 } 1788 it.items = append(it.items, items...) 1789 return nextPageToken, nil 1790 } 1791 1792 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1793 it.pageInfo.MaxSize = int(req.GetPageSize()) 1794 it.pageInfo.Token = req.GetPageToken() 1795 1796 return it 1797 } 1798 1799 // WaitOperation is a utility method from google.longrunning.Operations. 1800 func (c *scheduleRESTClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 1801 baseUrl, err := url.Parse(c.endpoint) 1802 if err != nil { 1803 return nil, err 1804 } 1805 baseUrl.Path += fmt.Sprintf("/ui/%v:wait", req.GetName()) 1806 1807 params := url.Values{} 1808 params.Add("$alt", "json;enum-encoding=int") 1809 if req.GetTimeout() != nil { 1810 field, err := protojson.Marshal(req.GetTimeout()) 1811 if err != nil { 1812 return nil, err 1813 } 1814 params.Add("timeout", string(field[1:len(field)-1])) 1815 } 1816 1817 baseUrl.RawQuery = params.Encode() 1818 1819 // Build HTTP headers from client and context metadata. 1820 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1821 1822 hds = append(c.xGoogHeaders, hds...) 1823 hds = append(hds, "Content-Type", "application/json") 1824 headers := gax.BuildHeaders(ctx, hds...) 1825 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 1826 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1827 resp := &longrunningpb.Operation{} 1828 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1829 if settings.Path != "" { 1830 baseUrl.Path = settings.Path 1831 } 1832 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil) 1833 if err != nil { 1834 return err 1835 } 1836 httpReq = httpReq.WithContext(ctx) 1837 httpReq.Header = headers 1838 1839 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "WaitOperation") 1840 if err != nil { 1841 return err 1842 } 1843 1844 if err := unm.Unmarshal(buf, resp); err != nil { 1845 return err 1846 } 1847 1848 return nil 1849 }, opts...) 1850 if e != nil { 1851 return nil, e 1852 } 1853 return resp, nil 1854 } 1855 1856 // DeleteScheduleOperation returns a new DeleteScheduleOperation from a given name. 1857 // The name must be that of a previously created DeleteScheduleOperation, possibly from a different process. 1858 func (c *scheduleGRPCClient) DeleteScheduleOperation(name string) *DeleteScheduleOperation { 1859 return &DeleteScheduleOperation{ 1860 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1861 } 1862 } 1863 1864 // DeleteScheduleOperation returns a new DeleteScheduleOperation from a given name. 1865 // The name must be that of a previously created DeleteScheduleOperation, possibly from a different process. 1866 func (c *scheduleRESTClient) DeleteScheduleOperation(name string) *DeleteScheduleOperation { 1867 override := fmt.Sprintf("/ui/%s", name) 1868 return &DeleteScheduleOperation{ 1869 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1870 pollPath: override, 1871 } 1872 }