Skip to content

Commit

Permalink
Merge #22
Browse files Browse the repository at this point in the history
22: feat(store): define persistent data structs r=paulyoong a=paulyoong

Initial definition of structures that need to be saved in the
persistent store.

Resolves: CAS-819

Co-authored-by: Paul Yoong <[email protected]>
  • Loading branch information
mayastor-bors and Paul Yoong committed Apr 1, 2021
2 parents 489908a + 4ec3477 commit 6b54ff7
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 44 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion control-plane/mbus-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ paperclip = { version = "0.5.0", features = ["actix3"] }
percent-encoding = "2.1.0"
uuid = { version = "0.7", features = ["v4"] }
url = "2.2.0"
store = { path = "../store" }

[dev-dependencies]
composer = { path = "../../composer" }
Expand Down
40 changes: 0 additions & 40 deletions control-plane/mbus-api/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,8 +1189,6 @@ pub struct Watch {

bus_impl_vector_request!(Watches, Watch);

use store::store::*;

/// Get Resource Watches
#[derive(Serialize, Deserialize, Default, Debug, Clone)]
#[serde(rename_all = "camelCase")]
Expand All @@ -1201,24 +1199,6 @@ pub struct GetWatchers {

bus_impl_message_all!(GetWatchers, GetWatches, Watches, Watcher);

impl ObjectKey for VolumeId {
fn key_type(&self) -> StorableObjectType {
StorableObjectType::Volume
}
fn key_uuid(&self) -> String {
self.0.to_string()
}
}

impl ObjectKey for NexusId {
fn key_type(&self) -> StorableObjectType {
StorableObjectType::Nexus
}
fn key_uuid(&self) -> String {
self.0.to_string()
}
}

/// The different resource types that can be watched
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -1253,26 +1233,6 @@ impl ToString for WatchResourceId {
}
}
}
impl ObjectKey for WatchResourceId {
fn key_type(&self) -> StorableObjectType {
match &self {
WatchResourceId::Node(_) => StorableObjectType::Node,
WatchResourceId::Pool(_) => StorableObjectType::Pool,
WatchResourceId::Replica(_) => StorableObjectType::Replica,
WatchResourceId::Nexus(_) => StorableObjectType::Nexus,
WatchResourceId::Volume(_) => StorableObjectType::Volume,
}
}
fn key_uuid(&self) -> String {
match &self {
WatchResourceId::Node(i) => i.to_string(),
WatchResourceId::Pool(i) => i.to_string(),
WatchResourceId::Replica(i) => i.to_string(),
WatchResourceId::Nexus(i) => i.to_string(),
WatchResourceId::Volume(i) => i.to_string(),
}
}
}

/// The difference types of watches
#[derive(Serialize, Deserialize, Debug, Clone, Apiv2Schema, Eq, PartialEq)]
Expand Down
1 change: 1 addition & 0 deletions control-plane/rest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ macros = { path = "../macros" }
http = "0.2.3"
tinytemplate = { version = "1.2" }
jsonwebtoken = "7.2.0"
store = { path = "../store" }

[dev-dependencies]
composer = { path = "../../composer" }
Expand Down
3 changes: 2 additions & 1 deletion control-plane/store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ etcd-client = "0.5.5"
tokio = { version = "0.2", features = ["full"] }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
async-trait = "=0.1.42"
async-trait = "0.1.36"
snafu = "0.6"
tracing = "0.1"
strum = "0.19"
strum_macros = "0.19"
mbus_api = { path = "../mbus-api" }

[dev-dependencies]
composer = { path = "../../composer" }
Expand Down
1 change: 1 addition & 0 deletions control-plane/store/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod etcd;
pub mod store;
pub mod types;
1 change: 1 addition & 0 deletions control-plane/store/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod v0;
230 changes: 230 additions & 0 deletions control-plane/store/src/types/v0.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
//! This module contains definitions of data structures that can be saved to the
//! persistent store.
use crate::store::{ObjectKey, StorableObjectType};
use mbus_api::v0;
use serde::{Deserialize, Serialize};

type NodeLabel = String;
type VolumeLabel = String;
type PoolLabel = String;

/// Node data structure used by the persistent store.
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct Node {
// Node information
node: v0::Node,
/// Node labels.
labels: Vec<NodeLabel>,
}

/// Pool data structure used by the persistent store.
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct Pool {
/// Current state of the pool.
pub state: Option<PoolState>,
/// Desired pool specification.
pub spec: PoolSpec,
}

/// Runtime state of the pool.
/// This should eventually satisfy the PoolSpec.
#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
pub struct PoolState {
/// Pool information returned by Mayastor.
pub pool: v0::Pool,
/// Pool labels.
pub labels: Vec<PoolLabel>,
}

/// User specification of a pool.
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct PoolSpec {
/// id of the mayastor instance
pub node: v0::NodeId,
/// id of the pool
pub id: v0::PoolId,
/// absolute disk paths claimed by the pool
pub disks: Vec<String>,
/// state of the pool
pub state: v0::PoolState,
/// Pool labels.
pub labels: Vec<PoolLabel>,
}

