1+ //! Configuration of an OpenSearch node
2+
13use std:: str:: FromStr ;
24
35use serde_json:: { Value , json} ;
@@ -14,33 +16,49 @@ use crate::{
1416 } ,
1517} ;
1618
19+ /// The main configuration file of OpenSearch
1720pub const CONFIGURATION_FILE_OPENSEARCH_YML : & str = "opensearch.yml" ;
1821
19- /// type: string
22+ /// The cluster name.
23+ /// Type: string
2024pub const CONFIG_OPTION_CLUSTER_NAME : & str = "cluster.name" ;
2125
22- /// type: (comma-separated) list of strings
26+ /// The list of hosts that perform discovery when a node is started.
27+ /// Type: (comma-separated) list of strings
2328pub const CONFIG_OPTION_DISCOVERY_SEED_HOSTS : & str = "discovery.seed_hosts" ;
2429
25- /// type: string
30+ /// By default, OpenSearch forms a multi-node cluster. Set `discovery.type` to `single-node` to
31+ /// form a single-node cluster.
32+ /// Type: string
2633pub const CONFIG_OPTION_DISCOVERY_TYPE : & str = "discovery.type" ;
2734
28- /// type: (comma-separated) list of strings
35+ /// A list of cluster-manager-eligible nodes used to bootstrap the cluster.
36+ /// Type: (comma-separated) list of strings
2937pub const CONFIG_OPTION_INITIAL_CLUSTER_MANAGER_NODES : & str =
3038 "cluster.initial_cluster_manager_nodes" ;
3139
32- /// type: string
40+ /// Binds an OpenSearch node to an address.
41+ /// Type: string
3342pub const CONFIG_OPTION_NETWORK_HOST : & str = "network.host" ;
3443
35- /// type: string
44+ /// A descriptive name for the node.
45+ /// Type: string
3646pub const CONFIG_OPTION_NODE_NAME : & str = "node.name" ;
3747
38- /// type: (comma-separated) list of strings
48+ /// Defines one or more roles for an OpenSearch node.
49+ /// Type: (comma-separated) list of strings
3950pub const CONFIG_OPTION_NODE_ROLES : & str = "node.roles" ;
4051
41- /// type: (comma-separated) list of strings
52+ /// Specifies a list of distinguished names (DNs) that denote the other nodes in the cluster.
53+ /// Type: (comma-separated) list of strings
4254pub const CONFIG_OPTION_PLUGINS_SECURITY_NODES_DN : & str = "plugins.security.nodes_dn" ;
4355
56+ /// Whether to enable TLS on the REST layer. If enabled, only HTTPS is allowed.
57+ /// Type: boolean
58+ pub const CONFIG_OPTION_PLUGINS_SECURITY_SSL_HTTP_ENABLED : & str =
59+ "plugins.security.ssl.http.enabled" ;
60+
61+ /// Configuration of an OpenSearch node based on the cluster and role-group configuration
4462pub struct NodeConfig {
4563 cluster : ValidatedCluster ,
4664 role_group_config : OpenSearchRoleGroupConfig ,
@@ -62,12 +80,15 @@ impl NodeConfig {
6280 }
6381 }
6482
65- /// static for the cluster
83+ /// Creates the main OpenSearch configuration file in YAML format
6684 pub fn static_opensearch_config_file ( & self ) -> String {
6785 Self :: to_yaml ( self . static_opensearch_config ( ) )
6886 }
6987
70- /// static for the cluster
88+ /// Creates the main OpenSearch configuration file as JSON map
89+ ///
90+ /// The file should only contain cluster-wide configuration options. Node-specific options
91+ /// should be defined as environment variables.
7192 pub fn static_opensearch_config ( & self ) -> serde_json:: Map < String , Value > {
7293 let mut config = serde_json:: Map :: new ( ) ;
7394
@@ -107,13 +128,15 @@ impl NodeConfig {
107128 config
108129 }
109130
131+ /// Returns `true` if TLS is enabled on the HTTP port
110132 pub fn tls_on_http_port_enabled ( & self ) -> bool {
111133 self . static_opensearch_config ( )
112- . get ( "plugins.security.ssl.http.enabled" )
134+ . get ( CONFIG_OPTION_PLUGINS_SECURITY_SSL_HTTP_ENABLED )
113135 . and_then ( Self :: value_as_bool)
114136 == Some ( true )
115137 }
116138
139+ /// Converts the given JSON value to `bool` if possible
117140 pub fn value_as_bool ( value : & Value ) -> Option < bool > {
118141 value. as_bool ( ) . or (
119142 // OpenSearch parses the strings "true" and "false" as boolean, see
@@ -124,7 +147,10 @@ impl NodeConfig {
124147 )
125148 }
126149
127- /// different for every node
150+ /// Creates environment variables for the OpenSearch configurations
151+ ///
152+ /// The environment variables should only contain node-specific configuration options.
153+ /// Cluster-wide options should be added to the configuration file.
128154 pub fn environment_variables ( & self ) -> EnvVarSet {
129155 EnvVarSet :: new ( )
130156 // Set the OpenSearch node name to the Pod name.
0 commit comments