增加分区
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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user