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
15 changes: 14 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions coman/.config/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[cscs]
current_system = "daint"
current_platform = "HPC"

image = "ubuntu"

Expand Down
1 change: 1 addition & 0 deletions coman/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ serde_json = "1.0.132"
signal-hook = "0.3.17"
strip-ansi-escapes = "0.2.0"
strum = { version = "0.26.3", features = ["derive"] }
strum_macros = "0.27.2"
tokio = { version = "1.47.1", features = ["full"] }
tokio-util = "0.7.16"
toml = "0.9.7"
Expand Down
9 changes: 7 additions & 2 deletions coman/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::{error::Error, path::PathBuf};

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

use crate::{
config::{get_config_dir, get_data_dir},
config::{ComputePlatform, get_config_dir, get_data_dir},
util::types::DockerImageUrl,
};

Expand All @@ -13,6 +14,10 @@ pub enum CliCommands {
Cscs {
#[command(subcommand)]
command: CscsCommands,
#[clap(short, long, help = "override compute system (e.g. 'eiger', 'daint')")]
system: Option<String>,
#[clap(short, long, ignore_case=true, value_parser=clap::builder::PossibleValuesParser::new(ComputePlatform::VARIANTS).map(|s|s.parse::<ComputePlatform>().unwrap()),help = "override compute platform (one of 'hpc', 'ml' or 'cw')")]
platform: Option<ComputePlatform>,
},
#[clap(about = "Create a new project configuration file")]
Init {
Expand Down
13 changes: 13 additions & 0 deletions coman/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use directories::ProjectDirs;
use eyre::eyre;
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use strum_macros::{EnumString, VariantNames};

const DEFAULT_CONFIG_TOML: &str = include_str!("../.config/config.toml");

Expand All @@ -23,11 +24,23 @@ pub struct AppConfig {
pub config_dir: PathBuf,
}

#[derive(Clone, Debug, Serialize, Deserialize, Default, strum::Display, EnumString, VariantNames)]
#[strum(serialize_all = "lowercase")]
#[allow(clippy::upper_case_acronyms)]
pub enum ComputePlatform {
#[default]
HPC,
ML,
CW,
}

#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct CscsConfig {
#[serde(default)]
pub current_system: String,
#[serde(default)]
pub current_platform: ComputePlatform,
#[serde(default)]
pub account: String,
#[serde(default)]
pub sbatch_script_template: String,
Expand Down
13 changes: 10 additions & 3 deletions coman/src/cscs/api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ use firecrest_client::{
use reqwest::Url;
use strum::Display;

use crate::trace_dbg;
use crate::{
config::{ComputePlatform, Config},
trace_dbg,
};

#[derive(Debug, Eq, Clone, PartialEq, PartialOrd, Ord, tabled::Tabled)]
pub struct UserInfo {
Expand Down Expand Up @@ -365,9 +368,13 @@ pub struct CscsApi {
}

impl CscsApi {
pub fn new(token: String) -> Result<Self> {
pub fn new(token: String, platform: Option<ComputePlatform>) -> Result<Self> {
let config = Config::new()?;
let client = FirecrestClient::default()
.base_path("https://api.cscs.ch/hpc/firecrest/v2/".to_owned())?
.base_path(format!(
"https://api.cscs.ch/{}/firecrest/v2/",
platform.unwrap_or(config.cscs.current_platform)
))?
.token(token);
Ok(Self { client })
}
Expand Down
67 changes: 49 additions & 18 deletions coman/src/cscs/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use tokio::{
};

use crate::{
config::ComputePlatform,
cscs::{
api_client::JobStatus,
handlers::{
Expand All @@ -38,8 +39,8 @@ pub(crate) async fn cli_cscs_login() -> Result<()> {
};
Ok(())
}
pub(crate) async fn cli_cscs_job_list() -> Result<()> {
match cscs_job_list().await {
pub(crate) async fn cli_cscs_job_list(system: Option<String>, platform: Option<ComputePlatform>) -> Result<()> {
match cscs_job_list(system, platform).await {
Ok(jobs) => {
let mut table = tabled::Table::new(jobs);
table.with(tabled::settings::Style::modern());
Expand All @@ -49,8 +50,12 @@ pub(crate) async fn cli_cscs_job_list() -> Result<()> {
Err(e) => Err(e),
}
}
pub(crate) async fn cli_cscs_job_detail(job_id: i64) -> Result<()> {
match cscs_job_details(job_id).await {
pub(crate) async fn cli_cscs_job_detail(
job_id: i64,
system: Option<String>,
platform: Option<ComputePlatform>,
) -> Result<()> {
match cscs_job_details(job_id, system, platform).await {
Ok(Some(job)) => {
let data = &[
("Id", job.id.to_string()),
Expand Down Expand Up @@ -80,8 +85,12 @@ pub(crate) async fn cli_cscs_job_detail(job_id: i64) -> Result<()> {
}
}

pub(crate) async fn cli_cscs_job_log(job_id: i64) -> Result<()> {
match cscs_job_log(job_id).await {
pub(crate) async fn cli_cscs_job_log(
job_id: i64,
system: Option<String>,
platform: Option<ComputePlatform>,
) -> Result<()> {
match cscs_job_log(job_id, system, platform).await {
Ok(content) => {
println!("{}", content);
Ok(())
Expand All @@ -96,16 +105,22 @@ pub(crate) async fn cli_cscs_job_start(
command: Option<Vec<String>>,
workdir: Option<String>,
env: Vec<(String, String)>,
system: Option<String>,
platform: Option<ComputePlatform>,
) -> Result<()> {
cscs_start_job(script_file, image, command, workdir, env).await
cscs_start_job(script_file, image, command, workdir, env, system, platform).await
}

pub(crate) async fn cli_cscs_job_cancel(job_id: i64) -> Result<()> {
cscs_job_cancel(job_id).await
pub(crate) async fn cli_cscs_job_cancel(
job_id: i64,
system: Option<String>,
platform: Option<ComputePlatform>,
) -> Result<()> {
cscs_job_cancel(job_id, system, platform).await
}

pub(crate) async fn cli_cscs_system_list() -> Result<()> {
match cscs_system_list().await {
pub(crate) async fn cli_cscs_system_list(platform: Option<ComputePlatform>) -> Result<()> {
match cscs_system_list(platform).await {
Ok(systems) => {
let mut table = tabled::Table::new(systems);
table.with(tabled::settings::Style::modern());
Expand All @@ -119,8 +134,12 @@ pub(crate) async fn cli_cscs_set_system(system_name: String, global: bool) -> Re
cscs_system_set(system_name, global).await
}

pub(crate) async fn cli_cscs_file_list(path: PathBuf) -> Result<()> {
match cscs_file_list(path).await {
pub(crate) async fn cli_cscs_file_list(
path: PathBuf,
system: Option<String>,
platform: Option<ComputePlatform>,
) -> Result<()> {
match cscs_file_list(path, system, platform).await {
Ok(path_entries) => {
let mut table = tabled::Table::new(path_entries);
table.with(tabled::settings::Style::empty());
Expand All @@ -131,8 +150,14 @@ pub(crate) async fn cli_cscs_file_list(path: PathBuf) -> Result<()> {
}
}

pub(crate) async fn cli_cscs_file_download(remote: PathBuf, local: PathBuf, account: Option<String>) -> Result<()> {
match cscs_file_download(remote, local.clone(), account).await {
pub(crate) async fn cli_cscs_file_download(
remote: PathBuf,
local: PathBuf,
account: Option<String>,
system: Option<String>,
platform: Option<ComputePlatform>,
) -> Result<()> {
match cscs_file_download(remote, local.clone(), account, system.clone(), platform.clone()).await {
Ok(None) => {
println!("File successfully downloaded");
Ok(())
Expand All @@ -143,7 +168,7 @@ pub(crate) async fn cli_cscs_file_download(remote: PathBuf, local: PathBuf, acco
println!("started s3 transfer job {}", job_data.0);
let mut transfer_done = false;
while !transfer_done {
if let Some(job) = cscs_job_details(job_data.0).await? {
if let Some(job) = cscs_job_details(job_data.0, system.clone(), platform.clone()).await? {
match job.status {
JobStatus::Pending | JobStatus::Running => {}
JobStatus::Finished => transfer_done = true,
Expand Down Expand Up @@ -182,8 +207,14 @@ pub(crate) async fn cli_cscs_file_download(remote: PathBuf, local: PathBuf, acco
}
}

pub(crate) async fn cli_cscs_file_upload(local: PathBuf, remote: PathBuf, account: Option<String>) -> Result<()> {
match cscs_file_upload(local.clone(), remote, account).await {
pub(crate) async fn cli_cscs_file_upload(
local: PathBuf,
remote: PathBuf,
account: Option<String>,
system: Option<String>,
platform: Option<ComputePlatform>,
) -> Result<()> {
match cscs_file_upload(local.clone(), remote, account, system, platform).await {
Ok(None) => {
println!("File successfully uploaded");
Ok(())
Expand Down
Loading