use of com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method updateImportedChildRule.
public void updateImportedChildRule(Rule parentRule, RuleNodeRequest ruleNodeRequest) throws IOException, UnExpectedRequestException {
if (parentRule.getChildRule() == null) {
return;
}
LOGGER.info("Start to update imported child rule.");
ObjectMapper objectMapper = new ObjectMapper();
Rule childRule = parentRule.getChildRule();
Rule childRuleObject = objectMapper.readValue(ruleNodeRequest.getChildRuleObject(), Rule.class);
Template childTemplateObject = 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.setAlarm(childRuleObject.getAlarm());
childRule.setAbortOnFailure(childRuleObject.getAbortOnFailure());
childRule.setFromContent(childRuleObject.getFromContent());
childRule.setWhereContent(childRuleObject.getWhereContent());
childRule.setRuleType(childRuleObject.getRuleType());
childRule.setRuleTemplateName(childTemplateObject.getName());
childRule.setOutputName(childRuleObject.getOutputName());
childRule.setFunctionType(childRuleObject.getFunctionType());
childRule.setFunctionContent(childRuleObject.getFunctionContent());
Template childTemplateInDb = ruleTemplateService.checkRuleTemplate(childTemplateObject.getId());
if (childTemplateInDb == null) {
throw new UnExpectedRequestException("Child template [id = " + childTemplateObject.getId() + "] does not exist.");
}
alarmConfigService.deleteByRule(childRule);
LOGGER.info("Succeed to delete all alarm_config of child rule. rule_id: {}", childRule.getId());
ruleVariableService.deleteByRule(childRule);
LOGGER.info("Succeed to delete all rule_variable of child rule. rule_id: {}", childRule.getId());
ruleDataSourceService.deleteByRule(childRule);
LOGGER.info("Succeed to delete all rule_dataSources of child rule. rule_id: {}", childRule.getId());
ruleDataSourceMappingService.deleteByRule(childRule);
LOGGER.info("Succeed to delete all rule_dataSource_mapping. rule_id: {}", childRule.getId());
Rule updateRule = ruleDao.saveRule(childRule);
List<RuleDataSource> ruleDataSourceList = new ArrayList<>();
for (RuleDataSource ruleDataSource : childRuleDataSources) {
ruleDataSource.setProjectId(parentRule.getProject().getId());
ruleDataSource.setRule(updateRule);
ruleDataSourceList.add(ruleDataSource);
}
List<AlarmConfig> alarmConfigList = new ArrayList<>();
for (AlarmConfig alarmConfig : childAlarmConfigs) {
alarmConfig.setRule(updateRule);
alarmConfigList.add(alarmConfig);
}
List<RuleVariable> ruleVariablesList = new ArrayList<>();
for (RuleVariable ruleVariable : childRuleVariables) {
ruleVariable.setRule(updateRule);
ruleVariablesList.add(ruleVariable);
}
updateRule.setAlarmConfigs(new HashSet<>(alarmConfigDao.saveAllAlarmConfig(alarmConfigList)));
updateRule.setRuleVariables(new HashSet<>(ruleVariableDao.saveAllRuleVariable(ruleVariablesList)));
updateRule.setRuleDataSources(new HashSet<>(ruleDataSourceDao.saveAllRuleDataSource(ruleDataSourceList)));
for (RuleDataSourceMapping ruleDataSourceMapping : childRuleDataSourceMappings) {
ruleDataSourceMapping.setRule(updateRule);
ruleDataSourceMappingDao.saveRuleDataSourceMapping(ruleDataSourceMapping);
}
updateRule.setParentRule(parentRule);
parentRule.setChildRule(updateRule);
}
use of com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping 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.RuleDataSourceMapping in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method constructMultiRequest.
private AddMultiSourceRuleRequest constructMultiRequest(Rule rule, RuleGroup ruleGroup) {
AddMultiSourceRuleRequest addMultiSourceRuleRequest = new AddMultiSourceRuleRequest();
String newVersion = ruleGroup.getVersion();
if (StringUtils.isEmpty(newVersion)) {
String newRuleName = rule.getName() + "_copy_" + ruleGroup.getId();
LOGGER.info("Multi rule start to be copied. Copied rule name: " + newRuleName);
addMultiSourceRuleRequest.setRuleName(newRuleName);
if (StringUtils.isNotBlank(rule.getCnName())) {
addMultiSourceRuleRequest.setRuleCnName(rule.getCnName() + "_副本");
}
} else {
String oldVersion = rule.getRuleGroup().getVersion();
LOGGER.info("Multi rule start to be copied. Copied rule name: " + rule.getName() + "_" + ruleGroup.getVersion());
if (StringUtils.isNotBlank(oldVersion) && rule.getName().endsWith(oldVersion)) {
addMultiSourceRuleRequest.setRuleName(rule.getName().replace(oldVersion, newVersion));
if (StringUtils.isNotBlank(rule.getCnName())) {
addMultiSourceRuleRequest.setRuleCnName(rule.getCnName().replace(oldVersion, newVersion));
}
} else {
addMultiSourceRuleRequest.setRuleName(rule.getName() + "_" + newVersion);
if (StringUtils.isNotBlank(rule.getCnName())) {
addMultiSourceRuleRequest.setRuleCnName(rule.getCnName() + "_" + newVersion);
}
}
}
String ruleDetail = rule.getDetail();
String clusterName = rule.getRuleDataSources().iterator().next().getClusterName();
addMultiSourceRuleRequest.setAbortOnFailure(rule.getAbortOnFailure());
addMultiSourceRuleRequest.setClusterName(clusterName);
addMultiSourceRuleRequest.setRuleDetail(ruleDetail);
addMultiSourceRuleRequest.setCsId(rule.getCsId());
addMultiSourceRuleRequest.setSpecifyStaticStartupParam(rule.getSpecifyStaticStartupParam());
addMultiSourceRuleRequest.setDeleteFailCheckResult(rule.getDeleteFailCheckResult());
addMultiSourceRuleRequest.setMultiSourceRuleTemplateId(rule.getTemplate().getId());
addMultiSourceRuleRequest.setStaticStartupParam(rule.getStaticStartupParam());
addMultiSourceRuleRequest.setProjectId(ruleGroup.getProjectId());
addMultiSourceRuleRequest.setRuleGroupId(ruleGroup.getId());
List<RuleVariable> filterRuleVariable = rule.getRuleVariables().stream().filter(ruleVariable -> ruleVariable.getTemplateMidTableInputMeta().getInputType().equals(TemplateInputTypeEnum.CONDITION.getCode())).collect(Collectors.toList());
if (filterRuleVariable != null && filterRuleVariable.size() != 0) {
addMultiSourceRuleRequest.setFilter(filterRuleVariable.iterator().next().getValue());
}
// Data source request
for (RuleDataSource ruleDataSource : rule.getRuleDataSources()) {
String databaseName = ruleDataSource.getDbName();
String tableName = ruleDataSource.getTableName();
String filter = ruleDataSource.getFilter();
Integer datasourceIndex = ruleDataSource.getDatasourceIndex();
MultiDataSourceConfigRequest dataSourceConfigRequest = new MultiDataSourceConfigRequest();
dataSourceConfigRequest.setDbName(databaseName);
dataSourceConfigRequest.setTableName(tableName);
dataSourceConfigRequest.setFilter(filter);
dataSourceConfigRequest.setProxyUser(ruleDataSource.getProxyUser());
if (ruleDataSource.getLinkisDataSourceId() != null) {
dataSourceConfigRequest.setLinkisDataSourceType(TemplateDataSourceTypeEnum.getMessage(ruleDataSource.getDatasourceType()));
dataSourceConfigRequest.setLinkisDataSourceName(ruleDataSource.getLinkisDataSourceName());
dataSourceConfigRequest.setLinkisDataSourceId(ruleDataSource.getLinkisDataSourceId());
}
if (datasourceIndex == 0) {
addMultiSourceRuleRequest.setSource(dataSourceConfigRequest);
} else {
addMultiSourceRuleRequest.setTarget(dataSourceConfigRequest);
}
}
// Mapping
List<MultiDataSourceJoinConfigRequest> mappings = new ArrayList<>();
for (RuleDataSourceMapping mapping : rule.getRuleDataSourceMappings()) {
MultiDataSourceJoinConfigRequest multiDataSourceJoinConfigRequest = new MultiDataSourceJoinConfigRequest();
multiDataSourceJoinConfigRequest.setOperation(mapping.getOperation());
multiDataSourceJoinConfigRequest.setLeftStatement(mapping.getLeftStatement());
multiDataSourceJoinConfigRequest.setRightStatement(mapping.getRightStatement());
List<MultiDataSourceJoinColumnRequest> left = getMultiDataSourceJoinColumnRequest(mapping.getLeftColumnNames(), mapping.getLeftColumnTypes());
List<MultiDataSourceJoinColumnRequest> right = getMultiDataSourceJoinColumnRequest(mapping.getRightColumnNames(), mapping.getLeftColumnTypes());
multiDataSourceJoinConfigRequest.setLeft(left);
multiDataSourceJoinConfigRequest.setRight(right);
mappings.add(multiDataSourceJoinConfigRequest);
}
addMultiSourceRuleRequest.setMappings(mappings);
List<AlarmConfigRequest> alarmConfigRequests = constructAlarmConfigRequest(rule.getAlarmConfigs());
addMultiSourceRuleRequest.setAlarm(true);
addMultiSourceRuleRequest.setAlarmVariable(alarmConfigRequests);
return addMultiSourceRuleRequest;
}
use of com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping 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.RuleDataSourceMapping in project Qualitis by WeBankFinTech.
the class OuterExecutionServiceImpl method getMappingCols.
private void getMappingCols(Rule currentRule, List<Map<String, String>> mappingCols) {
Map<String, String> leftCols = new LinkedHashMap<>();
Map<String, String> rightCols = new LinkedHashMap<>();
for (RuleDataSourceMapping ruleDataSourceMapping : currentRule.getRuleDataSourceMappings()) {
if (StringUtils.isBlank(ruleDataSourceMapping.getLeftColumnNames()) || StringUtils.isBlank(ruleDataSourceMapping.getLeftColumnTypes()) || StringUtils.isBlank(ruleDataSourceMapping.getRightColumnNames()) || StringUtils.isBlank(ruleDataSourceMapping.getRightColumnTypes())) {
break;
}
String[] leftJoinCols = ruleDataSourceMapping.getLeftColumnNames().split(",");
String[] leftJoinTypes = ruleDataSourceMapping.getLeftColumnTypes().split("\\|");
for (int i = 0; i < leftJoinCols.length; i++) {
leftCols.put(leftJoinCols[i].split("\\.")[1], leftJoinTypes[i]);
}
String[] rightJoinCols = ruleDataSourceMapping.getRightColumnNames().split(",");
String[] rightJoinTypes = ruleDataSourceMapping.getRightColumnTypes().split("\\|");
for (int i = 0; i < rightJoinCols.length; i++) {
rightCols.put(rightJoinCols[i].split("\\.")[1], rightJoinTypes[i]);
}
}
mappingCols.add(leftCols);
mappingCols.add(rightCols);
}
Aggregations