< Summary

Class:Microsoft.Azure.HDInsight.Job.JobOperations
Assembly:Microsoft.Azure.HDInsight.Job
File(s):C:\Git\azure-sdk-for-net\sdk\hdinsight\Microsoft.Azure.HDInsight.Job\src\Customizations\JobOperations.Customizations.cs
C:\Git\azure-sdk-for-net\sdk\hdinsight\Microsoft.Azure.HDInsight.Job\src\Generated\JobOperations.cs
Covered lines:1077
Uncovered lines:1294
Coverable lines:2371
Total lines:5200
Line coverage:45.4% (1077 of 2371)
Covered branches:600
Total branches:1420
Branch coverage:42.2% (600 of 1420)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-100%100%
SubmitHiveJobWithHttpMessagesAsync()-100%100%
SubmitMapReduceJobWithHttpMessagesAsync()-100%100%
SubmitMapReduceStreamingJobWithHttpMessagesAsync()-100%100%
SubmitPigJobWithHttpMessagesAsync()-100%100%
SubmitSqoopJobWithHttpMessagesAsync()-100%100%
GetJobOutputAsync()-0%100%
GetJobErrorLogsAsync()-0%100%
WaitForJobCompletionWithHttpMessagesAsync()-62.96%70%
GetJobStatusDirectory()-0%0%
GetStatusFolder(...)-0%0%
GetAppIdFromJobId(...)-66.67%50%
IsTransientError(...)-0%0%
LogMessages(...)-0%0%
.ctor(...)-80%50%
get_Client()-100%100%
GetWithHttpMessagesAsync()-71.11%64.81%
KillWithHttpMessagesAsync()-57.3%55.36%
ListWithHttpMessagesAsync()-57.78%55.56%
ListAfterJobIdWithHttpMessagesAsync()-58.16%58.33%
SubmitHiveJobWithHttpMessagesAsync()-56.67%55.17%
SubmitMapReduceJobWithHttpMessagesAsync()-56.67%55.17%
SubmitMapReduceStreamingJobWithHttpMessagesAsync()-56.67%55.17%
SubmitPigJobWithHttpMessagesAsync()-56.67%55.17%
SubmitSqoopJobWithHttpMessagesAsync()-56.67%55.17%
GetAppStateWithHttpMessagesAsync()-53.66%45.83%
ListSparkBatchJobWithHttpMessagesAsync()-54.02%51.92%
SubmitSparkBatchJobWithHttpMessagesAsync()-53.76%48.21%
GetSparkBatchJobWithHttpMessagesAsync()-51.81%43.75%
DeleteSparkBatchJobWithHttpMessagesAsync()-52.27%46.15%
GetSparkBatchLogWithHttpMessagesAsync()-0%0%
GetSparkBatchStateWithHttpMessagesAsync()-0%0%
ListSparkSessionJobWithHttpMessagesAsync()-54.02%51.92%
SubmitSparkSessionJobWithHttpMessagesAsync()-53.76%48.21%
GetSparkSessionJobWithHttpMessagesAsync()-51.81%43.75%
DeleteSparkSessionJobWithHttpMessagesAsync()-52.27%46.15%
GetSparkSessionLogWithHttpMessagesAsync()-0%0%
GetSparkSessionStateWithHttpMessagesAsync()-0%0%
ListSparkStatementJobWithHttpMessagesAsync()-51.81%43.75%
SubmitSparkStatementJobWithHttpMessagesAsync()-53.68%48.21%
GetSparkStatementJobWithHttpMessagesAsync()-0%0%
DeleteSparkStatementJobWithHttpMessagesAsync()-52.22%46.15%

File(s)

