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/30 11:48:53 UTC

[GitHub] [dolphinscheduler] caishunfeng commented on a diff in pull request #13023: delete taskDefinitionServiceImpl useless code

caishunfeng commented on code in PR #13023:
URL: https://github.com/apache/dolphinscheduler/pull/13023#discussion_r1035872014


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java:
##########
@@ -812,78 +811,89 @@ public Map<String, Object> updateTaskWithUpstream(User loginUser, long projectCo
         if (result.get(Constants.STATUS) != Status.SUCCESS && taskDefinitionToUpdate == null) {
             return result;
         }
+        // get sourceUpstreamTaskCodeSet
         List<ProcessTaskRelation> upstreamTaskRelations =
                 processTaskRelationMapper.queryUpstreamByCode(projectCode, taskCode);
-        Set<Long> upstreamCodeSet =
+        Set<Long> sourceUpstreamCodeSet =
                 upstreamTaskRelations.stream().map(ProcessTaskRelation::getPreTaskCode).collect(Collectors.toSet());
-        Set<Long> upstreamTaskCodes = Collections.emptySet();
-        if (StringUtils.isNotEmpty(upstreamCodes)) {
-            upstreamTaskCodes = Arrays.stream(upstreamCodes.split(Constants.COMMA)).map(Long::parseLong)
-                    .collect(Collectors.toSet());
-        }
-        if (CollectionUtils.isEqualCollection(upstreamCodeSet, upstreamTaskCodes) && taskDefinitionToUpdate == null) {
+        // get updateUpstreamTaskCodeSet
+        Set<Long> updateUpstreamTaskCodeSet = getTaskCodeSet(upstreamCodes, result);
+
+        if (CollectionUtils.isEqualCollection(sourceUpstreamCodeSet, updateUpstreamTaskCodeSet)
+                && taskDefinitionToUpdate == null) {
             putMsg(result, Status.SUCCESS);
             return result;
-        } else {
-            if (taskDefinitionToUpdate == null) {
-                taskDefinitionToUpdate = JSONUtils.parseObject(taskDefinitionJsonObj, TaskDefinitionLog.class);
-            }
+        } else if (taskDefinitionToUpdate == null) {
+            taskDefinitionToUpdate = JSONUtils.parseObject(taskDefinitionJsonObj, TaskDefinitionLog.class);
         }
-        Map<Long, TaskDefinition> queryUpStreamTaskCodeMap;
-        if (CollectionUtils.isNotEmpty(upstreamTaskCodes)) {
-            List<TaskDefinition> upstreamTaskDefinitionList = taskDefinitionMapper.queryByCodeList(upstreamTaskCodes);
-            queryUpStreamTaskCodeMap = upstreamTaskDefinitionList.stream()
-                    .collect(Collectors.toMap(TaskDefinition::getCode, taskDefinition -> taskDefinition));
-            // upstreamTaskCodes - queryUpStreamTaskCodeMap.keySet
-            upstreamTaskCodes.removeAll(queryUpStreamTaskCodeMap.keySet());
-            if (CollectionUtils.isNotEmpty(upstreamTaskCodes)) {
-                String notExistTaskCodes = StringUtils.join(upstreamTaskCodes, Constants.COMMA);
-                logger.error("Some task definitions in parameter upstreamTaskCodes do not exist, notExistTaskCodes:{}.",
-                        notExistTaskCodes);
-                putMsg(result, Status.TASK_DEFINE_NOT_EXIST, notExistTaskCodes);
-                return result;
-            }
-        } else {
-            queryUpStreamTaskCodeMap = new HashMap<>();
+        // get survive updateUpstreamTask
+        getUpdateUpstreamTaskCodeMap(updateUpstreamTaskCodeSet, result);
+        if (result.get(Constants.STATUS) != Status.SUCCESS) {
+            return result;
         }
-        if (CollectionUtils.isNotEmpty(upstreamTaskCodes)) {
+        // update log
+        if (CollectionUtils.isNotEmpty(updateUpstreamTaskCodeSet)) {
             ProcessTaskRelation taskRelation = upstreamTaskRelations.get(0);
             List<ProcessTaskRelation> processTaskRelations =
                     processTaskRelationMapper.queryByProcessCode(projectCode, taskRelation.getProcessDefinitionCode());
-            List<ProcessTaskRelation> processTaskRelationList = Lists.newArrayList(processTaskRelations);

Review Comment:
   It seems the `processTaskRelationList` never use.
   PTAL @ruanwenjun 



-- 
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