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 dataflow
18
19import (
20	"context"
21	"math"
22	"time"
23
24	gax "github.com/googleapis/gax-go/v2"
25	"google.golang.org/api/option"
26	"google.golang.org/api/option/internaloption"
27	gtransport "google.golang.org/api/transport/grpc"
28	dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3"
29	"google.golang.org/grpc"
30	"google.golang.org/grpc/metadata"
31)
32
33var newSnapshotsV1Beta3ClientHook clientHook
34
35// SnapshotsV1Beta3CallOptions contains the retry settings for each method of SnapshotsV1Beta3Client.
36type SnapshotsV1Beta3CallOptions struct {
37	GetSnapshot    []gax.CallOption
38	DeleteSnapshot []gax.CallOption
39	ListSnapshots  []gax.CallOption
40}
41
42func defaultSnapshotsV1Beta3GRPCClientOptions() []option.ClientOption {
43	return []option.ClientOption{
44		internaloption.WithDefaultEndpoint("dataflow.googleapis.com:443"),
45		internaloption.WithDefaultMTLSEndpoint("dataflow.mtls.googleapis.com:443"),
46		internaloption.WithDefaultAudience("https://dataflow.googleapis.com/"),
47		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
48		internaloption.EnableJwtWithScope(),
49		option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),
50		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
51			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
52	}
53}
54
55func defaultSnapshotsV1Beta3CallOptions() *SnapshotsV1Beta3CallOptions {
56	return &SnapshotsV1Beta3CallOptions{
57		GetSnapshot:    []gax.CallOption{},
58		DeleteSnapshot: []gax.CallOption{},
59		ListSnapshots:  []gax.CallOption{},
60	}
61}
62
63// internalSnapshotsV1Beta3Client is an interface that defines the methods availaible from Dataflow API.
64type internalSnapshotsV1Beta3Client interface {
65	Close() error
66	setGoogleClientInfo(...string)
67	Connection() *grpc.ClientConn
68	GetSnapshot(context.Context, *dataflowpb.GetSnapshotRequest, ...gax.CallOption) (*dataflowpb.Snapshot, error)
69	DeleteSnapshot(context.Context, *dataflowpb.DeleteSnapshotRequest, ...gax.CallOption) (*dataflowpb.DeleteSnapshotResponse, error)
70	ListSnapshots(context.Context, *dataflowpb.ListSnapshotsRequest, ...gax.CallOption) (*dataflowpb.ListSnapshotsResponse, error)
71}
72
73// SnapshotsV1Beta3Client is a client for interacting with Dataflow API.
74// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
75//
76// Provides methods to manage snapshots of Google Cloud Dataflow jobs.
77type SnapshotsV1Beta3Client struct {
78	// The internal transport-dependent client.
79	internalClient internalSnapshotsV1Beta3Client
80
81	// The call options for this service.
82	CallOptions *SnapshotsV1Beta3CallOptions
83}
84
85// Wrapper methods routed to the internal client.
86
87// Close closes the connection to the API service. The user should invoke this when
88// the client is no longer required.
89func (c *SnapshotsV1Beta3Client) Close() error {
90	return c.internalClient.Close()
91}
92
93// setGoogleClientInfo sets the name and version of the application in
94// the `x-goog-api-client` header passed on each request. Intended for
95// use by Google-written clients.
96func (c *SnapshotsV1Beta3Client) setGoogleClientInfo(keyval ...string) {
97	c.internalClient.setGoogleClientInfo(keyval...)
98}
99
100// Connection returns a connection to the API service.
101//
102// Deprecated.
103func (c *SnapshotsV1Beta3Client) Connection() *grpc.ClientConn {
104	return c.internalClient.Connection()
105}
106
107// GetSnapshot gets information about a snapshot.
108func (c *SnapshotsV1Beta3Client) GetSnapshot(ctx context.Context, req *dataflowpb.GetSnapshotRequest, opts ...gax.CallOption) (*dataflowpb.Snapshot, error) {
109	return c.internalClient.GetSnapshot(ctx, req, opts...)
110}
111
112// DeleteSnapshot deletes a snapshot.
113func (c *SnapshotsV1Beta3Client) DeleteSnapshot(ctx context.Context, req *dataflowpb.DeleteSnapshotRequest, opts ...gax.CallOption) (*dataflowpb.DeleteSnapshotResponse, error) {
114	return c.internalClient.DeleteSnapshot(ctx, req, opts...)
115}
116
117// ListSnapshots lists snapshots.
118func (c *SnapshotsV1Beta3Client) ListSnapshots(ctx context.Context, req *dataflowpb.ListSnapshotsRequest, opts ...gax.CallOption) (*dataflowpb.ListSnapshotsResponse, error) {
119	return c.internalClient.ListSnapshots(ctx, req, opts...)
120}
121
122// snapshotsV1Beta3GRPCClient is a client for interacting with Dataflow API over gRPC transport.
123//
124// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
125type snapshotsV1Beta3GRPCClient struct {
126	// Connection pool of gRPC connections to the service.
127	connPool gtransport.ConnPool
128
129	// flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE
130	disableDeadlines bool
131
132	// Points back to the CallOptions field of the containing SnapshotsV1Beta3Client
133	CallOptions **SnapshotsV1Beta3CallOptions
134
135	// The gRPC API client.
136	snapshotsV1Beta3Client dataflowpb.SnapshotsV1Beta3Client
137
138	// The x-goog-* metadata to be sent with each request.
139	xGoogMetadata metadata.MD
140}
141
142// NewSnapshotsV1Beta3Client creates a new snapshots v1 beta3 client based on gRPC.
143// The returned client must be Closed when it is done being used to clean up its underlying connections.
144//
145// Provides methods to manage snapshots of Google Cloud Dataflow jobs.
146func NewSnapshotsV1Beta3Client(ctx context.Context, opts ...option.ClientOption) (*SnapshotsV1Beta3Client, error) {
147	clientOpts := defaultSnapshotsV1Beta3GRPCClientOptions()
148	if newSnapshotsV1Beta3ClientHook != nil {
149		hookOpts, err := newSnapshotsV1Beta3ClientHook(ctx, clientHookParams{})
150		if err != nil {
151			return nil, err
152		}
153		clientOpts = append(clientOpts, hookOpts...)
154	}
155
156	disableDeadlines, err := checkDisableDeadlines()
157	if err != nil {
158		return nil, err
159	}
160
161	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
162	if err != nil {
163		return nil, err
164	}
165	client := SnapshotsV1Beta3Client{CallOptions: defaultSnapshotsV1Beta3CallOptions()}
166
167	c := &snapshotsV1Beta3GRPCClient{
168		connPool:               connPool,
169		disableDeadlines:       disableDeadlines,
170		snapshotsV1Beta3Client: dataflowpb.NewSnapshotsV1Beta3Client(connPool),
171		CallOptions:            &client.CallOptions,
172	}
173	c.setGoogleClientInfo()
174
175	client.internalClient = c
176
177	return &client, nil
178}
179
180// Connection returns a connection to the API service.
181//
182// Deprecated.
183func (c *snapshotsV1Beta3GRPCClient) Connection() *grpc.ClientConn {
184	return c.connPool.Conn()
185}
186
187// setGoogleClientInfo sets the name and version of the application in
188// the `x-goog-api-client` header passed on each request. Intended for
189// use by Google-written clients.
190func (c *snapshotsV1Beta3GRPCClient) setGoogleClientInfo(keyval ...string) {
191	kv := append([]string{"gl-go", versionGo()}, keyval...)
192	kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
193	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
194}
195
196// Close closes the connection to the API service. The user should invoke this when
197// the client is no longer required.
198func (c *snapshotsV1Beta3GRPCClient) Close() error {
199	return c.connPool.Close()
200}
201
202func (c *snapshotsV1Beta3GRPCClient) GetSnapshot(ctx context.Context, req *dataflowpb.GetSnapshotRequest, opts ...gax.CallOption) (*dataflowpb.Snapshot, error) {
203	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
204		cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
205		defer cancel()
206		ctx = cctx
207	}
208	ctx = insertMetadata(ctx, c.xGoogMetadata)
209	opts = append((*c.CallOptions).GetSnapshot[0:len((*c.CallOptions).GetSnapshot):len((*c.CallOptions).GetSnapshot)], opts...)
210	var resp *dataflowpb.Snapshot
211	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
212		var err error
213		resp, err = c.snapshotsV1Beta3Client.GetSnapshot(ctx, req, settings.GRPC...)
214		return err
215	}, opts...)
216	if err != nil {
217		return nil, err
218	}
219	return resp, nil
220}
221
222func (c *snapshotsV1Beta3GRPCClient) DeleteSnapshot(ctx context.Context, req *dataflowpb.DeleteSnapshotRequest, opts ...gax.CallOption) (*dataflowpb.DeleteSnapshotResponse, error) {
223	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
224		cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
225		defer cancel()
226		ctx = cctx
227	}
228	ctx = insertMetadata(ctx, c.xGoogMetadata)
229	opts = append((*c.CallOptions).DeleteSnapshot[0:len((*c.CallOptions).DeleteSnapshot):len((*c.CallOptions).DeleteSnapshot)], opts...)
230	var resp *dataflowpb.DeleteSnapshotResponse
231	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
232		var err error
233		resp, err = c.snapshotsV1Beta3Client.DeleteSnapshot(ctx, req, settings.GRPC...)
234		return err
235	}, opts...)
236	if err != nil {
237		return nil, err
238	}
239	return resp, nil
240}
241
242func (c *snapshotsV1Beta3GRPCClient) ListSnapshots(ctx context.Context, req *dataflowpb.ListSnapshotsRequest, opts ...gax.CallOption) (*dataflowpb.ListSnapshotsResponse, error) {
243	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
244		cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
245		defer cancel()
246		ctx = cctx
247	}
248	ctx = insertMetadata(ctx, c.xGoogMetadata)
249	opts = append((*c.CallOptions).ListSnapshots[0:len((*c.CallOptions).ListSnapshots):len((*c.CallOptions).ListSnapshots)], opts...)
250	var resp *dataflowpb.ListSnapshotsResponse
251	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
252		var err error
253		resp, err = c.snapshotsV1Beta3Client.ListSnapshots(ctx, req, settings.GRPC...)
254		return err
255	}, opts...)
256	if err != nil {
257		return nil, err
258	}
259	return resp, nil
260}
261