Search in sources :

Example 1 with TaskRuleAlarmConfig

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

the class ExecutionManagerImpl method modifyTaskStatus.

private int modifyTaskStatus(List<TaskRuleAlarmConfig> alarmConfigs, Task taskInDb, List<TaskResult> taskResults, int successRule) {
    boolean rulePass = true;
    for (TaskRuleAlarmConfig alarmConfig : alarmConfigs) {
        TaskResult taskResult = taskResults.stream().filter(taskResultInDb -> taskResultInDb.getRuleMetricId().equals(alarmConfig.getRuleMetric().getId())).iterator().next();
        if (!FilePassUtil.pass(alarmConfig, taskResult, taskResultDao)) {
            rulePass = false;
            alarmConfig.setStatus(AlarmConfigStatusEnum.NOT_PASS.getCode());
            if (alarmConfig.getDeleteFailCheckResult() != null && alarmConfig.getDeleteFailCheckResult()) {
                taskResult.setSaveResult(false);
                taskResultDao.saveTaskResult(taskResult);
            }
        } else {
            alarmConfig.setStatus(AlarmConfigStatusEnum.PASS.getCode());
        }
    }
    if (rulePass) {
        successRule++;
    } else if (taskInDb.getAbortOnFailure() != null && taskInDb.getAbortOnFailure()) {
        taskInDb.setStatus(TaskStatusEnum.FAILED.getCode());
    } else {
        taskInDb.setStatus(TaskStatusEnum.FAIL_CHECKOUT.getCode());
        taskInDb.setProgress(Double.parseDouble("1"));
    }
    return successRule;
}
Also used : TaskRuleAlarmConfig(com.webank.wedatasphere.qualitis.entity.TaskRuleAlarmConfig) TaskResult(com.webank.wedatasphere.qualitis.entity.TaskResult)

Example 2 with TaskRuleAlarmConfig

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

the class OuterExecutionServiceImpl method getApplicationResult.

