broker config

This commit is contained in:
许晓东
2021-11-04 16:50:20 +08:00
parent 2c2558d157
commit 2f2ee7f901
11 changed files with 345 additions and 37 deletions

View File

@@ -0,0 +1,24 @@
package com.xuxd.kafka.console.beans.dto;
import lombok.Data;
import org.apache.kafka.clients.admin.ConfigEntry;
/**
* kafka-console-ui.
*
* @author xuxd
* @date 2021-11-04 15:39:07
**/
@Data
public class AlterConfigDTO {
private String entity;
private String name;
private String value;
public ConfigEntry to() {
return new ConfigEntry(name, value);
}
}

View File

@@ -0,0 +1,11 @@
package com.xuxd.kafka.console.beans.enums;
/**
* kafka-console-ui.
*
* @author xuxd
* @date 2021-11-04 15:36:09
**/
public enum AlterType {
SET,DELETE
}

View File

@@ -50,13 +50,14 @@ public class ConfigEntryVO implements Comparable {
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;
}
if (!this.source.equals(that.source)) {
return ORDER_DICTIONARY.get(this.source) - ORDER_DICTIONARY.get(that.source);
}
return this.name.compareTo(that.name);
}
}

View File

@@ -1,11 +1,16 @@
package com.xuxd.kafka.console.controller;
import com.xuxd.kafka.console.beans.ResponseData;
import com.xuxd.kafka.console.beans.dto.AlterConfigDTO;
import com.xuxd.kafka.console.beans.enums.AlterType;
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.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -45,4 +50,14 @@ public class ConfigController {
public Object getBrokerConfig(String brokerId) {
return configService.getBrokerConfig(brokerId);
}
@PostMapping("/broker")
public Object setBrokerConfig(@RequestBody AlterConfigDTO dto) {
return configService.alterBrokerConfig(dto.getEntity(), dto.to(), AlterType.SET);
}
@DeleteMapping("/broker")
public Object deleteBrokerConfig(@RequestBody AlterConfigDTO dto) {
return configService.alterBrokerConfig(dto.getEntity(), dto.to(), AlterType.DELETE);
}
}

View File

@@ -1,6 +1,8 @@
package com.xuxd.kafka.console.service;
import com.xuxd.kafka.console.beans.ResponseData;
import com.xuxd.kafka.console.beans.enums.AlterType;
import org.apache.kafka.clients.admin.ConfigEntry;
/**
* kafka-console-ui.
@@ -13,4 +15,6 @@ public interface ConfigService {
ResponseData getTopicConfig(String topic);
ResponseData getBrokerConfig(String brokerId);
ResponseData alterBrokerConfig(String brokerId, ConfigEntry entry, AlterType type);
}

View File

@@ -1,6 +1,7 @@
package com.xuxd.kafka.console.service.impl;
import com.xuxd.kafka.console.beans.ResponseData;
import com.xuxd.kafka.console.beans.enums.AlterType;
import com.xuxd.kafka.console.beans.vo.ConfigEntryVO;
import com.xuxd.kafka.console.service.ConfigService;
import java.util.List;
@@ -9,6 +10,7 @@ import kafka.console.ConfigConsole;
import org.apache.kafka.clients.admin.ConfigEntry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import scala.Tuple2;
/**
* kafka-console-ui.
@@ -34,4 +36,17 @@ public class ConfigServiceImpl implements ConfigService {
return ResponseData.create().data(vos).success();
}
@Override public ResponseData alterBrokerConfig(String brokerId, ConfigEntry entry, AlterType type) {
Tuple2<Object, String> tuple2 = null;
switch (type) {
case SET:
tuple2 = configConsole.setBrokerConfig(brokerId, entry);
break;
case DELETE:
tuple2 = configConsole.deleteBrokerConfig(brokerId, entry);
break;
}
return (boolean) tuple2._1() ? ResponseData.create().success() : ResponseData.create().failed(tuple2._2());
}
}