Search in sources :

Example 1 with CatalogueVO

use of com.dtstack.taier.develop.dto.devlop.CatalogueVO in project Taier by DTStack.

the class BatchResourceService method addResource.

/**
 * 添加资源
 */
public CatalogueVO addResource(BatchResourceAddDTO batchResourceAddDTO) {
    Long tenantId = batchResourceAddDTO.getTenantId();
    Long userId = batchResourceAddDTO.getUserId();
    String resourceName;
    Long resourceId = null;
    BatchResource resourceDB = null;
    Integer resourceType = null;
    if (batchResourceAddDTO.getId() != null && batchResourceAddDTO.getId() != 0L) {
        resourceId = batchResourceAddDTO.getId();
        resourceDB = this.developResourceDao.getOne(resourceId);
        resourceName = resourceDB.getResourceName();
        resourceType = resourceDB.getResourceType();
    } else {
        if (StringUtils.isEmpty(batchResourceAddDTO.getResourceName())) {
            throw new RdosDefineException("需要设置参数 resourceName.", ErrorCode.INVALID_PARAMETERS);
        }
        resourceName = batchResourceAddDTO.getResourceName();
        resourceType = batchResourceAddDTO.getResourceType() == null ? ResourceType.OTHER.getType() : batchResourceAddDTO.getResourceType();
    }
    String hdfsPath = uploadHDFSFileWithResource(tenantId, resourceName, batchResourceAddDTO.getOriginalFilename(), batchResourceAddDTO.getTmpPath());
    BatchResource batchResource = null;
    // 重新上传资源
    if (Objects.nonNull(resourceId)) {
        batchResource = resourceDB;
        if (Deleted.DELETED.getStatus().equals(batchResource.getIsDeleted())) {
            throw new RdosDefineException(ErrorCode.CAN_NOT_FIND_RESOURCE);
        }
        batchResource.setResourceDesc(batchResourceAddDTO.getResourceDesc());
        batchResource.setOriginFileName(batchResourceAddDTO.getOriginalFilename());
        batchResource.setUrl(hdfsPath);
    } else {
        // 判断是否已经存在相同的资源了
        batchTaskService.checkName(resourceName, CatalogueType.RESOURCE_MANAGER.name(), null, 1, tenantId);
        batchResourceAddDTO.setUrl(hdfsPath);
        batchResourceAddDTO.setCreateUserId(userId);
        batchResource = PublicUtil.objectToObject(batchResourceAddDTO, BatchResource.class);
        if (Objects.isNull(batchResource)) {
            throw new RdosDefineException(ErrorCode.CAN_NOT_FIND_RESOURCE);
        }
        batchResource.setOriginFileName(batchResourceAddDTO.getOriginalFilename());
    }
    // resourceType 设置默认值
    resourceType = resourceType != null ? resourceType : ResourceType.OTHER.getType();
    batchResource.setResourceType(resourceType);
    batchResource.setModifyUserId(userId);
    addOrUpdate(batchResource);
    BatchCatalogue catalogue = batchCatalogueService.getOne(batchResource.getNodePid());
    CatalogueVO catalogueVO = new CatalogueVO();
    catalogueVO.setId(batchResource.getId());
    catalogueVO.setName(batchResource.getResourceName());
    catalogueVO.setType("file");
    catalogueVO.setLevel(catalogue.getLevel() + 1);
    catalogueVO.setChildren(null);
    catalogueVO.setParentId(catalogue.getId());
    catalogueVO.setResourceType(resourceType);
    String username = userService.getUserName(catalogue.getCreateUserId());
    catalogueVO.setCreateUser(username);
    return catalogueVO;
}
Also used : CatalogueVO(com.dtstack.taier.develop.dto.devlop.CatalogueVO) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) BatchResource(com.dtstack.taier.dao.domain.BatchResource) BatchCatalogue(com.dtstack.taier.dao.domain.BatchCatalogue)

Example 2 with CatalogueVO

