From 3f798131efd8e3d97cb453c6a4a07402478f12f5 Mon Sep 17 00:00:00 2001 From: "dmitry.travyan" Date: Tue, 29 Nov 2022 11:20:18 +0300 Subject: [PATCH] feat: all-rw feature --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 20 ++--- README.ru.md | 22 ++--- src/task/cluster/ins/v2.rs | 4 + src/task/cluster/topology.rs | 5 +- src/task/inventory/test.rs | 84 ++++++++++++++++++++ test/resources/test-2-new-cluster.genin.yaml | 4 +- 8 files changed, 117 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bdb4208..31c605e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -114,7 +114,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "genin" -version = "0.4.10" +version = "0.4.11" dependencies = [ "clap", "env_logger", diff --git a/Cargo.toml b/Cargo.toml index 4b0413c..0b4d517 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "genin" -version = "0.4.10" +version = "0.4.11" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md index e72b819..c05de0c 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,8 @@ Download and unzip the archive for the desired architecture. Universal executable: ```shell -curl -sLO https://binary.picodata.io/repository/raw/genin/bin/genin-0.4.8-x86_64-musl.tar.gz -tar -xvf genin-0.4.8-x86_64-musl.tar.gz ; sudo install genin /usr/local/bin/ +curl -sLO https://binary.picodata.io/repository/raw/genin/bin/genin-0.4.11-x86_64-musl.tar.gz +tar -xvf genin-0.4.11-x86_64-musl.tar.gz ; sudo install genin /usr/local/bin/ ``` --- @@ -85,11 +85,11 @@ sudo yum install -y genin 2. If you want to install `rpm` packages directly without adding our repository. ```shell -sudo rpm -i https://binary.picodata.io/repository/yum/el/8/x86_64/os/genin-0.4.8-1.el8.x86_64.rpm +sudo rpm -i https://binary.picodata.io/repository/yum/el/8/x86_64/os/genin-0.4.11-1.el8.x86_64.rpm ``` RHEL 7.x, CentOS 7.x ```shell -sudo rpm -i https://binary.picodata.io/repository/yum/el/7/x86_64/os/genin-0.4.8-1.el7.x86_64.rpm +sudo rpm -i https://binary.picodata.io/repository/yum/el/7/x86_64/os/genin-0.4.11-1.el7.x86_64.rpm ``` --- @@ -117,7 +117,7 @@ sudo apt install -y genin 2. Downloading and installing the package directly: ```shell -curl -sLO https://binary.picodata.io/repository/raw/genin/deb/genin-0.4.8.amd64.deb && sudo dpkg -i genin-0.4.8.amd64.deb +curl -sLO https://binary.picodata.io/repository/raw/genin/deb/genin-0.4.11.amd64.deb && sudo dpkg -i genin-0.4.11.amd64.deb ``` --- @@ -143,7 +143,7 @@ sudo apt install -y genin 2. Downloading and installing the package directly: ```shell -curl -sLO https://binary.picodata.io/repository/raw/genin/deb/genin-0.4.8.amd64.deb && sudo dpkg -i genin-0.4.8.amd64.deb +curl -sLO https://binary.picodata.io/repository/raw/genin/deb/genin-0.4.11.amd64.deb && sudo dpkg -i genin-0.4.11.amd64.deb ``` --- @@ -163,8 +163,8 @@ brew install genin Use the following command to grab and install Genin in macOS (10.10+) wihtout homebrew: ```shell -curl -L https://binary.picodata.io/repository/raw/genin/apple/genin-0.4.8-darwin-amd64.zip -o genin-0.4.8-darwin-amd64.zip -unzip genin-0.4.8-darwin-amd64.zip -d ~/bin/ +curl -L https://binary.picodata.io/repository/raw/genin/apple/genin-0.4.11-darwin-amd64.zip -o genin-0.4.11-darwin-amd64.zip +unzip genin-0.4.11-darwin-amd64.zip -d ~/bin/ ``` > **Note:** The application can then be found under the `~/bin` directory. > Make sure the directory is in your `$PATH`. @@ -182,8 +182,8 @@ brew install genin@0.3.8 #### Windows Use the following command to grab and install Genin in Windows 7 64 bit or newer: ```shell -curl.exe -L https://binary.picodata.io/repository/raw/genin/windows/genin-0.4.8-darwin-amd64.zip -o genin-0.4.8-windows-amd64.zip -unzip.exe genin-0.4.8-windows-amd64.zip -d %HOME%/.cargo/bin/ +curl.exe -L https://binary.picodata.io/repository/raw/genin/windows/genin-0.4.11-darwin-amd64.zip -o genin-0.4.11-windows-amd64.zip +unzip.exe genin-0.4.11-windows-amd64.zip -d %HOME%/.cargo/bin/ ``` > **Note:** The application can then be found under the `.cargo/bin` folder inside > your user profile folder. Make sure it is in your `%PATH%`. diff --git a/README.ru.md b/README.ru.md index 52cfde5..f49379a 100644 --- a/README.ru.md +++ b/README.ru.md @@ -50,8 +50,8 @@ Genin уже заранее скомпилирован под разные ар Универсальный исполняемый файл: ```shell -curl -sLO https://binary.picodata.io/repository/raw/genin/bin/genin-0.4.8-x86_64-musl.tar.gz -tar -xvf genin-0.4.8-x86_64-musl.tar.gz ; sudo install genin /usr/local/bin/ +curl -sLO https://binary.picodata.io/repository/raw/genin/bin/genin-0.4.11-x86_64-musl.tar.gz +tar -xvf genin-0.4.11-x86_64-musl.tar.gz ; sudo install genin /usr/local/bin/ ``` --- @@ -88,11 +88,11 @@ sudo yum install -y genin 2. Так же вы можете установить пакет `rpm` напрямую без добавления нашего репозитория. RHEL 8.x, CentOS 8.x, Rockylinux 8.x, recent Fedora version ```shell -sudo rpm -i https://binary.picodata.io/repository/yum/el/8/x86_64/os/genin-0.4.8-1.el8.x86_64.rpm +sudo rpm -i https://binary.picodata.io/repository/yum/el/8/x86_64/os/genin-0.4.11-1.el8.x86_64.rpm ``` RHEL 7.x, CentOS 7.x ```shell -sudo rpm -i https://binary.picodata.io/repository/yum/el/7/x86_64/os/genin-0.4.8-1.el7.x86_64.rpm +sudo rpm -i https://binary.picodata.io/repository/yum/el/7/x86_64/os/genin-0.4.11-1.el7.x86_64.rpm ``` > **Note:** будьте внимательны, так как при выборе не правильной версии ос могут быть ошибки > при установке `rpm` @@ -119,7 +119,7 @@ sudo apt install -y genin 2. Загрузкой и установкой пакета напрямую: ```shell -curl -sLO https://binary.picodata.io/repository/raw/genin/deb/genin-0.4.8.amd64.deb && sudo dpkg -i genin-0.4.8.amd64.deb +curl -sLO https://binary.picodata.io/repository/raw/genin/deb/genin-0.4.11.amd64.deb && sudo dpkg -i genin-0.4.11.amd64.deb ``` --- @@ -144,7 +144,7 @@ sudo apt install -y genin 2. Загрузкой и установкой пакета напрямую: ```shell -curl -sLO https://binary.picodata.io/repository/raw/genin/deb/genin-0.4.8.amd64.deb && sudo dpkg -i genin-0.4.8.amd64.deb +curl -sLO https://binary.picodata.io/repository/raw/genin/deb/genin-0.4.11.amd64.deb && sudo dpkg -i genin-0.4.11.amd64.deb ``` --- @@ -164,8 +164,8 @@ brew install genin Для установки без помощи homebrew используйте следующие команды для загрузки и установки Genin на macOS (10.10+): ```shell -curl -sLO https://binary.picodata.io/repository/raw/genin/osx/genin-0.4.8-x86_64-macosx.tar.gz -unzip genin-0.4.8-darwin-amd64.zip -d ~/bin/ +curl -sLO https://binary.picodata.io/repository/raw/genin/osx/genin-0.4.11-x86_64-macosx.tar.gz +unzip genin-0.4.11-darwin-amd64.zip -d ~/bin/ ``` --- @@ -189,8 +189,8 @@ brew install genin@0.3.8 Используйте следующие команды для скачивания и установки Genin на операционных системах Windows 7 64 и новее. ```shell -curl.exe -sLO https://binary.picodata.io/repository/raw/genin/win/genin-0.4.8-win64.zip -unzip.exe genin-0.4.8-win64.zip -d %HOME%/.cargo/bin/ +curl.exe -sLO https://binary.picodata.io/repository/raw/genin/win/genin-0.4.11-win64.zip +unzip.exe genin-0.4.11-win64.zip -d %HOME%/.cargo/bin/ ``` > **Note:** Genin будет распакован в директорию `.cargo/bin` которая находится в домашнем > каталоге важего пользователя. Перед использованием приложения пожалуйста удостоверьтесь @@ -200,7 +200,7 @@ unzip.exe genin-0.4.8-win64.zip -d %HOME%/.cargo/bin/ ``` genin --version ``` -Если вы видите сообщение `genin 0.4.8` значит установка прошла успешно. +Если вы видите сообщение `genin 0.4.11` значит установка прошла успешно. --- ## Руководство по использованию diff --git a/src/task/cluster/ins/v2.rs b/src/task/cluster/ins/v2.rs index d6b4e2a..9ae39e9 100644 --- a/src/task/cluster/ins/v2.rs +++ b/src/task/cluster/ins/v2.rs @@ -352,4 +352,8 @@ impl InstanceV2Config { ..self } } + + pub fn with_all_rw(self, all_rw: Option) -> Self { + Self { all_rw, ..self } + } } diff --git a/src/task/cluster/topology.rs b/src/task/cluster/topology.rs index 6be0dd1..86ebbbb 100644 --- a/src/task/cluster/topology.rs +++ b/src/task/cluster/topology.rs @@ -315,6 +315,8 @@ impl<'de> Deserialize<'de> for TopologySet { #[serde(default)] roles: Vec, #[serde(default)] + all_rw: Option, + #[serde(default)] cartridge_extra_env: IndexMap, #[serde(default)] config: InstanceV2Config, @@ -330,6 +332,7 @@ impl<'de> Deserialize<'de> for TopologySet { weight, failure_domains, mut roles, + all_rw, cartridge_extra_env, config, vars, @@ -352,7 +355,7 @@ impl<'de> Deserialize<'de> for TopologySet { failure_domains, roles, cartridge_extra_env, - config, + config: config.with_all_rw(all_rw), vars, } }, diff --git a/src/task/inventory/test.rs b/src/task/inventory/test.rs index 53a43ec..d1b0b31 100644 --- a/src/task/inventory/test.rs +++ b/src/task/inventory/test.rs @@ -376,3 +376,87 @@ all: assert_eq!(inventory, inventory_model); } + +#[test] +fn all_rw_only_in_replicaset() { + let cluster_v2_str: String = r#"--- +topology: + - name: storage + replicasets_count: 1 + roles: + - storage + all_rw: true +hosts: + - name: datacenter-1 + hosts: + - name: server-1 + config: + http_port: 8081 + binary_port: 3031 + address: 192.168.16.11 +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: Cluster = serde_yaml::from_str(&cluster_v2_str).unwrap(); + + let inventory_model_str: String = r#"--- +all: + 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 + cartridge_failover_params: + mode: stateful + state_provider: stateboard + stateboard_params: + uri: "192.168.16.11:4401" + password: password + hosts: + storage-1: + config: + advertise_uri: "192.168.16.11:3031" + http_port: 8081 + stateboard: + stateboard: true + config: + listen: "192.168.16.11:4401" + password: password + children: + storage-1-replicaset: + vars: + replicaset_alias: storage-1 + failover_priority: + - storage-1 + roles: + - storage + all_rw: true + hosts: + storage-1: ~ + server-1: + vars: + ansible_host: 192.168.16.11 + hosts: + storage-1: ~ + stateboard: ~"#.into(); + + let inventory_model: Inventory = serde_yaml::from_str(&inventory_model_str).unwrap(); + + let inventory = Inventory::try_from(&Some(cluster)).unwrap(); + + assert_eq!(inventory, inventory_model); +} diff --git a/test/resources/test-2-new-cluster.genin.yaml b/test/resources/test-2-new-cluster.genin.yaml index c8998ef..9dd8f75 100644 --- a/test/resources/test-2-new-cluster.genin.yaml +++ b/test/resources/test-2-new-cluster.genin.yaml @@ -79,8 +79,8 @@ failover: prefix: cartridge/myapp lock_delay: 30 endpoints: - - "http://192.168.16.11:5699" - - "http://192.168.16.12:5699" + - 'http://192.168.16.11:5699' + - 'http://192.168.16.12:5699' username: change_me password: change_me vars: