Browse Source

[Improvement] File deletion logic optimization (#11519)

* [Improvement] File deletion logic optimization
3.1.0-release
insist777 2 years ago committed by GitHub
parent
commit
006d8e21a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java
  2. 10
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java

1
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java

@ -239,6 +239,7 @@ public enum Status {
PARENT_RESOURCE_NOT_EXIST(20015, "parent resource not exist", "父资源文件不存在"), PARENT_RESOURCE_NOT_EXIST(20015, "parent resource not exist", "父资源文件不存在"),
RESOURCE_NOT_EXIST_OR_NO_PERMISSION(20016, "resource not exist or no permission,please view the task node and remove error resource", "请检查任务节点并移除无权限或者已删除的资源"), RESOURCE_NOT_EXIST_OR_NO_PERMISSION(20016, "resource not exist or no permission,please view the task node and remove error resource", "请检查任务节点并移除无权限或者已删除的资源"),
RESOURCE_IS_AUTHORIZED(20017, "resource is authorized to user {0},suffix not allowed to be modified", "资源文件已授权其他用户[{0}],后缀不允许修改"), RESOURCE_IS_AUTHORIZED(20017, "resource is authorized to user {0},suffix not allowed to be modified", "资源文件已授权其他用户[{0}],后缀不允许修改"),
RESOURCE_HAS_FOLDER(20018, "There are files or folders in the current directory:{0}", "当前目录下有文件或文件夹[{0}]"),
USER_NO_OPERATION_PERM(30001, "user has no operation privilege", "当前用户没有操作权限"), USER_NO_OPERATION_PERM(30001, "user has no operation privilege", "当前用户没有操作权限"),
USER_NO_OPERATION_PROJECT_PERM(30002, "user {0} is not has project {1} permission", "当前用户[{0}]没有[{1}]项目的操作权限"), USER_NO_OPERATION_PROJECT_PERM(30002, "user {0} is not has project {1} permission", "当前用户[{0}]没有[{1}]项目的操作权限"),

10
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java

@ -828,8 +828,16 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe
Set<Integer> resourceIdSet = resourceProcessMap.keySet(); Set<Integer> resourceIdSet = resourceProcessMap.keySet();
// get all children of the resource // get all children of the resource
List<Integer> allChildren = listAllChildren(resource, true); List<Integer> allChildren = listAllChildren(resource, true);
Integer[] needDeleteResourceIdArray = allChildren.toArray(new Integer[allChildren.size()]); Integer[] needDeleteResourceIdArray = allChildren.toArray(new Integer[allChildren.size()]);
if (needDeleteResourceIdArray.length >= 2){
logger.error("can't be deleted,because There are files or folders in the current directory:{}", resource);
putMsg(result, Status.RESOURCE_HAS_FOLDER, resource.getFileName());
return result;
}
//if resource type is UDF,need check whether it is bound by UDF function //if resource type is UDF,need check whether it is bound by UDF function
if (resource.getType() == (ResourceType.UDF)) { if (resource.getType() == (ResourceType.UDF)) {
List<UdfFunc> udfFuncs = udfFunctionMapper.listUdfByResourceId(needDeleteResourceIdArray); List<UdfFunc> udfFuncs = udfFunctionMapper.listUdfByResourceId(needDeleteResourceIdArray);
@ -840,6 +848,8 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe
} }
} }
if (resourceIdSet.contains(resource.getPid())) { if (resourceIdSet.contains(resource.getPid())) {
logger.error("can't be deleted,because it is used of process definition"); logger.error("can't be deleted,because it is used of process definition");
putMsg(result, Status.RESOURCE_IS_USED); putMsg(result, Status.RESOURCE_IS_USED);

Loading…
Cancel
Save