bdbyrne commented on a change in pull request #8628: URL: https://github.com/apache/kafka/pull/8628#discussion_r422269335
########## File path: core/src/test/scala/unit/kafka/admin/ConfigCommandTest.scala ########## @@ -398,16 +398,30 @@ class ConfigCommandTest extends ZooKeeperTestHarness with Logging { ConfigCommand.alterConfigWithZk(null, createOpts, new TestAdminZkClient(zkClient)) } - @Test - def shouldAddClientConfig(): Unit = { + def testShouldAddClientConfig(user: Option[String], clientId: Option[String]): Unit = { + def toValues(entityName: Option[String], entityType: String, command: String): + (Array[String], Option[String], Option[ClientQuotaFilterComponent]) = { + entityName match { + case Some(null) => + (Array("--entity-type", command, "--entity-default"), Some(null), + Some(ClientQuotaFilterComponent.ofDefaultEntity(entityType))) + case Some(name) => + (Array("--entity-type", command, "--entity-name", name), Some(name), + Some(ClientQuotaFilterComponent.ofEntity(entityType, name))) + case None => (Array.empty, None, None) + } + } + val (userArgs, userEntity, userComponent) = toValues(user, ClientQuotaEntity.USER, "users") + val (clientIdArgs, clientIdEntity, clientIdComponent) = toValues(clientId, ClientQuotaEntity.CLIENT_ID, "clients") + val createOpts = new ConfigCommandOptions(Array("--bootstrap-server", "localhost:9092", - "--entity-name", "my-client-id", - "--entity-type", "clients", "--alter", "--add-config", "consumer_byte_rate=20000,producer_byte_rate=10000", - "--delete-config", "request_percentage")) + "--delete-config", "request_percentage") ++ userArgs ++ clientIdArgs) - val entity = new ClientQuotaEntity(Map((ClientQuotaEntity.CLIENT_ID -> "my-client-id")).asJava) + val entity = new ClientQuotaEntity(Seq( Review comment: Done. ########## File path: core/src/main/scala/kafka/admin/ConfigCommand.scala ########## @@ -362,21 +362,22 @@ object ConfigCommand extends Config { ).asJavaCollection adminClient.incrementalAlterConfigs(Map(configResource -> alterLogLevelEntries).asJava, alterOptions).all().get(60, TimeUnit.SECONDS) - case ConfigType.User => - case ConfigType.Client => - val oldConfig: Map[String, java.lang.Double] = getClientQuotasConfig(adminClient, entityTypes, entityNames) + case ConfigType.User | ConfigType.Client => + val oldConfig = getClientQuotasConfig(adminClient, entityTypes, entityNames) val invalidConfigs = configsToBeDeleted.filterNot(oldConfig.contains) if (invalidConfigs.nonEmpty) throw new InvalidConfigurationException(s"Invalid config(s): ${invalidConfigs.mkString(",")}") - val entity = new ClientQuotaEntity(opts.entityTypes.map { entType => + val alterEntityTypes = entityTypes.map { entType => entType match { case ConfigType.User => ClientQuotaEntity.USER case ConfigType.Client => ClientQuotaEntity.CLIENT_ID case _ => throw new IllegalArgumentException(s"Unexpected entity type: ${entType}") } - }.zip(opts.entityNames).toMap.asJava) + } + val alterEntityNames = entityNames.map(en => if (en.nonEmpty) en else null) + val entity = new ClientQuotaEntity(alterEntityTypes.zip(alterEntityNames).toMap.asJava) Review comment: Done. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org