Skip to content

Commit

Permalink
chore: add configs
Browse files Browse the repository at this point in the history
Signed-off-by: themanforfree <[email protected]>
  • Loading branch information
themanforfree committed Feb 17, 2024
1 parent 9dfb7a2 commit fb8b97a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
45 changes: 45 additions & 0 deletions crates/utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ pub struct ClusterConfig {
/// Get xline server name
#[getset(get = "pub")]
name: String,
/// Xline server peer listen urls
#[getset(get = "pub")]
peer_listen_urls: Vec<String>,
/// Xline server peer advertise urls
#[getset(get = "pub")]
peer_advertise_urls: Vec<String>,
/// Xline server client listen urls
#[getset(get = "pub")]
client_listen_urls: Vec<String>,
/// Xline server client advertise urls
#[getset(get = "pub")]
client_advertise_urls: Vec<String>,
/// All the nodes in the xline cluster
#[getset(get = "pub")]
members: HashMap<String, Vec<String>>,
Expand Down Expand Up @@ -114,6 +126,10 @@ impl Default for ClusterConfig {
fn default() -> Self {
Self {
name: "default".to_owned(),
peer_listen_urls: vec!["http://127.0.0.1:2379".to_owned()],
peer_advertise_urls: vec!["http://127.0.0.1:2379".to_owned()],
client_listen_urls: vec!["http://127.0.0.1:2379".to_owned()],
client_advertise_urls: vec!["http://127.0.0.1:2379".to_owned()],
members: HashMap::from([(
"default".to_owned(),
vec!["http://127.0.0.1:2379".to_owned()],
Expand Down Expand Up @@ -160,8 +176,13 @@ impl ClusterConfig {
/// Generate a new `ClusterConfig` object
#[must_use]
#[inline]
#[allow(clippy::too_many_arguments)]
pub fn new(
name: String,
peer_listen_urls: Vec<String>,
peer_advertise_urls: Vec<String>,
client_listen_urls: Vec<String>,
client_advertise_urls: Vec<String>,
members: HashMap<String, Vec<String>>,
is_leader: bool,
curp: CurpConfig,
Expand All @@ -171,6 +192,10 @@ impl ClusterConfig {
) -> Self {
Self {
name,
peer_listen_urls,
peer_advertise_urls,
client_listen_urls,
client_advertise_urls,
members,
is_leader,
curp_config: curp,
Expand Down Expand Up @@ -1152,6 +1177,10 @@ mod tests {
name = 'node1'
is_leader = true
initial_cluster_state = 'new'
peer_listen_urls = ['127.0.0.1:2380']
peer_advertise_urls = ['127.0.0.1:2380']
client_listen_urls = ['127.0.0.1:2379']
client_advertise_urls = ['127.0.0.1:2379']
[cluster.server_timeout]
range_retry_timeout = '3s'
Expand Down Expand Up @@ -1243,6 +1272,10 @@ mod tests {
config.cluster,
ClusterConfig::new(
"node1".to_owned(),
vec!["127.0.0.1:2380".to_owned()],
vec!["127.0.0.1:2380".to_owned()],
vec!["127.0.0.1:2379".to_owned()],
vec!["127.0.0.1:2379".to_owned()],
HashMap::from_iter([
(
"node1".to_owned(),
Expand Down Expand Up @@ -1330,6 +1363,10 @@ mod tests {
r#"[cluster]
name = 'node1'
is_leader = true
peer_listen_urls = ['127.0.0.1:2380']
peer_advertise_urls = ['127.0.0.1:2380']
client_listen_urls = ['127.0.0.1:2379']
client_advertise_urls = ['127.0.0.1:2379']
[cluster.members]
node1 = ['127.0.0.1:2379']
Expand Down Expand Up @@ -1363,6 +1400,10 @@ mod tests {
config.cluster,
ClusterConfig::new(
"node1".to_owned(),
vec!["127.0.0.1:2380".to_owned()],
vec!["127.0.0.1:2380".to_owned()],
vec!["127.0.0.1:2379".to_owned()],
vec!["127.0.0.1:2379".to_owned()],
HashMap::from([
("node1".to_owned(), vec!["127.0.0.1:2379".to_owned()]),
("node2".to_owned(), vec!["127.0.0.1:2380".to_owned()]),
Expand Down Expand Up @@ -1411,6 +1452,10 @@ mod tests {
r#"[cluster]
name = 'node1'
is_leader = true
peer_listen_urls = ['127.0.0.1:2380']
peer_advertise_urls = ['127.0.0.1:2380']
client_listen_urls = ['127.0.0.1:2379']
client_advertise_urls = ['127.0.0.1:2379']
[cluster.members]
node1 = ['127.0.0.1:2379']
Expand Down
4 changes: 4 additions & 0 deletions crates/xline-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ impl Cluster {
let old_cluster = base_config.cluster();
let new_cluster = ClusterConfig::new(
name,
vec![],
vec![],
vec![],
vec![], // TODO
members,
is_leader,
old_cluster.curp_config().clone(),
Expand Down
16 changes: 16 additions & 0 deletions crates/xline/src/utils/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ pub struct ServerArgs {
/// Node name
#[clap(long)]
name: String,
/// Node peer listen urls
#[clap(long)]
peer_listen_urls: Vec<String>,
/// Node peer advertise urls
#[clap(long)]
peer_advertise_urls: Vec<String>,
/// Node client listen urls
#[clap(long)]
client_listen_urls: Vec<String>,
/// Node client advertise urls
#[clap(long)]
client_advertise_urls: Vec<String>,
/// Cluster peers. eg: node1=192.168.x.x:8080,192.168.x.x:8081,node2=192.168.x.x:8083
#[clap(long, value_parser = parse_members)]
members: HashMap<String, Vec<String>>,
Expand Down Expand Up @@ -256,6 +268,10 @@ impl From<ServerArgs> for XlineServerConfig {
let initial_cluster_state = args.initial_cluster_state.unwrap_or_default();
let cluster = ClusterConfig::new(
args.name,
args.peer_listen_urls,
args.peer_advertise_urls,
args.client_listen_urls,
args.client_advertise_urls,
args.members,
args.is_leader,
curp_config,
Expand Down

0 comments on commit fb8b97a

Please sign in to comment.