Search in sources :

Example 6 with BatchTask

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

the class BatchTaskService method trace.

public JSONObject trace(final Long taskId) {
    String sqlText = null;
    final BatchTask batchTask = this.getBatchTaskById(taskId);
    if (batchTask == null) {
        throw new RdosDefineException(ErrorCode.CAN_NOT_FIND_TASK);
    } else {
        sqlText = batchTask.getSqlText();
    }
    final String sql = Base64Util.baseDecode(sqlText);
    if (StringUtils.isBlank(sql)) {
        return null;
    }
    final JSONObject sqlJson = JSON.parseObject(sql);
    JSONObject parserJson = sqlJson.getJSONObject("parser");
    if (parserJson != null) {
        parserJson = this.checkTrace(parserJson);
        parserJson.put("sqlText", sqlJson.getString("job"));
        parserJson.put("syncMode", sqlJson.get("syncMode"));
        parserJson.put("taskId", taskId);
    }
    return parserJson;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) BatchTask(com.dtstack.taier.dao.domain.BatchTask) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException)

Example 7 with BatchTask

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

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

the class BatchTaskService method updateTaskResource.

/**
 * 更新任务主资源
 *
 * @param taskResourceMap
 * @return
 */
@Transactional
public void updateTaskResource(final Map<String, Object> taskResourceMap) {
    Preconditions.checkState(taskResourceMap.containsKey("id"), "need param of id");
    Preconditions.checkState(taskResourceMap.containsKey("resources"), "need param of resources");
    Preconditions.checkState(taskResourceMap.containsKey("tenantId"), "need param of tenantId");
    Preconditions.checkState(taskResourceMap.containsKey("createUserId"), "need param of createUserId");
    final Long id = MathUtil.getLongVal(taskResourceMap.get("id"));
    final List<Object> oriResourceList = (List<Object>) taskResourceMap.get("resources");
    final BatchTask task = this.developTaskDao.getOne(id);
    Preconditions.checkNotNull(task, "can not find task by id " + id);
    // 删除旧的资源
    batchTaskResourceService.deleteByTaskId(task.getId(), ResourceRefType.MAIN_RES.getType());
    // 添加新的资源
    if (CollectionUtils.isNotEmpty(oriResourceList)) {
        List<Long> resourceIdList = Lists.newArrayList();
        oriResourceList.forEach(tmpId -> resourceIdList.add(MathUtil.getLongVal(tmpId)));
        batchTaskResourceService.save(task, resourceIdList, ResourceRefType.MAIN_RES.getType());
    }
}
Also used : BatchTask(com.dtstack.taier.dao.domain.BatchTask) JSONObject(com.alibaba.fastjson.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with BatchTask

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

the class BatchTaskService method initTaskInfo.

/**
 *初始化 task的一些基本属性
 *
 * @param task
 * @return
 */
private boolean initTaskInfo(BatchTaskBatchVO task) {
    if (StringUtils.isBlank(task.getTaskDesc())) {
        task.setTaskDesc("");
    }
    if (StringUtils.isBlank(task.getTaskParams())) {
        task.setTaskParams("");
    }
    if (StringUtils.isBlank(task.getMainClass())) {
        task.setMainClass("");
    }
    if (StringUtils.isBlank(task.getScheduleConf())) {
        task.setScheduleConf(DEFAULT_SCHEDULE_CONF);
    } else {
        final JSONObject scheduleConf = JSON.parseObject(task.getScheduleConf());
        final String beginDate = scheduleConf.getString("beginDate");
        if (StringUtils.isBlank(beginDate) || "null".equalsIgnoreCase(beginDate)) {
            throw new RdosDefineException("生效日期起至时间不能为空");
        }
        final String endDate = scheduleConf.getString("endDate");
        if (StringUtils.isBlank(endDate) || "null".equalsIgnoreCase(endDate)) {
            throw new RdosDefineException("生效日期结束时间不能为空");
        }
    }
    if (task.getVersion() == null) {
        task.setVersion(0);
    }
    if (task.getCreateUserId() == null) {
        task.setCreateUserId(task.getUserId());
    }
    task.setGmtCreate(task.getGmtModified());
    // 增加注释
    task.setSqlText(this.createAnnotationText(task));
    task.setSubmitStatus(ESubmitStatus.UNSUBMIT.getStatus());
    task.setTaskParams(getDefaultTaskParam(task.getTenantId(), task.getTaskType()));
    task.setScheduleStatus(EScheduleStatus.NORMAL.getVal());
    task.setPeriodType(DEFAULT_SCHEDULE_PERIOD);
    String scConf = DEFAULT_SCHEDULE_CONF;
    int period = DEFAULT_SCHEDULE_PERIOD;
    if (task.getFlowId() != null && task.getFlowId() > 0) {
        final BatchTask flow = this.developTaskDao.getOne(task.getFlowId());
        if (flow != null) {
            scConf = flow.getScheduleConf();
            final ScheduleCron scheduleCron;
            try {
                scheduleCron = ScheduleFactory.parseFromJson(scConf);
            } catch (Exception e) {
                throw new RdosDefineException(e.getMessage(), e);
            }
            period = scheduleCron.getPeriodType();
        }
        task.setScheduleConf(scConf);
    }
    task.setPeriodType(period);
    if (Objects.isNull(task.getFlowId())) {
        task.setFlowId(0L);
    }
    return true;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) BatchTask(com.dtstack.taier.dao.domain.BatchTask) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) ScheduleCron(com.dtstack.taier.develop.parser.ScheduleCron) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) IOException(java.io.IOException) DtCenterDefException(com.dtstack.taier.common.exception.DtCenterDefException)

