Skip to content

Commit 88e71d5

Browse files
committed
refactor: use ConfigFileName enum where possible
1 parent 404a335 commit 88e71d5

3 files changed

Lines changed: 43 additions & 11 deletions

File tree

rust/operator-binary/src/controller/build/config_map.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ use crate::{
1212
controller::{
1313
ValidatedCluster,
1414
build::properties::{
15-
core_site, hive_site, logging, resolved_overrides, security_properties,
15+
ConfigFileName, core_site, hive_site, logging, resolved_overrides, security_properties,
1616
},
1717
build_recommended_labels,
1818
},
19-
crd::{
20-
CORE_SITE_XML, HIVE_METASTORE_LOG4J2_PROPERTIES, HIVE_SITE_XML, HiveRole,
21-
JVM_SECURITY_PROPERTIES_FILE, v1alpha1,
22-
},
19+
crd::{HiveRole, v1alpha1},
2320
framework::writer::{to_hadoop_xml, to_java_properties_string},
2421
};
2522

@@ -31,7 +28,7 @@ pub enum Error {
3128
#[snafu(display("failed to build hive-site.xml"))]
3229
BuildHiveSite { source: hive_site::Error },
3330

34-
#[snafu(display("failed to serialize {JVM_SECURITY_PROPERTIES_FILE}"))]
31+
#[snafu(display("failed to serialize {}", ConfigFileName::Security))]
3532
WriteSecurityProperties {
3633
source: crate::framework::writer::PropertiesWriterError,
3734
},
@@ -101,20 +98,26 @@ pub fn build_metastore_rolegroup_config_map(
10198
.context(MetadataBuildSnafu)?
10299
.build(),
103100
)
104-
.add_data(HIVE_SITE_XML, to_hadoop_xml(hive_site_data.iter()))
105101
.add_data(
106-
JVM_SECURITY_PROPERTIES_FILE,
102+
ConfigFileName::HiveSite.to_string(),
103+
to_hadoop_xml(hive_site_data.iter()),
104+
)
105+
.add_data(
106+
ConfigFileName::Security.to_string(),
107107
to_java_properties_string(security_data.iter())
108108
.context(WriteSecurityPropertiesSnafu)?,
109109
);
110110

111111
// core-site.xml is only required when Kerberos is enabled without an HDFS backend.
112112
if let Some(core_site_data) = core_site::build(&cluster.cluster_config) {
113-
cm_builder.add_data(CORE_SITE_XML, to_hadoop_xml(core_site_data.iter()));
113+
cm_builder.add_data(
114+
ConfigFileName::CoreSite.to_string(),
115+
to_hadoop_xml(core_site_data.iter()),
116+
);
114117
}
115118

116119
if let Some(log4j2_properties) = logging::build_log4j2(&rg.config.logging) {
117-
cm_builder.add_data(HIVE_METASTORE_LOG4J2_PROPERTIES, log4j2_properties);
120+
cm_builder.add_data(ConfigFileName::Log4j2.to_string(), log4j2_properties);
118121
}
119122
if let Some(vector_config) = logging::build_vector_config(rolegroup, &rg.config.logging) {
120123
cm_builder.add_data(VECTOR_CONFIG_FILE, vector_config);

rust/operator-binary/src/controller/build/properties/mod.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,35 @@ pub(crate) fn resolved_overrides(overrides: KeyValueConfigOverrides) -> BTreeMap
1919
.collect()
2020
}
2121

22+
/// The names of the Hive config files assembled into the rolegroup `ConfigMap`.
23+
#[derive(Clone, Copy, Debug, strum::Display)]
24+
pub enum ConfigFileName {
25+
#[strum(serialize = "hive-site.xml")]
26+
HiveSite,
27+
#[strum(serialize = "core-site.xml")]
28+
CoreSite,
29+
#[strum(serialize = "security.properties")]
30+
Security,
31+
#[strum(serialize = "metastore-log4j2.properties")]
32+
Log4j2,
33+
}
34+
35+
#[cfg(test)]
36+
mod tests {
37+
use super::*;
38+
39+
#[test]
40+
fn file_names_match_the_hive_on_disk_names() {
41+
assert_eq!(ConfigFileName::HiveSite.to_string(), "hive-site.xml");
42+
assert_eq!(ConfigFileName::CoreSite.to_string(), "core-site.xml");
43+
assert_eq!(ConfigFileName::Security.to_string(), "security.properties");
44+
assert_eq!(
45+
ConfigFileName::Log4j2.to_string(),
46+
"metastore-log4j2.properties"
47+
);
48+
}
49+
}
50+
2251
#[cfg(test)]
2352
pub(crate) mod test_support {
2453
use std::collections::BTreeMap;

rust/operator-binary/src/crd/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub const STACKABLE_LOG_CONFIG_MOUNT_DIR: &str = "/stackable/mount/log-config";
5555
pub const STACKABLE_LOG_CONFIG_MOUNT_DIR_NAME: &str = "log-config-mount";
5656

5757
// Config file names
58-
pub const CORE_SITE_XML: &str = "core-site.xml";
58+
// TODO(@maltesander): remove once fully consolidated with ConfigFileName
5959
pub const HIVE_SITE_XML: &str = "hive-site.xml";
6060
pub const HIVE_METASTORE_LOG4J2_PROPERTIES: &str = "metastore-log4j2.properties";
6161
pub const JVM_SECURITY_PROPERTIES_FILE: &str = "security.properties";

0 commit comments

Comments
 (0)