Skip to content

Commit 3817a5f

Browse files
committed
refactor: move role and port constants to builder
1 parent 4822af4 commit 3817a5f

3 files changed

Lines changed: 92 additions & 80 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ pub mod kerberos;
77
pub mod opa;
88
pub mod properties;
99
pub mod resource;
10+
pub mod role;
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//! Build-side behaviour of [`HbaseRole`]: the `bin/hbase` CLI subcommand name and the
2+
//! port name/number mapping. These are operator/product knowledge, kept out of the `crd` module
3+
//! so it stays a pure API definition.
4+
5+
use crate::crd::{
6+
HBASE_MASTER_METRICS_PORT, HBASE_MASTER_PORT, HBASE_MASTER_UI_PORT,
7+
HBASE_REGIONSERVER_METRICS_PORT, HBASE_REGIONSERVER_PORT, HBASE_REGIONSERVER_UI_PORT,
8+
HBASE_REST_METRICS_PORT, HBASE_REST_PORT, HBASE_REST_UI_PORT, HbaseRole,
9+
};
10+
11+
const HBASE_UI_PORT_NAME_HTTP: &str = "ui-http";
12+
const HBASE_UI_PORT_NAME_HTTPS: &str = "ui-https";
13+
const HBASE_REST_PORT_NAME_HTTP: &str = "rest-http";
14+
const HBASE_REST_PORT_NAME_HTTPS: &str = "rest-https";
15+
const HBASE_METRICS_PORT_NAME: &str = "metrics";
16+
17+
impl HbaseRole {
18+
/// Returns the name of the role as it is needed by the `bin/hbase {cli_role_name} start` command.
19+
pub fn cli_role_name(&self) -> String {
20+
match self {
21+
HbaseRole::Master | HbaseRole::RegionServer => self.to_string(),
22+
// Of course it is not called "restserver", so we need to have this match
23+
// instead of just letting the Display impl do it's thing ;P
24+
HbaseRole::RestServer => "rest".to_string(),
25+
}
26+
}
27+
28+
/// Returns required port name and port number tuples depending on the role.
29+
///
30+
/// Hbase versions 2.6.* will have two ports for each role. The metrics are available on the
31+
/// UI port.
32+
pub fn ports(&self, https_enabled: bool) -> Vec<(String, u16)> {
33+
vec![
34+
(self.data_port_name(https_enabled), self.data_port()),
35+
(
36+
Self::ui_port_name(https_enabled).to_string(),
37+
self.ui_port(),
38+
),
39+
]
40+
}
41+
42+
pub fn data_port(&self) -> u16 {
43+
match self {
44+
HbaseRole::Master => HBASE_MASTER_PORT,
45+
HbaseRole::RegionServer => HBASE_REGIONSERVER_PORT,
46+
HbaseRole::RestServer => HBASE_REST_PORT,
47+
}
48+
}
49+
50+
pub fn data_port_name(&self, https_enabled: bool) -> String {
51+
match self {
52+
HbaseRole::Master | HbaseRole::RegionServer => self.to_string(),
53+
HbaseRole::RestServer => {
54+
if https_enabled {
55+
HBASE_REST_PORT_NAME_HTTPS.to_owned()
56+
} else {
57+
HBASE_REST_PORT_NAME_HTTP.to_owned()
58+
}
59+
}
60+
}
61+
}
62+
63+
pub fn ui_port(&self) -> u16 {
64+
match self {
65+
HbaseRole::Master => HBASE_MASTER_UI_PORT,
66+
HbaseRole::RegionServer => HBASE_REGIONSERVER_UI_PORT,
67+
HbaseRole::RestServer => HBASE_REST_UI_PORT,
68+
}
69+
}
70+
71+
/// Name of the port used by the Web UI, which depends on HTTPS usage
72+
pub fn ui_port_name(has_https_enabled: bool) -> &'static str {
73+
if has_https_enabled {
74+
HBASE_UI_PORT_NAME_HTTPS
75+
} else {
76+
HBASE_UI_PORT_NAME_HTTP
77+
}
78+
}
79+
80+
pub fn metrics_port(&self) -> u16 {
81+
match self {
82+
HbaseRole::Master => HBASE_MASTER_METRICS_PORT,
83+
HbaseRole::RegionServer => HBASE_REGIONSERVER_METRICS_PORT,
84+
HbaseRole::RestServer => HBASE_REST_METRICS_PORT,
85+
}
86+
}
87+
88+
pub fn metrics_port_name() -> &'static str {
89+
HBASE_METRICS_PORT_NAME
90+
}
91+
}

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

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ pub const HBASE_CLUSTER_DISTRIBUTED: &str = "hbase.cluster.distributed";
5151
pub const HBASE_ROOTDIR: &str = "hbase.rootdir";
5252
const DEFAULT_HBASE_ROOTDIR: &str = "/hbase";
5353

