-
Notifications
You must be signed in to change notification settings - Fork 129
Backport ccm main #1296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Backport ccm main #1296
Changes from 1 commit
8ba3fc3
7a34172
6215b08
7a38b56
41e26cf
dbbecb7
d6f3fb2
2b0c18c
a02254c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
use std::path::Path; | ||
use std::process::ExitStatus; | ||
use std::sync::Arc; | ||
|
||
use crate::ccm::lib::ip_allocator::NetPrefix; | ||
|
||
use super::logged_cmd::LoggedCmd; | ||
use super::logged_cmd::RunOptions; | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq)] | ||
pub(crate) enum DBType { | ||
Scylla, | ||
#[allow(dead_code)] | ||
Cassandra, | ||
} | ||
|
||
pub(crate) struct Ccm { | ||
config_dir: String, | ||
cmd: Arc<LoggedCmd>, | ||
} | ||
|
||
impl Ccm { | ||
pub(crate) fn new(config_dir: &Path, cmd: Arc<LoggedCmd>) -> Self { | ||
Self { | ||
config_dir: config_dir | ||
.to_str() | ||
.expect("Config dir not representable as str") | ||
.to_string(), | ||
cmd, | ||
} | ||
} | ||
} | ||
|
||
pub(crate) struct ClusterCreate<'ccm> { | ||
ccm: &'ccm mut Ccm, | ||
name: String, | ||
version: String, | ||
ip_prefix: String, | ||
db_type: DBType, | ||
} | ||
|
||
impl Ccm { | ||
pub(crate) fn cluster_create( | ||
&mut self, | ||
name: String, | ||
version: String, | ||
ip_prefix: NetPrefix, | ||
db_type: DBType, | ||
) -> ClusterCreate<'_> { | ||
ClusterCreate { | ||
ccm: self, | ||
name, | ||
version, | ||
ip_prefix: ip_prefix.to_string(), | ||
db_type, | ||
} | ||
} | ||
} | ||
|
||
impl ClusterCreate<'_> { | ||
pub(crate) async fn run(self) -> Result<ExitStatus, anyhow::Error> { | ||
let mut args: Vec<&str> = vec![ | ||
"create", | ||
self.name.as_str(), | ||
"--version", | ||
self.version.as_str(), | ||
"--ipprefix", | ||
self.ip_prefix.as_str(), | ||
"--config-dir", | ||
self.ccm.config_dir.as_str(), | ||
]; | ||
if self.db_type == DBType::Scylla { | ||
args.push("--scylla"); | ||
} | ||
self.ccm | ||
.cmd | ||
.run_command("ccm", &args, RunOptions::new()) | ||
.await | ||
} | ||
} | ||
Comment on lines
+34
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 🤩 What a great, clean design! Congrats! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now all parameters are accepted in the constructor of the command. I'll switch it to builder pattern soon, and of course move other commands too. |
||
|
||
pub(crate) struct ClusterPopulate<'ccm> { | ||
ccm: &'ccm mut Ccm, | ||
nodes: String, | ||
ip_prefix: String, | ||
} | ||
|
||
impl Ccm { | ||
pub(crate) fn cluster_populate( | ||
&mut self, | ||
nodes: &[u8], | ||
ip_prefix: NetPrefix, | ||
) -> ClusterPopulate<'_> { | ||
let nodes_string = nodes | ||
.iter() | ||
.map(|node| node.to_string()) | ||
.collect::<Vec<String>>() | ||
.join(":"); | ||
Comment on lines
+94
to
+98
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛏️ Let's use |
||
ClusterPopulate { | ||
ccm: self, | ||
nodes: nodes_string, | ||
ip_prefix: ip_prefix.to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl ClusterPopulate<'_> { | ||
pub(crate) async fn run(self) -> Result<ExitStatus, anyhow::Error> { | ||
let args: Vec<&str> = vec![ | ||
"populate", | ||
"--ipprefix", | ||
self.ip_prefix.as_str(), | ||
"--nodes", | ||
self.nodes.as_str(), | ||
"--config-dir", | ||
self.ccm.config_dir.as_str(), | ||
]; | ||
self.ccm | ||
.cmd | ||
.run_command("ccm", &args, RunOptions::new()) | ||
.await | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ use std::str::FromStr; | |
use anyhow::{Context, Error}; | ||
|
||
/// A subnet prefix for local network (127.x.x.x/24). | ||
#[derive(Debug, Clone)] | ||
#[derive(Debug, Clone, Copy)] | ||
pub(crate) struct NetPrefix(IpAddr); | ||
|
||
impl NetPrefix { | ||
|
@@ -23,7 +23,7 @@ impl NetPrefix { | |
Ok(IpAddr::from_str(&value)?.into()) | ||
} | ||
|
||
pub(super) fn to_str(&self) -> String { | ||
pub(super) fn to_str(self) -> String { | ||
match self.0 { | ||
IpAddr::V4(v4) => { | ||
let octets = v4.octets(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 I doubted There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to change this name anyway, but not because of |
||
|
@@ -39,7 +39,7 @@ impl NetPrefix { | |
} | ||
} | ||
|
||
pub(super) fn to_ipaddress(&self, id: u16) -> IpAddr { | ||
pub(super) fn to_ipaddress(self, id: u16) -> IpAddr { | ||
match self.0 { | ||
IpAddr::V4(v4) => { | ||
let mut octets = v4.octets(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod ccm_cmd; | ||
pub(crate) mod cluster; | ||
mod ip_allocator; | ||
mod logged_cmd; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is customary in fs-related APIs to accept
impl AsRef<Path>
.