use of com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest 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);
}
}
use of com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest 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;
}
use of com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest in project Qualitis by WeBankFinTech.
the class AddFileRuleRequestBuilder method commonAlarmSetting.
public FileAlarmConfigRequest commonAlarmSetting(Integer checkTemplateEnum, Integer compareType, double value) {
FileAlarmConfigRequest newAlarmConfigRequest = new FileAlarmConfigRequest();
newAlarmConfigRequest.setUploadAbnormalValue(getUploadAbnormalValue());
newAlarmConfigRequest.setDeleteFailCheckResult(getDeleteFailCheckResult());
newAlarmConfigRequest.setUploadRuleMetricValue(getUploadRuleMetricValue());
newAlarmConfigRequest.setRuleMetricEnCode(getRuleMetricEnCode());
newAlarmConfigRequest.setFileOutputName(fileOutPut);
newAlarmConfigRequest.setThreshold(value);
switch(checkTemplateEnum) {
case 1:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.MONTH_FLUCTUATION.getCode());
break;
case 2:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.WEEK_FLUCTUATION.getCode());
break;
case 3:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.DAY_FLUCTUATION.getCode());
break;
case 4:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.FIXED_VALUE.getCode());
newAlarmConfigRequest.setCompareType(compareType);
break;
case 5:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.FULL_YEAR_RING_GROWTH.getCode());
break;
case 6:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.HALF_YEAR_GROWTH.getCode());
break;
case 7:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.SEASON_RING_GROWTH.getCode());
break;
case 8:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.MONTH_RING_GROWTH.getCode());
break;
case 9:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.WEEK_RING_GROWTH.getCode());
break;
case 10:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.DAY_RING_GROWTH.getCode());
break;
case 11:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.HOUR_RING_GROWTH.getCode());
break;
case 12:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.YEAR_ON_YEAR.getCode());
break;
default:
addFileRuleRequest.setAlarm(false);
LOGGER.info("");
}
return newAlarmConfigRequest;
}
use of com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest in project Qualitis by WeBankFinTech.
the class AddFileRuleRequestBuilder method commonAlarmSetting.
public FileAlarmConfigRequest commonAlarmSetting(Integer checkTemplateEnum, Integer compareType, String value) {
FileAlarmConfigRequest newAlarmConfigRequest = new FileAlarmConfigRequest();
newAlarmConfigRequest.setUploadAbnormalValue(getUploadAbnormalValue());
newAlarmConfigRequest.setDeleteFailCheckResult(getDeleteFailCheckResult());
newAlarmConfigRequest.setUploadRuleMetricValue(getUploadRuleMetricValue());
newAlarmConfigRequest.setRuleMetricEnCode(getRuleMetricEnCode());
newAlarmConfigRequest.setFileOutputName(fileOutPut);
if (value.contains(SpecCharEnum.EMPTY.getValue())) {
String[] fullSize = value.split(SpecCharEnum.EMPTY.getValue());
newAlarmConfigRequest.setThreshold(Double.parseDouble(fullSize[0]));
newAlarmConfigRequest.setFileOutputUnit(FileOutputUnitEnum.fileOutputUnitCode(fullSize[1].toUpperCase()));
} else {
newAlarmConfigRequest.setThreshold(Double.parseDouble(value));
}
switch(checkTemplateEnum) {
case 1:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.MONTH_FLUCTUATION.getCode());
break;
case 2:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.WEEK_FLUCTUATION.getCode());
break;
case 3:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.DAY_FLUCTUATION.getCode());
break;
case 4:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.FIXED_VALUE.getCode());
newAlarmConfigRequest.setCompareType(compareType);
break;
case 5:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.FULL_YEAR_RING_GROWTH.getCode());
break;
case 6:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.HALF_YEAR_GROWTH.getCode());
break;
case 7:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.SEASON_RING_GROWTH.getCode());
break;
case 8:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.MONTH_RING_GROWTH.getCode());
break;
case 9:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.WEEK_RING_GROWTH.getCode());
break;
case 10:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.DAY_RING_GROWTH.getCode());
break;
case 11:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.HOUR_RING_GROWTH.getCode());
break;
case 12:
newAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.YEAR_ON_YEAR.getCode());
break;
default:
addFileRuleRequest.setAlarm(false);
LOGGER.info("");
}
return newAlarmConfigRequest;
}
use of com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method constructAddFileRuleRequest.
private List<AddFileRuleRequest> constructAddFileRuleRequest(Map<String, List<ExcelTemplateFileRuleByProject>> fileRulePartitionedByRuleName, Project project, String localeStr) throws UnExpectedRequestException {
List<AddFileRuleRequest> addFileRuleRequests = new ArrayList<>();
for (String ruleName : fileRulePartitionedByRuleName.keySet()) {
List<ExcelTemplateFileRuleByProject> ruleInfos = fileRulePartitionedByRuleName.get(ruleName);
ExcelTemplateFileRuleByProject firstCommonInfo = ruleInfos.get(0);
AddFileRuleRequest addFileRuleRequest = new AddFileRuleRequest();
String ruleGroupName = firstCommonInfo.getRuleGroupName();
if (StringUtils.isBlank(ruleGroupName)) {
throw new UnExpectedRequestException("RuleGroupName {&CAN_NOT_BE_NULL_OR_EMPTY}");
}
boolean alarm = false;
List<FileAlarmConfigRequest> alarmConfigRequests = new ArrayList<>();
DataSourceRequest dataSourceRequest = new DataSourceRequest();
Long projectId = project.getId();
for (ExcelTemplateFileRuleByProject excelTemplateFileRule : ruleInfos) {
getDataFileSourceRequest(dataSourceRequest, excelTemplateFileRule);
getFileAlarmConfig(alarmConfigRequests, excelTemplateFileRule, localeStr);
}
RuleGroup ruleGroupInDb = ruleGroupDao.findByRuleGroupNameAndProjectId(ruleGroupName, projectId);
if (ruleGroupInDb != null) {
addFileRuleRequest.setRuleGroupId(ruleGroupInDb.getId());
} else {
RuleGroup ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup(ruleGroupName, project.getId()));
addFileRuleRequest.setRuleGroupId(ruleGroup.getId());
}
// Construct addRuleRequest
addFileRuleRequest.setRuleName(ruleName);
addFileRuleRequest.setRuleDetail(firstCommonInfo.getRuleDetail());
addFileRuleRequest.setAbortOnFailure(firstCommonInfo.getAbortOnFailure());
if (!alarmConfigRequests.isEmpty()) {
alarm = true;
}
addFileRuleRequest.setAlarm(alarm);
addFileRuleRequest.setAlarmVariable(alarmConfigRequests);
addFileRuleRequest.setDatasource(dataSourceRequest);
addFileRuleRequest.setProjectId(projectId);
addFileRuleRequests.add(addFileRuleRequest);
}
return addFileRuleRequests;
}
Aggregations