Package org.apache.kafka.common
Class Cluster
- java.lang.Object
-
- org.apache.kafka.common.Cluster
-
public final class Cluster extends Object
An immutable representation of a subset of the nodes, topics, and partitions in the Kafka cluster.
-
-
Constructor Summary
Constructors Constructor Description Cluster(String clusterId, Collection<Node> nodes, Collection<PartitionInfo> partitions, Set<String> unauthorizedTopics, Set<String> internalTopics)
Create a new cluster with the given id, nodes and partitionsCluster(String clusterId, Collection<Node> nodes, Collection<PartitionInfo> partitions, Set<String> unauthorizedTopics, Set<String> invalidTopics, Set<String> internalTopics, Node controller)
Create a new cluster with the given id, nodes and partitionsCluster(String clusterId, Collection<Node> nodes, Collection<PartitionInfo> partitions, Set<String> unauthorizedTopics, Set<String> invalidTopics, Set<String> internalTopics, Node controller, Map<String,Uuid> topicIds)
Create a new cluster with the given id, nodes, partitions and topicIdsCluster(String clusterId, Collection<Node> nodes, Collection<PartitionInfo> partitions, Set<String> unauthorizedTopics, Set<String> internalTopics, Node controller)
Create a new cluster with the given id, nodes and partitions
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<PartitionInfo>
availablePartitionsForTopic(String topic)
Get the list of available partitions for this topicstatic Cluster
bootstrap(List<InetSocketAddress> addresses)
Create a "bootstrap" cluster using the given list of host/portsClusterResource
clusterResource()
Node
controller()
static Cluster
empty()
Create an empty cluster instance with no nodes and no topic-partitions.boolean
equals(Object o)
int
hashCode()
Set<String>
internalTopics()
Set<String>
invalidTopics()
boolean
isBootstrapConfigured()
Node
leaderFor(TopicPartition topicPartition)
Get the current leader for the given topic-partitionNode
nodeById(int id)
Get the node by the node id (or null if the node is not online or does not exist)Optional<Node>
nodeIfOnline(TopicPartition partition, int id)
Get the node by node id if the replica for the given partition is onlineList<Node>
nodes()
PartitionInfo
partition(TopicPartition topicPartition)
Get the metadata for the specified partitionInteger
partitionCountForTopic(String topic)
Get the number of partitions for the given topic.List<PartitionInfo>
partitionsForNode(int nodeId)
Get the list of partitions whose leader is this nodeList<PartitionInfo>
partitionsForTopic(String topic)
Get the list of partitions for this topicUuid
topicId(String topic)
Collection<Uuid>
topicIds()
String
topicName(Uuid topicId)
Set<String>
topics()
Get all topics.String
toString()
Set<String>
unauthorizedTopics()
Cluster
withPartitions(Map<TopicPartition,PartitionInfo> partitions)
Return a copy of this cluster combined with `partitions`.
-
-
-
Constructor Detail
-
Cluster
public Cluster(String clusterId, Collection<Node> nodes, Collection<PartitionInfo> partitions, Set<String> unauthorizedTopics, Set<String> internalTopics)
Create a new cluster with the given id, nodes and partitions- Parameters:
nodes
- The nodes in the clusterpartitions
- Information about a subset of the topic-partitions this cluster hosts
-
Cluster
public Cluster(String clusterId, Collection<Node> nodes, Collection<PartitionInfo> partitions, Set<String> unauthorizedTopics, Set<String> internalTopics, Node controller)
Create a new cluster with the given id, nodes and partitions- Parameters:
nodes
- The nodes in the clusterpartitions
- Information about a subset of the topic-partitions this cluster hosts
-
Cluster
public Cluster(String clusterId, Collection<Node> nodes, Collection<PartitionInfo> partitions, Set<String> unauthorizedTopics, Set<String> invalidTopics, Set<String> internalTopics, Node controller)
Create a new cluster with the given id, nodes and partitions- Parameters:
nodes
- The nodes in the clusterpartitions
- Information about a subset of the topic-partitions this cluster hosts
-
Cluster
public Cluster(String clusterId, Collection<Node> nodes, Collection<PartitionInfo> partitions, Set<String> unauthorizedTopics, Set<String> invalidTopics, Set<String> internalTopics, Node controller, Map<String,Uuid> topicIds)
Create a new cluster with the given id, nodes, partitions and topicIds- Parameters:
nodes
- The nodes in the clusterpartitions
- Information about a subset of the topic-partitions this cluster hosts
-
-
Method Detail
-
empty
public static Cluster empty()
Create an empty cluster instance with no nodes and no topic-partitions.
-
bootstrap
public static Cluster bootstrap(List<InetSocketAddress> addresses)
Create a "bootstrap" cluster using the given list of host/ports- Parameters:
addresses
- The addresses- Returns:
- A cluster for these hosts/ports
-
withPartitions
public Cluster withPartitions(Map<TopicPartition,PartitionInfo> partitions)
Return a copy of this cluster combined with `partitions`.
-
nodeById
public Node nodeById(int id)
Get the node by the node id (or null if the node is not online or does not exist)- Parameters:
id
- The id of the node- Returns:
- The node, or null if the node is not online or does not exist
-
nodeIfOnline
public Optional<Node> nodeIfOnline(TopicPartition partition, int id)
Get the node by node id if the replica for the given partition is online- Parameters:
partition
-id
-- Returns:
- the node
-
leaderFor
public Node leaderFor(TopicPartition topicPartition)
Get the current leader for the given topic-partition- Parameters:
topicPartition
- The topic and partition we want to know the leader for- Returns:
- The node that is the leader for this topic-partition, or null if there is currently no leader
-
partition
public PartitionInfo partition(TopicPartition topicPartition)
Get the metadata for the specified partition- Parameters:
topicPartition
- The topic and partition to fetch info for- Returns:
- The metadata about the given topic and partition, or null if none is found
-
partitionsForTopic
public List<PartitionInfo> partitionsForTopic(String topic)
Get the list of partitions for this topic- Parameters:
topic
- The topic name- Returns:
- A list of partitions
-
partitionCountForTopic
public Integer partitionCountForTopic(String topic)
Get the number of partitions for the given topic.- Parameters:
topic
- The topic to get the number of partitions for- Returns:
- The number of partitions or null if there is no corresponding metadata
-
availablePartitionsForTopic
public List<PartitionInfo> availablePartitionsForTopic(String topic)
Get the list of available partitions for this topic- Parameters:
topic
- The topic name- Returns:
- A list of partitions
-
partitionsForNode
public List<PartitionInfo> partitionsForNode(int nodeId)
Get the list of partitions whose leader is this node- Parameters:
nodeId
- The node id- Returns:
- A list of partitions
-
isBootstrapConfigured
public boolean isBootstrapConfigured()
-
clusterResource
public ClusterResource clusterResource()
-
controller
public Node controller()
-
topicIds
public Collection<Uuid> topicIds()
-
-