-
Notifications
You must be signed in to change notification settings - Fork 198
/
register.rs
60 lines (50 loc) · 1.7 KB
/
register.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
//!
//! # Create Custom SPUs
//!
//! CLI tree to generate Create Custom SPUs
//!
use std::convert::TryFrom;
use structopt::StructOpt;
use fluvio::Fluvio;
use fluvio::metadata::spu::CustomSpuSpec;
use flv_util::socket_helpers::ServerAddress;
use crate::cli::ClusterCliError;
#[derive(Debug, StructOpt)]
pub struct RegisterCustomSpuOpt {
/// SPU id
#[structopt(short = "i", long = "id")]
id: i32,
/// SPU name
#[structopt(short = "n", long = "name", value_name = "string")]
name: Option<String>,
/// Rack name
#[structopt(short = "r", long = "rack", value_name = "string")]
rack: Option<String>,
/// Public server::port
#[structopt(short = "p", long = "public-server", value_name = "host:port")]
public_server: String,
/// Private server::port
#[structopt(short = "v", long = "private-server", value_name = "host:port")]
private_server: String,
}
impl RegisterCustomSpuOpt {
pub async fn process(self, fluvio: &Fluvio) -> Result<(), ClusterCliError> {
let (name, spec) = self.validate()?;
let admin = fluvio.admin().await;
admin.create(name, false, spec).await?;
Ok(())
}
/// Validate cli options. Generate target-server and register custom spu config.
fn validate(self) -> Result<(String, CustomSpuSpec), ClusterCliError> {
let cfg = (
self.name.unwrap_or(format!("custom-spu-{}", self.id)),
CustomSpuSpec {
id: self.id,
public_endpoint: ServerAddress::try_from(self.public_server)?.into(),
private_endpoint: ServerAddress::try_from(self.private_server)?.into(),
rack: self.rack,
},
);
Ok(cfg)
}
}