Skip to content

Commit f6becbd

Browse files
authored
[Optimize]Connect 提交任务变更为只保存用户修改的配置,并修复JSON模式下配置展示不全(#1047) (#1158)
请不要在没有先创建Issue的情况下创建Pull Request。 ## 变更的目的是什么 优化Content新增/编辑 ## 简短的更新日志 - [Bugfix] 自定义的高级配置项,在JSON模式下未显示这些配置(#1045) - [Optimize] 提交任务后只保存用户修改的配置,而不是将所有配置都保存起来,目前不论用户有没有修改配置都保存了所有的配置(#1047) ## 验证这一变化 XXXX 请遵循此清单,以帮助我们快速轻松地整合您的贡献: * [ ] 一个 PR(Pull Request的简写)只解决一个问题,禁止一个 PR 解决多个问题; * [ ] 确保 PR 有对应的 Issue(通常在您开始处理之前创建),除非是书写错误之类的琐碎更改不需要 Issue ; * [ ] 格式化 PR 及 Commit-Log 的标题及内容,例如 #861 。PS:Commit-Log 需要在 Git Commit 代码时进行填写,在 GitHub 上修改不了; * [ ] 编写足够详细的 PR 描述,以了解 PR 的作用、方式和原因; * [ ] 编写必要的单元测试来验证您的逻辑更正。如果提交了新功能或重大更改,请记住在 test 模块中添加 integration-test; * [ ] 确保编译通过,集成测试通过;
1 parent 07bd00d commit f6becbd

File tree

9 files changed

+82
-109
lines changed

9 files changed

+82
-109
lines changed

km-biz/src/main/java/com/xiaojukeji/know/streaming/km/biz/cluster/ClusterBrokersManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.xiaojukeji.know.streaming.km.common.bean.dto.cluster.ClusterBrokersOverviewDTO;
44
import com.xiaojukeji.know.streaming.km.common.bean.entity.result.PaginationResult;
5-
import com.xiaojukeji.know.streaming.km.common.bean.entity.result.Result;
65
import com.xiaojukeji.know.streaming.km.common.bean.vo.cluster.res.ClusterBrokersOverviewVO;
76
import com.xiaojukeji.know.streaming.km.common.bean.vo.cluster.res.ClusterBrokersStateVO;
87

@@ -23,5 +22,5 @@ public interface ClusterBrokersManager {
2322
* @param clusterPhyId 物理集群 id
2423
* @return 返回根据物理集群id获取到的集群对应broker状态信息
2524
*/
26-
Result<ClusterBrokersStateVO> getClusterPhyBrokersState(Long clusterPhyId);
25+
ClusterBrokersStateVO getClusterPhyBrokersState(Long clusterPhyId);
2726
}

km-biz/src/main/java/com/xiaojukeji/know/streaming/km/biz/cluster/impl/ClusterBrokersManagerImpl.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
import com.xiaojukeji.know.streaming.km.common.bean.entity.metrics.BrokerMetrics;
1313
import com.xiaojukeji.know.streaming.km.common.bean.entity.result.PaginationResult;
1414
import com.xiaojukeji.know.streaming.km.common.bean.entity.result.Result;
15-
import com.xiaojukeji.know.streaming.km.common.bean.entity.result.ResultStatus;
1615
import com.xiaojukeji.know.streaming.km.common.bean.entity.topic.Topic;
1716
import com.xiaojukeji.know.streaming.km.common.bean.vo.cluster.res.ClusterBrokersOverviewVO;
1817
import com.xiaojukeji.know.streaming.km.common.bean.vo.cluster.res.ClusterBrokersStateVO;
1918
import com.xiaojukeji.know.streaming.km.common.bean.vo.kafkacontroller.KafkaControllerVO;
2019
import com.xiaojukeji.know.streaming.km.common.constant.KafkaConstant;
21-
import com.xiaojukeji.know.streaming.km.common.constant.MsgConstant;
2220
import com.xiaojukeji.know.streaming.km.common.enums.SortTypeEnum;
2321
import com.xiaojukeji.know.streaming.km.common.enums.cluster.ClusterRunStateEnum;
2422
import com.xiaojukeji.know.streaming.km.common.utils.ConvertUtil;
@@ -28,7 +26,6 @@
2826
import com.xiaojukeji.know.streaming.km.core.service.broker.BrokerConfigService;
2927
import com.xiaojukeji.know.streaming.km.core.service.broker.BrokerMetricService;
3028
import com.xiaojukeji.know.streaming.km.core.service.broker.BrokerService;
31-
import com.xiaojukeji.know.streaming.km.core.service.cluster.ClusterPhyService;
3229
import com.xiaojukeji.know.streaming.km.core.service.kafkacontroller.KafkaControllerService;
3330
import com.xiaojukeji.know.streaming.km.core.service.topic.TopicService;
3431
import com.xiaojukeji.know.streaming.km.persistence.cache.LoadedClusterPhyCache;
@@ -63,9 +60,6 @@ public class ClusterBrokersManagerImpl implements ClusterBrokersManager {
6360
@Autowired
6461
private KafkaJMXClient kafkaJMXClient;
6562

66-
@Autowired
67-
private ClusterPhyService clusterPhyService;
68-
6963
@Override
7064
public PaginationResult<ClusterBrokersOverviewVO> getClusterPhyBrokersOverview(Long clusterPhyId, ClusterBrokersOverviewDTO dto) {
7165
// 获取集群Broker列表
@@ -114,12 +108,7 @@ public PaginationResult<ClusterBrokersOverviewVO> getClusterPhyBrokersOverview(L
114108
}
115109

116110
@Override
117-
public Result<ClusterBrokersStateVO> getClusterPhyBrokersState(Long clusterPhyId) {
118-
ClusterPhy clusterPhy = clusterPhyService.getClusterByCluster(clusterPhyId);
119-
if (clusterPhy == null) {
120-
return Result.buildFromRSAndMsg(ResultStatus.NOT_EXIST, MsgConstant.getClusterPhyNotExist(clusterPhyId));
121-
}
122-
111+
public ClusterBrokersStateVO getClusterPhyBrokersState(Long clusterPhyId) {
123112
ClusterBrokersStateVO clusterBrokersStateVO = new ClusterBrokersStateVO();
124113

125114
// 获取集群Broker列表
@@ -137,25 +126,24 @@ public Result<ClusterBrokersStateVO> getClusterPhyBrokersState(Long clusterPhyId
137126
);
138127

139128
// 获取controller信息
140-
Result<KafkaController> controllerResult = kafkaControllerService.getControllerFromKafka(clusterPhy);
129+
KafkaController kafkaController = kafkaControllerService.getKafkaControllerFromDB(clusterPhyId);
141130

142131
// 设置kafka-controller信息
143132
clusterBrokersStateVO.setKafkaControllerAlive(false);
144-
if(null != controllerResult.getData()) {
133+
if(null != kafkaController) {
145134
clusterBrokersStateVO.setKafkaController(
146135
this.convert2KafkaControllerVO(
147-
controllerResult.getData(),
148-
brokerService.getBroker(clusterPhyId, controllerResult.getData().getBrokerId())
136+
kafkaController,
137+
brokerService.getBroker(clusterPhyId, kafkaController.getBrokerId())
149138
)
150139
);
151140
clusterBrokersStateVO.setKafkaControllerAlive(true);
152141
}
153142

154-
clusterBrokersStateVO.setConfigSimilar(
155-
brokerConfigService.countBrokerConfigDiffsFromDB(clusterPhyId, KafkaConstant.CONFIG_SIMILAR_IGNORED_CONFIG_KEY_LIST) <= 0
143+
clusterBrokersStateVO.setConfigSimilar(brokerConfigService.countBrokerConfigDiffsFromDB(clusterPhyId, KafkaConstant.CONFIG_SIMILAR_IGNORED_CONFIG_KEY_LIST) <= 0
156144
);
157145

158-
return Result.buildSuc(clusterBrokersStateVO);
146+
return clusterBrokersStateVO;
159147
}
160148

161149
/**************************************************** private method ****************************************************/

km-console/packages/config-manager-fe/config/webpack.common.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ const babelOptions = {
1616
cacheDirectory: true,
1717
babelrc: false,
1818
presets: [require.resolve('@babel/preset-env'), require.resolve('@babel/preset-typescript'), require.resolve('@babel/preset-react')],
19-
overrides: [
20-
// TODO:编译时需要做的事情更多,应该只针对目标第三方库
21-
{
22-
include: './node_modules',
23-
sourceType: 'unambiguous'
24-
}
25-
],
2619
plugins: [
2720
[require.resolve('@babel/plugin-proposal-decorators'), { legacy: true }],
2821
[require.resolve('@babel/plugin-proposal-class-properties'), { loose: true }],

km-console/packages/layout-clusters-fe/src/pages/CommonConfig.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ export enum ClustersPermissionMap {
4545
CONNECTOR_DELETE = 'Connector-删除',
4646
CONNECTOR_RESTART = 'Connector-重启',
4747
CONNECTOR_STOP_RESUME = 'Connector-暂停&恢复',
48-
// Security
49-
SECURITY_ACL_ADD = 'Security-ACL新增',
50-
SECURITY_ACL_DELETE = 'Security-ACL删除',
51-
SECURITY_USER_ADD = 'Security-User新增',
52-
SECURITY_USER_DELETE = 'Security-User删除',
53-
SECURITY_USER_EDIT_PASSWORD = 'Security-User修改密码',
5448
}
5549

5650
export interface PermissionNode {

km-console/packages/layout-clusters-fe/src/pages/Connect/AddConnector.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,14 @@ const StepFormFirst = (props: SubFormProps) => {
189189
const result: FormConnectorConfigs = {
190190
pluginConfig: {},
191191
};
192+
193+
// 获取一份默认配置
194+
const defaultPluginConfig: any = {};
195+
192196
pluginConfig.configs.forEach(({ definition }) => {
197+
// 获取一份默认配置
198+
defaultPluginConfig[definition.name] = definition?.defaultValue;
199+
193200
if (!getExistFormItems(pluginType).includes(definition.name)) {
194201
const pluginConfigs = result.pluginConfig;
195202
const group = definition.group || 'Others';
@@ -205,7 +212,7 @@ const StepFormFirst = (props: SubFormProps) => {
205212

206213
Object.keys(result).length &&
207214
form.setFieldsValue({
208-
configs: result,
215+
configs: { ...result, defaultPluginConfig, editConnectorConfig: result.connectorConfig },
209216
});
210217
})
211218
.finally(() => props.setSubmitLoading(false));
@@ -957,6 +964,7 @@ export default forwardRef(
957964
}) => void
958965
) => {
959966
const promises: Promise<any>[] = [];
967+
const compareConfig = stepsFormRef.current[0].getFieldValue('configs'); // 获取步骤一的form信息
960968
Object.values(stepsFormRef.current).forEach((form, i) => {
961969
const promise = form
962970
.validateFields()
@@ -987,11 +995,22 @@ export default forwardRef(
987995
const [k, ...v] = l.split('=');
988996
result[k] = v.join('=');
989997
});
998+
999+
const editConnectorConfig = operateInfo.type === 'edit' ? compareConfig.editConnectorConfig : {}; // 编辑状态时拿到config配置
1000+
const newCompareConfig = { ...compareConfig.defaultPluginConfig, ...editConnectorConfig, ...result }; // 整合后的表单提交信息
1001+
Object.keys(newCompareConfig).forEach((item) => {
1002+
if (
1003+
newCompareConfig[item] === compareConfig.defaultPluginConfig[item] ||
1004+
newCompareConfig[item]?.toString() === compareConfig.defaultPluginConfig[item]?.toString()
1005+
) {
1006+
delete newCompareConfig[item]; // 清除默认值
1007+
}
1008+
});
9901009
callback({
9911010
success: {
9921011
connectClusterId: res[0].connectClusterId,
9931012
connectorName: result['name'],
994-
config: result,
1013+
config: newCompareConfig,
9951014
},
9961015
});
9971016
},

km-console/packages/layout-clusters-fe/src/pages/Connect/AddConnectorUseJSON.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const PLACEHOLDER = `配置格式如下
1010
1111
{
1212
"connectClusterName": "", // Connect Cluster 名称
13-
"config": { // 具体配置项
13+
"configs": { // 具体配置项
1414
"name": "",
1515
"connector.class": "",
1616
"tasks.max": 1,
@@ -47,7 +47,7 @@ export default forwardRef((props: any, ref) => {
4747
configs: JSON.stringify(
4848
{
4949
connectClusterName,
50-
config: defaultConfigs,
50+
configs: defaultConfigs,
5151
},
5252
null,
5353
2
@@ -63,13 +63,13 @@ export default forwardRef((props: any, ref) => {
6363
form.validateFields().then(
6464
(data) => {
6565
const postData = JSON.parse(data.configs);
66-
postData.connectorName = postData.config.name;
66+
postData.connectorName = postData.configs.name;
6767
postData.connectClusterId = connectClusters.find((cluster) => cluster.label === postData.connectClusterName).value;
6868
delete postData.connectClusterName;
6969

70-
Object.entries(postData.config).forEach(([key, val]) => {
70+
Object.entries(postData.configs).forEach(([key, val]) => {
7171
if (val === null) {
72-
delete postData.config[key];
72+
delete postData.configs[key];
7373
}
7474
});
7575
Utils.put(api.validateConnectorConfig, postData).then(
@@ -198,34 +198,34 @@ export default forwardRef((props: any, ref) => {
198198
}
199199
}
200200

201-
if (!v.config || typeof v.config !== 'object') {
202-
return Promise.reject('内容缺少 config 字段或字段格式错误');
201+
if (!v.configs || typeof v.configs !== 'object') {
202+
return Promise.reject('内容缺少 configs 字段或字段格式错误');
203203
} else {
204204
// 校验 connectorName 字段
205-
if (!v.config.name) {
206-
return Promise.reject('config 字段下缺少 name 项');
205+
if (!v.configs.name) {
206+
return Promise.reject('configs 字段下缺少 name 项');
207207
} else {
208-
if (type === 'edit' && v.config.name !== defaultConfigs.name) {
208+
if (type === 'edit' && v.configs.name !== defaultConfigs.name) {
209209
return Promise.reject('编辑模式下不允许修改 name 字段');
210210
}
211211
}
212-
if (!v.config['connector.class']) {
213-
return Promise.reject('config 字段下缺少 connector.class 项');
214-
} else if (type === 'edit' && v.config['connector.class'] !== defaultConfigs['connector.class']) {
212+
if (!v.configs['connector.class']) {
213+
return Promise.reject('configs 字段下缺少 connector.class 项');
214+
} else if (type === 'edit' && v.configs['connector.class'] !== defaultConfigs['connector.class']) {
215215
return Promise.reject('编辑模式下不允许修改 connector.class 字段');
216216
}
217217
}
218218

219219
if (type === 'create') {
220220
// 异步校验 connector 名称是否重复 以及 className 是否存在
221221
return Promise.all([
222-
Utils.request(api.isConnectorExist(connectClusterId, v.config.name)),
222+
Utils.request(api.isConnectorExist(connectClusterId, v.configs.name)),
223223
Utils.request(api.getConnectorPlugins(connectClusterId)),
224224
]).then(
225225
([data, plugins]: [any, ConnectorPlugin[]]) => {
226226
return data?.exist
227227
? Promise.reject('name 与已有 Connector 重复')
228-
: plugins.every((plugin) => plugin.className !== v.config['connector.class'])
228+
: plugins.every((plugin) => plugin.className !== v.configs['connector.class'])
229229
? Promise.reject('该 connectCluster 下不存在 connector.class 项配置的插件')
230230
: Promise.resolve();
231231
},

km-console/packages/layout-clusters-fe/src/pages/SecurityACLs/index.tsx

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import AddACLDrawer, {
1414
RESOURCE_TO_OPERATIONS_MAP,
1515
RESOURCE_MAP_KEYS,
1616
} from './EditDrawer';
17-
import { ClustersPermissionMap } from '../CommonConfig';
1817
import './index.less';
1918

2019
const { confirm } = Modal;
@@ -106,7 +105,7 @@ const SecurityACLs = (): JSX.Element => {
106105
};
107106

108107
const columns = () => {
109-
const baseColumns: any = [
108+
const baseColumns = [
110109
{
111110
title: 'Principal',
112111
dataIndex: 'kafkaUser',
@@ -144,9 +143,7 @@ const SecurityACLs = (): JSX.Element => {
144143
title: 'Host',
145144
dataIndex: 'aclClientHost',
146145
},
147-
];
148-
if (global.hasPermission && global.hasPermission(ClustersPermissionMap.SECURITY_ACL_DELETE)) {
149-
baseColumns.push({
146+
{
150147
title: '操作',
151148
dataIndex: '',
152149
width: 120,
@@ -159,8 +156,8 @@ const SecurityACLs = (): JSX.Element => {
159156
</>
160157
);
161158
},
162-
});
163-
}
159+
},
160+
];
164161

165162
return baseColumns;
166163
};
@@ -241,19 +238,15 @@ const SecurityACLs = (): JSX.Element => {
241238
</Form.Item>
242239
</Form>
243240
</div>
244-
{global.hasPermission && global.hasPermission(ClustersPermissionMap.SECURITY_ACL_ADD) ? (
245-
<div className={`${tableHeaderPrefix}-right`}>
246-
<Button
247-
type="primary"
248-
// icon={<PlusOutlined />}
249-
onClick={() => editDrawerRef.current.onOpen(true, getACLs)}
250-
>
251-
新增ACL
252-
</Button>
253-
</div>
254-
) : (
255-
<></>
256-
)}
241+
<div className={`${tableHeaderPrefix}-right`}>
242+
<Button
243+
type="primary"
244+
// icon={<PlusOutlined />}
245+
onClick={() => editDrawerRef.current.onOpen(true, getACLs)}
246+
>
247+
新增ACL
248+
</Button>
249+
</div>
257250
</div>
258251
<ProTable
259252
tableProps={{

0 commit comments

Comments
 (0)