diff --git a/.gitignore b/.gitignore index 2edc61b..82c0b30 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,8 @@ node_modules /deploy/terraform.tfstate.backup ./*.genin.yml ./*.genin.yaml +!/configs/*.yaml +!/configs/*.yml !/docs/examples/* /tests/.* .geninstate diff --git a/configs/cluster.genin.yml b/configs/cluster.genin.yml new file mode 100644 index 0000000..e9b80f8 --- /dev/null +++ b/configs/cluster.genin.yml @@ -0,0 +1,73 @@ +--- +# List of replicasets as an array +topology: + - name: router + # How many masters we want, by default equal 1 + replicasets_count: 1 + # Array of roles for this instance + roles: + - router + - failover-coordinator + - name: storage + # How many masters we want, by default equal 1 + replicasets_count: 2 + # Number of replicas in replicaset, default 0 + replication_factor: 2 + # Array of roles for this instance + roles: + - storage +# List of regions, datacenters, and servers +hosts: + - name: datacenter-1 + # Config with arbitrary key-values pairs + config: + # Specify http port to start counting from + http_port: 8081 + # Specify binary port to start counting from + binary_port: 3031 + # List of regions, datacenters, and servers + hosts: + - name: server-1 + # Config with arbitrary key-values pairs + config: + # Specify http port to start counting from + http_port: 8081 + # Specify binary port to start counting from + binary_port: 3031 + # Host or instance address (maybe IP or URI) + address: 192.168.16.11 + - name: server-2 + # Config with arbitrary key-values pairs + config: + # Specify http port to start counting from + http_port: 8081 + # Specify binary port to start counting from + binary_port: 3031 + # Host or instance address (maybe IP or URI) + address: 192.168.16.12 +# Failover management options +failover: + # Failover mode (stateful, eventual, disabled) + mode: stateful + # What is serve failover (stateboard, stateful) + state_provider: stateboard + # Params for chosen in state_provider failover type + stateboard_params: + # Uri on which the stateboard will be available + uri: "192.168.16.11:4401" + # Stateboard password + password: password +# Vars similar to those configured in the cartridge inventory +vars: + # Username under which the ansible will connect to the servers + ansible_user: ansible + # Ansible user password + ansible_password: ansible + # Application name + cartridge_app_name: myapp + # Cookie for connecting to the administrative console of the instances + cartridge_cluster_cookie: myapp-cookie + # Path to the application package + cartridge_package_path: /tmp/myapp.rpm + # Indicates if vshard must be bootstrapped on the cluster + cartridge_bootstrap_vshard: true diff --git a/src/main.rs b/src/main.rs index 2344245..f563a5d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,9 @@ const DEFAULT_STATEBOARD_PORT: u16 = 4401; const DEFAULT_HTTP_PORT: u16 = 8081; const DEFAULT_BINARY_PORT: u16 = 3031; +const DEFAULT_CFG_NAME: &str = "cluster.genin.yml"; +const DEFAULT_CFG: &[u8] = include_bytes!("../configs/cluster.genin.yml"); + fn main() -> Result<(), Box> { task::run_v2()?; Ok(()) diff --git a/src/task.rs b/src/task.rs index e5381f8..7de3417 100644 --- a/src/task.rs +++ b/src/task.rs @@ -199,8 +199,6 @@ pub trait Validate { type Error: fmt::Debug + ToString; fn validate(bytes: &[u8]) -> Result; - - fn whole_block(bytes: &[u8]) -> String; } trait AsError { diff --git a/src/task/args.rs b/src/task/args.rs index df6fe19..1ee8172 100644 --- a/src/task/args.rs +++ b/src/task/args.rs @@ -109,25 +109,6 @@ pub(super) fn read() -> ArgMatches { "Used to overwrite the output file, whether \ or not it exists.", ), - Arg::new("failover-mode") - .long("failover-mode") - .short('m') - .action(ArgAction::Set) - .default_value("stateful") - .help("(string): failover mode (stateful, eventual, disabled)"), - Arg::new("failover-state-provider") - .long("failover-state-provider") - .short('F') - .action(ArgAction::Set) - .default_value("stateboard") - .help("(string): failover state provider (etcd2, stateboard, disabled)"), - Arg::new("print") - .long("print") - .short('p') - .action(ArgAction::Set) - .default_values(["colorized", "ports"]) - .num_args(1..=3) - .help("(list, optional): cluster print output option"), Arg::new("quiet") .long("quiet") .short('q') diff --git a/src/task/cluster.rs b/src/task/cluster.rs index db55eba..364dd99 100644 --- a/src/task/cluster.rs +++ b/src/task/cluster.rs @@ -1,6 +1,6 @@ pub mod fs; -pub mod hst; -pub mod ins; +pub mod host; +pub mod instance; pub mod name; pub mod topology; @@ -15,26 +15,23 @@ use std::collections::HashMap; use std::fmt::{Debug, Display}; use std::fs::File; use std::io::{self, Write}; -use std::net::IpAddr; use std::path::{Path, PathBuf}; use thiserror::Error; -use crate::task::cluster::hst::v1::Host; -use crate::task::cluster::hst::v2::{HostV2, HostV2Config, WithHosts}; -use crate::task::cluster::hst::view::View; -use crate::task::cluster::ins::v2::{InstanceV2, InstanceV2Config, Instances}; -use crate::task::cluster::ins::Role; +use crate::task::cluster::host::hst::{Host, HostConfig, WithHosts}; +use crate::task::cluster::host::view::View; +use crate::task::cluster::instance::ins::{Instance, InstanceConfig, Instances}; +use crate::task::cluster::instance::Role; use crate::task::cluster::name::Name; use crate::task::cluster::topology::{InvalidTopologySet, Topology}; use crate::task::flv::Failover; -use crate::task::flv::{Mode, StateProvider, StateboardParams}; use crate::task::inventory::{Child, HostVars, Inventory}; use crate::task::vars::Vars; use crate::task::AsError; use crate::task::Validate; -use crate::{DEFAULT_BINARY_PORT, DEFAULT_HTTP_PORT}; +use crate::{DEFAULT_BINARY_PORT, DEFAULT_CFG, DEFAULT_CFG_NAME, DEFAULT_HTTP_PORT}; -use self::hst::v2::InvalidHostV2; +use self::host::hst::InvalidHost; use crate::task::flv::{FailoverError, InvalidFailover}; use crate::task::inventory::InventoryError; @@ -86,7 +83,7 @@ use super::{TypeError, DICT}; /// // hosts: /// // - name: server-10 /// // ip: 10.99.3.100 -/// hosts: HostV2, //TODO +/// hosts: Host, //TODO /// // Failover coordinator struct. /// // If cluster should be without failover (`failover_mode: "disabled"`) /// // this field will be skipped @@ -114,77 +111,22 @@ use super::{TypeError, DICT}; #[derive(Debug, PartialEq, Eq)] pub struct Cluster { pub topology: Topology, - pub hosts: HostV2, + pub hosts: Host, pub failover: Failover, pub vars: Vars, pub metadata: ClusterMetadata, } impl Default for Cluster { - /// Host can be Region, Datacenter, Server - /// ```yaml - /// hosts: - /// - name: selectel - /// hosts: - /// - name: moscow - /// config: - /// http_port: 8091 - /// binary_port: 3031 - /// distance: 10 - /// hosts: - /// - name: server-1 - /// config: - /// address: 192.168.99.11 - /// - name: server-2 - /// config: - /// address: 192.168.99.12 - /// - name: kaukaz - /// config: - /// distance: 20 - /// hosts: - /// - name: server-3 - /// config: - /// http_port: 8191 - /// binary_port: 3131 - /// ip: 10.99.3.100 - /// ``` fn default() -> Self { - let failover = Failover { - mode: Mode::Stateful, - state_provider: StateProvider::Stateboard, - failover_variants: super::flv::FailoverVariants::StateboardVariant(StateboardParams { - uri: super::flv::Uri { - address: hst::v2::Address::Ip(IpAddr::from([192, 168, 16, 11])), - port: 4401, - }, - password: String::from("password"), - }), - ..Default::default() - }; - - Self { - topology: Topology::default(), - hosts: HostV2::from("cluster") - .with_hosts(vec![HostV2::from("datacenter-1") - .with_hosts(vec![ - HostV2::from("server-1").with_config( - HostV2Config::from(IpAddr::from([192, 168, 16, 11])) - .with_ports((8081, 3031)), - ), - HostV2::from("server-2").with_config( - HostV2Config::from(IpAddr::from([192, 168, 16, 12])) - .with_ports((8081, 3031)), - ), - ]) - .with_config(HostV2Config::from((8081, 3031)))]) - .with_config(HostV2Config::from((8081, 3031))), - failover: failover.clone(), - vars: Vars::default().with_failover(failover), + let mut cluster = Cluster { metadata: ClusterMetadata { - paths: vec![PathBuf::from("cluster.genin.yml")], + paths: vec![DEFAULT_CFG_NAME.into()], }, - } - .spread() + ..serde_yaml::from_reader(DEFAULT_CFG).expect("cluster is yaml format") + }; + cluster.vars = cluster.vars.with_failover(cluster.failover.clone()); + cluster } } @@ -205,7 +147,7 @@ impl<'a> TryFrom<&'a ArgMatches> for Cluster { fn try_from(args: &'a ArgMatches) -> Result { match args.try_get_one::("source") { Ok(path) => { - let source = String::from("cluster.genin.yml"); + let source = String::from(DEFAULT_CFG_NAME); let path = path.unwrap_or(&source); let file = File::open(path)?; @@ -266,7 +208,7 @@ impl<'a> TryFrom<&'a Inventory> for Cluster { } else { name.get_parent_name().clone_with_index("replicaset") }; - let mut instance = InstanceV2::from((name, inventory_host)).with_roles( + let mut instance = Instance::from((name, inventory_host)).with_roles( inventory .all .children @@ -288,9 +230,9 @@ impl<'a> TryFrom<&'a Inventory> for Cluster { Ok(instance) }) - .collect::, ClusterError>>()?, + .collect::, ClusterError>>()?, ))?, - hosts: HostV2::from("cluster").with_hosts( + hosts: Host::from("cluster").with_hosts( inventory .all .children @@ -303,9 +245,9 @@ impl<'a> TryFrom<&'a Inventory> for Cluster { additional_config, }, .. - } => Some(HostV2 { + } => Some(Host { name: name.clone(), - config: HostV2Config::from(ansible_host.clone()) + config: HostConfig::from(ansible_host.clone()) .with_additional_config(additional_config.clone()) .with_ansible_host(ansible_host.clone()) .with_ports( @@ -330,21 +272,21 @@ impl<'a> TryFrom<&'a Inventory> for Cluster { .hosts .iter() .filter_map(|(name, instance)| { - let config = HostV2Config::from(&instance.config); + let config = HostConfig::from(&instance.config); debug!( "ansible_host: {} instance_address: {}", ansible_host, config.address() ); if ansible_host.eq(&config.address()) { - Some(InstanceV2 { + Some(Instance { name: name.clone(), stateboard: instance.stateboard.then_some(true), weight: None, failure_domains: Default::default(), roles: Vec::new(), cartridge_extra_env: instance.vars.clone(), - config: InstanceV2Config::from_inventory_host( + config: InstanceConfig::from_inventory_host( &instance, ), vars: instance.vars.clone(), @@ -354,12 +296,12 @@ impl<'a> TryFrom<&'a Inventory> for Cluster { None } }) - .collect::>(), + .collect::>(), ), }), Child::Replicaset { .. } => None, }) - .collect::>(), + .collect::>(), ), failover: inventory .all @@ -408,16 +350,9 @@ impl<'de> Deserialize<'de> for Cluster { #[derive(Deserialize)] #[serde(untagged)] enum ClusterHelper { - V1 { - instances: Vec, - hosts: Vec, - #[serde(default)] - failover: Failover, - vars: Vars, - }, - V2 { + Cluster { topology: Topology, - hosts: Vec, + hosts: Vec, #[serde(default)] failover: Failover, vars: Vars, @@ -426,32 +361,13 @@ impl<'de> Deserialize<'de> for Cluster { } ClusterHelper::deserialize(deserializer).and_then(|cluster| match cluster { - ClusterHelper::V1 { - instances, - hosts, - failover, - vars, - } => Ok(Cluster { - hosts: HostV2::from("cluster") - .with_hosts(hosts) - .with_http_port(DEFAULT_HTTP_PORT) - .with_binary_port(DEFAULT_BINARY_PORT), - topology: Topology::try_from(instances) - .map_err(|err| serde::de::Error::custom(err.to_string()))?, - failover, - vars, - metadata: ClusterMetadata { - paths: Default::default(), - }, - } - .spread()), - ClusterHelper::V2 { + ClusterHelper::Cluster { topology, hosts, failover, vars, } => Ok(Cluster { - hosts: HostV2::from("cluster") + hosts: Host::from("cluster") .with_hosts(hosts) .with_http_port(DEFAULT_HTTP_PORT) .with_binary_port(DEFAULT_BINARY_PORT), @@ -500,10 +416,6 @@ impl Validate for Cluster { fn validate(bytes: &[u8]) -> Result { serde_yaml::from_str(&check_placeholders(bytes)?) } - - fn whole_block(bytes: &[u8]) -> String { - String::from_utf8(bytes.to_vec()).unwrap() - } } pub fn check_placeholders(slice: &[u8]) -> Result { @@ -582,7 +494,7 @@ impl Cluster { std::mem::swap(&mut self.vars, &mut new.vars); std::mem::swap(&mut self.topology, &mut new.topology); - let hosts_diff = HostV2::merge(&mut self.hosts, &mut new.hosts, idiomatic); + let hosts_diff = Host::merge(&mut self.hosts, &mut new.hosts, idiomatic); debug!( "Instances to Add: {}", @@ -636,7 +548,7 @@ impl Cluster { let path = PathBuf::from( args.get_one::("output") .cloned() - .unwrap_or("cluster.genin.yml".into()), + .unwrap_or(DEFAULT_CFG_NAME.to_string()), ); let mut file = create_file_or_copy(path, args.get_flag("force"))?; @@ -892,25 +804,25 @@ impl From for ClusterError { } #[derive(Deserialize)] -struct HostV2Helper { +struct HostHelper { name: String, #[serde(default)] - config: HostV2Config, + config: HostConfig, #[serde(default)] - hosts: Vec, + hosts: Vec, } -impl From for HostV2 { - fn from(helper: HostV2Helper) -> Self { +impl From for Host { + fn from(helper: HostHelper) -> Self { let name = Name::from(helper.name.as_str()); helper.into_host_v2(name) } } -impl HostV2Helper { - fn into_host_v2(self, name: Name) -> HostV2 { +impl HostHelper { + fn into_host_v2(self, name: Name) -> Host { if self.hosts.is_empty() { - return HostV2 { + return Host { name, config: self.config, hosts: Vec::default(), @@ -920,7 +832,7 @@ impl HostV2Helper { }; } - HostV2 { + Host { hosts: self .hosts .into_iter() @@ -938,7 +850,7 @@ impl HostV2Helper { } } -struct TopologyMemberV1 { +struct TopologyMember { name: Name, count: usize, replicas: usize, @@ -947,7 +859,7 @@ struct TopologyMemberV1 { config: IndexMap, } -impl<'de> Deserialize<'de> for TopologyMemberV1 { +impl<'de> Deserialize<'de> for TopologyMember { fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, @@ -961,7 +873,6 @@ impl<'de> Deserialize<'de> for TopologyMemberV1 { replicas: usize, #[serde(default)] weight: usize, - #[serde(default)] roles: Vec, #[serde(default)] config: IndexMap, @@ -973,14 +884,11 @@ impl<'de> Deserialize<'de> for TopologyMemberV1 { count, replicas, weight, - mut roles, + roles, config, .. }| { - if roles.is_empty() { - roles = vec![Role::from(name.as_str())] - } - TopologyMemberV1 { + TopologyMember { name: Name::from(name), count, replicas, @@ -1040,7 +948,7 @@ impl std::fmt::Debug for InvalidCluster { .try_for_each(|host| -> Result<(), std::fmt::Error> { formatter.write_fmt(format_args!( "{:?}", - serde_yaml::from_value::(host.clone()) + serde_yaml::from_value::(host.clone()) .map(|mut host| { host.offset = "\n ".into(); host diff --git a/src/task/cluster/fs.rs b/src/task/cluster/fs.rs index 6afd9bd..cb742c5 100644 --- a/src/task/cluster/fs.rs +++ b/src/task/cluster/fs.rs @@ -69,26 +69,6 @@ impl FsInteraction { } } -#[allow(dead_code)] - -pub trait TryIntoFile { - type Error; - - fn try_into_file(self) -> Result, Self::Error>; -} - -impl TryIntoFile for Option { - type Error = std::io::Error; - - fn try_into_file(self) -> Result, Self::Error> { - if let Some(path) = self { - return File::open(path).map(Some); - } - - Ok(None) - } -} - pub struct IO { pub input: Option, pub output: Option, @@ -128,17 +108,6 @@ impl<'a> From<&'a ArgMatches> for IO { } } -#[allow(dead_code)] -pub trait TryMap { - type Error; - type Output; - - fn try_map(self, f: F) -> Result - where - Self: Sized, - F: FnOnce(Self) -> Result; -} - impl Display for IO where I: Display, diff --git a/src/task/cluster/hst/v2.rs b/src/task/cluster/host/hst.rs similarity index 85% rename from src/task/cluster/hst/v2.rs rename to src/task/cluster/host/hst.rs index ae95f2f..00ec518 100644 --- a/src/task/cluster/hst/v2.rs +++ b/src/task/cluster/host/hst.rs @@ -7,16 +7,16 @@ use std::{fmt, mem}; use tabled::papergrid::AnsiColor; use tabled::{builder::Builder, merge::Merge, Alignment, Tabled}; -use crate::task::cluster::hst::view::BG_BLACK; -use crate::task::cluster::hst::{merge_index_maps, v1::Host, v1::HostsVariants, view::View, IP}; -use crate::task::cluster::ins::v2::{FailureDomains, Instances}; +use crate::task::cluster::host::view::BG_BLACK; +use crate::task::cluster::host::{merge_index_maps, view::View, IP}; +use crate::task::cluster::instance::ins::{FailureDomains, Instances}; use crate::task::flv::{Failover, FailoverVariants}; use crate::task::state::Change; use crate::task::{AsError, ErrConfMapping, TypeError, DICT, LIST, NUMBER, STRING}; use crate::{ error::{GeninError, GeninErrorKind}, task::{ - cluster::ins::v2::{InstanceV2, InstanceV2Config}, + cluster::instance::ins::{Instance, InstanceConfig}, flv::Uri, }, task::{cluster::name::Name, inventory::InvHostConfig}, @@ -56,25 +56,25 @@ use super::view::{FG_BRIGHT_BLACK, FG_WHITE}; /// ip: 10.99.3.100 /// ``` #[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] -pub struct HostV2 { +pub struct Host { pub name: Name, - #[serde(skip_serializing_if = "HostV2Config::is_none", default)] - pub config: HostV2Config, + #[serde(skip_serializing_if = "HostConfig::is_none", default)] + pub config: HostConfig, #[serde(skip_serializing_if = "Vec::is_empty", default)] - pub hosts: Vec, + pub hosts: Vec, #[serde(skip)] - pub add_queue: IndexMap, + pub add_queue: IndexMap, #[serde(skip)] - pub delete_queue: IndexMap, + pub delete_queue: IndexMap, #[serde(skip_serializing_if = "Instances::is_empty", default)] pub instances: Instances, } -impl<'a> From<&'a str> for HostV2 { +impl<'a> From<&'a str> for Host { fn from(s: &'a str) -> Self { Self { name: Name::from(s), - config: HostV2Config::default(), + config: HostConfig::default(), hosts: Vec::default(), add_queue: IndexMap::default(), delete_queue: IndexMap::default(), @@ -83,11 +83,11 @@ impl<'a> From<&'a str> for HostV2 { } } -impl From for HostV2 { +impl From for Host { fn from(name: Name) -> Self { Self { name, - config: HostV2Config::default(), + config: HostConfig::default(), hosts: Vec::default(), add_queue: IndexMap::default(), delete_queue: IndexMap::default(), @@ -96,71 +96,17 @@ impl From for HostV2 { } } -impl From> for HostV2 { - fn from(hosts: Vec) -> Self { - HostV2 { - name: Name::from("cluster"), - config: HostV2Config::default(), - hosts: hosts - .into_iter() - .map(|host| HostV2::into_host_v2(Name::from("cluster"), host)) - .collect(), - add_queue: IndexMap::default(), - delete_queue: IndexMap::default(), - instances: Instances::default(), - } - } -} - -impl From for HostV2 { - fn from(host: Host) -> Self { - HostV2 { - name: Name::from(host.name), - config: HostV2Config { - http_port: host.ports.http_as_option(), - binary_port: host.ports.binary_as_option(), - address: Address::from(host.ip), - ansible_host: Default::default(), - distance: Some(host.distance).and_then(|distance| { - if distance.eq(&0) { - None - } else { - Some(distance) - } - }), - additional_config: IndexMap::new(), - }, - hosts: match host.hosts { - HostsVariants::None => Vec::new(), - HostsVariants::Hosts(hosts) => hosts.into_iter().map(HostV2::from).collect(), - }, - add_queue: IndexMap::default(), - delete_queue: IndexMap::default(), - instances: Instances::default(), - } - } -} - pub trait WithHosts { fn with_hosts(self, hosts: T) -> Self; } -impl WithHosts> for HostV2 { - fn with_hosts(self, hosts: Vec) -> Self { - Self { hosts, ..self } - } -} - -impl WithHosts> for HostV2 { +impl WithHosts> for Host { fn with_hosts(self, hosts: Vec) -> Self { - Self { - hosts: hosts.into_iter().map(HostV2::from).collect(), - ..self - } + Self { hosts, ..self } } } -impl PartialOrd for HostV2 { +impl PartialOrd for Host { fn partial_cmp(&self, other: &Self) -> Option { match self.instances.len().partial_cmp(&other.instances.len()) { Some(Ordering::Equal) => self.name.partial_cmp(&other.name), @@ -169,7 +115,7 @@ impl PartialOrd for HostV2 { } } -impl Ord for HostV2 { +impl Ord for Host { fn cmp(&self, other: &Self) -> Ordering { match self.instances.len().cmp(&other.instances.len()) { Ordering::Equal => self.name.cmp(&other.name), @@ -178,7 +124,7 @@ impl Ord for HostV2 { } } -impl Display for HostV2 { +impl Display for Host { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let collector = RefCell::new(vec![Vec::new(); self.depth()]); let depth = 0; @@ -193,64 +139,12 @@ impl Display for HostV2 { } } -impl HostV2 { - pub fn with_config(self, config: HostV2Config) -> Self { +impl Host { + #[cfg(test)] + pub fn with_config(self, config: HostConfig) -> Self { Self { config, ..self } } - fn into_host_v2(parent_name: Name, host: Host) -> HostV2 { - match host { - Host { - name, - ports, - ip, - hosts: HostsVariants::Hosts(hosts), - .. - } => { - let name = parent_name.with_raw_index(name); - HostV2 { - name: name.clone(), - config: HostV2Config { - http_port: ports.http_as_option(), - binary_port: ports.binary_as_option(), - address: Address::from(ip), - ansible_host: Default::default(), - distance: None, - additional_config: IndexMap::new(), - }, - hosts: hosts - .into_iter() - .map(|host| HostV2::into_host_v2(name.clone(), host)) - .collect(), - add_queue: IndexMap::default(), - delete_queue: IndexMap::default(), - instances: Instances::default(), - } - } - Host { - name, - ports, - ip, - hosts: HostsVariants::None, - .. - } => HostV2 { - name: parent_name.with_raw_index(name), - config: HostV2Config { - http_port: ports.http_as_option(), - binary_port: ports.binary_as_option(), - address: Address::from(ip), - ansible_host: Default::default(), - distance: None, - additional_config: IndexMap::new(), - }, - hosts: Vec::default(), - add_queue: IndexMap::default(), - delete_queue: IndexMap::default(), - instances: Instances::default(), - }, - } - } - pub fn spread(&mut self) { self.inner_spread(); } @@ -329,7 +223,7 @@ impl HostV2 { self.instances = instances } - fn push(&mut self, instance: InstanceV2) -> Result<(), GeninError> { + fn push(&mut self, instance: Instance) -> Result<(), GeninError> { let host = if let Some(host) = self.hosts.first_mut() { host } else { @@ -342,7 +236,7 @@ impl HostV2 { Ok(()) } - fn push_to_failure_domain(&mut self, mut instance: InstanceV2) -> Result<(), GeninError> { + fn push_to_failure_domain(&mut self, mut instance: Instance) -> Result<(), GeninError> { debug!( "trying to find reqested failure_domains inside host {} for instance {}", self.name, instance.name, @@ -363,7 +257,7 @@ impl HostV2 { // retain only hosts that contains one of failure domain members // failure_domains: ["dc-1"] -> vec!["dc-1"] - let mut failure_domain_hosts: Vec<&mut HostV2> = self + let mut failure_domain_hosts: Vec<&mut Host> = self .hosts .iter_mut() .filter_map(|host| { @@ -405,7 +299,7 @@ impl HostV2 { )) } - fn advertise_as_failure_domain(&mut self, instance: &mut InstanceV2) -> Result<(), GeninError> { + fn advertise_as_failure_domain(&mut self, instance: &mut Instance) -> Result<(), GeninError> { let failure_domains = instance.failure_domains.try_get_queue()?; let failure_domain_index = failure_domains .iter() @@ -436,10 +330,10 @@ impl HostV2 { } #[allow(unused)] - /// Count number for instances spreaded in HostV2 on all levels + /// Count number for instances spreaded in Host on all levels /// - /// * If top level HostV2 has 10 instances and instances not spreaded `size() = 0` - /// * If 20 instances already spreaded accross HostV2 childrens `size() = 20` + /// * If top level Host has 10 instances and instances not spreaded `size() = 0` + /// * If 20 instances already spreaded accross Host childrens `size() = 20` pub fn size(&self) -> usize { if self.hosts.is_empty() { self.instances.len() @@ -544,7 +438,7 @@ impl HostV2 { } } - pub fn lower_level_hosts(&self) -> Vec<&HostV2> { + pub fn lower_level_hosts(&self) -> Vec<&Host> { if self.hosts.is_empty() { vec![self] } else { @@ -582,11 +476,11 @@ impl HostV2 { Self { instances, ..self } } - pub fn with_add_queue(self, add_queue: IndexMap) -> Self { + pub fn with_add_queue(self, add_queue: IndexMap) -> Self { Self { add_queue, ..self } } - pub fn with_delete_queue(self, delete_queue: IndexMap) -> Self { + pub fn with_delete_queue(self, delete_queue: IndexMap) -> Self { Self { delete_queue, ..self @@ -609,7 +503,7 @@ impl HostV2 { .. } = failover { - self.instances.push(InstanceV2 { + self.instances.push(Instance { name: Name::from("stateboard"), stateboard: Some(true), weight: None, @@ -620,7 +514,7 @@ impl HostV2 { .into(), roles: Vec::new(), cartridge_extra_env: IndexMap::default(), - config: InstanceV2Config { + config: InstanceConfig { additional_config: vec![ ( String::from("listen"), @@ -633,7 +527,7 @@ impl HostV2 { ] .into_iter() .collect(), - ..InstanceV2Config::default() + ..InstanceConfig::default() }, vars: IndexMap::default(), view: View { @@ -648,7 +542,7 @@ impl HostV2 { // used only in tests pub fn with_http_port(self, http_port: u16) -> Self { Self { - config: HostV2Config { + config: HostConfig { http_port: Some(http_port), ..self.config }, @@ -660,7 +554,7 @@ impl HostV2 { // used only in tests pub fn with_binary_port(self, binary_port: u16) -> Self { Self { - config: HostV2Config { + config: HostConfig { binary_port: Some(binary_port), ..self.config }, @@ -672,7 +566,7 @@ impl HostV2 { // used only in tests pub fn with_address(self, address: Address) -> Self { Self { - config: HostV2Config { + config: HostConfig { address, ..self.config }, @@ -688,7 +582,7 @@ impl HostV2 { /// left [server-1, server-2, server-3] /// right [server-1, server-2] /// -> left [server-1, server-2] - pub fn merge(left: &mut HostV2, right: &mut HostV2, idiomatic: bool) -> Vec { + pub fn merge(left: &mut Host, right: &mut Host, idiomatic: bool) -> Vec { std::mem::swap(&mut left.config.distance, &mut right.config.distance); std::mem::swap( &mut left.config.additional_config, @@ -762,7 +656,7 @@ impl HostV2 { .iter_mut() .find(|left_host| left_host.name.eq(&right_host.name)) { - hosts_diff.extend(HostV2::merge(left_host, right_host, idiomatic)); + hosts_diff.extend(Host::merge(left_host, right_host, idiomatic)); } else { right_host.clear_instances(); left.hosts.push(right_host.clone()); @@ -823,7 +717,7 @@ impl HostV2 { .add_queue .iter() .map(|(_, instance)| instance.clone()) - .collect::>(); + .collect::>(); instances_for_spreading.sort(); self.instances = Instances::from(instances_for_spreading); } @@ -857,7 +751,7 @@ impl HostV2 { } #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq)] -pub struct HostV2Config { +pub struct HostConfig { #[serde(skip_serializing_if = "Option::is_none")] pub http_port: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -872,7 +766,7 @@ pub struct HostV2Config { pub additional_config: IndexMap, } -impl From<(u16, u16)> for HostV2Config { +impl From<(u16, u16)> for HostConfig { fn from(p: (u16, u16)) -> Self { Self { http_port: Some(p.0), @@ -882,7 +776,7 @@ impl From<(u16, u16)> for HostV2Config { } } -impl From for HostV2Config { +impl From for HostConfig { fn from(ip: IpAddr) -> Self { Self { address: Address::Ip(ip), @@ -891,7 +785,7 @@ impl From for HostV2Config { } } -impl From
for HostV2Config { +impl From
for HostConfig { fn from(address: Address) -> Self { Self { address, @@ -900,7 +794,7 @@ impl From
for HostV2Config { } } -impl From for HostV2Config { +impl From for HostConfig { fn from(distance: usize) -> Self { Self { distance: Some(distance), @@ -909,7 +803,7 @@ impl From for HostV2Config { } } -impl<'a> From<&'a InvHostConfig> for HostV2Config { +impl<'a> From<&'a InvHostConfig> for HostConfig { fn from(config: &'a InvHostConfig) -> Self { match config { InvHostConfig::Instance { @@ -944,7 +838,7 @@ impl<'a> From<&'a InvHostConfig> for HostV2Config { } } -impl From> for HostV2Config { +impl From> for HostConfig { fn from(additional_config: IndexMap) -> Self { let uri: Uri = additional_config .get("advertise_uri") @@ -961,7 +855,7 @@ impl From> for HostV2Config { } } -impl HostV2Config { +impl HostConfig { pub fn is_none(&self) -> bool { self.http_port.is_none() && self.binary_port.is_none() @@ -1003,7 +897,7 @@ impl HostV2Config { self.address.clone() } - pub fn merge(self, other: HostV2Config) -> Self { + pub fn merge(self, other: HostConfig) -> Self { Self { http_port: self.http_port.or(other.http_port), binary_port: self.binary_port.or(other.binary_port), @@ -1145,14 +1039,14 @@ pub struct IPSubnet(Vec); #[derive(Deserialize, Default)] #[serde(default)] -pub struct InvalidHostV2 { +pub struct InvalidHost { pub offset: String, name: Value, config: Value, hosts: Value, } -impl fmt::Debug for InvalidHostV2 { +impl fmt::Debug for InvalidHost { fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { // name: String match &self.name { @@ -1175,13 +1069,13 @@ impl fmt::Debug for InvalidHostV2 { } } - // config: InvalidHostV2Config + // config: InvalidHostConfig match &self.config { Value::Null => {} config @ Value::Mapping(_) => formatter.write_fmt(format_args!( "{} config: {:?}", &self.offset, - serde_yaml::from_value::(config.clone()) + serde_yaml::from_value::(config.clone()) .map(|mut config| { config.offset = format!("{} ", &self.offset); config @@ -1197,7 +1091,7 @@ impl fmt::Debug for InvalidHostV2 { } } - // hosts: InvalidHostV2 + // hosts: InvalidHost match &self.hosts { Value::Null => {} Value::Sequence(hosts) => { @@ -1207,7 +1101,7 @@ impl fmt::Debug for InvalidHostV2 { .try_for_each(|host| -> Result<(), std::fmt::Error> { formatter.write_fmt(format_args!( "{:?}", - serde_yaml::from_value::(host.clone()) + serde_yaml::from_value::(host.clone()) .map(|mut host| { host.offset = format!("{} ", &self.offset); host @@ -1231,7 +1125,7 @@ impl fmt::Debug for InvalidHostV2 { #[derive(Deserialize, Default)] #[serde(default)] -pub struct InvalidHostV2Config { +pub struct InvalidHostConfig { #[serde(skip)] offset: String, pub http_port: Value, @@ -1241,7 +1135,7 @@ pub struct InvalidHostV2Config { pub additional_config: Value, } -impl fmt::Debug for InvalidHostV2Config { +impl fmt::Debug for InvalidHostConfig { fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { // http_port: u16 match &self.http_port { diff --git a/src/task/cluster/hst.rs b/src/task/cluster/host/mod.rs similarity index 71% rename from src/task/cluster/hst.rs rename to src/task/cluster/host/mod.rs index d828ddf..7fe0010 100644 --- a/src/task/cluster/hst.rs +++ b/src/task/cluster/host/mod.rs @@ -1,10 +1,8 @@ +pub mod hst; pub mod view; -pub mod v1; -pub mod v2; - -use std::{fmt::Display, net::IpAddr, hash::Hash}; use indexmap::IndexMap; use serde::{Deserialize, Serialize}; +use std::{fmt::Display, hash::Hash, net::IpAddr}; #[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)] pub enum HostType { @@ -32,12 +30,6 @@ impl Display for HostType { } } -impl HostType { - pub fn is_server(&self) -> bool { - matches!(self, Self::Server) - } -} - #[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)] #[serde(untagged)] pub enum PortsVariants { @@ -51,26 +43,6 @@ impl Default for PortsVariants { } } -impl PortsVariants { - pub fn is_none(&self) -> bool { - matches!(self, Self::None) - } - - pub fn http_as_option(&self) -> Option { - match self { - PortsVariants::Ports(p) => Some(p.http), - PortsVariants::None => None, - } - } - - pub fn binary_as_option(&self) -> Option { - match self { - PortsVariants::Ports(p) => Some(p.binary), - PortsVariants::None => None, - } - } -} - #[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)] pub struct Ports { pub http: u16, @@ -116,16 +88,6 @@ impl ToString for IP { } } -impl IP { - pub fn is_none(&self) -> bool { - matches!(self, Self::None) - } -} - -pub fn is_null(u: &usize) -> bool { - matches!(u, 0) -} - pub fn merge_index_maps(left: IndexMap, right: IndexMap) -> IndexMap where A: Hash + Eq, diff --git a/src/task/cluster/host/snapshots/genin__task__cluster__host__test__host_with_failure_domains.snap b/src/task/cluster/host/snapshots/genin__task__cluster__host__test__host_with_failure_domains.snap new file mode 100644 index 0000000..f900bec --- /dev/null +++ b/src/task/cluster/host/snapshots/genin__task__cluster__host__test__host_with_failure_domains.snap @@ -0,0 +1,21 @@ +--- +source: src/task/cluster/host/test.rs +assertion_line: 488 +expression: uncolorize(&host) +--- ++----------------+----------------+----------------+-------------+-------------+ +| cluster | ++----------------+----------------+----------------+-------------+-------------+ +| dc-1 | dc-2 | ++----------------+----------------+----------------+-------------+-------------+ +| server-1 | server-2 | server-3 | server-4 | server-5 | ++----------------+----------------+----------------+-------------+-------------+ +| router-1 | storage-1-2 | storage-2-1 | storage-1-1 | storage-1-3 | +| 8081/3301 | 8081/3301 | 8081/3301 | 8081/3301 | 8081/3301 | ++----------------+----------------+----------------+-------------+-------------+ +| storage-2-3 | stateboard-1-1 | stateboard-1-2 | storage-2-2 | cache-2-1 | +| 8082/3302 | 8082/3302 | 8082/3302 | 8082/3302 | 8082/3302 | ++----------------+----------------+----------------+-------------+-------------+ +| stateboard-1-3 | | cache-2-3 | cache-2-2 | +| 8083/3303 | | 8083/3303 | 8083/3303 | ++----------------+----------------+----------------+-------------+-------------+ diff --git a/src/task/cluster/host/snapshots/genin__task__cluster__host__test__hosts_v2_print_table.snap b/src/task/cluster/host/snapshots/genin__task__cluster__host__test__hosts_v2_print_table.snap new file mode 100644 index 0000000..92623e9 --- /dev/null +++ b/src/task/cluster/host/snapshots/genin__task__cluster__host__test__hosts_v2_print_table.snap @@ -0,0 +1,32 @@ +--- +source: src/task/cluster/host/test.rs +assertion_line: 626 +expression: uncolorize(host) +--- ++-------------+-------------+--------------+--------------+--------------+--------------+--------------+--------------+ +| Cluster | ++-------------+-------------+--------------+--------------+--------------+--------------+--------------+--------------+ +| DC1 | DC2 | ++-------------+-------------+--------------+--------------+--------------+--------------+--------------+--------------+ +| Rack1 | Rack2 | Rack1 | Rack2 | ++-------------+-------------+--------------+--------------+--------------+--------------+--------------+--------------+ +| Server-1 | Server-2 | Server-3 | Server-4 | Server-5 | Server-6 | Server-7 | Server-8 | ++-------------+-------------+--------------+--------------+--------------+--------------+--------------+--------------+ +| router-1 | router-5 | router-3 | router-7 | router-2 | router-6 | router-4 | router-8 | +| 8081/3031 | 8081/3031 | 8081/3031 | 8081/3031 | 25000/26000 | 25000/26000 | 25000/26000 | 25000/26000 | ++-------------+-------------+--------------+--------------+--------------+--------------+--------------+--------------+ +| storage-1-1 | storage-1-5 | storage-1-3 | storage-1-7 | storage-1-2 | storage-1-6 | storage-1-4 | storage-1-8 | +| 8082/3032 | 8082/3032 | 8082/3032 | 8082/3032 | 25001/26001 | 25001/26001 | 25001/26001 | 25001/26001 | ++-------------+-------------+--------------+--------------+--------------+--------------+--------------+--------------+ +| storage-1-9 | storage-2-1 | storage-1-11 | storage-2-3 | storage-1-10 | storage-2-2 | storage-1-12 | storage-2-4 | +| 8083/3033 | 8083/3033 | 8083/3033 | 8083/3033 | 25002/26002 | 25002/26002 | 25002/26002 | 25002/26002 | ++-------------+-------------+--------------+--------------+--------------+--------------+--------------+--------------+ +| storage-2-5 | storage-2-9 | storage-2-7 | storage-2-11 | storage-2-6 | storage-2-10 | storage-2-8 | storage-2-12 | +| 8084/3034 | 8084/3034 | 8084/3034 | 8084/3034 | 25003/26003 | 25003/26003 | 25003/26003 | 25003/26003 | ++-------------+-------------+--------------+--------------+--------------+--------------+--------------+--------------+ +| storage-3-1 | storage-3-5 | storage-3-3 | storage-3-7 | storage-3-2 | storage-3-6 | storage-3-4 | storage-3-8 | +| 8085/3035 | 8085/3035 | 8085/3035 | 8085/3035 | 25004/26004 | 25004/26004 | 25004/26004 | 25004/26004 | ++-------------+-------------+--------------+--------------+--------------+--------------+--------------+--------------+ +| storage-3-9 | | storage-3-11 | | storage-3-10 | | storage-3-12 | | +| 8086/3036 | | 8086/3036 | | 25005/26005 | | 25005/26005 | | ++-------------+-------------+--------------+--------------+--------------+--------------+--------------+--------------+ diff --git a/src/task/cluster/host/snapshots/genin__task__cluster__host__test__hosts_v2_spreading.snap b/src/task/cluster/host/snapshots/genin__task__cluster__host__test__hosts_v2_spreading.snap new file mode 100644 index 0000000..423aaaa --- /dev/null +++ b/src/task/cluster/host/snapshots/genin__task__cluster__host__test__hosts_v2_spreading.snap @@ -0,0 +1,1191 @@ +--- +source: src/task/cluster/host/test.rs +assertion_line: 577 +expression: host +--- +Host { + name: Name { + childrens: [ + "Cluster", + ], + }, + config: HostConfig { + http_port: Some( + 8081, + ), + binary_port: Some( + 3031, + ), + address: Ip( + 192.168.123.11, + ), + ansible_host: None, + distance: None, + additional_config: {}, + }, + hosts: [ + Host { + name: Name { + childrens: [ + "Server-1", + ], + }, + config: HostConfig { + http_port: Some( + 8081, + ), + binary_port: Some( + 3031, + ), + address: Ip( + 192.168.123.11, + ), + ansible_host: None, + distance: None, + additional_config: {}, + }, + hosts: [], + add_queue: { + Name { + childrens: [ + "router", + "router-1", + ], + }: Instance { + name: Name { + childrens: [ + "router", + "router-1", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Router( + "router", + ), + FailoverCoordinator( + "failover-coordinator", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[37m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + Name { + childrens: [ + "storage", + "storage-1", + "storage-1-2", + ], + }: Instance { + name: Name { + childrens: [ + "storage", + "storage-1", + "storage-1-2", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[34m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + Name { + childrens: [ + "storage", + "storage-2", + "storage-2-2", + ], + }: Instance { + name: Name { + childrens: [ + "storage", + "storage-2", + "storage-2-2", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[36m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + }, + delete_queue: { + Name { + childrens: [ + "router", + "router-1", + ], + }: Instance { + name: Name { + childrens: [ + "router", + "router-1", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Router( + "router", + ), + FailoverCoordinator( + "failover-coordinator", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[37m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + Name { + childrens: [ + "storage", + "storage-1", + "storage-1-2", + ], + }: Instance { + name: Name { + childrens: [ + "storage", + "storage-1", + "storage-1-2", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[34m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + Name { + childrens: [ + "storage", + "storage-2", + "storage-2-2", + ], + }: Instance { + name: Name { + childrens: [ + "storage", + "storage-2", + "storage-2-2", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[36m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + }, + instances: Instances( + [ + Instance { + name: Name { + childrens: [ + "router", + "router-1", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Router( + "router", + ), + FailoverCoordinator( + "failover-coordinator", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: Some( + 8081, + ), + binary_port: Some( + 3031, + ), + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[37m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + Instance { + name: Name { + childrens: [ + "storage", + "storage-1", + "storage-1-2", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: Some( + 8082, + ), + binary_port: Some( + 3032, + ), + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[34m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + Instance { + name: Name { + childrens: [ + "storage", + "storage-2", + "storage-2-2", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: Some( + 8083, + ), + binary_port: Some( + 3033, + ), + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[36m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + ], + ), + }, + Host { + name: Name { + childrens: [ + "Server-2", + ], + }, + config: HostConfig { + http_port: Some( + 25000, + ), + binary_port: Some( + 26000, + ), + address: Ip( + 192.168.123.11, + ), + ansible_host: None, + distance: None, + additional_config: {}, + }, + hosts: [], + add_queue: { + Name { + childrens: [ + "storage", + "storage-1", + "storage-1-1", + ], + }: Instance { + name: Name { + childrens: [ + "storage", + "storage-1", + "storage-1-1", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[34m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + Name { + childrens: [ + "storage", + "storage-2", + "storage-2-1", + ], + }: Instance { + name: Name { + childrens: [ + "storage", + "storage-2", + "storage-2-1", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[36m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + }, + delete_queue: { + Name { + childrens: [ + "storage", + "storage-1", + "storage-1-1", + ], + }: Instance { + name: Name { + childrens: [ + "storage", + "storage-1", + "storage-1-1", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[34m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + Name { + childrens: [ + "storage", + "storage-2", + "storage-2-1", + ], + }: Instance { + name: Name { + childrens: [ + "storage", + "storage-2", + "storage-2-1", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[36m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + }, + instances: Instances( + [ + Instance { + name: Name { + childrens: [ + "storage", + "storage-1", + "storage-1-1", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: Some( + 25000, + ), + binary_port: Some( + 26000, + ), + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[34m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + Instance { + name: Name { + childrens: [ + "storage", + "storage-2", + "storage-2-1", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: Some( + 25001, + ), + binary_port: Some( + 26001, + ), + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[36m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + ], + ), + }, + ], + add_queue: { + Name { + childrens: [ + "router", + "router-1", + ], + }: Instance { + name: Name { + childrens: [ + "router", + "router-1", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Router( + "router", + ), + FailoverCoordinator( + "failover-coordinator", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[37m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + Name { + childrens: [ + "storage", + "storage-1", + "storage-1-1", + ], + }: Instance { + name: Name { + childrens: [ + "storage", + "storage-1", + "storage-1-1", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[34m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + Name { + childrens: [ + "storage", + "storage-1", + "storage-1-2", + ], + }: Instance { + name: Name { + childrens: [ + "storage", + "storage-1", + "storage-1-2", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[34m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + Name { + childrens: [ + "storage", + "storage-2", + "storage-2-1", + ], + }: Instance { + name: Name { + childrens: [ + "storage", + "storage-2", + "storage-2-1", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[36m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + Name { + childrens: [ + "storage", + "storage-2", + "storage-2-2", + ], + }: Instance { + name: Name { + childrens: [ + "storage", + "storage-2", + "storage-2-2", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[36m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + }, + delete_queue: { + Name { + childrens: [ + "router", + "router-1", + ], + }: Instance { + name: Name { + childrens: [ + "router", + "router-1", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Router( + "router", + ), + FailoverCoordinator( + "failover-coordinator", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[37m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + Name { + childrens: [ + "storage", + "storage-1", + "storage-1-1", + ], + }: Instance { + name: Name { + childrens: [ + "storage", + "storage-1", + "storage-1-1", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[34m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + Name { + childrens: [ + "storage", + "storage-1", + "storage-1-2", + ], + }: Instance { + name: Name { + childrens: [ + "storage", + "storage-1", + "storage-1-2", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[34m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + Name { + childrens: [ + "storage", + "storage-2", + "storage-2-1", + ], + }: Instance { + name: Name { + childrens: [ + "storage", + "storage-2", + "storage-2-1", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[36m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + Name { + childrens: [ + "storage", + "storage-2", + "storage-2-2", + ], + }: Instance { + name: Name { + childrens: [ + "storage", + "storage-2", + "storage-2-2", + ], + }, + stateboard: None, + weight: None, + failure_domains: NotProvided( + [], + ), + roles: [ + Storage( + "storage", + ), + ], + cartridge_extra_env: {}, + config: InstanceConfig { + http_port: None, + binary_port: None, + all_rw: None, + zone: None, + vshard_group: None, + additional_config: {}, + }, + vars: {}, + view: View { + color: AnsiColor { + prefix: "\u{1b}[36m", + suffix: "\u{1b}[39m", + }, + alignment: Horizontal( + Left, + ), + }, + }, + }, + instances: Instances( + [], + ), +} diff --git a/src/task/cluster/host/snapshots/genin__task__cluster__host__test__merge_with_decreasing_hosts.snap b/src/task/cluster/host/snapshots/genin__task__cluster__host__test__merge_with_decreasing_hosts.snap new file mode 100644 index 0000000..56d050b --- /dev/null +++ b/src/task/cluster/host/snapshots/genin__task__cluster__host__test__merge_with_decreasing_hosts.snap @@ -0,0 +1,27 @@ +--- +source: src/task/cluster/host/test.rs +assertion_line: 850 +expression: hosts_old +--- +name: cluster +config: + http_port: 8081 + binary_port: 3301 +hosts: + - name: dc-1 + hosts: + - name: server-1 + config: + address: 192.168.16.11 + - name: server-2 + config: + address: 192.168.16.12 + - name: dc-2 + hosts: + - name: server-4 + config: + address: 192.168.16.14 + - name: server-5 + config: + address: 192.168.16.15 + diff --git a/src/task/cluster/host/snapshots/genin__task__cluster__host__test__merge_with_increasig_hosts.snap b/src/task/cluster/host/snapshots/genin__task__cluster__host__test__merge_with_increasig_hosts.snap new file mode 100644 index 0000000..83c3f84 --- /dev/null +++ b/src/task/cluster/host/snapshots/genin__task__cluster__host__test__merge_with_increasig_hosts.snap @@ -0,0 +1,43 @@ +--- +source: src/task/cluster/host/test.rs +assertion_line: 774 +expression: hosts_old +--- +name: cluster +config: + http_port: 8081 + binary_port: 3301 +hosts: + - name: dc-1 + hosts: + - name: server-1 + config: + address: 192.168.32.101 + - name: server-2 + config: + address: 192.168.32.102 + - name: server-3 + config: + address: 192.168.16.13 + - name: dc-2 + hosts: + - name: server-4 + config: + address: 192.168.64.101 + - name: server-5 + config: + address: 192.168.64.102 + - name: server-6 + config: + address: 192.168.16.16 + - name: dc-3 + hosts: + - name: server-7 + config: + address: 192.168.16.17 + - name: server-8 + config: + address: 192.168.16.18 + - name: server-9 + config: + address: 192.168.16.19 diff --git a/src/task/cluster/hst/test.rs b/src/task/cluster/host/test.rs similarity index 57% rename from src/task/cluster/hst/test.rs rename to src/task/cluster/host/test.rs index 25c6673..7033ad6 100644 --- a/src/task/cluster/hst/test.rs +++ b/src/task/cluster/host/test.rs @@ -5,14 +5,14 @@ use tabled::Alignment; use crate::task::{ cluster::{ - hst::{ - v2::{Address, HostV2, HostV2Config, WithHosts}, + host::{ + hst::{Address, Host, HostConfig, WithHosts}, view::{View, FG_BLUE, FG_WHITE}, }, - ins::v2::{FailureDomains, InstanceV2, InstanceV2Config, Instances}, + instance::ins::{FailureDomains, Instance, InstanceConfig, Instances}, name::Name, topology::Topology, - HostV2Helper, + HostHelper, }, utils::uncolorize, }; @@ -35,11 +35,11 @@ hosts: "# .into(); - let hosts_v2: HostV2 = serde_yaml::from_str::(&hosts_v2_str) + let host: Host = serde_yaml::from_str::(&hosts_v2_str) .unwrap() .into(); - assert_eq!(hosts_v2.depth(), 2); + assert_eq!(host.depth(), 2); let hosts_v2_str: String = r#"--- name: cluster @@ -59,11 +59,11 @@ hosts: "# .into(); - let hosts_v2: HostV2 = serde_yaml::from_str::(&hosts_v2_str) + let host: Host = serde_yaml::from_str::(&hosts_v2_str) .unwrap() .into(); - assert_eq!(hosts_v2.depth(), 5); + assert_eq!(host.depth(), 5); } #[test] @@ -117,11 +117,11 @@ hosts: "# .into(); - let hosts_v2: HostV2 = serde_yaml::from_str::(&hosts_v2_str) + let host: Host = serde_yaml::from_str::(&hosts_v2_str) .unwrap() .into(); - assert_eq!(hosts_v2.width(), 10); + assert_eq!(host.width(), 10); } #[test] @@ -154,157 +154,155 @@ hosts: "# .into(); - let mut hosts_v2: HostV2 = HostV2::from( - serde_yaml::from_str::(&hosts_v2_str).unwrap(), - ) - .with_instances(Instances::from(vec![ - InstanceV2 { - name: Name::from("storage").with_index(1).with_index(1), - stateboard: None, - weight: None, - failure_domains: Default::default(), - roles: Vec::new(), - cartridge_extra_env: IndexMap::new(), - config: InstanceV2Config::default(), - vars: IndexMap::default(), - view: View { - color: FG_BLUE, - alignment: Alignment::left(), + let mut host: Host = Host::from(serde_yaml::from_str::(&hosts_v2_str).unwrap()) + .with_instances(Instances::from(vec![ + Instance { + name: Name::from("storage").with_index(1).with_index(1), + stateboard: None, + weight: None, + failure_domains: Default::default(), + roles: Vec::new(), + cartridge_extra_env: IndexMap::new(), + config: InstanceConfig::default(), + vars: IndexMap::default(), + view: View { + color: FG_BLUE, + alignment: Alignment::left(), + }, }, - }, - InstanceV2 { - name: Name::from("storage").with_index(1).with_index(2), - stateboard: None, - weight: None, - failure_domains: Default::default(), - roles: Vec::new(), - cartridge_extra_env: IndexMap::new(), - config: InstanceV2Config::default(), - vars: IndexMap::default(), - view: View { - color: FG_BLUE, - alignment: Alignment::left(), + Instance { + name: Name::from("storage").with_index(1).with_index(2), + stateboard: None, + weight: None, + failure_domains: Default::default(), + roles: Vec::new(), + cartridge_extra_env: IndexMap::new(), + config: InstanceConfig::default(), + vars: IndexMap::default(), + view: View { + color: FG_BLUE, + alignment: Alignment::left(), + }, }, - }, - InstanceV2 { - name: Name::from("storage").with_index(1).with_index(3), - stateboard: None, - weight: None, - failure_domains: Default::default(), - roles: Vec::new(), - cartridge_extra_env: IndexMap::new(), - config: InstanceV2Config::default(), - vars: IndexMap::default(), - view: View { - color: FG_BLUE, - alignment: Alignment::left(), + Instance { + name: Name::from("storage").with_index(1).with_index(3), + stateboard: None, + weight: None, + failure_domains: Default::default(), + roles: Vec::new(), + cartridge_extra_env: IndexMap::new(), + config: InstanceConfig::default(), + vars: IndexMap::default(), + view: View { + color: FG_BLUE, + alignment: Alignment::left(), + }, }, - }, - InstanceV2 { - name: Name::from("storage").with_index(1).with_index(4), - stateboard: None, - weight: None, - failure_domains: Default::default(), - roles: Vec::new(), - cartridge_extra_env: IndexMap::new(), - config: InstanceV2Config::default(), - vars: IndexMap::default(), - view: View { - color: FG_BLUE, - alignment: Alignment::left(), + Instance { + name: Name::from("storage").with_index(1).with_index(4), + stateboard: None, + weight: None, + failure_domains: Default::default(), + roles: Vec::new(), + cartridge_extra_env: IndexMap::new(), + config: InstanceConfig::default(), + vars: IndexMap::default(), + view: View { + color: FG_BLUE, + alignment: Alignment::left(), + }, }, - }, - InstanceV2 { - name: Name::from("storage").with_index(1).with_index(5), - stateboard: None, - weight: None, - failure_domains: Default::default(), - roles: Vec::new(), - cartridge_extra_env: IndexMap::new(), - config: InstanceV2Config::default(), - vars: IndexMap::default(), - view: View { - color: FG_BLUE, - alignment: Alignment::left(), + Instance { + name: Name::from("storage").with_index(1).with_index(5), + stateboard: None, + weight: None, + failure_domains: Default::default(), + roles: Vec::new(), + cartridge_extra_env: IndexMap::new(), + config: InstanceConfig::default(), + vars: IndexMap::default(), + view: View { + color: FG_BLUE, + alignment: Alignment::left(), + }, }, - }, - InstanceV2 { - name: Name::from("storage").with_index(1).with_index(6), - stateboard: None, - weight: None, - failure_domains: Default::default(), - roles: Vec::new(), - cartridge_extra_env: IndexMap::new(), - config: InstanceV2Config::default(), - vars: IndexMap::default(), - view: View { - color: FG_BLUE, - alignment: Alignment::left(), + Instance { + name: Name::from("storage").with_index(1).with_index(6), + stateboard: None, + weight: None, + failure_domains: Default::default(), + roles: Vec::new(), + cartridge_extra_env: IndexMap::new(), + config: InstanceConfig::default(), + vars: IndexMap::default(), + view: View { + color: FG_BLUE, + alignment: Alignment::left(), + }, }, - }, - InstanceV2 { - name: Name::from("storage").with_index(1).with_index(7), - stateboard: None, - weight: None, - failure_domains: Default::default(), - roles: Vec::new(), - cartridge_extra_env: IndexMap::new(), - config: InstanceV2Config::default(), - vars: IndexMap::default(), - view: View { - color: FG_BLUE, - alignment: Alignment::left(), + Instance { + name: Name::from("storage").with_index(1).with_index(7), + stateboard: None, + weight: None, + failure_domains: Default::default(), + roles: Vec::new(), + cartridge_extra_env: IndexMap::new(), + config: InstanceConfig::default(), + vars: IndexMap::default(), + view: View { + color: FG_BLUE, + alignment: Alignment::left(), + }, }, - }, - InstanceV2 { - name: Name::from("storage").with_index(1).with_index(8), - stateboard: None, - weight: None, - failure_domains: Default::default(), - roles: Vec::new(), - cartridge_extra_env: IndexMap::new(), - config: InstanceV2Config::default(), - vars: IndexMap::default(), - view: View { - color: FG_BLUE, - alignment: Alignment::left(), + Instance { + name: Name::from("storage").with_index(1).with_index(8), + stateboard: None, + weight: None, + failure_domains: Default::default(), + roles: Vec::new(), + cartridge_extra_env: IndexMap::new(), + config: InstanceConfig::default(), + vars: IndexMap::default(), + view: View { + color: FG_BLUE, + alignment: Alignment::left(), + }, }, - }, - InstanceV2 { - name: Name::from("storage").with_index(1).with_index(9), - stateboard: None, - weight: None, - failure_domains: Default::default(), - roles: Vec::new(), - cartridge_extra_env: IndexMap::new(), - config: InstanceV2Config::default(), - vars: IndexMap::default(), - view: View { - color: FG_BLUE, - alignment: Alignment::left(), + Instance { + name: Name::from("storage").with_index(1).with_index(9), + stateboard: None, + weight: None, + failure_domains: Default::default(), + roles: Vec::new(), + cartridge_extra_env: IndexMap::new(), + config: InstanceConfig::default(), + vars: IndexMap::default(), + view: View { + color: FG_BLUE, + alignment: Alignment::left(), + }, }, - }, - InstanceV2 { - name: Name::from("storage").with_index(1).with_index(10), - stateboard: None, - weight: None, - failure_domains: Default::default(), - roles: Vec::new(), - cartridge_extra_env: IndexMap::new(), - config: InstanceV2Config::default(), - vars: IndexMap::default(), - view: View { - color: FG_BLUE, - alignment: Alignment::left(), + Instance { + name: Name::from("storage").with_index(1).with_index(10), + stateboard: None, + weight: None, + failure_domains: Default::default(), + roles: Vec::new(), + cartridge_extra_env: IndexMap::new(), + config: InstanceConfig::default(), + vars: IndexMap::default(), + view: View { + color: FG_BLUE, + alignment: Alignment::left(), + }, }, - }, - ])); + ])); - assert_eq!(hosts_v2.size(), 0); + assert_eq!(host.size(), 0); - hosts_v2.spread(); + host.spread(); - assert_eq!(hosts_v2.size(), 10); + assert_eq!(host.size(), 10); } #[test] @@ -337,55 +335,54 @@ hosts: "# .into(); - let hosts_v2: HostV2 = serde_yaml::from_str::(&hosts_v2_str) + let host: Host = serde_yaml::from_str::(&hosts_v2_str) .unwrap() .into(); - hosts_v2 - .lower_level_hosts() + host.lower_level_hosts() .iter() .for_each(|host| println!("{}", host.name)); let lower_level_hosts_model = vec![ - HostV2::from( + Host::from( Name::from("cluster") .with_raw_index("dc-1") .with_raw_index("server-1"), ) - .with_config(HostV2Config::from(IpAddr::from([192, 168, 16, 11]))), - HostV2::from( + .with_config(HostConfig::from(IpAddr::from([192, 168, 16, 11]))), + Host::from( Name::from("cluster") .with_raw_index("dc-1") .with_raw_index("server-2"), ) - .with_config(HostV2Config::from(IpAddr::from([192, 168, 16, 12]))), - HostV2::from( + .with_config(HostConfig::from(IpAddr::from([192, 168, 16, 12]))), + Host::from( Name::from("cluster") .with_raw_index("dc-1") .with_raw_index("server-3"), ) - .with_config(HostV2Config::from(IpAddr::from([192, 168, 16, 13]))), - HostV2::from( + .with_config(HostConfig::from(IpAddr::from([192, 168, 16, 13]))), + Host::from( Name::from("cluster") .with_raw_index("dc-2") .with_raw_index("server-1"), ) - .with_config(HostV2Config::from(IpAddr::from([192, 168, 16, 14]))), - HostV2::from( + .with_config(HostConfig::from(IpAddr::from([192, 168, 16, 14]))), + Host::from( Name::from("cluster") .with_raw_index("dc-2") .with_raw_index("server-2"), ) - .with_config(HostV2Config::from(IpAddr::from([192, 168, 16, 15]))), + .with_config(HostConfig::from(IpAddr::from([192, 168, 16, 15]))), ]; assert_eq!( - hosts_v2.lower_level_hosts(), - lower_level_hosts_model.iter().collect::>() + host.lower_level_hosts(), + lower_level_hosts_model.iter().collect::>() ); } -fn failure_domain_test_host() -> HostV2 { +fn failure_domain_test_host() -> Host { let hosts_v2_str: String = r#"--- name: cluster config: @@ -414,19 +411,19 @@ hosts: "# .into(); - let mut host: HostV2 = serde_yaml::from_str::(&hosts_v2_str) + let mut host: Host = serde_yaml::from_str::(&hosts_v2_str) .unwrap() .into(); - fn new_instance(name: Name, failure_domains: FailureDomains) -> InstanceV2 { - InstanceV2 { + fn new_instance(name: Name, failure_domains: FailureDomains) -> Instance { + Instance { name, stateboard: Some(false), weight: None, failure_domains, roles: Vec::new(), cartridge_extra_env: IndexMap::new(), - config: InstanceV2Config::default(), + config: InstanceConfig::default(), vars: IndexMap::default(), view: View { color: FG_WHITE, @@ -465,9 +462,9 @@ hosts: } fn find_instance( - host: &HostV2, - mut predicate: impl FnMut(&InstanceV2) -> bool, -) -> Option<(&HostV2, &InstanceV2)> { + host: &Host, + mut predicate: impl FnMut(&Instance) -> bool, +) -> Option<(&Host, &Instance)> { let mut queue = VecDeque::new(); queue.push_front(host); @@ -505,7 +502,7 @@ fn hosts_force_failure_domain() { #[test] fn hosts_use_failure_domain_as_zone() { - fn failure_domain_instance_zone<'a>(host: &'a HostV2, instance_name: &str) -> Option<&'a str> { + fn failure_domain_instance_zone<'a>(host: &'a Host, instance_name: &str) -> Option<&'a str> { let (_, instance) = find_instance(host, |instance| instance.name.to_string() == instance_name).unwrap(); instance.config.zone.as_deref() @@ -550,10 +547,10 @@ fn hosts_v2_spreading() { let instances = Instances::from(&topology); - let mut hosts_v2 = HostV2::from("Cluster") + let mut host = Host::from("Cluster") .with_hosts(vec![ - HostV2::from("Server-1"), - HostV2::from("Server-2") + Host::from("Server-1"), + Host::from("Server-2") .with_http_port(25000) .with_binary_port(26000), ]) @@ -570,14 +567,14 @@ fn hosts_v2_spreading() { .collect(), ) .with_instances(instances) - .with_config(HostV2Config::from((8081, 3031))) + .with_config(HostConfig::from((8081, 3031))) .with_address(Address::from([192, 168, 123, 11])); - hosts_v2.spread(); + host.spread(); - println!("{}", &hosts_v2); + println!("{}", &host); - insta::assert_debug_snapshot!(hosts_v2); + insta::assert_debug_snapshot!(host); } #[test] @@ -600,92 +597,91 @@ fn hosts_v2_print_table() { let instances = Instances::from(&topology); - let mut hosts_v2 = HostV2::from("Cluster") + let mut host = Host::from("Cluster") .with_hosts(vec![ - HostV2::from("DC1").with_hosts(vec![ - HostV2::from("Rack1") - .with_hosts(vec![HostV2::from("Server-1"), HostV2::from("Server-2")]), - HostV2::from("Rack2") - .with_hosts(vec![HostV2::from("Server-3"), HostV2::from("Server-4")]), + Host::from("DC1").with_hosts(vec![ + Host::from("Rack1") + .with_hosts(vec![Host::from("Server-1"), Host::from("Server-2")]), + Host::from("Rack2") + .with_hosts(vec![Host::from("Server-3"), Host::from("Server-4")]), ]), - HostV2::from("DC2") + Host::from("DC2") .with_hosts(vec![ - HostV2::from("Rack1") - .with_hosts(vec![HostV2::from("Server-5"), HostV2::from("Server-6")]), - HostV2::from("Rack2") - .with_hosts(vec![HostV2::from("Server-7"), HostV2::from("Server-8")]), + Host::from("Rack1") + .with_hosts(vec![Host::from("Server-5"), Host::from("Server-6")]), + Host::from("Rack2") + .with_hosts(vec![Host::from("Server-7"), Host::from("Server-8")]), ]) .with_http_port(25000) .with_binary_port(26000), ]) .with_instances(instances) - .with_config(HostV2Config::from((8081, 3031))) + .with_config(HostConfig::from((8081, 3031))) .with_address(Address::from([192, 168, 123, 11])); - hosts_v2.spread(); + host.spread(); - println!("{}", hosts_v2); + println!("{}", host); - insta::assert_display_snapshot!(uncolorize(hosts_v2)); + insta::assert_display_snapshot!(uncolorize(host)); } #[test] fn hosts_v2_spread_stateboard() { - let mut hosts_v2 = HostV2::from("Cluster") + let mut host = Host::from("Cluster") .with_hosts(vec![ - HostV2::from("DC1").with_hosts(vec![ - HostV2::from("Rack1").with_hosts(vec![ - HostV2::from("Server-1") - .with_config(HostV2Config::from(IpAddr::from([192, 168, 123, 11]))), - HostV2::from("Server-2") - .with_config(HostV2Config::from(IpAddr::from([192, 168, 123, 12]))), + Host::from("DC1").with_hosts(vec![ + Host::from("Rack1").with_hosts(vec![ + Host::from("Server-1") + .with_config(HostConfig::from(IpAddr::from([192, 168, 123, 11]))), + Host::from("Server-2") + .with_config(HostConfig::from(IpAddr::from([192, 168, 123, 12]))), ]), - HostV2::from("Rack2").with_hosts(vec![ - HostV2::from("Server-3") - .with_config(HostV2Config::from(IpAddr::from([192, 168, 123, 101]))), - HostV2::from("Server-4") - .with_config(HostV2Config::from(IpAddr::from([192, 168, 123, 102]))), + Host::from("Rack2").with_hosts(vec![ + Host::from("Server-3") + .with_config(HostConfig::from(IpAddr::from([192, 168, 123, 101]))), + Host::from("Server-4") + .with_config(HostConfig::from(IpAddr::from([192, 168, 123, 102]))), ]), ]), - HostV2::from("DC2") + Host::from("DC2") .with_hosts(vec![ - HostV2::from("Rack1").with_hosts(vec![ - HostV2::from("Server-5") - .with_config(HostV2Config::from(IpAddr::from([192, 168, 66, 11]))), - HostV2::from("Server-6") - .with_config(HostV2Config::from(IpAddr::from([192, 168, 66, 12]))), + Host::from("Rack1").with_hosts(vec![ + Host::from("Server-5") + .with_config(HostConfig::from(IpAddr::from([192, 168, 66, 11]))), + Host::from("Server-6") + .with_config(HostConfig::from(IpAddr::from([192, 168, 66, 12]))), ]), - HostV2::from("Rack2").with_hosts(vec![ - HostV2::from("Server-7") - .with_config(HostV2Config::from(IpAddr::from([192, 168, 66, 101]))), - HostV2::from("Server-8") - .with_config(HostV2Config::from(IpAddr::from([192, 168, 66, 101]))), + Host::from("Rack2").with_hosts(vec![ + Host::from("Server-7") + .with_config(HostConfig::from(IpAddr::from([192, 168, 66, 101]))), + Host::from("Server-8") + .with_config(HostConfig::from(IpAddr::from([192, 168, 66, 101]))), ]), ]) .with_http_port(25000) .with_binary_port(26000), ]) - .with_config(HostV2Config::from((8081, 3031))); + .with_config(HostConfig::from((8081, 3031))); let address = Address::Ip("192.168.66.101".parse().unwrap()); - hosts_v2.instances.push(InstanceV2 { + host.instances.push(Instance { name: Name::from("stateboard"), stateboard: Some(true), weight: None, - failure_domains: vec![hosts_v2.get_name_by_address(&address).unwrap().to_string()].into(), + failure_domains: vec![host.get_name_by_address(&address).unwrap().to_string()].into(), roles: Vec::new(), cartridge_extra_env: IndexMap::new(), - config: InstanceV2Config::default(), + config: InstanceConfig::default(), vars: IndexMap::default(), view: View::default(), }); - hosts_v2.spread(); + host.spread(); assert_eq!( - hosts_v2 - .hosts + host.hosts .last() .unwrap() .hosts @@ -728,7 +724,7 @@ hosts: address: 192.168.64.102 "#; - let mut hosts_old = serde_yaml::from_str::(hosts_old_str).unwrap(); + let mut hosts_old = serde_yaml::from_str::(hosts_old_str).unwrap(); let hosts_new_str = r#"--- name: cluster @@ -771,9 +767,9 @@ hosts: address: 192.168.16.19 "#; - let mut hosts_new = serde_yaml::from_str::(hosts_new_str).unwrap(); + let mut hosts_new = serde_yaml::from_str::(hosts_new_str).unwrap(); - HostV2::merge(&mut hosts_old, &mut hosts_new, true); + Host::merge(&mut hosts_old, &mut hosts_new, true); insta::assert_yaml_snapshot!(hosts_old); } @@ -821,7 +817,7 @@ hosts: address: 192.168.16.19 "#; - let mut hosts_old = serde_yaml::from_str::(hosts_old_str).unwrap(); + let mut hosts_old = serde_yaml::from_str::(hosts_old_str).unwrap(); let hosts_new_str = r#"--- name: cluster @@ -847,9 +843,9 @@ hosts: address: 192.168.64.102 "#; - let mut hosts_new = serde_yaml::from_str::(hosts_new_str).unwrap(); + let mut hosts_new = serde_yaml::from_str::(hosts_new_str).unwrap(); - HostV2::merge(&mut hosts_old, &mut hosts_new, true); + Host::merge(&mut hosts_old, &mut hosts_new, true); insta::assert_yaml_snapshot!(hosts_old); } diff --git a/src/task/cluster/hst/view.rs b/src/task/cluster/host/view.rs similarity index 100% rename from src/task/cluster/hst/view.rs rename to src/task/cluster/host/view.rs diff --git a/src/task/cluster/hst/v1.rs b/src/task/cluster/hst/v1.rs deleted file mode 100644 index 7eedb18..0000000 --- a/src/task/cluster/hst/v1.rs +++ /dev/null @@ -1,45 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use crate::task::cluster::hst::{is_null, HostType, PortsVariants, IP}; - -#[derive(Serialize, Deserialize, Default, Debug, PartialEq, Eq)] -pub struct Host { - pub name: String, - #[serde(rename = "type", skip_serializing_if = "HostType::is_server", default)] - pub htype: HostType, - #[serde(skip_serializing_if = "is_null", default)] - pub distance: usize, - #[serde(skip_serializing_if = "PortsVariants::is_none", default)] - pub ports: PortsVariants, - #[serde(skip_serializing_if = "IP::is_none", default)] - pub ip: IP, - #[serde(skip_serializing_if = "HostsVariants::is_none", default)] - pub hosts: HostsVariants, -} - -#[allow(unused)] -impl Host { - #[inline] - pub fn name(&self) -> &str { - &self.name - } -} - -#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] -#[serde(untagged)] -pub enum HostsVariants { - Hosts(Vec), - None, -} - -impl Default for HostsVariants { - fn default() -> Self { - Self::None - } -} - -impl HostsVariants { - pub fn is_none(&self) -> bool { - matches!(self, Self::None) - } -} diff --git a/src/task/cluster/ins/v1.rs b/src/task/cluster/ins/v1.rs deleted file mode 100644 index c76ea4b..0000000 --- a/src/task/cluster/ins/v1.rs +++ /dev/null @@ -1,133 +0,0 @@ -use std::cmp::Ordering; - -use serde::{Serialize, Deserialize, de::Error}; -use indexmap::IndexMap; -use serde_yaml::Value; - -use crate::task::cluster::ins::{Type, count_one, default_weight, is_zero, Role, is_false}; - -#[derive(Serialize, Clone, Debug, Default, PartialEq, Eq)] -/// Some tarantool cartridge instance -/// -/// ```yaml -/// - name: "catalogue" -/// type: "storage" -/// count: 1 -/// replicas: 2 -/// weight: 10 -/// ``` -pub struct Instance { - pub name: String, - #[serde(skip)] - pub parent: String, - #[serde(rename = "type")] - pub itype: Type, - #[serde(default)] - pub count: usize, - #[serde(default, skip_serializing_if = "is_zero")] - pub replicas: usize, - #[serde(default = "default_weight", skip_serializing_if = "is_zero")] - pub weight: usize, - #[serde(default, skip_serializing_if = "is_false")] - pub stateboard: bool, - #[serde(default)] - pub roles: Vec, - #[serde(default, skip_serializing_if = "IndexMap::is_empty")] - pub config: IndexMap, -} - -impl PartialOrd for Instance { - fn partial_cmp(&self, other: &Self) -> Option { - match (self.itype, other.itype) { - (Type::Router, Type::Storage) - | (Type::Router, Type::Custom) - | (Type::Router, Type::Replica) - | (Type::Storage, Type::Custom) - | (Type::Storage, Type::Replica) => Some(Ordering::Less), - (left, right) if left == right => self.name.partial_cmp(&other.name), - _ => Some(Ordering::Greater), - } - } -} - -impl Ord for Instance { - fn cmp(&self, other: &Self) -> Ordering { - match (self.itype, other.itype) { - (Type::Router, Type::Storage) - | (Type::Router, Type::Custom) - | (Type::Router, Type::Replica) - | (Type::Storage, Type::Custom) - | (Type::Storage, Type::Replica) => Ordering::Less, - (left, right) if left == right => self.name.cmp(&other.name), - _ => Ordering::Greater, - } - } -} - -impl<'de> Deserialize<'de> for Instance { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - #[derive(Deserialize, Default)] - #[serde(default)] - struct InstanceHelper { - pub name: String, - #[serde(rename = "type")] - pub itype: Type, - pub count: usize, - #[serde(default = "count_one")] - pub replicas: usize, - #[serde(default = "default_weight")] - pub weight: usize, - pub roles: Vec, - pub config: IndexMap, - } - - if let Ok(InstanceHelper { - mut roles, - mut itype, - name, - count, - replicas, - weight, - config, - .. - }) = InstanceHelper::deserialize(deserializer) - { - // If type not defined in yaml let's try to infer based on name - if itype == Type::Unknown { - itype = Type::from(name.as_str()); - } - - if roles.is_empty() { - roles = vec![Role::from(name.as_str())] - } - if itype == Type::Storage { - return Ok(Instance { - name, - itype, - count, - replicas, - weight, - roles, - config, - ..Default::default() - }); - } else { - return Ok(Instance { - itype: Type::from(name.as_str()), - name, - count, - replicas: 0, - weight: 0, - roles, - config, - ..Default::default() - }); - } - } - Err(Error::custom("Error then deserializing Instance")) - } -} - diff --git a/src/task/cluster/ins/v2.rs b/src/task/cluster/instance/ins.rs similarity index 87% rename from src/task/cluster/ins/v2.rs rename to src/task/cluster/instance/ins.rs index bb329f8..1a6bd38 100644 --- a/src/task/cluster/ins/v2.rs +++ b/src/task/cluster/instance/ins.rs @@ -8,34 +8,34 @@ use std::vec::IntoIter; use tabled::papergrid::AnsiColor; use crate::error::{GeninError, GeninErrorKind}; -use crate::task::cluster::hst::merge_index_maps; -use crate::task::cluster::hst::v2::HostV2Config; -use crate::task::cluster::hst::view::View; -use crate::task::cluster::ins::Role; +use crate::task::cluster::host::hst::HostConfig; +use crate::task::cluster::host::merge_index_maps; +use crate::task::cluster::host::view::View; +use crate::task::cluster::instance::Role; use crate::task::cluster::name::Name; use crate::task::inventory::{InvHostConfig, InventoryHost}; #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct Instances(Vec); +pub struct Instances(Vec); -impl From> for Instances { - fn from(instances: Vec) -> Self { +impl From> for Instances { + fn from(instances: Vec) -> Self { Self(instances) } } impl Instances { - pub fn iter(&self) -> Iter { + pub fn iter(&self) -> Iter { self.0.iter() } - pub fn iter_mut(&mut self) -> IterMut { + pub fn iter_mut(&mut self) -> IterMut { self.0.iter_mut() } #[allow(unused)] // used in tests - pub fn into_iter(self) -> IntoIter { + pub fn into_iter(self) -> IntoIter { self.0.into_iter() } @@ -47,7 +47,7 @@ impl Instances { self.0.len() } - pub fn get(&self, index: usize) -> Option<&InstanceV2> { + pub fn get(&self, index: usize) -> Option<&Instance> { self.0.get(index) } @@ -57,29 +57,29 @@ impl Instances { #[allow(unused)] // used in tests - pub fn pop(&mut self) -> Option { + pub fn pop(&mut self) -> Option { self.0.pop() } #[allow(unused)] // used in tests - pub fn first(&self) -> Option<&InstanceV2> { + pub fn first(&self) -> Option<&Instance> { self.0.first() } #[allow(unused)] // used in tests - pub fn last(&self) -> Option<&InstanceV2> { + pub fn last(&self) -> Option<&Instance> { self.0.last() } - pub fn push(&mut self, instance: InstanceV2) { + pub fn push(&mut self, instance: Instance) { self.0.push(instance) } pub fn retain(&mut self, f: F) where - F: FnMut(&InstanceV2) -> bool, + F: FnMut(&Instance) -> bool, { self.0.retain(f) } @@ -88,15 +88,15 @@ impl Instances { self.0.clear() } - pub fn extend>(&mut self, iter: I) { + pub fn extend>(&mut self, iter: I) { self.0.extend(iter) } } impl IntoIterator for Instances { - type Item = InstanceV2; + type Item = Instance; - type IntoIter = std::vec::IntoIter; + type IntoIter = std::vec::IntoIter; fn into_iter(self) -> Self::IntoIter { self.0.into_iter() @@ -120,7 +120,7 @@ pub struct Replicaset { pub weight: Option, pub failure_domains: Vec, pub roles: Vec, - pub config: InstanceV2Config, + pub config: InstanceConfig, pub view: View, } @@ -138,28 +138,28 @@ pub struct Replicaset { /// instances with different names but similar configuration (based on the parent) /// ```rust /// let instances = vec![ -/// InstanceV2 { +/// Instance { /// name: Name::from("catalogue").with_index(1).with_index(1), /// stateboard: None, /// weight: Some(10), /// failure_domains: Default::default(), /// roles: vec![String::from("catalogue")], /// cartridge_extra_env: IndexMap::default(), -/// config: InstanceV2Config::default(), +/// config: InstanceConfig::default(), /// vars: IndexMap::default(), /// view: View { /// alignment: Alignment::left(), /// color: FG_BLUE, /// }, /// }, -/// InstanceV2 { +/// Instance { /// name: Name::from("catalogue").with_index(1).with_index(2), /// stateboard: None, /// weight: Some(10), /// failure_domains: Default::default(), /// roles: vec![String::from("catalogue")], /// cartridge_extra_env: IndexMap::default(), -/// config: InstanceV2Config::default(), +/// config: InstanceConfig::default(), /// vars: IndexMap::default(), /// view: View { /// alignment: Alignment::left(), @@ -169,7 +169,7 @@ pub struct Replicaset { /// ] /// ``` #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] -pub struct InstanceV2 { +pub struct Instance { /// Instance name with replicaset number and the index of the instance in the replicaset pub name: Name, //TODO: remove stateboard option @@ -180,13 +180,13 @@ pub struct InstanceV2 { pub failure_domains: FailureDomains, pub roles: Vec, pub cartridge_extra_env: IndexMap, - pub config: InstanceV2Config, + pub config: InstanceConfig, pub vars: IndexMap, #[serde(skip)] pub view: View, } -impl PartialOrd for InstanceV2 { +impl PartialOrd for Instance { fn partial_cmp(&self, other: &Self) -> Option { match self.name.partial_cmp(&other.name) { Some(Ordering::Equal) => Some(Ordering::Equal), @@ -195,13 +195,13 @@ impl PartialOrd for InstanceV2 { } } -impl Ord for InstanceV2 { +impl Ord for Instance { fn cmp(&self, other: &Self) -> Ordering { self.name.cmp(&other.name) } } -impl<'a> From<(&'a Name, &'a InventoryHost)> for InstanceV2 { +impl<'a> From<(&'a Name, &'a InventoryHost)> for Instance { fn from(inventory_host: (&'a Name, &'a InventoryHost)) -> Self { Self { name: inventory_host.0.clone(), @@ -210,14 +210,14 @@ impl<'a> From<(&'a Name, &'a InventoryHost)> for InstanceV2 { failure_domains: Default::default(), roles: Vec::default(), cartridge_extra_env: inventory_host.1.cartridge_extra_env.clone(), - config: InstanceV2Config::from_inventory_host(&inventory_host.1), + config: InstanceConfig::from_inventory_host(&inventory_host.1), vars: inventory_host.1.vars.clone(), view: View::default(), } } } -impl From for InstanceV2 { +impl From for Instance { fn from(name: Name) -> Self { Self { name, @@ -226,14 +226,14 @@ impl From for InstanceV2 { failure_domains: Default::default(), roles: Vec::default(), cartridge_extra_env: IndexMap::default(), - config: InstanceV2Config::default(), + config: InstanceConfig::default(), vars: IndexMap::default(), view: View::default(), } } } -impl InstanceV2 { +impl Instance { pub fn is_stateboard(&self) -> bool { if let Some(stateboard) = self.stateboard { stateboard @@ -326,7 +326,7 @@ impl Default for FailureDomains { } #[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq)] -pub struct InstanceV2Config { +pub struct InstanceConfig { #[serde(default, skip_serializing_if = "Option::is_none")] pub http_port: Option, #[serde(default, skip_serializing_if = "Option::is_none")] @@ -341,7 +341,7 @@ pub struct InstanceV2Config { pub additional_config: IndexMap, } -impl InstanceV2Config { +impl InstanceConfig { pub fn from_inventory_host(host: &InventoryHost) -> Self { match &host.config { InvHostConfig::Instance { @@ -368,7 +368,7 @@ impl InstanceV2Config { } } -impl<'a> From<&'a IndexMap> for InstanceV2Config { +impl<'a> From<&'a IndexMap> for InstanceConfig { fn from(config: &'a IndexMap) -> Self { Self { http_port: config @@ -396,8 +396,8 @@ impl<'a> From<&'a IndexMap> for InstanceV2Config { } #[allow(unused)] -impl InstanceV2Config { - pub fn merge_and_up_ports(self, other: HostV2Config, index: u16) -> Self { +impl InstanceConfig { + pub fn merge_and_up_ports(self, other: HostConfig, index: u16) -> Self { trace!("Config before merge: {:?}", &self); Self { http_port: self @@ -413,7 +413,7 @@ impl InstanceV2Config { } } - pub fn merge_with_host_v2_config(self, other: HostV2Config) -> Self { + pub fn merge_with_host_v2_config(self, other: HostConfig) -> Self { Self { http_port: self.http_port.or(other.http_port), binary_port: self.binary_port.or(other.binary_port), diff --git a/src/task/cluster/ins.rs b/src/task/cluster/instance/mod.rs similarity index 92% rename from src/task/cluster/ins.rs rename to src/task/cluster/instance/mod.rs index 48bed8b..9bb0494 100644 --- a/src/task/cluster/ins.rs +++ b/src/task/cluster/instance/mod.rs @@ -1,11 +1,10 @@ -pub(in crate::task) mod v1; -pub(in crate::task) mod v2; +pub mod ins; use indexmap::IndexMap; use serde::{de::Visitor, Deserialize, Serialize}; use serde_yaml::Value; -use super::hst::v2::Address; +use super::host::hst::Address; #[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Copy)] #[serde(rename_all = "camelCase")] @@ -120,22 +119,6 @@ impl Role { } } -pub fn is_zero(u: &usize) -> bool { - matches!(u, 0) -} - -pub fn is_false(v: &bool) -> bool { - !*v -} - -pub fn default_weight() -> usize { - 10 -} - -fn count_one() -> usize { - 1 -} - #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq)] pub struct Config { pub http_port: Option, diff --git a/src/task/cluster/ins/test.rs b/src/task/cluster/instance/test.rs similarity index 97% rename from src/task/cluster/ins/test.rs rename to src/task/cluster/instance/test.rs index 4f89c2c..d2b0cc1 100644 --- a/src/task/cluster/ins/test.rs +++ b/src/task/cluster/instance/test.rs @@ -1,7 +1,7 @@ use indexmap::IndexMap; use crate::task::cluster::{ - ins::{v1::Instance, v2::InstanceV2, Role, Type}, + ins::{v1::Instance, v2::Instance, Role, Type}, Cluster, }; @@ -152,7 +152,7 @@ count: 1 #[test] fn default_instances() { let instances = vec![ - InstanceV2 { + Instance { name: "router".into(), parent: "router".into(), itype: Type::Router, @@ -163,7 +163,7 @@ fn default_instances() { roles: vec![Role::router(), Role::failover_coordinator()], config: IndexMap::new(), }, - InstanceV2 { + Instance { name: "storage".into(), parent: "storage".into(), itype: Type::Storage, @@ -177,4 +177,3 @@ fn default_instances() { ]; assert_eq!(Cluster::default().topology(), instances); } - diff --git a/src/task/cluster/test.rs b/src/task/cluster/test.rs index 2ccce11..d02015d 100644 --- a/src/task/cluster/test.rs +++ b/src/task/cluster/test.rs @@ -1,10 +1,7 @@ -use std::convert::TryFrom; - +use crate::task::{cluster::host::hst::Address, serde_genin, utils::uncolorize}; use clap::{Arg, ArgAction, Command}; - -use crate::task::{ - cluster::hst::v2::Address, flv::StateboardParams, serde_genin, utils::uncolorize, -}; +use std::convert::TryFrom; +use std::net::IpAddr; use super::*; @@ -40,7 +37,7 @@ fn default_cluster() { } #[test] -/// ClusterV2.hosts string -> HostV2 -> ClusterV2.hosts string +/// Cluster.hosts string -> Host -> Cluster.hosts string fn cluster_hosts_v2_serde() { let hosts_v2_str: String = r#"--- name: cluster @@ -57,196 +54,28 @@ hosts: "# .into(); - let hosts_v2_model = HostV2::from("cluster") + let hosts_v2_model = Host::from("cluster") .with_hosts(vec![ - HostV2::from(Name::from("cluster").with_raw_index("server-1")) - .with_config(HostV2Config::from(IpAddr::from([192, 168, 16, 11]))), - HostV2::from(Name::from("cluster").with_raw_index("server-2")) - .with_config(HostV2Config::from(IpAddr::from([192, 168, 16, 12]))), + Host::from(Name::from("cluster").with_raw_index("server-1")) + .with_config(HostConfig::from(IpAddr::from([192, 168, 16, 11]))), + Host::from(Name::from("cluster").with_raw_index("server-2")) + .with_config(HostConfig::from(IpAddr::from([192, 168, 16, 12]))), ]) - .with_config(HostV2Config::from((8081, 3301))); + .with_config(HostConfig::from((8081, 3301))); - let hosts_v2: HostV2 = serde_yaml::from_str::(&hosts_v2_str) + let host: Host = serde_yaml::from_str::(&hosts_v2_str) .unwrap() .into(); - assert_eq!(hosts_v2, hosts_v2_model); + assert_eq!(host, hosts_v2_model); let hosts_v2_model_str = hosts_v2_str; - let hosts_v2_str = serde_yaml::to_string(&hosts_v2).unwrap(); + let hosts_v2_str = serde_yaml::to_string(&host).unwrap(); assert_eq!(hosts_v2_str, hosts_v2_model_str); } -#[test] -/// ClusterV1.hosts -> HostV2 -/// ClusterV1.hosts == ClusterV2.hosts -/// ClusterV1.hosts -> ClusterV2.hosts HostV2 string -fn hosts_v1_to_hosts_v2() { - let cluster_v1_str: String = r#"--- -instances: - - name: router - type: router - count: 0 -hosts: - - name: selectel - type: datacenter - ports: - http: 8081 - binary: 3031 - hosts: - - name: server-1 - ip: 192.168.16.11 - - name: server-2 - ip: 192.168.16.12 -failover: - mode: stateful - state_provider: stateboard - stateboard_params: - uri: 192.168.16.11:4401 - password: some_password -vars: - ansible_user: ansible - ansible_password: ansible - cartridge_app_name: myapp - cartridge_cluster_cookie: myapp-cookie - cartridge_package_path: /tmp/myapp.rpm - cartridge_bootstrap_vshard: true -"# - .into(); - - let mut hosts_v2_model = HostV2::from("cluster") - .with_hosts(vec![HostV2::from( - Name::from("cluster").with_raw_index("selectel"), - ) - .with_hosts(vec![ - HostV2::from( - Name::from("cluster") - .with_raw_index("selectel") - .with_raw_index("server-1"), - ) - .with_config(HostV2Config::from(IpAddr::from([192, 168, 16, 11]))), - HostV2::from( - Name::from("cluster") - .with_raw_index("selectel") - .with_raw_index("server-2"), - ) - .with_config(HostV2Config::from(IpAddr::from([192, 168, 16, 12]))), - ])]) - .with_config(HostV2Config::from((8081, 3031))); - - hosts_v2_model.with_stateboard(&Failover { - mode: Mode::Stateful, - state_provider: StateProvider::Stateboard, - failover_variants: crate::task::flv::FailoverVariants::StateboardVariant( - StateboardParams { - uri: crate::task::flv::Uri { - address: Address::Ip("192.168.16.11".parse().unwrap()), - port: 4401, - }, - password: "some_password".into(), - }, - ), - ..Default::default() - }); - - hosts_v2_model.spread(); - - let mut cluster_v1: Cluster = serde_yaml::from_str(&cluster_v1_str).unwrap(); - cluster_v1.hosts.add_queue = IndexMap::default(); - cluster_v1.hosts.delete_queue = IndexMap::default(); - - println!( - "stateboard 1: {:?}", - hosts_v2_model - .hosts - .first() - .unwrap() - .hosts - .first() - .unwrap() - .instances - ); - println!( - "stateboard 2: {:?}", - cluster_v1 - .hosts - .hosts - .first() - .unwrap() - .hosts - .first() - .unwrap() - .instances - ); - - assert_eq!(cluster_v1.hosts, hosts_v2_model); - - let cluster_v2_str: String = r#"--- -topology: - - name: router - replicasets_count: 0 -hosts: - - name: selectel - config: - http_port: 8081 - binary_port: 3031 - hosts: - - name: server-1 - config: - address: 192.168.16.11 - - name: server-2 - config: - address: 192.168.16.12 -failover: - mode: stateful - state_provider: stateboard - stateboard_params: - uri: "192.168.16.11:4401" - password: some_password -vars: - ansible_user: ansible - ansible_password: ansible - cartridge_app_name: myapp - cartridge_cluster_cookie: myapp-cookie - cartridge_package_path: /tmp/myapp.rpm - cartridge_bootstrap_vshard: true -"# - .into(); - - let mut cluster_v2: Cluster = serde_yaml::from_str(&cluster_v2_str).unwrap(); - cluster_v2.hosts.add_queue = IndexMap::default(); - cluster_v2.hosts.delete_queue = IndexMap::default(); - - println!( - "stateboard 3: {:?}", - cluster_v1 - .hosts - .hosts - .first() - .unwrap() - .hosts - .first() - .unwrap() - .instances - ); - println!( - "stateboard 4: {:?}", - cluster_v2 - .hosts - .hosts - .first() - .unwrap() - .hosts - .first() - .unwrap() - .instances - ); - - assert_eq!(cluster_v1.hosts, cluster_v2.hosts); -} - #[test] /// Args(only init) -> Cluster fn cluster_v2_from_args() { @@ -273,135 +102,6 @@ fn cluster_v2_from_args() { insta::assert_yaml_snapshot!(cluster); } -/// read string ClusterV1 -> serialize string ClusterV2 == ClusterV2 model -#[test] -fn cluster_v1_to_cluster_v2() { - let cluster_v1_str: String = r#"--- -instances: - - name: router - type: router - count: 1 - roles: - - router - - api - - failover-coordinator - - name: storage - type: storage - count: 2 - replicas: 2 - weight: 10 - roles: - - storage -hosts: - - name: selectel - type: datacenter - ports: - http: 8081 - binary: 3031 - hosts: - - name: server-1 - ip: 192.168.16.11 - - name: server-2 - ip: 192.168.16.12 -failover: - mode: stateful - state_provider: stateboard - stateboard_params: - uri: 192.168.16.11:4401 - password: password -vars: - ansible_user: ansible - ansible_password: ansible - cartridge_app_name: myapp - cartridge_cluster_cookie: myapp-cookie - cartridge_package_path: /tmp/myapp.rpm - cartridge_bootstrap_vshard: true -"# - .into(); - - let cluster_v2: Cluster = serde_yaml::from_str(&cluster_v1_str).unwrap(); - - insta::assert_yaml_snapshot!(cluster_v2); -} - -#[test] -fn cluster_v1_tdg_to_cluster_v2() { - let cluster_v1_tdg_str: String = r#"--- -instances: - - name: l-n - type: custom - count: 2 - replicas: 0 - weight: 10 - roles: - - logger - - notifier - - name: op-t - type: custom - count: 5 - replicas: 0 - weight: 10 - roles: - - output_processor - - task_runner - - name: c-ip - type: custom - count: 5 - replicas: 0 - weight: 10 - roles: - - connector - - input_processor - - failover-coordinator - - name: sch - type: custom - count: 2 - replicas: 0 - weight: 10 - roles: - - scheduler - - name: storage - type: storage - count: 3 - replicas: 2 - weight: 10 - roles: - - storage -hosts: - - name: vagr_tdg - type: datacenter - ports: - http: 8081 - binary: 3031 - hosts: - - name: tdg-1 - ip: 192.168.123.2 - - name: tdg-2 - ip: 192.168.123.3 - - name: tdg-3 - ip: 192.168.123.4 -failover: - mode: stateful - state_provider: etcd2 - etcd2_params: - prefix: cartridge/tdg - lock_delay: 30 - endpoints: - - "http://192.168.123.2:2379" -vars: - ansible_user: vagrant - ansible_password: vagrant - cartridge_app_name: tdg - cartridge_cluster_cookie: myapp-cookie - cartridge_package_path: ./tdg-1.7.17-0-g2a5b4bd18.rpm -"# - .into(); - - let cluster_v2: Cluster = serde_yaml::from_str(&cluster_v1_tdg_str).unwrap(); - - insta::assert_yaml_snapshot!(cluster_v2); -} - #[test] fn cluster_v2_from_inventory() { let inventory_str: String = r#"--- @@ -517,7 +217,7 @@ topology: - storage - name: api failure_domains: [server-2] - role: + roles: - api hosts: - name: datacenter-1 @@ -564,7 +264,7 @@ topology: - storage - name: api failure_domains: [server-2] - role: + roles: - api hosts: - name: datacenter-1 diff --git a/src/task/cluster/topology.rs b/src/task/cluster/topology.rs index 0a8ab45..cac7776 100644 --- a/src/task/cluster/topology.rs +++ b/src/task/cluster/topology.rs @@ -12,13 +12,13 @@ use crate::task::{ }; use super::{ - hst::view::{TableColors, View}, - ins::{ - v2::{InstanceV2, InstanceV2Config, Instances}, + host::view::{TableColors, View}, + instance::{ + ins::{Instance, InstanceConfig, Instances}, Role, }, name::Name, - TopologyMemberV1, + TopologyMember, }; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] @@ -43,7 +43,7 @@ impl TryFrom for Topology { .fold( IndexMap::::new(), |mut replicasets, - InstanceV2 { + Instance { name, weight, failure_domains, @@ -171,7 +171,7 @@ impl<'a> From<&'a Topology> for Instances { .flat_map(|repliaset_num| { if !replication_factor.is_none() { (1..=replication_factor.unwrap()) - .map(|instance_num| InstanceV2 { + .map(|instance_num| Instance { name: name .clone_with_index(repliaset_num) .clone_with_index(instance_num), @@ -189,9 +189,9 @@ impl<'a> From<&'a Topology> for Instances { ), }, }) - .collect::>() + .collect::>() } else { - vec![InstanceV2 { + vec![Instance { name: name.clone_with_index(repliaset_num), stateboard: None, weight: *weight, @@ -207,10 +207,10 @@ impl<'a> From<&'a Topology> for Instances { }] } }) - .collect::>() + .collect::>() }, ) - .collect::>(), + .collect::>(), ) } } @@ -231,13 +231,13 @@ impl Topology { } } -impl From> for Topology { - fn from(members: Vec) -> Self { +impl From> for Topology { + fn from(members: Vec) -> Self { Self( members .into_iter() .map( - |TopologyMemberV1 { + |TopologyMember { name, count, replicas, @@ -265,9 +265,9 @@ impl From> for Topology { failure_domains: Default::default(), roles, cartridge_extra_env: IndexMap::default(), - config: InstanceV2Config { + config: InstanceConfig { additional_config: config, - ..InstanceV2Config::default() + ..InstanceConfig::default() }, vars: IndexMap::default(), } @@ -289,7 +289,7 @@ impl Default for Topology { failure_domains: Default::default(), roles: vec![Role::router(), Role::failover_coordinator()], cartridge_extra_env: IndexMap::default(), - config: InstanceV2Config::default(), + config: InstanceConfig::default(), vars: IndexMap::default(), }, TopologySet { @@ -300,7 +300,7 @@ impl Default for Topology { failure_domains: Default::default(), roles: vec![Role::storage()], cartridge_extra_env: IndexMap::default(), - config: InstanceV2Config::default(), + config: InstanceConfig::default(), vars: IndexMap::default(), }, ]) @@ -322,8 +322,8 @@ struct TopologySet { roles: Vec, #[serde(default, skip_serializing_if = "IndexMap::is_empty")] cartridge_extra_env: IndexMap, - #[serde(skip_serializing_if = "InstanceV2Config::is_none")] - config: InstanceV2Config, + #[serde(skip_serializing_if = "InstanceConfig::is_none")] + config: InstanceConfig, #[serde(default, skip_serializing_if = "IndexMap::is_empty")] vars: IndexMap, } @@ -351,7 +351,7 @@ impl<'de> Deserialize<'de> for TopologySet { #[serde(default)] cartridge_extra_env: IndexMap, #[serde(default)] - config: Option, + config: Option, #[serde(default)] vars: IndexMap, } @@ -363,16 +363,13 @@ impl<'de> Deserialize<'de> for TopologySet { replication_factor, weight, failure_domains, - mut roles, + roles, all_rw, cartridge_extra_env, config, vars, }| { // If type not defined in yaml let's try to infer based on name - if roles.is_empty() { - roles = vec![Role::from(name.as_str())] - } TopologySet { name: Name::from(name), replicasets_count, @@ -583,7 +580,7 @@ impl std::fmt::Debug for InvalidTopologySet { Value::Null => {} config @ Value::Mapping(_) => formatter.write_fmt(format_args!( "{:?}", - serde_yaml::from_value::(config.clone()) + serde_yaml::from_value::(config.clone()) .map(|mut config| { config.offset = "\n ".into(); config @@ -672,7 +669,7 @@ impl<'a> std::fmt::Debug for InvalidRoles<'a> { #[derive(Deserialize, Default)] #[serde(default)] -pub struct ErrInstanceV2Config { +pub struct ErrInstanceConfig { #[serde(skip)] offset: String, http_port: Value, @@ -684,7 +681,7 @@ pub struct ErrInstanceV2Config { additional_config: Value, } -impl std::fmt::Debug for ErrInstanceV2Config { +impl std::fmt::Debug for ErrInstanceConfig { fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { formatter.write_fmt(format_args!("{}config: ", self.offset))?; // http_port: u16 diff --git a/src/task/cluster/topology/test.rs b/src/task/cluster/topology/test.rs index a9e5cf9..ce3ff8f 100644 --- a/src/task/cluster/topology/test.rs +++ b/src/task/cluster/topology/test.rs @@ -1,9 +1,9 @@ use indexmap::IndexMap; use crate::task::cluster::{ - hst::view::{FG_BLUE, FG_CYAN, FG_WHITE}, - ins::{ - v2::{InstanceV2, InstanceV2Config, Instances}, + host::view::{FG_BLUE, FG_CYAN, FG_WHITE}, + instance::{ + ins::{Instance, InstanceConfig, Instances}, Role, }, name::Name, @@ -15,19 +15,19 @@ use crate::task::cluster::{ /// instances -> topology -> instances fn topology_from_instances() { let instances_model = Instances::from(vec![ - InstanceV2::from(Name::from("router").with_index(1)) + Instance::from(Name::from("router").with_index(1)) .with_roles(vec![Role::router(), Role::failover_coordinator()]) .with_color(FG_WHITE), - InstanceV2::from(Name::from("storage").with_index(1).with_index(1)) + Instance::from(Name::from("storage").with_index(1).with_index(1)) .with_roles(vec![Role::storage()]) .with_color(FG_BLUE), - InstanceV2::from(Name::from("storage").with_index(1).with_index(2)) + Instance::from(Name::from("storage").with_index(1).with_index(2)) .with_roles(vec![Role::storage()]) .with_color(FG_BLUE), - InstanceV2::from(Name::from("storage").with_index(2).with_index(1)) + Instance::from(Name::from("storage").with_index(2).with_index(1)) .with_roles(vec![Role::storage()]) .with_color(FG_CYAN), - InstanceV2::from(Name::from("storage").with_index(2).with_index(2)) + Instance::from(Name::from("storage").with_index(2).with_index(2)) .with_roles(vec![Role::storage()]) .with_color(FG_CYAN), ]); @@ -40,7 +40,7 @@ fn topology_from_instances() { failure_domains: Default::default(), roles: vec![Role::router(), Role::failover_coordinator()], cartridge_extra_env: IndexMap::new(), - config: InstanceV2Config::default(), + config: InstanceConfig::default(), vars: IndexMap::default(), }, TopologySet { @@ -51,7 +51,7 @@ fn topology_from_instances() { failure_domains: Default::default(), roles: vec![Role::storage()], cartridge_extra_env: IndexMap::new(), - config: InstanceV2Config::default(), + config: InstanceConfig::default(), vars: IndexMap::default(), }, ]); @@ -66,7 +66,7 @@ fn topology_from_instances() { } #[test] -/// ClusterV2.topology string -> Topology -> ClusterV2.topology string +/// Cluster.topology string -> Topology -> Cluster.topology string fn topology_member_v2() { let topology_member_str: String = r#"--- name: router @@ -85,7 +85,7 @@ roles: failure_domains: Default::default(), roles: vec![Role::router(), Role::failover_coordinator()], cartridge_extra_env: IndexMap::new(), - config: InstanceV2Config::default(), + config: InstanceConfig::default(), vars: IndexMap::default(), }; @@ -103,19 +103,19 @@ roles: #[test] fn non_unique_replicaset_names() { let instances = Instances::from(vec![ - InstanceV2::from(Name::from("router").with_index(1)) + Instance::from(Name::from("router").with_index(1)) .with_roles(vec![Role::router(), Role::failover_coordinator()]) .with_color(FG_WHITE), - InstanceV2::from(Name::from("storage").with_index(1).with_index(1)) + Instance::from(Name::from("storage").with_index(1).with_index(1)) .with_roles(vec![Role::storage()]) .with_color(FG_BLUE), - InstanceV2::from(Name::from("storage").with_index(1).with_index(1)) + Instance::from(Name::from("storage").with_index(1).with_index(1)) .with_roles(vec![Role::storage()]) .with_color(FG_BLUE), - InstanceV2::from(Name::from("storage").with_index(2).with_index(1)) + Instance::from(Name::from("storage").with_index(2).with_index(1)) .with_roles(vec![Role::storage()]) .with_color(FG_CYAN), - InstanceV2::from(Name::from("storage").with_index(2).with_index(2)) + Instance::from(Name::from("storage").with_index(2).with_index(2)) .with_roles(vec![Role::storage()]) .with_color(FG_CYAN), ]); @@ -134,7 +134,7 @@ fn non_unique_replicaset_names() { failure_domains: Default::default(), roles: vec![Role::router(), Role::failover_coordinator()], cartridge_extra_env: IndexMap::new(), - config: InstanceV2Config::default(), + config: InstanceConfig::default(), vars: IndexMap::default(), }, TopologySet { @@ -145,7 +145,7 @@ fn non_unique_replicaset_names() { failure_domains: Default::default(), roles: vec![Role::storage()], cartridge_extra_env: IndexMap::new(), - config: InstanceV2Config::default(), + config: InstanceConfig::default(), vars: IndexMap::default(), }, ]); diff --git a/src/task/flv.rs b/src/task/flv.rs index 4659972..e934a7e 100644 --- a/src/task/flv.rs +++ b/src/task/flv.rs @@ -11,7 +11,7 @@ use crate::{ DEFAULT_STATEBOARD_PORT, }; -use super::{cluster::hst::v2::Address, AsError, TypeError, LIST, NUMBER, STRING}; +use super::{cluster::host::hst::Address, AsError, TypeError, LIST, NUMBER, STRING}; #[derive(Serialize, Clone, Debug, PartialEq, Eq)] /// Failover enum @@ -82,7 +82,7 @@ impl<'a> TryFrom<&'a ArgMatches> for Failover { mode: Mode::Disabled, state_provider: StateProvider::Disabled, failover_variants: FailoverVariants::Disabled, - ..Default::default() + ..Default::default() }) } (Some("eventual"), _) => Ok(Self { diff --git a/src/task/inventory.rs b/src/task/inventory.rs index 6f3d48a..bb43858 100644 --- a/src/task/inventory.rs +++ b/src/task/inventory.rs @@ -11,9 +11,9 @@ use serde::{Deserialize, Serialize}; use serde_yaml::Value; use thiserror::Error; -use crate::task::cluster::hst::v2::Address; -use crate::task::cluster::hst::v2::HostV2; -use crate::task::cluster::ins::v2::InstanceV2; +use crate::task::cluster::host::hst::Address; +use crate::task::cluster::host::hst::Host; +use crate::task::cluster::instance::ins::Instance; use crate::task::cluster::name::Name; use crate::task::flv::Uri; use crate::task::vars::Vars; @@ -21,7 +21,7 @@ use crate::task::Cluster; use crate::task::Validate; use crate::{ error::{GeninError, GeninErrorKind}, - task::cluster::ins::Role, + task::cluster::instance::Role, APP_VERSION, }; @@ -321,10 +321,6 @@ impl Validate for Inventory { fn validate(_bytes: &[u8]) -> Result { Ok(String::default()) } - - fn whole_block(bytes: &[u8]) -> String { - String::from_utf8(bytes.to_vec()).unwrap() - } } #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] @@ -365,8 +361,8 @@ pub enum InvHostConfig { Stateboard(IndexMap), } -impl<'a> From<(&'a InstanceV2, &'a HostV2)> for InvHostConfig { - fn from(pair: (&'a InstanceV2, &'a HostV2)) -> Self { +impl<'a> From<(&'a Instance, &'a Host)> for InvHostConfig { + fn from(pair: (&'a Instance, &'a Host)) -> Self { if !pair.0.is_stateboard() { InvHostConfig::Instance { advertise_uri: Uri { diff --git a/src/task/inventory/test.rs b/src/task/inventory/test.rs index 99f34c5..f56882f 100644 --- a/src/task/inventory/test.rs +++ b/src/task/inventory/test.rs @@ -4,80 +4,6 @@ use crate::task::cluster::Cluster; use super::Inventory; -#[test] -fn inventory_from_cluster_v1() { - let cluster_v1_str: String = r#"--- -instances: - - name: api - count: 1 - replicas: 0 - weight: 10 - roles: - - api - - name: calculator - count: 1 - replicas: 0 - weight: 10 - roles: - - calculator - - name: storage - type: storage - count: 2 - replicas: 2 - weight: 10 - roles: - - storage - config: - memtx_memory: 1179869184 - vinyl_memory: 10345452343 - - name: cache - type: storage - count: 2 - replicas: 2 - weight: 10 - roles: - - storage - - name: router - type: router - count: 1 - replicas: 0 - weight: 10 - roles: - - router - - failover-coordinator -hosts: - - name: docker - type: datacenter - ports: - http: 8100 - binary: 5002 - hosts: - - name: host-1 - ip: 10.99.16.65 - - name: host-2 - ip: 10.99.16.66 -failover: - mode: stateful - state_provider: stateboard - stateboard_params: - uri: - ip: 10.99.16.66 - port: 5001 - password: genin-app -vars: - ansible_user: ansible - ansible_password: ansible - cartridge_app_name: genin-app - cartridge_cluster_cookie: genin-app-secret-cookie"# - .into(); - - let cluster: Cluster = serde_yaml::from_str(&cluster_v1_str).unwrap(); - - let inventory = Inventory::try_from(&Some(cluster)).unwrap(); - - insta::assert_yaml_snapshot!(inventory); -} - #[test] fn inventory_per_instance_vars() { let cluster_v2_str: String = r#"--- diff --git a/src/task/state.rs b/src/task/state.rs index 7e58cf8..52f792c 100644 --- a/src/task/state.rs +++ b/src/task/state.rs @@ -12,9 +12,9 @@ use serde::{Deserialize, Serialize}; use sha256::{digest, try_digest, TrySha256Digest}; use thiserror::Error; -use crate::task::cluster::hst::view::{FG_GREEN, FG_RED}; +use crate::task::cluster::host::view::{FG_GREEN, FG_RED}; use crate::task::cluster::topology::Topology; -use crate::task::{cluster::hst::v2::HostV2, flv::Failover, vars::Vars}; +use crate::task::{cluster::host::hst::Host, flv::Failover, vars::Vars}; #[derive(Serialize, Deserialize, Debug)] pub struct State { @@ -28,7 +28,7 @@ pub struct State { pub hosts_changes: Vec, pub vars: Vars, pub topology: Topology, - pub hosts: HostV2, + pub hosts: Host, pub failover: Failover, } @@ -88,7 +88,10 @@ impl State { .cloned() .unwrap_or(".geninstate".into()); - remove_dir_all(state_dir) + remove_dir_all(state_dir.clone()) + .is_err() + .then(|| println!("State dir \"{}\" is empty", state_dir)); + Ok(()) } pub fn dump_by_path(&mut self, path: &str) -> Result<(), io::Error> { @@ -198,7 +201,7 @@ pub struct StateBuilder { path: Option, instances_changes: Option>, hosts_changes: Option>, - hosts: Option, + hosts: Option, vars: Option, failover: Option, topology: Option, @@ -249,7 +252,7 @@ impl StateBuilder { } } - pub fn hosts(self, hosts: &HostV2) -> Self { + pub fn hosts(self, hosts: &Host) -> Self { Self { hosts: Some(hosts.to_owned()), ..self diff --git a/src/task/vars/test.rs b/src/task/vars/test.rs index b4a3979..1e5769d 100644 --- a/src/task/vars/test.rs +++ b/src/task/vars/test.rs @@ -2,7 +2,7 @@ use indexmap::IndexMap; use crate::{ task::{ - cluster::hst::v2::Address, + cluster::host::hst::Address, flv::{Failover, FailoverVariants, Mode, StateProvider, StateboardParams, Uri}, utils::uncolorize, vars::Vars,