use of com.dtstack.taier.develop.dto.devlop.CatalogueVO in project Taier by DTStack.

the class BatchCatalogueService method getCatalogue.

/**
 * 条件查询目录
 * @param isGetFile
 * @param nodePid
 * @param catalogueType
 * @param userId
 * @param tenantId
 * @return
 */
public CatalogueVO getCatalogue(Boolean isGetFile, Long nodePid, String catalogueType, Long userId, Long tenantId) {
    CatalogueVO rootCatalogue = new CatalogueVO();
    // 0表示根目录
    if (nodePid == 0) {
        List<CatalogueVO> catalogues = getCatalogueOne(tenantId);
        rootCatalogue.setChildren(catalogues);
    } else {
        rootCatalogue.setId(nodePid);
        rootCatalogue.setCatalogueType(catalogueType);
        rootCatalogue = getChildNode(rootCatalogue, isGetFile, userId, tenantId);
    }
    return rootCatalogue;
}
Also used : BatchCatalogueVO(com.dtstack.taier.develop.dto.devlop.BatchCatalogueVO) CatalogueVO(com.dtstack.taier.develop.dto.devlop.CatalogueVO)

Example 3 with CatalogueVO

use of com.dtstack.taier.develop.dto.devlop.CatalogueVO in project Taier by DTStack.

the class BatchCatalogueService method getChildNode.

/**
 * 获得当前节点的子节点信息,包括子孙文件夹和子孙文件
 *
 * @param tenantId   租户id
 * @param isGetFile
 * @param userId
 * @return
 * @author jiangbo、toutian
 */