/// Volume information
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct Volume {
/// Current state of the volume.
pub state: Option<VolumeState>,
/// Desired volume specification.
pub spec: VolumeSpec,
}

/// Runtime state of the volume.
/// This should eventually satisfy the VolumeSpec.
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct VolumeState {
/// Volume size.
pub size: u64,
/// Volume labels.
pub labels: Vec<VolumeLabel>,
/// Number of replicas.
pub num_replicas: u8,
/// Protocol that the volume is shared over.
pub protocol: v0::Protocol,
/// Nexuses that make up the volume.
pub nexuses: Vec<v0::NexusId>,
/// Number of front-end paths.
pub num_paths: u8,
/// State of the volume.
pub state: v0::VolumeState,
}

/// User specification of a volume.
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct VolumeSpec {
/// Size that the volume should be.
pub size: u64,
/// Volume labels.
pub labels: Vec<VolumeLabel>,
/// Number of children the volume should have.
pub num_replicas: u8,
/// Protocol that the volume should be shared over.
pub protocol: v0::Protocol,
/// Number of front-end paths.
pub num_paths: u8,
/// State that the volume should eventually achieve.
pub state: v0::VolumeState,
}

/// Nexus information
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct Nexus {
/// Current state of the nexus.
pub state: Option<NexusState>,
/// Desired nexus specification.
pub spec: NexusSpec,
}

/// Runtime state of the nexus.
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct NexusState {
/// Nexus information.
pub nexus: v0::Nexus,
}

/// User specification of a nexus.
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct NexusSpec {
/// Node where the nexus should live.
pub node: v0::NodeId,
/// List of children.
pub children: Vec<Child>,
/// Size of the nexus.
pub size: u64,
/// The state the nexus should eventually reach.
pub state: v0::NexusState,
}

/// Child information
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct Child {
/// Current state of the child.
pub state: Option<ChildState>,
/// Desired child specification.
pub spec: ChildSpec,
}

/// Runtime state of a child.
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct ChildState {
pub child: v0::Child,
/// Size of the child.
pub size: u64,
/// UUID of the replica that the child connects to.
pub replica_uuid: String,
}

/// User specification of a child.
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct ChildSpec {
/// The size the child should be.
pub size: u64,
/// The UUID of the replica the child should be associated with.
pub replica_uuid: String,
/// The state the child should eventually reach.
pub state: v0::ChildState,
}

/// Replica information
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct Replica {
/// Current state of the replica.
pub state: Option<ReplicaState>,
/// Desired replica specification.
pub spec: ReplicaSpec,
}

/// Runtime state of a replica.
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct ReplicaState {
/// Replica information.
pub replica: v0::Replica,
/// State of the replica.
pub state: v0::ReplicaState,
}

/// User specification of a replica.
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct ReplicaSpec {
/// The size that the replica should be.
pub size: u64,
/// The pool that the replica should live on.
pub pool: v0::PoolId,
/// Protocol used for exposing the replica.
pub share: v0::Protocol,
/// Thin provisioning.
pub thin: bool,
/// The state that the replica should eventually achieve.
pub state: v0::ReplicaState,
}

impl ObjectKey for v0::VolumeId {
fn key_type(&self) -> StorableObjectType {
StorableObjectType::Volume
}
fn key_uuid(&self) -> String {
self.to_string()
}
}

impl ObjectKey for v0::NexusId {
fn key_type(&self) -> StorableObjectType {
StorableObjectType::Nexus
}
fn key_uuid(&self) -> String {
self.to_string()
}
}

impl ObjectKey for v0::WatchResourceId {
fn key_type(&self) -> StorableObjectType {
match &self {
v0::WatchResourceId::Node(_) => StorableObjectType::Node,
v0::WatchResourceId::Pool(_) => StorableObjectType::Pool,
v0::WatchResourceId::Replica(_) => StorableObjectType::Replica,
v0::WatchResourceId::Nexus(_) => StorableObjectType::Nexus,
v0::WatchResourceId::Volume(_) => StorableObjectType::Volume,
}
}
fn key_uuid(&self) -> String {
match &self {
v0::WatchResourceId::Node(i) => i.to_string(),
v0::WatchResourceId::Pool(i) => i.to_string(),
v0::WatchResourceId::Replica(i) => i.to_string(),
v0::WatchResourceId::Nexus(i) => i.to_string(),
v0::WatchResourceId::Volume(i) => i.to_string(),
}
}
}
2 changes: 1 addition & 1 deletion nix/pkgs/control-plane/cargo-project.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let
buildProps = rec {
name = "control-plane-${version}";
#cargoSha256 = "0000000000000000000000000000000000000000000000000000";
cargoSha256 = "1ns5j6dgvn655rjgcmzf44h8afv0b7dc1qyfgppyfs41772ka73p";
cargoSha256 = "1wi5pn647hz2pswm218f65ij5dm494wrb92y8gsbgc78k5z73g88";
inherit version;

src = whitelistSource ../../../. [
Expand Down

0 comments on commit 6b54ff7

Please sign in to comment.