preferred as leader.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package com.xuxd.kafka.console.beans.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
*
|
||||
* @author xuxd
|
||||
* @date 2021-11-10 20:09:20
|
||||
**/
|
||||
@Data
|
||||
public class ReplicationDTO {
|
||||
|
||||
private String topic;
|
||||
|
||||
private int partition;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.xuxd.kafka.console.controller;
|
||||
|
||||
import com.xuxd.kafka.console.beans.dto.ReplicationDTO;
|
||||
import com.xuxd.kafka.console.beans.dto.SyncDataDTO;
|
||||
import com.xuxd.kafka.console.service.OperationService;
|
||||
import org.apache.kafka.clients.admin.AdminClientConfig;
|
||||
@@ -46,4 +47,9 @@ public class OperationController {
|
||||
public Object deleteAlignment(@RequestParam Long id) {
|
||||
return operationService.deleteAlignmentById(id);
|
||||
}
|
||||
|
||||
@PostMapping("/replication/preferred")
|
||||
public Object electPreferredLeader(@RequestBody ReplicationDTO dto) {
|
||||
return operationService.electPreferredLeader(dto.getTopic(), dto.getPartition());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,4 +18,6 @@ public interface OperationService {
|
||||
ResponseData getAlignmentList();
|
||||
|
||||
ResponseData deleteAlignmentById(Long id);
|
||||
|
||||
ResponseData electPreferredLeader(String topic, int partition);
|
||||
}
|
||||
|
||||
@@ -9,9 +9,11 @@ import com.xuxd.kafka.console.beans.vo.OffsetAlignmentVO;
|
||||
import com.xuxd.kafka.console.dao.MinOffsetAlignmentMapper;
|
||||
import com.xuxd.kafka.console.service.OperationService;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import kafka.console.OperationConsole;
|
||||
import org.apache.kafka.common.TopicPartition;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
@@ -107,4 +109,17 @@ public class OperationServiceImpl implements OperationService {
|
||||
minOffsetAlignmentMapper.deleteById(id);
|
||||
return ResponseData.create().success();
|
||||
}
|
||||
|
||||
@Override public ResponseData electPreferredLeader(String topic, int partition) {
|
||||
Set<TopicPartition> partitions = new HashSet<>();
|
||||
if (partition != -1) {
|
||||
partitions.add(new TopicPartition(topic, partition));
|
||||
} else {
|
||||
|
||||
partitions.addAll(operationConsole.getTopicPartitions(topic));
|
||||
}
|
||||
Tuple2<Object, String> tuple2 = operationConsole.electPreferredLeader(partitions);
|
||||
|
||||
return (boolean) tuple2._1() ? ResponseData.create().success() : ResponseData.create().failed(tuple2._2());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user