| | 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.Core; |
| | 14 | | using Azure.Core.Pipeline; |
| | 15 | | using Azure.Search.Documents.Indexes.Models; |
| | 16 | |
|
| | 17 | | namespace Azure.Search.Documents |
| | 18 | | { |
| | 19 | | internal partial class ServiceRestClient |
| | 20 | | { |
| | 21 | | private string endpoint; |
| | 22 | | private Guid? xMsClientRequestId; |
| | 23 | | private string apiVersion; |
| | 24 | | private ClientDiagnostics _clientDiagnostics; |
| | 25 | | private HttpPipeline _pipeline; |
| | 26 | |
|
| | 27 | | /// <summary> Initializes a new instance of ServiceRestClient. </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 endpoint URL of the search service. </param> |
| | 31 | | /// <param name="xMsClientRequestId"> The tracking ID sent with the request to help with debugging. </param> |
| | 32 | | /// <param name="apiVersion"> Api Version. </param> |
| | 33 | | /// <exception cref="ArgumentNullException"> <paramref name="endpoint"/> or <paramref name="apiVersion"/> is nul |
| 6 | 34 | | public ServiceRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint, Guid? xMsC |
| | 35 | | { |
| 6 | 36 | | if (endpoint == null) |
| | 37 | | { |
| 0 | 38 | | throw new ArgumentNullException(nameof(endpoint)); |
| | 39 | | } |
| 6 | 40 | | if (apiVersion == null) |
| | 41 | | { |
| 0 | 42 | | throw new ArgumentNullException(nameof(apiVersion)); |
| | 43 | | } |
| | 44 | |
|
| 6 | 45 | | this.endpoint = endpoint; |
| 6 | 46 | | this.xMsClientRequestId = xMsClientRequestId; |
| 6 | 47 | | this.apiVersion = apiVersion; |
| 6 | 48 | | _clientDiagnostics = clientDiagnostics; |
| 6 | 49 | | _pipeline = pipeline; |
| 6 | 50 | | } |
| | 51 | |
|
| | 52 | | internal HttpMessage CreateGetServiceStatisticsRequest() |
| | 53 | | { |
| 6 | 54 | | var message = _pipeline.CreateMessage(); |
| 6 | 55 | | var request = message.Request; |
| 6 | 56 | | request.Method = RequestMethod.Get; |
| 6 | 57 | | var uri = new RawRequestUriBuilder(); |
| 6 | 58 | | uri.AppendRaw(endpoint, false); |
| 6 | 59 | | uri.AppendPath("/servicestats", false); |
| 6 | 60 | | uri.AppendQuery("api-version", apiVersion, true); |
| 6 | 61 | | request.Uri = uri; |
| 6 | 62 | | if (xMsClientRequestId != null) |
| | 63 | | { |
| 0 | 64 | | request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value); |
| | 65 | | } |
| 6 | 66 | | request.Headers.Add("Accept", "application/json; odata.metadata=minimal"); |
| 6 | 67 | | return message; |
| | 68 | | } |
| | 69 | |
|
| | 70 | | /// <summary> Gets service level statistics for a search service. </summary> |
| | 71 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 72 | | public async Task<Response<SearchServiceStatistics>> GetServiceStatisticsAsync(CancellationToken cancellationTok |
| | 73 | | { |
| 3 | 74 | | using var message = CreateGetServiceStatisticsRequest(); |
| 3 | 75 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 3 | 76 | | switch (message.Response.Status) |
| | 77 | | { |
| | 78 | | case 200: |
| | 79 | | { |
| | 80 | | SearchServiceStatistics value = default; |
| 3 | 81 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 3 | 82 | | value = SearchServiceStatistics.DeserializeSearchServiceStatistics(document.RootElement); |
| 3 | 83 | | return Response.FromValue(value, message.Response); |
| | 84 | | } |
| | 85 | | default: |
| 0 | 86 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 87 | | } |
| 3 | 88 | | } |
| | 89 | |
|
| | 90 | | /// <summary> Gets service level statistics for a search service. </summary> |
| | 91 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 92 | | public Response<SearchServiceStatistics> GetServiceStatistics(CancellationToken cancellationToken = default) |
| | 93 | | { |
| 3 | 94 | | using var message = CreateGetServiceStatisticsRequest(); |
| 3 | 95 | | _pipeline.Send(message, cancellationToken); |
| 3 | 96 | | switch (message.Response.Status) |
| | 97 | | { |
| | 98 | | case 200: |
| | 99 | | { |
| | 100 | | SearchServiceStatistics value = default; |
| 3 | 101 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 3 | 102 | | value = SearchServiceStatistics.DeserializeSearchServiceStatistics(document.RootElement); |
| 3 | 103 | | return Response.FromValue(value, message.Response); |
| | 104 | | } |
| | 105 | | default: |
| 0 | 106 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 107 | | } |
| 3 | 108 | | } |
| | 109 | | } |
| | 110 | | } |