Skip to content

Commit

Permalink
Remove obsolete ServerType enum
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Oct 12, 2022
1 parent cc1ecc6 commit 3f65a0b
Show file tree
Hide file tree
Showing 23 changed files with 76 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace OpenSearch.OpenSearch.Ephemeral
public class EphemeralCluster : EphemeralCluster<EphemeralClusterConfiguration>
{
public EphemeralCluster(OpenSearchVersion version, int numberOfNodes = 1)
: base(new EphemeralClusterConfiguration(version, ServerType.DEFAULT, ClusterFeatures.None, numberOfNodes: numberOfNodes))
: base(new EphemeralClusterConfiguration(version, ClusterFeatures.None, numberOfNodes: numberOfNodes))
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ namespace OpenSearch.OpenSearch.Ephemeral
{
public class EphemeralClusterConfiguration : ClusterConfiguration<EphemeralFileSystem>
{
public EphemeralClusterConfiguration(OpenSearchVersion version, ServerType serverType, OpenSearchPlugins plugins = null,
public EphemeralClusterConfiguration(OpenSearchVersion version, OpenSearchPlugins plugins = null,
int numberOfNodes = 1)
: this(version, serverType, ClusterFeatures.None, plugins, numberOfNodes)
: this(version, ClusterFeatures.None, plugins, numberOfNodes)
{
}

public EphemeralClusterConfiguration(OpenSearchVersion version, ServerType serverType, ClusterFeatures features,
public EphemeralClusterConfiguration(OpenSearchVersion version, ClusterFeatures features,
OpenSearchPlugins plugins = null, int numberOfNodes = 1)
: base(version, serverType, (v, s) => new EphemeralFileSystem(v, s), numberOfNodes, EphemeralClusterName)
: base(version, (v, s) => new EphemeralFileSystem(v, s), numberOfNodes, EphemeralClusterName)
{
Features = features;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public override void Run(IEphemeralCluster<EphemeralClusterConfiguration> cluste
var fs = cluster.FileSystem;
var script = Path.Combine(fs.OpenSearchHome, "server-initial-config.sh");

if (cluster.ClusterConfiguration.Artifact.ServerType == ServerType.OpenSearch)
File.WriteAllText(script, InitialConfigurationOpenSearch.GetConfigurationScript(cluster.ClusterConfiguration.Version));
File.WriteAllText(script, InitialConfigurationOpenSearch.GetConfigurationScript(cluster.ClusterConfiguration.Version));

cluster.Writer?.WriteDiagnostic($"{{{nameof(Run)}}} going to run [server-initial-config.sh]");

Expand All @@ -55,8 +54,7 @@ public override void Run(IEphemeralCluster<EphemeralClusterConfiguration> cluste

if (cluster.ClusterConfiguration.EnableSsl) return;

if (cluster.ClusterConfiguration.Artifact.ServerType == ServerType.OpenSearch)
File.AppendAllText(Path.Combine(fs.OpenSearchHome, "config", "opensearch.yml"), "plugins.security.disabled: true");
File.AppendAllText(Path.Combine(fs.OpenSearchHome, "config", "opensearch.yml"), "plugins.security.disabled: true");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ NodeConfiguration Modify(NodeConfiguration n, int p)
public IDisposable Start(TimeSpan waitForStarted)
{
var nodes = Nodes.Select(n => n.NodeConfiguration.DesiredNodeName).ToArray();
var lineHighlightWriter = new LineHighlightWriter(nodes, LineOutParser.From(ClusterConfiguration.ServerType));
var lineHighlightWriter = new LineHighlightWriter(nodes, LineOutParser.OpenSearch);
return Start(lineHighlightWriter, waitForStarted);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public interface IClusterConfiguration<out TFileSystem> where TFileSystem : INod
string ClusterName { get; }
NodeSettings DefaultNodeSettings { get; }
OpenSearchVersion Version { get; }
ServerType ServerType { get; }
int NumberOfNodes { get; }
int StartingPortNumber { get; set; }
bool NoCleanupAfterNodeStopped { get; set; }
Expand All @@ -55,17 +54,14 @@ public interface IClusterConfiguration<out TFileSystem> where TFileSystem : INod

public class ClusterConfiguration : ClusterConfiguration<NodeFileSystem>
{
public ClusterConfiguration(OpenSearchVersion version, ServerType serverType, string openSearchHome, int numberOfNodes = 1)
: base(version, serverType, (v, s) => new NodeFileSystem(v, openSearchHome), numberOfNodes, null)
{
}

public ClusterConfiguration(OpenSearchVersion version, ServerType serverType,
Func<OpenSearchVersion, string, NodeFileSystem> fileSystem = null, int numberOfNodes = 1,
string clusterName = null)
: base(version, serverType, fileSystem ?? ((v, s) => new NodeFileSystem(v, s)), numberOfNodes, clusterName)
{
}
public ClusterConfiguration(OpenSearchVersion version, string openSearchHome, int numberOfNodes = 1)
: base(version, (v, s) => new NodeFileSystem(v, openSearchHome), numberOfNodes, null) { }

public ClusterConfiguration(OpenSearchVersion version, Func<OpenSearchVersion, string, NodeFileSystem> fileSystem = null,
int numberOfNodes = 1,
string clusterName = null
)
: base(version, fileSystem ?? ((v, s) => new NodeFileSystem(v, s)), numberOfNodes, clusterName) { }
}

public class ClusterConfiguration<TFileSystem> : IClusterConfiguration<TFileSystem>
Expand All @@ -81,15 +77,15 @@ public class ClusterConfiguration<TFileSystem> : IClusterConfiguration<TFileSyst
/// </param>
/// <param name="numberOfNodes">The number of nodes in the cluster</param>
/// <param name="clusterName">The name of the cluster</param>
public ClusterConfiguration(OpenSearchVersion version, ServerType serverType, Func<OpenSearchVersion, string, TFileSystem> fileSystem,
int numberOfNodes = 1, string clusterName = null)
public ClusterConfiguration(OpenSearchVersion version, Func<OpenSearchVersion, string, TFileSystem> fileSystem,
int numberOfNodes = 1, string clusterName = null
)
{
if (fileSystem == null) throw new ArgumentException(nameof(fileSystem));

ClusterName = clusterName;
Version = version;
ServerType = serverType;
Artifact = version.Artifact(Product.From("opensearch", serverType: serverType));
Artifact = version.Artifact(Product.From("opensearch"));
FileSystem = fileSystem(Version, ClusterName);
NumberOfNodes = numberOfNodes;

Expand All @@ -112,7 +108,6 @@ public ClusterConfiguration(OpenSearchVersion version, ServerType serverType, Fu

public string ClusterName { get; }
public OpenSearchVersion Version { get; }
public ServerType ServerType { get; }
public TFileSystem FileSystem { get; }
public int NumberOfNodes { get; }
public int StartingPortNumber { get; set; } = 9200;
Expand All @@ -138,7 +133,7 @@ public virtual string CreateNodeName(int? node) =>
/// <summary>
/// Calculates the quorum given the number of instances
/// </summary>
private static int Quorum(int instanceCount) => Math.Max(1, (int) Math.Floor((double) instanceCount / 2) + 1);
private static int Quorum(int instanceCount) => Math.Max(1, (int)Math.Floor((double)instanceCount / 2) + 1);

/// <summary>
/// Creates a node attribute for the version of OpenSearch
Expand All @@ -155,6 +150,7 @@ public string AttributeKey(string attribute)
protected void Add(string key, string value)
{
if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)) return;

DefaultNodeSettings.Add(key, value);
}

Expand All @@ -165,6 +161,7 @@ protected void Add(string key, string value)
protected void Add(string key, string value, string range)
{
if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)) return;

if (string.IsNullOrWhiteSpace(range) || Version.InRange(range))
DefaultNodeSettings.Add(key, value, range);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class NodeConfiguration
{
private Action<StartArguments> _defaultStartArgs = s => { };

public NodeConfiguration(OpenSearchVersion version, int? port = null) : this(new ClusterConfiguration(version, ServerType.DEFAULT),
public NodeConfiguration(OpenSearchVersion version, int? port = null) : this(new ClusterConfiguration(version),
port)
{
}
Expand Down Expand Up @@ -85,7 +85,6 @@ public Action<StartArguments> ModifyStartArguments

public INodeFileSystem FileSystem => ClusterConfiguration.FileSystem;
public OpenSearchVersion Version => ClusterConfiguration.Version;
public ServerType ServerType => ClusterConfiguration.ServerType;
public string[] CommandLineArguments => Settings.ToCommandLineArguments(Version);

public void InitialMasterNodes(string initialMasterNodes) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,6 @@ private LineOutParser() { }
public static readonly LineOutParser OpenSearch = new(shortNamePrefix: "o.o", fullNamePrefix: "org.opensearch",
securityPluginName: "OpenSearchSecurityPlugin");

public static LineOutParser From(ServerType serverType)
{
switch (serverType)
{
case ServerType.OpenSearch:
return LineOutParser.OpenSearch;
default:
throw new ApplicationException(
$"Unexpected value for {nameof(serverType)} -- {serverType}");
}
}

/*
[2016-09-26T11:43:17,314][INFO ][o.e.n.Node ] [readonly-node-a9c5f4] initializing ...
[2016-09-26T11:43:17,470][INFO ][o.e.e.NodeEnvironment ] [readonly-node-a9c5f4] using [1] data paths, mounts [[BOOTCAMP (C:)]], net usable_space [27.7gb], net total_space [129.7gb], spins? [unknown], types [NTFS]
Expand Down Expand Up @@ -113,10 +101,7 @@ public bool TryParse(string line,
return true;
}

private bool TryGetStartedConfirmation(string section, string message)
{
return section == ShortName("n.Node") && message == "started";
}
private bool TryGetStartedConfirmation(string section, string message) => section == ShortName("n.Node") && message == "started";

public bool TryGetPortNumber(string section, string message, out int port)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,10 @@ public NodeFileSystem(OpenSearchVersion version, string openSearchHome = null)
protected static string BinarySuffix => IsMono || Path.DirectorySeparatorChar == '/' ? "" : ".bat";

/// <inheritdoc />
public string Binary
{
get
{
if (Artifact.ServerType == ServerType.OpenSearch)
return Path.Combine(OpenSearchHome, "bin", "opensearch") + BinarySuffix;
return Path.Combine(OpenSearchHome, "bin", "elasticsearch") + BinarySuffix;
}
}
public string Binary => Path.Combine(OpenSearchHome, "bin", "opensearch") + BinarySuffix;

/// <inheritdoc />
public string PluginBinary
{
get
{
if (Artifact.ServerType == ServerType.OpenSearch)
return Path.Combine(OpenSearchHome, "bin", "opensearch-plugin") + BinarySuffix;
return Path.Combine(OpenSearchHome, "bin", "elasticsearch-plugin") + BinarySuffix;
}
}
public string PluginBinary => Path.Combine(OpenSearchHome, "bin", "opensearch-plugin") + BinarySuffix;

/// <inheritdoc />
public string OpenSearchHome { get; }
Expand Down
30 changes: 17 additions & 13 deletions abstractions/src/OpenSearch.OpenSearch.Managed/OpenSearchNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ public class OpenSearchNode : ObservableProcess
private readonly ManualResetEvent _startedHandle = new ManualResetEvent(false);

public OpenSearchNode(OpenSearchVersion version, string openSearchHome = null)
: this(new NodeConfiguration(new ClusterConfiguration(version, ServerType.DEFAULT,
(v, s) => new NodeFileSystem(v, openSearchHome))))
{
}
: this(new NodeConfiguration(new ClusterConfiguration(version, (v, s) => new NodeFileSystem(v, openSearchHome)))) { }

public OpenSearchNode(NodeConfiguration config) : base(StartArgs(config)) => NodeConfiguration = config;

public string Version { get; private set; }
public int? Port { get; private set; }
public bool NodeStarted { get; private set; }
Expand Down Expand Up @@ -88,7 +86,7 @@ private static StartArguments StartArgs(NodeConfiguration config)

private static Dictionary<string, string> EnvVars(NodeConfiguration config)
{
var environmentVariables = new Dictionary<string, string> {{"OPENSEARCH_JAVA_OPTS", "-Xms1g -Xmx1g"}};
var environmentVariables = new Dictionary<string, string> { { "OPENSEARCH_JAVA_OPTS", "-Xms1g -Xmx1g" } };
if (!string.IsNullOrWhiteSpace(config.FileSystem.ConfigPath))
environmentVariables.Add(config.FileSystem.ConfigEnvironmentVariableName, config.FileSystem.ConfigPath);

Expand All @@ -101,9 +99,10 @@ private static Dictionary<string, string> EnvVars(NodeConfiguration config)
private bool AssumedStartedStateChecker(string section, string message)
{
if (AssumeStartedOnNotEnoughMasterPing
&& section.Contains("ZenDiscovery")
&& message.Contains("not enough master nodes discovered during pinging"))
&& section.Contains("ZenDiscovery")
&& message.Contains("not enough master nodes discovered during pinging"))
return true;

return false;
}

Expand All @@ -116,6 +115,7 @@ public IDisposable Start(IConsoleLineHandler writer, TimeSpan waitForStarted)
var node = NodeConfiguration.DesiredNodeName;
var subscription = SubscribeLines(writer);
if (WaitForStarted(waitForStarted)) return subscription;

subscription.Dispose();
throw new OpenSearchCleanExitException(
$"Failed to start node: {node} before the configured timeout of: {waitForStarted}");
Expand All @@ -130,11 +130,13 @@ public IDisposable SubscribeLines(IConsoleLineHandler writer, Action<LineOut> on
SubscribeLines(writer, onNext, delegate { }, delegate { });

public IDisposable SubscribeLines(IConsoleLineHandler writer, Action<LineOut> onNext,
Action<Exception> onError) =>
Action<Exception> onError
) =>
SubscribeLines(writer, onNext, onError, delegate { });

public IDisposable SubscribeLines(IConsoleLineHandler writer, Action<LineOut> onNext, Action<Exception> onError,
Action onCompleted)
Action onCompleted
)
{
Writer = writer;
var node = NodeConfiguration.DesiredNodeName;
Expand Down Expand Up @@ -188,19 +190,19 @@ protected override void OnBeforeWaitForEndOfStreamsError(TimeSpan waited)
private static void HardKill(int? processId)
{
if (!processId.HasValue) return;

try
{
var p = Process.GetProcessById(processId.Value);
p.Kill();
}
catch (Exception)
{
}
catch (Exception) { }
}

protected override bool ContinueReadingFromProcessReaders()
{
if (!NodeStarted) return true;

return true;

// some how if we return false here it leads to Task starvation in Proc and tests in e.g will OpenSearch.OpenSearch.Xunit will start
Expand All @@ -211,7 +213,7 @@ protected override bool ContinueReadingFromProcessReaders()

protected override bool KeepBufferingLines(LineOut c)
{
var lineOutParser = LineOutParser.From(NodeConfiguration.ServerType);
var lineOutParser = LineOutParser.OpenSearch;
//if the node is already started only keep buffering lines while we have a writer and the nodeconfiguration wants output after started
if (NodeStarted)
{
Expand Down Expand Up @@ -246,12 +248,14 @@ protected override bool KeepBufferingLines(LineOut c)
if (!Port.HasValue)
throw new OpenSearchCleanExitException(
$"Node started but OpenSearchNode did not grab its port number");

NodeStarted = true;
_startedHandle.Set();
}

// if we have dont a writer always return true
if (Writer != null) return true;

//otherwise only keep buffering if we are not started
return !started;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ public class XunitClusterConfiguration : EphemeralClusterConfiguration
{
public XunitClusterConfiguration(
OpenSearchVersion version,
ServerType serverType,
ClusterFeatures features = ClusterFeatures.None,
OpenSearchPlugins plugins = null,
int numberOfNodes = 1)
: base(version, serverType, features, plugins, numberOfNodes) =>
: base(version, features, plugins, numberOfNodes) =>
AdditionalAfterStartedTasks.Add(new PrintXunitAfterStartedTask());

/// <inheritdoc />
Expand Down
7 changes: 1 addition & 6 deletions abstractions/src/OpenSearch.Stack.ArtifactsApi/Artifact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ public class Artifact
internal Artifact(Product product, Version version, string downloadUrl, ArtifactBuildState state,
string buildHash)
{
ServerType = product.ServerType;
switch (ServerType)
{
case ServerType.OpenSearch: ProductName = "opensearch"; break; // actually = product.ProductName
}
ProductName = "opensearch";
Version = version;
DownloadUrl = product?.PatchDownloadUrl(downloadUrl);
State = state;
Expand Down Expand Up @@ -96,7 +92,6 @@ public string Archive
}

// ReSharper disable UnusedAutoPropertyAccessor.Global
public ServerType ServerType { get; }
public string ProductName { get; }
public Version Version { get; }
public string DownloadUrl { get; }
Expand Down
Loading

0 comments on commit 3f65a0b

Please sign in to comment.