C:\Git\azure-sdk-for-net\sdk\hdinsight\Microsoft.Azure.HDInsight.Job\src\Customizations\JobOperations.Customizations.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License. See License.txt in the project root for
 3// license information.
 4
 5namespace Microsoft.Azure.HDInsight.Job
 6{
 7    using System;
 8    using System.Collections.Generic;
 9    using System.Globalization;
 10    using System.IO;
 11    using System.Net;
 12    using System.Net.Http;
 13    using System.Text;
 14    using System.Threading;
 15    using System.Threading.Tasks;
 16    using Microsoft.Azure.HDInsight.Job.Models;
 17    using Microsoft.Rest;
 18    using Microsoft.Rest.Azure;
 19
 20    /// <summary>
 21    /// Operations for managing jobs against HDInsight clusters.
 22    /// </summary>
 23    internal partial class JobOperations : IServiceOperations<HDInsightJobClient>, IJobOperations
 24    {
 225        private static string jobPrefix = "job_";
 226        private static string appPrefix = "application_";
 27
 28        /// <summary>
 29        /// Submits a Hive job to an HDInsight cluster.
 30        /// </summary>
 31        /// <param name='parameters'>
 32        /// Required. Hive job parameters.
 33        /// </param>
 34        /// <returns>
 35        /// The Create Job operation response.
 36        /// </returns>
 37        public async Task<AzureOperationResponse<JobSubmissionJsonResponse>> SubmitHiveJobWithHttpMessagesAsync(HiveJobS
 38        {
 2039            using (var requestContents = new MemoryStream(Encoding.UTF8.GetBytes(parameters.GetJobPostRequestContent()))
 40            {
 2041                return await SubmitHiveJobWithHttpMessagesAsync(requestContents, customHeaders, cancellationToken).Confi
 42            }
 2043        }
 44
 45        /// <summary>
 46        /// Submits a MapReduce job to an HDInsight cluster.
 47        /// </summary>
 48        /// <param name='parameters'>
 49        /// Required. MapReduce job parameters.
 50        /// </param>
 51        /// <returns>
 52        /// The Create Job operation response.
 53        /// </returns>
 54        public async Task<AzureOperationResponse<JobSubmissionJsonResponse>> SubmitMapReduceJobWithHttpMessagesAsync(Map
 55        {
 656            using (var requestContents = new MemoryStream(Encoding.UTF8.GetBytes(parameters.GetJobPostRequestContent()))
 57            {
 658                return await SubmitMapReduceJobWithHttpMessagesAsync(requestContents, customHeaders, cancellationToken).
 59            }
 660        }
 61
 62        /// <summary>
 63        /// Submits a MapReduce streaming job to an HDInsight cluster.
 64        /// </summary>
 65        /// <param name='parameters'>
 66        /// Required. MapReduce job parameters.
 67        /// </param>
 68        /// <returns>
 69        /// The Create Job operation response.
 70        /// </returns>
 71        public async Task<AzureOperationResponse<JobSubmissionJsonResponse>> SubmitMapReduceStreamingJobWithHttpMessages
 72        {
 473            using (var requestContents = new MemoryStream(Encoding.UTF8.GetBytes(parameters.GetJobPostRequestContent()))
 74            {
 475                return await SubmitMapReduceStreamingJobWithHttpMessagesAsync(requestContents, customHeaders, cancellati
 76            }
 477        }
 78
 79        /// <summary>
 80        /// Submits a Pig job to an HDInsight cluster.
 81        /// </summary>
 82        /// <param name='parameters'>
 83        /// Required. Pig job parameters.
 84        /// </param>
 85        /// <returns>
 86        /// The Create Job operation response.
 87        /// </returns>
 88        public async Task<AzureOperationResponse<JobSubmissionJsonResponse>> SubmitPigJobWithHttpMessagesAsync(PigJobSub
 89        {
 490            using (var requestContents = new MemoryStream(Encoding.UTF8.GetBytes(parameters.GetJobPostRequestContent()))
 91            {
 492                return await SubmitPigJobWithHttpMessagesAsync(requestContents, customHeaders, cancellationToken).Config
 93            }
 494        }
 95
 96        /// <summary>
 97        /// Submits a Sqoop job to an HDInsight cluster.
 98        /// </summary>
 99        /// <param name='parameters'>
 100        /// Required. Sqoop job parameters.
 101        /// </param>
 102        /// <returns>
 103        /// The Create Job operation response.
 104        /// </returns>
 105        public async Task<AzureOperationResponse<JobSubmissionJsonResponse>> SubmitSqoopJobWithHttpMessagesAsync(SqoopJo
 106        {
 4107            using (var requestContents = new MemoryStream(Encoding.UTF8.GetBytes(parameters.GetJobPostRequestContent()))
 108            {
 4109                return await SubmitSqoopJobWithHttpMessagesAsync(requestContents, customHeaders, cancellationToken).Conf
 110            }
 4111        }
 112
 113        /// <summary>
 114        /// Gets the job output content as memory stream.
 115        /// </summary>
 116        /// <param name='jobId'>
 117        /// Required. The id of the job.
 118        /// </param>
 119        /// <param name="storageAccess">
 120        /// Required. The storage account object of type IStorageAccess.
 121        /// </param>
 122        /// <param name='cancellationToken'>
 123        /// Cancellation token.
 124        /// </param>
 125        /// <returns>
 126        /// The job output content as memory stream.
 127        /// </returns>
 128        public async Task<Stream> GetJobOutputAsync(string jobId, IStorageAccess storageAccess, CancellationToken cancel
 129        {
 0130            var blobReferencePath = await GetJobStatusDirectory(jobId, "stdout").ConfigureAwait(false);
 0131            return storageAccess.GetFileContent(blobReferencePath);
 0132        }
 133
 134        /// <summary>
 135        /// Gets the job error output content as memory stream.
 136        /// </summary>
 137        /// <param name='jobId'>
 138        /// Required. The id of the job.
 139        /// </param>
 140        /// <param name="storageAccess">
 141        /// Required. The storage account object of type IStorageAccess.
 142        /// </param>
 143        /// <param name='cancellationToken'>
 144        /// Cancellation token.
 145        /// </param>
 146        /// <returns>
 147        /// The job error output content as memory stream when job fails to run successfully.
 148        /// </returns>
 149        public async Task<Stream> GetJobErrorLogsAsync(string jobId, IStorageAccess storageAccess, CancellationToken can
 150        {
 0151            var blobReferencePath = await GetJobStatusDirectory(jobId, "stderr").ConfigureAwait(false);
 0152            return storageAccess.GetFileContent(blobReferencePath);
 0153        }
 154
 155        /// <summary>
 156        /// Wait for completion of a Job.
 157        /// </summary>
 158        /// <param name='jobId'>
 159        /// Required. The id of the job.
 160        /// </param>
 161        /// <param name='duration'>
 162        /// Optional. The maximum duration to wait for completion of job before returning to client. If not passed then 
 163        /// </param>
 164        /// <param name='waitInterval'>
 165        /// Optional. The interval to poll for job status. The default value is set from DefaultPollInterval property of
 166        /// </param>
 167        /// <exception cref="TimeoutException">
 168        /// Thrown when waiting for job completion exceeds the maximum duration specified by parameter duration.
 169        /// </exception>
 170        public async Task<AzureOperationResponse<JobDetailRootJsonObject>> WaitForJobCompletionWithHttpMessagesAsync(str
 171        {
 26172            var appId = GetAppIdFromJobId(jobId);
 26173            var startTime = DateTime.UtcNow;
 26174            bool waitTimeOut = false;
 175
 26176            if (waitInterval == null)
 177            {
 0178                waitInterval = HDInsightJobClient.DefaultPollInterval;
 179            }
 180
 181            // We poll Yarn for application status until application run is finished. If the application is
 182            // in finished state then we poll templeton to get completed job details.
 26183            AzureOperationResponse<JobDetailRootJsonObject> jobDetail = null;
 184
 185            // If duration is null means we need to keep retry until job is complete.
 406186            while (duration == null || !(waitTimeOut = ((DateTime.UtcNow - startTime) > duration)))
 187            {
 188                try
 189                {
 406190                    var jobState = await this.GetAppStateAsync(appId, CancellationToken.None).ConfigureAwait(false);
 191
 406192                    var appState = jobState.State;
 406193                    if (appState == ApplicationState.FINISHED || appState == ApplicationState.FAILED || appState == Appl
 194                    {
 195                        // Get the job finished details now and keep checking if Job is complete from Templeton
 196                        // as history server may not have picked up the completed job.
 26197                        using (jobDetail = await this.GetWithHttpMessagesAsync(jobId).ConfigureAwait(false))
 198                        {
 26199                            if (jobDetail.Body.Status.JobComplete == true)
 200                            {
 26201                                break;
 202                            }
 0203                        }
 204                    }
 380205                }
 0206                catch (CloudException ex)
 207                {
 208                    // If transient error then keep retry until user specified duration.
 0209                    if (IsTransientError(ex.Response.StatusCode))
 210                    {
 0211                        LogMessages(ex.Message);
 212                    }
 213                    else
 214                    {
 215                        // Throw the same exception back to client.
 0216                        throw ex;
 217                    }
 0218                }
 219                catch (HttpRequestException ex)
 220                {
 221                    // For any other Http exceptions we keep retry.
 0222                    LogMessages(ex.Message);
 0223                }
 224
 380225                ModelHelper.Delay(waitInterval.Value);
 226            }
 227
 26228            if (waitTimeOut)
 229            {
 230                // If user specified duration exceeded then raise a time out exception and kill the job if requested.
 0231                throw new TimeoutException(string.Format(CultureInfo.InvariantCulture, "The requested task failed to com
 232            }
 233
 26234            return jobDetail;
 26235        }
 236
 237        private async Task<string> GetJobStatusDirectory(string jobId, string file)
 238        {
 0239            var jobDetail = await this.GetAsync(jobId).ConfigureAwait(false);
 0240            var statusDir = GetStatusFolder(jobDetail);
 241
 0242            if (statusDir == null)
 243            {
 0244                throw new CloudException(string.Format("Job {0} was not created with a status folder and therefore no lo
 245            }
 246
 0247            return string.Format("user/{0}/{1}/{2}", jobDetail.User, statusDir, file);
 0248        }
 249
 250        private static string GetStatusFolder(JobDetailRootJsonObject job)
 251        {
 0252            return job.Userargs.Statusdir == null ? null : job.Userargs.Statusdir.ToString();
 253        }
 254
 255        private static string GetAppIdFromJobId(string jobId)
 256        {
 257            // Validate Job Id
 26258            if (string.IsNullOrWhiteSpace(jobId) || !jobId.StartsWith(jobPrefix))
 259            {
 0260                throw new CloudException(String.Format("Invalid job id {0}", jobId));
 261            }
 262
 26263            return appPrefix + jobId.Substring(jobPrefix.Length);
 264        }
 265
 266        private static bool IsTransientError(HttpStatusCode status)
 267        {
 0268            return status == HttpStatusCode.RequestTimeout ||
 0269                        (status >= HttpStatusCode.InternalServerError &&
 0270                        status != HttpStatusCode.NotImplemented &&
 0271                        status != HttpStatusCode.HttpVersionNotSupported);
 272        }
 273
 274        private static void LogMessages(string message)
 275        {
 0276            if (ServiceClientTracing.IsEnabled)
 277            {
 0278                ServiceClientTracing.Information(message);
 279            }
 0280        }
 281    }
 282}

C:\Git\azure-sdk-for-net\sdk\hdinsight\Microsoft.Azure.HDInsight.Job\src\Generated\JobOperations.cs

#LineLine coverage
 1// <auto-generated>
 2// Copyright (c) Microsoft Corporation. All rights reserved.
 3// Licensed under the MIT License. See License.txt in the project root for
 4// 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
 8// regenerated.
 9// </auto-generated>
 10
 11namespace Microsoft.Azure.HDInsight.Job
 12{
 13    using Microsoft.Rest;
 14    using Microsoft.Rest.Azure;
 15    using Models;
 16    using Newtonsoft.Json;
 17    using System.Collections;
 18    using System.Collections.Generic;
 19    using System.IO;
 20    using System.Linq;
 21    using System.Net;
 22    using System.Net.Http;
 23    using System.Threading;
 24    using System.Threading.Tasks;
 25
 26    /// <summary>
 27    /// JobOperations operations.
 28    /// </summary>
 29    internal partial class JobOperations : IServiceOperations<HDInsightJobClient>, IJobOperations
 30    {
 31        /// <summary>
 32        /// Initializes a new instance of the JobOperations class.
 33        /// </summary>
 34        /// <param name='client'>
 35        /// Reference to the service client.
 36        /// </param>
 37        /// <exception cref="System.ArgumentNullException">
 38        /// Thrown when a required parameter is null
 39        /// </exception>
 5840        internal JobOperations(HDInsightJobClient client)
 41        {
 5842            if (client == null)
 43            {
 044                throw new System.ArgumentNullException("client");
 45            }
 5846            Client = client;
 5847        }
 48
 49        /// <summary>
 50        /// Gets a reference to the HDInsightJobClient
 51        /// </summary>
 652652        public HDInsightJobClient Client { get; private set; }
 53
 54        /// <summary>
 55        /// Gets job details from the specified HDInsight cluster.
 56        /// </summary>
 57        /// <param name='jobId'>
 58        /// The id of the job.
 59        /// </param>
 60        /// <param name='customHeaders'>
 61        /// Headers that will be added to request.
 62        /// </param>
 63        /// <param name='cancellationToken'>
 64        /// The cancellation token.
 65        /// </param>
 66        /// <exception cref="JobOperationsErrorResponseException">
 67        /// Thrown when the operation returned an invalid status code
 68        /// </exception>
 69        /// <exception cref="SerializationException">
 70        /// Thrown when unable to deserialize the response
 71        /// </exception>
 72        /// <exception cref="ValidationException">
 73        /// Thrown when a required parameter is null
 74        /// </exception>
 75        /// <exception cref="System.ArgumentNullException">
 76        /// Thrown when a required parameter is null
 77        /// </exception>
 78        /// <return>
 79        /// A response object containing the response body and response headers.
 80        /// </return>
 81        public async Task<AzureOperationResponse<JobDetailRootJsonObject>> GetWithHttpMessagesAsync(string jobId, Dictio
 82        {
 3083            if (Client.Endpoint == null)
 84            {
 085                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 86            }
 3087            if (Client.Username == null)
 88            {
 089                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Username");
 90            }
 3091            if (jobId == null)
 92            {
 093                throw new ValidationException(ValidationRules.CannotBeNull, "jobId");
 94            }
 3095            string fields = "*";
 96            // Tracing
 3097            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 3098            string _invocationId = null;
 3099            if (_shouldTrace)
 100            {
 0101                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0102                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0103                tracingParameters.Add("jobId", jobId);
 0104                tracingParameters.Add("fields", fields);
 0105                tracingParameters.Add("cancellationToken", cancellationToken);
 0106                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 107            }
 108            // Construct URL
 30109            var _baseUrl = Client.BaseUri;
 30110            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "templeton/v1/jobs/{jobId}";
 30111            _url = _url.Replace("{endpoint}", Client.Endpoint);
 30112            _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId));
 30113            List<string> _queryParameters = new List<string>();
 30114            if (Client.Username != null)
 115            {
 30116                _queryParameters.Add(string.Format("user.name={0}", System.Uri.EscapeDataString(Client.Username)));
 117            }
 30118            if (fields != null)
 119            {
 30120                _queryParameters.Add(string.Format("fields={0}", System.Uri.EscapeDataString(fields)));
 121            }
 30122            if (_queryParameters.Count > 0)
 123            {
 30124                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 125            }
 126            // Create HTTP transport objects
 30127            var _httpRequest = new HttpRequestMessage();
 30128            HttpResponseMessage _httpResponse = null;
 30129            _httpRequest.Method = new HttpMethod("GET");
 30130            _httpRequest.RequestUri = new System.Uri(_url);
 131            // Set Headers
 30132            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 133            {
 30134                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 135            }
 30136            if (Client.AcceptLanguage != null)
 137            {
 30138                if (_httpRequest.Headers.Contains("accept-language"))
 139                {
 0140                    _httpRequest.Headers.Remove("accept-language");
 141                }
 30142                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 143            }
 144
 145
 30146            if (customHeaders != null)
 147            {
 0148                foreach(var _header in customHeaders)
 149                {
 0150                    if (_httpRequest.Headers.Contains(_header.Key))
 151                    {
 0152                        _httpRequest.Headers.Remove(_header.Key);
 153                    }
 0154                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 155                }
 156            }
 157
 158            // Serialize Request
 30159            string _requestContent = null;
 160            // Set Credentials
 30161            if (Client.Credentials != null)
 162            {
 30163                cancellationToken.ThrowIfCancellationRequested();
 30164                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 165            }
 166            // Send Request
 30167            if (_shouldTrace)
 168            {
 0169                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 170            }
 30171            cancellationToken.ThrowIfCancellationRequested();
 30172            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 30173            if (_shouldTrace)
 174            {
 0175                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 176            }
 30177            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 30178            cancellationToken.ThrowIfCancellationRequested();
 30179            string _responseContent = null;
 30180            if ((int)_statusCode != 200)
 181            {
 2182                var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod
 183                try
 184                {
 2185                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2186                    JobOperationsErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe
 2187                    if (_errorBody != null)
 188                    {
 2189                        ex.Body = _errorBody;
 190                    }
 2191                }
 0192                catch (JsonException)
 193                {
 194                    // Ignore the exception
 0195                }
 2196                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 2197                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 2198                if (_shouldTrace)
 199                {
 0200                    ServiceClientTracing.Error(_invocationId, ex);
 201                }
 2202                _httpRequest.Dispose();
 2203                if (_httpResponse != null)
 204                {
 2205                    _httpResponse.Dispose();
 206                }
 2207                throw ex;
 208            }
 209            // Create Result
 28210            var _result = new AzureOperationResponse<JobDetailRootJsonObject>();
 28211            _result.Request = _httpRequest;
 28212            _result.Response = _httpResponse;
 28213            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 214            {
 0215                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 216            }
 217            // Deserialize Response
 28218            if ((int)_statusCode == 200)
 219            {
 28220                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 221                try
 222                {
 28223                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobDetailRootJsonObject>(_respon
 28224                }
 0225                catch (JsonException ex)
 226                {
 0227                    _httpRequest.Dispose();
 0228                    if (_httpResponse != null)
 229                    {
 0230                        _httpResponse.Dispose();
 231                    }
 0232                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 233                }
 234            }
 28235            if (_shouldTrace)
 236            {
 0237                ServiceClientTracing.Exit(_invocationId, _result);
 238            }
 28239            return _result;
 28240        }
 241
 242        /// <summary>
 243        /// Initiates cancel on given running job in the specified HDInsight.
 244        /// </summary>
 245        /// <param name='jobId'>
 246        /// The id of the job.
 247        /// </param>
 248        /// <param name='customHeaders'>
 249        /// Headers that will be added to request.
 250        /// </param>
 251        /// <param name='cancellationToken'>
 252        /// The cancellation token.
 253        /// </param>
 254        /// <exception cref="JobOperationsErrorResponseException">
 255        /// Thrown when the operation returned an invalid status code
 256        /// </exception>
 257        /// <exception cref="SerializationException">
 258        /// Thrown when unable to deserialize the response
 259        /// </exception>
 260        /// <exception cref="ValidationException">
 261        /// Thrown when a required parameter is null
 262        /// </exception>
 263        /// <exception cref="System.ArgumentNullException">
 264        /// Thrown when a required parameter is null
 265        /// </exception>
 266        /// <return>
 267        /// A response object containing the response body and response headers.
 268        /// </return>
 269        public async Task<AzureOperationResponse<JobDetailRootJsonObject>> KillWithHttpMessagesAsync(string jobId, Dicti
 270        {
 4271            if (Client.Endpoint == null)
 272            {
 0273                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 274            }
 4275            if (Client.Username == null)
 276            {
 0277                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Username");
 278            }
 4279            if (jobId == null)
 280            {
 0281                throw new ValidationException(ValidationRules.CannotBeNull, "jobId");
 282            }
 4283            if (jobId != null)
 284            {
 4285                if (jobId.Length < 1)
 286                {
 2287                    throw new ValidationException(ValidationRules.MinLength, "jobId", 1);
 288                }
 289            }
 290            // Tracing
 2291            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2292            string _invocationId = null;
 2293            if (_shouldTrace)
 294            {
 0295                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0296                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0297                tracingParameters.Add("jobId", jobId);
 0298                tracingParameters.Add("cancellationToken", cancellationToken);
 0299                ServiceClientTracing.Enter(_invocationId, this, "Kill", tracingParameters);
 300            }
 301            // Construct URL
 2302            var _baseUrl = Client.BaseUri;
 2303            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "templeton/v1/jobs/{jobId}";
 2304            _url = _url.Replace("{endpoint}", Client.Endpoint);
 2305            _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId));
 2306            List<string> _queryParameters = new List<string>();
 2307            if (Client.Username != null)
 308            {
 2309                _queryParameters.Add(string.Format("user.name={0}", System.Uri.EscapeDataString(Client.Username)));
 310            }
 2311            if (_queryParameters.Count > 0)
 312            {
 2313                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 314            }
 315            // Create HTTP transport objects
 2316            var _httpRequest = new HttpRequestMessage();
 2317            HttpResponseMessage _httpResponse = null;
 2318            _httpRequest.Method = new HttpMethod("DELETE");
 2319            _httpRequest.RequestUri = new System.Uri(_url);
 320            // Set Headers
 2321            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 322            {
 2323                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 324            }
 2325            if (Client.AcceptLanguage != null)
 326            {
 2327                if (_httpRequest.Headers.Contains("accept-language"))
 328                {
 0329                    _httpRequest.Headers.Remove("accept-language");
 330                }
 2331                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 332            }
 333
 334
 2335            if (customHeaders != null)
 336            {
 0337                foreach(var _header in customHeaders)
 338                {
 0339                    if (_httpRequest.Headers.Contains(_header.Key))
 340                    {
 0341                        _httpRequest.Headers.Remove(_header.Key);
 342                    }
 0343                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 344                }
 345            }
 346
 347            // Serialize Request
 2348            string _requestContent = null;
 349            // Set Credentials
 2350            if (Client.Credentials != null)
 351            {
 2352                cancellationToken.ThrowIfCancellationRequested();
 2353                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 354            }
 355            // Send Request
 2356            if (_shouldTrace)
 357            {
 0358                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 359            }
 2360            cancellationToken.ThrowIfCancellationRequested();
 2361            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2362            if (_shouldTrace)
 363            {
 0364                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 365            }
 2366            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2367            cancellationToken.ThrowIfCancellationRequested();
 2368            string _responseContent = null;
 2369            if ((int)_statusCode != 200)
 370            {
 0371                var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod
 372                try
 373                {
 0374                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0375                    JobOperationsErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe
 0376                    if (_errorBody != null)
 377                    {
 0378                        ex.Body = _errorBody;
 379                    }
 0380                }
 0381                catch (JsonException)
 382                {
 383                    // Ignore the exception
 0384                }
 0385                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0386                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0387                if (_shouldTrace)
 388                {
 0389                    ServiceClientTracing.Error(_invocationId, ex);
 390                }
 0391                _httpRequest.Dispose();
 0392                if (_httpResponse != null)
 393                {
 0394                    _httpResponse.Dispose();
 395                }
 0396                throw ex;
 397            }
 398            // Create Result
 2399            var _result = new AzureOperationResponse<JobDetailRootJsonObject>();
 2400            _result.Request = _httpRequest;
 2401            _result.Response = _httpResponse;
 2402            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 403            {
 0404                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 405            }
 406            // Deserialize Response
 2407            if ((int)_statusCode == 200)
 408            {
 2409                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 410                try
 411                {
 2412                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobDetailRootJsonObject>(_respon
 2413                }
 0414                catch (JsonException ex)
 415                {
 0416                    _httpRequest.Dispose();
 0417                    if (_httpResponse != null)
 418                    {
 0419                        _httpResponse.Dispose();
 420                    }
 0421                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 422                }
 423            }
 2424            if (_shouldTrace)
 425            {
 0426                ServiceClientTracing.Exit(_invocationId, _result);
 427            }
 2428            return _result;
 2429        }
 430
 431        /// <summary>
 432        /// Gets the list of jobs from the specified HDInsight cluster.
 433        /// </summary>
 434        /// <param name='customHeaders'>
 435        /// Headers that will be added to request.
 436        /// </param>
 437        /// <param name='cancellationToken'>
 438        /// The cancellation token.
 439        /// </param>
 440        /// <exception cref="JobOperationsErrorResponseException">
 441        /// Thrown when the operation returned an invalid status code
 442        /// </exception>
 443        /// <exception cref="SerializationException">
 444        /// Thrown when unable to deserialize the response
 445        /// </exception>
 446        /// <exception cref="ValidationException">
 447        /// Thrown when a required parameter is null
 448        /// </exception>
 449        /// <exception cref="System.ArgumentNullException">
 450        /// Thrown when a required parameter is null
 451        /// </exception>
 452        /// <return>
 453        /// A response object containing the response body and response headers.
 454        /// </return>
 455        public async Task<AzureOperationResponse<IList<JobListJsonObject>>> ListWithHttpMessagesAsync(Dictionary<string,
 456        {
 6457            if (Client.Endpoint == null)
 458            {
 0459                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 460            }
 6461            if (Client.Username == null)
 462            {
 0463                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Username");
 464            }
 6465            string showall = "true";
 6466            string fields = "*";
 467            // Tracing
 6468            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 6469            string _invocationId = null;
 6470            if (_shouldTrace)
 471            {
 0472                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0473                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0474                tracingParameters.Add("showall", showall);
 0475                tracingParameters.Add("fields", fields);
 0476                tracingParameters.Add("cancellationToken", cancellationToken);
 0477                ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters);
 478            }
 479            // Construct URL
 6480            var _baseUrl = Client.BaseUri;
 6481            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "templeton/v1/jobs";
 6482            _url = _url.Replace("{endpoint}", Client.Endpoint);
 6483            List<string> _queryParameters = new List<string>();
 6484            if (Client.Username != null)
 485            {
 6486                _queryParameters.Add(string.Format("user.name={0}", System.Uri.EscapeDataString(Client.Username)));
 487            }
 6488            if (showall != null)
 489            {
 6490                _queryParameters.Add(string.Format("showall={0}", System.Uri.EscapeDataString(showall)));
 491            }
 6492            if (fields != null)
 493            {
 6494                _queryParameters.Add(string.Format("fields={0}", System.Uri.EscapeDataString(fields)));
 495            }
 6496            if (_queryParameters.Count > 0)
 497            {
 6498                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 499            }
 500            // Create HTTP transport objects
 6501            var _httpRequest = new HttpRequestMessage();
 6502            HttpResponseMessage _httpResponse = null;
 6503            _httpRequest.Method = new HttpMethod("GET");
 6504            _httpRequest.RequestUri = new System.Uri(_url);
 505            // Set Headers
 6506            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 507            {
 6508                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 509            }
 6510            if (Client.AcceptLanguage != null)
 511            {
 6512                if (_httpRequest.Headers.Contains("accept-language"))
 513                {
 0514                    _httpRequest.Headers.Remove("accept-language");
 515                }
 6516                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 517            }
 518
 519
 6520            if (customHeaders != null)
 521            {
 0522                foreach(var _header in customHeaders)
 523                {
 0524                    if (_httpRequest.Headers.Contains(_header.Key))
 525                    {
 0526                        _httpRequest.Headers.Remove(_header.Key);
 527                    }
 0528                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 529                }
 530            }
 531
 532            // Serialize Request
 6533            string _requestContent = null;
 534            // Set Credentials
 6535            if (Client.Credentials != null)
 536            {
 6537                cancellationToken.ThrowIfCancellationRequested();
 6538                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 539            }
 540            // Send Request
 6541            if (_shouldTrace)
 542            {
 0543                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 544            }
 6545            cancellationToken.ThrowIfCancellationRequested();
 6546            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 6547            if (_shouldTrace)
 548            {
 0549                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 550            }
 6551            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 6552            cancellationToken.ThrowIfCancellationRequested();
 6553            string _responseContent = null;
 6554            if ((int)_statusCode != 200)
 555            {
 0556                var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod
 557                try
 558                {
 0559                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0560                    JobOperationsErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe
 0561                    if (_errorBody != null)
 562                    {
 0563                        ex.Body = _errorBody;
 564                    }
 0565                }
 0566                catch (JsonException)
 567                {
 568                    // Ignore the exception
 0569                }
 0570                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0571                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0572                if (_shouldTrace)
 573                {
 0574                    ServiceClientTracing.Error(_invocationId, ex);
 575                }
 0576                _httpRequest.Dispose();
 0577                if (_httpResponse != null)
 578                {
 0579                    _httpResponse.Dispose();
 580                }
 0581                throw ex;
 582            }
 583            // Create Result
 6584            var _result = new AzureOperationResponse<IList<JobListJsonObject>>();
 6585            _result.Request = _httpRequest;
 6586            _result.Response = _httpResponse;
 6587            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 588            {
 0589                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 590            }
 591            // Deserialize Response
 6592            if ((int)_statusCode == 200)
 593            {
 6594                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 595                try
 596                {
 6597                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<JobListJsonObject>>(_respo
 6598                }
 0599                catch (JsonException ex)
 600                {
 0601                    _httpRequest.Dispose();
 0602                    if (_httpResponse != null)
 603                    {
 0604                        _httpResponse.Dispose();
 605                    }
 0606                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 607                }
 608            }
 6609            if (_shouldTrace)
 610            {
 0611                ServiceClientTracing.Exit(_invocationId, _result);
 612            }
 6613            return _result;
 6614        }
 615
 616        /// <summary>
 617        /// Gets numrecords Of Jobs after jobid from the specified HDInsight cluster.
 618        /// </summary>
 619        /// <param name='jobid'>
 620        /// JobId from where to list jobs.
 621        /// </param>
 622        /// <param name='numrecords'>
 623        /// Number of jobs to fetch.
 624        /// </param>
 625        /// <param name='customHeaders'>
 626        /// Headers that will be added to request.
 627        /// </param>
 628        /// <param name='cancellationToken'>
 629        /// The cancellation token.
 630        /// </param>
 631        /// <exception cref="JobOperationsErrorResponseException">
 632        /// Thrown when the operation returned an invalid status code
 633        /// </exception>
 634        /// <exception cref="SerializationException">
 635        /// Thrown when unable to deserialize the response
 636        /// </exception>
 637        /// <exception cref="ValidationException">
 638        /// Thrown when a required parameter is null
 639        /// </exception>
 640        /// <exception cref="System.ArgumentNullException">
 641        /// Thrown when a required parameter is null
 642        /// </exception>
 643        /// <return>
 644        /// A response object containing the response body and response headers.
 645        /// </return>
 646        public async Task<AzureOperationResponse<IList<JobListJsonObject>>> ListAfterJobIdWithHttpMessagesAsync(string j
 647        {
 18648            if (Client.Endpoint == null)
 649            {
 0650                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 651            }
 18652            if (Client.Username == null)
 653            {
 0654                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Username");
 655            }
 18656            if (numrecords < 1)
 657            {
 0658                throw new ValidationException(ValidationRules.InclusiveMinimum, "numrecords", 1);
 659            }
 18660            string showall = "true";
 18661            string fields = "*";
 662            // Tracing
 18663            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 18664            string _invocationId = null;
 18665            if (_shouldTrace)
 666            {
 0667                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0668                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0669                tracingParameters.Add("jobid", jobid);
 0670                tracingParameters.Add("numrecords", numrecords);
 0671                tracingParameters.Add("showall", showall);
 0672                tracingParameters.Add("fields", fields);
 0673                tracingParameters.Add("cancellationToken", cancellationToken);
 0674                ServiceClientTracing.Enter(_invocationId, this, "ListAfterJobId", tracingParameters);
 675            }
 676            // Construct URL
 18677            var _baseUrl = Client.BaseUri;
 18678            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "templeton/v1/jobs";
 18679            _url = _url.Replace("{endpoint}", Client.Endpoint);
 18680            List<string> _queryParameters = new List<string>();
 18681            if (Client.Username != null)
 682            {
 18683                _queryParameters.Add(string.Format("user.name={0}", System.Uri.EscapeDataString(Client.Username)));
 684            }
 18685            if (jobid != null)
 686            {
 18687                _queryParameters.Add(string.Format("jobid={0}", System.Uri.EscapeDataString(jobid)));
 688            }
 18689            if (numrecords != null)
 690            {
 18691                _queryParameters.Add(string.Format("numrecords={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe
 692            }
 18693            if (showall != null)
 694            {
 18695                _queryParameters.Add(string.Format("showall={0}", System.Uri.EscapeDataString(showall)));
 696            }
 18697            if (fields != null)
 698            {
 18699                _queryParameters.Add(string.Format("fields={0}", System.Uri.EscapeDataString(fields)));
 700            }
 18701            if (_queryParameters.Count > 0)
 702            {
 18703                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 704            }
 705            // Create HTTP transport objects
 18706            var _httpRequest = new HttpRequestMessage();
 18707            HttpResponseMessage _httpResponse = null;
 18708            _httpRequest.Method = new HttpMethod("GET");
 18709            _httpRequest.RequestUri = new System.Uri(_url);
 710            // Set Headers
 18711            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 712            {
 18713                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 714            }
 18715            if (Client.AcceptLanguage != null)
 716            {
 18717                if (_httpRequest.Headers.Contains("accept-language"))
 718                {
 0719                    _httpRequest.Headers.Remove("accept-language");
 720                }
 18721                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 722            }
 723
 724
 18725            if (customHeaders != null)
 726            {
 0727                foreach(var _header in customHeaders)
 728                {
 0729                    if (_httpRequest.Headers.Contains(_header.Key))
 730                    {
 0731                        _httpRequest.Headers.Remove(_header.Key);
 732                    }
 0733                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 734                }
 735            }
 736
 737            // Serialize Request
 18738            string _requestContent = null;
 739            // Set Credentials
 18740            if (Client.Credentials != null)
 741            {
 18742                cancellationToken.ThrowIfCancellationRequested();
 18743                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 744            }
 745            // Send Request
 18746            if (_shouldTrace)
 747            {
 0748                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 749            }
 18750            cancellationToken.ThrowIfCancellationRequested();
 18751            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 18752            if (_shouldTrace)
 753            {
 0754                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 755            }
 18756            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 18757            cancellationToken.ThrowIfCancellationRequested();
 18758            string _responseContent = null;
 18759            if ((int)_statusCode != 200)
 760            {
 0761                var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod
 762                try
 763                {
 0764                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0765                    JobOperationsErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe
 0766                    if (_errorBody != null)
 767                    {
 0768                        ex.Body = _errorBody;
 769                    }
 0770                }
 0771                catch (JsonException)
 772                {
 773                    // Ignore the exception
 0774                }
 0775                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0776                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0777                if (_shouldTrace)
 778                {
 0779                    ServiceClientTracing.Error(_invocationId, ex);
 780                }
 0781                _httpRequest.Dispose();
 0782                if (_httpResponse != null)
 783                {
 0784                    _httpResponse.Dispose();
 785                }
 0786                throw ex;
 787            }
 788            // Create Result
 18789            var _result = new AzureOperationResponse<IList<JobListJsonObject>>();
 18790            _result.Request = _httpRequest;
 18791            _result.Response = _httpResponse;
 18792            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 793            {
 0794                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 795            }
 796            // Deserialize Response
 18797            if ((int)_statusCode == 200)
 798            {
 18799                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 800                try
 801                {
 18802                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<JobListJsonObject>>(_respo
 18803                }
 0804                catch (JsonException ex)
 805                {
 0806                    _httpRequest.Dispose();
 0807                    if (_httpResponse != null)
 808                    {
 0809                        _httpResponse.Dispose();
 810                    }
 0811                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 812                }
 813            }
 18814            if (_shouldTrace)
 815            {
 0816                ServiceClientTracing.Exit(_invocationId, _result);
 817            }
 18818            return _result;
 18819        }
 820
 821        /// <summary>
 822        /// Submits a Hive job to an HDInsight cluster.
 823        /// </summary>
 824        /// <param name='content'>
 825        /// The content of the Hive job request.
 826        /// </param>
 827        /// <param name='customHeaders'>
 828        /// Headers that will be added to request.
 829        /// </param>
 830        /// <param name='cancellationToken'>
 831        /// The cancellation token.
 832        /// </param>
 833        /// <exception cref="JobOperationsErrorResponseException">
 834        /// Thrown when the operation returned an invalid status code
 835        /// </exception>
 836        /// <exception cref="SerializationException">
 837        /// Thrown when unable to deserialize the response
 838        /// </exception>
 839        /// <exception cref="ValidationException">
 840        /// Thrown when a required parameter is null
 841        /// </exception>
 842        /// <exception cref="System.ArgumentNullException">
 843        /// Thrown when a required parameter is null
 844        /// </exception>
 845        /// <return>
 846        /// A response object containing the response body and response headers.
 847        /// </return>
 848        public async Task<AzureOperationResponse<JobSubmissionJsonResponse>> SubmitHiveJobWithHttpMessagesAsync(Stream c
 849        {
 20850            if (Client.Endpoint == null)
 851            {
 0852                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 853            }
 20854            if (Client.Username == null)
 855            {
 0856                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Username");
 857            }
 20858            if (content == null)
 859            {
 0860                throw new ValidationException(ValidationRules.CannotBeNull, "content");
 861            }
 862            // Tracing
 20863            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 20864            string _invocationId = null;
 20865            if (_shouldTrace)
 866            {
 0867                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0868                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0869                tracingParameters.Add("content", content);
 0870                tracingParameters.Add("cancellationToken", cancellationToken);
 0871                ServiceClientTracing.Enter(_invocationId, this, "SubmitHiveJob", tracingParameters);
 872            }
 873            // Construct URL
 20874            var _baseUrl = Client.BaseUri;
 20875            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "templeton/v1/hive";
 20876            _url = _url.Replace("{endpoint}", Client.Endpoint);
 20877            List<string> _queryParameters = new List<string>();
 20878            if (Client.Username != null)
 879            {
 20880                _queryParameters.Add(string.Format("user.name={0}", System.Uri.EscapeDataString(Client.Username)));
 881            }
 20882            if (_queryParameters.Count > 0)
 883            {
 20884                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 885            }
 886            // Create HTTP transport objects
 20887            var _httpRequest = new HttpRequestMessage();
 20888            HttpResponseMessage _httpResponse = null;
 20889            _httpRequest.Method = new HttpMethod("POST");
 20890            _httpRequest.RequestUri = new System.Uri(_url);
 891            // Set Headers
 20892            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 893            {
 20894                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 895            }
 20896            if (Client.AcceptLanguage != null)
 897            {
 20898                if (_httpRequest.Headers.Contains("accept-language"))
 899                {
 0900                    _httpRequest.Headers.Remove("accept-language");
 901                }
 20902                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 903            }
 904
 905
 20906            if (customHeaders != null)
 907            {
 0908                foreach(var _header in customHeaders)
 909                {
 0910                    if (_httpRequest.Headers.Contains(_header.Key))
 911                    {
 0912                        _httpRequest.Headers.Remove(_header.Key);
 913                    }
 0914                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 915                }
 916            }
 917
 918            // Serialize Request
 20919            string _requestContent = null;
 20920            if(content == null)
 921            {
 0922              throw new System.ArgumentNullException("content");
 923            }
 20924            if (content != null && content != Stream.Null)
 925            {
 20926                _httpRequest.Content = new StreamContent(content);
 20927                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 928            }
 929            // Set Credentials
 20930            if (Client.Credentials != null)
 931            {
 20932                cancellationToken.ThrowIfCancellationRequested();
 20933                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 934            }
 935            // Send Request
 20936            if (_shouldTrace)
 937            {
 0938                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 939            }
 20940            cancellationToken.ThrowIfCancellationRequested();
 20941            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 20942            if (_shouldTrace)
 943            {
 0944                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 945            }
 20946            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 20947            cancellationToken.ThrowIfCancellationRequested();
 20948            string _responseContent = null;
 20949            if ((int)_statusCode != 200)
 950            {
 0951                var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod
 952                try
 953                {
 0954                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0955                    JobOperationsErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe
 0956                    if (_errorBody != null)
 957                    {
 0958                        ex.Body = _errorBody;
 959                    }
 0960                }
 0961                catch (JsonException)
 962                {
 963                    // Ignore the exception
 0964                }
 0965                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0966                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0967                if (_shouldTrace)
 968                {
 0969                    ServiceClientTracing.Error(_invocationId, ex);
 970                }
 0971                _httpRequest.Dispose();
 0972                if (_httpResponse != null)
 973                {
 0974                    _httpResponse.Dispose();
 975                }
 0976                throw ex;
 977            }
 978            // Create Result
 20979            var _result = new AzureOperationResponse<JobSubmissionJsonResponse>();
 20980            _result.Request = _httpRequest;
 20981            _result.Response = _httpResponse;
 20982            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 983            {
 0984                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 985            }
 986            // Deserialize Response
 20987            if ((int)_statusCode == 200)
 988            {
 20989                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 990                try
 991                {
 20992                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobSubmissionJsonResponse>(_resp
 20993                }
 0994                catch (JsonException ex)
 995                {
 0996                    _httpRequest.Dispose();
 0997                    if (_httpResponse != null)
 998                    {
 0999                        _httpResponse.Dispose();
 1000                    }
 01001                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1002                }
 1003            }
 201004            if (_shouldTrace)
 1005            {
 01006                ServiceClientTracing.Exit(_invocationId, _result);
 1007            }
 201008            return _result;
 201009        }
 1010
 1011        /// <summary>
 1012        /// Submits a MapReduce job to an HDInsight cluster.
 1013        /// </summary>
 1014        /// <param name='content'>
 1015        /// The content of the MapReduce job request.
 1016        /// </param>
 1017        /// <param name='customHeaders'>
 1018        /// Headers that will be added to request.
 1019        /// </param>
 1020        /// <param name='cancellationToken'>
 1021        /// The cancellation token.
 1022        /// </param>
 1023        /// <exception cref="JobOperationsErrorResponseException">
 1024        /// Thrown when the operation returned an invalid status code
 1025        /// </exception>
 1026        /// <exception cref="SerializationException">
 1027        /// Thrown when unable to deserialize the response
 1028        /// </exception>
 1029        /// <exception cref="ValidationException">
 1030        /// Thrown when a required parameter is null
 1031        /// </exception>
 1032        /// <exception cref="System.ArgumentNullException">
 1033        /// Thrown when a required parameter is null
 1034        /// </exception>
 1035        /// <return>
 1036        /// A response object containing the response body and response headers.
 1037        /// </return>
 1038        public async Task<AzureOperationResponse<JobSubmissionJsonResponse>> SubmitMapReduceJobWithHttpMessagesAsync(Str
 1039        {
 61040            if (Client.Endpoint == null)
 1041            {
 01042                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1043            }
 61044            if (Client.Username == null)
 1045            {
 01046                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Username");
 1047            }
 61048            if (content == null)
 1049            {
 01050                throw new ValidationException(ValidationRules.CannotBeNull, "content");
 1051            }
 1052            // Tracing
 61053            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 61054            string _invocationId = null;
 61055            if (_shouldTrace)
 1056            {
 01057                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01058                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01059                tracingParameters.Add("content", content);
 01060                tracingParameters.Add("cancellationToken", cancellationToken);
 01061                ServiceClientTracing.Enter(_invocationId, this, "SubmitMapReduceJob", tracingParameters);
 1062            }
 1063            // Construct URL
 61064            var _baseUrl = Client.BaseUri;
 61065            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "templeton/v1/mapreduce/jar";
 61066            _url = _url.Replace("{endpoint}", Client.Endpoint);
 61067            List<string> _queryParameters = new List<string>();
 61068            if (Client.Username != null)
 1069            {
 61070                _queryParameters.Add(string.Format("user.name={0}", System.Uri.EscapeDataString(Client.Username)));
 1071            }
 61072            if (_queryParameters.Count > 0)
 1073            {
 61074                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1075            }
 1076            // Create HTTP transport objects
 61077            var _httpRequest = new HttpRequestMessage();
 61078            HttpResponseMessage _httpResponse = null;
 61079            _httpRequest.Method = new HttpMethod("POST");
 61080            _httpRequest.RequestUri = new System.Uri(_url);
 1081            // Set Headers
 61082            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1083            {
 61084                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 1085            }
 61086            if (Client.AcceptLanguage != null)
 1087            {
 61088                if (_httpRequest.Headers.Contains("accept-language"))
 1089                {
 01090                    _httpRequest.Headers.Remove("accept-language");
 1091                }
 61092                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1093            }
 1094
 1095
 61096            if (customHeaders != null)
 1097            {
 01098                foreach(var _header in customHeaders)
 1099                {
 01100                    if (_httpRequest.Headers.Contains(_header.Key))
 1101                    {
 01102                        _httpRequest.Headers.Remove(_header.Key);
 1103                    }
 01104                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1105                }
 1106            }
 1107
 1108            // Serialize Request
 61109            string _requestContent = null;
 61110            if(content == null)
 1111            {
 01112              throw new System.ArgumentNullException("content");
 1113            }
 61114            if (content != null && content != Stream.Null)
 1115            {
 61116                _httpRequest.Content = new StreamContent(content);
 61117                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("text/plain
 1118            }
 1119            // Set Credentials
 61120            if (Client.Credentials != null)
 1121            {
 61122                cancellationToken.ThrowIfCancellationRequested();
 61123                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1124            }
 1125            // Send Request
 61126            if (_shouldTrace)
 1127            {
 01128                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1129            }
 61130            cancellationToken.ThrowIfCancellationRequested();
 61131            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 61132            if (_shouldTrace)
 1133            {
 01134                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1135            }
 61136            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 61137            cancellationToken.ThrowIfCancellationRequested();
 61138            string _responseContent = null;
 61139            if ((int)_statusCode != 200)
 1140            {
 01141                var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod
 1142                try
 1143                {
 01144                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01145                    JobOperationsErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe
 01146                    if (_errorBody != null)
 1147                    {
 01148                        ex.Body = _errorBody;
 1149                    }
 01150                }
 01151                catch (JsonException)
 1152                {
 1153                    // Ignore the exception
 01154                }
 01155                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01156                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01157                if (_shouldTrace)
 1158                {
 01159                    ServiceClientTracing.Error(_invocationId, ex);
 1160                }
 01161                _httpRequest.Dispose();
 01162                if (_httpResponse != null)
 1163                {
 01164                    _httpResponse.Dispose();
 1165                }
 01166                throw ex;
 1167            }
 1168            // Create Result
 61169            var _result = new AzureOperationResponse<JobSubmissionJsonResponse>();
 61170            _result.Request = _httpRequest;
 61171            _result.Response = _httpResponse;
 61172            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 1173            {
 01174                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 1175            }
 1176            // Deserialize Response
 61177            if ((int)_statusCode == 200)
 1178            {
 61179                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1180                try
 1181                {
 61182                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobSubmissionJsonResponse>(_resp
 61183                }
 01184                catch (JsonException ex)
 1185                {
 01186                    _httpRequest.Dispose();
 01187                    if (_httpResponse != null)
 1188                    {
 01189                        _httpResponse.Dispose();
 1190                    }
 01191                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1192                }
 1193            }
 61194            if (_shouldTrace)
 1195            {
 01196                ServiceClientTracing.Exit(_invocationId, _result);
 1197            }
 61198            return _result;
 61199        }
 1200
 1201        /// <summary>
 1202        /// Submits a MapReduce streaming job to an HDInsight cluster.
 1203        /// </summary>
 1204        /// <param name='content'>
 1205        /// The content of the MapReduce job request.
 1206        /// </param>
 1207        /// <param name='customHeaders'>
 1208        /// Headers that will be added to request.
 1209        /// </param>
 1210        /// <param name='cancellationToken'>
 1211        /// The cancellation token.
 1212        /// </param>
 1213        /// <exception cref="JobOperationsErrorResponseException">
 1214        /// Thrown when the operation returned an invalid status code
 1215        /// </exception>
 1216        /// <exception cref="SerializationException">
 1217        /// Thrown when unable to deserialize the response
 1218        /// </exception>
 1219        /// <exception cref="ValidationException">
 1220        /// Thrown when a required parameter is null
 1221        /// </exception>
 1222        /// <exception cref="System.ArgumentNullException">
 1223        /// Thrown when a required parameter is null
 1224        /// </exception>
 1225        /// <return>
 1226        /// A response object containing the response body and response headers.
 1227        /// </return>
 1228        public async Task<AzureOperationResponse<JobSubmissionJsonResponse>> SubmitMapReduceStreamingJobWithHttpMessages
 1229        {
 41230            if (Client.Endpoint == null)
 1231            {
 01232                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1233            }
 41234            if (Client.Username == null)
 1235            {
 01236                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Username");
 1237            }
 41238            if (content == null)
 1239            {
 01240                throw new ValidationException(ValidationRules.CannotBeNull, "content");
 1241            }
 1242            // Tracing
 41243            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 41244            string _invocationId = null;
 41245            if (_shouldTrace)
 1246            {
 01247                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01248                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01249                tracingParameters.Add("content", content);
 01250                tracingParameters.Add("cancellationToken", cancellationToken);
 01251                ServiceClientTracing.Enter(_invocationId, this, "SubmitMapReduceStreamingJob", tracingParameters);
 1252            }
 1253            // Construct URL
 41254            var _baseUrl = Client.BaseUri;
 41255            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "templeton/v1/mapreduce/streaming";
 41256            _url = _url.Replace("{endpoint}", Client.Endpoint);
 41257            List<string> _queryParameters = new List<string>();
 41258            if (Client.Username != null)
 1259            {
 41260                _queryParameters.Add(string.Format("user.name={0}", System.Uri.EscapeDataString(Client.Username)));
 1261            }
 41262            if (_queryParameters.Count > 0)
 1263            {
 41264                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1265            }
 1266            // Create HTTP transport objects
 41267            var _httpRequest = new HttpRequestMessage();
 41268            HttpResponseMessage _httpResponse = null;
 41269            _httpRequest.Method = new HttpMethod("POST");
 41270            _httpRequest.RequestUri = new System.Uri(_url);
 1271            // Set Headers
 41272            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1273            {
 41274                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 1275            }
 41276            if (Client.AcceptLanguage != null)
 1277            {
 41278                if (_httpRequest.Headers.Contains("accept-language"))
 1279                {
 01280                    _httpRequest.Headers.Remove("accept-language");
 1281                }
 41282                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1283            }
 1284
 1285
 41286            if (customHeaders != null)
 1287            {
 01288                foreach(var _header in customHeaders)
 1289                {
 01290                    if (_httpRequest.Headers.Contains(_header.Key))
 1291                    {
 01292                        _httpRequest.Headers.Remove(_header.Key);
 1293                    }
 01294                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1295                }
 1296            }
 1297
 1298            // Serialize Request
 41299            string _requestContent = null;
 41300            if(content == null)
 1301            {
 01302              throw new System.ArgumentNullException("content");
 1303            }
 41304            if (content != null && content != Stream.Null)
 1305            {
 41306                _httpRequest.Content = new StreamContent(content);
 41307                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("text/plain
 1308            }
 1309            // Set Credentials
 41310            if (Client.Credentials != null)
 1311            {
 41312                cancellationToken.ThrowIfCancellationRequested();
 41313                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1314            }
 1315            // Send Request
 41316            if (_shouldTrace)
 1317            {
 01318                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1319            }
 41320            cancellationToken.ThrowIfCancellationRequested();
 41321            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 41322            if (_shouldTrace)
 1323            {
 01324                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1325            }
 41326            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 41327            cancellationToken.ThrowIfCancellationRequested();
 41328            string _responseContent = null;
 41329            if ((int)_statusCode != 200)
 1330            {
 01331                var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod
 1332                try
 1333                {
 01334                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01335                    JobOperationsErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe
 01336                    if (_errorBody != null)
 1337                    {
 01338                        ex.Body = _errorBody;
 1339                    }
 01340                }
 01341                catch (JsonException)
 1342                {
 1343                    // Ignore the exception
 01344                }
 01345                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01346                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01347                if (_shouldTrace)
 1348                {
 01349                    ServiceClientTracing.Error(_invocationId, ex);
 1350                }
 01351                _httpRequest.Dispose();
 01352                if (_httpResponse != null)
 1353                {
 01354                    _httpResponse.Dispose();
 1355                }
 01356                throw ex;
 1357            }
 1358            // Create Result
 41359            var _result = new AzureOperationResponse<JobSubmissionJsonResponse>();
 41360            _result.Request = _httpRequest;
 41361            _result.Response = _httpResponse;
 41362            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 1363            {
 01364                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 1365            }
 1366            // Deserialize Response
 41367            if ((int)_statusCode == 200)
 1368            {
 41369                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1370                try
 1371                {
 41372                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobSubmissionJsonResponse>(_resp
 41373                }
 01374                catch (JsonException ex)
 1375                {
 01376                    _httpRequest.Dispose();
 01377                    if (_httpResponse != null)
 1378                    {
 01379                        _httpResponse.Dispose();
 1380                    }
 01381                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1382                }
 1383            }
 41384            if (_shouldTrace)
 1385            {
 01386                ServiceClientTracing.Exit(_invocationId, _result);
 1387            }
 41388            return _result;
 41389        }
 1390
 1391        /// <summary>
 1392        /// Submits a Pig job to an HDInsight cluster.
 1393        /// </summary>
 1394        /// <param name='content'>
 1395        /// The content of the Pig job request.
 1396        /// </param>
 1397        /// <param name='customHeaders'>
 1398        /// Headers that will be added to request.
 1399        /// </param>
 1400        /// <param name='cancellationToken'>
 1401        /// The cancellation token.
 1402        /// </param>
 1403        /// <exception cref="JobOperationsErrorResponseException">
 1404        /// Thrown when the operation returned an invalid status code
 1405        /// </exception>
 1406        /// <exception cref="SerializationException">
 1407        /// Thrown when unable to deserialize the response
 1408        /// </exception>
 1409        /// <exception cref="ValidationException">
 1410        /// Thrown when a required parameter is null
 1411        /// </exception>
 1412        /// <exception cref="System.ArgumentNullException">
 1413        /// Thrown when a required parameter is null
 1414        /// </exception>
 1415        /// <return>
 1416        /// A response object containing the response body and response headers.
 1417        /// </return>
 1418        public async Task<AzureOperationResponse<JobSubmissionJsonResponse>> SubmitPigJobWithHttpMessagesAsync(Stream co
 1419        {
 41420            if (Client.Endpoint == null)
 1421            {
 01422                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1423            }
 41424            if (Client.Username == null)
 1425            {
 01426                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Username");
 1427            }
 41428            if (content == null)
 1429            {
 01430                throw new ValidationException(ValidationRules.CannotBeNull, "content");
 1431            }
 1432            // Tracing
 41433            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 41434            string _invocationId = null;
 41435            if (_shouldTrace)
 1436            {
 01437                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01438                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01439                tracingParameters.Add("content", content);
 01440                tracingParameters.Add("cancellationToken", cancellationToken);
 01441                ServiceClientTracing.Enter(_invocationId, this, "SubmitPigJob", tracingParameters);
 1442            }
 1443            // Construct URL
 41444            var _baseUrl = Client.BaseUri;
 41445            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "templeton/v1/pig";
 41446            _url = _url.Replace("{endpoint}", Client.Endpoint);
 41447            List<string> _queryParameters = new List<string>();
 41448            if (Client.Username != null)
 1449            {
 41450                _queryParameters.Add(string.Format("user.name={0}", System.Uri.EscapeDataString(Client.Username)));
 1451            }
 41452            if (_queryParameters.Count > 0)
 1453            {
 41454                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1455            }
 1456            // Create HTTP transport objects
 41457            var _httpRequest = new HttpRequestMessage();
 41458            HttpResponseMessage _httpResponse = null;
 41459            _httpRequest.Method = new HttpMethod("POST");
 41460            _httpRequest.RequestUri = new System.Uri(_url);
 1461            // Set Headers
 41462            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1463            {
 41464                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 1465            }
 41466            if (Client.AcceptLanguage != null)
 1467            {
 41468                if (_httpRequest.Headers.Contains("accept-language"))
 1469                {
 01470                    _httpRequest.Headers.Remove("accept-language");
 1471                }
 41472                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1473            }
 1474
 1475
 41476            if (customHeaders != null)
 1477            {
 01478                foreach(var _header in customHeaders)
 1479                {
 01480                    if (_httpRequest.Headers.Contains(_header.Key))
 1481                    {
 01482                        _httpRequest.Headers.Remove(_header.Key);
 1483                    }
 01484                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1485                }
 1486            }
 1487
 1488            // Serialize Request
 41489            string _requestContent = null;
 41490            if(content == null)
 1491            {
 01492              throw new System.ArgumentNullException("content");
 1493            }
 41494            if (content != null && content != Stream.Null)
 1495            {
 41496                _httpRequest.Content = new StreamContent(content);
 41497                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("text/plain
 1498            }
 1499            // Set Credentials
 41500            if (Client.Credentials != null)
 1501            {
 41502                cancellationToken.ThrowIfCancellationRequested();
 41503                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1504            }
 1505            // Send Request
 41506            if (_shouldTrace)
 1507            {
 01508                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1509            }
 41510            cancellationToken.ThrowIfCancellationRequested();
 41511            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 41512            if (_shouldTrace)
 1513            {
 01514                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1515            }
 41516            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 41517            cancellationToken.ThrowIfCancellationRequested();
 41518            string _responseContent = null;
 41519            if ((int)_statusCode != 200)
 1520            {
 01521                var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod
 1522                try
 1523                {
 01524                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01525                    JobOperationsErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe
 01526                    if (_errorBody != null)
 1527                    {
 01528                        ex.Body = _errorBody;
 1529                    }
 01530                }
 01531                catch (JsonException)
 1532                {
 1533                    // Ignore the exception
 01534                }
 01535                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01536                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01537                if (_shouldTrace)
 1538                {
 01539                    ServiceClientTracing.Error(_invocationId, ex);
 1540                }
 01541                _httpRequest.Dispose();
 01542                if (_httpResponse != null)
 1543                {
 01544                    _httpResponse.Dispose();
 1545                }
 01546                throw ex;
 1547            }
 1548            // Create Result
 41549            var _result = new AzureOperationResponse<JobSubmissionJsonResponse>();
 41550            _result.Request = _httpRequest;
 41551            _result.Response = _httpResponse;
 41552            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 1553            {
 01554                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 1555            }
 1556            // Deserialize Response
 41557            if ((int)_statusCode == 200)
 1558            {
 41559                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1560                try
 1561                {
 41562                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobSubmissionJsonResponse>(_resp
 41563                }
 01564                catch (JsonException ex)
 1565                {
 01566                    _httpRequest.Dispose();
 01567                    if (_httpResponse != null)
 1568                    {
 01569                        _httpResponse.Dispose();
 1570                    }
 01571                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1572                }
 1573            }
 41574            if (_shouldTrace)
 1575            {
 01576                ServiceClientTracing.Exit(_invocationId, _result);
 1577            }
 41578            return _result;
 41579        }
 1580
 1581        /// <summary>
 1582        /// Submits a Sqoop job to an HDInsight cluster.
 1583        /// </summary>
 1584        /// <param name='content'>
 1585        /// The content of the Sqoop job request.
 1586        /// </param>
 1587        /// <param name='customHeaders'>
 1588        /// Headers that will be added to request.
 1589        /// </param>
 1590        /// <param name='cancellationToken'>
 1591        /// The cancellation token.
 1592        /// </param>
 1593        /// <exception cref="JobOperationsErrorResponseException">
 1594        /// Thrown when the operation returned an invalid status code
 1595        /// </exception>
 1596        /// <exception cref="SerializationException">
 1597        /// Thrown when unable to deserialize the response
 1598        /// </exception>
 1599        /// <exception cref="ValidationException">
 1600        /// Thrown when a required parameter is null
 1601        /// </exception>
 1602        /// <exception cref="System.ArgumentNullException">
 1603        /// Thrown when a required parameter is null
 1604        /// </exception>
 1605        /// <return>
 1606        /// A response object containing the response body and response headers.
 1607        /// </return>
 1608        public async Task<AzureOperationResponse<JobSubmissionJsonResponse>> SubmitSqoopJobWithHttpMessagesAsync(Stream 
 1609        {
 41610            if (Client.Endpoint == null)
 1611            {
 01612                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1613            }
 41614            if (Client.Username == null)
 1615            {
 01616                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Username");
 1617            }
 41618            if (content == null)
 1619            {
 01620                throw new ValidationException(ValidationRules.CannotBeNull, "content");
 1621            }
 1622            // Tracing
 41623            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 41624            string _invocationId = null;
 41625            if (_shouldTrace)
 1626            {
 01627                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01628                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01629                tracingParameters.Add("content", content);
 01630                tracingParameters.Add("cancellationToken", cancellationToken);
 01631                ServiceClientTracing.Enter(_invocationId, this, "SubmitSqoopJob", tracingParameters);
 1632            }
 1633            // Construct URL
 41634            var _baseUrl = Client.BaseUri;
 41635            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "templeton/v1/sqoop";
 41636            _url = _url.Replace("{endpoint}", Client.Endpoint);
 41637            List<string> _queryParameters = new List<string>();
 41638            if (Client.Username != null)
 1639            {
 41640                _queryParameters.Add(string.Format("user.name={0}", System.Uri.EscapeDataString(Client.Username)));
 1641            }
 41642            if (_queryParameters.Count > 0)
 1643            {
 41644                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1645            }
 1646            // Create HTTP transport objects
 41647            var _httpRequest = new HttpRequestMessage();
 41648            HttpResponseMessage _httpResponse = null;
 41649            _httpRequest.Method = new HttpMethod("POST");
 41650            _httpRequest.RequestUri = new System.Uri(_url);
 1651            // Set Headers
 41652            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1653            {
 41654                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 1655            }
 41656            if (Client.AcceptLanguage != null)
 1657            {
 41658                if (_httpRequest.Headers.Contains("accept-language"))
 1659                {
 01660                    _httpRequest.Headers.Remove("accept-language");
 1661                }
 41662                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1663            }
 1664
 1665
 41666            if (customHeaders != null)
 1667            {
 01668                foreach(var _header in customHeaders)
 1669                {
 01670                    if (_httpRequest.Headers.Contains(_header.Key))
 1671                    {
 01672                        _httpRequest.Headers.Remove(_header.Key);
 1673                    }
 01674                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1675                }
 1676            }
 1677
 1678            // Serialize Request
 41679            string _requestContent = null;
 41680            if(content == null)
 1681            {
 01682              throw new System.ArgumentNullException("content");
 1683            }
 41684            if (content != null && content != Stream.Null)
 1685            {
 41686                _httpRequest.Content = new StreamContent(content);
 41687                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("text/plain
 1688            }
 1689            // Set Credentials
 41690            if (Client.Credentials != null)
 1691            {
 41692                cancellationToken.ThrowIfCancellationRequested();
 41693                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1694            }
 1695            // Send Request
 41696            if (_shouldTrace)
 1697            {
 01698                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1699            }
 41700            cancellationToken.ThrowIfCancellationRequested();
 41701            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 41702            if (_shouldTrace)
 1703            {
 01704                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1705            }
 41706            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 41707            cancellationToken.ThrowIfCancellationRequested();
 41708            string _responseContent = null;
 41709            if ((int)_statusCode != 200)
 1710            {
 01711                var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod
 1712                try
 1713                {
 01714                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01715                    JobOperationsErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe
 01716                    if (_errorBody != null)
 1717                    {
 01718                        ex.Body = _errorBody;
 1719                    }
 01720                }
 01721                catch (JsonException)
 1722                {
 1723                    // Ignore the exception
 01724                }
 01725                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01726                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01727                if (_shouldTrace)
 1728                {
 01729                    ServiceClientTracing.Error(_invocationId, ex);
 1730                }
 01731                _httpRequest.Dispose();
 01732                if (_httpResponse != null)
 1733                {
 01734                    _httpResponse.Dispose();
 1735                }
 01736                throw ex;
 1737            }
 1738            // Create Result
 41739            var _result = new AzureOperationResponse<JobSubmissionJsonResponse>();
 41740            _result.Request = _httpRequest;
 41741            _result.Response = _httpResponse;
 41742            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 1743            {
 01744                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 1745            }
 1746            // Deserialize Response
 41747            if ((int)_statusCode == 200)
 1748            {
 41749                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1750                try
 1751                {
 41752                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobSubmissionJsonResponse>(_resp
 41753                }
 01754                catch (JsonException ex)
 1755                {
 01756                    _httpRequest.Dispose();
 01757                    if (_httpResponse != null)
 1758                    {
 01759                        _httpResponse.Dispose();
 1760                    }
 01761                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1762                }
 1763            }
 41764            if (_shouldTrace)
 1765            {
 01766                ServiceClientTracing.Exit(_invocationId, _result);
 1767            }
 41768            return _result;
 41769        }
 1770
 1771        /// <summary>
 1772        /// Gets application state from the specified HDInsight cluster.
 1773        /// </summary>
 1774        /// <param name='appId'>
 1775        /// The id of the job.
 1776        /// </param>
 1777        /// <param name='customHeaders'>
 1778        /// Headers that will be added to request.
 1779        /// </param>
 1780        /// <param name='cancellationToken'>
 1781        /// The cancellation token.
 1782        /// </param>
 1783        /// <exception cref="JobOperationsErrorResponseException">
 1784        /// Thrown when the operation returned an invalid status code
 1785        /// </exception>
 1786        /// <exception cref="SerializationException">
 1787        /// Thrown when unable to deserialize the response
 1788        /// </exception>
 1789        /// <exception cref="ValidationException">
 1790        /// Thrown when a required parameter is null
 1791        /// </exception>
 1792        /// <exception cref="System.ArgumentNullException">
 1793        /// Thrown when a required parameter is null
 1794        /// </exception>
 1795        /// <return>
 1796        /// A response object containing the response body and response headers.
 1797        /// </return>
 1798        public async Task<AzureOperationResponse<AppState>> GetAppStateWithHttpMessagesAsync(string appId, Dictionary<st
 1799        {
 4061800            if (Client.Endpoint == null)
 1801            {
 01802                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1803            }
 4061804            if (appId == null)
 1805            {
 01806                throw new ValidationException(ValidationRules.CannotBeNull, "appId");
 1807            }
 1808            // Tracing
 4061809            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 4061810            string _invocationId = null;
 4061811            if (_shouldTrace)
 1812            {
 01813                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01814                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01815                tracingParameters.Add("appId", appId);
 01816                tracingParameters.Add("cancellationToken", cancellationToken);
 01817                ServiceClientTracing.Enter(_invocationId, this, "GetAppState", tracingParameters);
 1818            }
 1819            // Construct URL
 4061820            var _baseUrl = Client.BaseUri;
 4061821            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "ws/v1/cluster/apps/{appId}/state";
 4061822            _url = _url.Replace("{endpoint}", Client.Endpoint);
 4061823            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(appId));
 4061824            List<string> _queryParameters = new List<string>();
 4061825            if (_queryParameters.Count > 0)
 1826            {
 01827                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1828            }
 1829            // Create HTTP transport objects
 4061830            var _httpRequest = new HttpRequestMessage();
 4061831            HttpResponseMessage _httpResponse = null;
 4061832            _httpRequest.Method = new HttpMethod("GET");
 4061833            _httpRequest.RequestUri = new System.Uri(_url);
 1834            // Set Headers
 4061835            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1836            {
 4061837                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 1838            }
 4061839            if (Client.AcceptLanguage != null)
 1840            {
 4061841                if (_httpRequest.Headers.Contains("accept-language"))
 1842                {
 01843                    _httpRequest.Headers.Remove("accept-language");
 1844                }
 4061845                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1846            }
 1847
 1848
 4061849            if (customHeaders != null)
 1850            {
 01851                foreach(var _header in customHeaders)
 1852                {
 01853                    if (_httpRequest.Headers.Contains(_header.Key))
 1854                    {
 01855                        _httpRequest.Headers.Remove(_header.Key);
 1856                    }
 01857                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1858                }
 1859            }
 1860
 1861            // Serialize Request
 4061862            string _requestContent = null;
 1863            // Set Credentials
 4061864            if (Client.Credentials != null)
 1865            {
 4061866                cancellationToken.ThrowIfCancellationRequested();
 4061867                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1868            }
 1869            // Send Request
 4061870            if (_shouldTrace)
 1871            {
 01872                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1873            }
 4061874            cancellationToken.ThrowIfCancellationRequested();
 4061875            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 4061876            if (_shouldTrace)
 1877            {
 01878                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1879            }
 4061880            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 4061881            cancellationToken.ThrowIfCancellationRequested();
 4061882            string _responseContent = null;
 4061883            if ((int)_statusCode != 200)
 1884            {
 01885                var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod
 1886                try
 1887                {
 01888                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01889                    JobOperationsErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe
 01890                    if (_errorBody != null)
 1891                    {
 01892                        ex.Body = _errorBody;
 1893                    }
 01894                }
 01895                catch (JsonException)
 1896                {
 1897                    // Ignore the exception
 01898                }
 01899                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01900                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01901                if (_shouldTrace)
 1902                {
 01903                    ServiceClientTracing.Error(_invocationId, ex);
 1904                }
 01905                _httpRequest.Dispose();
 01906                if (_httpResponse != null)
 1907                {
 01908                    _httpResponse.Dispose();
 1909                }
 01910                throw ex;
 1911            }
 1912            // Create Result
 4061913            var _result = new AzureOperationResponse<AppState>();
 4061914            _result.Request = _httpRequest;
 4061915            _result.Response = _httpResponse;
 4061916            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 1917            {
 01918                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 1919            }
 1920            // Deserialize Response
 4061921            if ((int)_statusCode == 200)
 1922            {
 4061923                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1924                try
 1925                {
 4061926                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<AppState>(_responseContent, Clie
 4061927                }
 01928                catch (JsonException ex)
 1929                {
 01930                    _httpRequest.Dispose();
 01931                    if (_httpResponse != null)
 1932                    {
 01933                        _httpResponse.Dispose();
 1934                    }
 01935                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1936                }
 1937            }
 4061938            if (_shouldTrace)
 1939            {
 01940                ServiceClientTracing.Exit(_invocationId, _result);
 1941            }
 4061942            return _result;
 4061943        }
 1944
 1945        /// <summary>
 1946        /// List all spark batch jobs
 1947        /// </summary>
 1948        /// <param name='fromParameter'>
 1949        /// Optional param specifying which index the list should begin from.
 1950        /// </param>
 1951        /// <param name='size'>
 1952        /// Optional param specifying the size of the returned list.
 1953        /// By default it is 20 and that is the maximum.
 1954        /// </param>
 1955        /// <param name='customHeaders'>
 1956        /// Headers that will be added to request.
 1957        /// </param>
 1958        /// <param name='cancellationToken'>
 1959        /// The cancellation token.
 1960        /// </param>
 1961        /// <exception cref="CloudException">
 1962        /// Thrown when the operation returned an invalid status code
 1963        /// </exception>
 1964        /// <exception cref="SerializationException">
 1965        /// Thrown when unable to deserialize the response
 1966        /// </exception>
 1967        /// <exception cref="ValidationException">
 1968        /// Thrown when a required parameter is null
 1969        /// </exception>
 1970        /// <exception cref="System.ArgumentNullException">
 1971        /// Thrown when a required parameter is null
 1972        /// </exception>
 1973        /// <return>
 1974        /// A response object containing the response body and response headers.
 1975        /// </return>
 1976        public async Task<AzureOperationResponse<SparkBatchJobCollection>> ListSparkBatchJobWithHttpMessagesAsync(int? f
 1977        {
 101978            if (Client.Endpoint == null)
 1979            {
 01980                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1981            }
 1982            // Tracing
 101983            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 101984            string _invocationId = null;
 101985            if (_shouldTrace)
 1986            {
 01987                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01988                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01989                tracingParameters.Add("fromParameter", fromParameter);
 01990                tracingParameters.Add("size", size);
 01991                tracingParameters.Add("cancellationToken", cancellationToken);
 01992                ServiceClientTracing.Enter(_invocationId, this, "ListSparkBatchJob", tracingParameters);
 1993            }
 1994            // Construct URL
 101995            var _baseUrl = Client.BaseUri;
 101996            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/batches";
 101997            _url = _url.Replace("{endpoint}", Client.Endpoint);
 101998            List<string> _queryParameters = new List<string>();
 101999            if (fromParameter != null)
 2000            {
 22001                _queryParameters.Add(string.Format("from={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo
 2002            }
 102003            if (size != null)
 2004            {
 22005                _queryParameters.Add(string.Format("size={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo
 2006            }
 102007            if (_queryParameters.Count > 0)
 2008            {
 22009                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 2010            }
 2011            // Create HTTP transport objects
 102012            var _httpRequest = new HttpRequestMessage();
 102013            HttpResponseMessage _httpResponse = null;
 102014            _httpRequest.Method = new HttpMethod("GET");
 102015            _httpRequest.RequestUri = new System.Uri(_url);
 2016            // Set Headers
 102017            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 2018            {
 102019                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 2020            }
 102021            if (Client.AcceptLanguage != null)
 2022            {
 102023                if (_httpRequest.Headers.Contains("accept-language"))
 2024                {
 02025                    _httpRequest.Headers.Remove("accept-language");
 2026                }
 102027                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 2028            }
 2029
 2030
 102031            if (customHeaders != null)
 2032            {
 02033                foreach(var _header in customHeaders)
 2034                {
 02035                    if (_httpRequest.Headers.Contains(_header.Key))
 2036                    {
 02037                        _httpRequest.Headers.Remove(_header.Key);
 2038                    }
 02039                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2040                }
 2041            }
 2042
 2043            // Serialize Request
 102044            string _requestContent = null;
 2045            // Set Credentials
 102046            if (Client.Credentials != null)
 2047            {
 102048                cancellationToken.ThrowIfCancellationRequested();
 102049                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2050            }
 2051            // Send Request
 102052            if (_shouldTrace)
 2053            {
 02054                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2055            }
 102056            cancellationToken.ThrowIfCancellationRequested();
 102057            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 102058            if (_shouldTrace)
 2059            {
 02060                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2061            }
 102062            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 102063            cancellationToken.ThrowIfCancellationRequested();
 102064            string _responseContent = null;
 102065            if ((int)_statusCode != 200)
 2066            {
 02067                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 2068                try
 2069                {
 02070                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02071                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 02072                    if (_errorBody != null)
 2073                    {
 02074                        ex = new CloudException(_errorBody.Message);
 02075                        ex.Body = _errorBody;
 2076                    }
 02077                }
 02078                catch (JsonException)
 2079                {
 2080                    // Ignore the exception
 02081                }
 02082                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02083                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02084                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 2085                {
 02086                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 2087                }
 02088                if (_shouldTrace)
 2089                {
 02090                    ServiceClientTracing.Error(_invocationId, ex);
 2091                }
 02092                _httpRequest.Dispose();
 02093                if (_httpResponse != null)
 2094                {
 02095                    _httpResponse.Dispose();
 2096                }
 02097                throw ex;
 2098            }
 2099            // Create Result
 102100            var _result = new AzureOperationResponse<SparkBatchJobCollection>();
 102101            _result.Request = _httpRequest;
 102102            _result.Response = _httpResponse;
 102103            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 2104            {
 02105                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 2106            }
 2107            // Deserialize Response
 102108            if ((int)_statusCode == 200)
 2109            {
 102110                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2111                try
 2112                {
 102113                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkBatchJobCollection>(_respon
 102114                }
 02115                catch (JsonException ex)
 2116                {
 02117                    _httpRequest.Dispose();
 02118                    if (_httpResponse != null)
 2119                    {
 02120                        _httpResponse.Dispose();
 2121                    }
 02122                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2123                }
 2124            }
 102125            if (_shouldTrace)
 2126            {
 02127                ServiceClientTracing.Exit(_invocationId, _result);
 2128            }
 102129            return _result;
 102130        }
 2131
 2132        /// <summary>
 2133        /// Create a new spark batch job.
 2134        /// </summary>
 2135        /// <param name='sparkBatchJobRequest'>
 2136        /// Livy compatible batch job request payload.
 2137        /// </param>
 2138        /// <param name='requestedBy'>
 2139        /// Add default value for X-Requested-By in header.
 2140        /// </param>
 2141        /// <param name='customHeaders'>
 2142        /// Headers that will be added to request.
 2143        /// </param>
 2144        /// <param name='cancellationToken'>
 2145        /// The cancellation token.
 2146        /// </param>
 2147        /// <exception cref="CloudException">
 2148        /// Thrown when the operation returned an invalid status code
 2149        /// </exception>
 2150        /// <exception cref="SerializationException">
 2151        /// Thrown when unable to deserialize the response
 2152        /// </exception>
 2153        /// <exception cref="ValidationException">
 2154        /// Thrown when a required parameter is null
 2155        /// </exception>
 2156        /// <exception cref="System.ArgumentNullException">
 2157        /// Thrown when a required parameter is null
 2158        /// </exception>
 2159        /// <return>
 2160        /// A response object containing the response body and response headers.
 2161        /// </return>
 2162        public async Task<AzureOperationResponse<SparkBatchJob>> SubmitSparkBatchJobWithHttpMessagesAsync(SparkBatchJobR
 2163        {
 62164            if (Client.Endpoint == null)
 2165            {
 02166                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 2167            }
 62168            if (sparkBatchJobRequest == null)
 2169            {
 02170                throw new ValidationException(ValidationRules.CannotBeNull, "sparkBatchJobRequest");
 2171            }
 2172            // Tracing
 62173            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 62174            string _invocationId = null;
 62175            if (_shouldTrace)
 2176            {
 02177                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02178                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02179                tracingParameters.Add("requestedBy", requestedBy);
 02180                tracingParameters.Add("sparkBatchJobRequest", sparkBatchJobRequest);
 02181                tracingParameters.Add("cancellationToken", cancellationToken);
 02182                ServiceClientTracing.Enter(_invocationId, this, "SubmitSparkBatchJob", tracingParameters);
 2183            }
 2184            // Construct URL
 62185            var _baseUrl = Client.BaseUri;
 62186            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/batches";
 62187            _url = _url.Replace("{endpoint}", Client.Endpoint);
 62188            List<string> _queryParameters = new List<string>();
 62189            if (_queryParameters.Count > 0)
 2190            {
 02191                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 2192            }
 2193            // Create HTTP transport objects
 62194            var _httpRequest = new HttpRequestMessage();
 62195            HttpResponseMessage _httpResponse = null;
 62196            _httpRequest.Method = new HttpMethod("POST");
 62197            _httpRequest.RequestUri = new System.Uri(_url);
 2198            // Set Headers
 62199            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 2200            {
 62201                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 2202            }
 62203            if (requestedBy != null)
 2204            {
 62205                if (_httpRequest.Headers.Contains("X-Requested-By"))
 2206                {
 02207                    _httpRequest.Headers.Remove("X-Requested-By");
 2208                }
 62209                _httpRequest.Headers.TryAddWithoutValidation("X-Requested-By", requestedBy);
 2210            }
 62211            if (Client.AcceptLanguage != null)
 2212            {
 62213                if (_httpRequest.Headers.Contains("accept-language"))
 2214                {
 02215                    _httpRequest.Headers.Remove("accept-language");
 2216                }
 62217                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 2218            }
 2219
 2220
 62221            if (customHeaders != null)
 2222            {
 02223                foreach(var _header in customHeaders)
 2224                {
 02225                    if (_httpRequest.Headers.Contains(_header.Key))
 2226                    {
 02227                        _httpRequest.Headers.Remove(_header.Key);
 2228                    }
 02229                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2230                }
 2231            }
 2232
 2233            // Serialize Request
 62234            string _requestContent = null;
 62235            if(sparkBatchJobRequest != null)
 2236            {
 62237                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(sparkBatchJobRequest, Client.Serial
 62238                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 62239                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 2240            }
 2241            // Set Credentials
 62242            if (Client.Credentials != null)
 2243            {
 62244                cancellationToken.ThrowIfCancellationRequested();
 62245                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2246            }
 2247            // Send Request
 62248            if (_shouldTrace)
 2249            {
 02250                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2251            }
 62252            cancellationToken.ThrowIfCancellationRequested();
 62253            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 62254            if (_shouldTrace)
 2255            {
 02256                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2257            }
 62258            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 62259            cancellationToken.ThrowIfCancellationRequested();
 62260            string _responseContent = null;
 62261            if ((int)_statusCode != 201)
 2262            {
 02263                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 2264                try
 2265                {
 02266                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02267                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 02268                    if (_errorBody != null)
 2269                    {
 02270                        ex = new CloudException(_errorBody.Message);
 02271                        ex.Body = _errorBody;
 2272                    }
 02273                }
 02274                catch (JsonException)
 2275                {
 2276                    // Ignore the exception
 02277                }
 02278                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02279                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02280                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 2281                {
 02282                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 2283                }
 02284                if (_shouldTrace)
 2285                {
 02286                    ServiceClientTracing.Error(_invocationId, ex);
 2287                }
 02288                _httpRequest.Dispose();
 02289                if (_httpResponse != null)
 2290                {
 02291                    _httpResponse.Dispose();
 2292                }
 02293                throw ex;
 2294            }
 2295            // Create Result
 62296            var _result = new AzureOperationResponse<SparkBatchJob>();
 62297            _result.Request = _httpRequest;
 62298            _result.Response = _httpResponse;
 62299            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 2300            {
 02301                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 2302            }
 2303            // Deserialize Response
 62304            if ((int)_statusCode == 201)
 2305            {
 62306                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2307                try
 2308                {
 62309                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkBatchJob>(_responseContent,
 62310                }
 02311                catch (JsonException ex)
 2312                {
 02313                    _httpRequest.Dispose();
 02314                    if (_httpResponse != null)
 2315                    {
 02316                        _httpResponse.Dispose();
 2317                    }
 02318                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2319                }
 2320            }
 62321            if (_shouldTrace)
 2322            {
 02323                ServiceClientTracing.Exit(_invocationId, _result);
 2324            }
 62325            return _result;
 62326        }
 2327
 2328        /// <summary>
 2329        /// Gets a single spark batch job.
 2330        /// </summary>
 2331        /// <param name='batchId'>
 2332        /// Identifier for the batch job.
 2333        /// </param>
 2334        /// <param name='customHeaders'>
 2335        /// Headers that will be added to request.
 2336        /// </param>
 2337        /// <param name='cancellationToken'>
 2338        /// The cancellation token.
 2339        /// </param>
 2340        /// <exception cref="CloudException">
 2341        /// Thrown when the operation returned an invalid status code
 2342        /// </exception>
 2343        /// <exception cref="SerializationException">
 2344        /// Thrown when unable to deserialize the response
 2345        /// </exception>
 2346        /// <exception cref="ValidationException">
 2347        /// Thrown when a required parameter is null
 2348        /// </exception>
 2349        /// <exception cref="System.ArgumentNullException">
 2350        /// Thrown when a required parameter is null
 2351        /// </exception>
 2352        /// <return>
 2353        /// A response object containing the response body and response headers.
 2354        /// </return>
 2355        public async Task<AzureOperationResponse<SparkBatchJob>> GetSparkBatchJobWithHttpMessagesAsync(int batchId, Dict
 2356        {
 22357            if (Client.Endpoint == null)
 2358            {
 02359                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 2360            }
 2361            // Tracing
 22362            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 22363            string _invocationId = null;
 22364            if (_shouldTrace)
 2365            {
 02366                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02367                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02368                tracingParameters.Add("batchId", batchId);
 02369                tracingParameters.Add("cancellationToken", cancellationToken);
 02370                ServiceClientTracing.Enter(_invocationId, this, "GetSparkBatchJob", tracingParameters);
 2371            }
 2372            // Construct URL
 22373            var _baseUrl = Client.BaseUri;
 22374            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/batches/{batchId}";
 22375            _url = _url.Replace("{endpoint}", Client.Endpoint);
 22376            _url = _url.Replace("{batchId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObj
 22377            List<string> _queryParameters = new List<string>();
 22378            if (_queryParameters.Count > 0)
 2379            {
 02380                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 2381            }
 2382            // Create HTTP transport objects
 22383            var _httpRequest = new HttpRequestMessage();
 22384            HttpResponseMessage _httpResponse = null;
 22385            _httpRequest.Method = new HttpMethod("GET");
 22386            _httpRequest.RequestUri = new System.Uri(_url);
 2387            // Set Headers
 22388            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 2389            {
 22390                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 2391            }
 22392            if (Client.AcceptLanguage != null)
 2393            {
 22394                if (_httpRequest.Headers.Contains("accept-language"))
 2395                {
 02396                    _httpRequest.Headers.Remove("accept-language");
 2397                }
 22398                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 2399            }
 2400
 2401
 22402            if (customHeaders != null)
 2403            {
 02404                foreach(var _header in customHeaders)
 2405                {
 02406                    if (_httpRequest.Headers.Contains(_header.Key))
 2407                    {
 02408                        _httpRequest.Headers.Remove(_header.Key);
 2409                    }
 02410                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2411                }
 2412            }
 2413
 2414            // Serialize Request
 22415            string _requestContent = null;
 2416            // Set Credentials
 22417            if (Client.Credentials != null)
 2418            {
 22419                cancellationToken.ThrowIfCancellationRequested();
 22420                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2421            }
 2422            // Send Request
 22423            if (_shouldTrace)
 2424            {
 02425                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2426            }
 22427            cancellationToken.ThrowIfCancellationRequested();
 22428            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 22429            if (_shouldTrace)
 2430            {
 02431                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2432            }
 22433            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 22434            cancellationToken.ThrowIfCancellationRequested();
 22435            string _responseContent = null;
 22436            if ((int)_statusCode != 200)
 2437            {
 02438                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 2439                try
 2440                {
 02441                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02442                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 02443                    if (_errorBody != null)
 2444                    {
 02445                        ex = new CloudException(_errorBody.Message);
 02446                        ex.Body = _errorBody;
 2447                    }
 02448                }
 02449                catch (JsonException)
 2450                {
 2451                    // Ignore the exception
 02452                }
 02453                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02454                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02455                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 2456                {
 02457                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 2458                }
 02459                if (_shouldTrace)
 2460                {
 02461                    ServiceClientTracing.Error(_invocationId, ex);
 2462                }
 02463                _httpRequest.Dispose();
 02464                if (_httpResponse != null)
 2465                {
 02466                    _httpResponse.Dispose();
 2467                }
 02468                throw ex;
 2469            }
 2470            // Create Result
 22471            var _result = new AzureOperationResponse<SparkBatchJob>();
 22472            _result.Request = _httpRequest;
 22473            _result.Response = _httpResponse;
 22474            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 2475            {
 02476                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 2477            }
 2478            // Deserialize Response
 22479            if ((int)_statusCode == 200)
 2480            {
 22481                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2482                try
 2483                {
 22484                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkBatchJob>(_responseContent,
 22485                }
 02486                catch (JsonException ex)
 2487                {
 02488                    _httpRequest.Dispose();
 02489                    if (_httpResponse != null)
 2490                    {
 02491                        _httpResponse.Dispose();
 2492                    }
 02493                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2494                }
 2495            }
 22496            if (_shouldTrace)
 2497            {
 02498                ServiceClientTracing.Exit(_invocationId, _result);
 2499            }
 22500            return _result;
 22501        }
 2502
 2503        /// <summary>
 2504        /// Cancels a running spark batch job.
 2505        /// </summary>
 2506        /// <param name='batchId'>
 2507        /// Identifier for the batch job.
 2508        /// </param>
 2509        /// <param name='requestedBy'>
 2510        /// Add default value for X-Requested-By in header.
 2511        /// </param>
 2512        /// <param name='customHeaders'>
 2513        /// Headers that will be added to request.
 2514        /// </param>
 2515        /// <param name='cancellationToken'>
 2516        /// The cancellation token.
 2517        /// </param>
 2518        /// <exception cref="CloudException">
 2519        /// Thrown when the operation returned an invalid status code
 2520        /// </exception>
 2521        /// <exception cref="SerializationException">
 2522        /// Thrown when unable to deserialize the response
 2523        /// </exception>
 2524        /// <exception cref="ValidationException">
 2525        /// Thrown when a required parameter is null
 2526        /// </exception>
 2527        /// <exception cref="System.ArgumentNullException">
 2528        /// Thrown when a required parameter is null
 2529        /// </exception>
 2530        /// <return>
 2531        /// A response object containing the response body and response headers.
 2532        /// </return>
 2533        public async Task<AzureOperationResponse<SparkJobDeletedResult>> DeleteSparkBatchJobWithHttpMessagesAsync(int ba
 2534        {
 22535            if (Client.Endpoint == null)
 2536            {
 02537                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 2538            }
 2539            // Tracing
 22540            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 22541            string _invocationId = null;
 22542            if (_shouldTrace)
 2543            {
 02544                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02545                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02546                tracingParameters.Add("requestedBy", requestedBy);
 02547                tracingParameters.Add("batchId", batchId);
 02548                tracingParameters.Add("cancellationToken", cancellationToken);
 02549                ServiceClientTracing.Enter(_invocationId, this, "DeleteSparkBatchJob", tracingParameters);
 2550            }
 2551            // Construct URL
 22552            var _baseUrl = Client.BaseUri;
 22553            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/batches/{batchId}";
 22554            _url = _url.Replace("{endpoint}", Client.Endpoint);
 22555            _url = _url.Replace("{batchId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObj
 22556            List<string> _queryParameters = new List<string>();
 22557            if (_queryParameters.Count > 0)
 2558            {
 02559                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 2560            }
 2561            // Create HTTP transport objects
 22562            var _httpRequest = new HttpRequestMessage();
 22563            HttpResponseMessage _httpResponse = null;
 22564            _httpRequest.Method = new HttpMethod("DELETE");
 22565            _httpRequest.RequestUri = new System.Uri(_url);
 2566            // Set Headers
 22567            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 2568            {
 22569                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 2570            }
 22571            if (requestedBy != null)
 2572            {
 22573                if (_httpRequest.Headers.Contains("X-Requested-By"))
 2574                {
 02575                    _httpRequest.Headers.Remove("X-Requested-By");
 2576                }
 22577                _httpRequest.Headers.TryAddWithoutValidation("X-Requested-By", requestedBy);
 2578            }
 22579            if (Client.AcceptLanguage != null)
 2580            {
 22581                if (_httpRequest.Headers.Contains("accept-language"))
 2582                {
 02583                    _httpRequest.Headers.Remove("accept-language");
 2584                }
 22585                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 2586            }
 2587
 2588
 22589            if (customHeaders != null)
 2590            {
 02591                foreach(var _header in customHeaders)
 2592                {
 02593                    if (_httpRequest.Headers.Contains(_header.Key))
 2594                    {
 02595                        _httpRequest.Headers.Remove(_header.Key);
 2596                    }
 02597                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2598                }
 2599            }
 2600
 2601            // Serialize Request
 22602            string _requestContent = null;
 2603            // Set Credentials
 22604            if (Client.Credentials != null)
 2605            {
 22606                cancellationToken.ThrowIfCancellationRequested();
 22607                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2608            }
 2609            // Send Request
 22610            if (_shouldTrace)
 2611            {
 02612                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2613            }
 22614            cancellationToken.ThrowIfCancellationRequested();
 22615            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 22616            if (_shouldTrace)
 2617            {
 02618                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2619            }
 22620            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 22621            cancellationToken.ThrowIfCancellationRequested();
 22622            string _responseContent = null;
 22623            if ((int)_statusCode != 200)
 2624            {
 02625                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 2626                try
 2627                {
 02628                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02629                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 02630                    if (_errorBody != null)
 2631                    {
 02632                        ex = new CloudException(_errorBody.Message);
 02633                        ex.Body = _errorBody;
 2634                    }
 02635                }
 02636                catch (JsonException)
 2637                {
 2638                    // Ignore the exception
 02639                }
 02640                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02641                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02642                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 2643                {
 02644                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 2645                }
 02646                if (_shouldTrace)
 2647                {
 02648                    ServiceClientTracing.Error(_invocationId, ex);
 2649                }
 02650                _httpRequest.Dispose();
 02651                if (_httpResponse != null)
 2652                {
 02653                    _httpResponse.Dispose();
 2654                }
 02655                throw ex;
 2656            }
 2657            // Create Result
 22658            var _result = new AzureOperationResponse<SparkJobDeletedResult>();
 22659            _result.Request = _httpRequest;
 22660            _result.Response = _httpResponse;
 22661            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 2662            {
 02663                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 2664            }
 2665            // Deserialize Response
 22666            if ((int)_statusCode == 200)
 2667            {
 22668                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2669                try
 2670                {
 22671                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkJobDeletedResult>(_response
 22672                }
 02673                catch (JsonException ex)
 2674                {
 02675                    _httpRequest.Dispose();
 02676                    if (_httpResponse != null)
 2677                    {
 02678                        _httpResponse.Dispose();
 2679                    }
 02680                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2681                }
 2682            }
 22683            if (_shouldTrace)
 2684            {
 02685                ServiceClientTracing.Exit(_invocationId, _result);
 2686            }
 22687            return _result;
 22688        }
 2689
 2690        /// <summary>
 2691        /// Gets a single spark batch job logs.
 2692        /// </summary>
 2693        /// <param name='batchId'>
 2694        /// Identifier for the batch job.
 2695        /// </param>
 2696        /// <param name='fromParameter'>
 2697        /// Optional param specifying which index the list should begin from.
 2698        /// </param>
 2699        /// <param name='size'>
 2700        /// Optional param specifying the size of the returned list.
 2701        /// By default it is 20 and that is the maximum.
 2702        /// </param>
 2703        /// <param name='customHeaders'>
 2704        /// Headers that will be added to request.
 2705        /// </param>
 2706        /// <param name='cancellationToken'>
 2707        /// The cancellation token.
 2708        /// </param>
 2709        /// <exception cref="CloudException">
 2710        /// Thrown when the operation returned an invalid status code
 2711        /// </exception>
 2712        /// <exception cref="SerializationException">
 2713        /// Thrown when unable to deserialize the response
 2714        /// </exception>
 2715        /// <exception cref="ValidationException">
 2716        /// Thrown when a required parameter is null
 2717        /// </exception>
 2718        /// <exception cref="System.ArgumentNullException">
 2719        /// Thrown when a required parameter is null
 2720        /// </exception>
 2721        /// <return>
 2722        /// A response object containing the response body and response headers.
 2723        /// </return>
 2724        public async Task<AzureOperationResponse<SparkJobLog>> GetSparkBatchLogWithHttpMessagesAsync(int batchId, int? f
 2725        {
 02726            if (Client.Endpoint == null)
 2727            {
 02728                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 2729            }
 2730            // Tracing
 02731            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 02732            string _invocationId = null;
 02733            if (_shouldTrace)
 2734            {
 02735                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02736                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02737                tracingParameters.Add("batchId", batchId);
 02738                tracingParameters.Add("fromParameter", fromParameter);
 02739                tracingParameters.Add("size", size);
 02740                tracingParameters.Add("cancellationToken", cancellationToken);
 02741                ServiceClientTracing.Enter(_invocationId, this, "GetSparkBatchLog", tracingParameters);
 2742            }
 2743            // Construct URL
 02744            var _baseUrl = Client.BaseUri;
 02745            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/batches/{batchId}/log";
 02746            _url = _url.Replace("{endpoint}", Client.Endpoint);
 02747            _url = _url.Replace("{batchId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObj
 02748            List<string> _queryParameters = new List<string>();
 02749            if (fromParameter != null)
 2750            {
 02751                _queryParameters.Add(string.Format("from={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo
 2752            }
 02753            if (size != null)
 2754            {
 02755                _queryParameters.Add(string.Format("size={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo
 2756            }
 02757            if (_queryParameters.Count > 0)
 2758            {
 02759                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 2760            }
 2761            // Create HTTP transport objects
 02762            var _httpRequest = new HttpRequestMessage();
 02763            HttpResponseMessage _httpResponse = null;
 02764            _httpRequest.Method = new HttpMethod("GET");
 02765            _httpRequest.RequestUri = new System.Uri(_url);
 2766            // Set Headers
 02767            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 2768            {
 02769                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 2770            }
 02771            if (Client.AcceptLanguage != null)
 2772            {
 02773                if (_httpRequest.Headers.Contains("accept-language"))
 2774                {
 02775                    _httpRequest.Headers.Remove("accept-language");
 2776                }
 02777                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 2778            }
 2779
 2780
 02781            if (customHeaders != null)
 2782            {
 02783                foreach(var _header in customHeaders)
 2784                {
 02785                    if (_httpRequest.Headers.Contains(_header.Key))
 2786                    {
 02787                        _httpRequest.Headers.Remove(_header.Key);
 2788                    }
 02789                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2790                }
 2791            }
 2792
 2793            // Serialize Request
 02794            string _requestContent = null;
 2795            // Set Credentials
 02796            if (Client.Credentials != null)
 2797            {
 02798                cancellationToken.ThrowIfCancellationRequested();
 02799                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2800            }
 2801            // Send Request
 02802            if (_shouldTrace)
 2803            {
 02804                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2805            }
 02806            cancellationToken.ThrowIfCancellationRequested();
 02807            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 02808            if (_shouldTrace)
 2809            {
 02810                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2811            }
 02812            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 02813            cancellationToken.ThrowIfCancellationRequested();
 02814            string _responseContent = null;
 02815            if ((int)_statusCode != 200)
 2816            {
 02817                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 2818                try
 2819                {
 02820                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02821                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 02822                    if (_errorBody != null)
 2823                    {
 02824                        ex = new CloudException(_errorBody.Message);
 02825                        ex.Body = _errorBody;
 2826                    }
 02827                }
 02828                catch (JsonException)
 2829                {
 2830                    // Ignore the exception
 02831                }
 02832                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02833                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02834                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 2835                {
 02836                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 2837                }
 02838                if (_shouldTrace)
 2839                {
 02840                    ServiceClientTracing.Error(_invocationId, ex);
 2841                }
 02842                _httpRequest.Dispose();
 02843                if (_httpResponse != null)
 2844                {
 02845                    _httpResponse.Dispose();
 2846                }
 02847                throw ex;
 2848            }
 2849            // Create Result
 02850            var _result = new AzureOperationResponse<SparkJobLog>();
 02851            _result.Request = _httpRequest;
 02852            _result.Response = _httpResponse;
 02853            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 2854            {
 02855                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 2856            }
 2857            // Deserialize Response
 02858            if ((int)_statusCode == 200)
 2859            {
 02860                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2861                try
 2862                {
 02863                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkJobLog>(_responseContent, C
 02864                }
 02865                catch (JsonException ex)
 2866                {
 02867                    _httpRequest.Dispose();
 02868                    if (_httpResponse != null)
 2869                    {
 02870                        _httpResponse.Dispose();
 2871                    }
 02872                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2873                }
 2874            }
 02875            if (_shouldTrace)
 2876            {
 02877                ServiceClientTracing.Exit(_invocationId, _result);
 2878            }
 02879            return _result;
 02880        }
 2881
 2882        /// <summary>
 2883        /// Gets a single spark batch state.
 2884        /// </summary>
 2885        /// <param name='batchId'>
 2886        /// Identifier for the batch job.
 2887        /// </param>
 2888        /// <param name='customHeaders'>
 2889        /// Headers that will be added to request.
 2890        /// </param>
 2891        /// <param name='cancellationToken'>
 2892        /// The cancellation token.
 2893        /// </param>
 2894        /// <exception cref="CloudException">
 2895        /// Thrown when the operation returned an invalid status code
 2896        /// </exception>
 2897        /// <exception cref="SerializationException">
 2898        /// Thrown when unable to deserialize the response
 2899        /// </exception>
 2900        /// <exception cref="ValidationException">
 2901        /// Thrown when a required parameter is null
 2902        /// </exception>
 2903        /// <exception cref="System.ArgumentNullException">
 2904        /// Thrown when a required parameter is null
 2905        /// </exception>
 2906        /// <return>
 2907        /// A response object containing the response body and response headers.
 2908        /// </return>
 2909        public async Task<AzureOperationResponse<SparkJobState>> GetSparkBatchStateWithHttpMessagesAsync(int batchId, Di
 2910        {
 02911            if (Client.Endpoint == null)
 2912            {
 02913                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 2914            }
 2915            // Tracing
 02916            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 02917            string _invocationId = null;
 02918            if (_shouldTrace)
 2919            {
 02920                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02921                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02922                tracingParameters.Add("batchId", batchId);
 02923                tracingParameters.Add("cancellationToken", cancellationToken);
 02924                ServiceClientTracing.Enter(_invocationId, this, "GetSparkBatchState", tracingParameters);
 2925            }
 2926            // Construct URL
 02927            var _baseUrl = Client.BaseUri;
 02928            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/batches/{batchId}/state";
 02929            _url = _url.Replace("{endpoint}", Client.Endpoint);
 02930            _url = _url.Replace("{batchId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObj
 02931            List<string> _queryParameters = new List<string>();
 02932            if (_queryParameters.Count > 0)
 2933            {
 02934                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 2935            }
 2936            // Create HTTP transport objects
 02937            var _httpRequest = new HttpRequestMessage();
 02938            HttpResponseMessage _httpResponse = null;
 02939            _httpRequest.Method = new HttpMethod("GET");
 02940            _httpRequest.RequestUri = new System.Uri(_url);
 2941            // Set Headers
 02942            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 2943            {
 02944                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 2945            }
 02946            if (Client.AcceptLanguage != null)
 2947            {
 02948                if (_httpRequest.Headers.Contains("accept-language"))
 2949                {
 02950                    _httpRequest.Headers.Remove("accept-language");
 2951                }
 02952                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 2953            }
 2954
 2955
 02956            if (customHeaders != null)
 2957            {
 02958                foreach(var _header in customHeaders)
 2959                {
 02960                    if (_httpRequest.Headers.Contains(_header.Key))
 2961                    {
 02962                        _httpRequest.Headers.Remove(_header.Key);
 2963                    }
 02964                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2965                }
 2966            }
 2967
 2968            // Serialize Request
 02969            string _requestContent = null;
 2970            // Set Credentials
 02971            if (Client.Credentials != null)
 2972            {
 02973                cancellationToken.ThrowIfCancellationRequested();
 02974                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2975            }
 2976            // Send Request
 02977            if (_shouldTrace)
 2978            {
 02979                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2980            }
 02981            cancellationToken.ThrowIfCancellationRequested();
 02982            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 02983            if (_shouldTrace)
 2984            {
 02985                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2986            }
 02987            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 02988            cancellationToken.ThrowIfCancellationRequested();
 02989            string _responseContent = null;
 02990            if ((int)_statusCode != 200)
 2991            {
 02992                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 2993                try
 2994                {
 02995                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02996                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 02997                    if (_errorBody != null)
 2998                    {
 02999                        ex = new CloudException(_errorBody.Message);
 03000                        ex.Body = _errorBody;
 3001                    }
 03002                }
 03003                catch (JsonException)
 3004                {
 3005                    // Ignore the exception
 03006                }
 03007                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 03008                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 03009                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 3010                {
 03011                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 3012                }
 03013                if (_shouldTrace)
 3014                {
 03015                    ServiceClientTracing.Error(_invocationId, ex);
 3016                }
 03017                _httpRequest.Dispose();
 03018                if (_httpResponse != null)
 3019                {
 03020                    _httpResponse.Dispose();
 3021                }
 03022                throw ex;
 3023            }
 3024            // Create Result
 03025            var _result = new AzureOperationResponse<SparkJobState>();
 03026            _result.Request = _httpRequest;
 03027            _result.Response = _httpResponse;
 03028            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 3029            {
 03030                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 3031            }
 3032            // Deserialize Response
 03033            if ((int)_statusCode == 200)
 3034            {
 03035                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 3036                try
 3037                {
 03038                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkJobState>(_responseContent,
 03039                }
 03040                catch (JsonException ex)
 3041                {
 03042                    _httpRequest.Dispose();
 03043                    if (_httpResponse != null)
 3044                    {
 03045                        _httpResponse.Dispose();
 3046                    }
 03047                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 3048                }
 3049            }
 03050            if (_shouldTrace)
 3051            {
 03052                ServiceClientTracing.Exit(_invocationId, _result);
 3053            }
 03054            return _result;
 03055        }
 3056
 3057        /// <summary>
 3058        /// List all spark sessions.
 3059        /// </summary>
 3060        /// <param name='fromParameter'>
 3061        /// Optional param specifying which index the list should begin from.
 3062        /// </param>
 3063        /// <param name='size'>
 3064        /// Optional param specifying the size of the returned list.
 3065        /// By default it is 20 and that is the maximum.
 3066        /// </param>
 3067        /// <param name='customHeaders'>
 3068        /// Headers that will be added to request.
 3069        /// </param>
 3070        /// <param name='cancellationToken'>
 3071        /// The cancellation token.
 3072        /// </param>
 3073        /// <exception cref="CloudException">
 3074        /// Thrown when the operation returned an invalid status code
 3075        /// </exception>
 3076        /// <exception cref="SerializationException">
 3077        /// Thrown when unable to deserialize the response
 3078        /// </exception>
 3079        /// <exception cref="ValidationException">
 3080        /// Thrown when a required parameter is null
 3081        /// </exception>
 3082        /// <exception cref="System.ArgumentNullException">
 3083        /// Thrown when a required parameter is null
 3084        /// </exception>
 3085        /// <return>
 3086        /// A response object containing the response body and response headers.
 3087        /// </return>
 3088        public async Task<AzureOperationResponse<SparkSessionCollection>> ListSparkSessionJobWithHttpMessagesAsync(int? 
 3089        {
 103090            if (Client.Endpoint == null)
 3091            {
 03092                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 3093            }
 3094            // Tracing
 103095            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 103096            string _invocationId = null;
 103097            if (_shouldTrace)
 3098            {
 03099                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 03100                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 03101                tracingParameters.Add("fromParameter", fromParameter);
 03102                tracingParameters.Add("size", size);
 03103                tracingParameters.Add("cancellationToken", cancellationToken);
 03104                ServiceClientTracing.Enter(_invocationId, this, "ListSparkSessionJob", tracingParameters);
 3105            }
 3106            // Construct URL
 103107            var _baseUrl = Client.BaseUri;
 103108            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions";
 103109            _url = _url.Replace("{endpoint}", Client.Endpoint);
 103110            List<string> _queryParameters = new List<string>();
 103111            if (fromParameter != null)
 3112            {
 23113                _queryParameters.Add(string.Format("from={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo
 3114            }
 103115            if (size != null)
 3116            {
 23117                _queryParameters.Add(string.Format("size={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo
 3118            }
 103119            if (_queryParameters.Count > 0)
 3120            {
 23121                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 3122            }
 3123            // Create HTTP transport objects
 103124            var _httpRequest = new HttpRequestMessage();
 103125            HttpResponseMessage _httpResponse = null;
 103126            _httpRequest.Method = new HttpMethod("GET");
 103127            _httpRequest.RequestUri = new System.Uri(_url);
 3128            // Set Headers
 103129            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 3130            {
 103131                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 3132            }
 103133            if (Client.AcceptLanguage != null)
 3134            {
 103135                if (_httpRequest.Headers.Contains("accept-language"))
 3136                {
 03137                    _httpRequest.Headers.Remove("accept-language");
 3138                }
 103139                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 3140            }
 3141
 3142
 103143            if (customHeaders != null)
 3144            {
 03145                foreach(var _header in customHeaders)
 3146                {
 03147                    if (_httpRequest.Headers.Contains(_header.Key))
 3148                    {
 03149                        _httpRequest.Headers.Remove(_header.Key);
 3150                    }
 03151                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 3152                }
 3153            }
 3154
 3155            // Serialize Request
 103156            string _requestContent = null;
 3157            // Set Credentials
 103158            if (Client.Credentials != null)
 3159            {
 103160                cancellationToken.ThrowIfCancellationRequested();
 103161                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3162            }
 3163            // Send Request
 103164            if (_shouldTrace)
 3165            {
 03166                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 3167            }
 103168            cancellationToken.ThrowIfCancellationRequested();
 103169            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 103170            if (_shouldTrace)
 3171            {
 03172                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 3173            }
 103174            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 103175            cancellationToken.ThrowIfCancellationRequested();
 103176            string _responseContent = null;
 103177            if ((int)_statusCode != 200)
 3178            {
 03179                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 3180                try
 3181                {
 03182                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 03183                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 03184                    if (_errorBody != null)
 3185                    {
 03186                        ex = new CloudException(_errorBody.Message);
 03187                        ex.Body = _errorBody;
 3188                    }
 03189                }
 03190                catch (JsonException)
 3191                {
 3192                    // Ignore the exception
 03193                }
 03194                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 03195                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 03196                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 3197                {
 03198                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 3199                }
 03200                if (_shouldTrace)
 3201                {
 03202                    ServiceClientTracing.Error(_invocationId, ex);
 3203                }
 03204                _httpRequest.Dispose();
 03205                if (_httpResponse != null)
 3206                {
 03207                    _httpResponse.Dispose();
 3208                }
 03209                throw ex;
 3210            }
 3211            // Create Result
 103212            var _result = new AzureOperationResponse<SparkSessionCollection>();
 103213            _result.Request = _httpRequest;
 103214            _result.Response = _httpResponse;
 103215            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 3216            {
 03217                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 3218            }
 3219            // Deserialize Response
 103220            if ((int)_statusCode == 200)
 3221            {
 103222                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 3223                try
 3224                {
 103225                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkSessionCollection>(_respons
 103226                }
 03227                catch (JsonException ex)
 3228                {
 03229                    _httpRequest.Dispose();
 03230                    if (_httpResponse != null)
 3231                    {
 03232                        _httpResponse.Dispose();
 3233                    }
 03234                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 3235                }
 3236            }
 103237            if (_shouldTrace)
 3238            {
 03239                ServiceClientTracing.Exit(_invocationId, _result);
 3240            }
 103241            return _result;
 103242        }
 3243
 3244        /// <summary>
 3245        /// Create a new spark session.
 3246        /// </summary>
 3247        /// <param name='sparkSessionJobRequest'>
 3248        /// Livy compatible session job request payload.
 3249        /// </param>
 3250        /// <param name='requestedBy'>
 3251        /// Add default value for X-Requested-By in header.
 3252        /// </param>
 3253        /// <param name='customHeaders'>
 3254        /// Headers that will be added to request.
 3255        /// </param>
 3256        /// <param name='cancellationToken'>
 3257        /// The cancellation token.
 3258        /// </param>
 3259        /// <exception cref="CloudException">
 3260        /// Thrown when the operation returned an invalid status code
 3261        /// </exception>
 3262        /// <exception cref="SerializationException">
 3263        /// Thrown when unable to deserialize the response
 3264        /// </exception>
 3265        /// <exception cref="ValidationException">
 3266        /// Thrown when a required parameter is null
 3267        /// </exception>
 3268        /// <exception cref="System.ArgumentNullException">
 3269        /// Thrown when a required parameter is null
 3270        /// </exception>
 3271        /// <return>
 3272        /// A response object containing the response body and response headers.
 3273        /// </return>
 3274        public async Task<AzureOperationResponse<SparkSessionJob>> SubmitSparkSessionJobWithHttpMessagesAsync(SparkSessi
 3275        {
 83276            if (Client.Endpoint == null)
 3277            {
 03278                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 3279            }
 83280            if (sparkSessionJobRequest == null)
 3281            {
 03282                throw new ValidationException(ValidationRules.CannotBeNull, "sparkSessionJobRequest");
 3283            }
 3284            // Tracing
 83285            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 83286            string _invocationId = null;
 83287            if (_shouldTrace)
 3288            {
 03289                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 03290                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 03291                tracingParameters.Add("requestedBy", requestedBy);
 03292                tracingParameters.Add("sparkSessionJobRequest", sparkSessionJobRequest);
 03293                tracingParameters.Add("cancellationToken", cancellationToken);
 03294                ServiceClientTracing.Enter(_invocationId, this, "SubmitSparkSessionJob", tracingParameters);
 3295            }
 3296            // Construct URL
 83297            var _baseUrl = Client.BaseUri;
 83298            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions";
 83299            _url = _url.Replace("{endpoint}", Client.Endpoint);
 83300            List<string> _queryParameters = new List<string>();
 83301            if (_queryParameters.Count > 0)
 3302            {
 03303                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 3304            }
 3305            // Create HTTP transport objects
 83306            var _httpRequest = new HttpRequestMessage();
 83307            HttpResponseMessage _httpResponse = null;
 83308            _httpRequest.Method = new HttpMethod("POST");
 83309            _httpRequest.RequestUri = new System.Uri(_url);
 3310            // Set Headers
 83311            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 3312            {
 83313                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 3314            }
 83315            if (requestedBy != null)
 3316            {
 83317                if (_httpRequest.Headers.Contains("X-Requested-By"))
 3318                {
 03319                    _httpRequest.Headers.Remove("X-Requested-By");
 3320                }
 83321                _httpRequest.Headers.TryAddWithoutValidation("X-Requested-By", requestedBy);
 3322            }
 83323            if (Client.AcceptLanguage != null)
 3324            {
 83325                if (_httpRequest.Headers.Contains("accept-language"))
 3326                {
 03327                    _httpRequest.Headers.Remove("accept-language");
 3328                }
 83329                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 3330            }
 3331
 3332
 83333            if (customHeaders != null)
 3334            {
 03335                foreach(var _header in customHeaders)
 3336                {
 03337                    if (_httpRequest.Headers.Contains(_header.Key))
 3338                    {
 03339                        _httpRequest.Headers.Remove(_header.Key);
 3340                    }
 03341                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 3342                }
 3343            }
 3344
 3345            // Serialize Request
 83346            string _requestContent = null;
 83347            if(sparkSessionJobRequest != null)
 3348            {
 83349                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(sparkSessionJobRequest, Client.Seri
 83350                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 83351                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 3352            }
 3353            // Set Credentials
 83354            if (Client.Credentials != null)
 3355            {
 83356                cancellationToken.ThrowIfCancellationRequested();
 83357                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3358            }
 3359            // Send Request
 83360            if (_shouldTrace)
 3361            {
 03362                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 3363            }
 83364            cancellationToken.ThrowIfCancellationRequested();
 83365            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 83366            if (_shouldTrace)
 3367            {
 03368                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 3369            }
 83370            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 83371            cancellationToken.ThrowIfCancellationRequested();
 83372            string _responseContent = null;
 83373            if ((int)_statusCode != 201)
 3374            {
 03375                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 3376                try
 3377                {
 03378                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 03379                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 03380                    if (_errorBody != null)
 3381                    {
 03382                        ex = new CloudException(_errorBody.Message);
 03383                        ex.Body = _errorBody;
 3384                    }
 03385                }
 03386                catch (JsonException)
 3387                {
 3388                    // Ignore the exception
 03389                }
 03390                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 03391                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 03392                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 3393                {
 03394                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 3395                }
 03396                if (_shouldTrace)
 3397                {
 03398                    ServiceClientTracing.Error(_invocationId, ex);
 3399                }
 03400                _httpRequest.Dispose();
 03401                if (_httpResponse != null)
 3402                {
 03403                    _httpResponse.Dispose();
 3404                }
 03405                throw ex;
 3406            }
 3407            // Create Result
 83408            var _result = new AzureOperationResponse<SparkSessionJob>();
 83409            _result.Request = _httpRequest;
 83410            _result.Response = _httpResponse;
 83411            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 3412            {
 03413                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 3414            }
 3415            // Deserialize Response
 83416            if ((int)_statusCode == 201)
 3417            {
 83418                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 3419                try
 3420                {
 83421                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkSessionJob>(_responseConten
 83422                }
 03423                catch (JsonException ex)
 3424                {
 03425                    _httpRequest.Dispose();
 03426                    if (_httpResponse != null)
 3427                    {
 03428                        _httpResponse.Dispose();
 3429                    }
 03430                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 3431                }
 3432            }
 83433            if (_shouldTrace)
 3434            {
 03435                ServiceClientTracing.Exit(_invocationId, _result);
 3436            }
 83437            return _result;
 83438        }
 3439
 3440        /// <summary>
 3441        /// Gets a single spark session.
 3442        /// </summary>
 3443        /// <param name='sessionId'>
 3444        /// Identifier for the session.
 3445        /// </param>
 3446        /// <param name='customHeaders'>
 3447        /// Headers that will be added to request.
 3448        /// </param>
 3449        /// <param name='cancellationToken'>
 3450        /// The cancellation token.
 3451        /// </param>
 3452        /// <exception cref="CloudException">
 3453        /// Thrown when the operation returned an invalid status code
 3454        /// </exception>
 3455        /// <exception cref="SerializationException">
 3456        /// Thrown when unable to deserialize the response
 3457        /// </exception>
 3458        /// <exception cref="ValidationException">
 3459        /// Thrown when a required parameter is null
 3460        /// </exception>
 3461        /// <exception cref="System.ArgumentNullException">
 3462        /// Thrown when a required parameter is null
 3463        /// </exception>
 3464        /// <return>
 3465        /// A response object containing the response body and response headers.
 3466        /// </return>
 3467        public async Task<AzureOperationResponse<SparkSessionJob>> GetSparkSessionJobWithHttpMessagesAsync(int sessionId
 3468        {
 23469            if (Client.Endpoint == null)
 3470            {
 03471                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 3472            }
 3473            // Tracing
 23474            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 23475            string _invocationId = null;
 23476            if (_shouldTrace)
 3477            {
 03478                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 03479                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 03480                tracingParameters.Add("sessionId", sessionId);
 03481                tracingParameters.Add("cancellationToken", cancellationToken);
 03482                ServiceClientTracing.Enter(_invocationId, this, "GetSparkSessionJob", tracingParameters);
 3483            }
 3484            // Construct URL
 23485            var _baseUrl = Client.BaseUri;
 23486            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions/{sessionId}";
 23487            _url = _url.Replace("{endpoint}", Client.Endpoint);
 23488            _url = _url.Replace("{sessionId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO
 23489            List<string> _queryParameters = new List<string>();
 23490            if (_queryParameters.Count > 0)
 3491            {
 03492                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 3493            }
 3494            // Create HTTP transport objects
 23495            var _httpRequest = new HttpRequestMessage();
 23496            HttpResponseMessage _httpResponse = null;
 23497            _httpRequest.Method = new HttpMethod("GET");
 23498            _httpRequest.RequestUri = new System.Uri(_url);
 3499            // Set Headers
 23500            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 3501            {
 23502                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 3503            }
 23504            if (Client.AcceptLanguage != null)
 3505            {
 23506                if (_httpRequest.Headers.Contains("accept-language"))
 3507                {
 03508                    _httpRequest.Headers.Remove("accept-language");
 3509                }
 23510                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 3511            }
 3512
 3513
 23514            if (customHeaders != null)
 3515            {
 03516                foreach(var _header in customHeaders)
 3517                {
 03518                    if (_httpRequest.Headers.Contains(_header.Key))
 3519                    {
 03520                        _httpRequest.Headers.Remove(_header.Key);
 3521                    }
 03522                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 3523                }
 3524            }
 3525
 3526            // Serialize Request
 23527            string _requestContent = null;
 3528            // Set Credentials
 23529            if (Client.Credentials != null)
 3530            {
 23531                cancellationToken.ThrowIfCancellationRequested();
 23532                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3533            }
 3534            // Send Request
 23535            if (_shouldTrace)
 3536            {
 03537                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 3538            }
 23539            cancellationToken.ThrowIfCancellationRequested();
 23540            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 23541            if (_shouldTrace)
 3542            {
 03543                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 3544            }
 23545            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 23546            cancellationToken.ThrowIfCancellationRequested();
 23547            string _responseContent = null;
 23548            if ((int)_statusCode != 200)
 3549            {
 03550                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 3551                try
 3552                {
 03553                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 03554                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 03555                    if (_errorBody != null)
 3556                    {
 03557                        ex = new CloudException(_errorBody.Message);
 03558                        ex.Body = _errorBody;
 3559                    }
 03560                }
 03561                catch (JsonException)
 3562                {
 3563                    // Ignore the exception
 03564                }
 03565                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 03566                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 03567                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 3568                {
 03569                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 3570                }
 03571                if (_shouldTrace)
 3572                {
 03573                    ServiceClientTracing.Error(_invocationId, ex);
 3574                }
 03575                _httpRequest.Dispose();
 03576                if (_httpResponse != null)
 3577                {
 03578                    _httpResponse.Dispose();
 3579                }
 03580                throw ex;
 3581            }
 3582            // Create Result
 23583            var _result = new AzureOperationResponse<SparkSessionJob>();
 23584            _result.Request = _httpRequest;
 23585            _result.Response = _httpResponse;
 23586            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 3587            {
 03588                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 3589            }
 3590            // Deserialize Response
 23591            if ((int)_statusCode == 200)
 3592            {
 23593                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 3594                try
 3595                {
 23596                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkSessionJob>(_responseConten
 23597                }
 03598                catch (JsonException ex)
 3599                {
 03600                    _httpRequest.Dispose();
 03601                    if (_httpResponse != null)
 3602                    {
 03603                        _httpResponse.Dispose();
 3604                    }
 03605                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 3606                }
 3607            }
 23608            if (_shouldTrace)
 3609            {
 03610                ServiceClientTracing.Exit(_invocationId, _result);
 3611            }
 23612            return _result;
 23613        }
 3614
 3615        /// <summary>
 3616        /// Cancels a running spark session.
 3617        /// </summary>
 3618        /// <param name='sessionId'>
 3619        /// Identifier for the session.
 3620        /// </param>
 3621        /// <param name='requestedBy'>
 3622        /// Add default value for X-Requested-By in header.
 3623        /// </param>
 3624        /// <param name='customHeaders'>
 3625        /// Headers that will be added to request.
 3626        /// </param>
 3627        /// <param name='cancellationToken'>
 3628        /// The cancellation token.
 3629        /// </param>
 3630        /// <exception cref="CloudException">
 3631        /// Thrown when the operation returned an invalid status code
 3632        /// </exception>
 3633        /// <exception cref="SerializationException">
 3634        /// Thrown when unable to deserialize the response
 3635        /// </exception>
 3636        /// <exception cref="ValidationException">
 3637        /// Thrown when a required parameter is null
 3638        /// </exception>
 3639        /// <exception cref="System.ArgumentNullException">
 3640        /// Thrown when a required parameter is null
 3641        /// </exception>
 3642        /// <return>
 3643        /// A response object containing the response body and response headers.
 3644        /// </return>
 3645        public async Task<AzureOperationResponse<SparkJobDeletedResult>> DeleteSparkSessionJobWithHttpMessagesAsync(int 
 3646        {
 83647            if (Client.Endpoint == null)
 3648            {
 03649                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 3650            }
 3651            // Tracing
 83652            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 83653            string _invocationId = null;
 83654            if (_shouldTrace)
 3655            {
 03656                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 03657                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 03658                tracingParameters.Add("requestedBy", requestedBy);
 03659                tracingParameters.Add("sessionId", sessionId);
 03660                tracingParameters.Add("cancellationToken", cancellationToken);
 03661                ServiceClientTracing.Enter(_invocationId, this, "DeleteSparkSessionJob", tracingParameters);
 3662            }
 3663            // Construct URL
 83664            var _baseUrl = Client.BaseUri;
 83665            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions/{sessionId}";
 83666            _url = _url.Replace("{endpoint}", Client.Endpoint);
 83667            _url = _url.Replace("{sessionId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO
 83668            List<string> _queryParameters = new List<string>();
 83669            if (_queryParameters.Count > 0)
 3670            {
 03671                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 3672            }
 3673            // Create HTTP transport objects
 83674            var _httpRequest = new HttpRequestMessage();
 83675            HttpResponseMessage _httpResponse = null;
 83676            _httpRequest.Method = new HttpMethod("DELETE");
 83677            _httpRequest.RequestUri = new System.Uri(_url);
 3678            // Set Headers
 83679            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 3680            {
 83681                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 3682            }
 83683            if (requestedBy != null)
 3684            {
 83685                if (_httpRequest.Headers.Contains("X-Requested-By"))
 3686                {
 03687                    _httpRequest.Headers.Remove("X-Requested-By");
 3688                }
 83689                _httpRequest.Headers.TryAddWithoutValidation("X-Requested-By", requestedBy);
 3690            }
 83691            if (Client.AcceptLanguage != null)
 3692            {
 83693                if (_httpRequest.Headers.Contains("accept-language"))
 3694                {
 03695                    _httpRequest.Headers.Remove("accept-language");
 3696                }
 83697                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 3698            }
 3699
 3700
 83701            if (customHeaders != null)
 3702            {
 03703                foreach(var _header in customHeaders)
 3704                {
 03705                    if (_httpRequest.Headers.Contains(_header.Key))
 3706                    {
 03707                        _httpRequest.Headers.Remove(_header.Key);
 3708                    }
 03709                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 3710                }
 3711            }
 3712
 3713            // Serialize Request
 83714            string _requestContent = null;
 3715            // Set Credentials
 83716            if (Client.Credentials != null)
 3717            {
 83718                cancellationToken.ThrowIfCancellationRequested();
 83719                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3720            }
 3721            // Send Request
 83722            if (_shouldTrace)
 3723            {
 03724                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 3725            }
 83726            cancellationToken.ThrowIfCancellationRequested();
 83727            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 83728            if (_shouldTrace)
 3729            {
 03730                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 3731            }
 83732            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 83733            cancellationToken.ThrowIfCancellationRequested();
 83734            string _responseContent = null;
 83735            if ((int)_statusCode != 200)
 3736            {
 03737                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 3738                try
 3739                {
 03740                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 03741                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 03742                    if (_errorBody != null)
 3743                    {
 03744                        ex = new CloudException(_errorBody.Message);
 03745                        ex.Body = _errorBody;
 3746                    }
 03747                }
 03748                catch (JsonException)
 3749                {
 3750                    // Ignore the exception
 03751                }
 03752                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 03753                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 03754                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 3755                {
 03756                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 3757                }
 03758                if (_shouldTrace)
 3759                {
 03760                    ServiceClientTracing.Error(_invocationId, ex);
 3761                }
 03762                _httpRequest.Dispose();
 03763                if (_httpResponse != null)
 3764                {
 03765                    _httpResponse.Dispose();
 3766                }
 03767                throw ex;
 3768            }
 3769            // Create Result
 83770            var _result = new AzureOperationResponse<SparkJobDeletedResult>();
 83771            _result.Request = _httpRequest;
 83772            _result.Response = _httpResponse;
 83773            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 3774            {
 03775                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 3776            }
 3777            // Deserialize Response
 83778            if ((int)_statusCode == 200)
 3779            {
 83780                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 3781                try
 3782                {
 83783                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkJobDeletedResult>(_response
 83784                }
 03785                catch (JsonException ex)
 3786                {
 03787                    _httpRequest.Dispose();
 03788                    if (_httpResponse != null)
 3789                    {
 03790                        _httpResponse.Dispose();
 3791                    }
 03792                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 3793                }
 3794            }
 83795            if (_shouldTrace)
 3796            {
 03797                ServiceClientTracing.Exit(_invocationId, _result);
 3798            }
 83799            return _result;
 83800        }
 3801
 3802        /// <summary>
 3803        /// Gets a single spark session job logs.
 3804        /// </summary>
 3805        /// <param name='sessionId'>
 3806        /// Identifier for the session job.
 3807        /// </param>
 3808        /// <param name='fromParameter'>
 3809        /// Optional param specifying which index the list should begin from.
 3810        /// </param>
 3811        /// <param name='size'>
 3812        /// Optional param specifying the size of the returned list.
 3813        /// By default it is 20 and that is the maximum.
 3814        /// </param>
 3815        /// <param name='customHeaders'>
 3816        /// Headers that will be added to request.
 3817        /// </param>
 3818        /// <param name='cancellationToken'>
 3819        /// The cancellation token.
 3820        /// </param>
 3821        /// <exception cref="CloudException">
 3822        /// Thrown when the operation returned an invalid status code
 3823        /// </exception>
 3824        /// <exception cref="SerializationException">
 3825        /// Thrown when unable to deserialize the response
 3826        /// </exception>
 3827        /// <exception cref="ValidationException">
 3828        /// Thrown when a required parameter is null
 3829        /// </exception>
 3830        /// <exception cref="System.ArgumentNullException">
 3831        /// Thrown when a required parameter is null
 3832        /// </exception>
 3833        /// <return>
 3834        /// A response object containing the response body and response headers.
 3835        /// </return>
 3836        public async Task<AzureOperationResponse<SparkJobLog>> GetSparkSessionLogWithHttpMessagesAsync(int sessionId, in
 3837        {
 03838            if (Client.Endpoint == null)
 3839            {
 03840                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 3841            }
 3842            // Tracing
 03843            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 03844            string _invocationId = null;
 03845            if (_shouldTrace)
 3846            {
 03847                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 03848                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 03849                tracingParameters.Add("sessionId", sessionId);
 03850                tracingParameters.Add("fromParameter", fromParameter);
 03851                tracingParameters.Add("size", size);
 03852                tracingParameters.Add("cancellationToken", cancellationToken);
 03853                ServiceClientTracing.Enter(_invocationId, this, "GetSparkSessionLog", tracingParameters);
 3854            }
 3855            // Construct URL
 03856            var _baseUrl = Client.BaseUri;
 03857            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions/{sessionId}/log";
 03858            _url = _url.Replace("{endpoint}", Client.Endpoint);
 03859            _url = _url.Replace("{sessionId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO
 03860            List<string> _queryParameters = new List<string>();
 03861            if (fromParameter != null)
 3862            {
 03863                _queryParameters.Add(string.Format("from={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo
 3864            }
 03865            if (size != null)
 3866            {
 03867                _queryParameters.Add(string.Format("size={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo
 3868            }
 03869            if (_queryParameters.Count > 0)
 3870            {
 03871                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 3872            }
 3873            // Create HTTP transport objects
 03874            var _httpRequest = new HttpRequestMessage();
 03875            HttpResponseMessage _httpResponse = null;
 03876            _httpRequest.Method = new HttpMethod("GET");
 03877            _httpRequest.RequestUri = new System.Uri(_url);
 3878            // Set Headers
 03879            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 3880            {
 03881                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 3882            }
 03883            if (Client.AcceptLanguage != null)
 3884            {
 03885                if (_httpRequest.Headers.Contains("accept-language"))
 3886                {
 03887                    _httpRequest.Headers.Remove("accept-language");
 3888                }
 03889                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 3890            }
 3891
 3892
 03893            if (customHeaders != null)
 3894            {
 03895                foreach(var _header in customHeaders)
 3896                {
 03897                    if (_httpRequest.Headers.Contains(_header.Key))
 3898                    {
 03899                        _httpRequest.Headers.Remove(_header.Key);
 3900                    }
 03901                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 3902                }
 3903            }
 3904
 3905            // Serialize Request
 03906            string _requestContent = null;
 3907            // Set Credentials
 03908            if (Client.Credentials != null)
 3909            {
 03910                cancellationToken.ThrowIfCancellationRequested();
 03911                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3912            }
 3913            // Send Request
 03914            if (_shouldTrace)
 3915            {
 03916                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 3917            }
 03918            cancellationToken.ThrowIfCancellationRequested();
 03919            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 03920            if (_shouldTrace)
 3921            {
 03922                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 3923            }
 03924            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 03925            cancellationToken.ThrowIfCancellationRequested();
 03926            string _responseContent = null;
 03927            if ((int)_statusCode != 200)
 3928            {
 03929                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 3930                try
 3931                {
 03932                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 03933                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 03934                    if (_errorBody != null)
 3935                    {
 03936                        ex = new CloudException(_errorBody.Message);
 03937                        ex.Body = _errorBody;
 3938                    }
 03939                }
 03940                catch (JsonException)
 3941                {
 3942                    // Ignore the exception
 03943                }
 03944                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 03945                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 03946                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 3947                {
 03948                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 3949                }
 03950                if (_shouldTrace)
 3951                {
 03952                    ServiceClientTracing.Error(_invocationId, ex);
 3953                }
 03954                _httpRequest.Dispose();
 03955                if (_httpResponse != null)
 3956                {
 03957                    _httpResponse.Dispose();
 3958                }
 03959                throw ex;
 3960            }
 3961            // Create Result
 03962            var _result = new AzureOperationResponse<SparkJobLog>();
 03963            _result.Request = _httpRequest;
 03964            _result.Response = _httpResponse;
 03965            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 3966            {
 03967                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 3968            }
 3969            // Deserialize Response
 03970            if ((int)_statusCode == 200)
 3971            {
 03972                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 3973                try
 3974                {
 03975                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkJobLog>(_responseContent, C
 03976                }
 03977                catch (JsonException ex)
 3978                {
 03979                    _httpRequest.Dispose();
 03980                    if (_httpResponse != null)
 3981                    {
 03982                        _httpResponse.Dispose();
 3983                    }
 03984                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 3985                }
 3986            }
 03987            if (_shouldTrace)
 3988            {
 03989                ServiceClientTracing.Exit(_invocationId, _result);
 3990            }
 03991            return _result;
 03992        }
 3993
 3994        /// <summary>
 3995        /// Gets a single spark session job state.
 3996        /// </summary>
 3997        /// <param name='sessionId'>
 3998        /// Identifier for the session job.
 3999        /// </param>
 4000        /// <param name='customHeaders'>
 4001        /// Headers that will be added to request.
 4002        /// </param>
 4003        /// <param name='cancellationToken'>
 4004        /// The cancellation token.
 4005        /// </param>
 4006        /// <exception cref="CloudException">
 4007        /// Thrown when the operation returned an invalid status code
 4008        /// </exception>
 4009        /// <exception cref="SerializationException">
 4010        /// Thrown when unable to deserialize the response
 4011        /// </exception>
 4012        /// <exception cref="ValidationException">
 4013        /// Thrown when a required parameter is null
 4014        /// </exception>
 4015        /// <exception cref="System.ArgumentNullException">
 4016        /// Thrown when a required parameter is null
 4017        /// </exception>
 4018        /// <return>
 4019        /// A response object containing the response body and response headers.
 4020        /// </return>
 4021        public async Task<AzureOperationResponse<SparkJobState>> GetSparkSessionStateWithHttpMessagesAsync(int sessionId
 4022        {
 04023            if (Client.Endpoint == null)
 4024            {
 04025                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 4026            }
 4027            // Tracing
 04028            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 04029            string _invocationId = null;
 04030            if (_shouldTrace)
 4031            {
 04032                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 04033                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 04034                tracingParameters.Add("sessionId", sessionId);
 04035                tracingParameters.Add("cancellationToken", cancellationToken);
 04036                ServiceClientTracing.Enter(_invocationId, this, "GetSparkSessionState", tracingParameters);
 4037            }
 4038            // Construct URL
 04039            var _baseUrl = Client.BaseUri;
 04040            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions/{sessionId}/state";
 04041            _url = _url.Replace("{endpoint}", Client.Endpoint);
 04042            _url = _url.Replace("{sessionId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO
 04043            List<string> _queryParameters = new List<string>();
 04044            if (_queryParameters.Count > 0)
 4045            {
 04046                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 4047            }
 4048            // Create HTTP transport objects
 04049            var _httpRequest = new HttpRequestMessage();
 04050            HttpResponseMessage _httpResponse = null;
 04051            _httpRequest.Method = new HttpMethod("GET");
 04052            _httpRequest.RequestUri = new System.Uri(_url);
 4053            // Set Headers
 04054            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 4055            {
 04056                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 4057            }
 04058            if (Client.AcceptLanguage != null)
 4059            {
 04060                if (_httpRequest.Headers.Contains("accept-language"))
 4061                {
 04062                    _httpRequest.Headers.Remove("accept-language");
 4063                }
 04064                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 4065            }
 4066
 4067
 04068            if (customHeaders != null)
 4069            {
 04070                foreach(var _header in customHeaders)
 4071                {
 04072                    if (_httpRequest.Headers.Contains(_header.Key))
 4073                    {
 04074                        _httpRequest.Headers.Remove(_header.Key);
 4075                    }
 04076                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 4077                }
 4078            }
 4079
 4080            // Serialize Request
 04081            string _requestContent = null;
 4082            // Set Credentials
 04083            if (Client.Credentials != null)
 4084            {
 04085                cancellationToken.ThrowIfCancellationRequested();
 04086                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 4087            }
 4088            // Send Request
 04089            if (_shouldTrace)
 4090            {
 04091                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 4092            }
 04093            cancellationToken.ThrowIfCancellationRequested();
 04094            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 04095            if (_shouldTrace)
 4096            {
 04097                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 4098            }
 04099            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 04100            cancellationToken.ThrowIfCancellationRequested();
 04101            string _responseContent = null;
 04102            if ((int)_statusCode != 200)
 4103            {
 04104                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 4105                try
 4106                {
 04107                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 04108                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 04109                    if (_errorBody != null)
 4110                    {
 04111                        ex = new CloudException(_errorBody.Message);
 04112                        ex.Body = _errorBody;
 4113                    }
 04114                }
 04115                catch (JsonException)
 4116                {
 4117                    // Ignore the exception
 04118                }
 04119                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 04120                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 04121                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 4122                {
 04123                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 4124                }
 04125                if (_shouldTrace)
 4126                {
 04127                    ServiceClientTracing.Error(_invocationId, ex);
 4128                }
 04129                _httpRequest.Dispose();
 04130                if (_httpResponse != null)
 4131                {
 04132                    _httpResponse.Dispose();
 4133                }
 04134                throw ex;
 4135            }
 4136            // Create Result
 04137            var _result = new AzureOperationResponse<SparkJobState>();
 04138            _result.Request = _httpRequest;
 04139            _result.Response = _httpResponse;
 04140            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 4141            {
 04142                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 4143            }
 4144            // Deserialize Response
 04145            if ((int)_statusCode == 200)
 4146            {
 04147                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 4148                try
 4149                {
 04150                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkJobState>(_responseContent,
 04151                }
 04152                catch (JsonException ex)
 4153                {
 04154                    _httpRequest.Dispose();
 04155                    if (_httpResponse != null)
 4156                    {
 04157                        _httpResponse.Dispose();
 4158                    }
 04159                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 4160                }
 4161            }
 04162            if (_shouldTrace)
 4163            {
 04164                ServiceClientTracing.Exit(_invocationId, _result);
 4165            }
 04166            return _result;
 04167        }
 4168
 4169        /// <summary>
 4170        /// Gets a list of statements within a spark session.
 4171        /// </summary>
 4172        /// <param name='sessionId'>
 4173        /// Identifier for the session.
 4174        /// </param>
 4175        /// <param name='customHeaders'>
 4176        /// Headers that will be added to request.
 4177        /// </param>
 4178        /// <param name='cancellationToken'>
 4179        /// The cancellation token.
 4180        /// </param>
 4181        /// <exception cref="CloudException">
 4182        /// Thrown when the operation returned an invalid status code
 4183        /// </exception>
 4184        /// <exception cref="SerializationException">
 4185        /// Thrown when unable to deserialize the response
 4186        /// </exception>
 4187        /// <exception cref="ValidationException">
 4188        /// Thrown when a required parameter is null
 4189        /// </exception>
 4190        /// <exception cref="System.ArgumentNullException">
 4191        /// Thrown when a required parameter is null
 4192        /// </exception>
 4193        /// <return>
 4194        /// A response object containing the response body and response headers.
 4195        /// </return>
 4196        public async Task<AzureOperationResponse<SparkStatementCollection>> ListSparkStatementJobWithHttpMessagesAsync(i
 4197        {
 44198            if (Client.Endpoint == null)
 4199            {
 04200                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 4201            }
 4202            // Tracing
 44203            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 44204            string _invocationId = null;
 44205            if (_shouldTrace)
 4206            {
 04207                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 04208                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 04209                tracingParameters.Add("sessionId", sessionId);
 04210                tracingParameters.Add("cancellationToken", cancellationToken);
 04211                ServiceClientTracing.Enter(_invocationId, this, "ListSparkStatementJob", tracingParameters);
 4212            }
 4213            // Construct URL
 44214            var _baseUrl = Client.BaseUri;
 44215            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions/{sessionId}/statements";
 44216            _url = _url.Replace("{endpoint}", Client.Endpoint);
 44217            _url = _url.Replace("{sessionId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO
 44218            List<string> _queryParameters = new List<string>();
 44219            if (_queryParameters.Count > 0)
 4220            {
 04221                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 4222            }
 4223            // Create HTTP transport objects
 44224            var _httpRequest = new HttpRequestMessage();
 44225            HttpResponseMessage _httpResponse = null;
 44226            _httpRequest.Method = new HttpMethod("GET");
 44227            _httpRequest.RequestUri = new System.Uri(_url);
 4228            // Set Headers
 44229            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 4230            {
 44231                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 4232            }
 44233            if (Client.AcceptLanguage != null)
 4234            {
 44235                if (_httpRequest.Headers.Contains("accept-language"))
 4236                {
 04237                    _httpRequest.Headers.Remove("accept-language");
 4238                }
 44239                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 4240            }
 4241
 4242
 44243            if (customHeaders != null)
 4244            {
 04245                foreach(var _header in customHeaders)
 4246                {
 04247                    if (_httpRequest.Headers.Contains(_header.Key))
 4248                    {
 04249                        _httpRequest.Headers.Remove(_header.Key);
 4250                    }
 04251                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 4252                }
 4253            }
 4254
 4255            // Serialize Request
 44256            string _requestContent = null;
 4257            // Set Credentials
 44258            if (Client.Credentials != null)
 4259            {
 44260                cancellationToken.ThrowIfCancellationRequested();
 44261                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 4262            }
 4263            // Send Request
 44264            if (_shouldTrace)
 4265            {
 04266                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 4267            }
 44268            cancellationToken.ThrowIfCancellationRequested();
 44269            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 44270            if (_shouldTrace)
 4271            {
 04272                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 4273            }
 44274            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 44275            cancellationToken.ThrowIfCancellationRequested();
 44276            string _responseContent = null;
 44277            if ((int)_statusCode != 200)
 4278            {
 04279                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 4280                try
 4281                {
 04282                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 04283                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 04284                    if (_errorBody != null)
 4285                    {
 04286                        ex = new CloudException(_errorBody.Message);
 04287                        ex.Body = _errorBody;
 4288                    }
 04289                }
 04290                catch (JsonException)
 4291                {
 4292                    // Ignore the exception
 04293                }
 04294                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 04295                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 04296                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 4297                {
 04298                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 4299                }
 04300                if (_shouldTrace)
 4301                {
 04302                    ServiceClientTracing.Error(_invocationId, ex);
 4303                }
 04304                _httpRequest.Dispose();
 04305                if (_httpResponse != null)
 4306                {
 04307                    _httpResponse.Dispose();
 4308                }
 04309                throw ex;
 4310            }
 4311            // Create Result
 44312            var _result = new AzureOperationResponse<SparkStatementCollection>();
 44313            _result.Request = _httpRequest;
 44314            _result.Response = _httpResponse;
 44315            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 4316            {
 04317                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 4318            }
 4319            // Deserialize Response
 44320            if ((int)_statusCode == 200)
 4321            {
 44322                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 4323                try
 4324                {
 44325                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkStatementCollection>(_respo
 44326                }
 04327                catch (JsonException ex)
 4328                {
 04329                    _httpRequest.Dispose();
 04330                    if (_httpResponse != null)
 4331                    {
 04332                        _httpResponse.Dispose();
 4333                    }
 04334                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 4335                }
 4336            }
 44337            if (_shouldTrace)
 4338            {
 04339                ServiceClientTracing.Exit(_invocationId, _result);
 4340            }
 44341            return _result;
 44342        }
 4343
 4344        /// <summary>
 4345        /// Create a statement within a spark session.
 4346        /// </summary>
 4347        /// <param name='sessionId'>
 4348        /// Identifier for the session.
 4349        /// </param>
 4350        /// <param name='sparkStatementRequest'>
 4351        /// Livy compatible batch job request payload.
 4352        /// </param>
 4353        /// <param name='requestedBy'>
 4354        /// Add default value for X-Requested-By in header.
 4355        /// </param>
 4356        /// <param name='customHeaders'>
 4357        /// Headers that will be added to request.
 4358        /// </param>
 4359        /// <param name='cancellationToken'>
 4360        /// The cancellation token.
 4361        /// </param>
 4362        /// <exception cref="CloudException">
 4363        /// Thrown when the operation returned an invalid status code
 4364        /// </exception>
 4365        /// <exception cref="SerializationException">
 4366        /// Thrown when unable to deserialize the response
 4367        /// </exception>
 4368        /// <exception cref="ValidationException">
 4369        /// Thrown when a required parameter is null
 4370        /// </exception>
 4371        /// <exception cref="System.ArgumentNullException">
 4372        /// Thrown when a required parameter is null
 4373        /// </exception>
 4374        /// <return>
 4375        /// A response object containing the response body and response headers.
 4376        /// </return>
 4377        public async Task<AzureOperationResponse<SparkStatement>> SubmitSparkStatementJobWithHttpMessagesAsync(int sessi
 4378        {
 24379            if (Client.Endpoint == null)
 4380            {
 04381                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 4382            }
 24383            if (sparkStatementRequest == null)
 4384            {
 04385                throw new ValidationException(ValidationRules.CannotBeNull, "sparkStatementRequest");
 4386            }
 4387            // Tracing
 24388            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 24389            string _invocationId = null;
 24390            if (_shouldTrace)
 4391            {
 04392                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 04393                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 04394                tracingParameters.Add("requestedBy", requestedBy);
 04395                tracingParameters.Add("sessionId", sessionId);
 04396                tracingParameters.Add("sparkStatementRequest", sparkStatementRequest);
 04397                tracingParameters.Add("cancellationToken", cancellationToken);
 04398                ServiceClientTracing.Enter(_invocationId, this, "SubmitSparkStatementJob", tracingParameters);
 4399            }
 4400            // Construct URL
 24401            var _baseUrl = Client.BaseUri;
 24402            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions/{sessionId}/statements";
 24403            _url = _url.Replace("{endpoint}", Client.Endpoint);
 24404            _url = _url.Replace("{sessionId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO
 24405            List<string> _queryParameters = new List<string>();
 24406            if (_queryParameters.Count > 0)
 4407            {
 04408                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 4409            }
 4410            // Create HTTP transport objects
 24411            var _httpRequest = new HttpRequestMessage();
 24412            HttpResponseMessage _httpResponse = null;
 24413            _httpRequest.Method = new HttpMethod("POST");
 24414            _httpRequest.RequestUri = new System.Uri(_url);
 4415            // Set Headers
 24416            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 4417            {
 24418                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 4419            }
 24420            if (requestedBy != null)
 4421            {
 24422                if (_httpRequest.Headers.Contains("X-Requested-By"))
 4423                {
 04424                    _httpRequest.Headers.Remove("X-Requested-By");
 4425                }
 24426                _httpRequest.Headers.TryAddWithoutValidation("X-Requested-By", requestedBy);
 4427            }
 24428            if (Client.AcceptLanguage != null)
 4429            {
 24430                if (_httpRequest.Headers.Contains("accept-language"))
 4431                {
 04432                    _httpRequest.Headers.Remove("accept-language");
 4433                }
 24434                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 4435            }
 4436
 4437
 24438            if (customHeaders != null)
 4439            {
 04440                foreach(var _header in customHeaders)
 4441                {
 04442                    if (_httpRequest.Headers.Contains(_header.Key))
 4443                    {
 04444                        _httpRequest.Headers.Remove(_header.Key);
 4445                    }
 04446                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 4447                }
 4448            }
 4449
 4450            // Serialize Request
 24451            string _requestContent = null;
 24452            if(sparkStatementRequest != null)
 4453            {
 24454                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(sparkStatementRequest, Client.Seria
 24455                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 24456                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 4457            }
 4458            // Set Credentials
 24459            if (Client.Credentials != null)
 4460            {
 24461                cancellationToken.ThrowIfCancellationRequested();
 24462                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 4463            }
 4464            // Send Request
 24465            if (_shouldTrace)
 4466            {
 04467                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 4468            }
 24469            cancellationToken.ThrowIfCancellationRequested();
 24470            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 24471            if (_shouldTrace)
 4472            {
 04473                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 4474            }
 24475            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 24476            cancellationToken.ThrowIfCancellationRequested();
 24477            string _responseContent = null;
 24478            if ((int)_statusCode != 201)
 4479            {
 04480                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 4481                try
 4482                {
 04483                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 04484                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 04485                    if (_errorBody != null)
 4486                    {
 04487                        ex = new CloudException(_errorBody.Message);
 04488                        ex.Body = _errorBody;
 4489                    }
 04490                }
 04491                catch (JsonException)
 4492                {
 4493                    // Ignore the exception
 04494                }
 04495                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 04496                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 04497                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 4498                {
 04499                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 4500                }
 04501                if (_shouldTrace)
 4502                {
 04503                    ServiceClientTracing.Error(_invocationId, ex);
 4504                }
 04505                _httpRequest.Dispose();
 04506                if (_httpResponse != null)
 4507                {
 04508                    _httpResponse.Dispose();
 4509                }
 04510                throw ex;
 4511            }
 4512            // Create Result
 24513            var _result = new AzureOperationResponse<SparkStatement>();
 24514            _result.Request = _httpRequest;
 24515            _result.Response = _httpResponse;
 24516            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 4517            {
 04518                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 4519            }
 4520            // Deserialize Response
 24521            if ((int)_statusCode == 201)
 4522            {
 24523                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 4524                try
 4525                {
 24526                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkStatement>(_responseContent
 24527                }
 04528                catch (JsonException ex)
 4529                {
 04530                    _httpRequest.Dispose();
 04531                    if (_httpResponse != null)
 4532                    {
 04533                        _httpResponse.Dispose();
 4534                    }
 04535                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 4536                }
 4537            }
 24538            if (_shouldTrace)
 4539            {
 04540                ServiceClientTracing.Exit(_invocationId, _result);
 4541            }
 24542            return _result;
 24543        }
 4544
 4545        /// <summary>
 4546        /// Gets a single statement within a spark session.
 4547        /// </summary>
 4548        /// <param name='sessionId'>
 4549        /// Identifier for the session.
 4550        /// </param>
 4551        /// <param name='statementId'>
 4552        /// Identifier for the statement.
 4553        /// </param>
 4554        /// <param name='customHeaders'>
 4555        /// Headers that will be added to request.
 4556        /// </param>
 4557        /// <param name='cancellationToken'>
 4558        /// The cancellation token.
 4559        /// </param>
 4560        /// <exception cref="CloudException">
 4561        /// Thrown when the operation returned an invalid status code
 4562        /// </exception>
 4563        /// <exception cref="SerializationException">
 4564        /// Thrown when unable to deserialize the response
 4565        /// </exception>
 4566        /// <exception cref="ValidationException">
 4567        /// Thrown when a required parameter is null
 4568        /// </exception>
 4569        /// <exception cref="System.ArgumentNullException">
 4570        /// Thrown when a required parameter is null
 4571        /// </exception>
 4572        /// <return>
 4573        /// A response object containing the response body and response headers.
 4574        /// </return>
 4575        public async Task<AzureOperationResponse<SparkStatement>> GetSparkStatementJobWithHttpMessagesAsync(int sessionI
 4576        {
 04577            if (Client.Endpoint == null)
 4578            {
 04579                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 4580            }
 4581            // Tracing
 04582            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 04583            string _invocationId = null;
 04584            if (_shouldTrace)
 4585            {
 04586                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 04587                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 04588                tracingParameters.Add("sessionId", sessionId);
 04589                tracingParameters.Add("statementId", statementId);
 04590                tracingParameters.Add("cancellationToken", cancellationToken);
 04591                ServiceClientTracing.Enter(_invocationId, this, "GetSparkStatementJob", tracingParameters);
 4592            }
 4593            // Construct URL
 04594            var _baseUrl = Client.BaseUri;
 04595            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions/{sessionId}/statements/{statement
 04596            _url = _url.Replace("{endpoint}", Client.Endpoint);
 04597            _url = _url.Replace("{sessionId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO
 04598            _url = _url.Replace("{statementId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Serializ
 04599            List<string> _queryParameters = new List<string>();
 04600            if (_queryParameters.Count > 0)
 4601            {
 04602                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 4603            }
 4604            // Create HTTP transport objects
 04605            var _httpRequest = new HttpRequestMessage();
 04606            HttpResponseMessage _httpResponse = null;
 04607            _httpRequest.Method = new HttpMethod("GET");
 04608            _httpRequest.RequestUri = new System.Uri(_url);
 4609            // Set Headers
 04610            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 4611            {
 04612                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 4613            }
 04614            if (Client.AcceptLanguage != null)
 4615            {
 04616                if (_httpRequest.Headers.Contains("accept-language"))
 4617                {
 04618                    _httpRequest.Headers.Remove("accept-language");
 4619                }
 04620                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 4621            }
 4622
 4623
 04624            if (customHeaders != null)
 4625            {
 04626                foreach(var _header in customHeaders)
 4627                {
 04628                    if (_httpRequest.Headers.Contains(_header.Key))
 4629                    {
 04630                        _httpRequest.Headers.Remove(_header.Key);
 4631                    }
 04632                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 4633                }
 4634            }
 4635
 4636            // Serialize Request
 04637            string _requestContent = null;
 4638            // Set Credentials
 04639            if (Client.Credentials != null)
 4640            {
 04641                cancellationToken.ThrowIfCancellationRequested();
 04642                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 4643            }
 4644            // Send Request
 04645            if (_shouldTrace)
 4646            {
 04647                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 4648            }
 04649            cancellationToken.ThrowIfCancellationRequested();
 04650            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 04651            if (_shouldTrace)
 4652            {
 04653                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 4654            }
 04655            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 04656            cancellationToken.ThrowIfCancellationRequested();
 04657            string _responseContent = null;
 04658            if ((int)_statusCode != 200)
 4659            {
 04660                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 4661                try
 4662                {
 04663                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 04664                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 04665                    if (_errorBody != null)
 4666                    {
 04667                        ex = new CloudException(_errorBody.Message);
 04668                        ex.Body = _errorBody;
 4669                    }
 04670                }
 04671                catch (JsonException)
 4672                {
 4673                    // Ignore the exception
 04674                }
 04675                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 04676                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 04677                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 4678                {
 04679                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 4680                }
 04681                if (_shouldTrace)
 4682                {
 04683                    ServiceClientTracing.Error(_invocationId, ex);
 4684                }
 04685                _httpRequest.Dispose();
 04686                if (_httpResponse != null)
 4687                {
 04688                    _httpResponse.Dispose();
 4689                }
 04690                throw ex;
 4691            }
 4692            // Create Result
 04693            var _result = new AzureOperationResponse<SparkStatement>();
 04694            _result.Request = _httpRequest;
 04695            _result.Response = _httpResponse;
 04696            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 4697            {
 04698                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 4699            }
 4700            // Deserialize Response
 04701            if ((int)_statusCode == 200)
 4702            {
 04703                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 4704                try
 4705                {
 04706                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkStatement>(_responseContent
 04707                }
 04708                catch (JsonException ex)
 4709                {
 04710                    _httpRequest.Dispose();
 04711                    if (_httpResponse != null)
 4712                    {
 04713                        _httpResponse.Dispose();
 4714                    }
 04715                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 4716                }
 4717            }
 04718            if (_shouldTrace)
 4719            {
 04720                ServiceClientTracing.Exit(_invocationId, _result);
 4721            }
 04722            return _result;
 04723        }
 4724
 4725        /// <summary>
 4726        /// Kill a statement within a session.
 4727        /// </summary>
 4728        /// <param name='sessionId'>
 4729        /// Identifier for the session.
 4730        /// </param>
 4731        /// <param name='statementId'>
 4732        /// Identifier for the statement.
 4733        /// </param>
 4734        /// <param name='requestedBy'>
 4735        /// Add default value for X-Requested-By in header.
 4736        /// </param>
 4737        /// <param name='customHeaders'>
 4738        /// Headers that will be added to request.
 4739        /// </param>
 4740        /// <param name='cancellationToken'>
 4741        /// The cancellation token.
 4742        /// </param>
 4743        /// <exception cref="CloudException">
 4744        /// Thrown when the operation returned an invalid status code
 4745        /// </exception>
 4746        /// <exception cref="SerializationException">
 4747        /// Thrown when unable to deserialize the response
 4748        /// </exception>
 4749        /// <exception cref="ValidationException">
 4750        /// Thrown when a required parameter is null
 4751        /// </exception>
 4752        /// <exception cref="System.ArgumentNullException">
 4753        /// Thrown when a required parameter is null
 4754        /// </exception>
 4755        /// <return>
 4756        /// A response object containing the response body and response headers.
 4757        /// </return>
 4758        public async Task<AzureOperationResponse<SparkStatementCancellationResult>> DeleteSparkStatementJobWithHttpMessa
 4759        {
 24760            if (Client.Endpoint == null)
 4761            {
 04762                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 4763            }
 4764            // Tracing
 24765            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 24766            string _invocationId = null;
 24767            if (_shouldTrace)
 4768            {
 04769                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 04770                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 04771                tracingParameters.Add("requestedBy", requestedBy);
 04772                tracingParameters.Add("sessionId", sessionId);
 04773                tracingParameters.Add("statementId", statementId);
 04774                tracingParameters.Add("cancellationToken", cancellationToken);
 04775                ServiceClientTracing.Enter(_invocationId, this, "DeleteSparkStatementJob", tracingParameters);
 4776            }
 4777            // Construct URL
 24778            var _baseUrl = Client.BaseUri;
 24779            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions/{sessionId}/statements/{statement
 24780            _url = _url.Replace("{endpoint}", Client.Endpoint);
 24781            _url = _url.Replace("{sessionId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO
 24782            _url = _url.Replace("{statementId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Serializ
 24783            List<string> _queryParameters = new List<string>();
 24784            if (_queryParameters.Count > 0)
 4785            {
 04786                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 4787            }
 4788            // Create HTTP transport objects
 24789            var _httpRequest = new HttpRequestMessage();
 24790            HttpResponseMessage _httpResponse = null;
 24791            _httpRequest.Method = new HttpMethod("POST");
 24792            _httpRequest.RequestUri = new System.Uri(_url);
 4793            // Set Headers
 24794            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 4795            {
 24796                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 4797            }
 24798            if (requestedBy != null)
 4799            {
 24800                if (_httpRequest.Headers.Contains("X-Requested-By"))
 4801                {
 04802                    _httpRequest.Headers.Remove("X-Requested-By");
 4803                }
 24804                _httpRequest.Headers.TryAddWithoutValidation("X-Requested-By", requestedBy);
 4805            }
 24806            if (Client.AcceptLanguage != null)
 4807            {
 24808                if (_httpRequest.Headers.Contains("accept-language"))
 4809                {
 04810                    _httpRequest.Headers.Remove("accept-language");
 4811                }
 24812                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 4813            }
 4814
 4815
 24816            if (customHeaders != null)
 4817            {
 04818                foreach(var _header in customHeaders)
 4819                {
 04820                    if (_httpRequest.Headers.Contains(_header.Key))
 4821                    {
 04822                        _httpRequest.Headers.Remove(_header.Key);
 4823                    }
 04824                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 4825                }
 4826            }
 4827
 4828            // Serialize Request
 24829            string _requestContent = null;
 4830            // Set Credentials
 24831            if (Client.Credentials != null)
 4832            {
 24833                cancellationToken.ThrowIfCancellationRequested();
 24834                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 4835            }
 4836            // Send Request
 24837            if (_shouldTrace)
 4838            {
 04839                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 4840            }
 24841            cancellationToken.ThrowIfCancellationRequested();
 24842            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 24843            if (_shouldTrace)
 4844            {
 04845                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 4846            }
 24847            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 24848            cancellationToken.ThrowIfCancellationRequested();
 24849            string _responseContent = null;
 24850            if ((int)_statusCode != 200)
 4851            {
 04852                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 4853                try
 4854                {
 04855                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 04856                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 04857                    if (_errorBody != null)
 4858                    {
 04859                        ex = new CloudException(_errorBody.Message);
 04860                        ex.Body = _errorBody;
 4861                    }
 04862                }
 04863                catch (JsonException)
 4864                {
 4865                    // Ignore the exception
 04866                }
 04867                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 04868                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 04869                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 4870                {
 04871                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 4872                }
 04873                if (_shouldTrace)
 4874                {
 04875                    ServiceClientTracing.Error(_invocationId, ex);
 4876                }
 04877                _httpRequest.Dispose();
 04878                if (_httpResponse != null)
 4879                {
 04880                    _httpResponse.Dispose();
 4881                }
 04882                throw ex;
 4883            }
 4884            // Create Result
 24885            var _result = new AzureOperationResponse<SparkStatementCancellationResult>();
 24886            _result.Request = _httpRequest;
 24887            _result.Response = _httpResponse;
 24888            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 4889            {
 04890                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 4891            }
 4892            // Deserialize Response
 24893            if ((int)_statusCode == 200)
 4894            {
 24895                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 4896                try
 4897                {
 24898                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkStatementCancellationResult
 24899                }
 04900                catch (JsonException ex)
 4901                {
 04902                    _httpRequest.Dispose();
 04903                    if (_httpResponse != null)
 4904                    {
 04905                        _httpResponse.Dispose();
 4906                    }
 04907                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 4908                }
 4909            }
 24910            if (_shouldTrace)
 4911            {
 04912                ServiceClientTracing.Exit(_invocationId, _result);
 4913            }
 24914            return _result;
 24915        }
 4916
 4917    }
 4918}

Methods/Properties

.cctor()
SubmitHiveJobWithHttpMessagesAsync()
SubmitMapReduceJobWithHttpMessagesAsync()
SubmitMapReduceStreamingJobWithHttpMessagesAsync()
SubmitPigJobWithHttpMessagesAsync()
SubmitSqoopJobWithHttpMessagesAsync()
GetJobOutputAsync()
GetJobErrorLogsAsync()
WaitForJobCompletionWithHttpMessagesAsync()
GetJobStatusDirectory()
GetStatusFolder(...)
GetAppIdFromJobId(...)
IsTransientError(...)
LogMessages(...)
.ctor(...)
get_Client()
GetWithHttpMessagesAsync()
KillWithHttpMessagesAsync()
ListWithHttpMessagesAsync()
ListAfterJobIdWithHttpMessagesAsync()
SubmitHiveJobWithHttpMessagesAsync()
SubmitMapReduceJobWithHttpMessagesAsync()
SubmitMapReduceStreamingJobWithHttpMessagesAsync()
SubmitPigJobWithHttpMessagesAsync()
SubmitSqoopJobWithHttpMessagesAsync()
GetAppStateWithHttpMessagesAsync()
ListSparkBatchJobWithHttpMessagesAsync()
SubmitSparkBatchJobWithHttpMessagesAsync()
GetSparkBatchJobWithHttpMessagesAsync()
DeleteSparkBatchJobWithHttpMessagesAsync()
GetSparkBatchLogWithHttpMessagesAsync()
GetSparkBatchStateWithHttpMessagesAsync()
ListSparkSessionJobWithHttpMessagesAsync()
SubmitSparkSessionJobWithHttpMessagesAsync()
GetSparkSessionJobWithHttpMessagesAsync()
DeleteSparkSessionJobWithHttpMessagesAsync()
GetSparkSessionLogWithHttpMessagesAsync()
GetSparkSessionStateWithHttpMessagesAsync()
ListSparkStatementJobWithHttpMessagesAsync()
SubmitSparkStatementJobWithHttpMessagesAsync()
GetSparkStatementJobWithHttpMessagesAsync()
DeleteSparkStatementJobWithHttpMessagesAsync()