Example 10 with BatchTask

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

the class BatchTaskService method checkFillPassword.

/**
 * 密码回填检查方法
 */
private void checkFillPassword(final TaskResourceParam param) {
    // 单独对同步任务中密码进行补全处理 将未变更的 ****** 填充为原密码信息 --2019/10/25 茂茂--
    if (param.getId() > 0 && EScheduleJobType.SYNC.getVal().equals(param.getTaskType())) {
        final String context = param.getSqlText();
        if (null == context) {
            return;
        }
        // 1、检查上送字段是否存在需要处理的密码,不存在直接跳过
        final Pattern pattern = Pattern.compile(PatternConstant.PASSWORD_FIELD_REGEX, Pattern.CASE_INSENSITIVE);
        final Matcher matcher = pattern.matcher(context);
        if (matcher.find()) {
            LOGGER.info("当前上送信息存在隐藏密码字段,准备执行旧密码回填操作");
            // 2、查询旧数据信息,保存成结构数据,待数据解析补充
            final BatchTask task = this.developTaskDao.getOne(param.getId());
            if (Objects.nonNull(task)) {
                final String sqlText = task.getSqlText();
                if (StringUtils.isNotEmpty(sqlText)) {
                    final JSONObject oldData = JSON.parseObject(Base64Util.baseDecode(sqlText));
                    // 3、处理新上送的数据,替换未变更的密码信息
                    final JSONObject newData = JSON.parseObject(context);
                    // 值并行处理 -- 固定接口直接写死job的值处理密码问题
                    this.fillPassword(newData, oldData.getJSONObject("job"));
                    param.setSqlText(newData.toJSONString());
                }
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) JSONObject(com.alibaba.fastjson.JSONObject) Matcher(java.util.regex.Matcher) BatchTask(com.dtstack.taier.dao.domain.BatchTask)

Aggregations

BatchTask (com.dtstack.taier.dao.domain.BatchTask)25 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)14 JSONObject (com.alibaba.fastjson.JSONObject)12 Transactional (org.springframework.transaction.annotation.Transactional)9 ArrayList (java.util.ArrayList)7 List (java.util.List)7 DtCenterDefException (com.dtstack.taier.common.exception.DtCenterDefException)6 BatchTaskBatchVO (com.dtstack.taier.develop.dto.devlop.BatchTaskBatchVO)6 BatchCatalogue (com.dtstack.taier.dao.domain.BatchCatalogue)5 BatchResource (com.dtstack.taier.dao.domain.BatchResource)5 IOException (java.io.IOException)5 Matcher (java.util.regex.Matcher)5 ReadWriteLockVO (com.dtstack.taier.develop.dto.devlop.ReadWriteLockVO)4 JSON (com.alibaba.fastjson.JSON)3 JSONArray (com.alibaba.fastjson.JSONArray)3 JSONPath (com.alibaba.fastjson.JSONPath)3 TypeReference (com.alibaba.fastjson.TypeReference)3 ClientCache (com.dtstack.dtcenter.loader.client.ClientCache)3 IClient (com.dtstack.dtcenter.loader.client.IClient)3 IKerberos (com.dtstack.dtcenter.loader.client.IKerberos)3