From fc7f05cf4eaf3ab5cf9d7b1e589e972133d0f43f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=99=93=E4=B8=9C?= <763795151@qq.com> Date: Mon, 6 Feb 2023 22:11:56 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=90=E6=B5=81=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=94=A8=E6=88=B7and=E5=AE=A2=E6=88=B7=E7=AB=AFID=E5=90=8C?= =?UTF-8?q?=E6=97=B6=E5=AD=98=E5=9C=A8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ClientQuotaController.java | 20 ++++++++------ .../kafka/console/ClientQuotaConsole.scala | 8 +++--- ui/src/views/quota/ClientQuota.vue | 9 +++---- ui/src/views/quota/QuotaList.vue | 27 ++++++++++++++----- ui/src/views/quota/UpdateQuotaConfig.vue | 27 ++++++++++++++----- ui/src/views/quota/UserAndClientIDQuota.vue | 25 ++++++++++++++--- 6 files changed, 84 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/xuxd/kafka/console/controller/ClientQuotaController.java b/src/main/java/com/xuxd/kafka/console/controller/ClientQuotaController.java index bce4f05..ad6c921 100644 --- a/src/main/java/com/xuxd/kafka/console/controller/ClientQuotaController.java +++ b/src/main/java/com/xuxd/kafka/console/controller/ClientQuotaController.java @@ -28,20 +28,24 @@ public class ClientQuotaController { @PostMapping public Object alterClientQuotaConfigs(@RequestBody AlterClientQuotaDTO request) { - if (CollectionUtils.isEmpty(request.getTypes()) - || CollectionUtils.isEmpty(request.getNames()) - || request.getTypes().size() != request.getNames().size()) { - return ResponseData.create().failed("types length and names length is invalid."); + if (request.getTypes().size() != 2) { + if (CollectionUtils.isEmpty(request.getTypes()) + || CollectionUtils.isEmpty(request.getNames()) + || request.getTypes().size() != request.getNames().size()) { + return ResponseData.create().failed("types length and names length is invalid."); + } } return clientQuotaService.alterClientQuotaConfigs(request); } @DeleteMapping public Object deleteClientQuotaConfigs(@RequestBody AlterClientQuotaDTO request) { - if (CollectionUtils.isEmpty(request.getTypes()) - || CollectionUtils.isEmpty(request.getNames()) - || request.getTypes().size() != request.getNames().size()) { - return ResponseData.create().failed("types length and names length is invalid."); + if (request.getTypes().size() != 2) { + if (CollectionUtils.isEmpty(request.getTypes()) + || CollectionUtils.isEmpty(request.getNames()) + || request.getTypes().size() != request.getNames().size()) { + return ResponseData.create().failed("types length and names length is invalid."); + } } return clientQuotaService.deleteClientQuotaConfigs(request); } diff --git a/src/main/scala/kafka/console/ClientQuotaConsole.scala b/src/main/scala/kafka/console/ClientQuotaConsole.scala index c24caac..0c3550f 100644 --- a/src/main/scala/kafka/console/ClientQuotaConsole.scala +++ b/src/main/scala/kafka/console/ClientQuotaConsole.scala @@ -34,12 +34,14 @@ class ClientQuotaConsole(config: KafkaConfig) extends KafkaConsole(config: Kafka } def alterQuotaConfigs(entityTypes: java.util.List[String], entityNames: java.util.List[String], configsToBeAddedMap: java.util.Map[String, String], configsToBeDeleted: java.util.List[String]): (Boolean, String) = { - withAdminClientAndCatchError(admin => alterQuotaConfigsInner(admin, entityTypes.asScala.toList, entityNames.asScala.toList, configsToBeAddedMap.asScala.toMap, configsToBeDeleted.asScala.toSeq), + withAdminClientAndCatchError(admin => { + alterQuotaConfigsInner(admin, entityTypes.asScala.toList, entityNames.asScala.toList, configsToBeAddedMap.asScala.toMap, configsToBeDeleted.asScala.toSeq) + (true, "") + }, e => { log.error("getAllClientQuotasConfigs error.", e) (false, e.getMessage) - }) - (true, "") + }).asInstanceOf[(Boolean, String)] } private def getAllClientQuotasConfigs(adminClient: Admin, entityTypes: List[String], entityNames: List[String]): java.util.Map[ClientQuotaEntity, java.util.Map[String, Double]] = { diff --git a/ui/src/views/quota/ClientQuota.vue b/ui/src/views/quota/ClientQuota.vue index 528ccab..0028481 100644 --- a/ui/src/views/quota/ClientQuota.vue +++ b/ui/src/views/quota/ClientQuota.vue @@ -13,9 +13,9 @@ - - - + + + @@ -25,11 +25,10 @@ import ClientIDQuota from "@/views/quota/ClientIDQuota.vue"; import UserQuota from "@/views/quota/UserQuota.vue"; import UserAndClientIDQuota from "@/views/quota/UserAndClientIDQuota.vue"; -import IpQuota from "@/views/quota/IpQuota.vue"; export default { name: "ClientQuota", - components: {ClientIDQuota, UserQuota, UserAndClientIDQuota, IpQuota}, + components: {ClientIDQuota, UserQuota, UserAndClientIDQuota}, data() { return { loading: false, diff --git a/ui/src/views/quota/QuotaList.vue b/ui/src/views/quota/QuotaList.vue index 83f40ef..852d1db 100644 --- a/ui/src/views/quota/QuotaList.vue +++ b/ui/src/views/quota/QuotaList.vue @@ -90,27 +90,42 @@ export default { this.loading = true; const params = {type: this.type}; params.types = []; + params.names = []; if (this.type == "user") { params.types.push("user"); if (record.user) { - params.names = [record.user.trim()]; + params.names.push(record.user.trim()); } else { - params.names = [""]; + params.names.push(""); } } else if (this.type == "client-id") { params.types.push("client-id"); if (record.client) { - params.names = [record.client.trim()]; + params.names.push(record.client.trim()); } else { - params.names = [""]; + params.names.push(""); } } if (this.type == "ip") { params.types.push("ip"); if (record.ip) { - params.names = [record.ip.trim()]; + params.names.push(record.ip.trim()); } else { - params.names = [""]; + params.names.push(""); + } + } + if (this.type == "user&client-id") { + params.types.push("user"); + params.types.push("client-id"); + if (record.user) { + params.names.push(record.user.trim()); + } else { + params.names.push(""); + } + if (record.client) { + params.names.push(record.client.trim()); + } else { + params.names.push(""); } } request({ diff --git a/ui/src/views/quota/UpdateQuotaConfig.vue b/ui/src/views/quota/UpdateQuotaConfig.vue index 2c36f8f..d97ac76 100644 --- a/ui/src/views/quota/UpdateQuotaConfig.vue +++ b/ui/src/views/quota/UpdateQuotaConfig.vue @@ -159,28 +159,43 @@ export default { params.deleteConfigs.push("requestPercentage"); } params.types = []; + params.names = []; if (this.showUser) { params.types.push("user"); if (values.user) { - params.names = [values.user.trim()]; + params.names.push(values.user.trim()); } else { - params.names = [""]; + params.names.push(""); } } if (this.showClientId) { params.types.push("client-id"); if (values.client) { - params.names = [values.client.trim()]; + params.names.push(values.client.trim()); } else { - params.names = [""]; + params.names.push(""); } } if (this.showIP) { params.types.push("ip"); if (values.ip) { - params.names = [values.ip.trim()]; + params.names.push(values.ip.trim()); } else { - params.names = [""]; + params.names.push(""); + } + } + if (this.showUser && this.showClientId) { + params.types.push("user"); + params.types.push("client-id"); + if (values.user) { + params.names.push(values.user.trim()); + } else { + params.names.push(""); + } + if (values.client) { + params.names.push(values.client.trim()); + } else { + params.names.push(""); } } this.loading = true; diff --git a/ui/src/views/quota/UserAndClientIDQuota.vue b/ui/src/views/quota/UserAndClientIDQuota.vue index 1619636..30fafb0 100644 --- a/ui/src/views/quota/UserAndClientIDQuota.vue +++ b/ui/src/views/quota/UserAndClientIDQuota.vue @@ -8,7 +8,7 @@ @submit="handleSearch" > - + + + + + 搜索 @@ -32,7 +42,8 @@ - + @@ -97,9 +108,15 @@ export default { this.form.validateFields((err, values) => { if (!err) { this.loading = true; - const params = {types: ["user"]}; + const params = {types: ["user", "client-id"], names: []}; if (values.user) { - params.names = [values.user.trim()]; + params.names.push(values.user.trim()); + } + if (values.client) { + if (params.names.length == 0) { + params.names.push(""); + } + params.names.push(values.client.trim()); } request({ url: KafkaClientQuotaApi.getClientQuotaConfigs.url,