kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From guozh...@apache.org
Subject kafka git commit: KAFKA-4584: Fail the 'kafka-configs' command if the config to be removed does not exist
Date Wed, 04 Jan 2017 05:41:20 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk 6d6c77a7a -> d62ef5525


KAFKA-4584: Fail the 'kafka-configs' command if the config to be removed does not exist

Author: Vahid Hashemian <vahidhashemian@us.ibm.com>

Reviewers: Guozhang Wang <wangguoz@gmail.com>

Closes #2300 from vahidhashemian/KAFKA-4584


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

Branch: refs/heads/trunk
Commit: d62ef55252594bbfa1c26fab19207a9632f7bdd3
Parents: 6d6c77a
Author: Vahid Hashemian <vahidhashemian@us.ibm.com>
Authored: Tue Jan 3 21:41:14 2017 -0800
Committer: Guozhang Wang <wangguoz@gmail.com>
Committed: Tue Jan 3 21:41:14 2017 -0800

----------------------------------------------------------------------
 core/src/main/scala/kafka/admin/ConfigCommand.scala   | 14 +++++++-------
 .../scala/unit/kafka/admin/ConfigCommandTest.scala    | 10 ++++++++++
 2 files changed, 17 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/d62ef552/core/src/main/scala/kafka/admin/ConfigCommand.scala
----------------------------------------------------------------------
diff --git a/core/src/main/scala/kafka/admin/ConfigCommand.scala b/core/src/main/scala/kafka/admin/ConfigCommand.scala
index 9c4c5ed..a6176a2 100644
--- a/core/src/main/scala/kafka/admin/ConfigCommand.scala
+++ b/core/src/main/scala/kafka/admin/ConfigCommand.scala
@@ -20,6 +20,7 @@ package kafka.admin
 import java.util.Properties
 import joptsimple._
 import kafka.common.Config
+import kafka.common.InvalidConfigException
 import kafka.log.LogConfig
 import kafka.server.{ConfigEntityName, ConfigType, DynamicConfig, QuotaId}
 import kafka.utils.{CommandLineUtils, ZkUtils}
@@ -83,14 +84,13 @@ object ConfigCommand extends Config {
     // compile the final set of configs
     val configs = utils.fetchEntityConfig(zkUtils, entityType, entityName)
 
+    // fail the command if any of the configs to be deleted does not exist
+    val invalidConfigs = configsToBeDeleted.filterNot(configs.containsKey(_))
+    if (invalidConfigs.nonEmpty)
+      throw new InvalidConfigException(s"Invalid config(s): ${invalidConfigs.mkString(",")}")
+
     configs.putAll(configsToBeAdded)
-    configsToBeDeleted.foreach { config =>
-      // log an error if the config to be deleted does not exist
-      if (!configs.containsKey(config))
-        System.err.println(s"Deleting config '$config' from entity '$entityName' of type
'$entityType' failed, because the specified config does not exist.")
-      else
-        configs.remove(config)
-    }
+    configsToBeDeleted.foreach(configs.remove(_))
 
     entityType match {
       case ConfigType.Topic => utils.changeTopicConfig(zkUtils, entityName, configs)

http://git-wip-us.apache.org/repos/asf/kafka/blob/d62ef552/core/src/test/scala/unit/kafka/admin/ConfigCommandTest.scala
----------------------------------------------------------------------
diff --git a/core/src/test/scala/unit/kafka/admin/ConfigCommandTest.scala b/core/src/test/scala/unit/kafka/admin/ConfigCommandTest.scala
index ff86693..62015cb 100644
--- a/core/src/test/scala/unit/kafka/admin/ConfigCommandTest.scala
+++ b/core/src/test/scala/unit/kafka/admin/ConfigCommandTest.scala
@@ -197,6 +197,16 @@ class ConfigCommandTest extends ZooKeeperTestHarness with Logging {
     ConfigCommand.alterConfig(null, createOpts, new TestAdminUtils)
   }
 
+  @Test (expected = classOf[InvalidConfigException])
+  def shouldNotUpdateBrokerConfigIfNonExistingConfigIsDeleted(): Unit = {
+    val createOpts = new ConfigCommandOptions(Array("--zookeeper", zkConnect,
+      "--entity-name", "my-topic",
+      "--entity-type", "topics",
+      "--alter",
+      "--delete-config", "missing_config1, missing_config2"))
+    ConfigCommand.alterConfig(null, createOpts, new TestAdminUtils)
+  }
+
   @Test
   def shouldDeleteBrokerConfig(): Unit = {
     val createOpts = new ConfigCommandOptions(Array("--zookeeper", zkConnect,


Mime
View raw message