|
|
@ -17,13 +17,10 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.api.service.impl; |
|
|
|
package org.apache.dolphinscheduler.api.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import static org.apache.dolphinscheduler.common.Constants.ALIAS; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import static org.apache.dolphinscheduler.common.Constants.CONTENT; |
|
|
|
import com.fasterxml.jackson.databind.SerializationFeature; |
|
|
|
import static org.apache.dolphinscheduler.common.Constants.JAR; |
|
|
|
import com.google.common.io.Files; |
|
|
|
|
|
|
|
import org.apache.commons.beanutils.BeanMap; |
|
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.dto.resources.ResourceComponent; |
|
|
|
import org.apache.dolphinscheduler.api.dto.resources.ResourceComponent; |
|
|
|
import org.apache.dolphinscheduler.api.dto.resources.filter.ResourceFilter; |
|
|
|
import org.apache.dolphinscheduler.api.dto.resources.filter.ResourceFilter; |
|
|
|
import org.apache.dolphinscheduler.api.dto.resources.visitor.ResourceTreeVisitor; |
|
|
|
import org.apache.dolphinscheduler.api.dto.resources.visitor.ResourceTreeVisitor; |
|
|
@ -40,10 +37,38 @@ import org.apache.dolphinscheduler.common.utils.FileUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.HadoopUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.HadoopUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.PropertyUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.PropertyUtils; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.*; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.Resource; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.*; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ResourcesUser; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.Tenant; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.UdfFunc; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.User; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ResourceMapper; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ResourceUserMapper; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.TenantMapper; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.UdfFuncMapper; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.UserMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.utils.ResourceProcessDefinitionUtils; |
|
|
|
import org.apache.dolphinscheduler.dao.utils.ResourceProcessDefinitionUtils; |
|
|
|
import org.apache.dolphinscheduler.spi.enums.ResourceType; |
|
|
|
import org.apache.dolphinscheduler.spi.enums.ResourceType; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.beanutils.BeanMap; |
|
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.text.MessageFormat; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
import java.util.regex.Matcher; |
|
|
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@ -52,13 +77,11 @@ import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import java.text.MessageFormat; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import java.util.*; |
|
|
|
import com.fasterxml.jackson.databind.SerializationFeature; |
|
|
|
import java.util.regex.Matcher; |
|
|
|
import com.google.common.base.Joiner; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import com.google.common.io.Files; |
|
|
|
|
|
|
|
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.*; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* resources service impl |
|
|
|
* resources service impl |
|
|
@ -198,6 +221,7 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
resourcesMapper.insert(resource); |
|
|
|
resourcesMapper.insert(resource); |
|
|
|
|
|
|
|
updateParentResourceSize(resource, resource.getSize()); |
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
Map<Object, Object> dataMap = new BeanMap(resource); |
|
|
|
Map<Object, Object> dataMap = new BeanMap(resource); |
|
|
|
Map<String, Object> resultMap = new HashMap<>(); |
|
|
|
Map<String, Object> resultMap = new HashMap<>(); |
|
|
@ -221,6 +245,33 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* update the folder's size of the resource |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param resource the current resource |
|
|
|
|
|
|
|
* @param size size |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void updateParentResourceSize(Resource resource, long size) { |
|
|
|
|
|
|
|
if (resource.getSize() > 0) { |
|
|
|
|
|
|
|
String[] splits = resource.getFullName().split("/"); |
|
|
|
|
|
|
|
for (int i = 1; i < splits.length; i++) { |
|
|
|
|
|
|
|
String parentFullName = Joiner.on("/").join(Arrays.copyOfRange(splits, 0, i)); |
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(parentFullName)) { |
|
|
|
|
|
|
|
List<Resource> resources = resourcesMapper.queryResource(parentFullName, resource.getType().ordinal()); |
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(resources)) { |
|
|
|
|
|
|
|
Resource parentResource = resources.get(0); |
|
|
|
|
|
|
|
if (parentResource.getSize() + size >= 0) { |
|
|
|
|
|
|
|
parentResource.setSize(parentResource.getSize() + size); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
parentResource.setSize(0L); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
resourcesMapper.updateById(parentResource); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* check resource is exists |
|
|
|
* check resource is exists |
|
|
|
* |
|
|
|
* |
|
|
@ -338,6 +389,7 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe |
|
|
|
|
|
|
|
|
|
|
|
// updateResource data
|
|
|
|
// updateResource data
|
|
|
|
Date now = new Date(); |
|
|
|
Date now = new Date(); |
|
|
|
|
|
|
|
long originFileSize = resource.getSize(); |
|
|
|
|
|
|
|
|
|
|
|
resource.setAlias(name); |
|
|
|
resource.setAlias(name); |
|
|
|
resource.setFileName(name); |
|
|
|
resource.setFileName(name); |
|
|
@ -423,6 +475,8 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe |
|
|
|
throw new ServiceException(String.format("delete resource: %s failed.", originFullName)); |
|
|
|
throw new ServiceException(String.format("delete resource: %s failed.", originFullName)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateParentResourceSize(resource, resource.getSize() - originFileSize); |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -705,11 +759,15 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe |
|
|
|
String hdfsFilename = HadoopUtils.getHdfsFileName(resource.getType(), tenantCode, resource.getFullName()); |
|
|
|
String hdfsFilename = HadoopUtils.getHdfsFileName(resource.getType(), tenantCode, resource.getFullName()); |
|
|
|
|
|
|
|
|
|
|
|
//delete data in database
|
|
|
|
//delete data in database
|
|
|
|
|
|
|
|
resourcesMapper.selectBatchIds(Arrays.asList(needDeleteResourceIdArray)).forEach(item -> { |
|
|
|
|
|
|
|
updateParentResourceSize(item, item.getSize() * -1); |
|
|
|
|
|
|
|
}); |
|
|
|
resourcesMapper.deleteIds(needDeleteResourceIdArray); |
|
|
|
resourcesMapper.deleteIds(needDeleteResourceIdArray); |
|
|
|
resourceUserMapper.deleteResourceUserArray(0, needDeleteResourceIdArray); |
|
|
|
resourceUserMapper.deleteResourceUserArray(0, needDeleteResourceIdArray); |
|
|
|
|
|
|
|
|
|
|
|
//delete file on hdfs
|
|
|
|
//delete file on hdfs
|
|
|
|
HadoopUtils.getInstance().delete(hdfsFilename, true); |
|
|
|
HadoopUtils.getInstance().delete(hdfsFilename, true); |
|
|
|
|
|
|
|
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
return result; |
|
|
@ -901,6 +959,7 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe |
|
|
|
Resource resource = new Resource(pid,name,fullName,false,desc,name,loginUser.getId(),type,content.getBytes().length,now,now); |
|
|
|
Resource resource = new Resource(pid,name,fullName,false,desc,name,loginUser.getId(),type,content.getBytes().length,now,now); |
|
|
|
|
|
|
|
|
|
|
|
resourcesMapper.insert(resource); |
|
|
|
resourcesMapper.insert(resource); |
|
|
|
|
|
|
|
updateParentResourceSize(resource, resource.getSize()); |
|
|
|
|
|
|
|
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
Map<Object, Object> dataMap = new BeanMap(resource); |
|
|
|
Map<Object, Object> dataMap = new BeanMap(resource); |
|
|
@ -995,10 +1054,13 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe |
|
|
|
if (StringUtils.isEmpty(tenantCode)) { |
|
|
|
if (StringUtils.isEmpty(tenantCode)) { |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
long originFileSize = resource.getSize(); |
|
|
|
resource.setSize(content.getBytes().length); |
|
|
|
resource.setSize(content.getBytes().length); |
|
|
|
resource.setUpdateTime(new Date()); |
|
|
|
resource.setUpdateTime(new Date()); |
|
|
|
resourcesMapper.updateById(resource); |
|
|
|
resourcesMapper.updateById(resource); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateParentResourceSize(resource, resource.getSize() - originFileSize); |
|
|
|
|
|
|
|
|
|
|
|
result = uploadContentToHdfs(resource.getFullName(), tenantCode, content); |
|
|
|
result = uploadContentToHdfs(resource.getFullName(), tenantCode, content); |
|
|
|
if (!result.getCode().equals(Status.SUCCESS.getCode())) { |
|
|
|
if (!result.getCode().equals(Status.SUCCESS.getCode())) { |
|
|
|
throw new ServiceException(result.getMsg()); |
|
|
|
throw new ServiceException(result.getMsg()); |
|
|
|