private CatalogueVO getChildNode(CatalogueVO currentCatalogueVO, Boolean isGetFile, Long userId, Long tenantId) {
    BatchCatalogue currentCatalogue = developCatalogueDao.getOne(currentCatalogueVO.getId());
    if (currentCatalogue == null) {
        throw new RdosDefineException(ErrorCode.CAN_NOT_FIND_CATALOGUE);
    }
    currentCatalogueVO.setTenantId(currentCatalogue.getTenantId());
    currentCatalogueVO.setName(currentCatalogue.getNodeName());
    currentCatalogueVO.setLevel(currentCatalogue.getLevel());
    currentCatalogueVO.setParentId(currentCatalogue.getNodePid());
    currentCatalogueVO.setType(FILE_TYPE_FOLDER);
    // 获取目录下的资源或任务列表
    if (isGetFile) {
        // 目录下的文件信息
        List<CatalogueVO> catalogueChildFileList = Lists.newArrayList();
        // 用户id 和 名称映射
        Map<Long, String> userIdAndNameMap = Maps.newHashMap();
        // 任务目录
        if (CatalogueType.TASK_DEVELOP.getType().equals(currentCatalogueVO.getCatalogueType())) {
            List<BatchTask> taskList = batchTaskService.catalogueListBatchTaskByNodePid(tenantId, currentCatalogueVO.getId());
            taskList.sort(Comparator.comparing(BatchTask::getName));
            if (CollectionUtils.isNotEmpty(taskList)) {
                List<Long> taskIds = taskList.stream().map(BatchTask::getId).collect(Collectors.toList());
                Map<Long, ReadWriteLockVO> readWriteLockIdAndVOMap = getReadWriteLockVOMap(tenantId, taskIds, userId, userIdAndNameMap);
                // 遍历目录下的所有任务
                for (BatchTask task : taskList) {
                    CatalogueVO childCatalogueTask = new CatalogueVO();
                    BeanUtils.copyProperties(task, childCatalogueTask);
                    childCatalogueTask.setType("file");
                    childCatalogueTask.setLevel(currentCatalogueVO.getLevel() + 1);
                    childCatalogueTask.setParentId(currentCatalogueVO.getId());
                    childCatalogueTask.setCreateUser(getUserNameInMemory(userIdAndNameMap, task.getCreateUserId()));
                    // 设置任务的读写锁信息
                    ReadWriteLockVO readWriteLockVO = readWriteLockIdAndVOMap.get(task.getId());
                    if (readWriteLockVO.getLastKeepLockUserName() == null) {
                        readWriteLockVO.setLastKeepLockUserName(getUserNameInMemory(userIdAndNameMap, task.getModifyUserId()));
                        readWriteLockVO.setGmtModified(task.getGmtModified());
                    }
                    childCatalogueTask.setReadWriteLockVO(readWriteLockVO);
                    catalogueChildFileList.add(childCatalogueTask);
                }
            }
        } else if (FUNCTION_CATALOGUE_TYPE.contains(currentCatalogueVO.getCatalogueType())) {
            // 处理函数目录
            List<BatchFunction> functionList = batchFunctionService.listByNodePidAndTenantId(currentCatalogueVO.getTenantId(), currentCatalogueVO.getId());
            if (CollectionUtils.isNotEmpty(functionList)) {
                functionList.sort(Comparator.comparing(BatchFunction::getName));
                for (BatchFunction function : functionList) {
                    CatalogueVO child = new CatalogueVO();
                    BeanUtils.copyProperties(function, child);
                    child.setLevel(currentCatalogueVO.getLevel() + 1);
                    child.setType("file");
                    child.setCreateUser(getUserNameInMemory(userIdAndNameMap, function.getCreateUserId()));
                    child.setParentId(function.getNodePid());
                    catalogueChildFileList.add(child);
                }
            }
        } else if (CatalogueType.RESOURCE_MANAGER.getType().equals(currentCatalogueVO.getCatalogueType())) {
            // 处理资源目录
            List<BatchResource> resourceList = batchResourceService.listByPidAndTenantId(tenantId, currentCatalogueVO.getId());
            resourceList.sort(Comparator.comparing(BatchResource::getResourceName));
            if (CollectionUtils.isNotEmpty(resourceList)) {
                for (BatchResource resource : resourceList) {
                    CatalogueVO childResource = new CatalogueVO();
                    BeanUtils.copyProperties(resource, childResource);
                    childResource.setName(resource.getResourceName());
                    childResource.setType("file");
                    childResource.setLevel(currentCatalogueVO.getLevel() + 1);
                    childResource.setParentId(currentCatalogueVO.getId());
                    childResource.setCreateUser(getUserNameInMemory(userIdAndNameMap, resource.getCreateUserId()));
                    catalogueChildFileList.add(childResource);
                }
            }
        }
        currentCatalogueVO.setChildren(catalogueChildFileList);
    }
    // 获取目录下的子目录
    List<BatchCatalogue> childCatalogues = this.getChildCataloguesByType(currentCatalogueVO.getId(), currentCatalogueVO.getCatalogueType(), currentCatalogue.getTenantId());
    childCatalogues = keepInitCatalogueBeTop(childCatalogues, currentCatalogue);
    List<CatalogueVO> children = new ArrayList<>();
    for (BatchCatalogue catalogue : childCatalogues) {
        CatalogueVO cv = CatalogueVO.toVO(catalogue);
        cv.setType(FILE_TYPE_FOLDER);
        this.changeSQLFunctionCatalogueType(catalogue, cv, currentCatalogueVO);
        children.add(cv);
    }
    if (currentCatalogueVO.getChildren() == null) {
        currentCatalogueVO.setChildren(children);
    } else {
        currentCatalogueVO.getChildren().addAll(0, children);
    }
    return currentCatalogueVO;
}
Also used : BatchFunction(com.dtstack.taier.dao.domain.BatchFunction) BatchTask(com.dtstack.taier.dao.domain.BatchTask) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) ReadWriteLockVO(com.dtstack.taier.develop.dto.devlop.ReadWriteLockVO) ArrayList(java.util.ArrayList) BatchCatalogueVO(com.dtstack.taier.develop.dto.devlop.BatchCatalogueVO) CatalogueVO(com.dtstack.taier.develop.dto.devlop.CatalogueVO) ArrayList(java.util.ArrayList) List(java.util.List) BatchResource(com.dtstack.taier.dao.domain.BatchResource) BatchCatalogue(com.dtstack.taier.dao.domain.BatchCatalogue)

