Search in sources :

Example 1 with ExcelResult

use of com.webank.wedatasphere.qualitis.excel.ExcelResult 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 2 with ExcelResult

use of com.webank.wedatasphere.qualitis.excel.ExcelResult in project Qualitis by WeBankFinTech.

the class ApplicationServiceImpl method writeExcelFile.

private void writeExcelFile(File tmpFile, List<String> tables, UploadResultRequest request) throws UnExpectedRequestException {
    int sheetNo = 1;
    OutputStream tmpOutputStream = null;
    try {
        Path parentPath = Paths.get(tmpFile.getParent());
        if (Files.notExists(parentPath)) {
            tmpFile.getParentFile().mkdirs();
        }
        if (!tmpFile.exists()) {
            LOGGER.info("Start to create local file.");
            tmpFile.createNewFile();
        }
        tmpOutputStream = new FileOutputStream(tmpFile);
        ExcelWriter writer = new ExcelWriter(tmpOutputStream, ExcelTypeEnum.XLSX, true);
        // Find task with the start time and end time.
        for (String tableName : tables) {
            List<Task> tasks = taskDao.findWithSubmitTimeAndDatasource(request.getStartTime(), request.getEndTime(), request.getClusterName(), request.getDatabaseName(), tableName);
            List<TaskRuleSimple> taskRuleSimples = tasks.stream().map(Task::getTaskRuleSimples).flatMap(taskRuleSimpleSet -> taskRuleSimpleSet.stream()).distinct().collect(Collectors.toList());
            // Generate analysis result excel
            List<ExcelResult> results = new ArrayList<>(taskRuleSimples.size());
            for (TaskRuleSimple taskRuleSimple : taskRuleSimples) {
                ExcelResult excelResult = new ExcelResult();
                excelResult.setRuleName(taskRuleSimple.getRuleName());
                excelResult.setClusterName(request.getClusterName());
                excelResult.setDatabaseName(request.getDatabaseName());
                excelResult.setTableName(tableName);
                excelResult.setBeginTime(taskRuleSimple.getTask().getBeginTime());
                excelResult.setEndTime(taskRuleSimple.getTask().getEndTime());
                StringBuffer checkTemplateStr = new StringBuffer();
                StringBuffer resultStr = new StringBuffer();
                joinAlarmConfig(results, taskRuleSimple, excelResult, request, checkTemplateStr, resultStr);
                results.add(excelResult);
            }
            Sheet templateSheet = new Sheet(sheetNo++, 0, ExcelResult.class);
            templateSheet.setSheetName(tableName + "-" + ExcelSheetName.ANALYSIS_NAME);
            writer.write(results, templateSheet);
        }
        writer.finish();
    } catch (FileNotFoundException e) {
        LOGGER.error(e.getMessage(), e);
        throw new UnExpectedRequestException("{&FAILED_TO_CREATE_LOCAL_FILE}");
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
        throw new UnExpectedRequestException("{&FAILED_TO_CREATE_LOCAL_FILE}");
    } finally {
        try {
            tmpOutputStream.close();
        } catch (IOException e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
}
Also used : Path(java.nio.file.Path) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Task(com.webank.wedatasphere.qualitis.entity.Task) ExcelResult(com.webank.wedatasphere.qualitis.excel.ExcelResult) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ExcelWriter(com.alibaba.excel.ExcelWriter) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileOutputStream(java.io.FileOutputStream) TaskRuleSimple(com.webank.wedatasphere.qualitis.entity.TaskRuleSimple) Sheet(com.alibaba.excel.metadata.Sheet)

Aggregations

ExcelResult (com.webank.wedatasphere.qualitis.excel.ExcelResult)2 ExcelWriter (com.alibaba.excel.ExcelWriter)1 Sheet (com.alibaba.excel.metadata.Sheet)1 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)1 Task (com.webank.wedatasphere.qualitis.entity.Task)1 TaskResult (com.webank.wedatasphere.qualitis.entity.TaskResult)1 TaskRuleAlarmConfig (com.webank.wedatasphere.qualitis.entity.TaskRuleAlarmConfig)1 TaskRuleSimple (com.webank.wedatasphere.qualitis.entity.TaskRuleSimple)1 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1