Skip to content

Commit a372028

Browse files
committed
Add ElasticsearchPlugin to determine plugin directory and validity for ES version
Simpler version of what exists in 5.x+.
1 parent 3829543 commit a372028

File tree

7 files changed

+87
-26
lines changed

7 files changed

+87
-26
lines changed

build/scripts/scripts.fsproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@
6161
-->
6262
<Import Project="..\..\.paket\paket.targets" />
6363
<ItemGroup>
64+
<None Include="Projects.fsx" />
6465
<None Include="Paths.fsx" />
66+
<None Include="Tooling.fsx" />
6567
<None Include="Releasing.fsx" />
6668
<None Include="Versioning.fsx" />
6769
<None Include="Profiling.fsx" />

docs/client-concepts/connection-pooling/request-overrides/disable-sniff-ping-per-request.asciidoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ new ClientCall()
6464
);
6565
----
6666
<1> disable sniffing
67+
6768
<2> first call is a successful ping
69+
6870
<3> sniff on startup call happens here, on the second call
6971

7072
Now, let's disable pinging on the request
@@ -87,6 +89,7 @@ audit = await audit.TraceCall(
8789
);
8890
----
8991
<1> disable ping
92+
9093
<2> No ping after sniffing
9194

9295
Finally, let's demonstrate disabling both sniff and ping on the request
@@ -108,5 +111,6 @@ audit = await audit.TraceCall(
108111
);
109112
----
110113
<1> diable ping and sniff
114+
111115
<2> no ping or sniff before the call
112116

