mirror of https://github.com/apache/kafka.git
KAFKA-9980: Fix bug where alterClientQuotas could not set default client quotas (#8658)
Reviewers: Colin P. McCabe <cmccabe@apache.org>
This commit is contained in:
parent
856e366512
commit
d9e9a18a19
|
@ -714,16 +714,16 @@ class AdminManager(val config: KafkaConfig,
|
|||
new DescribeConfigsResponse.ConfigEntry(name, valueAsString, source, isSensitive, readOnly, synonyms.asJava)
|
||||
}
|
||||
|
||||
private def sanitizeEntityName(entityName: String): String = {
|
||||
if (entityName == ConfigEntityName.Default)
|
||||
throw new InvalidRequestException(s"Entity name '${ConfigEntityName.Default}' is reserved")
|
||||
Sanitizer.sanitize(Option(entityName).getOrElse(ConfigEntityName.Default))
|
||||
}
|
||||
private def sanitizeEntityName(entityName: String): String =
|
||||
Option(entityName) match {
|
||||
case None => ConfigEntityName.Default
|
||||
case Some(name) => Sanitizer.sanitize(name)
|
||||
}
|
||||
|
||||
private def desanitizeEntityName(sanitizedEntityName: String): String =
|
||||
Sanitizer.desanitize(sanitizedEntityName) match {
|
||||
sanitizedEntityName match {
|
||||
case ConfigEntityName.Default => null
|
||||
case name => name
|
||||
case name => Sanitizer.desanitize(name)
|
||||
}
|
||||
|
||||
private def entityToSanitizedUserClientId(entity: ClientQuotaEntity): (Option[String], Option[String]) = {
|
||||
|
|
|
@ -382,6 +382,20 @@ class ClientQuotasRequestTest extends BaseRequestTest {
|
|||
))
|
||||
}
|
||||
|
||||
@Test
|
||||
def testClientQuotasWithDefaultName(): Unit = {
|
||||
// An entity using the name associated with the default entity name. The entity's name should be sanitized so
|
||||
// that it does not conflict with the default entity name.
|
||||
val entity = new ClientQuotaEntity(Map((ClientQuotaEntity.CLIENT_ID -> ConfigEntityName.Default)).asJava)
|
||||
alterEntityQuotas(entity, Map((ProducerByteRateProp -> Some(20000.0))), validateOnly = false)
|
||||
verifyDescribeEntityQuotas(entity, Map((ProducerByteRateProp -> 20000.0)))
|
||||
|
||||
// This should not match.
|
||||
val result = describeClientQuotas(
|
||||
ClientQuotaFilter.containsOnly(List(ClientQuotaFilterComponent.ofDefaultEntity(ClientQuotaEntity.CLIENT_ID)).asJava))
|
||||
assert(result.isEmpty)
|
||||
}
|
||||
|
||||
private def verifyDescribeEntityQuotas(entity: ClientQuotaEntity, quotas: Map[String, Double]) = {
|
||||
val components = entity.entries.asScala.map(e => ClientQuotaFilterComponent.ofEntity(e._1, e._2))
|
||||
val describe = describeClientQuotas(ClientQuotaFilter.containsOnly(components.toList.asJava))
|
||||
|
|
Loading…
Reference in New Issue