@Override
public GeneralResponse<?> getApplicationResult(String applicationId) throws UnExpectedRequestException {
    // Find application by applicationId
    Application applicationInDb = applicationDao.findById(applicationId);
    if (applicationInDb == null) {
        throw new UnExpectedRequestException(String.format("ApplicationId: %s {&DOES_NOT_EXIST}", applicationId));
    }
    Integer passNum = 0;
    Integer failedNum = 0;
    Integer notPassNum = 0;
    StringBuilder passMessage = new StringBuilder();
    StringBuilder failedMessage = new StringBuilder();
    StringBuilder notPassMessage = new StringBuilder();
    passMessage.append("The rules following below are pass(以下规则已通过校验): [");
    failedMessage.append("The rules following below are failed(以下规则已失败): [");
    notPassMessage.append("The rules following below are failed(以下规则未通过校验): [");
    // Find all tasks by application
    List<Task> tasks = taskDao.findByApplication(applicationInDb);
    // Find task rule simple in all tasks
    for (Task task : tasks) {
        // Add failed num, pass num if task status equals to Succeed, Failed
        if (task.getStatus().equals(TaskStatusEnum.FAILED.getCode())) {
            failedNum += task.getTaskRuleSimples().size();
            generateFailedMessage(task, failedMessage);
        } else if (task.getStatus().equals(TaskStatusEnum.PASS_CHECKOUT.getCode())) {
            passNum += task.getTaskRuleSimples().size();
            generatePassMessage(task, passMessage);
        } else if (task.getStatus().equals(TaskStatusEnum.FAIL_CHECKOUT.getCode())) {
            // Find not pass task if task status equals to failed_checkout
            for (TaskRuleSimple taskRuleSimple : task.getTaskRuleSimples()) {
                Boolean isPass = true;
                for (TaskRuleAlarmConfig taskRuleAlarmConfig : taskRuleSimple.getTaskRuleAlarmConfigList()) {
                    if (taskRuleAlarmConfig.getStatus().equals(AlarmConfigStatusEnum.NOT_PASS.getCode())) {
                        isPass = false;
                        break;
                    }
                }
                if (isPass) {
                    passNum++;
                    passMessage.append(taskRuleSimple.getRuleName()).append(", ");
                } else {
                    notPassNum++;
                    notPassMessage.append(taskRuleSimple.getRuleName()).append(", ");
                }
            }
        } else {
            throw new UnExpectedRequestException(String.format("ApplicationId: %s {&DOES_NOT_FINISHED_YET}", applicationId));
        }
    }
    passMessage.append("]").append(System.lineSeparator());
    failedMessage.append("]").append(System.lineSeparator());
    notPassMessage.append("]").append(System.lineSeparator());
    String resultMessage = passMessage.toString() + failedMessage.toString() + notPassMessage.toString();
    return new GeneralResponse<>("200", "{&SUCCEED_TO_GET_APPLICATION_RESULT}", new ApplicationResultResponse(passNum, failedNum, notPassNum, resultMessage));
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Task(com.webank.wedatasphere.qualitis.entity.Task) ApplicationResultResponse(com.webank.wedatasphere.qualitis.response.ApplicationResultResponse) TaskRuleAlarmConfig(com.webank.wedatasphere.qualitis.entity.TaskRuleAlarmConfig) Application(com.webank.wedatasphere.qualitis.entity.Application) TaskRuleSimple(com.webank.wedatasphere.qualitis.entity.TaskRuleSimple)

Example 3 with TaskRuleAlarmConfig

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

the class ApplicationServiceImpl method joinAlarmConfig.

private void joinAlarmConfig(List<ExcelResult> results, TaskRuleSimple taskRuleSimple, ExcelResult excelResult, UploadResultRequest request, StringBuffer checkTemplateStr, StringBuffer resultStr) {
    for (TaskRuleAlarmConfig taskRuleAlarmConfig : taskRuleSimple.getTaskRuleAlarmConfigList()) {
        Integer checkTemplate = taskRuleAlarmConfig.getCheckTemplate();
        String checkTemplateName = CheckTemplateEnum.getCheckTemplateName(checkTemplate);
        String outputName = taskRuleAlarmConfig.getOutputName();
        String compare = CompareTypeEnum.getCompareTypeName(taskRuleAlarmConfig.getCompareType());
        Double threshold = taskRuleAlarmConfig.getThreshold();
        Integer statusCode = taskRuleAlarmConfig.getStatus();
        String status = AlarmConfigStatusEnum.getMessage(statusCode);
        RuleMetric ruleMetric = taskRuleAlarmConfig.getRuleMetric();
        TaskResult taskResult = taskResultDao.find(taskRuleSimple.getApplicationId(), taskRuleSimple.getRuleId(), ruleMetric != null ? ruleMetric.getId() : -1);
        String resultValue = "";
        Long runDate = null;
        if (taskResult != null) {
            resultValue = StringUtils.isNotBlank(taskResult.getValue()) ? taskResult.getValue() : "0";
            runDate = taskResult.getRunDate();
        }
        if (request.getStatus().contains(statusCode)) {
            checkTemplateStr.append(checkTemplateName).append(StringUtils.isNotBlank(compare) ? compare : "").append(" ").append(threshold).append(" ").append(status);
            ExcelResult excelAlarmConfig = new ExcelResult();
            BeanUtils.copyProperties(excelResult, excelAlarmConfig);
            excelAlarmConfig.setRuleCheckTemplates(checkTemplateStr.toString());
            resultStr.append(outputName).append(": ").append(resultValue);
            excelAlarmConfig.setHistoryResult(resultStr.toString());
            excelAlarmConfig.setCreateTime(runDate != null ? runDate.toString() : "");
            excelAlarmConfig.setExecutionUser(taskRuleSimple.getExecuteUser());
            results.add(excelAlarmConfig);
            checkTemplateStr.delete(0, checkTemplateStr.length());
            resultStr.delete(0, checkTemplateStr.length());
        }
    }
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) TaskRuleAlarmConfig(com.webank.wedatasphere.qualitis.entity.TaskRuleAlarmConfig) ExcelResult(com.webank.wedatasphere.qualitis.excel.ExcelResult) TaskResult(com.webank.wedatasphere.qualitis.entity.TaskResult)

Example 4 with TaskRuleAlarmConfig

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

the class TaskServiceImpl method getTaskDetail.

@Override
public GeneralResponse<?> getTaskDetail(Long taskId) throws UnExpectedRequestException {
    Task taskInDb = taskDao.findById(taskId);
    if (taskInDb == null) {
        throw new UnExpectedRequestException("Job id [" + taskId + "] {&DOES_NOT_EXIST}");
    }
    // FIXME:
    List<TaskRuleAlarmConfig> distinct;
    Set<TaskRuleSimple> taskRuleSimples = new HashSet<>(taskInDb.getTaskRuleSimples().size());
    for (TaskRuleSimple taskRuleSimple : taskInDb.getTaskRuleSimples()) {
        distinct = taskRuleSimple.getTaskRuleAlarmConfigList().stream().distinct().collect(Collectors.toList());
        taskRuleSimple.setTaskRuleAlarmConfigList(distinct);
        taskRuleSimples.add(taskRuleSimple);
    }
    taskInDb.setTaskRuleSimples(taskRuleSimples);
    // Find single table verification rules
    List<TaskRuleSimple> singleRuleIds = taskInDb.getTaskRuleSimples().stream().filter(taskRuleSimple -> taskRuleSimple.getRuleType().equals(RuleTypeEnum.SINGLE_TEMPLATE_RULE.getCode())).collect(Collectors.toList());
    // Find all datasources of single table verification rules, and save it in the map
    Map<TaskRuleSimple, List<TaskDataSource>> singleRuleDataSourceMap = new HashMap<>(singleRuleIds.size());
    for (TaskRuleSimple taskRuleSimple : singleRuleIds) {
        singleRuleDataSourceMap.put(taskRuleSimple, taskDataSourceDao.findByTaskAndRuleId(taskInDb, taskRuleSimple.getRuleId()));
    }
    // Find custom table verification rules
    List<TaskRuleSimple> customRuleIds = taskInDb.getTaskRuleSimples().stream().filter(taskRuleSimple -> taskRuleSimple.getRuleType().equals(RuleTypeEnum.CUSTOM_RULE.getCode())).collect(Collectors.toList());
    // Find all datasources of custom table verification rules, and save it in the map
    Map<TaskRuleSimple, List<TaskDataSource>> customRuleDataSourceMap = new HashMap<>(customRuleIds.size());
    for (TaskRuleSimple taskRuleSimple : customRuleIds) {
        customRuleDataSourceMap.put(taskRuleSimple, taskDataSourceDao.findByTaskAndRuleId(taskInDb, taskRuleSimple.getRuleId()));
    }
    // Find multi-table verification rules
    List<TaskRuleSimple> multiRuleIds = taskInDb.getTaskRuleSimples().stream().filter(taskRuleSimple -> taskRuleSimple.getRuleType().equals(RuleTypeEnum.MULTI_TEMPLATE_RULE.getCode())).collect(Collectors.toList());
    // Find all datasources of multi-table verification rules, and save it in the map
    Map<TaskRuleSimple, List<TaskDataSource>> multiRuleDataSourceMap = new HashMap<>(multiRuleIds.size());
    for (TaskRuleSimple taskRuleSimple : multiRuleIds) {
        multiRuleDataSourceMap.put(taskRuleSimple, taskDataSourceDao.findByTaskAndRuleId(taskInDb, taskRuleSimple.getRuleId()));
    }
    // Find file table verification rules
    List<TaskRuleSimple> fileRuleIds = taskInDb.getTaskRuleSimples().stream().filter(taskRuleSimple -> taskRuleSimple.getRuleType().equals(RuleTypeEnum.FILE_TEMPLATE_RULE.getCode())).collect(Collectors.toList());
    // Find all datasources of file table verification rules, and save it in the map
    Map<TaskRuleSimple, List<TaskDataSource>> fileRuleDataSourceMap = new HashMap<>(fileRuleIds.size());
    for (TaskRuleSimple taskRuleSimple : fileRuleIds) {
        fileRuleDataSourceMap.put(taskRuleSimple, taskDataSourceDao.findByTaskAndRuleId(taskInDb, taskRuleSimple.getRuleId()));
    }
    List<Long> allRuleIds = new ArrayList<>();
    for (TaskRuleSimple taskRuleSimple : taskInDb.getTaskRuleSimples()) {
        allRuleIds.add(taskRuleSimple.getRuleId());
        if (taskRuleSimple.getChildRuleSimple() != null) {
            allRuleIds.add(taskRuleSimple.getChildRuleSimple().getRuleId());
        }
    }
    List<TaskResult> allTaskResult = taskResultDao.findByApplicationIdAndRuleIn(taskInDb.getApplication().getId(), allRuleIds);
    Map<Long, List<TaskResult>> allResultMap = new HashMap<>(allTaskResult.size());
    for (TaskResult taskResult : allTaskResult) {
        if (allResultMap.get(taskResult.getRuleId()) != null) {
            allResultMap.get(taskResult.getRuleId()).add(taskResult);
        } else {
            List<TaskResult> taskResults = new ArrayList<>(1);
            taskResults.add(taskResult);
            allResultMap.put(taskResult.getRuleId(), taskResults);
        }
    }
    TaskCheckResultResponse taskCheckResultResponse = new TaskCheckResultResponse(taskInDb, singleRuleDataSourceMap, customRuleDataSourceMap, multiRuleDataSourceMap, fileRuleDataSourceMap, allResultMap);
    return new GeneralResponse<>("200", "{&SUCCEED_TO_GET_TASK_DETAIL}", taskCheckResultResponse);
}
Also used : java.util(java.util) TaskService(com.webank.wedatasphere.qualitis.service.TaskService) TaskDataSourceDao(com.webank.wedatasphere.qualitis.dao.TaskDataSourceDao) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) RuleTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.RuleTypeEnum) TaskRuleSimple(com.webank.wedatasphere.qualitis.entity.TaskRuleSimple) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) TaskCheckResultResponse(com.webank.wedatasphere.qualitis.response.TaskCheckResultResponse) TaskDao(com.webank.wedatasphere.qualitis.dao.TaskDao) Task(com.webank.wedatasphere.qualitis.entity.Task) Service(org.springframework.stereotype.Service) TaskRuleAlarmConfig(com.webank.wedatasphere.qualitis.entity.TaskRuleAlarmConfig) TaskResultDao(com.webank.wedatasphere.qualitis.dao.TaskResultDao) TaskResult(com.webank.wedatasphere.qualitis.entity.TaskResult) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) TaskDataSource(com.webank.wedatasphere.qualitis.entity.TaskDataSource) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Task(com.webank.wedatasphere.qualitis.entity.Task) TaskCheckResultResponse(com.webank.wedatasphere.qualitis.response.TaskCheckResultResponse) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) TaskRuleAlarmConfig(com.webank.wedatasphere.qualitis.entity.TaskRuleAlarmConfig) TaskResult(com.webank.wedatasphere.qualitis.entity.TaskResult) TaskRuleSimple(com.webank.wedatasphere.qualitis.entity.TaskRuleSimple)

