Skip to content

Commit 0130a60

Browse files
committed
low level client now generated off 1.2 spec
1 parent fbdb6ba commit 0130a60

27 files changed

+3929
-1240
lines changed

src/CodeGeneration/CodeGeneration.LowLevelClient/ApiGenerator.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ namespace CodeGeneration.LowLevelClient
1717
{
1818
public static class ApiGenerator
1919
{
20-
private readonly static string _listingUrl = "https://github.com/elasticsearch/elasticsearch/tree/v1.1.0/rest-api-spec/api";
21-
private readonly static string _rawUrlPrefix = "https://raw.github.com/elasticsearch/elasticsearch/v1.1.0/rest-api-spec/api/";
20+
private readonly static string _listingUrl = "https://github.com/elasticsearch/elasticsearch/tree/v1.2.0/rest-api-spec/api";
21+
private readonly static string _rawUrlPrefix = "https://raw.github.com/elasticsearch/elasticsearch/v1.2.0/rest-api-spec/api/";
2222
private readonly static string _nestFolder = @"..\..\..\..\..\src\Nest\";
2323
private readonly static string _esNetFolder = @"..\..\..\..\..\src\Elasticsearch.Net\";
2424
private readonly static string _viewFolder = @"..\..\Views\";

src/CodeGeneration/CodeGeneration.LowLevelClient/Overrides/Allow404/ApiEndpointsThatAllow404.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public static class ApiEndpointsThatAllow404
1313
{
1414
"DocumentExists",
1515
"Delete",
16-
"IndexExists"
16+
"IndexExists",
17+
"Exists"
1718
};
1819
}
1920
}

