Skip to content

Commit

Permalink
chore: rename remote, edge and core to mirror, remote and home (#3966)
Browse files Browse the repository at this point in the history
  • Loading branch information
fraidev authored Apr 24, 2024
1 parent 29d1a11 commit 5a0ac15
Show file tree
Hide file tree
Showing 39 changed files with 255 additions and 254 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

20 changes: 10 additions & 10 deletions crates/fluvio-cli/src/client/home/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::io::BufReader;
use std::sync::Arc;
use anyhow::{anyhow, Result};
use clap::Parser;
use fluvio_controlplane_metadata::remote::{RemoteSpec, RemoteType};
use fluvio_extension_common::target::ClusterTarget;
use fluvio_extension_common::Terminal;
use fluvio_sc_schema::edge::EdgeMetadataExport;
use fluvio_sc_schema::mirror::{MirrorSpec, MirrorType};
use fluvio_sc_schema::remote_file::RemoteMetadataExport;

#[derive(Debug, Parser)]
pub struct ConnectOpt {
Expand All @@ -27,18 +27,18 @@ impl ConnectOpt {
.await;

let reader = BufReader::new(File::open(self.file)?);
let edge_metadata: EdgeMetadataExport = serde_json::from_reader(reader)
.map_err(|err| anyhow!("unable to load edge metadata: {}", err))?;
let core = edge_metadata.core;
let remote_metadata: RemoteMetadataExport = serde_json::from_reader(reader)
.map_err(|err| anyhow!("unable to load remote metadata: {}", err))?;
let home = remote_metadata.home;

let core_id = core.id.clone();
let home_id = home.id.clone();

let spec = RemoteSpec {
remote_type: RemoteType::Core(core),
let spec = MirrorSpec {
mirror_type: MirrorType::Home(home),
};

admin.create(core_id.clone(), false, spec).await?;
println!("connecting with \"{}\" cluster", core_id);
admin.create(home_id.clone(), false, spec).await?;
println!("connecting with \"{}\" cluster", home_id);
Ok(())
}
}
14 changes: 7 additions & 7 deletions crates/fluvio-cli/src/client/home/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::Result;
use clap::Parser;
use fluvio_extension_common::target::ClusterTarget;
use fluvio_extension_common::{OutputFormat, Terminal};
use fluvio_sc_schema::remote::{RemoteSpec, RemoteType};
use fluvio_sc_schema::mirror::{MirrorSpec, MirrorType};

use super::get_admin;

Expand All @@ -21,17 +21,17 @@ impl StatusOpt {
cluster_target: ClusterTarget,
) -> Result<()> {
let admin = get_admin(cluster_target).await?;
let list = admin.all::<RemoteSpec>().await?;
let list = admin.all::<MirrorSpec>().await?;
let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;

let outlist: Vec<(String, String, String, String)> = list
.into_iter()
.filter_map(|item| {
match item.spec.remote_type {
RemoteType::Core(core) => {
match item.spec.mirror_type {
MirrorType::Home(home) => {
Some((
core.id.to_string(), // Source ID
core.public_endpoint, // Route
home.id.to_string(), // Source ID
home.public_endpoint, // Route
item.status.to_string(), // Status
item.status.last_seen(now), // Last-Seen
))
Expand Down Expand Up @@ -92,7 +92,7 @@ mod output {
impl TableOutputHandler for TableList {
/// table header implementation
fn header(&self) -> Row {
Row::from(["REMOTE", "ROUTE", "STATUS", "LAST SEEN"])
Row::from(["HOME", "ROUTE", "STATUS", "LAST SEEN"])
}

/// return errors in string format
Expand Down
30 changes: 15 additions & 15 deletions crates/fluvio-cli/src/client/remote/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ use anyhow::{Context, Result};
use clap::Parser;
use fluvio_extension_common::{target::ClusterTarget, Terminal};
use fluvio_sc_schema::{
edge::EdgeMetadataExport,
remote::{Core, RemoteSpec, RemoteType},
mirror::{Home, MirrorSpec, MirrorType},
remote_file::RemoteMetadataExport,
};
use anyhow::anyhow;

use super::get_admin;

#[derive(Debug, Parser)]
pub struct ExportOpt {
/// id of the edge cluster to export
edge_id: String,
/// id of the remote cluster to export
remote_id: String,
/// name of the file where we should put the file
#[arg(long, short = 'f')]
file: Option<String>,
Expand All @@ -22,7 +22,7 @@ pub struct ExportOpt {
public_endpoint: Option<String>,
// id of the home cluster to share
#[arg(name = "c")]
core_id: Option<String>,
home_id: Option<String>,
}

impl ExportOpt {
Expand All @@ -39,24 +39,24 @@ impl ExportOpt {
};

let admin = get_admin(cluster_target).await?;
let all_remotes = admin.all::<RemoteSpec>().await?;
let _edge = all_remotes
let all_remotes = admin.all::<MirrorSpec>().await?;
let _remote = all_remotes
.iter()
.find(|remote| match &remote.spec.remote_type {
RemoteType::Edge(edge) => edge.id == self.edge_id,
.find(|remote| match &remote.spec.mirror_type {
MirrorType::Remote(remote) => remote.id == self.remote_id,
_ => false,
})
.ok_or_else(|| anyhow!("edge cluster not found"))?;
.ok_or_else(|| anyhow!("remote cluster not found"))?;

let core_id = self.core_id.clone().unwrap_or_else(|| "core".to_owned());
let home_id = self.home_id.clone().unwrap_or_else(|| "home".to_owned());

let core_metadata = Core {
id: core_id,
edge_id: self.edge_id,
let home_metadata = Home {
id: home_id,
remote_id: self.remote_id,
public_endpoint,
};

let metadata = EdgeMetadataExport::new(core_metadata);
let metadata = RemoteMetadataExport::new(home_metadata);

if let Some(filename) = self.file {
std::fs::write(filename, serde_json::to_string_pretty(&metadata)?)
Expand Down
12 changes: 6 additions & 6 deletions crates/fluvio-cli/src/client/remote/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::Result;
use clap::Parser;
use fluvio_extension_common::target::ClusterTarget;
use fluvio_extension_common::{OutputFormat, Terminal};
use fluvio_sc_schema::remote::{RemoteSpec, RemoteStatus, RemoteType};
use fluvio_sc_schema::mirror::{MirrorSpec, MirrorType};

use super::get_admin;

Expand All @@ -21,16 +21,16 @@ impl ListOpt {
cluster_target: ClusterTarget,
) -> Result<()> {
let admin = get_admin(cluster_target).await?;
let list = admin.all::<RemoteSpec>().await?;
let list = admin.all::<MirrorSpec>().await?;
let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;

let outlist: Vec<(String, String, String)> = list
.into_iter()
.filter_map(|item| match item.spec.remote_type {
RemoteType::Edge(edge) => {
let status: RemoteStatus = item.status.clone();
.filter_map(|item| match item.spec.mirror_type {
MirrorType::Remote(r) => {
let status = item.status.clone();
let last_seen = item.status.last_seen(now);
Some((edge.id, status.to_string(), last_seen))
Some((r.id, status.to_string(), last_seen))
}
_ => None,
})
Expand Down
10 changes: 5 additions & 5 deletions crates/fluvio-cli/src/client/remote/register.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::sync::Arc;
use anyhow::Result;
use clap::Parser;
use fluvio_controlplane_metadata::remote::{RemoteSpec, RemoteType};
use fluvio_controlplane_metadata::mirror::{MirrorSpec, MirrorType};
use fluvio_extension_common::target::ClusterTarget;
use fluvio_extension_common::Terminal;
use fluvio_sc_schema::remote::Edge;
use fluvio_sc_schema::mirror::Remote;

#[derive(Debug, Parser)]
pub struct RegisterOpt {
Expand All @@ -23,14 +23,14 @@ impl RegisterOpt {
.admin()
.await;

let spec = RemoteSpec {
remote_type: RemoteType::Edge(Edge {
let spec = MirrorSpec {
mirror_type: MirrorType::Remote(Remote {
id: self.name.clone(),
}),
};

admin.create(self.name.clone(), false, spec).await?;
println!("edge cluster \"{}\" was registered", self.name);
println!("remote cluster \"{}\" was registered", self.name);
Ok(())
}
}
6 changes: 3 additions & 3 deletions crates/fluvio-cli/src/client/remote/unregister.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use clap::Parser;
use fluvio_sc_schema::remote::RemoteSpec;
use fluvio_sc_schema::mirror::MirrorSpec;
use std::sync::Arc;
use fluvio_extension_common::target::ClusterTarget;
use fluvio_extension_common::Terminal;
Expand All @@ -17,8 +17,8 @@ impl UnregisterOpt {
cluster_target: ClusterTarget,
) -> Result<()> {
let admin = get_admin(cluster_target).await?;
admin.delete::<RemoteSpec>(&self.name).await?;
println!("edge cluster \"{}\" was unregistered", self.name);
admin.delete::<MirrorSpec>(&self.name).await?;
println!("remote cluster \"{}\" was unregistered", self.name);
Ok(())
}
}
4 changes: 2 additions & 2 deletions crates/fluvio-controlplane-metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod spg;
pub mod smartmodule;
pub mod tableformat;
pub mod message;
pub mod remote;
pub mod mirror;

pub use fluvio_stream_model::core;

Expand All @@ -32,7 +32,7 @@ pub mod extended {
SmartModule,
TableFormat,
DerivedStream,
Remote,
Mirror,
}

pub trait SpecExt: Spec {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
use fluvio_stream_model::k8_types::{Crd, GROUP, V1, CrdNames, Spec, Status, DefaultHeader};

use super::RemoteSpec;
use super::RemoteStatus;
use super::MirrorSpec;
use super::MirrorStatus;

const REMOTE_API: Crd = Crd {
group: GROUP,
version: V1,
names: CrdNames {
kind: "Remote",
plural: "remotes",
singular: "remote",
kind: "Mirror",
plural: "mirrors",
singular: "mirror",
},
};

impl Spec for RemoteSpec {
impl Spec for MirrorSpec {
type Header = DefaultHeader;
type Status = RemoteStatus;
type Status = MirrorStatus;
fn metadata() -> &'static Crd {
&REMOTE_API
}
}

impl Status for RemoteStatus {}
impl Status for MirrorStatus {}

#[cfg(test)]
mod test_v1_spec {
use std::{io::BufReader, fs::File};
use fluvio_stream_model::k8_types::K8Obj;
use crate::remote::Edge;
use crate::mirror::Remote;

use super::RemoteSpec;
use super::super::RemoteType;
use super::MirrorSpec;
use super::super::MirrorType;

type K8RemoteSpec = K8Obj<RemoteSpec>;
type K8RemoteSpec = K8Obj<MirrorSpec>;

#[test]
fn read_k8_remote_json() {
fn read_k8_mirror_json() {
let reader: BufReader<File> =
BufReader::new(File::open("tests/k8_remote_v1.json").expect("spec"));
BufReader::new(File::open("tests/k8_mirror_v1.json").expect("spec"));
let cluster: K8RemoteSpec = serde_json::from_reader(reader).expect("failed to parse topic");
assert_eq!(cluster.metadata.name, "offshore");
assert_eq!(
cluster.spec.remote_type,
RemoteType::Edge(Edge {
cluster.spec.mirror_type,
MirrorType::Remote(Remote {
id: "offshore-edge-1".to_owned(),
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ mod metadata {

use super::*;

impl Spec for RemoteSpec {
const LABEL: &'static str = "Remote";
impl Spec for MirrorSpec {
const LABEL: &'static str = "Mirror";
type IndexKey = String;
type Status = RemoteStatus;
type Status = MirrorStatus;
type Owner = Self;
}

impl SpecExt for RemoteSpec {
const OBJECT_TYPE: ObjectType = ObjectType::Remote;
impl SpecExt for MirrorSpec {
const OBJECT_TYPE: ObjectType = ObjectType::Mirror;
}

impl Status for RemoteStatus {}
impl Status for MirrorStatus {}

#[cfg(feature = "k8")]
mod extended {
Expand All @@ -40,9 +40,9 @@ mod metadata {
k8_types::K8Obj,
};

use super::metadata::RemoteSpec;
use super::metadata::MirrorSpec;

impl K8ExtendedSpec for RemoteSpec {
impl K8ExtendedSpec for MirrorSpec {
type K8Spec = Self;

fn convert_from_k8(
Expand Down
Loading

0 comments on commit 5a0ac15

Please sign in to comment.