diff --git a/v2/data/retry_rcc/windows.json b/v2/data/retry_rcc/windows.json index e60de1d6..2c04b434 100644 --- a/v2/data/retry_rcc/windows.json +++ b/v2/data/retry_rcc/windows.json @@ -1,28 +1,27 @@ { - "working_directory": "/tmp/outputdir", - "results_directory": "/tmp/results", - "log_directory": "/tmp/logs", - "environment": { - "rcc_binary_path": "C:\\Users\\vagrant\\AppData\\Local\\Microsoft\\WindowsApps\\rcc.exe", - "scheduler_robot_yaml_path": "C:\\robotmk\\v2\\data\\scheduler_rcc\\robot.yaml" - }, + "working_directory": "C:\\tmp\\output", + "results_directory": "C:\\tmp\\results", "suites": { "test": { - "execution_interval_seconds": 10, - "robot_target": "C:\\robotmk\\v2\\data\\retry_suite\\/tasks.robot", - "variants": [ - { - "variablefile": null, - "argumentfile": null - }, - { - "variablefile": "C:\\robotmk\\v2\\data\\retry_suite\\/retry_variables.yaml", - "argumentfile": null - } - ], - "retry_strategy": "incremental", - "robot_yaml_path": "C:\\robotmk\\v2\\data\\retry_rcc\\/robot.yaml", - "session": null + "robot_framework_config": { + "robot_target": "C:\\robotmk\\v2\\data\\retry_suite\\tasks.robot", + "variable_file": "C:\\robotmk\\v2\\data\\retry_suite\\retry_variables.yaml", + "argument_file": null, + "retry_strategy": "Incremental" + }, + "execution_config": { + "n_retries_max": 1, + "execution_interval_seconds": 10, + "timeout": 5 + }, + "environment_config": { + "type": "Rcc", + "binary_path": "C:\\Users\\vagrant\\AppData\\Local\\Microsoft\\WindowsApps\\rcc.exe", + "robocorp_home_path": "C:\\tmp\\ROBOCORP_HOME", + "robot_yaml_path": "C:\\robotmk\\v2\\data\\retry_rcc\\robot.yaml", + "build_timeout": 120 + }, + "session_config": {"type": "Current"} } } } diff --git a/v2/data/retry_suite/windows.json b/v2/data/retry_suite/windows.json index 59e3b21e..95ca1691 100644 --- a/v2/data/retry_suite/windows.json +++ b/v2/data/retry_suite/windows.json @@ -1,24 +1,21 @@ { "working_directory": "/tmp/outputdir", "results_directory": "/tmp/results", - "log_directory": "/tmp/logs", - "environment": "system_python", "suites": { "test": { - "execution_interval_seconds": 10, - "robot_target": "C:\\robotmk\\v2\\data\\retry_suite\\/tasks.robot", - "variants": [ - { - "variablefile": null, - "argumentfile": null - }, - { - "variablefile": "C:\\robotmk\\v2\\data\\retry_suite\\/retry_variables.yaml", - "argumentfile": null - } - ], - "retry_strategy": "incremental", - "session": null + "robot_framework_config": { + "robot_target": "C:\\robotmk\\v2\\data\\retry_suite\\tasks.robot", + "variable_file": "C:\\robotmk\\v2\\data\\retry_suite\\retry_variables.yaml", + "argument_file": null, + "retry_strategy": "Incremental" + }, + "execution_config": { + "n_retries_max": 1, + "execution_interval_seconds": 10, + "timeout": 5 + }, + "environment_config": {"type": "System"}, + "session_config": {"type": "Current"} } } } diff --git a/v2/rust/Cargo.lock b/v2/rust/Cargo.lock index fd4c7071..e196d588 100644 --- a/v2/rust/Cargo.lock +++ b/v2/rust/Cargo.lock @@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aho-corasick" -version = "1.0.5" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c378d78423fdad8089616f827526ee33c19f2fddbd5de1629152c9593ba4783" +checksum = "0f2135563fb5c609d2b2b87c1e8ce7bc41b0b45430fa9661f457981503dd5bf0" dependencies = [ "memchr", ] @@ -162,9 +162,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.3" +version = "4.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84ed82781cea27b43c9b106a979fe450a13a31aab0500595fb3fc06616de08e6" +checksum = "b1d7b8d5ec32af0fadc644bf1fd509a688c2103b185644bb1e29d164e0703136" dependencies = [ "clap_builder", "clap_derive", @@ -172,9 +172,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.2" +version = "4.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bb9faaa7c2ef94b2743a21f5a29e6f0010dff4caa69ac8e9d6cf8b6fa74da08" +checksum = "5179bb514e4d7c2051749d8fcefa2ed6d06a9f4e6d69faf3805f5d80b8cf8d56" dependencies = [ "anstream", "anstyle", @@ -235,9 +235,9 @@ dependencies = [ [[package]] name = "flexi_logger" -version = "0.26.0" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bce3f7c47b1db54c6f069388db50c82c0cf12268759a360c15d21b81f5e6123" +checksum = "47a8a297f2d1285b13abf253b27f2f4480eb6703a0424b5942f9dc872831045c" dependencies = [ "chrono", "glob", @@ -269,9 +269,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[package]] name = "iana-time-zone" @@ -307,6 +307,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + [[package]] name = "js-sys" version = "0.3.64" @@ -456,6 +462,7 @@ dependencies = [ "log", "quick-xml", "serde", + "serde_json", ] [[package]] @@ -477,6 +484,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "ryu" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" + [[package]] name = "serde" version = "1.0.188" @@ -497,6 +510,17 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +dependencies = [ + "itoa", + "ryu", + "serde", +] + [[package]] name = "strsim" version = "0.10.0" @@ -505,9 +529,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "2.0.33" +version = "2.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9caece70c63bfba29ec2fed841a09851b14a235c60010fa4de58089b6c025668" +checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" dependencies = [ "proc-macro2", "quote", diff --git a/v2/rust/Cargo.toml b/v2/rust/Cargo.toml index b83061af..1b03b7a6 100644 --- a/v2/rust/Cargo.toml +++ b/v2/rust/Cargo.toml @@ -12,4 +12,5 @@ clap = { version = "*", features = ["derive"] } flexi_logger = "*" log = "*" quick-xml = { version = "0.30.0", features = ["serialize"] } -serde = { version = "1.0.188", features = ["serde_derive"] } +serde = { version = "1.0.188", features = ["derive"] } +serde_json = "*" diff --git a/v2/rust/src/config.rs b/v2/rust/src/config.rs new file mode 100644 index 00000000..e5d92d44 --- /dev/null +++ b/v2/rust/src/config.rs @@ -0,0 +1,80 @@ +use serde::Deserialize; +use serde_json::from_str; +use std::collections::HashMap; +use std::fs::read_to_string; +use std::path::{Path, PathBuf}; + +pub fn load(path: &Path) -> anyhow::Result { + Ok(from_str(&read_to_string(path)?)?) +} + +#[derive(Deserialize)] +pub struct Config { + pub working_directory: PathBuf, + pub results_directory: PathBuf, + suites: HashMap, +} + +#[derive(Deserialize)] +pub struct SuiteConfig { + pub robot_framework_config: RobotFrameworkConfig, + pub execution_config: ExecutionConfig, + pub environment_config: EnvironmentConfig, + pub session_config: SessionConfig, +} + +#[derive(Deserialize)] +pub struct RobotFrameworkConfig { + pub robot_target: PathBuf, + pub variable_file: Option, + pub argument_file: Option, + pub retry_strategy: RetryStrategy, +} + +#[derive(Deserialize)] +pub enum RetryStrategy { + Incremental, + Complete, +} + +#[derive(Deserialize)] +pub struct ExecutionConfig { + pub n_retries_max: usize, + pub execution_interval_seconds: u64, + pub timeout: u64, +} + +#[derive(Deserialize)] +#[serde(tag = "type")] +pub enum EnvironmentConfig { + System, + Rcc(RCCEnvironmentConfig), +} + +#[derive(Deserialize)] +pub struct RCCEnvironmentConfig { + pub binary_path: PathBuf, + pub robocorp_home_path: PathBuf, + pub robot_yaml_path: PathBuf, + pub build_timeout: u64, +} + +#[derive(Deserialize)] +#[serde(tag = "type")] +pub enum SessionConfig { + Current, + SpecificUser(UserSessionConfig), +} + +#[derive(Deserialize)] +pub struct UserSessionConfig { + pub user_name: String, +} + +impl Config { + pub fn suites(&self) -> Vec<(&String, &SuiteConfig)> { + let mut suites: Vec<(&String, &SuiteConfig)> = self.suites.iter().collect(); + suites.sort_by_key(|(suite_name, _suite_config)| suite_name.to_string()); + suites + } +} diff --git a/v2/rust/src/main.rs b/v2/rust/src/main.rs index c13518f8..0bf55a55 100644 --- a/v2/rust/src/main.rs +++ b/v2/rust/src/main.rs @@ -1,16 +1,24 @@ #![allow(dead_code)] pub mod attempt; mod cli; +mod config; mod logging; +pub mod parse_xml; +use anyhow::Context; use clap::Parser; -use log::info; -pub mod parse_xml; +use log::{debug, info}; +use logging::log_and_return_error; fn main() -> anyhow::Result<()> { let args = cli::Args::parse(); logging::init(args.log_specification(), &args.log_path)?; info!("Program started and logging set up"); - Ok(()).map_err(logging::log_and_return_error) + let _config = config::load(&args.config_path) + .context("Configuration loading failed") + .map_err(log_and_return_error)?; + debug!("Configuration loaded"); + + Ok(()) }