Debian Codegraph @

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