1package batch
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/date"
14	"github.com/Azure/go-autorest/autorest/validation"
15	"github.com/Azure/go-autorest/tracing"
16	"github.com/gofrs/uuid"
17	"net/http"
18)
19
20// TaskClient is the a client for issuing REST requests to the Azure Batch service.
21type TaskClient struct {
22	BaseClient
23}
24
25// NewTaskClient creates an instance of the TaskClient client.
26func NewTaskClient(batchURL string) TaskClient {
27	return TaskClient{New(batchURL)}
28}
29
30// Add the maximum lifetime of a Task from addition to completion is 180 days. If a Task has not completed within 180
31// days of being added it will be terminated by the Batch service and left in whatever state it was in at that time.
32// Parameters:
33// jobID - the ID of the Job to which the Task is to be added.
34// task - the Task to be added.
35// timeout - the maximum time that the server can spend processing the request, in seconds. The default is 30
36// seconds.
37// clientRequestID - the caller-generated request identity, in the form of a GUID with no decoration such as
38// curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
39// returnClientRequestID - whether the server should return the client-request-id in the response.
40// ocpDate - the time the request was issued. Client libraries typically set this to the current system clock
41// time; set it explicitly if you are calling the REST API directly.
42func (client TaskClient) Add(ctx context.Context, jobID string, task TaskAddParameter, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result autorest.Response, err error) {
43	if tracing.IsEnabled() {
44		ctx = tracing.StartSpan(ctx, fqdn+"/TaskClient.Add")
45		defer func() {
46			sc := -1
47			if result.Response != nil {
48				sc = result.Response.StatusCode
49			}
50			tracing.EndSpan(ctx, sc, err)
51		}()
52	}
53	if err := validation.Validate([]validation.Validation{
54		{TargetValue: task,
55			Constraints: []validation.Constraint{{Target: "task.ID", Name: validation.Null, Rule: true, Chain: nil},
56				{Target: "task.CommandLine", Name: validation.Null, Rule: true, Chain: nil},
57				{Target: "task.ContainerSettings", Name: validation.Null, Rule: false,
58					Chain: []validation.Constraint{{Target: "task.ContainerSettings.ImageName", Name: validation.Null, Rule: true, Chain: nil},
59						{Target: "task.ContainerSettings.Registry", Name: validation.Null, Rule: false,
60							Chain: []validation.Constraint{{Target: "task.ContainerSettings.Registry.UserName", Name: validation.Null, Rule: true, Chain: nil},
61								{Target: "task.ContainerSettings.Registry.Password", Name: validation.Null, Rule: true, Chain: nil},
62							}},
63					}},
64				{Target: "task.AffinityInfo", Name: validation.Null, Rule: false,
65					Chain: []validation.Constraint{{Target: "task.AffinityInfo.AffinityID", Name: validation.Null, Rule: true, Chain: nil}}},
66				{Target: "task.MultiInstanceSettings", Name: validation.Null, Rule: false,
67					Chain: []validation.Constraint{{Target: "task.MultiInstanceSettings.CoordinationCommandLine", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
68		return result, validation.NewError("batch.TaskClient", "Add", err.Error())
69	}
70
71	req, err := client.AddPreparer(ctx, jobID, task, timeout, clientRequestID, returnClientRequestID, ocpDate)
72	if err != nil {
73		err = autorest.NewErrorWithError(err, "batch.TaskClient", "Add", nil, "Failure preparing request")
74		return
75	}
76
77	resp, err := client.AddSender(req)
78	if err != nil {
79		result.Response = resp
80		err = autorest.NewErrorWithError(err, "batch.TaskClient", "Add", resp, "Failure sending request")
81		return
82	}
83
84	result, err = client.AddResponder(resp)
85	if err != nil {
86		err = autorest.NewErrorWithError(err, "batch.TaskClient", "Add", resp, "Failure responding to request")
87		return
88	}
89
90	return
91}
92
93// AddPreparer prepares the Add request.
94func (client TaskClient) AddPreparer(ctx context.Context, jobID string, task TaskAddParameter, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (*http.Request, error) {
95	urlParameters := map[string]interface{}{
96		"batchUrl": client.BatchURL,
97	}
98
99	pathParameters := map[string]interface{}{
100		"jobId": autorest.Encode("path", jobID),
101	}
102
103	const APIVersion = "2020-09-01.12.0"
104	queryParameters := map[string]interface{}{
105		"api-version": APIVersion,
106	}
107	if timeout != nil {
108		queryParameters["timeout"] = autorest.Encode("query", *timeout)
109	} else {
110		queryParameters["timeout"] = autorest.Encode("query", 30)
111	}
112
113	preparer := autorest.CreatePreparer(
114		autorest.AsContentType("application/json; odata=minimalmetadata; charset=utf-8"),
115		autorest.AsPost(),
116		autorest.WithCustomBaseURL("{batchUrl}", urlParameters),
117		autorest.WithPathParameters("/jobs/{jobId}/tasks", pathParameters),
118		autorest.WithJSON(task),
119		autorest.WithQueryParameters(queryParameters))
120	if clientRequestID != nil {
121		preparer = autorest.DecoratePreparer(preparer,
122			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
123	}
124	if returnClientRequestID != nil {
125		preparer = autorest.DecoratePreparer(preparer,
126			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
127	} else {
128		preparer = autorest.DecoratePreparer(preparer,
129			autorest.WithHeader("return-client-request-id", autorest.String(false)))
130	}
131	if ocpDate != nil {
132		preparer = autorest.DecoratePreparer(preparer,
133			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
134	}
135	return preparer.Prepare((&http.Request{}).WithContext(ctx))
136}
137
138// AddSender sends the Add request. The method will close the
139// http.Response Body if it receives an error.
140func (client TaskClient) AddSender(req *http.Request) (*http.Response, error) {
141	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
142}
143
144// AddResponder handles the response to the Add request. The method always
145// closes the http.Response Body.
146func (client TaskClient) AddResponder(resp *http.Response) (result autorest.Response, err error) {
147	err = autorest.Respond(
148		resp,
149		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
150		autorest.ByClosing())
151	result.Response = resp
152	return
153}
154
155// AddCollection note that each Task must have a unique ID. The Batch service may not return the results for each Task
156// in the same order the Tasks were submitted in this request. If the server times out or the connection is closed
157// during the request, the request may have been partially or fully processed, or not at all. In such cases, the user
158// should re-issue the request. Note that it is up to the user to correctly handle failures when re-issuing a request.
159// For example, you should use the same Task IDs during a retry so that if the prior operation succeeded, the retry
160// will not create extra Tasks unexpectedly. If the response contains any Tasks which failed to add, a client can retry
161// the request. In a retry, it is most efficient to resubmit only Tasks that failed to add, and to omit Tasks that were
162// successfully added on the first attempt. The maximum lifetime of a Task from addition to completion is 180 days. If
163// a Task has not completed within 180 days of being added it will be terminated by the Batch service and left in
164// whatever state it was in at that time.
165// Parameters:
166// jobID - the ID of the Job to which the Task collection is to be added.
167// taskCollection - the Tasks to be added.
168// timeout - the maximum time that the server can spend processing the request, in seconds. The default is 30
169// seconds.
170// clientRequestID - the caller-generated request identity, in the form of a GUID with no decoration such as
171// curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
172// returnClientRequestID - whether the server should return the client-request-id in the response.
173// ocpDate - the time the request was issued. Client libraries typically set this to the current system clock
174// time; set it explicitly if you are calling the REST API directly.
175func (client TaskClient) AddCollection(ctx context.Context, jobID string, taskCollection TaskAddCollectionParameter, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result TaskAddCollectionResult, err error) {
176	if tracing.IsEnabled() {
177		ctx = tracing.StartSpan(ctx, fqdn+"/TaskClient.AddCollection")
178		defer func() {
179			sc := -1
180			if result.Response.Response != nil {
181				sc = result.Response.Response.StatusCode
182			}
183			tracing.EndSpan(ctx, sc, err)
184		}()
185	}
186	if err := validation.Validate([]validation.Validation{
187		{TargetValue: taskCollection,
188			Constraints: []validation.Constraint{{Target: "taskCollection.Value", Name: validation.Null, Rule: true,
189				Chain: []validation.Constraint{{Target: "taskCollection.Value", Name: validation.MaxItems, Rule: 100, Chain: nil}}}}}}); err != nil {
190		return result, validation.NewError("batch.TaskClient", "AddCollection", err.Error())
191	}
192
193	req, err := client.AddCollectionPreparer(ctx, jobID, taskCollection, timeout, clientRequestID, returnClientRequestID, ocpDate)
194	if err != nil {
195		err = autorest.NewErrorWithError(err, "batch.TaskClient", "AddCollection", nil, "Failure preparing request")
196		return
197	}
198
199	resp, err := client.AddCollectionSender(req)
200	if err != nil {
201		result.Response = autorest.Response{Response: resp}
202		err = autorest.NewErrorWithError(err, "batch.TaskClient", "AddCollection", resp, "Failure sending request")
203		return
204	}
205
206	result, err = client.AddCollectionResponder(resp)
207	if err != nil {
208		err = autorest.NewErrorWithError(err, "batch.TaskClient", "AddCollection", resp, "Failure responding to request")
209		return
210	}
211
212	return
213}
214
215// AddCollectionPreparer prepares the AddCollection request.
216func (client TaskClient) AddCollectionPreparer(ctx context.Context, jobID string, taskCollection TaskAddCollectionParameter, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (*http.Request, error) {
217	urlParameters := map[string]interface{}{
218		"batchUrl": client.BatchURL,
219	}
220
221	pathParameters := map[string]interface{}{
222		"jobId": autorest.Encode("path", jobID),
223	}
224
225	const APIVersion = "2020-09-01.12.0"
226	queryParameters := map[string]interface{}{
227		"api-version": APIVersion,
228	}
229	if timeout != nil {
230		queryParameters["timeout"] = autorest.Encode("query", *timeout)
231	} else {
232		queryParameters["timeout"] = autorest.Encode("query", 30)
233	}
234
235	preparer := autorest.CreatePreparer(
236		autorest.AsContentType("application/json; odata=minimalmetadata; charset=utf-8"),
237		autorest.AsPost(),
238		autorest.WithCustomBaseURL("{batchUrl}", urlParameters),
239		autorest.WithPathParameters("/jobs/{jobId}/addtaskcollection", pathParameters),
240		autorest.WithJSON(taskCollection),
241		autorest.WithQueryParameters(queryParameters))
242	if clientRequestID != nil {
243		preparer = autorest.DecoratePreparer(preparer,
244			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
245	}
246	if returnClientRequestID != nil {
247		preparer = autorest.DecoratePreparer(preparer,
248			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
249	} else {
250		preparer = autorest.DecoratePreparer(preparer,
251			autorest.WithHeader("return-client-request-id", autorest.String(false)))
252	}
253	if ocpDate != nil {
254		preparer = autorest.DecoratePreparer(preparer,
255			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
256	}
257	return preparer.Prepare((&http.Request{}).WithContext(ctx))
258}
259
260// AddCollectionSender sends the AddCollection request. The method will close the
261// http.Response Body if it receives an error.
262func (client TaskClient) AddCollectionSender(req *http.Request) (*http.Response, error) {
263	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
264}
265
266// AddCollectionResponder handles the response to the AddCollection request. The method always
267// closes the http.Response Body.
268func (client TaskClient) AddCollectionResponder(resp *http.Response) (result TaskAddCollectionResult, err error) {
269	err = autorest.Respond(
270		resp,
271		azure.WithErrorUnlessStatusCode(http.StatusOK),
272		autorest.ByUnmarshallingJSON(&result),
273		autorest.ByClosing())
274	result.Response = autorest.Response{Response: resp}
275	return
276}
277
278// Delete when a Task is deleted, all of the files in its directory on the Compute Node where it ran are also deleted
279// (regardless of the retention time). For multi-instance Tasks, the delete Task operation applies synchronously to the
280// primary task; subtasks and their files are then deleted asynchronously in the background.
281// Parameters:
282// jobID - the ID of the Job from which to delete the Task.
283// taskID - the ID of the Task to delete.
284// timeout - the maximum time that the server can spend processing the request, in seconds. The default is 30
285// seconds.
286// clientRequestID - the caller-generated request identity, in the form of a GUID with no decoration such as
287// curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
288// returnClientRequestID - whether the server should return the client-request-id in the response.
289// ocpDate - the time the request was issued. Client libraries typically set this to the current system clock
290// time; set it explicitly if you are calling the REST API directly.
291// ifMatch - an ETag value associated with the version of the resource known to the client. The operation will
292// be performed only if the resource's current ETag on the service exactly matches the value specified by the
293// client.
294// ifNoneMatch - an ETag value associated with the version of the resource known to the client. The operation
295// will be performed only if the resource's current ETag on the service does not match the value specified by
296// the client.
297// ifModifiedSince - a timestamp indicating the last modified time of the resource known to the client. The
298// operation will be performed only if the resource on the service has been modified since the specified time.
299// ifUnmodifiedSince - a timestamp indicating the last modified time of the resource known to the client. The
300// operation will be performed only if the resource on the service has not been modified since the specified
301// time.
302func (client TaskClient) Delete(ctx context.Context, jobID string, taskID string, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123, ifMatch string, ifNoneMatch string, ifModifiedSince *date.TimeRFC1123, ifUnmodifiedSince *date.TimeRFC1123) (result autorest.Response, err error) {
303	if tracing.IsEnabled() {
304		ctx = tracing.StartSpan(ctx, fqdn+"/TaskClient.Delete")
305		defer func() {
306			sc := -1
307			if result.Response != nil {
308				sc = result.Response.StatusCode
309			}
310			tracing.EndSpan(ctx, sc, err)
311		}()
312	}
313	req, err := client.DeletePreparer(ctx, jobID, taskID, timeout, clientRequestID, returnClientRequestID, ocpDate, ifMatch, ifNoneMatch, ifModifiedSince, ifUnmodifiedSince)
314	if err != nil {
315		err = autorest.NewErrorWithError(err, "batch.TaskClient", "Delete", nil, "Failure preparing request")
316		return
317	}
318
319	resp, err := client.DeleteSender(req)
320	if err != nil {
321		result.Response = resp
322		err = autorest.NewErrorWithError(err, "batch.TaskClient", "Delete", resp, "Failure sending request")
323		return
324	}
325
326	result, err = client.DeleteResponder(resp)
327	if err != nil {
328		err = autorest.NewErrorWithError(err, "batch.TaskClient", "Delete", resp, "Failure responding to request")
329		return
330	}
331
332	return
333}
334
335// DeletePreparer prepares the Delete request.
336func (client TaskClient) DeletePreparer(ctx context.Context, jobID string, taskID string, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123, ifMatch string, ifNoneMatch string, ifModifiedSince *date.TimeRFC1123, ifUnmodifiedSince *date.TimeRFC1123) (*http.Request, error) {
337	urlParameters := map[string]interface{}{
338		"batchUrl": client.BatchURL,
339	}
340
341	pathParameters := map[string]interface{}{
342		"jobId":  autorest.Encode("path", jobID),
343		"taskId": autorest.Encode("path", taskID),
344	}
345
346	const APIVersion = "2020-09-01.12.0"
347	queryParameters := map[string]interface{}{
348		"api-version": APIVersion,
349	}
350	if timeout != nil {
351		queryParameters["timeout"] = autorest.Encode("query", *timeout)
352	} else {
353		queryParameters["timeout"] = autorest.Encode("query", 30)
354	}
355
356	preparer := autorest.CreatePreparer(
357		autorest.AsDelete(),
358		autorest.WithCustomBaseURL("{batchUrl}", urlParameters),
359		autorest.WithPathParameters("/jobs/{jobId}/tasks/{taskId}", pathParameters),
360		autorest.WithQueryParameters(queryParameters))
361	if clientRequestID != nil {
362		preparer = autorest.DecoratePreparer(preparer,
363			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
364	}
365	if returnClientRequestID != nil {
366		preparer = autorest.DecoratePreparer(preparer,
367			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
368	} else {
369		preparer = autorest.DecoratePreparer(preparer,
370			autorest.WithHeader("return-client-request-id", autorest.String(false)))
371	}
372	if ocpDate != nil {
373		preparer = autorest.DecoratePreparer(preparer,
374			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
375	}
376	if len(ifMatch) > 0 {
377		preparer = autorest.DecoratePreparer(preparer,
378			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
379	}
380	if len(ifNoneMatch) > 0 {
381		preparer = autorest.DecoratePreparer(preparer,
382			autorest.WithHeader("If-None-Match", autorest.String(ifNoneMatch)))
383	}
384	if ifModifiedSince != nil {
385		preparer = autorest.DecoratePreparer(preparer,
386			autorest.WithHeader("If-Modified-Since", autorest.String(ifModifiedSince)))
387	}
388	if ifUnmodifiedSince != nil {
389		preparer = autorest.DecoratePreparer(preparer,
390			autorest.WithHeader("If-Unmodified-Since", autorest.String(ifUnmodifiedSince)))
391	}
392	return preparer.Prepare((&http.Request{}).WithContext(ctx))
393}
394
395// DeleteSender sends the Delete request. The method will close the
396// http.Response Body if it receives an error.
397func (client TaskClient) DeleteSender(req *http.Request) (*http.Response, error) {
398	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
399}
400
401// DeleteResponder handles the response to the Delete request. The method always
402// closes the http.Response Body.
403func (client TaskClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
404	err = autorest.Respond(
405		resp,
406		azure.WithErrorUnlessStatusCode(http.StatusOK),
407		autorest.ByClosing())
408	result.Response = resp
409	return
410}
411
412// Get for multi-instance Tasks, information such as affinityId, executionInfo and nodeInfo refer to the primary Task.
413// Use the list subtasks API to retrieve information about subtasks.
414// Parameters:
415// jobID - the ID of the Job that contains the Task.
416// taskID - the ID of the Task to get information about.
417// selectParameter - an OData $select clause.
418// expand - an OData $expand clause.
419// timeout - the maximum time that the server can spend processing the request, in seconds. The default is 30
420// seconds.
421// clientRequestID - the caller-generated request identity, in the form of a GUID with no decoration such as
422// curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
423// returnClientRequestID - whether the server should return the client-request-id in the response.
424// ocpDate - the time the request was issued. Client libraries typically set this to the current system clock
425// time; set it explicitly if you are calling the REST API directly.
426// ifMatch - an ETag value associated with the version of the resource known to the client. The operation will
427// be performed only if the resource's current ETag on the service exactly matches the value specified by the
428// client.
429// ifNoneMatch - an ETag value associated with the version of the resource known to the client. The operation
430// will be performed only if the resource's current ETag on the service does not match the value specified by
431// the client.
432// ifModifiedSince - a timestamp indicating the last modified time of the resource known to the client. The
433// operation will be performed only if the resource on the service has been modified since the specified time.
434// ifUnmodifiedSince - a timestamp indicating the last modified time of the resource known to the client. The
435// operation will be performed only if the resource on the service has not been modified since the specified
436// time.
437func (client TaskClient) Get(ctx context.Context, jobID string, taskID string, selectParameter string, expand string, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123, ifMatch string, ifNoneMatch string, ifModifiedSince *date.TimeRFC1123, ifUnmodifiedSince *date.TimeRFC1123) (result CloudTask, err error) {
438	if tracing.IsEnabled() {
439		ctx = tracing.StartSpan(ctx, fqdn+"/TaskClient.Get")
440		defer func() {
441			sc := -1
442			if result.Response.Response != nil {
443				sc = result.Response.Response.StatusCode
444			}
445			tracing.EndSpan(ctx, sc, err)
446		}()
447	}
448	req, err := client.GetPreparer(ctx, jobID, taskID, selectParameter, expand, timeout, clientRequestID, returnClientRequestID, ocpDate, ifMatch, ifNoneMatch, ifModifiedSince, ifUnmodifiedSince)
449	if err != nil {
450		err = autorest.NewErrorWithError(err, "batch.TaskClient", "Get", nil, "Failure preparing request")
451		return
452	}
453
454	resp, err := client.GetSender(req)
455	if err != nil {
456		result.Response = autorest.Response{Response: resp}
457		err = autorest.NewErrorWithError(err, "batch.TaskClient", "Get", resp, "Failure sending request")
458		return
459	}
460
461	result, err = client.GetResponder(resp)
462	if err != nil {
463		err = autorest.NewErrorWithError(err, "batch.TaskClient", "Get", resp, "Failure responding to request")
464		return
465	}
466
467	return
468}
469
470// GetPreparer prepares the Get request.
471func (client TaskClient) GetPreparer(ctx context.Context, jobID string, taskID string, selectParameter string, expand string, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123, ifMatch string, ifNoneMatch string, ifModifiedSince *date.TimeRFC1123, ifUnmodifiedSince *date.TimeRFC1123) (*http.Request, error) {
472	urlParameters := map[string]interface{}{
473		"batchUrl": client.BatchURL,
474	}
475
476	pathParameters := map[string]interface{}{
477		"jobId":  autorest.Encode("path", jobID),
478		"taskId": autorest.Encode("path", taskID),
479	}
480
481	const APIVersion = "2020-09-01.12.0"
482	queryParameters := map[string]interface{}{
483		"api-version": APIVersion,
484	}
485	if len(selectParameter) > 0 {
486		queryParameters["$select"] = autorest.Encode("query", selectParameter)
487	}
488	if len(expand) > 0 {
489		queryParameters["$expand"] = autorest.Encode("query", expand)
490	}
491	if timeout != nil {
492		queryParameters["timeout"] = autorest.Encode("query", *timeout)
493	} else {
494		queryParameters["timeout"] = autorest.Encode("query", 30)
495	}
496
497	preparer := autorest.CreatePreparer(
498		autorest.AsGet(),
499		autorest.WithCustomBaseURL("{batchUrl}", urlParameters),
500		autorest.WithPathParameters("/jobs/{jobId}/tasks/{taskId}", pathParameters),
501		autorest.WithQueryParameters(queryParameters))
502	if clientRequestID != nil {
503		preparer = autorest.DecoratePreparer(preparer,
504			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
505	}
506	if returnClientRequestID != nil {
507		preparer = autorest.DecoratePreparer(preparer,
508			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
509	} else {
510		preparer = autorest.DecoratePreparer(preparer,
511			autorest.WithHeader("return-client-request-id", autorest.String(false)))
512	}
513	if ocpDate != nil {
514		preparer = autorest.DecoratePreparer(preparer,
515			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
516	}
517	if len(ifMatch) > 0 {
518		preparer = autorest.DecoratePreparer(preparer,
519			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
520	}
521	if len(ifNoneMatch) > 0 {
522		preparer = autorest.DecoratePreparer(preparer,
523			autorest.WithHeader("If-None-Match", autorest.String(ifNoneMatch)))
524	}
525	if ifModifiedSince != nil {
526		preparer = autorest.DecoratePreparer(preparer,
527			autorest.WithHeader("If-Modified-Since", autorest.String(ifModifiedSince)))
528	}
529	if ifUnmodifiedSince != nil {
530		preparer = autorest.DecoratePreparer(preparer,
531			autorest.WithHeader("If-Unmodified-Since", autorest.String(ifUnmodifiedSince)))
532	}
533	return preparer.Prepare((&http.Request{}).WithContext(ctx))
534}
535
536// GetSender sends the Get request. The method will close the
537// http.Response Body if it receives an error.
538func (client TaskClient) GetSender(req *http.Request) (*http.Response, error) {
539	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
540}
541
542// GetResponder handles the response to the Get request. The method always
543// closes the http.Response Body.
544func (client TaskClient) GetResponder(resp *http.Response) (result CloudTask, err error) {
545	err = autorest.Respond(
546		resp,
547		azure.WithErrorUnlessStatusCode(http.StatusOK),
548		autorest.ByUnmarshallingJSON(&result),
549		autorest.ByClosing())
550	result.Response = autorest.Response{Response: resp}
551	return
552}
553
554// List for multi-instance Tasks, information such as affinityId, executionInfo and nodeInfo refer to the primary Task.
555// Use the list subtasks API to retrieve information about subtasks.
556// Parameters:
557// jobID - the ID of the Job.
558// filter - an OData $filter clause. For more information on constructing this filter, see
559// https://docs.microsoft.com/en-us/rest/api/batchservice/odata-filters-in-batch#list-tasks.
560// selectParameter - an OData $select clause.
561// expand - an OData $expand clause.
562// maxResults - the maximum number of items to return in the response. A maximum of 1000 Tasks can be returned.
563// timeout - the maximum time that the server can spend processing the request, in seconds. The default is 30
564// seconds.
565// clientRequestID - the caller-generated request identity, in the form of a GUID with no decoration such as
566// curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
567// returnClientRequestID - whether the server should return the client-request-id in the response.
568// ocpDate - the time the request was issued. Client libraries typically set this to the current system clock
569// time; set it explicitly if you are calling the REST API directly.
570func (client TaskClient) List(ctx context.Context, jobID string, filter string, selectParameter string, expand string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result CloudTaskListResultPage, err error) {
571	if tracing.IsEnabled() {
572		ctx = tracing.StartSpan(ctx, fqdn+"/TaskClient.List")
573		defer func() {
574			sc := -1
575			if result.ctlr.Response.Response != nil {
576				sc = result.ctlr.Response.Response.StatusCode
577			}
578			tracing.EndSpan(ctx, sc, err)
579		}()
580	}
581	if err := validation.Validate([]validation.Validation{
582		{TargetValue: maxResults,
583			Constraints: []validation.Constraint{{Target: "maxResults", Name: validation.Null, Rule: false,
584				Chain: []validation.Constraint{{Target: "maxResults", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
585					{Target: "maxResults", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
586				}}}}}); err != nil {
587		return result, validation.NewError("batch.TaskClient", "List", err.Error())
588	}
589
590	result.fn = client.listNextResults
591	req, err := client.ListPreparer(ctx, jobID, filter, selectParameter, expand, maxResults, timeout, clientRequestID, returnClientRequestID, ocpDate)
592	if err != nil {
593		err = autorest.NewErrorWithError(err, "batch.TaskClient", "List", nil, "Failure preparing request")
594		return
595	}
596
597	resp, err := client.ListSender(req)
598	if err != nil {
599		result.ctlr.Response = autorest.Response{Response: resp}
600		err = autorest.NewErrorWithError(err, "batch.TaskClient", "List", resp, "Failure sending request")
601		return
602	}
603
604	result.ctlr, err = client.ListResponder(resp)
605	if err != nil {
606		err = autorest.NewErrorWithError(err, "batch.TaskClient", "List", resp, "Failure responding to request")
607		return
608	}
609	if result.ctlr.hasNextLink() && result.ctlr.IsEmpty() {
610		err = result.NextWithContext(ctx)
611		return
612	}
613
614	return
615}
616
617// ListPreparer prepares the List request.
618func (client TaskClient) ListPreparer(ctx context.Context, jobID string, filter string, selectParameter string, expand string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (*http.Request, error) {
619	urlParameters := map[string]interface{}{
620		"batchUrl": client.BatchURL,
621	}
622
623	pathParameters := map[string]interface{}{
624		"jobId": autorest.Encode("path", jobID),
625	}
626
627	const APIVersion = "2020-09-01.12.0"
628	queryParameters := map[string]interface{}{
629		"api-version": APIVersion,
630	}
631	if len(filter) > 0 {
632		queryParameters["$filter"] = autorest.Encode("query", filter)
633	}
634	if len(selectParameter) > 0 {
635		queryParameters["$select"] = autorest.Encode("query", selectParameter)
636	}
637	if len(expand) > 0 {
638		queryParameters["$expand"] = autorest.Encode("query", expand)
639	}
640	if maxResults != nil {
641		queryParameters["maxresults"] = autorest.Encode("query", *maxResults)
642	} else {
643		queryParameters["maxresults"] = autorest.Encode("query", 1000)
644	}
645	if timeout != nil {
646		queryParameters["timeout"] = autorest.Encode("query", *timeout)
647	} else {
648		queryParameters["timeout"] = autorest.Encode("query", 30)
649	}
650
651	preparer := autorest.CreatePreparer(
652		autorest.AsGet(),
653		autorest.WithCustomBaseURL("{batchUrl}", urlParameters),
654		autorest.WithPathParameters("/jobs/{jobId}/tasks", pathParameters),
655		autorest.WithQueryParameters(queryParameters))
656	if clientRequestID != nil {
657		preparer = autorest.DecoratePreparer(preparer,
658			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
659	}
660	if returnClientRequestID != nil {
661		preparer = autorest.DecoratePreparer(preparer,
662			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
663	} else {
664		preparer = autorest.DecoratePreparer(preparer,
665			autorest.WithHeader("return-client-request-id", autorest.String(false)))
666	}
667	if ocpDate != nil {
668		preparer = autorest.DecoratePreparer(preparer,
669			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
670	}
671	return preparer.Prepare((&http.Request{}).WithContext(ctx))
672}
673
674// ListSender sends the List request. The method will close the
675// http.Response Body if it receives an error.
676func (client TaskClient) ListSender(req *http.Request) (*http.Response, error) {
677	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
678}
679
680// ListResponder handles the response to the List request. The method always
681// closes the http.Response Body.
682func (client TaskClient) ListResponder(resp *http.Response) (result CloudTaskListResult, err error) {
683	err = autorest.Respond(
684		resp,
685		azure.WithErrorUnlessStatusCode(http.StatusOK),
686		autorest.ByUnmarshallingJSON(&result),
687		autorest.ByClosing())
688	result.Response = autorest.Response{Response: resp}
689	return
690}
691
692// listNextResults retrieves the next set of results, if any.
693func (client TaskClient) listNextResults(ctx context.Context, lastResults CloudTaskListResult) (result CloudTaskListResult, err error) {
694	req, err := lastResults.cloudTaskListResultPreparer(ctx)
695	if err != nil {
696		return result, autorest.NewErrorWithError(err, "batch.TaskClient", "listNextResults", nil, "Failure preparing next results request")
697	}
698	if req == nil {
699		return
700	}
701	resp, err := client.ListSender(req)
702	if err != nil {
703		result.Response = autorest.Response{Response: resp}
704		return result, autorest.NewErrorWithError(err, "batch.TaskClient", "listNextResults", resp, "Failure sending next results request")
705	}
706	result, err = client.ListResponder(resp)
707	if err != nil {
708		err = autorest.NewErrorWithError(err, "batch.TaskClient", "listNextResults", resp, "Failure responding to next results request")
709	}
710	return
711}
712
713// ListComplete enumerates all values, automatically crossing page boundaries as required.
714func (client TaskClient) ListComplete(ctx context.Context, jobID string, filter string, selectParameter string, expand string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result CloudTaskListResultIterator, err error) {
715	if tracing.IsEnabled() {
716		ctx = tracing.StartSpan(ctx, fqdn+"/TaskClient.List")
717		defer func() {
718			sc := -1
719			if result.Response().Response.Response != nil {
720				sc = result.page.Response().Response.Response.StatusCode
721			}
722			tracing.EndSpan(ctx, sc, err)
723		}()
724	}
725	result.page, err = client.List(ctx, jobID, filter, selectParameter, expand, maxResults, timeout, clientRequestID, returnClientRequestID, ocpDate)
726	return
727}
728
729// ListSubtasks if the Task is not a multi-instance Task then this returns an empty collection.
730// Parameters:
731// jobID - the ID of the Job.
732// taskID - the ID of the Task.
733// selectParameter - an OData $select clause.
734// timeout - the maximum time that the server can spend processing the request, in seconds. The default is 30
735// seconds.
736// clientRequestID - the caller-generated request identity, in the form of a GUID with no decoration such as
737// curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
738// returnClientRequestID - whether the server should return the client-request-id in the response.
739// ocpDate - the time the request was issued. Client libraries typically set this to the current system clock
740// time; set it explicitly if you are calling the REST API directly.
741func (client TaskClient) ListSubtasks(ctx context.Context, jobID string, taskID string, selectParameter string, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result CloudTaskListSubtasksResult, err error) {
742	if tracing.IsEnabled() {
743		ctx = tracing.StartSpan(ctx, fqdn+"/TaskClient.ListSubtasks")
744		defer func() {
745			sc := -1
746			if result.Response.Response != nil {
747				sc = result.Response.Response.StatusCode
748			}
749			tracing.EndSpan(ctx, sc, err)
750		}()
751	}
752	req, err := client.ListSubtasksPreparer(ctx, jobID, taskID, selectParameter, timeout, clientRequestID, returnClientRequestID, ocpDate)
753	if err != nil {
754		err = autorest.NewErrorWithError(err, "batch.TaskClient", "ListSubtasks", nil, "Failure preparing request")
755		return
756	}
757
758	resp, err := client.ListSubtasksSender(req)
759	if err != nil {
760		result.Response = autorest.Response{Response: resp}
761		err = autorest.NewErrorWithError(err, "batch.TaskClient", "ListSubtasks", resp, "Failure sending request")
762		return
763	}
764
765	result, err = client.ListSubtasksResponder(resp)
766	if err != nil {
767		err = autorest.NewErrorWithError(err, "batch.TaskClient", "ListSubtasks", resp, "Failure responding to request")
768		return
769	}
770
771	return
772}
773
774// ListSubtasksPreparer prepares the ListSubtasks request.
775func (client TaskClient) ListSubtasksPreparer(ctx context.Context, jobID string, taskID string, selectParameter string, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (*http.Request, error) {
776	urlParameters := map[string]interface{}{
777		"batchUrl": client.BatchURL,
778	}
779
780	pathParameters := map[string]interface{}{
781		"jobId":  autorest.Encode("path", jobID),
782		"taskId": autorest.Encode("path", taskID),
783	}
784
785	const APIVersion = "2020-09-01.12.0"
786	queryParameters := map[string]interface{}{
787		"api-version": APIVersion,
788	}
789	if len(selectParameter) > 0 {
790		queryParameters["$select"] = autorest.Encode("query", selectParameter)
791	}
792	if timeout != nil {
793		queryParameters["timeout"] = autorest.Encode("query", *timeout)
794	} else {
795		queryParameters["timeout"] = autorest.Encode("query", 30)
796	}
797
798	preparer := autorest.CreatePreparer(
799		autorest.AsGet(),
800		autorest.WithCustomBaseURL("{batchUrl}", urlParameters),
801		autorest.WithPathParameters("/jobs/{jobId}/tasks/{taskId}/subtasksinfo", pathParameters),
802		autorest.WithQueryParameters(queryParameters))
803	if clientRequestID != nil {
804		preparer = autorest.DecoratePreparer(preparer,
805			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
806	}
807	if returnClientRequestID != nil {
808		preparer = autorest.DecoratePreparer(preparer,
809			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
810	} else {
811		preparer = autorest.DecoratePreparer(preparer,
812			autorest.WithHeader("return-client-request-id", autorest.String(false)))
813	}
814	if ocpDate != nil {
815		preparer = autorest.DecoratePreparer(preparer,
816			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
817	}
818	return preparer.Prepare((&http.Request{}).WithContext(ctx))
819}
820
821// ListSubtasksSender sends the ListSubtasks request. The method will close the
822// http.Response Body if it receives an error.
823func (client TaskClient) ListSubtasksSender(req *http.Request) (*http.Response, error) {
824	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
825}
826
827// ListSubtasksResponder handles the response to the ListSubtasks request. The method always
828// closes the http.Response Body.
829func (client TaskClient) ListSubtasksResponder(resp *http.Response) (result CloudTaskListSubtasksResult, err error) {
830	err = autorest.Respond(
831		resp,
832		azure.WithErrorUnlessStatusCode(http.StatusOK),
833		autorest.ByUnmarshallingJSON(&result),
834		autorest.ByClosing())
835	result.Response = autorest.Response{Response: resp}
836	return
837}
838
839// Reactivate reactivation makes a Task eligible to be retried again up to its maximum retry count. The Task's state is
840// changed to active. As the Task is no longer in the completed state, any previous exit code or failure information is
841// no longer available after reactivation. Each time a Task is reactivated, its retry count is reset to 0. Reactivation
842// will fail for Tasks that are not completed or that previously completed successfully (with an exit code of 0).
843// Additionally, it will fail if the Job has completed (or is terminating or deleting).
844// Parameters:
845// jobID - the ID of the Job containing the Task.
846// taskID - the ID of the Task to reactivate.
847// timeout - the maximum time that the server can spend processing the request, in seconds. The default is 30
848// seconds.
849// clientRequestID - the caller-generated request identity, in the form of a GUID with no decoration such as
850// curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
851// returnClientRequestID - whether the server should return the client-request-id in the response.
852// ocpDate - the time the request was issued. Client libraries typically set this to the current system clock
853// time; set it explicitly if you are calling the REST API directly.
854// ifMatch - an ETag value associated with the version of the resource known to the client. The operation will
855// be performed only if the resource's current ETag on the service exactly matches the value specified by the
856// client.
857// ifNoneMatch - an ETag value associated with the version of the resource known to the client. The operation
858// will be performed only if the resource's current ETag on the service does not match the value specified by
859// the client.
860// ifModifiedSince - a timestamp indicating the last modified time of the resource known to the client. The
861// operation will be performed only if the resource on the service has been modified since the specified time.
862// ifUnmodifiedSince - a timestamp indicating the last modified time of the resource known to the client. The
863// operation will be performed only if the resource on the service has not been modified since the specified
864// time.
865func (client TaskClient) Reactivate(ctx context.Context, jobID string, taskID string, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123, ifMatch string, ifNoneMatch string, ifModifiedSince *date.TimeRFC1123, ifUnmodifiedSince *date.TimeRFC1123) (result autorest.Response, err error) {
866	if tracing.IsEnabled() {
867		ctx = tracing.StartSpan(ctx, fqdn+"/TaskClient.Reactivate")
868		defer func() {
869			sc := -1
870			if result.Response != nil {
871				sc = result.Response.StatusCode
872			}
873			tracing.EndSpan(ctx, sc, err)
874		}()
875	}
876	req, err := client.ReactivatePreparer(ctx, jobID, taskID, timeout, clientRequestID, returnClientRequestID, ocpDate, ifMatch, ifNoneMatch, ifModifiedSince, ifUnmodifiedSince)
877	if err != nil {
878		err = autorest.NewErrorWithError(err, "batch.TaskClient", "Reactivate", nil, "Failure preparing request")
879		return
880	}
881
882	resp, err := client.ReactivateSender(req)
883	if err != nil {
884		result.Response = resp
885		err = autorest.NewErrorWithError(err, "batch.TaskClient", "Reactivate", resp, "Failure sending request")
886		return
887	}
888
889	result, err = client.ReactivateResponder(resp)
890	if err != nil {
891		err = autorest.NewErrorWithError(err, "batch.TaskClient", "Reactivate", resp, "Failure responding to request")
892		return
893	}
894
895	return
896}
897
898// ReactivatePreparer prepares the Reactivate request.
899func (client TaskClient) ReactivatePreparer(ctx context.Context, jobID string, taskID string, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123, ifMatch string, ifNoneMatch string, ifModifiedSince *date.TimeRFC1123, ifUnmodifiedSince *date.TimeRFC1123) (*http.Request, error) {
900	urlParameters := map[string]interface{}{
901		"batchUrl": client.BatchURL,
902	}
903
904	pathParameters := map[string]interface{}{
905		"jobId":  autorest.Encode("path", jobID),
906		"taskId": autorest.Encode("path", taskID),
907	}
908
909	const APIVersion = "2020-09-01.12.0"
910	queryParameters := map[string]interface{}{
911		"api-version": APIVersion,
912	}
913	if timeout != nil {
914		queryParameters["timeout"] = autorest.Encode("query", *timeout)
915	} else {
916		queryParameters["timeout"] = autorest.Encode("query", 30)
917	}
918
919	preparer := autorest.CreatePreparer(
920		autorest.AsPost(),
921		autorest.WithCustomBaseURL("{batchUrl}", urlParameters),
922		autorest.WithPathParameters("/jobs/{jobId}/tasks/{taskId}/reactivate", pathParameters),
923		autorest.WithQueryParameters(queryParameters))
924	if clientRequestID != nil {
925		preparer = autorest.DecoratePreparer(preparer,
926			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
927	}
928	if returnClientRequestID != nil {
929		preparer = autorest.DecoratePreparer(preparer,
930			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
931	} else {
932		preparer = autorest.DecoratePreparer(preparer,
933			autorest.WithHeader("return-client-request-id", autorest.String(false)))
934	}
935	if ocpDate != nil {
936		preparer = autorest.DecoratePreparer(preparer,
937			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
938	}
939	if len(ifMatch) > 0 {
940		preparer = autorest.DecoratePreparer(preparer,
941			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
942	}
943	if len(ifNoneMatch) > 0 {
944		preparer = autorest.DecoratePreparer(preparer,
945			autorest.WithHeader("If-None-Match", autorest.String(ifNoneMatch)))
946	}
947	if ifModifiedSince != nil {
948		preparer = autorest.DecoratePreparer(preparer,
949			autorest.WithHeader("If-Modified-Since", autorest.String(ifModifiedSince)))
950	}
951	if ifUnmodifiedSince != nil {
952		preparer = autorest.DecoratePreparer(preparer,
953			autorest.WithHeader("If-Unmodified-Since", autorest.String(ifUnmodifiedSince)))
954	}
955	return preparer.Prepare((&http.Request{}).WithContext(ctx))
956}
957
958// ReactivateSender sends the Reactivate request. The method will close the
959// http.Response Body if it receives an error.
960func (client TaskClient) ReactivateSender(req *http.Request) (*http.Response, error) {
961	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
962}
963
964// ReactivateResponder handles the response to the Reactivate request. The method always
965// closes the http.Response Body.
966func (client TaskClient) ReactivateResponder(resp *http.Response) (result autorest.Response, err error) {
967	err = autorest.Respond(
968		resp,
969		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
970		autorest.ByClosing())
971	result.Response = resp
972	return
973}
974
975// Terminate when the Task has been terminated, it moves to the completed state. For multi-instance Tasks, the
976// terminate Task operation applies synchronously to the primary task; subtasks are then terminated asynchronously in
977// the background.
978// Parameters:
979// jobID - the ID of the Job containing the Task.
980// taskID - the ID of the Task to terminate.
981// timeout - the maximum time that the server can spend processing the request, in seconds. The default is 30
982// seconds.
983// clientRequestID - the caller-generated request identity, in the form of a GUID with no decoration such as
984// curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
985// returnClientRequestID - whether the server should return the client-request-id in the response.
986// ocpDate - the time the request was issued. Client libraries typically set this to the current system clock
987// time; set it explicitly if you are calling the REST API directly.
988// ifMatch - an ETag value associated with the version of the resource known to the client. The operation will
989// be performed only if the resource's current ETag on the service exactly matches the value specified by the
990// client.
991// ifNoneMatch - an ETag value associated with the version of the resource known to the client. The operation
992// will be performed only if the resource's current ETag on the service does not match the value specified by
993// the client.
994// ifModifiedSince - a timestamp indicating the last modified time of the resource known to the client. The
995// operation will be performed only if the resource on the service has been modified since the specified time.
996// ifUnmodifiedSince - a timestamp indicating the last modified time of the resource known to the client. The
997// operation will be performed only if the resource on the service has not been modified since the specified
998// time.
999func (client TaskClient) Terminate(ctx context.Context, jobID string, taskID string, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123, ifMatch string, ifNoneMatch string, ifModifiedSince *date.TimeRFC1123, ifUnmodifiedSince *date.TimeRFC1123) (result autorest.Response, err error) {
1000	if tracing.IsEnabled() {
1001		ctx = tracing.StartSpan(ctx, fqdn+"/TaskClient.Terminate")
1002		defer func() {
1003			sc := -1
1004			if result.Response != nil {
1005				sc = result.Response.StatusCode
1006			}
1007			tracing.EndSpan(ctx, sc, err)
1008		}()
1009	}
1010	req, err := client.TerminatePreparer(ctx, jobID, taskID, timeout, clientRequestID, returnClientRequestID, ocpDate, ifMatch, ifNoneMatch, ifModifiedSince, ifUnmodifiedSince)
1011	if err != nil {
1012		err = autorest.NewErrorWithError(err, "batch.TaskClient", "Terminate", nil, "Failure preparing request")
1013		return
1014	}
1015
1016	resp, err := client.TerminateSender(req)
1017	if err != nil {
1018		result.Response = resp
1019		err = autorest.NewErrorWithError(err, "batch.TaskClient", "Terminate", resp, "Failure sending request")
1020		return
1021	}
1022
1023	result, err = client.TerminateResponder(resp)
1024	if err != nil {
1025		err = autorest.NewErrorWithError(err, "batch.TaskClient", "Terminate", resp, "Failure responding to request")
1026		return
1027	}
1028
1029	return
1030}
1031
1032// TerminatePreparer prepares the Terminate request.
1033func (client TaskClient) TerminatePreparer(ctx context.Context, jobID string, taskID string, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123, ifMatch string, ifNoneMatch string, ifModifiedSince *date.TimeRFC1123, ifUnmodifiedSince *date.TimeRFC1123) (*http.Request, error) {
1034	urlParameters := map[string]interface{}{
1035		"batchUrl": client.BatchURL,
1036	}
1037
1038	pathParameters := map[string]interface{}{
1039		"jobId":  autorest.Encode("path", jobID),
1040		"taskId": autorest.Encode("path", taskID),
1041	}
1042
1043	const APIVersion = "2020-09-01.12.0"
1044	queryParameters := map[string]interface{}{
1045		"api-version": APIVersion,
1046	}
1047	if timeout != nil {
1048		queryParameters["timeout"] = autorest.Encode("query", *timeout)
1049	} else {
1050		queryParameters["timeout"] = autorest.Encode("query", 30)
1051	}
1052
1053	preparer := autorest.CreatePreparer(
1054		autorest.AsPost(),
1055		autorest.WithCustomBaseURL("{batchUrl}", urlParameters),
1056		autorest.WithPathParameters("/jobs/{jobId}/tasks/{taskId}/terminate", pathParameters),
1057		autorest.WithQueryParameters(queryParameters))
1058	if clientRequestID != nil {
1059		preparer = autorest.DecoratePreparer(preparer,
1060			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
1061	}
1062	if returnClientRequestID != nil {
1063		preparer = autorest.DecoratePreparer(preparer,
1064			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
1065	} else {
1066		preparer = autorest.DecoratePreparer(preparer,
1067			autorest.WithHeader("return-client-request-id", autorest.String(false)))
1068	}
1069	if ocpDate != nil {
1070		preparer = autorest.DecoratePreparer(preparer,
1071			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
1072	}
1073	if len(ifMatch) > 0 {
1074		preparer = autorest.DecoratePreparer(preparer,
1075			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
1076	}
1077	if len(ifNoneMatch) > 0 {
1078		preparer = autorest.DecoratePreparer(preparer,
1079			autorest.WithHeader("If-None-Match", autorest.String(ifNoneMatch)))
1080	}
1081	if ifModifiedSince != nil {
1082		preparer = autorest.DecoratePreparer(preparer,
1083			autorest.WithHeader("If-Modified-Since", autorest.String(ifModifiedSince)))
1084	}
1085	if ifUnmodifiedSince != nil {
1086		preparer = autorest.DecoratePreparer(preparer,
1087			autorest.WithHeader("If-Unmodified-Since", autorest.String(ifUnmodifiedSince)))
1088	}
1089	return preparer.Prepare((&http.Request{}).WithContext(ctx))
1090}
1091
1092// TerminateSender sends the Terminate request. The method will close the
1093// http.Response Body if it receives an error.
1094func (client TaskClient) TerminateSender(req *http.Request) (*http.Response, error) {
1095	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
1096}
1097
1098// TerminateResponder handles the response to the Terminate request. The method always
1099// closes the http.Response Body.
1100func (client TaskClient) TerminateResponder(resp *http.Response) (result autorest.Response, err error) {
1101	err = autorest.Respond(
1102		resp,
1103		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
1104		autorest.ByClosing())
1105	result.Response = resp
1106	return
1107}
1108
1109// Update updates the properties of the specified Task.
1110// Parameters:
1111// jobID - the ID of the Job containing the Task.
1112// taskID - the ID of the Task to update.
1113// taskUpdateParameter - the parameters for the request.
1114// timeout - the maximum time that the server can spend processing the request, in seconds. The default is 30
1115// seconds.
1116// clientRequestID - the caller-generated request identity, in the form of a GUID with no decoration such as
1117// curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
1118// returnClientRequestID - whether the server should return the client-request-id in the response.
1119// ocpDate - the time the request was issued. Client libraries typically set this to the current system clock
1120// time; set it explicitly if you are calling the REST API directly.
1121// ifMatch - an ETag value associated with the version of the resource known to the client. The operation will
1122// be performed only if the resource's current ETag on the service exactly matches the value specified by the
1123// client.
1124// ifNoneMatch - an ETag value associated with the version of the resource known to the client. The operation
1125// will be performed only if the resource's current ETag on the service does not match the value specified by
1126// the client.
1127// ifModifiedSince - a timestamp indicating the last modified time of the resource known to the client. The
1128// operation will be performed only if the resource on the service has been modified since the specified time.
1129// ifUnmodifiedSince - a timestamp indicating the last modified time of the resource known to the client. The
1130// operation will be performed only if the resource on the service has not been modified since the specified
1131// time.
1132func (client TaskClient) Update(ctx context.Context, jobID string, taskID string, taskUpdateParameter TaskUpdateParameter, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123, ifMatch string, ifNoneMatch string, ifModifiedSince *date.TimeRFC1123, ifUnmodifiedSince *date.TimeRFC1123) (result autorest.Response, err error) {
1133	if tracing.IsEnabled() {
1134		ctx = tracing.StartSpan(ctx, fqdn+"/TaskClient.Update")
1135		defer func() {
1136			sc := -1
1137			if result.Response != nil {
1138				sc = result.Response.StatusCode
1139			}
1140			tracing.EndSpan(ctx, sc, err)
1141		}()
1142	}
1143	req, err := client.UpdatePreparer(ctx, jobID, taskID, taskUpdateParameter, timeout, clientRequestID, returnClientRequestID, ocpDate, ifMatch, ifNoneMatch, ifModifiedSince, ifUnmodifiedSince)
1144	if err != nil {
1145		err = autorest.NewErrorWithError(err, "batch.TaskClient", "Update", nil, "Failure preparing request")
1146		return
1147	}
1148
1149	resp, err := client.UpdateSender(req)
1150	if err != nil {
1151		result.Response = resp
1152		err = autorest.NewErrorWithError(err, "batch.TaskClient", "Update", resp, "Failure sending request")
1153		return
1154	}
1155
1156	result, err = client.UpdateResponder(resp)
1157	if err != nil {
1158		err = autorest.NewErrorWithError(err, "batch.TaskClient", "Update", resp, "Failure responding to request")
1159		return
1160	}
1161
1162	return
1163}
1164
1165// UpdatePreparer prepares the Update request.
1166func (client TaskClient) UpdatePreparer(ctx context.Context, jobID string, taskID string, taskUpdateParameter TaskUpdateParameter, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123, ifMatch string, ifNoneMatch string, ifModifiedSince *date.TimeRFC1123, ifUnmodifiedSince *date.TimeRFC1123) (*http.Request, error) {
1167	urlParameters := map[string]interface{}{
1168		"batchUrl": client.BatchURL,
1169	}
1170
1171	pathParameters := map[string]interface{}{
1172		"jobId":  autorest.Encode("path", jobID),
1173		"taskId": autorest.Encode("path", taskID),
1174	}
1175
1176	const APIVersion = "2020-09-01.12.0"
1177	queryParameters := map[string]interface{}{
1178		"api-version": APIVersion,
1179	}
1180	if timeout != nil {
1181		queryParameters["timeout"] = autorest.Encode("query", *timeout)
1182	} else {
1183		queryParameters["timeout"] = autorest.Encode("query", 30)
1184	}
1185
1186	preparer := autorest.CreatePreparer(
1187		autorest.AsContentType("application/json; odata=minimalmetadata; charset=utf-8"),
1188		autorest.AsPut(),
1189		autorest.WithCustomBaseURL("{batchUrl}", urlParameters),
1190		autorest.WithPathParameters("/jobs/{jobId}/tasks/{taskId}", pathParameters),
1191		autorest.WithJSON(taskUpdateParameter),
1192		autorest.WithQueryParameters(queryParameters))
1193	if clientRequestID != nil {
1194		preparer = autorest.DecoratePreparer(preparer,
1195			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
1196	}
1197	if returnClientRequestID != nil {
1198		preparer = autorest.DecoratePreparer(preparer,
1199			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
1200	} else {
1201		preparer = autorest.DecoratePreparer(preparer,
1202			autorest.WithHeader("return-client-request-id", autorest.String(false)))
1203	}
1204	if ocpDate != nil {
1205		preparer = autorest.DecoratePreparer(preparer,
1206			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
1207	}
1208	if len(ifMatch) > 0 {
1209		preparer = autorest.DecoratePreparer(preparer,
1210			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
1211	}
1212	if len(ifNoneMatch) > 0 {
1213		preparer = autorest.DecoratePreparer(preparer,
1214			autorest.WithHeader("If-None-Match", autorest.String(ifNoneMatch)))
1215	}
1216	if ifModifiedSince != nil {
1217		preparer = autorest.DecoratePreparer(preparer,
1218			autorest.WithHeader("If-Modified-Since", autorest.String(ifModifiedSince)))
1219	}
1220	if ifUnmodifiedSince != nil {
1221		preparer = autorest.DecoratePreparer(preparer,
1222			autorest.WithHeader("If-Unmodified-Since", autorest.String(ifUnmodifiedSince)))
1223	}
1224	return preparer.Prepare((&http.Request{}).WithContext(ctx))
1225}
1226
1227// UpdateSender sends the Update request. The method will close the
1228// http.Response Body if it receives an error.
1229func (client TaskClient) UpdateSender(req *http.Request) (*http.Response, error) {
1230	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
1231}
1232
1233// UpdateResponder handles the response to the Update request. The method always
1234// closes the http.Response Body.
1235func (client TaskClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
1236	err = autorest.Respond(
1237		resp,
1238		azure.WithErrorUnlessStatusCode(http.StatusOK),
1239		autorest.ByClosing())
1240	result.Response = resp
1241	return
1242}
1243