Search in sources :

Example 1 with BatchTaskBatchVO

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

the class BatchTaskService method getTaskById.

/**
 * 数据开发-根据任务id,查询详情
 *
 * @return
 * @author toutian
 */
public BatchTaskBatchVO getTaskById(final ScheduleTaskVO scheduleTaskVO) {
    final BatchTask task = this.developTaskDao.getOne(scheduleTaskVO.getId());
    if (task == null) {
        throw new RdosDefineException(ErrorCode.CAN_NOT_FIND_TASK);
    }
    final List<BatchResource> resources = this.batchTaskResourceService.getResources(scheduleTaskVO.getId(), ResourceRefType.MAIN_RES.getType());
    final List<BatchResource> refResourceIdList = this.batchTaskResourceService.getResources(scheduleTaskVO.getId(), ResourceRefType.DEPENDENCY_RES.getType());
    final BatchTaskBatchVO taskVO = new BatchTaskBatchVO(this.batchTaskTaskService.getForefathers(task));
    taskVO.setVersion(task.getVersion());
    if (task.getTaskType().intValue() == EScheduleJobType.SYNC.getVal().intValue()) {
        // 同步任务类型
        final String taskJson = Base64Util.baseDecode(task.getSqlText());
        if (StringUtils.isBlank(taskJson)) {
            // 向导模式存在为空的情况
            taskVO.setCreateModel(Constant.CREATE_MODEL_GUIDE);
            taskVO.setSqlText("");
        } else {
            final JSONObject obj = JSON.parseObject(taskJson);
            taskVO.setCreateModel(obj.get("createModel") == null ? Constant.CREATE_MODEL_GUIDE : Integer.parseInt(String.valueOf(obj.get("createModel"))));
            formatSqlText(taskVO, obj);
        }
    }
    this.setTaskOperatorModelAndOptions(taskVO, task);
    if (task.getFlowId() != null && task.getFlowId() > 0) {
        taskVO.setFlowId(task.getFlowId());
        final BatchTask flow = this.developTaskDao.getOne(task.getFlowId());
        if (flow != null) {
            taskVO.setFlowName(flow.getName());
        }
    }
    final BatchCatalogue catalogue = batchCatalogueService.getOne(task.getNodePid());
    if (catalogue != null) {
        taskVO.setNodePName(catalogue.getNodeName());
    }
    taskVO.setResourceList(resources);
    taskVO.setRefResourceList(refResourceIdList);
    PageQuery pageQuery = new PageQuery(1, 5, "gmt_create", Sort.DESC.name());
    List<BatchTaskVersionDetailDTO> taskVersions = batchTaskVersionService.listByTaskId(scheduleTaskVO.getId(), pageQuery).stream().map(ver -> {
        if (StringUtils.isNotBlank(ver.getOriginSql())) {
            if (task.getTaskType().intValue() == EScheduleJobType.SYNC.getVal().intValue()) {
                ver.setSqlText(ver.getSqlText());
            } else {
                ver.setSqlText(ver.getOriginSql());
            }
        }
        // 填充用户名称
        ver.setUserName(userService.getUserName(ver.getCreateUserId()));
        return ver;
    }).collect(Collectors.toList());
    taskVO.setTaskVersions(taskVersions);
    // 密码脱敏 --2019/10/25 茂茂-- 同步任务 密码脱敏 仅 向导模式 修改成 全部模式
    if (task.getTaskType().intValue() == EScheduleJobType.SYNC.getVal().intValue()) {
        try {
            taskVO.setSqlText(JsonUtils.formatJSON(DataFilter.passwordFilter(taskVO.getSqlText())));
        } catch (final Exception e) {
            LOGGER.error("同步任务json解析失败 taskId = {}", task.getId(), e);
            taskVO.setSqlText(DataFilter.passwordFilter(taskVO.getSqlText()));
        }
        for (BatchTaskVersionDetailDTO taskVersion : taskVO.getTaskVersions()) {
            try {
                taskVersion.setSqlText(JsonUtils.formatJSON(DataFilter.passwordFilter(taskVersion.getSqlText())));
            } catch (final Exception e) {
                LOGGER.error("同步任务json解析失败 taskVersionId = {}", taskVersion.getId(), e);
                taskVersion.setSqlText(DataFilter.passwordFilter(taskVersion.getSqlText()));
            }
        }
    }
    final ReadWriteLockVO readWriteLockVO = this.readWriteLockService.getDetail(scheduleTaskVO.getTenantId(), task.getId(), ReadWriteLockType.BATCH_TASK, scheduleTaskVO.getUserId(), task.getModifyUserId(), task.getGmtModified());
    taskVO.setReadWriteLockVO(readWriteLockVO);
    taskVO.setUserId(scheduleTaskVO.getUserId());
    setTaskVariables(taskVO, scheduleTaskVO.getId());
    final List<Long> userIds = new ArrayList<>();
    userIds.add(task.getCreateUserId());
    final Map<Long, User> userMap = userService.getUserMap(userIds);
    buildUserDTOInfo(userMap, taskVO);
    return taskVO;
}
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) User(com.dtstack.taier.dao.domain.User) BatchTask(com.dtstack.taier.dao.domain.BatchTask) PageQuery(com.dtstack.taier.dao.pager.PageQuery) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) ReadWriteLockVO(com.dtstack.taier.develop.dto.devlop.ReadWriteLockVO) ArrayList(java.util.ArrayList) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) IOException(java.io.IOException) DtCenterDefException(com.dtstack.taier.common.exception.DtCenterDefException) JSONObject(com.alibaba.fastjson.JSONObject) BatchTaskBatchVO(com.dtstack.taier.develop.dto.devlop.BatchTaskBatchVO) BatchResource(com.dtstack.taier.dao.domain.BatchResource) BatchTaskVersionDetailDTO(com.dtstack.taier.dao.dto.BatchTaskVersionDetailDTO) BatchCatalogue(com.dtstack.taier.dao.domain.BatchCatalogue)

Example 2 with BatchTaskBatchVO

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

the class BatchTaskTaskService method getForefathers.

/**
 * 展开上一个父节点
 *
 * @author toutian
 */
public ScheduleTaskVO getForefathers(BatchTask task) {
    BatchTaskBatchVO vo = new BatchTaskBatchVO();
    BeanUtils.copyProperties(task, vo);
    vo.setVersion(task.getVersion());
    vo.setCreateUser(userService.getUserByDTO(task.getCreateUserId()));
    vo.setModifyUser(userService.getUserByDTO(task.getModifyUserId()));
    vo.setTenantName(tenantService.getTenantById(task.getTenantId()).getTenantName());
    List<BatchTaskTask> taskTasks = developTaskTaskDao.listByTaskId(task.getId());
    if (CollectionUtils.isEmpty(taskTasks)) {
        return vo;
    }
    List<ScheduleTaskVO> fatherTaskVOs = Lists.newArrayList();
    for (BatchTaskTask taskTask : taskTasks) {
        Long parentTaskId = taskTask.getParentTaskId();
        ScheduleTaskShade taskShade = taskService.findTaskByTaskId(parentTaskId);
        if (taskShade != null) {
            ScheduleTaskVO scheduleTaskVO = new ScheduleTaskVO();
            BeanUtils.copyProperties(taskShade, scheduleTaskVO);
            scheduleTaskVO.setId(taskShade.getTaskId());
            scheduleTaskVO.setTenantName(tenantService.getByDtTenantId(taskShade.getTenantId()).getTenantName());
            fatherTaskVOs.add(scheduleTaskVO);
        }
    }
    vo.setTaskVOS(fatherTaskVOs);
    return vo;
}
Also used : BatchTaskTask(com.dtstack.taier.dao.domain.BatchTaskTask) BatchTaskBatchVO(com.dtstack.taier.develop.dto.devlop.BatchTaskBatchVO) ScheduleTaskVO(com.dtstack.taier.scheduler.vo.ScheduleTaskVO) ScheduleTaskShade(com.dtstack.taier.dao.domain.ScheduleTaskShade)

Example 3 with BatchTaskBatchVO

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

the class BatchTaskService method updateTask.

/**
 * 新增/更新任务
 *
 * @param task
 * @param isEditBaseInfo 如果是右键编辑的情况则不更新任务参数
 * @return
 */
@Transactional
public BatchTaskBatchVO updateTask(final BatchTaskBatchVO task, final Boolean isEditBaseInfo) {
    if (task.getName() == null) {
        throw new RdosDefineException("任务名称不能为空.", ErrorCode.INVALID_PARAMETERS);
    }
    if (!PublicUtil.matcher(task.getName(), TASK_PATTERN)) {
        throw new RdosDefineException("名称只能由字母、数据、中文、下划线组成", ErrorCode.INVALID_PARAMETERS);
    }
    task.setGmtModified(Timestamp.valueOf(LocalDateTime.now()));
    BatchTask batchTask = this.developTaskDao.getByName(task.getName(), task.getTenantId());
    boolean isAdd = false;
    if (task.getId() > 0) {
        // update
        BatchTask specialTask = getOneWithError(task.getId());
        if (task.getTaskType() == null) {
            task.setTaskType(specialTask.getTaskType());
        }
        String oriTaskName = specialTask.getName();
        if (batchTask != null && !batchTask.getId().equals(task.getId())) {
            throw new RdosDefineException(ErrorCode.NAME_ALREADY_EXIST);
        }
        BatchTask specialTask1 = new BatchTask();
        ReadWriteLockVO readWriteLockVO = this.readWriteLockService.dealWithLock(task.getTenantId(), task.getId(), ReadWriteLockType.BATCH_TASK, task.getUserId(), res -> {
            task.setCreateUser(null);
            task.setIsDeleted(Deleted.NORMAL.getStatus());
            if (task.getVersion() == null) {
                task.setVersion(0);
            }
            PublicUtil.copyPropertiesIgnoreNull(task, specialTask1);
            final Integer updateResult = this.developTaskDao.update(specialTask1);
            if (updateResult == 1) {
                task.setVersion(task.getVersion() + 1);
            }
            return updateResult;
        });
        task.setReadWriteLockVO(readWriteLockVO);
        // 如果是工作流任务 更新父节点调度类型时,需要同样更新子节点
        if (EScheduleJobType.WORK_FLOW.getVal().equals(task.getTaskType()) && task.getFlowId() == 0 && StringUtils.isNotEmpty(task.getScheduleConf())) {
            updateSonTaskPeriodType(task.getId(), task.getPeriodType(), task.getScheduleConf());
        }
        if (!oriTaskName.equals(task.getName())) {
            // 修改名字需要同步到taskShade
            this.taskService.updateTaskName(task.getId(), task.getName());
        }
        LOGGER.info("success update batchTask, taskId:{}", task.getId());
    } else {
        if (batchTask != null) {
            throw new RdosDefineException(ErrorCode.NAME_ALREADY_EXIST);
        }
        // 初始化task的一些属性
        isAdd = initTaskInfo(task);
        BatchTask insertTask = new BatchTask();
        BeanUtils.copyProperties(task, insertTask);
        // 如果是工作流获取父任务的锁 用来保证父任务一定会更新成功 这里有并发问题 如果同时对一个工作流添加子任务 会丢失
        if (task.getFlowId() > 0) {
            BatchTask parentTask = developTaskDao.getOne(task.getFlowId());
            BatchReadWriteLock readWriteLock = developReadWriteLockDao.getByTenantIdAndRelationIdAndType(0L, parentTask.getId(), ReadWriteLockType.BATCH_TASK.name());
            if (readWriteLock == null) {
                throw new RdosDefineException("父任务锁不存在");
            }
            if (!readWriteLock.getVersion().equals(task.getParentReadWriteLockVersion())) {
                throw new RdosDefineException("当前任务已被修改,请重新打开任务后再次提交");
            }
        }
        developTaskDao.insert(insertTask);
        task.setTaskId(insertTask.getId());
        task.setId(insertTask.getId());
        // parseCreateTaskExeArgs(task);
        // 新增锁
        ReadWriteLockVO readWriteLockVO = this.readWriteLockService.getLock(task.getTenantId(), task.getUserId(), ReadWriteLockType.BATCH_TASK.name(), task.getId(), null);
        task.setReadWriteLockVO(readWriteLockVO);
        LOGGER.info("success insert batchTask, taskId:{}", task.getId());
    }
    // 右键编辑时会调用另一个接口
    if (BooleanUtils.isNotTrue(isEditBaseInfo)) {
        if (!EScheduleJobType.WORK_FLOW.getVal().equals(task.getTaskType()) && !EScheduleJobType.VIRTUAL.getVal().equals(task.getTaskType())) {
            // 新增加不校验自定义参数
            if (!isAdd) {
                this.batchTaskParamService.checkParams(task.getSqlText(), task.getTaskVariables());
            }
        }
        this.batchTaskParamService.addOrUpdateTaskParam(task);
    }
    final BatchTaskBatchVO batchTaskBatchVO = new BatchTaskBatchVO(task);
    batchTaskBatchVO.setReadWriteLockVO(task.getReadWriteLockVO());
    batchTaskBatchVO.setVersion(task.getVersion());
    return batchTaskBatchVO;
}
Also used : BatchTask(com.dtstack.taier.dao.domain.BatchTask) BatchTaskBatchVO(com.dtstack.taier.develop.dto.devlop.BatchTaskBatchVO) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) ReadWriteLockVO(com.dtstack.taier.develop.dto.devlop.ReadWriteLockVO) BatchReadWriteLock(com.dtstack.taier.dao.domain.BatchReadWriteLock) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with BatchTaskBatchVO

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

