Skip to content

Commit 2a89847

Browse files
authored
minor improvements and bugfixes (#50)
* make image parameter optional * check job status in ssh proxy * wait for coman sqsh upload to finish before starting job * template local edf and sbatch files if specified * add coman config show command that shows whole config * warning for sqsh and ssh keys * add cancel job action to tui * add tui delete file option
1 parent 0f61194 commit 2a89847

12 files changed

Lines changed: 256 additions & 110 deletions

File tree

coman/.config/config.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ current_system = "daint" # what system/cluster to execute commands on
44
current_platform = "HPC" # what platform to execute commands on (valid: HPC, ML or CW)
55

66

7-
image = "ubuntu" # default docker image to use
7+
# image = "ubuntu" # default docker image to use
88

9-
command = [
10-
"sleep",
11-
"1",
12-
] # command to execute within the container, i.e. the job you want to run
9+
# command = [
10+
# "sleep",
11+
# "1",
12+
# ] # command to execute within the container, i.e. the job you want to run
1313

1414
# the sbatch script you want to execute
1515
# this gets templated with values specified in the {{}} and {% %} expressions (see https://keats.github.io/tera/docs/#templates for

coman/src/app/messages.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub enum JobMsg {
5555
Log(usize),
5656
Details(JobDetail),
5757
GetDetails(usize),
58+
Cancel(usize),
5859
Switch,
5960
Close,
6061
}

coman/src/app/model.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,18 @@ where
342342
});
343343
None
344344
}
345+
JobMsg::Cancel(jobid) => {
346+
let background_tx = self.background_task_tx.clone();
347+
let event_tx = self.user_event_tx.clone();
348+
tokio::spawn(async move {
349+
background_tx.send(BackgroundTask::CancelJob(jobid)).await.unwrap();
350+
event_tx
351+
.send(UserEvent::Status(StatusEvent::Info("cancelling job...".to_owned())))
352+
.await
353+
.unwrap();
354+
});
355+
None
356+
}
345357
JobMsg::Details(jobdetail) => {
346358
if self.app.mounted(&Id::WorkloadList) {
347359
assert!(

coman/src/app/user_events.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub enum FileEvent {
1818
List(String, Vec<PathEntry>), // Id, Subpaths
1919
DownloadCurrentFile,
2020
DownloadSuccessful,
21+
DeleteCurrentFile,
22+
DeleteSuccessful(String),
2123
}
2224

2325
#[derive(Debug, Eq, Clone, PartialEq, PartialOrd, Ord)]
@@ -26,13 +28,18 @@ pub enum StatusEvent {
2628
Info(String),
2729
Warning(String),
2830
}
31+
#[derive(Debug, Eq, Clone, PartialEq, PartialOrd, Ord)]
32+
pub enum JobEvent {
33+
Cancel,
34+
}
2935

3036
#[derive(Debug, Eq, Clone, PartialOrd, Ord)]
3137
pub enum UserEvent {
3238
Cscs(CscsEvent),
3339
File(FileEvent),
3440
Error(String),
3541
Info(String),
42+
Job(JobEvent),
3643
Status(StatusEvent),
3744
SwitchedToView(View),
3845
}

coman/src/cli.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ use strum::VariantNames;
1111

1212
use crate::{
1313
config::{ComputePlatform, Config, get_config_dir, get_data_dir, get_project_local_config_file},
14-
cscs::api_client::client::{EdfSpec as EdfSpecEnum, ScriptSpec as ScriptSpecEnum},
14+
cscs::{
15+
api_client::{
16+
client::{EdfSpec as EdfSpecEnum, ScriptSpec as ScriptSpecEnum},
17+
types::JobStatus,
18+
},
19+
handlers::cscs_job_details,
20+
},
1521
util::types::DockerImageUrl,
1622
};
1723

@@ -92,10 +98,14 @@ pub enum ConfigCommands {
9298
#[clap(help = "Value to set", value_parser = parse_toml_value, value_hint=ValueHint::Other)]
9399
value: toml_edit::Value,
94100
},
101+
#[clap(about = "Get config values")]
95102
Get {
96103
#[clap(help = "Config key path, e.g. `cscs.current_system`", value_hint=ValueHint::Other)]
97104
key_path: String,
98105
},
106+
107+
#[clap(about = "Show whole currently active config")]
108+
Show,
99109
}
100110

101111
#[allow(clippy::large_enum_variant)]
@@ -451,6 +461,14 @@ pub(crate) async fn cli_exec_command(command: Vec<String>) -> Result<()> {
451461
/// Thin wrapper around iroh proxy
452462
pub(crate) async fn cli_proxy_command(system: String, job_id: i64) -> Result<()> {
453463
let data_dir = get_data_dir();
464+
let job_info = cscs_job_details(job_id, Some(system.clone()), None).await?;
465+
if job_info.is_none() {
466+
return Err(eyre!("remote job does not exist!"));
467+
} else if let Some(job_info) = job_info
468+
&& job_info.status == JobStatus::Running
469+
{
470+
return Err(eyre!("remote job is not in running state, connection not available"));
471+
}
454472
let endpoint_id = std::fs::read_to_string(data_dir.join(format!("{}_{}.endpoint", system, job_id)))?;
455473
println!("{}", endpoint_id);
456474
iroh_ssh::api::proxy_mode(iroh_ssh::ProxyArgs { node_id: endpoint_id })

coman/src/components/context_menu.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use tuirealm::{
88

99
use crate::app::{
1010
messages::{MenuMsg, Msg, View},
11-
user_events::{FileEvent, UserEvent},
11+
user_events::{FileEvent, JobEvent, UserEvent},
1212
};
1313

1414
#[derive(MockComponent)]
@@ -24,6 +24,8 @@ impl ContextMenu {
2424
.add_row()
2525
.add_col(TextSpan::from("Switch System").fg(Color::Cyan))
2626
.add_row()
27+
.add_col(TextSpan::from("Cancel Job").fg(Color::Cyan))
28+
.add_row()
2729
.add_col(TextSpan::from("Quit").fg(Color::Cyan))
2830
.add_row()
2931
.build()
@@ -32,7 +34,8 @@ impl ContextMenu {
3234
match index {
3335
0 => Some(Msg::Menu(MenuMsg::CscsLogin)),
3436
1 => Some(Msg::Menu(MenuMsg::CscsSwitchSystem)),
35-
2 => Some(Msg::AppClose),
37+
2 => Some(Msg::Menu(MenuMsg::Event(UserEvent::Job(JobEvent::Cancel)))),
38+
3 => Some(Msg::AppClose),
3639
_ => Some(Msg::Menu(MenuMsg::Closed)),
3740
}
3841
}
@@ -44,6 +47,8 @@ impl ContextMenu {
4447
.add_row()
4548
.add_col(TextSpan::from("Download").fg(Color::Cyan))
4649
.add_row()
50+
.add_col(TextSpan::from("Delete").fg(Color::Cyan))
51+
.add_row()
4752
.add_col(TextSpan::from("Quit").fg(Color::Cyan))
4853
.add_row()
4954
.build()
@@ -55,7 +60,8 @@ impl ContextMenu {
5560
2 => Some(Msg::Menu(MenuMsg::Event(UserEvent::File(
5661
FileEvent::DownloadCurrentFile,
5762
)))),
58-
3 => Some(Msg::AppClose),
63+
3 => Some(Msg::Menu(MenuMsg::Event(UserEvent::File(FileEvent::DeleteCurrentFile)))),
64+
4 => Some(Msg::AppClose),
5965
_ => Some(Msg::Menu(MenuMsg::Closed)),
6066
}
6167
}

coman/src/components/file_tree.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::{
1515
user_events::{FileEvent, UserEvent},
1616
},
1717
cscs::{api_client::types::PathType, ports::BackgroundTask},
18+
trace_dbg,
1819
};
1920

2021
#[derive(Debug, PartialEq, PartialOrd, Ord, Eq, Clone)]
@@ -174,6 +175,27 @@ impl Component<Msg, UserEvent> for FileTree {
174175
}
175176
CmdResult::None
176177
}
178+
Event::User(UserEvent::File(FileEvent::DeleteCurrentFile)) => {
179+
if let State::One(StateValue::String(id)) = self.state() {
180+
let tree_tx = self.file_tree_tx.clone();
181+
let id = trace_dbg!(id);
182+
tokio::spawn(async move {
183+
tree_tx.send(BackgroundTask::DeleteFile(id)).await.unwrap();
184+
});
185+
}
186+
CmdResult::None
187+
}
188+
Event::User(UserEvent::File(FileEvent::DeleteSuccessful(id))) => {
189+
let mut selected_id = id.clone();
190+
let tree = self.component.tree_mut();
191+
let parent = tree.root_mut().parent_mut(&id);
192+
if let Some(parent) = parent {
193+
parent.remove_child(&id);
194+
selected_id = parent.id().clone();
195+
}
196+
self.attr(Attribute::Custom(TREE_INITIAL_NODE), AttrValue::String(selected_id));
197+
CmdResult::Changed(self.component.state())
198+
}
177199
_ => CmdResult::None,
178200
};
179201
Some(Msg::None)

coman/src/components/workload_list.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ impl Component<Msg, UserEvent> for WorkloadList {
8181
}
8282
self.perform(Cmd::Change)
8383
}
84+
Event::User(UserEvent::Job(crate::app::user_events::JobEvent::Cancel)) => {
85+
if let State::One(StateValue::Usize(index)) = self.state()
86+
&& !self.jobs.is_empty()
87+
{
88+
let job = self.jobs[index].clone();
89+
return Some(Msg::Job(JobMsg::Cancel(job.id)));
90+
}
91+
CmdResult::None
92+
}
8493
Event::Keyboard(KeyEvent { code: Key::Enter, .. }) => {
8594
if let State::One(StateValue::Usize(index)) = self.state()
8695
&& !self.jobs.is_empty()

coman/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub struct CscsConfig {
5858
#[serde(default)]
5959
pub env: HashMap<String, String>,
6060
#[serde(default)]
61-
pub image: String,
61+
pub image: Option<String>,
6262
#[serde(default)]
6363
pub edf_file_template: String,
6464
#[serde(default)]

0 commit comments

Comments
 (0)