Example 5 with TaskRuleAlarmConfig

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

the class TaskChecker method checkTaskRuleSimplePass.

@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
private Boolean checkTaskRuleSimplePass(String applicationId, TaskRuleSimple taskRuleSimple) {
    Boolean passFlag = true;
    List<TaskResult> taskResults = taskResultDao.findByApplicationAndRule(applicationId, taskRuleSimple.getRuleId());
    for (TaskResult taskResult : taskResults) {
        List<TaskRuleAlarmConfig> taskRuleAlarmConfigList = taskRuleSimple.getTaskRuleAlarmConfigList();
        Long ruleMetricId = taskResult.getRuleMetricId();
        if (ruleMetricId != null && ruleMetricId.longValue() != -1) {
            taskRuleAlarmConfigList = taskRuleAlarmConfigList.stream().filter(taskRuleAlarmConfig -> taskRuleAlarmConfig.getRuleMetric().getId().equals(ruleMetricId)).collect(Collectors.toList());
        }
        for (TaskRuleAlarmConfig taskRuleAlarmConfig : taskRuleAlarmConfigList) {
            if (PassUtil.notSafe(applicationId, taskRuleSimple.getRuleId(), taskRuleAlarmConfig, taskResult, taskResultDao)) {
                taskRuleAlarmConfig.setStatus(AlarmConfigStatusEnum.PASS.getCode());
            } else {
                passFlag = false;
                taskRuleAlarmConfig.setStatus(AlarmConfigStatusEnum.NOT_PASS.getCode());
                if (taskRuleSimple.getRuleType().equals(RuleTemplateTypeEnum.CUSTOM.getCode())) {
                    if (taskRuleAlarmConfig.getDeleteFailCheckResult() != null && true == taskRuleAlarmConfig.getDeleteFailCheckResult().booleanValue()) {
                        taskResult.setSaveResult(false);
                        taskResultDao.saveTaskResult(taskResult);
                    }
                } else {
                    if (taskRuleSimple.getDeleteFailCheckResult() != null && true == taskRuleSimple.getDeleteFailCheckResult().booleanValue()) {
                        taskResult.setSaveResult(false);
                        taskResultDao.saveTaskResult(taskResult);
                    }
                }
            }
        }
    }
    return passFlag;
}
Also used : TaskRuleAlarmConfig(com.webank.wedatasphere.qualitis.entity.TaskRuleAlarmConfig) TaskResult(com.webank.wedatasphere.qualitis.entity.TaskResult) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