Example 4 with CatalogueVO

use of com.dtstack.taier.develop.dto.devlop.CatalogueVO in project Taier by DTStack.

the class BatchCatalogueService method getCatalogueOne.

/**
 * 获取 租户 下的 0 级目录极其子目录
 * @param tenantId
 * @return
 */
public List<CatalogueVO> getCatalogueOne(Long tenantId) {
    // 查询 0 级目录
    List<BatchCatalogue> zeroCatalogues = developCatalogueDao.listByLevelAndTenantId(0, tenantId);
    // 从字典表中查询出初始化的 0 级目录
    List<Dict> zeroCatalogueDictList = dictService.listByDictType(DictType.DATA_DEVELOP_CATALOGUE);
    // 从字典表中查询出初始化的 1 级目录
    List<Dict> oneCatalogueDictList = dictService.listByDictType(DictType.DATA_DEVELOP_CATALOGUE_L1);
    // 0 级目录的中文和英文名称
    Map<String, String> zeroCatalogueType = zeroCatalogueDictList.stream().collect(Collectors.toMap(Dict::getDictDesc, Dict::getDictName, (key1, key2) -> key1));
    // 1 级目录的中文和英文名称
    Map<String, String> oneCatalogueType = oneCatalogueDictList.stream().collect(Collectors.toMap(Dict::getDictDesc, Dict::getDictName, (key1, key2) -> key1));
    List<CatalogueVO> zeroCatalogueVOList = new ArrayList<>(zeroCatalogues.size());
    for (BatchCatalogue zeroCatalogue : zeroCatalogues) {
        CatalogueVO zeroCatalogueVO = CatalogueVO.toVO(zeroCatalogue);
        zeroCatalogueVO.setCatalogueType(zeroCatalogueType.get(zeroCatalogue.getNodeName()));
        zeroCatalogueVO.setType(FILE_TYPE_FOLDER);
        zeroCatalogueVOList.add(zeroCatalogueVO);
        // 查询一级目录下的子目录
        List<BatchCatalogue> oneChildCatalogues = developCatalogueDao.listByPidAndTenantId(zeroCatalogue.getId(), tenantId);
        if (FUNCTION_MANAGER_NAME.equals(zeroCatalogue.getNodeName())) {
            // 如果是函数目录,默认添加上系统函数目录
            BatchCatalogue systemFuncCatalogue = developCatalogueDao.getSystemFunctionCatalogueOne(EngineCatalogueType.SPARK.getType());
            if (systemFuncCatalogue != null) {
                oneChildCatalogues.add(systemFuncCatalogue);
            }
        }
        List<CatalogueVO> oneChildCatalogueVOList = new ArrayList<>(oneChildCatalogues.size());
        for (BatchCatalogue oneChildCatalogue : oneChildCatalogues) {
            CatalogueVO oneChildCatalogueVO = CatalogueVO.toVO(oneChildCatalogue);
            if (EngineCatalogueType.SPARK.getDesc().equals(oneChildCatalogueVO.getName())) {
                // spark  函数管理 不是目录
                oneChildCatalogueVO.setType("catalogue");
            } else {
                oneChildCatalogueVO.setType("folder");
            }
            oneChildCatalogueVO.setCatalogueType(oneCatalogueType.get(oneChildCatalogue.getNodeName()));
            oneChildCatalogueVOList.add(oneChildCatalogueVO);
        }
        zeroCatalogueVO.setChildren(oneChildCatalogueVOList);
    }
    return zeroCatalogueVOList;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) UserService(com.dtstack.taier.develop.service.user.UserService) LoggerFactory(org.slf4j.LoggerFactory) LocalDateTime(java.time.LocalDateTime) CatalogueType(com.dtstack.taier.common.enums.CatalogueType) Autowired(org.springframework.beans.factory.annotation.Autowired) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) HashMap(java.util.HashMap) BatchCatalogue(com.dtstack.taier.dao.domain.BatchCatalogue) BatchCatalogueVO(com.dtstack.taier.develop.dto.devlop.BatchCatalogueVO) EngineCatalogueType(com.dtstack.taier.common.enums.EngineCatalogueType) ArrayList(java.util.ArrayList) Dict(com.dtstack.taier.dao.domain.Dict) BatchTaskGetComponentVersionResultVO(com.dtstack.taier.develop.vo.develop.result.BatchTaskGetComponentVersionResultVO) Lists(com.google.common.collect.Lists) CatalogueLevel(com.dtstack.taier.common.enums.CatalogueLevel) DevelopCatalogueDao(com.dtstack.taier.dao.mapper.DevelopCatalogueDao) CollectionUtils(org.apache.commons.collections.CollectionUtils) Service(org.springframework.stereotype.Service) Map(java.util.Map) CatalogueVO(com.dtstack.taier.develop.dto.devlop.CatalogueVO) ComputeType(com.dtstack.taier.common.enums.ComputeType) ErrorCode(com.dtstack.taier.common.exception.ErrorCode) BatchFunction(com.dtstack.taier.dao.domain.BatchFunction) TemplateCatalogue(com.dtstack.taier.develop.enums.develop.TemplateCatalogue) BatchTask(com.dtstack.taier.dao.domain.BatchTask) Logger(org.slf4j.Logger) DictType(com.dtstack.taier.common.enums.DictType) ReadWriteLockType(com.dtstack.taier.common.enums.ReadWriteLockType) Timestamp(java.sql.Timestamp) Set(java.util.Set) BatchResource(com.dtstack.taier.dao.domain.BatchResource) ScheduleDictService(com.dtstack.taier.scheduler.service.ScheduleDictService) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) RdosBatchCatalogueTypeEnum(com.dtstack.taier.develop.enums.develop.RdosBatchCatalogueTypeEnum) Sets(com.google.common.collect.Sets) TaskResourceParam(com.dtstack.taier.develop.dto.devlop.TaskResourceParam) EComponentType(com.dtstack.taier.common.enums.EComponentType) Objects(java.util.Objects) List(java.util.List) ComponentVO(com.dtstack.taier.scheduler.vo.ComponentVO) ReadWriteLockVO(com.dtstack.taier.develop.dto.devlop.ReadWriteLockVO) EScheduleJobType(com.dtstack.taier.common.enums.EScheduleJobType) Comparator(java.util.Comparator) Deleted(com.dtstack.taier.common.enums.Deleted) BeanUtils(org.springframework.beans.BeanUtils) Transactional(org.springframework.transaction.annotation.Transactional) BatchCatalogueVO(com.dtstack.taier.develop.dto.devlop.BatchCatalogueVO) CatalogueVO(com.dtstack.taier.develop.dto.devlop.CatalogueVO) Dict(com.dtstack.taier.dao.domain.Dict) ArrayList(java.util.ArrayList) BatchCatalogue(com.dtstack.taier.dao.domain.BatchCatalogue)

