use of com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method getFileRule.
@Override
public List<ExcelTemplateFileRuleByProject> getFileRule(Iterable<Rule> rules, String localeStr) {
List<ExcelTemplateFileRuleByProject> lines = new ArrayList<>();
for (Rule rule : rules) {
if (!rule.getRuleType().equals(RuleTypeEnum.FILE_TEMPLATE_RULE.getCode())) {
continue;
}
String ruleName = rule.getName();
String ruleCnName = rule.getCnName();
String ruleDetail = rule.getDetail();
String templateName = rule.getTemplate().getName();
ExcelTemplateFileRuleByProject ruleLinePrefix = new ExcelTemplateFileRuleByProject();
ruleLinePrefix.setRuleName(ruleName);
ruleLinePrefix.setRuleCnName(ruleCnName);
ruleLinePrefix.setRuleDetail(ruleDetail);
ruleLinePrefix.setTemplateName(templateName);
ruleLinePrefix.setProjectName(rule.getProject().getName());
ruleLinePrefix.setAbortOnFailure(rule.getAbortOnFailure());
ruleLinePrefix.setRuleGroupName(rule.getRuleGroup().getRuleGroupName());
ruleLinePrefix.setCreateUser(rule.getCreateUser());
ruleLinePrefix.setCreateTime(rule.getCreateTime());
ruleLinePrefix.setModifyUser(rule.getModifyUser());
ruleLinePrefix.setModifyTime(rule.getModifyTime());
ruleLinePrefix.setDeleteFailCheckResult(rule.getDeleteFailCheckResult());
lines.add(ruleLinePrefix);
for (RuleDataSource ruleDataSource : rule.getRuleDataSources()) {
String clusterName = ruleDataSource.getClusterName();
String databaseName = ruleDataSource.getDbName();
String tableName = ruleDataSource.getTableName();
String filter = ruleDataSource.getFilter();
ExcelTemplateFileRuleByProject tmp = new ExcelTemplateFileRuleByProject(rule.getName());
tmp.setClusterName(clusterName);
tmp.setDatabaseName(databaseName);
tmp.setTableName(tableName);
tmp.setFilter(filter);
LOGGER.info("Collect excel line: {}", tmp);
lines.add(tmp);
}
for (AlarmConfig alarmConfig : rule.getAlarmConfigs()) {
Double threshold = alarmConfig.getThreshold();
String alarmCompareType = CompareTypeEnum.getCompareTypeName(alarmConfig.getCompareType());
String alarmOutputName = FileOutputNameEnum.getFileOutputName(alarmConfig.getFileOutputName(), localeStr);
String checkTemplateName = CheckTemplateEnum.getCheckTemplateName(alarmConfig.getCheckTemplate(), localeStr);
String unit = alarmConfig.getFileOutputUnit() == null ? "" : FileOutputUnitEnum.fileOutputUnit(alarmConfig.getFileOutputUnit());
ExcelTemplateFileRuleByProject tmp = new ExcelTemplateFileRuleByProject(rule.getName());
tmp.setUnit(unit);
tmp.setCompareType(alarmCompareType);
tmp.setAlarmCheckName(alarmOutputName);
tmp.setCheckTemplateName(checkTemplateName);
tmp.setThreshold(String.valueOf(threshold));
RuleMetric ruleMetric = alarmConfig.getRuleMetric();
// Recod rule metric info (unique code).
if (ruleMetric != null) {
String enCode = ruleMetric.getEnCode();
tmp.setRuleMetricEnCode(enCode);
tmp.setRuleMetricName(ruleMetric.getName());
}
LOGGER.info("Collect excel line: {}", tmp);
lines.add(tmp);
}
}
return lines;
}
use of com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method basicInfoToExcel.
private void basicInfoToExcel(ExcelCustomRuleByProject ruleLinePrefix, Rule rule) {
String ruleName = rule.getName();
String ruleDetail = rule.getDetail();
String ruleCnName = rule.getCnName();
String outputName = rule.getOutputName();
Boolean saveMidTable = rule.getTemplate().getSaveMidTable();
RuleDataSource ruleDataSource = rule.getRuleDataSources().iterator().next();
ruleLinePrefix.setProxyUser(ruleDataSource.getProxyUser());
String clusterName = ruleDataSource.getClusterName();
// Original custom rule, not sql check type.
if (rule.getFunctionType() != null && StringUtils.isNotBlank(rule.getFunctionContent()) && StringUtils.isNotBlank(rule.getFromContent()) && StringUtils.isNotBlank(rule.getWhereContent())) {
String functionName = FunctionTypeEnum.getFunctionByCode(rule.getFunctionType());
String functionContent = rule.getFunctionContent();
String whereContent = rule.getWhereContent();
String fromContent = rule.getFromContent();
ruleLinePrefix.setFunctionContent(functionContent);
ruleLinePrefix.setWhereContent(whereContent);
ruleLinePrefix.setFunctionName(functionName);
ruleLinePrefix.setFromContent(fromContent);
} else {
ruleLinePrefix.setSqlCheckArea(rule.getTemplate().getMidTableAction());
}
if (ruleDataSource.getLinkisDataSourceId() != null) {
String linkisDataSourceName = ruleDataSource.getLinkisDataSourceName();
String linkisDataSourceId = String.valueOf(ruleDataSource.getLinkisDataSourceId());
String linkisDataSourceType = TemplateDataSourceTypeEnum.getMessage(ruleDataSource.getDatasourceType());
ruleLinePrefix.setLinkisDataSourceName(linkisDataSourceName);
ruleLinePrefix.setLinkisDataSourceType(linkisDataSourceType);
ruleLinePrefix.setLinkisDataSourceId(linkisDataSourceId);
}
ruleLinePrefix.setRuleGroupName(rule.getRuleGroup().getRuleGroupName());
ruleLinePrefix.setProjectName(rule.getProject().getName());
ruleLinePrefix.setAbortOnFailure(rule.getAbortOnFailure());
ruleLinePrefix.setRuleDetail(ruleDetail);
ruleLinePrefix.setRuleCnName(ruleCnName);
ruleLinePrefix.setRuleName(ruleName);
ruleLinePrefix.setOutputName(outputName);
ruleLinePrefix.setClusterName(clusterName);
ruleLinePrefix.setSaveMidTable(saveMidTable);
ruleLinePrefix.setCreateUser(rule.getCreateUser());
ruleLinePrefix.setCreateTime(rule.getCreateTime());
ruleLinePrefix.setModifyUser(rule.getModifyUser());
ruleLinePrefix.setModifyTime(rule.getModifyTime());
ruleLinePrefix.setDeleteFailCheckResult(rule.getDeleteFailCheckResult());
ruleLinePrefix.setSpecifyStaticStartupParam(rule.getSpecifyStaticStartupParam());
if (rule.getSpecifyStaticStartupParam() != null && rule.getSpecifyStaticStartupParam()) {
ruleLinePrefix.setStaticStartupParam(rule.getStaticStartupParam());
}
}
use of com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource in project Qualitis by WeBankFinTech.
the class RuleDataSourceServiceImpl method checkAndSaveCustomRuleDataSource.
@Override
@Transactional(rollbackFor = { RuntimeException.class })
public List<RuleDataSource> checkAndSaveCustomRuleDataSource(String clusterName, String proxyUser, String loginUser, Rule savedRule, boolean cs, boolean sqlCheck, Long linkisDataSourceId, Long linkisDataSourceVersionId, String linkisDataSourceName, String linkisDataSourceType) {
List<RuleDataSource> ruleDataSources = new ArrayList<>();
RuleDataSource ruleDataSource = new RuleDataSource();
ruleDataSource.setDatasourceIndex(ORIGINAL_INDEX);
ruleDataSource.setClusterName(clusterName);
ruleDataSource.setProxyUser(proxyUser);
ruleDataSource.setRule(savedRule);
if (StringUtils.isNotBlank(linkisDataSourceType)) {
ruleDataSource.setLinkisDataSourceId(linkisDataSourceId);
ruleDataSource.setLinkisDataSourceName(linkisDataSourceName);
ruleDataSource.setLinkisDataSourceVersionId(linkisDataSourceVersionId);
ruleDataSource.setDatasourceType(TemplateDataSourceTypeEnum.getCode(linkisDataSourceType));
}
ruleDataSources.add(ruleDataSource);
LOGGER.info("Start to save custom rule datasource with cluster name and proxy user.");
if (CollectionUtils.isEmpty(ruleDataSources)) {
return ruleDataSources;
}
return ruleDatasourceDao.saveAllRuleDataSource(ruleDataSources);
}
use of com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource in project Qualitis by WeBankFinTech.
the class RuleDataSourceServiceImpl method checkAndSaveFileRuleDataSource.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public RuleDataSource checkAndSaveFileRuleDataSource(DataSourceRequest request, Rule rule, boolean cs) throws UnExpectedRequestException {
DataSourceRequest.checkRequest(request, cs, "File rule datasource request");
RuleDataSource newRuleDataSource = new RuleDataSource();
newRuleDataSource.setClusterName(request.getClusterName());
newRuleDataSource.setDbName(request.getDbName());
newRuleDataSource.setTableName(request.getTableName());
if (request.getFilter() != null) {
newRuleDataSource.setFilter(request.getFilter());
} else {
newRuleDataSource.setFilter("");
}
newRuleDataSource.setColName("");
newRuleDataSource.setProxyUser(request.getProxyUser());
newRuleDataSource.setRule(rule);
newRuleDataSource.setProjectId(rule.getProject().getId());
return ruleDatasourceDao.saveRuleDataSource(newRuleDataSource);
}
use of com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource in project Qualitis by WeBankFinTech.
the class FileRuleServiceImpl method addRuleReal.
private GeneralResponse<RuleResponse> addRuleReal(AddFileRuleRequest request, String loginUser) throws UnExpectedRequestException, PermissionDeniedRequestException {
// Check Arguments
AddFileRuleRequest.checkRequest(request, false);
// Generate Template, TemplateOutputMeta and save
Template template = ruleTemplateService.addFileTemplate(request);
// Check existence of project
Project projectInDb = projectService.checkProjectExistence(request.getProjectId(), loginUser);
String nowDate = ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date());
// Check permissions of project
List<Integer> permissions = new ArrayList<>();
permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
projectService.checkProjectPermission(projectInDb, loginUser, permissions);
// Check unique of rule name
ruleService.checkRuleName(request.getRuleName(), projectInDb, null);
// Check cluster support
ruleDataSourceService.checkDataSourceClusterSupport(request.getDatasource().getClusterName());
RuleGroup ruleGroup;
if (request.getRuleGroupId() != null) {
ruleGroup = ruleGroupDao.findById(request.getRuleGroupId());
if (ruleGroup == null) {
throw new UnExpectedRequestException(String.format("Rule Group: %s {&DOES_NOT_EXIST}", request.getRuleGroupId()));
}
} else {
ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup("Group_" + UUID.randomUUID().toString().replace("-", ""), projectInDb.getId()));
}
// Save rule.
Rule newRule = new Rule();
newRule.setRuleType(RuleTypeEnum.FILE_TEMPLATE_RULE.getCode());
newRule.setTemplate(template);
newRule.setName(request.getRuleName());
newRule.setCnName(request.getRuleCnName());
newRule.setDetail(request.getRuleDetail());
newRule.setAlarm(request.getAlarm());
newRule.setProject(projectInDb);
newRule.setRuleTemplateName(template.getName());
newRule.setRuleGroup(ruleGroup);
newRule.setAbortOnFailure(request.getAbortOnFailure());
newRule.setCreateUser(loginUser);
newRule.setCreateTime(nowDate);
String csId = request.getCsId();
boolean cs = false;
if (StringUtils.isNotBlank(csId)) {
newRule.setCsId(csId);
cs = true;
}
Rule savedRule = ruleDao.saveRule(newRule);
LOGGER.info("Succeed to save file rule, rule_id: {}", savedRule.getId());
List<AlarmConfig> savedAlarmConfigs = new ArrayList<>();
if (request.getAlarm()) {
savedAlarmConfigs = alarmConfigService.checkAndSaveFileAlarmVariable(request.getAlarmVariable(), savedRule);
LOGGER.info("Succeed to save alarm_configs, alarm_configs: {}", savedAlarmConfigs);
}
List<RuleDataSource> ruleDataSources = new ArrayList<>();
ruleDataSources.add(ruleDataSourceService.checkAndSaveFileRuleDataSource(request.getDatasource(), savedRule, cs));
savedRule.setAlarmConfigs(new HashSet<>(savedAlarmConfigs));
savedRule.setRuleDataSources(new HashSet<>(ruleDataSources));
// Update rule count of datasource
ruleDataSourceService.updateRuleDataSourceCount(savedRule, 1);
RuleResponse response = new RuleResponse(savedRule);
LOGGER.info("Succeed to add file rule, rule_id: {}", savedRule.getId());
return new GeneralResponse<>("200", "{&SUCCEED_TO_ADD_FILE_RULE}", response);
}
Aggregations