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 newTemplatesClientHook clientHook
34
35// TemplatesCallOptions contains the retry settings for each method of TemplatesClient.
36type TemplatesCallOptions struct {
37	CreateJobFromTemplate []gax.CallOption
38	LaunchTemplate        []gax.CallOption
39	GetTemplate           []gax.CallOption
40}
41
42func defaultTemplatesGRPCClientOptions() []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 defaultTemplatesCallOptions() *TemplatesCallOptions {
56	return &TemplatesCallOptions{
57		CreateJobFromTemplate: []gax.CallOption{},
58		LaunchTemplate:        []gax.CallOption{},
59		GetTemplate:           []gax.CallOption{},
60	}
61}
62
63// internalTemplatesClient is an interface that defines the methods availaible from Dataflow API.
64type internalTemplatesClient interface {
65	Close() error
66	setGoogleClientInfo(...string)
67	Connection() *grpc.ClientConn
68	CreateJobFromTemplate(context.Context, *dataflowpb.CreateJobFromTemplateRequest, ...gax.CallOption) (*dataflowpb.Job, error)
69	LaunchTemplate(context.Context, *dataflowpb.LaunchTemplateRequest, ...gax.CallOption) (*dataflowpb.LaunchTemplateResponse, error)
70	GetTemplate(context.Context, *dataflowpb.GetTemplateRequest, ...gax.CallOption) (*dataflowpb.GetTemplateResponse, error)
71}
72
73// TemplatesClient 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 a method to create Cloud Dataflow jobs from templates.
77type TemplatesClient struct {
78	// The internal transport-dependent client.
79	internalClient internalTemplatesClient
80
81	// The call options for this service.
82	CallOptions *TemplatesCallOptions
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 *TemplatesClient) 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 *TemplatesClient) setGoogleClientInfo(keyval ...string) {
97	c.internalClient.setGoogleClientInfo(keyval...)
98}
99
100// Connection returns a connection to the API service.
101//
102// Deprecated.
103func (c *TemplatesClient) Connection() *grpc.ClientConn {
104	return c.internalClient.Connection()
105}
106
107// CreateJobFromTemplate creates a Cloud Dataflow job from a template.
108func (c *TemplatesClient) CreateJobFromTemplate(ctx context.Context, req *dataflowpb.CreateJobFromTemplateRequest, opts ...gax.CallOption) (*dataflowpb.Job, error) {
109	return c.internalClient.CreateJobFromTemplate(ctx, req, opts...)
110}
111
112// LaunchTemplate launch a template.
113func (c *TemplatesClient) LaunchTemplate(ctx context.Context, req *dataflowpb.LaunchTemplateRequest, opts ...gax.CallOption) (*dataflowpb.LaunchTemplateResponse, error) {
114	return c.internalClient.LaunchTemplate(ctx, req, opts...)
115}
116
117// GetTemplate get the template associated with a template.
118func (c *TemplatesClient) GetTemplate(ctx context.Context, req *dataflowpb.GetTemplateRequest, opts ...gax.CallOption) (*dataflowpb.GetTemplateResponse, error) {
119	return c.internalClient.GetTemplate(ctx, req, opts...)
120}
121
122// templatesGRPCClient 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 templatesGRPCClient 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 TemplatesClient
133	CallOptions **TemplatesCallOptions
134
135	// The gRPC API client.
136	templatesClient dataflowpb.TemplatesServiceClient
137
138	// The x-goog-* metadata to be sent with each request.
139	xGoogMetadata metadata.MD
140}
141
142// NewTemplatesClient creates a new templates service 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 a method to create Cloud Dataflow jobs from templates.
146func NewTemplatesClient(ctx context.Context, opts ...option.ClientOption) (*TemplatesClient, error) {
147	clientOpts := defaultTemplatesGRPCClientOptions()
148	if newTemplatesClientHook != nil {
149		hookOpts, err := newTemplatesClientHook(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 := TemplatesClient{CallOptions: defaultTemplatesCallOptions()}
166
167	c := &templatesGRPCClient{
168		connPool:         connPool,
169		disableDeadlines: disableDeadlines,
170		templatesClient:  dataflowpb.NewTemplatesServiceClient(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 *templatesGRPCClient) 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 *templatesGRPCClient) 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 *templatesGRPCClient) Close() error {
199	return c.connPool.Close()
200}
201
202func (c *templatesGRPCClient) CreateJobFromTemplate(ctx context.Context, req *dataflowpb.CreateJobFromTemplateRequest, opts ...gax.CallOption) (*dataflowpb.Job, 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).CreateJobFromTemplate[0:len((*c.CallOptions).CreateJobFromTemplate):len((*c.CallOptions).CreateJobFromTemplate)], opts...)
210	var resp *dataflowpb.Job
211	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
212		var err error
213		resp, err = c.templatesClient.CreateJobFromTemplate(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 *templatesGRPCClient) LaunchTemplate(ctx context.Context, req *dataflowpb.LaunchTemplateRequest, opts ...gax.CallOption) (*dataflowpb.LaunchTemplateResponse, 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).LaunchTemplate[0:len((*c.CallOptions).LaunchTemplate):len((*c.CallOptions).LaunchTemplate)], opts...)
230	var resp *dataflowpb.LaunchTemplateResponse
231	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
232		var err error
233		resp, err = c.templatesClient.LaunchTemplate(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 *templatesGRPCClient) GetTemplate(ctx context.Context, req *dataflowpb.GetTemplateRequest, opts ...gax.CallOption) (*dataflowpb.GetTemplateResponse, 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).GetTemplate[0:len((*c.CallOptions).GetTemplate):len((*c.CallOptions).GetTemplate)], opts...)
250	var resp *dataflowpb.GetTemplateResponse
251	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
252		var err error
253		resp, err = c.templatesClient.GetTemplate(ctx, req, settings.GRPC...)
254		return err
255	}, opts...)
256	if err != nil {
257		return nil, err
258	}
259	return resp, nil
260}
261