1// +build go1.13
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5// Code generated by Microsoft (R) AutoRest Code Generator.
6// Changes may cause incorrect behavior and will be lost if the code is regenerated.
7
8package azartifacts
9
10import (
11	"context"
12	"fmt"
13	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
14	"net/http"
15	"time"
16)
17
18// DataFlowDebugSessionClient contains the methods for the DataFlowDebugSession group.
19// Don't use this type directly, use NewDataFlowDebugSessionClient() instead.
20type DataFlowDebugSessionClient struct {
21	con *Connection
22}
23
24// NewDataFlowDebugSessionClient creates a new instance of DataFlowDebugSessionClient with the specified values.
25func NewDataFlowDebugSessionClient(con *Connection) *DataFlowDebugSessionClient {
26	return &DataFlowDebugSessionClient{con: con}
27}
28
29// AddDataFlow - Add a data flow into debug session.
30// If the operation fails it returns the *CloudError error type.
31func (client *DataFlowDebugSessionClient) AddDataFlow(ctx context.Context, request DataFlowDebugPackage, options *DataFlowDebugSessionAddDataFlowOptions) (AddDataFlowToDebugSessionResponseResponse, error) {
32	req, err := client.addDataFlowCreateRequest(ctx, request, options)
33	if err != nil {
34		return AddDataFlowToDebugSessionResponseResponse{}, err
35	}
36	resp, err := client.con.Pipeline().Do(req)
37	if err != nil {
38		return AddDataFlowToDebugSessionResponseResponse{}, err
39	}
40	if !resp.HasStatusCode(http.StatusOK) {
41		return AddDataFlowToDebugSessionResponseResponse{}, client.addDataFlowHandleError(resp)
42	}
43	return client.addDataFlowHandleResponse(resp)
44}
45
46// addDataFlowCreateRequest creates the AddDataFlow request.
47func (client *DataFlowDebugSessionClient) addDataFlowCreateRequest(ctx context.Context, request DataFlowDebugPackage, options *DataFlowDebugSessionAddDataFlowOptions) (*azcore.Request, error) {
48	urlPath := "/addDataFlowToDebugSession"
49	req, err := azcore.NewRequest(ctx, http.MethodPost, azcore.JoinPaths(client.con.Endpoint(), urlPath))
50	if err != nil {
51		return nil, err
52	}
53	req.Telemetry(telemetryInfo)
54	reqQP := req.URL.Query()
55	reqQP.Set("api-version", "2019-06-01-preview")
56	req.URL.RawQuery = reqQP.Encode()
57	req.Header.Set("Accept", "application/json")
58	return req, req.MarshalAsJSON(request)
59}
60
61// addDataFlowHandleResponse handles the AddDataFlow response.
62func (client *DataFlowDebugSessionClient) addDataFlowHandleResponse(resp *azcore.Response) (AddDataFlowToDebugSessionResponseResponse, error) {
63	var val *AddDataFlowToDebugSessionResponse
64	if err := resp.UnmarshalAsJSON(&val); err != nil {
65		return AddDataFlowToDebugSessionResponseResponse{}, err
66	}
67	return AddDataFlowToDebugSessionResponseResponse{RawResponse: resp.Response, AddDataFlowToDebugSessionResponse: val}, nil
68}
69
70// addDataFlowHandleError handles the AddDataFlow error response.
71func (client *DataFlowDebugSessionClient) addDataFlowHandleError(resp *azcore.Response) error {
72	body, err := resp.Payload()
73	if err != nil {
74		return azcore.NewResponseError(err, resp.Response)
75	}
76	errType := CloudError{raw: string(body)}
77	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
78		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
79	}
80	return azcore.NewResponseError(&errType, resp.Response)
81}
82
83// BeginCreateDataFlowDebugSession - Creates a data flow debug session.
84// If the operation fails it returns the *CloudError error type.
85func (client *DataFlowDebugSessionClient) BeginCreateDataFlowDebugSession(ctx context.Context, request CreateDataFlowDebugSessionRequest, options *DataFlowDebugSessionBeginCreateDataFlowDebugSessionOptions) (CreateDataFlowDebugSessionResponsePollerResponse, error) {
86	resp, err := client.createDataFlowDebugSession(ctx, request, options)
87	if err != nil {
88		return CreateDataFlowDebugSessionResponsePollerResponse{}, err
89	}
90	result := CreateDataFlowDebugSessionResponsePollerResponse{
91		RawResponse: resp.Response,
92	}
93	pt, err := azcore.NewLROPoller("DataFlowDebugSessionClient.CreateDataFlowDebugSession", resp, client.con.Pipeline(), client.createDataFlowDebugSessionHandleError)
94	if err != nil {
95		return CreateDataFlowDebugSessionResponsePollerResponse{}, err
96	}
97	poller := &createDataFlowDebugSessionResponsePoller{
98		pt: pt,
99	}
100	result.Poller = poller
101	result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (CreateDataFlowDebugSessionResponseResponse, error) {
102		return poller.pollUntilDone(ctx, frequency)
103	}
104	return result, nil
105}
106
107// ResumeCreateDataFlowDebugSession creates a new CreateDataFlowDebugSessionResponsePoller from the specified resume token.
108// token - The value must come from a previous call to CreateDataFlowDebugSessionResponsePoller.ResumeToken().
109func (client *DataFlowDebugSessionClient) ResumeCreateDataFlowDebugSession(ctx context.Context, token string) (CreateDataFlowDebugSessionResponsePollerResponse, error) {
110	pt, err := azcore.NewLROPollerFromResumeToken("DataFlowDebugSessionClient.CreateDataFlowDebugSession", token, client.con.Pipeline(), client.createDataFlowDebugSessionHandleError)
111	if err != nil {
112		return CreateDataFlowDebugSessionResponsePollerResponse{}, err
113	}
114	poller := &createDataFlowDebugSessionResponsePoller{
115		pt: pt,
116	}
117	resp, err := poller.Poll(ctx)
118	if err != nil {
119		return CreateDataFlowDebugSessionResponsePollerResponse{}, err
120	}
121	result := CreateDataFlowDebugSessionResponsePollerResponse{
122		RawResponse: resp,
123	}
124	result.Poller = poller
125	result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (CreateDataFlowDebugSessionResponseResponse, error) {
126		return poller.pollUntilDone(ctx, frequency)
127	}
128	return result, nil
129}
130
131// CreateDataFlowDebugSession - Creates a data flow debug session.
132// If the operation fails it returns the *CloudError error type.
133func (client *DataFlowDebugSessionClient) createDataFlowDebugSession(ctx context.Context, request CreateDataFlowDebugSessionRequest, options *DataFlowDebugSessionBeginCreateDataFlowDebugSessionOptions) (*azcore.Response, error) {
134	req, err := client.createDataFlowDebugSessionCreateRequest(ctx, request, options)
135	if err != nil {
136		return nil, err
137	}
138	resp, err := client.con.Pipeline().Do(req)
139	if err != nil {
140		return nil, err
141	}
142	if !resp.HasStatusCode(http.StatusOK, http.StatusAccepted) {
143		return nil, client.createDataFlowDebugSessionHandleError(resp)
144	}
145	return resp, nil
146}
147
148// createDataFlowDebugSessionCreateRequest creates the CreateDataFlowDebugSession request.
149func (client *DataFlowDebugSessionClient) createDataFlowDebugSessionCreateRequest(ctx context.Context, request CreateDataFlowDebugSessionRequest, options *DataFlowDebugSessionBeginCreateDataFlowDebugSessionOptions) (*azcore.Request, error) {
150	urlPath := "/createDataFlowDebugSession"
151	req, err := azcore.NewRequest(ctx, http.MethodPost, azcore.JoinPaths(client.con.Endpoint(), urlPath))
152	if err != nil {
153		return nil, err
154	}
155	req.Telemetry(telemetryInfo)
156	reqQP := req.URL.Query()
157	reqQP.Set("api-version", "2019-06-01-preview")
158	req.URL.RawQuery = reqQP.Encode()
159	req.Header.Set("Accept", "application/json")
160	return req, req.MarshalAsJSON(request)
161}
162
163// createDataFlowDebugSessionHandleError handles the CreateDataFlowDebugSession error response.
164func (client *DataFlowDebugSessionClient) createDataFlowDebugSessionHandleError(resp *azcore.Response) error {
165	body, err := resp.Payload()
166	if err != nil {
167		return azcore.NewResponseError(err, resp.Response)
168	}
169	errType := CloudError{raw: string(body)}
170	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
171		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
172	}
173	return azcore.NewResponseError(&errType, resp.Response)
174}
175
176// DeleteDataFlowDebugSession - Deletes a data flow debug session.
177// If the operation fails it returns the *CloudError error type.
178func (client *DataFlowDebugSessionClient) DeleteDataFlowDebugSession(ctx context.Context, request DeleteDataFlowDebugSessionRequest, options *DataFlowDebugSessionDeleteDataFlowDebugSessionOptions) (*http.Response, error) {
179	req, err := client.deleteDataFlowDebugSessionCreateRequest(ctx, request, options)
180	if err != nil {
181		return nil, err
182	}
183	resp, err := client.con.Pipeline().Do(req)
184	if err != nil {
185		return nil, err
186	}
187	if !resp.HasStatusCode(http.StatusOK) {
188		return nil, client.deleteDataFlowDebugSessionHandleError(resp)
189	}
190	return resp.Response, nil
191}
192
193// deleteDataFlowDebugSessionCreateRequest creates the DeleteDataFlowDebugSession request.
194func (client *DataFlowDebugSessionClient) deleteDataFlowDebugSessionCreateRequest(ctx context.Context, request DeleteDataFlowDebugSessionRequest, options *DataFlowDebugSessionDeleteDataFlowDebugSessionOptions) (*azcore.Request, error) {
195	urlPath := "/deleteDataFlowDebugSession"
196	req, err := azcore.NewRequest(ctx, http.MethodPost, azcore.JoinPaths(client.con.Endpoint(), urlPath))
197	if err != nil {
198		return nil, err
199	}
200	req.Telemetry(telemetryInfo)
201	reqQP := req.URL.Query()
202	reqQP.Set("api-version", "2019-06-01-preview")
203	req.URL.RawQuery = reqQP.Encode()
204	req.Header.Set("Accept", "application/json")
205	return req, req.MarshalAsJSON(request)
206}
207
208// deleteDataFlowDebugSessionHandleError handles the DeleteDataFlowDebugSession error response.
209func (client *DataFlowDebugSessionClient) deleteDataFlowDebugSessionHandleError(resp *azcore.Response) error {
210	body, err := resp.Payload()
211	if err != nil {
212		return azcore.NewResponseError(err, resp.Response)
213	}
214	errType := CloudError{raw: string(body)}
215	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
216		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
217	}
218	return azcore.NewResponseError(&errType, resp.Response)
219}
220
221// BeginExecuteCommand - Execute a data flow debug command.
222// If the operation fails it returns the *CloudError error type.
223func (client *DataFlowDebugSessionClient) BeginExecuteCommand(ctx context.Context, request DataFlowDebugCommandRequest, options *DataFlowDebugSessionBeginExecuteCommandOptions) (DataFlowDebugCommandResponsePollerResponse, error) {
224	resp, err := client.executeCommand(ctx, request, options)
225	if err != nil {
226		return DataFlowDebugCommandResponsePollerResponse{}, err
227	}
228	result := DataFlowDebugCommandResponsePollerResponse{
229		RawResponse: resp.Response,
230	}
231	pt, err := azcore.NewLROPoller("DataFlowDebugSessionClient.ExecuteCommand", resp, client.con.Pipeline(), client.executeCommandHandleError)
232	if err != nil {
233		return DataFlowDebugCommandResponsePollerResponse{}, err
234	}
235	poller := &dataFlowDebugCommandResponsePoller{
236		pt: pt,
237	}
238	result.Poller = poller
239	result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (DataFlowDebugCommandResponseResponse, error) {
240		return poller.pollUntilDone(ctx, frequency)
241	}
242	return result, nil
243}
244
245// ResumeExecuteCommand creates a new DataFlowDebugCommandResponsePoller from the specified resume token.
246// token - The value must come from a previous call to DataFlowDebugCommandResponsePoller.ResumeToken().
247func (client *DataFlowDebugSessionClient) ResumeExecuteCommand(ctx context.Context, token string) (DataFlowDebugCommandResponsePollerResponse, error) {
248	pt, err := azcore.NewLROPollerFromResumeToken("DataFlowDebugSessionClient.ExecuteCommand", token, client.con.Pipeline(), client.executeCommandHandleError)
249	if err != nil {
250		return DataFlowDebugCommandResponsePollerResponse{}, err
251	}
252	poller := &dataFlowDebugCommandResponsePoller{
253		pt: pt,
254	}
255	resp, err := poller.Poll(ctx)
256	if err != nil {
257		return DataFlowDebugCommandResponsePollerResponse{}, err
258	}
259	result := DataFlowDebugCommandResponsePollerResponse{
260		RawResponse: resp,
261	}
262	result.Poller = poller
263	result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (DataFlowDebugCommandResponseResponse, error) {
264		return poller.pollUntilDone(ctx, frequency)
265	}
266	return result, nil
267}
268
269// ExecuteCommand - Execute a data flow debug command.
270// If the operation fails it returns the *CloudError error type.
271func (client *DataFlowDebugSessionClient) executeCommand(ctx context.Context, request DataFlowDebugCommandRequest, options *DataFlowDebugSessionBeginExecuteCommandOptions) (*azcore.Response, error) {
272	req, err := client.executeCommandCreateRequest(ctx, request, options)
273	if err != nil {
274		return nil, err
275	}
276	resp, err := client.con.Pipeline().Do(req)
277	if err != nil {
278		return nil, err
279	}
280	if !resp.HasStatusCode(http.StatusOK, http.StatusAccepted) {
281		return nil, client.executeCommandHandleError(resp)
282	}
283	return resp, nil
284}
285
286// executeCommandCreateRequest creates the ExecuteCommand request.
287func (client *DataFlowDebugSessionClient) executeCommandCreateRequest(ctx context.Context, request DataFlowDebugCommandRequest, options *DataFlowDebugSessionBeginExecuteCommandOptions) (*azcore.Request, error) {
288	urlPath := "/executeDataFlowDebugCommand"
289	req, err := azcore.NewRequest(ctx, http.MethodPost, azcore.JoinPaths(client.con.Endpoint(), urlPath))
290	if err != nil {
291		return nil, err
292	}
293	req.Telemetry(telemetryInfo)
294	reqQP := req.URL.Query()
295	reqQP.Set("api-version", "2019-06-01-preview")
296	req.URL.RawQuery = reqQP.Encode()
297	req.Header.Set("Accept", "application/json")
298	return req, req.MarshalAsJSON(request)
299}
300
301// executeCommandHandleError handles the ExecuteCommand error response.
302func (client *DataFlowDebugSessionClient) executeCommandHandleError(resp *azcore.Response) error {
303	body, err := resp.Payload()
304	if err != nil {
305		return azcore.NewResponseError(err, resp.Response)
306	}
307	errType := CloudError{raw: string(body)}
308	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
309		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
310	}
311	return azcore.NewResponseError(&errType, resp.Response)
312}
313
314// QueryDataFlowDebugSessionsByWorkspace - Query all active data flow debug sessions.
315// If the operation fails it returns the *CloudError error type.
316func (client *DataFlowDebugSessionClient) QueryDataFlowDebugSessionsByWorkspace(options *DataFlowDebugSessionQueryDataFlowDebugSessionsByWorkspaceOptions) QueryDataFlowDebugSessionsResponsePager {
317	return &queryDataFlowDebugSessionsResponsePager{
318		pipeline: client.con.Pipeline(),
319		requester: func(ctx context.Context) (*azcore.Request, error) {
320			return client.queryDataFlowDebugSessionsByWorkspaceCreateRequest(ctx, options)
321		},
322		responder: client.queryDataFlowDebugSessionsByWorkspaceHandleResponse,
323		errorer:   client.queryDataFlowDebugSessionsByWorkspaceHandleError,
324		advancer: func(ctx context.Context, resp QueryDataFlowDebugSessionsResponseResponse) (*azcore.Request, error) {
325			return azcore.NewRequest(ctx, http.MethodGet, *resp.QueryDataFlowDebugSessionsResponse.NextLink)
326		},
327		statusCodes: []int{http.StatusOK},
328	}
329}
330
331// queryDataFlowDebugSessionsByWorkspaceCreateRequest creates the QueryDataFlowDebugSessionsByWorkspace request.
332func (client *DataFlowDebugSessionClient) queryDataFlowDebugSessionsByWorkspaceCreateRequest(ctx context.Context, options *DataFlowDebugSessionQueryDataFlowDebugSessionsByWorkspaceOptions) (*azcore.Request, error) {
333	urlPath := "/queryDataFlowDebugSessions"
334	req, err := azcore.NewRequest(ctx, http.MethodPost, azcore.JoinPaths(client.con.Endpoint(), urlPath))
335	if err != nil {
336		return nil, err
337	}
338	req.Telemetry(telemetryInfo)
339	reqQP := req.URL.Query()
340	reqQP.Set("api-version", "2019-06-01-preview")
341	req.URL.RawQuery = reqQP.Encode()
342	req.Header.Set("Accept", "application/json")
343	return req, nil
344}
345
346// queryDataFlowDebugSessionsByWorkspaceHandleResponse handles the QueryDataFlowDebugSessionsByWorkspace response.
347func (client *DataFlowDebugSessionClient) queryDataFlowDebugSessionsByWorkspaceHandleResponse(resp *azcore.Response) (QueryDataFlowDebugSessionsResponseResponse, error) {
348	var val *QueryDataFlowDebugSessionsResponse
349	if err := resp.UnmarshalAsJSON(&val); err != nil {
350		return QueryDataFlowDebugSessionsResponseResponse{}, err
351	}
352	return QueryDataFlowDebugSessionsResponseResponse{RawResponse: resp.Response, QueryDataFlowDebugSessionsResponse: val}, nil
353}
354
355// queryDataFlowDebugSessionsByWorkspaceHandleError handles the QueryDataFlowDebugSessionsByWorkspace error response.
356func (client *DataFlowDebugSessionClient) queryDataFlowDebugSessionsByWorkspaceHandleError(resp *azcore.Response) error {
357	body, err := resp.Payload()
358	if err != nil {
359		return azcore.NewResponseError(err, resp.Response)
360	}
361	errType := CloudError{raw: string(body)}
362	if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil {
363		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
364	}
365	return azcore.NewResponseError(&errType, resp.Response)
366}
367