TaskRuleAlarmConfig (com.webank.wedatasphere.qualitis.entity.TaskRuleAlarmConfig)5 TaskResult (com.webank.wedatasphere.qualitis.entity.TaskResult)4 Task (com.webank.wedatasphere.qualitis.entity.Task)2 TaskRuleSimple (com.webank.wedatasphere.qualitis.entity.TaskRuleSimple)2 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)2 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)2 TaskDao (com.webank.wedatasphere.qualitis.dao.TaskDao)1 TaskDataSourceDao (com.webank.wedatasphere.qualitis.dao.TaskDataSourceDao)1 TaskResultDao (com.webank.wedatasphere.qualitis.dao.TaskResultDao)1 Application (com.webank.wedatasphere.qualitis.entity.Application)1 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)1 TaskDataSource (com.webank.wedatasphere.qualitis.entity.TaskDataSource)1 ExcelResult (com.webank.wedatasphere.qualitis.excel.ExcelResult)1 ApplicationResultResponse (com.webank.wedatasphere.qualitis.response.ApplicationResultResponse)1 TaskCheckResultResponse (com.webank.wedatasphere.qualitis.response.TaskCheckResultResponse)1 RuleTypeEnum (com.webank.wedatasphere.qualitis.rule.constant.RuleTypeEnum)1 TaskService (com.webank.wedatasphere.qualitis.service.TaskService)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1