diff --git a/src/main/java/com/xuxd/kafka/console/controller/TopicController.java b/src/main/java/com/xuxd/kafka/console/controller/TopicController.java index e775318..c5b083b 100644 --- a/src/main/java/com/xuxd/kafka/console/controller/TopicController.java +++ b/src/main/java/com/xuxd/kafka/console/controller/TopicController.java @@ -43,8 +43,8 @@ public class TopicController { } @DeleteMapping - public Object deleteTopic(@RequestParam String topic) { - return topicService.deleteTopic(topic); + public Object deleteTopic(@RequestBody List topics) { + return topicService.deleteTopics(topics); } @GetMapping("/partition") diff --git a/src/main/java/com/xuxd/kafka/console/service/TopicService.java b/src/main/java/com/xuxd/kafka/console/service/TopicService.java index 2255e7a..3828974 100644 --- a/src/main/java/com/xuxd/kafka/console/service/TopicService.java +++ b/src/main/java/com/xuxd/kafka/console/service/TopicService.java @@ -4,6 +4,8 @@ import com.xuxd.kafka.console.beans.ReplicaAssignment; import com.xuxd.kafka.console.beans.ResponseData; import com.xuxd.kafka.console.beans.enums.TopicThrottleSwitch; import com.xuxd.kafka.console.beans.enums.TopicType; + +import java.util.Collection; import java.util.List; import org.apache.kafka.clients.admin.NewTopic; @@ -19,7 +21,7 @@ public interface TopicService { ResponseData getTopicList(String topic, TopicType type); - ResponseData deleteTopic(String topic); + ResponseData deleteTopics(Collection topics); ResponseData getTopicPartitionInfo(String topic); diff --git a/src/main/java/com/xuxd/kafka/console/service/impl/TopicServiceImpl.java b/src/main/java/com/xuxd/kafka/console/service/impl/TopicServiceImpl.java index ccf5e4c..3074d74 100644 --- a/src/main/java/com/xuxd/kafka/console/service/impl/TopicServiceImpl.java +++ b/src/main/java/com/xuxd/kafka/console/service/impl/TopicServiceImpl.java @@ -9,16 +9,6 @@ import com.xuxd.kafka.console.beans.vo.TopicDescriptionVO; import com.xuxd.kafka.console.beans.vo.TopicPartitionVO; import com.xuxd.kafka.console.service.TopicService; import com.xuxd.kafka.console.utils.GsonUtil; -import java.util.Calendar; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.atomic.AtomicLong; -import java.util.stream.Collectors; import kafka.console.MessageConsole; import kafka.console.TopicConsole; import lombok.extern.slf4j.Slf4j; @@ -33,6 +23,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import scala.Tuple2; +import java.util.*; +import java.util.concurrent.atomic.AtomicLong; +import java.util.stream.Collectors; + /** * kafka-console-ui. * @@ -87,8 +81,8 @@ public class TopicServiceImpl implements TopicService { return ResponseData.create().data(topicDescriptions.stream().map(d -> TopicDescriptionVO.from(d))).success(); } - @Override public ResponseData deleteTopic(String topic) { - Tuple2 tuple2 = topicConsole.deleteTopic(topic); + @Override public ResponseData deleteTopics(Collection topics) { + Tuple2 tuple2 = topicConsole.deleteTopics(topics); return (Boolean) tuple2._1 ? ResponseData.create().success() : ResponseData.create().failed(tuple2._2); } diff --git a/src/main/scala/kafka/console/TopicConsole.scala b/src/main/scala/kafka/console/TopicConsole.scala index a16bb03..054ffbb 100644 --- a/src/main/scala/kafka/console/TopicConsole.scala +++ b/src/main/scala/kafka/console/TopicConsole.scala @@ -66,17 +66,17 @@ class TopicConsole(config: KafkaConfig) extends KafkaConsole(config: KafkaConfig /** * delete topic by topic name. * - * @param topic topic name. + * @param topics topic name list. * @return result or : fail message. */ - def deleteTopic(topic: String): (Boolean, String) = { + def deleteTopics(topics: util.Collection[String]): (Boolean, String) = { withAdminClientAndCatchError(admin => { val timeoutMs = ContextConfigHolder.CONTEXT_CONFIG.get().getRequestTimeoutMs() - admin.deleteTopics(Collections.singleton(topic), new DeleteTopicsOptions().retryOnQuotaViolation(false)).all().get(timeoutMs, TimeUnit.MILLISECONDS) + admin.deleteTopics(topics, new DeleteTopicsOptions().retryOnQuotaViolation(false)).all().get(timeoutMs, TimeUnit.MILLISECONDS) (true, "") }, e => { - log.error("delete topic error, topic: " + topic, e) + log.error("delete topic error, topic: " + topics, e) (false, e.getMessage) }).asInstanceOf[(Boolean, String)] } diff --git a/ui/src/views/topic/Topic.vue b/ui/src/views/topic/Topic.vue index d004d2a..919c509 100644 --- a/ui/src/views/topic/Topic.vue +++ b/ui/src/views/topic/Topic.vue @@ -49,10 +49,26 @@ 新增 + + + 批量删除 + + + + + @@ -225,8 +241,14 @@ export default { filterTopic: "", filteredData: [], type: "normal", + selectedRowKeys: [], // Check here to configure the default column }; }, + computed: { + hasSelected() { + return this.selectedRowKeys.length > 0; + }, + }, methods: { handleSearch(e) { e.preventDefault(); @@ -256,14 +278,16 @@ export default { } }); }, - deleteTopic(topic) { + deleteTopics(topics) { request({ - url: KafkaTopicApi.deleteTopic.url + "?topic=" + topic, + url: KafkaTopicApi.deleteTopic.url, method: KafkaTopicApi.deleteTopic.method, + data: topics }).then((res) => { if (res.code == 0) { this.$message.success(res.msg); this.getTopicList(); + this.selectedRowKeys = []; } else { notification.error({ message: "error", @@ -272,6 +296,9 @@ export default { } }); }, + deleteTopic(topic) { + this.deleteTopics([topic]) + }, onTopicUpdate(input) { this.filterTopic = input.target.value; this.filter(); @@ -342,9 +369,13 @@ export default { closeThrottleDialog() { this.showThrottleDialog = false; }, + onSelectChange(selectedRowKeys) { + this.selectedRowKeys = selectedRowKeys; + }, }, created() { this.getTopicList(); + this.selectedRowKeys = []; }, }; @@ -431,4 +462,8 @@ const columns = [ .type-select { width: 200px !important; } + +.btn-left { + margin-left: 1%; +}