Skip to content

Commit 653e7ed

Browse files
kamirrprekucki
andauthored
activity: add volume spec to ExeScriptCommand::Deploy (#188)
* activity: add volume spec to ExeScriptCommand::Deploy * activity: use bytesize for Volume size & preallocate * Revert "Feature/market scan (#185)" This reverts commit 1dc4062. * activity: Volume size no longer optional * activity: Simplify Volume API * activity: update OpenAPI spec with rough definition * activity: add volume spec to ExeScriptCommand::Deploy * activity: use bytesize for Volume size & preallocate * Revert "Feature/market scan (#185)" This reverts commit 1dc4062. * activity: Volume size no longer optional * activity: Simplify Volume API * activity: update OpenAPI spec with rough definition * activity: Add Volumes::as_volumes to construct a cannonical form * Merge fixup --------- Co-authored-by: Przemysław Krzysztof Rekucki <[email protected]>
1 parent 3c1191b commit 653e7ed

File tree

8 files changed

+130
-54
lines changed

8 files changed

+130
-54
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ members = ["model"]
2929
secp256k1 = ">=0.23,<0.28"
3030

3131
[dependencies]
32-
ya-client-model = { version = "0.7", path = "model" }
32+
ya-client-model = { version = "0.6", path = "model" }
3333
awc = { version = "3", default-features = false }
3434
actix-codec = "0.5"
3535
bytes = "1"
@@ -59,7 +59,7 @@ anyhow = "1.0"
5959
bigdecimal = { version = "0.2" }
6060
env_logger = "0.10"
6161
structopt = "0.3"
62-
clap = "4.5.7"
6362

6463
[package.metadata.release]
64+
dev-version = false
6565
enable-all-features = true

examples/list_offers.rs

Lines changed: 0 additions & 44 deletions
This file was deleted.

model/Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ya-client-model"
3-
version = "0.7.0"
3+
version = "0.6.0"
44
description = "Yagna REST API data model"
55
authors = ["Golem Factory <[email protected]>"]
66
homepage = "https://github.com/golemfactory/ya-client"
@@ -14,8 +14,9 @@ with-diesel = ['diesel']
1414
sgx = ['secp256k1', 'openssl', 'hex', 'secp256k1/serde']
1515

1616
[dependencies]
17-
bigdecimal = { version = "0.2", features = ["serde"]}
18-
chrono = { version = "0.4", features = ["serde"]}
17+
bigdecimal = { version = "0.2", features = ["serde"] }
18+
bytesize = { version = "1.3.0", features = ["serde"] }
19+
chrono = { version = "0.4", features = ["serde"] }
1920
derive_more = "0.99"
2021
humantime-serde = "1.1"
2122
rand = "0.8"
@@ -28,9 +29,10 @@ strum_macros = "0.24.3"
2829
thiserror = "1.0"
2930

3031
diesel = { version = "1.4", optional = true }
31-
hex = { version = "0.4", optional = true}
32+
hex = { version = "0.4", optional = true }
3233
secp256k1 = { workspace = true, optional = true }
3334
openssl = { version = "0.10", optional = true }
3435

3536
[package.metadata.release]
37+
dev-version = false
3638
enable-all-features = true

model/src/activity/exe_script_command.rs

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
use crate::activity::ExeScriptCommandState;
12+
use bytesize::ByteSize;
1213
use serde::{Deserialize, Serialize};
1314
use std::collections::HashMap;
1415
use std::time::Duration;
@@ -26,8 +27,9 @@ pub enum ExeScriptCommand {
2627
#[serde(default)]
2728
hostname: Option<String>,
2829

30+
#[serde(skip_serializing_if = "Option::is_none")]
2931
#[serde(default)]
30-
volumes: Vec<String>,
32+
volumes: Option<Volumes>,
3133

3234
#[serde(default)]
3335
env: HashMap<String, String>,
@@ -58,6 +60,46 @@ pub enum ExeScriptCommand {
5860
Terminate {},
5961
}
6062

63+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
64+
#[serde(rename_all = "lowercase")]
65+
pub enum VolumeMount {
66+
Host {},
67+
Ram {
68+
size: ByteSize,
69+
},
70+
Storage {
71+
size: ByteSize,
72+
#[serde(skip_serializing_if = "Option::is_none")]
73+
#[serde(default)]
74+
preallocate: Option<ByteSize>,
75+
#[serde(skip_serializing_if = "Option::is_none")]
76+
#[serde(default)]
77+
errors: Option<String>,
78+
},
79+
}
80+
81+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
82+
#[serde(untagged)]
83+
pub enum Volumes {
84+
Simple(Vec<String>),
85+
Detailed {
86+
#[serde(flatten)]
87+
volumes: HashMap<String, VolumeMount>,
88+
},
89+
}
90+
91+
impl Volumes {
92+
pub fn as_volumes(self) -> HashMap<String, VolumeMount> {
93+
match self {
94+
Volumes::Simple(paths) => paths
95+
.into_iter()
96+
.map(|path| (path, VolumeMount::Host {}))
97+
.collect(),
98+
Volumes::Detailed { volumes } => volumes,
99+
}
100+
}
101+
}
102+
61103
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
62104
#[serde(rename_all = "camelCase")]
63105
pub struct Network {
@@ -199,6 +241,11 @@ impl From<ExeScriptCommand> for ExeScriptCommandState {
199241

200242
#[cfg(test)]
201243
mod test {
244+
use bytesize::ByteSize;
245+
246+
use super::Volumes;
247+
use crate::activity::exe_script_command::VolumeMount;
248+
use std::collections::HashMap;
202249

203250
#[test]
204251
fn test_transfers_parsing() {
@@ -236,4 +283,67 @@ mod test {
236283
]"#;
237284
let _: Vec<super::ExeScriptCommand> = serde_json::from_str(command).unwrap();
238285
}
286+
287+
#[test]
288+
fn test_volumes_simple() {
289+
let volumes_json = r#"[
290+
"/golem/input",
291+
"/golem/output"
292+
]"#;
293+
let volumes: Volumes = serde_json::from_str(&volumes_json).unwrap();
294+
295+
assert_eq!(
296+
volumes,
297+
Volumes::Simple(vec![
298+
"/golem/input".to_string(),
299+
"/golem/output".to_string()
300+
])
301+
);
302+
}
303+
304+
#[test]
305+
fn test_volumes_detailed() {
306+
let volumes_json = r#"{
307+
"/golem/input": { "host": {} },
308+
"/golem/output": { "host": {} },
309+
"/storage": {
310+
"storage": {
311+
"size": "10GiB",
312+
"preallocate": "2GiB"
313+
}
314+
},
315+
"/": {
316+
"ram": {
317+
"size": "1024MiB"
318+
}
319+
}
320+
}"#;
321+
let volumes: Volumes = serde_json::from_str(&volumes_json).unwrap();
322+
323+
assert_eq!(
324+
volumes,
325+
Volumes::Detailed {
326+
volumes: {
327+
let mut map = HashMap::new();
328+
map.insert("/golem/input".to_string(), VolumeMount::Host {});
329+
map.insert("/golem/output".to_string(), VolumeMount::Host {});
330+
map.insert(
331+
"/storage".to_string(),
332+
VolumeMount::Storage {
333+
size: ByteSize::gib(10),
334+
preallocate: Some(ByteSize::gib(2)),
335+
errors: None,
336+
},
337+
);
338+
map.insert(
339+
"/".to_string(),
340+
VolumeMount::Ram {
341+
size: ByteSize::b(1073741824),
342+
},
343+
);
344+
map
345+
}
346+
}
347+
);
348+
}
239349
}

release.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sign-commit=true
2+
sign-tag=true
3+
dev-version=false
4+
pre-release-commit-message="release {{crate_name}} {{version}}"
5+
enable-all-features=true

specs/activity-api.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ components:
487487
"net": [{ "id": "id", "ip": "10.0.0.2", "mask": "255.255.0.0" }],
488488
"hosts": {"master": "10.0.0.1"},
489489
"nodes": {"10.0.0.1": "0xdeadbeef"},
490+
"volumes": {"/": { "storage": { "size": "10g" } }},
490491
"progress" : {"updateInterval": "300ms", "updateStep": null}
491492
}
492493
},
@@ -559,6 +560,10 @@ components:
559560
type: object
560561
additionalProperties:
561562
type: string
563+
volumes:
564+
type: object
565+
additionalProperties:
566+
type: string
562567
progress:
563568
$ref: '#/components/schemas/ProgressArgs'
564569

specs/market-api.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ paths:
7979
$ref: 'common.yaml#/responses/NotFound'
8080
default:
8181
$ref: 'common.yaml#/responses/UnexpectedError'
82-
83-
/scan/{subscriptionId}:
8482
delete:
8583
tags:
8684
- requestor

src/market/requestor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ impl MarketRequestorApi {
350350
}
351351

352352
pub async fn end_scan(&self, subscription_id: &str) -> Result<()> {
353-
let url = url_format!("scan/{subscription_id}");
353+
let url = url_format!("scan/{subscription_id}/events");
354354
self.client.delete(&url).send().json().await
355355
}
356356
}

0 commit comments

Comments
 (0)