src/CodeGeneration/CodeGeneration.YamlTestsRunner/YamlTestsGenerator.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ namespace CodeGeneration.YamlTestsRunner
2525
using YamlTestSuite = Dictionary<string, object>;
2626
public static class YamlTestsGenerator
2727
{
28-
private readonly static string _listingUrl = "https://github.com/elasticsearch/elasticsearch/tree/v1.1.0/rest-api-spec/test";
29-
private readonly static string _rawUrlPrefix = "https://raw.github.com/elasticsearch/elasticsearch/v1.1.0/rest-api-spec/test/";
28+
private readonly static string _listingUrl = "https://github.com/elasticsearch/elasticsearch/tree/v1.2.0/rest-api-spec/test";
29+
private readonly static string _rawUrlPrefix = "https://raw.github.com/elasticsearch/elasticsearch/v1.2.0/rest-api-spec/test/";
3030
private readonly static string _testProjectFolder = @"..\..\..\..\..\src\Tests\Elasticsearch.Net.Integration.Yaml\";
3131
private readonly static string _rawClientInterface = @"..\..\..\..\..\src\Elasticsearch.Net\IElasticsearchClient.generated.cs";
3232
private readonly static string _viewFolder = @"..\..\Views\";

src/Elasticsearch.Net/Connection/ElasticsearchServerException.cs

+16-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,27 @@
99

1010
namespace Elasticsearch.Net.Connection
1111
{
12+
internal class OneToOneServerException
13+
{
14+
public int status { get; set; }
15+
public string error { get; set; }
16+
}
17+
1218
public class ElasticsearchServerError
1319
{
1420
public int Status { get; set; }
1521
public string Error { get; set; }
1622
public string ExceptionType { get; set; }
17-
23+
24+
internal static ElasticsearchServerError Create(OneToOneServerException e)
25+
{
26+
if (e == null) return null;
27+
return new ElasticsearchServerError
28+
{
29+
Status = e.status,
30+
Error = e.error
31+
};
32+
}
1833
}
1934

2035
public class ElasticsearchServerException : Exception

src/Elasticsearch.Net/Connection/Transport.cs

+45-25
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ private ElasticsearchResponse<T> DoRequest<T>(TransportRequestState<T> requestSt
174174
if (!SniffingDisabled(requestState.RequestConfiguration))
175175
SniffIfInformationIsTooOld(retried);
176176

177-
IElasticsearchResponse response = null;
177+
var aliveResponse = false;
178178

179179
int initialSeed; bool shouldPingHint;
180180
var baseUri = GetNextBaseUri(requestState, out initialSeed, out shouldPingHint);
@@ -200,7 +200,7 @@ private ElasticsearchResponse<T> DoRequest<T>(TransportRequestState<T> requestSt
200200
var typedResponse = this.StreamToTypedResponse<T>(streamResponse, requestState.DeserializationState);
201201
typedResponse.NumberOfRetries = retried;
202202
this.SetErrorDiagnosticsAndPatchSuccess(requestState, error, typedResponse, streamResponse);
203-
response = typedResponse;
203+
aliveResponse = typedResponse.SuccessOrKnownError;
204204
return typedResponse;
205205
}
206206
}
@@ -215,7 +215,7 @@ private ElasticsearchResponse<T> DoRequest<T>(TransportRequestState<T> requestSt
215215
finally
216216
{
217217
//make sure we always call markalive on the uri if the connection was succesful
218-
if (!seenError && response != null && response.SuccessOrKnownError)
218+
if (!seenError && aliveResponse)
219219
this._connectionPool.MarkAlive(baseUri);
220220
}
221221
return RetryRequest<T>(requestState, baseUri, retried);
@@ -237,27 +237,6 @@ private void SetErrorDiagnosticsAndPatchSuccess<T>(TransportRequestState<T> requ
237237
}
238238
}
239239

240-
private ElasticsearchServerError ThrowOrGetErrorFromStreamResponse<T>(TransportRequestState<T> requestState,
241-
ElasticsearchResponse<Stream> streamResponse)
242-
{
243-
ElasticsearchServerError error = null;
244-
if ((!streamResponse.Success && requestState.RequestConfiguration == null)
245-
|| (!streamResponse.Success
246-
&& requestState.RequestConfiguration != null
247-
&& requestState.RequestConfiguration.AllowedStatusCodes.All(i => i != streamResponse.HttpStatusCode)))
248-
{
249-
if (streamResponse.Response != null)
250-
error = this.Serializer.Deserialize<ElasticsearchServerError>(streamResponse.Response);
251-
else
252-
error = new ElasticsearchServerError
253-
{
254-
Status = streamResponse.HttpStatusCode.GetValueOrDefault(-1)
255-
};
256-
if (this.Settings.ThrowOnElasticsearchServerExceptions)
257-
throw new ElasticsearchServerException(error);
258-
}
259-
return error;
260-
}
261240

262241
private Uri GetNextBaseUri<T>(TransportRequestState<T> requestState, out int initialSeed, out bool shouldPingHint)
263242
{
@@ -375,6 +354,8 @@ private Task<ElasticsearchResponse<T>> _doRequestAsyncOrRetry<T>(
375354
{
376355
tt.Result.NumberOfRetries = retried;
377356
this.SetErrorDiagnosticsAndPatchSuccess(requestState, error, tt.Result, t.Result);
357+
if (tt.Result.SuccessOrKnownError)
358+
this._connectionPool.MarkAlive(baseUri);
378359
return tt;
379360
}).Unwrap();
380361
}
@@ -459,7 +440,46 @@ private void SetByteResult(ElasticsearchResponse<byte[]> response, byte[] rawRes
459440
response.Response = rawResponse;
460441
}
461442

462-
private ElasticsearchResponse<T> StreamToTypedResponse<T>(ElasticsearchResponse<Stream> streamResponse, object deserializationState)
443+
private ElasticsearchServerError ThrowOrGetErrorFromStreamResponse<T>(
444+
TransportRequestState<T> requestState,
445+
ElasticsearchResponse<Stream> streamResponse)
446+
{
447+
ElasticsearchServerError error = null;
448+
if ((!streamResponse.Success && requestState.RequestConfiguration == null)
449+
|| (!streamResponse.Success
450+
&& requestState.RequestConfiguration != null
451+
&& requestState.RequestConfiguration.AllowedStatusCodes.All(i => i != streamResponse.HttpStatusCode)))
452+
{
453+
454+
if (streamResponse.Response != null && !this.Settings.KeepRawResponse)
455+
{
456+
var e =this.Serializer.Deserialize<OneToOneServerException>(streamResponse.Response);
457+
error = ElasticsearchServerError.Create(e);
458+
}
459+
else if (streamResponse.Response != null && this.Settings.KeepRawResponse)
460+
{
461+
var ms = new MemoryStream();
462+
streamResponse.Response.CopyTo(ms);
463+
ms.Position = 0;
464+
streamResponse.ResponseRaw = ms.ToArray();
465+
var e =this.Serializer.Deserialize<OneToOneServerException>(ms);
466+
error = ElasticsearchServerError.Create(e);
467+
ms.Position = 0;
468+
streamResponse.Response = ms;
469+
}
470+
else
471+
error = new ElasticsearchServerError
472+
{
473+
Status = streamResponse.HttpStatusCode.GetValueOrDefault(-1)
474+
};
475+
if (this.Settings.ThrowOnElasticsearchServerExceptions)
476+
throw new ElasticsearchServerException(error);
477+
}
478+
return error;
479+
}
480+
private ElasticsearchResponse<T> StreamToTypedResponse<T>(
481+
ElasticsearchResponse<Stream> streamResponse,
482+
object deserializationState)
463483
{
464484
//if the user explicitly wants a stream returned the undisposed stream
465485
if (typeof(Stream).IsAssignableFrom(typeof(T)))

src/Elasticsearch.Net/Domain/Enums.Generated.cs

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
///This file contains all the typed enums that the client rest api spec exposes.
99
///This file is automatically generated from https://github.com/elasticsearch/elasticsearch-rest-api-spec
10-
///Generated of commit 5f64a7f7e8
10+
///Generated of commit
1111
namespace Elasticsearch.Net
1212
{
1313

@@ -207,7 +207,9 @@ public enum IndicesStatsMetric
207207
[EnumMember(Value = "store")]
208208
Store,
209209
[EnumMember(Value = "warmer")]
210-
Warmer
210+
Warmer,
211+
[EnumMember(Value = "suggest")]
212+
Suggest
211213
}
212214

213215

@@ -294,7 +296,9 @@ public enum NodesStatsIndexMetric
294296
[EnumMember(Value = "store")]
295297
Store,
296298
[EnumMember(Value = "warmer")]
297-
Warmer
299+
Warmer,
300+
[EnumMember(Value = "suggest")]
301+
Suggest
298302
}
299303

300304

@@ -481,6 +485,7 @@ public static string Resolve(Enum e)
481485
case IndicesStatsMetric.Segments: return "segments";
482486
case IndicesStatsMetric.Store: return "store";
483487
case IndicesStatsMetric.Warmer: return "warmer";
488+
case IndicesStatsMetric.Suggest: return "suggest";
484489
}
485490
}
486491

