Search in sources :

Example 1 with BatchTaskParam

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

the class BatchTaskParamService method getTaskParam.

public List<BatchTaskParam> getTaskParam(final long taskId) {
    List<BatchTaskParam> taskParams = developTaskParamDao.listByTaskId(taskId);
    // 特殊处理 TaskParam 系统参数
    for (BatchTaskParam taskParamShade : taskParams) {
        if (!EParamType.SYS_TYPE.getType().equals(taskParamShade.getType())) {
            continue;
        }
        // 将 command 属性设置为系统表的 command
        BatchSysParameter sysParameter = batchSysParamService.getBatchSysParamByName(taskParamShade.getParamName());
        taskParamShade.setParamCommand(sysParameter.getParamCommand());
    }
    return taskParams;
}
Also used : BatchTaskParam(com.dtstack.taier.dao.domain.BatchTaskParam) BatchSysParameter(com.dtstack.taier.dao.domain.BatchSysParameter)

Example 2 with BatchTaskParam

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

the class BatchTaskParamService method checkParams.

/**
 * 校验任务中的 系统参数 和 自定义参数
 * @param jobContent SQL内容
 * @param parameterSet 任务参数
 */
public void checkParams(final String jobContent, final List parameterSet) {
    // 校验任务参数不能为空参数
    if (CollectionUtils.isNotEmpty(parameterSet)) {
        for (Object paramObj : parameterSet) {
            BatchTaskParam batchTaskParam = PublicUtil.objectToObject(paramObj, BatchTaskParam.class);
            if (batchTaskParam != null) {
                if (StringUtils.isBlank(batchTaskParam.getParamCommand()) || "$[]".equalsIgnoreCase(batchTaskParam.getParamCommand())) {
                    throw new RdosDefineException("自定义参数赋值不能为空");
                }
            }
        }
    }
    String jobStr = jobContent;
    if (StringUtils.isBlank(jobStr)) {
        return;
    }
    // 校验任务参数时,先清除sql中的注释
    String sqlWithoutComments = this.batchSqlExeService.removeComment(jobStr);
    if (StringUtils.isNotEmpty(sqlWithoutComments)) {
        sqlWithoutComments = sqlWithoutComments.replaceAll("\\s*", "");
    }
    // 校验任务参数时,先删除 数据同步任务 配置项
    if (sqlWithoutComments.contains(FormNames.HBASE_CONFIG) || sqlWithoutComments.contains(FormNames.HADOOP_CONFIG) || sqlWithoutComments.contains(FormNames.KERBEROS_CONFIG)) {
        sqlWithoutComments = removeConfig(sqlWithoutComments);
    }
    // 正则解析SQL中的 系统参数 和 自定义参数
    Matcher matcher = PARAM_REGEX_PATTERN.matcher(sqlWithoutComments);
    if (matcher.find()) {
        if (CollectionUtils.isEmpty(parameterSet)) {
            LOGGER.error("jobContent:{}", jobContent);
            throw new RdosDefineException(ErrorCode.TASK_PARAM_CONTENT_NOT_NULL);
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) BatchTaskParam(com.dtstack.taier.dao.domain.BatchTaskParam) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) JSONObject(com.alibaba.fastjson.JSONObject)

Example 3 with BatchTaskParam

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

the class BatchTaskService method buildScheduleTaskShadeDTO.

/**
 * 构建一个要发布到engine的任务DTO {@link ScheduleTaskShadeDTO}
 * @param batchTask 要发布的任务集合
 * @param parentTaskIds 父任务的id
 * @return 调度任务DTO
 */
private ScheduleTaskShadeDTO buildScheduleTaskShadeDTO(final BatchTask batchTask, List<Long> parentTaskIds) {
    if (batchTask.getId() <= 0) {
        // 只有异常情况才会走到该逻辑
        throw new RdosDefineException("batchTask id can't be 0", ErrorCode.SERVER_EXCEPTION);
    }
    final long taskId = batchTask.getId();
    // 清空任务关联的batch_task_param, task_resource, task_task 表信息
    this.batchTaskParamShadeService.clearDataByTaskId(taskId);
    this.batchTaskResourceShadeService.clearDataByTaskId(taskId);
    final List<BatchTaskParam> batchTaskParamList = this.batchTaskParamService.getTaskParam(batchTask.getId());
    // 查询出任务所有的关联的资源(运行主体资源和依赖引用资源)
    final List<BatchTaskResource> batchTaskResourceList = this.batchTaskResourceService.getTaskResources(batchTask.getId(), null);
    List<Long> parentTaskList = this.batchTaskTaskService.getAllParentTaskId(batchTask.getId());
    parentTaskIds.addAll(parentTaskList);
    if (!CollectionUtils.isEmpty(batchTaskResourceList)) {
        this.batchTaskResourceShadeService.saveTaskResource(batchTaskResourceList);
    }
    // 保存batch_task_shade
    final ScheduleTaskShadeDTO scheduleTaskShadeDTO = new ScheduleTaskShadeDTO();
    BeanUtils.copyProperties(batchTask, scheduleTaskShadeDTO);
    scheduleTaskShadeDTO.setTaskId(batchTask.getId());
    scheduleTaskShadeDTO.setScheduleStatus(EScheduleStatus.NORMAL.getVal());
    if (!CollectionUtils.isEmpty(batchTaskParamList)) {
        this.batchTaskParamShadeService.saveTaskParam(batchTaskParamList);
    } else {
        scheduleTaskShadeDTO.setTaskParams("");
    }
    return scheduleTaskShadeDTO;
}
Also used : BatchTaskResource(com.dtstack.taier.dao.domain.BatchTaskResource) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) BatchTaskParam(com.dtstack.taier.dao.domain.BatchTaskParam) ScheduleTaskShadeDTO(com.dtstack.taier.scheduler.dto.schedule.ScheduleTaskShadeDTO)

Example 4 with BatchTaskParam

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

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

the class BatchTaskParamService method buildBatchTaskParams.

public List<BatchTaskParam> buildBatchTaskParams(final long taskId, final List<BatchParamDTO> batchParamDTOS) {
    final List<BatchTaskParam> saves = new ArrayList<>(batchParamDTOS.size());
    for (final BatchParamDTO tmp : batchParamDTOS) {
        if (StringUtils.isBlank(tmp.getParamCommand())) {
            throw new RdosDefineException("自定义参数赋值不能为空");
        }
        BatchTaskParam batchTaskParam = new BatchTaskParam();
        batchTaskParam.setTaskId(taskId);
        batchTaskParam.setType(tmp.getType());
        batchTaskParam.setParamName(tmp.getParamName());
        batchTaskParam.setParamCommand(tmp.getParamCommand());
        saves.add(this.addOrUpdate(batchTaskParam));
    }
    return saves;
}
Also used : BatchParamDTO(com.dtstack.taier.develop.dto.devlop.BatchParamDTO) BatchTaskParam(com.dtstack.taier.dao.domain.BatchTaskParam) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) ArrayList(java.util.ArrayList)

Aggregations

BatchTaskParam (com.dtstack.taier.dao.domain.BatchTaskParam)8 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)5 JSONObject (com.alibaba.fastjson.JSONObject)3 ArrayList (java.util.ArrayList)3 DataSourceType (com.dtstack.dtcenter.loader.source.DataSourceType)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)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 ISourceDTO (com.dtstack.dtcenter.loader.dto.source.ISourceDTO)1 PatternConstant (com.dtstack.taier.common.constant.PatternConstant)1 CatalogueType (com.dtstack.taier.common.enums.CatalogueType)1