Skip to content

Commit 8a5a2fe

Browse files
authored
Remove high level to low level dispatch (#3658)
High level client now directly calls into DoRequest and no longer calls its equivalent low level method * remove _LowLevelDispatch.generated.cs * renamed temp names for methods to DoRequest(Async) * LowLevelDispatch no longer part of code generation * Requests now responsible for building urls, came up with a decent first attempt at cached builders * fixed test failures mainly to do with _all no no longer magically be rewritten * IndexRequest is an odd one it needs a reference to a resolved id in order to determine the right HttpMethod Made this explicit through ResolvedRouteValues but not too keen to keep this around. ConnectionSettings small refactor, now exposes Id to uniquely identify the instance
2 parents 45026fc + 1b2a116 commit 8a5a2fe

File tree

280 files changed

+3468
-9867
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

280 files changed

+3468
-9867
lines changed

src/CodeGeneration/ApiGenerator/ApiGenerator.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.IO;
55
using System.Linq;
66
using ApiGenerator.Domain;
7-
using CsQuery.EquationParser.Implementation;
87
using Newtonsoft.Json.Linq;
98
using RazorLight;
109
using ShellProgressBar;
@@ -31,7 +30,6 @@ public static void Generate(string downloadBranch, params string[] folders)
3130
{ GenerateRequests, "Requests" },
3231
{ GenerateEnums, "Enums" },
3332
{ GenerateRawClient, "Lowlevel client" },
34-
{ GenerateRawDispatch, "Dispatch" },
3533
};
3634

3735
using (var pbar = new ProgressBar(actions.Count, "Generating code", new ProgressBarOptions { BackgroundColor = ConsoleColor.DarkGray }))
@@ -195,14 +193,6 @@ private static void GenerateClientInterface(RestApiSpec model)
195193
File.WriteAllText(targetFile, source);
196194
}
197195

