broker config
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package com.xuxd.kafka.console.beans.vo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import lombok.Data;
|
||||
import org.apache.kafka.clients.admin.ConfigEntry;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
*
|
||||
* @author xuxd
|
||||
* @date 2021-11-03 15:32:08
|
||||
**/
|
||||
@Data
|
||||
public class ConfigEntryVO implements Comparable {
|
||||
|
||||
private static final Map<String, Integer> ORDER_DICTIONARY = new HashMap<>();
|
||||
|
||||
static {
|
||||
ORDER_DICTIONARY.put("DYNAMIC_TOPIC_CONFIG", 0);
|
||||
ORDER_DICTIONARY.put("DYNAMIC_BROKER_LOGGER_CONFIG", 1);
|
||||
ORDER_DICTIONARY.put("DYNAMIC_BROKER_CONFIG", 2);
|
||||
ORDER_DICTIONARY.put("DYNAMIC_DEFAULT_BROKER_CONFIG", 3);
|
||||
ORDER_DICTIONARY.put("DEFAULT_CONFIG", 4);
|
||||
ORDER_DICTIONARY.put("STATIC_BROKER_CONFIG", 5);
|
||||
ORDER_DICTIONARY.put("UNKNOWN", 6);
|
||||
}
|
||||
|
||||
private String name;
|
||||
|
||||
private String value;
|
||||
|
||||
private String source;
|
||||
|
||||
private boolean sensitive;
|
||||
|
||||
private boolean readOnly;
|
||||
|
||||
public static ConfigEntryVO from(ConfigEntry entry) {
|
||||
ConfigEntryVO vo = new ConfigEntryVO();
|
||||
vo.name = entry.name();
|
||||
vo.value = entry.value();
|
||||
vo.source = entry.source().name();
|
||||
vo.sensitive = entry.isSensitive();
|
||||
vo.readOnly = entry.isReadOnly();
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override public int compareTo(Object o) {
|
||||
|
||||
ConfigEntryVO that = (ConfigEntryVO) o;
|
||||
|
||||
if (!this.source.equals(that.source)) {
|
||||
return ORDER_DICTIONARY.get(this.source) - ORDER_DICTIONARY.get(that.source);
|
||||
}
|
||||
if (this.readOnly != that.readOnly) {
|
||||
return this.readOnly ? 1 : -1;
|
||||
}
|
||||
|
||||
return this.name.compareTo(that.name);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import com.xuxd.kafka.console.config.KafkaConfig;
|
||||
import com.xuxd.kafka.console.service.ConfigService;
|
||||
import com.xuxd.kafka.console.utils.ConvertUtil;
|
||||
import java.util.Map;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -43,7 +42,7 @@ public class ConfigController {
|
||||
}
|
||||
|
||||
@GetMapping("/broker")
|
||||
public Object getTopicConfig() {
|
||||
return configService.getBrokerConfig();
|
||||
public Object getBrokerConfig(String brokerId) {
|
||||
return configService.getBrokerConfig(brokerId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,5 +12,5 @@ public interface ConfigService {
|
||||
|
||||
ResponseData getTopicConfig(String topic);
|
||||
|
||||
ResponseData getBrokerConfig();
|
||||
ResponseData getBrokerConfig(String brokerId);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.xuxd.kafka.console.service.impl;
|
||||
|
||||
import com.xuxd.kafka.console.beans.ResponseData;
|
||||
import com.xuxd.kafka.console.beans.vo.ConfigEntryVO;
|
||||
import com.xuxd.kafka.console.service.ConfigService;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import kafka.console.ConfigConsole;
|
||||
import org.apache.kafka.clients.admin.ConfigEntry;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -22,11 +24,14 @@ public class ConfigServiceImpl implements ConfigService {
|
||||
|
||||
@Override public ResponseData getTopicConfig(String topic) {
|
||||
List<ConfigEntry> configEntries = configConsole.getTopicConfig(topic);
|
||||
return ResponseData.create().success();
|
||||
List<ConfigEntryVO> vos = configEntries.stream().map(ConfigEntryVO::from).sorted().collect(Collectors.toList());
|
||||
return ResponseData.create().data(vos).success();
|
||||
}
|
||||
|
||||
@Override public ResponseData getBrokerConfig() {
|
||||
List<ConfigEntry> configEntries = configConsole.getBrokerConfig();
|
||||
return ResponseData.create().success();
|
||||
@Override public ResponseData getBrokerConfig(String brokerId) {
|
||||
List<ConfigEntry> configEntries = configConsole.getBrokerConfig(brokerId);
|
||||
List<ConfigEntryVO> vos = configEntries.stream().map(ConfigEntryVO::from).sorted().collect(Collectors.toList());
|
||||
return ResponseData.create().data(vos).success();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user