1package sql
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//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/autorest/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// JobStepsClient is the the Azure SQL Database management API provides a RESTful set of web services that interact
19// with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, update, and
20// delete databases.
21type JobStepsClient struct {
22	BaseClient
23}
24
25// NewJobStepsClient creates an instance of the JobStepsClient client.
26func NewJobStepsClient(subscriptionID string) JobStepsClient {
27	return NewJobStepsClientWithBaseURI(DefaultBaseURI, subscriptionID)
28}
29
30// NewJobStepsClientWithBaseURI creates an instance of the JobStepsClient client using a custom endpoint.  Use this
31// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
32func NewJobStepsClientWithBaseURI(baseURI string, subscriptionID string) JobStepsClient {
33	return JobStepsClient{NewWithBaseURI(baseURI, subscriptionID)}
34}
35
36// CreateOrUpdate creates or updates a job step. This will implicitly create a new job version.
37// Parameters:
38// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
39// from the Azure Resource Manager API or the portal.
40// serverName - the name of the server.
41// jobAgentName - the name of the job agent.
42// jobName - the name of the job.
43// stepName - the name of the job step.
44// parameters - the requested state of the job step.
45func (client JobStepsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, jobName string, stepName string, parameters JobStep) (result JobStep, err error) {
46	if tracing.IsEnabled() {
47		ctx = tracing.StartSpan(ctx, fqdn+"/JobStepsClient.CreateOrUpdate")
48		defer func() {
49			sc := -1
50			if result.Response.Response != nil {
51				sc = result.Response.Response.StatusCode
52			}
53			tracing.EndSpan(ctx, sc, err)
54		}()
55	}
56	if err := validation.Validate([]validation.Validation{
57		{TargetValue: parameters,
58			Constraints: []validation.Constraint{{Target: "parameters.JobStepProperties", Name: validation.Null, Rule: false,
59				Chain: []validation.Constraint{{Target: "parameters.JobStepProperties.TargetGroup", Name: validation.Null, Rule: true, Chain: nil},
60					{Target: "parameters.JobStepProperties.Credential", Name: validation.Null, Rule: true, Chain: nil},
61					{Target: "parameters.JobStepProperties.Action", Name: validation.Null, Rule: true,
62						Chain: []validation.Constraint{{Target: "parameters.JobStepProperties.Action.Value", Name: validation.Null, Rule: true, Chain: nil}}},
63					{Target: "parameters.JobStepProperties.Output", Name: validation.Null, Rule: false,
64						Chain: []validation.Constraint{{Target: "parameters.JobStepProperties.Output.ServerName", Name: validation.Null, Rule: true, Chain: nil},
65							{Target: "parameters.JobStepProperties.Output.DatabaseName", Name: validation.Null, Rule: true, Chain: nil},
66							{Target: "parameters.JobStepProperties.Output.TableName", Name: validation.Null, Rule: true, Chain: nil},
67							{Target: "parameters.JobStepProperties.Output.Credential", Name: validation.Null, Rule: true, Chain: nil},
68						}},
69				}}}}}); err != nil {
70		return result, validation.NewError("sql.JobStepsClient", "CreateOrUpdate", err.Error())
71	}
72
73	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serverName, jobAgentName, jobName, stepName, parameters)
74	if err != nil {
75		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "CreateOrUpdate", nil, "Failure preparing request")
76		return
77	}
78
79	resp, err := client.CreateOrUpdateSender(req)
80	if err != nil {
81		result.Response = autorest.Response{Response: resp}
82		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "CreateOrUpdate", resp, "Failure sending request")
83		return
84	}
85
86	result, err = client.CreateOrUpdateResponder(resp)
87	if err != nil {
88		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "CreateOrUpdate", resp, "Failure responding to request")
89		return
90	}
91
92	return
93}
94
95// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
96func (client JobStepsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, jobName string, stepName string, parameters JobStep) (*http.Request, error) {
97	pathParameters := map[string]interface{}{
98		"jobAgentName":      autorest.Encode("path", jobAgentName),
99		"jobName":           autorest.Encode("path", jobName),
100		"resourceGroupName": autorest.Encode("path", resourceGroupName),
101		"serverName":        autorest.Encode("path", serverName),
102		"stepName":          autorest.Encode("path", stepName),
103		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
104	}
105
106	const APIVersion = "2017-03-01-preview"
107	queryParameters := map[string]interface{}{
108		"api-version": APIVersion,
109	}
110
111	preparer := autorest.CreatePreparer(
112		autorest.AsContentType("application/json; charset=utf-8"),
113		autorest.AsPut(),
114		autorest.WithBaseURL(client.BaseURI),
115		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}", pathParameters),
116		autorest.WithJSON(parameters),
117		autorest.WithQueryParameters(queryParameters))
118	return preparer.Prepare((&http.Request{}).WithContext(ctx))
119}
120
121// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
122// http.Response Body if it receives an error.
123func (client JobStepsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
124	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
125}
126
127// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
128// closes the http.Response Body.
129func (client JobStepsClient) CreateOrUpdateResponder(resp *http.Response) (result JobStep, err error) {
130	err = autorest.Respond(
131		resp,
132		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
133		autorest.ByUnmarshallingJSON(&result),
134		autorest.ByClosing())
135	result.Response = autorest.Response{Response: resp}
136	return
137}
138
139// Delete deletes a job step. This will implicitly create a new job version.
140// Parameters:
141// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
142// from the Azure Resource Manager API or the portal.
143// serverName - the name of the server.
144// jobAgentName - the name of the job agent.
145// jobName - the name of the job.
146// stepName - the name of the job step to delete.
147func (client JobStepsClient) Delete(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, jobName string, stepName string) (result autorest.Response, err error) {
148	if tracing.IsEnabled() {
149		ctx = tracing.StartSpan(ctx, fqdn+"/JobStepsClient.Delete")
150		defer func() {
151			sc := -1
152			if result.Response != nil {
153				sc = result.Response.StatusCode
154			}
155			tracing.EndSpan(ctx, sc, err)
156		}()
157	}
158	req, err := client.DeletePreparer(ctx, resourceGroupName, serverName, jobAgentName, jobName, stepName)
159	if err != nil {
160		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "Delete", nil, "Failure preparing request")
161		return
162	}
163
164	resp, err := client.DeleteSender(req)
165	if err != nil {
166		result.Response = resp
167		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "Delete", resp, "Failure sending request")
168		return
169	}
170
171	result, err = client.DeleteResponder(resp)
172	if err != nil {
173		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "Delete", resp, "Failure responding to request")
174		return
175	}
176
177	return
178}
179
180// DeletePreparer prepares the Delete request.
181func (client JobStepsClient) DeletePreparer(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, jobName string, stepName string) (*http.Request, error) {
182	pathParameters := map[string]interface{}{
183		"jobAgentName":      autorest.Encode("path", jobAgentName),
184		"jobName":           autorest.Encode("path", jobName),
185		"resourceGroupName": autorest.Encode("path", resourceGroupName),
186		"serverName":        autorest.Encode("path", serverName),
187		"stepName":          autorest.Encode("path", stepName),
188		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
189	}
190
191	const APIVersion = "2017-03-01-preview"
192	queryParameters := map[string]interface{}{
193		"api-version": APIVersion,
194	}
195
196	preparer := autorest.CreatePreparer(
197		autorest.AsDelete(),
198		autorest.WithBaseURL(client.BaseURI),
199		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}", pathParameters),
200		autorest.WithQueryParameters(queryParameters))
201	return preparer.Prepare((&http.Request{}).WithContext(ctx))
202}
203
204// DeleteSender sends the Delete request. The method will close the
205// http.Response Body if it receives an error.
206func (client JobStepsClient) DeleteSender(req *http.Request) (*http.Response, error) {
207	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
208}
209
210// DeleteResponder handles the response to the Delete request. The method always
211// closes the http.Response Body.
212func (client JobStepsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
213	err = autorest.Respond(
214		resp,
215		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
216		autorest.ByClosing())
217	result.Response = resp
218	return
219}
220
221// Get gets a job step in a job's current version.
222// Parameters:
223// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
224// from the Azure Resource Manager API or the portal.
225// serverName - the name of the server.
226// jobAgentName - the name of the job agent.
227// jobName - the name of the job.
228// stepName - the name of the job step.
229func (client JobStepsClient) Get(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, jobName string, stepName string) (result JobStep, err error) {
230	if tracing.IsEnabled() {
231		ctx = tracing.StartSpan(ctx, fqdn+"/JobStepsClient.Get")
232		defer func() {
233			sc := -1
234			if result.Response.Response != nil {
235				sc = result.Response.Response.StatusCode
236			}
237			tracing.EndSpan(ctx, sc, err)
238		}()
239	}
240	req, err := client.GetPreparer(ctx, resourceGroupName, serverName, jobAgentName, jobName, stepName)
241	if err != nil {
242		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "Get", nil, "Failure preparing request")
243		return
244	}
245
246	resp, err := client.GetSender(req)
247	if err != nil {
248		result.Response = autorest.Response{Response: resp}
249		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "Get", resp, "Failure sending request")
250		return
251	}
252
253	result, err = client.GetResponder(resp)
254	if err != nil {
255		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "Get", resp, "Failure responding to request")
256		return
257	}
258
259	return
260}
261
262// GetPreparer prepares the Get request.
263func (client JobStepsClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, jobName string, stepName string) (*http.Request, error) {
264	pathParameters := map[string]interface{}{
265		"jobAgentName":      autorest.Encode("path", jobAgentName),
266		"jobName":           autorest.Encode("path", jobName),
267		"resourceGroupName": autorest.Encode("path", resourceGroupName),
268		"serverName":        autorest.Encode("path", serverName),
269		"stepName":          autorest.Encode("path", stepName),
270		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
271	}
272
273	const APIVersion = "2017-03-01-preview"
274	queryParameters := map[string]interface{}{
275		"api-version": APIVersion,
276	}
277
278	preparer := autorest.CreatePreparer(
279		autorest.AsGet(),
280		autorest.WithBaseURL(client.BaseURI),
281		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}", pathParameters),
282		autorest.WithQueryParameters(queryParameters))
283	return preparer.Prepare((&http.Request{}).WithContext(ctx))
284}
285
286// GetSender sends the Get request. The method will close the
287// http.Response Body if it receives an error.
288func (client JobStepsClient) GetSender(req *http.Request) (*http.Response, error) {
289	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
290}
291
292// GetResponder handles the response to the Get request. The method always
293// closes the http.Response Body.
294func (client JobStepsClient) GetResponder(resp *http.Response) (result JobStep, err error) {
295	err = autorest.Respond(
296		resp,
297		azure.WithErrorUnlessStatusCode(http.StatusOK),
298		autorest.ByUnmarshallingJSON(&result),
299		autorest.ByClosing())
300	result.Response = autorest.Response{Response: resp}
301	return
302}
303
304// GetByVersion gets the specified version of a job step.
305// Parameters:
306// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
307// from the Azure Resource Manager API or the portal.
308// serverName - the name of the server.
309// jobAgentName - the name of the job agent.
310// jobName - the name of the job.
311// jobVersion - the version of the job to get.
312// stepName - the name of the job step.
313func (client JobStepsClient) GetByVersion(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, jobName string, jobVersion int32, stepName string) (result JobStep, err error) {
314	if tracing.IsEnabled() {
315		ctx = tracing.StartSpan(ctx, fqdn+"/JobStepsClient.GetByVersion")
316		defer func() {
317			sc := -1
318			if result.Response.Response != nil {
319				sc = result.Response.Response.StatusCode
320			}
321			tracing.EndSpan(ctx, sc, err)
322		}()
323	}
324	req, err := client.GetByVersionPreparer(ctx, resourceGroupName, serverName, jobAgentName, jobName, jobVersion, stepName)
325	if err != nil {
326		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "GetByVersion", nil, "Failure preparing request")
327		return
328	}
329
330	resp, err := client.GetByVersionSender(req)
331	if err != nil {
332		result.Response = autorest.Response{Response: resp}
333		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "GetByVersion", resp, "Failure sending request")
334		return
335	}
336
337	result, err = client.GetByVersionResponder(resp)
338	if err != nil {
339		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "GetByVersion", resp, "Failure responding to request")
340		return
341	}
342
343	return
344}
345
346// GetByVersionPreparer prepares the GetByVersion request.
347func (client JobStepsClient) GetByVersionPreparer(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, jobName string, jobVersion int32, stepName string) (*http.Request, error) {
348	pathParameters := map[string]interface{}{
349		"jobAgentName":      autorest.Encode("path", jobAgentName),
350		"jobName":           autorest.Encode("path", jobName),
351		"jobVersion":        autorest.Encode("path", jobVersion),
352		"resourceGroupName": autorest.Encode("path", resourceGroupName),
353		"serverName":        autorest.Encode("path", serverName),
354		"stepName":          autorest.Encode("path", stepName),
355		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
356	}
357
358	const APIVersion = "2017-03-01-preview"
359	queryParameters := map[string]interface{}{
360		"api-version": APIVersion,
361	}
362
363	preparer := autorest.CreatePreparer(
364		autorest.AsGet(),
365		autorest.WithBaseURL(client.BaseURI),
366		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}/steps/{stepName}", pathParameters),
367		autorest.WithQueryParameters(queryParameters))
368	return preparer.Prepare((&http.Request{}).WithContext(ctx))
369}
370
371// GetByVersionSender sends the GetByVersion request. The method will close the
372// http.Response Body if it receives an error.
373func (client JobStepsClient) GetByVersionSender(req *http.Request) (*http.Response, error) {
374	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
375}
376
377// GetByVersionResponder handles the response to the GetByVersion request. The method always
378// closes the http.Response Body.
379func (client JobStepsClient) GetByVersionResponder(resp *http.Response) (result JobStep, err error) {
380	err = autorest.Respond(
381		resp,
382		azure.WithErrorUnlessStatusCode(http.StatusOK),
383		autorest.ByUnmarshallingJSON(&result),
384		autorest.ByClosing())
385	result.Response = autorest.Response{Response: resp}
386	return
387}
388
389// ListByJob gets all job steps for a job's current version.
390// Parameters:
391// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
392// from the Azure Resource Manager API or the portal.
393// serverName - the name of the server.
394// jobAgentName - the name of the job agent.
395// jobName - the name of the job to get.
396func (client JobStepsClient) ListByJob(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, jobName string) (result JobStepListResultPage, err error) {
397	if tracing.IsEnabled() {
398		ctx = tracing.StartSpan(ctx, fqdn+"/JobStepsClient.ListByJob")
399		defer func() {
400			sc := -1
401			if result.jslr.Response.Response != nil {
402				sc = result.jslr.Response.Response.StatusCode
403			}
404			tracing.EndSpan(ctx, sc, err)
405		}()
406	}
407	result.fn = client.listByJobNextResults
408	req, err := client.ListByJobPreparer(ctx, resourceGroupName, serverName, jobAgentName, jobName)
409	if err != nil {
410		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "ListByJob", nil, "Failure preparing request")
411		return
412	}
413
414	resp, err := client.ListByJobSender(req)
415	if err != nil {
416		result.jslr.Response = autorest.Response{Response: resp}
417		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "ListByJob", resp, "Failure sending request")
418		return
419	}
420
421	result.jslr, err = client.ListByJobResponder(resp)
422	if err != nil {
423		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "ListByJob", resp, "Failure responding to request")
424		return
425	}
426	if result.jslr.hasNextLink() && result.jslr.IsEmpty() {
427		err = result.NextWithContext(ctx)
428		return
429	}
430
431	return
432}
433
434// ListByJobPreparer prepares the ListByJob request.
435func (client JobStepsClient) ListByJobPreparer(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, jobName string) (*http.Request, error) {
436	pathParameters := map[string]interface{}{
437		"jobAgentName":      autorest.Encode("path", jobAgentName),
438		"jobName":           autorest.Encode("path", jobName),
439		"resourceGroupName": autorest.Encode("path", resourceGroupName),
440		"serverName":        autorest.Encode("path", serverName),
441		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
442	}
443
444	const APIVersion = "2017-03-01-preview"
445	queryParameters := map[string]interface{}{
446		"api-version": APIVersion,
447	}
448
449	preparer := autorest.CreatePreparer(
450		autorest.AsGet(),
451		autorest.WithBaseURL(client.BaseURI),
452		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps", pathParameters),
453		autorest.WithQueryParameters(queryParameters))
454	return preparer.Prepare((&http.Request{}).WithContext(ctx))
455}
456
457// ListByJobSender sends the ListByJob request. The method will close the
458// http.Response Body if it receives an error.
459func (client JobStepsClient) ListByJobSender(req *http.Request) (*http.Response, error) {
460	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
461}
462
463// ListByJobResponder handles the response to the ListByJob request. The method always
464// closes the http.Response Body.
465func (client JobStepsClient) ListByJobResponder(resp *http.Response) (result JobStepListResult, err error) {
466	err = autorest.Respond(
467		resp,
468		azure.WithErrorUnlessStatusCode(http.StatusOK),
469		autorest.ByUnmarshallingJSON(&result),
470		autorest.ByClosing())
471	result.Response = autorest.Response{Response: resp}
472	return
473}
474
475// listByJobNextResults retrieves the next set of results, if any.
476func (client JobStepsClient) listByJobNextResults(ctx context.Context, lastResults JobStepListResult) (result JobStepListResult, err error) {
477	req, err := lastResults.jobStepListResultPreparer(ctx)
478	if err != nil {
479		return result, autorest.NewErrorWithError(err, "sql.JobStepsClient", "listByJobNextResults", nil, "Failure preparing next results request")
480	}
481	if req == nil {
482		return
483	}
484	resp, err := client.ListByJobSender(req)
485	if err != nil {
486		result.Response = autorest.Response{Response: resp}
487		return result, autorest.NewErrorWithError(err, "sql.JobStepsClient", "listByJobNextResults", resp, "Failure sending next results request")
488	}
489	result, err = client.ListByJobResponder(resp)
490	if err != nil {
491		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "listByJobNextResults", resp, "Failure responding to next results request")
492	}
493	return
494}
495
496// ListByJobComplete enumerates all values, automatically crossing page boundaries as required.
497func (client JobStepsClient) ListByJobComplete(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, jobName string) (result JobStepListResultIterator, err error) {
498	if tracing.IsEnabled() {
499		ctx = tracing.StartSpan(ctx, fqdn+"/JobStepsClient.ListByJob")
500		defer func() {
501			sc := -1
502			if result.Response().Response.Response != nil {
503				sc = result.page.Response().Response.Response.StatusCode
504			}
505			tracing.EndSpan(ctx, sc, err)
506		}()
507	}
508	result.page, err = client.ListByJob(ctx, resourceGroupName, serverName, jobAgentName, jobName)
509	return
510}
511
512// ListByVersion gets all job steps in the specified job version.
513// Parameters:
514// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
515// from the Azure Resource Manager API or the portal.
516// serverName - the name of the server.
517// jobAgentName - the name of the job agent.
518// jobName - the name of the job to get.
519// jobVersion - the version of the job to get.
520func (client JobStepsClient) ListByVersion(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, jobName string, jobVersion int32) (result JobStepListResultPage, err error) {
521	if tracing.IsEnabled() {
522		ctx = tracing.StartSpan(ctx, fqdn+"/JobStepsClient.ListByVersion")
523		defer func() {
524			sc := -1
525			if result.jslr.Response.Response != nil {
526				sc = result.jslr.Response.Response.StatusCode
527			}
528			tracing.EndSpan(ctx, sc, err)
529		}()
530	}
531	result.fn = client.listByVersionNextResults
532	req, err := client.ListByVersionPreparer(ctx, resourceGroupName, serverName, jobAgentName, jobName, jobVersion)
533	if err != nil {
534		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "ListByVersion", nil, "Failure preparing request")
535		return
536	}
537
538	resp, err := client.ListByVersionSender(req)
539	if err != nil {
540		result.jslr.Response = autorest.Response{Response: resp}
541		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "ListByVersion", resp, "Failure sending request")
542		return
543	}
544
545	result.jslr, err = client.ListByVersionResponder(resp)
546	if err != nil {
547		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "ListByVersion", resp, "Failure responding to request")
548		return
549	}
550	if result.jslr.hasNextLink() && result.jslr.IsEmpty() {
551		err = result.NextWithContext(ctx)
552		return
553	}
554
555	return
556}
557
558// ListByVersionPreparer prepares the ListByVersion request.
559func (client JobStepsClient) ListByVersionPreparer(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, jobName string, jobVersion int32) (*http.Request, error) {
560	pathParameters := map[string]interface{}{
561		"jobAgentName":      autorest.Encode("path", jobAgentName),
562		"jobName":           autorest.Encode("path", jobName),
563		"jobVersion":        autorest.Encode("path", jobVersion),
564		"resourceGroupName": autorest.Encode("path", resourceGroupName),
565		"serverName":        autorest.Encode("path", serverName),
566		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
567	}
568
569	const APIVersion = "2017-03-01-preview"
570	queryParameters := map[string]interface{}{
571		"api-version": APIVersion,
572	}
573
574	preparer := autorest.CreatePreparer(
575		autorest.AsGet(),
576		autorest.WithBaseURL(client.BaseURI),
577		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}/steps", pathParameters),
578		autorest.WithQueryParameters(queryParameters))
579	return preparer.Prepare((&http.Request{}).WithContext(ctx))
580}
581
582// ListByVersionSender sends the ListByVersion request. The method will close the
583// http.Response Body if it receives an error.
584func (client JobStepsClient) ListByVersionSender(req *http.Request) (*http.Response, error) {
585	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
586}
587
588// ListByVersionResponder handles the response to the ListByVersion request. The method always
589// closes the http.Response Body.
590func (client JobStepsClient) ListByVersionResponder(resp *http.Response) (result JobStepListResult, err error) {
591	err = autorest.Respond(
592		resp,
593		azure.WithErrorUnlessStatusCode(http.StatusOK),
594		autorest.ByUnmarshallingJSON(&result),
595		autorest.ByClosing())
596	result.Response = autorest.Response{Response: resp}
597	return
598}
599
600// listByVersionNextResults retrieves the next set of results, if any.
601func (client JobStepsClient) listByVersionNextResults(ctx context.Context, lastResults JobStepListResult) (result JobStepListResult, err error) {
602	req, err := lastResults.jobStepListResultPreparer(ctx)
603	if err != nil {
604		return result, autorest.NewErrorWithError(err, "sql.JobStepsClient", "listByVersionNextResults", nil, "Failure preparing next results request")
605	}
606	if req == nil {
607		return
608	}
609	resp, err := client.ListByVersionSender(req)
610	if err != nil {
611		result.Response = autorest.Response{Response: resp}
612		return result, autorest.NewErrorWithError(err, "sql.JobStepsClient", "listByVersionNextResults", resp, "Failure sending next results request")
613	}
614	result, err = client.ListByVersionResponder(resp)
615	if err != nil {
616		err = autorest.NewErrorWithError(err, "sql.JobStepsClient", "listByVersionNextResults", resp, "Failure responding to next results request")
617	}
618	return
619}
620
621// ListByVersionComplete enumerates all values, automatically crossing page boundaries as required.
622func (client JobStepsClient) ListByVersionComplete(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, jobName string, jobVersion int32) (result JobStepListResultIterator, err error) {
623	if tracing.IsEnabled() {
624		ctx = tracing.StartSpan(ctx, fqdn+"/JobStepsClient.ListByVersion")
625		defer func() {
626			sc := -1
627			if result.Response().Response.Response != nil {
628				sc = result.page.Response().Response.Response.StatusCode
629			}
630			tracing.EndSpan(ctx, sc, err)
631		}()
632	}
633	result.page, err = client.ListByVersion(ctx, resourceGroupName, serverName, jobAgentName, jobName, jobVersion)
634	return
635}
636