This is an automated email from the ASF dual-hosted git repository.
leonbao pushed a commit to branch 1.3.0-release
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git
The following commit(s) were added to refs/heads/1.3.0-release by this push:
new 1200c7d fix #2860:copy files and create empty directory (#2876)
1200c7d is described below
commit 1200c7d1d6f60dfca7438cda25208ecef3a1ff23
Author: lgcareer <[email protected]>
AuthorDate: Tue Jun 2 18:33:06 2020 +0800
fix #2860:copy files and create empty directory (#2876)
* copy resources need get top directory first
* copy resources need get top directory first
* fix #2860:copy files and create empty directory
---
.../dolphinscheduler/api/service/UsersService.java | 46 +++++++++++++++++++---
1 file changed, 40 insertions(+), 6 deletions(-)
diff --git
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java
index b76ca83..815dcb0 100644
---
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java
+++
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java
@@ -21,6 +21,7 @@ import
com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.dolphinscheduler.api.dto.resources.ResourceComponent;
import
org.apache.dolphinscheduler.api.dto.resources.visitor.ResourceTreeVisitor;
import org.apache.dolphinscheduler.api.enums.Status;
+import org.apache.dolphinscheduler.api.exceptions.ServiceException;
import org.apache.dolphinscheduler.api.utils.CheckUtils;
import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.api.utils.Result;
@@ -37,6 +38,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
@@ -338,9 +340,7 @@ public class UsersService extends BaseService {
if (CollectionUtils.isNotEmpty(fileResourcesList)) {
ResourceTreeVisitor resourceTreeVisitor = new
ResourceTreeVisitor(fileResourcesList);
ResourceComponent resourceComponent =
resourceTreeVisitor.visit();
- for (ResourceComponent resource :
resourceComponent.getChildren()) {
- HadoopUtils.getInstance().copy(oldResourcePath
+ "/" + resource.getName(), newResourcePath, false, true);
- }
+ copyResourceFiles(resourceComponent,
oldResourcePath, newResourcePath);
}
//udf resources
@@ -349,9 +349,7 @@ public class UsersService extends BaseService {
if (CollectionUtils.isNotEmpty(udfResourceList)) {
ResourceTreeVisitor resourceTreeVisitor = new
ResourceTreeVisitor(udfResourceList);
ResourceComponent resourceComponent =
resourceTreeVisitor.visit();
- for (ResourceComponent resource :
resourceComponent.getChildren()) {
- HadoopUtils.getInstance().copy(oldUdfsPath +
"/" + resource.getName(), newUdfsPath, false, true);
- }
+ copyResourceFiles(resourceComponent, oldUdfsPath,
newUdfsPath);
}
//Delete the user from the old tenant directory
@@ -871,4 +869,40 @@ public class UsersService extends BaseService {
return msg;
}
+
+ /**
+ * copy resource files
+ * @param resourceComponent resource component
+ * @param srcBasePath src base path
+ * @param dstBasePath dst base path
+ * @throws IOException io exception
+ */
+ private void copyResourceFiles(ResourceComponent resourceComponent, String
srcBasePath, String dstBasePath) throws IOException {
+ List<ResourceComponent> components = resourceComponent.getChildren();
+
+ if (CollectionUtils.isNotEmpty(components)) {
+ for (ResourceComponent component:components) {
+ // verify whether exist
+ if
(!HadoopUtils.getInstance().exists(String.format("%s/%s",srcBasePath,component.getFullName()))){
+ logger.error("resource file: {} not exist,copy
error",component.getFullName());
+ throw new ServiceException(Status.RESOURCE_NOT_EXIST);
+ }
+
+ if (!component.isDirctory()) {
+ // copy it to dst
+
HadoopUtils.getInstance().copy(String.format("%s/%s",srcBasePath,component.getFullName()),String.format("%s/%s",dstBasePath,component.getFullName()),false,true);
+ continue;
+ }
+
+ if(CollectionUtils.isEmpty(component.getChildren())) {
+ // if not exist,need create it
+ if
(!HadoopUtils.getInstance().exists(String.format("%s/%s",dstBasePath,component.getFullName())))
{
+
HadoopUtils.getInstance().mkdir(String.format("%s/%s",dstBasePath,component.getFullName()));
+ }
+ }else{
+ copyResourceFiles(component,srcBasePath,dstBasePath);
+ }
+ }
+ }
+ }
}