Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions coman/.config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ sbatch_script_template = """
#SBATCH --job-name={{name}}
#SBATCH --ntasks=1
#SBATCH --time=10:00
srun --environment={{environment_file}} {{command}}
srun {% if environment_file %}--environment={{environment_file}}{% endif %} {{command}}
"""

edf_file_template = """
image = "{{edf_image}}"
{% if edf_image %}image = "{{edf_image}}"{% endif %}
mounts = [{% for source, target in mount %}"{{source}}:{{target}}",{% endfor %}]
workdir = "{{container_workdir}}"

Expand Down
84 changes: 79 additions & 5 deletions coman/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::{error::Error, path::PathBuf};

use clap::{Parser, Subcommand, builder::TypedValueParser};
use clap::{Args, Parser, Subcommand, builder::TypedValueParser};
use strum::VariantNames;

use crate::{
config::{ComputePlatform, get_config_dir, get_data_dir, get_project_local_config_file},
cscs::api_client::client::{EdfSpec as EdfSpecEnum, ScriptSpec as ScriptSpecEnum},
util::types::DockerImageUrl,
};

Expand Down Expand Up @@ -56,6 +57,77 @@ pub enum CscsCommands {
},
}

#[derive(Args, Clone, Debug)]
#[group(multiple = false)]
pub struct ScriptSpec {
#[arg(
long,
help = "generate and upload script file based on template (on by default unless `--local` or `--remote` are passed)"
)]
generate_script: bool,
#[arg(long, value_name = "PATH", help = "upload local script file")]
local_script: Option<PathBuf>,
#[arg(long, value_name = "PATH", help = "use script file already present on remote")]
remote_script: Option<PathBuf>,
}
impl Default for ScriptSpec {
fn default() -> Self {
Self {
generate_script: true,
local_script: Default::default(),
remote_script: Default::default(),
}
}
}

impl From<ScriptSpec> for ScriptSpecEnum {
fn from(val: ScriptSpec) -> Self {
if let Some(local_script) = val.local_script {
ScriptSpecEnum::Local(local_script)
} else if let Some(remote_script) = val.remote_script {
ScriptSpecEnum::Remote(remote_script)
} else {
ScriptSpecEnum::Generate
}
}
}

#[derive(Args, Clone, Debug)]
#[group(multiple = false)]
pub struct EdfSpec {
#[arg(
long,
help = "generate and upload edf file based on template (on by default unless `--local` or `--remote` are passed)"
)]
generate_edf: bool,
#[arg(long, value_name = "PATH", help = "upload local edf file")]
local_edf: Option<PathBuf>,
#[arg(long, value_name = "PATH", help = "use edf file already present on remote")]
remote_edf: Option<PathBuf>,
}

impl Default for EdfSpec {
fn default() -> Self {
Self {
generate_edf: true,
local_edf: Default::default(),
remote_edf: Default::default(),
}
}
}

impl From<EdfSpec> for EdfSpecEnum {
fn from(val: EdfSpec) -> Self {
if let Some(local_edf) = val.local_edf {
EdfSpecEnum::Local(local_edf)
} else if let Some(remote_edf) = val.remote_edf {
EdfSpecEnum::Remote(remote_edf)
} else {
EdfSpecEnum::Generate
}
}
}

#[allow(clippy::large_enum_variant)]
#[derive(Subcommand, Debug)]
pub enum CscsJobCommands {
Expand All @@ -74,8 +146,6 @@ pub enum CscsJobCommands {
Submit {
#[clap(short, long, help = "name of the job")]
name: Option<String>,
#[clap(short, long, help = "the path to the srun script file to use")]
script_file: Option<PathBuf>,
#[clap(
short,
long,
Expand All @@ -88,10 +158,14 @@ pub enum CscsJobCommands {
mount: Vec<(String, String)>,
#[clap(short, long, help = "The docker image to use")]
image: Option<DockerImageUrl>,
#[clap(short, long, help = "Path where stdout of the job gets written to")]
#[clap(long, help = "Path where stdout of the job gets written to")]
stdout: Option<PathBuf>,
#[clap(short, long, help = "Path where stderr of the job gets written to")]
#[clap(long, help = "Path where stderr of the job gets written to")]
stderr: Option<PathBuf>,
#[command(flatten)]
edf_spec: Option<EdfSpec>,
#[command(flatten)]
script_spec: Option<ScriptSpec>,
#[clap(trailing_var_arg = true, help = "The command to run in the container")]
command: Option<Vec<String>>,
},
Expand Down
17 changes: 16 additions & 1 deletion coman/src/cscs/api_client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,32 @@ use crate::{
trace_dbg,
util::types::DockerImageUrl,
};
#[derive(Debug, Clone, Default)]
pub enum ScriptSpec {
#[default]
Generate,
Local(PathBuf),
Remote(PathBuf),
}
#[derive(Debug, Clone, Default)]
pub enum EdfSpec {
#[default]
Generate,
Local(PathBuf),
Remote(PathBuf),
}

#[derive(Debug, Clone, Default)]
pub struct JobStartOptions {
pub script_file: Option<PathBuf>,
pub image: Option<DockerImageUrl>,
pub command: Option<Vec<String>>,
pub stdout: Option<PathBuf>,
pub stderr: Option<PathBuf>,
pub container_workdir: Option<String>,
pub env: Vec<(String, String)>,
pub mount: Vec<(String, String)>,
pub edf_spec: EdfSpec,
pub script_spec: ScriptSpec,
}

pub struct CscsApi {
Expand Down
4 changes: 2 additions & 2 deletions coman/src/cscs/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
api_client::{client::JobStartOptions, types::JobStatus},
handlers::{
cscs_file_download, cscs_file_list, cscs_file_upload, cscs_job_cancel, cscs_job_details, cscs_job_list,
cscs_job_log, cscs_login, cscs_start_job, cscs_system_list, cscs_system_set,
cscs_job_log, cscs_job_start, cscs_login, cscs_system_list, cscs_system_set,
},
},
};
Expand Down Expand Up @@ -107,7 +107,7 @@ pub(crate) async fn cli_cscs_job_start(
platform: Option<ComputePlatform>,
account: Option<String>,
) -> Result<()> {
match cscs_start_job(name, options, system, platform, account).await {
match cscs_job_start(name, options, system, platform, account).await {
Ok(_) => {
println!("Job started");
Ok(())
Expand Down
Loading