Skip to content

Commit 3cd6a1f

Browse files
authored
allow specifying custom edf and script file on job submission (#42)
* allow specifying edf source * allow specifying script source
1 parent 31fde46 commit 3cd6a1f

6 files changed

Lines changed: 232 additions & 71 deletions

File tree

coman/.config/config.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ sbatch_script_template = """
1111
#SBATCH --job-name={{name}}
1212
#SBATCH --ntasks=1
1313
#SBATCH --time=10:00
14-
srun --environment={{environment_file}} {{command}}
14+
srun {% if environment_file %}--environment={{environment_file}}{% endif %} {{command}}
1515
"""
1616

1717
edf_file_template = """
18-
image = "{{edf_image}}"
18+
{% if edf_image %}image = "{{edf_image}}"{% endif %}
1919
mounts = [{% for source, target in mount %}"{{source}}:{{target}}",{% endfor %}]
2020
workdir = "{{container_workdir}}"
2121

coman/src/cli.rs

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use std::{error::Error, path::PathBuf};
22

3-
use clap::{Parser, Subcommand, builder::TypedValueParser};
3+
use clap::{Args, Parser, Subcommand, builder::TypedValueParser};
44
use strum::VariantNames;
55

66
use crate::{
77
config::{ComputePlatform, get_config_dir, get_data_dir, get_project_local_config_file},
8+
cscs::api_client::client::{EdfSpec as EdfSpecEnum, ScriptSpec as ScriptSpecEnum},
89
util::types::DockerImageUrl,
910
};
1011

@@ -56,6 +57,77 @@ pub enum CscsCommands {
5657
},
5758
}
5859

60+
#[derive(Args, Clone, Debug)]
61+
#[group(multiple = false)]
62+
pub struct ScriptSpec {
63+
#[arg(
64+
long,
65+
help = "generate and upload script file based on template (on by default unless `--local` or `--remote` are passed)"
66+
)]
67+
generate_script: bool,
68+
#[arg(long, value_name = "PATH", help = "upload local script file")]
69+
local_script: Option<PathBuf>,
70+
#[arg(long, value_name = "PATH", help = "use script file already present on remote")]
71+
remote_script: Option<PathBuf>,
72+
}
73+
impl Default for ScriptSpec {
74+
fn default() -> Self {
75+
Self {
76+
generate_script: true,
77+
local_script: Default::default(),
78+
remote_script: Default::default(),
79+
}
80+
}
81+
}
82+
83+
impl From<ScriptSpec> for ScriptSpecEnum {
84+
fn from(val: ScriptSpec) -> Self {
85+
if let Some(local_script) = val.local_script {
86+
ScriptSpecEnum::Local(local_script)
87+
} else if let Some(remote_script) = val.remote_script {
88+
ScriptSpecEnum::Remote(remote_script)
89+
} else {
90+
ScriptSpecEnum::Generate
91+
}
92+
}
93+
}
94+
95+
#[derive(Args, Clone, Debug)]
96+
#[group(multiple = false)]
97+
pub struct EdfSpec {
98+
#[arg(
99+
long,
100+
help = "generate and upload edf file based on template (on by default unless `--local` or `--remote` are passed)"
101+
)]
102+
generate_edf: bool,
103+
#[arg(long, value_name = "PATH", help = "upload local edf file")]
104+
local_edf: Option<PathBuf>,
105+
#[arg(long, value_name = "PATH", help = "use edf file already present on remote")]
106+
remote_edf: Option<PathBuf>,
107+
}
108+
109+
impl Default for EdfSpec {
110+
fn default() -> Self {
111+
Self {
112+
generate_edf: true,
113+
local_edf: Default::default(),
114+
remote_edf: Default::default(),
115+
}
116+
}
117+
}
118+
119+
impl From<EdfSpec> for EdfSpecEnum {
120+
fn from(val: EdfSpec) -> Self {
121+
if let Some(local_edf) = val.local_edf {
122+
EdfSpecEnum::Local(local_edf)
123+
} else if let Some(remote_edf) = val.remote_edf {
124+
EdfSpecEnum::Remote(remote_edf)
125+
} else {
126+
EdfSpecEnum::Generate
127+
}
128+
}
129+
}
130+
59131
#[allow(clippy::large_enum_variant)]
60132
#[derive(Subcommand, Debug)]
61133
pub enum CscsJobCommands {
@@ -74,8 +146,6 @@ pub enum CscsJobCommands {
74146
Submit {
75147
#[clap(short, long, help = "name of the job")]
76148
name: Option<String>,
77-
#[clap(short, long, help = "the path to the srun script file to use")]
78-
script_file: Option<PathBuf>,
79149
#[clap(
80150
short,
81151
long,
@@ -88,10 +158,14 @@ pub enum CscsJobCommands {
88158
mount: Vec<(String, String)>,
89159
#[clap(short, long, help = "The docker image to use")]
90160
image: Option<DockerImageUrl>,
91-
#[clap(short, long, help = "Path where stdout of the job gets written to")]
161+
#[clap(long, help = "Path where stdout of the job gets written to")]
92162
stdout: Option<PathBuf>,
93-
#[clap(short, long, help = "Path where stderr of the job gets written to")]
163+
#[clap(long, help = "Path where stderr of the job gets written to")]
94164
stderr: Option<PathBuf>,
165+
#[command(flatten)]
166+
edf_spec: Option<EdfSpec>,
167+
#[command(flatten)]
168+
script_spec: Option<ScriptSpec>,
95169
#[clap(trailing_var_arg = true, help = "The command to run in the container")]
96170
command: Option<Vec<String>>,
97171
},

coman/src/cscs/api_client/client.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,32 @@ use crate::{
2424
trace_dbg,
2525
util::types::DockerImageUrl,
2626
};
27+
#[derive(Debug, Clone, Default)]
28+
pub enum ScriptSpec {
29+
#[default]
30+
Generate,
31+
Local(PathBuf),
32+
Remote(PathBuf),
33+
}
34+
#[derive(Debug, Clone, Default)]
35+
pub enum EdfSpec {
36+
#[default]
37+
Generate,
38+
Local(PathBuf),
39+
Remote(PathBuf),
40+
}
2741

2842
#[derive(Debug, Clone, Default)]
2943
pub struct JobStartOptions {
30-
pub script_file: Option<PathBuf>,
3144
pub image: Option<DockerImageUrl>,
3245
pub command: Option<Vec<String>>,
3346
pub stdout: Option<PathBuf>,
3447
pub stderr: Option<PathBuf>,
3548
pub container_workdir: Option<String>,
3649
pub env: Vec<(String, String)>,
3750
pub mount: Vec<(String, String)>,
51+
pub edf_spec: EdfSpec,
52+
pub script_spec: ScriptSpec,
3853
}
3954

4055
pub struct CscsApi {

coman/src/cscs/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::{
2121
api_client::{client::JobStartOptions, types::JobStatus},
2222
handlers::{
2323
cscs_file_download, cscs_file_list, cscs_file_upload, cscs_job_cancel, cscs_job_details, cscs_job_list,
24-
cscs_job_log, cscs_login, cscs_start_job, cscs_system_list, cscs_system_set,
24+
cscs_job_log, cscs_job_start, cscs_login, cscs_system_list, cscs_system_set,
2525
},
2626
},
2727
};
@@ -107,7 +107,7 @@ pub(crate) async fn cli_cscs_job_start(
107107
platform: Option<ComputePlatform>,
108108
account: Option<String>,
109109
) -> Result<()> {
110-
match cscs_start_job(name, options, system, platform, account).await {
110+
match cscs_job_start(name, options, system, platform, account).await {
111111
Ok(_) => {
112112
println!("Job started");
113113
Ok(())

0 commit comments

Comments
 (0)