| | 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 | |
|
| | 11 | | namespace 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> |
| 58 | 40 | | internal JobOperations(HDInsightJobClient client) |
| | 41 | | { |
| 58 | 42 | | if (client == null) |
| | 43 | | { |
| 0 | 44 | | throw new System.ArgumentNullException("client"); |
| | 45 | | } |
| 58 | 46 | | Client = client; |
| 58 | 47 | | } |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Gets a reference to the HDInsightJobClient |
| | 51 | | /// </summary> |
| 6526 | 52 | | 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 | | { |
| 30 | 83 | | if (Client.Endpoint == null) |
| | 84 | | { |
| 0 | 85 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 86 | | } |
| 30 | 87 | | if (Client.Username == null) |
| | 88 | | { |
| 0 | 89 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Username"); |
| | 90 | | } |
| 30 | 91 | | if (jobId == null) |
| | 92 | | { |
| 0 | 93 | | throw new ValidationException(ValidationRules.CannotBeNull, "jobId"); |
| | 94 | | } |
| 30 | 95 | | string fields = "*"; |
| | 96 | | // Tracing |
| 30 | 97 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 30 | 98 | | string _invocationId = null; |
| 30 | 99 | | if (_shouldTrace) |
| | 100 | | { |
| 0 | 101 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 102 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 103 | | tracingParameters.Add("jobId", jobId); |
| 0 | 104 | | tracingParameters.Add("fields", fields); |
| 0 | 105 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 106 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 107 | | } |
| | 108 | | // Construct URL |
| 30 | 109 | | var _baseUrl = Client.BaseUri; |
| 30 | 110 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "templeton/v1/jobs/{jobId}"; |
| 30 | 111 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 30 | 112 | | _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId)); |
| 30 | 113 | | List<string> _queryParameters = new List<string>(); |
| 30 | 114 | | if (Client.Username != null) |
| | 115 | | { |
| 30 | 116 | | _queryParameters.Add(string.Format("user.name={0}", System.Uri.EscapeDataString(Client.Username))); |
| | 117 | | } |
| 30 | 118 | | if (fields != null) |
| | 119 | | { |
| 30 | 120 | | _queryParameters.Add(string.Format("fields={0}", System.Uri.EscapeDataString(fields))); |
| | 121 | | } |
| 30 | 122 | | if (_queryParameters.Count > 0) |
| | 123 | | { |
| 30 | 124 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 125 | | } |
| | 126 | | // Create HTTP transport objects |
| 30 | 127 | | var _httpRequest = new HttpRequestMessage(); |
| 30 | 128 | | HttpResponseMessage _httpResponse = null; |
| 30 | 129 | | _httpRequest.Method = new HttpMethod("GET"); |
| 30 | 130 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 131 | | // Set Headers |
| 30 | 132 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 133 | | { |
| 30 | 134 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 135 | | } |
| 30 | 136 | | if (Client.AcceptLanguage != null) |
| | 137 | | { |
| 30 | 138 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 139 | | { |
| 0 | 140 | | _httpRequest.Headers.Remove("accept-language"); |
| | 141 | | } |
| 30 | 142 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 143 | | } |
| | 144 | |
|
| | 145 | |
|
| 30 | 146 | | if (customHeaders != null) |
| | 147 | | { |
| 0 | 148 | | foreach(var _header in customHeaders) |
| | 149 | | { |
| 0 | 150 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 151 | | { |
| 0 | 152 | | _httpRequest.Headers.Remove(_header.Key); |
| | 153 | | } |
| 0 | 154 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 155 | | } |
| | 156 | | } |
| | 157 | |
|
| | 158 | | // Serialize Request |
| 30 | 159 | | string _requestContent = null; |
| | 160 | | // Set Credentials |
| 30 | 161 | | if (Client.Credentials != null) |
| | 162 | | { |
| 30 | 163 | | cancellationToken.ThrowIfCancellationRequested(); |
| 30 | 164 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 165 | | } |
| | 166 | | // Send Request |
| 30 | 167 | | if (_shouldTrace) |
| | 168 | | { |
| 0 | 169 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 170 | | } |
| 30 | 171 | | cancellationToken.ThrowIfCancellationRequested(); |
| 30 | 172 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 30 | 173 | | if (_shouldTrace) |
| | 174 | | { |
| 0 | 175 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 176 | | } |
| 30 | 177 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 30 | 178 | | cancellationToken.ThrowIfCancellationRequested(); |
| 30 | 179 | | string _responseContent = null; |
| 30 | 180 | | if ((int)_statusCode != 200) |
| | 181 | | { |
| 2 | 182 | | var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod |
| | 183 | | try |
| | 184 | | { |
| 2 | 185 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 2 | 186 | | JobOperationsErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe |
| 2 | 187 | | if (_errorBody != null) |
| | 188 | | { |
| 2 | 189 | | ex.Body = _errorBody; |
| | 190 | | } |
| 2 | 191 | | } |
| 0 | 192 | | catch (JsonException) |
| | 193 | | { |
| | 194 | | // Ignore the exception |
| 0 | 195 | | } |
| 2 | 196 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 2 | 197 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 2 | 198 | | if (_shouldTrace) |
| | 199 | | { |
| 0 | 200 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 201 | | } |
| 2 | 202 | | _httpRequest.Dispose(); |
| 2 | 203 | | if (_httpResponse != null) |
| | 204 | | { |
| 2 | 205 | | _httpResponse.Dispose(); |
| | 206 | | } |
| 2 | 207 | | throw ex; |
| | 208 | | } |
| | 209 | | // Create Result |
| 28 | 210 | | var _result = new AzureOperationResponse<JobDetailRootJsonObject>(); |
| 28 | 211 | | _result.Request = _httpRequest; |
| 28 | 212 | | _result.Response = _httpResponse; |
| 28 | 213 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 214 | | { |
| 0 | 215 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 216 | | } |
| | 217 | | // Deserialize Response |
| 28 | 218 | | if ((int)_statusCode == 200) |
| | 219 | | { |
| 28 | 220 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 221 | | try |
| | 222 | | { |
| 28 | 223 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobDetailRootJsonObject>(_respon |
| 28 | 224 | | } |
| 0 | 225 | | catch (JsonException ex) |
| | 226 | | { |
| 0 | 227 | | _httpRequest.Dispose(); |
| 0 | 228 | | if (_httpResponse != null) |
| | 229 | | { |
| 0 | 230 | | _httpResponse.Dispose(); |
| | 231 | | } |
| 0 | 232 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 233 | | } |
| | 234 | | } |
| 28 | 235 | | if (_shouldTrace) |
| | 236 | | { |
| 0 | 237 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 238 | | } |
| 28 | 239 | | return _result; |
| 28 | 240 | | } |
| | 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 | | { |
| 4 | 271 | | if (Client.Endpoint == null) |
| | 272 | | { |
| 0 | 273 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 274 | | } |
| 4 | 275 | | if (Client.Username == null) |
| | 276 | | { |
| 0 | 277 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Username"); |
| | 278 | | } |
| 4 | 279 | | if (jobId == null) |
| | 280 | | { |
| 0 | 281 | | throw new ValidationException(ValidationRules.CannotBeNull, "jobId"); |
| | 282 | | } |
| 4 | 283 | | if (jobId != null) |
| | 284 | | { |
| 4 | 285 | | if (jobId.Length < 1) |
| | 286 | | { |
| 2 | 287 | | throw new ValidationException(ValidationRules.MinLength, "jobId", 1); |
| | 288 | | } |
| | 289 | | } |
| | 290 | | // Tracing |
| 2 | 291 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 292 | | string _invocationId = null; |
| 2 | 293 | | if (_shouldTrace) |
| | 294 | | { |
| 0 | 295 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 296 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 297 | | tracingParameters.Add("jobId", jobId); |
| 0 | 298 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 299 | | ServiceClientTracing.Enter(_invocationId, this, "Kill", tracingParameters); |
| | 300 | | } |
| | 301 | | // Construct URL |
| 2 | 302 | | var _baseUrl = Client.BaseUri; |
| 2 | 303 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "templeton/v1/jobs/{jobId}"; |
| 2 | 304 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 2 | 305 | | _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId)); |
| 2 | 306 | | List<string> _queryParameters = new List<string>(); |
| 2 | 307 | | if (Client.Username != null) |
| | 308 | | { |
| 2 | 309 | | _queryParameters.Add(string.Format("user.name={0}", System.Uri.EscapeDataString(Client.Username))); |
| | 310 | | } |
| 2 | 311 | | if (_queryParameters.Count > 0) |
| | 312 | | { |
| 2 | 313 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 314 | | } |
| | 315 | | // Create HTTP transport objects |
| 2 | 316 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 317 | | HttpResponseMessage _httpResponse = null; |
| 2 | 318 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 2 | 319 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 320 | | // Set Headers |
| 2 | 321 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 322 | | { |
| 2 | 323 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 324 | | } |
| 2 | 325 | | if (Client.AcceptLanguage != null) |
| | 326 | | { |
| 2 | 327 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 328 | | { |
| 0 | 329 | | _httpRequest.Headers.Remove("accept-language"); |
| | 330 | | } |
| 2 | 331 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 332 | | } |
| | 333 | |
|
| | 334 | |
|
| 2 | 335 | | if (customHeaders != null) |
| | 336 | | { |
| 0 | 337 | | foreach(var _header in customHeaders) |
| | 338 | | { |
| 0 | 339 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 340 | | { |
| 0 | 341 | | _httpRequest.Headers.Remove(_header.Key); |
| | 342 | | } |
| 0 | 343 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 344 | | } |
| | 345 | | } |
| | 346 | |
|
| | 347 | | // Serialize Request |
| 2 | 348 | | string _requestContent = null; |
| | 349 | | // Set Credentials |
| 2 | 350 | | if (Client.Credentials != null) |
| | 351 | | { |
| 2 | 352 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 353 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 354 | | } |
| | 355 | | // Send Request |
| 2 | 356 | | if (_shouldTrace) |
| | 357 | | { |
| 0 | 358 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 359 | | } |
| 2 | 360 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 361 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 362 | | if (_shouldTrace) |
| | 363 | | { |
| 0 | 364 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 365 | | } |
| 2 | 366 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 367 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 368 | | string _responseContent = null; |
| 2 | 369 | | if ((int)_statusCode != 200) |
| | 370 | | { |
| 0 | 371 | | var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod |
| | 372 | | try |
| | 373 | | { |
| 0 | 374 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 375 | | JobOperationsErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe |
| 0 | 376 | | if (_errorBody != null) |
| | 377 | | { |
| 0 | 378 | | ex.Body = _errorBody; |
| | 379 | | } |
| 0 | 380 | | } |
| 0 | 381 | | catch (JsonException) |
| | 382 | | { |
| | 383 | | // Ignore the exception |
| 0 | 384 | | } |
| 0 | 385 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 386 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 387 | | if (_shouldTrace) |
| | 388 | | { |
| 0 | 389 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 390 | | } |
| 0 | 391 | | _httpRequest.Dispose(); |
| 0 | 392 | | if (_httpResponse != null) |
| | 393 | | { |
| 0 | 394 | | _httpResponse.Dispose(); |
| | 395 | | } |
| 0 | 396 | | throw ex; |
| | 397 | | } |
| | 398 | | // Create Result |
| 2 | 399 | | var _result = new AzureOperationResponse<JobDetailRootJsonObject>(); |
| 2 | 400 | | _result.Request = _httpRequest; |
| 2 | 401 | | _result.Response = _httpResponse; |
| 2 | 402 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 403 | | { |
| 0 | 404 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 405 | | } |
| | 406 | | // Deserialize Response |
| 2 | 407 | | if ((int)_statusCode == 200) |
| | 408 | | { |
| 2 | 409 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 410 | | try |
| | 411 | | { |
| 2 | 412 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobDetailRootJsonObject>(_respon |
| 2 | 413 | | } |
| 0 | 414 | | catch (JsonException ex) |
| | 415 | | { |
| 0 | 416 | | _httpRequest.Dispose(); |
| 0 | 417 | | if (_httpResponse != null) |
| | 418 | | { |
| 0 | 419 | | _httpResponse.Dispose(); |
| | 420 | | } |
| 0 | 421 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 422 | | } |
| | 423 | | } |
| 2 | 424 | | if (_shouldTrace) |
| | 425 | | { |
| 0 | 426 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 427 | | } |
| 2 | 428 | | return _result; |
| 2 | 429 | | } |
| | 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 | | { |
| 6 | 457 | | if (Client.Endpoint == null) |
| | 458 | | { |
| 0 | 459 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 460 | | } |
| 6 | 461 | | if (Client.Username == null) |
| | 462 | | { |
| 0 | 463 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Username"); |
| | 464 | | } |
| 6 | 465 | | string showall = "true"; |
| 6 | 466 | | string fields = "*"; |
| | 467 | | // Tracing |
| 6 | 468 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 6 | 469 | | string _invocationId = null; |
| 6 | 470 | | if (_shouldTrace) |
| | 471 | | { |
| 0 | 472 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 473 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 474 | | tracingParameters.Add("showall", showall); |
| 0 | 475 | | tracingParameters.Add("fields", fields); |
| 0 | 476 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 477 | | ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters); |
| | 478 | | } |
| | 479 | | // Construct URL |
| 6 | 480 | | var _baseUrl = Client.BaseUri; |
| 6 | 481 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "templeton/v1/jobs"; |
| 6 | 482 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 6 | 483 | | List<string> _queryParameters = new List<string>(); |
| 6 | 484 | | if (Client.Username != null) |
| | 485 | | { |
| 6 | 486 | | _queryParameters.Add(string.Format("user.name={0}", System.Uri.EscapeDataString(Client.Username))); |
| | 487 | | } |
| 6 | 488 | | if (showall != null) |
| | 489 | | { |
| 6 | 490 | | _queryParameters.Add(string.Format("showall={0}", System.Uri.EscapeDataString(showall))); |
| | 491 | | } |
| 6 | 492 | | if (fields != null) |
| | 493 | | { |
| 6 | 494 | | _queryParameters.Add(string.Format("fields={0}", System.Uri.EscapeDataString(fields))); |
| | 495 | | } |
| 6 | 496 | | if (_queryParameters.Count > 0) |
| | 497 | | { |
| 6 | 498 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 499 | | } |
| | 500 | | // Create HTTP transport objects |
| 6 | 501 | | var _httpRequest = new HttpRequestMessage(); |
| 6 | 502 | | HttpResponseMessage _httpResponse = null; |
| 6 | 503 | | _httpRequest.Method = new HttpMethod("GET"); |
| 6 | 504 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 505 | | // Set Headers |
| 6 | 506 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 507 | | { |
| 6 | 508 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 509 | | } |
| 6 | 510 | | if (Client.AcceptLanguage != null) |
| | 511 | | { |
| 6 | 512 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 513 | | { |
| 0 | 514 | | _httpRequest.Headers.Remove("accept-language"); |
| | 515 | | } |
| 6 | 516 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 517 | | } |
| | 518 | |
|
| | 519 | |
|
| 6 | 520 | | if (customHeaders != null) |
| | 521 | | { |
| 0 | 522 | | foreach(var _header in customHeaders) |
| | 523 | | { |
| 0 | 524 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 525 | | { |
| 0 | 526 | | _httpRequest.Headers.Remove(_header.Key); |
| | 527 | | } |
| 0 | 528 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 529 | | } |
| | 530 | | } |
| | 531 | |
|
| | 532 | | // Serialize Request |
| 6 | 533 | | string _requestContent = null; |
| | 534 | | // Set Credentials |
| 6 | 535 | | if (Client.Credentials != null) |
| | 536 | | { |
| 6 | 537 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 538 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 539 | | } |
| | 540 | | // Send Request |
| 6 | 541 | | if (_shouldTrace) |
| | 542 | | { |
| 0 | 543 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 544 | | } |
| 6 | 545 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 546 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 6 | 547 | | if (_shouldTrace) |
| | 548 | | { |
| 0 | 549 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 550 | | } |
| 6 | 551 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 6 | 552 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 553 | | string _responseContent = null; |
| 6 | 554 | | if ((int)_statusCode != 200) |
| | 555 | | { |
| 0 | 556 | | var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod |
| | 557 | | try |
| | 558 | | { |
| 0 | 559 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 560 | | JobOperationsErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe |
| 0 | 561 | | if (_errorBody != null) |
| | 562 | | { |
| 0 | 563 | | ex.Body = _errorBody; |
| | 564 | | } |
| 0 | 565 | | } |
| 0 | 566 | | catch (JsonException) |
| | 567 | | { |
| | 568 | | // Ignore the exception |
| 0 | 569 | | } |
| 0 | 570 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 571 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 572 | | if (_shouldTrace) |
| | 573 | | { |
| 0 | 574 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 575 | | } |
| 0 | 576 | | _httpRequest.Dispose(); |
| 0 | 577 | | if (_httpResponse != null) |
| | 578 | | { |
| 0 | 579 | | _httpResponse.Dispose(); |
| | 580 | | } |
| 0 | 581 | | throw ex; |
| | 582 | | } |
| | 583 | | // Create Result |
| 6 | 584 | | var _result = new AzureOperationResponse<IList<JobListJsonObject>>(); |
| 6 | 585 | | _result.Request = _httpRequest; |
| 6 | 586 | | _result.Response = _httpResponse; |
| 6 | 587 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 588 | | { |
| 0 | 589 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 590 | | } |
| | 591 | | // Deserialize Response |
| 6 | 592 | | if ((int)_statusCode == 200) |
| | 593 | | { |
| 6 | 594 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 595 | | try |
| | 596 | | { |
| 6 | 597 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<JobListJsonObject>>(_respo |
| 6 | 598 | | } |
| 0 | 599 | | catch (JsonException ex) |
| | 600 | | { |
| 0 | 601 | | _httpRequest.Dispose(); |
| 0 | 602 | | if (_httpResponse != null) |
| | 603 | | { |
| 0 | 604 | | _httpResponse.Dispose(); |
| | 605 | | } |
| 0 | 606 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 607 | | } |
| | 608 | | } |
| 6 | 609 | | if (_shouldTrace) |
| | 610 | | { |
| 0 | 611 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 612 | | } |
| 6 | 613 | | return _result; |
| 6 | 614 | | } |
| | 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 | | { |
| 18 | 648 | | if (Client.Endpoint == null) |
| | 649 | | { |
| 0 | 650 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 651 | | } |
| 18 | 652 | | if (Client.Username == null) |
| | 653 | | { |
| 0 | 654 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Username"); |
| | 655 | | } |
| 18 | 656 | | if (numrecords < 1) |
| | 657 | | { |
| 0 | 658 | | throw new ValidationException(ValidationRules.InclusiveMinimum, "numrecords", 1); |
| | 659 | | } |
| 18 | 660 | | string showall = "true"; |
| 18 | 661 | | string fields = "*"; |
| | 662 | | // Tracing |
| 18 | 663 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 18 | 664 | | string _invocationId = null; |
| 18 | 665 | | if (_shouldTrace) |
| | 666 | | { |
| 0 | 667 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 668 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 669 | | tracingParameters.Add("jobid", jobid); |
| 0 | 670 | | tracingParameters.Add("numrecords", numrecords); |
| 0 | 671 | | tracingParameters.Add("showall", showall); |
| 0 | 672 | | tracingParameters.Add("fields", fields); |
| 0 | 673 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 674 | | ServiceClientTracing.Enter(_invocationId, this, "ListAfterJobId", tracingParameters); |
| | 675 | | } |
| | 676 | | // Construct URL |
| 18 | 677 | | var _baseUrl = Client.BaseUri; |
| 18 | 678 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "templeton/v1/jobs"; |
| 18 | 679 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 18 | 680 | | List<string> _queryParameters = new List<string>(); |
| 18 | 681 | | if (Client.Username != null) |
| | 682 | | { |
| 18 | 683 | | _queryParameters.Add(string.Format("user.name={0}", System.Uri.EscapeDataString(Client.Username))); |
| | 684 | | } |
| 18 | 685 | | if (jobid != null) |
| | 686 | | { |
| 18 | 687 | | _queryParameters.Add(string.Format("jobid={0}", System.Uri.EscapeDataString(jobid))); |
| | 688 | | } |
| 18 | 689 | | if (numrecords != null) |
| | 690 | | { |
| 18 | 691 | | _queryParameters.Add(string.Format("numrecords={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe |
| | 692 | | } |
| 18 | 693 | | if (showall != null) |
| | 694 | | { |
| 18 | 695 | | _queryParameters.Add(string.Format("showall={0}", System.Uri.EscapeDataString(showall))); |
| | 696 | | } |
| 18 | 697 | | if (fields != null) |
| | 698 | | { |
| 18 | 699 | | _queryParameters.Add(string.Format("fields={0}", System.Uri.EscapeDataString(fields))); |
| | 700 | | } |
| 18 | 701 | | if (_queryParameters.Count > 0) |
| | 702 | | { |
| 18 | 703 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 704 | | } |
| | 705 | | // Create HTTP transport objects |
| 18 | 706 | | var _httpRequest = new HttpRequestMessage(); |
| 18 | 707 | | HttpResponseMessage _httpResponse = null; |
| 18 | 708 | | _httpRequest.Method = new HttpMethod("GET"); |
| 18 | 709 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 710 | | // Set Headers |
| 18 | 711 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 712 | | { |
| 18 | 713 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 714 | | } |
| 18 | 715 | | if (Client.AcceptLanguage != null) |
| | 716 | | { |
| 18 | 717 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 718 | | { |
| 0 | 719 | | _httpRequest.Headers.Remove("accept-language"); |
| | 720 | | } |
| 18 | 721 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 722 | | } |
| | 723 | |
|
| | 724 | |
|
| 18 | 725 | | if (customHeaders != null) |
| | 726 | | { |
| 0 | 727 | | foreach(var _header in customHeaders) |
| | 728 | | { |
| 0 | 729 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 730 | | { |
| 0 | 731 | | _httpRequest.Headers.Remove(_header.Key); |
| | 732 | | } |
| 0 | 733 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 734 | | } |
| | 735 | | } |
| | 736 | |
|
| | 737 | | // Serialize Request |
| 18 | 738 | | string _requestContent = null; |
| | 739 | | // Set Credentials |
| 18 | 740 | | if (Client.Credentials != null) |
| | 741 | | { |
| 18 | 742 | | cancellationToken.ThrowIfCancellationRequested(); |
| 18 | 743 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 744 | | } |
| | 745 | | // Send Request |
| 18 | 746 | | if (_shouldTrace) |
| | 747 | | { |
| 0 | 748 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 749 | | } |
| 18 | 750 | | cancellationToken.ThrowIfCancellationRequested(); |
| 18 | 751 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 18 | 752 | | if (_shouldTrace) |
| | 753 | | { |
| 0 | 754 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 755 | | } |
| 18 | 756 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 18 | 757 | | cancellationToken.ThrowIfCancellationRequested(); |
| 18 | 758 | | string _responseContent = null; |
| 18 | 759 | | if ((int)_statusCode != 200) |
| | 760 | | { |
| 0 | 761 | | var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod |
| | 762 | | try |
| | 763 | | { |
| 0 | 764 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 765 | | JobOperationsErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe |
| 0 | 766 | | if (_errorBody != null) |
| | 767 | | { |
| 0 | 768 | | ex.Body = _errorBody; |
| | 769 | | } |
| 0 | 770 | | } |
| 0 | 771 | | catch (JsonException) |
| | 772 | | { |
| | 773 | | // Ignore the exception |
| 0 | 774 | | } |
| 0 | 775 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 776 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 777 | | if (_shouldTrace) |
| | 778 | | { |
| 0 | 779 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 780 | | } |
| 0 | 781 | | _httpRequest.Dispose(); |
| 0 | 782 | | if (_httpResponse != null) |
| | 783 | | { |
| 0 | 784 | | _httpResponse.Dispose(); |
| | 785 | | } |
| 0 | 786 | | throw ex; |
| | 787 | | } |
| | 788 | | // Create Result |
| 18 | 789 | | var _result = new AzureOperationResponse<IList<JobListJsonObject>>(); |
| 18 | 790 | | _result.Request = _httpRequest; |
| 18 | 791 | | _result.Response = _httpResponse; |
| 18 | 792 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 793 | | { |
| 0 | 794 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 795 | | } |
| | 796 | | // Deserialize Response |
| 18 | 797 | | if ((int)_statusCode == 200) |
| | 798 | | { |
| 18 | 799 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 800 | | try |
| | 801 | | { |
| 18 | 802 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<JobListJsonObject>>(_respo |
| 18 | 803 | | } |
| 0 | 804 | | catch (JsonException ex) |
| | 805 | | { |
| 0 | 806 | | _httpRequest.Dispose(); |
| 0 | 807 | | if (_httpResponse != null) |
| | 808 | | { |
| 0 | 809 | | _httpResponse.Dispose(); |
| | 810 | | } |
| 0 | 811 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 812 | | } |
| | 813 | | } |
| 18 | 814 | | if (_shouldTrace) |
| | 815 | | { |
| 0 | 816 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 817 | | } |
| 18 | 818 | | return _result; |
| 18 | 819 | | } |
| | 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 | | { |
| 20 | 850 | | if (Client.Endpoint == null) |
| | 851 | | { |
| 0 | 852 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 853 | | } |
| 20 | 854 | | if (Client.Username == null) |
| | 855 | | { |
| 0 | 856 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Username"); |
| | 857 | | } |
| 20 | 858 | | if (content == null) |
| | 859 | | { |
| 0 | 860 | | throw new ValidationException(ValidationRules.CannotBeNull, "content"); |
| | 861 | | } |
| | 862 | | // Tracing |
| 20 | 863 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 20 | 864 | | string _invocationId = null; |
| 20 | 865 | | if (_shouldTrace) |
| | 866 | | { |
| 0 | 867 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 868 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 869 | | tracingParameters.Add("content", content); |
| 0 | 870 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 871 | | ServiceClientTracing.Enter(_invocationId, this, "SubmitHiveJob", tracingParameters); |
| | 872 | | } |
| | 873 | | // Construct URL |
| 20 | 874 | | var _baseUrl = Client.BaseUri; |
| 20 | 875 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "templeton/v1/hive"; |
| 20 | 876 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 20 | 877 | | List<string> _queryParameters = new List<string>(); |
| 20 | 878 | | if (Client.Username != null) |
| | 879 | | { |
| 20 | 880 | | _queryParameters.Add(string.Format("user.name={0}", System.Uri.EscapeDataString(Client.Username))); |
| | 881 | | } |
| 20 | 882 | | if (_queryParameters.Count > 0) |
| | 883 | | { |
| 20 | 884 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 885 | | } |
| | 886 | | // Create HTTP transport objects |
| 20 | 887 | | var _httpRequest = new HttpRequestMessage(); |
| 20 | 888 | | HttpResponseMessage _httpResponse = null; |
| 20 | 889 | | _httpRequest.Method = new HttpMethod("POST"); |
| 20 | 890 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 891 | | // Set Headers |
| 20 | 892 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 893 | | { |
| 20 | 894 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 895 | | } |
| 20 | 896 | | if (Client.AcceptLanguage != null) |
| | 897 | | { |
| 20 | 898 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 899 | | { |
| 0 | 900 | | _httpRequest.Headers.Remove("accept-language"); |
| | 901 | | } |
| 20 | 902 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 903 | | } |
| | 904 | |
|
| | 905 | |
|
| 20 | 906 | | if (customHeaders != null) |
| | 907 | | { |
| 0 | 908 | | foreach(var _header in customHeaders) |
| | 909 | | { |
| 0 | 910 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 911 | | { |
| 0 | 912 | | _httpRequest.Headers.Remove(_header.Key); |
| | 913 | | } |
| 0 | 914 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 915 | | } |
| | 916 | | } |
| | 917 | |
|
| | 918 | | // Serialize Request |
| 20 | 919 | | string _requestContent = null; |
| 20 | 920 | | if(content == null) |
| | 921 | | { |
| 0 | 922 | | throw new System.ArgumentNullException("content"); |
| | 923 | | } |
| 20 | 924 | | if (content != null && content != Stream.Null) |
| | 925 | | { |
| 20 | 926 | | _httpRequest.Content = new StreamContent(content); |
| 20 | 927 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 928 | | } |
| | 929 | | // Set Credentials |
| 20 | 930 | | if (Client.Credentials != null) |
| | 931 | | { |
| 20 | 932 | | cancellationToken.ThrowIfCancellationRequested(); |
| 20 | 933 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 934 | | } |
| | 935 | | // Send Request |
| 20 | 936 | | if (_shouldTrace) |
| | 937 | | { |
| 0 | 938 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 939 | | } |
| 20 | 940 | | cancellationToken.ThrowIfCancellationRequested(); |
| 20 | 941 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 20 | 942 | | if (_shouldTrace) |
| | 943 | | { |
| 0 | 944 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 945 | | } |
| 20 | 946 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 20 | 947 | | cancellationToken.ThrowIfCancellationRequested(); |
| 20 | 948 | | string _responseContent = null; |
| 20 | 949 | | if ((int)_statusCode != 200) |
| | 950 | | { |
| 0 | 951 | | var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod |
| | 952 | | try |
| | 953 | | { |
| 0 | 954 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 955 | | JobOperationsErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe |
| 0 | 956 | | if (_errorBody != null) |
| | 957 | | { |
| 0 | 958 | | ex.Body = _errorBody; |
| | 959 | | } |
| 0 | 960 | | } |
| 0 | 961 | | catch (JsonException) |
| | 962 | | { |
| | 963 | | // Ignore the exception |
| 0 | 964 | | } |
| 0 | 965 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 966 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 967 | | if (_shouldTrace) |
| | 968 | | { |
| 0 | 969 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 970 | | } |
| 0 | 971 | | _httpRequest.Dispose(); |
| 0 | 972 | | if (_httpResponse != null) |
| | 973 | | { |
| 0 | 974 | | _httpResponse.Dispose(); |
| | 975 | | } |
| 0 | 976 | | throw ex; |
| | 977 | | } |
| | 978 | | // Create Result |
| 20 | 979 | | var _result = new AzureOperationResponse<JobSubmissionJsonResponse>(); |
| 20 | 980 | | _result.Request = _httpRequest; |
| 20 | 981 | | _result.Response = _httpResponse; |
| 20 | 982 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 983 | | { |
| 0 | 984 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 985 | | } |
| | 986 | | // Deserialize Response |
| 20 | 987 | | if ((int)_statusCode == 200) |
| | 988 | | { |
| 20 | 989 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 990 | | try |
| | 991 | | { |
| 20 | 992 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobSubmissionJsonResponse>(_resp |
| 20 | 993 | | } |
| 0 | 994 | | catch (JsonException ex) |
| | 995 | | { |
| 0 | 996 | | _httpRequest.Dispose(); |
| 0 | 997 | | if (_httpResponse != null) |
| | 998 | | { |
| 0 | 999 | | _httpResponse.Dispose(); |
| | 1000 | | } |
| 0 | 1001 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1002 | | } |
| | 1003 | | } |
| 20 | 1004 | | if (_shouldTrace) |
| | 1005 | | { |
| 0 | 1006 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1007 | | } |
| 20 | 1008 | | return _result; |
| 20 | 1009 | | } |
| | 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 | | { |
| 6 | 1040 | | if (Client.Endpoint == null) |
| | 1041 | | { |
| 0 | 1042 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1043 | | } |
| 6 | 1044 | | if (Client.Username == null) |
| | 1045 | | { |
| 0 | 1046 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Username"); |
| | 1047 | | } |
| 6 | 1048 | | if (content == null) |
| | 1049 | | { |
| 0 | 1050 | | throw new ValidationException(ValidationRules.CannotBeNull, "content"); |
| | 1051 | | } |
| | 1052 | | // Tracing |
| 6 | 1053 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 6 | 1054 | | string _invocationId = null; |
| 6 | 1055 | | if (_shouldTrace) |
| | 1056 | | { |
| 0 | 1057 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1058 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1059 | | tracingParameters.Add("content", content); |
| 0 | 1060 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1061 | | ServiceClientTracing.Enter(_invocationId, this, "SubmitMapReduceJob", tracingParameters); |
| | 1062 | | } |
| | 1063 | | // Construct URL |
| 6 | 1064 | | var _baseUrl = Client.BaseUri; |
| 6 | 1065 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "templeton/v1/mapreduce/jar"; |
| 6 | 1066 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 6 | 1067 | | List<string> _queryParameters = new List<string>(); |
| 6 | 1068 | | if (Client.Username != null) |
| | 1069 | | { |
| 6 | 1070 | | _queryParameters.Add(string.Format("user.name={0}", System.Uri.EscapeDataString(Client.Username))); |
| | 1071 | | } |
| 6 | 1072 | | if (_queryParameters.Count > 0) |
| | 1073 | | { |
| 6 | 1074 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1075 | | } |
| | 1076 | | // Create HTTP transport objects |
| 6 | 1077 | | var _httpRequest = new HttpRequestMessage(); |
| 6 | 1078 | | HttpResponseMessage _httpResponse = null; |
| 6 | 1079 | | _httpRequest.Method = new HttpMethod("POST"); |
| 6 | 1080 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1081 | | // Set Headers |
| 6 | 1082 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1083 | | { |
| 6 | 1084 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1085 | | } |
| 6 | 1086 | | if (Client.AcceptLanguage != null) |
| | 1087 | | { |
| 6 | 1088 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1089 | | { |
| 0 | 1090 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1091 | | } |
| 6 | 1092 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1093 | | } |
| | 1094 | |
|
| | 1095 | |
|
| 6 | 1096 | | if (customHeaders != null) |
| | 1097 | | { |
| 0 | 1098 | | foreach(var _header in customHeaders) |
| | 1099 | | { |
| 0 | 1100 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1101 | | { |
| 0 | 1102 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1103 | | } |
| 0 | 1104 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1105 | | } |
| | 1106 | | } |
| | 1107 | |
|
| | 1108 | | // Serialize Request |
| 6 | 1109 | | string _requestContent = null; |
| 6 | 1110 | | if(content == null) |
| | 1111 | | { |
| 0 | 1112 | | throw new System.ArgumentNullException("content"); |
| | 1113 | | } |
| 6 | 1114 | | if (content != null && content != Stream.Null) |
| | 1115 | | { |
| 6 | 1116 | | _httpRequest.Content = new StreamContent(content); |
| 6 | 1117 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("text/plain |
| | 1118 | | } |
| | 1119 | | // Set Credentials |
| 6 | 1120 | | if (Client.Credentials != null) |
| | 1121 | | { |
| 6 | 1122 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 1123 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1124 | | } |
| | 1125 | | // Send Request |
| 6 | 1126 | | if (_shouldTrace) |
| | 1127 | | { |
| 0 | 1128 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1129 | | } |
| 6 | 1130 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 1131 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 6 | 1132 | | if (_shouldTrace) |
| | 1133 | | { |
| 0 | 1134 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1135 | | } |
| 6 | 1136 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 6 | 1137 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 1138 | | string _responseContent = null; |
| 6 | 1139 | | if ((int)_statusCode != 200) |
| | 1140 | | { |
| 0 | 1141 | | var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod |
| | 1142 | | try |
| | 1143 | | { |
| 0 | 1144 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1145 | | JobOperationsErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe |
| 0 | 1146 | | if (_errorBody != null) |
| | 1147 | | { |
| 0 | 1148 | | ex.Body = _errorBody; |
| | 1149 | | } |
| 0 | 1150 | | } |
| 0 | 1151 | | catch (JsonException) |
| | 1152 | | { |
| | 1153 | | // Ignore the exception |
| 0 | 1154 | | } |
| 0 | 1155 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1156 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1157 | | if (_shouldTrace) |
| | 1158 | | { |
| 0 | 1159 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1160 | | } |
| 0 | 1161 | | _httpRequest.Dispose(); |
| 0 | 1162 | | if (_httpResponse != null) |
| | 1163 | | { |
| 0 | 1164 | | _httpResponse.Dispose(); |
| | 1165 | | } |
| 0 | 1166 | | throw ex; |
| | 1167 | | } |
| | 1168 | | // Create Result |
| 6 | 1169 | | var _result = new AzureOperationResponse<JobSubmissionJsonResponse>(); |
| 6 | 1170 | | _result.Request = _httpRequest; |
| 6 | 1171 | | _result.Response = _httpResponse; |
| 6 | 1172 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1173 | | { |
| 0 | 1174 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1175 | | } |
| | 1176 | | // Deserialize Response |
| 6 | 1177 | | if ((int)_statusCode == 200) |
| | 1178 | | { |
| 6 | 1179 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1180 | | try |
| | 1181 | | { |
| 6 | 1182 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobSubmissionJsonResponse>(_resp |
| 6 | 1183 | | } |
| 0 | 1184 | | catch (JsonException ex) |
| | 1185 | | { |
| 0 | 1186 | | _httpRequest.Dispose(); |
| 0 | 1187 | | if (_httpResponse != null) |
| | 1188 | | { |
| 0 | 1189 | | _httpResponse.Dispose(); |
| | 1190 | | } |
| 0 | 1191 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1192 | | } |
| | 1193 | | } |
| 6 | 1194 | | if (_shouldTrace) |
| | 1195 | | { |
| 0 | 1196 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1197 | | } |
| 6 | 1198 | | return _result; |
| 6 | 1199 | | } |
| | 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 | | { |
| 4 | 1230 | | if (Client.Endpoint == null) |
| | 1231 | | { |
| 0 | 1232 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1233 | | } |
| 4 | 1234 | | if (Client.Username == null) |
| | 1235 | | { |
| 0 | 1236 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Username"); |
| | 1237 | | } |
| 4 | 1238 | | if (content == null) |
| | 1239 | | { |
| 0 | 1240 | | throw new ValidationException(ValidationRules.CannotBeNull, "content"); |
| | 1241 | | } |
| | 1242 | | // Tracing |
| 4 | 1243 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 1244 | | string _invocationId = null; |
| 4 | 1245 | | if (_shouldTrace) |
| | 1246 | | { |
| 0 | 1247 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1248 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1249 | | tracingParameters.Add("content", content); |
| 0 | 1250 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1251 | | ServiceClientTracing.Enter(_invocationId, this, "SubmitMapReduceStreamingJob", tracingParameters); |
| | 1252 | | } |
| | 1253 | | // Construct URL |
| 4 | 1254 | | var _baseUrl = Client.BaseUri; |
| 4 | 1255 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "templeton/v1/mapreduce/streaming"; |
| 4 | 1256 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 4 | 1257 | | List<string> _queryParameters = new List<string>(); |
| 4 | 1258 | | if (Client.Username != null) |
| | 1259 | | { |
| 4 | 1260 | | _queryParameters.Add(string.Format("user.name={0}", System.Uri.EscapeDataString(Client.Username))); |
| | 1261 | | } |
| 4 | 1262 | | if (_queryParameters.Count > 0) |
| | 1263 | | { |
| 4 | 1264 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1265 | | } |
| | 1266 | | // Create HTTP transport objects |
| 4 | 1267 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 1268 | | HttpResponseMessage _httpResponse = null; |
| 4 | 1269 | | _httpRequest.Method = new HttpMethod("POST"); |
| 4 | 1270 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1271 | | // Set Headers |
| 4 | 1272 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1273 | | { |
| 4 | 1274 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1275 | | } |
| 4 | 1276 | | if (Client.AcceptLanguage != null) |
| | 1277 | | { |
| 4 | 1278 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1279 | | { |
| 0 | 1280 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1281 | | } |
| 4 | 1282 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1283 | | } |
| | 1284 | |
|
| | 1285 | |
|
| 4 | 1286 | | if (customHeaders != null) |
| | 1287 | | { |
| 0 | 1288 | | foreach(var _header in customHeaders) |
| | 1289 | | { |
| 0 | 1290 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1291 | | { |
| 0 | 1292 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1293 | | } |
| 0 | 1294 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1295 | | } |
| | 1296 | | } |
| | 1297 | |
|
| | 1298 | | // Serialize Request |
| 4 | 1299 | | string _requestContent = null; |
| 4 | 1300 | | if(content == null) |
| | 1301 | | { |
| 0 | 1302 | | throw new System.ArgumentNullException("content"); |
| | 1303 | | } |
| 4 | 1304 | | if (content != null && content != Stream.Null) |
| | 1305 | | { |
| 4 | 1306 | | _httpRequest.Content = new StreamContent(content); |
| 4 | 1307 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("text/plain |
| | 1308 | | } |
| | 1309 | | // Set Credentials |
| 4 | 1310 | | if (Client.Credentials != null) |
| | 1311 | | { |
| 4 | 1312 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1313 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1314 | | } |
| | 1315 | | // Send Request |
| 4 | 1316 | | if (_shouldTrace) |
| | 1317 | | { |
| 0 | 1318 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1319 | | } |
| 4 | 1320 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1321 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 1322 | | if (_shouldTrace) |
| | 1323 | | { |
| 0 | 1324 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1325 | | } |
| 4 | 1326 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 1327 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1328 | | string _responseContent = null; |
| 4 | 1329 | | if ((int)_statusCode != 200) |
| | 1330 | | { |
| 0 | 1331 | | var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod |
| | 1332 | | try |
| | 1333 | | { |
| 0 | 1334 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1335 | | JobOperationsErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe |
| 0 | 1336 | | if (_errorBody != null) |
| | 1337 | | { |
| 0 | 1338 | | ex.Body = _errorBody; |
| | 1339 | | } |
| 0 | 1340 | | } |
| 0 | 1341 | | catch (JsonException) |
| | 1342 | | { |
| | 1343 | | // Ignore the exception |
| 0 | 1344 | | } |
| 0 | 1345 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1346 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1347 | | if (_shouldTrace) |
| | 1348 | | { |
| 0 | 1349 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1350 | | } |
| 0 | 1351 | | _httpRequest.Dispose(); |
| 0 | 1352 | | if (_httpResponse != null) |
| | 1353 | | { |
| 0 | 1354 | | _httpResponse.Dispose(); |
| | 1355 | | } |
| 0 | 1356 | | throw ex; |
| | 1357 | | } |
| | 1358 | | // Create Result |
| 4 | 1359 | | var _result = new AzureOperationResponse<JobSubmissionJsonResponse>(); |
| 4 | 1360 | | _result.Request = _httpRequest; |
| 4 | 1361 | | _result.Response = _httpResponse; |
| 4 | 1362 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1363 | | { |
| 0 | 1364 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1365 | | } |
| | 1366 | | // Deserialize Response |
| 4 | 1367 | | if ((int)_statusCode == 200) |
| | 1368 | | { |
| 4 | 1369 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1370 | | try |
| | 1371 | | { |
| 4 | 1372 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobSubmissionJsonResponse>(_resp |
| 4 | 1373 | | } |
| 0 | 1374 | | catch (JsonException ex) |
| | 1375 | | { |
| 0 | 1376 | | _httpRequest.Dispose(); |
| 0 | 1377 | | if (_httpResponse != null) |
| | 1378 | | { |
| 0 | 1379 | | _httpResponse.Dispose(); |
| | 1380 | | } |
| 0 | 1381 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1382 | | } |
| | 1383 | | } |
| 4 | 1384 | | if (_shouldTrace) |
| | 1385 | | { |
| 0 | 1386 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1387 | | } |
| 4 | 1388 | | return _result; |
| 4 | 1389 | | } |
| | 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 | | { |
| 4 | 1420 | | if (Client.Endpoint == null) |
| | 1421 | | { |
| 0 | 1422 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1423 | | } |
| 4 | 1424 | | if (Client.Username == null) |
| | 1425 | | { |
| 0 | 1426 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Username"); |
| | 1427 | | } |
| 4 | 1428 | | if (content == null) |
| | 1429 | | { |
| 0 | 1430 | | throw new ValidationException(ValidationRules.CannotBeNull, "content"); |
| | 1431 | | } |
| | 1432 | | // Tracing |
| 4 | 1433 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 1434 | | string _invocationId = null; |
| 4 | 1435 | | if (_shouldTrace) |
| | 1436 | | { |
| 0 | 1437 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1438 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1439 | | tracingParameters.Add("content", content); |
| 0 | 1440 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1441 | | ServiceClientTracing.Enter(_invocationId, this, "SubmitPigJob", tracingParameters); |
| | 1442 | | } |
| | 1443 | | // Construct URL |
| 4 | 1444 | | var _baseUrl = Client.BaseUri; |
| 4 | 1445 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "templeton/v1/pig"; |
| 4 | 1446 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 4 | 1447 | | List<string> _queryParameters = new List<string>(); |
| 4 | 1448 | | if (Client.Username != null) |
| | 1449 | | { |
| 4 | 1450 | | _queryParameters.Add(string.Format("user.name={0}", System.Uri.EscapeDataString(Client.Username))); |
| | 1451 | | } |
| 4 | 1452 | | if (_queryParameters.Count > 0) |
| | 1453 | | { |
| 4 | 1454 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1455 | | } |
| | 1456 | | // Create HTTP transport objects |
| 4 | 1457 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 1458 | | HttpResponseMessage _httpResponse = null; |
| 4 | 1459 | | _httpRequest.Method = new HttpMethod("POST"); |
| 4 | 1460 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1461 | | // Set Headers |
| 4 | 1462 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1463 | | { |
| 4 | 1464 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1465 | | } |
| 4 | 1466 | | if (Client.AcceptLanguage != null) |
| | 1467 | | { |
| 4 | 1468 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1469 | | { |
| 0 | 1470 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1471 | | } |
| 4 | 1472 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1473 | | } |
| | 1474 | |
|
| | 1475 | |
|
| 4 | 1476 | | if (customHeaders != null) |
| | 1477 | | { |
| 0 | 1478 | | foreach(var _header in customHeaders) |
| | 1479 | | { |
| 0 | 1480 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1481 | | { |
| 0 | 1482 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1483 | | } |
| 0 | 1484 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1485 | | } |
| | 1486 | | } |
| | 1487 | |
|
| | 1488 | | // Serialize Request |
| 4 | 1489 | | string _requestContent = null; |
| 4 | 1490 | | if(content == null) |
| | 1491 | | { |
| 0 | 1492 | | throw new System.ArgumentNullException("content"); |
| | 1493 | | } |
| 4 | 1494 | | if (content != null && content != Stream.Null) |
| | 1495 | | { |
| 4 | 1496 | | _httpRequest.Content = new StreamContent(content); |
| 4 | 1497 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("text/plain |
| | 1498 | | } |
| | 1499 | | // Set Credentials |
| 4 | 1500 | | if (Client.Credentials != null) |
| | 1501 | | { |
| 4 | 1502 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1503 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1504 | | } |
| | 1505 | | // Send Request |
| 4 | 1506 | | if (_shouldTrace) |
| | 1507 | | { |
| 0 | 1508 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1509 | | } |
| 4 | 1510 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1511 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 1512 | | if (_shouldTrace) |
| | 1513 | | { |
| 0 | 1514 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1515 | | } |
| 4 | 1516 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 1517 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1518 | | string _responseContent = null; |
| 4 | 1519 | | if ((int)_statusCode != 200) |
| | 1520 | | { |
| 0 | 1521 | | var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod |
| | 1522 | | try |
| | 1523 | | { |
| 0 | 1524 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1525 | | JobOperationsErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe |
| 0 | 1526 | | if (_errorBody != null) |
| | 1527 | | { |
| 0 | 1528 | | ex.Body = _errorBody; |
| | 1529 | | } |
| 0 | 1530 | | } |
| 0 | 1531 | | catch (JsonException) |
| | 1532 | | { |
| | 1533 | | // Ignore the exception |
| 0 | 1534 | | } |
| 0 | 1535 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1536 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1537 | | if (_shouldTrace) |
| | 1538 | | { |
| 0 | 1539 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1540 | | } |
| 0 | 1541 | | _httpRequest.Dispose(); |
| 0 | 1542 | | if (_httpResponse != null) |
| | 1543 | | { |
| 0 | 1544 | | _httpResponse.Dispose(); |
| | 1545 | | } |
| 0 | 1546 | | throw ex; |
| | 1547 | | } |
| | 1548 | | // Create Result |
| 4 | 1549 | | var _result = new AzureOperationResponse<JobSubmissionJsonResponse>(); |
| 4 | 1550 | | _result.Request = _httpRequest; |
| 4 | 1551 | | _result.Response = _httpResponse; |
| 4 | 1552 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1553 | | { |
| 0 | 1554 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1555 | | } |
| | 1556 | | // Deserialize Response |
| 4 | 1557 | | if ((int)_statusCode == 200) |
| | 1558 | | { |
| 4 | 1559 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1560 | | try |
| | 1561 | | { |
| 4 | 1562 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobSubmissionJsonResponse>(_resp |
| 4 | 1563 | | } |
| 0 | 1564 | | catch (JsonException ex) |
| | 1565 | | { |
| 0 | 1566 | | _httpRequest.Dispose(); |
| 0 | 1567 | | if (_httpResponse != null) |
| | 1568 | | { |
| 0 | 1569 | | _httpResponse.Dispose(); |
| | 1570 | | } |
| 0 | 1571 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1572 | | } |
| | 1573 | | } |
| 4 | 1574 | | if (_shouldTrace) |
| | 1575 | | { |
| 0 | 1576 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1577 | | } |
| 4 | 1578 | | return _result; |
| 4 | 1579 | | } |
| | 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 | | { |
| 4 | 1610 | | if (Client.Endpoint == null) |
| | 1611 | | { |
| 0 | 1612 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1613 | | } |
| 4 | 1614 | | if (Client.Username == null) |
| | 1615 | | { |
| 0 | 1616 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Username"); |
| | 1617 | | } |
| 4 | 1618 | | if (content == null) |
| | 1619 | | { |
| 0 | 1620 | | throw new ValidationException(ValidationRules.CannotBeNull, "content"); |
| | 1621 | | } |
| | 1622 | | // Tracing |
| 4 | 1623 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 1624 | | string _invocationId = null; |
| 4 | 1625 | | if (_shouldTrace) |
| | 1626 | | { |
| 0 | 1627 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1628 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1629 | | tracingParameters.Add("content", content); |
| 0 | 1630 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1631 | | ServiceClientTracing.Enter(_invocationId, this, "SubmitSqoopJob", tracingParameters); |
| | 1632 | | } |
| | 1633 | | // Construct URL |
| 4 | 1634 | | var _baseUrl = Client.BaseUri; |
| 4 | 1635 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "templeton/v1/sqoop"; |
| 4 | 1636 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 4 | 1637 | | List<string> _queryParameters = new List<string>(); |
| 4 | 1638 | | if (Client.Username != null) |
| | 1639 | | { |
| 4 | 1640 | | _queryParameters.Add(string.Format("user.name={0}", System.Uri.EscapeDataString(Client.Username))); |
| | 1641 | | } |
| 4 | 1642 | | if (_queryParameters.Count > 0) |
| | 1643 | | { |
| 4 | 1644 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1645 | | } |
| | 1646 | | // Create HTTP transport objects |
| 4 | 1647 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 1648 | | HttpResponseMessage _httpResponse = null; |
| 4 | 1649 | | _httpRequest.Method = new HttpMethod("POST"); |
| 4 | 1650 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1651 | | // Set Headers |
| 4 | 1652 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1653 | | { |
| 4 | 1654 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1655 | | } |
| 4 | 1656 | | if (Client.AcceptLanguage != null) |
| | 1657 | | { |
| 4 | 1658 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1659 | | { |
| 0 | 1660 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1661 | | } |
| 4 | 1662 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1663 | | } |
| | 1664 | |
|
| | 1665 | |
|
| 4 | 1666 | | if (customHeaders != null) |
| | 1667 | | { |
| 0 | 1668 | | foreach(var _header in customHeaders) |
| | 1669 | | { |
| 0 | 1670 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1671 | | { |
| 0 | 1672 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1673 | | } |
| 0 | 1674 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1675 | | } |
| | 1676 | | } |
| | 1677 | |
|
| | 1678 | | // Serialize Request |
| 4 | 1679 | | string _requestContent = null; |
| 4 | 1680 | | if(content == null) |
| | 1681 | | { |
| 0 | 1682 | | throw new System.ArgumentNullException("content"); |
| | 1683 | | } |
| 4 | 1684 | | if (content != null && content != Stream.Null) |
| | 1685 | | { |
| 4 | 1686 | | _httpRequest.Content = new StreamContent(content); |
| 4 | 1687 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("text/plain |
| | 1688 | | } |
| | 1689 | | // Set Credentials |
| 4 | 1690 | | if (Client.Credentials != null) |
| | 1691 | | { |
| 4 | 1692 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1693 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1694 | | } |
| | 1695 | | // Send Request |
| 4 | 1696 | | if (_shouldTrace) |
| | 1697 | | { |
| 0 | 1698 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1699 | | } |
| 4 | 1700 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1701 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 1702 | | if (_shouldTrace) |
| | 1703 | | { |
| 0 | 1704 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1705 | | } |
| 4 | 1706 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 1707 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1708 | | string _responseContent = null; |
| 4 | 1709 | | if ((int)_statusCode != 200) |
| | 1710 | | { |
| 0 | 1711 | | var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod |
| | 1712 | | try |
| | 1713 | | { |
| 0 | 1714 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1715 | | JobOperationsErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe |
| 0 | 1716 | | if (_errorBody != null) |
| | 1717 | | { |
| 0 | 1718 | | ex.Body = _errorBody; |
| | 1719 | | } |
| 0 | 1720 | | } |
| 0 | 1721 | | catch (JsonException) |
| | 1722 | | { |
| | 1723 | | // Ignore the exception |
| 0 | 1724 | | } |
| 0 | 1725 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1726 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1727 | | if (_shouldTrace) |
| | 1728 | | { |
| 0 | 1729 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1730 | | } |
| 0 | 1731 | | _httpRequest.Dispose(); |
| 0 | 1732 | | if (_httpResponse != null) |
| | 1733 | | { |
| 0 | 1734 | | _httpResponse.Dispose(); |
| | 1735 | | } |
| 0 | 1736 | | throw ex; |
| | 1737 | | } |
| | 1738 | | // Create Result |
| 4 | 1739 | | var _result = new AzureOperationResponse<JobSubmissionJsonResponse>(); |
| 4 | 1740 | | _result.Request = _httpRequest; |
| 4 | 1741 | | _result.Response = _httpResponse; |
| 4 | 1742 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1743 | | { |
| 0 | 1744 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1745 | | } |
| | 1746 | | // Deserialize Response |
| 4 | 1747 | | if ((int)_statusCode == 200) |
| | 1748 | | { |
| 4 | 1749 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1750 | | try |
| | 1751 | | { |
| 4 | 1752 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobSubmissionJsonResponse>(_resp |
| 4 | 1753 | | } |
| 0 | 1754 | | catch (JsonException ex) |
| | 1755 | | { |
| 0 | 1756 | | _httpRequest.Dispose(); |
| 0 | 1757 | | if (_httpResponse != null) |
| | 1758 | | { |
| 0 | 1759 | | _httpResponse.Dispose(); |
| | 1760 | | } |
| 0 | 1761 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1762 | | } |
| | 1763 | | } |
| 4 | 1764 | | if (_shouldTrace) |
| | 1765 | | { |
| 0 | 1766 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1767 | | } |
| 4 | 1768 | | return _result; |
| 4 | 1769 | | } |
| | 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 | | { |
| 406 | 1800 | | if (Client.Endpoint == null) |
| | 1801 | | { |
| 0 | 1802 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1803 | | } |
| 406 | 1804 | | if (appId == null) |
| | 1805 | | { |
| 0 | 1806 | | throw new ValidationException(ValidationRules.CannotBeNull, "appId"); |
| | 1807 | | } |
| | 1808 | | // Tracing |
| 406 | 1809 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 406 | 1810 | | string _invocationId = null; |
| 406 | 1811 | | if (_shouldTrace) |
| | 1812 | | { |
| 0 | 1813 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1814 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1815 | | tracingParameters.Add("appId", appId); |
| 0 | 1816 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1817 | | ServiceClientTracing.Enter(_invocationId, this, "GetAppState", tracingParameters); |
| | 1818 | | } |
| | 1819 | | // Construct URL |
| 406 | 1820 | | var _baseUrl = Client.BaseUri; |
| 406 | 1821 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "ws/v1/cluster/apps/{appId}/state"; |
| 406 | 1822 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 406 | 1823 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(appId)); |
| 406 | 1824 | | List<string> _queryParameters = new List<string>(); |
| 406 | 1825 | | if (_queryParameters.Count > 0) |
| | 1826 | | { |
| 0 | 1827 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1828 | | } |
| | 1829 | | // Create HTTP transport objects |
| 406 | 1830 | | var _httpRequest = new HttpRequestMessage(); |
| 406 | 1831 | | HttpResponseMessage _httpResponse = null; |
| 406 | 1832 | | _httpRequest.Method = new HttpMethod("GET"); |
| 406 | 1833 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1834 | | // Set Headers |
| 406 | 1835 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1836 | | { |
| 406 | 1837 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1838 | | } |
| 406 | 1839 | | if (Client.AcceptLanguage != null) |
| | 1840 | | { |
| 406 | 1841 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1842 | | { |
| 0 | 1843 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1844 | | } |
| 406 | 1845 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1846 | | } |
| | 1847 | |
|
| | 1848 | |
|
| 406 | 1849 | | if (customHeaders != null) |
| | 1850 | | { |
| 0 | 1851 | | foreach(var _header in customHeaders) |
| | 1852 | | { |
| 0 | 1853 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1854 | | { |
| 0 | 1855 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1856 | | } |
| 0 | 1857 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1858 | | } |
| | 1859 | | } |
| | 1860 | |
|
| | 1861 | | // Serialize Request |
| 406 | 1862 | | string _requestContent = null; |
| | 1863 | | // Set Credentials |
| 406 | 1864 | | if (Client.Credentials != null) |
| | 1865 | | { |
| 406 | 1866 | | cancellationToken.ThrowIfCancellationRequested(); |
| 406 | 1867 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1868 | | } |
| | 1869 | | // Send Request |
| 406 | 1870 | | if (_shouldTrace) |
| | 1871 | | { |
| 0 | 1872 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1873 | | } |
| 406 | 1874 | | cancellationToken.ThrowIfCancellationRequested(); |
| 406 | 1875 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 406 | 1876 | | if (_shouldTrace) |
| | 1877 | | { |
| 0 | 1878 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1879 | | } |
| 406 | 1880 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 406 | 1881 | | cancellationToken.ThrowIfCancellationRequested(); |
| 406 | 1882 | | string _responseContent = null; |
| 406 | 1883 | | if ((int)_statusCode != 200) |
| | 1884 | | { |
| 0 | 1885 | | var ex = new JobOperationsErrorResponseException(string.Format("Operation returned an invalid status cod |
| | 1886 | | try |
| | 1887 | | { |
| 0 | 1888 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1889 | | JobOperationsErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<JobOpe |
| 0 | 1890 | | if (_errorBody != null) |
| | 1891 | | { |
| 0 | 1892 | | ex.Body = _errorBody; |
| | 1893 | | } |
| 0 | 1894 | | } |
| 0 | 1895 | | catch (JsonException) |
| | 1896 | | { |
| | 1897 | | // Ignore the exception |
| 0 | 1898 | | } |
| 0 | 1899 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1900 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1901 | | if (_shouldTrace) |
| | 1902 | | { |
| 0 | 1903 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1904 | | } |
| 0 | 1905 | | _httpRequest.Dispose(); |
| 0 | 1906 | | if (_httpResponse != null) |
| | 1907 | | { |
| 0 | 1908 | | _httpResponse.Dispose(); |
| | 1909 | | } |
| 0 | 1910 | | throw ex; |
| | 1911 | | } |
| | 1912 | | // Create Result |
| 406 | 1913 | | var _result = new AzureOperationResponse<AppState>(); |
| 406 | 1914 | | _result.Request = _httpRequest; |
| 406 | 1915 | | _result.Response = _httpResponse; |
| 406 | 1916 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1917 | | { |
| 0 | 1918 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1919 | | } |
| | 1920 | | // Deserialize Response |
| 406 | 1921 | | if ((int)_statusCode == 200) |
| | 1922 | | { |
| 406 | 1923 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1924 | | try |
| | 1925 | | { |
| 406 | 1926 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<AppState>(_responseContent, Clie |
| 406 | 1927 | | } |
| 0 | 1928 | | catch (JsonException ex) |
| | 1929 | | { |
| 0 | 1930 | | _httpRequest.Dispose(); |
| 0 | 1931 | | if (_httpResponse != null) |
| | 1932 | | { |
| 0 | 1933 | | _httpResponse.Dispose(); |
| | 1934 | | } |
| 0 | 1935 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1936 | | } |
| | 1937 | | } |
| 406 | 1938 | | if (_shouldTrace) |
| | 1939 | | { |
| 0 | 1940 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1941 | | } |
| 406 | 1942 | | return _result; |
| 406 | 1943 | | } |
| | 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 | | { |
| 10 | 1978 | | if (Client.Endpoint == null) |
| | 1979 | | { |
| 0 | 1980 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1981 | | } |
| | 1982 | | // Tracing |
| 10 | 1983 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 10 | 1984 | | string _invocationId = null; |
| 10 | 1985 | | if (_shouldTrace) |
| | 1986 | | { |
| 0 | 1987 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1988 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1989 | | tracingParameters.Add("fromParameter", fromParameter); |
| 0 | 1990 | | tracingParameters.Add("size", size); |
| 0 | 1991 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1992 | | ServiceClientTracing.Enter(_invocationId, this, "ListSparkBatchJob", tracingParameters); |
| | 1993 | | } |
| | 1994 | | // Construct URL |
| 10 | 1995 | | var _baseUrl = Client.BaseUri; |
| 10 | 1996 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/batches"; |
| 10 | 1997 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 10 | 1998 | | List<string> _queryParameters = new List<string>(); |
| 10 | 1999 | | if (fromParameter != null) |
| | 2000 | | { |
| 2 | 2001 | | _queryParameters.Add(string.Format("from={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo |
| | 2002 | | } |
| 10 | 2003 | | if (size != null) |
| | 2004 | | { |
| 2 | 2005 | | _queryParameters.Add(string.Format("size={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo |
| | 2006 | | } |
| 10 | 2007 | | if (_queryParameters.Count > 0) |
| | 2008 | | { |
| 2 | 2009 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 2010 | | } |
| | 2011 | | // Create HTTP transport objects |
| 10 | 2012 | | var _httpRequest = new HttpRequestMessage(); |
| 10 | 2013 | | HttpResponseMessage _httpResponse = null; |
| 10 | 2014 | | _httpRequest.Method = new HttpMethod("GET"); |
| 10 | 2015 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2016 | | // Set Headers |
| 10 | 2017 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 2018 | | { |
| 10 | 2019 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 2020 | | } |
| 10 | 2021 | | if (Client.AcceptLanguage != null) |
| | 2022 | | { |
| 10 | 2023 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 2024 | | { |
| 0 | 2025 | | _httpRequest.Headers.Remove("accept-language"); |
| | 2026 | | } |
| 10 | 2027 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 2028 | | } |
| | 2029 | |
|
| | 2030 | |
|
| 10 | 2031 | | if (customHeaders != null) |
| | 2032 | | { |
| 0 | 2033 | | foreach(var _header in customHeaders) |
| | 2034 | | { |
| 0 | 2035 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2036 | | { |
| 0 | 2037 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2038 | | } |
| 0 | 2039 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2040 | | } |
| | 2041 | | } |
| | 2042 | |
|
| | 2043 | | // Serialize Request |
| 10 | 2044 | | string _requestContent = null; |
| | 2045 | | // Set Credentials |
| 10 | 2046 | | if (Client.Credentials != null) |
| | 2047 | | { |
| 10 | 2048 | | cancellationToken.ThrowIfCancellationRequested(); |
| 10 | 2049 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2050 | | } |
| | 2051 | | // Send Request |
| 10 | 2052 | | if (_shouldTrace) |
| | 2053 | | { |
| 0 | 2054 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2055 | | } |
| 10 | 2056 | | cancellationToken.ThrowIfCancellationRequested(); |
| 10 | 2057 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 10 | 2058 | | if (_shouldTrace) |
| | 2059 | | { |
| 0 | 2060 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2061 | | } |
| 10 | 2062 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 10 | 2063 | | cancellationToken.ThrowIfCancellationRequested(); |
| 10 | 2064 | | string _responseContent = null; |
| 10 | 2065 | | if ((int)_statusCode != 200) |
| | 2066 | | { |
| 0 | 2067 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 2068 | | try |
| | 2069 | | { |
| 0 | 2070 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2071 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 2072 | | if (_errorBody != null) |
| | 2073 | | { |
| 0 | 2074 | | ex = new CloudException(_errorBody.Message); |
| 0 | 2075 | | ex.Body = _errorBody; |
| | 2076 | | } |
| 0 | 2077 | | } |
| 0 | 2078 | | catch (JsonException) |
| | 2079 | | { |
| | 2080 | | // Ignore the exception |
| 0 | 2081 | | } |
| 0 | 2082 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2083 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2084 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 2085 | | { |
| 0 | 2086 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 2087 | | } |
| 0 | 2088 | | if (_shouldTrace) |
| | 2089 | | { |
| 0 | 2090 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2091 | | } |
| 0 | 2092 | | _httpRequest.Dispose(); |
| 0 | 2093 | | if (_httpResponse != null) |
| | 2094 | | { |
| 0 | 2095 | | _httpResponse.Dispose(); |
| | 2096 | | } |
| 0 | 2097 | | throw ex; |
| | 2098 | | } |
| | 2099 | | // Create Result |
| 10 | 2100 | | var _result = new AzureOperationResponse<SparkBatchJobCollection>(); |
| 10 | 2101 | | _result.Request = _httpRequest; |
| 10 | 2102 | | _result.Response = _httpResponse; |
| 10 | 2103 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 2104 | | { |
| 0 | 2105 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 2106 | | } |
| | 2107 | | // Deserialize Response |
| 10 | 2108 | | if ((int)_statusCode == 200) |
| | 2109 | | { |
| 10 | 2110 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2111 | | try |
| | 2112 | | { |
| 10 | 2113 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkBatchJobCollection>(_respon |
| 10 | 2114 | | } |
| 0 | 2115 | | catch (JsonException ex) |
| | 2116 | | { |
| 0 | 2117 | | _httpRequest.Dispose(); |
| 0 | 2118 | | if (_httpResponse != null) |
| | 2119 | | { |
| 0 | 2120 | | _httpResponse.Dispose(); |
| | 2121 | | } |
| 0 | 2122 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2123 | | } |
| | 2124 | | } |
| 10 | 2125 | | if (_shouldTrace) |
| | 2126 | | { |
| 0 | 2127 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2128 | | } |
| 10 | 2129 | | return _result; |
| 10 | 2130 | | } |
| | 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 | | { |
| 6 | 2164 | | if (Client.Endpoint == null) |
| | 2165 | | { |
| 0 | 2166 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 2167 | | } |
| 6 | 2168 | | if (sparkBatchJobRequest == null) |
| | 2169 | | { |
| 0 | 2170 | | throw new ValidationException(ValidationRules.CannotBeNull, "sparkBatchJobRequest"); |
| | 2171 | | } |
| | 2172 | | // Tracing |
| 6 | 2173 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 6 | 2174 | | string _invocationId = null; |
| 6 | 2175 | | if (_shouldTrace) |
| | 2176 | | { |
| 0 | 2177 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2178 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2179 | | tracingParameters.Add("requestedBy", requestedBy); |
| 0 | 2180 | | tracingParameters.Add("sparkBatchJobRequest", sparkBatchJobRequest); |
| 0 | 2181 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2182 | | ServiceClientTracing.Enter(_invocationId, this, "SubmitSparkBatchJob", tracingParameters); |
| | 2183 | | } |
| | 2184 | | // Construct URL |
| 6 | 2185 | | var _baseUrl = Client.BaseUri; |
| 6 | 2186 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/batches"; |
| 6 | 2187 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 6 | 2188 | | List<string> _queryParameters = new List<string>(); |
| 6 | 2189 | | if (_queryParameters.Count > 0) |
| | 2190 | | { |
| 0 | 2191 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 2192 | | } |
| | 2193 | | // Create HTTP transport objects |
| 6 | 2194 | | var _httpRequest = new HttpRequestMessage(); |
| 6 | 2195 | | HttpResponseMessage _httpResponse = null; |
| 6 | 2196 | | _httpRequest.Method = new HttpMethod("POST"); |
| 6 | 2197 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2198 | | // Set Headers |
| 6 | 2199 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 2200 | | { |
| 6 | 2201 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 2202 | | } |
| 6 | 2203 | | if (requestedBy != null) |
| | 2204 | | { |
| 6 | 2205 | | if (_httpRequest.Headers.Contains("X-Requested-By")) |
| | 2206 | | { |
| 0 | 2207 | | _httpRequest.Headers.Remove("X-Requested-By"); |
| | 2208 | | } |
| 6 | 2209 | | _httpRequest.Headers.TryAddWithoutValidation("X-Requested-By", requestedBy); |
| | 2210 | | } |
| 6 | 2211 | | if (Client.AcceptLanguage != null) |
| | 2212 | | { |
| 6 | 2213 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 2214 | | { |
| 0 | 2215 | | _httpRequest.Headers.Remove("accept-language"); |
| | 2216 | | } |
| 6 | 2217 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 2218 | | } |
| | 2219 | |
|
| | 2220 | |
|
| 6 | 2221 | | if (customHeaders != null) |
| | 2222 | | { |
| 0 | 2223 | | foreach(var _header in customHeaders) |
| | 2224 | | { |
| 0 | 2225 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2226 | | { |
| 0 | 2227 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2228 | | } |
| 0 | 2229 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2230 | | } |
| | 2231 | | } |
| | 2232 | |
|
| | 2233 | | // Serialize Request |
| 6 | 2234 | | string _requestContent = null; |
| 6 | 2235 | | if(sparkBatchJobRequest != null) |
| | 2236 | | { |
| 6 | 2237 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(sparkBatchJobRequest, Client.Serial |
| 6 | 2238 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 6 | 2239 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 2240 | | } |
| | 2241 | | // Set Credentials |
| 6 | 2242 | | if (Client.Credentials != null) |
| | 2243 | | { |
| 6 | 2244 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 2245 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2246 | | } |
| | 2247 | | // Send Request |
| 6 | 2248 | | if (_shouldTrace) |
| | 2249 | | { |
| 0 | 2250 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2251 | | } |
| 6 | 2252 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 2253 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 6 | 2254 | | if (_shouldTrace) |
| | 2255 | | { |
| 0 | 2256 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2257 | | } |
| 6 | 2258 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 6 | 2259 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 2260 | | string _responseContent = null; |
| 6 | 2261 | | if ((int)_statusCode != 201) |
| | 2262 | | { |
| 0 | 2263 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 2264 | | try |
| | 2265 | | { |
| 0 | 2266 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2267 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 2268 | | if (_errorBody != null) |
| | 2269 | | { |
| 0 | 2270 | | ex = new CloudException(_errorBody.Message); |
| 0 | 2271 | | ex.Body = _errorBody; |
| | 2272 | | } |
| 0 | 2273 | | } |
| 0 | 2274 | | catch (JsonException) |
| | 2275 | | { |
| | 2276 | | // Ignore the exception |
| 0 | 2277 | | } |
| 0 | 2278 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2279 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2280 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 2281 | | { |
| 0 | 2282 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 2283 | | } |
| 0 | 2284 | | if (_shouldTrace) |
| | 2285 | | { |
| 0 | 2286 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2287 | | } |
| 0 | 2288 | | _httpRequest.Dispose(); |
| 0 | 2289 | | if (_httpResponse != null) |
| | 2290 | | { |
| 0 | 2291 | | _httpResponse.Dispose(); |
| | 2292 | | } |
| 0 | 2293 | | throw ex; |
| | 2294 | | } |
| | 2295 | | // Create Result |
| 6 | 2296 | | var _result = new AzureOperationResponse<SparkBatchJob>(); |
| 6 | 2297 | | _result.Request = _httpRequest; |
| 6 | 2298 | | _result.Response = _httpResponse; |
| 6 | 2299 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 2300 | | { |
| 0 | 2301 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 2302 | | } |
| | 2303 | | // Deserialize Response |
| 6 | 2304 | | if ((int)_statusCode == 201) |
| | 2305 | | { |
| 6 | 2306 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2307 | | try |
| | 2308 | | { |
| 6 | 2309 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkBatchJob>(_responseContent, |
| 6 | 2310 | | } |
| 0 | 2311 | | catch (JsonException ex) |
| | 2312 | | { |
| 0 | 2313 | | _httpRequest.Dispose(); |
| 0 | 2314 | | if (_httpResponse != null) |
| | 2315 | | { |
| 0 | 2316 | | _httpResponse.Dispose(); |
| | 2317 | | } |
| 0 | 2318 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2319 | | } |
| | 2320 | | } |
| 6 | 2321 | | if (_shouldTrace) |
| | 2322 | | { |
| 0 | 2323 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2324 | | } |
| 6 | 2325 | | return _result; |
| 6 | 2326 | | } |
| | 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 | | { |
| 2 | 2357 | | if (Client.Endpoint == null) |
| | 2358 | | { |
| 0 | 2359 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 2360 | | } |
| | 2361 | | // Tracing |
| 2 | 2362 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 2363 | | string _invocationId = null; |
| 2 | 2364 | | if (_shouldTrace) |
| | 2365 | | { |
| 0 | 2366 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2367 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2368 | | tracingParameters.Add("batchId", batchId); |
| 0 | 2369 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2370 | | ServiceClientTracing.Enter(_invocationId, this, "GetSparkBatchJob", tracingParameters); |
| | 2371 | | } |
| | 2372 | | // Construct URL |
| 2 | 2373 | | var _baseUrl = Client.BaseUri; |
| 2 | 2374 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/batches/{batchId}"; |
| 2 | 2375 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 2 | 2376 | | _url = _url.Replace("{batchId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObj |
| 2 | 2377 | | List<string> _queryParameters = new List<string>(); |
| 2 | 2378 | | if (_queryParameters.Count > 0) |
| | 2379 | | { |
| 0 | 2380 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 2381 | | } |
| | 2382 | | // Create HTTP transport objects |
| 2 | 2383 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 2384 | | HttpResponseMessage _httpResponse = null; |
| 2 | 2385 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 2386 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2387 | | // Set Headers |
| 2 | 2388 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 2389 | | { |
| 2 | 2390 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 2391 | | } |
| 2 | 2392 | | if (Client.AcceptLanguage != null) |
| | 2393 | | { |
| 2 | 2394 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 2395 | | { |
| 0 | 2396 | | _httpRequest.Headers.Remove("accept-language"); |
| | 2397 | | } |
| 2 | 2398 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 2399 | | } |
| | 2400 | |
|
| | 2401 | |
|
| 2 | 2402 | | if (customHeaders != null) |
| | 2403 | | { |
| 0 | 2404 | | foreach(var _header in customHeaders) |
| | 2405 | | { |
| 0 | 2406 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2407 | | { |
| 0 | 2408 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2409 | | } |
| 0 | 2410 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2411 | | } |
| | 2412 | | } |
| | 2413 | |
|
| | 2414 | | // Serialize Request |
| 2 | 2415 | | string _requestContent = null; |
| | 2416 | | // Set Credentials |
| 2 | 2417 | | if (Client.Credentials != null) |
| | 2418 | | { |
| 2 | 2419 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2420 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2421 | | } |
| | 2422 | | // Send Request |
| 2 | 2423 | | if (_shouldTrace) |
| | 2424 | | { |
| 0 | 2425 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2426 | | } |
| 2 | 2427 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2428 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 2429 | | if (_shouldTrace) |
| | 2430 | | { |
| 0 | 2431 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2432 | | } |
| 2 | 2433 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 2434 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2435 | | string _responseContent = null; |
| 2 | 2436 | | if ((int)_statusCode != 200) |
| | 2437 | | { |
| 0 | 2438 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 2439 | | try |
| | 2440 | | { |
| 0 | 2441 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2442 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 2443 | | if (_errorBody != null) |
| | 2444 | | { |
| 0 | 2445 | | ex = new CloudException(_errorBody.Message); |
| 0 | 2446 | | ex.Body = _errorBody; |
| | 2447 | | } |
| 0 | 2448 | | } |
| 0 | 2449 | | catch (JsonException) |
| | 2450 | | { |
| | 2451 | | // Ignore the exception |
| 0 | 2452 | | } |
| 0 | 2453 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2454 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2455 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 2456 | | { |
| 0 | 2457 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 2458 | | } |
| 0 | 2459 | | if (_shouldTrace) |
| | 2460 | | { |
| 0 | 2461 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2462 | | } |
| 0 | 2463 | | _httpRequest.Dispose(); |
| 0 | 2464 | | if (_httpResponse != null) |
| | 2465 | | { |
| 0 | 2466 | | _httpResponse.Dispose(); |
| | 2467 | | } |
| 0 | 2468 | | throw ex; |
| | 2469 | | } |
| | 2470 | | // Create Result |
| 2 | 2471 | | var _result = new AzureOperationResponse<SparkBatchJob>(); |
| 2 | 2472 | | _result.Request = _httpRequest; |
| 2 | 2473 | | _result.Response = _httpResponse; |
| 2 | 2474 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 2475 | | { |
| 0 | 2476 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 2477 | | } |
| | 2478 | | // Deserialize Response |
| 2 | 2479 | | if ((int)_statusCode == 200) |
| | 2480 | | { |
| 2 | 2481 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2482 | | try |
| | 2483 | | { |
| 2 | 2484 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkBatchJob>(_responseContent, |
| 2 | 2485 | | } |
| 0 | 2486 | | catch (JsonException ex) |
| | 2487 | | { |
| 0 | 2488 | | _httpRequest.Dispose(); |
| 0 | 2489 | | if (_httpResponse != null) |
| | 2490 | | { |
| 0 | 2491 | | _httpResponse.Dispose(); |
| | 2492 | | } |
| 0 | 2493 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2494 | | } |
| | 2495 | | } |
| 2 | 2496 | | if (_shouldTrace) |
| | 2497 | | { |
| 0 | 2498 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2499 | | } |
| 2 | 2500 | | return _result; |
| 2 | 2501 | | } |
| | 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 | | { |
| 2 | 2535 | | if (Client.Endpoint == null) |
| | 2536 | | { |
| 0 | 2537 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 2538 | | } |
| | 2539 | | // Tracing |
| 2 | 2540 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 2541 | | string _invocationId = null; |
| 2 | 2542 | | if (_shouldTrace) |
| | 2543 | | { |
| 0 | 2544 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2545 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2546 | | tracingParameters.Add("requestedBy", requestedBy); |
| 0 | 2547 | | tracingParameters.Add("batchId", batchId); |
| 0 | 2548 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2549 | | ServiceClientTracing.Enter(_invocationId, this, "DeleteSparkBatchJob", tracingParameters); |
| | 2550 | | } |
| | 2551 | | // Construct URL |
| 2 | 2552 | | var _baseUrl = Client.BaseUri; |
| 2 | 2553 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/batches/{batchId}"; |
| 2 | 2554 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 2 | 2555 | | _url = _url.Replace("{batchId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObj |
| 2 | 2556 | | List<string> _queryParameters = new List<string>(); |
| 2 | 2557 | | if (_queryParameters.Count > 0) |
| | 2558 | | { |
| 0 | 2559 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 2560 | | } |
| | 2561 | | // Create HTTP transport objects |
| 2 | 2562 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 2563 | | HttpResponseMessage _httpResponse = null; |
| 2 | 2564 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 2 | 2565 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2566 | | // Set Headers |
| 2 | 2567 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 2568 | | { |
| 2 | 2569 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 2570 | | } |
| 2 | 2571 | | if (requestedBy != null) |
| | 2572 | | { |
| 2 | 2573 | | if (_httpRequest.Headers.Contains("X-Requested-By")) |
| | 2574 | | { |
| 0 | 2575 | | _httpRequest.Headers.Remove("X-Requested-By"); |
| | 2576 | | } |
| 2 | 2577 | | _httpRequest.Headers.TryAddWithoutValidation("X-Requested-By", requestedBy); |
| | 2578 | | } |
| 2 | 2579 | | if (Client.AcceptLanguage != null) |
| | 2580 | | { |
| 2 | 2581 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 2582 | | { |
| 0 | 2583 | | _httpRequest.Headers.Remove("accept-language"); |
| | 2584 | | } |
| 2 | 2585 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 2586 | | } |
| | 2587 | |
|
| | 2588 | |
|
| 2 | 2589 | | if (customHeaders != null) |
| | 2590 | | { |
| 0 | 2591 | | foreach(var _header in customHeaders) |
| | 2592 | | { |
| 0 | 2593 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2594 | | { |
| 0 | 2595 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2596 | | } |
| 0 | 2597 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2598 | | } |
| | 2599 | | } |
| | 2600 | |
|
| | 2601 | | // Serialize Request |
| 2 | 2602 | | string _requestContent = null; |
| | 2603 | | // Set Credentials |
| 2 | 2604 | | if (Client.Credentials != null) |
| | 2605 | | { |
| 2 | 2606 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2607 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2608 | | } |
| | 2609 | | // Send Request |
| 2 | 2610 | | if (_shouldTrace) |
| | 2611 | | { |
| 0 | 2612 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2613 | | } |
| 2 | 2614 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2615 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 2616 | | if (_shouldTrace) |
| | 2617 | | { |
| 0 | 2618 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2619 | | } |
| 2 | 2620 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 2621 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2622 | | string _responseContent = null; |
| 2 | 2623 | | if ((int)_statusCode != 200) |
| | 2624 | | { |
| 0 | 2625 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 2626 | | try |
| | 2627 | | { |
| 0 | 2628 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2629 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 2630 | | if (_errorBody != null) |
| | 2631 | | { |
| 0 | 2632 | | ex = new CloudException(_errorBody.Message); |
| 0 | 2633 | | ex.Body = _errorBody; |
| | 2634 | | } |
| 0 | 2635 | | } |
| 0 | 2636 | | catch (JsonException) |
| | 2637 | | { |
| | 2638 | | // Ignore the exception |
| 0 | 2639 | | } |
| 0 | 2640 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2641 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2642 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 2643 | | { |
| 0 | 2644 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 2645 | | } |
| 0 | 2646 | | if (_shouldTrace) |
| | 2647 | | { |
| 0 | 2648 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2649 | | } |
| 0 | 2650 | | _httpRequest.Dispose(); |
| 0 | 2651 | | if (_httpResponse != null) |
| | 2652 | | { |
| 0 | 2653 | | _httpResponse.Dispose(); |
| | 2654 | | } |
| 0 | 2655 | | throw ex; |
| | 2656 | | } |
| | 2657 | | // Create Result |
| 2 | 2658 | | var _result = new AzureOperationResponse<SparkJobDeletedResult>(); |
| 2 | 2659 | | _result.Request = _httpRequest; |
| 2 | 2660 | | _result.Response = _httpResponse; |
| 2 | 2661 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 2662 | | { |
| 0 | 2663 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 2664 | | } |
| | 2665 | | // Deserialize Response |
| 2 | 2666 | | if ((int)_statusCode == 200) |
| | 2667 | | { |
| 2 | 2668 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2669 | | try |
| | 2670 | | { |
| 2 | 2671 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkJobDeletedResult>(_response |
| 2 | 2672 | | } |
| 0 | 2673 | | catch (JsonException ex) |
| | 2674 | | { |
| 0 | 2675 | | _httpRequest.Dispose(); |
| 0 | 2676 | | if (_httpResponse != null) |
| | 2677 | | { |
| 0 | 2678 | | _httpResponse.Dispose(); |
| | 2679 | | } |
| 0 | 2680 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2681 | | } |
| | 2682 | | } |
| 2 | 2683 | | if (_shouldTrace) |
| | 2684 | | { |
| 0 | 2685 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2686 | | } |
| 2 | 2687 | | return _result; |
| 2 | 2688 | | } |
| | 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 | | { |
| 0 | 2726 | | if (Client.Endpoint == null) |
| | 2727 | | { |
| 0 | 2728 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 2729 | | } |
| | 2730 | | // Tracing |
| 0 | 2731 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 2732 | | string _invocationId = null; |
| 0 | 2733 | | if (_shouldTrace) |
| | 2734 | | { |
| 0 | 2735 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2736 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2737 | | tracingParameters.Add("batchId", batchId); |
| 0 | 2738 | | tracingParameters.Add("fromParameter", fromParameter); |
| 0 | 2739 | | tracingParameters.Add("size", size); |
| 0 | 2740 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2741 | | ServiceClientTracing.Enter(_invocationId, this, "GetSparkBatchLog", tracingParameters); |
| | 2742 | | } |
| | 2743 | | // Construct URL |
| 0 | 2744 | | var _baseUrl = Client.BaseUri; |
| 0 | 2745 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/batches/{batchId}/log"; |
| 0 | 2746 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 0 | 2747 | | _url = _url.Replace("{batchId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObj |
| 0 | 2748 | | List<string> _queryParameters = new List<string>(); |
| 0 | 2749 | | if (fromParameter != null) |
| | 2750 | | { |
| 0 | 2751 | | _queryParameters.Add(string.Format("from={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo |
| | 2752 | | } |
| 0 | 2753 | | if (size != null) |
| | 2754 | | { |
| 0 | 2755 | | _queryParameters.Add(string.Format("size={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo |
| | 2756 | | } |
| 0 | 2757 | | if (_queryParameters.Count > 0) |
| | 2758 | | { |
| 0 | 2759 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 2760 | | } |
| | 2761 | | // Create HTTP transport objects |
| 0 | 2762 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 2763 | | HttpResponseMessage _httpResponse = null; |
| 0 | 2764 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 2765 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2766 | | // Set Headers |
| 0 | 2767 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 2768 | | { |
| 0 | 2769 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 2770 | | } |
| 0 | 2771 | | if (Client.AcceptLanguage != null) |
| | 2772 | | { |
| 0 | 2773 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 2774 | | { |
| 0 | 2775 | | _httpRequest.Headers.Remove("accept-language"); |
| | 2776 | | } |
| 0 | 2777 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 2778 | | } |
| | 2779 | |
|
| | 2780 | |
|
| 0 | 2781 | | if (customHeaders != null) |
| | 2782 | | { |
| 0 | 2783 | | foreach(var _header in customHeaders) |
| | 2784 | | { |
| 0 | 2785 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2786 | | { |
| 0 | 2787 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2788 | | } |
| 0 | 2789 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2790 | | } |
| | 2791 | | } |
| | 2792 | |
|
| | 2793 | | // Serialize Request |
| 0 | 2794 | | string _requestContent = null; |
| | 2795 | | // Set Credentials |
| 0 | 2796 | | if (Client.Credentials != null) |
| | 2797 | | { |
| 0 | 2798 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2799 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2800 | | } |
| | 2801 | | // Send Request |
| 0 | 2802 | | if (_shouldTrace) |
| | 2803 | | { |
| 0 | 2804 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2805 | | } |
| 0 | 2806 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2807 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 2808 | | if (_shouldTrace) |
| | 2809 | | { |
| 0 | 2810 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2811 | | } |
| 0 | 2812 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 2813 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2814 | | string _responseContent = null; |
| 0 | 2815 | | if ((int)_statusCode != 200) |
| | 2816 | | { |
| 0 | 2817 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 2818 | | try |
| | 2819 | | { |
| 0 | 2820 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2821 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 2822 | | if (_errorBody != null) |
| | 2823 | | { |
| 0 | 2824 | | ex = new CloudException(_errorBody.Message); |
| 0 | 2825 | | ex.Body = _errorBody; |
| | 2826 | | } |
| 0 | 2827 | | } |
| 0 | 2828 | | catch (JsonException) |
| | 2829 | | { |
| | 2830 | | // Ignore the exception |
| 0 | 2831 | | } |
| 0 | 2832 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2833 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2834 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 2835 | | { |
| 0 | 2836 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 2837 | | } |
| 0 | 2838 | | if (_shouldTrace) |
| | 2839 | | { |
| 0 | 2840 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2841 | | } |
| 0 | 2842 | | _httpRequest.Dispose(); |
| 0 | 2843 | | if (_httpResponse != null) |
| | 2844 | | { |
| 0 | 2845 | | _httpResponse.Dispose(); |
| | 2846 | | } |
| 0 | 2847 | | throw ex; |
| | 2848 | | } |
| | 2849 | | // Create Result |
| 0 | 2850 | | var _result = new AzureOperationResponse<SparkJobLog>(); |
| 0 | 2851 | | _result.Request = _httpRequest; |
| 0 | 2852 | | _result.Response = _httpResponse; |
| 0 | 2853 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 2854 | | { |
| 0 | 2855 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 2856 | | } |
| | 2857 | | // Deserialize Response |
| 0 | 2858 | | if ((int)_statusCode == 200) |
| | 2859 | | { |
| 0 | 2860 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2861 | | try |
| | 2862 | | { |
| 0 | 2863 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkJobLog>(_responseContent, C |
| 0 | 2864 | | } |
| 0 | 2865 | | catch (JsonException ex) |
| | 2866 | | { |
| 0 | 2867 | | _httpRequest.Dispose(); |
| 0 | 2868 | | if (_httpResponse != null) |
| | 2869 | | { |
| 0 | 2870 | | _httpResponse.Dispose(); |
| | 2871 | | } |
| 0 | 2872 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2873 | | } |
| | 2874 | | } |
| 0 | 2875 | | if (_shouldTrace) |
| | 2876 | | { |
| 0 | 2877 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2878 | | } |
| 0 | 2879 | | return _result; |
| 0 | 2880 | | } |
| | 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 | | { |
| 0 | 2911 | | if (Client.Endpoint == null) |
| | 2912 | | { |
| 0 | 2913 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 2914 | | } |
| | 2915 | | // Tracing |
| 0 | 2916 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 2917 | | string _invocationId = null; |
| 0 | 2918 | | if (_shouldTrace) |
| | 2919 | | { |
| 0 | 2920 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2921 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2922 | | tracingParameters.Add("batchId", batchId); |
| 0 | 2923 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2924 | | ServiceClientTracing.Enter(_invocationId, this, "GetSparkBatchState", tracingParameters); |
| | 2925 | | } |
| | 2926 | | // Construct URL |
| 0 | 2927 | | var _baseUrl = Client.BaseUri; |
| 0 | 2928 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/batches/{batchId}/state"; |
| 0 | 2929 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 0 | 2930 | | _url = _url.Replace("{batchId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObj |
| 0 | 2931 | | List<string> _queryParameters = new List<string>(); |
| 0 | 2932 | | if (_queryParameters.Count > 0) |
| | 2933 | | { |
| 0 | 2934 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 2935 | | } |
| | 2936 | | // Create HTTP transport objects |
| 0 | 2937 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 2938 | | HttpResponseMessage _httpResponse = null; |
| 0 | 2939 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 2940 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2941 | | // Set Headers |
| 0 | 2942 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 2943 | | { |
| 0 | 2944 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 2945 | | } |
| 0 | 2946 | | if (Client.AcceptLanguage != null) |
| | 2947 | | { |
| 0 | 2948 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 2949 | | { |
| 0 | 2950 | | _httpRequest.Headers.Remove("accept-language"); |
| | 2951 | | } |
| 0 | 2952 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 2953 | | } |
| | 2954 | |
|
| | 2955 | |
|
| 0 | 2956 | | if (customHeaders != null) |
| | 2957 | | { |
| 0 | 2958 | | foreach(var _header in customHeaders) |
| | 2959 | | { |
| 0 | 2960 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2961 | | { |
| 0 | 2962 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2963 | | } |
| 0 | 2964 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2965 | | } |
| | 2966 | | } |
| | 2967 | |
|
| | 2968 | | // Serialize Request |
| 0 | 2969 | | string _requestContent = null; |
| | 2970 | | // Set Credentials |
| 0 | 2971 | | if (Client.Credentials != null) |
| | 2972 | | { |
| 0 | 2973 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2974 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2975 | | } |
| | 2976 | | // Send Request |
| 0 | 2977 | | if (_shouldTrace) |
| | 2978 | | { |
| 0 | 2979 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2980 | | } |
| 0 | 2981 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2982 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 2983 | | if (_shouldTrace) |
| | 2984 | | { |
| 0 | 2985 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2986 | | } |
| 0 | 2987 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 2988 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2989 | | string _responseContent = null; |
| 0 | 2990 | | if ((int)_statusCode != 200) |
| | 2991 | | { |
| 0 | 2992 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 2993 | | try |
| | 2994 | | { |
| 0 | 2995 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2996 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 2997 | | if (_errorBody != null) |
| | 2998 | | { |
| 0 | 2999 | | ex = new CloudException(_errorBody.Message); |
| 0 | 3000 | | ex.Body = _errorBody; |
| | 3001 | | } |
| 0 | 3002 | | } |
| 0 | 3003 | | catch (JsonException) |
| | 3004 | | { |
| | 3005 | | // Ignore the exception |
| 0 | 3006 | | } |
| 0 | 3007 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3008 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3009 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 3010 | | { |
| 0 | 3011 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 3012 | | } |
| 0 | 3013 | | if (_shouldTrace) |
| | 3014 | | { |
| 0 | 3015 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3016 | | } |
| 0 | 3017 | | _httpRequest.Dispose(); |
| 0 | 3018 | | if (_httpResponse != null) |
| | 3019 | | { |
| 0 | 3020 | | _httpResponse.Dispose(); |
| | 3021 | | } |
| 0 | 3022 | | throw ex; |
| | 3023 | | } |
| | 3024 | | // Create Result |
| 0 | 3025 | | var _result = new AzureOperationResponse<SparkJobState>(); |
| 0 | 3026 | | _result.Request = _httpRequest; |
| 0 | 3027 | | _result.Response = _httpResponse; |
| 0 | 3028 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 3029 | | { |
| 0 | 3030 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 3031 | | } |
| | 3032 | | // Deserialize Response |
| 0 | 3033 | | if ((int)_statusCode == 200) |
| | 3034 | | { |
| 0 | 3035 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3036 | | try |
| | 3037 | | { |
| 0 | 3038 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkJobState>(_responseContent, |
| 0 | 3039 | | } |
| 0 | 3040 | | catch (JsonException ex) |
| | 3041 | | { |
| 0 | 3042 | | _httpRequest.Dispose(); |
| 0 | 3043 | | if (_httpResponse != null) |
| | 3044 | | { |
| 0 | 3045 | | _httpResponse.Dispose(); |
| | 3046 | | } |
| 0 | 3047 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3048 | | } |
| | 3049 | | } |
| 0 | 3050 | | if (_shouldTrace) |
| | 3051 | | { |
| 0 | 3052 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3053 | | } |
| 0 | 3054 | | return _result; |
| 0 | 3055 | | } |
| | 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 | | { |
| 10 | 3090 | | if (Client.Endpoint == null) |
| | 3091 | | { |
| 0 | 3092 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 3093 | | } |
| | 3094 | | // Tracing |
| 10 | 3095 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 10 | 3096 | | string _invocationId = null; |
| 10 | 3097 | | if (_shouldTrace) |
| | 3098 | | { |
| 0 | 3099 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3100 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3101 | | tracingParameters.Add("fromParameter", fromParameter); |
| 0 | 3102 | | tracingParameters.Add("size", size); |
| 0 | 3103 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3104 | | ServiceClientTracing.Enter(_invocationId, this, "ListSparkSessionJob", tracingParameters); |
| | 3105 | | } |
| | 3106 | | // Construct URL |
| 10 | 3107 | | var _baseUrl = Client.BaseUri; |
| 10 | 3108 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions"; |
| 10 | 3109 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 10 | 3110 | | List<string> _queryParameters = new List<string>(); |
| 10 | 3111 | | if (fromParameter != null) |
| | 3112 | | { |
| 2 | 3113 | | _queryParameters.Add(string.Format("from={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo |
| | 3114 | | } |
| 10 | 3115 | | if (size != null) |
| | 3116 | | { |
| 2 | 3117 | | _queryParameters.Add(string.Format("size={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo |
| | 3118 | | } |
| 10 | 3119 | | if (_queryParameters.Count > 0) |
| | 3120 | | { |
| 2 | 3121 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 3122 | | } |
| | 3123 | | // Create HTTP transport objects |
| 10 | 3124 | | var _httpRequest = new HttpRequestMessage(); |
| 10 | 3125 | | HttpResponseMessage _httpResponse = null; |
| 10 | 3126 | | _httpRequest.Method = new HttpMethod("GET"); |
| 10 | 3127 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3128 | | // Set Headers |
| 10 | 3129 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 3130 | | { |
| 10 | 3131 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 3132 | | } |
| 10 | 3133 | | if (Client.AcceptLanguage != null) |
| | 3134 | | { |
| 10 | 3135 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 3136 | | { |
| 0 | 3137 | | _httpRequest.Headers.Remove("accept-language"); |
| | 3138 | | } |
| 10 | 3139 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 3140 | | } |
| | 3141 | |
|
| | 3142 | |
|
| 10 | 3143 | | if (customHeaders != null) |
| | 3144 | | { |
| 0 | 3145 | | foreach(var _header in customHeaders) |
| | 3146 | | { |
| 0 | 3147 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3148 | | { |
| 0 | 3149 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3150 | | } |
| 0 | 3151 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3152 | | } |
| | 3153 | | } |
| | 3154 | |
|
| | 3155 | | // Serialize Request |
| 10 | 3156 | | string _requestContent = null; |
| | 3157 | | // Set Credentials |
| 10 | 3158 | | if (Client.Credentials != null) |
| | 3159 | | { |
| 10 | 3160 | | cancellationToken.ThrowIfCancellationRequested(); |
| 10 | 3161 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3162 | | } |
| | 3163 | | // Send Request |
| 10 | 3164 | | if (_shouldTrace) |
| | 3165 | | { |
| 0 | 3166 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3167 | | } |
| 10 | 3168 | | cancellationToken.ThrowIfCancellationRequested(); |
| 10 | 3169 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 10 | 3170 | | if (_shouldTrace) |
| | 3171 | | { |
| 0 | 3172 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3173 | | } |
| 10 | 3174 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 10 | 3175 | | cancellationToken.ThrowIfCancellationRequested(); |
| 10 | 3176 | | string _responseContent = null; |
| 10 | 3177 | | if ((int)_statusCode != 200) |
| | 3178 | | { |
| 0 | 3179 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 3180 | | try |
| | 3181 | | { |
| 0 | 3182 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3183 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 3184 | | if (_errorBody != null) |
| | 3185 | | { |
| 0 | 3186 | | ex = new CloudException(_errorBody.Message); |
| 0 | 3187 | | ex.Body = _errorBody; |
| | 3188 | | } |
| 0 | 3189 | | } |
| 0 | 3190 | | catch (JsonException) |
| | 3191 | | { |
| | 3192 | | // Ignore the exception |
| 0 | 3193 | | } |
| 0 | 3194 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3195 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3196 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 3197 | | { |
| 0 | 3198 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 3199 | | } |
| 0 | 3200 | | if (_shouldTrace) |
| | 3201 | | { |
| 0 | 3202 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3203 | | } |
| 0 | 3204 | | _httpRequest.Dispose(); |
| 0 | 3205 | | if (_httpResponse != null) |
| | 3206 | | { |
| 0 | 3207 | | _httpResponse.Dispose(); |
| | 3208 | | } |
| 0 | 3209 | | throw ex; |
| | 3210 | | } |
| | 3211 | | // Create Result |
| 10 | 3212 | | var _result = new AzureOperationResponse<SparkSessionCollection>(); |
| 10 | 3213 | | _result.Request = _httpRequest; |
| 10 | 3214 | | _result.Response = _httpResponse; |
| 10 | 3215 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 3216 | | { |
| 0 | 3217 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 3218 | | } |
| | 3219 | | // Deserialize Response |
| 10 | 3220 | | if ((int)_statusCode == 200) |
| | 3221 | | { |
| 10 | 3222 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3223 | | try |
| | 3224 | | { |
| 10 | 3225 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkSessionCollection>(_respons |
| 10 | 3226 | | } |
| 0 | 3227 | | catch (JsonException ex) |
| | 3228 | | { |
| 0 | 3229 | | _httpRequest.Dispose(); |
| 0 | 3230 | | if (_httpResponse != null) |
| | 3231 | | { |
| 0 | 3232 | | _httpResponse.Dispose(); |
| | 3233 | | } |
| 0 | 3234 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3235 | | } |
| | 3236 | | } |
| 10 | 3237 | | if (_shouldTrace) |
| | 3238 | | { |
| 0 | 3239 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3240 | | } |
| 10 | 3241 | | return _result; |
| 10 | 3242 | | } |
| | 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 | | { |
| 8 | 3276 | | if (Client.Endpoint == null) |
| | 3277 | | { |
| 0 | 3278 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 3279 | | } |
| 8 | 3280 | | if (sparkSessionJobRequest == null) |
| | 3281 | | { |
| 0 | 3282 | | throw new ValidationException(ValidationRules.CannotBeNull, "sparkSessionJobRequest"); |
| | 3283 | | } |
| | 3284 | | // Tracing |
| 8 | 3285 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 8 | 3286 | | string _invocationId = null; |
| 8 | 3287 | | if (_shouldTrace) |
| | 3288 | | { |
| 0 | 3289 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3290 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3291 | | tracingParameters.Add("requestedBy", requestedBy); |
| 0 | 3292 | | tracingParameters.Add("sparkSessionJobRequest", sparkSessionJobRequest); |
| 0 | 3293 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3294 | | ServiceClientTracing.Enter(_invocationId, this, "SubmitSparkSessionJob", tracingParameters); |
| | 3295 | | } |
| | 3296 | | // Construct URL |
| 8 | 3297 | | var _baseUrl = Client.BaseUri; |
| 8 | 3298 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions"; |
| 8 | 3299 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 8 | 3300 | | List<string> _queryParameters = new List<string>(); |
| 8 | 3301 | | if (_queryParameters.Count > 0) |
| | 3302 | | { |
| 0 | 3303 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 3304 | | } |
| | 3305 | | // Create HTTP transport objects |
| 8 | 3306 | | var _httpRequest = new HttpRequestMessage(); |
| 8 | 3307 | | HttpResponseMessage _httpResponse = null; |
| 8 | 3308 | | _httpRequest.Method = new HttpMethod("POST"); |
| 8 | 3309 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3310 | | // Set Headers |
| 8 | 3311 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 3312 | | { |
| 8 | 3313 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 3314 | | } |
| 8 | 3315 | | if (requestedBy != null) |
| | 3316 | | { |
| 8 | 3317 | | if (_httpRequest.Headers.Contains("X-Requested-By")) |
| | 3318 | | { |
| 0 | 3319 | | _httpRequest.Headers.Remove("X-Requested-By"); |
| | 3320 | | } |
| 8 | 3321 | | _httpRequest.Headers.TryAddWithoutValidation("X-Requested-By", requestedBy); |
| | 3322 | | } |
| 8 | 3323 | | if (Client.AcceptLanguage != null) |
| | 3324 | | { |
| 8 | 3325 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 3326 | | { |
| 0 | 3327 | | _httpRequest.Headers.Remove("accept-language"); |
| | 3328 | | } |
| 8 | 3329 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 3330 | | } |
| | 3331 | |
|
| | 3332 | |
|
| 8 | 3333 | | if (customHeaders != null) |
| | 3334 | | { |
| 0 | 3335 | | foreach(var _header in customHeaders) |
| | 3336 | | { |
| 0 | 3337 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3338 | | { |
| 0 | 3339 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3340 | | } |
| 0 | 3341 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3342 | | } |
| | 3343 | | } |
| | 3344 | |
|
| | 3345 | | // Serialize Request |
| 8 | 3346 | | string _requestContent = null; |
| 8 | 3347 | | if(sparkSessionJobRequest != null) |
| | 3348 | | { |
| 8 | 3349 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(sparkSessionJobRequest, Client.Seri |
| 8 | 3350 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 8 | 3351 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 3352 | | } |
| | 3353 | | // Set Credentials |
| 8 | 3354 | | if (Client.Credentials != null) |
| | 3355 | | { |
| 8 | 3356 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 3357 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3358 | | } |
| | 3359 | | // Send Request |
| 8 | 3360 | | if (_shouldTrace) |
| | 3361 | | { |
| 0 | 3362 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3363 | | } |
| 8 | 3364 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 3365 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 8 | 3366 | | if (_shouldTrace) |
| | 3367 | | { |
| 0 | 3368 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3369 | | } |
| 8 | 3370 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 8 | 3371 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 3372 | | string _responseContent = null; |
| 8 | 3373 | | if ((int)_statusCode != 201) |
| | 3374 | | { |
| 0 | 3375 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 3376 | | try |
| | 3377 | | { |
| 0 | 3378 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3379 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 3380 | | if (_errorBody != null) |
| | 3381 | | { |
| 0 | 3382 | | ex = new CloudException(_errorBody.Message); |
| 0 | 3383 | | ex.Body = _errorBody; |
| | 3384 | | } |
| 0 | 3385 | | } |
| 0 | 3386 | | catch (JsonException) |
| | 3387 | | { |
| | 3388 | | // Ignore the exception |
| 0 | 3389 | | } |
| 0 | 3390 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3391 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3392 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 3393 | | { |
| 0 | 3394 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 3395 | | } |
| 0 | 3396 | | if (_shouldTrace) |
| | 3397 | | { |
| 0 | 3398 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3399 | | } |
| 0 | 3400 | | _httpRequest.Dispose(); |
| 0 | 3401 | | if (_httpResponse != null) |
| | 3402 | | { |
| 0 | 3403 | | _httpResponse.Dispose(); |
| | 3404 | | } |
| 0 | 3405 | | throw ex; |
| | 3406 | | } |
| | 3407 | | // Create Result |
| 8 | 3408 | | var _result = new AzureOperationResponse<SparkSessionJob>(); |
| 8 | 3409 | | _result.Request = _httpRequest; |
| 8 | 3410 | | _result.Response = _httpResponse; |
| 8 | 3411 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 3412 | | { |
| 0 | 3413 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 3414 | | } |
| | 3415 | | // Deserialize Response |
| 8 | 3416 | | if ((int)_statusCode == 201) |
| | 3417 | | { |
| 8 | 3418 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3419 | | try |
| | 3420 | | { |
| 8 | 3421 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkSessionJob>(_responseConten |
| 8 | 3422 | | } |
| 0 | 3423 | | catch (JsonException ex) |
| | 3424 | | { |
| 0 | 3425 | | _httpRequest.Dispose(); |
| 0 | 3426 | | if (_httpResponse != null) |
| | 3427 | | { |
| 0 | 3428 | | _httpResponse.Dispose(); |
| | 3429 | | } |
| 0 | 3430 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3431 | | } |
| | 3432 | | } |
| 8 | 3433 | | if (_shouldTrace) |
| | 3434 | | { |
| 0 | 3435 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3436 | | } |
| 8 | 3437 | | return _result; |
| 8 | 3438 | | } |
| | 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 | | { |
| 2 | 3469 | | if (Client.Endpoint == null) |
| | 3470 | | { |
| 0 | 3471 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 3472 | | } |
| | 3473 | | // Tracing |
| 2 | 3474 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 3475 | | string _invocationId = null; |
| 2 | 3476 | | if (_shouldTrace) |
| | 3477 | | { |
| 0 | 3478 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3479 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3480 | | tracingParameters.Add("sessionId", sessionId); |
| 0 | 3481 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3482 | | ServiceClientTracing.Enter(_invocationId, this, "GetSparkSessionJob", tracingParameters); |
| | 3483 | | } |
| | 3484 | | // Construct URL |
| 2 | 3485 | | var _baseUrl = Client.BaseUri; |
| 2 | 3486 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions/{sessionId}"; |
| 2 | 3487 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 2 | 3488 | | _url = _url.Replace("{sessionId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO |
| 2 | 3489 | | List<string> _queryParameters = new List<string>(); |
| 2 | 3490 | | if (_queryParameters.Count > 0) |
| | 3491 | | { |
| 0 | 3492 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 3493 | | } |
| | 3494 | | // Create HTTP transport objects |
| 2 | 3495 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 3496 | | HttpResponseMessage _httpResponse = null; |
| 2 | 3497 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 3498 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3499 | | // Set Headers |
| 2 | 3500 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 3501 | | { |
| 2 | 3502 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 3503 | | } |
| 2 | 3504 | | if (Client.AcceptLanguage != null) |
| | 3505 | | { |
| 2 | 3506 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 3507 | | { |
| 0 | 3508 | | _httpRequest.Headers.Remove("accept-language"); |
| | 3509 | | } |
| 2 | 3510 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 3511 | | } |
| | 3512 | |
|
| | 3513 | |
|
| 2 | 3514 | | if (customHeaders != null) |
| | 3515 | | { |
| 0 | 3516 | | foreach(var _header in customHeaders) |
| | 3517 | | { |
| 0 | 3518 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3519 | | { |
| 0 | 3520 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3521 | | } |
| 0 | 3522 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3523 | | } |
| | 3524 | | } |
| | 3525 | |
|
| | 3526 | | // Serialize Request |
| 2 | 3527 | | string _requestContent = null; |
| | 3528 | | // Set Credentials |
| 2 | 3529 | | if (Client.Credentials != null) |
| | 3530 | | { |
| 2 | 3531 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3532 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3533 | | } |
| | 3534 | | // Send Request |
| 2 | 3535 | | if (_shouldTrace) |
| | 3536 | | { |
| 0 | 3537 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3538 | | } |
| 2 | 3539 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3540 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 3541 | | if (_shouldTrace) |
| | 3542 | | { |
| 0 | 3543 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3544 | | } |
| 2 | 3545 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 3546 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3547 | | string _responseContent = null; |
| 2 | 3548 | | if ((int)_statusCode != 200) |
| | 3549 | | { |
| 0 | 3550 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 3551 | | try |
| | 3552 | | { |
| 0 | 3553 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3554 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 3555 | | if (_errorBody != null) |
| | 3556 | | { |
| 0 | 3557 | | ex = new CloudException(_errorBody.Message); |
| 0 | 3558 | | ex.Body = _errorBody; |
| | 3559 | | } |
| 0 | 3560 | | } |
| 0 | 3561 | | catch (JsonException) |
| | 3562 | | { |
| | 3563 | | // Ignore the exception |
| 0 | 3564 | | } |
| 0 | 3565 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3566 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3567 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 3568 | | { |
| 0 | 3569 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 3570 | | } |
| 0 | 3571 | | if (_shouldTrace) |
| | 3572 | | { |
| 0 | 3573 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3574 | | } |
| 0 | 3575 | | _httpRequest.Dispose(); |
| 0 | 3576 | | if (_httpResponse != null) |
| | 3577 | | { |
| 0 | 3578 | | _httpResponse.Dispose(); |
| | 3579 | | } |
| 0 | 3580 | | throw ex; |
| | 3581 | | } |
| | 3582 | | // Create Result |
| 2 | 3583 | | var _result = new AzureOperationResponse<SparkSessionJob>(); |
| 2 | 3584 | | _result.Request = _httpRequest; |
| 2 | 3585 | | _result.Response = _httpResponse; |
| 2 | 3586 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 3587 | | { |
| 0 | 3588 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 3589 | | } |
| | 3590 | | // Deserialize Response |
| 2 | 3591 | | if ((int)_statusCode == 200) |
| | 3592 | | { |
| 2 | 3593 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3594 | | try |
| | 3595 | | { |
| 2 | 3596 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkSessionJob>(_responseConten |
| 2 | 3597 | | } |
| 0 | 3598 | | catch (JsonException ex) |
| | 3599 | | { |
| 0 | 3600 | | _httpRequest.Dispose(); |
| 0 | 3601 | | if (_httpResponse != null) |
| | 3602 | | { |
| 0 | 3603 | | _httpResponse.Dispose(); |
| | 3604 | | } |
| 0 | 3605 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3606 | | } |
| | 3607 | | } |
| 2 | 3608 | | if (_shouldTrace) |
| | 3609 | | { |
| 0 | 3610 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3611 | | } |
| 2 | 3612 | | return _result; |
| 2 | 3613 | | } |
| | 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 | | { |
| 8 | 3647 | | if (Client.Endpoint == null) |
| | 3648 | | { |
| 0 | 3649 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 3650 | | } |
| | 3651 | | // Tracing |
| 8 | 3652 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 8 | 3653 | | string _invocationId = null; |
| 8 | 3654 | | if (_shouldTrace) |
| | 3655 | | { |
| 0 | 3656 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3657 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3658 | | tracingParameters.Add("requestedBy", requestedBy); |
| 0 | 3659 | | tracingParameters.Add("sessionId", sessionId); |
| 0 | 3660 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3661 | | ServiceClientTracing.Enter(_invocationId, this, "DeleteSparkSessionJob", tracingParameters); |
| | 3662 | | } |
| | 3663 | | // Construct URL |
| 8 | 3664 | | var _baseUrl = Client.BaseUri; |
| 8 | 3665 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions/{sessionId}"; |
| 8 | 3666 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 8 | 3667 | | _url = _url.Replace("{sessionId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO |
| 8 | 3668 | | List<string> _queryParameters = new List<string>(); |
| 8 | 3669 | | if (_queryParameters.Count > 0) |
| | 3670 | | { |
| 0 | 3671 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 3672 | | } |
| | 3673 | | // Create HTTP transport objects |
| 8 | 3674 | | var _httpRequest = new HttpRequestMessage(); |
| 8 | 3675 | | HttpResponseMessage _httpResponse = null; |
| 8 | 3676 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 8 | 3677 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3678 | | // Set Headers |
| 8 | 3679 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 3680 | | { |
| 8 | 3681 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 3682 | | } |
| 8 | 3683 | | if (requestedBy != null) |
| | 3684 | | { |
| 8 | 3685 | | if (_httpRequest.Headers.Contains("X-Requested-By")) |
| | 3686 | | { |
| 0 | 3687 | | _httpRequest.Headers.Remove("X-Requested-By"); |
| | 3688 | | } |
| 8 | 3689 | | _httpRequest.Headers.TryAddWithoutValidation("X-Requested-By", requestedBy); |
| | 3690 | | } |
| 8 | 3691 | | if (Client.AcceptLanguage != null) |
| | 3692 | | { |
| 8 | 3693 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 3694 | | { |
| 0 | 3695 | | _httpRequest.Headers.Remove("accept-language"); |
| | 3696 | | } |
| 8 | 3697 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 3698 | | } |
| | 3699 | |
|
| | 3700 | |
|
| 8 | 3701 | | if (customHeaders != null) |
| | 3702 | | { |
| 0 | 3703 | | foreach(var _header in customHeaders) |
| | 3704 | | { |
| 0 | 3705 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3706 | | { |
| 0 | 3707 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3708 | | } |
| 0 | 3709 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3710 | | } |
| | 3711 | | } |
| | 3712 | |
|
| | 3713 | | // Serialize Request |
| 8 | 3714 | | string _requestContent = null; |
| | 3715 | | // Set Credentials |
| 8 | 3716 | | if (Client.Credentials != null) |
| | 3717 | | { |
| 8 | 3718 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 3719 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3720 | | } |
| | 3721 | | // Send Request |
| 8 | 3722 | | if (_shouldTrace) |
| | 3723 | | { |
| 0 | 3724 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3725 | | } |
| 8 | 3726 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 3727 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 8 | 3728 | | if (_shouldTrace) |
| | 3729 | | { |
| 0 | 3730 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3731 | | } |
| 8 | 3732 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 8 | 3733 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 3734 | | string _responseContent = null; |
| 8 | 3735 | | if ((int)_statusCode != 200) |
| | 3736 | | { |
| 0 | 3737 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 3738 | | try |
| | 3739 | | { |
| 0 | 3740 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3741 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 3742 | | if (_errorBody != null) |
| | 3743 | | { |
| 0 | 3744 | | ex = new CloudException(_errorBody.Message); |
| 0 | 3745 | | ex.Body = _errorBody; |
| | 3746 | | } |
| 0 | 3747 | | } |
| 0 | 3748 | | catch (JsonException) |
| | 3749 | | { |
| | 3750 | | // Ignore the exception |
| 0 | 3751 | | } |
| 0 | 3752 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3753 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3754 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 3755 | | { |
| 0 | 3756 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 3757 | | } |
| 0 | 3758 | | if (_shouldTrace) |
| | 3759 | | { |
| 0 | 3760 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3761 | | } |
| 0 | 3762 | | _httpRequest.Dispose(); |
| 0 | 3763 | | if (_httpResponse != null) |
| | 3764 | | { |
| 0 | 3765 | | _httpResponse.Dispose(); |
| | 3766 | | } |
| 0 | 3767 | | throw ex; |
| | 3768 | | } |
| | 3769 | | // Create Result |
| 8 | 3770 | | var _result = new AzureOperationResponse<SparkJobDeletedResult>(); |
| 8 | 3771 | | _result.Request = _httpRequest; |
| 8 | 3772 | | _result.Response = _httpResponse; |
| 8 | 3773 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 3774 | | { |
| 0 | 3775 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 3776 | | } |
| | 3777 | | // Deserialize Response |
| 8 | 3778 | | if ((int)_statusCode == 200) |
| | 3779 | | { |
| 8 | 3780 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3781 | | try |
| | 3782 | | { |
| 8 | 3783 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkJobDeletedResult>(_response |
| 8 | 3784 | | } |
| 0 | 3785 | | catch (JsonException ex) |
| | 3786 | | { |
| 0 | 3787 | | _httpRequest.Dispose(); |
| 0 | 3788 | | if (_httpResponse != null) |
| | 3789 | | { |
| 0 | 3790 | | _httpResponse.Dispose(); |
| | 3791 | | } |
| 0 | 3792 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3793 | | } |
| | 3794 | | } |
| 8 | 3795 | | if (_shouldTrace) |
| | 3796 | | { |
| 0 | 3797 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3798 | | } |
| 8 | 3799 | | return _result; |
| 8 | 3800 | | } |
| | 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 | | { |
| 0 | 3838 | | if (Client.Endpoint == null) |
| | 3839 | | { |
| 0 | 3840 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 3841 | | } |
| | 3842 | | // Tracing |
| 0 | 3843 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 3844 | | string _invocationId = null; |
| 0 | 3845 | | if (_shouldTrace) |
| | 3846 | | { |
| 0 | 3847 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3848 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3849 | | tracingParameters.Add("sessionId", sessionId); |
| 0 | 3850 | | tracingParameters.Add("fromParameter", fromParameter); |
| 0 | 3851 | | tracingParameters.Add("size", size); |
| 0 | 3852 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3853 | | ServiceClientTracing.Enter(_invocationId, this, "GetSparkSessionLog", tracingParameters); |
| | 3854 | | } |
| | 3855 | | // Construct URL |
| 0 | 3856 | | var _baseUrl = Client.BaseUri; |
| 0 | 3857 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions/{sessionId}/log"; |
| 0 | 3858 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 0 | 3859 | | _url = _url.Replace("{sessionId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO |
| 0 | 3860 | | List<string> _queryParameters = new List<string>(); |
| 0 | 3861 | | if (fromParameter != null) |
| | 3862 | | { |
| 0 | 3863 | | _queryParameters.Add(string.Format("from={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo |
| | 3864 | | } |
| 0 | 3865 | | if (size != null) |
| | 3866 | | { |
| 0 | 3867 | | _queryParameters.Add(string.Format("size={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo |
| | 3868 | | } |
| 0 | 3869 | | if (_queryParameters.Count > 0) |
| | 3870 | | { |
| 0 | 3871 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 3872 | | } |
| | 3873 | | // Create HTTP transport objects |
| 0 | 3874 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 3875 | | HttpResponseMessage _httpResponse = null; |
| 0 | 3876 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 3877 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3878 | | // Set Headers |
| 0 | 3879 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 3880 | | { |
| 0 | 3881 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 3882 | | } |
| 0 | 3883 | | if (Client.AcceptLanguage != null) |
| | 3884 | | { |
| 0 | 3885 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 3886 | | { |
| 0 | 3887 | | _httpRequest.Headers.Remove("accept-language"); |
| | 3888 | | } |
| 0 | 3889 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 3890 | | } |
| | 3891 | |
|
| | 3892 | |
|
| 0 | 3893 | | if (customHeaders != null) |
| | 3894 | | { |
| 0 | 3895 | | foreach(var _header in customHeaders) |
| | 3896 | | { |
| 0 | 3897 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3898 | | { |
| 0 | 3899 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3900 | | } |
| 0 | 3901 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3902 | | } |
| | 3903 | | } |
| | 3904 | |
|
| | 3905 | | // Serialize Request |
| 0 | 3906 | | string _requestContent = null; |
| | 3907 | | // Set Credentials |
| 0 | 3908 | | if (Client.Credentials != null) |
| | 3909 | | { |
| 0 | 3910 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3911 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3912 | | } |
| | 3913 | | // Send Request |
| 0 | 3914 | | if (_shouldTrace) |
| | 3915 | | { |
| 0 | 3916 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3917 | | } |
| 0 | 3918 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3919 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 3920 | | if (_shouldTrace) |
| | 3921 | | { |
| 0 | 3922 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3923 | | } |
| 0 | 3924 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 3925 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3926 | | string _responseContent = null; |
| 0 | 3927 | | if ((int)_statusCode != 200) |
| | 3928 | | { |
| 0 | 3929 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 3930 | | try |
| | 3931 | | { |
| 0 | 3932 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3933 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 3934 | | if (_errorBody != null) |
| | 3935 | | { |
| 0 | 3936 | | ex = new CloudException(_errorBody.Message); |
| 0 | 3937 | | ex.Body = _errorBody; |
| | 3938 | | } |
| 0 | 3939 | | } |
| 0 | 3940 | | catch (JsonException) |
| | 3941 | | { |
| | 3942 | | // Ignore the exception |
| 0 | 3943 | | } |
| 0 | 3944 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3945 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3946 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 3947 | | { |
| 0 | 3948 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 3949 | | } |
| 0 | 3950 | | if (_shouldTrace) |
| | 3951 | | { |
| 0 | 3952 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3953 | | } |
| 0 | 3954 | | _httpRequest.Dispose(); |
| 0 | 3955 | | if (_httpResponse != null) |
| | 3956 | | { |
| 0 | 3957 | | _httpResponse.Dispose(); |
| | 3958 | | } |
| 0 | 3959 | | throw ex; |
| | 3960 | | } |
| | 3961 | | // Create Result |
| 0 | 3962 | | var _result = new AzureOperationResponse<SparkJobLog>(); |
| 0 | 3963 | | _result.Request = _httpRequest; |
| 0 | 3964 | | _result.Response = _httpResponse; |
| 0 | 3965 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 3966 | | { |
| 0 | 3967 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 3968 | | } |
| | 3969 | | // Deserialize Response |
| 0 | 3970 | | if ((int)_statusCode == 200) |
| | 3971 | | { |
| 0 | 3972 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3973 | | try |
| | 3974 | | { |
| 0 | 3975 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkJobLog>(_responseContent, C |
| 0 | 3976 | | } |
| 0 | 3977 | | catch (JsonException ex) |
| | 3978 | | { |
| 0 | 3979 | | _httpRequest.Dispose(); |
| 0 | 3980 | | if (_httpResponse != null) |
| | 3981 | | { |
| 0 | 3982 | | _httpResponse.Dispose(); |
| | 3983 | | } |
| 0 | 3984 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3985 | | } |
| | 3986 | | } |
| 0 | 3987 | | if (_shouldTrace) |
| | 3988 | | { |
| 0 | 3989 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3990 | | } |
| 0 | 3991 | | return _result; |
| 0 | 3992 | | } |
| | 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 | | { |
| 0 | 4023 | | if (Client.Endpoint == null) |
| | 4024 | | { |
| 0 | 4025 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 4026 | | } |
| | 4027 | | // Tracing |
| 0 | 4028 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 4029 | | string _invocationId = null; |
| 0 | 4030 | | if (_shouldTrace) |
| | 4031 | | { |
| 0 | 4032 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 4033 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 4034 | | tracingParameters.Add("sessionId", sessionId); |
| 0 | 4035 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 4036 | | ServiceClientTracing.Enter(_invocationId, this, "GetSparkSessionState", tracingParameters); |
| | 4037 | | } |
| | 4038 | | // Construct URL |
| 0 | 4039 | | var _baseUrl = Client.BaseUri; |
| 0 | 4040 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions/{sessionId}/state"; |
| 0 | 4041 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 0 | 4042 | | _url = _url.Replace("{sessionId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO |
| 0 | 4043 | | List<string> _queryParameters = new List<string>(); |
| 0 | 4044 | | if (_queryParameters.Count > 0) |
| | 4045 | | { |
| 0 | 4046 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 4047 | | } |
| | 4048 | | // Create HTTP transport objects |
| 0 | 4049 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 4050 | | HttpResponseMessage _httpResponse = null; |
| 0 | 4051 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 4052 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 4053 | | // Set Headers |
| 0 | 4054 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 4055 | | { |
| 0 | 4056 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 4057 | | } |
| 0 | 4058 | | if (Client.AcceptLanguage != null) |
| | 4059 | | { |
| 0 | 4060 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 4061 | | { |
| 0 | 4062 | | _httpRequest.Headers.Remove("accept-language"); |
| | 4063 | | } |
| 0 | 4064 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 4065 | | } |
| | 4066 | |
|
| | 4067 | |
|
| 0 | 4068 | | if (customHeaders != null) |
| | 4069 | | { |
| 0 | 4070 | | foreach(var _header in customHeaders) |
| | 4071 | | { |
| 0 | 4072 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 4073 | | { |
| 0 | 4074 | | _httpRequest.Headers.Remove(_header.Key); |
| | 4075 | | } |
| 0 | 4076 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 4077 | | } |
| | 4078 | | } |
| | 4079 | |
|
| | 4080 | | // Serialize Request |
| 0 | 4081 | | string _requestContent = null; |
| | 4082 | | // Set Credentials |
| 0 | 4083 | | if (Client.Credentials != null) |
| | 4084 | | { |
| 0 | 4085 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 4086 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 4087 | | } |
| | 4088 | | // Send Request |
| 0 | 4089 | | if (_shouldTrace) |
| | 4090 | | { |
| 0 | 4091 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 4092 | | } |
| 0 | 4093 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 4094 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 4095 | | if (_shouldTrace) |
| | 4096 | | { |
| 0 | 4097 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 4098 | | } |
| 0 | 4099 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 4100 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 4101 | | string _responseContent = null; |
| 0 | 4102 | | if ((int)_statusCode != 200) |
| | 4103 | | { |
| 0 | 4104 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 4105 | | try |
| | 4106 | | { |
| 0 | 4107 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 4108 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 4109 | | if (_errorBody != null) |
| | 4110 | | { |
| 0 | 4111 | | ex = new CloudException(_errorBody.Message); |
| 0 | 4112 | | ex.Body = _errorBody; |
| | 4113 | | } |
| 0 | 4114 | | } |
| 0 | 4115 | | catch (JsonException) |
| | 4116 | | { |
| | 4117 | | // Ignore the exception |
| 0 | 4118 | | } |
| 0 | 4119 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 4120 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 4121 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 4122 | | { |
| 0 | 4123 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 4124 | | } |
| 0 | 4125 | | if (_shouldTrace) |
| | 4126 | | { |
| 0 | 4127 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 4128 | | } |
| 0 | 4129 | | _httpRequest.Dispose(); |
| 0 | 4130 | | if (_httpResponse != null) |
| | 4131 | | { |
| 0 | 4132 | | _httpResponse.Dispose(); |
| | 4133 | | } |
| 0 | 4134 | | throw ex; |
| | 4135 | | } |
| | 4136 | | // Create Result |
| 0 | 4137 | | var _result = new AzureOperationResponse<SparkJobState>(); |
| 0 | 4138 | | _result.Request = _httpRequest; |
| 0 | 4139 | | _result.Response = _httpResponse; |
| 0 | 4140 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 4141 | | { |
| 0 | 4142 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 4143 | | } |
| | 4144 | | // Deserialize Response |
| 0 | 4145 | | if ((int)_statusCode == 200) |
| | 4146 | | { |
| 0 | 4147 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 4148 | | try |
| | 4149 | | { |
| 0 | 4150 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkJobState>(_responseContent, |
| 0 | 4151 | | } |
| 0 | 4152 | | catch (JsonException ex) |
| | 4153 | | { |
| 0 | 4154 | | _httpRequest.Dispose(); |
| 0 | 4155 | | if (_httpResponse != null) |
| | 4156 | | { |
| 0 | 4157 | | _httpResponse.Dispose(); |
| | 4158 | | } |
| 0 | 4159 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 4160 | | } |
| | 4161 | | } |
| 0 | 4162 | | if (_shouldTrace) |
| | 4163 | | { |
| 0 | 4164 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 4165 | | } |
| 0 | 4166 | | return _result; |
| 0 | 4167 | | } |
| | 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 | | { |
| 4 | 4198 | | if (Client.Endpoint == null) |
| | 4199 | | { |
| 0 | 4200 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 4201 | | } |
| | 4202 | | // Tracing |
| 4 | 4203 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 4204 | | string _invocationId = null; |
| 4 | 4205 | | if (_shouldTrace) |
| | 4206 | | { |
| 0 | 4207 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 4208 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 4209 | | tracingParameters.Add("sessionId", sessionId); |
| 0 | 4210 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 4211 | | ServiceClientTracing.Enter(_invocationId, this, "ListSparkStatementJob", tracingParameters); |
| | 4212 | | } |
| | 4213 | | // Construct URL |
| 4 | 4214 | | var _baseUrl = Client.BaseUri; |
| 4 | 4215 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions/{sessionId}/statements"; |
| 4 | 4216 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 4 | 4217 | | _url = _url.Replace("{sessionId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO |
| 4 | 4218 | | List<string> _queryParameters = new List<string>(); |
| 4 | 4219 | | if (_queryParameters.Count > 0) |
| | 4220 | | { |
| 0 | 4221 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 4222 | | } |
| | 4223 | | // Create HTTP transport objects |
| 4 | 4224 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 4225 | | HttpResponseMessage _httpResponse = null; |
| 4 | 4226 | | _httpRequest.Method = new HttpMethod("GET"); |
| 4 | 4227 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 4228 | | // Set Headers |
| 4 | 4229 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 4230 | | { |
| 4 | 4231 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 4232 | | } |
| 4 | 4233 | | if (Client.AcceptLanguage != null) |
| | 4234 | | { |
| 4 | 4235 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 4236 | | { |
| 0 | 4237 | | _httpRequest.Headers.Remove("accept-language"); |
| | 4238 | | } |
| 4 | 4239 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 4240 | | } |
| | 4241 | |
|
| | 4242 | |
|
| 4 | 4243 | | if (customHeaders != null) |
| | 4244 | | { |
| 0 | 4245 | | foreach(var _header in customHeaders) |
| | 4246 | | { |
| 0 | 4247 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 4248 | | { |
| 0 | 4249 | | _httpRequest.Headers.Remove(_header.Key); |
| | 4250 | | } |
| 0 | 4251 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 4252 | | } |
| | 4253 | | } |
| | 4254 | |
|
| | 4255 | | // Serialize Request |
| 4 | 4256 | | string _requestContent = null; |
| | 4257 | | // Set Credentials |
| 4 | 4258 | | if (Client.Credentials != null) |
| | 4259 | | { |
| 4 | 4260 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 4261 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 4262 | | } |
| | 4263 | | // Send Request |
| 4 | 4264 | | if (_shouldTrace) |
| | 4265 | | { |
| 0 | 4266 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 4267 | | } |
| 4 | 4268 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 4269 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 4270 | | if (_shouldTrace) |
| | 4271 | | { |
| 0 | 4272 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 4273 | | } |
| 4 | 4274 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 4275 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 4276 | | string _responseContent = null; |
| 4 | 4277 | | if ((int)_statusCode != 200) |
| | 4278 | | { |
| 0 | 4279 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 4280 | | try |
| | 4281 | | { |
| 0 | 4282 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 4283 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 4284 | | if (_errorBody != null) |
| | 4285 | | { |
| 0 | 4286 | | ex = new CloudException(_errorBody.Message); |
| 0 | 4287 | | ex.Body = _errorBody; |
| | 4288 | | } |
| 0 | 4289 | | } |
| 0 | 4290 | | catch (JsonException) |
| | 4291 | | { |
| | 4292 | | // Ignore the exception |
| 0 | 4293 | | } |
| 0 | 4294 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 4295 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 4296 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 4297 | | { |
| 0 | 4298 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 4299 | | } |
| 0 | 4300 | | if (_shouldTrace) |
| | 4301 | | { |
| 0 | 4302 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 4303 | | } |
| 0 | 4304 | | _httpRequest.Dispose(); |
| 0 | 4305 | | if (_httpResponse != null) |
| | 4306 | | { |
| 0 | 4307 | | _httpResponse.Dispose(); |
| | 4308 | | } |
| 0 | 4309 | | throw ex; |
| | 4310 | | } |
| | 4311 | | // Create Result |
| 4 | 4312 | | var _result = new AzureOperationResponse<SparkStatementCollection>(); |
| 4 | 4313 | | _result.Request = _httpRequest; |
| 4 | 4314 | | _result.Response = _httpResponse; |
| 4 | 4315 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 4316 | | { |
| 0 | 4317 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 4318 | | } |
| | 4319 | | // Deserialize Response |
| 4 | 4320 | | if ((int)_statusCode == 200) |
| | 4321 | | { |
| 4 | 4322 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 4323 | | try |
| | 4324 | | { |
| 4 | 4325 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkStatementCollection>(_respo |
| 4 | 4326 | | } |
| 0 | 4327 | | catch (JsonException ex) |
| | 4328 | | { |
| 0 | 4329 | | _httpRequest.Dispose(); |
| 0 | 4330 | | if (_httpResponse != null) |
| | 4331 | | { |
| 0 | 4332 | | _httpResponse.Dispose(); |
| | 4333 | | } |
| 0 | 4334 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 4335 | | } |
| | 4336 | | } |
| 4 | 4337 | | if (_shouldTrace) |
| | 4338 | | { |
| 0 | 4339 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 4340 | | } |
| 4 | 4341 | | return _result; |
| 4 | 4342 | | } |
| | 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 | | { |
| 2 | 4379 | | if (Client.Endpoint == null) |
| | 4380 | | { |
| 0 | 4381 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 4382 | | } |
| 2 | 4383 | | if (sparkStatementRequest == null) |
| | 4384 | | { |
| 0 | 4385 | | throw new ValidationException(ValidationRules.CannotBeNull, "sparkStatementRequest"); |
| | 4386 | | } |
| | 4387 | | // Tracing |
| 2 | 4388 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 4389 | | string _invocationId = null; |
| 2 | 4390 | | if (_shouldTrace) |
| | 4391 | | { |
| 0 | 4392 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 4393 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 4394 | | tracingParameters.Add("requestedBy", requestedBy); |
| 0 | 4395 | | tracingParameters.Add("sessionId", sessionId); |
| 0 | 4396 | | tracingParameters.Add("sparkStatementRequest", sparkStatementRequest); |
| 0 | 4397 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 4398 | | ServiceClientTracing.Enter(_invocationId, this, "SubmitSparkStatementJob", tracingParameters); |
| | 4399 | | } |
| | 4400 | | // Construct URL |
| 2 | 4401 | | var _baseUrl = Client.BaseUri; |
| 2 | 4402 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions/{sessionId}/statements"; |
| 2 | 4403 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 2 | 4404 | | _url = _url.Replace("{sessionId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO |
| 2 | 4405 | | List<string> _queryParameters = new List<string>(); |
| 2 | 4406 | | if (_queryParameters.Count > 0) |
| | 4407 | | { |
| 0 | 4408 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 4409 | | } |
| | 4410 | | // Create HTTP transport objects |
| 2 | 4411 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 4412 | | HttpResponseMessage _httpResponse = null; |
| 2 | 4413 | | _httpRequest.Method = new HttpMethod("POST"); |
| 2 | 4414 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 4415 | | // Set Headers |
| 2 | 4416 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 4417 | | { |
| 2 | 4418 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 4419 | | } |
| 2 | 4420 | | if (requestedBy != null) |
| | 4421 | | { |
| 2 | 4422 | | if (_httpRequest.Headers.Contains("X-Requested-By")) |
| | 4423 | | { |
| 0 | 4424 | | _httpRequest.Headers.Remove("X-Requested-By"); |
| | 4425 | | } |
| 2 | 4426 | | _httpRequest.Headers.TryAddWithoutValidation("X-Requested-By", requestedBy); |
| | 4427 | | } |
| 2 | 4428 | | if (Client.AcceptLanguage != null) |
| | 4429 | | { |
| 2 | 4430 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 4431 | | { |
| 0 | 4432 | | _httpRequest.Headers.Remove("accept-language"); |
| | 4433 | | } |
| 2 | 4434 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 4435 | | } |
| | 4436 | |
|
| | 4437 | |
|
| 2 | 4438 | | if (customHeaders != null) |
| | 4439 | | { |
| 0 | 4440 | | foreach(var _header in customHeaders) |
| | 4441 | | { |
| 0 | 4442 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 4443 | | { |
| 0 | 4444 | | _httpRequest.Headers.Remove(_header.Key); |
| | 4445 | | } |
| 0 | 4446 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 4447 | | } |
| | 4448 | | } |
| | 4449 | |
|
| | 4450 | | // Serialize Request |
| 2 | 4451 | | string _requestContent = null; |
| 2 | 4452 | | if(sparkStatementRequest != null) |
| | 4453 | | { |
| 2 | 4454 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(sparkStatementRequest, Client.Seria |
| 2 | 4455 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 2 | 4456 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 4457 | | } |
| | 4458 | | // Set Credentials |
| 2 | 4459 | | if (Client.Credentials != null) |
| | 4460 | | { |
| 2 | 4461 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 4462 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 4463 | | } |
| | 4464 | | // Send Request |
| 2 | 4465 | | if (_shouldTrace) |
| | 4466 | | { |
| 0 | 4467 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 4468 | | } |
| 2 | 4469 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 4470 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 4471 | | if (_shouldTrace) |
| | 4472 | | { |
| 0 | 4473 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 4474 | | } |
| 2 | 4475 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 4476 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 4477 | | string _responseContent = null; |
| 2 | 4478 | | if ((int)_statusCode != 201) |
| | 4479 | | { |
| 0 | 4480 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 4481 | | try |
| | 4482 | | { |
| 0 | 4483 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 4484 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 4485 | | if (_errorBody != null) |
| | 4486 | | { |
| 0 | 4487 | | ex = new CloudException(_errorBody.Message); |
| 0 | 4488 | | ex.Body = _errorBody; |
| | 4489 | | } |
| 0 | 4490 | | } |
| 0 | 4491 | | catch (JsonException) |
| | 4492 | | { |
| | 4493 | | // Ignore the exception |
| 0 | 4494 | | } |
| 0 | 4495 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 4496 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 4497 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 4498 | | { |
| 0 | 4499 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 4500 | | } |
| 0 | 4501 | | if (_shouldTrace) |
| | 4502 | | { |
| 0 | 4503 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 4504 | | } |
| 0 | 4505 | | _httpRequest.Dispose(); |
| 0 | 4506 | | if (_httpResponse != null) |
| | 4507 | | { |
| 0 | 4508 | | _httpResponse.Dispose(); |
| | 4509 | | } |
| 0 | 4510 | | throw ex; |
| | 4511 | | } |
| | 4512 | | // Create Result |
| 2 | 4513 | | var _result = new AzureOperationResponse<SparkStatement>(); |
| 2 | 4514 | | _result.Request = _httpRequest; |
| 2 | 4515 | | _result.Response = _httpResponse; |
| 2 | 4516 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 4517 | | { |
| 0 | 4518 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 4519 | | } |
| | 4520 | | // Deserialize Response |
| 2 | 4521 | | if ((int)_statusCode == 201) |
| | 4522 | | { |
| 2 | 4523 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 4524 | | try |
| | 4525 | | { |
| 2 | 4526 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkStatement>(_responseContent |
| 2 | 4527 | | } |
| 0 | 4528 | | catch (JsonException ex) |
| | 4529 | | { |
| 0 | 4530 | | _httpRequest.Dispose(); |
| 0 | 4531 | | if (_httpResponse != null) |
| | 4532 | | { |
| 0 | 4533 | | _httpResponse.Dispose(); |
| | 4534 | | } |
| 0 | 4535 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 4536 | | } |
| | 4537 | | } |
| 2 | 4538 | | if (_shouldTrace) |
| | 4539 | | { |
| 0 | 4540 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 4541 | | } |
| 2 | 4542 | | return _result; |
| 2 | 4543 | | } |
| | 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 | | { |
| 0 | 4577 | | if (Client.Endpoint == null) |
| | 4578 | | { |
| 0 | 4579 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 4580 | | } |
| | 4581 | | // Tracing |
| 0 | 4582 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 4583 | | string _invocationId = null; |
| 0 | 4584 | | if (_shouldTrace) |
| | 4585 | | { |
| 0 | 4586 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 4587 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 4588 | | tracingParameters.Add("sessionId", sessionId); |
| 0 | 4589 | | tracingParameters.Add("statementId", statementId); |
| 0 | 4590 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 4591 | | ServiceClientTracing.Enter(_invocationId, this, "GetSparkStatementJob", tracingParameters); |
| | 4592 | | } |
| | 4593 | | // Construct URL |
| 0 | 4594 | | var _baseUrl = Client.BaseUri; |
| 0 | 4595 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions/{sessionId}/statements/{statement |
| 0 | 4596 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 0 | 4597 | | _url = _url.Replace("{sessionId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO |
| 0 | 4598 | | _url = _url.Replace("{statementId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Serializ |
| 0 | 4599 | | List<string> _queryParameters = new List<string>(); |
| 0 | 4600 | | if (_queryParameters.Count > 0) |
| | 4601 | | { |
| 0 | 4602 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 4603 | | } |
| | 4604 | | // Create HTTP transport objects |
| 0 | 4605 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 4606 | | HttpResponseMessage _httpResponse = null; |
| 0 | 4607 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 4608 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 4609 | | // Set Headers |
| 0 | 4610 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 4611 | | { |
| 0 | 4612 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 4613 | | } |
| 0 | 4614 | | if (Client.AcceptLanguage != null) |
| | 4615 | | { |
| 0 | 4616 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 4617 | | { |
| 0 | 4618 | | _httpRequest.Headers.Remove("accept-language"); |
| | 4619 | | } |
| 0 | 4620 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 4621 | | } |
| | 4622 | |
|
| | 4623 | |
|
| 0 | 4624 | | if (customHeaders != null) |
| | 4625 | | { |
| 0 | 4626 | | foreach(var _header in customHeaders) |
| | 4627 | | { |
| 0 | 4628 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 4629 | | { |
| 0 | 4630 | | _httpRequest.Headers.Remove(_header.Key); |
| | 4631 | | } |
| 0 | 4632 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 4633 | | } |
| | 4634 | | } |
| | 4635 | |
|
| | 4636 | | // Serialize Request |
| 0 | 4637 | | string _requestContent = null; |
| | 4638 | | // Set Credentials |
| 0 | 4639 | | if (Client.Credentials != null) |
| | 4640 | | { |
| 0 | 4641 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 4642 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 4643 | | } |
| | 4644 | | // Send Request |
| 0 | 4645 | | if (_shouldTrace) |
| | 4646 | | { |
| 0 | 4647 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 4648 | | } |
| 0 | 4649 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 4650 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 4651 | | if (_shouldTrace) |
| | 4652 | | { |
| 0 | 4653 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 4654 | | } |
| 0 | 4655 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 4656 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 4657 | | string _responseContent = null; |
| 0 | 4658 | | if ((int)_statusCode != 200) |
| | 4659 | | { |
| 0 | 4660 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 4661 | | try |
| | 4662 | | { |
| 0 | 4663 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 4664 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 4665 | | if (_errorBody != null) |
| | 4666 | | { |
| 0 | 4667 | | ex = new CloudException(_errorBody.Message); |
| 0 | 4668 | | ex.Body = _errorBody; |
| | 4669 | | } |
| 0 | 4670 | | } |
| 0 | 4671 | | catch (JsonException) |
| | 4672 | | { |
| | 4673 | | // Ignore the exception |
| 0 | 4674 | | } |
| 0 | 4675 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 4676 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 4677 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 4678 | | { |
| 0 | 4679 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 4680 | | } |
| 0 | 4681 | | if (_shouldTrace) |
| | 4682 | | { |
| 0 | 4683 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 4684 | | } |
| 0 | 4685 | | _httpRequest.Dispose(); |
| 0 | 4686 | | if (_httpResponse != null) |
| | 4687 | | { |
| 0 | 4688 | | _httpResponse.Dispose(); |
| | 4689 | | } |
| 0 | 4690 | | throw ex; |
| | 4691 | | } |
| | 4692 | | // Create Result |
| 0 | 4693 | | var _result = new AzureOperationResponse<SparkStatement>(); |
| 0 | 4694 | | _result.Request = _httpRequest; |
| 0 | 4695 | | _result.Response = _httpResponse; |
| 0 | 4696 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 4697 | | { |
| 0 | 4698 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 4699 | | } |
| | 4700 | | // Deserialize Response |
| 0 | 4701 | | if ((int)_statusCode == 200) |
| | 4702 | | { |
| 0 | 4703 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 4704 | | try |
| | 4705 | | { |
| 0 | 4706 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkStatement>(_responseContent |
| 0 | 4707 | | } |
| 0 | 4708 | | catch (JsonException ex) |
| | 4709 | | { |
| 0 | 4710 | | _httpRequest.Dispose(); |
| 0 | 4711 | | if (_httpResponse != null) |
| | 4712 | | { |
| 0 | 4713 | | _httpResponse.Dispose(); |
| | 4714 | | } |
| 0 | 4715 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 4716 | | } |
| | 4717 | | } |
| 0 | 4718 | | if (_shouldTrace) |
| | 4719 | | { |
| 0 | 4720 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 4721 | | } |
| 0 | 4722 | | return _result; |
| 0 | 4723 | | } |
| | 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 | | { |
| 2 | 4760 | | if (Client.Endpoint == null) |
| | 4761 | | { |
| 0 | 4762 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 4763 | | } |
| | 4764 | | // Tracing |
| 2 | 4765 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 4766 | | string _invocationId = null; |
| 2 | 4767 | | if (_shouldTrace) |
| | 4768 | | { |
| 0 | 4769 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 4770 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 4771 | | tracingParameters.Add("requestedBy", requestedBy); |
| 0 | 4772 | | tracingParameters.Add("sessionId", sessionId); |
| 0 | 4773 | | tracingParameters.Add("statementId", statementId); |
| 0 | 4774 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 4775 | | ServiceClientTracing.Enter(_invocationId, this, "DeleteSparkStatementJob", tracingParameters); |
| | 4776 | | } |
| | 4777 | | // Construct URL |
| 2 | 4778 | | var _baseUrl = Client.BaseUri; |
| 2 | 4779 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "livy/sessions/{sessionId}/statements/{statement |
| 2 | 4780 | | _url = _url.Replace("{endpoint}", Client.Endpoint); |
| 2 | 4781 | | _url = _url.Replace("{sessionId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO |
| 2 | 4782 | | _url = _url.Replace("{statementId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Serializ |
| 2 | 4783 | | List<string> _queryParameters = new List<string>(); |
| 2 | 4784 | | if (_queryParameters.Count > 0) |
| | 4785 | | { |
| 0 | 4786 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 4787 | | } |
| | 4788 | | // Create HTTP transport objects |
| 2 | 4789 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 4790 | | HttpResponseMessage _httpResponse = null; |
| 2 | 4791 | | _httpRequest.Method = new HttpMethod("POST"); |
| 2 | 4792 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 4793 | | // Set Headers |
| 2 | 4794 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 4795 | | { |
| 2 | 4796 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 4797 | | } |
| 2 | 4798 | | if (requestedBy != null) |
| | 4799 | | { |
| 2 | 4800 | | if (_httpRequest.Headers.Contains("X-Requested-By")) |
| | 4801 | | { |
| 0 | 4802 | | _httpRequest.Headers.Remove("X-Requested-By"); |
| | 4803 | | } |
| 2 | 4804 | | _httpRequest.Headers.TryAddWithoutValidation("X-Requested-By", requestedBy); |
| | 4805 | | } |
| 2 | 4806 | | if (Client.AcceptLanguage != null) |
| | 4807 | | { |
| 2 | 4808 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 4809 | | { |
| 0 | 4810 | | _httpRequest.Headers.Remove("accept-language"); |
| | 4811 | | } |
| 2 | 4812 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 4813 | | } |
| | 4814 | |
|
| | 4815 | |
|
| 2 | 4816 | | if (customHeaders != null) |
| | 4817 | | { |
| 0 | 4818 | | foreach(var _header in customHeaders) |
| | 4819 | | { |
| 0 | 4820 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 4821 | | { |
| 0 | 4822 | | _httpRequest.Headers.Remove(_header.Key); |
| | 4823 | | } |
| 0 | 4824 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 4825 | | } |
| | 4826 | | } |
| | 4827 | |
|
| | 4828 | | // Serialize Request |
| 2 | 4829 | | string _requestContent = null; |
| | 4830 | | // Set Credentials |
| 2 | 4831 | | if (Client.Credentials != null) |
| | 4832 | | { |
| 2 | 4833 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 4834 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 4835 | | } |
| | 4836 | | // Send Request |
| 2 | 4837 | | if (_shouldTrace) |
| | 4838 | | { |
| 0 | 4839 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 4840 | | } |
| 2 | 4841 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 4842 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 4843 | | if (_shouldTrace) |
| | 4844 | | { |
| 0 | 4845 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 4846 | | } |
| 2 | 4847 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 4848 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 4849 | | string _responseContent = null; |
| 2 | 4850 | | if ((int)_statusCode != 200) |
| | 4851 | | { |
| 0 | 4852 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 4853 | | try |
| | 4854 | | { |
| 0 | 4855 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 4856 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 4857 | | if (_errorBody != null) |
| | 4858 | | { |
| 0 | 4859 | | ex = new CloudException(_errorBody.Message); |
| 0 | 4860 | | ex.Body = _errorBody; |
| | 4861 | | } |
| 0 | 4862 | | } |
| 0 | 4863 | | catch (JsonException) |
| | 4864 | | { |
| | 4865 | | // Ignore the exception |
| 0 | 4866 | | } |
| 0 | 4867 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 4868 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 4869 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 4870 | | { |
| 0 | 4871 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 4872 | | } |
| 0 | 4873 | | if (_shouldTrace) |
| | 4874 | | { |
| 0 | 4875 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 4876 | | } |
| 0 | 4877 | | _httpRequest.Dispose(); |
| 0 | 4878 | | if (_httpResponse != null) |
| | 4879 | | { |
| 0 | 4880 | | _httpResponse.Dispose(); |
| | 4881 | | } |
| 0 | 4882 | | throw ex; |
| | 4883 | | } |
| | 4884 | | // Create Result |
| 2 | 4885 | | var _result = new AzureOperationResponse<SparkStatementCancellationResult>(); |
| 2 | 4886 | | _result.Request = _httpRequest; |
| 2 | 4887 | | _result.Response = _httpResponse; |
| 2 | 4888 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 4889 | | { |
| 0 | 4890 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 4891 | | } |
| | 4892 | | // Deserialize Response |
| 2 | 4893 | | if ((int)_statusCode == 200) |
| | 4894 | | { |
| 2 | 4895 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 4896 | | try |
| | 4897 | | { |
| 2 | 4898 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<SparkStatementCancellationResult |
| 2 | 4899 | | } |
| 0 | 4900 | | catch (JsonException ex) |
| | 4901 | | { |
| 0 | 4902 | | _httpRequest.Dispose(); |
| 0 | 4903 | | if (_httpResponse != null) |
| | 4904 | | { |
| 0 | 4905 | | _httpResponse.Dispose(); |
| | 4906 | | } |
| 0 | 4907 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 4908 | | } |
| | 4909 | | } |
| 2 | 4910 | | if (_shouldTrace) |
| | 4911 | | { |
| 0 | 4912 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 4913 | | } |
| 2 | 4914 | | return _result; |
| 2 | 4915 | | } |
| | 4916 | |
|
| | 4917 | | } |
| | 4918 | | } |