kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jun...@apache.org
Subject git commit: kafka-827; improve list topic output format; patched by Jun Rao; reviewed by Neha Narkhede
Date Mon, 01 Apr 2013 17:42:08 GMT
Updated Branches:
  refs/heads/0.8 a9ce73cfd -> 3c27988ca


kafka-827; improve list topic output format; patched by Jun Rao; reviewed by Neha Narkhede


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/3c27988c
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/3c27988c
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/3c27988c

Branch: refs/heads/0.8
Commit: 3c27988ca4036985f4c7bef62b9bbae3f95f0fb9
Parents: a9ce73c
Author: Jun Rao <junrao@gmail.com>
Authored: Mon Apr 1 10:41:40 2013 -0700
Committer: Jun Rao <junrao@gmail.com>
Committed: Mon Apr 1 10:41:40 2013 -0700

----------------------------------------------------------------------
 .../main/scala/kafka/admin/ListTopicCommand.scala  |    4 ++--
 core/src/main/scala/kafka/api/TopicMetadata.scala  |   11 +++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/3c27988c/core/src/main/scala/kafka/admin/ListTopicCommand.scala
----------------------------------------------------------------------
diff --git a/core/src/main/scala/kafka/admin/ListTopicCommand.scala b/core/src/main/scala/kafka/admin/ListTopicCommand.scala
index f91eca2..baeb099 100644
--- a/core/src/main/scala/kafka/admin/ListTopicCommand.scala
+++ b/core/src/main/scala/kafka/admin/ListTopicCommand.scala
@@ -26,7 +26,7 @@ object ListTopicCommand {
 
   def main(args: Array[String]): Unit = {
     val parser = new OptionParser
-    val topicOpt = parser.accepts("topic", "REQUIRED: The topic to be deleted.")
+    val topicOpt = parser.accepts("topic", "REQUIRED: The topic to be listed. Defaults to
all existing topics.")
                          .withRequiredArg
                          .describedAs("topic")
                          .ofType(classOf[String])
@@ -55,7 +55,7 @@ object ListTopicCommand {
       zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer)
 
       if (topic == "")
-        topicList = ZkUtils.getChildren(zkClient, ZkUtils.BrokerTopicsPath)
+        topicList = ZkUtils.getChildren(zkClient, ZkUtils.BrokerTopicsPath).sorted
       else
         topicList = List(topic)
 

http://git-wip-us.apache.org/repos/asf/kafka/blob/3c27988c/core/src/main/scala/kafka/api/TopicMetadata.scala
----------------------------------------------------------------------
diff --git a/core/src/main/scala/kafka/api/TopicMetadata.scala b/core/src/main/scala/kafka/api/TopicMetadata.scala
index 409de76..f822678 100644
--- a/core/src/main/scala/kafka/api/TopicMetadata.scala
+++ b/core/src/main/scala/kafka/api/TopicMetadata.scala
@@ -108,6 +108,17 @@ case class PartitionMetadata(partitionId: Int,
     buffer.putInt(isr.size)
     isr.foreach(r => buffer.putInt(r.id))
   }
+
+  override def toString(): String = {
+    val partitionMetadataString = new StringBuilder
+    partitionMetadataString.append("\tpartition " + partitionId)
+    partitionMetadataString.append("\tleader: " + (if(leader.isDefined) formatBroker(leader.get)
else "none"))
+    partitionMetadataString.append("\treplicas: " + replicas.map(formatBroker).mkString(","))
+    partitionMetadataString.append("\tisr: " + isr.map(formatBroker).mkString(","))
+    partitionMetadataString.toString()
+  }
+
+  private def formatBroker(broker: Broker) = broker.id + " (" + broker.host + ":" + broker.port
+ ")"
 }
 
 


Mime
View raw message