-
Notifications
You must be signed in to change notification settings - Fork 198
/
create.rs
73 lines (58 loc) · 1.87 KB
/
create.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//!
//! # Create Mange SPU Groups
//!
//! CLI tree to generate Create Managed SPU Groups
//!
use tracing::debug;
use structopt::StructOpt;
use fluvio::Fluvio;
use fluvio::metadata::spg::*;
use crate::cli::ClusterCliError;
// -----------------------------------
// CLI Options
// -----------------------------------
#[derive(Debug, StructOpt, Default)]
pub struct CreateManagedSpuGroupOpt {
/// The name for the new SPU Group
#[structopt(value_name = "name")]
pub name: String,
/// The number of SPUs to create in this SPG
#[structopt(short, long, value_name = "integer", default_value = "1")]
pub replicas: u16,
/// Minimum SPU ID
#[structopt(long, value_name = "integer", default_value = "1")]
pub min_id: i32,
/// Rack name
#[structopt(long, value_name = "string")]
pub rack: Option<String>,
/// The amount of storage to assign to this SPG
#[structopt(long, value_name = "string")]
pub storage_size: Option<String>,
}
impl CreateManagedSpuGroupOpt {
pub async fn process(self, fluvio: &Fluvio) -> Result<(), ClusterCliError> {
let (name, spec) = self.validate();
debug!("creating spg: {}, spec: {:#?}", name, spec);
let admin = fluvio.admin().await;
admin.create(name, false, spec).await?;
Ok(())
}
/// Validate cli options. Generate target-server and create spu group config.
fn validate(self) -> (String, SpuGroupSpec) {
let storage = self.storage_size.map(|storage_size| StorageConfig {
size: Some(storage_size),
..Default::default()
});
let spu_config = SpuConfig {
storage,
rack: self.rack,
..Default::default()
};
let spec = SpuGroupSpec {
replicas: self.replicas,
min_id: self.min_id,
spu_config,
};
(self.name, spec)
}
}