| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | // <auto-generated/> |
| | 5 | |
|
| | 6 | | #nullable disable |
| | 7 | |
|
| | 8 | | using System; |
| | 9 | | using System.Text.Json; |
| | 10 | | using System.Threading; |
| | 11 | | using System.Threading.Tasks; |
| | 12 | | using Azure; |
| | 13 | | using Azure.Analytics.Synapse.Spark.Models; |
| | 14 | | using Azure.Core; |
| | 15 | | using Azure.Core.Pipeline; |
| | 16 | |
|
| | 17 | | namespace Azure.Analytics.Synapse.Spark |
| | 18 | | { |
| | 19 | | internal partial class SparkSessionRestClient |
| | 20 | | { |
| | 21 | | private string endpoint; |
| | 22 | | private string sparkPoolName; |
| | 23 | | private string livyApiVersion; |
| | 24 | | private ClientDiagnostics _clientDiagnostics; |
| | 25 | | private HttpPipeline _pipeline; |
| | 26 | |
|
| | 27 | | /// <summary> Initializes a new instance of SparkSessionRestClient. </summary> |
| | 28 | | /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param> |
| | 29 | | /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param> |
| | 30 | | /// <param name="endpoint"> The workspace development endpoint, for example https://myworkspace.dev.azuresynapse |
| | 31 | | /// <param name="sparkPoolName"> Name of the spark pool. </param> |
| | 32 | | /// <param name="livyApiVersion"> Valid api-version for the request. </param> |
| | 33 | | /// <exception cref="ArgumentNullException"> <paramref name="endpoint"/>, <paramref name="sparkPoolName"/>, or < |
| 8 | 34 | | public SparkSessionRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint, strin |
| | 35 | | { |
| 8 | 36 | | if (endpoint == null) |
| | 37 | | { |
| 0 | 38 | | throw new ArgumentNullException(nameof(endpoint)); |
| | 39 | | } |
| 8 | 40 | | if (sparkPoolName == null) |
| | 41 | | { |
| 0 | 42 | | throw new ArgumentNullException(nameof(sparkPoolName)); |
| | 43 | | } |
| 8 | 44 | | if (livyApiVersion == null) |
| | 45 | | { |
| 0 | 46 | | throw new ArgumentNullException(nameof(livyApiVersion)); |
| | 47 | | } |
| | 48 | |
|
| 8 | 49 | | this.endpoint = endpoint; |
| 8 | 50 | | this.sparkPoolName = sparkPoolName; |
| 8 | 51 | | this.livyApiVersion = livyApiVersion; |
| 8 | 52 | | _clientDiagnostics = clientDiagnostics; |
| 8 | 53 | | _pipeline = pipeline; |
| 8 | 54 | | } |
| | 55 | |
|
| | 56 | | internal HttpMessage CreateGetSparkSessionsRequest(int? @from, int? size, bool? detailed) |
| | 57 | | { |
| 4 | 58 | | var message = _pipeline.CreateMessage(); |
| 4 | 59 | | var request = message.Request; |
| 4 | 60 | | request.Method = RequestMethod.Get; |
| 4 | 61 | | var uri = new RawRequestUriBuilder(); |
| 4 | 62 | | uri.AppendRaw(endpoint, false); |
| 4 | 63 | | uri.AppendRaw("/livyApi/versions/", false); |
| 4 | 64 | | uri.AppendRaw(livyApiVersion, false); |
| 4 | 65 | | uri.AppendRaw("/sparkPools/", false); |
| 4 | 66 | | uri.AppendRaw(sparkPoolName, false); |
| 4 | 67 | | uri.AppendPath("/sessions", false); |
| 4 | 68 | | if (@from != null) |
| | 69 | | { |
| 0 | 70 | | uri.AppendQuery("from", @from.Value, true); |
| | 71 | | } |
| 4 | 72 | | if (size != null) |
| | 73 | | { |
| 0 | 74 | | uri.AppendQuery("size", size.Value, true); |
| | 75 | | } |
| 4 | 76 | | if (detailed != null) |
| | 77 | | { |
| 0 | 78 | | uri.AppendQuery("detailed", detailed.Value, true); |
| | 79 | | } |
| 4 | 80 | | request.Uri = uri; |
| 4 | 81 | | return message; |
| | 82 | | } |
| | 83 | |
|
| | 84 | | /// <summary> List all spark sessions which are running under a particular spark pool. </summary> |
| | 85 | | /// <param name="from"> Optional param specifying which index the list should begin from. </param> |
| | 86 | | /// <param name="size"> |
| | 87 | | /// Optional param specifying the size of the returned list. |
| | 88 | | /// |
| | 89 | | /// By default it is 20 and that is the maximum. |
| | 90 | | /// </param> |
| | 91 | | /// <param name="detailed"> Optional query param specifying whether detailed response is returned beyond plain l |
| | 92 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 93 | | public async Task<Response<SparkSessionCollection>> GetSparkSessionsAsync(int? @from = null, int? size = null, b |
| | 94 | | { |
| 2 | 95 | | using var message = CreateGetSparkSessionsRequest(@from, size, detailed); |
| 2 | 96 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 2 | 97 | | switch (message.Response.Status) |
| | 98 | | { |
| | 99 | | case 200: |
| | 100 | | { |
| | 101 | | SparkSessionCollection value = default; |
| 2 | 102 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 2 | 103 | | value = SparkSessionCollection.DeserializeSparkSessionCollection(document.RootElement); |
| 2 | 104 | | return Response.FromValue(value, message.Response); |
| | 105 | | } |
| | 106 | | default: |
| 0 | 107 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 108 | | } |
| 2 | 109 | | } |
| | 110 | |
|
| | 111 | | /// <summary> List all spark sessions which are running under a particular spark pool. </summary> |
| | 112 | | /// <param name="from"> Optional param specifying which index the list should begin from. </param> |
| | 113 | | /// <param name="size"> |
| | 114 | | /// Optional param specifying the size of the returned list. |
| | 115 | | /// |
| | 116 | | /// By default it is 20 and that is the maximum. |
| | 117 | | /// </param> |
| | 118 | | /// <param name="detailed"> Optional query param specifying whether detailed response is returned beyond plain l |
| | 119 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 120 | | public Response<SparkSessionCollection> GetSparkSessions(int? @from = null, int? size = null, bool? detailed = n |
| | 121 | | { |
| 2 | 122 | | using var message = CreateGetSparkSessionsRequest(@from, size, detailed); |
| 2 | 123 | | _pipeline.Send(message, cancellationToken); |
| 2 | 124 | | switch (message.Response.Status) |
| | 125 | | { |
| | 126 | | case 200: |
| | 127 | | { |
| | 128 | | SparkSessionCollection value = default; |
| 2 | 129 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 2 | 130 | | value = SparkSessionCollection.DeserializeSparkSessionCollection(document.RootElement); |
| 2 | 131 | | return Response.FromValue(value, message.Response); |
| | 132 | | } |
| | 133 | | default: |
| 0 | 134 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 135 | | } |
| 2 | 136 | | } |
| | 137 | |
|
| | 138 | | internal HttpMessage CreateCreateSparkSessionRequest(SparkSessionOptions sparkSessionOptions, bool? detailed) |
| | 139 | | { |
| 0 | 140 | | var message = _pipeline.CreateMessage(); |
| 0 | 141 | | var request = message.Request; |
| 0 | 142 | | request.Method = RequestMethod.Post; |
| 0 | 143 | | var uri = new RawRequestUriBuilder(); |
| 0 | 144 | | uri.AppendRaw(endpoint, false); |
| 0 | 145 | | uri.AppendRaw("/livyApi/versions/", false); |
| 0 | 146 | | uri.AppendRaw(livyApiVersion, false); |
| 0 | 147 | | uri.AppendRaw("/sparkPools/", false); |
| 0 | 148 | | uri.AppendRaw(sparkPoolName, false); |
| 0 | 149 | | uri.AppendPath("/sessions", false); |
| 0 | 150 | | if (detailed != null) |
| | 151 | | { |
| 0 | 152 | | uri.AppendQuery("detailed", detailed.Value, true); |
| | 153 | | } |
| 0 | 154 | | request.Uri = uri; |
| 0 | 155 | | request.Headers.Add("Content-Type", "application/json"); |
| 0 | 156 | | var content = new Utf8JsonRequestContent(); |
| 0 | 157 | | content.JsonWriter.WriteObjectValue(sparkSessionOptions); |
| 0 | 158 | | request.Content = content; |
| 0 | 159 | | return message; |
| | 160 | | } |
| | 161 | |
|
| | 162 | | /// <summary> Create new spark session. </summary> |
| | 163 | | /// <param name="sparkSessionOptions"> Livy compatible batch job request payload. </param> |
| | 164 | | /// <param name="detailed"> Optional query param specifying whether detailed response is returned beyond plain l |
| | 165 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 166 | | /// <exception cref="ArgumentNullException"> <paramref name="sparkSessionOptions"/> is null. </exception> |
| | 167 | | public async Task<Response<SparkSession>> CreateSparkSessionAsync(SparkSessionOptions sparkSessionOptions, bool? |
| | 168 | | { |
| 0 | 169 | | if (sparkSessionOptions == null) |
| | 170 | | { |
| 0 | 171 | | throw new ArgumentNullException(nameof(sparkSessionOptions)); |
| | 172 | | } |
| | 173 | |
|
| 0 | 174 | | using var message = CreateCreateSparkSessionRequest(sparkSessionOptions, detailed); |
| 0 | 175 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 176 | | switch (message.Response.Status) |
| | 177 | | { |
| | 178 | | case 200: |
| | 179 | | { |
| | 180 | | SparkSession value = default; |
| 0 | 181 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 182 | | value = SparkSession.DeserializeSparkSession(document.RootElement); |
| 0 | 183 | | return Response.FromValue(value, message.Response); |
| | 184 | | } |
| | 185 | | default: |
| 0 | 186 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 187 | | } |
| 0 | 188 | | } |
| | 189 | |
|
| | 190 | | /// <summary> Create new spark session. </summary> |
| | 191 | | /// <param name="sparkSessionOptions"> Livy compatible batch job request payload. </param> |
| | 192 | | /// <param name="detailed"> Optional query param specifying whether detailed response is returned beyond plain l |
| | 193 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 194 | | /// <exception cref="ArgumentNullException"> <paramref name="sparkSessionOptions"/> is null. </exception> |
| | 195 | | public Response<SparkSession> CreateSparkSession(SparkSessionOptions sparkSessionOptions, bool? detailed = null, |
| | 196 | | { |
| 0 | 197 | | if (sparkSessionOptions == null) |
| | 198 | | { |
| 0 | 199 | | throw new ArgumentNullException(nameof(sparkSessionOptions)); |
| | 200 | | } |
| | 201 | |
|
| 0 | 202 | | using var message = CreateCreateSparkSessionRequest(sparkSessionOptions, detailed); |
| 0 | 203 | | _pipeline.Send(message, cancellationToken); |
| 0 | 204 | | switch (message.Response.Status) |
| | 205 | | { |
| | 206 | | case 200: |
| | 207 | | { |
| | 208 | | SparkSession value = default; |
| 0 | 209 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 210 | | value = SparkSession.DeserializeSparkSession(document.RootElement); |
| 0 | 211 | | return Response.FromValue(value, message.Response); |
| | 212 | | } |
| | 213 | | default: |
| 0 | 214 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 215 | | } |
| 0 | 216 | | } |
| | 217 | |
|
| | 218 | | internal HttpMessage CreateGetSparkSessionRequest(int sessionId, bool? detailed) |
| | 219 | | { |
| 80 | 220 | | var message = _pipeline.CreateMessage(); |
| 80 | 221 | | var request = message.Request; |
| 80 | 222 | | request.Method = RequestMethod.Get; |
| 80 | 223 | | var uri = new RawRequestUriBuilder(); |
| 80 | 224 | | uri.AppendRaw(endpoint, false); |
| 80 | 225 | | uri.AppendRaw("/livyApi/versions/", false); |
| 80 | 226 | | uri.AppendRaw(livyApiVersion, false); |
| 80 | 227 | | uri.AppendRaw("/sparkPools/", false); |
| 80 | 228 | | uri.AppendRaw(sparkPoolName, false); |
| 80 | 229 | | uri.AppendPath("/sessions/", false); |
| 80 | 230 | | uri.AppendPath(sessionId, true); |
| 80 | 231 | | if (detailed != null) |
| | 232 | | { |
| 0 | 233 | | uri.AppendQuery("detailed", detailed.Value, true); |
| | 234 | | } |
| 80 | 235 | | request.Uri = uri; |
| 80 | 236 | | return message; |
| | 237 | | } |
| | 238 | |
|
| | 239 | | /// <summary> Gets a single spark session. </summary> |
| | 240 | | /// <param name="sessionId"> Identifier for the session. </param> |
| | 241 | | /// <param name="detailed"> Optional query param specifying whether detailed response is returned beyond plain l |
| | 242 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 243 | | public async Task<Response<SparkSession>> GetSparkSessionAsync(int sessionId, bool? detailed = null, Cancellatio |
| | 244 | | { |
| 40 | 245 | | using var message = CreateGetSparkSessionRequest(sessionId, detailed); |
| 40 | 246 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 40 | 247 | | switch (message.Response.Status) |
| | 248 | | { |
| | 249 | | case 200: |
| | 250 | | { |
| | 251 | | SparkSession value = default; |
| 40 | 252 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 40 | 253 | | value = SparkSession.DeserializeSparkSession(document.RootElement); |
| 40 | 254 | | return Response.FromValue(value, message.Response); |
| | 255 | | } |
| | 256 | | default: |
| 0 | 257 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 258 | | } |
| 40 | 259 | | } |
| | 260 | |
|
| | 261 | | /// <summary> Gets a single spark session. </summary> |
| | 262 | | /// <param name="sessionId"> Identifier for the session. </param> |
| | 263 | | /// <param name="detailed"> Optional query param specifying whether detailed response is returned beyond plain l |
| | 264 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 265 | | public Response<SparkSession> GetSparkSession(int sessionId, bool? detailed = null, CancellationToken cancellati |
| | 266 | | { |
| 40 | 267 | | using var message = CreateGetSparkSessionRequest(sessionId, detailed); |
| 40 | 268 | | _pipeline.Send(message, cancellationToken); |
| 40 | 269 | | switch (message.Response.Status) |
| | 270 | | { |
| | 271 | | case 200: |
| | 272 | | { |
| | 273 | | SparkSession value = default; |
| 40 | 274 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 40 | 275 | | value = SparkSession.DeserializeSparkSession(document.RootElement); |
| 40 | 276 | | return Response.FromValue(value, message.Response); |
| | 277 | | } |
| | 278 | | default: |
| 0 | 279 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 280 | | } |
| 40 | 281 | | } |
| | 282 | |
|
| | 283 | | internal HttpMessage CreateCancelSparkSessionRequest(int sessionId) |
| | 284 | | { |
| 0 | 285 | | var message = _pipeline.CreateMessage(); |
| 0 | 286 | | var request = message.Request; |
| 0 | 287 | | request.Method = RequestMethod.Delete; |
| 0 | 288 | | var uri = new RawRequestUriBuilder(); |
| 0 | 289 | | uri.AppendRaw(endpoint, false); |
| 0 | 290 | | uri.AppendRaw("/livyApi/versions/", false); |
| 0 | 291 | | uri.AppendRaw(livyApiVersion, false); |
| 0 | 292 | | uri.AppendRaw("/sparkPools/", false); |
| 0 | 293 | | uri.AppendRaw(sparkPoolName, false); |
| 0 | 294 | | uri.AppendPath("/sessions/", false); |
| 0 | 295 | | uri.AppendPath(sessionId, true); |
| 0 | 296 | | request.Uri = uri; |
| 0 | 297 | | return message; |
| | 298 | | } |
| | 299 | |
|
| | 300 | | /// <summary> Cancels a running spark session. </summary> |
| | 301 | | /// <param name="sessionId"> Identifier for the session. </param> |
| | 302 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 303 | | public async Task<Response> CancelSparkSessionAsync(int sessionId, CancellationToken cancellationToken = default |
| | 304 | | { |
| 0 | 305 | | using var message = CreateCancelSparkSessionRequest(sessionId); |
| 0 | 306 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 307 | | switch (message.Response.Status) |
| | 308 | | { |
| | 309 | | case 200: |
| 0 | 310 | | return message.Response; |
| | 311 | | default: |
| 0 | 312 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 313 | | } |
| 0 | 314 | | } |
| | 315 | |
|
| | 316 | | /// <summary> Cancels a running spark session. </summary> |
| | 317 | | /// <param name="sessionId"> Identifier for the session. </param> |
| | 318 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 319 | | public Response CancelSparkSession(int sessionId, CancellationToken cancellationToken = default) |
| | 320 | | { |
| 0 | 321 | | using var message = CreateCancelSparkSessionRequest(sessionId); |
| 0 | 322 | | _pipeline.Send(message, cancellationToken); |
| 0 | 323 | | switch (message.Response.Status) |
| | 324 | | { |
| | 325 | | case 200: |
| 0 | 326 | | return message.Response; |
| | 327 | | default: |
| 0 | 328 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 329 | | } |
| 0 | 330 | | } |
| | 331 | |
|
| | 332 | | internal HttpMessage CreateResetSparkSessionTimeoutRequest(int sessionId) |
| | 333 | | { |
| 0 | 334 | | var message = _pipeline.CreateMessage(); |
| 0 | 335 | | var request = message.Request; |
| 0 | 336 | | request.Method = RequestMethod.Put; |
| 0 | 337 | | var uri = new RawRequestUriBuilder(); |
| 0 | 338 | | uri.AppendRaw(endpoint, false); |
| 0 | 339 | | uri.AppendRaw("/livyApi/versions/", false); |
| 0 | 340 | | uri.AppendRaw(livyApiVersion, false); |
| 0 | 341 | | uri.AppendRaw("/sparkPools/", false); |
| 0 | 342 | | uri.AppendRaw(sparkPoolName, false); |
| 0 | 343 | | uri.AppendPath("/sessions/", false); |
| 0 | 344 | | uri.AppendPath(sessionId, true); |
| 0 | 345 | | uri.AppendPath("/reset-timeout", false); |
| 0 | 346 | | request.Uri = uri; |
| 0 | 347 | | return message; |
| | 348 | | } |
| | 349 | |
|
| | 350 | | /// <summary> Sends a keep alive call to the current session to reset the session timeout. </summary> |
| | 351 | | /// <param name="sessionId"> Identifier for the session. </param> |
| | 352 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 353 | | public async Task<Response> ResetSparkSessionTimeoutAsync(int sessionId, CancellationToken cancellationToken = d |
| | 354 | | { |
| 0 | 355 | | using var message = CreateResetSparkSessionTimeoutRequest(sessionId); |
| 0 | 356 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 357 | | switch (message.Response.Status) |
| | 358 | | { |
| | 359 | | case 200: |
| 0 | 360 | | return message.Response; |
| | 361 | | default: |
| 0 | 362 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 363 | | } |
| 0 | 364 | | } |
| | 365 | |
|
| | 366 | | /// <summary> Sends a keep alive call to the current session to reset the session timeout. </summary> |
| | 367 | | /// <param name="sessionId"> Identifier for the session. </param> |
| | 368 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 369 | | public Response ResetSparkSessionTimeout(int sessionId, CancellationToken cancellationToken = default) |
| | 370 | | { |
| 0 | 371 | | using var message = CreateResetSparkSessionTimeoutRequest(sessionId); |
| 0 | 372 | | _pipeline.Send(message, cancellationToken); |
| 0 | 373 | | switch (message.Response.Status) |
| | 374 | | { |
| | 375 | | case 200: |
| 0 | 376 | | return message.Response; |
| | 377 | | default: |
| 0 | 378 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 379 | | } |
| 0 | 380 | | } |
| | 381 | |
|
| | 382 | | internal HttpMessage CreateGetSparkStatementsRequest(int sessionId) |
| | 383 | | { |
| 0 | 384 | | var message = _pipeline.CreateMessage(); |
| 0 | 385 | | var request = message.Request; |
| 0 | 386 | | request.Method = RequestMethod.Get; |
| 0 | 387 | | var uri = new RawRequestUriBuilder(); |
| 0 | 388 | | uri.AppendRaw(endpoint, false); |
| 0 | 389 | | uri.AppendRaw("/livyApi/versions/", false); |
| 0 | 390 | | uri.AppendRaw(livyApiVersion, false); |
| 0 | 391 | | uri.AppendRaw("/sparkPools/", false); |
| 0 | 392 | | uri.AppendRaw(sparkPoolName, false); |
| 0 | 393 | | uri.AppendPath("/sessions/", false); |
| 0 | 394 | | uri.AppendPath(sessionId, true); |
| 0 | 395 | | uri.AppendPath("/statements", false); |
| 0 | 396 | | request.Uri = uri; |
| 0 | 397 | | return message; |
| | 398 | | } |
| | 399 | |
|
| | 400 | | /// <summary> Gets a list of statements within a spark session. </summary> |
| | 401 | | /// <param name="sessionId"> Identifier for the session. </param> |
| | 402 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 403 | | public async Task<Response<SparkStatementCollection>> GetSparkStatementsAsync(int sessionId, CancellationToken c |
| | 404 | | { |
| 0 | 405 | | using var message = CreateGetSparkStatementsRequest(sessionId); |
| 0 | 406 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 407 | | switch (message.Response.Status) |
| | 408 | | { |
| | 409 | | case 200: |
| | 410 | | { |
| | 411 | | SparkStatementCollection value = default; |
| 0 | 412 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 413 | | value = SparkStatementCollection.DeserializeSparkStatementCollection(document.RootElement); |
| 0 | 414 | | return Response.FromValue(value, message.Response); |
| | 415 | | } |
| | 416 | | default: |
| 0 | 417 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 418 | | } |
| 0 | 419 | | } |
| | 420 | |
|
| | 421 | | /// <summary> Gets a list of statements within a spark session. </summary> |
| | 422 | | /// <param name="sessionId"> Identifier for the session. </param> |
| | 423 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 424 | | public Response<SparkStatementCollection> GetSparkStatements(int sessionId, CancellationToken cancellationToken |
| | 425 | | { |
| 0 | 426 | | using var message = CreateGetSparkStatementsRequest(sessionId); |
| 0 | 427 | | _pipeline.Send(message, cancellationToken); |
| 0 | 428 | | switch (message.Response.Status) |
| | 429 | | { |
| | 430 | | case 200: |
| | 431 | | { |
| | 432 | | SparkStatementCollection value = default; |
| 0 | 433 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 434 | | value = SparkStatementCollection.DeserializeSparkStatementCollection(document.RootElement); |
| 0 | 435 | | return Response.FromValue(value, message.Response); |
| | 436 | | } |
| | 437 | | default: |
| 0 | 438 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 439 | | } |
| 0 | 440 | | } |
| | 441 | |
|
| | 442 | | internal HttpMessage CreateCreateSparkStatementRequest(int sessionId, SparkStatementOptions sparkStatementOption |
| | 443 | | { |
| 0 | 444 | | var message = _pipeline.CreateMessage(); |
| 0 | 445 | | var request = message.Request; |
| 0 | 446 | | request.Method = RequestMethod.Post; |
| 0 | 447 | | var uri = new RawRequestUriBuilder(); |
| 0 | 448 | | uri.AppendRaw(endpoint, false); |
| 0 | 449 | | uri.AppendRaw("/livyApi/versions/", false); |
| 0 | 450 | | uri.AppendRaw(livyApiVersion, false); |
| 0 | 451 | | uri.AppendRaw("/sparkPools/", false); |
| 0 | 452 | | uri.AppendRaw(sparkPoolName, false); |
| 0 | 453 | | uri.AppendPath("/sessions/", false); |
| 0 | 454 | | uri.AppendPath(sessionId, true); |
| 0 | 455 | | uri.AppendPath("/statements", false); |
| 0 | 456 | | request.Uri = uri; |
| 0 | 457 | | request.Headers.Add("Content-Type", "application/json"); |
| 0 | 458 | | var content = new Utf8JsonRequestContent(); |
| 0 | 459 | | content.JsonWriter.WriteObjectValue(sparkStatementOptions); |
| 0 | 460 | | request.Content = content; |
| 0 | 461 | | return message; |
| | 462 | | } |
| | 463 | |
|
| | 464 | | /// <summary> Create statement within a spark session. </summary> |
| | 465 | | /// <param name="sessionId"> Identifier for the session. </param> |
| | 466 | | /// <param name="sparkStatementOptions"> Livy compatible batch job request payload. </param> |
| | 467 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 468 | | /// <exception cref="ArgumentNullException"> <paramref name="sparkStatementOptions"/> is null. </exception> |
| | 469 | | public async Task<Response<SparkStatement>> CreateSparkStatementAsync(int sessionId, SparkStatementOptions spark |
| | 470 | | { |
| 0 | 471 | | if (sparkStatementOptions == null) |
| | 472 | | { |
| 0 | 473 | | throw new ArgumentNullException(nameof(sparkStatementOptions)); |
| | 474 | | } |
| | 475 | |
|
| 0 | 476 | | using var message = CreateCreateSparkStatementRequest(sessionId, sparkStatementOptions); |
| 0 | 477 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 478 | | switch (message.Response.Status) |
| | 479 | | { |
| | 480 | | case 200: |
| | 481 | | { |
| | 482 | | SparkStatement value = default; |
| 0 | 483 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 484 | | value = SparkStatement.DeserializeSparkStatement(document.RootElement); |
| 0 | 485 | | return Response.FromValue(value, message.Response); |
| | 486 | | } |
| | 487 | | default: |
| 0 | 488 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 489 | | } |
| 0 | 490 | | } |
| | 491 | |
|
| | 492 | | /// <summary> Create statement within a spark session. </summary> |
| | 493 | | /// <param name="sessionId"> Identifier for the session. </param> |
| | 494 | | /// <param name="sparkStatementOptions"> Livy compatible batch job request payload. </param> |
| | 495 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 496 | | /// <exception cref="ArgumentNullException"> <paramref name="sparkStatementOptions"/> is null. </exception> |
| | 497 | | public Response<SparkStatement> CreateSparkStatement(int sessionId, SparkStatementOptions sparkStatementOptions, |
| | 498 | | { |
| 0 | 499 | | if (sparkStatementOptions == null) |
| | 500 | | { |
| 0 | 501 | | throw new ArgumentNullException(nameof(sparkStatementOptions)); |
| | 502 | | } |
| | 503 | |
|
| 0 | 504 | | using var message = CreateCreateSparkStatementRequest(sessionId, sparkStatementOptions); |
| 0 | 505 | | _pipeline.Send(message, cancellationToken); |
| 0 | 506 | | switch (message.Response.Status) |
| | 507 | | { |
| | 508 | | case 200: |
| | 509 | | { |
| | 510 | | SparkStatement value = default; |
| 0 | 511 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 512 | | value = SparkStatement.DeserializeSparkStatement(document.RootElement); |
| 0 | 513 | | return Response.FromValue(value, message.Response); |
| | 514 | | } |
| | 515 | | default: |
| 0 | 516 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 517 | | } |
| 0 | 518 | | } |
| | 519 | |
|
| | 520 | | internal HttpMessage CreateGetSparkStatementRequest(int sessionId, int statementId) |
| | 521 | | { |
| 0 | 522 | | var message = _pipeline.CreateMessage(); |
| 0 | 523 | | var request = message.Request; |
| 0 | 524 | | request.Method = RequestMethod.Get; |
| 0 | 525 | | var uri = new RawRequestUriBuilder(); |
| 0 | 526 | | uri.AppendRaw(endpoint, false); |
| 0 | 527 | | uri.AppendRaw("/livyApi/versions/", false); |
| 0 | 528 | | uri.AppendRaw(livyApiVersion, false); |
| 0 | 529 | | uri.AppendRaw("/sparkPools/", false); |
| 0 | 530 | | uri.AppendRaw(sparkPoolName, false); |
| 0 | 531 | | uri.AppendPath("/sessions/", false); |
| 0 | 532 | | uri.AppendPath(sessionId, true); |
| 0 | 533 | | uri.AppendPath("/statements/", false); |
| 0 | 534 | | uri.AppendPath(statementId, true); |
| 0 | 535 | | request.Uri = uri; |
| 0 | 536 | | return message; |
| | 537 | | } |
| | 538 | |
|
| | 539 | | /// <summary> Gets a single statement within a spark session. </summary> |
| | 540 | | /// <param name="sessionId"> Identifier for the session. </param> |
| | 541 | | /// <param name="statementId"> Identifier for the statement. </param> |
| | 542 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 543 | | public async Task<Response<SparkStatement>> GetSparkStatementAsync(int sessionId, int statementId, CancellationT |
| | 544 | | { |
| 0 | 545 | | using var message = CreateGetSparkStatementRequest(sessionId, statementId); |
| 0 | 546 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 547 | | switch (message.Response.Status) |
| | 548 | | { |
| | 549 | | case 200: |
| | 550 | | { |
| | 551 | | SparkStatement value = default; |
| 0 | 552 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 553 | | value = SparkStatement.DeserializeSparkStatement(document.RootElement); |
| 0 | 554 | | return Response.FromValue(value, message.Response); |
| | 555 | | } |
| | 556 | | default: |
| 0 | 557 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 558 | | } |
| 0 | 559 | | } |
| | 560 | |
|
| | 561 | | /// <summary> Gets a single statement within a spark session. </summary> |
| | 562 | | /// <param name="sessionId"> Identifier for the session. </param> |
| | 563 | | /// <param name="statementId"> Identifier for the statement. </param> |
| | 564 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 565 | | public Response<SparkStatement> GetSparkStatement(int sessionId, int statementId, CancellationToken cancellation |
| | 566 | | { |
| 0 | 567 | | using var message = CreateGetSparkStatementRequest(sessionId, statementId); |
| 0 | 568 | | _pipeline.Send(message, cancellationToken); |
| 0 | 569 | | switch (message.Response.Status) |
| | 570 | | { |
| | 571 | | case 200: |
| | 572 | | { |
| | 573 | | SparkStatement value = default; |
| 0 | 574 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 575 | | value = SparkStatement.DeserializeSparkStatement(document.RootElement); |
| 0 | 576 | | return Response.FromValue(value, message.Response); |
| | 577 | | } |
| | 578 | | default: |
| 0 | 579 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 580 | | } |
| 0 | 581 | | } |
| | 582 | |
|
| | 583 | | internal HttpMessage CreateCancelSparkStatementRequest(int sessionId, int statementId) |
| | 584 | | { |
| 0 | 585 | | var message = _pipeline.CreateMessage(); |
| 0 | 586 | | var request = message.Request; |
| 0 | 587 | | request.Method = RequestMethod.Post; |
| 0 | 588 | | var uri = new RawRequestUriBuilder(); |
| 0 | 589 | | uri.AppendRaw(endpoint, false); |
| 0 | 590 | | uri.AppendRaw("/livyApi/versions/", false); |
| 0 | 591 | | uri.AppendRaw(livyApiVersion, false); |
| 0 | 592 | | uri.AppendRaw("/sparkPools/", false); |
| 0 | 593 | | uri.AppendRaw(sparkPoolName, false); |
| 0 | 594 | | uri.AppendPath("/sessions/", false); |
| 0 | 595 | | uri.AppendPath(sessionId, true); |
| 0 | 596 | | uri.AppendPath("/statements/", false); |
| 0 | 597 | | uri.AppendPath(statementId, true); |
| 0 | 598 | | uri.AppendPath("/cancel", false); |
| 0 | 599 | | request.Uri = uri; |
| 0 | 600 | | return message; |
| | 601 | | } |
| | 602 | |
|
| | 603 | | /// <summary> Kill a statement within a session. </summary> |
| | 604 | | /// <param name="sessionId"> Identifier for the session. </param> |
| | 605 | | /// <param name="statementId"> Identifier for the statement. </param> |
| | 606 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 607 | | public async Task<Response<SparkStatementCancellationResult>> CancelSparkStatementAsync(int sessionId, int state |
| | 608 | | { |
| 0 | 609 | | using var message = CreateCancelSparkStatementRequest(sessionId, statementId); |
| 0 | 610 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 611 | | switch (message.Response.Status) |
| | 612 | | { |
| | 613 | | case 200: |
| | 614 | | { |
| | 615 | | SparkStatementCancellationResult value = default; |
| 0 | 616 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 617 | | value = SparkStatementCancellationResult.DeserializeSparkStatementCancellationResult(document.Ro |
| 0 | 618 | | return Response.FromValue(value, message.Response); |
| | 619 | | } |
| | 620 | | default: |
| 0 | 621 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 622 | | } |
| 0 | 623 | | } |
| | 624 | |
|
| | 625 | | /// <summary> Kill a statement within a session. </summary> |
| | 626 | | /// <param name="sessionId"> Identifier for the session. </param> |
| | 627 | | /// <param name="statementId"> Identifier for the statement. </param> |
| | 628 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 629 | | public Response<SparkStatementCancellationResult> CancelSparkStatement(int sessionId, int statementId, Cancellat |
| | 630 | | { |
| 0 | 631 | | using var message = CreateCancelSparkStatementRequest(sessionId, statementId); |
| 0 | 632 | | _pipeline.Send(message, cancellationToken); |
| 0 | 633 | | switch (message.Response.Status) |
| | 634 | | { |
| | 635 | | case 200: |
| | 636 | | { |
| | 637 | | SparkStatementCancellationResult value = default; |
| 0 | 638 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 639 | | value = SparkStatementCancellationResult.DeserializeSparkStatementCancellationResult(document.Ro |
| 0 | 640 | | return Response.FromValue(value, message.Response); |
| | 641 | | } |
| | 642 | | default: |
| 0 | 643 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 644 | | } |
| 0 | 645 | | } |
| | 646 | | } |
| | 647 | | } |