use of com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method constructAddMultiSourceRuleRequest.
private List<AddMultiSourceRuleRequest> constructAddMultiSourceRuleRequest(Map<String, List<ExcelMultiTemplateRuleByProject>> multiRulePartitionedByRuleName, Project project, String localeStr) throws UnExpectedRequestException {
List<AddMultiSourceRuleRequest> addMultiSourceRuleRequests = new ArrayList<>();
for (String ruleName : multiRulePartitionedByRuleName.keySet()) {
List<ExcelMultiTemplateRuleByProject> ruleInfos = multiRulePartitionedByRuleName.get(ruleName);
ExcelMultiTemplateRuleByProject firstCommonInfo = ruleInfos.get(0);
AddMultiSourceRuleRequest addMultiSourceRuleRequest = new AddMultiSourceRuleRequest();
String ruleTemplateName = firstCommonInfo.getTemplateName();
String ruleGroupName = firstCommonInfo.getRuleGroupName();
addMultiSourceRuleRequest.setSpecifyStaticStartupParam(firstCommonInfo.getSpecifyStaticStartupParam());
addMultiSourceRuleRequest.setDeleteFailCheckResult(firstCommonInfo.getDeleteFailCheckResult());
addMultiSourceRuleRequest.setStaticStartupParam(firstCommonInfo.getStaticStartupParam());
addMultiSourceRuleRequest.setAbortOnFailure(firstCommonInfo.getAbortOnFailure());
if (StringUtils.isBlank(ruleGroupName)) {
throw new UnExpectedRequestException("RuleGroupName {&CAN_NOT_BE_NULL_OR_EMPTY}");
}
Template template = findTemplateByName(ruleTemplateName);
if (template == null) {
throw new UnExpectedRequestException("{&TEMPLATE_NAME}: [" + ruleTemplateName + "] {&DOES_NOT_EXIST}");
}
String filter = null;
boolean alarm = false;
String clusterName = firstCommonInfo.getClusterName();
MultiDataSourceConfigRequest sourceConfigRequest = new MultiDataSourceConfigRequest();
MultiDataSourceConfigRequest targetConfigRequest = new MultiDataSourceConfigRequest();
List<MultiDataSourceJoinConfigRequest> mappings = new ArrayList<>();
List<AlarmConfigRequest> alarmConfigRequests = new ArrayList<>();
for (ExcelMultiTemplateRuleByProject excelMultiTemplateRule : ruleInfos) {
if (StringUtils.isNotBlank(excelMultiTemplateRule.getWhereFilter())) {
filter = excelMultiTemplateRule.getWhereFilter();
}
getAlarmConfig(alarmConfigRequests, excelMultiTemplateRule, template, localeStr);
getMultiDataSourceRequest(sourceConfigRequest, excelMultiTemplateRule, 0);
getMultiDataSourceRequest(targetConfigRequest, excelMultiTemplateRule, 1);
getMultiDataSourceJoinRequest(mappings, excelMultiTemplateRule);
}
if (alarmConfigRequests.size() != 0) {
alarm = true;
}
RuleGroup ruleGroupInDb = ruleGroupDao.findByRuleGroupNameAndProjectId(ruleGroupName, project.getId());
if (ruleGroupInDb != null) {
addMultiSourceRuleRequest.setRuleGroupId(ruleGroupInDb.getId());
} else {
RuleGroup ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup(ruleGroupName, project.getId()));
addMultiSourceRuleRequest.setRuleGroupId(ruleGroup.getId());
}
addMultiSourceRuleRequest.setRuleName(ruleName);
addMultiSourceRuleRequest.setClusterName(clusterName);
addMultiSourceRuleRequest.setProjectId(project.getId());
addMultiSourceRuleRequest.setRuleDetail(firstCommonInfo.getRuleDetail());
addMultiSourceRuleRequest.setMultiSourceRuleTemplateId(template.getId());
addMultiSourceRuleRequest.setAlarmVariable(alarmConfigRequests);
addMultiSourceRuleRequests.add(addMultiSourceRuleRequest);
addMultiSourceRuleRequest.setSource(sourceConfigRequest);
addMultiSourceRuleRequest.setTarget(targetConfigRequest);
addMultiSourceRuleRequest.setMappings(mappings);
addMultiSourceRuleRequest.setFilter(filter);
addMultiSourceRuleRequest.setAlarm(alarm);
}
return addMultiSourceRuleRequests;
}
use of com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method constructAddRuleRequest.
private List<AddRuleRequest> constructAddRuleRequest(Map<String, List<ExcelTemplateRuleByProject>> partitionedByRuleName, Project project, String localeStr) throws UnExpectedRequestException {
List<AddRuleRequest> addRuleRequests = new ArrayList<>();
for (String ruleName : partitionedByRuleName.keySet()) {
List<ExcelTemplateRuleByProject> ruleInfos = partitionedByRuleName.get(ruleName);
ExcelTemplateRuleByProject firstCommonInfo = ruleInfos.get(0);
AddRuleRequest addRuleRequest = new AddRuleRequest();
String ruleDetail = firstCommonInfo.getRuleDetail();
String ruleCnName = firstCommonInfo.getRuleCnName();
String ruleGroupName = firstCommonInfo.getRuleGroupName();
String ruleTemplateName = firstCommonInfo.getTemplateName();
addRuleRequest.setRuleCnName(ruleCnName);
addRuleRequest.setAbortOnFailure(firstCommonInfo.getAbortOnFailure());
addRuleRequest.setStaticStartupParam(firstCommonInfo.getStaticStartupParam());
addRuleRequest.setDeleteFailCheckResult(firstCommonInfo.getDeleteFailCheckResult());
addRuleRequest.setSpecifyStaticStartupParam(firstCommonInfo.getSpecifyStaticStartupParam());
if (StringUtils.isBlank(ruleGroupName)) {
throw new UnExpectedRequestException("RuleGroupName {&CAN_NOT_BE_NULL_OR_EMPTY}");
}
Template template = findTemplateByName(ruleTemplateName);
if (template == null) {
throw new UnExpectedRequestException("{&TEMPLATE_NAME}: [" + ruleTemplateName + "] {&DOES_NOT_EXIST}");
}
boolean alarm = false;
Long projectId = project.getId();
List<DataSourceRequest> dataSourceRequests = new ArrayList<>();
List<AlarmConfigRequest> alarmConfigRequests = new ArrayList<>();
List<TemplateArgumentRequest> templateArgumentRequests = new ArrayList<>();
for (ExcelTemplateRuleByProject excelTemplateRuleByProject : ruleInfos) {
getDataSourceRequest(dataSourceRequests, excelTemplateRuleByProject);
getTemplateArgument(templateArgumentRequests, excelTemplateRuleByProject, template);
getAlarmConfig(alarmConfigRequests, excelTemplateRuleByProject, template, localeStr);
}
RuleGroup ruleGroupInDb = ruleGroupDao.findByRuleGroupNameAndProjectId(ruleGroupName, projectId);
if (ruleGroupInDb != null) {
addRuleRequest.setRuleGroupId(ruleGroupInDb.getId());
} else {
RuleGroup ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup(ruleGroupName, project.getId()));
addRuleRequest.setRuleGroupId(ruleGroup.getId());
}
// Construct addRuleRequest
addRuleRequest.setRuleName(ruleName);
addRuleRequest.setRuleDetail(ruleDetail);
addRuleRequest.setRuleTemplateId(template.getId());
if (!alarmConfigRequests.isEmpty()) {
alarm = true;
}
addRuleRequest.setAlarmVariable(alarmConfigRequests);
addRuleRequest.setDatasource(dataSourceRequests);
addRuleRequest.setProjectId(projectId);
addRuleRequest.setAlarm(alarm);
addRuleRequest.setTemplateArgumentRequests(templateArgumentRequests);
addRuleRequests.add(addRuleRequest);
}
return addRuleRequests;
}
use of com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest 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.rule.request.AlarmConfigRequest 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);
}
Aggregations