1package media
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// JobsClient is the client for the Jobs methods of the Media service.
19type JobsClient struct {
20	BaseClient
21}
22
23// NewJobsClient creates an instance of the JobsClient client.
24func NewJobsClient(subscriptionID string) JobsClient {
25	return NewJobsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewJobsClientWithBaseURI creates an instance of the JobsClient client using a custom endpoint.  Use this when
29// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewJobsClientWithBaseURI(baseURI string, subscriptionID string) JobsClient {
31	return JobsClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CancelJob cancel a Job.
35// Parameters:
36// resourceGroupName - the name of the resource group within the Azure subscription.
37// accountName - the Media Services account name.
38// transformName - the Transform name.
39// jobName - the Job name.
40func (client JobsClient) CancelJob(ctx context.Context, resourceGroupName string, accountName string, transformName string, jobName string) (result autorest.Response, err error) {
41	if tracing.IsEnabled() {
42		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.CancelJob")
43		defer func() {
44			sc := -1
45			if result.Response != nil {
46				sc = result.Response.StatusCode
47			}
48			tracing.EndSpan(ctx, sc, err)
49		}()
50	}
51	req, err := client.CancelJobPreparer(ctx, resourceGroupName, accountName, transformName, jobName)
52	if err != nil {
53		err = autorest.NewErrorWithError(err, "media.JobsClient", "CancelJob", nil, "Failure preparing request")
54		return
55	}
56
57	resp, err := client.CancelJobSender(req)
58	if err != nil {
59		result.Response = resp
60		err = autorest.NewErrorWithError(err, "media.JobsClient", "CancelJob", resp, "Failure sending request")
61		return
62	}
63
64	result, err = client.CancelJobResponder(resp)
65	if err != nil {
66		err = autorest.NewErrorWithError(err, "media.JobsClient", "CancelJob", resp, "Failure responding to request")
67		return
68	}
69
70	return
71}
72
73// CancelJobPreparer prepares the CancelJob request.
74func (client JobsClient) CancelJobPreparer(ctx context.Context, resourceGroupName string, accountName string, transformName string, jobName string) (*http.Request, error) {
75	pathParameters := map[string]interface{}{
76		"accountName":       autorest.Encode("path", accountName),
77		"jobName":           autorest.Encode("path", jobName),
78		"resourceGroupName": autorest.Encode("path", resourceGroupName),
79		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
80		"transformName":     autorest.Encode("path", transformName),
81	}
82
83	const APIVersion = "2020-05-01"
84	queryParameters := map[string]interface{}{
85		"api-version": APIVersion,
86	}
87
88	preparer := autorest.CreatePreparer(
89		autorest.AsPost(),
90		autorest.WithBaseURL(client.BaseURI),
91		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/transforms/{transformName}/jobs/{jobName}/cancelJob", pathParameters),
92		autorest.WithQueryParameters(queryParameters))
93	return preparer.Prepare((&http.Request{}).WithContext(ctx))
94}
95
96// CancelJobSender sends the CancelJob request. The method will close the
97// http.Response Body if it receives an error.
98func (client JobsClient) CancelJobSender(req *http.Request) (*http.Response, error) {
99	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
100}
101
102// CancelJobResponder handles the response to the CancelJob request. The method always
103// closes the http.Response Body.
104func (client JobsClient) CancelJobResponder(resp *http.Response) (result autorest.Response, err error) {
105	err = autorest.Respond(
106		resp,
107		azure.WithErrorUnlessStatusCode(http.StatusOK),
108		autorest.ByClosing())
109	result.Response = resp
110	return
111}
112
113// Create creates a Job.
114// Parameters:
115// resourceGroupName - the name of the resource group within the Azure subscription.
116// accountName - the Media Services account name.
117// transformName - the Transform name.
118// jobName - the Job name.
119// parameters - the request parameters
120func (client JobsClient) Create(ctx context.Context, resourceGroupName string, accountName string, transformName string, jobName string, parameters Job) (result Job, err error) {
121	if tracing.IsEnabled() {
122		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Create")
123		defer func() {
124			sc := -1
125			if result.Response.Response != nil {
126				sc = result.Response.Response.StatusCode
127			}
128			tracing.EndSpan(ctx, sc, err)
129		}()
130	}
131	if err := validation.Validate([]validation.Validation{
132		{TargetValue: parameters,
133			Constraints: []validation.Constraint{{Target: "parameters.JobProperties", Name: validation.Null, Rule: false,
134				Chain: []validation.Constraint{{Target: "parameters.JobProperties.Outputs", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
135		return result, validation.NewError("media.JobsClient", "Create", err.Error())
136	}
137
138	req, err := client.CreatePreparer(ctx, resourceGroupName, accountName, transformName, jobName, parameters)
139	if err != nil {
140		err = autorest.NewErrorWithError(err, "media.JobsClient", "Create", nil, "Failure preparing request")
141		return
142	}
143
144	resp, err := client.CreateSender(req)
145	if err != nil {
146		result.Response = autorest.Response{Response: resp}
147		err = autorest.NewErrorWithError(err, "media.JobsClient", "Create", resp, "Failure sending request")
148		return
149	}
150
151	result, err = client.CreateResponder(resp)
152	if err != nil {
153		err = autorest.NewErrorWithError(err, "media.JobsClient", "Create", resp, "Failure responding to request")
154		return
155	}
156
157	return
158}
159
160// CreatePreparer prepares the Create request.
161func (client JobsClient) CreatePreparer(ctx context.Context, resourceGroupName string, accountName string, transformName string, jobName string, parameters Job) (*http.Request, error) {
162	pathParameters := map[string]interface{}{
163		"accountName":       autorest.Encode("path", accountName),
164		"jobName":           autorest.Encode("path", jobName),
165		"resourceGroupName": autorest.Encode("path", resourceGroupName),
166		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
167		"transformName":     autorest.Encode("path", transformName),
168	}
169
170	const APIVersion = "2020-05-01"
171	queryParameters := map[string]interface{}{
172		"api-version": APIVersion,
173	}
174
175	parameters.SystemData = nil
176	preparer := autorest.CreatePreparer(
177		autorest.AsContentType("application/json; charset=utf-8"),
178		autorest.AsPut(),
179		autorest.WithBaseURL(client.BaseURI),
180		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/transforms/{transformName}/jobs/{jobName}", pathParameters),
181		autorest.WithJSON(parameters),
182		autorest.WithQueryParameters(queryParameters))
183	return preparer.Prepare((&http.Request{}).WithContext(ctx))
184}
185
186// CreateSender sends the Create request. The method will close the
187// http.Response Body if it receives an error.
188func (client JobsClient) CreateSender(req *http.Request) (*http.Response, error) {
189	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
190}
191
192// CreateResponder handles the response to the Create request. The method always
193// closes the http.Response Body.
194func (client JobsClient) CreateResponder(resp *http.Response) (result Job, err error) {
195	err = autorest.Respond(
196		resp,
197		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
198		autorest.ByUnmarshallingJSON(&result),
199		autorest.ByClosing())
200	result.Response = autorest.Response{Response: resp}
201	return
202}
203
204// Delete deletes a Job.
205// Parameters:
206// resourceGroupName - the name of the resource group within the Azure subscription.
207// accountName - the Media Services account name.
208// transformName - the Transform name.
209// jobName - the Job name.
210func (client JobsClient) Delete(ctx context.Context, resourceGroupName string, accountName string, transformName string, jobName string) (result autorest.Response, err error) {
211	if tracing.IsEnabled() {
212		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Delete")
213		defer func() {
214			sc := -1
215			if result.Response != nil {
216				sc = result.Response.StatusCode
217			}
218			tracing.EndSpan(ctx, sc, err)
219		}()
220	}
221	req, err := client.DeletePreparer(ctx, resourceGroupName, accountName, transformName, jobName)
222	if err != nil {
223		err = autorest.NewErrorWithError(err, "media.JobsClient", "Delete", nil, "Failure preparing request")
224		return
225	}
226
227	resp, err := client.DeleteSender(req)
228	if err != nil {
229		result.Response = resp
230		err = autorest.NewErrorWithError(err, "media.JobsClient", "Delete", resp, "Failure sending request")
231		return
232	}
233
234	result, err = client.DeleteResponder(resp)
235	if err != nil {
236		err = autorest.NewErrorWithError(err, "media.JobsClient", "Delete", resp, "Failure responding to request")
237		return
238	}
239
240	return
241}
242
243// DeletePreparer prepares the Delete request.
244func (client JobsClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string, transformName string, jobName string) (*http.Request, error) {
245	pathParameters := map[string]interface{}{
246		"accountName":       autorest.Encode("path", accountName),
247		"jobName":           autorest.Encode("path", jobName),
248		"resourceGroupName": autorest.Encode("path", resourceGroupName),
249		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
250		"transformName":     autorest.Encode("path", transformName),
251	}
252
253	const APIVersion = "2020-05-01"
254	queryParameters := map[string]interface{}{
255		"api-version": APIVersion,
256	}
257
258	preparer := autorest.CreatePreparer(
259		autorest.AsDelete(),
260		autorest.WithBaseURL(client.BaseURI),
261		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/transforms/{transformName}/jobs/{jobName}", pathParameters),
262		autorest.WithQueryParameters(queryParameters))
263	return preparer.Prepare((&http.Request{}).WithContext(ctx))
264}
265
266// DeleteSender sends the Delete request. The method will close the
267// http.Response Body if it receives an error.
268func (client JobsClient) DeleteSender(req *http.Request) (*http.Response, error) {
269	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
270}
271
272// DeleteResponder handles the response to the Delete request. The method always
273// closes the http.Response Body.
274func (client JobsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
275	err = autorest.Respond(
276		resp,
277		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
278		autorest.ByClosing())
279	result.Response = resp
280	return
281}
282
283// Get gets a Job.
284// Parameters:
285// resourceGroupName - the name of the resource group within the Azure subscription.
286// accountName - the Media Services account name.
287// transformName - the Transform name.
288// jobName - the Job name.
289func (client JobsClient) Get(ctx context.Context, resourceGroupName string, accountName string, transformName string, jobName string) (result Job, err error) {
290	if tracing.IsEnabled() {
291		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Get")
292		defer func() {
293			sc := -1
294			if result.Response.Response != nil {
295				sc = result.Response.Response.StatusCode
296			}
297			tracing.EndSpan(ctx, sc, err)
298		}()
299	}
300	req, err := client.GetPreparer(ctx, resourceGroupName, accountName, transformName, jobName)
301	if err != nil {
302		err = autorest.NewErrorWithError(err, "media.JobsClient", "Get", nil, "Failure preparing request")
303		return
304	}
305
306	resp, err := client.GetSender(req)
307	if err != nil {
308		result.Response = autorest.Response{Response: resp}
309		err = autorest.NewErrorWithError(err, "media.JobsClient", "Get", resp, "Failure sending request")
310		return
311	}
312
313	result, err = client.GetResponder(resp)
314	if err != nil {
315		err = autorest.NewErrorWithError(err, "media.JobsClient", "Get", resp, "Failure responding to request")
316		return
317	}
318
319	return
320}
321
322// GetPreparer prepares the Get request.
323func (client JobsClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string, transformName string, jobName string) (*http.Request, error) {
324	pathParameters := map[string]interface{}{
325		"accountName":       autorest.Encode("path", accountName),
326		"jobName":           autorest.Encode("path", jobName),
327		"resourceGroupName": autorest.Encode("path", resourceGroupName),
328		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
329		"transformName":     autorest.Encode("path", transformName),
330	}
331
332	const APIVersion = "2020-05-01"
333	queryParameters := map[string]interface{}{
334		"api-version": APIVersion,
335	}
336
337	preparer := autorest.CreatePreparer(
338		autorest.AsGet(),
339		autorest.WithBaseURL(client.BaseURI),
340		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/transforms/{transformName}/jobs/{jobName}", pathParameters),
341		autorest.WithQueryParameters(queryParameters))
342	return preparer.Prepare((&http.Request{}).WithContext(ctx))
343}
344
345// GetSender sends the Get request. The method will close the
346// http.Response Body if it receives an error.
347func (client JobsClient) GetSender(req *http.Request) (*http.Response, error) {
348	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
349}
350
351// GetResponder handles the response to the Get request. The method always
352// closes the http.Response Body.
353func (client JobsClient) GetResponder(resp *http.Response) (result Job, err error) {
354	err = autorest.Respond(
355		resp,
356		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNotFound),
357		autorest.ByUnmarshallingJSON(&result),
358		autorest.ByClosing())
359	result.Response = autorest.Response{Response: resp}
360	return
361}
362
363// List lists all of the Jobs for the Transform.
364// Parameters:
365// resourceGroupName - the name of the resource group within the Azure subscription.
366// accountName - the Media Services account name.
367// transformName - the Transform name.
368// filter - restricts the set of items returned.
369// orderby - specifies the key by which the result collection should be ordered.
370func (client JobsClient) List(ctx context.Context, resourceGroupName string, accountName string, transformName string, filter string, orderby string) (result JobCollectionPage, err error) {
371	if tracing.IsEnabled() {
372		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.List")
373		defer func() {
374			sc := -1
375			if result.jc.Response.Response != nil {
376				sc = result.jc.Response.Response.StatusCode
377			}
378			tracing.EndSpan(ctx, sc, err)
379		}()
380	}
381	result.fn = client.listNextResults
382	req, err := client.ListPreparer(ctx, resourceGroupName, accountName, transformName, filter, orderby)
383	if err != nil {
384		err = autorest.NewErrorWithError(err, "media.JobsClient", "List", nil, "Failure preparing request")
385		return
386	}
387
388	resp, err := client.ListSender(req)
389	if err != nil {
390		result.jc.Response = autorest.Response{Response: resp}
391		err = autorest.NewErrorWithError(err, "media.JobsClient", "List", resp, "Failure sending request")
392		return
393	}
394
395	result.jc, err = client.ListResponder(resp)
396	if err != nil {
397		err = autorest.NewErrorWithError(err, "media.JobsClient", "List", resp, "Failure responding to request")
398		return
399	}
400	if result.jc.hasNextLink() && result.jc.IsEmpty() {
401		err = result.NextWithContext(ctx)
402		return
403	}
404
405	return
406}
407
408// ListPreparer prepares the List request.
409func (client JobsClient) ListPreparer(ctx context.Context, resourceGroupName string, accountName string, transformName string, filter string, orderby string) (*http.Request, error) {
410	pathParameters := map[string]interface{}{
411		"accountName":       autorest.Encode("path", accountName),
412		"resourceGroupName": autorest.Encode("path", resourceGroupName),
413		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
414		"transformName":     autorest.Encode("path", transformName),
415	}
416
417	const APIVersion = "2020-05-01"
418	queryParameters := map[string]interface{}{
419		"api-version": APIVersion,
420	}
421	if len(filter) > 0 {
422		queryParameters["$filter"] = autorest.Encode("query", filter)
423	}
424	if len(orderby) > 0 {
425		queryParameters["$orderby"] = autorest.Encode("query", orderby)
426	}
427
428	preparer := autorest.CreatePreparer(
429		autorest.AsGet(),
430		autorest.WithBaseURL(client.BaseURI),
431		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/transforms/{transformName}/jobs", pathParameters),
432		autorest.WithQueryParameters(queryParameters))
433	return preparer.Prepare((&http.Request{}).WithContext(ctx))
434}
435
436// ListSender sends the List request. The method will close the
437// http.Response Body if it receives an error.
438func (client JobsClient) ListSender(req *http.Request) (*http.Response, error) {
439	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
440}
441
442// ListResponder handles the response to the List request. The method always
443// closes the http.Response Body.
444func (client JobsClient) ListResponder(resp *http.Response) (result JobCollection, err error) {
445	err = autorest.Respond(
446		resp,
447		azure.WithErrorUnlessStatusCode(http.StatusOK),
448		autorest.ByUnmarshallingJSON(&result),
449		autorest.ByClosing())
450	result.Response = autorest.Response{Response: resp}
451	return
452}
453
454// listNextResults retrieves the next set of results, if any.
455func (client JobsClient) listNextResults(ctx context.Context, lastResults JobCollection) (result JobCollection, err error) {
456	req, err := lastResults.jobCollectionPreparer(ctx)
457	if err != nil {
458		return result, autorest.NewErrorWithError(err, "media.JobsClient", "listNextResults", nil, "Failure preparing next results request")
459	}
460	if req == nil {
461		return
462	}
463	resp, err := client.ListSender(req)
464	if err != nil {
465		result.Response = autorest.Response{Response: resp}
466		return result, autorest.NewErrorWithError(err, "media.JobsClient", "listNextResults", resp, "Failure sending next results request")
467	}
468	result, err = client.ListResponder(resp)
469	if err != nil {
470		err = autorest.NewErrorWithError(err, "media.JobsClient", "listNextResults", resp, "Failure responding to next results request")
471	}
472	return
473}
474
475// ListComplete enumerates all values, automatically crossing page boundaries as required.
476func (client JobsClient) ListComplete(ctx context.Context, resourceGroupName string, accountName string, transformName string, filter string, orderby string) (result JobCollectionIterator, err error) {
477	if tracing.IsEnabled() {
478		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.List")
479		defer func() {
480			sc := -1
481			if result.Response().Response.Response != nil {
482				sc = result.page.Response().Response.Response.StatusCode
483			}
484			tracing.EndSpan(ctx, sc, err)
485		}()
486	}
487	result.page, err = client.List(ctx, resourceGroupName, accountName, transformName, filter, orderby)
488	return
489}
490
491// Update update is only supported for description and priority. Updating Priority will take effect when the Job state
492// is Queued or Scheduled and depending on the timing the priority update may be ignored.
493// Parameters:
494// resourceGroupName - the name of the resource group within the Azure subscription.
495// accountName - the Media Services account name.
496// transformName - the Transform name.
497// jobName - the Job name.
498// parameters - the request parameters
499func (client JobsClient) Update(ctx context.Context, resourceGroupName string, accountName string, transformName string, jobName string, parameters Job) (result Job, err error) {
500	if tracing.IsEnabled() {
501		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Update")
502		defer func() {
503			sc := -1
504			if result.Response.Response != nil {
505				sc = result.Response.Response.StatusCode
506			}
507			tracing.EndSpan(ctx, sc, err)
508		}()
509	}
510	req, err := client.UpdatePreparer(ctx, resourceGroupName, accountName, transformName, jobName, parameters)
511	if err != nil {
512		err = autorest.NewErrorWithError(err, "media.JobsClient", "Update", nil, "Failure preparing request")
513		return
514	}
515
516	resp, err := client.UpdateSender(req)
517	if err != nil {
518		result.Response = autorest.Response{Response: resp}
519		err = autorest.NewErrorWithError(err, "media.JobsClient", "Update", resp, "Failure sending request")
520		return
521	}
522
523	result, err = client.UpdateResponder(resp)
524	if err != nil {
525		err = autorest.NewErrorWithError(err, "media.JobsClient", "Update", resp, "Failure responding to request")
526		return
527	}
528
529	return
530}
531
532// UpdatePreparer prepares the Update request.
533func (client JobsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, accountName string, transformName string, jobName string, parameters Job) (*http.Request, error) {
534	pathParameters := map[string]interface{}{
535		"accountName":       autorest.Encode("path", accountName),
536		"jobName":           autorest.Encode("path", jobName),
537		"resourceGroupName": autorest.Encode("path", resourceGroupName),
538		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
539		"transformName":     autorest.Encode("path", transformName),
540	}
541
542	const APIVersion = "2020-05-01"
543	queryParameters := map[string]interface{}{
544		"api-version": APIVersion,
545	}
546
547	parameters.SystemData = nil
548	preparer := autorest.CreatePreparer(
549		autorest.AsContentType("application/json; charset=utf-8"),
550		autorest.AsPatch(),
551		autorest.WithBaseURL(client.BaseURI),
552		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/transforms/{transformName}/jobs/{jobName}", pathParameters),
553		autorest.WithJSON(parameters),
554		autorest.WithQueryParameters(queryParameters))
555	return preparer.Prepare((&http.Request{}).WithContext(ctx))
556}
557
558// UpdateSender sends the Update request. The method will close the
559// http.Response Body if it receives an error.
560func (client JobsClient) UpdateSender(req *http.Request) (*http.Response, error) {
561	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
562}
563
564// UpdateResponder handles the response to the Update request. The method always
565// closes the http.Response Body.
566func (client JobsClient) UpdateResponder(resp *http.Response) (result Job, err error) {
567	err = autorest.Respond(
568		resp,
569		azure.WithErrorUnlessStatusCode(http.StatusOK),
570		autorest.ByUnmarshallingJSON(&result),
571		autorest.ByClosing())
572	result.Response = autorest.Response{Response: resp}
573	return
574}
575