@@ -12,10 +12,10 @@ use stackable_operator::{
1212 k8s_openapi:: apimachinery:: pkg:: api:: resource:: Quantity ,
1313 kube:: { runtime:: reflector:: ObjectRef , CustomResource } ,
1414 product_config_utils:: { ConfigError , Configuration } ,
15- role_utils:: { Role , RoleGroupRef } ,
15+ role_utils:: { Role , RoleGroup , RoleGroupRef } ,
1616 schemars:: { self , JsonSchema } ,
1717} ;
18- use std:: collections:: BTreeMap ;
18+ use std:: { collections:: BTreeMap , str :: FromStr } ;
1919use strum:: { Display , EnumIter , EnumString } ;
2020
2121pub const APP_NAME : & str = "hbase" ;
@@ -47,8 +47,15 @@ pub const JVM_HEAP_FACTOR: f32 = 0.8;
4747
4848#[ derive( Snafu , Debug ) ]
4949pub enum Error {
50+ #[ snafu( display( "the role [{role}] is invalid and does not exist in HBase" ) ) ]
51+ InvalidRole {
52+ source : strum:: ParseError ,
53+ role : String ,
54+ } ,
5055 #[ snafu( display( "the HBase role [{role}] is missing from spec" ) ) ]
5156 MissingHbaseRole { role : String } ,
57+ #[ snafu( display( "the HBase role group [{role_group}] is missing from spec" ) ) ]
58+ MissingHbaseRoleGroup { role_group : String } ,
5259 #[ snafu( display( "fragment validation failure" ) ) ]
5360 FragmentValidationFailure { source : ValidationError } ,
5461}
@@ -278,6 +285,27 @@ impl HbaseCluster {
278285 }
279286 }
280287
288+ /// Get the RoleGroup struct for the given ref
289+ pub fn get_role_group (
290+ & self ,
291+ rolegroup_ref : & RoleGroupRef < HbaseCluster > ,
292+ ) -> Result < & RoleGroup < HbaseConfig > , Error > {
293+ let role_variant =
294+ HbaseRole :: from_str ( & rolegroup_ref. role ) . with_context ( |_| InvalidRoleSnafu {
295+ role : rolegroup_ref. role . to_owned ( ) ,
296+ } ) ?;
297+ let role = self
298+ . get_role ( & role_variant)
299+ . with_context ( || MissingHbaseRoleSnafu {
300+ role : role_variant. to_string ( ) ,
301+ } ) ?;
302+ role. role_groups
303+ . get ( & rolegroup_ref. role_group )
304+ . with_context ( || MissingHbaseRoleGroupSnafu {
305+ role_group : rolegroup_ref. role_group . to_owned ( ) ,
306+ } )
307+ }
308+
281309 pub fn root_dir ( & self ) -> String {
282310 self . spec
283311 . config
0 commit comments