Skip to main content

Cluster

Struct Cluster 

Source
pub struct Cluster { /* private fields */ }
Expand description

An immutable representation of a subset of the nodes, topics, and partitions in the Kafka cluster.

Implementations§

Source§

impl Cluster

Source

pub fn new( cluster_id: Option<String>, nodes: Vec<Node>, partitions: Vec<PartitionInfo>, unauthorized_topics: HashSet<String>, internal_topics: HashSet<String>, ) -> Self

Create a new cluster with the given id, nodes and partitions.

Corresponds to Java’s Cluster(String, Collection<Node>, Collection<PartitionInfo>, Set<String>, Set<String>) (Cluster.java:57), whose parameters {clusterId, nodes, partitions, unauthorizedTopics, internalTopics} are the intersection across the four public constructors — so it owns the plain name (CLAUDE.md §2).

§Arguments
  • nodes - The nodes in the cluster
  • partitions - Information about a subset of the topic-partitions this cluster hosts
Source

pub fn with_controller( cluster_id: Option<String>, nodes: Vec<Node>, partitions: Vec<PartitionInfo>, unauthorized_topics: HashSet<String>, internal_topics: HashSet<String>, controller: Option<Node>, ) -> Self

Create a new cluster with the given id, nodes, partitions and controller.

Corresponds to Java’s Cluster(String, Collection<Node>, Collection<PartitionInfo>, Set<String>, Set<String>, Node) (Cluster.java:70).

§Arguments
  • nodes - The nodes in the cluster
  • partitions - Information about a subset of the topic-partitions this cluster hosts
Source

pub fn with_invalid_topics_controller( cluster_id: Option<String>, nodes: Vec<Node>, partitions: Vec<PartitionInfo>, unauthorized_topics: HashSet<String>, invalid_topics: HashSet<String>, internal_topics: HashSet<String>, controller: Option<Node>, ) -> Self

Create a new cluster with the given id, nodes, partitions, invalid topics and controller.

Corresponds to Java’s Cluster(String, Collection<Node>, Collection<PartitionInfo>, Set<String>, Set<String>, Set<String>, Node) (Cluster.java:84).

§Arguments
  • nodes - The nodes in the cluster
  • partitions - Information about a subset of the topic-partitions this cluster hosts
Source

pub fn with_invalid_topics_controller_topic_ids( cluster_id: Option<String>, nodes: Vec<Node>, partitions: Vec<PartitionInfo>, unauthorized_topics: HashSet<String>, invalid_topics: HashSet<String>, internal_topics: HashSet<String>, controller: Option<Node>, topic_ids: HashMap<String, Uuid>, ) -> Self

Create a new cluster with the given id, nodes, partitions and topic ids.

Corresponds to Java’s widest public constructor (Cluster.java:99).

§Arguments
  • nodes - The nodes in the cluster
  • partitions - Information about a subset of the topic-partitions this cluster hosts
Source

pub fn empty() -> Self

Create an empty cluster instance with no nodes and no topic-partitions.

Source

pub fn bootstrap(addresses: &[(String, SocketAddr)]) -> Self

Create a “bootstrap” cluster using the given list of (hostname, address) pairs.

Source

pub fn with_partitions( &self, partitions: HashMap<TopicPartition, PartitionInfo>, ) -> Self

Return a copy of this cluster combined with additional partitions.

Source

pub fn nodes(&self) -> &[Node]

The known set of nodes.

Source

pub fn node_by_id(&self, id: i32) -> Option<&Node>

Get the node by the node id (or None if the node is not online or does not exist).

Source

pub fn node_if_online( &self, partition: &TopicPartition, id: i32, ) -> Option<&Node>

Get the node by node id if the replica for the given partition is online.

Source

pub fn leader_for(&self, topic_partition: &TopicPartition) -> Option<&Node>

Get the current leader for the given topic-partition.

Source

pub fn partition( &self, topic_partition: &TopicPartition, ) -> Option<&PartitionInfo>

Get the metadata for the specified partition.

Source

pub fn partitions_for_topic(&self, topic: &str) -> &[PartitionInfo]

Get the list of partitions for this topic.

Source

pub fn partition_count_for_topic(&self, topic: &str) -> Option<usize>

Get the number of partitions for the given topic.

Source

pub fn available_partitions_for_topic(&self, topic: &str) -> &[PartitionInfo]

Get the list of available partitions for this topic.

Source

pub fn partitions_for_node(&self, node_id: i32) -> &[PartitionInfo]

Get the list of partitions whose leader is this node.

Source

pub fn topics(&self) -> impl Iterator<Item = &str>

Get all topics.

Source

pub fn unauthorized_topics(&self) -> &HashSet<String>

Unauthorized topics.

Source

pub fn invalid_topics(&self) -> &HashSet<String>

Invalid topics.

Source

pub fn internal_topics(&self) -> &HashSet<String>

Internal topics.

Source

pub fn is_bootstrap_configured(&self) -> bool

Whether bootstrap is configured.

Source

pub fn cluster_resource(&self) -> &ClusterResource

The cluster resource metadata.

Source

pub fn controller(&self) -> Option<&Node>

The controller node, if known.

Source

pub fn topic_ids(&self) -> impl Iterator<Item = &Uuid>

All topic IDs.

Source

pub fn topic_id(&self, topic: &str) -> Uuid

Get the topic ID for a given topic name.

Source

pub fn topic_name(&self, topic_id: &Uuid) -> Option<&str>

Get the topic name for a given topic ID.

Trait Implementations§

Source§

impl Clone for Cluster

Source§

fn clone(&self) -> Cluster

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Cluster

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Cluster

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Cluster

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Cluster

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Cluster

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V