Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/admin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use fluvio::FluvioAdmin as FluvioAdminNative;
use fluvio_sc_schema::topic::TopicSpec;
use fluvio_future::task::run_block_on;
use fluvio_sc_schema::objects::ListFilter;

pub struct FluvioAdmin { pub inner: FluvioAdminNative }

Expand All @@ -10,11 +11,29 @@ impl FluvioAdmin {
run_block_on(FluvioAdminNative::connect()).map(|a| Box::new(FluvioAdmin { inner: a })).map_err(|e| e.to_string())
}

pub fn connect_with_config(config: &super::FluvioConfig) -> Result<Box<FluvioAdmin>, String> {
run_block_on(FluvioAdminNative::connect_with_config(&config.inner))
.map(|a| Box::new(FluvioAdmin { inner: a }))
.map_err(|e| e.to_string())
}

pub fn topic_exists(self: &Self, topic: &str) -> bool {
run_block_on(self.inner.list::<TopicSpec, ListFilter>(Vec::new()))
.map(|topics| topics.into_iter().any(|t| t.name == topic))
.unwrap_or(false)
}

pub fn create_topic(self: &Self, topic: &str, partitions: i32, replicas: i32) -> Result<(), String> {
run_block_on(self.inner.create(topic.to_string(), false, TopicSpec::new_computed(partitions as u32, replicas as u32, None)))
.map_err(|e| e.to_string())
}

pub fn list_topics(&self) -> Result<Vec<String>, String> {
run_block_on(self.inner.list::<TopicSpec, ListFilter>(Vec::new()))
.map(|topics| topics.into_iter().map(|t| t.name).collect())
.map_err(|e| e.to_string())
}

pub fn delete_topic(self: &Self, topic: &str) -> Result<(), String> {
run_block_on(self.inner.delete::<TopicSpec>(topic.to_string()))
.map_err(|e| e.to_string())
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ mod ffi {
/// Connects to the Fluvio Administrative controller
#[Self = "FluvioAdmin"]
fn connect() -> Result<Box<FluvioAdmin>>;
/// Connects to the Fluvio Administrative controller with explicit config
#[Self = "FluvioAdmin"]
fn connect_with_config(config: &FluvioConfig) -> Result<Box<FluvioAdmin>>;
/// Lists all topics
fn list_topics(self: &FluvioAdmin) -> Result<Vec<String>>;
/// Checks if a topic exists
fn topic_exists(self: &FluvioAdmin, topic: &str) -> bool;
/// Dispatches a command to create a new topic
fn create_topic(self: &FluvioAdmin, topic: &str, partitions: i32, replicas: i32) -> Result<()>;
/// Dispatches a command to violently delete a topic
Expand Down
Loading