use of com.webank.wedatasphere.qualitis.entity.RuleMetric in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method constructAlarmConfigRequest.
private List<AlarmConfigRequest> constructAlarmConfigRequest(Set<AlarmConfig> alarmConfigs) {
List<AlarmConfigRequest> alarmConfigRequests = new ArrayList<>(alarmConfigs.size());
for (AlarmConfig alarmConfig : alarmConfigs) {
AlarmConfigRequest alarmConfigRequest = new AlarmConfigRequest();
alarmConfigRequest.setOutputMetaId(alarmConfig.getTemplateOutputMeta().getId());
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());
alarmConfigRequests.add(alarmConfigRequest);
}
return alarmConfigRequests;
}
use of com.webank.wedatasphere.qualitis.entity.RuleMetric in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method updateImportedRule.
public void updateImportedRule(Rule rule, Rule ruleInDb, RuleGroup ruleGroup, RuleNodeRequest ruleNodeRequest, Template template, Set<AlarmConfig> alarmConfigs, Set<RuleVariable> ruleVariables, Set<RuleDataSource> ruleDataSources, Set<RuleDataSourceMapping> ruleDataSourceMappings) throws UnExpectedRequestException, IOException {
ruleInDb.setRuleGroup(ruleGroup);
ruleInDb.setAlarm(rule.getAlarm());
ruleInDb.setAbortOnFailure(rule.getAbortOnFailure());
ruleInDb.setFromContent(rule.getFromContent());
ruleInDb.setWhereContent(rule.getWhereContent());
ruleInDb.setRuleType(rule.getRuleType());
ruleInDb.setRuleTemplateName(template.getName());
ruleInDb.setOutputName(rule.getOutputName());
ruleInDb.setFunctionType(rule.getFunctionType());
ruleInDb.setFunctionContent(rule.getFunctionContent());
ruleInDb.setDeleteFailCheckResult(rule.getDeleteFailCheckResult());
if (RuleTypeEnum.CUSTOM_RULE.getCode().equals(rule.getRuleType())) {
ruleTemplateService.deleteCustomTemplate(ruleInDb.getTemplate());
Template savedTemplate = ruleTemplateDao.saveTemplate(template);
Set<TemplateStatisticsInputMeta> templateStatisticsInputMetas = new HashSet<>();
Set<TemplateOutputMeta> templateOutputMetaSet = new HashSet<>();
if (rule.getOutputName() != null && rule.getFunctionType() != null && rule.getFunctionContent() != null) {
templateStatisticsInputMetas = templateStatisticsInputMetaService.getAndSaveTemplateStatisticsInputMeta(rule.getOutputName(), rule.getFunctionType(), rule.getFunctionContent(), savedTemplate.getSaveMidTable(), savedTemplate);
templateOutputMetaSet = templateOutputMetaService.getAndSaveTemplateOutputMeta(rule.getOutputName(), rule.getFunctionType(), savedTemplate.getSaveMidTable(), savedTemplate);
} else {
List<RuleMetric> ruleMetrics = alarmConfigs.stream().map(AlarmConfig::getRuleMetric).collect(Collectors.toList());
for (RuleMetric ruleMetric : ruleMetrics) {
templateStatisticsInputMetas.addAll(templateStatisticsInputMetaService.getAndSaveTemplateStatisticsInputMeta(ruleMetric.getName(), FunctionTypeEnum.MAX_FUNCTION.getCode(), ruleMetric.getName(), savedTemplate.getSaveMidTable(), savedTemplate));
templateOutputMetaSet.addAll(templateOutputMetaService.getAndSaveTemplateOutputMeta(ruleMetric.getName(), FunctionTypeEnum.MAX_FUNCTION.getCode(), savedTemplate.getSaveMidTable(), savedTemplate));
}
}
savedTemplate.setStatisticAction(templateStatisticsInputMetas);
savedTemplate.setTemplateOutputMetas(templateOutputMetaSet);
ruleInDb.setTemplate(savedTemplate);
} else {
synchroRuleTemplate(ruleNodeRequest, ruleInDb, template, ruleDataSources);
}
alarmConfigService.deleteByRule(ruleInDb);
LOGGER.info("Succeed to delete all alarm_config. rule_id: {}", ruleInDb.getId());
Integer ruleType = ruleInDb.getRuleType();
if (RuleTypeEnum.SINGLE_TEMPLATE_RULE.getCode().equals(ruleType) || RuleTypeEnum.MULTI_TEMPLATE_RULE.getCode().equals(ruleType)) {
ruleVariableService.deleteByRule(ruleInDb);
LOGGER.info("Succeed to delete all rule_variable. rule_id: {}", ruleInDb.getId());
if (RuleTypeEnum.MULTI_TEMPLATE_RULE.getCode().equals(ruleType)) {
ruleDataSourceMappingService.deleteByRule(ruleInDb);
LOGGER.info("Succeed to delete all rule_dataSource_mapping. rule_id: {}", ruleInDb.getId());
}
}
ruleDataSourceService.deleteByRule(ruleInDb);
LOGGER.info("Succeed to delete all rule_dataSources. rule_id: {}", ruleInDb.getId());
Rule updateRule = ruleDao.saveRule(ruleInDb);
saveRuleInfo(updateRule, template, updateRule.getProject(), alarmConfigs, ruleVariables, ruleDataSources, ruleDataSourceMappings);
updateImportedChildRule(updateRule, ruleNodeRequest);
}
use of com.webank.wedatasphere.qualitis.entity.RuleMetric in project Qualitis by WeBankFinTech.
the class AlarmConfigServiceImpl method checkAndSaveCustomAlarmVariable.
@Override
public List<AlarmConfig> checkAndSaveCustomAlarmVariable(List<CustomAlarmConfigRequest> requests, Rule rule) throws UnExpectedRequestException {
List<AlarmConfig> alarmConfigs = new ArrayList<>();
List<RuleMetric> ruleMetrics = new ArrayList<>();
for (CustomAlarmConfigRequest request : requests) {
AlarmConfig newAlarmConfig = new AlarmConfig();
RuleMetric ruleMetric = ruleMetricDao.findByEnCode(request.getRuleMetricEnCode());
newAlarmConfig.setRuleMetric(ruleMetric);
ruleMetrics.add(ruleMetric);
// Check existence of templateOutputMeta
TemplateOutputMeta templateOutputMetaInDb = rule.getTemplate().getTemplateOutputMetas().stream().filter(f -> f.getOutputName().equals(ruleMetric.getName())).iterator().next();
// Generate alarmConfig and save
newAlarmConfig.setRule(rule);
newAlarmConfig.setTemplateOutputMeta(templateOutputMetaInDb);
newAlarmConfig.setCheckTemplate(request.getCheckTemplate());
newAlarmConfig.setThreshold(request.getThreshold());
Integer checkTemplateCode = request.getCheckTemplate();
if (checkTemplateCode.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())) {
newAlarmConfig.setCompareType(request.getCompareType());
}
newAlarmConfig.setUploadAbnormalValue(request.getUploadAbnormalValue());
newAlarmConfig.setUploadRuleMetricValue(request.getUploadRuleMetricValue());
newAlarmConfig.setDeleteFailCheckResult(request.getDeleteFailCheckResult());
alarmConfigs.add(newAlarmConfig);
}
Set<String> deptNames = ruleMetrics.stream().map(RuleMetric::getDepartmentName).collect(Collectors.toSet());
if (deptNames.size() > 1) {
throw new UnExpectedRequestException("{&NOT_SAME_DEPT_SYS_METRIC}");
}
return alarmConfigDao.saveAllAlarmConfig(alarmConfigs);
}
use of com.webank.wedatasphere.qualitis.entity.RuleMetric in project Qualitis by WeBankFinTech.
the class AlarmConfigServiceImpl method checkAndSaveAlarmVariable.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public List<AlarmConfig> checkAndSaveAlarmVariable(List<AlarmConfigRequest> requests, Rule rule) throws UnExpectedRequestException {
List<AlarmConfig> alarmConfigs = new ArrayList<>();
for (AlarmConfigRequest request : requests) {
// Check Arguments
AlarmConfigRequest.checkRequest(request);
// Check existence of templateOutputMeta
TemplateOutputMeta templateOutputMetaInDb = templateOutputMetaService.checkTemplateOutputMetaId(request.getOutputMetaId());
// return if is multi-table template
if (isChildOrParentOutput(rule.getTemplate(), templateOutputMetaInDb)) {
continue;
}
// Check template output meta
checkTemplateContain(rule.getTemplate(), templateOutputMetaInDb);
// Generate alarmConfig and save
AlarmConfig newAlarmConfig = new AlarmConfig();
newAlarmConfig.setRule(rule);
newAlarmConfig.setTemplateOutputMeta(templateOutputMetaInDb);
newAlarmConfig.setCheckTemplate(request.getCheckTemplate());
newAlarmConfig.setThreshold(request.getThreshold());
Integer checkTemplateCode = request.getCheckTemplate();
if (checkTemplateCode.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())) {
newAlarmConfig.setCompareType(request.getCompareType());
}
if (StringUtils.isNotBlank(request.getRuleMetricEnCode())) {
RuleMetric ruleMetric = ruleMetricDao.findByEnCode(request.getRuleMetricEnCode());
newAlarmConfig.setRuleMetric(ruleMetric);
newAlarmConfig.setUploadAbnormalValue(request.getUploadAbnormalValue());
newAlarmConfig.setUploadRuleMetricValue(request.getUploadRuleMetricValue());
}
alarmConfigs.add(newAlarmConfig);
}
return alarmConfigDao.saveAllAlarmConfig(alarmConfigs);
}
use of com.webank.wedatasphere.qualitis.entity.RuleMetric in project Qualitis by WeBankFinTech.
the class AlarmConfigServiceImpl method checkAndSaveFileAlarmVariable.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public List<AlarmConfig> checkAndSaveFileAlarmVariable(List<FileAlarmConfigRequest> requests, Rule rule) {
List<AlarmConfig> alarmConfigs = new ArrayList<>();
for (FileAlarmConfigRequest request : requests) {
// Generate alarmConfig and save
AlarmConfig newAlarmConfig = new AlarmConfig();
newAlarmConfig.setFileOutputName(request.getFileOutputName());
newAlarmConfig.setFileOutputUnit(request.getFileOutputUnit());
newAlarmConfig.setRule(rule);
newAlarmConfig.setCheckTemplate(request.getCheckTemplate());
newAlarmConfig.setThreshold(request.getThreshold());
Integer checkTemplateCode = request.getCheckTemplate();
if (checkTemplateCode.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())) {
newAlarmConfig.setCompareType(request.getCompareType());
}
if (StringUtils.isNotBlank(request.getRuleMetricEnCode())) {
RuleMetric ruleMetric = ruleMetricDao.findByEnCode(request.getRuleMetricEnCode());
newAlarmConfig.setRuleMetric(ruleMetric);
}
newAlarmConfig.setUploadAbnormalValue(request.getUploadAbnormalValue());
newAlarmConfig.setUploadRuleMetricValue(request.getUploadRuleMetricValue());
newAlarmConfig.setDeleteFailCheckResult(request.getDeleteFailCheckResult());
alarmConfigs.add(newAlarmConfig);
}
return alarmConfigDao.saveAllAlarmConfig(alarmConfigs);
}
Aggregations