未验证 提交 733e8bcb 编写于 作者: L lgcareer 提交者: GitHub

support download the resources existed in process definition which was old version (#2506)

* fix #2442 and remove unavailable code

* revert verifyResourceName method

* Add ServiceException

* add ServiceExceptionTest

* update ServiceExceptionTest

* add ServiceExceptionTest in pom

* support download the resources existed in process definition which was old version
上级 64d335d9
...@@ -48,13 +48,13 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -48,13 +48,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.util.HashSet; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import static org.apache.dolphinscheduler.common.Constants.*; import static org.apache.dolphinscheduler.common.Constants.SLEEP_TIME_MILLIS;
/** /**
* TaskUpdateQueue consumer * TaskUpdateQueue consumer
...@@ -328,36 +328,38 @@ public class TaskPriorityQueueConsumer extends Thread{ ...@@ -328,36 +328,38 @@ public class TaskPriorityQueueConsumer extends Thread{
return false; return false;
} }
/** /**
* create project resource files * get resource full name list
*/ */
private List<String> getResourceFullNames(TaskNode taskNode){ private List<String> getResourceFullNames(TaskNode taskNode) {
List<String> resourceFullNameList = new ArrayList<>();
Set<Integer> resourceIdsSet = new HashSet<>();
AbstractParameters baseParam = TaskParametersUtils.getParameters(taskNode.getType(), taskNode.getParams()); AbstractParameters baseParam = TaskParametersUtils.getParameters(taskNode.getType(), taskNode.getParams());
if (baseParam != null) { if (baseParam != null) {
List<ResourceInfo> projectResourceFiles = baseParam.getResourceFilesList(); List<ResourceInfo> projectResourceFiles = baseParam.getResourceFilesList();
if (projectResourceFiles != null) { if (projectResourceFiles != null) {
Stream<Integer> resourceInfotream = projectResourceFiles.stream().map(resourceInfo -> resourceInfo.getId());
resourceIdsSet.addAll(resourceInfotream.collect(Collectors.toSet()));
} // filter the resources that the resource id equals 0
} Set<ResourceInfo> oldVersionResources = projectResourceFiles.stream().filter(t -> t.getId() == 0).collect(Collectors.toSet());
if (CollectionUtils.isNotEmpty(oldVersionResources)) {
resourceFullNameList.addAll(oldVersionResources.stream().map(resource -> resource.getRes()).collect(Collectors.toSet()));
}
if (CollectionUtils.isEmpty(resourceIdsSet)){ // get the resource id in order to get the resource names in batch
return null; Stream<Integer> resourceIdStream = projectResourceFiles.stream().map(resourceInfo -> resourceInfo.getId());
} Set<Integer> resourceIdsSet = resourceIdStream.collect(Collectors.toSet());
Integer[] resourceIds = resourceIdsSet.toArray(new Integer[resourceIdsSet.size()]);
List<Resource> resources = processService.listResourceByIds(resourceIds); if (CollectionUtils.isNotEmpty(resourceIdsSet)) {
Integer[] resourceIds = resourceIdsSet.toArray(new Integer[resourceIdsSet.size()]);
List<String> resourceFullNames = resources.stream() List<Resource> resources = processService.listResourceByIds(resourceIds);
.map(resourceInfo -> resourceInfo.getFullName()) resourceFullNameList.addAll(resources.stream()
.collect(Collectors.toList()); .map(resourceInfo -> resourceInfo.getFullName())
.collect(Collectors.toList()));
}
}
}
return resourceFullNames; return resourceFullNameList;
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册