Search in sources :

Example 6 with RuleMetric

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

the class RuleBatchServiceImpl method getFileAlarmConfig.

private void getFileAlarmConfig(List<FileAlarmConfigRequest> alarmConfigRequests, ExcelTemplateFileRuleByProject excelTemplateFileRule, String localeStr) throws UnExpectedRequestException {
    String templateOutputName = excelTemplateFileRule.getAlarmCheckName();
    if (!StringUtils.isBlank(templateOutputName)) {
        Integer unit = FileOutputUnitEnum.fileOutputUnitCode(excelTemplateFileRule.getUnit());
        String checkTemplateName = excelTemplateFileRule.getCheckTemplateName();
        String compareTypeName = excelTemplateFileRule.getCompareType();
        String threshold = excelTemplateFileRule.getThreshold();
        FileAlarmConfigRequest fileAlarmConfigRequest = new FileAlarmConfigRequest();
        fileAlarmConfigRequest.setFileOutputName(FileOutputNameEnum.getFileOutputNameCode(templateOutputName, localeStr));
        fileAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.getCheckTemplateCode(checkTemplateName, localeStr));
        fileAlarmConfigRequest.setCompareType(CompareTypeEnum.getCompareTypeCode(compareTypeName));
        fileAlarmConfigRequest.setThreshold(Double.valueOf(threshold));
        fileAlarmConfigRequest.setFileOutputUnit(unit);
        // Rule Metric.
        String ruleMetricEnCode = excelTemplateFileRule.getRuleMetricEnCode();
        if (StringUtils.isNotBlank(ruleMetricEnCode)) {
            RuleMetric ruleMetricInDb = ruleMetricDao.findByEnCode(ruleMetricEnCode);
            if (ruleMetricInDb == null) {
                throw new UnExpectedRequestException("Rule metric[Code=" + ruleMetricEnCode + "] " + "{&DOES_NOT_EXIST}");
            }
            String code = ruleMetricInDb.getEnCode();
            fileAlarmConfigRequest.setRuleMetricEnCode(code);
        }
        alarmConfigRequests.add(fileAlarmConfigRequest);
    }
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest)

Example 7 with RuleMetric

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

the class ProjectBatchServiceImpl method modifyRuleMetric.

private void modifyRuleMetric(ExcelRuleMetric excelRuleMetric, RuleMetric ruleMetric, String userName) throws UnExpectedRequestException, PermissionDeniedRequestException {
    // Check en code existence.
    RuleMetric ruleMetricInDb = ruleMetricDao.findByEnCode(excelRuleMetric.getEnCode());
    if (ruleMetricInDb != null && ruleMetricInDb.getId().longValue() != ruleMetric.getId().longValue()) {
        throw new UnExpectedRequestException("Rule Metric [EN_CODE=" + excelRuleMetric.getEnCode() + "] {&DOES_NOT_EXIST}");
    }
    LOGGER.info("Start to modify rule metric, modify request: [{}], user: [{}]", excelRuleMetric.toString(), userName);
    User loginUser = userDao.findByUsername(userName);
    List<UserRole> userRoles = userRoleDao.findByUser(loginUser);
    Integer roleType = roleService.getRoleType(userRoles);
    if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
        LOGGER.info("First level(created by SYS_ADMIN) indicator will be modified soon.");
    } else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
        LOGGER.info("Second level(created by DEPARTMENT_ADMIN) indicator will be modified soon.");
        if (ruleMetric.getLevel().equals(RuleMetricLevelEnum.DEFAULT_METRIC.getCode())) {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
        List<Department> managedDepartment = new ArrayList<>();
        for (UserRole userRole : userRoles) {
            Department department = userRole.getRole().getDepartment();
            if (department != null) {
                managedDepartment.add(department);
            }
        }
        RuleMetricDepartmentUser ruleMetricDepartmentUser = ruleMetricDepartmentUserDao.findByRuleMetric(ruleMetric);
        if (ruleMetricDepartmentUser != null && managedDepartment.contains(ruleMetricDepartmentUser.getDepartment())) {
            LOGGER.info("Rule metric[{}] comes from department: {}", ruleMetric.toString(), ruleMetricDepartmentUser.getDepartment().getName());
        } else {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
    } else {
        LOGGER.info("Third level(created by PROJECTOR) indicator will be modified soon.");
        if (!ruleMetric.getLevel().equals(RuleMetricLevelEnum.PERSONAL_METRIC.getCode()) || !ruleMetric.getCreateUser().equals(loginUser.getUserName())) {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
    }
    ruleMetric.setName(excelRuleMetric.getName());
    ruleMetric.setMetricDesc(excelRuleMetric.getMetricDesc());
    ruleMetric.setSubSystemName(excelRuleMetric.getSubSystemName());
    ruleMetric.setFullCnName(excelRuleMetric.getFullCnName());
    ruleMetric.setModifyUser(userName);
    ruleMetric.setModifyTime(ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date()));
    ruleMetric.setType(excelRuleMetric.getType());
    ruleMetric.setFrequency(Integer.parseInt(excelRuleMetric.getFrequency()));
    ruleMetric.setEnCode(excelRuleMetric.getEnCode());
    ruleMetric.setDepartmentName(excelRuleMetric.getDepartmentName());
    ruleMetric.setDevDepartmentName(excelRuleMetric.getDevDepartmentName());
    ruleMetric.setOpsDepartmentName(excelRuleMetric.getOpsDepartmentName());
    ruleMetric.setAvailable(excelRuleMetric.getAvailable());
    ruleMetricDao.add(ruleMetric);
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) Department(com.webank.wedatasphere.qualitis.entity.Department) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) User(com.webank.wedatasphere.qualitis.entity.User) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole)

Example 8 with RuleMetric

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

the class ExecutionManagerImpl method saveTaskRusult.

private List<TaskResult> saveTaskRusult(String fullSize, double fileCount, Application application, String submitTime, Rule rule, Set<AlarmConfig> alarmConfig, String runDate) throws UnExpectedRequestException {
    double number = Double.parseDouble(fullSize.split(" ")[0]);
    String unit = fullSize.split(" ")[1];
    // Save task result.
    List<TaskResult> taskResults = new ArrayList<>();
    List<Integer> fileOutputNames = alarmConfig.stream().map(AlarmConfig::getFileOutputName).distinct().collect(Collectors.toList());
    for (Integer fileOutputName : fileOutputNames) {
        AlarmConfig currentAlarmConfig = alarmConfig.stream().filter(alarmConfigSetting -> alarmConfigSetting.getFileOutputName().equals(fileOutputName)).iterator().next();
        RuleMetric ruleMetric = currentAlarmConfig.getRuleMetric();
        if (ruleMetric == null) {
            throw new UnExpectedRequestException("File rule metric {&CAN_NOT_BE_NULL_OR_EMPTY}");
        }
        TaskResult taskResult;
        if (StringUtils.isNotBlank(runDate)) {
            TaskResult existTaskResult = taskResultDao.find(runDate, rule.getId(), ruleMetric.getId());
            if (existTaskResult != null) {
                taskResult = existTaskResult;
            } else {
                taskResult = new TaskResult();
                Date runRealDate = null;
                try {
                    runRealDate = new SimpleDateFormat("yyyyMMdd").parse(runDate);
                } catch (ParseException e) {
                    String errorMsg = "Parse date string with run date failed. Exception message: " + e.getMessage();
                    LOGGER.error(errorMsg);
                    throw new UnExpectedRequestException(errorMsg);
                }
                taskResult.setRunDate(runRealDate.getTime());
            }
        } else {
            taskResult = new TaskResult();
        }
        taskResult.setApplicationId(application.getId());
        taskResult.setCreateTime(submitTime);
        taskResult.setRuleId(rule.getId());
        taskResult.setRuleMetricId(ruleMetric.getId());
        if (fileOutputName.equals(FileOutputNameEnum.FILE_COUNT.getCode())) {
            taskResult.setResultType("int");
            taskResult.setValue(fileCount + "");
        } else if (fileOutputName.equals(FileOutputNameEnum.DIR_SIZE.getCode())) {
            String alarmConfigUnit = FileOutputUnitEnum.fileOutputUnit(currentAlarmConfig.getFileOutputUnit());
            taskResult.setResultType(alarmConfigUnit);
            taskResult.setValue(UnitTransfer.alarmconfigToTaskResult(number, alarmConfigUnit, unit.toUpperCase()) + "");
        } else {
            throw new UnExpectedRequestException("Unknown file output name.");
        }
        taskResults.add(taskResultDao.saveTaskResult(taskResult));
    }
    return taskResults;
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ArrayList(java.util.ArrayList) Date(java.util.Date) TaskResult(com.webank.wedatasphere.qualitis.entity.TaskResult) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig) TaskRuleAlarmConfig(com.webank.wedatasphere.qualitis.entity.TaskRuleAlarmConfig)

Example 9 with RuleMetric

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

the class RuleNodeServiceImpl method constructFileRequest.

private AddFileRuleRequest constructFileRequest(Rule rule, RuleGroup ruleGroup) {
    AddFileRuleRequest addFileRuleRequest = new AddFileRuleRequest();
    String newVersion = ruleGroup.getVersion();
    if (StringUtils.isEmpty(newVersion)) {
        String newRuleName = rule.getName() + "_copy_" + ruleGroup.getId();
        LOGGER.info("File rule start to be copied. Copied rule name: " + newRuleName);
        addFileRuleRequest.setRuleName(newRuleName);
        if (StringUtils.isNotBlank(rule.getCnName())) {
            addFileRuleRequest.setRuleCnName(rule.getCnName() + "_副本");
        }
    } else {
        String oldVersion = rule.getRuleGroup().getVersion();
        LOGGER.info("File rule start to be copied. Copied rule name: " + rule.getName() + "_" + ruleGroup.getVersion());
        if (StringUtils.isNotBlank(oldVersion) && rule.getName().endsWith(oldVersion)) {
            addFileRuleRequest.setRuleName(rule.getName().replace(oldVersion, newVersion));
            if (StringUtils.isNotBlank(rule.getCnName())) {
                addFileRuleRequest.setRuleCnName(rule.getCnName().replace(oldVersion, newVersion));
            }
        } else {
            addFileRuleRequest.setRuleName(rule.getName() + "_" + newVersion);
            if (StringUtils.isNotBlank(rule.getCnName())) {
                addFileRuleRequest.setRuleCnName(rule.getCnName() + "_" + newVersion);
            }
        }
    }
    String ruleDetail = rule.getDetail();
    addFileRuleRequest.setRuleDetail(ruleDetail);
    addFileRuleRequest.setAbortOnFailure(rule.getAbortOnFailure());
    addFileRuleRequest.setCsId(rule.getCsId());
    addFileRuleRequest.setRuleGroupId(ruleGroup.getId());
    addFileRuleRequest.setProjectId(ruleGroup.getProjectId());
    addFileRuleRequest.setAbortOnFailure(rule.getAbortOnFailure());
    for (RuleDataSource ruleDataSource : rule.getRuleDataSources()) {
        DataSourceRequest dataSourceRequest = new DataSourceRequest();
        String clusterName = ruleDataSource.getClusterName();
        String databaseName = ruleDataSource.getDbName();
        String tableName = ruleDataSource.getTableName();
        String filter = ruleDataSource.getFilter();
        dataSourceRequest.setClusterName(clusterName);
        dataSourceRequest.setDbName(databaseName);
        dataSourceRequest.setTableName(tableName);
        dataSourceRequest.setFilter(filter);
        addFileRuleRequest.setDatasource(dataSourceRequest);
        break;
    }
    List<FileAlarmConfigRequest> alarmVariable = new ArrayList<>();
    for (AlarmConfig alarmConfig : rule.getAlarmConfigs()) {
        FileAlarmConfigRequest fileAlarmConfigRequest = new FileAlarmConfigRequest();
        Double threshold = alarmConfig.getThreshold();
        Integer unit = alarmConfig.getFileOutputUnit();
        Integer alarmCompareType = alarmConfig.getCompareType();
        Integer alarmOutputName = alarmConfig.getFileOutputName();
        Integer checkTemplateName = alarmConfig.getCheckTemplate();
        fileAlarmConfigRequest.setFileOutputUnit(unit);
        fileAlarmConfigRequest.setCompareType(alarmCompareType);
        fileAlarmConfigRequest.setFileOutputName(alarmOutputName);
        fileAlarmConfigRequest.setCheckTemplate(checkTemplateName);
        fileAlarmConfigRequest.setThreshold(threshold);
        RuleMetric ruleMetric = alarmConfig.getRuleMetric();
        // Recod rule metric info (unique code).
        if (ruleMetric != null) {
            String enCode = ruleMetric.getEnCode();
            fileAlarmConfigRequest.setRuleMetricEnCode(enCode);
            fileAlarmConfigRequest.setUploadAbnormalValue(alarmConfig.getUploadAbnormalValue());
            fileAlarmConfigRequest.setUploadRuleMetricValue(alarmConfig.getUploadRuleMetricValue());
        }
        fileAlarmConfigRequest.setDeleteFailCheckResult(alarmConfig.getDeleteFailCheckResult());
        alarmVariable.add(fileAlarmConfigRequest);
    }
    addFileRuleRequest.setAlarm(true);
    addFileRuleRequest.setAlarmVariable(alarmVariable);
    return addFileRuleRequest;
}
Also used : DataSourceRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest) RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) AddFileRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddFileRuleRequest) ArrayList(java.util.ArrayList) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)

Example 10 with RuleMetric

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

the class RuleNodeServiceImpl method constructCustomAlarmConfigRequest.

private List<CustomAlarmConfigRequest> constructCustomAlarmConfigRequest(Set<AlarmConfig> alarmConfigs, AddCustomRuleRequest addCustomRuleRequest) {
    List<CustomAlarmConfigRequest> alarmConfigRequests = new ArrayList<>(alarmConfigs.size());
    for (AlarmConfig alarmConfig : alarmConfigs) {
        CustomAlarmConfigRequest alarmConfigRequest = new CustomAlarmConfigRequest();
        alarmConfigRequest.setCheckTemplate(alarmConfig.getCheckTemplate());
        alarmConfigRequest.setCompareType(alarmConfig.getCompareType());
        alarmConfigRequest.setThreshold(alarmConfig.getThreshold());
        RuleMetric ruleMetric = alarmConfig.getRuleMetric();
        alarmConfigRequest.setRuleMetricEnCode(ruleMetric != null ? ruleMetric.getEnCode() : "");
        alarmConfigRequest.setUploadAbnormalValue(alarmConfig.getUploadAbnormalValue());
        alarmConfigRequest.setUploadRuleMetricValue(alarmConfig.getUploadRuleMetricValue());
        alarmConfigRequest.setDeleteFailCheckResult(alarmConfig.getDeleteFailCheckResult());
        addCustomRuleRequest.setOutputName(ruleMetric.getName());
        alarmConfigRequests.add(alarmConfigRequest);
    }
    return alarmConfigRequests;
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest) ArrayList(java.util.ArrayList) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)

Aggregations

RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)36 ArrayList (java.util.ArrayList)23 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)19 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)15 RuleMetricDepartmentUser (com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser)10 User (com.webank.wedatasphere.qualitis.entity.User)10 Department (com.webank.wedatasphere.qualitis.entity.Department)9 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)9 List (java.util.List)9 ExcelRuleMetric (com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric)8 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)8 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)7 TemplateOutputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta)7 CustomAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest)7 FileAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest)7 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)6 RuleMetricResponse (com.webank.wedatasphere.qualitis.response.RuleMetricResponse)6 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)5 Date (java.util.Date)5 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)4