198-
private static void GenerateRawDispatch(RestApiSpec model)
199-
{
200-
var targetFile = CodeConfiguration.NestFolder + @"_Generated/_LowLevelDispatch.Generated.cs";
201-
var source = DoRazor(nameof(GenerateRawDispatch), File.ReadAllText(CodeConfiguration.ViewFolder + @"_LowLevelDispatch.Generated.cshtml"),
202-
model);
203-
File.WriteAllText(targetFile, source);
204-
}
205-
206196
private static void GenerateRawClient(RestApiSpec model)
207197
{
208198
var targetFile = CodeConfiguration.EsNetFolder + @"ElasticLowLevelClient.Generated.cs";

src/CodeGeneration/ApiGenerator/Views/_Descriptors.Generated.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace Nest
3737
///<summary>descriptor for @method.FullName <pre>@method.Documentation</pre></summary>
3838
public partial class @Raw(type) @(Raw(string.Format(" : RequestDescriptorBase<{0},{1}, {2}>, {2}", type, method.QueryStringParamName, concreteInterface)))
3939
{
40+
internal override ApiUrls ApiUrls => @(Raw(method.RequestType)).Urls;
4041
@foreach (Constructor c in Constructor.DescriptorConstructors(method))
4142
{
4243
<text> @(Raw(CodeGenerator.Constructor(c)))

src/CodeGeneration/ApiGenerator/Views/_LowLevelDispatch.Generated.cshtml

Lines changed: 0 additions & 117 deletions
This file was deleted.

src/CodeGeneration/ApiGenerator/Views/_Requests.Generated.cshtml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ namespace Nest
7676
public partial class @Raw(method.RequestType) @Raw(string.Format(": PlainRequestBase<{0}>, {1}", method.QueryStringParamName, method.InterfaceType))
7777
{
7878
protected @(Raw(method.InterfaceType)) Self => this;
79+
internal static ApiUrls Urls = new ApiUrls(new [] {@Raw(string.Join(", ", method.Url.ExposedApiPaths.Select(p=>$"\"{p.Path}\"")))});
80+
internal override ApiUrls ApiUrls => Urls;
7981
@foreach (Constructor c in Constructor.RequestConstructors(method, inheritsFromPlainRequestBase: true))
8082
{
8183
<text> @(Raw(CodeGenerator.Constructor(c)))

src/Elasticsearch.Net/Configuration/ConnectionConfiguration.cs

Lines changed: 28 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -64,71 +64,42 @@ public abstract class ConnectionConfiguration<T> : IConnectionConfigurationValue
6464
where T : ConnectionConfiguration<T>
6565
{
6666
private readonly IConnection _connection;
67-
6867
private readonly IConnectionPool _connectionPool;
69-
7068
private readonly NameValueCollection _headers = new NameValueCollection();
71-
7269
private readonly NameValueCollection _queryString = new NameValueCollection();
7370
private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);
74-
71+
private readonly ElasticsearchUrlFormatter _urlFormatter;
72+
7573
private BasicAuthenticationCredentials _basicAuthCredentials;
76-
7774
private X509CertificateCollection _clientCertificates;
7875
private Action<IApiCallDetails> _completedRequestHandler = DefaultCompletedRequestHandler;
79-
8076
private int _connectionLimit;
81-
8277
private TimeSpan? _deadTimeout;
83-
8478
private bool _disableAutomaticProxyDetection = false;
85-
8679
private bool _disableDirectStreaming = false;
87-
8880
private bool _disablePings;
89-
9081
private bool _enableHttpCompression;
91-
9282
private bool _enableHttpPipelining = true;
93-
9483
private TimeSpan? _keepAliveInterval;
95-
9684
private TimeSpan? _keepAliveTime;
97-
9885
private TimeSpan? _maxDeadTimeout;
99-
10086
private int? _maxRetries;
101-
10287
private TimeSpan? _maxRetryTimeout;
103-
10488
private Func<Node, bool> _nodePredicate = DefaultNodePredicate;
10589
private Action<RequestData> _onRequestDataCreated = DefaultRequestDataCreated;
106-
10790
private TimeSpan? _pingTimeout;
108-
10991
private bool _prettyJson;
110-
11192
private string _proxyAddress;
112-
11393
private string _proxyPassword;
114-
11594
private string _proxyUsername;
116-
11795
private TimeSpan _requestTimeout;
118-
11996
private Func<object, X509Certificate, X509Chain, SslPolicyErrors, bool> _serverCertificateValidationCallback;
120-
12197
private IReadOnlyCollection<int> _skipDeserializationForStatusCodes = new ReadOnlyCollection<int>(new int[] { });
122-
12398
private TimeSpan? _sniffLifeSpan;
124-
12599
private bool _sniffOnConnectionFault;
126-
127100
private bool _sniffOnStartup;
128-
129101
private bool _throwExceptions;
130-
131-
private readonly ElasticsearchUrlFormatter _urlFormatter;
102+
private string _uniqueId = Guid.NewGuid().ToString("N");
132103

133104
protected ConnectionConfiguration(IConnectionPool connectionPool, IConnection connection, IElasticsearchSerializer requestResponseSerializer)
134105
{
@@ -147,6 +118,7 @@ protected ConnectionConfiguration(IConnectionPool connectionPool, IConnection co
147118
_urlFormatter = new ElasticsearchUrlFormatter(this);
148119
}
149120

121+
string IConnectionConfigurationValues.Id => _uniqueId;
150122
protected IElasticsearchSerializer UseThisRequestResponseSerializer { get; set; }
151123
BasicAuthenticationCredentials IConnectionConfigurationValues.BasicAuthenticationCredentials => _basicAuthCredentials;
152124
SemaphoreSlim IConnectionConfigurationValues.BootstrapLock => _semaphore;
@@ -205,11 +177,11 @@ private static void DefaultRequestDataCreated(RequestData response) { }
205177

206178
private static bool DefaultNodePredicate(Node node) => true;
207179

208-
private T Assign<TValue>(TValue value, Action<ConnectionConfiguration<T>, TValue> assigner) => Fluent.Assign((T)this, value, assigner);
180+
protected T UpdateId() => Fluent.Assign<T, T, string>((T)this, Guid.NewGuid().ToString("N"), (a, v) => a._uniqueId = v);
181+
182+
protected T Assign<TValue>(TValue value, Action<T, TValue> assigner) => Fluent.Assign((T)this, value, assigner).UpdateId();
209183

210-
/// <summary>
211-
/// The default serializer used to serialize documents to and from JSON
212-
/// </summary>
184+
/// <summary> The default serializer used to serialize documents to and from JSON </summary>
213185
protected virtual IElasticsearchSerializer DefaultSerializer(T settings) => new LowLevelRequestResponseSerializer();
214186

215187
/// <summary>
@@ -225,9 +197,7 @@ public T EnableTcpKeepAlive(TimeSpan keepAliveTime, TimeSpan keepAliveInterval)
225197
Assign(keepAliveTime, (a, v) => a._keepAliveTime = v)
226198
.Assign(keepAliveInterval, (a, v) => a._keepAliveInterval = v);
227199

228-
/// <summary>
229-
/// The maximum number of retries for a given request,
230-
/// </summary>
200+
/// <summary> The maximum number of retries for a given request </summary>
231201
public T MaximumRetries(int maxRetries) => Assign(maxRetries, (a, v) => a._maxRetries = v);
232202

233203
/// <summary>
@@ -341,14 +311,10 @@ public T SniffOnConnectionFault(bool sniffsOnConnectionFault = true) =>
341311
/// <summary>
342312
/// If your connection has to go through proxy, use this method to specify the proxy url
343313
/// </summary>
344-
public T Proxy(Uri proxyAdress, string username, string password)
345-
{
346-
proxyAdress.ThrowIfNull(nameof(proxyAdress));
347-
_proxyAddress = proxyAdress.ToString();
348-
_proxyUsername = username;
349-
_proxyPassword = password;
350-
return (T)this;
351-
}
314+
public T Proxy(Uri proxyAdress, string username, string password) =>
315+
Assign(proxyAdress.ToString(), (a, v) => a._proxyAddress = v)
316+
.Assign(username, (a, v) => a._proxyUsername = v)
317+
.Assign(password, (a, v) => a._proxyPassword = v);
352318

353319
/// <summary>
354320
/// Forces all requests to have ?pretty=true querystring parameter appended,
@@ -422,13 +388,7 @@ public T BasicAuthentication(string userName, string password) =>
422388
/// verbatim.
423389
/// </summary>
424390
/// <param name="predicate">Return true if you want the node to be used for API calls</param>
425-
public T NodePredicate(Func<Node, bool> predicate)
426-
{
427-
if (predicate == null) return (T)this;
428-
429-
_nodePredicate = predicate;
430-
return (T)this;
431-
}
391+
public T NodePredicate(Func<Node, bool> predicate) => Assign(predicate ?? DefaultNodePredicate, (a, v) => a._nodePredicate = predicate);
432392

433393
/// <summary>
434394
/// Turns on settings that aid in debugging like DisableDirectStreaming() and PrettyJson()
@@ -440,22 +400,20 @@ public T NodePredicate(Func<Node, bool> predicate)
440400
/// ConnectionSettings. If no callback is passed, DebugInformation from the response
441401
/// will be written to the debug output by default.
442402
/// </param>
443-
public T EnableDebugMode(Action<IApiCallDetails> onRequestCompleted = null)
444-
{
445-
_disableDirectStreaming = true;
446-
PrettyJson(true);
447-
IncludeServerStackTraceOnError(true);
448-
449-
var originalCompletedRequestHandler = _completedRequestHandler;
450-
var debugCompletedRequestHandler = onRequestCompleted ?? (d => Debug.WriteLine(d.DebugInformation));
451-
_completedRequestHandler = d =>
452-
{
453-
originalCompletedRequestHandler?.Invoke(d);
454-
debugCompletedRequestHandler?.Invoke(d);
455-
};
456-
457-
return (T)this;
458-
}
403+
public T EnableDebugMode(Action<IApiCallDetails> onRequestCompleted = null) =>
404+
PrettyJson()
405+
.IncludeServerStackTraceOnError()
406+
.DisableDirectStreaming()
407+
.Assign(onRequestCompleted, (a, v) =>
408+
{
409+
var originalCompletedRequestHandler = _completedRequestHandler;
410+
var debugCompletedRequestHandler = v ?? (d => Debug.WriteLine(d.DebugInformation));
411+
_completedRequestHandler = d =>
412+
{
413+
originalCompletedRequestHandler?.Invoke(d);
414+
debugCompletedRequestHandler.Invoke(d);
415+
};
416+
});
459417

460418
/// <summary>
461419
/// Register a ServerCertificateValidationCallback, this is called per endpoint until it returns true.

src/Elasticsearch.Net/Configuration/IConnectionConfigurationValues.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ namespace Elasticsearch.Net
99
{
1010
public interface IConnectionConfigurationValues : IDisposable
1111
{
12+
// TODO: reevaluate for the 7.0.0-beta1
13+
/// <summary> A unique id for this connection settings instance </summary>
14+
string Id { get; }
15+
1216
/// <summary>
1317
/// Basic access authorization credentials to specify with all requests.
1418
/// </summary>

src/Elasticsearch.Net/Serialization/ElasticsearchUrlFormatter.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ public string Format(string format, object arg, IFormatProvider formatProvider)
2626

2727
public object GetFormat(Type formatType) => formatType == typeof(ICustomFormatter) ? this : null;
2828

29-
public string CreateEscapedString(object value)
30-
{
31-
var r = CreateString(value, _settings);
32-
return r.IsNullOrEmpty() ? string.Empty : Uri.EscapeDataString(r);
33-
}
34-
3529
public string CreateString(object value) => CreateString(value, _settings);
3630

3731
public static string CreateString(object value, IConnectionConfigurationValues settings)

0 commit comments

Comments
 (0)