src/Tests/Framework/Integration/Process/ElasticsearchNode.cs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ namespace Tests.Framework.Integration
2121
public class ElasticsearchNode : IDisposable
2222
{
2323
private static readonly object _lock = new object();
24-
// <installpath> <> <plugin folder prefix>
25-
private readonly Dictionary<string, Func<string, string>> SupportedPlugins = new Dictionary<string, Func<string, string>>
26-
{
27-
{ "delete-by-query", _ => "delete-by-query" },
28-
{ "cloud-azure", _ => "cloud-azure" },
29-
{ "mapper-attachments", MapperAttachmentPlugin.GetVersion },
30-
{ "mapper-murmur3", _ => "mapper-murmur3" },
31-
{ "license", _ => "license" },
32-
{ "graph", _ => "graph" },
33-
{ "shield", _ => "shield" },
34-
{ "watcher", _ => "watcher" },
24+
25+
private readonly ElasticsearchPlugin[] SupportedPlugins = {
26+
new ElasticsearchPlugin("delete-by-query"),
27+
new ElasticsearchPlugin("cloud-azure"),
28+
new ElasticsearchPlugin("mapper-attachments", _ => true, MapperAttachmentPlugin.GetDirectory, MapperAttachmentPlugin.GetVersion),
29+
new ElasticsearchPlugin("mapper-murmur3"),
30+
new ElasticsearchPlugin("license"),
31+
new ElasticsearchPlugin("graph", v => v >= new ElasticsearchVersionInfo("2.3.0")),
32+
new ElasticsearchPlugin("shield"),
33+
new ElasticsearchPlugin("watcher")
3534
};
35+
3636
private string[] DefaultNodeSettings { get; }
3737

3838
private readonly bool _testAgainstAlreadyRunningElasticsearch;
@@ -50,10 +50,10 @@ public class ElasticsearchNode : IDisposable
5050

5151
public string TypeOfCluster { get; }
5252
public bool Started { get; private set; }
53-
public bool RunningIntegrations { get; private set; }
53+
public bool RunningIntegrations { get; }
5454
public string ClusterName { get; }
5555
public string NodeName { get; }
56-
public string RepositoryPath { get; private set; }
56+
public string RepositoryPath { get; }
5757
public ElasticsearchNodeInfo Info { get; private set; }
5858
public int Port { get; private set; }
5959

@@ -155,15 +155,14 @@ public ElasticsearchNode(
155155

156156
}
157157

158-
private object _lockGetClient = new object { };
158+
private readonly object _lockGetClient = new object();
159159
private IElasticClient _client;
160160
public IElasticClient Client
161161
{
162162
get
163163
{
164164
if (!this.Started && TestClient.Configuration.RunIntegrationTests)
165165
{
166-
167166
throw new Exception("can not request a client from an ElasticsearchNode if that node hasn't started yet");
168167
}
169168

@@ -174,6 +173,7 @@ public IElasticClient Client
174173
if (this._client != null) return this._client;
175174

176175
var port = this.Started ? this.Port : 9200;
176+
// ReSharper disable once PossibleMultipleWriteAccessInDoubleCheckLocking
177177
this._client = TestClient.GetClient(ComposeSettings, port);
178178
return this.Client;
179179
}
@@ -247,9 +247,14 @@ private IObservable<ElasticsearchMessage> UseAlreadyRunningInstance(ManualResetE
247247

248248
var checkPlugins = client.CatPlugins();
249249

250-
var missingPlugins = SupportedPlugins.Keys.Except(checkPlugins.Records.Select(r => r.Component)).ToList();
250+
var missingPlugins = SupportedPlugins
251+
.Where(p => p.IsValid(this.VersionInfo))
252+
.Select(p => p.Name)
253+
.Except(checkPlugins.Records.Select(r => r.Component))
254+
.ToList();
255+
251256
if (missingPlugins.Any())
252-
throw new Exception($"Already running elasticsearch missed the following plugin(s): {string.Join(", ", missingPlugins)}.");
257+
throw new Exception($"Already running elasticsearch missing the following plugin(s): {string.Join(", ", missingPlugins)}.");
253258

254259
this.Started = true;
255260
this.Port = 9200;
@@ -397,10 +402,10 @@ private void InstallPlugins()
397402
if (this.VersionInfo.ParsedVersion.Major >= 5) pluginCommand = "elasticsearch-plugin";
398403

399404
var pluginBat = Path.Combine(this.RoamingClusterFolder, "bin", pluginCommand) + ".bat";
400-
foreach (var plugin in SupportedPlugins)
405+
foreach (var plugin in SupportedPlugins.Where(p => p.IsValid(this.VersionInfo)))
401406
{
402-
var installPath = plugin.Key;
403-
var command = plugin.Value(this.VersionInfo.Version);
407+
var installPath = plugin.PluginDirectory(this.VersionInfo);
408+
var command = plugin.PluginVersion(this.VersionInfo);
404409
var pluginFolder = Path.Combine(this.RoamingClusterFolder, "plugins", installPath);
405410

406411
if (!Directory.Exists(this.RoamingClusterFolder)) continue;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
3+
namespace Tests.Framework.Integration
4+
{
5+
public class ElasticsearchPlugin
6+
{
7+
private readonly string _name;
8+
private readonly Func<ElasticsearchVersionInfo, bool> _valid;
9+
private readonly Func<ElasticsearchVersionInfo, string> _pluginDirectory;
10+
private readonly Func<ElasticsearchVersionInfo, string> _pluginVersion;
11+
12+
public ElasticsearchPlugin(string name) : this(name, null, null, null) {}
13+
14+
public ElasticsearchPlugin(string name, Func<ElasticsearchVersionInfo, bool> valid) : this(name, valid, null, null) {}
15+
16+
public ElasticsearchPlugin(
17+
string name,
18+
Func<ElasticsearchVersionInfo, bool> valid,
19+
Func<ElasticsearchVersionInfo, string> pluginDirectory,
20+
Func<ElasticsearchVersionInfo, string> pluginVersion)
21+
{
22+
if (name == null) throw new ArgumentNullException(nameof(name));
23+
24+
_name = name;
25+
_valid = valid;
26+
_pluginDirectory = pluginDirectory;
27+
_pluginVersion = pluginVersion;
28+
}
29+
30+
public string Name => _name;
31+
32+
public string PluginDirectory(ElasticsearchVersionInfo elasticsearchVersion) =>
33+
_pluginDirectory?.Invoke(elasticsearchVersion) ?? _name;
34+
35+
public string PluginVersion(ElasticsearchVersionInfo elasticsearchVersion) =>
36+
_pluginVersion?.Invoke(elasticsearchVersion) ?? _name;
37+
38+
public bool IsValid(ElasticsearchVersionInfo version) =>
39+
_valid?.Invoke(version) ?? true;
40+
41+
}
42+
}

src/Tests/Framework/Integration/Process/ElasticsearchVersionInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
namespace Tests.Framework.Integration
77
{
8-
public class ElasticsearchVersionInfo
8+
public class ElasticsearchVersionInfo : SemVer.Version
99
{
10-
public ElasticsearchVersionInfo(string version)
10+
public ElasticsearchVersionInfo(string version) : base(version)
1111
{
1212
this.Version = version;
1313

@@ -38,4 +38,4 @@ public ElasticsearchVersionInfo(string version)
3838
? "https://oss.sonatype.org/content/repositories/snapshots/org/elasticsearch/distribution/zip/elasticsearch"
3939
: "https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/zip/elasticsearch";
4040
}
41-
}
41+
}

src/Tests/Framework/Integration/Process/MapperAttachmentPlugin.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,23 @@ public class MapperAttachmentPlugin
2525
{"0.90", "elasticsearch/elasticsearch-mapper-attachments/1.9.0"}
2626
};
2727

28-
public static string GetVersion(string elasticsearchVersion)
28+
public static string GetVersion(ElasticsearchVersionInfo elasticsearchVersion)
2929
{
3030
string attachmentVersion;
31-
if (!Versions.TryGetValue(elasticsearchVersion, out attachmentVersion))
31+
if (!Versions.TryGetValue(elasticsearchVersion.Version, out attachmentVersion))
3232
{
3333
// assume latest version in elasticsearch repository
3434
attachmentVersion = "mapper-attachments";
3535
}
3636

3737
return attachmentVersion;
3838
}
39+
40+
public static string GetDirectory(ElasticsearchVersionInfo elasticsearchVersion)
41+
{
42+
return elasticsearchVersion < new ElasticsearchVersionInfo("2.1.0")
43+
? "elasticsearch-mapper-attachments"
44+
: "mapper-attachments";
45+
}
3946
}
40-
}
47+
}

src/Tests/Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@
443443
<Compile Include=".\QueryDsl\Geo\Shape\MultiPoint\GeoMultiPointUsageTests.cs" />
444444
<Compile Include=".\QueryDsl\Geo\Shape\Point\GeoPointUsageTests.cs" />
445445
<Compile Include=".\QueryDsl\Geo\Shape\Polygon\GeoPolygonUsageTests.cs" />
446+
<Compile Include="Framework\Integration\Process\ElasticsearchPlugin.cs" />
446447
<Compile Include="QueryDsl\Geo\Shape\GeoShapeQueryUsageTestsBase.cs" />
447448
<Compile Include=".\QueryDsl\Joining\HasChild\HasChildQueryUsageTests.cs" />
448449
<Compile Include=".\QueryDsl\Joining\HasParent\HasParentQueryUsageTests.cs" />

0 commit comments

Comments
 (0)