Debian Codegraph @

visionai/apiv1/health_check_client.go

raw
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 visionai
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27
28 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
29 visionaipb "cloud.google.com/go/visionai/apiv1/visionaipb"
30 gax "github.com/googleapis/gax-go/v2"
31 "google.golang.org/api/iterator"
32 "google.golang.org/api/option"
33 "google.golang.org/api/option/internaloption"
34 gtransport "google.golang.org/api/transport/grpc"
35 httptransport "google.golang.org/api/transport/http"
36 "google.golang.org/grpc"
37 "google.golang.org/protobuf/encoding/protojson"
38 "google.golang.org/protobuf/proto"
39 )
40
41 var newHealthCheckClientHook clientHook
42
43 // HealthCheckCallOptions contains the retry settings for each method of HealthCheckClient.
44 type HealthCheckCallOptions struct {
45 HealthCheck []gax.CallOption
46 CancelOperation []gax.CallOption
47 DeleteOperation []gax.CallOption
48 GetOperation []gax.CallOption
49 ListOperations []gax.CallOption
50 }
51
52 func defaultHealthCheckGRPCClientOptions() []option.ClientOption {
53 return []option.ClientOption{
54 internaloption.WithDefaultEndpoint("visionai.googleapis.com:443"),
55 internaloption.WithDefaultEndpointTemplate("visionai.UNIVERSE_DOMAIN:443"),
56 internaloption.WithDefaultMTLSEndpoint("visionai.mtls.googleapis.com:443"),
57 internaloption.WithDefaultUniverseDomain("googleapis.com"),
58 internaloption.WithDefaultAudience("https://visionai.googleapis.com/"),
59 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
60 internaloption.EnableJwtWithScope(),
61 internaloption.EnableNewAuthLibrary(),
62 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
63 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
64 }
65 }
66
67 func defaultHealthCheckCallOptions() *HealthCheckCallOptions {
68 return &HealthCheckCallOptions{
69 HealthCheck: []gax.CallOption{},
70 CancelOperation: []gax.CallOption{},
71 DeleteOperation: []gax.CallOption{},
72 GetOperation: []gax.CallOption{},
73 ListOperations: []gax.CallOption{},
74 }
75 }
76
77 func defaultHealthCheckRESTCallOptions() *HealthCheckCallOptions {
78 return &HealthCheckCallOptions{
79 HealthCheck: []gax.CallOption{},
80 CancelOperation: []gax.CallOption{},
81 DeleteOperation: []gax.CallOption{},
82 GetOperation: []gax.CallOption{},
83 ListOperations: []gax.CallOption{},
84 }
85 }
86
87 // internalHealthCheckClient is an interface that defines the methods available from Vision AI API.
88 type internalHealthCheckClient interface {
89 Close() error
90 setGoogleClientInfo(...string)
91 Connection() *grpc.ClientConn
92 HealthCheck(context.Context, *visionaipb.HealthCheckRequest, ...gax.CallOption) (*visionaipb.HealthCheckResponse, error)
93 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
94 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error
95 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
96 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
97 }
98
99 // HealthCheckClient is a client for interacting with Vision AI API.
100 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
101 //
102 // HealthCheckService provides an interface for Vertex AI Vision Cluster Health
103 // Check.
104 type HealthCheckClient struct {
105 // The internal transport-dependent client.
106 internalClient internalHealthCheckClient
107
108 // The call options for this service.
109 CallOptions *HealthCheckCallOptions
110 }
111
112 // Wrapper methods routed to the internal client.
113
114 // Close closes the connection to the API service. The user should invoke this when
115 // the client is no longer required.
116 func (c *HealthCheckClient) Close() error {
117 return c.internalClient.Close()
118 }
119
120 // setGoogleClientInfo sets the name and version of the application in
121 // the `x-goog-api-client` header passed on each request. Intended for
122 // use by Google-written clients.
123 func (c *HealthCheckClient) setGoogleClientInfo(keyval ...string) {
124 c.internalClient.setGoogleClientInfo(keyval...)
125 }
126
127 // Connection returns a connection to the API service.
128 //
129 // Deprecated: Connections are now pooled so this method does not always
130 // return the same resource.
131 func (c *HealthCheckClient) Connection() *grpc.ClientConn {
132 return c.internalClient.Connection()
133 }
134
135 // HealthCheck healthCheck method checks the health status of the cluster.
136 func (c *HealthCheckClient) HealthCheck(ctx context.Context, req *visionaipb.HealthCheckRequest, opts ...gax.CallOption) (*visionaipb.HealthCheckResponse, error) {
137 return c.internalClient.HealthCheck(ctx, req, opts...)
138 }
139
140 // CancelOperation is a utility method from google.longrunning.Operations.
141 func (c *HealthCheckClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
142 return c.internalClient.CancelOperation(ctx, req, opts...)
143 }
144
145 // DeleteOperation is a utility method from google.longrunning.Operations.
146 func (c *HealthCheckClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
147 return c.internalClient.DeleteOperation(ctx, req, opts...)
148 }
149
150 // GetOperation is a utility method from google.longrunning.Operations.
151 func (c *HealthCheckClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
152 return c.internalClient.GetOperation(ctx, req, opts...)
153 }
154
155 // ListOperations is a utility method from google.longrunning.Operations.
156 func (c *HealthCheckClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
157 return c.internalClient.ListOperations(ctx, req, opts...)
158 }
159
160 // healthCheckGRPCClient is a client for interacting with Vision AI API over gRPC transport.
161 //
162 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
163 type healthCheckGRPCClient struct {
164 // Connection pool of gRPC connections to the service.
165 connPool gtransport.ConnPool
166
167 // Points back to the CallOptions field of the containing HealthCheckClient
168 CallOptions **HealthCheckCallOptions
169
170 // The gRPC API client.
171 healthCheckClient visionaipb.HealthCheckServiceClient
172
173 operationsClient longrunningpb.OperationsClient
174
175 // The x-goog-* metadata to be sent with each request.
176 xGoogHeaders []string
177
178 logger *slog.Logger
179 }
180
181 // NewHealthCheckClient creates a new health check service client based on gRPC.
182 // The returned client must be Closed when it is done being used to clean up its underlying connections.
183 //
184 // HealthCheckService provides an interface for Vertex AI Vision Cluster Health
185 // Check.
186 func NewHealthCheckClient(ctx context.Context, opts ...option.ClientOption) (*HealthCheckClient, error) {
187 clientOpts := defaultHealthCheckGRPCClientOptions()
188 if newHealthCheckClientHook != nil {
189 hookOpts, err := newHealthCheckClientHook(ctx, clientHookParams{})
190 if err != nil {
191 return nil, err
192 }
193 clientOpts = append(clientOpts, hookOpts...)
194 }
195
196 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
197 if err != nil {
198 return nil, err
199 }
200 client := HealthCheckClient{CallOptions: defaultHealthCheckCallOptions()}
201
202 c := &healthCheckGRPCClient{
203 connPool: connPool,
204 healthCheckClient: visionaipb.NewHealthCheckServiceClient(connPool),
205 CallOptions: &client.CallOptions,
206 logger: internaloption.GetLogger(opts),
207 operationsClient: longrunningpb.NewOperationsClient(connPool),
208 }
209 c.setGoogleClientInfo()
210
211 client.internalClient = c
212
213 return &client, nil
214 }
215
216 // Connection returns a connection to the API service.
217 //
218 // Deprecated: Connections are now pooled so this method does not always
219 // return the same resource.
220 func (c *healthCheckGRPCClient) Connection() *grpc.ClientConn {
221 return c.connPool.Conn()
222 }
223
224 // setGoogleClientInfo sets the name and version of the application in
225 // the `x-goog-api-client` header passed on each request. Intended for
226 // use by Google-written clients.
227 func (c *healthCheckGRPCClient) setGoogleClientInfo(keyval ...string) {
228 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
229 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
230 c.xGoogHeaders = []string{
231 "x-goog-api-client", gax.XGoogHeader(kv...),
232 }
233 }
234
235 // Close closes the connection to the API service. The user should invoke this when
236 // the client is no longer required.
237 func (c *healthCheckGRPCClient) Close() error {
238 return c.connPool.Close()
239 }
240
241 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
242 type healthCheckRESTClient struct {
243 // The http endpoint to connect to.
244 endpoint string
245
246 // The http client.
247 httpClient *http.Client
248
249 // The x-goog-* headers to be sent with each request.
250 xGoogHeaders []string
251
252 // Points back to the CallOptions field of the containing HealthCheckClient
253 CallOptions **HealthCheckCallOptions
254
255 logger *slog.Logger
256 }
257
258 // NewHealthCheckRESTClient creates a new health check service rest client.
259 //
260 // HealthCheckService provides an interface for Vertex AI Vision Cluster Health
261 // Check.
262 func NewHealthCheckRESTClient(ctx context.Context, opts ...option.ClientOption) (*HealthCheckClient, error) {
263 clientOpts := append(defaultHealthCheckRESTClientOptions(), opts...)
264 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
265 if err != nil {
266 return nil, err
267 }
268
269 callOpts := defaultHealthCheckRESTCallOptions()
270 c := &healthCheckRESTClient{
271 endpoint: endpoint,
272 httpClient: httpClient,
273 CallOptions: &callOpts,
274 logger: internaloption.GetLogger(opts),
275 }
276 c.setGoogleClientInfo()
277
278 return &HealthCheckClient{internalClient: c, CallOptions: callOpts}, nil
279 }
280
281 func defaultHealthCheckRESTClientOptions() []option.ClientOption {
282 return []option.ClientOption{
283 internaloption.WithDefaultEndpoint("https://visionai.googleapis.com"),
284 internaloption.WithDefaultEndpointTemplate("https://visionai.UNIVERSE_DOMAIN"),
285 internaloption.WithDefaultMTLSEndpoint("https://visionai.mtls.googleapis.com"),
286 internaloption.WithDefaultUniverseDomain("googleapis.com"),
287 internaloption.WithDefaultAudience("https://visionai.googleapis.com/"),
288 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
289 internaloption.EnableNewAuthLibrary(),
290 }
291 }
292
293 // setGoogleClientInfo sets the name and version of the application in
294 // the `x-goog-api-client` header passed on each request. Intended for
295 // use by Google-written clients.
296 func (c *healthCheckRESTClient) setGoogleClientInfo(keyval ...string) {
297 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
298 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
299 c.xGoogHeaders = []string{
300 "x-goog-api-client", gax.XGoogHeader(kv...),
301 }
302 }
303
304 // Close closes the connection to the API service. The user should invoke this when
305 // the client is no longer required.
306 func (c *healthCheckRESTClient) Close() error {
307 // Replace httpClient with nil to force cleanup.
308 c.httpClient = nil
309 return nil
310 }
311
312 // Connection returns a connection to the API service.
313 //
314 // Deprecated: This method always returns nil.
315 func (c *healthCheckRESTClient) Connection() *grpc.ClientConn {
316 return nil
317 }
318 func (c *healthCheckGRPCClient) HealthCheck(ctx context.Context, req *visionaipb.HealthCheckRequest, opts ...gax.CallOption) (*visionaipb.HealthCheckResponse, error) {
319 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "cluster", url.QueryEscape(req.GetCluster()))}
320
321 hds = append(c.xGoogHeaders, hds...)
322 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
323 opts = append((*c.CallOptions).HealthCheck[0:len((*c.CallOptions).HealthCheck):len((*c.CallOptions).HealthCheck)], opts...)
324 var resp *visionaipb.HealthCheckResponse
325 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
326 var err error
327 resp, err = executeRPC(ctx, c.healthCheckClient.HealthCheck, req, settings.GRPC, c.logger, "HealthCheck")
328 return err
329 }, opts...)
330 if err != nil {
331 return nil, err
332 }
333 return resp, nil
334 }
335
336 func (c *healthCheckGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
337 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
338
339 hds = append(c.xGoogHeaders, hds...)
340 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
341 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
342 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
343 var err error
344 _, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation")
345 return err
346 }, opts...)
347 return err
348 }
349
350 func (c *healthCheckGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
351 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
352
353 hds = append(c.xGoogHeaders, hds...)
354 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
355 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...)
356 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
357 var err error
358 _, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation")
359 return err
360 }, opts...)
361 return err
362 }
363
364 func (c *healthCheckGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
365 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
366
367 hds = append(c.xGoogHeaders, hds...)
368 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
369 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
370 var resp *longrunningpb.Operation
371 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
372 var err error
373 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
374 return err
375 }, opts...)
376 if err != nil {
377 return nil, err
378 }
379 return resp, nil
380 }
381
382 func (c *healthCheckGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
383 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
384
385 hds = append(c.xGoogHeaders, hds...)
386 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
387 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
388 it := &OperationIterator{}
389 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
390 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
391 resp := &longrunningpb.ListOperationsResponse{}
392 if pageToken != "" {
393 req.PageToken = pageToken
394 }
395 if pageSize > math.MaxInt32 {
396 req.PageSize = math.MaxInt32
397 } else if pageSize != 0 {
398 req.PageSize = int32(pageSize)
399 }
400 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
401 var err error
402 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations")
403 return err
404 }, opts...)
405 if err != nil {
406 return nil, "", err
407 }
408
409 it.Response = resp
410 return resp.GetOperations(), resp.GetNextPageToken(), nil
411 }
412 fetch := func(pageSize int, pageToken string) (string, error) {
413 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
414 if err != nil {
415 return "", err
416 }
417 it.items = append(it.items, items...)
418 return nextPageToken, nil
419 }
420
421 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
422 it.pageInfo.MaxSize = int(req.GetPageSize())
423 it.pageInfo.Token = req.GetPageToken()
424
425 return it
426 }
427
428 // HealthCheck healthCheck method checks the health status of the cluster.
429 func (c *healthCheckRESTClient) HealthCheck(ctx context.Context, req *visionaipb.HealthCheckRequest, opts ...gax.CallOption) (*visionaipb.HealthCheckResponse, error) {
430 baseUrl, err := url.Parse(c.endpoint)
431 if err != nil {
432 return nil, err
433 }
434 baseUrl.Path += fmt.Sprintf("/v1/%v:healthCheck", req.GetCluster())
435
436 params := url.Values{}
437 params.Add("$alt", "json;enum-encoding=int")
438
439 baseUrl.RawQuery = params.Encode()
440
441 // Build HTTP headers from client and context metadata.
442 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "cluster", url.QueryEscape(req.GetCluster()))}
443
444 hds = append(c.xGoogHeaders, hds...)
445 hds = append(hds, "Content-Type", "application/json")
446 headers := gax.BuildHeaders(ctx, hds...)
447 opts = append((*c.CallOptions).HealthCheck[0:len((*c.CallOptions).HealthCheck):len((*c.CallOptions).HealthCheck)], opts...)
448 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
449 resp := &visionaipb.HealthCheckResponse{}
450 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
451 if settings.Path != "" {
452 baseUrl.Path = settings.Path
453 }
454 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
455 if err != nil {
456 return err
457 }
458 httpReq = httpReq.WithContext(ctx)
459 httpReq.Header = headers
460
461 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "HealthCheck")
462 if err != nil {
463 return err
464 }
465
466 if err := unm.Unmarshal(buf, resp); err != nil {
467 return err
468 }
469
470 return nil
471 }, opts...)
472 if e != nil {
473 return nil, e
474 }
475 return resp, nil
476 }
477
478 // CancelOperation is a utility method from google.longrunning.Operations.
479 func (c *healthCheckRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
480 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
481 jsonReq, err := m.Marshal(req)
482 if err != nil {
483 return err
484 }
485
486 baseUrl, err := url.Parse(c.endpoint)
487 if err != nil {
488 return err
489 }
490 baseUrl.Path += fmt.Sprintf("/v1/%v:cancel", req.GetName())
491
492 params := url.Values{}
493 params.Add("$alt", "json;enum-encoding=int")
494
495 baseUrl.RawQuery = params.Encode()
496
497 // Build HTTP headers from client and context metadata.
498 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
499
500 hds = append(c.xGoogHeaders, hds...)
501 hds = append(hds, "Content-Type", "application/json")
502 headers := gax.BuildHeaders(ctx, hds...)
503 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
504 if settings.Path != "" {
505 baseUrl.Path = settings.Path
506 }
507 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
508 if err != nil {
509 return err
510 }
511 httpReq = httpReq.WithContext(ctx)
512 httpReq.Header = headers
513
514 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CancelOperation")
515 return err
516 }, opts...)
517 }
518
519 // DeleteOperation is a utility method from google.longrunning.Operations.
520 func (c *healthCheckRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
521 baseUrl, err := url.Parse(c.endpoint)
522 if err != nil {
523 return err
524 }
525 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
526
527 params := url.Values{}
528 params.Add("$alt", "json;enum-encoding=int")
529
530 baseUrl.RawQuery = params.Encode()
531
532 // Build HTTP headers from client and context metadata.
533 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
534
535 hds = append(c.xGoogHeaders, hds...)
536 hds = append(hds, "Content-Type", "application/json")
537 headers := gax.BuildHeaders(ctx, hds...)
538 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
539 if settings.Path != "" {
540 baseUrl.Path = settings.Path
541 }
542 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
543 if err != nil {
544 return err
545 }
546 httpReq = httpReq.WithContext(ctx)
547 httpReq.Header = headers
548
549 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation")
550 return err
551 }, opts...)
552 }
553
554 // GetOperation is a utility method from google.longrunning.Operations.
555 func (c *healthCheckRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
556 baseUrl, err := url.Parse(c.endpoint)
557 if err != nil {
558 return nil, err
559 }
560 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
561
562 params := url.Values{}
563 params.Add("$alt", "json;enum-encoding=int")
564
565 baseUrl.RawQuery = params.Encode()
566
567 // Build HTTP headers from client and context metadata.
568 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
569
570 hds = append(c.xGoogHeaders, hds...)
571 hds = append(hds, "Content-Type", "application/json")
572 headers := gax.BuildHeaders(ctx, hds...)
573 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
574 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
575 resp := &longrunningpb.Operation{}
576 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
577 if settings.Path != "" {
578 baseUrl.Path = settings.Path
579 }
580 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
581 if err != nil {
582 return err
583 }
584 httpReq = httpReq.WithContext(ctx)
585 httpReq.Header = headers
586
587 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
588 if err != nil {
589 return err
590 }
591
592 if err := unm.Unmarshal(buf, resp); err != nil {
593 return err
594 }
595
596 return nil
597 }, opts...)
598 if e != nil {
599 return nil, e
600 }
601 return resp, nil
602 }
603
604 // ListOperations is a utility method from google.longrunning.Operations.
605 func (c *healthCheckRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
606 it := &OperationIterator{}
607 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
608 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
609 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
610 resp := &longrunningpb.ListOperationsResponse{}
611 if pageToken != "" {
612 req.PageToken = pageToken
613 }
614 if pageSize > math.MaxInt32 {
615 req.PageSize = math.MaxInt32
616 } else if pageSize != 0 {
617 req.PageSize = int32(pageSize)
618 }
619 baseUrl, err := url.Parse(c.endpoint)
620 if err != nil {
621 return nil, "", err
622 }
623 baseUrl.Path += fmt.Sprintf("/v1/%v/operations", req.GetName())
624
625 params := url.Values{}
626 params.Add("$alt", "json;enum-encoding=int")
627 if req.GetFilter() != "" {
628 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
629 }
630 if req.GetPageSize() != 0 {
631 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
632 }
633 if req.GetPageToken() != "" {
634 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
635 }
636
637 baseUrl.RawQuery = params.Encode()
638
639 // Build HTTP headers from client and context metadata.
640 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
641 headers := gax.BuildHeaders(ctx, hds...)
642 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
643 if settings.Path != "" {
644 baseUrl.Path = settings.Path
645 }
646 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
647 if err != nil {
648 return err
649 }
650 httpReq.Header = headers
651
652 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations")
653 if err != nil {
654 return err
655 }
656 if err := unm.Unmarshal(buf, resp); err != nil {
657 return err
658 }
659
660 return nil
661 }, opts...)
662 if e != nil {
663 return nil, "", e
664 }
665 it.Response = resp
666 return resp.GetOperations(), resp.GetNextPageToken(), nil
667 }
668
669 fetch := func(pageSize int, pageToken string) (string, error) {
670 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
671 if err != nil {
672 return "", err
673 }
674 it.items = append(it.items, items...)
675 return nextPageToken, nil
676 }
677
678 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
679 it.pageInfo.MaxSize = int(req.GetPageSize())
680 it.pageInfo.Token = req.GetPageToken()
681
682 return it
683 }