-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use new lib for the topic list
- Loading branch information
1 parent
a117ae0
commit d6d348c
Showing
12 changed files
with
95 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
use super::error::{ Result }; | ||
use crate::{ configuration::Cluster, kafka::admin::{ list_topics, TopicInfo } }; | ||
use log::debug; | ||
|
||
use crate::lib::TopicInfo; | ||
|
||
use super::{ error::{ Result }, AppState }; | ||
|
||
#[tauri::command] | ||
pub async fn list_topic(cluster: Cluster, topic: Option<&str>) -> Result<Vec<TopicInfo>> { | ||
Ok(list_topics(&cluster, topic)?) | ||
pub async fn list_topics(cluster_id: String, state: tauri::State<'_, AppState>) -> Result<Vec<TopicInfo>> { | ||
debug!("Retrieve the list of topics"); | ||
let cluster = state.get_by_cluster_id(&cluster_id).await; | ||
Ok(cluster.admin_client.list_topics()?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::{ collections::HashMap, sync::Arc }; | ||
|
||
use futures::lock::Mutex; | ||
use log::debug; | ||
|
||
use crate::lib::{ Cluster, ConfigStore }; | ||
|
||
type ClusterId = String; | ||
|
||
#[derive(Default)] | ||
pub struct AppState { | ||
clusters: Arc<Mutex<HashMap<ClusterId, Cluster>>>, | ||
} | ||
|
||
impl AppState { | ||
pub async fn get_by_cluster_id(&self, cluster_id: &str) -> Cluster { | ||
let clusters = self.clusters.clone(); | ||
let mut map = clusters.lock().await; | ||
if map.get(cluster_id).is_none() { | ||
debug!("Initialise cluster {}", cluster_id); | ||
let configurations = ConfigStore::new().get_configuration().expect("Unable to get the configuration"); | ||
let cluster_config = configurations.clusters | ||
.iter() | ||
.find(|c| c.id == cluster_id) | ||
.expect("Unable to find the cluster config"); | ||
let cluster = Cluster::new(cluster_config.to_owned()); | ||
map.insert(cluster_id.into(), cluster); | ||
} | ||
map.get(cluster_id) | ||
.expect("Something went wrong retrieving a cluster that must be in the clusters vector") | ||
.clone() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod client; | ||
mod types; | ||
|
||
pub use client::{ Admin, KafkaAdmin }; | ||
pub use client::{ Admin, KafkaAdmin }; | ||
pub use types::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod types; | ||
mod config_store; | ||
|
||
pub use types::*; | ||
pub use types::*; | ||
pub use config_store::ConfigStore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters