Search in sources :

Example 1 with CheckSyntaxResult

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

the class BatchHadoopJobExeService method readyForTaskStartTrigger.

/**
 * 构建 exeArgs、sqlText、taskParams
 * @param actionParam
 * @param tenantId
 * @param batchTask
 * @param taskParamsToReplace
 * @throws Exception
 */
@Override
public void readyForTaskStartTrigger(Map<String, Object> actionParam, Long tenantId, BatchTask batchTask, List<BatchTaskParamShade> taskParamsToReplace) throws Exception {
    String sql = batchTask.getSqlText() == null ? "" : batchTask.getSqlText();
    String taskParams = batchTask.getTaskParams();
    if (EScheduleJobType.SPARK_SQL.getVal().equals(batchTask.getTaskType())) {
        // Spark SQL任务默认在前面加上建表的类型
        sql = String.format("set hive.default.fileformat=%s;\n ", environmentContext.getCreateTableType()) + sql;
        batchTaskParamService.checkParams(sql, taskParamsToReplace);
        // 构建运行的SQL
        CheckSyntaxResult result = batchSqlExeService.processSqlText(tenantId, batchTask.getTaskType(), sql);
        sql = result.getSql();
    } else if (EScheduleJobType.SYNC.getVal().equals(batchTask.getTaskType())) {
        JSONObject syncJob = JSON.parseObject(Base64Util.baseDecode(batchTask.getSqlText()));
        taskParams = replaceSyncParll(taskParams, parseSyncChannel(syncJob));
        String job = syncJob.getString("job");
        // 向导模式根据job中的sourceId填充数据源信息,保证每次运行取到最新的连接信息
        job = datasourceService.setJobDataSourceInfo(job, tenantId, syncJob.getIntValue("createModel"));
        batchTaskParamService.checkParams(batchTaskParamService.checkSyncJobParams(job), taskParamsToReplace);
        actionParam.put("job", job);
    }
    actionParam.put("sqlText", sql);
    actionParam.put("taskParams", taskParams);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) CheckSyntaxResult(com.dtstack.taier.develop.dto.devlop.CheckSyntaxResult)

Example 2 with CheckSyntaxResult

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

the class BatchSqlExeService method processSqlText.

/**
 * 处理自定义函数 和 构建真正运行的SQL
 *
 * @param tenantId
 * @param taskType
 * @param sqlText
 * @return
 */
public CheckSyntaxResult processSqlText(final Long tenantId, Integer taskType, final String sqlText) {
    CheckSyntaxResult result = new CheckSyntaxResult();
    TenantComponent tenantEngine = this.developTenantComponentService.getByTenantAndEngineType(tenantId, taskType);
    Preconditions.checkNotNull(tenantEngine, String.format("tenantEngine %d not support task type %d", tenantId, taskType));
    ISqlExeService sqlExeService = this.multiEngineServiceFactory.getSqlExeService(taskType);
    // 处理自定义函数
    String sqlPlus = buildCustomFunctionSparkSql(sqlText, tenantId, taskType);
    // 构建真正运行的SQL,去掉注释,加上use db 同时格式化SQL
    String sqls = sqlExeService.process(sqlPlus, tenantEngine.getComponentIdentity());
    result.setSql(sqls);
    result.setCheckResult(true);
    return result;
}
Also used : ISqlExeService(com.dtstack.taier.develop.service.develop.ISqlExeService) TenantComponent(com.dtstack.taier.dao.domain.TenantComponent) CheckSyntaxResult(com.dtstack.taier.develop.dto.devlop.CheckSyntaxResult)

Example 3 with CheckSyntaxResult

use of com.dtstack.taier.develop.dto.devlop.CheckSyntaxResult 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)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)2 CheckSyntaxResult (com.dtstack.taier.develop.dto.devlop.CheckSyntaxResult)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 DataSourceType (com.dtstack.dtcenter.loader.source.DataSourceType)1 PatternConstant (com.dtstack.taier.common.constant.PatternConstant)1 CatalogueType (com.dtstack.taier.common.enums.CatalogueType)1 Deleted (com.dtstack.taier.common.enums.Deleted)1 DependencyType (com.dtstack.taier.common.enums.DependencyType)1 DictType (com.dtstack.taier.common.enums.DictType)1 EComponentType (com.dtstack.taier.common.enums.EComponentType)1 EDeployType (com.dtstack.taier.common.enums.EDeployType)1