Search in sources :

Example 6 with TaskRuleSimple

use of com.webank.wedatasphere.qualitis.entity.TaskRuleSimple in project Qualitis by WeBankFinTech.

the class TaskCheckResultResponse method partitionMultiRule.

private Map<String, List<Map<TaskRuleSimple, List<TaskDataSource>>>> partitionMultiRule(Map<TaskRuleSimple, List<TaskDataSource>> multiRuleDataSourceMap) {
    Map<String, List<Map<TaskRuleSimple, List<TaskDataSource>>>> result = new HashMap<>(8);
    for (TaskRuleSimple taskRuleSimple : multiRuleDataSourceMap.keySet()) {
        List<TaskDataSource> taskDataSources = multiRuleDataSourceMap.get(taskRuleSimple);
        String sourceDb = null;
        String sourceTable = null;
        String targetDb = null;
        String targetTable = null;
        for (TaskDataSource taskDataSource : taskDataSources) {
            if (taskDataSource.getDatasourceIndex() == 0) {
                sourceDb = taskDataSource.getDatabaseName();
                sourceTable = taskDataSource.getTableName();
            } else {
                targetDb = taskDataSource.getDatabaseName();
                targetTable = taskDataSource.getTableName();
            }
        }
        String key = sourceDb + "." + sourceTable + "." + targetDb + "." + targetTable;
        if (result.containsKey(key)) {
            List<Map<TaskRuleSimple, List<TaskDataSource>>> tmp = result.get(key);
            tmp.add(Collections.singletonMap(taskRuleSimple, taskDataSources));
        } else {
            List<Map<TaskRuleSimple, List<TaskDataSource>>> tmp = new ArrayList<>();
            tmp.add(Collections.singletonMap(taskRuleSimple, taskDataSources));
            result.put(key, tmp);
        }
    }
    return result;
}
Also used : TaskDataSource(com.webank.wedatasphere.qualitis.entity.TaskDataSource) TaskRuleSimple(com.webank.wedatasphere.qualitis.entity.TaskRuleSimple)

Example 7 with TaskRuleSimple

use of com.webank.wedatasphere.qualitis.entity.TaskRuleSimple in project Qualitis by WeBankFinTech.

the class OuterExecutionServiceImpl method commonExecution.

