diff --git a/.editorconfig b/.editorconfig
index 63a79b9250..a50a0c0691 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -17,6 +17,46 @@ indent_size = 2
[*.{cs,vb}]
trim_trailing_whitespace = true
+# Naming styles
+
+dotnet_naming_style.pascal_case.required_prefix =
+dotnet_naming_style.pascal_case.required_suffix =
+dotnet_naming_style.pascal_case.word_separator =
+dotnet_naming_style.pascal_case.capitalization = pascal_case
+
+dotnet_naming_style.begins_with_i.required_prefix = I
+dotnet_naming_style.begins_with_i.required_suffix =
+dotnet_naming_style.begins_with_i.word_separator =
+dotnet_naming_style.begins_with_i.capitalization = pascal_case
+
+# Naming rules
+
+dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
+dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
+dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
+
+dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
+dotnet_naming_rule.types_should_be_pascal_case.symbols = types
+dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
+
+dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
+dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
+dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
+
+# Symbol specifications
+
+dotnet_naming_symbols.interface.applicable_kinds = interface
+dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.interface.required_modifiers =
+
+dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
+dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.types.required_modifiers =
+
+dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
+dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.non_field_members.required_modifiers =
+
# ---
# naming conventions https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions
# currently not supported in Rider/Resharper so not using these for now
@@ -103,80 +143,183 @@ dotnet_naming_symbols.public_members.applicable_accessibilities = public
dotnet_naming_style.public_members.capitalization = pascal_case
+# this. and Me. preferences
+dotnet_style_qualification_for_event = false:error
dotnet_style_qualification_for_field = false:error
-dotnet_style_qualification_for_property = false:error
dotnet_style_qualification_for_method = false:error
-dotnet_style_qualification_for_event = false:error
+dotnet_style_qualification_for_property = false:error
# Use language keywords instead of framework type names for type references
dotnet_style_predefined_type_for_locals_parameters_members = true:error
dotnet_style_predefined_type_for_member_access = true:error
+# Parentheses preferences
+dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
+dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
+dotnet_style_parentheses_in_other_operators = never_if_unnecessary
+dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity
+
+# Modifier preferences
+dotnet_style_require_accessibility_modifiers = for_non_interface_members:error
+dotnet_style_readonly_field = true:error
+
# Suggest more modern language features when available
-dotnet_style_object_initializer = true:error
+# Expression-level preferences
+dotnet_style_coalesce_expression = true:error
dotnet_style_collection_initializer = true:error
dotnet_style_explicit_tuple_names = true:error
+dotnet_style_namespace_match_folder = true
+dotnet_style_null_propagation = true:error
+dotnet_style_object_initializer = true:error # our setting:true:error. Set to false if performing a dotnet format
+dotnet_style_operator_placement_when_wrapping = beginning_of_line
+dotnet_style_prefer_auto_properties = true
+dotnet_style_prefer_collection_expression = true
+dotnet_style_prefer_compound_assignment = true
+dotnet_style_prefer_conditional_expression_over_assignment = true
+dotnet_style_prefer_conditional_expression_over_return = true
+dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed
dotnet_style_prefer_inferred_anonymous_type_member_names = true:error
dotnet_style_prefer_inferred_tuple_names = true:error
-dotnet_style_coalesce_expression = true:error
-dotnet_style_null_propagation = true:error
+dotnet_style_prefer_is_null_check_over_reference_equality_method = true
+dotnet_style_prefer_simplified_boolean_expressions = true
+dotnet_style_prefer_simplified_interpolation = true
-dotnet_style_require_accessibility_modifiers = for_non_interface_members:error
-dotnet_style_readonly_field = true:error
+# Field preferences
+dotnet_style_readonly_field = true
+
+# Parameter preferences
+dotnet_code_quality_unused_parameters = all
+
+# Suppression preferences
+dotnet_remove_unnecessary_suppression_exclusions = none
+
+# New line preferences
+dotnet_style_allow_multiple_blank_lines_experimental = true
+dotnet_style_allow_statement_immediately_after_block_experimental = true
+
+#### C# Coding Conventions ####
-# CSharp code style settings:
[*.cs]
# Prefer "var" everywhere
+csharp_style_var_elsewhere = true:error
csharp_style_var_for_built_in_types = true:error
csharp_style_var_when_type_is_apparent = true:error
-csharp_style_var_elsewhere = true:error
-csharp_style_expression_bodied_methods = true:error
+csharp_style_expression_bodied_accessors = true:error
csharp_style_expression_bodied_constructors = true:error
+csharp_style_expression_bodied_indexers = true:error
+csharp_style_expression_bodied_lambdas = true
+csharp_style_expression_bodied_local_functions = false
+csharp_style_expression_bodied_methods = true:error
csharp_style_expression_bodied_operators = true:error
csharp_style_expression_bodied_properties = true:error
-csharp_style_expression_bodied_indexers = true:error
-csharp_style_expression_bodied_accessors = true:error
# Suggest more modern language features when available
-csharp_style_pattern_matching_over_is_with_cast_check = true:error
-csharp_style_pattern_matching_over_as_with_null_check = true:error
-csharp_style_inlined_variable_declaration = true:error
-csharp_style_deconstructed_variable_declaration = true:error
+
csharp_style_pattern_local_over_anonymous_function = true:error
-csharp_style_throw_expression = true:error
+csharp_style_pattern_matching_over_as_with_null_check = true:error
+csharp_style_pattern_matching_over_is_with_cast_check = true:error
+csharp_style_prefer_extended_property_pattern = true
+csharp_style_prefer_not_pattern = true
+csharp_style_prefer_pattern_matching = true
+csharp_style_prefer_switch_expression = true
+
+# Null-checking preferences
csharp_style_conditional_delegate_call = true:error
-csharp_prefer_braces = false:warning
+# Modifier preferences
+csharp_prefer_static_local_function = true
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:error
+csharp_style_prefer_readonly_struct = true
+csharp_style_prefer_readonly_struct_member = true
-# ---
-# formatting conventions https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#formatting-conventions
+# Code-block preferences
+csharp_prefer_braces = false:warning
+csharp_prefer_simple_using_statement = true
+csharp_style_namespace_declarations = file_scoped:error #This allows for no { } for namespaces
+csharp_style_prefer_method_group_conversion = true
+csharp_style_prefer_primary_constructors = false:warning
+csharp_style_prefer_top_level_statements = true
+
+# Expression-level preferences
+csharp_prefer_simple_default_expression = true
+csharp_style_deconstructed_variable_declaration = true:error
+csharp_style_implicit_object_creation_when_type_is_apparent = true
+csharp_style_inlined_variable_declaration = true:error # our setting:true:error. Set to false if performing a dotnet format
+csharp_style_prefer_index_operator = true
+csharp_style_prefer_local_over_anonymous_function = true
+csharp_style_prefer_null_check_over_type_check = true
+csharp_style_prefer_range_operator = true
+csharp_style_prefer_tuple_swap = true
+csharp_style_prefer_utf8_string_literals = true
+csharp_style_throw_expression = true:error
+csharp_style_unused_value_assignment_preference = discard_variable
+csharp_style_unused_value_expression_statement_preference = discard_variable
+
+# 'using' directive preferences
+# csharp_using_directive_placement = outside_namespace
+
+# New line preferences
+csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true
+csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true
+csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true
+csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true
+csharp_style_allow_embedded_statements_on_same_line_experimental = true
# Newline settings (Allman yo!)
-csharp_new_line_before_open_brace = all
-csharp_new_line_before_else = true
+
csharp_new_line_before_catch = true
+csharp_new_line_before_else = true
csharp_new_line_before_finally = true
-csharp_new_line_before_members_in_object_initializers = true
# just a suggestion do to our JSON tests that use anonymous types to
# represent json quite a bit (makes copy paste easier).
csharp_new_line_before_members_in_anonymous_types = true
+csharp_new_line_before_members_in_object_initializers = true
+csharp_new_line_before_open_brace = all
csharp_new_line_between_query_expression_clauses = true
-# Indent
+# Indentation preferences https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options
+csharp_indent_block_contents = true
+csharp_indent_braces = false
csharp_indent_case_contents = true
+csharp_indent_case_contents_when_block = true
+csharp_indent_labels = one_less_than_current # our setting:one_less_than_current. Change to 'no_change' if running dotnet format to keep the current formatting https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options#csharp_indent_labels
csharp_indent_switch_labels = true
+
+# Space preferences
csharp_space_after_cast = false
+csharp_space_after_colon_in_inheritance_clause = true
+csharp_space_after_comma = true
+csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
-csharp_space_between_method_declaration_parameter_list_parentheses = false
+csharp_space_after_semicolon_in_for_statement = true
+csharp_space_around_binary_operators = before_and_after
+csharp_space_around_declaration_statements = false
+csharp_space_before_colon_in_inheritance_clause = true
+csharp_space_before_comma = false
+csharp_space_before_dot = false
+csharp_space_before_open_square_brackets = false
+csharp_space_before_semicolon_in_for_statement = false
+csharp_space_between_empty_square_brackets = false
+csharp_space_between_method_call_empty_parameter_list_parentheses = false
+csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
+csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
+csharp_space_between_method_declaration_name_and_open_parenthesis = false
+csharp_space_between_method_declaration_parameter_list_parentheses = false
+csharp_space_between_parentheses = false
+csharp_space_between_square_brackets = false
-#Wrap
-csharp_preserve_single_line_statements = false
+# Wrapping preferences
csharp_preserve_single_line_blocks = true
+csharp_preserve_single_line_statements = true #our setting:false. Set to true if performing a dotnet format https://stackoverflow.com/questions/49760158/visual-studio-2017-auto-formatting-single-line-if-statements-without-braces
# Resharper
+
+resharper_check_namespace_highlighting=do_not_show
+
+resharper_csharp_accessor_owner_body=expression_body
+
resharper_csharp_braces_for_lock=required_for_multiline
resharper_csharp_braces_for_using=required_for_multiline
resharper_csharp_braces_for_while=required_for_multiline
@@ -185,11 +328,18 @@ resharper_csharp_braces_for_for=required_for_multiline
resharper_csharp_braces_for_fixed=required_for_multiline
resharper_csharp_braces_for_ifelse=required_for_multiline
-resharper_csharp_accessor_owner_body=expression_body
+resharper_inheritdoc_invalid_usage_highlighting=do_not_show
resharper_redundant_case_label_highlighting=do_not_show
+resharper_redundant_anonymous_type_property_name_highlighting=do_not_show
resharper_redundant_argument_default_value_highlighting=do_not_show
+resharper_unused_member_local_highlighting=do_not_show
+resharper_unused_parameter_local_highlighting=do_not_show
+resharper_unused_variable_highlighting=do_not_show
+
+resharper_xUnit_1013_highlighting=do_not_show
+
[*.{sh,bat,ps1}]
trim_trailing_whitespace=true
insert_final_newline=true
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/ClusterAuthentication.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/ClusterAuthentication.cs
index 9f69796b96..a30d25e07f 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/ClusterAuthentication.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/ClusterAuthentication.cs
@@ -26,36 +26,35 @@
* under the License.
*/
-namespace OpenSearch.OpenSearch.Ephemeral
+namespace OpenSearch.OpenSearch.Ephemeral;
+
+///
+/// Authentication credentials for the cluster
+///
+public class ClusterAuthentication
{
- ///
- /// Authentication credentials for the cluster
- ///
- public class ClusterAuthentication
- {
- ///
- /// Administrator credentials
- ///
- public static Credentials Admin => new Credentials {Username = "admin", Role = "admin"};
+ ///
+ /// Administrator credentials
+ ///
+ public static Credentials Admin => new Credentials { Username = "admin", Role = "admin" };
- ///
- /// User credentials
- ///
- public static Credentials User => new Credentials {Username = "admin", Role = "admin"};
+ ///
+ /// User credentials
+ ///
+ public static Credentials User => new Credentials { Username = "admin", Role = "admin" };
- ///
- /// Credentials for all users
- ///
- public static Credentials[] AllUsers { get; } = {Admin, User};
+ ///
+ /// Credentials for all users
+ ///
+ public static Credentials[] AllUsers { get; } = { Admin, User };
- ///
- /// Authentication credentials
- ///
- public class Credentials
- {
- public string Username { get; set; }
- public string Role { get; set; }
- public string Password => Username;
- }
- }
+ ///
+ /// Authentication credentials
+ ///
+ public class Credentials
+ {
+ public string Username { get; set; }
+ public string Role { get; set; }
+ public string Password => Username;
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/ClusterFeatures.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/ClusterFeatures.cs
index ce36b0d436..89a433f4c2 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/ClusterFeatures.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/ClusterFeatures.cs
@@ -28,23 +28,22 @@
using System;
-namespace OpenSearch.OpenSearch.Ephemeral
+namespace OpenSearch.OpenSearch.Ephemeral;
+
+///
+/// Hints to what features the cluster to be started should have.
+/// It's up to the to actually bootstrap these features.
+///
+[Flags]
+public enum ClusterFeatures
{
- ///
- /// Hints to what features the cluster to be started should have.
- /// It's up to the to actually bootstrap these features.
- ///
- [Flags]
- public enum ClusterFeatures
- {
- ///
- /// No features
- ///
- None = 1 << 0,
+ ///
+ /// No features
+ ///
+ None = 1 << 0,
- ///
- /// SSL/TLS for HTTP and Transport layers
- ///
- SSL = 1 << 3,
- }
+ ///
+ /// SSL/TLS for HTTP and Transport layers
+ ///
+ SSL = 1 << 3,
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/EphemeralCluster.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/EphemeralCluster.cs
index f0e3769c96..357194b0b1 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/EphemeralCluster.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/EphemeralCluster.cs
@@ -37,105 +37,104 @@
using OpenSearch.OpenSearch.Managed.Configuration;
using OpenSearch.Stack.ArtifactsApi;
-namespace OpenSearch.OpenSearch.Ephemeral
+namespace OpenSearch.OpenSearch.Ephemeral;
+
+public class EphemeralCluster : EphemeralCluster
+{
+ public EphemeralCluster(OpenSearchVersion version, int numberOfNodes = 1)
+ : base(new EphemeralClusterConfiguration(version, ClusterFeatures.None, numberOfNodes: numberOfNodes))
+ {
+ }
+
+ public EphemeralCluster(EphemeralClusterConfiguration clusterConfiguration) : base(clusterConfiguration)
+ {
+ }
+}
+
+public abstract class EphemeralCluster : ClusterBase,
+ IEphemeralCluster
+ where TConfiguration : EphemeralClusterConfiguration
{
- public class EphemeralCluster : EphemeralCluster
- {
- public EphemeralCluster(OpenSearchVersion version, int numberOfNodes = 1)
- : base(new EphemeralClusterConfiguration(version, ClusterFeatures.None, numberOfNodes: numberOfNodes))
- {
- }
-
- public EphemeralCluster(EphemeralClusterConfiguration clusterConfiguration) : base(clusterConfiguration)
- {
- }
- }
-
- public abstract class EphemeralCluster : ClusterBase,
- IEphemeralCluster
- where TConfiguration : EphemeralClusterConfiguration
- {
- protected EphemeralCluster(TConfiguration clusterConfiguration) : base(clusterConfiguration) =>
- Composer = new EphemeralClusterComposer(this);
-
- protected EphemeralClusterComposer Composer { get; }
-
- protected override void ModifyNodeConfiguration(NodeConfiguration nodeConfiguration, int port)
- {
- base.ModifyNodeConfiguration(nodeConfiguration, port);
-
- if (!ClusterConfiguration.EnableSsl) nodeConfiguration.Add("plugins.security.disabled", "true");
- }
-
- public virtual ICollection NodesUris(string hostName = null)
- {
- hostName = hostName ?? (ClusterConfiguration.HttpFiddlerAware && Process.GetProcessesByName("fiddler").Any()
- ? "ipv4.fiddler"
- : "localhost");
- var ssl = ClusterConfiguration.EnableSsl ? "s" : "";
- return Nodes
- .Select(n => $"http{ssl}://{hostName}:{n.Port ?? 9200}")
- .Distinct()
- .Select(n => new Uri(n))
- .ToList();
- }
-
- public bool CachingAndCachedHomeExists()
- {
- if (!ClusterConfiguration.CacheOpenSearchHomeInstallation) return false;
- var cachedOpenSearchHomeFolder = Path.Combine(FileSystem.LocalFolder, GetCacheFolderName());
- return Directory.Exists(cachedOpenSearchHomeFolder);
- }
-
- public virtual string GetCacheFolderName()
- {
- var config = ClusterConfiguration;
-
- var sb = new StringBuilder();
- sb.Append(EphemeralClusterComposerBase.InstallationTasks.Count());
- sb.Append("-");
- if (config.EnableSsl) sb.Append("ssl");
- if (config.Plugins != null && config.Plugins.Count > 0)
- {
- sb.Append("-");
- foreach (var p in config.Plugins.OrderBy(p => p.SubProductName))
- sb.Append(p.SubProductName.ToLowerInvariant());
- }
-
- var name = sb.ToString();
-
- return CalculateSha1(name, Encoding.UTF8);
- }
-
- protected override void OnBeforeStart()
- {
- Composer.Install();
- Composer.OnBeforeStart();
- }
-
- protected override void OnDispose() => Composer.OnStop();
-
- protected override void OnAfterStarted() => Composer.OnAfterStart();
-
- protected override string SeeLogsMessage(string message)
- {
- var log = Path.Combine(FileSystem.LogsPath, $"{ClusterConfiguration.ClusterName}.log");
- if (!File.Exists(log) || ClusterConfiguration.ShowOpenSearchOutputAfterStarted) return message;
- if (!Started) return message;
- using (var fileStream = new FileStream(log, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- using (var textReader = new StreamReader(fileStream))
- {
- var logContents = textReader.ReadToEnd();
- return message + $" contents of {log}:{Environment.NewLine}" + logContents;
- }
- }
-
- public static string CalculateSha1(string text, Encoding enc)
- {
- var buffer = enc.GetBytes(text);
- var cryptoTransformSha1 = new SHA1CryptoServiceProvider();
- return BitConverter.ToString(cryptoTransformSha1.ComputeHash(buffer))
- .Replace("-", "").ToLowerInvariant().Substring(0, 12);
- }
- }
+ protected EphemeralCluster(TConfiguration clusterConfiguration) : base(clusterConfiguration) =>
+ Composer = new EphemeralClusterComposer(this);
+
+ protected EphemeralClusterComposer Composer { get; }
+
+ protected override void ModifyNodeConfiguration(NodeConfiguration nodeConfiguration, int port)
+ {
+ base.ModifyNodeConfiguration(nodeConfiguration, port);
+
+ if (!ClusterConfiguration.EnableSsl) nodeConfiguration.Add("plugins.security.disabled", "true");
+ }
+
+ public virtual ICollection NodesUris(string hostName = null)
+ {
+ hostName = hostName ?? (ClusterConfiguration.HttpFiddlerAware && Process.GetProcessesByName("fiddler").Any()
+ ? "ipv4.fiddler"
+ : "localhost");
+ var ssl = ClusterConfiguration.EnableSsl ? "s" : "";
+ return Nodes
+ .Select(n => $"http{ssl}://{hostName}:{n.Port ?? 9200}")
+ .Distinct()
+ .Select(n => new Uri(n))
+ .ToList();
+ }
+
+ public bool CachingAndCachedHomeExists()
+ {
+ if (!ClusterConfiguration.CacheOpenSearchHomeInstallation) return false;
+ var cachedOpenSearchHomeFolder = Path.Combine(FileSystem.LocalFolder, GetCacheFolderName());
+ return Directory.Exists(cachedOpenSearchHomeFolder);
+ }
+
+ public virtual string GetCacheFolderName()
+ {
+ var config = ClusterConfiguration;
+
+ var sb = new StringBuilder();
+ sb.Append(EphemeralClusterComposerBase.InstallationTasks.Count());
+ sb.Append("-");
+ if (config.EnableSsl) sb.Append("ssl");
+ if (config.Plugins != null && config.Plugins.Count > 0)
+ {
+ sb.Append("-");
+ foreach (var p in config.Plugins.OrderBy(p => p.SubProductName))
+ sb.Append(p.SubProductName.ToLowerInvariant());
+ }
+
+ var name = sb.ToString();
+
+ return CalculateSha1(name, Encoding.UTF8);
+ }
+
+ protected override void OnBeforeStart()
+ {
+ Composer.Install();
+ Composer.OnBeforeStart();
+ }
+
+ protected override void OnDispose() => Composer.OnStop();
+
+ protected override void OnAfterStarted() => Composer.OnAfterStart();
+
+ protected override string SeeLogsMessage(string message)
+ {
+ var log = Path.Combine(FileSystem.LogsPath, $"{ClusterConfiguration.ClusterName}.log");
+ if (!File.Exists(log) || ClusterConfiguration.ShowOpenSearchOutputAfterStarted) return message;
+ if (!Started) return message;
+ using (var fileStream = new FileStream(log, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
+ using (var textReader = new StreamReader(fileStream))
+ {
+ var logContents = textReader.ReadToEnd();
+ return message + $" contents of {log}:{Environment.NewLine}" + logContents;
+ }
+ }
+
+ public static string CalculateSha1(string text, Encoding enc)
+ {
+ var buffer = enc.GetBytes(text);
+ var cryptoTransformSha1 = new SHA1CryptoServiceProvider();
+ return BitConverter.ToString(cryptoTransformSha1.ComputeHash(buffer))
+ .Replace("-", "").ToLowerInvariant().Substring(0, 12);
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/EphemeralClusterComposer.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/EphemeralClusterComposer.cs
index bd055f4874..580357ab62 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/EphemeralClusterComposer.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/EphemeralClusterComposer.cs
@@ -35,101 +35,100 @@
using OpenSearch.OpenSearch.Ephemeral.Tasks.ValidationTasks;
using OpenSearch.OpenSearch.Managed.FileSystem;
-namespace OpenSearch.OpenSearch.Ephemeral
+namespace OpenSearch.OpenSearch.Ephemeral;
+
+public class EphemeralClusterComposerBase
+{
+ protected EphemeralClusterComposerBase()
+ {
+ }
+
+ internal static IEnumerable InstallationTasks { get; } = new List
+ {
+ new PrintConfiguration(),
+ new CreateLocalApplicationDirectory(),
+ new CopyCachedOpenSearchInstallation(),
+ new EnsureJavaHomeEnvironmentVariableIsSet(),
+ new DownloadOpenSearchVersion(),
+ new UnzipOpenSearch(),
+ new SetOpenSearchBundledJdkJavaHome(),
+ new InstallPlugins(),
+ new InitialConfiguration()
+ };
+
+ protected static IEnumerable BeforeStart { get; } = new List
+ {
+ new CreateEphemeralDirectory(),
+ new CacheOpenSearchInstallation()
+ };
+
+ protected static IEnumerable NodeStoppedTasks { get; } = new List
+ {
+ new CleanUpDirectoriesAfterNodeStopped()
+ };
+
+ protected static IEnumerable AfterStartedTasks { get; } = new List
+ {
+ new ValidateRunningVersion(),
+ new ValidateClusterStateTask(),
+ new ValidatePluginsTask(),
+ };
+}
+
+
+public class EphemeralClusterComposer : EphemeralClusterComposerBase
+ where TConfiguration : EphemeralClusterConfiguration
{
- public class EphemeralClusterComposerBase
- {
- protected EphemeralClusterComposerBase()
- {
- }
-
- internal static IEnumerable InstallationTasks { get; } = new List
- {
- new PrintConfiguration(),
- new CreateLocalApplicationDirectory(),
- new CopyCachedOpenSearchInstallation(),
- new EnsureJavaHomeEnvironmentVariableIsSet(),
- new DownloadOpenSearchVersion(),
- new UnzipOpenSearch(),
- new SetOpenSearchBundledJdkJavaHome(),
- new InstallPlugins(),
- new InitialConfiguration()
- };
-
- protected static IEnumerable BeforeStart { get; } = new List
- {
- new CreateEphemeralDirectory(),
- new CacheOpenSearchInstallation()
- };
-
- protected static IEnumerable NodeStoppedTasks { get; } = new List
- {
- new CleanUpDirectoriesAfterNodeStopped()
- };
-
- protected static IEnumerable AfterStartedTasks { get; } = new List
- {
- new ValidateRunningVersion(),
- new ValidateClusterStateTask(),
- new ValidatePluginsTask(),
- };
- }
-
-
- public class EphemeralClusterComposer : EphemeralClusterComposerBase
- where TConfiguration : EphemeralClusterConfiguration
- {
- private readonly object _lock = new object();
- public EphemeralClusterComposer(IEphemeralCluster cluster) => Cluster = cluster;
-
- private IEphemeralCluster Cluster { get; }
-
- private bool NodeStarted { get; set; }
-
- public void OnStop() => Itterate(NodeStoppedTasks, (t, c, fs) => t.Run(c, NodeStarted), false);
-
- public void Install() => Itterate(InstallationTasks, (t, c, fs) => t.Run(c));
-
- public void OnBeforeStart()
- {
- var tasks = new List(BeforeStart);
- if (Cluster.ClusterConfiguration.AdditionalBeforeNodeStartedTasks != null)
- tasks.AddRange(Cluster.ClusterConfiguration.AdditionalBeforeNodeStartedTasks);
-
- if (Cluster.ClusterConfiguration.PrintYamlFilesInConfigFolder)
- tasks.Add(new PrintYamlContents());
-
- Itterate(tasks, (t, c, fs) => t.Run(c));
-
- NodeStarted = true;
- }
-
- public void OnAfterStart()
- {
- if (Cluster.ClusterConfiguration.SkipBuiltInAfterStartTasks) return;
- var tasks = new List(AfterStartedTasks);
- if (Cluster.ClusterConfiguration.AdditionalAfterStartedTasks != null)
- tasks.AddRange(Cluster.ClusterConfiguration.AdditionalAfterStartedTasks);
- Itterate(tasks, (t, c, fs) => t.Run(c), false);
- }
-
- private void Itterate(IEnumerable collection,
- Action, INodeFileSystem> act, bool callOnStop = true)
- {
- lock (_lock)
- {
- var cluster = Cluster;
- foreach (var task in collection)
- try
- {
- act(task, cluster, cluster.FileSystem);
- }
- catch (Exception)
- {
- if (callOnStop) OnStop();
- throw;
- }
- }
- }
- }
+ private readonly object _lock = new object();
+ public EphemeralClusterComposer(IEphemeralCluster cluster) => Cluster = cluster;
+
+ private IEphemeralCluster Cluster { get; }
+
+ private bool NodeStarted { get; set; }
+
+ public void OnStop() => Itterate(NodeStoppedTasks, (t, c, fs) => t.Run(c, NodeStarted), false);
+
+ public void Install() => Itterate(InstallationTasks, (t, c, fs) => t.Run(c));
+
+ public void OnBeforeStart()
+ {
+ var tasks = new List(BeforeStart);
+ if (Cluster.ClusterConfiguration.AdditionalBeforeNodeStartedTasks != null)
+ tasks.AddRange(Cluster.ClusterConfiguration.AdditionalBeforeNodeStartedTasks);
+
+ if (Cluster.ClusterConfiguration.PrintYamlFilesInConfigFolder)
+ tasks.Add(new PrintYamlContents());
+
+ Itterate(tasks, (t, c, fs) => t.Run(c));
+
+ NodeStarted = true;
+ }
+
+ public void OnAfterStart()
+ {
+ if (Cluster.ClusterConfiguration.SkipBuiltInAfterStartTasks) return;
+ var tasks = new List(AfterStartedTasks);
+ if (Cluster.ClusterConfiguration.AdditionalAfterStartedTasks != null)
+ tasks.AddRange(Cluster.ClusterConfiguration.AdditionalAfterStartedTasks);
+ Itterate(tasks, (t, c, fs) => t.Run(c), false);
+ }
+
+ private void Itterate(IEnumerable collection,
+ Action, INodeFileSystem> act, bool callOnStop = true)
+ {
+ lock (_lock)
+ {
+ var cluster = Cluster;
+ foreach (var task in collection)
+ try
+ {
+ act(task, cluster, cluster.FileSystem);
+ }
+ catch (Exception)
+ {
+ if (callOnStop) OnStop();
+ throw;
+ }
+ }
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/EphemeralClusterConfiguration.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/EphemeralClusterConfiguration.cs
index 77aaef02c4..9bd691a685 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/EphemeralClusterConfiguration.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/EphemeralClusterConfiguration.cs
@@ -36,67 +36,66 @@
using OpenSearch.Stack.ArtifactsApi;
using OpenSearch.Stack.ArtifactsApi.Products;
-namespace OpenSearch.OpenSearch.Ephemeral
+namespace OpenSearch.OpenSearch.Ephemeral;
+
+public class EphemeralClusterConfiguration : ClusterConfiguration
{
- public class EphemeralClusterConfiguration : ClusterConfiguration
- {
- public EphemeralClusterConfiguration(OpenSearchVersion version, OpenSearchPlugins plugins = null,
- int numberOfNodes = 1)
- : this(version, ClusterFeatures.None, plugins, numberOfNodes)
- {
- }
-
- public EphemeralClusterConfiguration(OpenSearchVersion version, ClusterFeatures features,
- OpenSearchPlugins plugins = null, int numberOfNodes = 1)
- : base(version, (v, s) => new EphemeralFileSystem(v, s), numberOfNodes, EphemeralClusterName)
- {
- Features = features;
-
- var pluginsList = plugins?.ToList() ?? new List();
- Plugins = new OpenSearchPlugins(pluginsList);
- }
-
- private static string UniqueishSuffix => Guid.NewGuid().ToString("N").Substring(0, 6);
- private static string EphemeralClusterName => $"ephemeral-cluster-{UniqueishSuffix}";
-
- ///
- /// The features supported by the cluster
- ///
- public ClusterFeatures Features { get; }
-
- ///
- /// The collection of plugins to install
- ///
- public OpenSearchPlugins Plugins { get; }
-
- ///
- /// Validates that the plugins to install can be installed on the target OpenSearch version.
- /// This can be useful to fail early when subsequent operations are relying on installation
- /// succeeding.
- ///
- public bool ValidatePluginsToInstall { get; } = true;
-
- public bool EnableSsl => Features.HasFlag(ClusterFeatures.SSL);
-
- public IList AdditionalBeforeNodeStartedTasks { get; } = new List();
-
- public IList AdditionalAfterStartedTasks { get; } = new List();
-
- ///
- /// Expert level setting, skips all built-in validation tasks for cases where you need to guarantee your call is the
- /// first call into the cluster
- ///
- public bool SkipBuiltInAfterStartTasks { get; set; }
-
- /// Bootstrapping HTTP calls should attempt to auto route traffic through fiddler if its running
- public bool HttpFiddlerAware { get; set; }
-
- protected virtual string NodePrefix => "ephemeral";
-
- public override string CreateNodeName(int? node)
- {
- var suffix = Guid.NewGuid().ToString("N").Substring(0, 6);
- return $"{NodePrefix}-node-{suffix}{node}";
- }
- }
+ public EphemeralClusterConfiguration(OpenSearchVersion version, OpenSearchPlugins plugins = null,
+ int numberOfNodes = 1)
+ : this(version, ClusterFeatures.None, plugins, numberOfNodes)
+ {
+ }
+
+ public EphemeralClusterConfiguration(OpenSearchVersion version, ClusterFeatures features,
+ OpenSearchPlugins plugins = null, int numberOfNodes = 1)
+ : base(version, (v, s) => new EphemeralFileSystem(v, s), numberOfNodes, EphemeralClusterName)
+ {
+ Features = features;
+
+ var pluginsList = plugins?.ToList() ?? new List();
+ Plugins = new OpenSearchPlugins(pluginsList);
+ }
+
+ private static string UniqueishSuffix => Guid.NewGuid().ToString("N").Substring(0, 6);
+ private static string EphemeralClusterName => $"ephemeral-cluster-{UniqueishSuffix}";
+
+ ///
+ /// The features supported by the cluster
+ ///
+ public ClusterFeatures Features { get; }
+
+ ///
+ /// The collection of plugins to install
+ ///
+ public OpenSearchPlugins Plugins { get; }
+
+ ///
+ /// Validates that the plugins to install can be installed on the target OpenSearch version.
+ /// This can be useful to fail early when subsequent operations are relying on installation
+ /// succeeding.
+ ///
+ public bool ValidatePluginsToInstall { get; } = true;
+
+ public bool EnableSsl => Features.HasFlag(ClusterFeatures.SSL);
+
+ public IList AdditionalBeforeNodeStartedTasks { get; } = new List();
+
+ public IList AdditionalAfterStartedTasks { get; } = new List();
+
+ ///
+ /// Expert level setting, skips all built-in validation tasks for cases where you need to guarantee your call is the
+ /// first call into the cluster
+ ///
+ public bool SkipBuiltInAfterStartTasks { get; set; }
+
+ /// Bootstrapping HTTP calls should attempt to auto route traffic through fiddler if its running
+ public bool HttpFiddlerAware { get; set; }
+
+ protected virtual string NodePrefix => "ephemeral";
+
+ public override string CreateNodeName(int? node)
+ {
+ var suffix = Guid.NewGuid().ToString("N").Substring(0, 6);
+ return $"{NodePrefix}-node-{suffix}{node}";
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/EphemeralFileSystem.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/EphemeralFileSystem.cs
index 9eebfa981c..657bcdd3cb 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/EphemeralFileSystem.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/EphemeralFileSystem.cs
@@ -31,57 +31,56 @@
using OpenSearch.Stack.ArtifactsApi;
using OpenSearch.Stack.ArtifactsApi.Products;
-namespace OpenSearch.OpenSearch.Ephemeral
+namespace OpenSearch.OpenSearch.Ephemeral;
+
+public class EphemeralFileSystem : NodeFileSystem
{
- public class EphemeralFileSystem : NodeFileSystem
- {
- public EphemeralFileSystem(OpenSearchVersion version, string clusterName) : base(version,
- EphemeralHome(version, clusterName)) => ClusterName = clusterName;
+ public EphemeralFileSystem(OpenSearchVersion version, string clusterName) : base(version,
+ EphemeralHome(version, clusterName)) => ClusterName = clusterName;
- private string ClusterName { get; }
+ private string ClusterName { get; }
- public string TempFolder => Path.Combine(Path.GetTempPath(), SubFolder, Artifact.LocalFolderName, ClusterName);
+ public string TempFolder => Path.Combine(Path.GetTempPath(), SubFolder, Artifact.LocalFolderName, ClusterName);
- public override string ConfigPath => Path.Combine(TempFolder, "config");
- public override string LogsPath => Path.Combine(TempFolder, "logs");
- public override string RepositoryPath => Path.Combine(TempFolder, "repositories");
- public override string DataPath => Path.Combine(TempFolder, "data");
+ public override string ConfigPath => Path.Combine(TempFolder, "config");
+ public override string LogsPath => Path.Combine(TempFolder, "logs");
+ public override string RepositoryPath => Path.Combine(TempFolder, "repositories");
+ public override string DataPath => Path.Combine(TempFolder, "data");
- //certificates
- public string CertificateFolderName => "node-certificates";
- public string CertificateNodeName => "node01";
- public string ClientCertificateName => "cn=John Doe,ou=example,o=com";
- public string ClientCertificateFilename => "john_doe";
+ //certificates
+ public string CertificateFolderName => "node-certificates";
+ public string CertificateNodeName => "node01";
+ public string ClientCertificateName => "cn=John Doe,ou=example,o=com";
+ public string ClientCertificateFilename => "john_doe";
- public string CertificatesPath => Path.Combine(ConfigPath, CertificateFolderName);
+ public string CertificatesPath => Path.Combine(ConfigPath, CertificateFolderName);
- public string CaCertificate => Path.Combine(CertificatesPath, "ca", "ca") + ".crt";
+ public string CaCertificate => Path.Combine(CertificatesPath, "ca", "ca") + ".crt";
- public string NodePrivateKey =>
- Path.Combine(CertificatesPath, CertificateNodeName, CertificateNodeName) + ".key";
+ public string NodePrivateKey =>
+ Path.Combine(CertificatesPath, CertificateNodeName, CertificateNodeName) + ".key";
- public string NodeCertificate =>
- Path.Combine(CertificatesPath, CertificateNodeName, CertificateNodeName) + ".crt";
+ public string NodeCertificate =>
+ Path.Combine(CertificatesPath, CertificateNodeName, CertificateNodeName) + ".crt";
- public string ClientCertificate =>
- Path.Combine(CertificatesPath, ClientCertificateFilename, ClientCertificateFilename) + ".crt";
+ public string ClientCertificate =>
+ Path.Combine(CertificatesPath, ClientCertificateFilename, ClientCertificateFilename) + ".crt";
- public string ClientPrivateKey =>
- Path.Combine(CertificatesPath, ClientCertificateFilename, ClientCertificateFilename) + ".key";
+ public string ClientPrivateKey =>
+ Path.Combine(CertificatesPath, ClientCertificateFilename, ClientCertificateFilename) + ".key";
- public string UnusedCertificateFolderName => $"unused-{CertificateFolderName}";
- public string UnusedCertificatesPath => Path.Combine(ConfigPath, UnusedCertificateFolderName);
- public string UnusedCaCertificate => Path.Combine(UnusedCertificatesPath, "ca", "ca") + ".crt";
+ public string UnusedCertificateFolderName => $"unused-{CertificateFolderName}";
+ public string UnusedCertificatesPath => Path.Combine(ConfigPath, UnusedCertificateFolderName);
+ public string UnusedCaCertificate => Path.Combine(UnusedCertificatesPath, "ca", "ca") + ".crt";
- public string UnusedClientCertificate =>
- Path.Combine(UnusedCertificatesPath, ClientCertificateFilename, ClientCertificateFilename) + ".crt";
+ public string UnusedClientCertificate =>
+ Path.Combine(UnusedCertificatesPath, ClientCertificateFilename, ClientCertificateFilename) + ".crt";
- protected static string EphemeralHome(OpenSearchVersion version, string clusterName)
- {
- var temp = Path.Combine(Path.GetTempPath(), SubFolder,
- version.Artifact(Product.OpenSearch).LocalFolderName, clusterName);
- return Path.Combine(temp, "home");
- }
- }
+ protected static string EphemeralHome(OpenSearchVersion version, string clusterName)
+ {
+ var temp = Path.Combine(Path.GetTempPath(), SubFolder,
+ version.Artifact(Product.OpenSearch).LocalFolderName, clusterName);
+ return Path.Combine(temp, "home");
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/IEphemeralCluster.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/IEphemeralCluster.cs
index d97995713a..4f64e59c4d 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/IEphemeralCluster.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/IEphemeralCluster.cs
@@ -30,17 +30,16 @@
using System.Collections.Generic;
using OpenSearch.OpenSearch.Managed;
-namespace OpenSearch.OpenSearch.Ephemeral
+namespace OpenSearch.OpenSearch.Ephemeral;
+
+public interface IEphemeralCluster
{
- public interface IEphemeralCluster
- {
- ICollection NodesUris(string hostName = null);
- string GetCacheFolderName();
- bool CachingAndCachedHomeExists();
- }
+ ICollection NodesUris(string hostName = null);
+ string GetCacheFolderName();
+ bool CachingAndCachedHomeExists();
+}
- public interface IEphemeralCluster : IEphemeralCluster, ICluster
- where TConfiguration : EphemeralClusterConfiguration
- {
- }
+public interface IEphemeralCluster : IEphemeralCluster, ICluster
+ where TConfiguration : EphemeralClusterConfiguration
+{
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Plugins/OpenSearchPlugins.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Plugins/OpenSearchPlugins.cs
index 7c15f6a5a1..4f25f811b2 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Plugins/OpenSearchPlugins.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Plugins/OpenSearchPlugins.cs
@@ -31,47 +31,46 @@
using System.Linq;
using OpenSearch.Stack.ArtifactsApi.Products;
-namespace OpenSearch.OpenSearch.Ephemeral.Plugins
+namespace OpenSearch.OpenSearch.Ephemeral.Plugins;
+
+public class OpenSearchPlugins : ReadOnlyCollection
{
- public class OpenSearchPlugins : ReadOnlyCollection
- {
- public OpenSearchPlugins(IList list) : base(list)
- {
- }
+ public OpenSearchPlugins(IList list) : base(list)
+ {
+ }
- public OpenSearchPlugins(params OpenSearchPlugin[] list) : base(list)
- {
- }
+ public OpenSearchPlugins(params OpenSearchPlugin[] list) : base(list)
+ {
+ }
- public static OpenSearchPlugins Supported { get; } =
- new OpenSearchPlugins(new List
- {
- OpenSearchPlugin.AnalysisIcu,
- OpenSearchPlugin.AnalysisKuromoji,
- OpenSearchPlugin.AnalysisNori,
- OpenSearchPlugin.AnalysisPhonetic,
- OpenSearchPlugin.AnalysisSmartCn,
- OpenSearchPlugin.AnalysisStempel,
- OpenSearchPlugin.AnalysisUkrainian,
- OpenSearchPlugin.DiscoveryAzureClassic,
- OpenSearchPlugin.DiscoveryEC2,
- OpenSearchPlugin.DiscoveryFile,
- OpenSearchPlugin.DiscoveryGCE,
- OpenSearchPlugin.IngestAttachment,
- OpenSearchPlugin.IngestGeoIp,
- OpenSearchPlugin.IngestUserAgent,
- OpenSearchPlugin.MapperAttachment,
- OpenSearchPlugin.MapperMurmur3,
- OpenSearchPlugin.MapperSize,
- OpenSearchPlugin.RepositoryAzure,
- OpenSearchPlugin.RepositoryGCS,
- OpenSearchPlugin.RepositoryHDFS,
- OpenSearchPlugin.RepositoryS3,
- OpenSearchPlugin.Security,
- OpenSearchPlugin.StoreSMB,
- OpenSearchPlugin.DeleteByQuery,
- });
+ public static OpenSearchPlugins Supported { get; } =
+ new OpenSearchPlugins(new List
+ {
+ OpenSearchPlugin.AnalysisIcu,
+ OpenSearchPlugin.AnalysisKuromoji,
+ OpenSearchPlugin.AnalysisNori,
+ OpenSearchPlugin.AnalysisPhonetic,
+ OpenSearchPlugin.AnalysisSmartCn,
+ OpenSearchPlugin.AnalysisStempel,
+ OpenSearchPlugin.AnalysisUkrainian,
+ OpenSearchPlugin.DiscoveryAzureClassic,
+ OpenSearchPlugin.DiscoveryEC2,
+ OpenSearchPlugin.DiscoveryFile,
+ OpenSearchPlugin.DiscoveryGCE,
+ OpenSearchPlugin.IngestAttachment,
+ OpenSearchPlugin.IngestGeoIp,
+ OpenSearchPlugin.IngestUserAgent,
+ OpenSearchPlugin.MapperAttachment,
+ OpenSearchPlugin.MapperMurmur3,
+ OpenSearchPlugin.MapperSize,
+ OpenSearchPlugin.RepositoryAzure,
+ OpenSearchPlugin.RepositoryGCS,
+ OpenSearchPlugin.RepositoryHDFS,
+ OpenSearchPlugin.RepositoryS3,
+ OpenSearchPlugin.Security,
+ OpenSearchPlugin.StoreSMB,
+ OpenSearchPlugin.DeleteByQuery,
+ });
- public override string ToString() => string.Join(", ", Items.Select(s => s.SubProductName));
- }
+ public override string ToString() => string.Join(", ", Items.Select(s => s.SubProductName));
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/SecurityRealms.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/SecurityRealms.cs
index 76bf8c751c..738013827f 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/SecurityRealms.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/SecurityRealms.cs
@@ -26,12 +26,11 @@
* under the License.
*/
-namespace OpenSearch.OpenSearch.Ephemeral
+namespace OpenSearch.OpenSearch.Ephemeral;
+
+public static class SecurityRealms
{
- public static class SecurityRealms
- {
- public const string FileRealm = "file1";
+ public const string FileRealm = "file1";
- public const string PkiRealm = "pki1";
- }
+ public const string PkiRealm = "pki1";
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/AfterNodeStoppedTasks/CleanUpDirectoriesAfterNodeStopped.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/AfterNodeStoppedTasks/CleanUpDirectoriesAfterNodeStopped.cs
index 8acaa36384..b390e4039e 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/AfterNodeStoppedTasks/CleanUpDirectoriesAfterNodeStopped.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/AfterNodeStoppedTasks/CleanUpDirectoriesAfterNodeStopped.cs
@@ -30,55 +30,54 @@
using OpenSearch.OpenSearch.Managed.ConsoleWriters;
using ProcNet.Std;
-namespace OpenSearch.OpenSearch.Ephemeral.Tasks.AfterNodeStoppedTasks
+namespace OpenSearch.OpenSearch.Ephemeral.Tasks.AfterNodeStoppedTasks;
+
+public class CleanUpDirectoriesAfterNodeStopped : IClusterTeardownTask
{
- public class CleanUpDirectoriesAfterNodeStopped : IClusterTeardownTask
- {
- public void Run(IEphemeralCluster cluster, bool nodeStarted)
- {
- var fs = cluster.FileSystem;
- var w = cluster.Writer;
- var a = cluster.ClusterConfiguration.Artifact;
- if (cluster.ClusterConfiguration.NoCleanupAfterNodeStopped)
- {
- w.WriteDiagnostic(
- $"{{{nameof(CleanUpDirectoriesAfterNodeStopped)}}} skipping cleanup as requested on cluster configuration");
- return;
- }
+ public void Run(IEphemeralCluster cluster, bool nodeStarted)
+ {
+ var fs = cluster.FileSystem;
+ var w = cluster.Writer;
+ var a = cluster.ClusterConfiguration.Artifact;
+ if (cluster.ClusterConfiguration.NoCleanupAfterNodeStopped)
+ {
+ w.WriteDiagnostic(
+ $"{{{nameof(CleanUpDirectoriesAfterNodeStopped)}}} skipping cleanup as requested on cluster configuration");
+ return;
+ }
- DeleteDirectory(w, "cluster data", fs.DataPath);
- DeleteDirectory(w, "cluster config", fs.ConfigPath);
- DeleteDirectory(w, "cluster logs", fs.LogsPath);
- DeleteDirectory(w, "repositories", fs.RepositoryPath);
- var efs = fs as EphemeralFileSystem;
- if (!string.IsNullOrWhiteSpace(efs?.TempFolder))
- DeleteDirectory(w, "cluster temp folder", efs.TempFolder);
+ DeleteDirectory(w, "cluster data", fs.DataPath);
+ DeleteDirectory(w, "cluster config", fs.ConfigPath);
+ DeleteDirectory(w, "cluster logs", fs.LogsPath);
+ DeleteDirectory(w, "repositories", fs.RepositoryPath);
+ var efs = fs as EphemeralFileSystem;
+ if (!string.IsNullOrWhiteSpace(efs?.TempFolder))
+ DeleteDirectory(w, "cluster temp folder", efs.TempFolder);
- if (efs != null)
- {
- var extractedFolder = Path.Combine(fs.LocalFolder, a.FolderInZip);
- if (extractedFolder != fs.OpenSearchHome)
- DeleteDirectory(w, "ephemeral OPENSEARCH_HOME", fs.OpenSearchHome);
- //if the node was not started delete the cached extractedFolder
- if (!nodeStarted)
- DeleteDirectory(w, "cached extracted folder - node failed to start", extractedFolder);
- }
+ if (efs != null)
+ {
+ var extractedFolder = Path.Combine(fs.LocalFolder, a.FolderInZip);
+ if (extractedFolder != fs.OpenSearchHome)
+ DeleteDirectory(w, "ephemeral OPENSEARCH_HOME", fs.OpenSearchHome);
+ //if the node was not started delete the cached extractedFolder
+ if (!nodeStarted)
+ DeleteDirectory(w, "cached extracted folder - node failed to start", extractedFolder);
+ }
- //if the node did not start make sure we delete the cached folder as we can not assume its in a good state
- var cachedOpenSearchHomeFolder = Path.Combine(fs.LocalFolder, cluster.GetCacheFolderName());
- if (cluster.ClusterConfiguration.CacheOpenSearchHomeInstallation && !nodeStarted)
- DeleteDirectory(w, "cached installation - node failed to start", cachedOpenSearchHomeFolder);
- else
- w.WriteDiagnostic(
- $"{{{nameof(CleanUpDirectoriesAfterNodeStopped)}}} Leaving [cached folder] on disk: {{{cachedOpenSearchHomeFolder}}}");
- }
+ //if the node did not start make sure we delete the cached folder as we can not assume its in a good state
+ var cachedOpenSearchHomeFolder = Path.Combine(fs.LocalFolder, cluster.GetCacheFolderName());
+ if (cluster.ClusterConfiguration.CacheOpenSearchHomeInstallation && !nodeStarted)
+ DeleteDirectory(w, "cached installation - node failed to start", cachedOpenSearchHomeFolder);
+ else
+ w.WriteDiagnostic(
+ $"{{{nameof(CleanUpDirectoriesAfterNodeStopped)}}} Leaving [cached folder] on disk: {{{cachedOpenSearchHomeFolder}}}");
+ }
- private static void DeleteDirectory(IConsoleLineHandler w, string description, string path)
- {
- if (!Directory.Exists(path)) return;
- w.WriteDiagnostic(
- $"{{{nameof(CleanUpDirectoriesAfterNodeStopped)}}} attempting to delete [{description}]: {{{path}}}");
- Directory.Delete(path, true);
- }
- }
+ private static void DeleteDirectory(IConsoleLineHandler w, string description, string path)
+ {
+ if (!Directory.Exists(path)) return;
+ w.WriteDiagnostic(
+ $"{{{nameof(CleanUpDirectoriesAfterNodeStopped)}}} attempting to delete [{description}]: {{{path}}}");
+ Directory.Delete(path, true);
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/BeforeStartNodeTasks/CacheOpenSearchInstallation.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/BeforeStartNodeTasks/CacheOpenSearchInstallation.cs
index 85a0a1fc89..d01a0964ac 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/BeforeStartNodeTasks/CacheOpenSearchInstallation.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/BeforeStartNodeTasks/CacheOpenSearchInstallation.cs
@@ -29,29 +29,28 @@
using System.IO;
using OpenSearch.OpenSearch.Managed.ConsoleWriters;
-namespace OpenSearch.OpenSearch.Ephemeral.Tasks.BeforeStartNodeTasks
+namespace OpenSearch.OpenSearch.Ephemeral.Tasks.BeforeStartNodeTasks;
+
+public class CacheOpenSearchInstallation : ClusterComposeTask
{
- public class CacheOpenSearchInstallation : ClusterComposeTask
- {
- public override void Run(IEphemeralCluster cluster)
- {
- if (!cluster.ClusterConfiguration.CacheOpenSearchHomeInstallation) return;
+ public override void Run(IEphemeralCluster cluster)
+ {
+ if (!cluster.ClusterConfiguration.CacheOpenSearchHomeInstallation) return;
- var fs = cluster.FileSystem;
- var cachedOpenSearchHomeFolder = Path.Combine(fs.LocalFolder, cluster.GetCacheFolderName());
- var cachedOpenSearchConfig = Path.Combine(cachedOpenSearchHomeFolder, "config");
- if (File.Exists(cachedOpenSearchConfig))
- {
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(CacheOpenSearchInstallation)}}} cached home already exists [{cachedOpenSearchHomeFolder}]");
- return;
- }
+ var fs = cluster.FileSystem;
+ var cachedOpenSearchHomeFolder = Path.Combine(fs.LocalFolder, cluster.GetCacheFolderName());
+ var cachedOpenSearchConfig = Path.Combine(cachedOpenSearchHomeFolder, "config");
+ if (File.Exists(cachedOpenSearchConfig))
+ {
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(CacheOpenSearchInstallation)}}} cached home already exists [{cachedOpenSearchHomeFolder}]");
+ return;
+ }
- var source = fs.OpenSearchHome;
- var target = cachedOpenSearchHomeFolder;
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(CacheOpenSearchInstallation)}}} caching {{{source}}} to [{target}]");
- CopyFolder(source, target, false);
- }
- }
+ var source = fs.OpenSearchHome;
+ var target = cachedOpenSearchHomeFolder;
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(CacheOpenSearchInstallation)}}} caching {{{source}}} to [{target}]");
+ CopyFolder(source, target, false);
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/BeforeStartNodeTasks/CreateEphemeralDirectory.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/BeforeStartNodeTasks/CreateEphemeralDirectory.cs
index 67e77cbc8b..b417342ed3 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/BeforeStartNodeTasks/CreateEphemeralDirectory.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/BeforeStartNodeTasks/CreateEphemeralDirectory.cs
@@ -30,56 +30,55 @@
using OpenSearch.OpenSearch.Managed.ConsoleWriters;
using OpenSearch.OpenSearch.Managed.FileSystem;
-namespace OpenSearch.OpenSearch.Ephemeral.Tasks.BeforeStartNodeTasks
+namespace OpenSearch.OpenSearch.Ephemeral.Tasks.BeforeStartNodeTasks;
+
+public class CreateEphemeralDirectory : ClusterComposeTask
{
- public class CreateEphemeralDirectory : ClusterComposeTask
- {
- public override void Run(IEphemeralCluster cluster)
- {
- var fs = cluster.FileSystem;
- if (!(fs is EphemeralFileSystem f))
- {
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(CreateEphemeralDirectory)}}} unexpected IFileSystem implementation {{{fs.GetType()}}}");
- return;
- }
+ public override void Run(IEphemeralCluster cluster)
+ {
+ var fs = cluster.FileSystem;
+ if (!(fs is EphemeralFileSystem f))
+ {
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(CreateEphemeralDirectory)}}} unexpected IFileSystem implementation {{{fs.GetType()}}}");
+ return;
+ }
- cluster.Writer?.WriteDiagnostic($"{{{nameof(CreateEphemeralDirectory)}}} creating {{{f.TempFolder}}}");
+ cluster.Writer?.WriteDiagnostic($"{{{nameof(CreateEphemeralDirectory)}}} creating {{{f.TempFolder}}}");
- Directory.CreateDirectory(f.TempFolder);
+ Directory.CreateDirectory(f.TempFolder);
- if (!Directory.Exists(f.ConfigPath))
- {
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(CreateEphemeralDirectory)}}} creating config folder {{{f.ConfigPath}}}");
- Directory.CreateDirectory(f.ConfigPath);
- }
+ if (!Directory.Exists(f.ConfigPath))
+ {
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(CreateEphemeralDirectory)}}} creating config folder {{{f.ConfigPath}}}");
+ Directory.CreateDirectory(f.ConfigPath);
+ }
- CopyHomeConfigToEphemeralConfig(cluster, f, fs);
- }
+ CopyHomeConfigToEphemeralConfig(cluster, f, fs);
+ }
- private static void CopyHomeConfigToEphemeralConfig(IEphemeralCluster cluster,
- EphemeralFileSystem ephemeralFileSystem, INodeFileSystem fs)
- {
- var target = ephemeralFileSystem.ConfigPath;
- var cachedOpenSearchHomeFolder = Path.Combine(fs.LocalFolder, cluster.GetCacheFolderName());
- var cachedOpenSearchYaml = Path.Combine(cachedOpenSearchHomeFolder, "config", "opensearch.yaml");
+ private static void CopyHomeConfigToEphemeralConfig(IEphemeralCluster cluster,
+ EphemeralFileSystem ephemeralFileSystem, INodeFileSystem fs)
+ {
+ var target = ephemeralFileSystem.ConfigPath;
+ var cachedOpenSearchHomeFolder = Path.Combine(fs.LocalFolder, cluster.GetCacheFolderName());
+ var cachedOpenSearchYaml = Path.Combine(cachedOpenSearchHomeFolder, "config", "opensearch.yaml");
- var homeSource =
- cluster.ClusterConfiguration.CacheOpenSearchHomeInstallation && File.Exists(cachedOpenSearchYaml)
- ? cachedOpenSearchHomeFolder
- : fs.OpenSearchHome;
- var source = Path.Combine(homeSource, "config");
- if (!Directory.Exists(source))
- {
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(CreateEphemeralDirectory)}}} source config {{{source}}} does not exist nothing to copy");
- return;
- }
+ var homeSource =
+ cluster.ClusterConfiguration.CacheOpenSearchHomeInstallation && File.Exists(cachedOpenSearchYaml)
+ ? cachedOpenSearchHomeFolder
+ : fs.OpenSearchHome;
+ var source = Path.Combine(homeSource, "config");
+ if (!Directory.Exists(source))
+ {
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(CreateEphemeralDirectory)}}} source config {{{source}}} does not exist nothing to copy");
+ return;
+ }
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(CreateEphemeralDirectory)}}} copying cached {{{source}}} as to [{target}]");
- CopyFolder(source, target);
- }
- }
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(CreateEphemeralDirectory)}}} copying cached {{{source}}} as to [{target}]");
+ CopyFolder(source, target);
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/BeforeStartNodeTasks/PrintYamlContents.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/BeforeStartNodeTasks/PrintYamlContents.cs
index d525d8eb65..445f63fff0 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/BeforeStartNodeTasks/PrintYamlContents.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/BeforeStartNodeTasks/PrintYamlContents.cs
@@ -30,34 +30,33 @@
using System.Linq;
using OpenSearch.OpenSearch.Managed.ConsoleWriters;
-namespace OpenSearch.OpenSearch.Ephemeral.Tasks.BeforeStartNodeTasks
+namespace OpenSearch.OpenSearch.Ephemeral.Tasks.BeforeStartNodeTasks;
+
+public class PrintYamlContents : ClusterComposeTask
{
- public class PrintYamlContents : ClusterComposeTask
- {
- public override void Run(IEphemeralCluster cluster)
- {
- var c = cluster.ClusterConfiguration;
- var v = c.Version;
- var fs = cluster.FileSystem;
+ public override void Run(IEphemeralCluster cluster)
+ {
+ var c = cluster.ClusterConfiguration;
+ var v = c.Version;
+ var fs = cluster.FileSystem;
- var files = Directory.GetFiles(fs.ConfigPath, "*.yml", SearchOption.AllDirectories);
- foreach (var file in files) DumpFile(cluster, file);
- }
+ var files = Directory.GetFiles(fs.ConfigPath, "*.yml", SearchOption.AllDirectories);
+ foreach (var file in files) DumpFile(cluster, file);
+ }
- private static void DumpFile(IEphemeralCluster cluster, string configFile)
- {
- if (!File.Exists(configFile))
- {
- cluster.Writer.WriteDiagnostic(
- $"{{{nameof(PrintYamlContents)}}} skipped printing [{configFile}] as it does not exists");
- return;
- }
+ private static void DumpFile(IEphemeralCluster cluster, string configFile)
+ {
+ if (!File.Exists(configFile))
+ {
+ cluster.Writer.WriteDiagnostic(
+ $"{{{nameof(PrintYamlContents)}}} skipped printing [{configFile}] as it does not exists");
+ return;
+ }
- var fileName = Path.GetFileName(configFile);
- cluster.Writer.WriteDiagnostic($"{{{nameof(PrintYamlContents)}}} printing [{configFile}]");
- var lines = File.ReadAllLines(configFile).ToList();
- foreach (var l in lines.Where(l => !string.IsNullOrWhiteSpace(l) && !l.StartsWith("#")))
- cluster.Writer.WriteDiagnostic($"{{{nameof(PrintYamlContents)}}} [{fileName}] {l}");
- }
- }
+ var fileName = Path.GetFileName(configFile);
+ cluster.Writer.WriteDiagnostic($"{{{nameof(PrintYamlContents)}}} printing [{configFile}]");
+ var lines = File.ReadAllLines(configFile).ToList();
+ foreach (var l in lines.Where(l => !string.IsNullOrWhiteSpace(l) && !l.StartsWith("#")))
+ cluster.Writer.WriteDiagnostic($"{{{nameof(PrintYamlContents)}}} [{fileName}] {l}");
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/IClusterComposeTask.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/IClusterComposeTask.cs
index 74441951ef..3c5b0bc5f8 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/IClusterComposeTask.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/IClusterComposeTask.cs
@@ -40,234 +40,233 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
-using OpenSearch.OpenSearch.Managed.ConsoleWriters;
using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.Tar;
+using OpenSearch.OpenSearch.Managed.ConsoleWriters;
using ProcNet;
using ProcNet.Std;
-namespace OpenSearch.OpenSearch.Ephemeral.Tasks
+namespace OpenSearch.OpenSearch.Ephemeral.Tasks;
+
+public interface IClusterComposeTask
+{
+ void Run(IEphemeralCluster cluster);
+}
+
+public interface IClusterTeardownTask
+{
+ ///
+ /// Called when the cluster disposes, used to clean up after itself.
+ ///
+ /// The cluster configuration of the node that was started
+ /// Whether the cluster composer was successful in starting the node
+ void Run(IEphemeralCluster cluster, bool nodeStarted);
+}
+
+public abstract class ClusterComposeTask : IClusterComposeTask
{
- public interface IClusterComposeTask
- {
- void Run(IEphemeralCluster cluster);
- }
-
- public interface IClusterTeardownTask
- {
- ///
- /// Called when the cluster disposes, used to clean up after itself.
- ///
- /// The cluster configuration of the node that was started
- /// Whether the cluster composer was successful in starting the node
- void Run(IEphemeralCluster cluster, bool nodeStarted);
- }
-
- public abstract class ClusterComposeTask : IClusterComposeTask
- {
- protected static bool IsWindows { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
- protected static string BinarySuffix => IsWindows ? ".bat" : string.Empty;
- public abstract void Run(IEphemeralCluster cluster);
-
- protected static void DownloadFile(string from, string to)
- {
- if (File.Exists(to)) return;
- var http = new HttpClient();
- using (var stream = http.GetStreamAsync(new Uri(from)).GetAwaiter().GetResult())
- using (var fileStream = File.Create(to))
- {
- stream.CopyTo(fileStream);
- fileStream.Flush();
- }
- }
-
- protected string GetResponseException(HttpResponseMessage m) =>
- $"Code: {m?.StatusCode} Reason: {m?.ReasonPhrase} Content: {GetResponseString(m)}";
-
- protected string GetResponseString(HttpResponseMessage m) =>
- m?.Content?.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult() ?? string.Empty;
-
- protected HttpResponseMessage Get(IEphemeralCluster cluster, string path,
- string query) =>
- Call(cluster, path, query, (c, u, t) => c.GetAsync(u, t));
-
- protected HttpResponseMessage Post(IEphemeralCluster cluster, string path,
- string query, string json) =>
- Call(cluster, path, query,
- (c, u, t) => c.PostAsync(u, new StringContent(json, Encoding.UTF8, "application/json"), t));
-
- private HttpResponseMessage Call(
- IEphemeralCluster cluster,
- string path,
- string query,
- Func> verb)
- {
- var q = string.IsNullOrEmpty(query) ? "pretty=true" : query + "&pretty=true";
- var statusUrl = new UriBuilder(cluster.NodesUris().First()) {Path = path, Query = q}.Uri;
-
- var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(20));
- var handler = new HttpClientHandler
- {
- AutomaticDecompression =
- DecompressionMethods.Deflate | DecompressionMethods.GZip | DecompressionMethods.None,
- };
- cluster.Writer.WriteDiagnostic(
- $"{{{nameof(Call)}}} [{statusUrl}] SSL: {cluster.ClusterConfiguration.EnableSsl}");
- if (cluster.ClusterConfiguration.EnableSsl)
- {
+ protected static bool IsWindows { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
+ protected static string BinarySuffix => IsWindows ? ".bat" : string.Empty;
+ public abstract void Run(IEphemeralCluster cluster);
+
+ protected static void DownloadFile(string from, string to)
+ {
+ if (File.Exists(to)) return;
+ var http = new HttpClient();
+ using (var stream = http.GetStreamAsync(new Uri(from)).GetAwaiter().GetResult())
+ using (var fileStream = File.Create(to))
+ {
+ stream.CopyTo(fileStream);
+ fileStream.Flush();
+ }
+ }
+
+ protected string GetResponseException(HttpResponseMessage m) =>
+ $"Code: {m?.StatusCode} Reason: {m?.ReasonPhrase} Content: {GetResponseString(m)}";
+
+ protected string GetResponseString(HttpResponseMessage m) =>
+ m?.Content?.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult() ?? string.Empty;
+
+ protected HttpResponseMessage Get(IEphemeralCluster cluster, string path,
+ string query) =>
+ Call(cluster, path, query, (c, u, t) => c.GetAsync(u, t));
+
+ protected HttpResponseMessage Post(IEphemeralCluster cluster, string path,
+ string query, string json) =>
+ Call(cluster, path, query,
+ (c, u, t) => c.PostAsync(u, new StringContent(json, Encoding.UTF8, "application/json"), t));
+
+ private HttpResponseMessage Call(
+ IEphemeralCluster cluster,
+ string path,
+ string query,
+ Func> verb)
+ {
+ var q = string.IsNullOrEmpty(query) ? "pretty=true" : query + "&pretty=true";
+ var statusUrl = new UriBuilder(cluster.NodesUris().First()) { Path = path, Query = q }.Uri;
+
+ var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(20));
+ var handler = new HttpClientHandler
+ {
+ AutomaticDecompression =
+ DecompressionMethods.Deflate | DecompressionMethods.GZip | DecompressionMethods.None,
+ };
+ cluster.Writer.WriteDiagnostic(
+ $"{{{nameof(Call)}}} [{statusUrl}] SSL: {cluster.ClusterConfiguration.EnableSsl}");
+ if (cluster.ClusterConfiguration.EnableSsl)
+ {
#if !NETSTANDARD
ServicePointManager.ServerCertificateValidationCallback += ServerCertificateValidationCallback;
#else
- handler.ServerCertificateCustomValidationCallback += (m, c, cn, p) => true;
+ handler.ServerCertificateCustomValidationCallback += (m, c, cn, p) => true;
#endif
- }
-
- using (var client = new HttpClient(handler) {Timeout = TimeSpan.FromSeconds(20)})
- {
- if (cluster.ClusterConfiguration.EnableSsl)
- {
- var byteArray =
- Encoding.ASCII.GetBytes(
- $"{ClusterAuthentication.Admin.Username}:{ClusterAuthentication.Admin.Password}");
- client.DefaultRequestHeaders.Authorization =
- new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
- }
-
- try
- {
- var response = verb(client, statusUrl, tokenSource.Token).ConfigureAwait(false).GetAwaiter()
- .GetResult();
- if (!response.IsSuccessStatusCode)
- {
- cluster.Writer.WriteDiagnostic(
- $"{{{nameof(Call)}}} [{statusUrl}] Unsuccessful status code: [{(int) response.StatusCode}]");
- var body = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
- foreach (var l in (body ?? string.Empty).Split('\n', '\r'))
- cluster.Writer.WriteDiagnostic($"{{{nameof(Call)}}} [{statusUrl}] returned [{l}]");
- }
-
- return response;
- }
- catch (Exception e)
- {
- cluster.Writer.WriteError($"{{{nameof(Call)}}} [{statusUrl}] exception: {e}");
- throw;
- }
- finally
- {
+ }
+
+ using (var client = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(20) })
+ {
+ if (cluster.ClusterConfiguration.EnableSsl)
+ {
+ var byteArray =
+ Encoding.ASCII.GetBytes(
+ $"{ClusterAuthentication.Admin.Username}:{ClusterAuthentication.Admin.Password}");
+ client.DefaultRequestHeaders.Authorization =
+ new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
+ }
+
+ try
+ {
+ var response = verb(client, statusUrl, tokenSource.Token).ConfigureAwait(false).GetAwaiter()
+ .GetResult();
+ if (!response.IsSuccessStatusCode)
+ {
+ cluster.Writer.WriteDiagnostic(
+ $"{{{nameof(Call)}}} [{statusUrl}] Unsuccessful status code: [{(int)response.StatusCode}]");
+ var body = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
+ foreach (var l in (body ?? string.Empty).Split('\n', '\r'))
+ cluster.Writer.WriteDiagnostic($"{{{nameof(Call)}}} [{statusUrl}] returned [{l}]");
+ }
+
+ return response;
+ }
+ catch (Exception e)
+ {
+ cluster.Writer.WriteError($"{{{nameof(Call)}}} [{statusUrl}] exception: {e}");
+ throw;
+ }
+ finally
+ {
#if !NETSTANDARD
ServicePointManager.ServerCertificateValidationCallback -= ServerCertificateValidationCallback;
#endif
- }
- }
- }
-
- private static bool ServerCertificateValidationCallback(object sender, X509Certificate certificate,
- X509Chain chain, SslPolicyErrors sslpolicyerrors) => true;
-
- protected static void WriteFileIfNotExist(string fileLocation, string contents)
- {
- if (!File.Exists(fileLocation)) File.WriteAllText(fileLocation, contents);
- }
-
- protected static void ExecuteBinary(EphemeralClusterConfiguration config, IConsoleLineHandler writer,
- string binary, string description, params string[] arguments) =>
- ExecuteBinaryInternal(config, writer, binary, description, null, arguments);
-
- protected static void ExecuteBinary(EphemeralClusterConfiguration config, IConsoleLineHandler writer,
- string binary, string description, IDictionary environmentVariables,
- params string[] arguments) =>
- ExecuteBinaryInternal(config, writer, binary, description, environmentVariables, arguments);
-
- private static void ExecuteBinaryInternal(EphemeralClusterConfiguration config, IConsoleLineHandler writer,
- string binary, string description, IDictionary environmentVariables, params string[] arguments)
- {
- var command = $"{{{binary}}} {{{string.Join(" ", arguments)}}}";
- writer?.WriteDiagnostic($"{{{nameof(ExecuteBinary)}}} starting process [{description}] {command}");
-
- var environment = new Dictionary
- {
- {config.FileSystem.ConfigEnvironmentVariableName, config.FileSystem.ConfigPath},
- {"OPENSEARCH_HOME", config.FileSystem.OpenSearchHome}
- };
-
- if (environmentVariables != null)
- {
- foreach (var kvp in environmentVariables)
- environment[kvp.Key] = kvp.Value;
- }
-
- var timeout = TimeSpan.FromSeconds(420);
- var processStartArguments = new StartArguments(binary, arguments)
- {
- Environment = environment
- };
-
- var result = Proc.Start(processStartArguments, timeout, new ConsoleOutColorWriter());
-
- if (!result.Completed)
- throw new Exception($"Timeout while executing {description} exceeded {timeout}");
-
- if (result.ExitCode != 0)
- throw new Exception(
- $"Expected exit code 0 but received ({result.ExitCode}) while executing {description}: {command}");
-
- var errorOut = result.ConsoleOut.Where(c => c.Error).ToList();
-
- if (errorOut.Any(e =>
- !string.IsNullOrWhiteSpace(e.Line) && !e.Line.Contains("usage of JAVA_HOME is deprecated")) &&
- !binary.Contains("plugin") && !binary.Contains("cert"))
- throw new Exception(
- $"Received error out with exitCode ({result.ExitCode}) while executing {description}: {command}");
-
- writer?.WriteDiagnostic(
- $"{{{nameof(ExecuteBinary)}}} finished process [{description}] {{{result.ExitCode}}}");
- }
-
- protected static void CopyFolder(string source, string target, bool overwrite = true)
- {
- foreach (var sourceDir in Directory.GetDirectories(source, "*", SearchOption.AllDirectories))
- {
- var targetDir = sourceDir.Replace(source, target);
- Directory.CreateDirectory(targetDir);
- }
-
- foreach (var sourcePath in Directory.GetFiles(source, "*.*", SearchOption.AllDirectories))
- {
- var targetPath = sourcePath.Replace(source, target);
- if (!overwrite && File.Exists(targetPath)) continue;
- File.Copy(sourcePath, targetPath, overwrite);
- }
- }
-
- protected static void Extract(string file, string toFolder)
- {
- if (file.EndsWith(".zip")) ExtractZip(file, toFolder);
- else if (file.EndsWith(".tar.gz")) ExtractTarGz(file, toFolder);
- else if (file.EndsWith(".tar")) ExtractTar(file, toFolder);
- else throw new Exception("Can not extract:" + file);
- }
-
- private static void ExtractTar(string file, string toFolder)
- {
- using (var inStream = File.OpenRead(file))
- using (var tarArchive = TarArchive.CreateInputTarArchive(inStream, Encoding.UTF8))
- tarArchive.ExtractContents(toFolder);
- }
-
- private static void ExtractTarGz(string file, string toFolder)
- {
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- using (var inStream = File.OpenRead(file))
- using (var gzipStream = new GZipInputStream(inStream))
- using (var tarArchive = TarArchive.CreateInputTarArchive(gzipStream, Encoding.UTF8))
- tarArchive.ExtractContents(toFolder);
- else
- //SharpZipLib loses permissions when untarring
- Proc.Exec("tar", "-xvf", file, "-C", toFolder);
- }
-
- private static void ExtractZip(string file, string toFolder) =>
- ZipFile.ExtractToDirectory(file, toFolder);
- }
+ }
+ }
+ }
+
+ private static bool ServerCertificateValidationCallback(object sender, X509Certificate certificate,
+ X509Chain chain, SslPolicyErrors sslpolicyerrors) => true;
+
+ protected static void WriteFileIfNotExist(string fileLocation, string contents)
+ {
+ if (!File.Exists(fileLocation)) File.WriteAllText(fileLocation, contents);
+ }
+
+ protected static void ExecuteBinary(EphemeralClusterConfiguration config, IConsoleLineHandler writer,
+ string binary, string description, params string[] arguments) =>
+ ExecuteBinaryInternal(config, writer, binary, description, null, arguments);
+
+ protected static void ExecuteBinary(EphemeralClusterConfiguration config, IConsoleLineHandler writer,
+ string binary, string description, IDictionary environmentVariables,
+ params string[] arguments) =>
+ ExecuteBinaryInternal(config, writer, binary, description, environmentVariables, arguments);
+
+ private static void ExecuteBinaryInternal(EphemeralClusterConfiguration config, IConsoleLineHandler writer,
+ string binary, string description, IDictionary environmentVariables, params string[] arguments)
+ {
+ var command = $"{{{binary}}} {{{string.Join(" ", arguments)}}}";
+ writer?.WriteDiagnostic($"{{{nameof(ExecuteBinary)}}} starting process [{description}] {command}");
+
+ var environment = new Dictionary
+ {
+ {config.FileSystem.ConfigEnvironmentVariableName, config.FileSystem.ConfigPath},
+ {"OPENSEARCH_HOME", config.FileSystem.OpenSearchHome}
+ };
+
+ if (environmentVariables != null)
+ {
+ foreach (var kvp in environmentVariables)
+ environment[kvp.Key] = kvp.Value;
+ }
+
+ var timeout = TimeSpan.FromSeconds(420);
+ var processStartArguments = new StartArguments(binary, arguments)
+ {
+ Environment = environment
+ };
+
+ var result = Proc.Start(processStartArguments, timeout, new ConsoleOutColorWriter());
+
+ if (!result.Completed)
+ throw new Exception($"Timeout while executing {description} exceeded {timeout}");
+
+ if (result.ExitCode != 0)
+ throw new Exception(
+ $"Expected exit code 0 but received ({result.ExitCode}) while executing {description}: {command}");
+
+ var errorOut = result.ConsoleOut.Where(c => c.Error).ToList();
+
+ if (errorOut.Any(e =>
+ !string.IsNullOrWhiteSpace(e.Line) && !e.Line.Contains("usage of JAVA_HOME is deprecated")) &&
+ !binary.Contains("plugin") && !binary.Contains("cert"))
+ throw new Exception(
+ $"Received error out with exitCode ({result.ExitCode}) while executing {description}: {command}");
+
+ writer?.WriteDiagnostic(
+ $"{{{nameof(ExecuteBinary)}}} finished process [{description}] {{{result.ExitCode}}}");
+ }
+
+ protected static void CopyFolder(string source, string target, bool overwrite = true)
+ {
+ foreach (var sourceDir in Directory.GetDirectories(source, "*", SearchOption.AllDirectories))
+ {
+ var targetDir = sourceDir.Replace(source, target);
+ Directory.CreateDirectory(targetDir);
+ }
+
+ foreach (var sourcePath in Directory.GetFiles(source, "*.*", SearchOption.AllDirectories))
+ {
+ var targetPath = sourcePath.Replace(source, target);
+ if (!overwrite && File.Exists(targetPath)) continue;
+ File.Copy(sourcePath, targetPath, overwrite);
+ }
+ }
+
+ protected static void Extract(string file, string toFolder)
+ {
+ if (file.EndsWith(".zip")) ExtractZip(file, toFolder);
+ else if (file.EndsWith(".tar.gz")) ExtractTarGz(file, toFolder);
+ else if (file.EndsWith(".tar")) ExtractTar(file, toFolder);
+ else throw new Exception("Can not extract:" + file);
+ }
+
+ private static void ExtractTar(string file, string toFolder)
+ {
+ using (var inStream = File.OpenRead(file))
+ using (var tarArchive = TarArchive.CreateInputTarArchive(inStream, Encoding.UTF8))
+ tarArchive.ExtractContents(toFolder);
+ }
+
+ private static void ExtractTarGz(string file, string toFolder)
+ {
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ using (var inStream = File.OpenRead(file))
+ using (var gzipStream = new GZipInputStream(inStream))
+ using (var tarArchive = TarArchive.CreateInputTarArchive(gzipStream, Encoding.UTF8))
+ tarArchive.ExtractContents(toFolder);
+ else
+ //SharpZipLib loses permissions when untarring
+ Proc.Exec("tar", "-xvf", file, "-C", toFolder);
+ }
+
+ private static void ExtractZip(string file, string toFolder) =>
+ ZipFile.ExtractToDirectory(file, toFolder);
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/CopyCachedOpenSearchInstallation.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/CopyCachedOpenSearchInstallation.cs
index 5c7862de44..e52f814489 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/CopyCachedOpenSearchInstallation.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/CopyCachedOpenSearchInstallation.cs
@@ -29,23 +29,22 @@
using System.IO;
using OpenSearch.OpenSearch.Managed.ConsoleWriters;
-namespace OpenSearch.OpenSearch.Ephemeral.Tasks.InstallationTasks
+namespace OpenSearch.OpenSearch.Ephemeral.Tasks.InstallationTasks;
+
+public class CopyCachedOpenSearchInstallation : ClusterComposeTask
{
- public class CopyCachedOpenSearchInstallation : ClusterComposeTask
- {
- public override void Run(IEphemeralCluster cluster)
- {
- if (!cluster.ClusterConfiguration.CacheOpenSearchHomeInstallation) return;
+ public override void Run(IEphemeralCluster cluster)
+ {
+ if (!cluster.ClusterConfiguration.CacheOpenSearchHomeInstallation) return;
- var fs = cluster.FileSystem;
- var cachedOpenSearchHomeFolder = Path.Combine(fs.LocalFolder, cluster.GetCacheFolderName());
- if (!Directory.Exists(cachedOpenSearchHomeFolder)) return;
+ var fs = cluster.FileSystem;
+ var cachedOpenSearchHomeFolder = Path.Combine(fs.LocalFolder, cluster.GetCacheFolderName());
+ if (!Directory.Exists(cachedOpenSearchHomeFolder)) return;
- var source = cachedOpenSearchHomeFolder;
- var target = fs.OpenSearchHome;
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(CopyCachedOpenSearchInstallation)}}} using cached OPENSEARCH_HOME {{{source}}} and copying it to [{target}]");
- CopyFolder(source, target);
- }
- }
+ var source = cachedOpenSearchHomeFolder;
+ var target = fs.OpenSearchHome;
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(CopyCachedOpenSearchInstallation)}}} using cached OPENSEARCH_HOME {{{source}}} and copying it to [{target}]");
+ CopyFolder(source, target);
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/CreateLocalApplicationDirectory.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/CreateLocalApplicationDirectory.cs
index 35c8e98ec0..f40b7a1965 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/CreateLocalApplicationDirectory.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/CreateLocalApplicationDirectory.cs
@@ -29,24 +29,23 @@
using System.IO;
using OpenSearch.OpenSearch.Managed.ConsoleWriters;
-namespace OpenSearch.OpenSearch.Ephemeral.Tasks.InstallationTasks
+namespace OpenSearch.OpenSearch.Ephemeral.Tasks.InstallationTasks;
+
+public class CreateLocalApplicationDirectory : ClusterComposeTask
{
- public class CreateLocalApplicationDirectory : ClusterComposeTask
- {
- public override void Run(IEphemeralCluster cluster)
- {
- var fs = cluster.FileSystem;
- if (Directory.Exists(fs.LocalFolder))
- {
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(CreateLocalApplicationDirectory)}}} already exists: {{{fs.LocalFolder}}}");
- return;
- }
+ public override void Run(IEphemeralCluster cluster)
+ {
+ var fs = cluster.FileSystem;
+ if (Directory.Exists(fs.LocalFolder))
+ {
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(CreateLocalApplicationDirectory)}}} already exists: {{{fs.LocalFolder}}}");
+ return;
+ }
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(CreateLocalApplicationDirectory)}}} creating {{{fs.LocalFolder}}}");
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(CreateLocalApplicationDirectory)}}} creating {{{fs.LocalFolder}}}");
- Directory.CreateDirectory(fs.LocalFolder);
- }
- }
+ Directory.CreateDirectory(fs.LocalFolder);
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/DownloadOpenSearchVersion.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/DownloadOpenSearchVersion.cs
index 6f2131a7a9..682010cce4 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/DownloadOpenSearchVersion.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/DownloadOpenSearchVersion.cs
@@ -31,41 +31,40 @@
using OpenSearch.OpenSearch.Managed.ConsoleWriters;
using OpenSearch.Stack.ArtifactsApi.Products;
-namespace OpenSearch.OpenSearch.Ephemeral.Tasks.InstallationTasks
+namespace OpenSearch.OpenSearch.Ephemeral.Tasks.InstallationTasks;
+
+public class DownloadOpenSearchVersion : ClusterComposeTask
{
- public class DownloadOpenSearchVersion : ClusterComposeTask
- {
- public override void Run(IEphemeralCluster cluster)
- {
- if (cluster.CachingAndCachedHomeExists()) return;
+ public override void Run(IEphemeralCluster cluster)
+ {
+ if (cluster.CachingAndCachedHomeExists()) return;
- var fs = cluster.FileSystem;
- var v = cluster.ClusterConfiguration.Version;
- var a = cluster.ClusterConfiguration.Artifact;
- var from = v.Artifact(Product.OpenSearch).DownloadUrl;
- var to = Path.Combine(fs.LocalFolder, a.Archive);
- if (File.Exists(to))
- {
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(DownloadOpenSearchVersion)}}} {v} was already downloaded");
- return;
- }
+ var fs = cluster.FileSystem;
+ var v = cluster.ClusterConfiguration.Version;
+ var a = cluster.ClusterConfiguration.Artifact;
+ var from = v.Artifact(Product.OpenSearch).DownloadUrl;
+ var to = Path.Combine(fs.LocalFolder, a.Archive);
+ if (File.Exists(to))
+ {
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(DownloadOpenSearchVersion)}}} {v} was already downloaded");
+ return;
+ }
- if (Environment.GetEnvironmentVariable("OPENSEARCH_DISTRIBUTION") is {} distributionPath)
- {
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(DownloadOpenSearchVersion)}}} copying OpenSearch [{v}] from {{{distributionPath}}} {{{to}}}");
- File.Copy(distributionPath, to);
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(DownloadOpenSearchVersion)}}} copied OpenSearch [{v}] from {{{distributionPath}}} {{{to}}}");
- return;
- }
+ if (Environment.GetEnvironmentVariable("OPENSEARCH_DISTRIBUTION") is { } distributionPath)
+ {
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(DownloadOpenSearchVersion)}}} copying OpenSearch [{v}] from {{{distributionPath}}} {{{to}}}");
+ File.Copy(distributionPath, to);
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(DownloadOpenSearchVersion)}}} copied OpenSearch [{v}] from {{{distributionPath}}} {{{to}}}");
+ return;
+ }
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(DownloadOpenSearchVersion)}}} downloading OpenSearch [{v}] from {{{from}}} {{{to}}}");
- DownloadFile(from, to);
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(DownloadOpenSearchVersion)}}} downloaded OpenSearch [{v}] from {{{from}}} {{{to}}}");
- }
- }
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(DownloadOpenSearchVersion)}}} downloading OpenSearch [{v}] from {{{from}}} {{{to}}}");
+ DownloadFile(from, to);
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(DownloadOpenSearchVersion)}}} downloaded OpenSearch [{v}] from {{{from}}} {{{to}}}");
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/EnsureJavaHomeEnvironmentVariableIsSet.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/EnsureJavaHomeEnvironmentVariableIsSet.cs
index faa8a00641..fb3fecd045 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/EnsureJavaHomeEnvironmentVariableIsSet.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/EnsureJavaHomeEnvironmentVariableIsSet.cs
@@ -30,34 +30,33 @@
using System.IO;
using OpenSearch.OpenSearch.Managed.ConsoleWriters;
-namespace OpenSearch.OpenSearch.Ephemeral.Tasks.InstallationTasks
+namespace OpenSearch.OpenSearch.Ephemeral.Tasks.InstallationTasks;
+
+public class EnsureJavaHomeEnvironmentVariableIsSet : ClusterComposeTask
{
- public class EnsureJavaHomeEnvironmentVariableIsSet : ClusterComposeTask
- {
- public override void Run(IEphemeralCluster cluster)
- {
- var fs = cluster.FileSystem;
+ public override void Run(IEphemeralCluster cluster)
+ {
+ var fs = cluster.FileSystem;
- var envVarName = cluster.ClusterConfiguration.JavaHomeEnvironmentVariable;
- var javaHome = Environment.GetEnvironmentVariable(envVarName);
- var cachedOpenSearchHomeFolder = Path.Combine(fs.LocalFolder, cluster.GetCacheFolderName());
- var jdkFolder = Path.Combine(cachedOpenSearchHomeFolder, "jdk");
- if (Directory.Exists(jdkFolder))
- {
- //prefer bundled jdk
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(EnsureJavaHomeEnvironmentVariableIsSet)}}} [{envVarName}] is set to bundled jdk: {{{jdkFolder}}} ");
- Environment.SetEnvironmentVariable("JAVA_HOME", jdkFolder);
- }
- else if (!string.IsNullOrWhiteSpace(javaHome))
- {
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(EnsureJavaHomeEnvironmentVariableIsSet)}}} [{envVarName}] is set; clearing value for process to prefer bundled jdk...");
- Environment.SetEnvironmentVariable(envVarName, null);
- }
- else
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(EnsureJavaHomeEnvironmentVariableIsSet)}}} {envVarName} is not set proceeding or using default JDK");
- }
- }
+ var envVarName = cluster.ClusterConfiguration.JavaHomeEnvironmentVariable;
+ var javaHome = Environment.GetEnvironmentVariable(envVarName);
+ var cachedOpenSearchHomeFolder = Path.Combine(fs.LocalFolder, cluster.GetCacheFolderName());
+ var jdkFolder = Path.Combine(cachedOpenSearchHomeFolder, "jdk");
+ if (Directory.Exists(jdkFolder))
+ {
+ //prefer bundled jdk
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(EnsureJavaHomeEnvironmentVariableIsSet)}}} [{envVarName}] is set to bundled jdk: {{{jdkFolder}}} ");
+ Environment.SetEnvironmentVariable("JAVA_HOME", jdkFolder);
+ }
+ else if (!string.IsNullOrWhiteSpace(javaHome))
+ {
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(EnsureJavaHomeEnvironmentVariableIsSet)}}} [{envVarName}] is set; clearing value for process to prefer bundled jdk...");
+ Environment.SetEnvironmentVariable(envVarName, null);
+ }
+ else
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(EnsureJavaHomeEnvironmentVariableIsSet)}}} {envVarName} is not set proceeding or using default JDK");
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/InitialConfiguration.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/InitialConfiguration.cs
index 9540c07edb..ac14dd0e80 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/InitialConfiguration.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/InitialConfiguration.cs
@@ -33,46 +33,45 @@
using OpenSearch.Stack.ArtifactsApi.Products;
using SemanticVersioning;
-namespace OpenSearch.OpenSearch.Ephemeral.Tasks.InstallationTasks
+namespace OpenSearch.OpenSearch.Ephemeral.Tasks.InstallationTasks;
+
+public class InitialConfiguration : ClusterComposeTask
{
- public class InitialConfiguration : ClusterComposeTask
- {
- public override void Run(IEphemeralCluster cluster)
- {
- var fs = cluster.FileSystem;
+ public override void Run(IEphemeralCluster cluster)
+ {
+ var fs = cluster.FileSystem;
- var installConfigDir = Path.Combine(fs.OpenSearchHome, "config");
- var installConfigFile = Path.Combine(installConfigDir, "opensearch.yml");
- var pluginSecurity = Path.Combine(fs.OpenSearchHome, "plugins/opensearch-security");
+ var installConfigDir = Path.Combine(fs.OpenSearchHome, "config");
+ var installConfigFile = Path.Combine(installConfigDir, "opensearch.yml");
+ var pluginSecurity = Path.Combine(fs.OpenSearchHome, "plugins/opensearch-security");
- if (!Directory.Exists(pluginSecurity))
- return;
+ if (!Directory.Exists(pluginSecurity))
+ return;
- var isNewDemoScript = cluster.ClusterConfiguration.Version.BaseVersion() >= new Version(2, 12, 0);
+ var isNewDemoScript = cluster.ClusterConfiguration.Version.BaseVersion() >= new Version(2, 12, 0);
- const string securityInstallDemoConfigSubPath = "tools/install_demo_configuration.sh";
- var securityInstallDemoConfig = Path.Combine(pluginSecurity, securityInstallDemoConfigSubPath);
+ const string securityInstallDemoConfigSubPath = "tools/install_demo_configuration.sh";
+ var securityInstallDemoConfig = Path.Combine(pluginSecurity, securityInstallDemoConfigSubPath);
- cluster.Writer?.WriteDiagnostic($"{{{nameof(InitialConfiguration)}}} going to run [{securityInstallDemoConfigSubPath}]");
+ cluster.Writer?.WriteDiagnostic($"{{{nameof(InitialConfiguration)}}} going to run [{securityInstallDemoConfigSubPath}]");
- if (File.Exists(installConfigFile) && File.ReadLines(installConfigFile).Any(l => l.Contains("plugins.security"))) return;
+ if (File.Exists(installConfigFile) && File.ReadLines(installConfigFile).Any(l => l.Contains("plugins.security"))) return;
- var env = new Dictionary();
- var args = new List { securityInstallDemoConfig, "-y", "-i" };
+ var env = new Dictionary();
+ var args = new List { securityInstallDemoConfig, "-y", "-i" };
- if (isNewDemoScript)
- {
- env.Add("OPENSEARCH_INITIAL_ADMIN_PASSWORD", "admin");
- args.Add("-t");
- }
+ if (isNewDemoScript)
+ {
+ env.Add("OPENSEARCH_INITIAL_ADMIN_PASSWORD", "admin");
+ args.Add("-t");
+ }
- ExecuteBinary(
- cluster.ClusterConfiguration,
- cluster.Writer,
- "/bin/bash",
- "install security plugin demo configuration",
- env,
- args.ToArray());
- }
- }
+ ExecuteBinary(
+ cluster.ClusterConfiguration,
+ cluster.Writer,
+ "/bin/bash",
+ "install security plugin demo configuration",
+ env,
+ args.ToArray());
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/InstallPlugins.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/InstallPlugins.cs
index 3225476353..fe64dc7a1a 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/InstallPlugins.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/InstallPlugins.cs
@@ -40,180 +40,179 @@
using OpenSearch.Stack.ArtifactsApi;
using OpenSearch.Stack.ArtifactsApi.Products;
-namespace OpenSearch.OpenSearch.Ephemeral.Tasks.InstallationTasks
+namespace OpenSearch.OpenSearch.Ephemeral.Tasks.InstallationTasks;
+
+public class InstallPlugins : ClusterComposeTask
{
- public class InstallPlugins : ClusterComposeTask
- {
- private static readonly HttpClient HttpClient = new();
-
- public override void Run(IEphemeralCluster cluster)
- {
- if (cluster.CachingAndCachedHomeExists()) return;
-
- var v = cluster.ClusterConfiguration.Version;
-
- var fs = cluster.FileSystem;
- var requiredPlugins = cluster.ClusterConfiguration.Plugins;
-
- if (cluster.ClusterConfiguration.ValidatePluginsToInstall)
- {
- var invalidPlugins = requiredPlugins
- .Where(p => !p.IsValid(v))
- .Select(p => p.SubProductName).ToList();
- if (invalidPlugins.Any())
- throw new OpenSearchCleanExitException(
- $"Can not install the following plugins for version {v}: {string.Join(", ", invalidPlugins)} ");
- }
-
- foreach (var plugin in requiredPlugins)
- {
- var includedByDefault = plugin.IsIncludedOutOfTheBox(v);
- if (includedByDefault)
- {
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(InstallPlugins)}}} SKIP plugin [{plugin.SubProductName}] shipped OOTB as of: {{{plugin.ShippedByDefaultAsOf}}}");
- continue;
- }
-
- var validForCurrentVersion = plugin.IsValid(v);
- if (!validForCurrentVersion)
- {
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(InstallPlugins)}}} SKIP plugin [{plugin.SubProductName}] not valid for version: {{{v}}}");
- continue;
- }
-
- var alreadyInstalled = AlreadyInstalled(fs, plugin.SubProductName);
- if (alreadyInstalled)
- {
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(InstallPlugins)}}} SKIP plugin [{plugin.SubProductName}] already installed");
- continue;
- }
-
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(InstallPlugins)}}} attempting install [{plugin.SubProductName}] as it's not OOTB: {{{plugin.ShippedByDefaultAsOf}}} and valid for {v}: {{{plugin.IsValid(v)}}}");
-
- var homeConfigPath = Path.Combine(fs.OpenSearchHome, "config");
-
- if (!Directory.Exists(homeConfigPath)) Directory.CreateDirectory(homeConfigPath);
-
- var env = new Dictionary
- {
- { fs.ConfigEnvironmentVariableName, homeConfigPath }
- };
-
- ExecuteBinary(
- cluster.ClusterConfiguration,
- cluster.Writer,
- fs.PluginBinary,
- $"install opensearch plugin: {plugin.SubProductName}",
- env,
- "install", "--batch", GetPluginLocation(plugin, v));
-
- CopyConfigDirectoryToHomeCacheConfigDirectory(cluster, plugin);
- }
-
- cluster.Writer?.WriteDiagnostic($"{{{nameof(InstallPlugins)}}} all plugins installed");
- }
-
- private static string GetPluginLocation(OpenSearchPlugin plugin, OpenSearchVersion v)
- {
- var pluginName = plugin.SubProductName;
- var versionVariants = new[]
- {
- v.ToString(),
- $"{v.BaseVersion()}.0{(v.IsPreRelease ? $"-{v.PreRelease}" : string.Empty)}",
- };
-
- if (Environment.GetEnvironmentVariable("OPENSEARCH_PLUGINS_DIRECTORY") is { } pluginsDirectory)
- {
- foreach (var versionVariant in versionVariants)
- {
- var pluginFile = Path.Combine(pluginsDirectory, $"{pluginName}-{versionVariant}.zip");
- if (File.Exists(pluginFile))
- {
- return new UriBuilder("file",string.Empty)
- {
- Path = pluginFile
- .Replace("%",$"%{(int)'%':X2}")
- .Replace("[",$"%{(int)'[':X2}")
- .Replace("]",$"%{(int)']':X2}"),
- }
- .Uri
- .AbsoluteUri;
- }
- }
- }
-
- if (v.IsSnapshot)
- return DeterminePluginSnapshotUrl(pluginName, versionVariants);
-
- return pluginName;
- }
-
- private static string DeterminePluginSnapshotUrl(string pluginName, string[] versionVariants)
- {
- try
- {
- var baseUrl = $"https://aws.oss.sonatype.org/content/repositories/snapshots/org/opensearch/plugin/{pluginName}";
-
- var versionConditions = string.Join(" or ", versionVariants.Select(v => $".='{v}'"));
- var version = SelectNodeWithinRemoteXml(
- $"{baseUrl}/maven-metadata.xml",
- $"metadata/versioning/versions/version[{versionConditions}]")
- .InnerText;
-
- var versionUrl = $"{baseUrl}/{version}";
-
- var snapshotVersion = SelectNodeWithinRemoteXml(
- $"{versionUrl}/maven-metadata.xml",
- "metadata/versioning/snapshotVersions/snapshotVersion[extension='zip']/value")
- .InnerText;
-
- return $"{versionUrl}/{pluginName}-{snapshotVersion}.zip";
- }
- catch (Exception e)
- {
- throw new Exception($"Could not determine snapshot url for plugin `{pluginName}` at versions `{string.Join(", ", versionVariants)}`", e);
- }
- }
-
- private static XmlNode SelectNodeWithinRemoteXml(string url, [LanguageInjection("XPath")] string xPath)
- {
- var task = Task.Run(async () =>
- {
- var msg = await HttpClient.GetAsync(url);
- msg.EnsureSuccessStatusCode();
- var xml = await msg.Content.ReadAsStringAsync();
- var doc = new XmlDocument();
- doc.LoadXml(xml);
- return doc.SelectSingleNode(xPath) ?? throw new Exception($"Could not find node matching XPath: `{xPath}` within `{xml}`");
- });
- task.Wait();
- return task.Result;
- }
-
- private static void CopyConfigDirectoryToHomeCacheConfigDirectory(
- IEphemeralCluster cluster, OpenSearchPlugin plugin)
- {
- if (!cluster.ClusterConfiguration.CacheOpenSearchHomeInstallation) return;
- var fs = cluster.FileSystem;
- var cachedOpenSearchHomeFolder = Path.Combine(fs.LocalFolder, cluster.GetCacheFolderName());
- var configTarget = Path.Combine(cachedOpenSearchHomeFolder, "config");
-
- var configPluginPath = Path.Combine(fs.ConfigPath, plugin.SubProductName);
- var configPluginPathCached = Path.Combine(configTarget, plugin.SubProductName);
- if (!Directory.Exists(configPluginPath) || Directory.Exists(configPluginPathCached)) return;
-
- Directory.CreateDirectory(configPluginPathCached);
- CopyFolder(configPluginPath, configPluginPathCached);
- }
-
- private static bool AlreadyInstalled(INodeFileSystem fileSystem, string folderName)
- {
- var pluginFolder = Path.Combine(fileSystem.OpenSearchHome, "plugins", folderName);
- return Directory.Exists(pluginFolder);
- }
- }
+ private static readonly HttpClient HttpClient = new();
+
+ public override void Run(IEphemeralCluster cluster)
+ {
+ if (cluster.CachingAndCachedHomeExists()) return;
+
+ var v = cluster.ClusterConfiguration.Version;
+
+ var fs = cluster.FileSystem;
+ var requiredPlugins = cluster.ClusterConfiguration.Plugins;
+
+ if (cluster.ClusterConfiguration.ValidatePluginsToInstall)
+ {
+ var invalidPlugins = requiredPlugins
+ .Where(p => !p.IsValid(v))
+ .Select(p => p.SubProductName).ToList();
+ if (invalidPlugins.Any())
+ throw new OpenSearchCleanExitException(
+ $"Can not install the following plugins for version {v}: {string.Join(", ", invalidPlugins)} ");
+ }
+
+ foreach (var plugin in requiredPlugins)
+ {
+ var includedByDefault = plugin.IsIncludedOutOfTheBox(v);
+ if (includedByDefault)
+ {
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(InstallPlugins)}}} SKIP plugin [{plugin.SubProductName}] shipped OOTB as of: {{{plugin.ShippedByDefaultAsOf}}}");
+ continue;
+ }
+
+ var validForCurrentVersion = plugin.IsValid(v);
+ if (!validForCurrentVersion)
+ {
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(InstallPlugins)}}} SKIP plugin [{plugin.SubProductName}] not valid for version: {{{v}}}");
+ continue;
+ }
+
+ var alreadyInstalled = AlreadyInstalled(fs, plugin.SubProductName);
+ if (alreadyInstalled)
+ {
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(InstallPlugins)}}} SKIP plugin [{plugin.SubProductName}] already installed");
+ continue;
+ }
+
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(InstallPlugins)}}} attempting install [{plugin.SubProductName}] as it's not OOTB: {{{plugin.ShippedByDefaultAsOf}}} and valid for {v}: {{{plugin.IsValid(v)}}}");
+
+ var homeConfigPath = Path.Combine(fs.OpenSearchHome, "config");
+
+ if (!Directory.Exists(homeConfigPath)) Directory.CreateDirectory(homeConfigPath);
+
+ var env = new Dictionary
+ {
+ { fs.ConfigEnvironmentVariableName, homeConfigPath }
+ };
+
+ ExecuteBinary(
+ cluster.ClusterConfiguration,
+ cluster.Writer,
+ fs.PluginBinary,
+ $"install opensearch plugin: {plugin.SubProductName}",
+ env,
+ "install", "--batch", GetPluginLocation(plugin, v));
+
+ CopyConfigDirectoryToHomeCacheConfigDirectory(cluster, plugin);
+ }
+
+ cluster.Writer?.WriteDiagnostic($"{{{nameof(InstallPlugins)}}} all plugins installed");
+ }
+
+ private static string GetPluginLocation(OpenSearchPlugin plugin, OpenSearchVersion v)
+ {
+ var pluginName = plugin.SubProductName;
+ var versionVariants = new[]
+ {
+ v.ToString(),
+ $"{v.BaseVersion()}.0{(v.IsPreRelease ? $"-{v.PreRelease}" : string.Empty)}",
+ };
+
+ if (Environment.GetEnvironmentVariable("OPENSEARCH_PLUGINS_DIRECTORY") is { } pluginsDirectory)
+ {
+ foreach (var versionVariant in versionVariants)
+ {
+ var pluginFile = Path.Combine(pluginsDirectory, $"{pluginName}-{versionVariant}.zip");
+ if (File.Exists(pluginFile))
+ {
+ return new UriBuilder("file", string.Empty)
+ {
+ Path = pluginFile
+ .Replace("%", $"%{(int)'%':X2}")
+ .Replace("[", $"%{(int)'[':X2}")
+ .Replace("]", $"%{(int)']':X2}"),
+ }
+ .Uri
+ .AbsoluteUri;
+ }
+ }
+ }
+
+ if (v.IsSnapshot)
+ return DeterminePluginSnapshotUrl(pluginName, versionVariants);
+
+ return pluginName;
+ }
+
+ private static string DeterminePluginSnapshotUrl(string pluginName, string[] versionVariants)
+ {
+ try
+ {
+ var baseUrl = $"https://aws.oss.sonatype.org/content/repositories/snapshots/org/opensearch/plugin/{pluginName}";
+
+ var versionConditions = string.Join(" or ", versionVariants.Select(v => $".='{v}'"));
+ var version = SelectNodeWithinRemoteXml(
+ $"{baseUrl}/maven-metadata.xml",
+ $"metadata/versioning/versions/version[{versionConditions}]")
+ .InnerText;
+
+ var versionUrl = $"{baseUrl}/{version}";
+
+ var snapshotVersion = SelectNodeWithinRemoteXml(
+ $"{versionUrl}/maven-metadata.xml",
+ "metadata/versioning/snapshotVersions/snapshotVersion[extension='zip']/value")
+ .InnerText;
+
+ return $"{versionUrl}/{pluginName}-{snapshotVersion}.zip";
+ }
+ catch (Exception e)
+ {
+ throw new Exception($"Could not determine snapshot url for plugin `{pluginName}` at versions `{string.Join(", ", versionVariants)}`", e);
+ }
+ }
+
+ private static XmlNode SelectNodeWithinRemoteXml(string url, [LanguageInjection("XPath")] string xPath)
+ {
+ var task = Task.Run(async () =>
+ {
+ var msg = await HttpClient.GetAsync(url);
+ msg.EnsureSuccessStatusCode();
+ var xml = await msg.Content.ReadAsStringAsync();
+ var doc = new XmlDocument();
+ doc.LoadXml(xml);
+ return doc.SelectSingleNode(xPath) ?? throw new Exception($"Could not find node matching XPath: `{xPath}` within `{xml}`");
+ });
+ task.Wait();
+ return task.Result;
+ }
+
+ private static void CopyConfigDirectoryToHomeCacheConfigDirectory(
+ IEphemeralCluster cluster, OpenSearchPlugin plugin)
+ {
+ if (!cluster.ClusterConfiguration.CacheOpenSearchHomeInstallation) return;
+ var fs = cluster.FileSystem;
+ var cachedOpenSearchHomeFolder = Path.Combine(fs.LocalFolder, cluster.GetCacheFolderName());
+ var configTarget = Path.Combine(cachedOpenSearchHomeFolder, "config");
+
+ var configPluginPath = Path.Combine(fs.ConfigPath, plugin.SubProductName);
+ var configPluginPathCached = Path.Combine(configTarget, plugin.SubProductName);
+ if (!Directory.Exists(configPluginPath) || Directory.Exists(configPluginPathCached)) return;
+
+ Directory.CreateDirectory(configPluginPathCached);
+ CopyFolder(configPluginPath, configPluginPathCached);
+ }
+
+ private static bool AlreadyInstalled(INodeFileSystem fileSystem, string folderName)
+ {
+ var pluginFolder = Path.Combine(fileSystem.OpenSearchHome, "plugins", folderName);
+ return Directory.Exists(pluginFolder);
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/PrintConfiguration.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/PrintConfiguration.cs
index 42248300c5..91fb616cfa 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/PrintConfiguration.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/PrintConfiguration.cs
@@ -31,46 +31,45 @@
using OpenSearch.OpenSearch.Managed.ConsoleWriters;
using static OpenSearch.OpenSearch.Ephemeral.ClusterFeatures;
-namespace OpenSearch.OpenSearch.Ephemeral.Tasks.InstallationTasks
+namespace OpenSearch.OpenSearch.Ephemeral.Tasks.InstallationTasks;
+
+public class PrintConfiguration : ClusterComposeTask
{
- public class PrintConfiguration : ClusterComposeTask
- {
- public override void Run(IEphemeralCluster cluster)
- {
- var c = cluster.ClusterConfiguration;
- var version = c.Version;
+ public override void Run(IEphemeralCluster cluster)
+ {
+ var c = cluster.ClusterConfiguration;
+ var version = c.Version;
- string F(ClusterFeatures feature)
- {
- return c.Features.HasFlag(feature) ? Enum.GetName(typeof(ClusterFeatures), feature) : string.Empty;
- }
+ string F(ClusterFeatures feature)
+ {
+ return c.Features.HasFlag(feature) ? Enum.GetName(typeof(ClusterFeatures), feature) : string.Empty;
+ }
- var features = string.Join("|",
- new[] { F(SSL)}.Where(v => !string.IsNullOrWhiteSpace(v)));
- features = string.IsNullOrWhiteSpace(features) ? "None" : features;
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(PrintConfiguration)}}} starting {{{version}}} with features [{features}]");
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.NumberOfNodes)}}} [{c.NumberOfNodes}]");
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.ClusterName)}}} [{c.ClusterName}]");
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.EnableSsl)}}} [{c.EnableSsl}]");
- cluster.Writer?.WriteDiagnostic($"{{{nameof(PrintConfiguration)}}} {{{nameof(c.Plugins)}}} [{c.Plugins}]");
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.CacheOpenSearchHomeInstallation)}}} [{c.CacheOpenSearchHomeInstallation}]");
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.ShowOpenSearchOutputAfterStarted)}}} [{c.ShowOpenSearchOutputAfterStarted}]");
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.ValidatePluginsToInstall)}}} [{c.ValidatePluginsToInstall}]");
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.PrintYamlFilesInConfigFolder)}}} [{c.PrintYamlFilesInConfigFolder}]");
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.SkipBuiltInAfterStartTasks)}}} [{c.SkipBuiltInAfterStartTasks}]");
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.HttpFiddlerAware)}}} [{c.HttpFiddlerAware}]");
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.NoCleanupAfterNodeStopped)}}} [{c.NoCleanupAfterNodeStopped}]");
- }
- }
+ var features = string.Join("|",
+ new[] { F(SSL) }.Where(v => !string.IsNullOrWhiteSpace(v)));
+ features = string.IsNullOrWhiteSpace(features) ? "None" : features;
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(PrintConfiguration)}}} starting {{{version}}} with features [{features}]");
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.NumberOfNodes)}}} [{c.NumberOfNodes}]");
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.ClusterName)}}} [{c.ClusterName}]");
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.EnableSsl)}}} [{c.EnableSsl}]");
+ cluster.Writer?.WriteDiagnostic($"{{{nameof(PrintConfiguration)}}} {{{nameof(c.Plugins)}}} [{c.Plugins}]");
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.CacheOpenSearchHomeInstallation)}}} [{c.CacheOpenSearchHomeInstallation}]");
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.ShowOpenSearchOutputAfterStarted)}}} [{c.ShowOpenSearchOutputAfterStarted}]");
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.ValidatePluginsToInstall)}}} [{c.ValidatePluginsToInstall}]");
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.PrintYamlFilesInConfigFolder)}}} [{c.PrintYamlFilesInConfigFolder}]");
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.SkipBuiltInAfterStartTasks)}}} [{c.SkipBuiltInAfterStartTasks}]");
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.HttpFiddlerAware)}}} [{c.HttpFiddlerAware}]");
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(PrintConfiguration)}}} {{{nameof(c.NoCleanupAfterNodeStopped)}}} [{c.NoCleanupAfterNodeStopped}]");
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/SetOpenSearchBundledJdkJavaHome.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/SetOpenSearchBundledJdkJavaHome.cs
index 82a28dac64..7f9c207472 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/SetOpenSearchBundledJdkJavaHome.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/SetOpenSearchBundledJdkJavaHome.cs
@@ -30,24 +30,23 @@
using System.IO;
using OpenSearch.OpenSearch.Managed.ConsoleWriters;
-namespace OpenSearch.OpenSearch.Ephemeral.Tasks.InstallationTasks
+namespace OpenSearch.OpenSearch.Ephemeral.Tasks.InstallationTasks;
+
+public class SetOpenSearchBundledJdkJavaHome : ClusterComposeTask
{
- public class SetOpenSearchBundledJdkJavaHome : ClusterComposeTask
- {
- public override void Run(IEphemeralCluster cluster)
- {
- var fs = cluster.FileSystem;
- var jdkFolder = Path.Combine(fs.OpenSearchHome, "jdk");
- if (Directory.Exists(jdkFolder))
- {
- var envVarName = cluster.ClusterConfiguration.JavaHomeEnvironmentVariable;
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(SetOpenSearchBundledJdkJavaHome)}}} [{envVarName}] is set to bundled jdk: {{{jdkFolder}}} ");
- Environment.SetEnvironmentVariable(envVarName, jdkFolder);
- }
- else
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(SetOpenSearchBundledJdkJavaHome)}}} [No bundled jdk found] looked in: {{{jdkFolder}}} ");
- }
- }
+ public override void Run(IEphemeralCluster cluster)
+ {
+ var fs = cluster.FileSystem;
+ var jdkFolder = Path.Combine(fs.OpenSearchHome, "jdk");
+ if (Directory.Exists(jdkFolder))
+ {
+ var envVarName = cluster.ClusterConfiguration.JavaHomeEnvironmentVariable;
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(SetOpenSearchBundledJdkJavaHome)}}} [{envVarName}] is set to bundled jdk: {{{jdkFolder}}} ");
+ Environment.SetEnvironmentVariable(envVarName, jdkFolder);
+ }
+ else
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(SetOpenSearchBundledJdkJavaHome)}}} [No bundled jdk found] looked in: {{{jdkFolder}}} ");
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/UnzipOpenSearch.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/UnzipOpenSearch.cs
index 81a80693f4..0bff53785a 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/UnzipOpenSearch.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/InstallationTasks/UnzipOpenSearch.cs
@@ -29,40 +29,39 @@
using System.IO;
using OpenSearch.OpenSearch.Managed.ConsoleWriters;
-namespace OpenSearch.OpenSearch.Ephemeral.Tasks.InstallationTasks
+namespace OpenSearch.OpenSearch.Ephemeral.Tasks.InstallationTasks;
+
+public class UnzipOpenSearch : ClusterComposeTask
{
- public class UnzipOpenSearch : ClusterComposeTask
- {
- public override void Run(IEphemeralCluster cluster)
- {
- if (cluster.CachingAndCachedHomeExists()) return;
+ public override void Run(IEphemeralCluster cluster)
+ {
+ if (cluster.CachingAndCachedHomeExists()) return;
- var fs = cluster.FileSystem;
- var v = cluster.ClusterConfiguration.Version;
- var a = cluster.ClusterConfiguration.Artifact;
- if (Directory.Exists(fs.OpenSearchHome))
- {
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(UnzipOpenSearch)}}} skipping [{fs.OpenSearchHome}] already exists");
- return;
- }
+ var fs = cluster.FileSystem;
+ var v = cluster.ClusterConfiguration.Version;
+ var a = cluster.ClusterConfiguration.Artifact;
+ if (Directory.Exists(fs.OpenSearchHome))
+ {
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(UnzipOpenSearch)}}} skipping [{fs.OpenSearchHome}] already exists");
+ return;
+ }
- var from = Path.Combine(fs.LocalFolder, a.Archive);
- var extractedFolder = Path.Combine(fs.LocalFolder, a.FolderInZip);
- if (!Directory.Exists(extractedFolder))
- {
- cluster.Writer?.WriteDiagnostic($"{{{nameof(UnzipOpenSearch)}}} unzipping version [{v}] {{{from}}}");
- Extract(from, fs.LocalFolder);
+ var from = Path.Combine(fs.LocalFolder, a.Archive);
+ var extractedFolder = Path.Combine(fs.LocalFolder, a.FolderInZip);
+ if (!Directory.Exists(extractedFolder))
+ {
+ cluster.Writer?.WriteDiagnostic($"{{{nameof(UnzipOpenSearch)}}} unzipping version [{v}] {{{from}}}");
+ Extract(from, fs.LocalFolder);
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(UnzipOpenSearch)}}} extracted version [{v}] to {{{fs.LocalFolder}}}");
- }
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(UnzipOpenSearch)}}} extracted version [{v}] to {{{fs.LocalFolder}}}");
+ }
- if (extractedFolder == fs.OpenSearchHome) return;
+ if (extractedFolder == fs.OpenSearchHome) return;
- cluster.Writer?.WriteDiagnostic(
- $"{{{nameof(UnzipOpenSearch)}}} Copying extracted folder {{{extractedFolder}}} => {fs.OpenSearchHome}");
- CopyFolder(extractedFolder, fs.OpenSearchHome);
- }
- }
+ cluster.Writer?.WriteDiagnostic(
+ $"{{{nameof(UnzipOpenSearch)}}} Copying extracted folder {{{extractedFolder}}} => {fs.OpenSearchHome}");
+ CopyFolder(extractedFolder, fs.OpenSearchHome);
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/ValidationTasks/ValidateClusterStateTask.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/ValidationTasks/ValidateClusterStateTask.cs
index 1778867b89..d255378a1e 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/ValidationTasks/ValidateClusterStateTask.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/ValidationTasks/ValidateClusterStateTask.cs
@@ -30,18 +30,17 @@
using System.Net;
using OpenSearch.OpenSearch.Managed.ConsoleWriters;
-namespace OpenSearch.OpenSearch.Ephemeral.Tasks.ValidationTasks
+namespace OpenSearch.OpenSearch.Ephemeral.Tasks.ValidationTasks;
+
+public class ValidateClusterStateTask : ClusterComposeTask
{
- public class ValidateClusterStateTask : ClusterComposeTask
- {
- public override void Run(IEphemeralCluster cluster)
- {
- cluster.Writer.WriteDiagnostic(
- $"{{{nameof(ValidateClusterStateTask)}}} waiting cluster to go into yellow health state");
- var healthyResponse = Get(cluster, "_cluster/health", "wait_for_status=yellow&timeout=20s");
- if (healthyResponse == null || healthyResponse.StatusCode != HttpStatusCode.OK)
- throw new Exception(
- $"Cluster health waiting for status yellow failed after 20s {GetResponseException(healthyResponse)}");
- }
- }
+ public override void Run(IEphemeralCluster cluster)
+ {
+ cluster.Writer.WriteDiagnostic(
+ $"{{{nameof(ValidateClusterStateTask)}}} waiting cluster to go into yellow health state");
+ var healthyResponse = Get(cluster, "_cluster/health", "wait_for_status=yellow&timeout=20s");
+ if (healthyResponse == null || healthyResponse.StatusCode != HttpStatusCode.OK)
+ throw new Exception(
+ $"Cluster health waiting for status yellow failed after 20s {GetResponseException(healthyResponse)}");
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/ValidationTasks/ValidatePluginsTask.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/ValidationTasks/ValidatePluginsTask.cs
index 045a53b263..9b5e80129c 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/ValidationTasks/ValidatePluginsTask.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/ValidationTasks/ValidatePluginsTask.cs
@@ -32,37 +32,36 @@
using OpenSearch.OpenSearch.Managed.ConsoleWriters;
using OpenSearch.Stack.ArtifactsApi;
-namespace OpenSearch.OpenSearch.Ephemeral.Tasks.ValidationTasks
+namespace OpenSearch.OpenSearch.Ephemeral.Tasks.ValidationTasks;
+
+public class ValidatePluginsTask : ClusterComposeTask
{
- public class ValidatePluginsTask : ClusterComposeTask
- {
- public override void Run(IEphemeralCluster cluster)
- {
- var v = cluster.ClusterConfiguration.Version;
- var requestPlugins = cluster.ClusterConfiguration.Plugins
- .Where(p => p.IsValid(v))
- .Where(p => !p.IsIncludedOutOfTheBox(v))
- .Select(p => p.GetExistsMoniker(v))
- .ToList();
- if (!requestPlugins.Any()) return;
+ public override void Run(IEphemeralCluster cluster)
+ {
+ var v = cluster.ClusterConfiguration.Version;
+ var requestPlugins = cluster.ClusterConfiguration.Plugins
+ .Where(p => p.IsValid(v))
+ .Where(p => !p.IsIncludedOutOfTheBox(v))
+ .Select(p => p.GetExistsMoniker(v))
+ .ToList();
+ if (!requestPlugins.Any()) return;
- cluster.Writer.WriteDiagnostic(
- $"{{{nameof(ValidatePluginsTask)}}} validating the cluster is running the requested plugins");
- var catPlugins = Get(cluster, "_cat/plugins", "h=component");
- if (catPlugins == null || !catPlugins.IsSuccessStatusCode)
- throw new Exception(
- $"Calling _cat/plugins did not result in an OK response {GetResponseException(catPlugins)}");
+ cluster.Writer.WriteDiagnostic(
+ $"{{{nameof(ValidatePluginsTask)}}} validating the cluster is running the requested plugins");
+ var catPlugins = Get(cluster, "_cat/plugins", "h=component");
+ if (catPlugins == null || !catPlugins.IsSuccessStatusCode)
+ throw new Exception(
+ $"Calling _cat/plugins did not result in an OK response {GetResponseException(catPlugins)}");
- var installedPlugins = GetResponseString(catPlugins)
- .Split(new[] {'\n'}, StringSplitOptions.RemoveEmptyEntries).ToList();
+ var installedPlugins = GetResponseString(catPlugins)
+ .Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).ToList();
- var missingPlugins = requestPlugins.Except(installedPlugins).ToList();
- if (!missingPlugins.Any()) return;
+ var missingPlugins = requestPlugins.Except(installedPlugins).ToList();
+ if (!missingPlugins.Any()) return;
- var missingString = string.Join(", ", missingPlugins);
- var pluginsString = string.Join(", ", installedPlugins);
- throw new Exception(
- $"Already running opensearch missed the following plugin(s): {missingString} currently installed: {pluginsString}.");
- }
- }
+ var missingString = string.Join(", ", missingPlugins);
+ var pluginsString = string.Join(", ", installedPlugins);
+ throw new Exception(
+ $"Already running opensearch missed the following plugin(s): {missingString} currently installed: {pluginsString}.");
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/ValidationTasks/ValidateRunningVersion.cs b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/ValidationTasks/ValidateRunningVersion.cs
index 3dba4bd000..377f5581b7 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/ValidationTasks/ValidateRunningVersion.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Ephemeral/Tasks/ValidationTasks/ValidateRunningVersion.cs
@@ -32,45 +32,44 @@
using System.Threading;
using OpenSearch.OpenSearch.Managed.ConsoleWriters;
-namespace OpenSearch.OpenSearch.Ephemeral.Tasks.ValidationTasks
+namespace OpenSearch.OpenSearch.Ephemeral.Tasks.ValidationTasks;
+
+public class ValidateRunningVersion : ClusterComposeTask
{
- public class ValidateRunningVersion : ClusterComposeTask
- {
- public override void Run(IEphemeralCluster cluster)
- {
- void WriteDiagnostic(string message) =>
- cluster.Writer?.WriteDiagnostic($"{{{nameof(ValidateRunningVersion)}}} {message}");
- var requestedVersion = cluster.ClusterConfiguration.Version;
+ public override void Run(IEphemeralCluster cluster)
+ {
+ void WriteDiagnostic(string message) =>
+ cluster.Writer?.WriteDiagnostic($"{{{nameof(ValidateRunningVersion)}}} {message}");
+ var requestedVersion = cluster.ClusterConfiguration.Version;
- WriteDiagnostic($"validating the cluster is running the requested version: {requestedVersion}");
+ WriteDiagnostic($"validating the cluster is running the requested version: {requestedVersion}");
- HttpResponseMessage catNodes = null;
- var retryCount = 4;
- var initialRetryWait = 5;
- foreach (var retry in Enumerable.Range(1, retryCount))
- {
- catNodes = Get(cluster, "_cat/nodes", "h=version");
- if (catNodes.IsSuccessStatusCode) break;
- var retryWait = TimeSpan.FromSeconds(initialRetryWait * retry);
- WriteDiagnostic($"{catNodes.StatusCode} response for GET _cat/nodes. Waiting to retry #{retry}");
- Thread.Sleep(retryWait);
- }
- if (catNodes is not {IsSuccessStatusCode: true})
- {
- throw new Exception(
- $"Calling _cat/nodes for version checking did not result in an OK response {GetResponseException(catNodes)}");
- }
+ HttpResponseMessage catNodes = null;
+ var retryCount = 4;
+ var initialRetryWait = 5;
+ foreach (var retry in Enumerable.Range(1, retryCount))
+ {
+ catNodes = Get(cluster, "_cat/nodes", "h=version");
+ if (catNodes.IsSuccessStatusCode) break;
+ var retryWait = TimeSpan.FromSeconds(initialRetryWait * retry);
+ WriteDiagnostic($"{catNodes.StatusCode} response for GET _cat/nodes. Waiting to retry #{retry}");
+ Thread.Sleep(retryWait);
+ }
+ if (catNodes is not { IsSuccessStatusCode: true })
+ {
+ throw new Exception(
+ $"Calling _cat/nodes for version checking did not result in an OK response {GetResponseException(catNodes)}");
+ }
- var nodeVersions = GetResponseString(catNodes).Split(new[] {'\n'}, StringSplitOptions.RemoveEmptyEntries)
- .ToList();
+ var nodeVersions = GetResponseString(catNodes).Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)
+ .ToList();
- var anchorVersion = $"{requestedVersion.Major}.{requestedVersion.Minor}.{requestedVersion.Patch}";
- var allOnRequestedVersion = nodeVersions.All(v => v.Trim() == anchorVersion);
- if (!allOnRequestedVersion)
- {
- throw new Exception(
- $"Not all the running nodes in the cluster are on requested version: {anchorVersion} received: {string.Join(", ", nodeVersions)}");
- }
- }
- }
+ var anchorVersion = $"{requestedVersion.Major}.{requestedVersion.Minor}.{requestedVersion.Patch}";
+ var allOnRequestedVersion = nodeVersions.All(v => v.Trim() == anchorVersion);
+ if (!allOnRequestedVersion)
+ {
+ throw new Exception(
+ $"Not all the running nodes in the cluster are on requested version: {anchorVersion} received: {string.Join(", ", nodeVersions)}");
+ }
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Managed/ClusterBase.cs b/abstractions/src/OpenSearch.OpenSearch.Managed/ClusterBase.cs
index 3cdb74e966..b23d06cfba 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Managed/ClusterBase.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Managed/ClusterBase.cs
@@ -38,187 +38,186 @@
using OpenSearch.Stack.ArtifactsApi;
using ProcNet.Std;
-namespace OpenSearch.OpenSearch.Managed
+namespace OpenSearch.OpenSearch.Managed;
+
+public interface ICluster : IDisposable
+ where TConfiguration : IClusterConfiguration
+{
+ string ClusterMoniker { get; }
+ TConfiguration ClusterConfiguration { get; }
+ INodeFileSystem FileSystem { get; }
+ bool Started { get; }
+ ReadOnlyCollection Nodes { get; }
+ IConsoleLineHandler Writer { get; }
+
+ IDisposable Start();
+
+ IDisposable Start(TimeSpan waitForStarted);
+
+ IDisposable Start(IConsoleLineHandler writer, TimeSpan waitForStarted);
+}
+
+
+public abstract class ClusterBase : ClusterBase
+{
+ protected ClusterBase(ClusterConfiguration clusterConfiguration) : base(clusterConfiguration)
+ {
+ }
+}
+
+public abstract class ClusterBase : ICluster
+ where TConfiguration : IClusterConfiguration
{
- public interface ICluster : IDisposable
- where TConfiguration : IClusterConfiguration
- {
- string ClusterMoniker { get; }
- TConfiguration ClusterConfiguration { get; }
- INodeFileSystem FileSystem { get; }
- bool Started { get; }
- ReadOnlyCollection Nodes { get; }
- IConsoleLineHandler Writer { get; }
-
- IDisposable Start();
-
- IDisposable Start(TimeSpan waitForStarted);
-
- IDisposable Start(IConsoleLineHandler writer, TimeSpan waitForStarted);
- }
-
-
- public abstract class ClusterBase : ClusterBase
- {
- protected ClusterBase(ClusterConfiguration clusterConfiguration) : base(clusterConfiguration)
- {
- }
- }
-
- public abstract class ClusterBase : ICluster
- where TConfiguration : IClusterConfiguration
- {
- private Action _defaultConfigSelector = (n, i) => { };
-
- protected ClusterBase(TConfiguration clusterConfiguration)
- {
- ClusterConfiguration = clusterConfiguration;
- ClusterMoniker = GetType().Name.Replace("Cluster", "");
-
- NodeConfiguration Modify(NodeConfiguration n, int p)
- {
- ModifyNodeConfiguration(n, p);
- return n;
- }
-
- var nodes =
- (from port in Enumerable.Range(ClusterConfiguration.StartingPortNumber,
- ClusterConfiguration.NumberOfNodes)
- let config = new NodeConfiguration(clusterConfiguration, port, ClusterMoniker)
- {
- ShowOpenSearchOutputAfterStarted =
- clusterConfiguration.ShowOpenSearchOutputAfterStarted,
- }
- let node = new OpenSearchNode(Modify(config, port))
- {
- AssumeStartedOnNotEnoughMasterPing = ClusterConfiguration.NumberOfNodes > 1,
- }
- select node).ToList();
-
- var initialMasterNodes = string.Join(",", nodes.Select(n => n.NodeConfiguration.DesiredNodeName));
- foreach (var node in nodes)
- node.NodeConfiguration.InitialMasterNodes(initialMasterNodes);
-
- Nodes = new ReadOnlyCollection(nodes);
- }
-
- ///
- /// A short name to identify the cluster defaults to the subclass name with Cluster
- /// removed
- ///
- public virtual string ClusterMoniker { get; }
-
- public TConfiguration ClusterConfiguration { get; }
- public INodeFileSystem FileSystem => ClusterConfiguration.FileSystem;
-
- public ReadOnlyCollection Nodes { get; }
- public bool Started { get; private set; }
- public IConsoleLineHandler Writer { get; private set; } = NoopConsoleLineWriter.Instance;
-
- public IDisposable Start() => Start(TimeSpan.FromMinutes(2));
-
- public IDisposable Start(TimeSpan waitForStarted)
- {
- var nodes = Nodes.Select(n => n.NodeConfiguration.DesiredNodeName).ToArray();
- var lineHighlightWriter = new LineHighlightWriter(nodes, LineOutParser.OpenSearch);
- return Start(lineHighlightWriter, waitForStarted);
- }
-
- public IDisposable Start(IConsoleLineHandler writer, TimeSpan waitForStarted)
- {
- Writer = writer ?? NoopConsoleLineWriter.Instance;
-
- OnBeforeStart();
-
- var subscriptions = new Subscriptions();
-
- foreach (var node in Nodes)
- {
- subscriptions.Add(node.SubscribeLines(writer));
- if (node.WaitForStarted(waitForStarted)) continue;
-
- var nodeExceptions = Nodes.Select(n => n.LastSeenException).Where(e => e != null).ToList();
- writer?.WriteError(
- $"{{{GetType().Name}.{nameof(Start)}}} cluster did not start after {waitForStarted}");
- throw new AggregateException($"Not all nodes started after waiting {waitForStarted}", nodeExceptions);
- }
-
- Started = Nodes.All(n => n.NodeStarted);
- if (!Started)
- {
- var nodeExceptions = Nodes.Select(n => n.LastSeenException).Where(e => e != null).ToList();
- var message = $"{{{GetType().Name}.{nameof(Start)}}} cluster did not start successfully";
- var seeLogsMessage = SeeLogsMessage(message);
- writer?.WriteError(seeLogsMessage);
- throw new AggregateException(seeLogsMessage, nodeExceptions);
- }
-
- try
- {
- OnAfterStarted();
- SeedCluster();
- }
- catch (Exception e)
- {
- writer?.WriteError(e.ToString());
- throw;
- }
-
- return subscriptions;
- }
-
- public void Dispose()
- {
- Started = false;
- foreach (var node in Nodes)
- node?.Dispose();
-
- OnDispose();
- }
-
- protected virtual void ModifyNodeConfiguration(NodeConfiguration nodeConfiguration, int port)
- {
- }
-
- protected virtual void SeedCluster()
- {
- }
-
-
- protected virtual string SeeLogsMessage(string message)
- {
- var log = Path.Combine(FileSystem.LogsPath, $"{ClusterConfiguration.ClusterName}.log");
- return $"{message} see {log} to diagnose the issue";
- }
-
- public void WaitForExit(TimeSpan waitForCompletion)
- {
- foreach (var node in Nodes)
- node.WaitForCompletion(waitForCompletion);
- }
-
- protected virtual void OnAfterStarted()
- {
- }
-
- protected virtual void OnBeforeStart()
- {
- }
-
- protected virtual void OnDispose()
- {
- }
-
- private class Subscriptions : IDisposable
- {
- private List Disposables { get; } = new List();
-
- public void Dispose()
- {
- foreach (var d in Disposables) d.Dispose();
- }
-
- internal void Add(IDisposable disposable) => Disposables.Add(disposable);
- }
- }
+ private Action _defaultConfigSelector = (n, i) => { };
+
+ protected ClusterBase(TConfiguration clusterConfiguration)
+ {
+ ClusterConfiguration = clusterConfiguration;
+ ClusterMoniker = GetType().Name.Replace("Cluster", "");
+
+ NodeConfiguration Modify(NodeConfiguration n, int p)
+ {
+ ModifyNodeConfiguration(n, p);
+ return n;
+ }
+
+ var nodes =
+ (from port in Enumerable.Range(ClusterConfiguration.StartingPortNumber,
+ ClusterConfiguration.NumberOfNodes)
+ let config = new NodeConfiguration(clusterConfiguration, port, ClusterMoniker)
+ {
+ ShowOpenSearchOutputAfterStarted =
+ clusterConfiguration.ShowOpenSearchOutputAfterStarted,
+ }
+ let node = new OpenSearchNode(Modify(config, port))
+ {
+ AssumeStartedOnNotEnoughMasterPing = ClusterConfiguration.NumberOfNodes > 1,
+ }
+ select node).ToList();
+
+ var initialMasterNodes = string.Join(",", nodes.Select(n => n.NodeConfiguration.DesiredNodeName));
+ foreach (var node in nodes)
+ node.NodeConfiguration.InitialMasterNodes(initialMasterNodes);
+
+ Nodes = new ReadOnlyCollection(nodes);
+ }
+
+ ///
+ /// A short name to identify the cluster defaults to the subclass name with Cluster
+ /// removed
+ ///
+ public virtual string ClusterMoniker { get; }
+
+ public TConfiguration ClusterConfiguration { get; }
+ public INodeFileSystem FileSystem => ClusterConfiguration.FileSystem;
+
+ public ReadOnlyCollection Nodes { get; }
+ public bool Started { get; private set; }
+ public IConsoleLineHandler Writer { get; private set; } = NoopConsoleLineWriter.Instance;
+
+ public IDisposable Start() => Start(TimeSpan.FromMinutes(2));
+
+ public IDisposable Start(TimeSpan waitForStarted)
+ {
+ var nodes = Nodes.Select(n => n.NodeConfiguration.DesiredNodeName).ToArray();
+ var lineHighlightWriter = new LineHighlightWriter(nodes, LineOutParser.OpenSearch);
+ return Start(lineHighlightWriter, waitForStarted);
+ }
+
+ public IDisposable Start(IConsoleLineHandler writer, TimeSpan waitForStarted)
+ {
+ Writer = writer ?? NoopConsoleLineWriter.Instance;
+
+ OnBeforeStart();
+
+ var subscriptions = new Subscriptions();
+
+ foreach (var node in Nodes)
+ {
+ subscriptions.Add(node.SubscribeLines(writer));
+ if (node.WaitForStarted(waitForStarted)) continue;
+
+ var nodeExceptions = Nodes.Select(n => n.LastSeenException).Where(e => e != null).ToList();
+ writer?.WriteError(
+ $"{{{GetType().Name}.{nameof(Start)}}} cluster did not start after {waitForStarted}");
+ throw new AggregateException($"Not all nodes started after waiting {waitForStarted}", nodeExceptions);
+ }
+
+ Started = Nodes.All(n => n.NodeStarted);
+ if (!Started)
+ {
+ var nodeExceptions = Nodes.Select(n => n.LastSeenException).Where(e => e != null).ToList();
+ var message = $"{{{GetType().Name}.{nameof(Start)}}} cluster did not start successfully";
+ var seeLogsMessage = SeeLogsMessage(message);
+ writer?.WriteError(seeLogsMessage);
+ throw new AggregateException(seeLogsMessage, nodeExceptions);
+ }
+
+ try
+ {
+ OnAfterStarted();
+ SeedCluster();
+ }
+ catch (Exception e)
+ {
+ writer?.WriteError(e.ToString());
+ throw;
+ }
+
+ return subscriptions;
+ }
+
+ public void Dispose()
+ {
+ Started = false;
+ foreach (var node in Nodes)
+ node?.Dispose();
+
+ OnDispose();
+ }
+
+ protected virtual void ModifyNodeConfiguration(NodeConfiguration nodeConfiguration, int port)
+ {
+ }
+
+ protected virtual void SeedCluster()
+ {
+ }
+
+
+ protected virtual string SeeLogsMessage(string message)
+ {
+ var log = Path.Combine(FileSystem.LogsPath, $"{ClusterConfiguration.ClusterName}.log");
+ return $"{message} see {log} to diagnose the issue";
+ }
+
+ public void WaitForExit(TimeSpan waitForCompletion)
+ {
+ foreach (var node in Nodes)
+ node.WaitForCompletion(waitForCompletion);
+ }
+
+ protected virtual void OnAfterStarted()
+ {
+ }
+
+ protected virtual void OnBeforeStart()
+ {
+ }
+
+ protected virtual void OnDispose()
+ {
+ }
+
+ private class Subscriptions : IDisposable
+ {
+ private List Disposables { get; } = new List();
+
+ public void Dispose()
+ {
+ foreach (var d in Disposables) d.Dispose();
+ }
+
+ internal void Add(IDisposable disposable) => Disposables.Add(disposable);
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/ClusterConfiguration.cs b/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/ClusterConfiguration.cs
index e74d8bd116..0c719dab7c 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/ClusterConfiguration.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/ClusterConfiguration.cs
@@ -33,137 +33,136 @@
using OpenSearch.Stack.ArtifactsApi;
using OpenSearch.Stack.ArtifactsApi.Products;
-namespace OpenSearch.OpenSearch.Managed.Configuration
+namespace OpenSearch.OpenSearch.Managed.Configuration;
+
+public interface IClusterConfiguration where TFileSystem : INodeFileSystem
+{
+ TFileSystem FileSystem { get; }
+
+ string ClusterName { get; }
+ NodeSettings DefaultNodeSettings { get; }
+ OpenSearchVersion Version { get; }
+ int NumberOfNodes { get; }
+ int StartingPortNumber { get; set; }
+ bool NoCleanupAfterNodeStopped { get; set; }
+
+ bool ShowOpenSearchOutputAfterStarted { get; set; }
+ bool CacheOpenSearchHomeInstallation { get; set; }
+
+ string CreateNodeName(int? node);
+}
+
+public class ClusterConfiguration : ClusterConfiguration
+{
+ public ClusterConfiguration(OpenSearchVersion version, string openSearchHome, int numberOfNodes = 1)
+ : base(version, (v, s) => new NodeFileSystem(v, openSearchHome), numberOfNodes, null) { }
+
+ public ClusterConfiguration(OpenSearchVersion version, Func fileSystem = null,
+ int numberOfNodes = 1,
+ string clusterName = null
+ )
+ : base(version, fileSystem ?? ((v, s) => new NodeFileSystem(v, s)), numberOfNodes, clusterName) { }
+}
+
+public class ClusterConfiguration : IClusterConfiguration
+ where TFileSystem : INodeFileSystem
{
- public interface IClusterConfiguration where TFileSystem : INodeFileSystem
- {
- TFileSystem FileSystem { get; }
-
- string ClusterName { get; }
- NodeSettings DefaultNodeSettings { get; }
- OpenSearchVersion Version { get; }
- int NumberOfNodes { get; }
- int StartingPortNumber { get; set; }
- bool NoCleanupAfterNodeStopped { get; set; }
-
- bool ShowOpenSearchOutputAfterStarted { get; set; }
- bool CacheOpenSearchHomeInstallation { get; set; }
-
- string CreateNodeName(int? node);
- }
-
- public class ClusterConfiguration : ClusterConfiguration
- {
- public ClusterConfiguration(OpenSearchVersion version, string openSearchHome, int numberOfNodes = 1)
- : base(version, (v, s) => new NodeFileSystem(v, openSearchHome), numberOfNodes, null) { }
-
- public ClusterConfiguration(OpenSearchVersion version, Func fileSystem = null,
- int numberOfNodes = 1,
- string clusterName = null
- )
- : base(version, fileSystem ?? ((v, s) => new NodeFileSystem(v, s)), numberOfNodes, clusterName) { }
- }
-
- public class ClusterConfiguration : IClusterConfiguration
- where TFileSystem : INodeFileSystem
- {
- ///
- /// Creates a new instance of a configuration for an OpenSearch cluster.
- ///
- /// The version of OpenSearch
- ///
- /// A delegate to create the instance of .
- /// Passed the OpenSearch version and the Cluster name
- ///
- /// The number of nodes in the cluster
- /// The name of the cluster
- public ClusterConfiguration(OpenSearchVersion version, Func fileSystem,
- int numberOfNodes = 1, string clusterName = null
- )
- {
- if (fileSystem == null) throw new ArgumentException(nameof(fileSystem));
-
- ClusterName = clusterName;
- Version = version;
- Artifact = version.Artifact(Product.From("opensearch"));
- FileSystem = fileSystem(Version, ClusterName);
- NumberOfNodes = numberOfNodes;
-
- var fs = FileSystem;
- Add("node.max_local_storage_nodes", numberOfNodes.ToString(CultureInfo.InvariantCulture), "1.0.0");
-
- Add("cluster.name", clusterName);
- Add("path.repo", fs.RepositoryPath);
- Add("path.data", fs.DataPath);
- var logsPathDefault = Path.Combine(fs.OpenSearchHome, "logs");
- if (logsPathDefault != fs.LogsPath) Add("path.logs", fs.LogsPath);
- }
-
- public Artifact Artifact { get; }
-
- public string JavaHomeEnvironmentVariable => "JAVA_HOME";
-
- /// Will print the contents of all the yaml files when starting the cluster up, great for debugging purposes
- public bool PrintYamlFilesInConfigFolder { get; set; }
-
- public string ClusterName { get; }
- public OpenSearchVersion Version { get; }
- public TFileSystem FileSystem { get; }
- public int NumberOfNodes { get; }
- public int StartingPortNumber { get; set; } = 9200;
- public bool NoCleanupAfterNodeStopped { get; set; }
-
- ///
- /// Whether should continue to write output to console after it has started.
- /// Defaults to true
- ///
- public bool ShowOpenSearchOutputAfterStarted { get; set; } = true;
-
- public bool CacheOpenSearchHomeInstallation { get; set; }
-
- /// The node settings to apply to each started node
- public NodeSettings DefaultNodeSettings { get; } = new NodeSettings();
-
- ///
- /// Creates a node name
- ///
- public virtual string CreateNodeName(int? node) =>
- node.HasValue ? $"managed-opensearch-{node}" : " managed-opensearch";
-
- ///
- /// Calculates the quorum given the number of instances
- ///
- private static int Quorum(int instanceCount) => Math.Max(1, (int)Math.Floor((double)instanceCount / 2) + 1);
-
- ///
- /// Creates a node attribute for the version of OpenSearch
- ///
- public string AttributeKey(string attribute)
- {
- var attr = "attr.";
- return $"node.{attr}{attribute}";
- }
-
- ///
- /// Adds a node setting to the default node settings
- ///
- protected void Add(string key, string value)
- {
- if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)) return;
-
- DefaultNodeSettings.Add(key, value);
- }
-
- ///
- /// Adds a node setting to the default node settings only if the OpenSearch
- /// version is in the range.
- ///
- 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);
- }
- }
+ ///
+ /// Creates a new instance of a configuration for an OpenSearch cluster.
+ ///
+ /// The version of OpenSearch
+ ///
+ /// A delegate to create the instance of .
+ /// Passed the OpenSearch version and the Cluster name
+ ///
+ /// The number of nodes in the cluster
+ /// The name of the cluster
+ public ClusterConfiguration(OpenSearchVersion version, Func fileSystem,
+ int numberOfNodes = 1, string clusterName = null
+ )
+ {
+ if (fileSystem == null) throw new ArgumentException(nameof(fileSystem));
+
+ ClusterName = clusterName;
+ Version = version;
+ Artifact = version.Artifact(Product.From("opensearch"));
+ FileSystem = fileSystem(Version, ClusterName);
+ NumberOfNodes = numberOfNodes;
+
+ var fs = FileSystem;
+ Add("node.max_local_storage_nodes", numberOfNodes.ToString(CultureInfo.InvariantCulture), "1.0.0");
+
+ Add("cluster.name", clusterName);
+ Add("path.repo", fs.RepositoryPath);
+ Add("path.data", fs.DataPath);
+ var logsPathDefault = Path.Combine(fs.OpenSearchHome, "logs");
+ if (logsPathDefault != fs.LogsPath) Add("path.logs", fs.LogsPath);
+ }
+
+ public Artifact Artifact { get; }
+
+ public string JavaHomeEnvironmentVariable => "JAVA_HOME";
+
+ /// Will print the contents of all the yaml files when starting the cluster up, great for debugging purposes
+ public bool PrintYamlFilesInConfigFolder { get; set; }
+
+ public string ClusterName { get; }
+ public OpenSearchVersion Version { get; }
+ public TFileSystem FileSystem { get; }
+ public int NumberOfNodes { get; }
+ public int StartingPortNumber { get; set; } = 9200;
+ public bool NoCleanupAfterNodeStopped { get; set; }
+
+ ///
+ /// Whether should continue to write output to console after it has started.
+ /// Defaults to true
+ ///
+ public bool ShowOpenSearchOutputAfterStarted { get; set; } = true;
+
+ public bool CacheOpenSearchHomeInstallation { get; set; }
+
+ /// The node settings to apply to each started node
+ public NodeSettings DefaultNodeSettings { get; } = new NodeSettings();
+
+ ///
+ /// Creates a node name
+ ///
+ public virtual string CreateNodeName(int? node) =>
+ node.HasValue ? $"managed-opensearch-{node}" : " managed-opensearch";
+
+ ///
+ /// Calculates the quorum given the number of instances
+ ///
+ private static int Quorum(int instanceCount) => Math.Max(1, (int)Math.Floor((double)instanceCount / 2) + 1);
+
+ ///
+ /// Creates a node attribute for the version of OpenSearch
+ ///
+ public string AttributeKey(string attribute)
+ {
+ var attr = "attr.";
+ return $"node.{attr}{attribute}";
+ }
+
+ ///
+ /// Adds a node setting to the default node settings
+ ///
+ protected void Add(string key, string value)
+ {
+ if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)) return;
+
+ DefaultNodeSettings.Add(key, value);
+ }
+
+ ///
+ /// Adds a node setting to the default node settings only if the OpenSearch
+ /// version is in the range.
+ ///
+ 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);
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/NodeConfiguration.cs b/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/NodeConfiguration.cs
index 1e379e1470..27bdd36ca5 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/NodeConfiguration.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/NodeConfiguration.cs
@@ -32,77 +32,76 @@
using OpenSearch.Stack.ArtifactsApi;
using ProcNet;
-namespace OpenSearch.OpenSearch.Managed.Configuration
+namespace OpenSearch.OpenSearch.Managed.Configuration;
+
+public class NodeConfiguration
{
- public class NodeConfiguration
- {
- private Action _defaultStartArgs = s => { };
-
- public NodeConfiguration(OpenSearchVersion version, int? port = null) : this(new ClusterConfiguration(version),
- port)
- {
- }
-
- public NodeConfiguration(IClusterConfiguration clusterConfiguration, int? port = null,
- string nodePrefix = null)
- {
- ClusterConfiguration = clusterConfiguration;
- DesiredPort = port;
- DesiredNodeName = CreateNodeName(port, nodePrefix) ?? clusterConfiguration.CreateNodeName(port);
- Settings = new NodeSettings(clusterConfiguration.DefaultNodeSettings);
-
- if (!string.IsNullOrWhiteSpace(DesiredNodeName)) Settings.Add("node.name", DesiredNodeName);
- if (DesiredPort.HasValue)
- Settings.Add("http.port", DesiredPort.Value.ToString(CultureInfo.InvariantCulture));
- }
-
- private IClusterConfiguration ClusterConfiguration { get; }
-
- public int? DesiredPort { get; }
- public string DesiredNodeName { get; }
-
- public Action ModifyStartArguments
- {
- get => _defaultStartArgs;
- set => _defaultStartArgs = value ?? (s => { });
- }
-
- ///
- /// Wheter should continue to write output to console after it has started.
- /// Defaults to true but useful to turn of if it proofs to be too noisy
- ///
- public bool ShowOpenSearchOutputAfterStarted { get; set; } = true;
-
- ///
- /// The expected duration of the shut down sequence for OpenSearch. After this wait duration a hard kill will occur.
- ///
- public TimeSpan WaitForShutdown { get; set; } = TimeSpan.FromSeconds(10);
-
- ///
- /// Copy of . Add individual node settings here.
- ///
- public NodeSettings Settings { get; }
-
- public INodeFileSystem FileSystem => ClusterConfiguration.FileSystem;
- public OpenSearchVersion Version => ClusterConfiguration.Version;
- public string[] CommandLineArguments => Settings.ToCommandLineArguments(Version);
-
- public void InitialMasterNodes(string initialMasterNodes) =>
- Settings.Add("cluster.initial_master_nodes", initialMasterNodes, ">=1.0.0");
-
- public string AttributeKey(string attribute)
- {
- var attr = "attr.";
- return $"node.{attr}{attribute}";
- }
-
- public void Add(string key, string value) => Settings.Add(key, value);
-
- private string CreateNodeName(int? node, string prefix = null)
- {
- if (prefix == null) return null;
- var suffix = Guid.NewGuid().ToString("N").Substring(0, 6);
- return $"{prefix.Replace("Cluster", "").ToLowerInvariant()}-node-{suffix}{node}";
- }
- }
+ private Action _defaultStartArgs = s => { };
+
+ public NodeConfiguration(OpenSearchVersion version, int? port = null) : this(new ClusterConfiguration(version),
+ port)
+ {
+ }
+
+ public NodeConfiguration(IClusterConfiguration clusterConfiguration, int? port = null,
+ string nodePrefix = null)
+ {
+ ClusterConfiguration = clusterConfiguration;
+ DesiredPort = port;
+ DesiredNodeName = CreateNodeName(port, nodePrefix) ?? clusterConfiguration.CreateNodeName(port);
+ Settings = new NodeSettings(clusterConfiguration.DefaultNodeSettings);
+
+ if (!string.IsNullOrWhiteSpace(DesiredNodeName)) Settings.Add("node.name", DesiredNodeName);
+ if (DesiredPort.HasValue)
+ Settings.Add("http.port", DesiredPort.Value.ToString(CultureInfo.InvariantCulture));
+ }
+
+ private IClusterConfiguration ClusterConfiguration { get; }
+
+ public int? DesiredPort { get; }
+ public string DesiredNodeName { get; }
+
+ public Action ModifyStartArguments
+ {
+ get => _defaultStartArgs;
+ set => _defaultStartArgs = value ?? (s => { });
+ }
+
+ ///
+ /// Wheter should continue to write output to console after it has started.
+ /// Defaults to true but useful to turn of if it proofs to be too noisy
+ ///
+ public bool ShowOpenSearchOutputAfterStarted { get; set; } = true;
+
+ ///
+ /// The expected duration of the shut down sequence for OpenSearch. After this wait duration a hard kill will occur.
+ ///
+ public TimeSpan WaitForShutdown { get; set; } = TimeSpan.FromSeconds(10);
+
+ ///
+ /// Copy of . Add individual node settings here.
+ ///
+ public NodeSettings Settings { get; }
+
+ public INodeFileSystem FileSystem => ClusterConfiguration.FileSystem;
+ public OpenSearchVersion Version => ClusterConfiguration.Version;
+ public string[] CommandLineArguments => Settings.ToCommandLineArguments(Version);
+
+ public void InitialMasterNodes(string initialMasterNodes) =>
+ Settings.Add("cluster.initial_master_nodes", initialMasterNodes, ">=1.0.0");
+
+ public string AttributeKey(string attribute)
+ {
+ var attr = "attr.";
+ return $"node.{attr}{attribute}";
+ }
+
+ public void Add(string key, string value) => Settings.Add(key, value);
+
+ private string CreateNodeName(int? node, string prefix = null)
+ {
+ if (prefix == null) return null;
+ var suffix = Guid.NewGuid().ToString("N").Substring(0, 6);
+ return $"{prefix.Replace("Cluster", "").ToLowerInvariant()}-node-{suffix}{node}";
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/NodeSetting.cs b/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/NodeSetting.cs
index 8d2c8f40f2..8a38c13274 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/NodeSetting.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/NodeSetting.cs
@@ -26,25 +26,24 @@
* under the License.
*/
-namespace OpenSearch.OpenSearch.Managed.Configuration
+namespace OpenSearch.OpenSearch.Managed.Configuration;
+
+public struct NodeSetting
{
- public struct NodeSetting
- {
- public string Key { get; }
- public string Value { get; }
+ public string Key { get; }
+ public string Value { get; }
- ///
- /// Stores for which opensearch version range this setting is applicable
- ///
- public string VersionRange { get; }
+ ///
+ /// Stores for which opensearch version range this setting is applicable
+ ///
+ public string VersionRange { get; }
- public NodeSetting(string key, string value, string range)
- {
- Key = key;
- Value = value;
- VersionRange = range;
- }
+ public NodeSetting(string key, string value, string range)
+ {
+ Key = key;
+ Value = value;
+ VersionRange = range;
+ }
- public override string ToString() => $"{Key}={Value}";
- }
+ public override string ToString() => $"{Key}={Value}";
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/NodeSettings.cs b/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/NodeSettings.cs
index ea34663ca7..6a62456aa9 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/NodeSettings.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Managed/Configuration/NodeSettings.cs
@@ -31,40 +31,39 @@
using System.Linq;
using OpenSearch.Stack.ArtifactsApi;
-namespace OpenSearch.OpenSearch.Managed.Configuration
+namespace OpenSearch.OpenSearch.Managed.Configuration;
+
+public class NodeSettings : List
{
- public class NodeSettings : List
- {
- public NodeSettings()
- {
- }
+ public NodeSettings()
+ {
+ }
- public NodeSettings(NodeSettings settings) : base(settings)
- {
- }
+ 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 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) => Add(new NodeSetting(key, value, null));
- public void Add(string key, string value, string versionRange) =>
- Add(new NodeSetting(key, value, versionRange));
+ public void Add(string key, string value, string versionRange) =>
+ Add(new NodeSetting(key, value, versionRange));
- public string[] ToCommandLineArguments(OpenSearchVersion version) =>
- 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 opensearch to dedup
- .GroupBy(setting => setting.Key)
- .Select(g => g.Last())
- .SelectMany(s => new[] { "-E", s.ToString() })
- .ToArray();
- }
+ public string[] ToCommandLineArguments(OpenSearchVersion version) =>
+ 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 opensearch to dedup
+ .GroupBy(setting => setting.Key)
+ .Select(g => g.Last())
+ .SelectMany(s => new[] { "-E", s.ToString() })
+ .ToArray();
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/ConsoleLineWriter.cs b/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/ConsoleLineWriter.cs
index 1f8e2911e7..993a40e15d 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/ConsoleLineWriter.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/ConsoleLineWriter.cs
@@ -29,16 +29,15 @@
using System;
using ProcNet.Std;
-namespace OpenSearch.OpenSearch.Managed.ConsoleWriters
+namespace OpenSearch.OpenSearch.Managed.ConsoleWriters;
+
+public class ConsoleLineWriter : IConsoleLineHandler
{
- public class ConsoleLineWriter : IConsoleLineHandler
- {
- public void Handle(LineOut lineOut)
- {
- var w = lineOut.Error ? Console.Error : Console.Out;
- w.WriteLine(lineOut);
- }
+ public void Handle(LineOut lineOut)
+ {
+ var w = lineOut.Error ? Console.Error : Console.Out;
+ w.WriteLine(lineOut);
+ }
- public void Handle(Exception e) => Console.Error.WriteLine(e);
- }
+ public void Handle(Exception e) => Console.Error.WriteLine(e);
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/ExceptionLineParser.cs b/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/ExceptionLineParser.cs
index f54b8eb648..99c892e8a7 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/ExceptionLineParser.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/ExceptionLineParser.cs
@@ -28,38 +28,37 @@
using System.Text.RegularExpressions;
-namespace OpenSearch.OpenSearch.Managed.ConsoleWriters
+namespace OpenSearch.OpenSearch.Managed.ConsoleWriters;
+
+public static class ExceptionLineParser
{
- public static class ExceptionLineParser
- {
- private static readonly Regex CauseRegex = new Regex(@"^(?.*?Exception:)(?.*?)$");
+ private static readonly Regex CauseRegex = new Regex(@"^(?.*?Exception:)(?.*?)$");
- private static readonly Regex
- LocRegex = new Regex(@"^(?\s*?at )(?.*?)\((?.*?)\)(?.*?)$");
+ private static readonly Regex
+ LocRegex = new Regex(@"^(?\s*?at )(?.*?)\((?.*?)\)(?.*?)$");
- public static bool TryParseCause(string line, out string cause, out string message)
- {
- cause = message = null;
- if (string.IsNullOrEmpty(line)) return false;
- var match = CauseRegex.Match(line);
- if (!match.Success) return false;
- cause = match.Groups["cause"].Value.Trim();
- message = match.Groups["message"].Value.Trim();
- return true;
- }
+ public static bool TryParseCause(string line, out string cause, out string message)
+ {
+ cause = message = null;
+ if (string.IsNullOrEmpty(line)) return false;
+ var match = CauseRegex.Match(line);
+ if (!match.Success) return false;
+ cause = match.Groups["cause"].Value.Trim();
+ message = match.Groups["message"].Value.Trim();
+ return true;
+ }
- public static bool TryParseStackTrace(string line, out string at, out string method, out string file,
- out string jar)
- {
- at = method = file = jar = null;
- if (string.IsNullOrEmpty(line)) return false;
- var match = LocRegex.Match(line);
- if (!match.Success) return false;
- at = match.Groups["at"].Value;
- method = match.Groups["method"].Value.Trim();
- file = match.Groups["file"].Value.Trim();
- jar = match.Groups["jar"].Value.Trim();
- return true;
- }
- }
+ public static bool TryParseStackTrace(string line, out string at, out string method, out string file,
+ out string jar)
+ {
+ at = method = file = jar = null;
+ if (string.IsNullOrEmpty(line)) return false;
+ var match = LocRegex.Match(line);
+ if (!match.Success) return false;
+ at = match.Groups["at"].Value;
+ method = match.Groups["method"].Value.Trim();
+ file = match.Groups["file"].Value.Trim();
+ jar = match.Groups["jar"].Value.Trim();
+ return true;
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/IConsoleLineWriter.cs b/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/IConsoleLineWriter.cs
index 000c2c78b8..425b6eb416 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/IConsoleLineWriter.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/IConsoleLineWriter.cs
@@ -29,25 +29,24 @@
using System;
using ProcNet.Std;
-namespace OpenSearch.OpenSearch.Managed.ConsoleWriters
+namespace OpenSearch.OpenSearch.Managed.ConsoleWriters;
+
+public static class LineWriterExtensions
{
- public static class LineWriterExtensions
- {
- public static void WriteDiagnostic(this IConsoleLineHandler writer, string message) =>
- writer.Handle(Info(message));
+ public static void WriteDiagnostic(this IConsoleLineHandler writer, string message) =>
+ writer.Handle(Info(message));
- public static void WriteDiagnostic(this IConsoleLineHandler writer, string message, string node) =>
- writer?.Handle(Info(node != null ? $"[{node}] {message}" : message));
+ public static void WriteDiagnostic(this IConsoleLineHandler writer, string message, string node) =>
+ writer?.Handle(Info(node != null ? $"[{node}] {message}" : message));
- public static void WriteError(this IConsoleLineHandler writer, string message) => writer.Handle(Error(message));
+ public static void WriteError(this IConsoleLineHandler writer, string message) => writer.Handle(Error(message));
- public static void WriteError(this IConsoleLineHandler writer, string message, string node) =>
- writer?.Handle(Error(node != null ? $"[{node}] {message}" : message));
+ public static void WriteError(this IConsoleLineHandler writer, string message, string node) =>
+ writer?.Handle(Error(node != null ? $"[{node}] {message}" : message));
- private static string Format(bool error, string message) =>
- $"[{DateTime.UtcNow:yyyy-MM-ddThh:mm:ss,fff}][{(error ? "ERROR" : "INFO ")}][Managed OpenSearch\t] {message}";
+ private static string Format(bool error, string message) =>
+ $"[{DateTime.UtcNow:yyyy-MM-ddThh:mm:ss,fff}][{(error ? "ERROR" : "INFO ")}][Managed OpenSearch\t] {message}";
- private static LineOut Info(string message) => ConsoleOut.Out(Format(false, message));
- private static LineOut Error(string message) => ConsoleOut.ErrorOut(Format(true, message));
- }
+ private static LineOut Info(string message) => ConsoleOut.Out(Format(false, message));
+ private static LineOut Error(string message) => ConsoleOut.ErrorOut(Format(true, message));
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/LineHighlightWriter.cs b/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/LineHighlightWriter.cs
index 53e3ab08b7..c4a22266b9 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/LineHighlightWriter.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/LineHighlightWriter.cs
@@ -32,220 +32,219 @@
using System.Linq;
using ProcNet.Std;
-namespace OpenSearch.OpenSearch.Managed.ConsoleWriters
+namespace OpenSearch.OpenSearch.Managed.ConsoleWriters;
+
+public class LineHighlightWriter : IConsoleLineHandler
{
- public class LineHighlightWriter : IConsoleLineHandler
- {
- private readonly LineOutParser _lineOutParser;
-
- private static readonly ConsoleColor[] AvailableNodeColors =
- {
- ConsoleColor.DarkGreen, ConsoleColor.DarkBlue, ConsoleColor.DarkRed, ConsoleColor.DarkCyan,
- ConsoleColor.DarkYellow, ConsoleColor.Blue,
- };
-
- private static readonly object Lock = new object();
-
- private static readonly char[] Anchors = {'[', ']', '{', '}'};
-
- private readonly Dictionary _nodeColors;
-
- public LineHighlightWriter()
- {
- }
-
- public LineHighlightWriter(IList nodes, LineOutParser lineOutParser)
- {
- _lineOutParser = lineOutParser ?? throw new NullReferenceException(nameof(lineOutParser));
- if (nodes == null) throw new NullReferenceException(nameof(nodes));
-
- var colors = new Dictionary();
- for (var i = 0; i < nodes.Count; i++)
- {
- var color = i % AvailableNodeColors.Length;
- colors.Add(nodes[i], AvailableNodeColors[color]);
- }
-
- _nodeColors = colors;
- }
-
- public void Handle(Exception e)
- {
- lock (Lock)
- {
- Console.BackgroundColor = ConsoleColor.Red;
- Console.ForegroundColor = ConsoleColor.White;
- Console.Error.WriteLine(e);
- Console.ResetColor();
- }
- }
-
- public void Handle(LineOut lineOut)
- {
- var parsed = _lineOutParser.TryParse(lineOut.Line, out var date, out var level, out var section,
- out var node, out var message, out _);
- if (parsed) Write(lineOut.Error, date, level, section, node, message, NodeColor);
- else if (ExceptionLineParser.TryParseCause(lineOut.Line, out var cause, out var causeMessage))
- WriteCausedBy(lineOut.Error, cause, causeMessage);
-
- else if (ExceptionLineParser.TryParseStackTrace(lineOut.Line, out var at, out var method, out var file,
- out var jar))
- WriteStackTraceLine(lineOut.Error, at, method, file, jar);
-
- else Write(lineOut.Error, lineOut.Line);
- }
-
- private ConsoleColor NodeColor(string node) =>
- _nodeColors != null && _nodeColors.TryGetValue(node, out var color) ? color : AvailableNodeColors[0];
-
- private static void Write(bool error, string date, string level, string section, string node, string message,
- Func getNodeColor = null)
- {
- lock (Lock)
- {
- var w = error ? Console.Error : Console.Out;
- WriteBlock(w, ConsoleColor.DarkGray, date);
- WriteBlock(w, LevelColor(level), level, 5);
-
- if (!string.IsNullOrWhiteSpace(section))
- {
- WriteBlock(w, ConsoleColor.DarkCyan, section, 25);
- WriteSpace(w);
- }
-
- WriteBlock(w, getNodeColor?.Invoke(node) ?? ConsoleColor.DarkGreen, node);
- WriteSpace(w);
-
- var messageColor = error || level == "ERROR" ? ConsoleColor.Red : ConsoleColor.White;
- WriteMessage(w, messageColor, message);
-
- Console.ResetColor();
- w.Flush();
- }
- }
-
- private static void WriteCausedBy(bool error, string cause, string causeMessage)
- {
- lock (Lock)
- {
- var w = error ? Console.Error : Console.Out;
- Write(w, ConsoleColor.DarkRed, cause);
- WriteSpace(w);
- Write(w, ConsoleColor.Red, causeMessage);
- w.WriteLine();
- Console.ResetColor();
- w.Flush();
- }
- }
-
- private static void WriteStackTraceLine(bool error, string at, string method, string file, string jar)
- {
- lock (Lock)
- {
- var w = error ? Console.Error : Console.Out;
- Write(w, ConsoleColor.DarkGray, at);
- Write(w, ConsoleColor.DarkBlue, method);
- Write(w, ConsoleColor.DarkGray, "(");
- Write(w, ConsoleColor.Blue, file);
- Write(w, ConsoleColor.DarkGray, ")");
- WriteSpace(w);
- Write(w, ConsoleColor.Gray, jar);
- w.WriteLine();
-
- Console.ResetColor();
- w.Flush();
- }
- }
-
- private static void Write(bool error, string message)
- {
- lock (Lock)
- {
- var w = error ? Console.Error : Console.Out;
- var messageColor = error ? ConsoleColor.Red : ConsoleColor.White;
- WriteMessage(w, messageColor, message);
- Console.ResetColor();
- w.Flush();
- }
- }
-
- private static ConsoleColor LevelColor(string level)
- {
- switch (level ?? "")
- {
- case "WARN": return ConsoleColor.Yellow;
- case "FATAL":
- case "ERROR":
- return ConsoleColor.Red;
- case "DEBUG":
- case "TRACE":
- return ConsoleColor.DarkGray;
- default:
- return ConsoleColor.Cyan;
- }
- }
-
- private static IEnumerable Parts(string s)
- {
- int start = 0, index;
- while ((index = s.IndexOfAny(Anchors, start)) != -1)
- {
- if (index - start > 0)
- yield return s.Substring(start, index - start);
-
- yield return s.Substring(index, 1);
- start = index + 1;
- }
-
- if (start < s.Length)
- yield return s.Substring(start);
- }
-
- private static void WriteMessage(TextWriter w, ConsoleColor color, string message)
- {
- var insideSquareBracket = 0;
- var insideCurlyBracket = 0;
- foreach (var p in Parts(message))
- {
- if (p.Length == 0) continue;
- if (p[0] == '[') insideSquareBracket++;
- else if (p[0] == ']') insideSquareBracket--;
- else if (p[0] == '{') insideCurlyBracket++;
- else if (p[0] == '}') insideCurlyBracket--;
-
- if (Anchors.Contains(p[0])) Console.ForegroundColor = ConsoleColor.DarkGray;
- else if (insideSquareBracket > 0) Console.ForegroundColor = ConsoleColor.Yellow;
- else if (insideCurlyBracket > 0) Console.ForegroundColor = ConsoleColor.Blue;
- else Console.ForegroundColor = color;
-
- w.Write(p);
- }
-
- Console.ResetColor();
- w.WriteLine();
- }
-
- private static void WriteSpace(TextWriter w) => w.Write(" ");
-
- private static void WriteBlock(TextWriter w, ConsoleColor color, string block, int? pad = null)
- {
- if (string.IsNullOrEmpty(block)) return;
- var b = pad != null ? block.PadRight(pad.Value) : block;
- Console.ForegroundColor = ConsoleColor.DarkGray;
- w.Write("[");
- Console.ForegroundColor = color;
- w.Write(b);
- Console.ForegroundColor = ConsoleColor.DarkGray;
- w.Write("]");
- }
-
- private static void Write(TextWriter w, ConsoleColor color, string block, int? pad = null)
- {
- var b = pad != null ? block.PadRight(pad.Value) : block;
- var original = Console.ForegroundColor;
- Console.ForegroundColor = color;
- w.Write(b);
- Console.ForegroundColor = original;
- }
- }
+ private readonly LineOutParser _lineOutParser;
+
+ private static readonly ConsoleColor[] AvailableNodeColors =
+ {
+ ConsoleColor.DarkGreen, ConsoleColor.DarkBlue, ConsoleColor.DarkRed, ConsoleColor.DarkCyan,
+ ConsoleColor.DarkYellow, ConsoleColor.Blue,
+ };
+
+ private static readonly object Lock = new object();
+
+ private static readonly char[] Anchors = { '[', ']', '{', '}' };
+
+ private readonly Dictionary _nodeColors;
+
+ public LineHighlightWriter()
+ {
+ }
+
+ public LineHighlightWriter(IList nodes, LineOutParser lineOutParser)
+ {
+ _lineOutParser = lineOutParser ?? throw new NullReferenceException(nameof(lineOutParser));
+ if (nodes == null) throw new NullReferenceException(nameof(nodes));
+
+ var colors = new Dictionary();
+ for (var i = 0; i < nodes.Count; i++)
+ {
+ var color = i % AvailableNodeColors.Length;
+ colors.Add(nodes[i], AvailableNodeColors[color]);
+ }
+
+ _nodeColors = colors;
+ }
+
+ public void Handle(Exception e)
+ {
+ lock (Lock)
+ {
+ Console.BackgroundColor = ConsoleColor.Red;
+ Console.ForegroundColor = ConsoleColor.White;
+ Console.Error.WriteLine(e);
+ Console.ResetColor();
+ }
+ }
+
+ public void Handle(LineOut lineOut)
+ {
+ var parsed = _lineOutParser.TryParse(lineOut.Line, out var date, out var level, out var section,
+ out var node, out var message, out _);
+ if (parsed) Write(lineOut.Error, date, level, section, node, message, NodeColor);
+ else if (ExceptionLineParser.TryParseCause(lineOut.Line, out var cause, out var causeMessage))
+ WriteCausedBy(lineOut.Error, cause, causeMessage);
+
+ else if (ExceptionLineParser.TryParseStackTrace(lineOut.Line, out var at, out var method, out var file,
+ out var jar))
+ WriteStackTraceLine(lineOut.Error, at, method, file, jar);
+
+ else Write(lineOut.Error, lineOut.Line);
+ }
+
+ private ConsoleColor NodeColor(string node) =>
+ _nodeColors != null && _nodeColors.TryGetValue(node, out var color) ? color : AvailableNodeColors[0];
+
+ private static void Write(bool error, string date, string level, string section, string node, string message,
+ Func getNodeColor = null)
+ {
+ lock (Lock)
+ {
+ var w = error ? Console.Error : Console.Out;
+ WriteBlock(w, ConsoleColor.DarkGray, date);
+ WriteBlock(w, LevelColor(level), level, 5);
+
+ if (!string.IsNullOrWhiteSpace(section))
+ {
+ WriteBlock(w, ConsoleColor.DarkCyan, section, 25);
+ WriteSpace(w);
+ }
+
+ WriteBlock(w, getNodeColor?.Invoke(node) ?? ConsoleColor.DarkGreen, node);
+ WriteSpace(w);
+
+ var messageColor = error || level == "ERROR" ? ConsoleColor.Red : ConsoleColor.White;
+ WriteMessage(w, messageColor, message);
+
+ Console.ResetColor();
+ w.Flush();
+ }
+ }
+
+ private static void WriteCausedBy(bool error, string cause, string causeMessage)
+ {
+ lock (Lock)
+ {
+ var w = error ? Console.Error : Console.Out;
+ Write(w, ConsoleColor.DarkRed, cause);
+ WriteSpace(w);
+ Write(w, ConsoleColor.Red, causeMessage);
+ w.WriteLine();
+ Console.ResetColor();
+ w.Flush();
+ }
+ }
+
+ private static void WriteStackTraceLine(bool error, string at, string method, string file, string jar)
+ {
+ lock (Lock)
+ {
+ var w = error ? Console.Error : Console.Out;
+ Write(w, ConsoleColor.DarkGray, at);
+ Write(w, ConsoleColor.DarkBlue, method);
+ Write(w, ConsoleColor.DarkGray, "(");
+ Write(w, ConsoleColor.Blue, file);
+ Write(w, ConsoleColor.DarkGray, ")");
+ WriteSpace(w);
+ Write(w, ConsoleColor.Gray, jar);
+ w.WriteLine();
+
+ Console.ResetColor();
+ w.Flush();
+ }
+ }
+
+ private static void Write(bool error, string message)
+ {
+ lock (Lock)
+ {
+ var w = error ? Console.Error : Console.Out;
+ var messageColor = error ? ConsoleColor.Red : ConsoleColor.White;
+ WriteMessage(w, messageColor, message);
+ Console.ResetColor();
+ w.Flush();
+ }
+ }
+
+ private static ConsoleColor LevelColor(string level)
+ {
+ switch (level ?? "")
+ {
+ case "WARN": return ConsoleColor.Yellow;
+ case "FATAL":
+ case "ERROR":
+ return ConsoleColor.Red;
+ case "DEBUG":
+ case "TRACE":
+ return ConsoleColor.DarkGray;
+ default:
+ return ConsoleColor.Cyan;
+ }
+ }
+
+ private static IEnumerable Parts(string s)
+ {
+ int start = 0, index;
+ while ((index = s.IndexOfAny(Anchors, start)) != -1)
+ {
+ if (index - start > 0)
+ yield return s.Substring(start, index - start);
+
+ yield return s.Substring(index, 1);
+ start = index + 1;
+ }
+
+ if (start < s.Length)
+ yield return s.Substring(start);
+ }
+
+ private static void WriteMessage(TextWriter w, ConsoleColor color, string message)
+ {
+ var insideSquareBracket = 0;
+ var insideCurlyBracket = 0;
+ foreach (var p in Parts(message))
+ {
+ if (p.Length == 0) continue;
+ if (p[0] == '[') insideSquareBracket++;
+ else if (p[0] == ']') insideSquareBracket--;
+ else if (p[0] == '{') insideCurlyBracket++;
+ else if (p[0] == '}') insideCurlyBracket--;
+
+ if (Anchors.Contains(p[0])) Console.ForegroundColor = ConsoleColor.DarkGray;
+ else if (insideSquareBracket > 0) Console.ForegroundColor = ConsoleColor.Yellow;
+ else if (insideCurlyBracket > 0) Console.ForegroundColor = ConsoleColor.Blue;
+ else Console.ForegroundColor = color;
+
+ w.Write(p);
+ }
+
+ Console.ResetColor();
+ w.WriteLine();
+ }
+
+ private static void WriteSpace(TextWriter w) => w.Write(" ");
+
+ private static void WriteBlock(TextWriter w, ConsoleColor color, string block, int? pad = null)
+ {
+ if (string.IsNullOrEmpty(block)) return;
+ var b = pad != null ? block.PadRight(pad.Value) : block;
+ Console.ForegroundColor = ConsoleColor.DarkGray;
+ w.Write("[");
+ Console.ForegroundColor = color;
+ w.Write(b);
+ Console.ForegroundColor = ConsoleColor.DarkGray;
+ w.Write("]");
+ }
+
+ private static void Write(TextWriter w, ConsoleColor color, string block, int? pad = null)
+ {
+ var b = pad != null ? block.PadRight(pad.Value) : block;
+ var original = Console.ForegroundColor;
+ Console.ForegroundColor = color;
+ w.Write(b);
+ Console.ForegroundColor = original;
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/LineOutParser.cs b/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/LineOutParser.cs
index 1acfc8c6a0..f49ff2f8a0 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/LineOutParser.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/LineOutParser.cs
@@ -30,116 +30,115 @@
using System.Text.RegularExpressions;
using OpenSearch.Stack.ArtifactsApi;
-namespace OpenSearch.OpenSearch.Managed.ConsoleWriters
-{
- public class LineOutParser
- {
- private LineOutParser() { }
-
- public static readonly LineOutParser OpenSearch = new(shortNamePrefix: "o.o", fullNamePrefix: "org.opensearch",
- securityPluginName: "OpenSearchSecurityPlugin");
+namespace OpenSearch.OpenSearch.Managed.ConsoleWriters;
-/*
-[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]
-[2016-09-26T11:43:17,471][INFO ][o.e.e.NodeEnvironment ] [readonly-node-a9c5f4] heap size [1.9gb], compressed ordinary object pointers [true]
-[2016-09-26T11:43:17,475][INFO ][o.e.n.Node ] [readonly-node-a9c5f4] version[5.0.0-beta1], pid[13172], build[7eb6260/2016-09-20T23:10:37.942Z], OS[Windows 10/10.0/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_101/25.101-b13]
-[2016-09-26T11:43:19,160][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [aggs-matrix-stats]
-[2016-09-26T11:43:19,160][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [ingest-common]
-[2016-09-26T11:43:19,161][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [lang-expression]
-[2016-09-26T11:43:19,161][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [lang-groovy]
-[2016-09-26T11:43:19,161][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [lang-mustache]
-[2016-09-26T11:43:19,162][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [lang-painless]
-[2016-09-26T11:43:19,162][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [percolator]
-[2016-09-26T11:43:19,162][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [reindex]
-[2016-09-26T11:43:19,162][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [transport-netty3]
-[2016-09-26T11:43:19,163][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [transport-netty4]
-[2016-09-26T11:43:19,163][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded plugin [ingest-attachment]
-[2016-09-26T11:43:19,164][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded plugin [ingest-geoip]
-[2016-09-26T11:43:19,164][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded plugin [mapper-attachments]
-[2016-09-26T11:43:19,164][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded plugin [mapper-murmur3]
-[2016-09-26T11:43:19,374][WARN ][d.m.attachment ] [mapper-attachments] plugin has been deprecated and will be replaced by [ingest-attachment] plugin.
-[2016-09-26T11:43:22,179][INFO ][o.e.n.Node ] [readonly-node-a9c5f4] initialized
-[2016-09-26T11:43:22,180][INFO ][o.e.n.Node ] [readonly-node-a9c5f4] starting ...
-*/
- private static readonly Regex ConsoleLineParser =
- new Regex(@"\[(?.*?)\]\[(?.*?)\](?:\[(?.*?)\])(?: \[(?.*?)\])? (?.+)");
-
- private static readonly Regex PortParser = new Regex(@"bound_address(es)?(opensearch)? {.+\:(?\d+)}");
-
- //[2016-09-26T11:43:17,475][INFO ][o.e.n.Node ] [readonly-node-a9c5f4] version[5.0.0-beta1], pid[13172], build[7eb6260/2016-09-20T23:10:37.942Z], OS[Windows 10/10.0/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_101/25.101-b13]
- private static readonly Regex InfoParser =
- new Regex(@"version\[(?.*)\], pid\[(?.*)\], build\[(?.+)\]");
-
- private LineOutParser(string shortNamePrefix, string fullNamePrefix, string securityPluginName) : this()
- {
- _shortNamePrefix = shortNamePrefix;
- _fullNamePrefix = fullNamePrefix;
- _securityPluginRegex = new Regex(Regex.Escape(securityPluginName));
- }
-
- private readonly Regex _securityPluginRegex;
- private readonly string _shortNamePrefix;
- private readonly string _fullNamePrefix ;
-
- public bool TryParse(string line,
- out string date, out string level, out string section, out string node, out string message,
- out bool started)
- {
- date = level = section = node = message = null;
- started = false;
- if (string.IsNullOrEmpty(line)) return false;
-
- var match = ConsoleLineParser.Match(line);
- if (!match.Success) return false;
- date = match.Groups["date"].Value.Trim();
- level = match.Groups["level"].Value.Trim();
- section = match.Groups["section"].Value.Trim().Replace(_fullNamePrefix + ".", "");
- node = match.Groups["node"].Value.Trim();
- message = match.Groups["message"].Value.Trim();
- started = TryGetStartedConfirmation(section, message);
- return true;
- }
-
- private bool TryGetStartedConfirmation(string section, string message) => section == ShortName("n.Node") && message == "started";
-
- public bool TryGetPortNumber(string section, string message, out int port)
- {
- port = 0;
- var inHttpSection =
- section == ShortName("h.HttpServer")
- || section == "http"
- || section == ShortName("h.AbstractHttpServerTransport")
- || section == ShortName("h.n.Netty4HttpServerTransport")
- || section == ShortName("x.s.t.n.SecurityNetty4HttpServerTransport");
- if (!inHttpSection) return false;
-
- if (string.IsNullOrWhiteSpace(message)) return false;
-
- var match = PortParser.Match(message);
- if (!match.Success) return false;
-
- var portString = match.Groups["port"].Value.Trim();
- port = int.Parse(portString);
- return true;
- }
-
- public bool TryParseNodeInfo(string section, string message, out string version, out int? pid)
- {
- var inNodeSection = section == ShortName("n.Node") || section == "node";
-
- version = null;
- pid = null;
- if (!inNodeSection) return false;
-
- var match = InfoParser.Match(message.Replace(Environment.NewLine, ""));
- if (!match.Success) return false;
-
- version = match.Groups["version"].Value.Trim();
- pid = int.Parse(match.Groups["pid"].Value.Trim());
- return true;
- }
-
- private string ShortName(string suffix) => $"{_shortNamePrefix}.{suffix}";
- }
+public class LineOutParser
+{
+ private LineOutParser() { }
+
+ public static readonly LineOutParser OpenSearch = new(shortNamePrefix: "o.o", fullNamePrefix: "org.opensearch",
+ securityPluginName: "OpenSearchSecurityPlugin");
+
+ /*
+ [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]
+ [2016-09-26T11:43:17,471][INFO ][o.e.e.NodeEnvironment ] [readonly-node-a9c5f4] heap size [1.9gb], compressed ordinary object pointers [true]
+ [2016-09-26T11:43:17,475][INFO ][o.e.n.Node ] [readonly-node-a9c5f4] version[5.0.0-beta1], pid[13172], build[7eb6260/2016-09-20T23:10:37.942Z], OS[Windows 10/10.0/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_101/25.101-b13]
+ [2016-09-26T11:43:19,160][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [aggs-matrix-stats]
+ [2016-09-26T11:43:19,160][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [ingest-common]
+ [2016-09-26T11:43:19,161][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [lang-expression]
+ [2016-09-26T11:43:19,161][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [lang-groovy]
+ [2016-09-26T11:43:19,161][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [lang-mustache]
+ [2016-09-26T11:43:19,162][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [lang-painless]
+ [2016-09-26T11:43:19,162][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [percolator]
+ [2016-09-26T11:43:19,162][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [reindex]
+ [2016-09-26T11:43:19,162][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [transport-netty3]
+ [2016-09-26T11:43:19,163][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded module [transport-netty4]
+ [2016-09-26T11:43:19,163][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded plugin [ingest-attachment]
+ [2016-09-26T11:43:19,164][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded plugin [ingest-geoip]
+ [2016-09-26T11:43:19,164][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded plugin [mapper-attachments]
+ [2016-09-26T11:43:19,164][INFO ][o.e.p.PluginsService ] [readonly-node-a9c5f4] loaded plugin [mapper-murmur3]
+ [2016-09-26T11:43:19,374][WARN ][d.m.attachment ] [mapper-attachments] plugin has been deprecated and will be replaced by [ingest-attachment] plugin.
+ [2016-09-26T11:43:22,179][INFO ][o.e.n.Node ] [readonly-node-a9c5f4] initialized
+ [2016-09-26T11:43:22,180][INFO ][o.e.n.Node ] [readonly-node-a9c5f4] starting ...
+ */
+ private static readonly Regex ConsoleLineParser =
+ new Regex(@"\[(?.*?)\]\[(?.*?)\](?:\[(?.*?)\])(?: \[(?.*?)\])? (?.+)");
+
+ private static readonly Regex PortParser = new Regex(@"bound_address(es)?(opensearch)? {.+\:(?\d+)}");
+
+ //[2016-09-26T11:43:17,475][INFO ][o.e.n.Node ] [readonly-node-a9c5f4] version[5.0.0-beta1], pid[13172], build[7eb6260/2016-09-20T23:10:37.942Z], OS[Windows 10/10.0/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_101/25.101-b13]
+ private static readonly Regex InfoParser =
+ new Regex(@"version\[(?.*)\], pid\[(?.*)\], build\[(?.+)\]");
+
+ private LineOutParser(string shortNamePrefix, string fullNamePrefix, string securityPluginName) : this()
+ {
+ _shortNamePrefix = shortNamePrefix;
+ _fullNamePrefix = fullNamePrefix;
+ _securityPluginRegex = new Regex(Regex.Escape(securityPluginName));
+ }
+
+ private readonly Regex _securityPluginRegex;
+ private readonly string _shortNamePrefix;
+ private readonly string _fullNamePrefix;
+
+ public bool TryParse(string line,
+ out string date, out string level, out string section, out string node, out string message,
+ out bool started)
+ {
+ date = level = section = node = message = null;
+ started = false;
+ if (string.IsNullOrEmpty(line)) return false;
+
+ var match = ConsoleLineParser.Match(line);
+ if (!match.Success) return false;
+ date = match.Groups["date"].Value.Trim();
+ level = match.Groups["level"].Value.Trim();
+ section = match.Groups["section"].Value.Trim().Replace(_fullNamePrefix + ".", "");
+ node = match.Groups["node"].Value.Trim();
+ message = match.Groups["message"].Value.Trim();
+ started = TryGetStartedConfirmation(section, message);
+ return true;
+ }
+
+ private bool TryGetStartedConfirmation(string section, string message) => section == ShortName("n.Node") && message == "started";
+
+ public bool TryGetPortNumber(string section, string message, out int port)
+ {
+ port = 0;
+ var inHttpSection =
+ section == ShortName("h.HttpServer")
+ || section == "http"
+ || section == ShortName("h.AbstractHttpServerTransport")
+ || section == ShortName("h.n.Netty4HttpServerTransport")
+ || section == ShortName("x.s.t.n.SecurityNetty4HttpServerTransport");
+ if (!inHttpSection) return false;
+
+ if (string.IsNullOrWhiteSpace(message)) return false;
+
+ var match = PortParser.Match(message);
+ if (!match.Success) return false;
+
+ var portString = match.Groups["port"].Value.Trim();
+ port = int.Parse(portString);
+ return true;
+ }
+
+ public bool TryParseNodeInfo(string section, string message, out string version, out int? pid)
+ {
+ var inNodeSection = section == ShortName("n.Node") || section == "node";
+
+ version = null;
+ pid = null;
+ if (!inNodeSection) return false;
+
+ var match = InfoParser.Match(message.Replace(Environment.NewLine, ""));
+ if (!match.Success) return false;
+
+ version = match.Groups["version"].Value.Trim();
+ pid = int.Parse(match.Groups["pid"].Value.Trim());
+ return true;
+ }
+
+ private string ShortName(string suffix) => $"{_shortNamePrefix}.{suffix}";
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/NoopConsoleLineWriter.cs b/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/NoopConsoleLineWriter.cs
index e8e24c3900..55347aedc0 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/NoopConsoleLineWriter.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Managed/ConsoleWriters/NoopConsoleLineWriter.cs
@@ -29,18 +29,17 @@
using System;
using ProcNet.Std;
-namespace OpenSearch.OpenSearch.Managed.ConsoleWriters
+namespace OpenSearch.OpenSearch.Managed.ConsoleWriters;
+
+internal class NoopConsoleLineWriter : IConsoleLineHandler
{
- internal class NoopConsoleLineWriter : IConsoleLineHandler
- {
- public static NoopConsoleLineWriter Instance { get; } = new NoopConsoleLineWriter();
+ public static NoopConsoleLineWriter Instance { get; } = new NoopConsoleLineWriter();
- public void Handle(LineOut lineOut)
- {
- }
+ public void Handle(LineOut lineOut)
+ {
+ }
- public void Handle(Exception e)
- {
- }
- }
+ public void Handle(Exception e)
+ {
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Managed/FileSystem/INodeFileSystem.cs b/abstractions/src/OpenSearch.OpenSearch.Managed/FileSystem/INodeFileSystem.cs
index ff71128c20..e3f7a955f1 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Managed/FileSystem/INodeFileSystem.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Managed/FileSystem/INodeFileSystem.cs
@@ -26,54 +26,53 @@
* under the License.
*/
-namespace OpenSearch.OpenSearch.Managed.FileSystem
+namespace OpenSearch.OpenSearch.Managed.FileSystem;
+
+///
+/// The file system for an OpenSearch node
+///
+public interface INodeFileSystem
{
- ///
- /// The file system for an OpenSearch node
- ///
- public interface INodeFileSystem
- {
- ///
- /// The path to the script to start OpenSearch
- ///
- string Binary { get; }
+ ///
+ /// The path to the script to start OpenSearch
+ ///
+ string Binary { get; }
- ///
- /// The path to the script to manage plugins
- ///
- string PluginBinary { get; }
+ ///
+ /// The path to the script to manage plugins
+ ///
+ string PluginBinary { get; }
- ///
- /// The path to the home directory
- ///
- string OpenSearchHome { get; }
+ ///
+ /// The path to the home directory
+ ///
+ string OpenSearchHome { get; }
- ///
- /// The path to the config directory
- ///
- string ConfigPath { get; }
+ ///
+ /// The path to the config directory
+ ///
+ string ConfigPath { get; }
- ///
- /// The path to the data directory
- ///
- string DataPath { get; }
+ ///
+ /// The path to the data directory
+ ///
+ string DataPath { get; }
- ///
- /// The path to the logs directory
- ///
- string LogsPath { get; }
+ ///
+ /// The path to the logs directory
+ ///
+ string LogsPath { get; }
- ///
- /// The path to the repository directory
- ///
- string RepositoryPath { get; }
+ ///
+ /// The path to the repository directory
+ ///
+ string RepositoryPath { get; }
- ///
- /// The path to the directory in which this node resides
- ///
- string LocalFolder { get; }
+ ///
+ /// The path to the directory in which this node resides
+ ///
+ string LocalFolder { get; }
- /// The config environment variable to use for this version
- string ConfigEnvironmentVariableName { get; }
- }
+ /// The config environment variable to use for this version
+ string ConfigEnvironmentVariableName { get; }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Managed/FileSystem/NodeFileSystem.cs b/abstractions/src/OpenSearch.OpenSearch.Managed/FileSystem/NodeFileSystem.cs
index 8a1c091bfb..e49ff3a851 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Managed/FileSystem/NodeFileSystem.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Managed/FileSystem/NodeFileSystem.cs
@@ -32,69 +32,68 @@
using OpenSearch.Stack.ArtifactsApi;
using OpenSearch.Stack.ArtifactsApi.Products;
-namespace OpenSearch.OpenSearch.Managed.FileSystem
+namespace OpenSearch.OpenSearch.Managed.FileSystem;
+
+///
+public class NodeFileSystem : INodeFileSystem
{
- ///
- public class NodeFileSystem : INodeFileSystem
- {
- protected const string SubFolder = "OpenSearchManaged";
+ protected const string SubFolder = "OpenSearchManaged";
- public NodeFileSystem(OpenSearchVersion version, string openSearchHome = null)
- {
- Version = version;
- Artifact = version.Artifact(Product.OpenSearch);
- LocalFolder = AppDataFolder(version);
- OpenSearchHome = openSearchHome ??
- GetOpenSearchHomeVariable() ?? throw new ArgumentNullException(nameof(openSearchHome));
+ public NodeFileSystem(OpenSearchVersion version, string openSearchHome = null)
+ {
+ Version = version;
+ Artifact = version.Artifact(Product.OpenSearch);
+ LocalFolder = AppDataFolder(version);
+ OpenSearchHome = openSearchHome ??
+ GetOpenSearchHomeVariable() ?? throw new ArgumentNullException(nameof(openSearchHome));
- ConfigEnvironmentVariableName = "OPENSEARCH_PATH_CONF";
- }
+ ConfigEnvironmentVariableName = "OPENSEARCH_PATH_CONF";
+ }
- protected OpenSearchVersion Version { get; }
- protected Artifact Artifact { get; }
+ protected OpenSearchVersion Version { get; }
+ protected Artifact Artifact { get; }
- private static bool IsMono { get; } = Type.GetType("Mono.Runtime") != null;
+ private static bool IsMono { get; } = Type.GetType("Mono.Runtime") != null;
- protected static string BinarySuffix => IsMono || Path.DirectorySeparatorChar == '/' ? "" : ".bat";
+ protected static string BinarySuffix => IsMono || Path.DirectorySeparatorChar == '/' ? "" : ".bat";
- ///
- public string Binary => Path.Combine(OpenSearchHome, "bin", "opensearch") + BinarySuffix;
+ ///
+ public string Binary => Path.Combine(OpenSearchHome, "bin", "opensearch") + BinarySuffix;
- ///
- public string PluginBinary => Path.Combine(OpenSearchHome, "bin", "opensearch-plugin") + BinarySuffix;
+ ///
+ public string PluginBinary => Path.Combine(OpenSearchHome, "bin", "opensearch-plugin") + BinarySuffix;
- ///
- public string OpenSearchHome { get; }
+ ///
+ public string OpenSearchHome { get; }
- ///
- public string LocalFolder { get; }
+ ///
+ public string LocalFolder { get; }
- ///
- public virtual string ConfigPath => null;
+ ///
+ public virtual string ConfigPath => null;
- ///
- public virtual string DataPath => null;
+ ///
+ public virtual string DataPath => null;
- ///
- public virtual string LogsPath => null;
+ ///
+ public virtual string LogsPath => null;
- ///
- public virtual string RepositoryPath => null;
+ ///
+ public virtual string RepositoryPath => null;
- public string ConfigEnvironmentVariableName { get; }
+ public string ConfigEnvironmentVariableName { get; }
- protected static string AppDataFolder(OpenSearchVersion version)
- {
- var appData = GetApplicationDataDirectory();
- return Path.Combine(appData, SubFolder, version.Artifact(Product.OpenSearch).LocalFolderName);
- }
+ protected static string AppDataFolder(OpenSearchVersion version)
+ {
+ var appData = GetApplicationDataDirectory();
+ return Path.Combine(appData, SubFolder, version.Artifact(Product.OpenSearch).LocalFolderName);
+ }
- protected static string GetOpenSearchHomeVariable() => Environment.GetEnvironmentVariable("OPENSEARCH_HOME");
+ protected static string GetOpenSearchHomeVariable() => Environment.GetEnvironmentVariable("OPENSEARCH_HOME");
- protected static string GetApplicationDataDirectory() =>
- RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
- ? Environment.GetEnvironmentVariable("LocalAppData")
- : Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData,
- Environment.SpecialFolderOption.Create);
- }
+ protected static string GetApplicationDataDirectory() =>
+ RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
+ ? Environment.GetEnvironmentVariable("LocalAppData")
+ : Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData,
+ Environment.SpecialFolderOption.Create);
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Managed/OpenSearchCleanExitException.cs b/abstractions/src/OpenSearch.OpenSearch.Managed/OpenSearchCleanExitException.cs
index 4200fa39d5..05f415d703 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Managed/OpenSearchCleanExitException.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Managed/OpenSearchCleanExitException.cs
@@ -28,16 +28,15 @@
using System;
-namespace OpenSearch.OpenSearch.Managed
+namespace OpenSearch.OpenSearch.Managed;
+
+public class OpenSearchCleanExitException : Exception
{
- public class OpenSearchCleanExitException : Exception
- {
- public OpenSearchCleanExitException(string message) : base(message)
- {
- }
+ public OpenSearchCleanExitException(string message) : base(message)
+ {
+ }
- public OpenSearchCleanExitException(string message, Exception innerException) : base(message, innerException)
- {
- }
- }
+ public OpenSearchCleanExitException(string message, Exception innerException) : base(message, innerException)
+ {
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Managed/OpenSearchCluster.cs b/abstractions/src/OpenSearch.OpenSearch.Managed/OpenSearchCluster.cs
index 97456a376b..561b845c58 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Managed/OpenSearchCluster.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Managed/OpenSearchCluster.cs
@@ -28,12 +28,11 @@
using OpenSearch.OpenSearch.Managed.Configuration;
-namespace OpenSearch.OpenSearch.Managed
+namespace OpenSearch.OpenSearch.Managed;
+
+public class OpenSearchCluster : ClusterBase
{
- public class OpenSearchCluster : ClusterBase
- {
- public OpenSearchCluster(ClusterConfiguration clusterConfiguration) : base(clusterConfiguration)
- {
- }
- }
+ public OpenSearchCluster(ClusterConfiguration clusterConfiguration) : base(clusterConfiguration)
+ {
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Managed/OpenSearchNode.cs b/abstractions/src/OpenSearch.OpenSearch.Managed/OpenSearchNode.cs
index da8250901a..a5af441d31 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Managed/OpenSearchNode.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Managed/OpenSearchNode.cs
@@ -39,246 +39,245 @@
using ProcNet;
using ProcNet.Std;
-namespace OpenSearch.OpenSearch.Managed
+namespace OpenSearch.OpenSearch.Managed;
+
+public class OpenSearchNode : ObservableProcess
{
- public class OpenSearchNode : ObservableProcess
- {
- private readonly ManualResetEvent _startedHandle = new ManualResetEvent(false);
-
- public OpenSearchNode(OpenSearchVersion version, string openSearchHome = null)
- : 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; }
- public NodeConfiguration NodeConfiguration { get; }
-
- private int? JavaProcessId { get; set; }
- public override int? ProcessId => JavaProcessId ?? base.ProcessId;
- public int? HostProcessId => base.ProcessId;
-
- ///
- /// Set this true if you want the node to go into assumed started state as soon as its waiting for more nodes to start
- /// doing the election.
- /// Useful to speed up starting multi node clusters
- ///
- public bool AssumeStartedOnNotEnoughMasterPing { get; set; }
-
- internal IConsoleLineHandler Writer { get; private set; }
-
- public Exception LastSeenException { get; set; }
- public WaitHandle StartedHandle => _startedHandle;
-
- private static StartArguments StartArgs(NodeConfiguration config)
- {
- //var args = new[] {config.FileSystem.Binary}.Concat(config.CommandLineArguments);
-
- var startArguments = new StartArguments(config.FileSystem.Binary, config.CommandLineArguments)
- {
- SendControlCFirst = true,
- Environment = EnvVars(config),
- WaitForExit = config.WaitForShutdown,
- WaitForStreamReadersTimeout = config.WaitForShutdown
- };
- config.ModifyStartArguments(startArguments);
- return startArguments;
- }
-
- private static Dictionary EnvVars(NodeConfiguration config)
- {
- var javaOpts = new List { "-Xms1g", "-Xmx1g" };
-
- var environmentVariables = new Dictionary { { "OPENSEARCH_JAVA_OPTS", string.Join(" ", javaOpts) } };
-
- if (!string.IsNullOrWhiteSpace(config.FileSystem.ConfigPath))
- environmentVariables.Add(config.FileSystem.ConfigEnvironmentVariableName, config.FileSystem.ConfigPath);
-
- if (!string.IsNullOrWhiteSpace(config.FileSystem.OpenSearchHome))
- environmentVariables.Add("OPENSEARCH_HOME", config.FileSystem.OpenSearchHome);
-
- var knnLibDir = Path.Combine(config.FileSystem.OpenSearchHome, "plugins", "opensearch-knn", config.Version >= "1.3.10" ? "lib" : "knnlib");
- if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
- AppendPathEnvVar("JAVA_LIBRARY_PATH", knnLibDir);
- else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
- AppendPathEnvVar("LD_LIBRARY_PATH", knnLibDir);
-
- return environmentVariables;
- }
-
- private static void AppendPathEnvVar(string name, string value)
- {
- var previous = Environment.GetEnvironmentVariable(name);
- Environment.SetEnvironmentVariable(name,
- string.IsNullOrWhiteSpace(previous)
- ? value
- : $"{previous}{Path.PathSeparator}{value}"
- );
- }
-
- private bool AssumedStartedStateChecker(string section, string message)
- {
- if (AssumeStartedOnNotEnoughMasterPing
- && section.Contains("ZenDiscovery")
- && message.Contains("not enough master nodes discovered during pinging"))
- return true;
-
- return false;
- }
-
- public IDisposable Start() => Start(TimeSpan.FromMinutes(2));
-
- public IDisposable Start(TimeSpan waitForStarted) => Start(new LineHighlightWriter(), waitForStarted);
-
- 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}");
- }
-
- public IDisposable SubscribeLines() => SubscribeLines(new LineHighlightWriter());
-
- public IDisposable SubscribeLines(IConsoleLineHandler writer) =>
- SubscribeLines(writer, delegate { }, delegate { }, delegate { });
-
- public IDisposable SubscribeLines(IConsoleLineHandler writer, Action onNext) =>
- SubscribeLines(writer, onNext, delegate { }, delegate { });
-
- public IDisposable SubscribeLines(IConsoleLineHandler writer, Action onNext,
- Action onError
- ) =>
- SubscribeLines(writer, onNext, onError, delegate { });
-
- public IDisposable SubscribeLines(IConsoleLineHandler writer, Action onNext, Action onError,
- Action onCompleted
- )
- {
- Writer = writer;
- var node = NodeConfiguration.DesiredNodeName;
- writer?.WriteDiagnostic($"OpenSearch location: [{Binary}]", node);
- writer?.WriteDiagnostic($"Settings: {{{string.Join(" ", NodeConfiguration.CommandLineArguments)}}}", node);
-
- var envVarName = "JAVA_HOME";
- var javaHome = Environment.GetEnvironmentVariable(envVarName);
- writer?.WriteDiagnostic($"{envVarName}: {{{javaHome}}}", node);
- Process.StartInfo.Environment[envVarName] = javaHome;
-
- return SubscribeLines(
- l =>
- {
- writer?.Handle(l);
- onNext?.Invoke(l);
- },
- e =>
- {
- LastSeenException = e;
- writer?.Handle(e);
- onError?.Invoke(e);
- _startedHandle.Set();
- },
- () =>
- {
- onCompleted?.Invoke();
- _startedHandle.Set();
- });
- }
-
- public bool WaitForStarted(TimeSpan timeout) => _startedHandle.WaitOne(timeout);
-
- protected override void OnBeforeSetCompletedHandle()
- {
- _startedHandle.Set();
- base.OnBeforeSetCompletedHandle();
- }
-
- protected override void OnBeforeWaitForEndOfStreamsError(TimeSpan waited)
- {
- // The wait for streams finished before streams were fully read.
- // this usually indicates the process is still running.
- // Proc will successfully kill the host but will leave the JavaProcess the bat file starts running
- // The opensearch jar is closing down so won't leak but might prevent EphemeralClusterComposer to do its clean up.
- // We do a hard kill on both here to make sure both processes are gone.
- HardKill(HostProcessId);
- HardKill(JavaProcessId);
- }
-
- private static void HardKill(int? processId)
- {
- if (!processId.HasValue) return;
-
- try
- {
- var p = Process.GetProcessById(processId.Value);
- p.Kill();
- }
- 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
- // to timeout. This makes little sense to me now, so leaving this performance optimization out for now. Hopefully another fresh look will yield
- // to (not so) obvious.
- //return this.NodeConfiguration.ShowOpenSearchOutputAfterStarted;
- }
-
- protected override bool KeepBufferingLines(LineOut c)
- {
- 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)
- {
- var keepBuffering = Writer != null && NodeConfiguration.ShowOpenSearchOutputAfterStarted;
- if (!keepBuffering) CancelAsyncReads();
- return keepBuffering;
- }
-
- var parsed = lineOutParser.TryParse(c?.Line, out _, out _, out var section, out _, out var message,
- out var started);
-
- if (!parsed) return Writer != null;
-
- if (JavaProcessId == null && lineOutParser.TryParseNodeInfo(section, message, out var version, out var pid))
- {
- JavaProcessId = pid;
- Version = version;
- }
-
- else if (lineOutParser.TryGetPortNumber(section, message, out var port))
- {
- Port = port;
- var dp = NodeConfiguration.DesiredPort;
- if (dp.HasValue && Port != dp.Value)
- throw new OpenSearchCleanExitException(
- $"Node started on port {port} but {dp.Value} was requested");
- }
-
- if (!started) started = AssumedStartedStateChecker(section, message);
- if (started)
- {
- 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;
- }
- }
+ private readonly ManualResetEvent _startedHandle = new ManualResetEvent(false);
+
+ public OpenSearchNode(OpenSearchVersion version, string openSearchHome = null)
+ : 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; }
+ public NodeConfiguration NodeConfiguration { get; }
+
+ private int? JavaProcessId { get; set; }
+ public override int? ProcessId => JavaProcessId ?? base.ProcessId;
+ public int? HostProcessId => base.ProcessId;
+
+ ///
+ /// Set this true if you want the node to go into assumed started state as soon as its waiting for more nodes to start
+ /// doing the election.
+ /// Useful to speed up starting multi node clusters
+ ///
+ public bool AssumeStartedOnNotEnoughMasterPing { get; set; }
+
+ internal IConsoleLineHandler Writer { get; private set; }
+
+ public Exception LastSeenException { get; set; }
+ public WaitHandle StartedHandle => _startedHandle;
+
+ private static StartArguments StartArgs(NodeConfiguration config)
+ {
+ //var args = new[] {config.FileSystem.Binary}.Concat(config.CommandLineArguments);
+
+ var startArguments = new StartArguments(config.FileSystem.Binary, config.CommandLineArguments)
+ {
+ SendControlCFirst = true,
+ Environment = EnvVars(config),
+ WaitForExit = config.WaitForShutdown,
+ WaitForStreamReadersTimeout = config.WaitForShutdown
+ };
+ config.ModifyStartArguments(startArguments);
+ return startArguments;
+ }
+
+ private static Dictionary EnvVars(NodeConfiguration config)
+ {
+ var javaOpts = new List { "-Xms1g", "-Xmx1g" };
+
+ var environmentVariables = new Dictionary { { "OPENSEARCH_JAVA_OPTS", string.Join(" ", javaOpts) } };
+
+ if (!string.IsNullOrWhiteSpace(config.FileSystem.ConfigPath))
+ environmentVariables.Add(config.FileSystem.ConfigEnvironmentVariableName, config.FileSystem.ConfigPath);
+
+ if (!string.IsNullOrWhiteSpace(config.FileSystem.OpenSearchHome))
+ environmentVariables.Add("OPENSEARCH_HOME", config.FileSystem.OpenSearchHome);
+
+ var knnLibDir = Path.Combine(config.FileSystem.OpenSearchHome, "plugins", "opensearch-knn", config.Version >= "1.3.10" ? "lib" : "knnlib");
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+ AppendPathEnvVar("JAVA_LIBRARY_PATH", knnLibDir);
+ else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+ AppendPathEnvVar("LD_LIBRARY_PATH", knnLibDir);
+
+ return environmentVariables;
+ }
+
+ private static void AppendPathEnvVar(string name, string value)
+ {
+ var previous = Environment.GetEnvironmentVariable(name);
+ Environment.SetEnvironmentVariable(name,
+ string.IsNullOrWhiteSpace(previous)
+ ? value
+ : $"{previous}{Path.PathSeparator}{value}"
+ );
+ }
+
+ private bool AssumedStartedStateChecker(string section, string message)
+ {
+ if (AssumeStartedOnNotEnoughMasterPing
+ && section.Contains("ZenDiscovery")
+ && message.Contains("not enough master nodes discovered during pinging"))
+ return true;
+
+ return false;
+ }
+
+ public IDisposable Start() => Start(TimeSpan.FromMinutes(2));
+
+ public IDisposable Start(TimeSpan waitForStarted) => Start(new LineHighlightWriter(), waitForStarted);
+
+ 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}");
+ }
+
+ public IDisposable SubscribeLines() => SubscribeLines(new LineHighlightWriter());
+
+ public IDisposable SubscribeLines(IConsoleLineHandler writer) =>
+ SubscribeLines(writer, delegate { }, delegate { }, delegate { });
+
+ public IDisposable SubscribeLines(IConsoleLineHandler writer, Action onNext) =>
+ SubscribeLines(writer, onNext, delegate { }, delegate { });
+
+ public IDisposable SubscribeLines(IConsoleLineHandler writer, Action onNext,
+ Action onError
+ ) =>
+ SubscribeLines(writer, onNext, onError, delegate { });
+
+ public IDisposable SubscribeLines(IConsoleLineHandler writer, Action onNext, Action onError,
+ Action onCompleted
+ )
+ {
+ Writer = writer;
+ var node = NodeConfiguration.DesiredNodeName;
+ writer?.WriteDiagnostic($"OpenSearch location: [{Binary}]", node);
+ writer?.WriteDiagnostic($"Settings: {{{string.Join(" ", NodeConfiguration.CommandLineArguments)}}}", node);
+
+ var envVarName = "JAVA_HOME";
+ var javaHome = Environment.GetEnvironmentVariable(envVarName);
+ writer?.WriteDiagnostic($"{envVarName}: {{{javaHome}}}", node);
+ Process.StartInfo.Environment[envVarName] = javaHome;
+
+ return SubscribeLines(
+ l =>
+ {
+ writer?.Handle(l);
+ onNext?.Invoke(l);
+ },
+ e =>
+ {
+ LastSeenException = e;
+ writer?.Handle(e);
+ onError?.Invoke(e);
+ _startedHandle.Set();
+ },
+ () =>
+ {
+ onCompleted?.Invoke();
+ _startedHandle.Set();
+ });
+ }
+
+ public bool WaitForStarted(TimeSpan timeout) => _startedHandle.WaitOne(timeout);
+
+ protected override void OnBeforeSetCompletedHandle()
+ {
+ _startedHandle.Set();
+ base.OnBeforeSetCompletedHandle();
+ }
+
+ protected override void OnBeforeWaitForEndOfStreamsError(TimeSpan waited)
+ {
+ // The wait for streams finished before streams were fully read.
+ // this usually indicates the process is still running.
+ // Proc will successfully kill the host but will leave the JavaProcess the bat file starts running
+ // The opensearch jar is closing down so won't leak but might prevent EphemeralClusterComposer to do its clean up.
+ // We do a hard kill on both here to make sure both processes are gone.
+ HardKill(HostProcessId);
+ HardKill(JavaProcessId);
+ }
+
+ private static void HardKill(int? processId)
+ {
+ if (!processId.HasValue) return;
+
+ try
+ {
+ var p = Process.GetProcessById(processId.Value);
+ p.Kill();
+ }
+ 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
+ // to timeout. This makes little sense to me now, so leaving this performance optimization out for now. Hopefully another fresh look will yield
+ // to (not so) obvious.
+ //return this.NodeConfiguration.ShowOpenSearchOutputAfterStarted;
+ }
+
+ protected override bool KeepBufferingLines(LineOut c)
+ {
+ 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)
+ {
+ var keepBuffering = Writer != null && NodeConfiguration.ShowOpenSearchOutputAfterStarted;
+ if (!keepBuffering) CancelAsyncReads();
+ return keepBuffering;
+ }
+
+ var parsed = lineOutParser.TryParse(c?.Line, out _, out _, out var section, out _, out var message,
+ out var started);
+
+ if (!parsed) return Writer != null;
+
+ if (JavaProcessId == null && lineOutParser.TryParseNodeInfo(section, message, out var version, out var pid))
+ {
+ JavaProcessId = pid;
+ Version = version;
+ }
+
+ else if (lineOutParser.TryGetPortNumber(section, message, out var port))
+ {
+ Port = port;
+ var dp = NodeConfiguration.DesiredPort;
+ if (dp.HasValue && Port != dp.Value)
+ throw new OpenSearchCleanExitException(
+ $"Node started on port {port} but {dp.Value} was requested");
+ }
+
+ if (!started) started = AssumedStartedStateChecker(section, message);
+ if (started)
+ {
+ 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;
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Xunit/OpenSearchXunitConfigurationAttribute.cs b/abstractions/src/OpenSearch.OpenSearch.Xunit/OpenSearchXunitConfigurationAttribute.cs
index 4efb622b98..030b93a59b 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Xunit/OpenSearchXunitConfigurationAttribute.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Xunit/OpenSearchXunitConfigurationAttribute.cs
@@ -28,30 +28,29 @@
using System;
-namespace OpenSearch.OpenSearch.Xunit
+namespace OpenSearch.OpenSearch.Xunit;
+
+///
+/// An assembly attribute that specifies the
+/// for Xunit tests within the assembly.
+///
+[AttributeUsage(AttributeTargets.Assembly)]
+public class OpenSearchXunitConfigurationAttribute : Attribute
{
- ///
- /// An assembly attribute that specifies the
- /// for Xunit tests within the assembly.
- ///
- [AttributeUsage(AttributeTargets.Assembly)]
- public class OpenSearchXunitConfigurationAttribute : Attribute
- {
- ///
- /// Creates a new instance of
- ///
- ///
- /// A type deriving from that specifies the run options
- ///
- public OpenSearchXunitConfigurationAttribute(Type type)
- {
- var options = Activator.CreateInstance(type) as OpenSearchXunitRunOptions;
- Options = options ?? new OpenSearchXunitRunOptions();
- }
+ ///
+ /// Creates a new instance of
+ ///
+ ///
+ /// A type deriving from that specifies the run options
+ ///
+ public OpenSearchXunitConfigurationAttribute(Type type)
+ {
+ var options = Activator.CreateInstance(type) as OpenSearchXunitRunOptions;
+ Options = options ?? new OpenSearchXunitRunOptions();
+ }
- ///
- /// The run options
- ///
- public OpenSearchXunitRunOptions Options { get; }
- }
+ ///
+ /// The run options
+ ///
+ public OpenSearchXunitRunOptions Options { get; }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Xunit/OpenSearchXunitRunOptions.cs b/abstractions/src/OpenSearch.OpenSearch.Xunit/OpenSearchXunitRunOptions.cs
index ff841b76c3..f234d7b678 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Xunit/OpenSearchXunitRunOptions.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Xunit/OpenSearchXunitRunOptions.cs
@@ -33,65 +33,64 @@
using OpenSearch.OpenSearch.Xunit.XunitPlumbing;
using OpenSearch.Stack.ArtifactsApi;
-namespace OpenSearch.OpenSearch.Xunit
+namespace OpenSearch.OpenSearch.Xunit;
+
+///
+/// The Xunit test runner options
+///
+public class OpenSearchXunitRunOptions
{
- ///
- /// The Xunit test runner options
- ///
- public class OpenSearchXunitRunOptions
- {
- ///
- /// Informs the runner whether we expect to run integration tests. Defaults to true
- ///
- public bool RunIntegrationTests { get; set; } = true;
+ ///
+ /// Informs the runner whether we expect to run integration tests. Defaults to true
+ ///
+ public bool RunIntegrationTests { get; set; } = true;
- ///
- /// Setting this to true will assume the cluster that is currently running was started for the purpose of these tests
- /// Defaults to false
- ///
- public bool IntegrationTestsMayUseAlreadyRunningNode { get; set; } = false;
+ ///
+ /// Setting this to true will assume the cluster that is currently running was started for the purpose of these tests
+ /// Defaults to false
+ ///
+ public bool IntegrationTestsMayUseAlreadyRunningNode { get; set; } = false;
- ///
- /// Informs the runner whether unit tests will be run. Defaults to false.
- /// If set to true and is false, the runner will run all the
- /// tests in parallel with the maximum degree of parallelism
- ///
- public bool RunUnitTests { get; set; }
+ ///
+ /// Informs the runner whether unit tests will be run. Defaults to false.
+ /// If set to true and is false, the runner will run all the
+ /// tests in parallel with the maximum degree of parallelism
+ ///
+ public bool RunUnitTests { get; set; }
- ///
- /// A global test filter that can be used to only run certain tests.
- /// Accepts a comma separated list of filters
- ///
- public string TestFilter { get; set; }
+ ///
+ /// A global test filter that can be used to only run certain tests.
+ /// Accepts a comma separated list of filters
+ ///
+ public string TestFilter { get; set; }
- ///
- /// A global cluster filter that can be used to only run certain cluster's tests.
- /// Accepts a comma separated list of filters
- ///
- public string ClusterFilter { get; set; }
+ ///
+ /// A global cluster filter that can be used to only run certain cluster's tests.
+ /// Accepts a comma separated list of filters
+ ///
+ public string ClusterFilter { get; set; }
- ///
- /// Informs the runner what version of OpenSearch is under test. Required for
- /// to kick in
- ///
- public OpenSearchVersion Version { get; set; }
+ ///
+ /// Informs the runner what version of OpenSearch is under test. Required for
+ /// to kick in
+ ///
+ public OpenSearchVersion Version { get; set; }
- ///
- /// Called when the tests have finished running successfully
- ///
- /// Per cluster timings of the total test time, including starting OpenSearch
- /// All collection of failed cluster, failed tests tuples
- public virtual void OnTestsFinished(Dictionary runnerClusterTotals,
- ConcurrentBag> runnerFailedCollections)
- {
- }
+ ///
+ /// Called when the tests have finished running successfully
+ ///
+ /// Per cluster timings of the total test time, including starting OpenSearch
+ /// All collection of failed cluster, failed tests tuples
+ public virtual void OnTestsFinished(Dictionary runnerClusterTotals,
+ ConcurrentBag> runnerFailedCollections)
+ {
+ }
- ///
- /// Called before tests run. An ideal place to perform actions such as writing information to
- /// .
- ///
- public virtual void OnBeforeTestsRun()
- {
- }
- }
+ ///
+ /// Called before tests run. An ideal place to perform actions such as writing information to
+ /// .
+ ///
+ public virtual void OnBeforeTestsRun()
+ {
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Xunit/OpenSearchXunitRunner.cs b/abstractions/src/OpenSearch.OpenSearch.Xunit/OpenSearchXunitRunner.cs
index b9ba0fec81..ed7b32685e 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Xunit/OpenSearchXunitRunner.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Xunit/OpenSearchXunitRunner.cs
@@ -28,10 +28,9 @@
using OpenSearch.OpenSearch.Ephemeral;
-namespace OpenSearch.OpenSearch.Xunit
+namespace OpenSearch.OpenSearch.Xunit;
+
+public static class OpenSearchXunitRunner
{
- public static class OpenSearchXunitRunner
- {
- public static IEphemeralCluster CurrentCluster { get; internal set; }
- }
+ public static IEphemeralCluster CurrentCluster { get; internal set; }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Xunit/PrintXunitAfterStartedTask.cs b/abstractions/src/OpenSearch.OpenSearch.Xunit/PrintXunitAfterStartedTask.cs
index eea8e4f381..1c8e31fe8a 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Xunit/PrintXunitAfterStartedTask.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Xunit/PrintXunitAfterStartedTask.cs
@@ -30,18 +30,17 @@
using OpenSearch.OpenSearch.Ephemeral.Tasks;
using OpenSearch.OpenSearch.Managed.ConsoleWriters;
-namespace OpenSearch.OpenSearch.Xunit
+namespace OpenSearch.OpenSearch.Xunit;
+
+///
+/// A task that writes a diagnostic message to indicate that tests will now run
+///
+public class PrintXunitAfterStartedTask : ClusterComposeTask
{
- ///
- /// A task that writes a diagnostic message to indicate that tests will now run
- ///
- public class PrintXunitAfterStartedTask : ClusterComposeTask
- {
- ///
- public override void Run(IEphemeralCluster cluster)
- {
- var name = cluster.GetType().Name;
- cluster.Writer.WriteDiagnostic($"All good! kicking off [{name}] tests now");
- }
- }
+ ///
+ public override void Run(IEphemeralCluster cluster)
+ {
+ var name = cluster.GetType().Name;
+ cluster.Writer.WriteDiagnostic($"All good! kicking off [{name}] tests now");
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Xunit/Sdk/ForEachAsyncExtensions.cs b/abstractions/src/OpenSearch.OpenSearch.Xunit/Sdk/ForEachAsyncExtensions.cs
index 8e2f4c61ff..108ca1d2e1 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Xunit/Sdk/ForEachAsyncExtensions.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Xunit/Sdk/ForEachAsyncExtensions.cs
@@ -32,18 +32,17 @@
using System.Linq;
using System.Threading.Tasks;
-namespace OpenSearch.OpenSearch.Xunit.Sdk
+namespace OpenSearch.OpenSearch.Xunit.Sdk;
+
+internal static class ForEachAsyncExtensions
{
- internal static class ForEachAsyncExtensions
- {
- internal static Task ForEachAsync(this IEnumerable source, int dop, Func body) =>
- Task.WhenAll(
- from partition in Partitioner.Create(source).GetPartitions(dop)
- select Task.Run(async delegate
- {
- using (partition)
- while (partition.MoveNext())
- await body(partition.Current).ConfigureAwait(false);
- }));
- }
+ internal static Task ForEachAsync(this IEnumerable source, int dop, Func body) =>
+ Task.WhenAll(
+ from partition in Partitioner.Create(source).GetPartitions(dop)
+ select Task.Run(async delegate
+ {
+ using (partition)
+ while (partition.MoveNext())
+ await body(partition.Current).ConfigureAwait(false);
+ }));
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Xunit/Sdk/OpenSearchTestFramework.cs b/abstractions/src/OpenSearch.OpenSearch.Xunit/Sdk/OpenSearchTestFramework.cs
index 621b6f0d84..b1b814efeb 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Xunit/Sdk/OpenSearchTestFramework.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Xunit/Sdk/OpenSearchTestFramework.cs
@@ -30,27 +30,26 @@
using Xunit.Abstractions;
using Xunit.Sdk;
-namespace OpenSearch.OpenSearch.Xunit.Sdk
+namespace OpenSearch.OpenSearch.Xunit.Sdk;
+
+public class OpenSearchTestFramework : XunitTestFramework
{
- public class OpenSearchTestFramework : XunitTestFramework
- {
- public OpenSearchTestFramework(IMessageSink messageSink) : base(messageSink)
- {
- }
+ public OpenSearchTestFramework(IMessageSink messageSink) : base(messageSink)
+ {
+ }
- protected override ITestFrameworkDiscoverer CreateDiscoverer(IAssemblyInfo assemblyInfo) =>
- new OpenSearchTestFrameworkDiscoverer(assemblyInfo, SourceInformationProvider, DiagnosticMessageSink);
+ protected override ITestFrameworkDiscoverer CreateDiscoverer(IAssemblyInfo assemblyInfo) =>
+ new OpenSearchTestFrameworkDiscoverer(assemblyInfo, SourceInformationProvider, DiagnosticMessageSink);
- protected override ITestFrameworkExecutor CreateExecutor(AssemblyName assemblyName)
- {
- var assembly = Assembly.Load(assemblyName);
- var options = assembly.GetCustomAttribute()?.Options ??
- new OpenSearchXunitRunOptions();
+ protected override ITestFrameworkExecutor CreateExecutor(AssemblyName assemblyName)
+ {
+ var assembly = Assembly.Load(assemblyName);
+ var options = assembly.GetCustomAttribute()?.Options ??
+ new OpenSearchXunitRunOptions();
- return new TestFrameworkExecutor(assemblyName, SourceInformationProvider, DiagnosticMessageSink)
- {
- Options = options
- };
- }
- }
+ return new TestFrameworkExecutor(assemblyName, SourceInformationProvider, DiagnosticMessageSink)
+ {
+ Options = options
+ };
+ }
}
diff --git a/abstractions/src/OpenSearch.OpenSearch.Xunit/Sdk/OpenSearchTestFrameworkDiscoverer.cs b/abstractions/src/OpenSearch.OpenSearch.Xunit/Sdk/OpenSearchTestFrameworkDiscoverer.cs
index b59692b347..32d5650abe 100644
--- a/abstractions/src/OpenSearch.OpenSearch.Xunit/Sdk/OpenSearchTestFrameworkDiscoverer.cs
+++ b/abstractions/src/OpenSearch.OpenSearch.Xunit/Sdk/OpenSearchTestFrameworkDiscoverer.cs
@@ -30,36 +30,35 @@
using Xunit.Abstractions;
using Xunit.Sdk;
-namespace OpenSearch.OpenSearch.Xunit.Sdk
+namespace OpenSearch.OpenSearch.Xunit.Sdk;
+
+public class OpenSearchTestFrameworkDiscoverer : XunitTestFrameworkDiscoverer
{
- public class OpenSearchTestFrameworkDiscoverer : XunitTestFrameworkDiscoverer
- {
- public OpenSearchTestFrameworkDiscoverer(IAssemblyInfo assemblyInfo, ISourceInformationProvider sourceProvider,
- IMessageSink diagnosticMessageSink, IXunitTestCollectionFactory collectionFactory = null) : base(
- assemblyInfo, sourceProvider, diagnosticMessageSink, collectionFactory)
- {
- var a = Assembly.Load(new AssemblyName(assemblyInfo.Name));
- var options = a.GetCustomAttribute()?.Options ??
- new OpenSearchXunitRunOptions();
- Options = options;
- }
+ public OpenSearchTestFrameworkDiscoverer(IAssemblyInfo assemblyInfo, ISourceInformationProvider sourceProvider,
+ IMessageSink diagnosticMessageSink, IXunitTestCollectionFactory collectionFactory = null) : base(
+ assemblyInfo, sourceProvider, diagnosticMessageSink, collectionFactory)
+ {
+ var a = Assembly.Load(new AssemblyName(assemblyInfo.Name));
+ var options = a.GetCustomAttribute()?.Options ??
+ new OpenSearchXunitRunOptions();
+ Options = options;
+ }
- ///