11use snafu:: { OptionExt , ResultExt , Snafu } ;
2- use stackable_operator:: {
3- memory:: { BinaryMultiple , MemoryQuantity } ,
4- role_utils:: { self , JvmArgumentOverrides } ,
5- } ;
2+ use stackable_operator:: memory:: { BinaryMultiple , MemoryQuantity } ;
63
74use super :: properties:: ConfigFileName ;
8- use crate :: crd:: {
9- HiveRoleType , METRICS_PORT , MetaStoreConfig , STACKABLE_CONFIG_DIR , STACKABLE_TRUST_STORE ,
10- STACKABLE_TRUST_STORE_PASSWORD , v1alpha1:: HiveCluster ,
5+ use crate :: {
6+ controller:: HiveRoleGroupConfig ,
7+ crd:: {
8+ METRICS_PORT , MetaStoreConfig , STACKABLE_CONFIG_DIR , STACKABLE_TRUST_STORE ,
9+ STACKABLE_TRUST_STORE_PASSWORD , v1alpha1:: HiveCluster ,
10+ } ,
1111} ;
1212
1313const JAVA_HEAP_FACTOR : f32 = 0.8 ;
@@ -21,17 +21,10 @@ pub enum Error {
2121 InvalidMemoryConfig {
2222 source : stackable_operator:: memory:: Error ,
2323 } ,
24-
25- #[ snafu( display( "failed to merge jvm argument overrides" ) ) ]
26- MergeJvmArgumentOverrides { source : role_utils:: Error } ,
2724}
2825
2926/// All JVM arguments.
30- fn construct_jvm_args (
31- hive : & HiveCluster ,
32- role : & HiveRoleType ,
33- role_group : & str ,
34- ) -> Result < Vec < String > , Error > {
27+ fn construct_jvm_args ( hive : & HiveCluster , rg : & HiveRoleGroupConfig ) -> Vec < String > {
3528 let security_properties = ConfigFileName :: Security ;
3629 let mut jvm_args = vec ! [
3730 format!( "-Djava.security.properties={STACKABLE_CONFIG_DIR}/{security_properties}" ) ,
@@ -47,27 +40,18 @@ fn construct_jvm_args(
4740 jvm_args. push ( "-Djava.security.krb5.conf=/stackable/kerberos/krb5.conf" . to_owned ( ) ) ;
4841 }
4942
50- let operator_generated = JvmArgumentOverrides :: new_with_only_additions ( jvm_args) ;
51- let merged = role
52- . get_merged_jvm_argument_overrides ( role_group, & operator_generated)
53- . context ( MergeJvmArgumentOverridesSnafu ) ?;
54- Ok ( merged
55- . effective_jvm_config_after_merging ( )
56- // Sorry for the clone, that's how operator-rs is currently modelled :P
57- . clone ( ) )
43+ // Apply the already-merged (role + role group) JVM argument overrides on top of the
44+ // operator-generated base arguments.
45+ rg. jvm_argument_overrides . apply_to ( jvm_args)
5846}
5947
6048/// Arguments that go into `HADOOP_OPTS`, so *not* the heap settings (which you can get using
6149/// [`construct_hadoop_heapsize_env`]).
62- pub fn construct_non_heap_jvm_args (
63- hive : & HiveCluster ,
64- role : & HiveRoleType ,
65- role_group : & str ,
66- ) -> Result < String , Error > {
67- let mut jvm_args = construct_jvm_args ( hive, role, role_group) ?;
50+ pub fn construct_non_heap_jvm_args ( hive : & HiveCluster , rg : & HiveRoleGroupConfig ) -> String {
51+ let mut jvm_args = construct_jvm_args ( hive, rg) ;
6852 jvm_args. retain ( |arg| !is_heap_jvm_argument ( arg) ) ;
6953
70- Ok ( jvm_args. join ( " " ) )
54+ jvm_args. join ( " " )
7155}
7256
7357/// This will be put into `HADOOP_HEAPSIZE`, which is just the heap size in megabytes (*without* the `m`
@@ -96,10 +80,21 @@ fn is_heap_jvm_argument(jvm_argument: &str) -> bool {
9680
9781#[ cfg( test) ]
9882mod tests {
99- use stackable_operator:: utils:: yaml_from_str_singleton_map;
100-
10183 use super :: * ;
102- use crate :: crd:: HiveRole ;
84+ use crate :: {
85+ controller:: test_support:: { minimal_hive, validated_cluster} ,
86+ crd:: HiveRole ,
87+ } ;
88+
89+ fn metastore_default ( hive : & crate :: crd:: v1alpha1:: HiveCluster ) -> HiveRoleGroupConfig {
90+ let validated = validated_cluster ( hive) ;
91+ validated
92+ . role_group_configs
93+ . get ( & HiveRole :: MetaStore )
94+ . and_then ( |groups| groups. get ( "default" ) )
95+ . expect ( "metastore default role group should exist" )
96+ . clone ( )
97+ }
10398
10499 #[ test]
105100 fn test_construct_jvm_arguments_defaults ( ) {
@@ -108,6 +103,8 @@ mod tests {
108103 kind: HiveCluster
109104 metadata:
110105 name: simple-hive
106+ namespace: default
107+ uid: 12345678-1234-1234-1234-123456789012
111108 spec:
112109 image:
113110 productVersion: 4.2.0
@@ -119,9 +116,10 @@ mod tests {
119116 default:
120117 replicas: 1
121118 "# ;
122- let ( hive, merged_config, role, rolegroup) = construct_boilerplate ( input) ;
123- let non_heap_jvm_args = construct_non_heap_jvm_args ( & hive, & role, & rolegroup) . unwrap ( ) ;
124- let hadoop_heapsize_env = construct_hadoop_heapsize_env ( & merged_config) . unwrap ( ) ;
119+ let hive = minimal_hive ( input) ;
120+ let rg = metastore_default ( & hive) ;
121+ let non_heap_jvm_args = construct_non_heap_jvm_args ( & hive, & rg) ;
122+ let hadoop_heapsize_env = construct_hadoop_heapsize_env ( & rg. config ) . unwrap ( ) ;
125123
126124 assert_eq ! (
127125 non_heap_jvm_args,
@@ -141,6 +139,8 @@ mod tests {
141139 kind: HiveCluster
142140 metadata:
143141 name: simple-hive
142+ namespace: default
143+ uid: 12345678-1234-1234-1234-123456789012
144144 spec:
145145 image:
146146 productVersion: 4.2.0
@@ -169,9 +169,10 @@ mod tests {
169169 - -Xmx40000m
170170 - -Dhttps.proxyPort=1234
171171 "# ;
172- let ( hive, merged_config, role, rolegroup) = construct_boilerplate ( input) ;
173- let non_heap_jvm_args = construct_non_heap_jvm_args ( & hive, & role, & rolegroup) . unwrap ( ) ;
174- let hadoop_heapsize_env = construct_hadoop_heapsize_env ( & merged_config) . unwrap ( ) ;
172+ let hive = minimal_hive ( input) ;
173+ let rg = metastore_default ( & hive) ;
174+ let non_heap_jvm_args = construct_non_heap_jvm_args ( & hive, & rg) ;
175+ let hadoop_heapsize_env = construct_hadoop_heapsize_env ( & rg. config ) . unwrap ( ) ;
175176
176177 assert_eq ! (
177178 non_heap_jvm_args,
@@ -186,18 +187,4 @@ mod tests {
186187 ) ;
187188 assert_eq ! ( hadoop_heapsize_env, "34406" ) ;
188189 }
189-
190- fn construct_boilerplate (
191- hive_cluster : & str ,
192- ) -> ( HiveCluster , MetaStoreConfig , HiveRoleType , String ) {
193- let hive: HiveCluster =
194- yaml_from_str_singleton_map ( hive_cluster) . expect ( "invalid test input" ) ;
195-
196- let hive_role = HiveRole :: MetaStore ;
197- let rolegroup_ref = hive. metastore_rolegroup_ref ( "default" ) ;
198- let merged_config = hive. merged_config ( & hive_role, & rolegroup_ref) . unwrap ( ) ;
199- let role = hive. spec . metastore . clone ( ) . unwrap ( ) ;
200-
201- ( hive, merged_config, role, "default" . to_owned ( ) )
202- }
203190}
0 commit comments