54-
const HBASE_UI_PORT_NAME_HTTP: &str = "ui-http";
55-
const HBASE_UI_PORT_NAME_HTTPS: &str = "ui-https";
56-
const HBASE_REST_PORT_NAME_HTTP: &str = "rest-http";
57-
const HBASE_REST_PORT_NAME_HTTPS: &str = "rest-https";
58-
const HBASE_METRICS_PORT_NAME: &str = "metrics";
59-
6054
pub const HBASE_MASTER_PORT: u16 = 16000;
6155
// HBase always uses 16010, regardless of http or https. On 2024-01-17 we decided in Arch-meeting that we want to stick
6256
// the port numbers to what the product is doing, so we get the least surprise for users - even when this means we have
@@ -278,80 +272,6 @@ impl HbaseRole {
278272
const DEFAULT_REST_SECRET_LIFETIME: Duration = Duration::from_days_unchecked(1);
279273
const DEFAULT_REST_SERVER_GRACEFUL_SHUTDOWN_TIMEOUT: Duration =
280274
Duration::from_minutes_unchecked(5);
281-
282-
/// Returns the name of the role as it is needed by the `bin/hbase {cli_role_name} start` command.
283-
pub fn cli_role_name(&self) -> String {
284-
match self {
285-
HbaseRole::Master | HbaseRole::RegionServer => self.to_string(),
286-
// Of course it is not called "restserver", so we need to have this match
287-
// instead of just letting the Display impl do it's thing ;P
288-
HbaseRole::RestServer => "rest".to_string(),
289-
}
290-
}
291-
292-
/// Returns required port name and port number tuples depending on the role.
293-
///
294-
/// Hbase versions 2.6.* will have two ports for each role. The metrics are available on the
295-
/// UI port.
296-
pub fn ports(&self, https_enabled: bool) -> Vec<(String, u16)> {
297-
vec![
298-
(self.data_port_name(https_enabled), self.data_port()),
299-
(
300-
Self::ui_port_name(https_enabled).to_string(),
301-
self.ui_port(),
302-
),
303-
]
304-
}
305-
306-
pub fn data_port(&self) -> u16 {
307-
match self {
308-
HbaseRole::Master => HBASE_MASTER_PORT,
309-
HbaseRole::RegionServer => HBASE_REGIONSERVER_PORT,
310-
HbaseRole::RestServer => HBASE_REST_PORT,
311-
}
312-
}
313-
314-
pub fn data_port_name(&self, https_enabled: bool) -> String {
315-
match self {
316-
HbaseRole::Master | HbaseRole::RegionServer => self.to_string(),
317-
HbaseRole::RestServer => {
318-
if https_enabled {
319-
HBASE_REST_PORT_NAME_HTTPS.to_owned()
320-
} else {
321-
HBASE_REST_PORT_NAME_HTTP.to_owned()
322-
}
323-
}
324-
}
325-
}
326-
327-
pub fn ui_port(&self) -> u16 {
328-
match self {
329-
HbaseRole::Master => HBASE_MASTER_UI_PORT,
330-
HbaseRole::RegionServer => HBASE_REGIONSERVER_UI_PORT,
331-
HbaseRole::RestServer => HBASE_REST_UI_PORT,
332-
}
333-
}
334-
335-
/// Name of the port used by the Web UI, which depends on HTTPS usage
336-
pub fn ui_port_name(has_https_enabled: bool) -> &'static str {
337-
if has_https_enabled {
338-
HBASE_UI_PORT_NAME_HTTPS
339-
} else {
340-
HBASE_UI_PORT_NAME_HTTP
341-
}
342-
}
343-
344-
pub fn metrics_port(&self) -> u16 {
345-
match self {
346-
HbaseRole::Master => HBASE_MASTER_METRICS_PORT,
347-
HbaseRole::RegionServer => HBASE_REGIONSERVER_METRICS_PORT,
348-
HbaseRole::RestServer => HBASE_REST_METRICS_PORT,
349-
}
350-
}
351-
352-
pub fn metrics_port_name() -> &'static str {
353-
HBASE_METRICS_PORT_NAME
354-
}
355275
}
356276

357277
fn default_resources(role: &HbaseRole) -> ResourcesFragment<HbaseStorageConfig, NoRuntimeLimits> {

0 commit comments

Comments
 (0)