@Override
public ApplicationTaskSimpleResponse commonExecution(List<Rule> rules, StringBuffer partition, String executionUser, String nodeName, String startupParam, String clusterName, String setFlag, Map<String, String> execParams, Application newApplication, Date date, StringBuffer runDate) throws RuleVariableNotSupportException, JobSubmitException, RuleVariableNotFoundException, ArgumentException, ConvertException, DataQualityTaskException, TaskTypeException, ClusterInfoNotConfigException, SystemConfigException, UnExpectedRequestException, MetaDataAcquireFailedException, IOException, TaskNotExistException, SemanticException, ParseException, DataSourceMoveException, DataSourceOverSizeException, org.apache.hadoop.hive.ql.parse.ParseException, BothNullDatasourceException, RightNullDatasourceException, LeftNullDatasourceException, java.text.ParseException {
    // current user
    String userName = executionUser;
    // Generate database name.
    String database = generateDatabase(userName);
    LOGGER.info("Succeed to generate database_name: {}", database);
    // Save application
    newApplication.setRuleSize(rules.size());
    newApplication.setSavedDb(database);
    Application saveApplication = applicationDao.saveApplication(newApplication);
    List<TaskSubmitResult> taskSubmitResults = new ArrayList<>();
    List<Rule> fileRules = new ArrayList<>();
    Map<Long, Map> dataSourceMysqlConnect = new HashMap<>(2);
    for (Iterator<Rule> iterator = rules.iterator(); iterator.hasNext(); ) {
        Rule currentRule = iterator.next();
        if (currentRule.getRuleType().equals(RuleTypeEnum.CUSTOM_RULE.getCode())) {
            // Replace with execution parameter and parse datasource to save.
            customReSaveDateSource(currentRule, execParams, clusterName, date);
        }
        List<Map<String, String>> mappingCols = new ArrayList<>();
        getMappingCols(currentRule, mappingCols);
        // Check datasource before submit job.
        try {
            checkDatasource(currentRule, userName, partition, mappingCols, nodeName, clusterName, dataSourceMysqlConnect);
        } catch (BothNullDatasourceException e) {
            Task taskInDb = taskDao.save(new Task(newApplication, newApplication.getSubmitTime(), TaskStatusEnum.SUCCEED.getCode()));
            taskInDb.setClusterName(clusterName);
            TaskRuleSimple taskRuleSimple = new TaskRuleSimple(currentRule, taskInDb);
            Set<TaskDataSource> taskDataSources = new HashSet<>(fileRules.size());
            Set<TaskRuleSimple> taskRuleSimples = new HashSet<>(fileRules.size());
            taskRuleSimples.add(taskRuleSimpleRepository.save(taskRuleSimple));
            for (RuleDataSource ruleDataSource : currentRule.getRuleDataSources()) {
                taskDataSources.add(taskDataSourceRepository.save(new TaskDataSource(ruleDataSource, taskInDb)));
            }
            taskInDb.setEndTime(ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date()));
            taskInDb.setTaskDataSources(taskDataSources);
            taskInDb.setTaskRuleSimples(taskRuleSimples);
            TaskResult taskResult = new TaskResult();
            taskResult.setApplicationId(newApplication.getId());
            taskResult.setCreateTime(newApplication.getSubmitTime());
            taskResult.setRuleId(currentRule.getId());
            taskResult.setResultType("Long");
            taskResult.setValue(0 + "");
            taskResultDao.saveTaskResult(taskResult);
            taskDao.save(taskInDb);
            iterator.remove();
            if (!iterator.hasNext()) {
                throw e;
            }
            continue;
        }
        if (currentRule.getRuleType().equals(RuleTypeEnum.FILE_TEMPLATE_RULE.getCode())) {
            fileRules.add(currentRule);
            LOGGER.info("Succeed to find file rule. Rule: {}", currentRule.getId() + " " + currentRule.getName());
            iterator.remove();
        }
    }
    String submitTime = ExecutionManagerImpl.PRINT_TIME_FORMAT.format(date);
    // General task.
    if (!rules.isEmpty()) {
        taskSubmitResults.addAll(executionManager.submitApplication(rules, nodeName, submitTime, userName, database, partition, date, saveApplication, clusterName, startupParam, setFlag, execParams, runDate, dataSourceMysqlConnect));
    }
    // Execute file rule task and save task result.
    if (!fileRules.isEmpty()) {
        taskSubmitResults.add(executionManager.executeFileRule(fileRules, submitTime, saveApplication, userName, clusterName, runDate));
    }
    saveApplication.setTotalTaskNum(taskSubmitResults.size());
    LOGGER.info("Succeed to submit application. result: {}", taskSubmitResults);
    Application applicationInDb = applicationDao.saveApplication(saveApplication);
    LOGGER.info("Succeed to save application. application: {}", applicationInDb);
    return new ApplicationTaskSimpleResponse(taskSubmitResults);
}
Also used : Task(com.webank.wedatasphere.qualitis.entity.Task) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) ApplicationTaskSimpleResponse(com.webank.wedatasphere.qualitis.response.ApplicationTaskSimpleResponse) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(java.util.Date) TaskDataSource(com.webank.wedatasphere.qualitis.entity.TaskDataSource) BothNullDatasourceException(com.webank.wedatasphere.qualitis.exception.BothNullDatasourceException) TaskResult(com.webank.wedatasphere.qualitis.entity.TaskResult) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) Application(com.webank.wedatasphere.qualitis.entity.Application) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) TaskRuleSimple(com.webank.wedatasphere.qualitis.entity.TaskRuleSimple) TaskSubmitResult(com.webank.wedatasphere.qualitis.bean.TaskSubmitResult)

Aggregations

TaskRuleSimple (com.webank.wedatasphere.qualitis.entity.TaskRuleSimple)7 Task (com.webank.wedatasphere.qualitis.entity.Task)5 TaskDataSource (com.webank.wedatasphere.qualitis.entity.TaskDataSource)5 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)4 TaskResult (com.webank.wedatasphere.qualitis.entity.TaskResult)3 TaskRule (com.webank.wedatasphere.qualitis.bean.TaskRule)2 TaskRuleDataSource (com.webank.wedatasphere.qualitis.bean.TaskRuleDataSource)2 TaskSubmitResult (com.webank.wedatasphere.qualitis.bean.TaskSubmitResult)2 Application (com.webank.wedatasphere.qualitis.entity.Application)2 TaskRuleAlarmConfig (com.webank.wedatasphere.qualitis.entity.TaskRuleAlarmConfig)2 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)2 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)2 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 ExcelWriter (com.alibaba.excel.ExcelWriter)1 Sheet (com.alibaba.excel.metadata.Sheet)1 DataQualityTask (com.webank.wedatasphere.qualitis.bean.DataQualityTask)1 TaskDao (com.webank.wedatasphere.qualitis.dao.TaskDao)1