@@ -18,11 +18,7 @@ use stackable_operator::{
1818 fragment:: { self , Fragment , ValidationError } ,
1919 merge:: { Atomic , Merge } ,
2020 } ,
21- k8s_openapi:: {
22- api:: core:: v1:: { EnvVar , EnvVarSource , ObjectFieldSelector } ,
23- apimachinery:: pkg:: api:: resource:: Quantity ,
24- DeepMerge ,
25- } ,
21+ k8s_openapi:: { api:: core:: v1:: EnvVar , apimachinery:: pkg:: api:: resource:: Quantity , DeepMerge } ,
2622 kube:: { runtime:: reflector:: ObjectRef , CustomResource , ResourceExt } ,
2723 product_config_utils:: Configuration ,
2824 product_logging:: { self , spec:: Logging } ,
@@ -1076,36 +1072,14 @@ impl HbaseCluster {
10761072
10771073pub fn merged_env ( rolegroup_config : Option < & BTreeMap < String , String > > ) -> Vec < EnvVar > {
10781074 let merged_env: Vec < EnvVar > = if let Some ( rolegroup_config) = rolegroup_config {
1079- let mut env_vars_from_config : Vec < EnvVar > = rolegroup_config
1075+ rolegroup_config
10801076 . iter ( )
10811077 . map ( |( env_name, env_value) | EnvVar {
10821078 name : env_name. clone ( ) ,
10831079 value : Some ( env_value. to_owned ( ) ) ,
10841080 value_from : None ,
10851081 } )
1086- . collect ( ) ;
1087-
1088- // Needed by the hbase-entrypoint.sh script
1089- env_vars_from_config. push ( EnvVar {
1090- name : "NAMESPACE" . to_string ( ) ,
1091- value : None ,
1092- value_from : Some ( EnvVarSource {
1093- field_ref : Some ( ObjectFieldSelector {
1094- field_path : "metadata.namespace" . to_string ( ) ,
1095- ..Default :: default ( )
1096- } ) ,
1097- ..Default :: default ( )
1098- } ) ,
1099- } ) ;
1100-
1101- // Needed by the hbase-entrypoint.sh script
1102- env_vars_from_config. push ( EnvVar {
1103- name : "REGION_MOVER_OPTS" . to_string ( ) ,
1104- value : None ,
1105- value_from : None ,
1106- } ) ;
1107-
1108- env_vars_from_config
1082+ . collect ( )
11091083 } else {
11101084 vec ! [ ]
11111085 } ;
@@ -1155,12 +1129,14 @@ impl AnyServiceConfig {
11551129 }
11561130 }
11571131
1158- /// This function is called for all HBase roles but it currently only returns something for the
1159- /// region server roles.
1160- /// For all other roles it currently returns an empty string meaning there is no command to run
1161- /// before shutdown.
1162- /// This might change in the future.
1163- pub fn pre_shutdown_command ( & self ) -> String {
1132+ /// Returns command line arguments to pass on to the region mover tool.
1133+ /// The follwing arguments are excluded because they are already part of the
1134+ /// hbase-entrypoint.sh script.
1135+ /// The most important argument, '--regionserverhost' can only be computed on the Pod
1136+ /// because it contains the pod's hostname.
1137+ ///
1138+ /// Returns an empty string if the region mover is disabled or any other role is "self".
1139+ pub fn region_mover_args ( & self ) -> String {
11641140 match self {
11651141 AnyServiceConfig :: RegionServer ( config) => {
11661142 if config. region_mover . run_before_shutdown {
@@ -1175,12 +1151,6 @@ impl AnyServiceConfig {
11751151 } )
11761152 . unwrap_or ( DEFAULT_REGION_MOVER_TIMEOUT . as_secs ( ) ) ;
11771153 let mut command = vec ! [
1178- "bin/hbase" . to_string( ) ,
1179- "org.apache.hadoop.hbase.util.RegionMover" . to_string( ) ,
1180- "--regionserverhost" . to_string( ) ,
1181- "localhost" . to_string( ) ,
1182- "--operation" . to_string( ) ,
1183- "unload" . to_string( ) ,
11841154 "--maxthreads" . to_string( ) ,
11851155 config. region_mover. max_threads. to_string( ) ,
11861156 "--timeout" . to_string( ) ,
@@ -1189,21 +1159,20 @@ impl AnyServiceConfig {
11891159 if !config. region_mover . ack {
11901160 command. push ( "--noack" . to_string ( ) ) ;
11911161 }
1192- //
1162+
11931163 command. extend (
11941164 config
11951165 . region_mover
11961166 . extra_opts
11971167 . iter ( )
11981168 . map ( |s| escape ( std:: borrow:: Cow :: Borrowed ( s) ) . to_string ( ) ) ,
11991169 ) ;
1200- let command = command. join ( " " ) ;
1201- format ! ( "\" {command}\" " )
1170+ command. join ( " " )
12021171 } else {
1203- "\" \" " . to_string ( )
1172+ "" . to_string ( )
12041173 }
12051174 }
1206- _ => "\" \" " . to_string ( ) ,
1175+ _ => "" . to_string ( ) ,
12071176 }
12081177 }
12091178}
@@ -1217,10 +1186,7 @@ mod tests {
12171186 transform_all_roles_to_config, validate_all_roles_and_groups_config,
12181187 } ;
12191188
1220- use crate :: {
1221- merged_env, AnyServiceConfig , HbaseCluster , HbaseConfig , HbaseRole , RegionMover ,
1222- RegionServerConfig ,
1223- } ;
1189+ use crate :: { merged_env, HbaseCluster , HbaseRole } ;
12241190
12251191 use product_config:: { types:: PropertyNameKind , ProductConfigManager } ;
12261192
@@ -1315,72 +1281,4 @@ spec:
13151281 env_map. get( "TEST_VAR_FROM_MRG" )
13161282 ) ;
13171283 }
1318-
1319- #[ test]
1320- fn test_pre_shutdown_command_master ( ) {
1321- let config = AnyServiceConfig :: Master ( HbaseConfig :: default ( ) ) ;
1322- assert_eq ! ( config. pre_shutdown_command( ) , "\" \" " ) ;
1323- }
1324-
1325- #[ test]
1326- fn test_pre_shutdown_command_region_server_disabled ( ) {
1327- let config = AnyServiceConfig :: RegionServer ( RegionServerConfig :: default ( ) ) ;
1328- assert_eq ! ( config. pre_shutdown_command( ) , "\" \" " ) ;
1329- }
1330-
1331- #[ test]
1332- fn test_pre_shutdown_command_region_server_enabled_1 ( ) {
1333- let config = AnyServiceConfig :: RegionServer ( RegionServerConfig {
1334- region_mover : RegionMover {
1335- run_before_shutdown : true ,
1336- max_threads : 1 ,
1337- ack : true ,
1338- extra_opts : vec ! [ ] ,
1339- } ,
1340- ..RegionServerConfig :: default ( )
1341- } ) ;
1342- assert_eq ! ( config. pre_shutdown_command( ) , "\" bin/hbase org.apache.hadoop.hbase.util.RegionMover --regionserverhost localhost --operation unload --maxthreads 1 --timeout 3540\" " ) ;
1343- }
1344-
1345- #[ test]
1346- fn test_pre_shutdown_command_region_server_enabled_2 ( ) {
1347- let config = AnyServiceConfig :: RegionServer ( RegionServerConfig {
1348- region_mover : RegionMover {
1349- run_before_shutdown : true ,
1350- max_threads : 5 ,
1351- ack : false ,
1352- extra_opts : vec ! [ ] ,
1353- } ,
1354- ..RegionServerConfig :: default ( )
1355- } ) ;
1356- assert_eq ! ( config. pre_shutdown_command( ) , "\" bin/hbase org.apache.hadoop.hbase.util.RegionMover --regionserverhost localhost --operation unload --maxthreads 5 --timeout 3540 --noack\" " ) ;
1357- }
1358-
1359- #[ test]
1360- fn test_pre_shutdown_command_region_server_enabled_3 ( ) {
1361- let config = AnyServiceConfig :: RegionServer ( RegionServerConfig {
1362- region_mover : RegionMover {
1363- run_before_shutdown : true ,
1364- max_threads : 5 ,
1365- ack : false ,
1366- extra_opts : vec ! [ "-x" . to_string( ) , "/blubb" . to_string( ) ] ,
1367- } ,
1368- ..RegionServerConfig :: default ( )
1369- } ) ;
1370- assert_eq ! ( config. pre_shutdown_command( ) , "\" bin/hbase org.apache.hadoop.hbase.util.RegionMover --regionserverhost localhost --operation unload --maxthreads 5 --timeout 3540 --noack -x /blubb\" " ) ;
1371- }
1372-
1373- #[ test]
1374- fn test_pre_shutdown_command_region_server_enabled_4 ( ) {
1375- let config = AnyServiceConfig :: RegionServer ( RegionServerConfig {
1376- region_mover : RegionMover {
1377- run_before_shutdown : true ,
1378- max_threads : 1 ,
1379- ack : true ,
1380- extra_opts : vec ! [ "&&" . to_string( ) , "sudo gotcha!" . to_string( ) ] ,
1381- } ,
1382- ..RegionServerConfig :: default ( )
1383- } ) ;
1384- assert_eq ! ( config. pre_shutdown_command( ) , "\" bin/hbase org.apache.hadoop.hbase.util.RegionMover --regionserverhost localhost --operation unload --maxthreads 1 --timeout 3540 '&&' 'sudo gotcha'\\ !''\" " ) ;
1385- }
13861284}
0 commit comments