1// Copyright 2019 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 gapic-generator. DO NOT EDIT.
16
17package redis
18
19import (
20	"context"
21	"fmt"
22	"math"
23	"time"
24
25	"cloud.google.com/go/longrunning"
26	lroauto "cloud.google.com/go/longrunning/autogen"
27	"github.com/golang/protobuf/proto"
28	anypb "github.com/golang/protobuf/ptypes/any"
29	gax "github.com/googleapis/gax-go/v2"
30	"google.golang.org/api/iterator"
31	"google.golang.org/api/option"
32	"google.golang.org/api/transport"
33	redispb "google.golang.org/genproto/googleapis/cloud/redis/v1beta1"
34	longrunningpb "google.golang.org/genproto/googleapis/longrunning"
35	"google.golang.org/grpc"
36	"google.golang.org/grpc/metadata"
37)
38
39// CloudRedisCallOptions contains the retry settings for each method of CloudRedisClient.
40type CloudRedisCallOptions struct {
41	ListInstances    []gax.CallOption
42	GetInstance      []gax.CallOption
43	CreateInstance   []gax.CallOption
44	UpdateInstance   []gax.CallOption
45	DeleteInstance   []gax.CallOption
46	FailoverInstance []gax.CallOption
47}
48
49func defaultCloudRedisClientOptions() []option.ClientOption {
50	return []option.ClientOption{
51		option.WithEndpoint("redis.googleapis.com:443"),
52		option.WithScopes(DefaultAuthScopes()...),
53	}
54}
55
56func defaultCloudRedisCallOptions() *CloudRedisCallOptions {
57	retry := map[[2]string][]gax.CallOption{}
58	return &CloudRedisCallOptions{
59		ListInstances:    retry[[2]string{"default", "non_idempotent"}],
60		GetInstance:      retry[[2]string{"default", "non_idempotent"}],
61		CreateInstance:   retry[[2]string{"default", "non_idempotent"}],
62		UpdateInstance:   retry[[2]string{"default", "non_idempotent"}],
63		DeleteInstance:   retry[[2]string{"default", "non_idempotent"}],
64		FailoverInstance: retry[[2]string{"default", "non_idempotent"}],
65	}
66}
67
68// CloudRedisClient is a client for interacting with Google Cloud Memorystore for Redis API.
69//
70// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
71type CloudRedisClient struct {
72	// The connection to the service.
73	conn *grpc.ClientConn
74
75	// The gRPC API client.
76	cloudRedisClient redispb.CloudRedisClient
77
78	// LROClient is used internally to handle longrunning operations.
79	// It is exposed so that its CallOptions can be modified if required.
80	// Users should not Close this client.
81	LROClient *lroauto.OperationsClient
82
83	// The call options for this service.
84	CallOptions *CloudRedisCallOptions
85
86	// The x-goog-* metadata to be sent with each request.
87	xGoogMetadata metadata.MD
88}
89
90// NewCloudRedisClient creates a new cloud redis client.
91//
92// Configures and manages Cloud Memorystore for Redis instances
93//
94// Google Cloud Memorystore for Redis v1beta1
95//
96// The redis.googleapis.com service implements the Google Cloud Memorystore
97// for Redis API and defines the following resource model for managing Redis
98// instances:
99//
100//   The service works with a collection of cloud projects, named: /projects/*
101//
102//   Each project has a collection of available locations, named: /locations/*
103//
104//   Each location has a collection of Redis instances, named: /instances/*
105//
106//   As such, Redis instances are resources of the form:
107//   /projects/{project_id}/locations/{location_id}/instances/{instance_id}
108//
109// Note that location_id must be refering to a GCP region; for example:
110//
111//   projects/redpepper-1290/locations/us-central1/instances/my-redis
112func NewCloudRedisClient(ctx context.Context, opts ...option.ClientOption) (*CloudRedisClient, error) {
113	conn, err := transport.DialGRPC(ctx, append(defaultCloudRedisClientOptions(), opts...)...)
114	if err != nil {
115		return nil, err
116	}
117	c := &CloudRedisClient{
118		conn:        conn,
119		CallOptions: defaultCloudRedisCallOptions(),
120
121		cloudRedisClient: redispb.NewCloudRedisClient(conn),
122	}
123	c.setGoogleClientInfo()
124
125	c.LROClient, err = lroauto.NewOperationsClient(ctx, option.WithGRPCConn(conn))
126	if err != nil {
127		// This error "should not happen", since we are just reusing old connection
128		// and never actually need to dial.
129		// If this does happen, we could leak conn. However, we cannot close conn:
130		// If the user invoked the function with option.WithGRPCConn,
131		// we would close a connection that's still in use.
132		// TODO(pongad): investigate error conditions.
133		return nil, err
134	}
135	return c, nil
136}
137
138// Connection returns the client's connection to the API service.
139func (c *CloudRedisClient) Connection() *grpc.ClientConn {
140	return c.conn
141}
142
143// Close closes the connection to the API service. The user should invoke this when
144// the client is no longer required.
145func (c *CloudRedisClient) Close() error {
146	return c.conn.Close()
147}
148
149// setGoogleClientInfo sets the name and version of the application in
150// the `x-goog-api-client` header passed on each request. Intended for
151// use by Google-written clients.
152func (c *CloudRedisClient) setGoogleClientInfo(keyval ...string) {
153	kv := append([]string{"gl-go", versionGo()}, keyval...)
154	kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
155	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
156}
157
158// ListInstances lists all Redis instances owned by a project in either the specified
159// location (region) or all locations.
160//
161// The location should have the following format:
162//
163//   projects/{project_id}/locations/{location_id}
164//
165// If location_id is specified as - (wildcard), then all regions
166// available to the project are queried, and the results are aggregated.
167func (c *CloudRedisClient) ListInstances(ctx context.Context, req *redispb.ListInstancesRequest, opts ...gax.CallOption) *InstanceIterator {
168	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", req.GetParent()))
169	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
170	opts = append(c.CallOptions.ListInstances[0:len(c.CallOptions.ListInstances):len(c.CallOptions.ListInstances)], opts...)
171	it := &InstanceIterator{}
172	req = proto.Clone(req).(*redispb.ListInstancesRequest)
173	it.InternalFetch = func(pageSize int, pageToken string) ([]*redispb.Instance, string, error) {
174		var resp *redispb.ListInstancesResponse
175		req.PageToken = pageToken
176		if pageSize > math.MaxInt32 {
177			req.PageSize = math.MaxInt32
178		} else {
179			req.PageSize = int32(pageSize)
180		}
181		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
182			var err error
183			resp, err = c.cloudRedisClient.ListInstances(ctx, req, settings.GRPC...)
184			return err
185		}, opts...)
186		if err != nil {
187			return nil, "", err
188		}
189		return resp.Instances, resp.NextPageToken, nil
190	}
191	fetch := func(pageSize int, pageToken string) (string, error) {
192		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
193		if err != nil {
194			return "", err
195		}
196		it.items = append(it.items, items...)
197		return nextPageToken, nil
198	}
199	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
200	it.pageInfo.MaxSize = int(req.PageSize)
201	it.pageInfo.Token = req.PageToken
202	return it
203}
204
205// GetInstance gets the details of a specific Redis instance.
206func (c *CloudRedisClient) GetInstance(ctx context.Context, req *redispb.GetInstanceRequest, opts ...gax.CallOption) (*redispb.Instance, error) {
207	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", req.GetName()))
208	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
209	opts = append(c.CallOptions.GetInstance[0:len(c.CallOptions.GetInstance):len(c.CallOptions.GetInstance)], opts...)
210	var resp *redispb.Instance
211	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
212		var err error
213		resp, err = c.cloudRedisClient.GetInstance(ctx, req, settings.GRPC...)
214		return err
215	}, opts...)
216	if err != nil {
217		return nil, err
218	}
219	return resp, nil
220}
221
222// CreateInstance creates a Redis instance based on the specified tier and memory size.
223//
224// By default, the instance is accessible from the project's
225// default network (at /compute/docs/networks-and-firewalls#networks).
226//
227// The creation is executed asynchronously and callers may check the returned
228// operation to track its progress. Once the operation is completed the Redis
229// instance will be fully functional. Completed longrunning.Operation will
230// contain the new instance object in the response field.
231//
232// The returned operation is automatically deleted after a few hours, so there
233// is no need to call DeleteOperation.
234func (c *CloudRedisClient) CreateInstance(ctx context.Context, req *redispb.CreateInstanceRequest, opts ...gax.CallOption) (*CreateInstanceOperation, error) {
235	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", req.GetParent()))
236	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
237	opts = append(c.CallOptions.CreateInstance[0:len(c.CallOptions.CreateInstance):len(c.CallOptions.CreateInstance)], opts...)
238	var resp *longrunningpb.Operation
239	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
240		var err error
241		resp, err = c.cloudRedisClient.CreateInstance(ctx, req, settings.GRPC...)
242		return err
243	}, opts...)
244	if err != nil {
245		return nil, err
246	}
247	return &CreateInstanceOperation{
248		lro: longrunning.InternalNewOperation(c.LROClient, resp),
249	}, nil
250}
251
252// UpdateInstance updates the metadata and configuration of a specific Redis instance.
253//
254// Completed longrunning.Operation will contain the new instance object
255// in the response field. The returned operation is automatically deleted
256// after a few hours, so there is no need to call DeleteOperation.
257func (c *CloudRedisClient) UpdateInstance(ctx context.Context, req *redispb.UpdateInstanceRequest, opts ...gax.CallOption) (*UpdateInstanceOperation, error) {
258	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "instance.name", req.GetInstance().GetName()))
259	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
260	opts = append(c.CallOptions.UpdateInstance[0:len(c.CallOptions.UpdateInstance):len(c.CallOptions.UpdateInstance)], opts...)
261	var resp *longrunningpb.Operation
262	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
263		var err error
264		resp, err = c.cloudRedisClient.UpdateInstance(ctx, req, settings.GRPC...)
265		return err
266	}, opts...)
267	if err != nil {
268		return nil, err
269	}
270	return &UpdateInstanceOperation{
271		lro: longrunning.InternalNewOperation(c.LROClient, resp),
272	}, nil
273}
274
275// DeleteInstance deletes a specific Redis instance.  Instance stops serving and data is
276// deleted.
277func (c *CloudRedisClient) DeleteInstance(ctx context.Context, req *redispb.DeleteInstanceRequest, opts ...gax.CallOption) (*DeleteInstanceOperation, error) {
278	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", req.GetName()))
279	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
280	opts = append(c.CallOptions.DeleteInstance[0:len(c.CallOptions.DeleteInstance):len(c.CallOptions.DeleteInstance)], opts...)
281	var resp *longrunningpb.Operation
282	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
283		var err error
284		resp, err = c.cloudRedisClient.DeleteInstance(ctx, req, settings.GRPC...)
285		return err
286	}, opts...)
287	if err != nil {
288		return nil, err
289	}
290	return &DeleteInstanceOperation{
291		lro: longrunning.InternalNewOperation(c.LROClient, resp),
292	}, nil
293}
294
295// FailoverInstance failover the master role to current replica node against a specific
296// STANDARD tier redis instance.
297func (c *CloudRedisClient) FailoverInstance(ctx context.Context, req *redispb.FailoverInstanceRequest, opts ...gax.CallOption) (*FailoverInstanceOperation, error) {
298	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", req.GetName()))
299	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
300	opts = append(c.CallOptions.FailoverInstance[0:len(c.CallOptions.FailoverInstance):len(c.CallOptions.FailoverInstance)], opts...)
301	var resp *longrunningpb.Operation
302	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
303		var err error
304		resp, err = c.cloudRedisClient.FailoverInstance(ctx, req, settings.GRPC...)
305		return err
306	}, opts...)
307	if err != nil {
308		return nil, err
309	}
310	return &FailoverInstanceOperation{
311		lro: longrunning.InternalNewOperation(c.LROClient, resp),
312	}, nil
313}
314
315// InstanceIterator manages a stream of *redispb.Instance.
316type InstanceIterator struct {
317	items    []*redispb.Instance
318	pageInfo *iterator.PageInfo
319	nextFunc func() error
320
321	// InternalFetch is for use by the Google Cloud Libraries only.
322	// It is not part of the stable interface of this package.
323	//
324	// InternalFetch returns results from a single call to the underlying RPC.
325	// The number of results is no greater than pageSize.
326	// If there are no more results, nextPageToken is empty and err is nil.
327	InternalFetch func(pageSize int, pageToken string) (results []*redispb.Instance, nextPageToken string, err error)
328}
329
330// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
331func (it *InstanceIterator) PageInfo() *iterator.PageInfo {
332	return it.pageInfo
333}
334
335// Next returns the next result. Its second return value is iterator.Done if there are no more
336// results. Once Next returns Done, all subsequent calls will return Done.
337func (it *InstanceIterator) Next() (*redispb.Instance, error) {
338	var item *redispb.Instance
339	if err := it.nextFunc(); err != nil {
340		return item, err
341	}
342	item = it.items[0]
343	it.items = it.items[1:]
344	return item, nil
345}
346
347func (it *InstanceIterator) bufLen() int {
348	return len(it.items)
349}
350
351func (it *InstanceIterator) takeBuf() interface{} {
352	b := it.items
353	it.items = nil
354	return b
355}
356
357// CreateInstanceOperation manages a long-running operation from CreateInstance.
358type CreateInstanceOperation struct {
359	lro *longrunning.Operation
360}
361
362// CreateInstanceOperation returns a new CreateInstanceOperation from a given name.
363// The name must be that of a previously created CreateInstanceOperation, possibly from a different process.
364func (c *CloudRedisClient) CreateInstanceOperation(name string) *CreateInstanceOperation {
365	return &CreateInstanceOperation{
366		lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
367	}
368}
369
370// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
371//
372// See documentation of Poll for error-handling information.
373func (op *CreateInstanceOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*redispb.Instance, error) {
374	var resp redispb.Instance
375	if err := op.lro.WaitWithInterval(ctx, &resp, 360000*time.Millisecond, opts...); err != nil {
376		return nil, err
377	}
378	return &resp, nil
379}
380
381// Poll fetches the latest state of the long-running operation.
382//
383// Poll also fetches the latest metadata, which can be retrieved by Metadata.
384//
385// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
386// the operation has completed with failure, the error is returned and op.Done will return true.
387// If Poll succeeds and the operation has completed successfully,
388// op.Done will return true, and the response of the operation is returned.
389// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
390func (op *CreateInstanceOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*redispb.Instance, error) {
391	var resp redispb.Instance
392	if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
393		return nil, err
394	}
395	if !op.Done() {
396		return nil, nil
397	}
398	return &resp, nil
399}
400
401// Metadata returns metadata associated with the long-running operation.
402// Metadata itself does not contact the server, but Poll does.
403// To get the latest metadata, call this method after a successful call to Poll.
404// If the metadata is not available, the returned metadata and error are both nil.
405func (op *CreateInstanceOperation) Metadata() (*anypb.Any, error) {
406	var meta anypb.Any
407	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
408		return nil, nil
409	} else if err != nil {
410		return nil, err
411	}
412	return &meta, nil
413}
414
415// Done reports whether the long-running operation has completed.
416func (op *CreateInstanceOperation) Done() bool {
417	return op.lro.Done()
418}
419
420// Name returns the name of the long-running operation.
421// The name is assigned by the server and is unique within the service from which the operation is created.
422func (op *CreateInstanceOperation) Name() string {
423	return op.lro.Name()
424}
425
426// DeleteInstanceOperation manages a long-running operation from DeleteInstance.
427type DeleteInstanceOperation struct {
428	lro *longrunning.Operation
429}
430
431// DeleteInstanceOperation returns a new DeleteInstanceOperation from a given name.
432// The name must be that of a previously created DeleteInstanceOperation, possibly from a different process.
433func (c *CloudRedisClient) DeleteInstanceOperation(name string) *DeleteInstanceOperation {
434	return &DeleteInstanceOperation{
435		lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
436	}
437}
438
439// Wait blocks until the long-running operation is completed, returning any error encountered.
440//
441// See documentation of Poll for error-handling information.
442func (op *DeleteInstanceOperation) Wait(ctx context.Context, opts ...gax.CallOption) error {
443	return op.lro.WaitWithInterval(ctx, nil, 360000*time.Millisecond, opts...)
444}
445
446// Poll fetches the latest state of the long-running operation.
447//
448// Poll also fetches the latest metadata, which can be retrieved by Metadata.
449//
450// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
451// the operation has completed with failure, the error is returned and op.Done will return true.
452// If Poll succeeds and the operation has completed successfully, op.Done will return true.
453func (op *DeleteInstanceOperation) Poll(ctx context.Context, opts ...gax.CallOption) error {
454	return op.lro.Poll(ctx, nil, opts...)
455}
456
457// Metadata returns metadata associated with the long-running operation.
458// Metadata itself does not contact the server, but Poll does.
459// To get the latest metadata, call this method after a successful call to Poll.
460// If the metadata is not available, the returned metadata and error are both nil.
461func (op *DeleteInstanceOperation) Metadata() (*anypb.Any, error) {
462	var meta anypb.Any
463	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
464		return nil, nil
465	} else if err != nil {
466		return nil, err
467	}
468	return &meta, nil
469}
470
471// Done reports whether the long-running operation has completed.
472func (op *DeleteInstanceOperation) Done() bool {
473	return op.lro.Done()
474}
475
476// Name returns the name of the long-running operation.
477// The name is assigned by the server and is unique within the service from which the operation is created.
478func (op *DeleteInstanceOperation) Name() string {
479	return op.lro.Name()
480}
481
482// FailoverInstanceOperation manages a long-running operation from FailoverInstance.
483type FailoverInstanceOperation struct {
484	lro *longrunning.Operation
485}
486
487// FailoverInstanceOperation returns a new FailoverInstanceOperation from a given name.
488// The name must be that of a previously created FailoverInstanceOperation, possibly from a different process.
489func (c *CloudRedisClient) FailoverInstanceOperation(name string) *FailoverInstanceOperation {
490	return &FailoverInstanceOperation{
491		lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
492	}
493}
494
495// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
496//
497// See documentation of Poll for error-handling information.
498func (op *FailoverInstanceOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*redispb.Instance, error) {
499	var resp redispb.Instance
500	if err := op.lro.WaitWithInterval(ctx, &resp, 360000*time.Millisecond, opts...); err != nil {
501		return nil, err
502	}
503	return &resp, nil
504}
505
506// Poll fetches the latest state of the long-running operation.
507//
508// Poll also fetches the latest metadata, which can be retrieved by Metadata.
509//
510// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
511// the operation has completed with failure, the error is returned and op.Done will return true.
512// If Poll succeeds and the operation has completed successfully,
513// op.Done will return true, and the response of the operation is returned.
514// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
515func (op *FailoverInstanceOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*redispb.Instance, error) {
516	var resp redispb.Instance
517	if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
518		return nil, err
519	}
520	if !op.Done() {
521		return nil, nil
522	}
523	return &resp, nil
524}
525
526// Metadata returns metadata associated with the long-running operation.
527// Metadata itself does not contact the server, but Poll does.
528// To get the latest metadata, call this method after a successful call to Poll.
529// If the metadata is not available, the returned metadata and error are both nil.
530func (op *FailoverInstanceOperation) Metadata() (*anypb.Any, error) {
531	var meta anypb.Any
532	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
533		return nil, nil
534	} else if err != nil {
535		return nil, err
536	}
537	return &meta, nil
538}
539
540// Done reports whether the long-running operation has completed.
541func (op *FailoverInstanceOperation) Done() bool {
542	return op.lro.Done()
543}
544
545// Name returns the name of the long-running operation.
546// The name is assigned by the server and is unique within the service from which the operation is created.
547func (op *FailoverInstanceOperation) Name() string {
548	return op.lro.Name()
549}
550
551// UpdateInstanceOperation manages a long-running operation from UpdateInstance.
552type UpdateInstanceOperation struct {
553	lro *longrunning.Operation
554}
555
556// UpdateInstanceOperation returns a new UpdateInstanceOperation from a given name.
557// The name must be that of a previously created UpdateInstanceOperation, possibly from a different process.
558func (c *CloudRedisClient) UpdateInstanceOperation(name string) *UpdateInstanceOperation {
559	return &UpdateInstanceOperation{
560		lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
561	}
562}
563
564// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
565//
566// See documentation of Poll for error-handling information.
567func (op *UpdateInstanceOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*redispb.Instance, error) {
568	var resp redispb.Instance
569	if err := op.lro.WaitWithInterval(ctx, &resp, 360000*time.Millisecond, opts...); err != nil {
570		return nil, err
571	}
572	return &resp, nil
573}
574
575// Poll fetches the latest state of the long-running operation.
576//
577// Poll also fetches the latest metadata, which can be retrieved by Metadata.
578//
579// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
580// the operation has completed with failure, the error is returned and op.Done will return true.
581// If Poll succeeds and the operation has completed successfully,
582// op.Done will return true, and the response of the operation is returned.
583// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
584func (op *UpdateInstanceOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*redispb.Instance, error) {
585	var resp redispb.Instance
586	if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
587		return nil, err
588	}
589	if !op.Done() {
590		return nil, nil
591	}
592	return &resp, nil
593}
594
595// Metadata returns metadata associated with the long-running operation.
596// Metadata itself does not contact the server, but Poll does.
597// To get the latest metadata, call this method after a successful call to Poll.
598// If the metadata is not available, the returned metadata and error are both nil.
599func (op *UpdateInstanceOperation) Metadata() (*anypb.Any, error) {
600	var meta anypb.Any
601	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
602		return nil, nil
603	} else if err != nil {
604		return nil, err
605	}
606	return &meta, nil
607}
608
609// Done reports whether the long-running operation has completed.
610func (op *UpdateInstanceOperation) Done() bool {
611	return op.lro.Done()
612}
613
614// Name returns the name of the long-running operation.
615// The name is assigned by the server and is unique within the service from which the operation is created.
616func (op *UpdateInstanceOperation) Name() string {
617	return op.lro.Name()
618}
619