You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/11/13 03:24:14 UTC

[GitHub] [dolphinscheduler] ruanwenjun commented on a diff in pull request #12874: [Fix-12832][API] Fix update worker group exception group name already exists.

ruanwenjun commented on code in PR #12874:
URL: https://github.com/apache/dolphinscheduler/pull/12874#discussion_r1020834741


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java:
##########
@@ -165,20 +161,21 @@ protected void handleDefaultWorkGroup(WorkerGroupMapper workerGroupMapper, Worke
      * @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
+        // check registry server

Review Comment:
   We don't need to check the worker group exist in registry, we have removed the worker group in registry path.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org