use of com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method importChildRule.
private void importChildRule(Rule parentRule, RuleGroup ruleGroup, RuleNodeRequest ruleNodeRequest, Project projectInDb) throws IOException {
LOGGER.info("Start to import child rule.");
ObjectMapper objectMapper = new ObjectMapper();
Rule childRule = objectMapper.readValue(ruleNodeRequest.getChildRuleObject(), Rule.class);
Template childTemplate = objectMapper.readValue(ruleNodeRequest.getChildTemplateObject(), Template.class);
Set<RuleDataSource> childRuleDataSources = objectMapper.readValue(ruleNodeRequest.getChildRuleDataSourcesObject(), new TypeReference<Set<RuleDataSource>>() {
});
Set<RuleDataSourceMapping> childRuleDataSourceMappings = objectMapper.readValue(ruleNodeRequest.getChildRuleDataSourceMappingsObject(), new TypeReference<Set<RuleDataSourceMapping>>() {
});
Set<AlarmConfig> childAlarmConfigs = objectMapper.readValue(ruleNodeRequest.getChildAlarmConfigsObject(), new TypeReference<Set<AlarmConfig>>() {
});
Set<RuleVariable> childRuleVariables = objectMapper.readValue(ruleNodeRequest.getChildRuleVariablesObject(), new TypeReference<Set<RuleVariable>>() {
});
childRule.setProject(projectInDb);
childRule.setTemplate(childTemplate);
childRule.setRuleGroup(ruleGroup);
Rule savedRule = ruleDao.saveRule(childRule);
LOGGER.info("Succeed to save child rule. Rule info is {}", savedRule.toString());
List<AlarmConfig> alarmConfigList = new ArrayList<>();
for (AlarmConfig alarmConfig : childAlarmConfigs) {
alarmConfig.setRule(savedRule);
alarmConfigList.add(alarmConfig);
}
List<RuleVariable> ruleVariablesList = new ArrayList<>();
for (RuleVariable ruleVariable : childRuleVariables) {
ruleVariable.setRule(savedRule);
ruleVariablesList.add(ruleVariable);
}
List<RuleDataSource> ruleDataSourceList = new ArrayList<>();
for (RuleDataSource ruleDataSource : childRuleDataSources) {
ruleDataSource.setProjectId(projectInDb.getId());
ruleDataSource.setRule(savedRule);
ruleDataSourceList.add(ruleDataSource);
}
savedRule.setAlarmConfigs(new HashSet<>(alarmConfigDao.saveAllAlarmConfig(alarmConfigList)));
savedRule.setRuleVariables(new HashSet<>(ruleVariableDao.saveAllRuleVariable(ruleVariablesList)));
savedRule.setRuleDataSources(new HashSet<>(ruleDataSourceDao.saveAllRuleDataSource(ruleDataSourceList)));
for (RuleDataSourceMapping ruleDataSourceMapping : childRuleDataSourceMappings) {
ruleDataSourceMapping.setRule(savedRule);
ruleDataSourceMappingDao.saveRuleDataSourceMapping(ruleDataSourceMapping);
}
savedRule.setParentRule(parentRule);
parentRule.setChildRule(savedRule);
LOGGER.info("Succeed to import child rule.");
}
use of com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig 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.rule.entity.AlarmConfig 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.rule.entity.AlarmConfig 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);
}
use of com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig in project Qualitis by WeBankFinTech.
the class CustomRuleServiceImpl method addCustomRuleReal.
private GeneralResponse<RuleResponse> addCustomRuleReal(AddCustomRuleRequest request, String loginUser) throws UnExpectedRequestException, PermissionDeniedRequestException {
// Check Arguments
AddCustomRuleRequest.checkRequest(request);
String nowDate = ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date());
// Generate Template, TemplateStatisticsInputMeta and save
Template template = ruleTemplateService.addCustomTemplate(request);
TemplateDataSourceType templateDataSourceType = new TemplateDataSourceType();
if (request.getLinkisDataSourceType() == null) {
templateDataSourceType.setDataSourceTypeId(TemplateDataSourceTypeEnum.HIVE.getCode());
} else {
templateDataSourceType.setDataSourceTypeId(TemplateDataSourceTypeEnum.MYSQL.getCode());
}
templateDataSourceType.setTemplate(template);
templateDataSourceTypeDao.save(templateDataSourceType);
// Save rule, rule_alarm_config and ruleDataSource
// Check existence of project
Project projectInDb = projectService.checkProjectExistence(request.getProjectId(), loginUser);
// 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 if cluster name is supported
ruleDataSourceService.checkDataSourceClusterSupport(request.getClusterName());
RuleGroup ruleGroup;
if (request.getRuleGroupId() != null) {
ruleGroup = ruleGroupDao.findById(request.getRuleGroupId());
if (ruleGroup == null) {
throw new UnExpectedRequestException(String.format("Rule Group: %s {&CAN_NOT_BE_NULL_OR_EMPTY}", request.getRuleGroupId()));
}
} else {
ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup("Group_" + UUID.randomUUID().toString().replace("-", ""), projectInDb.getId()));
}
Rule newRule = new Rule();
// Set basic info.
setBasicInfo(newRule, projectInDb, ruleGroup, template, loginUser, nowDate, request);
String csId = request.getCsId();
// For context service.
boolean cs = false;
if (StringUtils.isNotBlank(csId)) {
newRule.setCsId(csId);
cs = true;
}
String fileId = request.getFileId();
// For fps file check.
boolean fps = false;
if (StringUtils.isNotBlank(fileId)) {
fps = true;
}
String sqlCheckArea = request.getSqlCheckArea();
// For fps file check.
boolean sqlCheck = false;
if (StringUtils.isNotBlank(sqlCheckArea)) {
sqlCheck = true;
}
Rule savedRule = ruleDao.saveRule(newRule);
LOGGER.info("Succeed to save custom rule, rule_id: {}", savedRule.getId());
List<AlarmConfig> savedAlarmConfigs = new ArrayList<>();
if (request.getAlarm()) {
savedAlarmConfigs = alarmConfigService.checkAndSaveCustomAlarmVariable(request.getAlarmVariable(), savedRule);
LOGGER.info("Succeed to save alarm_configs, alarm_configs: {}", savedAlarmConfigs);
}
List<RuleDataSource> ruleDataSources = ruleDataSourceService.checkAndSaveCustomRuleDataSource(request.getClusterName(), request.getProxyUser(), loginUser, savedRule, cs, sqlCheck, request.getLinkisDataSourceId(), request.getLinkisDataSourceVersionId(), request.getLinkisDataSourceName(), request.getLinkisDataSourceType());
savedRule.setAlarmConfigs(new HashSet<>(savedAlarmConfigs));
if (CollectionUtils.isNotEmpty(ruleDataSources)) {
savedRule.setRuleDataSources(new HashSet<>(ruleDataSources));
}
// Update rule count of datasource
ruleDataSourceService.updateRuleDataSourceCount(savedRule, 1);
RuleResponse response = new RuleResponse(savedRule);
LOGGER.info("Succeed to add custom rule, rule_id: {}", savedRule.getId());
return new GeneralResponse<>("200", "{&SUCCEED_TO_ADD_CUSTOM_RULE}", response);
}
Aggregations