Search in sources :

Example 16 with BatchTask

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

the class BatchTaskService method mapDfs.

/**
 * 图深度遍历
 *
 * @param taskId  任务ID
 * @param set     已经遍历过的节点
 * @param nodeMap 任务完整依赖关系  key:节点  value 节点的所有父节点
 */
private void mapDfs(Long taskId, HashSet<Long> set, Map<Long, List<Long>> nodeMap) {
    HashSet<Long> node = new HashSet<>(set);
    // 判断该节点是否以及存在,如果存在,则证明成环了
    if (set.contains(taskId)) {
        BatchTask task = developTaskDao.getOne(taskId);
        if (Objects.nonNull(task)) {
            throw new RdosDefineException(String.format("%s任务发生依赖闭环", task.getName()));
        }
    }
    node.add(taskId);
    for (Long j : nodeMap.get(taskId)) {
        mapDfs(j, node, nodeMap);
    }
}
Also used : BatchTask(com.dtstack.taier.dao.domain.BatchTask) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) HashSet(java.util.HashSet)

Example 17 with BatchTask

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

the class BatchTaskService method operateIncreCol.

/**
 * 处理增量标识  主要处理两部分 1 处理增量标识字段  2.处理调度依赖
 * @param param
 */
private void operateIncreCol(TaskResourceParam param) {
    final BatchTask task = this.developTaskDao.getOne(param.getId());
    if (StringUtils.isNotEmpty(task.getSqlText())) {
        final JSONObject json = JSON.parseObject(Base64Util.baseDecode(task.getSqlText()));
        json.put("syncModel", param.getSyncModel());
        // 处理增量标示
        operateIncreamColumn(json, param.getSyncModel());
        param.setSqlText(json.toJSONString());
    }
    JSONObject scheduleConf = JSON.parseObject(task.getScheduleConf());
    Integer selfReliance = scheduleConf.getInteger("selfReliance");
    if (param.getSyncModel() == SyncModel.HAS_INCRE_COL.getModel() && !DependencyType.SELF_DEPENDENCY_SUCCESS.getType().equals(selfReliance) && !DependencyType.SELF_DEPENDENCY_END.getType().equals(selfReliance)) {
        scheduleConf.put("selfReliance", DependencyType.SELF_DEPENDENCY_END.getType());
        param.setScheduleConf(scheduleConf.toJSONString());
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) BatchTask(com.dtstack.taier.dao.domain.BatchTask)

Example 18 with BatchTask

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

the class BatchTaskService method updateTaskRefResource.

/**
 * 更新任务引用资源
 *
 * @param taskResourceMap
 * @return
 */
@Transactional
public void updateTaskRefResource(final Map<String, Object> taskResourceMap) {
    Preconditions.checkState(taskResourceMap.containsKey("id"), "need param of id");
    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> refResourceList = (List<Object>) taskResourceMap.get("refResource");
    final BatchTask task = getOneWithError(id);
    // 删除旧的资源
    batchTaskResourceService.deleteByTaskId(task.getId(), ResourceRefType.DEPENDENCY_RES.getType());
    // 添加新的关联资源
    if (CollectionUtils.isNotEmpty(refResourceList)) {
        final List<Long> refResourceIdList = Lists.newArrayList();
        refResourceList.forEach(tmpId -> refResourceIdList.add(MathUtil.getLongVal(tmpId)));
        this.batchTaskResourceService.save(task, refResourceIdList, ResourceRefType.DEPENDENCY_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 19 with BatchTask

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

the class BatchTaskService method checkTaskAndSaveVersion.

/**
 * 检查要发布的任务并保存版本信息
 *
 * @param task 任务信息
 * @param tenantId 项目id
 * @param userId 用户id
 * @param publishDesc 发布描述
 * @param isRoot 是否是管理员
 * @param ignoreCheck 是否忽略检查
 * @return 检查结果
 */
private TaskCheckResultVO checkTaskAndSaveVersion(BatchTask task, Long tenantId, Long userId, String publishDesc, Boolean isRoot, Boolean ignoreCheck) {
    TaskCheckResultVO checkVo = new TaskCheckResultVO();
    checkVo.setErrorSign(PublishTaskStatusEnum.NOMAL.getType());
    checkTaskCanSubmit(task);
    task.setSubmitStatus(ESubmitStatus.SUBMIT.getStatus());
    task.setGmtModified(Timestamp.valueOf(LocalDateTime.now()));
    final BatchTaskVersion version = new BatchTaskVersion();
    version.setCreateUserId(userId);
    String versionSqlText = StringUtils.EMPTY;
    if (EScheduleJobType.SPARK_SQL.getVal().intValue() == task.getTaskType().intValue()) {
        // 语法检测
        List<BatchTaskParam> taskParamsToReplace = batchTaskParamService.getTaskParam(task.getId());
        versionSqlText = this.jobParamReplace.paramReplace(task.getSqlText(), taskParamsToReplace, this.sdf.format(new Date()));
        // 避免重复校验
        CheckSyntaxResult syntaxResult = batchSqlExeService.processSqlText(task.getTenantId(), task.getTaskType(), versionSqlText);
        if (!syntaxResult.getCheckResult()) {
            checkVo.setErrorSign(PublishTaskStatusEnum.CHECKSYNTAXERROR.getType());
            checkVo.setErrorMessage(syntaxResult.getMessage());
            return checkVo;
        }
    } else if (EScheduleJobType.SYNC.getVal().intValue() == task.getTaskType().intValue()) {
        if (StringUtils.isNotEmpty(task.getSqlText())) {
            final JSONObject jsonTask = JSON.parseObject(Base64Util.baseDecode(task.getSqlText()));
            Integer createModelType = Integer.valueOf(jsonTask.getString("createModel"));
            JSONObject job = jsonTask.getJSONObject("job");
            if (Objects.isNull(job)) {
                throw new RdosDefineException(String.format("数据同步任务:%s 未配置", task.getName()));
            }
            // 检测job格式
            SyncJobCheck.checkJobFormat(job.toJSONString(), createModelType);
            versionSqlText = jsonTask.getString("job");
        }
    }
    version.setSqlText(versionSqlText);
    version.setOriginSql(task.getSqlText());
    version.setTenantId(task.getTenantId());
    version.setTaskId(task.getId());
    // 任务的版本号
    version.setVersion(task.getVersion());
    version.setTaskParams(task.getTaskParams());
    version.setScheduleConf(task.getScheduleConf());
    version.setScheduleStatus(task.getScheduleStatus());
    version.setGmtModified(task.getGmtModified());
    String dependencyTaskIds = StringUtils.EMPTY;
    final List<BatchTaskTask> taskTasks = this.batchTaskTaskService.getAllParentTask(task.getId());
    if (CollectionUtils.isNotEmpty(taskTasks)) {
        List<Map<String, Object>> parentTasks = taskTasks.stream().map(taskTask -> {
            Map<String, Object> map = Maps.newHashMap();
            map.put("parentTaskId", taskTask.getParentTaskId());
            return map;
        }).collect(Collectors.toList());
        dependencyTaskIds = JSON.toJSONString(parentTasks);
    }
    version.setDependencyTaskIds(dependencyTaskIds);
    version.setPublishDesc(null == publishDesc ? "" : publishDesc);
    // 插入一条记录信息
    batchTaskVersionService.insert(version);
    task.setVersion(version.getId().intValue());
    return checkVo;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Arrays(java.util.Arrays) SourceDTOType(com.dtstack.taier.develop.enums.develop.SourceDTOType) DependencyType(com.dtstack.taier.common.enums.DependencyType) TaskParamTemplate(com.dtstack.taier.dao.domain.TaskParamTemplate) ISourceDTO(com.dtstack.dtcenter.loader.dto.source.ISourceDTO) CatalogueType(com.dtstack.taier.common.enums.CatalogueType) Autowired(org.springframework.beans.factory.annotation.Autowired) KerberosConfigVerify(com.dtstack.taier.common.kerberos.KerberosConfigVerify) JSONPath(com.alibaba.fastjson.JSONPath) BooleanUtils(org.apache.commons.lang.BooleanUtils) SyncModel(com.dtstack.taier.develop.enums.develop.SyncModel) Matcher(java.util.regex.Matcher) ComponentService(com.dtstack.taier.scheduler.service.ComponentService) Pair(org.apache.commons.lang3.tuple.Pair) BatchReadWriteLock(com.dtstack.taier.dao.domain.BatchReadWriteLock) Map(java.util.Map) TaskCatalogueVO(com.dtstack.taier.develop.dto.devlop.TaskCatalogueVO) TaskGetNotDeleteVO(com.dtstack.taier.develop.dto.devlop.TaskGetNotDeleteVO) DevelopTaskDao(com.dtstack.taier.dao.mapper.DevelopTaskDao) ScheduleTaskShade(com.dtstack.taier.dao.domain.ScheduleTaskShade) DictType(com.dtstack.taier.common.enums.DictType) Strings(com.dtstack.taier.common.util.Strings) BatchTaskVersionDetailDTO(com.dtstack.taier.dao.dto.BatchTaskVersionDetailDTO) Resource(javax.annotation.Resource) PublishTaskStatusEnum(com.dtstack.taier.common.enums.PublishTaskStatusEnum) AllProductGlobalSearchVO(com.dtstack.taier.develop.vo.develop.query.AllProductGlobalSearchVO) Set(java.util.Set) DatasourceService(com.dtstack.taier.develop.service.datasource.impl.DatasourceService) BatchTaskVersion(com.dtstack.taier.dao.domain.BatchTaskVersion) BatchResource(com.dtstack.taier.dao.domain.BatchResource) SyncJobCheck(com.dtstack.taier.develop.utils.develop.sync.job.SyncJobCheck) ScheduleTaskVO(com.dtstack.taier.scheduler.vo.ScheduleTaskVO) TypeReference(com.alibaba.fastjson.TypeReference) SqlQueryDTO(com.dtstack.dtcenter.loader.dto.SqlQueryDTO) PageQuery(com.dtstack.taier.dao.pager.PageQuery) BatchTaskBatchVO(com.dtstack.taier.develop.dto.devlop.BatchTaskBatchVO) EScheduleStatus(com.dtstack.taier.common.enums.EScheduleStatus) ScheduleFactory(com.dtstack.taier.develop.parser.ScheduleFactory) CheckSyntaxResult(com.dtstack.taier.develop.dto.devlop.CheckSyntaxResult) LocalDateTime(java.time.LocalDateTime) EnvironmentContext(com.dtstack.taier.common.env.EnvironmentContext) TenantService(com.dtstack.taier.develop.service.console.TenantService) SimpleDateFormat(java.text.SimpleDateFormat) IClient(com.dtstack.dtcenter.loader.client.IClient) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) MathUtil(com.dtstack.taier.pluginapi.util.MathUtil) ArrayList(java.util.ArrayList) UserDTO(com.dtstack.taier.dao.dto.UserDTO) JSONArray(com.alibaba.fastjson.JSONArray) Dict(com.dtstack.taier.dao.domain.Dict) FuncType(com.dtstack.taier.common.enums.FuncType) Tenant(com.dtstack.taier.dao.domain.Tenant) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) ClusterService(com.dtstack.taier.scheduler.service.ClusterService) DataSourceType(com.dtstack.dtcenter.loader.source.DataSourceType) TaskLockStatus(com.dtstack.taier.common.enums.TaskLockStatus) ErrorCode(com.dtstack.taier.common.exception.ErrorCode) TaskOperateType(com.dtstack.taier.develop.enums.develop.TaskOperateType) ScheduleTaskShadeDTO(com.dtstack.taier.scheduler.dto.schedule.ScheduleTaskShadeDTO) User(com.dtstack.taier.dao.domain.User) IOException(java.io.IOException) Sort(com.dtstack.taier.dao.pager.Sort) ScheduleDictService(com.dtstack.taier.scheduler.service.ScheduleDictService) File(java.io.File) BatchTaskResource(com.dtstack.taier.dao.domain.BatchTaskResource) JSON(com.alibaba.fastjson.JSON) PublicUtil(com.dtstack.taier.common.util.PublicUtil) BatchDataSource(com.dtstack.taier.dao.domain.BatchDataSource) ResourceRefType(com.dtstack.taier.common.enums.ResourceRefType) Preconditions(com.google.common.base.Preconditions) EScheduleJobType(com.dtstack.taier.common.enums.EScheduleJobType) SavaTaskDTO(com.dtstack.taier.scheduler.dto.schedule.SavaTaskDTO) UserService(com.dtstack.taier.develop.service.user.UserService) Date(java.util.Date) ListUtils(org.apache.commons.collections.ListUtils) LoggerFactory(org.slf4j.LoggerFactory) BatchTaskTask(com.dtstack.taier.dao.domain.BatchTaskTask) BatchTaskGetComponentVersionResultVO(com.dtstack.taier.develop.vo.develop.result.BatchTaskGetComponentVersionResultVO) ColumnMetaDTO(com.dtstack.dtcenter.loader.dto.ColumnMetaDTO) Base64Util(com.dtstack.taier.common.util.Base64Util) Component(com.dtstack.taier.dao.domain.Component) ScheduleCron(com.dtstack.taier.develop.parser.ScheduleCron) DateFormat(java.text.DateFormat) EDeployType(com.dtstack.taier.common.enums.EDeployType) PatternConstant(com.dtstack.taier.common.constant.PatternConstant) ESchedulePeriodType(com.dtstack.taier.develop.parser.ESchedulePeriodType) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) IKerberos(com.dtstack.dtcenter.loader.client.IKerberos) ClientCache(com.dtstack.dtcenter.loader.client.ClientCache) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) TaskCheckResultVO(com.dtstack.taier.develop.dto.devlop.TaskCheckResultVO) TaskResourceParam(com.dtstack.taier.develop.dto.devlop.TaskResourceParam) Objects(java.util.Objects) List(java.util.List) BatchSysParameter(com.dtstack.taier.dao.domain.BatchSysParameter) DevelopReadWriteLockDao(com.dtstack.taier.dao.mapper.DevelopReadWriteLockDao) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) JSONObject(com.alibaba.fastjson.JSONObject) PluginName(com.dtstack.taier.develop.utils.develop.sync.job.PluginName) Pattern(java.util.regex.Pattern) BatchAllProductGlobalReturnVO(com.dtstack.taier.develop.vo.develop.result.BatchAllProductGlobalReturnVO) Deleted(com.dtstack.taier.common.enums.Deleted) BeanUtils(org.springframework.beans.BeanUtils) HashMap(java.util.HashMap) BatchCatalogue(com.dtstack.taier.dao.domain.BatchCatalogue) HashSet(java.util.HashSet) TaskCreateModelType(com.dtstack.taier.develop.enums.develop.TaskCreateModelType) CollectionUtils(org.apache.commons.collections.CollectionUtils) TaskParamTemplateService(com.dtstack.taier.develop.service.task.TaskParamTemplateService) Constant(com.dtstack.taier.develop.utils.develop.common.enums.Constant) DtCenterDefException(com.dtstack.taier.common.exception.DtCenterDefException) BatchTask(com.dtstack.taier.dao.domain.BatchTask) TaskService(com.dtstack.taier.develop.service.schedule.TaskService) Logger(org.slf4j.Logger) MapUtils(org.apache.commons.collections.MapUtils) DataFilter(com.dtstack.taier.common.util.DataFilter) ReadWriteLockType(com.dtstack.taier.common.enums.ReadWriteLockType) BatchTaskDTO(com.dtstack.taier.dao.dto.BatchTaskDTO) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Maps(com.google.common.collect.Maps) EComponentType(com.dtstack.taier.common.enums.EComponentType) ReadWriteLockVO(com.dtstack.taier.develop.dto.devlop.ReadWriteLockVO) BatchTaskParam(com.dtstack.taier.dao.domain.BatchTaskParam) Comparator(java.util.Comparator) ESubmitStatus(com.dtstack.taier.common.enums.ESubmitStatus) JsonUtils(com.dtstack.taier.common.util.JsonUtils) Transactional(org.springframework.transaction.annotation.Transactional) BatchTaskVersion(com.dtstack.taier.dao.domain.BatchTaskVersion) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) CheckSyntaxResult(com.dtstack.taier.develop.dto.devlop.CheckSyntaxResult) Date(java.util.Date) BatchTaskTask(com.dtstack.taier.dao.domain.BatchTaskTask) JSONObject(com.alibaba.fastjson.JSONObject) BatchTaskParam(com.dtstack.taier.dao.domain.BatchTaskParam) TaskCheckResultVO(com.dtstack.taier.develop.dto.devlop.TaskCheckResultVO) Map(java.util.Map) HashMap(java.util.HashMap)

