增加分区
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package com.xuxd.kafka.console.beans.dto;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@@ -17,5 +19,5 @@ public class AddPartitionDTO {
|
||||
|
||||
private int addNum;
|
||||
|
||||
private List<List<Integer>> assignment = new ArrayList<>();
|
||||
private Map<Integer, List<Integer>> assignment = new HashMap<>();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,10 @@ import com.xuxd.kafka.console.beans.dto.AddPartitionDTO;
|
||||
import com.xuxd.kafka.console.beans.dto.NewTopicDTO;
|
||||
import com.xuxd.kafka.console.beans.enums.TopicType;
|
||||
import com.xuxd.kafka.console.service.TopicService;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -48,6 +52,18 @@ public class TopicController {
|
||||
|
||||
@PostMapping("/partition/new")
|
||||
public Object addPartition(@RequestBody AddPartitionDTO partitionDTO) {
|
||||
return topicService.addPartitions(partitionDTO.getTopic().trim(), partitionDTO.getAddNum(), partitionDTO.getAssignment());
|
||||
String topic = partitionDTO.getTopic().trim();
|
||||
int addNum = partitionDTO.getAddNum();
|
||||
Map<Integer, List<Integer>> assignmentMap = partitionDTO.getAssignment();
|
||||
List<List<Integer>> assignment = Collections.emptyList();
|
||||
|
||||
if (!assignmentMap.isEmpty()) {
|
||||
assignment = new ArrayList<>(addNum);
|
||||
for (int i = 1; i <= addNum; i++) {
|
||||
assignment.add(assignmentMap.containsKey(i) ? assignmentMap.get(i) : Collections.emptyList());
|
||||
}
|
||||
}
|
||||
|
||||
return topicService.addPartitions(topic, addNum, assignment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.xuxd.kafka.console.interceptor;
|
||||
|
||||
import com.xuxd.kafka.console.beans.ResponseData;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
*
|
||||
* @author xuxd
|
||||
* @date 2021-10-19 14:32:18
|
||||
**/
|
||||
@Slf4j
|
||||
@ControllerAdvice(basePackages = "com.xuxd.kafka.console.controller")
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
@ResponseBody
|
||||
public Object exceptionHandler(HttpServletRequest req, Exception ex) throws Exception {
|
||||
|
||||
log.error("exception handle: ", ex);
|
||||
return ResponseData.create().failed(ex.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,10 @@ export const KafkaTopicApi = {
|
||||
url: "/topic/new",
|
||||
method: "post",
|
||||
},
|
||||
addPartition: {
|
||||
url: "/topic/partition/new",
|
||||
method: "post",
|
||||
},
|
||||
};
|
||||
|
||||
export const KafkaConsumerApi = {
|
||||
|
||||
@@ -18,20 +18,18 @@
|
||||
@submit="handleSubmit"
|
||||
>
|
||||
<a-form-item label="Topic名称">
|
||||
<a-input disabled="true"
|
||||
v-decorator="[
|
||||
'name',
|
||||
{ rules: [{ required: true, message: '输入topic名称!' }] },
|
||||
]"
|
||||
<a-input
|
||||
:disabled="true"
|
||||
v-decorator="['topic', { initialValue: topic }]"
|
||||
placeholder="topic"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="分区">
|
||||
<a-form-item label="增加分区数">
|
||||
<a-input-number
|
||||
:min="1"
|
||||
:max="128"
|
||||
:max="32"
|
||||
v-decorator="[
|
||||
'numPartitions',
|
||||
'addNum',
|
||||
{
|
||||
initialValue: 1,
|
||||
rules: [{ required: true, message: '输入分区数!' }],
|
||||
@@ -40,14 +38,13 @@
|
||||
/>
|
||||
<span class="ant-form-text"> 个分区 </span>
|
||||
</a-form-item>
|
||||
<a-form-item label="属性">
|
||||
<a-form-item label="副本">
|
||||
<a-textarea
|
||||
rows="5"
|
||||
placeholder="格式示例如下:
|
||||
max.message.bytes=1024
|
||||
retention.bytes=1024
|
||||
retention.ms=3600000"
|
||||
v-decorator="['configs']"
|
||||
placeholder="可选参数,指定新增分区的副本,格式示例如下:
|
||||
1=1,2
|
||||
2=2,3"
|
||||
v-decorator="['assignment']"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item :wrapper-col="{ span: 12, offset: 5 }">
|
||||
@@ -99,24 +96,25 @@ export default {
|
||||
e.preventDefault();
|
||||
this.form.validateFields((err, values) => {
|
||||
if (!err) {
|
||||
if (values.configs) {
|
||||
const config = {};
|
||||
values.configs.split("\n").forEach((e) => {
|
||||
if (values.assignment) {
|
||||
const assignment = {};
|
||||
values.assignment.split("\n").forEach((e) => {
|
||||
const c = e.split("=");
|
||||
if (c.length > 1) {
|
||||
let k = c[0].trim(),
|
||||
v = c[1].trim();
|
||||
if (k && v) {
|
||||
config[k] = v;
|
||||
let k = c[0];
|
||||
let v = c[1];
|
||||
let arr = v.split(",");
|
||||
if (arr.length > 0) {
|
||||
assignment[k] = arr;
|
||||
}
|
||||
}
|
||||
});
|
||||
values.configs = config;
|
||||
values.assignment = assignment;
|
||||
}
|
||||
this.loading = true;
|
||||
request({
|
||||
url: KafkaTopicApi.creatTopic.url,
|
||||
method: KafkaTopicApi.creatTopic.method,
|
||||
url: KafkaTopicApi.addPartition.url,
|
||||
method: KafkaTopicApi.addPartition.method,
|
||||
data: values,
|
||||
}).then((res) => {
|
||||
this.loading = false;
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
size="small"
|
||||
href="javascript:;"
|
||||
class="operation-btn"
|
||||
@click="openAddPartitionDialog"
|
||||
@click="openAddPartitionDialog(record.name)"
|
||||
>增加分区
|
||||
</a-button>
|
||||
</div>
|
||||
@@ -91,6 +91,7 @@
|
||||
</CreateTopic>
|
||||
<AddPartition
|
||||
:visible="showAddPartition"
|
||||
:topic="selectDetail.resourceName"
|
||||
@closeAddPartitionDialog="closeAddPartitionDialog"
|
||||
></AddPartition>
|
||||
</div>
|
||||
@@ -183,7 +184,8 @@ export default {
|
||||
this.getTopicList();
|
||||
}
|
||||
},
|
||||
openAddPartitionDialog() {
|
||||
openAddPartitionDialog(topic) {
|
||||
this.selectDetail.resourceName = topic;
|
||||
this.showAddPartition = true;
|
||||
},
|
||||
closeAddPartitionDialog(res) {
|
||||
|
||||
Reference in New Issue
Block a user