-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathNodeSettings.cs
52 lines (45 loc) · 1.69 KB
/
NodeSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information
using System;
using System.Collections.Generic;
using System.Linq;
using Elastic.Stack.ArtifactsApi;
namespace Elastic.Elasticsearch.Managed.Configuration
{
public class NodeSettings : List<NodeSetting>
{
public NodeSettings()
{
}
public NodeSettings(NodeSettings settings) : base(settings)
{
}
public void Add(string setting)
{
var s = setting.Split(new[] {'='}, 2, StringSplitOptions.RemoveEmptyEntries);
if (s.Length != 2)
throw new ArgumentException($"Can only add node settings in key=value from but received: {setting}");
Add(new NodeSetting(s[0], s[1], null));
}
public void Add(string key, string value) => Add(new NodeSetting(key, value, null));
public void Add(string key, string value, string versionRange) =>
Add(new NodeSetting(key, value, versionRange));
public string[] ToCommandLineArguments(ElasticVersion version)
{
var settingArgument = "-E";
return this
//if a node setting is only applicable for a certain version make sure its filtered out
.Where(s => string.IsNullOrEmpty(s.VersionRange) || version.InRange(s.VersionRange))
//allow additional settings to take precedence over already DefaultNodeSettings
//without relying on elasticsearch to dedup, 5.4.0 no longer allows passing the same setting twice
//on the command with the latter taking precedence
.GroupBy(setting => setting.Key)
.Select(g => g.Last())
.SelectMany<NodeSetting, string>(
s => [settingArgument, $"{s}"]
)
.ToArray();
}
}
}