use of com.webank.wedatasphere.qualitis.rule.request.AddFileRuleRequest in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method copyRuleByRuleGroupId.
@Override
public GeneralResponse<RuleResponse> copyRuleByRuleGroupId(CopyRuleRequest request) throws UnExpectedRequestException, PermissionDeniedRequestException {
CopyRuleRequest.checkRequest(request);
Long ruleGroupId = request.getSourceRuleGroupId();
RuleGroup ruleGroupInDb = ruleGroupDao.findById(request.getSourceRuleGroupId());
int totalFinish = 0;
RuleGroup targetRuleGroup;
if (request.getTargetRuleGroupId() != null) {
RuleGroup targetRuleGroupInDb = ruleGroupDao.findById(request.getTargetRuleGroupId());
if (targetRuleGroupInDb != null) {
targetRuleGroup = targetRuleGroupInDb;
} else {
throw new UnExpectedRequestException("Rule group id is illegal.");
}
} else {
RuleGroup currentRuleGroup = new RuleGroup("Group_" + UUID.randomUUID().toString().replace("-", ""), request.getTargetProjectId() != null ? request.getTargetProjectId() : ruleGroupInDb.getProjectId());
currentRuleGroup.setVersion(request.getVersion());
targetRuleGroup = ruleGroupDao.saveRuleGroup(currentRuleGroup);
}
if (ruleGroupId != null) {
LOGGER.info("Start to copy rules of rule group[ID=" + ruleGroupId + "].");
if (ruleGroupInDb == null) {
throw new UnExpectedRequestException("Rule group {&DOES_NOT_EXIST}");
}
List<Rule> rules = ruleDao.findByRuleGroup(ruleGroupInDb);
for (Rule rule : rules) {
switch(rule.getRuleType().intValue()) {
case 1:
AddRuleRequest addRuleRequest = constructSingleRequest(rule, targetRuleGroup);
ruleService.addRuleForOuter(addRuleRequest, request.getCreateUser());
totalFinish++;
break;
case 2:
AddCustomRuleRequest addCustomRuleRequest = constructCustomRequest(rule, targetRuleGroup);
customRuleService.addRuleForOuter(addCustomRuleRequest, request.getCreateUser());
totalFinish++;
break;
case 3:
AddMultiSourceRuleRequest addMultiSourceRuleRequest = constructMultiRequest(rule, targetRuleGroup);
addMultiSourceRuleRequest.setLoginUser(request.getCreateUser());
multiSourceRuleService.addRuleForOuter(addMultiSourceRuleRequest, false);
totalFinish++;
break;
case 4:
AddFileRuleRequest addFileRuleRequest = constructFileRequest(rule, targetRuleGroup);
fileRuleService.addRuleForOuter(addFileRuleRequest, request.getCreateUser());
totalFinish++;
break;
default:
}
}
if (totalFinish != rules.size()) {
return new GeneralResponse<>("200", "{©_RULE_FAILED}", new RuleResponse(targetRuleGroup.getId()));
}
} else if (CollectionUtils.isNotEmpty(request.getSourceRuleIdList())) {
}
return new GeneralResponse<>("200", "{©_RULE_SUCCESSFULLY}", new RuleResponse(targetRuleGroup.getId()));
}
use of com.webank.wedatasphere.qualitis.rule.request.AddFileRuleRequest 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.request.AddFileRuleRequest in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method constructAddFileRuleRequest.
private List<AddFileRuleRequest> constructAddFileRuleRequest(Map<String, List<ExcelTemplateFileRuleByProject>> fileRulePartitionedByRuleName, Project project, String localeStr) throws UnExpectedRequestException {
List<AddFileRuleRequest> addFileRuleRequests = new ArrayList<>();
for (String ruleName : fileRulePartitionedByRuleName.keySet()) {
List<ExcelTemplateFileRuleByProject> ruleInfos = fileRulePartitionedByRuleName.get(ruleName);
ExcelTemplateFileRuleByProject firstCommonInfo = ruleInfos.get(0);
AddFileRuleRequest addFileRuleRequest = new AddFileRuleRequest();
String ruleGroupName = firstCommonInfo.getRuleGroupName();
if (StringUtils.isBlank(ruleGroupName)) {
throw new UnExpectedRequestException("RuleGroupName {&CAN_NOT_BE_NULL_OR_EMPTY}");
}
boolean alarm = false;
List<FileAlarmConfigRequest> alarmConfigRequests = new ArrayList<>();
DataSourceRequest dataSourceRequest = new DataSourceRequest();
Long projectId = project.getId();
for (ExcelTemplateFileRuleByProject excelTemplateFileRule : ruleInfos) {
getDataFileSourceRequest(dataSourceRequest, excelTemplateFileRule);
getFileAlarmConfig(alarmConfigRequests, excelTemplateFileRule, localeStr);
}
RuleGroup ruleGroupInDb = ruleGroupDao.findByRuleGroupNameAndProjectId(ruleGroupName, projectId);
if (ruleGroupInDb != null) {
addFileRuleRequest.setRuleGroupId(ruleGroupInDb.getId());
} else {
RuleGroup ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup(ruleGroupName, project.getId()));
addFileRuleRequest.setRuleGroupId(ruleGroup.getId());
}
// Construct addRuleRequest
addFileRuleRequest.setRuleName(ruleName);
addFileRuleRequest.setRuleDetail(firstCommonInfo.getRuleDetail());
addFileRuleRequest.setAbortOnFailure(firstCommonInfo.getAbortOnFailure());
if (!alarmConfigRequests.isEmpty()) {
alarm = true;
}
addFileRuleRequest.setAlarm(alarm);
addFileRuleRequest.setAlarmVariable(alarmConfigRequests);
addFileRuleRequest.setDatasource(dataSourceRequest);
addFileRuleRequest.setProjectId(projectId);
addFileRuleRequests.add(addFileRuleRequest);
}
return addFileRuleRequests;
}
use of com.webank.wedatasphere.qualitis.rule.request.AddFileRuleRequest in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method addTemplateFileRule.
private void addTemplateFileRule(Map<String, List<ExcelTemplateFileRuleByProject>> fileRulePartitionedByRuleName, Project project, String userName, boolean aomp) throws UnExpectedRequestException, PermissionDeniedRequestException {
Map<String, List<ExcelTemplateFileRuleByProject>> modifyRulePartitionedByRuleName = new HashMap<>(1);
Map<String, List<ExcelTemplateFileRuleByProject>> addRulePartitionedByRuleName = new HashMap<>(1);
String localeStr = httpServletRequest.getHeader("Content-Language");
for (Iterator<String> iterator = fileRulePartitionedByRuleName.keySet().iterator(); iterator.hasNext(); ) {
String currentRuleName = iterator.next();
Rule currentRule = ruleDao.findByProjectAndRuleName(project, currentRuleName);
if (currentRule != null) {
modifyRulePartitionedByRuleName.put(currentRuleName, fileRulePartitionedByRuleName.get(currentRuleName));
List<AddFileRuleRequest> addRuleRequestList = constructAddFileRuleRequest(modifyRulePartitionedByRuleName, project, localeStr);
ModifyFileRuleRequest modifyRuleRequest = new ModifyFileRuleRequest();
modifyRuleRequest.setRuleId(currentRule.getId());
AddFileRuleRequest addRuleRequest = addRuleRequestList.iterator().next();
BeanUtils.copyProperties(addRuleRequest, modifyRuleRequest);
LOGGER.info("Start to modify template file rule. request: {}", modifyRuleRequest);
if (aomp) {
fileRuleService.modifyRuleDetailForOuter(modifyRuleRequest, userName);
} else {
fileRuleService.modifyRuleDetail(modifyRuleRequest);
}
LOGGER.info("Success to modify template file rule");
modifyRulePartitionedByRuleName.clear();
} else {
addRulePartitionedByRuleName.put(currentRuleName, fileRulePartitionedByRuleName.get(currentRuleName));
List<AddFileRuleRequest> addRuleRequestList = constructAddFileRuleRequest(addRulePartitionedByRuleName, project, localeStr);
AddFileRuleRequest currentAddFileRuleRequest = addRuleRequestList.iterator().next();
LOGGER.info("Start to add template file rule. request: {}", currentAddFileRuleRequest);
if (aomp) {
fileRuleService.addRuleForOuter(currentAddFileRuleRequest, userName);
} else {
fileRuleService.addRuleForUpload(currentAddFileRuleRequest);
}
LOGGER.info("Success to add template file rule.");
addRulePartitionedByRuleName.clear();
}
}
}
use of com.webank.wedatasphere.qualitis.rule.request.AddFileRuleRequest in project Qualitis by WeBankFinTech.
the class FileRuleServiceImpl method modifyRuleDetailReal.
private GeneralResponse<RuleResponse> modifyRuleDetailReal(ModifyFileRuleRequest request, String loginUser) throws UnExpectedRequestException, PermissionDeniedRequestException {
// Check Arguments
ModifyFileRuleRequest.checkRequest(request);
// Check existence of rule
Rule ruleInDb = ruleDao.findById(request.getRuleId());
if (ruleInDb == null) {
throw new UnExpectedRequestException("rule_id [" + request.getRuleId() + "] {&DOES_NOT_EXIST}");
}
// Check existence of project
Project projectInDb = projectService.checkProjectExistence(ruleInDb.getProject().getId(), loginUser);
// Check permissions of project
List<Integer> permissions = new ArrayList<>();
permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
projectService.checkProjectPermission(projectInDb, loginUser, permissions);
if (!ruleInDb.getRuleType().equals(RuleTypeEnum.FILE_TEMPLATE_RULE.getCode())) {
throw new UnExpectedRequestException("rule(id: [" + request.getRuleId() + "]) {&IS_NOT_A_FILE_RULE}");
}
LOGGER.info("Succeed to find rule. rule_id: {}", ruleInDb.getId());
String nowDate = ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date());
String csId = request.getCsId();
boolean cs = false;
if (StringUtils.isNotBlank(csId)) {
cs = true;
ruleInDb.setCsId(csId);
} else {
LOGGER.info("Delete context service ID. rule_id: {}, cs_id: {}", ruleInDb.getId(), ruleInDb.getCsId());
ruleInDb.setCsId(csId);
LOGGER.info("After delete context service ID. rule_id: {}, cs_id: {}", ruleInDb.getId(), ruleInDb.getCsId());
}
// Check cluster support
ruleDataSourceService.checkDataSourceClusterSupport(request.getDatasource().getClusterName());
// Delete alarm config by file rule
alarmConfigService.deleteByRule(ruleInDb);
LOGGER.info("Succeed to delete all alarm_config. rule_id: {}", ruleInDb.getId());
// Delete template of file rule
ruleTemplateService.deleteFileRuleTemplate(ruleInDb.getTemplate().getId());
LOGGER.info("Succeed to delete file rule template. rule_id: {}", request.getRuleId());
// Delete rule datasource of file rule
ruleDataSourceService.deleteByRule(ruleInDb);
LOGGER.info("Succeed to delete all rule_dataSources. rule_id: {}", ruleInDb.getId());
// Update rule count of datasource
ruleDataSourceService.updateRuleDataSourceCount(ruleInDb, -1);
// Check existence of rule
AddFileRuleRequest addFileRuleRequest = new AddFileRuleRequest();
BeanUtils.copyProperties(request, addFileRuleRequest);
Template template = ruleTemplateService.addFileTemplate(addFileRuleRequest);
// Save rule
ruleInDb.setRuleType(RuleTypeEnum.FILE_TEMPLATE_RULE.getCode());
ruleInDb.setTemplate(template);
ruleInDb.setName(request.getRuleName());
ruleInDb.setCnName(request.getRuleCnName());
ruleInDb.setDetail(request.getRuleDetail());
ruleInDb.setAlarm(request.getAlarm());
ruleInDb.setRuleTemplateName(template.getName());
ruleInDb.setAbortOnFailure(request.getAbortOnFailure());
ruleInDb.setModifyUser(loginUser);
ruleInDb.setModifyTime(nowDate);
Rule savedRule = ruleDao.saveRule(ruleInDb);
LOGGER.info("Succeed to save file rule, rule_id: {}", savedRule.getId());
List<AlarmConfig> savedAlarmConfigs = new ArrayList<>();
if (request.getAlarm()) {
savedAlarmConfigs = alarmConfigService.checkAndSaveFileAlarmVariable(request.getAlarmVariable(), savedRule);
LOGGER.info("Succeed to save alarm_configs, alarm_configs: {}", savedAlarmConfigs);
}
List<RuleDataSource> ruleDataSources = new ArrayList<>();
ruleDataSources.add(ruleDataSourceService.checkAndSaveFileRuleDataSource(request.getDatasource(), savedRule, cs));
savedRule.setAlarmConfigs(new HashSet<>(savedAlarmConfigs));
savedRule.setRuleDataSources(new HashSet<>(ruleDataSources));
// Update rule count of datasource
ruleDataSourceService.updateRuleDataSourceCount(ruleInDb, 1);
RuleResponse response = new RuleResponse(savedRule);
LOGGER.info("Succeed to modify file rule, rule_id: {}", savedRule.getId());
// projectEventService.record(savedRule.getProject().getId(), loginUser, "modify", "file rule[name= " + savedRule.getName() + "].", EventTypeEnum.MODIFY_PROJECT.getCode());
return new GeneralResponse<>("200", "{&SUCCEED_TO_MODIFY_FILE_RULE}", response);
}
Aggregations