增加分区
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
package com.xuxd.kafka.console.beans.dto;
|
package com.xuxd.kafka.console.beans.dto;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,5 +19,5 @@ public class AddPartitionDTO {
|
|||||||
|
|
||||||
private int addNum;
|
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.dto.NewTopicDTO;
|
||||||
import com.xuxd.kafka.console.beans.enums.TopicType;
|
import com.xuxd.kafka.console.beans.enums.TopicType;
|
||||||
import com.xuxd.kafka.console.service.TopicService;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@@ -48,6 +52,18 @@ public class TopicController {
|
|||||||
|
|
||||||
@PostMapping("/partition/new")
|
@PostMapping("/partition/new")
|
||||||
public Object addPartition(@RequestBody AddPartitionDTO partitionDTO) {
|
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",
|
url: "/topic/new",
|
||||||
method: "post",
|
method: "post",
|
||||||
},
|
},
|
||||||
|
addPartition: {
|
||||||
|
url: "/topic/partition/new",
|
||||||
|
method: "post",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const KafkaConsumerApi = {
|
export const KafkaConsumerApi = {
|
||||||
|
|||||||
@@ -18,20 +18,18 @@
|
|||||||
@submit="handleSubmit"
|
@submit="handleSubmit"
|
||||||
>
|
>
|
||||||
<a-form-item label="Topic名称">
|
<a-form-item label="Topic名称">
|
||||||
<a-input disabled="true"
|
<a-input
|
||||||
v-decorator="[
|
:disabled="true"
|
||||||
'name',
|
v-decorator="['topic', { initialValue: topic }]"
|
||||||
{ rules: [{ required: true, message: '输入topic名称!' }] },
|
|
||||||
]"
|
|
||||||
placeholder="topic"
|
placeholder="topic"
|
||||||
/>
|
/>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item label="分区">
|
<a-form-item label="增加分区数">
|
||||||
<a-input-number
|
<a-input-number
|
||||||
:min="1"
|
:min="1"
|
||||||
:max="128"
|
:max="32"
|
||||||
v-decorator="[
|
v-decorator="[
|
||||||
'numPartitions',
|
'addNum',
|
||||||
{
|
{
|
||||||
initialValue: 1,
|
initialValue: 1,
|
||||||
rules: [{ required: true, message: '输入分区数!' }],
|
rules: [{ required: true, message: '输入分区数!' }],
|
||||||
@@ -40,14 +38,13 @@
|
|||||||
/>
|
/>
|
||||||
<span class="ant-form-text"> 个分区 </span>
|
<span class="ant-form-text"> 个分区 </span>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item label="属性">
|
<a-form-item label="副本">
|
||||||
<a-textarea
|
<a-textarea
|
||||||
rows="5"
|
rows="5"
|
||||||
placeholder="格式示例如下:
|
placeholder="可选参数,指定新增分区的副本,格式示例如下:
|
||||||
max.message.bytes=1024
|
1=1,2
|
||||||
retention.bytes=1024
|
2=2,3"
|
||||||
retention.ms=3600000"
|
v-decorator="['assignment']"
|
||||||
v-decorator="['configs']"
|
|
||||||
/>
|
/>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item :wrapper-col="{ span: 12, offset: 5 }">
|
<a-form-item :wrapper-col="{ span: 12, offset: 5 }">
|
||||||
@@ -99,24 +96,25 @@ export default {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.form.validateFields((err, values) => {
|
this.form.validateFields((err, values) => {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
if (values.configs) {
|
if (values.assignment) {
|
||||||
const config = {};
|
const assignment = {};
|
||||||
values.configs.split("\n").forEach((e) => {
|
values.assignment.split("\n").forEach((e) => {
|
||||||
const c = e.split("=");
|
const c = e.split("=");
|
||||||
if (c.length > 1) {
|
if (c.length > 1) {
|
||||||
let k = c[0].trim(),
|
let k = c[0];
|
||||||
v = c[1].trim();
|
let v = c[1];
|
||||||
if (k && v) {
|
let arr = v.split(",");
|
||||||
config[k] = v;
|
if (arr.length > 0) {
|
||||||
|
assignment[k] = arr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
values.configs = config;
|
values.assignment = assignment;
|
||||||
}
|
}
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
request({
|
request({
|
||||||
url: KafkaTopicApi.creatTopic.url,
|
url: KafkaTopicApi.addPartition.url,
|
||||||
method: KafkaTopicApi.creatTopic.method,
|
method: KafkaTopicApi.addPartition.method,
|
||||||
data: values,
|
data: values,
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
|
|||||||
@@ -74,7 +74,7 @@
|
|||||||
size="small"
|
size="small"
|
||||||
href="javascript:;"
|
href="javascript:;"
|
||||||
class="operation-btn"
|
class="operation-btn"
|
||||||
@click="openAddPartitionDialog"
|
@click="openAddPartitionDialog(record.name)"
|
||||||
>增加分区
|
>增加分区
|
||||||
</a-button>
|
</a-button>
|
||||||
</div>
|
</div>
|
||||||
@@ -91,6 +91,7 @@
|
|||||||
</CreateTopic>
|
</CreateTopic>
|
||||||
<AddPartition
|
<AddPartition
|
||||||
:visible="showAddPartition"
|
:visible="showAddPartition"
|
||||||
|
:topic="selectDetail.resourceName"
|
||||||
@closeAddPartitionDialog="closeAddPartitionDialog"
|
@closeAddPartitionDialog="closeAddPartitionDialog"
|
||||||
></AddPartition>
|
></AddPartition>
|
||||||
</div>
|
</div>
|
||||||
@@ -183,7 +184,8 @@ export default {
|
|||||||
this.getTopicList();
|
this.getTopicList();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
openAddPartitionDialog() {
|
openAddPartitionDialog(topic) {
|
||||||
|
this.selectDetail.resourceName = topic;
|
||||||
this.showAddPartition = true;
|
this.showAddPartition = true;
|
||||||
},
|
},
|
||||||
closeAddPartitionDialog(res) {
|
closeAddPartitionDialog(res) {
|
||||||
|
|||||||
Reference in New Issue
Block a user