Example 20 with BatchTask

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

the class BatchTaskService method publishBatchTaskInfo.

/**
 * 批量发布任务至engine
 * @param publishTask 要发布的task集合
 * @param tenantId 项目id
 * @param userId 用户id
 * @param publishDesc 发布描述
 * @param isRoot 是否是管理员
 * @param ignoreCheck 忽略检查
 * @return 发布结果
 */
public TaskCheckResultVO publishBatchTaskInfo(BatchTask publishTask, Long tenantId, Long userId, String publishDesc, Boolean isRoot, Boolean ignoreCheck) {
    // 判断任务责任人是否存在 如果任务责任人不存在或无权限 不允许提交
    User user = userService.getById(publishTask.getCreateUserId());
    if (user == null) {
        throw new RdosDefineException(String.format("%s任务责任人在数栈中不存在", publishTask.getName()));
    }
    TaskCheckResultVO checkResultVO = new TaskCheckResultVO();
    checkResultVO.setErrorSign(PublishTaskStatusEnum.NOMAL.getType());
    // 检查任务是否可以发布并记录版本信息
    TaskCheckResultVO resultVO = checkTaskAndSaveVersion(publishTask, tenantId, userId, publishDesc, isRoot, ignoreCheck);
    if (!PublishTaskStatusEnum.NOMAL.getType().equals(resultVO.getErrorSign())) {
        // 做一下优化 如果是工作流任务的话 把任务名称打印出来
        if (publishTask.getFlowId() > 0) {
            resultVO.setErrorMessage(String.format("任务:%s提交失败,原因是:%s", publishTask.getName(), resultVO.getErrorMessage()));
        }
        return resultVO;
    }
    // 发布任务中所有的依赖关系
    List<Long> parentTaskIds = Lists.newArrayList();
    ScheduleTaskShadeDTO scheduleTaskShadeDTO = buildScheduleTaskShadeDTO(publishTask, parentTaskIds);
    // 提交任务参数信息并保存任务记录和更新任务状态
    try {
        BatchTask batchTask = getOneWithError(scheduleTaskShadeDTO.getTaskId());
        String extraInfo = this.batchJobService.getExtraInfo(batchTask, userId, null);
        scheduleTaskShadeDTO.setExtraInfo(extraInfo);
        // 无异常保存一条任务记录并更新任务状态
        saveRecordAndUpdateSubmitStatus(batchTask, tenantId, userId, TaskOperateType.COMMIT.getType(), ESubmitStatus.SUBMIT.getStatus());
    } catch (Exception e) {
        LOGGER.error("send task error {} ", scheduleTaskShadeDTO.getTaskId(), e);
        throw new RdosDefineException(String.format("任务提交异常:%s", e.getMessage()), e);
    }
    SavaTaskDTO savaTaskDTO = new SavaTaskDTO();
    savaTaskDTO.setScheduleTaskShadeDTO(scheduleTaskShadeDTO);
    savaTaskDTO.setParentTaskIdList(parentTaskIds);
    // 批量发布任务
    this.taskService.saveTask(savaTaskDTO);
    LOGGER.info("待发布任务参数提交完毕");
    return checkResultVO;
}
Also used : User(com.dtstack.taier.dao.domain.User) BatchTask(com.dtstack.taier.dao.domain.BatchTask) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) TaskCheckResultVO(com.dtstack.taier.develop.dto.devlop.TaskCheckResultVO) ScheduleTaskShadeDTO(com.dtstack.taier.scheduler.dto.schedule.ScheduleTaskShadeDTO) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) IOException(java.io.IOException) DtCenterDefException(com.dtstack.taier.common.exception.DtCenterDefException) SavaTaskDTO(com.dtstack.taier.scheduler.dto.schedule.SavaTaskDTO)

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