the class BatchTaskService method addOrUpdateTask.

/**
 * 数据开发-新建/更新 任务
 *
 * @param param 任务
 * @return
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 * @author toutian
 */
@Transactional(rollbackFor = Exception.class)
public TaskCatalogueVO addOrUpdateTask(final TaskResourceParam param) {
    // 检查密码回填操作
    this.checkFillPassword(param);
    // 数据预处理 主要是数据同步任务 生成sqlText
    this.checkBeforeUpdateTask(param);
    if (StringUtils.isNotBlank(param.getScheduleConf())) {
        // 处理调度配置
        JSONObject schduleConf = JSON.parseObject(param.getScheduleConf());
        if (schduleConf.get("isExpire") != null && "false".equals(schduleConf.get("isExpire").toString())) {
            schduleConf.replace("isLastInstance", true);
            param.setScheduleConf(schduleConf.toString());
        }
        param.setPeriodType(schduleConf.getInteger("periodType"));
    }
    if (param.getId() > 0 && param.getTaskType().equals(EScheduleJobType.WORK_FLOW.getVal())) {
        // 更新子任务间的依赖关系
        final String sqlText = param.getSqlText();
        if (StringUtils.isNotBlank(sqlText)) {
            final Map<Long, List<Long>> relations = this.parseTaskRelationsFromSqlText(sqlText);
            // 判断任务依赖是否成环
            if (MapUtils.isNotEmpty(relations)) {
                checkIsLoopByList(relations);
            }
            for (final Map.Entry<Long, List<Long>> entry : relations.entrySet()) {
                List<BatchTask> dependencyTasks = getTaskByIds(entry.getValue());
                dependencyTasks.stream().forEach(task -> {
                    task.setTenantId(param.getTenantId());
                });
                batchTaskTaskService.addOrUpdateTaskTask(entry.getKey(), dependencyTasks);
            }
        }
    }
    BatchTaskBatchVO task = PublicUtil.objectToObject(param, BatchTaskBatchVO.class);
    task.setModifyUserId(param.getUserId());
    task.setVersion(Objects.isNull(param.getVersion()) ? 0 : param.getVersion());
    task.parsePeriodType();
    task = this.updateTask(task, param.getEditBaseInfo());
    TaskCatalogueVO taskCatalogueVO = new TaskCatalogueVO(task, task.getNodePid());
    // 强行置为更新
    taskCatalogueVO.getReadWriteLockVO().setResult(TaskLockStatus.TO_UPDATE.getVal());
    // 更新 关联资源
    if (param.getResourceIdList() != null) {
        final Map<String, Object> params = Maps.newHashMap();
        params.put("id", task.getId());
        params.put("resources", param.getResourceIdList());
        params.put("createUserId", task.getCreateUserId());
        this.updateTaskResource(params);
    }
    if (param.getRefResourceIdList() != null) {
        final Map<String, Object> params = Maps.newHashMap();
        params.put("id", task.getId());
        params.put("refResource", param.getRefResourceIdList());
        params.put("createUserId", task.getCreateUserId());
        this.updateTaskRefResource(params);
    }
    final User user = userService.getById(task.getModifyUserId());
    if (user != null) {
        taskCatalogueVO.setCreateUser(user.getUserName());
    }
    final List<BatchTask> dependencyTasks = param.getDependencyTasks();
    if (dependencyTasks != null) {
        this.batchTaskTaskService.addOrUpdateTaskTask(task.getId(), dependencyTasks);
        taskCatalogueVO.setDependencyTasks(dependencyTasks);
    }
    String createUserName = userService.getUserName(task.getCreateUserId());
    taskCatalogueVO.setCreateUser(createUserName);
    taskCatalogueVO.setCatalogueType(CatalogueType.TASK_DEVELOP.getType());
    return taskCatalogueVO;
}
Also used : User(com.dtstack.taier.dao.domain.User) BatchTask(com.dtstack.taier.dao.domain.BatchTask) TaskCatalogueVO(com.dtstack.taier.develop.dto.devlop.TaskCatalogueVO) JSONObject(com.alibaba.fastjson.JSONObject) BatchTaskBatchVO(com.dtstack.taier.develop.dto.devlop.BatchTaskBatchVO) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(com.alibaba.fastjson.JSONObject) Map(java.util.Map) HashMap(java.util.HashMap) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with BatchTaskBatchVO

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

