1// Copyright 2018 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// AUTO-GENERATED CODE. DO NOT EDIT.
16
17package debugger
18
19import (
20	"context"
21	"time"
22
23	gax "github.com/googleapis/gax-go"
24	"google.golang.org/api/option"
25	"google.golang.org/api/transport"
26	clouddebuggerpb "google.golang.org/genproto/googleapis/devtools/clouddebugger/v2"
27	"google.golang.org/grpc"
28	"google.golang.org/grpc/codes"
29	"google.golang.org/grpc/metadata"
30)
31
32// Debugger2CallOptions contains the retry settings for each method of Debugger2Client.
33type Debugger2CallOptions struct {
34	SetBreakpoint    []gax.CallOption
35	GetBreakpoint    []gax.CallOption
36	DeleteBreakpoint []gax.CallOption
37	ListBreakpoints  []gax.CallOption
38	ListDebuggees    []gax.CallOption
39}
40
41func defaultDebugger2ClientOptions() []option.ClientOption {
42	return []option.ClientOption{
43		option.WithEndpoint("clouddebugger.googleapis.com:443"),
44		option.WithScopes(DefaultAuthScopes()...),
45	}
46}
47
48func defaultDebugger2CallOptions() *Debugger2CallOptions {
49	retry := map[[2]string][]gax.CallOption{
50		{"default", "idempotent"}: {
51			gax.WithRetry(func() gax.Retryer {
52				return gax.OnCodes([]codes.Code{
53					codes.DeadlineExceeded,
54					codes.Unavailable,
55				}, gax.Backoff{
56					Initial:    100 * time.Millisecond,
57					Max:        60000 * time.Millisecond,
58					Multiplier: 1.3,
59				})
60			}),
61		},
62	}
63	return &Debugger2CallOptions{
64		SetBreakpoint:    retry[[2]string{"default", "non_idempotent"}],
65		GetBreakpoint:    retry[[2]string{"default", "idempotent"}],
66		DeleteBreakpoint: retry[[2]string{"default", "idempotent"}],
67		ListBreakpoints:  retry[[2]string{"default", "idempotent"}],
68		ListDebuggees:    retry[[2]string{"default", "idempotent"}],
69	}
70}
71
72// Debugger2Client is a client for interacting with Stackdriver Debugger API.
73//
74// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
75type Debugger2Client struct {
76	// The connection to the service.
77	conn *grpc.ClientConn
78
79	// The gRPC API client.
80	debugger2Client clouddebuggerpb.Debugger2Client
81
82	// The call options for this service.
83	CallOptions *Debugger2CallOptions
84
85	// The x-goog-* metadata to be sent with each request.
86	xGoogMetadata metadata.MD
87}
88
89// NewDebugger2Client creates a new debugger2 client.
90//
91// The Debugger service provides the API that allows users to collect run-time
92// information from a running application, without stopping or slowing it down
93// and without modifying its state.  An application may include one or
94// more replicated processes performing the same work.
95//
96// A debugged application is represented using the Debuggee concept. The
97// Debugger service provides a way to query for available debuggees, but does
98// not provide a way to create one.  A debuggee is created using the Controller
99// service, usually by running a debugger agent with the application.
100//
101// The Debugger service enables the client to set one or more Breakpoints on a
102// Debuggee and collect the results of the set Breakpoints.
103func NewDebugger2Client(ctx context.Context, opts ...option.ClientOption) (*Debugger2Client, error) {
104	conn, err := transport.DialGRPC(ctx, append(defaultDebugger2ClientOptions(), opts...)...)
105	if err != nil {
106		return nil, err
107	}
108	c := &Debugger2Client{
109		conn:        conn,
110		CallOptions: defaultDebugger2CallOptions(),
111
112		debugger2Client: clouddebuggerpb.NewDebugger2Client(conn),
113	}
114	c.SetGoogleClientInfo()
115	return c, nil
116}
117
118// Connection returns the client's connection to the API service.
119func (c *Debugger2Client) Connection() *grpc.ClientConn {
120	return c.conn
121}
122
123// Close closes the connection to the API service. The user should invoke this when
124// the client is no longer required.
125func (c *Debugger2Client) Close() error {
126	return c.conn.Close()
127}
128
129// SetGoogleClientInfo sets the name and version of the application in
130// the `x-goog-api-client` header passed on each request. Intended for
131// use by Google-written clients.
132func (c *Debugger2Client) SetGoogleClientInfo(keyval ...string) {
133	kv := append([]string{"gl-go", versionGo()}, keyval...)
134	kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
135	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
136}
137
138// SetBreakpoint sets the breakpoint to the debuggee.
139func (c *Debugger2Client) SetBreakpoint(ctx context.Context, req *clouddebuggerpb.SetBreakpointRequest, opts ...gax.CallOption) (*clouddebuggerpb.SetBreakpointResponse, error) {
140	ctx = insertMetadata(ctx, c.xGoogMetadata)
141	opts = append(c.CallOptions.SetBreakpoint[0:len(c.CallOptions.SetBreakpoint):len(c.CallOptions.SetBreakpoint)], opts...)
142	var resp *clouddebuggerpb.SetBreakpointResponse
143	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
144		var err error
145		resp, err = c.debugger2Client.SetBreakpoint(ctx, req, settings.GRPC...)
146		return err
147	}, opts...)
148	if err != nil {
149		return nil, err
150	}
151	return resp, nil
152}
153
154// GetBreakpoint gets breakpoint information.
155func (c *Debugger2Client) GetBreakpoint(ctx context.Context, req *clouddebuggerpb.GetBreakpointRequest, opts ...gax.CallOption) (*clouddebuggerpb.GetBreakpointResponse, error) {
156	ctx = insertMetadata(ctx, c.xGoogMetadata)
157	opts = append(c.CallOptions.GetBreakpoint[0:len(c.CallOptions.GetBreakpoint):len(c.CallOptions.GetBreakpoint)], opts...)
158	var resp *clouddebuggerpb.GetBreakpointResponse
159	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
160		var err error
161		resp, err = c.debugger2Client.GetBreakpoint(ctx, req, settings.GRPC...)
162		return err
163	}, opts...)
164	if err != nil {
165		return nil, err
166	}
167	return resp, nil
168}
169
170// DeleteBreakpoint deletes the breakpoint from the debuggee.
171func (c *Debugger2Client) DeleteBreakpoint(ctx context.Context, req *clouddebuggerpb.DeleteBreakpointRequest, opts ...gax.CallOption) error {
172	ctx = insertMetadata(ctx, c.xGoogMetadata)
173	opts = append(c.CallOptions.DeleteBreakpoint[0:len(c.CallOptions.DeleteBreakpoint):len(c.CallOptions.DeleteBreakpoint)], opts...)
174	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
175		var err error
176		_, err = c.debugger2Client.DeleteBreakpoint(ctx, req, settings.GRPC...)
177		return err
178	}, opts...)
179	return err
180}
181
182// ListBreakpoints lists all breakpoints for the debuggee.
183func (c *Debugger2Client) ListBreakpoints(ctx context.Context, req *clouddebuggerpb.ListBreakpointsRequest, opts ...gax.CallOption) (*clouddebuggerpb.ListBreakpointsResponse, error) {
184	ctx = insertMetadata(ctx, c.xGoogMetadata)
185	opts = append(c.CallOptions.ListBreakpoints[0:len(c.CallOptions.ListBreakpoints):len(c.CallOptions.ListBreakpoints)], opts...)
186	var resp *clouddebuggerpb.ListBreakpointsResponse
187	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
188		var err error
189		resp, err = c.debugger2Client.ListBreakpoints(ctx, req, settings.GRPC...)
190		return err
191	}, opts...)
192	if err != nil {
193		return nil, err
194	}
195	return resp, nil
196}
197
198// ListDebuggees lists all the debuggees that the user has access to.
199func (c *Debugger2Client) ListDebuggees(ctx context.Context, req *clouddebuggerpb.ListDebuggeesRequest, opts ...gax.CallOption) (*clouddebuggerpb.ListDebuggeesResponse, error) {
200	ctx = insertMetadata(ctx, c.xGoogMetadata)
201	opts = append(c.CallOptions.ListDebuggees[0:len(c.CallOptions.ListDebuggees):len(c.CallOptions.ListDebuggees)], opts...)
202	var resp *clouddebuggerpb.ListDebuggeesResponse
203	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
204		var err error
205		resp, err = c.debugger2Client.ListDebuggees(ctx, req, settings.GRPC...)
206		return err
207	}, opts...)
208	if err != nil {
209		return nil, err
210	}
211	return resp, nil
212}
213