Search in sources :

Example 1 with BatchFunction

use of com.dtstack.taier.dao.domain.BatchFunction 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 2 with BatchFunction

use of com.dtstack.taier.dao.domain.BatchFunction in project Taier by DTStack.

the class BatchFunctionService method deleteFunction.

/**
 * 删除函数
 * @param userId
 * @param functionId
 */
@Transactional(rollbackFor = Exception.class)
public void deleteFunction(Long userId, Long functionId) {
    BatchFunction batchFunction = developFunctionDao.getOne(functionId);
    if (Objects.isNull(batchFunction)) {
        throw new RdosDefineException(ErrorCode.FUNCTION_CAN_NOT_FIND);
    }
    if (FuncType.SYSTEM.getType().equals(batchFunction.getType())) {
        throw new RdosDefineException(ErrorCode.SYSTEM_FUNCTION_CAN_NOT_MODIFY);
    }
    batchFunctionResourceService.deleteByFunctionId(functionId);
    batchFunction = new BatchFunction();
    batchFunction.setId(functionId);
    batchFunction.setIsDeleted(Deleted.DELETED.getStatus());
    batchFunction.setModifyUserId(userId);
    addOrUpdate(batchFunction);
}
Also used : BatchFunction(com.dtstack.taier.dao.domain.BatchFunction) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with BatchFunction

use of com.dtstack.taier.dao.domain.BatchFunction in project Taier by DTStack.

the class BatchFunctionService method moveFunction.

/**
 * 移动函数
 * @param userId
 * @param functionId
 * @param nodePid
 */
public void moveFunction(Long userId, Long functionId, Long nodePid) {
    BatchFunction bf = developFunctionDao.getOne(functionId);
    if (Objects.isNull(bf)) {
        throw new RdosDefineException(ErrorCode.FUNCTION_CAN_NOT_FIND);
    }
    if (FuncType.SYSTEM.getType().equals(bf.getType())) {
        throw new RdosDefineException(ErrorCode.SYSTEM_FUNCTION_CAN_NOT_MODIFY);
    }
    bf = new BatchFunction();
    bf.setId(functionId);
    bf.setNodePid(nodePid);
    bf.setModifyUserId(userId);
    addOrUpdate(bf);
}
Also used : BatchFunction(com.dtstack.taier.dao.domain.BatchFunction) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException)

Example 4 with BatchFunction

use of com.dtstack.taier.dao.domain.BatchFunction in project Taier by DTStack.

the class BatchFunctionService method buildContainFunction.

/**
 * 判断sql是否包含自定义函数
 *
 * @param sql
 * @param tenantId
 * @return
 */
public String buildContainFunction(String sql, Long tenantId, Integer taskType) {
    StringBuilder sb = new StringBuilder();
    sql = SqlFormatUtil.formatSql(sql).toLowerCase();
    // sql中的自定义函数
    SqlParserImpl sqlParser = parserFactory.getSqlParser(ETableType.HIVE);
    Set<String> sqlFunctionNames = sqlParser.parseFunction(sql);
    if (CollectionUtils.isEmpty(sqlFunctionNames)) {
        return StringUtils.EMPTY;
    }
    // 获取此项目下的自定义函数名称
    List<BatchFunction> tenantCustomFunctions = listTenantFunction(tenantId, FunctionType.USER.getType(), taskType);
    if (CollectionUtils.isEmpty(tenantCustomFunctions)) {
        return StringUtils.EMPTY;
    }
    List<String> customFunctionNames = tenantCustomFunctions.stream().map(BatchFunction::getName).collect(Collectors.toList());
    // 循环sql中的函数判断是否是项目中的名称
    for (String sqlFunctionName : sqlFunctionNames) {
        // 如果sql中的函数存在于此项目下
        if (customFunctionNames.contains(sqlFunctionName)) {
            BatchFunction byNameAndTenantId = developFunctionDao.getByNameAndTenantId(tenantId, sqlFunctionName);
            sb.append(createTempUDF(byNameAndTenantId));
        }
    }
    return sb.toString();
}
Also used : BatchFunction(com.dtstack.taier.dao.domain.BatchFunction) SqlParserImpl(com.dtstack.taier.develop.sql.SqlParserImpl)

Example 5 with BatchFunction

use of com.dtstack.taier.dao.domain.BatchFunction in project Taier by DTStack.

the class BatchFunctionService method validContainSelfFunction.

/**
 * 校验是否包含了函数
 *
 * @param sql
 * @param tenantId
 * @param functionType
 * @return
 */
public boolean validContainSelfFunction(String sql, Long tenantId, Integer functionType, Integer taskType) {
    if (StringUtils.isBlank(sql) || Objects.isNull(tenantId)) {
        return false;
    }
    sql = SqlFormatUtil.formatSql(sql).toLowerCase();
    // sql中的自定义函数
    SqlParserImpl sqlParser = parserFactory.getSqlParser(ETableType.HIVE);
    Set<String> sqlFunctionNames = sqlParser.parseFunction(sql);
    if (CollectionUtils.isEmpty(sqlFunctionNames)) {
        return false;
    }
    // 获取此项目下的自定义函数名称
    List<BatchFunction> projectFunctions = listTenantFunction(tenantId, functionType, taskType);
    if (CollectionUtils.isEmpty(projectFunctions)) {
        return false;
    }
    List<String> projectFunctionNames = projectFunctions.stream().map(BatchFunction::getName).collect(Collectors.toList());
    // 循环sql中的函数判断是否是项目中的名称
    for (String sqlFunctionName : sqlFunctionNames) {
        // 如果sql中的函数存在于此项目下
        if (projectFunctionNames.contains(sqlFunctionName)) {
            return true;
        }
    }
    return false;
}
Also used : BatchFunction(com.dtstack.taier.dao.domain.BatchFunction) SqlParserImpl(com.dtstack.taier.develop.sql.SqlParserImpl)

Aggregations

BatchFunction (com.dtstack.taier.dao.domain.BatchFunction)7 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)3 SqlParserImpl (com.dtstack.taier.develop.sql.SqlParserImpl)2 BatchCatalogue (com.dtstack.taier.dao.domain.BatchCatalogue)1 BatchFunctionResource (com.dtstack.taier.dao.domain.BatchFunctionResource)1 BatchResource (com.dtstack.taier.dao.domain.BatchResource)1 BatchTask (com.dtstack.taier.dao.domain.BatchTask)1 BatchCatalogueVO (com.dtstack.taier.develop.dto.devlop.BatchCatalogueVO)1 BatchFunctionVO (com.dtstack.taier.develop.dto.devlop.BatchFunctionVO)1 CatalogueVO (com.dtstack.taier.develop.dto.devlop.CatalogueVO)1 ReadWriteLockVO (com.dtstack.taier.develop.dto.devlop.ReadWriteLockVO)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PostConstruct (javax.annotation.PostConstruct)1 Transactional (org.springframework.transaction.annotation.Transactional)1