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 = "2018-03-30-preview" 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 = "2018-03-30-preview" 171 queryParameters := map[string]interface{}{ 172 "api-version": APIVersion, 173 } 174 175 preparer := autorest.CreatePreparer( 176 autorest.AsContentType("application/json; charset=utf-8"), 177 autorest.AsPut(), 178 autorest.WithBaseURL(client.BaseURI), 179 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/transforms/{transformName}/jobs/{jobName}", pathParameters), 180 autorest.WithJSON(parameters), 181 autorest.WithQueryParameters(queryParameters)) 182 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 183} 184 185// CreateSender sends the Create request. The method will close the 186// http.Response Body if it receives an error. 187func (client JobsClient) CreateSender(req *http.Request) (*http.Response, error) { 188 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 189} 190 191// CreateResponder handles the response to the Create request. The method always 192// closes the http.Response Body. 193func (client JobsClient) CreateResponder(resp *http.Response) (result Job, err error) { 194 err = autorest.Respond( 195 resp, 196 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 197 autorest.ByUnmarshallingJSON(&result), 198 autorest.ByClosing()) 199 result.Response = autorest.Response{Response: resp} 200 return 201} 202 203// Delete deletes a Job. 204// Parameters: 205// resourceGroupName - the name of the resource group within the Azure subscription. 206// accountName - the Media Services account name. 207// transformName - the Transform name. 208// jobName - the Job name. 209func (client JobsClient) Delete(ctx context.Context, resourceGroupName string, accountName string, transformName string, jobName string) (result autorest.Response, err error) { 210 if tracing.IsEnabled() { 211 ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Delete") 212 defer func() { 213 sc := -1 214 if result.Response != nil { 215 sc = result.Response.StatusCode 216 } 217 tracing.EndSpan(ctx, sc, err) 218 }() 219 } 220 req, err := client.DeletePreparer(ctx, resourceGroupName, accountName, transformName, jobName) 221 if err != nil { 222 err = autorest.NewErrorWithError(err, "media.JobsClient", "Delete", nil, "Failure preparing request") 223 return 224 } 225 226 resp, err := client.DeleteSender(req) 227 if err != nil { 228 result.Response = resp 229 err = autorest.NewErrorWithError(err, "media.JobsClient", "Delete", resp, "Failure sending request") 230 return 231 } 232 233 result, err = client.DeleteResponder(resp) 234 if err != nil { 235 err = autorest.NewErrorWithError(err, "media.JobsClient", "Delete", resp, "Failure responding to request") 236 return 237 } 238 239 return 240} 241 242// DeletePreparer prepares the Delete request. 243func (client JobsClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string, transformName string, jobName string) (*http.Request, error) { 244 pathParameters := map[string]interface{}{ 245 "accountName": autorest.Encode("path", accountName), 246 "jobName": autorest.Encode("path", jobName), 247 "resourceGroupName": autorest.Encode("path", resourceGroupName), 248 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 249 "transformName": autorest.Encode("path", transformName), 250 } 251 252 const APIVersion = "2018-03-30-preview" 253 queryParameters := map[string]interface{}{ 254 "api-version": APIVersion, 255 } 256 257 preparer := autorest.CreatePreparer( 258 autorest.AsDelete(), 259 autorest.WithBaseURL(client.BaseURI), 260 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/transforms/{transformName}/jobs/{jobName}", pathParameters), 261 autorest.WithQueryParameters(queryParameters)) 262 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 263} 264 265// DeleteSender sends the Delete request. The method will close the 266// http.Response Body if it receives an error. 267func (client JobsClient) DeleteSender(req *http.Request) (*http.Response, error) { 268 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 269} 270 271// DeleteResponder handles the response to the Delete request. The method always 272// closes the http.Response Body. 273func (client JobsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 274 err = autorest.Respond( 275 resp, 276 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 277 autorest.ByClosing()) 278 result.Response = resp 279 return 280} 281 282// Get gets a Job. 283// Parameters: 284// resourceGroupName - the name of the resource group within the Azure subscription. 285// accountName - the Media Services account name. 286// transformName - the Transform name. 287// jobName - the Job name. 288func (client JobsClient) Get(ctx context.Context, resourceGroupName string, accountName string, transformName string, jobName string) (result Job, err error) { 289 if tracing.IsEnabled() { 290 ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Get") 291 defer func() { 292 sc := -1 293 if result.Response.Response != nil { 294 sc = result.Response.Response.StatusCode 295 } 296 tracing.EndSpan(ctx, sc, err) 297 }() 298 } 299 req, err := client.GetPreparer(ctx, resourceGroupName, accountName, transformName, jobName) 300 if err != nil { 301 err = autorest.NewErrorWithError(err, "media.JobsClient", "Get", nil, "Failure preparing request") 302 return 303 } 304 305 resp, err := client.GetSender(req) 306 if err != nil { 307 result.Response = autorest.Response{Response: resp} 308 err = autorest.NewErrorWithError(err, "media.JobsClient", "Get", resp, "Failure sending request") 309 return 310 } 311 312 result, err = client.GetResponder(resp) 313 if err != nil { 314 err = autorest.NewErrorWithError(err, "media.JobsClient", "Get", resp, "Failure responding to request") 315 return 316 } 317 318 return 319} 320 321// GetPreparer prepares the Get request. 322func (client JobsClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string, transformName string, jobName string) (*http.Request, error) { 323 pathParameters := map[string]interface{}{ 324 "accountName": autorest.Encode("path", accountName), 325 "jobName": autorest.Encode("path", jobName), 326 "resourceGroupName": autorest.Encode("path", resourceGroupName), 327 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 328 "transformName": autorest.Encode("path", transformName), 329 } 330 331 const APIVersion = "2018-03-30-preview" 332 queryParameters := map[string]interface{}{ 333 "api-version": APIVersion, 334 } 335 336 preparer := autorest.CreatePreparer( 337 autorest.AsGet(), 338 autorest.WithBaseURL(client.BaseURI), 339 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/transforms/{transformName}/jobs/{jobName}", pathParameters), 340 autorest.WithQueryParameters(queryParameters)) 341 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 342} 343 344// GetSender sends the Get request. The method will close the 345// http.Response Body if it receives an error. 346func (client JobsClient) GetSender(req *http.Request) (*http.Response, error) { 347 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 348} 349 350// GetResponder handles the response to the Get request. The method always 351// closes the http.Response Body. 352func (client JobsClient) GetResponder(resp *http.Response) (result Job, err error) { 353 err = autorest.Respond( 354 resp, 355 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNotFound), 356 autorest.ByUnmarshallingJSON(&result), 357 autorest.ByClosing()) 358 result.Response = autorest.Response{Response: resp} 359 return 360} 361 362// List lists all of the Jobs for the Transform. 363// Parameters: 364// resourceGroupName - the name of the resource group within the Azure subscription. 365// accountName - the Media Services account name. 366// transformName - the Transform name. 367// filter - restricts the set of items returned. 368// top - specifies a non-negative integer n that limits the number of items returned from a collection. The 369// service returns the number of available items up to but not greater than the specified value n. 370// skip - specifies a non-negative integer n that excludes the first n items of the queried collection from the 371// result. The service returns items starting at position n+1. 372func (client JobsClient) List(ctx context.Context, resourceGroupName string, accountName string, transformName string, filter string, top *int32, skip *int32) (result JobCollectionPage, err error) { 373 if tracing.IsEnabled() { 374 ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.List") 375 defer func() { 376 sc := -1 377 if result.jc.Response.Response != nil { 378 sc = result.jc.Response.Response.StatusCode 379 } 380 tracing.EndSpan(ctx, sc, err) 381 }() 382 } 383 result.fn = client.listNextResults 384 req, err := client.ListPreparer(ctx, resourceGroupName, accountName, transformName, filter, top, skip) 385 if err != nil { 386 err = autorest.NewErrorWithError(err, "media.JobsClient", "List", nil, "Failure preparing request") 387 return 388 } 389 390 resp, err := client.ListSender(req) 391 if err != nil { 392 result.jc.Response = autorest.Response{Response: resp} 393 err = autorest.NewErrorWithError(err, "media.JobsClient", "List", resp, "Failure sending request") 394 return 395 } 396 397 result.jc, err = client.ListResponder(resp) 398 if err != nil { 399 err = autorest.NewErrorWithError(err, "media.JobsClient", "List", resp, "Failure responding to request") 400 return 401 } 402 if result.jc.hasNextLink() && result.jc.IsEmpty() { 403 err = result.NextWithContext(ctx) 404 return 405 } 406 407 return 408} 409 410// ListPreparer prepares the List request. 411func (client JobsClient) ListPreparer(ctx context.Context, resourceGroupName string, accountName string, transformName string, filter string, top *int32, skip *int32) (*http.Request, error) { 412 pathParameters := map[string]interface{}{ 413 "accountName": autorest.Encode("path", accountName), 414 "resourceGroupName": autorest.Encode("path", resourceGroupName), 415 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 416 "transformName": autorest.Encode("path", transformName), 417 } 418 419 const APIVersion = "2018-03-30-preview" 420 queryParameters := map[string]interface{}{ 421 "api-version": APIVersion, 422 } 423 if len(filter) > 0 { 424 queryParameters["$filter"] = autorest.Encode("query", filter) 425 } 426 if top != nil { 427 queryParameters["$top"] = autorest.Encode("query", *top) 428 } 429 if skip != nil { 430 queryParameters["$skip"] = autorest.Encode("query", *skip) 431 } 432 433 preparer := autorest.CreatePreparer( 434 autorest.AsGet(), 435 autorest.WithBaseURL(client.BaseURI), 436 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/transforms/{transformName}/jobs", pathParameters), 437 autorest.WithQueryParameters(queryParameters)) 438 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 439} 440 441// ListSender sends the List request. The method will close the 442// http.Response Body if it receives an error. 443func (client JobsClient) ListSender(req *http.Request) (*http.Response, error) { 444 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 445} 446 447// ListResponder handles the response to the List request. The method always 448// closes the http.Response Body. 449func (client JobsClient) ListResponder(resp *http.Response) (result JobCollection, err error) { 450 err = autorest.Respond( 451 resp, 452 azure.WithErrorUnlessStatusCode(http.StatusOK), 453 autorest.ByUnmarshallingJSON(&result), 454 autorest.ByClosing()) 455 result.Response = autorest.Response{Response: resp} 456 return 457} 458 459// listNextResults retrieves the next set of results, if any. 460func (client JobsClient) listNextResults(ctx context.Context, lastResults JobCollection) (result JobCollection, err error) { 461 req, err := lastResults.jobCollectionPreparer(ctx) 462 if err != nil { 463 return result, autorest.NewErrorWithError(err, "media.JobsClient", "listNextResults", nil, "Failure preparing next results request") 464 } 465 if req == nil { 466 return 467 } 468 resp, err := client.ListSender(req) 469 if err != nil { 470 result.Response = autorest.Response{Response: resp} 471 return result, autorest.NewErrorWithError(err, "media.JobsClient", "listNextResults", resp, "Failure sending next results request") 472 } 473 result, err = client.ListResponder(resp) 474 if err != nil { 475 err = autorest.NewErrorWithError(err, "media.JobsClient", "listNextResults", resp, "Failure responding to next results request") 476 } 477 return 478} 479 480// ListComplete enumerates all values, automatically crossing page boundaries as required. 481func (client JobsClient) ListComplete(ctx context.Context, resourceGroupName string, accountName string, transformName string, filter string, top *int32, skip *int32) (result JobCollectionIterator, err error) { 482 if tracing.IsEnabled() { 483 ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.List") 484 defer func() { 485 sc := -1 486 if result.Response().Response.Response != nil { 487 sc = result.page.Response().Response.Response.StatusCode 488 } 489 tracing.EndSpan(ctx, sc, err) 490 }() 491 } 492 result.page, err = client.List(ctx, resourceGroupName, accountName, transformName, filter, top, skip) 493 return 494} 495