Example 5 with CatalogueVO

use of com.dtstack.taier.develop.dto.devlop.CatalogueVO in project Taier by DTStack.

the class BatchCatalogueService method addCatalogue.

/**
 * 新增 and 修改目录
 * @param catalogue
 * @return
 */
public CatalogueVO addCatalogue(BatchCatalogue catalogue) {
    if (Objects.isNull(catalogue)) {
        throw new RdosDefineException(ErrorCode.CATALOGUE_NOT_EMPTY);
    }
    if (StringUtils.isBlank(catalogue.getNodeName())) {
        throw new RdosDefineException(ErrorCode.CATALOGUE_NAME_NOT_EMPTY);
    }
    catalogue.setNodeName(catalogue.getNodeName().trim());
    // 校验文件夹中是否含有空格
    if (catalogue.getNodeName().contains(" ")) {
        throw new RdosDefineException(ErrorCode.CATALOGUE_NAME_CANNOT_CONTAIN_SPACES);
    }
    BatchCatalogue dbCatalogue = developCatalogueDao.getByPidAndName(catalogue.getTenantId(), catalogue.getNodePid(), catalogue.getNodeName());
    if (dbCatalogue != null) {
        throw new RdosDefineException(ErrorCode.CATALOGUE_EXISTS);
    }
    // 校验当前父级直接一层的子目录或者任务的个数总数不可超过SUB_AMOUNTS_LIMIT(2000)
    Integer subAmountsByNodePid = developCatalogueDao.getSubAmountsByNodePid(catalogue.getNodePid(), catalogue.getTenantId());
    if (subAmountsByNodePid >= SUB_AMOUNTS_LIMIT) {
        throw new RdosDefineException(ErrorCode.SUBDIRECTORY_OR_FILE_AMOUNT_RESTRICTIONS);
    }
    int parentCatalogueLevel = catalogue.getNodePid() == 0L ? 0 : this.isOverLevelLimit(catalogue.getNodePid());
    catalogue.setLevel(parentCatalogueLevel + 1);
    catalogue.setCreateUserId(catalogue.getCreateUserId());
    catalogue.setGmtModified(Timestamp.valueOf(LocalDateTime.now()));
    catalogue.setGmtCreate(Timestamp.valueOf(LocalDateTime.now()));
    if (null == catalogue.getCatalogueType()) {
        catalogue.setCatalogueType(RdosBatchCatalogueTypeEnum.NORAML.getType());
    }
    if (RdosBatchCatalogueTypeEnum.TENANT.getType().equals(catalogue.getCatalogueType())) {
        if (catalogue.getLevel() > 3) {
            throw new RdosDefineException(ErrorCode.CREATE_TENANT_CATALOGUE_LEVE);
        }
    }
    addOrUpdate(catalogue);
    CatalogueVO cv = CatalogueVO.toVO(catalogue);
    cv.setType(BatchCatalogueService.FILE_TYPE_FOLDER);
    return cv;
}
Also used : BatchCatalogueVO(com.dtstack.taier.develop.dto.devlop.BatchCatalogueVO) CatalogueVO(com.dtstack.taier.develop.dto.devlop.CatalogueVO) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) BatchCatalogue(com.dtstack.taier.dao.domain.BatchCatalogue)

