未验证 提交 e3cf72cb 编写于 作者: K Kerwin 提交者: GitHub

[Fix-12832][API] Fix update worker group exception group name already exists. (#12874)

上级 250d81bc
......@@ -113,15 +113,11 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro
return result;
}
Date now = new Date();
WorkerGroup workerGroup;
WorkerGroup workerGroup = null;
if (id != 0) {
workerGroup = workerGroupMapper.selectById(id);
// check exist
if (workerGroup == null) {
workerGroup = new WorkerGroup();
workerGroup.setCreateTime(now);
}
} else {
}
if (workerGroup == null) {
workerGroup = new WorkerGroup();
workerGroup.setCreateTime(now);
}
......@@ -165,23 +161,21 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro
* @return boolean
*/
private boolean checkWorkerGroupNameExists(WorkerGroup workerGroup) {
// check database
List<WorkerGroup> workerGroupList = workerGroupMapper.queryWorkerGroupByName(workerGroup.getName());
if (CollectionUtils.isNotEmpty(workerGroupList)) {
// new group has same name
// create group, the same group name exists in the database
if (workerGroup.getId() == null) {
return true;
}
// check group id
for (WorkerGroup group : workerGroupList) {
if (Objects.equals(group.getId(), workerGroup.getId())) {
return true;
}
// update group, the database exists with the same group name except itself
Optional<WorkerGroup> sameNameWorkGroupOptional = workerGroupList.stream()
.filter(group -> !Objects.equals(group.getId(), workerGroup.getId())).findFirst();
if (sameNameWorkGroupOptional.isPresent()) {
return true;
}
}
// check zookeeper
String workerGroupPath =
Constants.REGISTRY_DOLPHINSCHEDULER_WORKERS + Constants.SINGLE_SLASH + workerGroup.getName();
return registryClient.exists(workerGroupPath);
return false;
}
/**
......
......@@ -153,9 +153,6 @@ public class WorkerGroupServiceTest {
baseServiceLogger)).thenReturn(true);
Mockito.when(workerGroupMapper.selectById(1)).thenReturn(null);
Mockito.when(workerGroupMapper.queryWorkerGroupByName(GROUP_NAME)).thenReturn(null);
String workerGroupPath =
Constants.REGISTRY_DOLPHINSCHEDULER_WORKERS + Constants.SINGLE_SLASH + GROUP_NAME;
Mockito.when(registryClient.exists(workerGroupPath)).thenReturn(false);
Map<String, String> serverMaps = new HashMap<>();
serverMaps.put("localhost1:0000", "");
Mockito.when(registryClient.getServerMaps(NodeType.WORKER)).thenReturn(serverMaps);
......@@ -176,9 +173,6 @@ public class WorkerGroupServiceTest {
Mockito.when(workerGroupMapper.selectById(1)).thenReturn(null);
Mockito.when(workerGroupMapper.queryWorkerGroupByName(GROUP_NAME)).thenReturn(null);
String workerGroupPath =
Constants.REGISTRY_DOLPHINSCHEDULER_WORKERS + Constants.SINGLE_SLASH + GROUP_NAME;
Mockito.when(registryClient.exists(workerGroupPath)).thenReturn(false);
Map<String, String> serverMaps = new HashMap<>();
serverMaps.put("localhost:0000", "");
Mockito.when(registryClient.getServerMaps(NodeType.WORKER)).thenReturn(serverMaps);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册