1// Copyright 2021 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 database
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	iampb "google.golang.org/genproto/googleapis/iam/v1"
35	longrunningpb "google.golang.org/genproto/googleapis/longrunning"
36	databasepb "google.golang.org/genproto/googleapis/spanner/admin/database/v1"
37	"google.golang.org/grpc"
38	"google.golang.org/grpc/codes"
39	"google.golang.org/grpc/metadata"
40)
41
42var newDatabaseAdminClientHook clientHook
43
44// DatabaseAdminCallOptions contains the retry settings for each method of DatabaseAdminClient.
45type DatabaseAdminCallOptions struct {
46	ListDatabases          []gax.CallOption
47	CreateDatabase         []gax.CallOption
48	GetDatabase            []gax.CallOption
49	UpdateDatabaseDdl      []gax.CallOption
50	DropDatabase           []gax.CallOption
51	GetDatabaseDdl         []gax.CallOption
52	SetIamPolicy           []gax.CallOption
53	GetIamPolicy           []gax.CallOption
54	TestIamPermissions     []gax.CallOption
55	CreateBackup           []gax.CallOption
56	GetBackup              []gax.CallOption
57	UpdateBackup           []gax.CallOption
58	DeleteBackup           []gax.CallOption
59	ListBackups            []gax.CallOption
60	RestoreDatabase        []gax.CallOption
61	ListDatabaseOperations []gax.CallOption
62	ListBackupOperations   []gax.CallOption
63}
64
65func defaultDatabaseAdminGRPCClientOptions() []option.ClientOption {
66	return []option.ClientOption{
67		internaloption.WithDefaultEndpoint("spanner.googleapis.com:443"),
68		internaloption.WithDefaultMTLSEndpoint("spanner.mtls.googleapis.com:443"),
69		internaloption.WithDefaultAudience("https://spanner.googleapis.com/"),
70		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
71		option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),
72		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
73			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
74	}
75}
76
77func defaultDatabaseAdminCallOptions() *DatabaseAdminCallOptions {
78	return &DatabaseAdminCallOptions{
79		ListDatabases: []gax.CallOption{
80			gax.WithRetry(func() gax.Retryer {
81				return gax.OnCodes([]codes.Code{
82					codes.Unavailable,
83					codes.DeadlineExceeded,
84				}, gax.Backoff{
85					Initial:    1000 * time.Millisecond,
86					Max:        32000 * time.Millisecond,
87					Multiplier: 1.30,
88				})
89			}),
90		},
91		CreateDatabase: []gax.CallOption{},
92		GetDatabase: []gax.CallOption{
93			gax.WithRetry(func() gax.Retryer {
94				return gax.OnCodes([]codes.Code{
95					codes.Unavailable,
96					codes.DeadlineExceeded,
97				}, gax.Backoff{
98					Initial:    1000 * time.Millisecond,
99					Max:        32000 * time.Millisecond,
100					Multiplier: 1.30,
101				})
102			}),
103		},
104		UpdateDatabaseDdl: []gax.CallOption{
105			gax.WithRetry(func() gax.Retryer {
106				return gax.OnCodes([]codes.Code{
107					codes.Unavailable,
108					codes.DeadlineExceeded,
109				}, gax.Backoff{
110					Initial:    1000 * time.Millisecond,
111					Max:        32000 * time.Millisecond,
112					Multiplier: 1.30,
113				})
114			}),
115		},
116		DropDatabase: []gax.CallOption{
117			gax.WithRetry(func() gax.Retryer {
118				return gax.OnCodes([]codes.Code{
119					codes.Unavailable,
120					codes.DeadlineExceeded,
121				}, gax.Backoff{
122					Initial:    1000 * time.Millisecond,
123					Max:        32000 * time.Millisecond,
124					Multiplier: 1.30,
125				})
126			}),
127		},
128		GetDatabaseDdl: []gax.CallOption{
129			gax.WithRetry(func() gax.Retryer {
130				return gax.OnCodes([]codes.Code{
131					codes.Unavailable,
132					codes.DeadlineExceeded,
133				}, gax.Backoff{
134					Initial:    1000 * time.Millisecond,
135					Max:        32000 * time.Millisecond,
136					Multiplier: 1.30,
137				})
138			}),
139		},
140		SetIamPolicy: []gax.CallOption{},
141		GetIamPolicy: []gax.CallOption{
142			gax.WithRetry(func() gax.Retryer {
143				return gax.OnCodes([]codes.Code{
144					codes.Unavailable,
145					codes.DeadlineExceeded,
146				}, gax.Backoff{
147					Initial:    1000 * time.Millisecond,
148					Max:        32000 * time.Millisecond,
149					Multiplier: 1.30,
150				})
151			}),
152		},
153		TestIamPermissions: []gax.CallOption{},
154		CreateBackup:       []gax.CallOption{},
155		GetBackup: []gax.CallOption{
156			gax.WithRetry(func() gax.Retryer {
157				return gax.OnCodes([]codes.Code{
158					codes.Unavailable,
159					codes.DeadlineExceeded,
160				}, gax.Backoff{
161					Initial:    1000 * time.Millisecond,
162					Max:        32000 * time.Millisecond,
163					Multiplier: 1.30,
164				})
165			}),
166		},
167		UpdateBackup: []gax.CallOption{
168			gax.WithRetry(func() gax.Retryer {
169				return gax.OnCodes([]codes.Code{
170					codes.Unavailable,
171					codes.DeadlineExceeded,
172				}, gax.Backoff{
173					Initial:    1000 * time.Millisecond,
174					Max:        32000 * time.Millisecond,
175					Multiplier: 1.30,
176				})
177			}),
178		},
179		DeleteBackup: []gax.CallOption{
180			gax.WithRetry(func() gax.Retryer {
181				return gax.OnCodes([]codes.Code{
182					codes.Unavailable,
183					codes.DeadlineExceeded,
184				}, gax.Backoff{
185					Initial:    1000 * time.Millisecond,
186					Max:        32000 * time.Millisecond,
187					Multiplier: 1.30,
188				})
189			}),
190		},
191		ListBackups: []gax.CallOption{
192			gax.WithRetry(func() gax.Retryer {
193				return gax.OnCodes([]codes.Code{
194					codes.Unavailable,
195					codes.DeadlineExceeded,
196				}, gax.Backoff{
197					Initial:    1000 * time.Millisecond,
198					Max:        32000 * time.Millisecond,
199					Multiplier: 1.30,
200				})
201			}),
202		},
203		RestoreDatabase: []gax.CallOption{},
204		ListDatabaseOperations: []gax.CallOption{
205			gax.WithRetry(func() gax.Retryer {
206				return gax.OnCodes([]codes.Code{
207					codes.Unavailable,
208					codes.DeadlineExceeded,
209				}, gax.Backoff{
210					Initial:    1000 * time.Millisecond,
211					Max:        32000 * time.Millisecond,
212					Multiplier: 1.30,
213				})
214			}),
215		},
216		ListBackupOperations: []gax.CallOption{
217			gax.WithRetry(func() gax.Retryer {
218				return gax.OnCodes([]codes.Code{
219					codes.Unavailable,
220					codes.DeadlineExceeded,
221				}, gax.Backoff{
222					Initial:    1000 * time.Millisecond,
223					Max:        32000 * time.Millisecond,
224					Multiplier: 1.30,
225				})
226			}),
227		},
228	}
229}
230
231// internalDatabaseAdminClient is an interface that defines the methods availaible from Cloud Spanner Database Admin API.
232type internalDatabaseAdminClient interface {
233	Close() error
234	setGoogleClientInfo(...string)
235	Connection() *grpc.ClientConn
236	ListDatabases(context.Context, *databasepb.ListDatabasesRequest, ...gax.CallOption) *DatabaseIterator
237	CreateDatabase(context.Context, *databasepb.CreateDatabaseRequest, ...gax.CallOption) (*CreateDatabaseOperation, error)
238	CreateDatabaseOperation(name string) *CreateDatabaseOperation
239	GetDatabase(context.Context, *databasepb.GetDatabaseRequest, ...gax.CallOption) (*databasepb.Database, error)
240	UpdateDatabaseDdl(context.Context, *databasepb.UpdateDatabaseDdlRequest, ...gax.CallOption) (*UpdateDatabaseDdlOperation, error)
241	UpdateDatabaseDdlOperation(name string) *UpdateDatabaseDdlOperation
242	DropDatabase(context.Context, *databasepb.DropDatabaseRequest, ...gax.CallOption) error
243	GetDatabaseDdl(context.Context, *databasepb.GetDatabaseDdlRequest, ...gax.CallOption) (*databasepb.GetDatabaseDdlResponse, error)
244	SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
245	GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
246	TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
247	CreateBackup(context.Context, *databasepb.CreateBackupRequest, ...gax.CallOption) (*CreateBackupOperation, error)
248	CreateBackupOperation(name string) *CreateBackupOperation
249	GetBackup(context.Context, *databasepb.GetBackupRequest, ...gax.CallOption) (*databasepb.Backup, error)
250	UpdateBackup(context.Context, *databasepb.UpdateBackupRequest, ...gax.CallOption) (*databasepb.Backup, error)
251	DeleteBackup(context.Context, *databasepb.DeleteBackupRequest, ...gax.CallOption) error
252	ListBackups(context.Context, *databasepb.ListBackupsRequest, ...gax.CallOption) *BackupIterator
253	RestoreDatabase(context.Context, *databasepb.RestoreDatabaseRequest, ...gax.CallOption) (*RestoreDatabaseOperation, error)
254	RestoreDatabaseOperation(name string) *RestoreDatabaseOperation
255	ListDatabaseOperations(context.Context, *databasepb.ListDatabaseOperationsRequest, ...gax.CallOption) *OperationIterator
256	ListBackupOperations(context.Context, *databasepb.ListBackupOperationsRequest, ...gax.CallOption) *OperationIterator
257}
258
259// DatabaseAdminClient is a client for interacting with Cloud Spanner Database Admin API.
260// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
261//
262// Cloud Spanner Database Admin API
263//
264// The Cloud Spanner Database Admin API can be used to create, drop, and
265// list databases. It also enables updating the schema of pre-existing
266// databases. It can be also used to create, delete and list backups for a
267// database and to restore from an existing backup.
268type DatabaseAdminClient struct {
269	// The internal transport-dependent client.
270	internalClient internalDatabaseAdminClient
271
272	// The call options for this service.
273	CallOptions *DatabaseAdminCallOptions
274
275	// LROClient is used internally to handle long-running operations.
276	// It is exposed so that its CallOptions can be modified if required.
277	// Users should not Close this client.
278	LROClient *lroauto.OperationsClient
279}
280
281// Wrapper methods routed to the internal client.
282
283// Close closes the connection to the API service. The user should invoke this when
284// the client is no longer required.
285func (c *DatabaseAdminClient) Close() error {
286	return c.internalClient.Close()
287}
288
289// setGoogleClientInfo sets the name and version of the application in
290// the `x-goog-api-client` header passed on each request. Intended for
291// use by Google-written clients.
292func (c *DatabaseAdminClient) setGoogleClientInfo(keyval ...string) {
293	c.internalClient.setGoogleClientInfo(keyval...)
294}
295
296// Connection returns a connection to the API service.
297//
298// Deprecated.
299func (c *DatabaseAdminClient) Connection() *grpc.ClientConn {
300	return c.internalClient.Connection()
301}
302
303// ListDatabases lists Cloud Spanner databases.
304func (c *DatabaseAdminClient) ListDatabases(ctx context.Context, req *databasepb.ListDatabasesRequest, opts ...gax.CallOption) *DatabaseIterator {
305	return c.internalClient.ListDatabases(ctx, req, opts...)
306}
307
308// CreateDatabase creates a new Cloud Spanner database and starts to prepare it for serving.
309// The returned [long-running operation][google.longrunning.Operation] will
310// have a name of the format <database_name>/operations/<operation_id> and
311// can be used to track preparation of the database. The
312// metadata field type is
313// CreateDatabaseMetadata. The
314// response field type is
315// Database, if successful.
316func (c *DatabaseAdminClient) CreateDatabase(ctx context.Context, req *databasepb.CreateDatabaseRequest, opts ...gax.CallOption) (*CreateDatabaseOperation, error) {
317	return c.internalClient.CreateDatabase(ctx, req, opts...)
318}
319
320// CreateDatabaseOperation returns a new CreateDatabaseOperation from a given name.
321// The name must be that of a previously created CreateDatabaseOperation, possibly from a different process.
322func (c *DatabaseAdminClient) CreateDatabaseOperation(name string) *CreateDatabaseOperation {
323	return c.internalClient.CreateDatabaseOperation(name)
324}
325
326// GetDatabase gets the state of a Cloud Spanner database.
327func (c *DatabaseAdminClient) GetDatabase(ctx context.Context, req *databasepb.GetDatabaseRequest, opts ...gax.CallOption) (*databasepb.Database, error) {
328	return c.internalClient.GetDatabase(ctx, req, opts...)
329}
330
331// UpdateDatabaseDdl updates the schema of a Cloud Spanner database by
332// creating/altering/dropping tables, columns, indexes, etc. The returned
333// [long-running operation][google.longrunning.Operation] will have a name of
334// the format <database_name>/operations/<operation_id> and can be used to
335// track execution of the schema change(s). The
336// metadata field type is
337// UpdateDatabaseDdlMetadata.  The operation has no response.
338func (c *DatabaseAdminClient) UpdateDatabaseDdl(ctx context.Context, req *databasepb.UpdateDatabaseDdlRequest, opts ...gax.CallOption) (*UpdateDatabaseDdlOperation, error) {
339	return c.internalClient.UpdateDatabaseDdl(ctx, req, opts...)
340}
341
342// UpdateDatabaseDdlOperation returns a new UpdateDatabaseDdlOperation from a given name.
343// The name must be that of a previously created UpdateDatabaseDdlOperation, possibly from a different process.
344func (c *DatabaseAdminClient) UpdateDatabaseDdlOperation(name string) *UpdateDatabaseDdlOperation {
345	return c.internalClient.UpdateDatabaseDdlOperation(name)
346}
347
348// DropDatabase drops (aka deletes) a Cloud Spanner database.
349// Completed backups for the database will be retained according to their
350// expire_time.
351func (c *DatabaseAdminClient) DropDatabase(ctx context.Context, req *databasepb.DropDatabaseRequest, opts ...gax.CallOption) error {
352	return c.internalClient.DropDatabase(ctx, req, opts...)
353}
354
355// GetDatabaseDdl returns the schema of a Cloud Spanner database as a list of formatted
356// DDL statements. This method does not show pending schema updates, those may
357// be queried using the Operations API.
358func (c *DatabaseAdminClient) GetDatabaseDdl(ctx context.Context, req *databasepb.GetDatabaseDdlRequest, opts ...gax.CallOption) (*databasepb.GetDatabaseDdlResponse, error) {
359	return c.internalClient.GetDatabaseDdl(ctx, req, opts...)
360}
361
362// SetIamPolicy sets the access control policy on a database or backup resource.
363// Replaces any existing policy.
364//
365// Authorization requires spanner.databases.setIamPolicy
366// permission on resource.
367// For backups, authorization requires spanner.backups.setIamPolicy
368// permission on resource.
369func (c *DatabaseAdminClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
370	return c.internalClient.SetIamPolicy(ctx, req, opts...)
371}
372
373// GetIamPolicy gets the access control policy for a database or backup resource.
374// Returns an empty policy if a database or backup exists but does not have a
375// policy set.
376//
377// Authorization requires spanner.databases.getIamPolicy permission on
378// resource.
379// For backups, authorization requires spanner.backups.getIamPolicy
380// permission on resource.
381func (c *DatabaseAdminClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
382	return c.internalClient.GetIamPolicy(ctx, req, opts...)
383}
384
385// TestIamPermissions returns permissions that the caller has on the specified database or backup
386// resource.
387//
388// Attempting this RPC on a non-existent Cloud Spanner database will
389// result in a NOT_FOUND error if the user has
390// spanner.databases.list permission on the containing Cloud
391// Spanner instance. Otherwise returns an empty set of permissions.
392// Calling this method on a backup that does not exist will
393// result in a NOT_FOUND error if the user has
394// spanner.backups.list permission on the containing instance.
395func (c *DatabaseAdminClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
396	return c.internalClient.TestIamPermissions(ctx, req, opts...)
397}
398
399// CreateBackup starts creating a new Cloud Spanner Backup.
400// The returned backup [long-running operation][google.longrunning.Operation]
401// will have a name of the format
402// projects/<project>/instances/<instance>/backups/<backup>/operations/<operation_id>
403// and can be used to track creation of the backup. The
404// metadata field type is
405// CreateBackupMetadata. The
406// response field type is
407// Backup, if successful. Cancelling the returned operation will stop the
408// creation and delete the backup.
409// There can be only one pending backup creation per database. Backup creation
410// of different databases can run concurrently.
411func (c *DatabaseAdminClient) CreateBackup(ctx context.Context, req *databasepb.CreateBackupRequest, opts ...gax.CallOption) (*CreateBackupOperation, error) {
412	return c.internalClient.CreateBackup(ctx, req, opts...)
413}
414
415// CreateBackupOperation returns a new CreateBackupOperation from a given name.
416// The name must be that of a previously created CreateBackupOperation, possibly from a different process.
417func (c *DatabaseAdminClient) CreateBackupOperation(name string) *CreateBackupOperation {
418	return c.internalClient.CreateBackupOperation(name)
419}
420
421// GetBackup gets metadata on a pending or completed Backup.
422func (c *DatabaseAdminClient) GetBackup(ctx context.Context, req *databasepb.GetBackupRequest, opts ...gax.CallOption) (*databasepb.Backup, error) {
423	return c.internalClient.GetBackup(ctx, req, opts...)
424}
425
426// UpdateBackup updates a pending or completed Backup.
427func (c *DatabaseAdminClient) UpdateBackup(ctx context.Context, req *databasepb.UpdateBackupRequest, opts ...gax.CallOption) (*databasepb.Backup, error) {
428	return c.internalClient.UpdateBackup(ctx, req, opts...)
429}
430
431// DeleteBackup deletes a pending or completed Backup.
432func (c *DatabaseAdminClient) DeleteBackup(ctx context.Context, req *databasepb.DeleteBackupRequest, opts ...gax.CallOption) error {
433	return c.internalClient.DeleteBackup(ctx, req, opts...)
434}
435
436// ListBackups lists completed and pending backups.
437// Backups returned are ordered by create_time in descending order,
438// starting from the most recent create_time.
439func (c *DatabaseAdminClient) ListBackups(ctx context.Context, req *databasepb.ListBackupsRequest, opts ...gax.CallOption) *BackupIterator {
440	return c.internalClient.ListBackups(ctx, req, opts...)
441}
442
443// RestoreDatabase create a new database by restoring from a completed backup. The new
444// database must be in the same project and in an instance with the same
445// instance configuration as the instance containing
446// the backup. The returned database [long-running
447// operation][google.longrunning.Operation] has a name of the format
448// projects/<project>/instances/<instance>/databases/<database>/operations/<operation_id>,
449// and can be used to track the progress of the operation, and to cancel it.
450// The metadata field type is
451// RestoreDatabaseMetadata.
452// The response type
453// is Database, if
454// successful. Cancelling the returned operation will stop the restore and
455// delete the database.
456// There can be only one database being restored into an instance at a time.
457// Once the restore operation completes, a new restore operation can be
458// initiated, without waiting for the optimize operation associated with the
459// first restore to complete.
460func (c *DatabaseAdminClient) RestoreDatabase(ctx context.Context, req *databasepb.RestoreDatabaseRequest, opts ...gax.CallOption) (*RestoreDatabaseOperation, error) {
461	return c.internalClient.RestoreDatabase(ctx, req, opts...)
462}
463
464// RestoreDatabaseOperation returns a new RestoreDatabaseOperation from a given name.
465// The name must be that of a previously created RestoreDatabaseOperation, possibly from a different process.
466func (c *DatabaseAdminClient) RestoreDatabaseOperation(name string) *RestoreDatabaseOperation {
467	return c.internalClient.RestoreDatabaseOperation(name)
468}
469
470// ListDatabaseOperations lists database [longrunning-operations][google.longrunning.Operation].
471// A database operation has a name of the form
472// projects/<project>/instances/<instance>/databases/<database>/operations/<operation>.
473// The long-running operation
474// metadata field type
475// metadata.type_url describes the type of the metadata. Operations returned
476// include those that have completed/failed/canceled within the last 7 days,
477// and pending operations.
478func (c *DatabaseAdminClient) ListDatabaseOperations(ctx context.Context, req *databasepb.ListDatabaseOperationsRequest, opts ...gax.CallOption) *OperationIterator {
479	return c.internalClient.ListDatabaseOperations(ctx, req, opts...)
480}
481
482// ListBackupOperations lists the backup [long-running operations][google.longrunning.Operation] in
483// the given instance. A backup operation has a name of the form
484// projects/<project>/instances/<instance>/backups/<backup>/operations/<operation>.
485// The long-running operation
486// metadata field type
487// metadata.type_url describes the type of the metadata. Operations returned
488// include those that have completed/failed/canceled within the last 7 days,
489// and pending operations. Operations returned are ordered by
490// operation.metadata.value.progress.start_time in descending order starting
491// from the most recently started operation.
492func (c *DatabaseAdminClient) ListBackupOperations(ctx context.Context, req *databasepb.ListBackupOperationsRequest, opts ...gax.CallOption) *OperationIterator {
493	return c.internalClient.ListBackupOperations(ctx, req, opts...)
494}
495
496// databaseAdminGRPCClient is a client for interacting with Cloud Spanner Database Admin API over gRPC transport.
497//
498// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
499type databaseAdminGRPCClient struct {
500	// Connection pool of gRPC connections to the service.
501	connPool gtransport.ConnPool
502
503	// flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE
504	disableDeadlines bool
505
506	// Points back to the CallOptions field of the containing DatabaseAdminClient
507	CallOptions **DatabaseAdminCallOptions
508
509	// The gRPC API client.
510	databaseAdminClient databasepb.DatabaseAdminClient
511
512	// LROClient is used internally to handle long-running operations.
513	// It is exposed so that its CallOptions can be modified if required.
514	// Users should not Close this client.
515	LROClient **lroauto.OperationsClient
516
517	// The x-goog-* metadata to be sent with each request.
518	xGoogMetadata metadata.MD
519}
520
521// NewDatabaseAdminClient creates a new database admin client based on gRPC.
522// The returned client must be Closed when it is done being used to clean up its underlying connections.
523//
524// Cloud Spanner Database Admin API
525//
526// The Cloud Spanner Database Admin API can be used to create, drop, and
527// list databases. It also enables updating the schema of pre-existing
528// databases. It can be also used to create, delete and list backups for a
529// database and to restore from an existing backup.
530func NewDatabaseAdminClient(ctx context.Context, opts ...option.ClientOption) (*DatabaseAdminClient, error) {
531	clientOpts := defaultDatabaseAdminGRPCClientOptions()
532	if newDatabaseAdminClientHook != nil {
533		hookOpts, err := newDatabaseAdminClientHook(ctx, clientHookParams{})
534		if err != nil {
535			return nil, err
536		}
537		clientOpts = append(clientOpts, hookOpts...)
538	}
539
540	disableDeadlines, err := checkDisableDeadlines()
541	if err != nil {
542		return nil, err
543	}
544
545	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
546	if err != nil {
547		return nil, err
548	}
549	client := DatabaseAdminClient{CallOptions: defaultDatabaseAdminCallOptions()}
550
551	c := &databaseAdminGRPCClient{
552		connPool:            connPool,
553		disableDeadlines:    disableDeadlines,
554		databaseAdminClient: databasepb.NewDatabaseAdminClient(connPool),
555		CallOptions:         &client.CallOptions,
556	}
557	c.setGoogleClientInfo()
558
559	client.internalClient = c
560
561	client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
562	if err != nil {
563		// This error "should not happen", since we are just reusing old connection pool
564		// and never actually need to dial.
565		// If this does happen, we could leak connp. However, we cannot close conn:
566		// If the user invoked the constructor with option.WithGRPCConn,
567		// we would close a connection that's still in use.
568		// TODO: investigate error conditions.
569		return nil, err
570	}
571	c.LROClient = &client.LROClient
572	return &client, nil
573}
574
575// Connection returns a connection to the API service.
576//
577// Deprecated.
578func (c *databaseAdminGRPCClient) Connection() *grpc.ClientConn {
579	return c.connPool.Conn()
580}
581
582// setGoogleClientInfo sets the name and version of the application in
583// the `x-goog-api-client` header passed on each request. Intended for
584// use by Google-written clients.
585func (c *databaseAdminGRPCClient) setGoogleClientInfo(keyval ...string) {
586	kv := append([]string{"gl-go", versionGo()}, keyval...)
587	kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
588	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
589}
590
591// Close closes the connection to the API service. The user should invoke this when
592// the client is no longer required.
593func (c *databaseAdminGRPCClient) Close() error {
594	return c.connPool.Close()
595}
596
597func (c *databaseAdminGRPCClient) ListDatabases(ctx context.Context, req *databasepb.ListDatabasesRequest, opts ...gax.CallOption) *DatabaseIterator {
598	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
599	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
600	opts = append((*c.CallOptions).ListDatabases[0:len((*c.CallOptions).ListDatabases):len((*c.CallOptions).ListDatabases)], opts...)
601	it := &DatabaseIterator{}
602	req = proto.Clone(req).(*databasepb.ListDatabasesRequest)
603	it.InternalFetch = func(pageSize int, pageToken string) ([]*databasepb.Database, string, error) {
604		var resp *databasepb.ListDatabasesResponse
605		req.PageToken = pageToken
606		if pageSize > math.MaxInt32 {
607			req.PageSize = math.MaxInt32
608		} else {
609			req.PageSize = int32(pageSize)
610		}
611		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
612			var err error
613			resp, err = c.databaseAdminClient.ListDatabases(ctx, req, settings.GRPC...)
614			return err
615		}, opts...)
616		if err != nil {
617			return nil, "", err
618		}
619
620		it.Response = resp
621		return resp.GetDatabases(), resp.GetNextPageToken(), nil
622	}
623	fetch := func(pageSize int, pageToken string) (string, error) {
624		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
625		if err != nil {
626			return "", err
627		}
628		it.items = append(it.items, items...)
629		return nextPageToken, nil
630	}
631	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
632	it.pageInfo.MaxSize = int(req.GetPageSize())
633	it.pageInfo.Token = req.GetPageToken()
634	return it
635}
636
637func (c *databaseAdminGRPCClient) CreateDatabase(ctx context.Context, req *databasepb.CreateDatabaseRequest, opts ...gax.CallOption) (*CreateDatabaseOperation, error) {
638	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
639		cctx, cancel := context.WithTimeout(ctx, 3600000*time.Millisecond)
640		defer cancel()
641		ctx = cctx
642	}
643	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
644	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
645	opts = append((*c.CallOptions).CreateDatabase[0:len((*c.CallOptions).CreateDatabase):len((*c.CallOptions).CreateDatabase)], opts...)
646	var resp *longrunningpb.Operation
647	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
648		var err error
649		resp, err = c.databaseAdminClient.CreateDatabase(ctx, req, settings.GRPC...)
650		return err
651	}, opts...)
652	if err != nil {
653		return nil, err
654	}
655	return &CreateDatabaseOperation{
656		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
657	}, nil
658}
659
660func (c *databaseAdminGRPCClient) GetDatabase(ctx context.Context, req *databasepb.GetDatabaseRequest, opts ...gax.CallOption) (*databasepb.Database, error) {
661	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
662		cctx, cancel := context.WithTimeout(ctx, 3600000*time.Millisecond)
663		defer cancel()
664		ctx = cctx
665	}
666	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
667	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
668	opts = append((*c.CallOptions).GetDatabase[0:len((*c.CallOptions).GetDatabase):len((*c.CallOptions).GetDatabase)], opts...)
669	var resp *databasepb.Database
670	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
671		var err error
672		resp, err = c.databaseAdminClient.GetDatabase(ctx, req, settings.GRPC...)
673		return err
674	}, opts...)
675	if err != nil {
676		return nil, err
677	}
678	return resp, nil
679}
680
681func (c *databaseAdminGRPCClient) UpdateDatabaseDdl(ctx context.Context, req *databasepb.UpdateDatabaseDdlRequest, opts ...gax.CallOption) (*UpdateDatabaseDdlOperation, error) {
682	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
683		cctx, cancel := context.WithTimeout(ctx, 3600000*time.Millisecond)
684		defer cancel()
685		ctx = cctx
686	}
687	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "database", url.QueryEscape(req.GetDatabase())))
688	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
689	opts = append((*c.CallOptions).UpdateDatabaseDdl[0:len((*c.CallOptions).UpdateDatabaseDdl):len((*c.CallOptions).UpdateDatabaseDdl)], opts...)
690	var resp *longrunningpb.Operation
691	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
692		var err error
693		resp, err = c.databaseAdminClient.UpdateDatabaseDdl(ctx, req, settings.GRPC...)
694		return err
695	}, opts...)
696	if err != nil {
697		return nil, err
698	}
699	return &UpdateDatabaseDdlOperation{
700		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
701	}, nil
702}
703
704func (c *databaseAdminGRPCClient) DropDatabase(ctx context.Context, req *databasepb.DropDatabaseRequest, opts ...gax.CallOption) error {
705	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
706		cctx, cancel := context.WithTimeout(ctx, 3600000*time.Millisecond)
707		defer cancel()
708		ctx = cctx
709	}
710	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "database", url.QueryEscape(req.GetDatabase())))
711	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
712	opts = append((*c.CallOptions).DropDatabase[0:len((*c.CallOptions).DropDatabase):len((*c.CallOptions).DropDatabase)], opts...)
713	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
714		var err error
715		_, err = c.databaseAdminClient.DropDatabase(ctx, req, settings.GRPC...)
716		return err
717	}, opts...)
718	return err
719}
720
721func (c *databaseAdminGRPCClient) GetDatabaseDdl(ctx context.Context, req *databasepb.GetDatabaseDdlRequest, opts ...gax.CallOption) (*databasepb.GetDatabaseDdlResponse, error) {
722	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
723		cctx, cancel := context.WithTimeout(ctx, 3600000*time.Millisecond)
724		defer cancel()
725		ctx = cctx
726	}
727	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "database", url.QueryEscape(req.GetDatabase())))
728	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
729	opts = append((*c.CallOptions).GetDatabaseDdl[0:len((*c.CallOptions).GetDatabaseDdl):len((*c.CallOptions).GetDatabaseDdl)], opts...)
730	var resp *databasepb.GetDatabaseDdlResponse
731	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
732		var err error
733		resp, err = c.databaseAdminClient.GetDatabaseDdl(ctx, req, settings.GRPC...)
734		return err
735	}, opts...)
736	if err != nil {
737		return nil, err
738	}
739	return resp, nil
740}
741
742func (c *databaseAdminGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
743	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
744		cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond)
745		defer cancel()
746		ctx = cctx
747	}
748	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource())))
749	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
750	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
751	var resp *iampb.Policy
752	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
753		var err error
754		resp, err = c.databaseAdminClient.SetIamPolicy(ctx, req, settings.GRPC...)
755		return err
756	}, opts...)
757	if err != nil {
758		return nil, err
759	}
760	return resp, nil
761}
762
763func (c *databaseAdminGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
764	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
765		cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond)
766		defer cancel()
767		ctx = cctx
768	}
769	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource())))
770	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
771	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
772	var resp *iampb.Policy
773	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
774		var err error
775		resp, err = c.databaseAdminClient.GetIamPolicy(ctx, req, settings.GRPC...)
776		return err
777	}, opts...)
778	if err != nil {
779		return nil, err
780	}
781	return resp, nil
782}
783
784func (c *databaseAdminGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
785	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
786		cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond)
787		defer cancel()
788		ctx = cctx
789	}
790	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource())))
791	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
792	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
793	var resp *iampb.TestIamPermissionsResponse
794	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
795		var err error
796		resp, err = c.databaseAdminClient.TestIamPermissions(ctx, req, settings.GRPC...)
797		return err
798	}, opts...)
799	if err != nil {
800		return nil, err
801	}
802	return resp, nil
803}
804
805func (c *databaseAdminGRPCClient) CreateBackup(ctx context.Context, req *databasepb.CreateBackupRequest, opts ...gax.CallOption) (*CreateBackupOperation, error) {
806	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
807		cctx, cancel := context.WithTimeout(ctx, 3600000*time.Millisecond)
808		defer cancel()
809		ctx = cctx
810	}
811	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
812	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
813	opts = append((*c.CallOptions).CreateBackup[0:len((*c.CallOptions).CreateBackup):len((*c.CallOptions).CreateBackup)], opts...)
814	var resp *longrunningpb.Operation
815	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
816		var err error
817		resp, err = c.databaseAdminClient.CreateBackup(ctx, req, settings.GRPC...)
818		return err
819	}, opts...)
820	if err != nil {
821		return nil, err
822	}
823	return &CreateBackupOperation{
824		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
825	}, nil
826}
827
828func (c *databaseAdminGRPCClient) GetBackup(ctx context.Context, req *databasepb.GetBackupRequest, opts ...gax.CallOption) (*databasepb.Backup, error) {
829	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
830		cctx, cancel := context.WithTimeout(ctx, 3600000*time.Millisecond)
831		defer cancel()
832		ctx = cctx
833	}
834	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
835	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
836	opts = append((*c.CallOptions).GetBackup[0:len((*c.CallOptions).GetBackup):len((*c.CallOptions).GetBackup)], opts...)
837	var resp *databasepb.Backup
838	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
839		var err error
840		resp, err = c.databaseAdminClient.GetBackup(ctx, req, settings.GRPC...)
841		return err
842	}, opts...)
843	if err != nil {
844		return nil, err
845	}
846	return resp, nil
847}
848
849func (c *databaseAdminGRPCClient) UpdateBackup(ctx context.Context, req *databasepb.UpdateBackupRequest, opts ...gax.CallOption) (*databasepb.Backup, error) {
850	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
851		cctx, cancel := context.WithTimeout(ctx, 3600000*time.Millisecond)
852		defer cancel()
853		ctx = cctx
854	}
855	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "backup.name", url.QueryEscape(req.GetBackup().GetName())))
856	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
857	opts = append((*c.CallOptions).UpdateBackup[0:len((*c.CallOptions).UpdateBackup):len((*c.CallOptions).UpdateBackup)], opts...)
858	var resp *databasepb.Backup
859	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
860		var err error
861		resp, err = c.databaseAdminClient.UpdateBackup(ctx, req, settings.GRPC...)
862		return err
863	}, opts...)
864	if err != nil {
865		return nil, err
866	}
867	return resp, nil
868}
869
870func (c *databaseAdminGRPCClient) DeleteBackup(ctx context.Context, req *databasepb.DeleteBackupRequest, opts ...gax.CallOption) error {
871	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
872		cctx, cancel := context.WithTimeout(ctx, 3600000*time.Millisecond)
873		defer cancel()
874		ctx = cctx
875	}
876	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
877	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
878	opts = append((*c.CallOptions).DeleteBackup[0:len((*c.CallOptions).DeleteBackup):len((*c.CallOptions).DeleteBackup)], opts...)
879	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
880		var err error
881		_, err = c.databaseAdminClient.DeleteBackup(ctx, req, settings.GRPC...)
882		return err
883	}, opts...)
884	return err
885}
886
887func (c *databaseAdminGRPCClient) ListBackups(ctx context.Context, req *databasepb.ListBackupsRequest, opts ...gax.CallOption) *BackupIterator {
888	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
889	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
890	opts = append((*c.CallOptions).ListBackups[0:len((*c.CallOptions).ListBackups):len((*c.CallOptions).ListBackups)], opts...)
891	it := &BackupIterator{}
892	req = proto.Clone(req).(*databasepb.ListBackupsRequest)
893	it.InternalFetch = func(pageSize int, pageToken string) ([]*databasepb.Backup, string, error) {
894		var resp *databasepb.ListBackupsResponse
895		req.PageToken = pageToken
896		if pageSize > math.MaxInt32 {
897			req.PageSize = math.MaxInt32
898		} else {
899			req.PageSize = int32(pageSize)
900		}
901		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
902			var err error
903			resp, err = c.databaseAdminClient.ListBackups(ctx, req, settings.GRPC...)
904			return err
905		}, opts...)
906		if err != nil {
907			return nil, "", err
908		}
909
910		it.Response = resp
911		return resp.GetBackups(), resp.GetNextPageToken(), nil
912	}
913	fetch := func(pageSize int, pageToken string) (string, error) {
914		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
915		if err != nil {
916			return "", err
917		}
918		it.items = append(it.items, items...)
919		return nextPageToken, nil
920	}
921	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
922	it.pageInfo.MaxSize = int(req.GetPageSize())
923	it.pageInfo.Token = req.GetPageToken()
924	return it
925}
926
927func (c *databaseAdminGRPCClient) RestoreDatabase(ctx context.Context, req *databasepb.RestoreDatabaseRequest, opts ...gax.CallOption) (*RestoreDatabaseOperation, error) {
928	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
929		cctx, cancel := context.WithTimeout(ctx, 3600000*time.Millisecond)
930		defer cancel()
931		ctx = cctx
932	}
933	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
934	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
935	opts = append((*c.CallOptions).RestoreDatabase[0:len((*c.CallOptions).RestoreDatabase):len((*c.CallOptions).RestoreDatabase)], opts...)
936	var resp *longrunningpb.Operation
937	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
938		var err error
939		resp, err = c.databaseAdminClient.RestoreDatabase(ctx, req, settings.GRPC...)
940		return err
941	}, opts...)
942	if err != nil {
943		return nil, err
944	}
945	return &RestoreDatabaseOperation{
946		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
947	}, nil
948}
949
950func (c *databaseAdminGRPCClient) ListDatabaseOperations(ctx context.Context, req *databasepb.ListDatabaseOperationsRequest, opts ...gax.CallOption) *OperationIterator {
951	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
952	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
953	opts = append((*c.CallOptions).ListDatabaseOperations[0:len((*c.CallOptions).ListDatabaseOperations):len((*c.CallOptions).ListDatabaseOperations)], opts...)
954	it := &OperationIterator{}
955	req = proto.Clone(req).(*databasepb.ListDatabaseOperationsRequest)
956	it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
957		var resp *databasepb.ListDatabaseOperationsResponse
958		req.PageToken = pageToken
959		if pageSize > math.MaxInt32 {
960			req.PageSize = math.MaxInt32
961		} else {
962			req.PageSize = int32(pageSize)
963		}
964		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
965			var err error
966			resp, err = c.databaseAdminClient.ListDatabaseOperations(ctx, req, settings.GRPC...)
967			return err
968		}, opts...)
969		if err != nil {
970			return nil, "", err
971		}
972
973		it.Response = resp
974		return resp.GetOperations(), resp.GetNextPageToken(), nil
975	}
976	fetch := func(pageSize int, pageToken string) (string, error) {
977		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
978		if err != nil {
979			return "", err
980		}
981		it.items = append(it.items, items...)
982		return nextPageToken, nil
983	}
984	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
985	it.pageInfo.MaxSize = int(req.GetPageSize())
986	it.pageInfo.Token = req.GetPageToken()
987	return it
988}
989
990func (c *databaseAdminGRPCClient) ListBackupOperations(ctx context.Context, req *databasepb.ListBackupOperationsRequest, opts ...gax.CallOption) *OperationIterator {
991	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
992	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
993	opts = append((*c.CallOptions).ListBackupOperations[0:len((*c.CallOptions).ListBackupOperations):len((*c.CallOptions).ListBackupOperations)], opts...)
994	it := &OperationIterator{}
995	req = proto.Clone(req).(*databasepb.ListBackupOperationsRequest)
996	it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
997		var resp *databasepb.ListBackupOperationsResponse
998		req.PageToken = pageToken
999		if pageSize > math.MaxInt32 {
1000			req.PageSize = math.MaxInt32
1001		} else {
1002			req.PageSize = int32(pageSize)
1003		}
1004		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1005			var err error
1006			resp, err = c.databaseAdminClient.ListBackupOperations(ctx, req, settings.GRPC...)
1007			return err
1008		}, opts...)
1009		if err != nil {
1010			return nil, "", err
1011		}
1012
1013		it.Response = resp
1014		return resp.GetOperations(), resp.GetNextPageToken(), nil
1015	}
1016	fetch := func(pageSize int, pageToken string) (string, error) {
1017		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1018		if err != nil {
1019			return "", err
1020		}
1021		it.items = append(it.items, items...)
1022		return nextPageToken, nil
1023	}
1024	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1025	it.pageInfo.MaxSize = int(req.GetPageSize())
1026	it.pageInfo.Token = req.GetPageToken()
1027	return it
1028}
1029
1030// CreateBackupOperation manages a long-running operation from CreateBackup.
1031type CreateBackupOperation struct {
1032	lro *longrunning.Operation
1033}
1034
1035// CreateBackupOperation returns a new CreateBackupOperation from a given name.
1036// The name must be that of a previously created CreateBackupOperation, possibly from a different process.
1037func (c *databaseAdminGRPCClient) CreateBackupOperation(name string) *CreateBackupOperation {
1038	return &CreateBackupOperation{
1039		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1040	}
1041}
1042
1043// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
1044//
1045// See documentation of Poll for error-handling information.
1046func (op *CreateBackupOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*databasepb.Backup, error) {
1047	var resp databasepb.Backup
1048	if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
1049		return nil, err
1050	}
1051	return &resp, nil
1052}
1053
1054// Poll fetches the latest state of the long-running operation.
1055//
1056// Poll also fetches the latest metadata, which can be retrieved by Metadata.
1057//
1058// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
1059// the operation has completed with failure, the error is returned and op.Done will return true.
1060// If Poll succeeds and the operation has completed successfully,
1061// op.Done will return true, and the response of the operation is returned.
1062// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
1063func (op *CreateBackupOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*databasepb.Backup, error) {
1064	var resp databasepb.Backup
1065	if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
1066		return nil, err
1067	}
1068	if !op.Done() {
1069		return nil, nil
1070	}
1071	return &resp, nil
1072}
1073
1074// Metadata returns metadata associated with the long-running operation.
1075// Metadata itself does not contact the server, but Poll does.
1076// To get the latest metadata, call this method after a successful call to Poll.
1077// If the metadata is not available, the returned metadata and error are both nil.
1078func (op *CreateBackupOperation) Metadata() (*databasepb.CreateBackupMetadata, error) {
1079	var meta databasepb.CreateBackupMetadata
1080	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
1081		return nil, nil
1082	} else if err != nil {
1083		return nil, err
1084	}
1085	return &meta, nil
1086}
1087
1088// Done reports whether the long-running operation has completed.
1089func (op *CreateBackupOperation) Done() bool {
1090	return op.lro.Done()
1091}
1092
1093// Name returns the name of the long-running operation.
1094// The name is assigned by the server and is unique within the service from which the operation is created.
1095func (op *CreateBackupOperation) Name() string {
1096	return op.lro.Name()
1097}
1098
1099// CreateDatabaseOperation manages a long-running operation from CreateDatabase.
1100type CreateDatabaseOperation struct {
1101	lro *longrunning.Operation
1102}
1103
1104// CreateDatabaseOperation returns a new CreateDatabaseOperation from a given name.
1105// The name must be that of a previously created CreateDatabaseOperation, possibly from a different process.
1106func (c *databaseAdminGRPCClient) CreateDatabaseOperation(name string) *CreateDatabaseOperation {
1107	return &CreateDatabaseOperation{
1108		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1109	}
1110}
1111
1112// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
1113//
1114// See documentation of Poll for error-handling information.
1115func (op *CreateDatabaseOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error) {
1116	var resp databasepb.Database
1117	if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
1118		return nil, err
1119	}
1120	return &resp, nil
1121}
1122
1123// Poll fetches the latest state of the long-running operation.
1124//
1125// Poll also fetches the latest metadata, which can be retrieved by Metadata.
1126//
1127// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
1128// the operation has completed with failure, the error is returned and op.Done will return true.
1129// If Poll succeeds and the operation has completed successfully,
1130// op.Done will return true, and the response of the operation is returned.
1131// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
1132func (op *CreateDatabaseOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error) {
1133	var resp databasepb.Database
1134	if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
1135		return nil, err
1136	}
1137	if !op.Done() {
1138		return nil, nil
1139	}
1140	return &resp, nil
1141}
1142
1143// Metadata returns metadata associated with the long-running operation.
1144// Metadata itself does not contact the server, but Poll does.
1145// To get the latest metadata, call this method after a successful call to Poll.
1146// If the metadata is not available, the returned metadata and error are both nil.
1147func (op *CreateDatabaseOperation) Metadata() (*databasepb.CreateDatabaseMetadata, error) {
1148	var meta databasepb.CreateDatabaseMetadata
1149	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
1150		return nil, nil
1151	} else if err != nil {
1152		return nil, err
1153	}
1154	return &meta, nil
1155}
1156
1157// Done reports whether the long-running operation has completed.
1158func (op *CreateDatabaseOperation) Done() bool {
1159	return op.lro.Done()
1160}
1161
1162// Name returns the name of the long-running operation.
1163// The name is assigned by the server and is unique within the service from which the operation is created.
1164func (op *CreateDatabaseOperation) Name() string {
1165	return op.lro.Name()
1166}
1167
1168// RestoreDatabaseOperation manages a long-running operation from RestoreDatabase.
1169type RestoreDatabaseOperation struct {
1170	lro *longrunning.Operation
1171}
1172
1173// RestoreDatabaseOperation returns a new RestoreDatabaseOperation from a given name.
1174// The name must be that of a previously created RestoreDatabaseOperation, possibly from a different process.
1175func (c *databaseAdminGRPCClient) RestoreDatabaseOperation(name string) *RestoreDatabaseOperation {
1176	return &RestoreDatabaseOperation{
1177		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1178	}
1179}
1180
1181// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
1182//
1183// See documentation of Poll for error-handling information.
1184func (op *RestoreDatabaseOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error) {
1185	var resp databasepb.Database
1186	if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
1187		return nil, err
1188	}
1189	return &resp, nil
1190}
1191
1192// Poll fetches the latest state of the long-running operation.
1193//
1194// Poll also fetches the latest metadata, which can be retrieved by Metadata.
1195//
1196// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
1197// the operation has completed with failure, the error is returned and op.Done will return true.
1198// If Poll succeeds and the operation has completed successfully,
1199// op.Done will return true, and the response of the operation is returned.
1200// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
1201func (op *RestoreDatabaseOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error) {
1202	var resp databasepb.Database
1203	if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
1204		return nil, err
1205	}
1206	if !op.Done() {
1207		return nil, nil
1208	}
1209	return &resp, nil
1210}
1211
1212// Metadata returns metadata associated with the long-running operation.
1213// Metadata itself does not contact the server, but Poll does.
1214// To get the latest metadata, call this method after a successful call to Poll.
1215// If the metadata is not available, the returned metadata and error are both nil.
1216func (op *RestoreDatabaseOperation) Metadata() (*databasepb.RestoreDatabaseMetadata, error) {
1217	var meta databasepb.RestoreDatabaseMetadata
1218	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
1219		return nil, nil
1220	} else if err != nil {
1221		return nil, err
1222	}
1223	return &meta, nil
1224}
1225
1226// Done reports whether the long-running operation has completed.
1227func (op *RestoreDatabaseOperation) Done() bool {
1228	return op.lro.Done()
1229}
1230
1231// Name returns the name of the long-running operation.
1232// The name is assigned by the server and is unique within the service from which the operation is created.
1233func (op *RestoreDatabaseOperation) Name() string {
1234	return op.lro.Name()
1235}
1236
1237// UpdateDatabaseDdlOperation manages a long-running operation from UpdateDatabaseDdl.
1238type UpdateDatabaseDdlOperation struct {
1239	lro *longrunning.Operation
1240}
1241
1242// UpdateDatabaseDdlOperation returns a new UpdateDatabaseDdlOperation from a given name.
1243// The name must be that of a previously created UpdateDatabaseDdlOperation, possibly from a different process.
1244func (c *databaseAdminGRPCClient) UpdateDatabaseDdlOperation(name string) *UpdateDatabaseDdlOperation {
1245	return &UpdateDatabaseDdlOperation{
1246		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1247	}
1248}
1249
1250// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
1251//
1252// See documentation of Poll for error-handling information.
1253func (op *UpdateDatabaseDdlOperation) Wait(ctx context.Context, opts ...gax.CallOption) error {
1254	return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...)
1255}
1256
1257// Poll fetches the latest state of the long-running operation.
1258//
1259// Poll also fetches the latest metadata, which can be retrieved by Metadata.
1260//
1261// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
1262// the operation has completed with failure, the error is returned and op.Done will return true.
1263// If Poll succeeds and the operation has completed successfully,
1264// op.Done will return true, and the response of the operation is returned.
1265// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
1266func (op *UpdateDatabaseDdlOperation) Poll(ctx context.Context, opts ...gax.CallOption) error {
1267	return op.lro.Poll(ctx, nil, opts...)
1268}
1269
1270// Metadata returns metadata associated with the long-running operation.
1271// Metadata itself does not contact the server, but Poll does.
1272// To get the latest metadata, call this method after a successful call to Poll.
1273// If the metadata is not available, the returned metadata and error are both nil.
1274func (op *UpdateDatabaseDdlOperation) Metadata() (*databasepb.UpdateDatabaseDdlMetadata, error) {
1275	var meta databasepb.UpdateDatabaseDdlMetadata
1276	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
1277		return nil, nil
1278	} else if err != nil {
1279		return nil, err
1280	}
1281	return &meta, nil
1282}
1283
1284// Done reports whether the long-running operation has completed.
1285func (op *UpdateDatabaseDdlOperation) Done() bool {
1286	return op.lro.Done()
1287}
1288
1289// Name returns the name of the long-running operation.
1290// The name is assigned by the server and is unique within the service from which the operation is created.
1291func (op *UpdateDatabaseDdlOperation) Name() string {
1292	return op.lro.Name()
1293}
1294
1295// BackupIterator manages a stream of *databasepb.Backup.
1296type BackupIterator struct {
1297	items    []*databasepb.Backup
1298	pageInfo *iterator.PageInfo
1299	nextFunc func() error
1300
1301	// Response is the raw response for the current page.
1302	// It must be cast to the RPC response type.
1303	// Calling Next() or InternalFetch() updates this value.
1304	Response interface{}
1305
1306	// InternalFetch is for use by the Google Cloud Libraries only.
1307	// It is not part of the stable interface of this package.
1308	//
1309	// InternalFetch returns results from a single call to the underlying RPC.
1310	// The number of results is no greater than pageSize.
1311	// If there are no more results, nextPageToken is empty and err is nil.
1312	InternalFetch func(pageSize int, pageToken string) (results []*databasepb.Backup, nextPageToken string, err error)
1313}
1314
1315// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
1316func (it *BackupIterator) PageInfo() *iterator.PageInfo {
1317	return it.pageInfo
1318}
1319
1320// Next returns the next result. Its second return value is iterator.Done if there are no more
1321// results. Once Next returns Done, all subsequent calls will return Done.
1322func (it *BackupIterator) Next() (*databasepb.Backup, error) {
1323	var item *databasepb.Backup
1324	if err := it.nextFunc(); err != nil {
1325		return item, err
1326	}
1327	item = it.items[0]
1328	it.items = it.items[1:]
1329	return item, nil
1330}
1331
1332func (it *BackupIterator) bufLen() int {
1333	return len(it.items)
1334}
1335
1336func (it *BackupIterator) takeBuf() interface{} {
1337	b := it.items
1338	it.items = nil
1339	return b
1340}
1341
1342// DatabaseIterator manages a stream of *databasepb.Database.
1343type DatabaseIterator struct {
1344	items    []*databasepb.Database
1345	pageInfo *iterator.PageInfo
1346	nextFunc func() error
1347
1348	// Response is the raw response for the current page.
1349	// It must be cast to the RPC response type.
1350	// Calling Next() or InternalFetch() updates this value.
1351	Response interface{}
1352
1353	// InternalFetch is for use by the Google Cloud Libraries only.
1354	// It is not part of the stable interface of this package.
1355	//
1356	// InternalFetch returns results from a single call to the underlying RPC.
1357	// The number of results is no greater than pageSize.
1358	// If there are no more results, nextPageToken is empty and err is nil.
1359	InternalFetch func(pageSize int, pageToken string) (results []*databasepb.Database, nextPageToken string, err error)
1360}
1361
1362// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
1363func (it *DatabaseIterator) PageInfo() *iterator.PageInfo {
1364	return it.pageInfo
1365}
1366
1367// Next returns the next result. Its second return value is iterator.Done if there are no more
1368// results. Once Next returns Done, all subsequent calls will return Done.
1369func (it *DatabaseIterator) Next() (*databasepb.Database, error) {
1370	var item *databasepb.Database
1371	if err := it.nextFunc(); err != nil {
1372		return item, err
1373	}
1374	item = it.items[0]
1375	it.items = it.items[1:]
1376	return item, nil
1377}
1378
1379func (it *DatabaseIterator) bufLen() int {
1380	return len(it.items)
1381}
1382
1383func (it *DatabaseIterator) takeBuf() interface{} {
1384	b := it.items
1385	it.items = nil
1386	return b
1387}
1388
1389// OperationIterator manages a stream of *longrunningpb.Operation.
1390type OperationIterator struct {
1391	items    []*longrunningpb.Operation
1392	pageInfo *iterator.PageInfo
1393	nextFunc func() error
1394
1395	// Response is the raw response for the current page.
1396	// It must be cast to the RPC response type.
1397	// Calling Next() or InternalFetch() updates this value.
1398	Response interface{}
1399
1400	// InternalFetch is for use by the Google Cloud Libraries only.
1401	// It is not part of the stable interface of this package.
1402	//
1403	// InternalFetch returns results from a single call to the underlying RPC.
1404	// The number of results is no greater than pageSize.
1405	// If there are no more results, nextPageToken is empty and err is nil.
1406	InternalFetch func(pageSize int, pageToken string) (results []*longrunningpb.Operation, nextPageToken string, err error)
1407}
1408
1409// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
1410func (it *OperationIterator) PageInfo() *iterator.PageInfo {
1411	return it.pageInfo
1412}
1413
1414// Next returns the next result. Its second return value is iterator.Done if there are no more
1415// results. Once Next returns Done, all subsequent calls will return Done.
1416func (it *OperationIterator) Next() (*longrunningpb.Operation, error) {
1417	var item *longrunningpb.Operation
1418	if err := it.nextFunc(); err != nil {
1419		return item, err
1420	}
1421	item = it.items[0]
1422	it.items = it.items[1:]
1423	return item, nil
1424}
1425
1426func (it *OperationIterator) bufLen() int {
1427	return len(it.items)
1428}
1429
1430func (it *OperationIterator) takeBuf() interface{} {
1431	b := it.items
1432	it.items = nil
1433	return b
1434}
1435