use of com.webank.wedatasphere.qualitis.rule.request.AddCustomRuleRequest 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.AddCustomRuleRequest in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method constructAddCustomRuleRequest.
private List<AddCustomRuleRequest> constructAddCustomRuleRequest(Map<String, List<ExcelCustomRuleByProject>> customRulePartitionedByRuleName, Project project, String localeStr) throws UnExpectedRequestException {
List<AddCustomRuleRequest> addCustomRuleRequests = new ArrayList<>();
for (String ruleName : customRulePartitionedByRuleName.keySet()) {
List<ExcelCustomRuleByProject> ruleInfos = customRulePartitionedByRuleName.get(ruleName);
AddCustomRuleRequest addCustomRuleRequest = new AddCustomRuleRequest();
ExcelCustomRuleByProject firstCommonInfo = ruleInfos.get(0);
boolean alarm = false;
Long projectId = project.getId();
addCustomRuleRequest.setSpecifyStaticStartupParam(firstCommonInfo.getSpecifyStaticStartupParam());
addCustomRuleRequest.setDeleteFailCheckResult(firstCommonInfo.getDeleteFailCheckResult());
addCustomRuleRequest.setStaticStartupParam(firstCommonInfo.getStaticStartupParam());
addCustomRuleRequest.setAbortOnFailure(firstCommonInfo.getAbortOnFailure());
addCustomRuleRequest.setProxyUser(firstCommonInfo.getProxyUser());
String ruleGroupName = firstCommonInfo.getRuleGroupName();
String clusterName = firstCommonInfo.getClusterName();
String outputName = firstCommonInfo.getOutputName();
String fromContent = null;
String whereContent = null;
Integer functionType = null;
String functionContent = null;
Boolean saveMidTable = firstCommonInfo.getSaveMidTable();
if (firstCommonInfo.getLinkisDataSourceId() != null) {
addCustomRuleRequest.setLinkisDataSourceId(Long.parseLong(firstCommonInfo.getLinkisDataSourceId()));
addCustomRuleRequest.setLinkisDataSourceName(firstCommonInfo.getLinkisDataSourceName());
addCustomRuleRequest.setLinkisDataSourceType(firstCommonInfo.getLinkisDataSourceType());
}
if (StringUtils.isNotBlank(firstCommonInfo.getFunctionName()) && StringUtils.isNotBlank(firstCommonInfo.getFunctionContent()) && StringUtils.isNotBlank(firstCommonInfo.getFromContent()) && StringUtils.isNotBlank(firstCommonInfo.getWhereContent())) {
functionType = FunctionTypeEnum.getFunctionTypeByName(firstCommonInfo.getFunctionName());
functionContent = firstCommonInfo.getFunctionContent();
whereContent = firstCommonInfo.getWhereContent();
fromContent = firstCommonInfo.getFromContent();
} else {
addCustomRuleRequest.setSqlCheckArea(firstCommonInfo.getSqlCheckArea());
}
List<CustomAlarmConfigRequest> alarmConfigRequests = new ArrayList<>();
for (ExcelCustomRuleByProject excelCustomRule : ruleInfos) {
getCustomAlarmConfig(alarmConfigRequests, excelCustomRule, localeStr);
}
if (StringUtils.isBlank(ruleGroupName)) {
throw new UnExpectedRequestException("RuleGroupName {&CAN_NOT_BE_NULL_OR_EMPTY}");
}
RuleGroup ruleGroupInDb = ruleGroupDao.findByRuleGroupNameAndProjectId(ruleGroupName, projectId);
if (ruleGroupInDb != null) {
addCustomRuleRequest.setRuleGroupId(ruleGroupInDb.getId());
} else {
RuleGroup ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup(ruleGroupName, project.getId()));
addCustomRuleRequest.setRuleGroupId(ruleGroup.getId());
}
addCustomRuleRequest.setRuleName(ruleName);
addCustomRuleRequest.setRuleCnName(firstCommonInfo.getRuleCnName());
addCustomRuleRequest.setRuleDetail(firstCommonInfo.getRuleDetail());
if (!alarmConfigRequests.isEmpty()) {
alarm = true;
}
addCustomRuleRequest.setAlarm(alarm);
addCustomRuleRequest.setProjectId(projectId);
addCustomRuleRequest.setOutputName(outputName);
addCustomRuleRequest.setFunctionType(functionType);
addCustomRuleRequest.setSaveMidTable(saveMidTable);
addCustomRuleRequest.setFunctionContent(functionContent);
addCustomRuleRequest.setAlarmVariable(alarmConfigRequests);
addCustomRuleRequest.setWhereContent(whereContent);
addCustomRuleRequest.setFromContent(fromContent);
addCustomRuleRequest.setClusterName(clusterName);
addCustomRuleRequests.add(addCustomRuleRequest);
}
return addCustomRuleRequests;
}
use of com.webank.wedatasphere.qualitis.rule.request.AddCustomRuleRequest in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method addCustomRule.
private void addCustomRule(Map<String, List<ExcelCustomRuleByProject>> customRulePartitionedByRuleName, Project project, String userName, boolean aomp) throws UnExpectedRequestException, SemanticException, ParseException, TaskNotExistException, ClusterInfoNotConfigException, MetaDataAcquireFailedException, PermissionDeniedRequestException {
Map<String, List<ExcelCustomRuleByProject>> modifyRulePartitionedByRuleName = new HashMap<>(1);
Map<String, List<ExcelCustomRuleByProject>> addRulePartitionedByRuleName = new HashMap<>(1);
String localeStr = httpServletRequest.getHeader("Content-Language");
for (Iterator<String> iterator = customRulePartitionedByRuleName.keySet().iterator(); iterator.hasNext(); ) {
String currentRuleName = iterator.next();
Rule currentRule = ruleDao.findByProjectAndRuleName(project, currentRuleName);
if (currentRule != null) {
modifyRulePartitionedByRuleName.put(currentRuleName, customRulePartitionedByRuleName.get(currentRuleName));
List<AddCustomRuleRequest> addRuleRequestList = constructAddCustomRuleRequest(modifyRulePartitionedByRuleName, project, localeStr);
ModifyCustomRuleRequest modifyRuleRequest = new ModifyCustomRuleRequest();
modifyRuleRequest.setRuleId(currentRule.getId());
AddCustomRuleRequest addRuleRequest = addRuleRequestList.iterator().next();
BeanUtils.copyProperties(addRuleRequest, modifyRuleRequest);
LOGGER.info("Start to modify custom rule. request: {}", modifyRuleRequest);
if (aomp) {
customRuleService.modifyRuleDetailForOuter(modifyRuleRequest, userName);
} else {
customRuleService.modifyCustomRule(modifyRuleRequest);
}
LOGGER.info("Succeed to modify custom rule");
modifyRulePartitionedByRuleName.clear();
} else {
addRulePartitionedByRuleName.put(currentRuleName, customRulePartitionedByRuleName.get(currentRuleName));
List<AddCustomRuleRequest> addRuleRequestList = constructAddCustomRuleRequest(addRulePartitionedByRuleName, project, localeStr);
AddCustomRuleRequest currentAddCustomRuleRequest = addRuleRequestList.iterator().next();
LOGGER.info("Start to add custom rule. request: {}", currentAddCustomRuleRequest);
if (aomp) {
customRuleService.addRuleForOuter(currentAddCustomRuleRequest, userName);
} else {
customRuleService.addCustomRuleForUpload(currentAddCustomRuleRequest);
}
LOGGER.info("Succeed to add custom rule");
addRulePartitionedByRuleName.clear();
}
}
}
use of com.webank.wedatasphere.qualitis.rule.request.AddCustomRuleRequest in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method constructCustomRequest.
private AddCustomRuleRequest constructCustomRequest(Rule rule, RuleGroup ruleGroup) {
AddCustomRuleRequest addCustomRuleRequest = new AddCustomRuleRequest();
String newVersion = ruleGroup.getVersion();
if (StringUtils.isEmpty(newVersion)) {
String newRuleName = rule.getName() + "_copy_" + ruleGroup.getId();
LOGGER.info("Custom rule start to be copied. Copied rule name: " + newRuleName);
addCustomRuleRequest.setRuleName(newRuleName);
if (StringUtils.isNotBlank(rule.getCnName())) {
addCustomRuleRequest.setRuleCnName(rule.getCnName() + "_副本");
}
} else {
String oldVersion = rule.getRuleGroup().getVersion();
LOGGER.info("Custom rule start to be copied. Copied rule name: " + rule.getName() + "_" + ruleGroup.getVersion());
if (StringUtils.isNotBlank(oldVersion) && rule.getName().endsWith(oldVersion)) {
addCustomRuleRequest.setRuleName(rule.getName().replace(oldVersion, newVersion));
if (StringUtils.isNotBlank(rule.getCnName())) {
addCustomRuleRequest.setRuleCnName(rule.getCnName().replace(oldVersion, newVersion));
}
} else {
addCustomRuleRequest.setRuleName(rule.getName() + "_" + newVersion);
if (StringUtils.isNotBlank(rule.getCnName())) {
addCustomRuleRequest.setRuleCnName(rule.getCnName() + "_" + newVersion);
}
}
}
addCustomRuleRequest.setRuleDetail(rule.getDetail());
addCustomRuleRequest.setSaveMidTable(rule.getTemplate().getSaveMidTable());
if (rule.getFunctionType() != null && StringUtils.isNotBlank(rule.getFunctionContent()) && StringUtils.isNotBlank(rule.getFromContent()) && StringUtils.isNotBlank(rule.getWhereContent())) {
String functionContent = rule.getFunctionContent();
String whereContent = rule.getWhereContent();
String fromContent = rule.getFromContent();
addCustomRuleRequest.setFunctionType(rule.getFunctionType());
addCustomRuleRequest.setFunctionContent(functionContent);
addCustomRuleRequest.setWhereContent(whereContent);
addCustomRuleRequest.setFromContent(fromContent);
} else {
addCustomRuleRequest.setSqlCheckArea(rule.getTemplate().getMidTableAction());
}
addCustomRuleRequest.setAlarm(true);
addCustomRuleRequest.setAlarmVariable(constructCustomAlarmConfigRequest(rule.getAlarmConfigs(), addCustomRuleRequest));
RuleDataSource ruleDataSource = rule.getRuleDataSources().iterator().next();
addCustomRuleRequest.setClusterName(ruleDataSource.getClusterName());
addCustomRuleRequest.setProxyUser(ruleDataSource.getProxyUser());
addCustomRuleRequest.setProjectId(ruleGroup.getProjectId());
addCustomRuleRequest.setRuleGroupId(ruleGroup.getId());
addCustomRuleRequest.setCsId(rule.getCsId());
addCustomRuleRequest.setAbortOnFailure(rule.getAbortOnFailure());
addCustomRuleRequest.setStaticStartupParam(rule.getStaticStartupParam());
addCustomRuleRequest.setSpecifyStaticStartupParam(rule.getSpecifyStaticStartupParam());
if (ruleDataSource.getLinkisDataSourceId() != null) {
addCustomRuleRequest.setLinkisDataSourceId(ruleDataSource.getLinkisDataSourceId());
addCustomRuleRequest.setLinkisDataSourceName(ruleDataSource.getLinkisDataSourceName());
addCustomRuleRequest.setLinkisDataSourceType(TemplateDataSourceTypeEnum.getMessage(ruleDataSource.getDatasourceType()));
}
return addCustomRuleRequest;
}
use of com.webank.wedatasphere.qualitis.rule.request.AddCustomRuleRequest in project Qualitis by WeBankFinTech.
the class CustomRuleServiceImpl method modifyCustomRuleReal.
private GeneralResponse<RuleResponse> modifyCustomRuleReal(ModifyCustomRuleRequest request, String loginUser) throws UnExpectedRequestException, MetaDataAcquireFailedException, PermissionDeniedRequestException {
ModifyCustomRuleRequest.checkRequest(request);
Rule ruleInDb = ruleDao.findById(request.getRuleId());
if (ruleInDb == null) {
throw new UnExpectedRequestException("rule_id [" + request.getRuleId() + "] {&DOES_NOT_EXIST}");
}
Project projectInDb = projectService.checkProjectExistence(ruleInDb.getProject().getId(), loginUser);
if (!ruleInDb.getRuleType().equals(RuleTypeEnum.CUSTOM_RULE.getCode())) {
throw new UnExpectedRequestException("rule_id: [" + request.getRuleId() + "]) {&IS_NOT_A_CUSTOM_RULE}");
}
// Check permissions of project
List<Integer> permissions = new ArrayList<>();
permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
projectService.checkProjectPermission(projectInDb, loginUser, permissions);
LOGGER.info("Succeed to find custom rule. rule_id: {}", ruleInDb.getId());
// Check existence of project name
ruleService.checkRuleName(request.getRuleName(), ruleInDb.getProject(), ruleInDb.getId());
// Check if cluster name supported
ruleDataSourceService.checkDataSourceClusterSupport(request.getClusterName());
String nowDate = ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date());
// Delete alarm config by custom rule
alarmConfigService.deleteByRule(ruleInDb);
LOGGER.info("Succeed to delete all alarm_config. rule_id: {}", ruleInDb.getId());
// Delete template of custom rule
ruleTemplateService.deleteCustomTemplate(ruleInDb.getTemplate());
LOGGER.info("Succeed to delete custom rule template. rule_id: {}", request.getRuleId());
// Delete rule datasource of custom 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);
// Save template, alarm config, rule datasource of custom rule
AddCustomRuleRequest addCustomRuleRequest = new AddCustomRuleRequest();
BeanUtils.copyProperties(request, addCustomRuleRequest);
Template template = ruleTemplateService.addCustomTemplate(addCustomRuleRequest);
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);
// Modify custom rule and save
setBasicInfo(ruleInDb, template, loginUser, nowDate, request);
String csId = request.getCsId();
ruleInDb.setCsId(csId);
boolean cs = false;
if (StringUtils.isNotBlank(csId)) {
cs = true;
}
String fileId = request.getFileId();
boolean fps = false;
if (StringUtils.isNotBlank(fileId)) {
fps = true;
}
String sqlCheckArea = request.getSqlCheckArea();
boolean sqlCheck = false;
if (StringUtils.isNotBlank(sqlCheckArea)) {
sqlCheck = true;
}
Rule savedRule = ruleDao.saveRule(ruleInDb);
// Save alarm config and rule datasource
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(ruleInDb, 1);
RuleResponse response = new RuleResponse(savedRule);
LOGGER.info("Succeed to modify custom rule, rule_id: {}", savedRule.getId());
// projectEventService.record(savedRule.getProject().getId(), loginUser, "modify", "custom rule[name= " + savedRule.getName() + "].", EventTypeEnum.MODIFY_PROJECT.getCode());
return new GeneralResponse<>("200", "{&SUCCEED_TO_MODIFY_CUSTOM_RULE}", response);
}
Aggregations