the class BatchTaskService method guideToTemplate.

/**
 * 向导模式转模版
 * @param param
 * @return
 * @throws Exception
 */
@Transactional
public TaskCatalogueVO guideToTemplate(final TaskResourceParam param) {
    final BatchTask task = this.developTaskDao.getOne(param.getId());
    BatchTaskBatchVO taskVO = new BatchTaskBatchVO();
    taskVO.setId(param.getId());
    taskVO.setName(task.getName());
    taskVO.setVersion(param.getVersion());
    taskVO.setUserId(param.getUserId());
    taskVO.setNodePid(task.getNodePid());
    taskVO.setReadWriteLockVO(param.getReadWriteLockVO());
    taskVO.setLockVersion(param.getLockVersion());
    taskVO.setTenantId(param.getTenantId());
    final JSONObject sqlJson = JSON.parseObject(Base64Util.baseDecode(task.getSqlText()));
    sqlJson.put("createModel", TaskCreateModelType.TEMPLATE.getType());
    taskVO.setSqlText(Base64Util.baseEncode(sqlJson.toJSONString()));
    taskVO = this.updateTask(taskVO, true);
    final TaskCatalogueVO taskCatalogueVO = new TaskCatalogueVO(taskVO, taskVO.getNodePid());
    return taskCatalogueVO;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) BatchTask(com.dtstack.taier.dao.domain.BatchTask) BatchTaskBatchVO(com.dtstack.taier.develop.dto.devlop.BatchTaskBatchVO) TaskCatalogueVO(com.dtstack.taier.develop.dto.devlop.TaskCatalogueVO) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

BatchTaskBatchVO (com.dtstack.taier.develop.dto.devlop.BatchTaskBatchVO)5 BatchTask (com.dtstack.taier.dao.domain.BatchTask)4 Transactional (org.springframework.transaction.annotation.Transactional)4 JSONObject (com.alibaba.fastjson.JSONObject)3 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)2 BatchReadWriteLock (com.dtstack.taier.dao.domain.BatchReadWriteLock)2 BatchTaskTask (com.dtstack.taier.dao.domain.BatchTaskTask)2 ScheduleTaskShade (com.dtstack.taier.dao.domain.ScheduleTaskShade)2 ReadWriteLockVO (com.dtstack.taier.develop.dto.devlop.ReadWriteLockVO)2 TaskCatalogueVO (com.dtstack.taier.develop.dto.devlop.TaskCatalogueVO)2 ScheduleTaskVO (com.dtstack.taier.scheduler.vo.ScheduleTaskVO)2 JSON (com.alibaba.fastjson.JSON)1 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONPath (com.alibaba.fastjson.JSONPath)1 TypeReference (com.alibaba.fastjson.TypeReference)1 ClientCache (com.dtstack.dtcenter.loader.client.ClientCache)1 IClient (com.dtstack.dtcenter.loader.client.IClient)1 IKerberos (com.dtstack.dtcenter.loader.client.IKerberos)1 ColumnMetaDTO (com.dtstack.dtcenter.loader.dto.ColumnMetaDTO)1 SqlQueryDTO (com.dtstack.dtcenter.loader.dto.SqlQueryDTO)1