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