use of com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method importRule.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class }, propagation = Propagation.REQUIRED)
public void importRule(RuleNodeRequest ruleNodeRequest, Project projectInDb, RuleGroup ruleGroup, ObjectMapper objectMapper) throws UnExpectedRequestException, IOException {
// Rule, Template, RuleGroup.
Rule rule = objectMapper.readValue(ruleNodeRequest.getRuleObject(), Rule.class);
Template template = objectMapper.readValue(ruleNodeRequest.getTemplateObject(), Template.class);
// RuleDataSource.
Set<RuleDataSource> ruleDataSources = objectMapper.readValue(ruleNodeRequest.getRuleDataSourcesObject(), new TypeReference<Set<RuleDataSource>>() {
});
Set<RuleDataSourceMapping> ruleDataSourceMappings = objectMapper.readValue(ruleNodeRequest.getRuleDataSourceMappingsObject(), new TypeReference<Set<RuleDataSourceMapping>>() {
});
// Rule check meta info.
Set<AlarmConfig> alarmConfigs = objectMapper.readValue(ruleNodeRequest.getAlarmConfigsObject(), new TypeReference<Set<AlarmConfig>>() {
});
Set<RuleVariable> ruleVariables = objectMapper.readValue(ruleNodeRequest.getRuleVariablesObject(), new TypeReference<Set<RuleVariable>>() {
});
LOGGER.info("Import basic information: {}", new StringBuilder().append("\n").append(rule.getName()).append("\n").append(template.getName()).append("\n").toString());
LOGGER.info(objectMapper.writeValueAsString(ruleNodeRequest));
Rule ruleInDb = ruleDao.findByProjectAndRuleName(projectInDb, rule.getName());
try {
importRuleReal(ruleNodeRequest, ruleInDb, rule, projectInDb, template, ruleGroup, alarmConfigs, ruleVariables, ruleDataSources, ruleDataSourceMappings);
} catch (NullPointerException e) {
LOGGER.error("Rule object attributes must not be null.", e);
}
}
use of com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method saveRuleInfo.
public void saveRuleInfo(Rule savedRule, Template template, Project projectInDb, Set<AlarmConfig> alarmConfigs, Set<RuleVariable> ruleVariables, Set<RuleDataSource> ruleDataSources, Set<RuleDataSourceMapping> ruleDataSourceMappings) {
LOGGER.info("Start to save rule Info.");
List<AlarmConfig> alarmConfigList = new ArrayList<>();
for (AlarmConfig alarmConfig : alarmConfigs) {
alarmConfig.setRule(savedRule);
ruleMetricSycn(alarmConfig);
alarmConfig.setTemplateOutputMeta(savedRule.getTemplate().getTemplateOutputMetas().iterator().next());
alarmConfigList.add(alarmConfig);
}
List<RuleVariable> ruleVariablesList = new ArrayList<>();
TemplateStatisticsInputMeta templateStatisticsInputMeta = savedRule.getTemplate().getStatisticAction().iterator().next();
for (RuleVariable ruleVariable : ruleVariables) {
ruleVariable.setRule(savedRule);
ruleVariable.setTemplateStatisticsInputMeta(templateStatisticsInputMeta);
ruleVariablesList.add(ruleVariable);
}
if (template.getId().intValue() != savedRule.getTemplate().getId().intValue()) {
ruleVariablesList.sort(Comparator.comparing(RuleVariable::getId));
List<TemplateMidTableInputMeta> templateMidTableInputMetaList = new ArrayList<>();
if (savedRule.getTemplate().getTemplateMidTableInputMetas() != null) {
templateMidTableInputMetaList.addAll(savedRule.getTemplate().getTemplateMidTableInputMetas());
templateMidTableInputMetaList.sort(Comparator.comparing(TemplateMidTableInputMeta::getId));
Iterator iterator = templateMidTableInputMetaList.iterator();
for (RuleVariable ruleVariable : ruleVariablesList) {
ruleVariable.setTemplateMidTableInputMeta((TemplateMidTableInputMeta) iterator.next());
}
}
}
List<RuleDataSource> ruleDataSourceList = new ArrayList<>();
for (RuleDataSource ruleDataSource : ruleDataSources) {
ruleDataSource.setProjectId(projectInDb.getId());
ruleDataSource.setRule(savedRule);
ruleDataSourceList.add(ruleDataSource);
}
if (RuleTypeEnum.CUSTOM_RULE.getCode().equals(savedRule.getRuleType())) {
List<AlarmConfig> customAlarmConfigs = new ArrayList<>();
for (AlarmConfig alarmConfig : alarmConfigList) {
TemplateOutputMeta templateOutputMetaInDb = savedRule.getTemplate().getTemplateOutputMetas().iterator().next();
AlarmConfig customAlarmConfig = new AlarmConfig();
customAlarmConfig.setRule(savedRule);
customAlarmConfig.setRuleMetric(alarmConfig.getRuleMetric());
customAlarmConfig.setThreshold(alarmConfig.getThreshold());
customAlarmConfig.setTemplateOutputMeta(templateOutputMetaInDb);
customAlarmConfig.setCheckTemplate(alarmConfig.getCheckTemplate());
Integer checkTemplateCode = alarmConfig.getCheckTemplate();
if (alarmConfig.getCheckTemplate().equals(CheckTemplateEnum.FIXED_VALUE.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.FULL_YEAR_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.HALF_YEAR_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.SEASON_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.MONTH_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.WEEK_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.DAY_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.HOUR_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.YEAR_ON_YEAR.getCode())) {
customAlarmConfig.setCompareType(alarmConfig.getCompareType());
}
customAlarmConfigs.add(customAlarmConfig);
}
savedRule.setAlarmConfigs(new HashSet<>(alarmConfigDao.saveAllAlarmConfig(customAlarmConfigs)));
savedRule.setRuleDataSources(new HashSet<>(ruleDataSourceDao.saveAllRuleDataSource(ruleDataSourceList)));
} else {
savedRule.setAlarmConfigs(new HashSet<>(alarmConfigDao.saveAllAlarmConfig(alarmConfigList)));
savedRule.setRuleVariables(new HashSet<>(ruleVariableDao.saveAllRuleVariable(ruleVariablesList)));
savedRule.setRuleDataSources(new HashSet<>(ruleDataSourceDao.saveAllRuleDataSource(ruleDataSourceList)));
for (RuleDataSourceMapping ruleDataSourceMapping : ruleDataSourceMappings) {
ruleDataSourceMapping.setRule(savedRule);
ruleDataSourceMappingDao.saveRuleDataSourceMapping(ruleDataSourceMapping);
}
}
}
use of com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig 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.entity.AlarmConfig in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method updateImportedFileRule.
private void updateImportedFileRule(Rule rule, Rule ruleInDb, RuleGroup ruleGroup, Set<AlarmConfig> alarmConfigs, Set<RuleDataSource> ruleDataSources) {
ruleInDb.setRuleGroup(ruleGroup);
ruleInDb.setAlarm(rule.getAlarm());
ruleInDb.setAbortOnFailure(rule.getAbortOnFailure());
alarmConfigService.deleteByRule(ruleInDb);
LOGGER.info("Succeed to delete all alarm_config. rule_id: {}", ruleInDb.getId());
ruleDataSourceService.deleteByRule(ruleInDb);
LOGGER.info("Succeed to delete all rule_dataSources. rule_id: {}", ruleInDb.getId());
Rule updateRule = ruleDao.saveRule(ruleInDb);
// Save file alarmconfig
List<AlarmConfig> alarmConfigList = new ArrayList<>();
for (AlarmConfig alarmConfig : alarmConfigs) {
alarmConfig.setRule(updateRule);
alarmConfigList.add(alarmConfig);
}
// Save file datasource
List<RuleDataSource> ruleDataSourceList = new ArrayList<>();
for (RuleDataSource ruleDataSource : ruleDataSources) {
ruleDataSource.setProjectId(updateRule.getId());
ruleDataSource.setRule(updateRule);
ruleDataSourceList.add(ruleDataSource);
}
updateRule.setAlarmConfigs(new HashSet<>(alarmConfigDao.saveAllAlarmConfig(alarmConfigList)));
updateRule.setRuleDataSources(new HashSet<>(ruleDataSourceDao.saveAllRuleDataSource(ruleDataSourceList)));
}
use of com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig 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;
}
Aggregations