fluvio_controlplane_metadata/spg/
spec.rs

1#![allow(clippy::assign_op_pattern)]
2
3use fluvio_protocol::{Encoder, Decoder};
4use fluvio_types::defaults::{SPU_LOG_BASE_DIR, SPU_LOG_SIZE};
5
6#[derive(Encoder, Decoder, Default, Debug, Eq, PartialEq, Clone)]
7#[cfg_attr(
8    feature = "use_serde",
9    derive(serde::Serialize, serde::Deserialize),
10    serde(rename_all = "camelCase")
11)]
12pub struct SpuGroupSpec {
13    /// The number of replicas for the spu group
14    pub replicas: u16,
15
16    /// The base spu id that the spu group uses to increment the spu ids
17    /// Note: Spu id is a globally unique resource and it cannot be shared
18    pub min_id: i32,
19
20    /// Configuration elements to be applied to each SPUs in the group
21    pub spu_config: SpuConfig,
22}
23
24#[derive(Encoder, Decoder, Default, Debug, Clone, Eq, PartialEq)]
25#[cfg_attr(
26    feature = "use_serde",
27    derive(serde::Serialize, serde::Deserialize),
28    serde(rename_all = "camelCase")
29)]
30pub struct SpuConfig {
31    pub rack: Option<String>,
32    pub replication: Option<ReplicationConfig>,
33    pub storage: Option<StorageConfig>,
34    pub env: Vec<EnvVar>,
35}
36
37impl SpuConfig {
38    pub fn real_storage_config(&self) -> RealStorageConfig {
39        if let Some(config) = &self.storage {
40            config.real_config()
41        } else {
42            StorageConfig::default().real_config()
43        }
44    }
45}
46
47#[derive(Encoder, Decoder, Default, Debug, Eq, PartialEq, Clone)]
48#[cfg_attr(
49    feature = "use_serde",
50    derive(serde::Serialize, serde::Deserialize),
51    serde(rename_all = "camelCase")
52)]
53pub struct ReplicationConfig {
54    pub in_sync_replica_min: Option<u16>,
55}
56
57#[derive(Encoder, Decoder, Debug, Default, Eq, PartialEq, Clone)]
58#[cfg_attr(
59    feature = "use_serde",
60    derive(serde::Serialize, serde::Deserialize),
61    serde(rename_all = "camelCase")
62)]
63pub struct StorageConfig {
64    pub log_dir: Option<String>,
65    pub size: Option<String>,
66}
67
68impl StorageConfig {
69    /// fill in the values if not defined
70    /// that should be used
71    pub fn real_config(&self) -> RealStorageConfig {
72        RealStorageConfig {
73            log_dir: self
74                .log_dir
75                .clone()
76                .unwrap_or_else(|| SPU_LOG_BASE_DIR.to_owned()),
77            size: self.size.clone().unwrap_or_else(|| SPU_LOG_SIZE.to_owned()),
78        }
79    }
80}
81
82/// real storage configuration
83pub struct RealStorageConfig {
84    pub log_dir: String,
85    pub size: String,
86}
87
88#[derive(Encoder, Decoder, Default, Debug, Eq, PartialEq, Clone)]
89#[cfg_attr(
90    feature = "use_serde",
91    derive(serde::Serialize, serde::Deserialize),
92    serde(rename_all = "camelCase")
93)]
94pub struct EnvVar {
95    pub name: String,
96    pub value: String,
97}