use of com.webank.wedatasphere.qualitis.project.entity.Project 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);
}
use of com.webank.wedatasphere.qualitis.project.entity.Project 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);
}
use of com.webank.wedatasphere.qualitis.project.entity.Project in project Qualitis by WeBankFinTech.
the class CustomRuleServiceImpl method deleteCustomRule.
/**
* Delete custom rules, including template of custom rules
* @param request
* @return
* @throws UnExpectedRequestException
*/
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteCustomRule(DeleteCustomRuleRequest request) throws UnExpectedRequestException, PermissionDeniedRequestException {
// Check Arguments
DeleteCustomRuleRequest.checkRequest(request);
String loginUser = HttpUtils.getUserName(httpServletRequest);
// Check existence of rule by ruleId
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.CUSTOM_RULE.getCode())) {
throw new UnExpectedRequestException("rule_id: [" + request.getRuleId() + "]) {&IS_NOT_A_CUSTOM_RULE}");
}
// Update rule count of datasource
ruleDataSourceService.updateRuleDataSourceCount(ruleInDb, -1);
return deleteCustomRuleReal(ruleInDb);
}
use of com.webank.wedatasphere.qualitis.project.entity.Project 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);
}
use of com.webank.wedatasphere.qualitis.project.entity.Project in project Qualitis by WeBankFinTech.
the class ProjectRepositoryTest method test.
@Test
@Transactional
public void test() {
// 保存是否成功
Project entity = new Project();
entity.setName("junitProject");
entity.setCreateUser("setCreateUser");
entity.setCreateUserFullName("setCreateUserFullName");
entity.setDescription("setDescription");
entity.setUserDepartment("setUserDepartment");
Project saveEntity = repository.save(entity);
assertTrue(saveEntity.getId() != 0);
// 保存到数据库的对象是否和保存的值一致
List<Project> findByCreateUserList = repository.findByCreateUser(saveEntity.getCreateUser());
assertTrue(findByCreateUserList.size() > 0);
assertEquals(findByCreateUserList.get(0).getName(), saveEntity.getName());
// 根据username查询的数据库对象是否和保存的值一致
Project findByNameUser = repository.findByName(saveEntity.getName());
assertNotNull(findByNameUser);
assertEquals(findByNameUser.getName(), saveEntity.getName());
}
Aggregations