1// Copyright 2020 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
17package gaming
18
19import (
20	"context"
21	"fmt"
22	"math"
23	"net/url"
24	"time"
25
26	"cloud.google.com/go/longrunning"
27	lroauto "cloud.google.com/go/longrunning/autogen"
28	"github.com/golang/protobuf/proto"
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/option/internaloption"
33	gtransport "google.golang.org/api/transport/grpc"
34	gamingpb "google.golang.org/genproto/googleapis/cloud/gaming/v1beta"
35	longrunningpb "google.golang.org/genproto/googleapis/longrunning"
36	"google.golang.org/grpc"
37	"google.golang.org/grpc/codes"
38	"google.golang.org/grpc/metadata"
39)
40
41var newGameServerClustersClientHook clientHook
42
43// GameServerClustersCallOptions contains the retry settings for each method of GameServerClustersClient.
44type GameServerClustersCallOptions struct {
45	ListGameServerClusters         []gax.CallOption
46	GetGameServerCluster           []gax.CallOption
47	CreateGameServerCluster        []gax.CallOption
48	PreviewCreateGameServerCluster []gax.CallOption
49	DeleteGameServerCluster        []gax.CallOption
50	PreviewDeleteGameServerCluster []gax.CallOption
51	UpdateGameServerCluster        []gax.CallOption
52	PreviewUpdateGameServerCluster []gax.CallOption
53}
54
55func defaultGameServerClustersClientOptions() []option.ClientOption {
56	return []option.ClientOption{
57		internaloption.WithDefaultEndpoint("gameservices.googleapis.com:443"),
58		internaloption.WithDefaultMTLSEndpoint("gameservices.mtls.googleapis.com:443"),
59		option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),
60		option.WithScopes(DefaultAuthScopes()...),
61		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
62			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
63	}
64}
65
66func defaultGameServerClustersCallOptions() *GameServerClustersCallOptions {
67	return &GameServerClustersCallOptions{
68		ListGameServerClusters: []gax.CallOption{
69			gax.WithRetry(func() gax.Retryer {
70				return gax.OnCodes([]codes.Code{
71					codes.Unavailable,
72				}, gax.Backoff{
73					Initial:    1000 * time.Millisecond,
74					Max:        10000 * time.Millisecond,
75					Multiplier: 1.30,
76				})
77			}),
78		},
79		GetGameServerCluster: []gax.CallOption{
80			gax.WithRetry(func() gax.Retryer {
81				return gax.OnCodes([]codes.Code{
82					codes.Unavailable,
83				}, gax.Backoff{
84					Initial:    1000 * time.Millisecond,
85					Max:        10000 * time.Millisecond,
86					Multiplier: 1.30,
87				})
88			}),
89		},
90		CreateGameServerCluster: []gax.CallOption{},
91		PreviewCreateGameServerCluster: []gax.CallOption{
92			gax.WithRetry(func() gax.Retryer {
93				return gax.OnCodes([]codes.Code{
94					codes.Unavailable,
95				}, gax.Backoff{
96					Initial:    1000 * time.Millisecond,
97					Max:        10000 * time.Millisecond,
98					Multiplier: 1.30,
99				})
100			}),
101		},
102		DeleteGameServerCluster: []gax.CallOption{},
103		PreviewDeleteGameServerCluster: []gax.CallOption{
104			gax.WithRetry(func() gax.Retryer {
105				return gax.OnCodes([]codes.Code{
106					codes.Unavailable,
107				}, gax.Backoff{
108					Initial:    1000 * time.Millisecond,
109					Max:        10000 * time.Millisecond,
110					Multiplier: 1.30,
111				})
112			}),
113		},
114		UpdateGameServerCluster: []gax.CallOption{},
115		PreviewUpdateGameServerCluster: []gax.CallOption{
116			gax.WithRetry(func() gax.Retryer {
117				return gax.OnCodes([]codes.Code{
118					codes.Unavailable,
119				}, gax.Backoff{
120					Initial:    1000 * time.Millisecond,
121					Max:        10000 * time.Millisecond,
122					Multiplier: 1.30,
123				})
124			}),
125		},
126	}
127}
128
129// GameServerClustersClient is a client for interacting with .
130//
131// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
132type GameServerClustersClient struct {
133	// Connection pool of gRPC connections to the service.
134	connPool gtransport.ConnPool
135
136	// flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE
137	disableDeadlines bool
138
139	// The gRPC API client.
140	gameServerClustersClient gamingpb.GameServerClustersServiceClient
141
142	// LROClient is used internally to handle longrunning operations.
143	// It is exposed so that its CallOptions can be modified if required.
144	// Users should not Close this client.
145	LROClient *lroauto.OperationsClient
146
147	// The call options for this service.
148	CallOptions *GameServerClustersCallOptions
149
150	// The x-goog-* metadata to be sent with each request.
151	xGoogMetadata metadata.MD
152}
153
154// NewGameServerClustersClient creates a new game server clusters service client.
155//
156// The game server cluster maps to Kubernetes clusters running Agones and is
157// used to manage fleets within clusters.
158func NewGameServerClustersClient(ctx context.Context, opts ...option.ClientOption) (*GameServerClustersClient, error) {
159	clientOpts := defaultGameServerClustersClientOptions()
160
161	if newGameServerClustersClientHook != nil {
162		hookOpts, err := newGameServerClustersClientHook(ctx, clientHookParams{})
163		if err != nil {
164			return nil, err
165		}
166		clientOpts = append(clientOpts, hookOpts...)
167	}
168
169	disableDeadlines, err := checkDisableDeadlines()
170	if err != nil {
171		return nil, err
172	}
173
174	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
175	if err != nil {
176		return nil, err
177	}
178	c := &GameServerClustersClient{
179		connPool:         connPool,
180		disableDeadlines: disableDeadlines,
181		CallOptions:      defaultGameServerClustersCallOptions(),
182
183		gameServerClustersClient: gamingpb.NewGameServerClustersServiceClient(connPool),
184	}
185	c.setGoogleClientInfo()
186
187	c.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
188	if err != nil {
189		// This error "should not happen", since we are just reusing old connection pool
190		// and never actually need to dial.
191		// If this does happen, we could leak connp. However, we cannot close conn:
192		// If the user invoked the constructor with option.WithGRPCConn,
193		// we would close a connection that's still in use.
194		// TODO: investigate error conditions.
195		return nil, err
196	}
197	return c, nil
198}
199
200// Connection returns a connection to the API service.
201//
202// Deprecated.
203func (c *GameServerClustersClient) Connection() *grpc.ClientConn {
204	return c.connPool.Conn()
205}
206
207// Close closes the connection to the API service. The user should invoke this when
208// the client is no longer required.
209func (c *GameServerClustersClient) Close() error {
210	return c.connPool.Close()
211}
212
213// setGoogleClientInfo sets the name and version of the application in
214// the `x-goog-api-client` header passed on each request. Intended for
215// use by Google-written clients.
216func (c *GameServerClustersClient) setGoogleClientInfo(keyval ...string) {
217	kv := append([]string{"gl-go", versionGo()}, keyval...)
218	kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
219	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
220}
221
222// ListGameServerClusters lists game server clusters in a given project and location.
223func (c *GameServerClustersClient) ListGameServerClusters(ctx context.Context, req *gamingpb.ListGameServerClustersRequest, opts ...gax.CallOption) *GameServerClusterIterator {
224	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
225	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
226	opts = append(c.CallOptions.ListGameServerClusters[0:len(c.CallOptions.ListGameServerClusters):len(c.CallOptions.ListGameServerClusters)], opts...)
227	it := &GameServerClusterIterator{}
228	req = proto.Clone(req).(*gamingpb.ListGameServerClustersRequest)
229	it.InternalFetch = func(pageSize int, pageToken string) ([]*gamingpb.GameServerCluster, string, error) {
230		var resp *gamingpb.ListGameServerClustersResponse
231		req.PageToken = pageToken
232		if pageSize > math.MaxInt32 {
233			req.PageSize = math.MaxInt32
234		} else {
235			req.PageSize = int32(pageSize)
236		}
237		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
238			var err error
239			resp, err = c.gameServerClustersClient.ListGameServerClusters(ctx, req, settings.GRPC...)
240			return err
241		}, opts...)
242		if err != nil {
243			return nil, "", err
244		}
245
246		it.Response = resp
247		return resp.GetGameServerClusters(), resp.GetNextPageToken(), nil
248	}
249	fetch := func(pageSize int, pageToken string) (string, error) {
250		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
251		if err != nil {
252			return "", err
253		}
254		it.items = append(it.items, items...)
255		return nextPageToken, nil
256	}
257	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
258	it.pageInfo.MaxSize = int(req.GetPageSize())
259	it.pageInfo.Token = req.GetPageToken()
260	return it
261}
262
263// GetGameServerCluster gets details of a single game server cluster.
264func (c *GameServerClustersClient) GetGameServerCluster(ctx context.Context, req *gamingpb.GetGameServerClusterRequest, opts ...gax.CallOption) (*gamingpb.GameServerCluster, error) {
265	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
266		cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
267		defer cancel()
268		ctx = cctx
269	}
270	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
271	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
272	opts = append(c.CallOptions.GetGameServerCluster[0:len(c.CallOptions.GetGameServerCluster):len(c.CallOptions.GetGameServerCluster)], opts...)
273	var resp *gamingpb.GameServerCluster
274	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
275		var err error
276		resp, err = c.gameServerClustersClient.GetGameServerCluster(ctx, req, settings.GRPC...)
277		return err
278	}, opts...)
279	if err != nil {
280		return nil, err
281	}
282	return resp, nil
283}
284
285// CreateGameServerCluster creates a new game server cluster in a given project and location.
286func (c *GameServerClustersClient) CreateGameServerCluster(ctx context.Context, req *gamingpb.CreateGameServerClusterRequest, opts ...gax.CallOption) (*CreateGameServerClusterOperation, error) {
287	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
288		cctx, cancel := context.WithTimeout(ctx, 120000*time.Millisecond)
289		defer cancel()
290		ctx = cctx
291	}
292	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
293	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
294	opts = append(c.CallOptions.CreateGameServerCluster[0:len(c.CallOptions.CreateGameServerCluster):len(c.CallOptions.CreateGameServerCluster)], opts...)
295	var resp *longrunningpb.Operation
296	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
297		var err error
298		resp, err = c.gameServerClustersClient.CreateGameServerCluster(ctx, req, settings.GRPC...)
299		return err
300	}, opts...)
301	if err != nil {
302		return nil, err
303	}
304	return &CreateGameServerClusterOperation{
305		lro: longrunning.InternalNewOperation(c.LROClient, resp),
306	}, nil
307}
308
309// PreviewCreateGameServerCluster previews creation of a new game server cluster in a given project and
310// location.
311func (c *GameServerClustersClient) PreviewCreateGameServerCluster(ctx context.Context, req *gamingpb.PreviewCreateGameServerClusterRequest, opts ...gax.CallOption) (*gamingpb.PreviewCreateGameServerClusterResponse, error) {
312	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
313		cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
314		defer cancel()
315		ctx = cctx
316	}
317	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
318	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
319	opts = append(c.CallOptions.PreviewCreateGameServerCluster[0:len(c.CallOptions.PreviewCreateGameServerCluster):len(c.CallOptions.PreviewCreateGameServerCluster)], opts...)
320	var resp *gamingpb.PreviewCreateGameServerClusterResponse
321	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
322		var err error
323		resp, err = c.gameServerClustersClient.PreviewCreateGameServerCluster(ctx, req, settings.GRPC...)
324		return err
325	}, opts...)
326	if err != nil {
327		return nil, err
328	}
329	return resp, nil
330}
331
332// DeleteGameServerCluster deletes a single game server cluster.
333func (c *GameServerClustersClient) DeleteGameServerCluster(ctx context.Context, req *gamingpb.DeleteGameServerClusterRequest, opts ...gax.CallOption) (*DeleteGameServerClusterOperation, error) {
334	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
335		cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
336		defer cancel()
337		ctx = cctx
338	}
339	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
340	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
341	opts = append(c.CallOptions.DeleteGameServerCluster[0:len(c.CallOptions.DeleteGameServerCluster):len(c.CallOptions.DeleteGameServerCluster)], opts...)
342	var resp *longrunningpb.Operation
343	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
344		var err error
345		resp, err = c.gameServerClustersClient.DeleteGameServerCluster(ctx, req, settings.GRPC...)
346		return err
347	}, opts...)
348	if err != nil {
349		return nil, err
350	}
351	return &DeleteGameServerClusterOperation{
352		lro: longrunning.InternalNewOperation(c.LROClient, resp),
353	}, nil
354}
355
356// PreviewDeleteGameServerCluster previews deletion of a single game server cluster.
357func (c *GameServerClustersClient) PreviewDeleteGameServerCluster(ctx context.Context, req *gamingpb.PreviewDeleteGameServerClusterRequest, opts ...gax.CallOption) (*gamingpb.PreviewDeleteGameServerClusterResponse, error) {
358	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
359		cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
360		defer cancel()
361		ctx = cctx
362	}
363	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
364	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
365	opts = append(c.CallOptions.PreviewDeleteGameServerCluster[0:len(c.CallOptions.PreviewDeleteGameServerCluster):len(c.CallOptions.PreviewDeleteGameServerCluster)], opts...)
366	var resp *gamingpb.PreviewDeleteGameServerClusterResponse
367	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
368		var err error
369		resp, err = c.gameServerClustersClient.PreviewDeleteGameServerCluster(ctx, req, settings.GRPC...)
370		return err
371	}, opts...)
372	if err != nil {
373		return nil, err
374	}
375	return resp, nil
376}
377
378// UpdateGameServerCluster patches a single game server cluster.
379func (c *GameServerClustersClient) UpdateGameServerCluster(ctx context.Context, req *gamingpb.UpdateGameServerClusterRequest, opts ...gax.CallOption) (*UpdateGameServerClusterOperation, error) {
380	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
381		cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
382		defer cancel()
383		ctx = cctx
384	}
385	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "game_server_cluster.name", url.QueryEscape(req.GetGameServerCluster().GetName())))
386	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
387	opts = append(c.CallOptions.UpdateGameServerCluster[0:len(c.CallOptions.UpdateGameServerCluster):len(c.CallOptions.UpdateGameServerCluster)], opts...)
388	var resp *longrunningpb.Operation
389	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
390		var err error
391		resp, err = c.gameServerClustersClient.UpdateGameServerCluster(ctx, req, settings.GRPC...)
392		return err
393	}, opts...)
394	if err != nil {
395		return nil, err
396	}
397	return &UpdateGameServerClusterOperation{
398		lro: longrunning.InternalNewOperation(c.LROClient, resp),
399	}, nil
400}
401
402// PreviewUpdateGameServerCluster previews updating a GameServerCluster.
403func (c *GameServerClustersClient) PreviewUpdateGameServerCluster(ctx context.Context, req *gamingpb.PreviewUpdateGameServerClusterRequest, opts ...gax.CallOption) (*gamingpb.PreviewUpdateGameServerClusterResponse, error) {
404	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
405		cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
406		defer cancel()
407		ctx = cctx
408	}
409	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "game_server_cluster.name", url.QueryEscape(req.GetGameServerCluster().GetName())))
410	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
411	opts = append(c.CallOptions.PreviewUpdateGameServerCluster[0:len(c.CallOptions.PreviewUpdateGameServerCluster):len(c.CallOptions.PreviewUpdateGameServerCluster)], opts...)
412	var resp *gamingpb.PreviewUpdateGameServerClusterResponse
413	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
414		var err error
415		resp, err = c.gameServerClustersClient.PreviewUpdateGameServerCluster(ctx, req, settings.GRPC...)
416		return err
417	}, opts...)
418	if err != nil {
419		return nil, err
420	}
421	return resp, nil
422}
423
424// CreateGameServerClusterOperation manages a long-running operation from CreateGameServerCluster.
425type CreateGameServerClusterOperation struct {
426	lro *longrunning.Operation
427}
428
429// CreateGameServerClusterOperation returns a new CreateGameServerClusterOperation from a given name.
430// The name must be that of a previously created CreateGameServerClusterOperation, possibly from a different process.
431func (c *GameServerClustersClient) CreateGameServerClusterOperation(name string) *CreateGameServerClusterOperation {
432	return &CreateGameServerClusterOperation{
433		lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
434	}
435}
436
437// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
438//
439// See documentation of Poll for error-handling information.
440func (op *CreateGameServerClusterOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*gamingpb.GameServerCluster, error) {
441	var resp gamingpb.GameServerCluster
442	if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
443		return nil, err
444	}
445	return &resp, nil
446}
447
448// Poll fetches the latest state of the long-running operation.
449//
450// Poll also fetches the latest metadata, which can be retrieved by Metadata.
451//
452// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
453// the operation has completed with failure, the error is returned and op.Done will return true.
454// If Poll succeeds and the operation has completed successfully,
455// op.Done will return true, and the response of the operation is returned.
456// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
457func (op *CreateGameServerClusterOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*gamingpb.GameServerCluster, error) {
458	var resp gamingpb.GameServerCluster
459	if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
460		return nil, err
461	}
462	if !op.Done() {
463		return nil, nil
464	}
465	return &resp, nil
466}
467
468// Metadata returns metadata associated with the long-running operation.
469// Metadata itself does not contact the server, but Poll does.
470// To get the latest metadata, call this method after a successful call to Poll.
471// If the metadata is not available, the returned metadata and error are both nil.
472func (op *CreateGameServerClusterOperation) Metadata() (*gamingpb.OperationMetadata, error) {
473	var meta gamingpb.OperationMetadata
474	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
475		return nil, nil
476	} else if err != nil {
477		return nil, err
478	}
479	return &meta, nil
480}
481
482// Done reports whether the long-running operation has completed.
483func (op *CreateGameServerClusterOperation) Done() bool {
484	return op.lro.Done()
485}
486
487// Name returns the name of the long-running operation.
488// The name is assigned by the server and is unique within the service from which the operation is created.
489func (op *CreateGameServerClusterOperation) Name() string {
490	return op.lro.Name()
491}
492
493// DeleteGameServerClusterOperation manages a long-running operation from DeleteGameServerCluster.
494type DeleteGameServerClusterOperation struct {
495	lro *longrunning.Operation
496}
497
498// DeleteGameServerClusterOperation returns a new DeleteGameServerClusterOperation from a given name.
499// The name must be that of a previously created DeleteGameServerClusterOperation, possibly from a different process.
500func (c *GameServerClustersClient) DeleteGameServerClusterOperation(name string) *DeleteGameServerClusterOperation {
501	return &DeleteGameServerClusterOperation{
502		lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
503	}
504}
505
506// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
507//
508// See documentation of Poll for error-handling information.
509func (op *DeleteGameServerClusterOperation) Wait(ctx context.Context, opts ...gax.CallOption) error {
510	return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...)
511}
512
513// Poll fetches the latest state of the long-running operation.
514//
515// Poll also fetches the latest metadata, which can be retrieved by Metadata.
516//
517// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
518// the operation has completed with failure, the error is returned and op.Done will return true.
519// If Poll succeeds and the operation has completed successfully,
520// op.Done will return true, and the response of the operation is returned.
521// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
522func (op *DeleteGameServerClusterOperation) Poll(ctx context.Context, opts ...gax.CallOption) error {
523	return op.lro.Poll(ctx, nil, opts...)
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 *DeleteGameServerClusterOperation) Metadata() (*gamingpb.OperationMetadata, error) {
531	var meta gamingpb.OperationMetadata
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 *DeleteGameServerClusterOperation) 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 *DeleteGameServerClusterOperation) Name() string {
548	return op.lro.Name()
549}
550
551// UpdateGameServerClusterOperation manages a long-running operation from UpdateGameServerCluster.
552type UpdateGameServerClusterOperation struct {
553	lro *longrunning.Operation
554}
555
556// UpdateGameServerClusterOperation returns a new UpdateGameServerClusterOperation from a given name.
557// The name must be that of a previously created UpdateGameServerClusterOperation, possibly from a different process.
558func (c *GameServerClustersClient) UpdateGameServerClusterOperation(name string) *UpdateGameServerClusterOperation {
559	return &UpdateGameServerClusterOperation{
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 *UpdateGameServerClusterOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*gamingpb.GameServerCluster, error) {
568	var resp gamingpb.GameServerCluster
569	if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, 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 *UpdateGameServerClusterOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*gamingpb.GameServerCluster, error) {
585	var resp gamingpb.GameServerCluster
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 *UpdateGameServerClusterOperation) Metadata() (*gamingpb.OperationMetadata, error) {
600	var meta gamingpb.OperationMetadata
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 *UpdateGameServerClusterOperation) 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 *UpdateGameServerClusterOperation) Name() string {
617	return op.lro.Name()
618}
619
620// GameServerClusterIterator manages a stream of *gamingpb.GameServerCluster.
621type GameServerClusterIterator struct {
622	items    []*gamingpb.GameServerCluster
623	pageInfo *iterator.PageInfo
624	nextFunc func() error
625
626	// Response is the raw response for the current page.
627	// It must be cast to the RPC response type.
628	// Calling Next() or InternalFetch() updates this value.
629	Response interface{}
630
631	// InternalFetch is for use by the Google Cloud Libraries only.
632	// It is not part of the stable interface of this package.
633	//
634	// InternalFetch returns results from a single call to the underlying RPC.
635	// The number of results is no greater than pageSize.
636	// If there are no more results, nextPageToken is empty and err is nil.
637	InternalFetch func(pageSize int, pageToken string) (results []*gamingpb.GameServerCluster, nextPageToken string, err error)
638}
639
640// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
641func (it *GameServerClusterIterator) PageInfo() *iterator.PageInfo {
642	return it.pageInfo
643}
644
645// Next returns the next result. Its second return value is iterator.Done if there are no more
646// results. Once Next returns Done, all subsequent calls will return Done.
647func (it *GameServerClusterIterator) Next() (*gamingpb.GameServerCluster, error) {
648	var item *gamingpb.GameServerCluster
649	if err := it.nextFunc(); err != nil {
650		return item, err
651	}
652	item = it.items[0]
653	it.items = it.items[1:]
654	return item, nil
655}
656
657func (it *GameServerClusterIterator) bufLen() int {
658	return len(it.items)
659}
660
661func (it *GameServerClusterIterator) takeBuf() interface{} {
662	b := it.items
663	it.items = nil
664	return b
665}
666