|
|
@@ -3,6 +3,8 @@ use serde::Deserialize;
|
|
|
use std::collections::HashMap;
|
|
|
use tracing::info;
|
|
|
|
|
|
+pub use crate::pre_serve::{BeforeServeTable, OnFailure, PreServeCommand};
|
|
|
+
|
|
|
#[derive(Clone, Deserialize)]
|
|
|
pub struct Node {
|
|
|
pub name: String,
|
|
|
@@ -28,48 +30,6 @@ pub struct Cluster {
|
|
|
pub nodes: Vec<Node>,
|
|
|
}
|
|
|
|
|
|
-/// Behaviour on a non-zero exit code for a [`PreServeCommand`].
|
|
|
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Deserialize)]
|
|
|
-#[serde(rename_all = "lowercase")]
|
|
|
-pub enum OnFailure {
|
|
|
- /// Abort the serve (default).
|
|
|
- #[default]
|
|
|
- Abort,
|
|
|
- /// Log a warning but continue.
|
|
|
- Warn,
|
|
|
- /// Continue silently.
|
|
|
- Continue,
|
|
|
-}
|
|
|
-
|
|
|
-/// One entry in a `before_serve` block. Either a bare command string
|
|
|
-/// (defaults to `on_failure = abort`) or a table with explicit `on_failure`.
|
|
|
-#[derive(Clone, Debug, Deserialize)]
|
|
|
-#[serde(untagged)]
|
|
|
-pub enum PreServeCommand {
|
|
|
- Bare(String),
|
|
|
- Configured {
|
|
|
- command: String,
|
|
|
- #[serde(default)]
|
|
|
- on_failure: OnFailure,
|
|
|
- },
|
|
|
-}
|
|
|
-
|
|
|
-impl PreServeCommand {
|
|
|
- pub fn command(&self) -> &str {
|
|
|
- match self {
|
|
|
- PreServeCommand::Bare(c) => c,
|
|
|
- PreServeCommand::Configured { command, .. } => command,
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- pub fn on_failure(&self) -> OnFailure {
|
|
|
- match self {
|
|
|
- PreServeCommand::Bare(_) => OnFailure::default(),
|
|
|
- PreServeCommand::Configured { on_failure, .. } => *on_failure,
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
/// Top-level config containing cluster definitions and per-cluster
|
|
|
/// pre-serve commands.
|
|
|
#[derive(Clone, Deserialize)]
|
|
|
@@ -88,14 +48,10 @@ pub struct Config {
|
|
|
/// Per-cluster pre-serve commands. Looked up by cluster name.
|
|
|
#[serde(default)]
|
|
|
pub before_serve: HashMap<String, BeforeServeTable>,
|
|
|
-}
|
|
|
-
|
|
|
-/// TOML sub-table under `[before_serve."<cluster>"]`. Currently only
|
|
|
-/// carries `commands`; reserved for future per-cluster tuning.
|
|
|
-#[derive(Clone, Debug, Default, Deserialize)]
|
|
|
-pub struct BeforeServeTable {
|
|
|
+ /// Command aliases for `cargo run exec --alias`. Keyed by alias
|
|
|
+ /// name, value is the shell command to run.
|
|
|
#[serde(default)]
|
|
|
- pub commands: Vec<PreServeCommand>,
|
|
|
+ pub exec_aliases: HashMap<String, String>,
|
|
|
}
|
|
|
|
|
|
fn default_init_port() -> u16 {
|
|
|
@@ -400,6 +356,7 @@ nodes = [
|
|
|
hf_cache_dir: None,
|
|
|
init_port: 25000,
|
|
|
before_serve: HashMap::new(),
|
|
|
+ exec_aliases: HashMap::new(),
|
|
|
};
|
|
|
config.nccl.insert("test-cluster".to_string(), test_nccl());
|
|
|
|
|
|
@@ -418,6 +375,7 @@ nodes = [
|
|
|
hf_cache_dir: None,
|
|
|
init_port: 25000,
|
|
|
before_serve: HashMap::new(),
|
|
|
+ exec_aliases: HashMap::new(),
|
|
|
};
|
|
|
config.nccl.insert("test-cluster".to_string(), test_nccl());
|
|
|
|
|
|
@@ -436,6 +394,7 @@ nodes = [
|
|
|
hf_cache_dir: None,
|
|
|
init_port: 25000,
|
|
|
before_serve: HashMap::new(),
|
|
|
+ exec_aliases: HashMap::new(),
|
|
|
};
|
|
|
let result = select_cluster(&config, "auto");
|
|
|
assert!(result.is_err());
|
|
|
@@ -451,6 +410,7 @@ nodes = [
|
|
|
hf_cache_dir: None,
|
|
|
init_port: 25000,
|
|
|
before_serve: HashMap::new(),
|
|
|
+ exec_aliases: HashMap::new(),
|
|
|
};
|
|
|
let result = select_cluster(&config, "nonexistent");
|
|
|
assert!(result.is_err());
|
|
|
@@ -468,6 +428,7 @@ nodes = [
|
|
|
hf_cache_dir: None,
|
|
|
init_port: 25000,
|
|
|
before_serve: HashMap::new(),
|
|
|
+ exec_aliases: HashMap::new(),
|
|
|
};
|
|
|
let cluster = select_cluster_by_name(&config, "test-cluster").unwrap();
|
|
|
assert_eq!(cluster.name, "test-cluster");
|
|
|
@@ -484,6 +445,7 @@ nodes = [
|
|
|
hf_cache_dir: None,
|
|
|
init_port: 25000,
|
|
|
before_serve: HashMap::new(),
|
|
|
+ exec_aliases: HashMap::new(),
|
|
|
};
|
|
|
let result = select_cluster_by_name(&config, "no-such-cluster");
|
|
|
assert!(result.is_err());
|