Aggregations

CatalogueVO (com.dtstack.taier.develop.dto.devlop.CatalogueVO)5 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)4 BatchCatalogue (com.dtstack.taier.dao.domain.BatchCatalogue)4 BatchCatalogueVO (com.dtstack.taier.develop.dto.devlop.BatchCatalogueVO)4 BatchResource (com.dtstack.taier.dao.domain.BatchResource)3 BatchFunction (com.dtstack.taier.dao.domain.BatchFunction)2 BatchTask (com.dtstack.taier.dao.domain.BatchTask)2 ReadWriteLockVO (com.dtstack.taier.develop.dto.devlop.ReadWriteLockVO)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CatalogueLevel (com.dtstack.taier.common.enums.CatalogueLevel)1 CatalogueType (com.dtstack.taier.common.enums.CatalogueType)1 ComputeType (com.dtstack.taier.common.enums.ComputeType)1 Deleted (com.dtstack.taier.common.enums.Deleted)1 DictType (com.dtstack.taier.common.enums.DictType)1 EComponentType (com.dtstack.taier.common.enums.EComponentType)1 EScheduleJobType (com.dtstack.taier.common.enums.EScheduleJobType)1 EngineCatalogueType (com.dtstack.taier.common.enums.EngineCatalogueType)1 ReadWriteLockType (com.dtstack.taier.common.enums.ReadWriteLockType)1 ErrorCode (com.dtstack.taier.common.exception.ErrorCode)1