Skip to content

Commit 0ac4f62

Browse files
committed
update firecrest api, fix coman squash downloading, fix tests
1 parent 7623c98 commit 0ac4f62

8 files changed

Lines changed: 150 additions & 59 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coman/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,3 @@ current_dir = "0.1.2"
9494
injectorpp = "0.4.0"
9595
rstest = "0.26.1"
9696
tempfile = "3.24.0"
97-
tmp_env = "0.1.1"

coman/src/config.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@ mod tests {
449449
assert_eq!(layer.data.to_string(), "[cscs]\nvalue=10\nother_value = 20\n");
450450
}
451451

452-
#[cfg(target_family = "unix")]
453452
#[test]
454453
fn test_config_read_write() {
455454
let project_dir = tempdir().expect("couldn't create temp dir");
@@ -474,8 +473,33 @@ mod tests {
474473
std::fs::create_dir_all(global_config.parent().unwrap()).expect("couldn't create config dir");
475474
std::fs::write(&global_config, "[cscs]\ncurrent_system = \"global\"").expect("couldn't create config file");
476475

477-
let _tmp_env = tmp_env::set_var("HOME", home_dir.path().as_os_str());
478-
let mut conf = Config::new().expect("couldn't load config");
476+
let default_layer: DocumentMut = DEFAULT_CONFIG_TOML.parse().expect("couldn't parse default config");
477+
let global_layer = Layer::from_path(global_config).expect("couldn't create global layer");
478+
let project_layer = Layer::from_path(project_config).expect("couldn't create project layer");
479+
let mut builder =
480+
config::Config::builder().add_source(config::File::from_str(DEFAULT_CONFIG_TOML, config::FileFormat::Toml));
481+
builder = builder
482+
.add_source(config::File::from_str(
483+
&global_layer.data.to_string(),
484+
config::FileFormat::Toml,
485+
))
486+
.add_source(config::File::from_str(
487+
&project_layer.data.to_string(),
488+
config::FileFormat::Toml,
489+
));
490+
491+
let cfg: ComanConfig = builder
492+
.build()
493+
.expect("couldn't build")
494+
.try_deserialize()
495+
.expect("couldn't deserialize");
496+
let mut conf = Config {
497+
values: cfg,
498+
default_layer,
499+
global_layer,
500+
project_layer: Some(project_layer),
501+
};
502+
479503
assert_eq!(conf.values.cscs.current_system, "project");
480504
conf.set("cscs.current_system", "global2", true)
481505
.expect("couldn't set global config value");

coman/src/cscs/api_client/client.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use firecrest_client::{
99
get_compute_system_jobs, post_compute_system_job,
1010
},
1111
filesystem_api::{
12-
get_filesystem_ops_download, get_filesystem_ops_ls, get_filesystem_ops_stat, get_filesystem_ops_tail,
13-
post_filesystem_ops_mkdir, post_filesystem_ops_upload, post_filesystem_transfer_download,
14-
post_filesystem_transfer_upload, put_filesystem_ops_chmod,
12+
delete_filesystem_ops_rm, get_filesystem_ops_download, get_filesystem_ops_ls, get_filesystem_ops_stat,
13+
get_filesystem_ops_tail, post_filesystem_ops_mkdir, post_filesystem_ops_upload,
14+
post_filesystem_transfer_download, post_filesystem_transfer_upload, put_filesystem_ops_chmod,
1515
},
1616
status_api::{get_status_systems, get_status_userinfo},
1717
types::DownloadFileResponseTransferDirectives,
@@ -161,6 +161,12 @@ impl CscsApi {
161161
.wrap_err("couldn't change directory permission")?;
162162
Ok(())
163163
}
164+
pub async fn rm_path(&self, system_name: &str, path: PathBuf) -> Result<()> {
165+
delete_filesystem_ops_rm(&self.client, system_name, path)
166+
.await
167+
.wrap_err("couldn't remove remote file")?;
168+
Ok(())
169+
}
164170
pub async fn upload(&self, system_name: &str, target: PathBuf, file: Vec<u8>) -> Result<()> {
165171
post_filesystem_ops_upload(&self.client, system_name, target, file)
166172
.await
@@ -242,8 +248,8 @@ impl CscsApi {
242248
mod tests {
243249
use claim::*;
244250
use firecrest_client::types::{
245-
DownloadFileResponse, FirecrestFilesystemTransferModelsTransferJob, GetJobMetadataResponse, GetJobResponse,
246-
GetSystemsResponse, HPCCluster, JobMetadataModel, JobModel, JobStatus, PostJobSubmissionResponse,
251+
DownloadFileResponse, GetJobMetadataResponse, GetJobResponse, GetSystemsResponse, HPCCluster, JobMetadataModel,
252+
JobModel, JobStatus, LibDatatransfersDatatransferBaseTransferJob, PostJobSubmissionResponse,
247253
S3TransferResponse, UploadFileResponse,
248254
};
249255
use injectorpp::interface::injector::*;
@@ -459,7 +465,7 @@ mod tests {
459465
))
460466
.will_return_async(injectorpp::async_return!(
461467
Ok(UploadFileResponse {
462-
transfer_job: FirecrestFilesystemTransferModelsTransferJob {
468+
transfer_job: LibDatatransfersDatatransferBaseTransferJob {
463469
job_id: 1,
464470
..Default::default()
465471
},
@@ -493,7 +499,7 @@ mod tests {
493499
))
494500
.will_return_async(injectorpp::async_return!(
495501
Ok(DownloadFileResponse {
496-
transfer_job: FirecrestFilesystemTransferModelsTransferJob {
502+
transfer_job: LibDatatransfersDatatransferBaseTransferJob {
497503
job_id: 1,
498504
..Default::default()
499505
},

coman/src/cscs/handlers.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,17 @@ async fn inject_coman_squash(
382382
#[cfg(target_family = "windows")]
383383
let size = file_meta.file_size() as usize;
384384

385-
let existing = api_client.list_path(current_system, target.clone()).await?;
386-
if !existing.is_empty() {
385+
let response = api_client.list_path(current_system, target.clone()).await;
386+
if let Ok(existing) = response
387+
&& !existing.is_empty()
388+
{
387389
//squash file already present on remote, don't upload if it's the same
388390
let entry = existing.first().unwrap();
389391
if entry.size.unwrap_or_default() == size {
390392
return Ok(Some(target));
393+
} else {
394+
// remove file before upload
395+
api_client.rm_path(current_system, target.clone()).await?;
391396
}
392397
}
393398
//upload squash file
@@ -421,7 +426,10 @@ async fn inject_coman_squash(
421426
.map(|(i, etag)| (i + 1, etag))
422427
.map(|(i, etag)| format!("<Part><PartNumber>{}</PartNumber><ETag>{}</ETag></Part>", i, etag))
423428
.join("");
424-
let body = format!("<CompleteMultipartUpload>{}</CompleteMultipartUpload>", body);
429+
let body = format!(
430+
"<CompleteMultipartUpload xmlns=\"http://s3.amazonaws.com/doc/2006-03-01\">{}</CompleteMultipartUpload>",
431+
body
432+
);
425433
let req = client.post(transfer_data.1.complete_upload_url).body(body).build()?;
426434
let resp = client.execute(req).await?;
427435
resp.error_for_status()?;

firecrest_client/src/filesystem_api.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,14 @@ pub async fn post_filesystem_transfer_download(
227227
model.transfer_directives = transfer_dir;
228228
Ok(model)
229229
}
230+
231+
pub async fn delete_filesystem_ops_rm(client: &FirecrestClient, system_name: &str, path: PathBuf) -> Result<()> {
232+
let path = path.as_os_str().to_str().ok_or(eyre!("couldn't cast path to string"))?;
233+
let _ = client
234+
.delete(
235+
format!("filesystem/{system_name}/ops/rm").as_str(),
236+
Some(vec![("path", path)]),
237+
)
238+
.await?;
239+
Ok(())
240+
}

firecrest_client/src/types.rs

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! AUTO-GENERATED CODE - DO NOT EDIT!
1010
//!
1111
//! FirecREST
12-
//! Version: 2.4.1
12+
//! Version: 2.4.2
1313
//! Generated by `oas3-gen v0.21.1`
1414
//!
1515
//! No description provided
@@ -178,7 +178,7 @@ pub struct CompressRequest {
178178
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default)]
179179
pub struct CompressResponse {
180180
#[serde(rename = "transferJob")]
181-
pub transfer_job: FirecrestFilesystemTransferModelsTransferJob,
181+
pub transfer_job: LibDatatransfersDatatransferBaseTransferJob,
182182
}
183183
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, oas3_gen_support::Default)]
184184
pub enum CompressionType {
@@ -219,7 +219,7 @@ pub struct CopyRequest {
219219
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default)]
220220
pub struct CopyResponse {
221221
#[serde(rename = "transferJob")]
222-
pub transfer_job: FirecrestFilesystemTransferModelsTransferJob,
222+
pub transfer_job: LibDatatransfersDatatransferBaseTransferJob,
223223
}
224224
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default)]
225225
#[serde(default)]
@@ -278,7 +278,7 @@ impl DeleteJobCancelComputeSystemNameJobsJobIdDeleteRequest {
278278
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default)]
279279
pub struct DeleteResponse {
280280
#[serde(rename = "transferJob")]
281-
pub transfer_job: FirecrestFilesystemTransferModelsTransferJob,
281+
pub transfer_job: LibDatatransfersDatatransferBaseTransferJob,
282282
}
283283
///Delete file or directory operation (`rm`)
284284
#[derive(Debug, Clone, validator::Validate, oas3_gen_support::Default)]
@@ -421,7 +421,7 @@ pub struct DownloadFileResponse {
421421
#[serde(rename = "transferDirectives")]
422422
pub transfer_directives: DownloadFileResponseTransferDirectives,
423423
#[serde(rename = "transferJob")]
424-
pub transfer_job: FirecrestFilesystemTransferModelsTransferJob,
424+
pub transfer_job: LibDatatransfersDatatransferBaseTransferJob,
425425
}
426426
///Data transfer parameters specific to the transfer method
427427
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default)]
@@ -519,7 +519,7 @@ pub struct ExtractRequest {
519519
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default)]
520520
pub struct ExtractResponse {
521521
#[serde(rename = "transferJob")]
522-
pub transfer_job: FirecrestFilesystemTransferModelsTransferJob,
522+
pub transfer_job: LibDatatransfersDatatransferBaseTransferJob,
523523
}
524524
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default)]
525525
pub struct File {
@@ -617,22 +617,6 @@ pub struct FilesystemServiceHealth {
617617
#[serde(rename = "serviceType")]
618618
pub service_type: String,
619619
}
620-
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default)]
621-
pub struct FirecrestFilesystemTransferModelsTransferJob {
622-
#[serde(rename = "jobId")]
623-
pub job_id: i64,
624-
pub logs: FirecrestFilesystemTransferModelsTransferJobLogs,
625-
pub system: String,
626-
#[serde(rename = "workingDirectory")]
627-
pub working_directory: String,
628-
}
629-
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default)]
630-
pub struct FirecrestFilesystemTransferModelsTransferJobLogs {
631-
#[serde(rename = "errorLog")]
632-
pub error_log: String,
633-
#[serde(rename = "outputLog")]
634-
pub output_log: String,
635-
}
636620
///Output the checksum of a file (using SHA-256 algotithm)
637621
#[derive(Debug, Clone, validator::Validate, oas3_gen_support::Default)]
638622
pub struct GetChecksumFilesystemSystemNameOpsChecksumGetRequest {
@@ -1059,6 +1043,9 @@ pub struct GetJobsComputeSystemNameJobsGetRequest {
10591043
/// - Location: `Query`
10601044
#[default(Some(false))]
10611045
pub allusers: Option<bool>,
1046+
///If specified, filter jobs by account name
1047+
/// - Location: `Query`
1048+
pub account: Option<String>,
10621049
}
10631050
impl GetJobsComputeSystemNameJobsGetRequest {
10641051
///Render the request path with parameters.
@@ -1078,6 +1065,15 @@ impl GetJobsComputeSystemNameJobsGetRequest {
10781065
)
10791066
.unwrap();
10801067
}
1068+
if let Some(value) = &self.account {
1069+
prefix = if prefix == '\0' { '?' } else { '&' };
1070+
write!(
1071+
&mut path,
1072+
"{prefix}account={}",
1073+
oas3_gen_support::percent_encode_query_component(&oas3_gen_support::serialize_query_param(value)?)
1074+
)
1075+
.unwrap();
1076+
}
10811077
Ok(path)
10821078
}
10831079
///Parse the HTTP response into the response enum.
@@ -1945,6 +1941,22 @@ pub struct JobTime {
19451941
pub start: Option<i64>,
19461942
pub suspended: Option<i64>,
19471943
}
1944+
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default)]
1945+
pub struct LibDatatransfersDatatransferBaseTransferJob {
1946+
#[serde(rename = "jobId")]
1947+
pub job_id: i64,
1948+
pub logs: LibDatatransfersDatatransferBaseTransferJobLogs,
1949+
pub system: String,
1950+
#[serde(rename = "workingDirectory")]
1951+
pub working_directory: String,
1952+
}
1953+
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default)]
1954+
pub struct LibDatatransfersDatatransferBaseTransferJobLogs {
1955+
#[serde(rename = "errorLog")]
1956+
pub error_log: String,
1957+
#[serde(rename = "outputLog")]
1958+
pub output_log: String,
1959+
}
19481960
///Create move file or directory operation (`mv`) (for files larger than 5242880 Bytes)
19491961
#[derive(Debug, Clone, validator::Validate, oas3_gen_support::Default)]
19501962
pub struct MoveMvFilesystemSystemNameTransferMvPostRequest {
@@ -2010,7 +2022,7 @@ pub struct MoveRequest {
20102022
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default)]
20112023
pub struct MoveResponse {
20122024
#[serde(rename = "transferJob")]
2013-
pub transfer_job: FirecrestFilesystemTransferModelsTransferJob,
2025+
pub transfer_job: LibDatatransfersDatatransferBaseTransferJob,
20142026
}
20152027
///Configuration for multipart upload behavior.
20162028
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default)]
@@ -2951,6 +2963,10 @@ pub struct Scheduler {
29512963
///Scheduler API version.
29522964
#[serde(rename = "apiVersion")]
29532965
pub api_version: Option<String>,
2966+
///Scheduler connection mode.
2967+
#[serde(rename = "connectionMode")]
2968+
#[default(Some(Default::default()))]
2969+
pub connection_mode: Option<SchedulerConnectionMode>,
29542970
///Timeout in seconds for scheduler communication with the API.
29552971
#[default(Some(10i64))]
29562972
pub timeout: Option<i64>,
@@ -2960,6 +2976,17 @@ pub struct Scheduler {
29602976
///Scheduler version.
29612977
pub version: String,
29622978
}
2979+
///Modes to connect to the schedulers present in the system
2980+
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, oas3_gen_support::Default)]
2981+
pub enum SchedulerConnectionMode {
2982+
#[serde(rename = "hybrid")]
2983+
#[default]
2984+
Hybrid,
2985+
#[serde(rename = "rest")]
2986+
Rest,
2987+
#[serde(rename = "ssh")]
2988+
Ssh,
2989+
}
29632990
///Health check result for the job scheduler.
29642991
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default)]
29652992
#[serde(default)]
@@ -3044,7 +3071,7 @@ pub struct UploadFileResponse {
30443071
#[serde(rename = "transferDirectives")]
30453072
pub transfer_directives: DownloadFileResponseTransferDirectives,
30463073
#[serde(rename = "transferJob")]
3047-
pub transfer_job: FirecrestFilesystemTransferModelsTransferJob,
3074+
pub transfer_job: LibDatatransfersDatatransferBaseTransferJob,
30483075
}
30493076
#[derive(Debug, Clone, PartialEq, Deserialize, oas3_gen_support::Default)]
30503077
pub struct UserInfoResponse {

0 commit comments

Comments
 (0)