Skip to content

Commit

Permalink
Scheduler: Introduce suite grouping at the external config level
Browse files Browse the repository at this point in the history
  • Loading branch information
jherbel committed Jan 12, 2024
1 parent 6621804 commit 11c5e00
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 123 deletions.
112 changes: 61 additions & 51 deletions src/bin/scheduler/internal_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,44 +46,44 @@ pub fn from_external_config(
cancellation_token: CancellationToken,
results_directory_locker: Locker,
) -> (GlobalConfig, Vec<Suite>) {
let mut suites: Vec<Suite> = external_config
.suites
.into_iter()
.enumerate()
.map(|(suite_index, (suite_id, suite_config))| Suite {
id: suite_id.clone(),
working_directory: external_config
.working_directory
.join("suites")
.join(&suite_id),
results_file: suite_results_directory(&external_config.results_directory)
.join(format!("{}.json", suite_id)),
timeout: suite_config.execution_config.timeout,
robot: Robot {
robot_target: suite_config.robot_config.robot_target,
command_line_args: suite_config.robot_config.command_line_args,
n_attempts_max: suite_config.execution_config.n_attempts_max,
retry_strategy: suite_config.execution_config.retry_strategy,
},
environment: Environment::new(
&suite_id,
&external_config.rcc_config.binary_path,
&suite_config.environment_config,
),
session: Session::new(&suite_config.session_config),
working_directory_cleanup_config: suite_config.working_directory_cleanup_config,
cancellation_token: cancellation_token.clone(),
host: suite_config.host,
results_directory_locker: results_directory_locker.clone(),
metadata: suite_config.metadata,
group_affiliation: GroupAffiliation {
group_index: suite_index,
position_in_group: 0,
execution_interval: suite_config.execution_config.execution_interval_seconds,
},
})
.collect();
sort_suites_by_id(&mut suites);
let mut suites = vec![];

for (group_index, sequential_group) in external_config.suite_groups.into_iter().enumerate() {
for (suite_index, suite_config) in sequential_group.suites.into_iter().enumerate() {
suites.push(Suite {
id: suite_config.id.clone(),
working_directory: external_config
.working_directory
.join("suites")
.join(&suite_config.id),
results_file: suite_results_directory(&external_config.results_directory)
.join(format!("{}.json", suite_config.id)),
timeout: suite_config.execution_config.timeout,
robot: Robot {
robot_target: suite_config.robot_config.robot_target,
command_line_args: suite_config.robot_config.command_line_args,
n_attempts_max: suite_config.execution_config.n_attempts_max,
retry_strategy: suite_config.execution_config.retry_strategy,
},
environment: Environment::new(
&suite_config.id,
&external_config.rcc_config.binary_path,
&suite_config.environment_config,
),
session: Session::new(&suite_config.session_config),
working_directory_cleanup_config: suite_config.working_directory_cleanup_config,
cancellation_token: cancellation_token.clone(),
host: suite_config.host,
results_directory_locker: results_directory_locker.clone(),
metadata: suite_config.metadata,
group_affiliation: GroupAffiliation {
group_index,
position_in_group: suite_index,
execution_interval: sequential_group.execution_interval,
},
});
}
}
(
GlobalConfig {
working_directory: external_config.working_directory,
Expand All @@ -96,31 +96,35 @@ pub fn from_external_config(
)
}

pub fn sort_suites_by_id(suites: &mut [Suite]) {
suites.sort_by_key(|suite| suite.id.to_string());
pub fn sort_suites_by_grouping(suites: &mut [Suite]) {
suites.sort_by_key(|suite| {
(
suite.group_affiliation.group_index,
suite.group_affiliation.position_in_group,
)
});
}

#[cfg(test)]
mod tests {
use super::*;
use robotmk::config::{
CustomRCCProfileConfig, EnvironmentConfig, ExecutionConfig, RCCEnvironmentConfig,
RCCProfileConfig, RetryStrategy, RobotConfig, SessionConfig, SuiteConfig,
UserSessionConfig,
RCCProfileConfig, RetryStrategy, RobotConfig, SequentialSuiteGroup, SessionConfig,
SuiteConfig, UserSessionConfig,
};
use robotmk::environment::{Environment, RCCEnvironment, SystemEnvironment};
use std::collections::HashMap;

fn system_suite_config() -> SuiteConfig {
SuiteConfig {
id: "system".into(),
robot_config: RobotConfig {
robot_target: Utf8PathBuf::from("/suite/system/tasks.robot"),
command_line_args: vec![],
},
execution_config: ExecutionConfig {
n_attempts_max: 1,
retry_strategy: RetryStrategy::Incremental,
execution_interval_seconds: 300,
timeout: 60,
},
environment_config: EnvironmentConfig::System,
Expand All @@ -135,14 +139,14 @@ mod tests {

fn rcc_suite_config() -> SuiteConfig {
SuiteConfig {
id: "rcc".into(),
robot_config: RobotConfig {
robot_target: Utf8PathBuf::from("/suite/rcc/tasks.robot"),
command_line_args: vec![],
},
execution_config: ExecutionConfig {
n_attempts_max: 1,
retry_strategy: RetryStrategy::Complete,
execution_interval_seconds: 300,
timeout: 60,
},
environment_config: EnvironmentConfig::Rcc(RCCEnvironmentConfig {
Expand Down Expand Up @@ -175,10 +179,16 @@ mod tests {
path: "/rcc_profile_robotmk.yaml".into(),
}),
},
suites: HashMap::from([
(String::from("system"), system_suite_config()),
(String::from("rcc"), rcc_suite_config()),
]),
suite_groups: vec![
SequentialSuiteGroup {
suites: vec![rcc_suite_config()],
execution_interval: 300,
},
SequentialSuiteGroup {
suites: vec![system_suite_config()],
execution_interval: 300,
},
],
},
cancellation_token.clone(),
Locker::new("/config.json", Some(&cancellation_token)),
Expand Down Expand Up @@ -233,7 +243,7 @@ mod tests {
assert_eq!(
suites[0].group_affiliation,
GroupAffiliation {
group_index: 1,
group_index: 0,
position_in_group: 0,
execution_interval: 300,
}
Expand Down Expand Up @@ -268,7 +278,7 @@ mod tests {
assert_eq!(
suites[1].group_affiliation,
GroupAffiliation {
group_index: 0,
group_index: 1,
position_in_group: 0,
execution_interval: 300,
}
Expand Down
4 changes: 2 additions & 2 deletions src/bin/scheduler/setup/rcc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::all_configured_users;
use super::icacls::run_icacls_command;
use crate::internal_config::{sort_suites_by_id, GlobalConfig, Suite};
use crate::internal_config::{sort_suites_by_grouping, GlobalConfig, Suite};
use crate::logging::log_and_return_error;
use robotmk::command_spec::CommandSpec;
use robotmk::environment::Environment;
Expand Down Expand Up @@ -42,7 +42,7 @@ pub fn setup(global_config: &GlobalConfig, suites: Vec<Suite>) -> AnyhowResult<V
}

surviving_suites.append(&mut rcc_setup(global_config, rcc_suites)?);
sort_suites_by_id(&mut surviving_suites);
sort_suites_by_grouping(&mut surviving_suites);
Ok(surviving_suites)
}

Expand Down
11 changes: 8 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use anyhow::Result as AnyhowResult;
use camino::{Utf8Path, Utf8PathBuf};
use serde::{Deserialize, Serialize};
use serde_json::from_str;
use std::collections::HashMap;
use std::fs::read_to_string;

pub fn load(path: &Utf8Path) -> AnyhowResult<Config> {
Expand All @@ -15,7 +14,7 @@ pub struct Config {
pub working_directory: Utf8PathBuf,
pub results_directory: Utf8PathBuf,
pub rcc_config: RCCConfig,
pub suites: HashMap<String, SuiteConfig>,
pub suite_groups: Vec<SequentialSuiteGroup>,
}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
Expand All @@ -36,8 +35,15 @@ pub struct CustomRCCProfileConfig {
pub path: Utf8PathBuf,
}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct SequentialSuiteGroup {
pub suites: Vec<SuiteConfig>,
pub execution_interval: u64,
}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct SuiteConfig {
pub id: String,
pub robot_config: RobotConfig,
pub execution_config: ExecutionConfig,
pub environment_config: EnvironmentConfig,
Expand All @@ -57,7 +63,6 @@ pub struct RobotConfig {
pub struct ExecutionConfig {
pub n_attempts_max: usize,
pub retry_strategy: RetryStrategy,
pub execution_interval_seconds: u64,
pub timeout: u64,
}

Expand Down
Loading

0 comments on commit 11c5e00

Please sign in to comment.