@@ -541,6 +546,7 @@ public static string Resolve(Enum e)
541546
case NodesStatsIndexMetric.Segments: return "segments";
542547
case NodesStatsIndexMetric.Store: return "store";
543548
case NodesStatsIndexMetric.Warmer: return "warmer";
549+
case NodesStatsIndexMetric.Suggest: return "suggest";
544550
}
545551
}
546552

src/Elasticsearch.Net/Domain/IElasticsearchResponse.cs

+32-3
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,51 @@ namespace Elasticsearch.Net
66
{
77
public interface IElasticsearchResponse
88
{
9+
/// <summary>
10+
/// The response status code is in the 200 range or is in the allowed list of status codes set on the request.
11+
/// </summary>
912
bool Success { get; }
10-
bool SuccessOrKnownError { get; }
13+
14+
/// <summary>
15+
/// The request settings used by the request responsible for this response
16+
/// </summary>
1117
IConnectionConfigurationValues Settings { get; }
18+
19+
/// <summary>
20+
/// If Success is false this will hold the original exception.
21+
/// Can be a CLR exception or a mapped server side exception (ElasticsearchServerException)
22+
/// </summary>
1223
Exception OriginalException { get; }
24+
25+
/// <summary>
26+
/// The HTTP method used by the request
27+
/// </summary>
1328
string RequestMethod { get; }
29+
30+
/// <summary>
31+
/// The url as requested
32+
/// </summary>
1433
string RequestUrl { get; }
15-
[DebuggerDisplay("{Request != null ? System.Text.Encoding.UTF8.GetString(Request) : null,nq}")]
16-
byte[] Request { get; }
34+
35+
/// <summary>
36+
/// The status code as returned by Elasticsearch
37+
/// </summary>
1738
int? HttpStatusCode { get; }
39+
40+
41+
/// <summary>
42+
/// The number of times to request had to be retried before succeeding on a live node
43+
/// </summary>
1844
int NumberOfRetries { get; }
1945

2046
/// <summary>
2147
/// The raw byte response, only set when IncludeRawResponse() is set on Connection configuration
2248
/// </summary>
2349
[DebuggerDisplay("{ResponseRaw != null ? System.Text.Encoding.UTF8.GetString(ResponseRaw) : null,nq}")]
2450
byte[] ResponseRaw { get; }
51+
52+
[DebuggerDisplay("{Request != null ? System.Text.Encoding.UTF8.GetString(Request) : null,nq}")]
53+
byte[] Request { get; }
2554
}
2655

2756
public interface IResponseWithRequestInformation

0 commit comments

Comments
 (0)