use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class ExecutionManagerImpl method killApplication.
@Override
public GeneralResponse<?> killApplication(Application applicationInDb, String user) throws JobKillException, UnExpectedRequestException, ClusterInfoNotConfigException {
List<Task> tasks = taskDao.findByApplication(applicationInDb);
List<JobKillResult> results = new ArrayList<>();
if (tasks == null || tasks.isEmpty()) {
throw new UnExpectedRequestException("Sub tasks {&CAN_NOT_BE_NULL_OR_EMPTY}");
}
for (Task task : tasks) {
ClusterInfo clusterInfo = clusterInfoDao.findByClusterName(task.getClusterName());
if (clusterInfo == null) {
throw new ClusterInfoNotConfigException("Failed to find cluster id: " + task.getClusterName() + " configuration");
}
results.add(abstractJobSubmitter.killJob(user, clusterInfo.getClusterName(), task));
task.setStatus(TaskStatusEnum.CANCELLED.getCode());
task.setEndTime(ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date()));
taskDao.save(task);
}
return new GeneralResponse<>("200", "{&SUCCESS_TO_KILL_TASK}", results.size());
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse 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.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method importRuleGroup.
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<RuleResponse> importRuleGroup(RuleNodeRequests ruleNodeRequests) throws UnExpectedRequestException, IOException, PermissionDeniedRequestException {
// Project, rule group.
Project projectInDb = projectDao.findById(ruleNodeRequests.getNewProjectId());
ObjectMapper objectMapper = new ObjectMapper();
RuleGroup ruleGroup = objectMapper.readValue(ruleNodeRequests.getRuleNodeRequests().iterator().next().getRuleGroupObject(), RuleGroup.class);
RuleGroup ruleGroupInDb = ruleGroupDao.saveRuleGroup(new RuleGroup(ruleGroup.getRuleGroupName(), projectInDb.getId()));
if (DEV_CENTER.equals(localConfig.getCenter())) {
CopyRuleRequest copyRuleRequest = new CopyRuleRequest();
copyRuleRequest.setSourceRuleGroupId(ruleGroup.getId());
copyRuleRequest.setCreateUser(projectInDb.getCreateUser());
copyRuleRequest.setTargetRuleGroupId(ruleGroupInDb.getId());
copyRuleRequest.setTargetProjectId(ruleNodeRequests.getNewProjectId());
copyRuleByRuleGroupId(copyRuleRequest);
return new GeneralResponse<>("200", "{&IMPORT_RULE_SUCCESSFULLY}", new RuleResponse(ruleGroupInDb.getId()));
}
if (projectInDb != null) {
LOGGER.info("Project info : {}", projectInDb.toString());
} else {
// For special case:
// A project already exists in DSS. when creating a workflow in this project and publish it, Qualitis service cannot find the project.
// Because Qualitis did not run when this project had been created in DSS.
LOGGER.info("Start to create workflow project. Project[id = {}] is not exist.", ruleNodeRequests.getNewProjectId());
String userName = ruleNodeRequests.getUserName();
User currentUser = userDao.findByUsername(userName);
if (currentUser == null) {
LOGGER.info("Start to create user. User name is {}", userName);
try {
userService.autoAddUser(userName);
currentUser = userDao.findByUsername(userName);
} catch (RoleNotFoundException e) {
LOGGER.error("Role cannot be found. Exception: {}", e);
}
}
Project newProject = projectService.addProjectReal(currentUser.getId(), currentUser.getUserName() + "_project_" + UUID.randomUUID().toString(), currentUser.getUserName() + "_项目_" + UUID.randomUUID().toString(), "Auto created.");
newProject.setProjectType(ProjectTypeEnum.WORKFLOW_PROJECT.getCode());
projectInDb = projectDao.saveProject(newProject);
LOGGER.info("Succeed to create project. New project: {}", projectInDb.toString());
}
for (RuleNodeRequest request : ruleNodeRequests.getRuleNodeRequests()) {
importRule(request, projectInDb, ruleGroupInDb, objectMapper);
}
return new GeneralResponse<>("200", "{&IMPORT_RULE_SUCCESSFULLY}", new RuleResponse(ruleGroupInDb.getId()));
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method exportRuleByGroupId.
@Override
public GeneralResponse<RuleNodeResponses> exportRuleByGroupId(Long ruleGroupId) throws UnExpectedRequestException {
// Check existence of ruleGroup
RuleGroup ruleGroup = ruleGroupDao.findById(ruleGroupId);
if (ruleGroup == null) {
throw new UnExpectedRequestException("Rule group [Id = " + ruleGroupId + "] does not exist.");
}
LOGGER.info("Succeed to find rule group. Rule group id: {}.", ruleGroup.getId());
List<RuleNodeResponse> responses = new ArrayList<>();
try {
List<Rule> rules = ruleDao.findByRuleGroup(ruleGroup);
if (CollectionUtils.isEmpty(rules)) {
throw new UnExpectedRequestException("Rule group [id = " + ruleGroup.getId() + "] does not have rules.");
}
for (Rule rule : rules) {
responses.add(ruleNodeResponse(rule));
}
} catch (IOException e) {
LOGGER.error("Failed to export rule because of JSON serialization opeartions.", e);
return new GeneralResponse<>("500", "{&FAILED_TO_EXPORT_RULE}", null);
}
LOGGER.info("Succeed to export rule. Rule info: {}", Arrays.toString(responses.toArray()));
RuleNodeResponses ruleNodeResponses = new RuleNodeResponses(responses);
return new GeneralResponse<>("200", "{&EXPORT_RULE_SUCCESSFULLY}", ruleNodeResponses);
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class RuleServiceImpl method modifyRuleDetailReal.
private GeneralResponse<RuleResponse> modifyRuleDetailReal(ModifyRuleRequest request, String loginUser) throws UnExpectedRequestException, PermissionDeniedRequestException {
// Check Arguments
ModifyRuleRequest.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);
if (!ruleInDb.getRuleType().equals(RuleTypeEnum.SINGLE_TEMPLATE_RULE.getCode())) {
throw new UnExpectedRequestException("rule(id: [" + request.getRuleId() + "]) {&IS_NOT_A_RULE_WITH_TEMPLATE}");
}
// Check permissions of project
List<Integer> permissions = new ArrayList<>();
permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
projectService.checkProjectPermission(projectInDb, loginUser, permissions);
LOGGER.info("Succeed to find rule. rule_id: {}", ruleInDb.getId());
// For workflow node context.
String csId = request.getCsId();
boolean cs = false;
if (StringUtils.isNotBlank(csId)) {
cs = true;
}
ruleInDb.setCsId(csId);
// Check existence of rule template
Template templateInDb = ruleTemplateService.checkRuleTemplate(request.getRuleTemplateId());
// Check datasource size
checkDataSourceNumber(templateInDb, request.getDatasource());
// Check cluster name supported
checkDataSourceClusterLimit(request.getDatasource());
// Check arguments size
checkRuleArgumentSize(request.getTemplateArgumentRequests(), templateInDb);
// Check existence of rule
checkRuleName(request.getRuleName(), ruleInDb.getProject(), ruleInDb.getId());
// Basic rule info.
setBasicInfo(ruleInDb, templateInDb, request, loginUser);
// Delete all alarm_config,rule_variable,rule_datasource
alarmConfigService.deleteByRule(ruleInDb);
LOGGER.info("Succeed to delete all alarm_config. rule_id: {}", ruleInDb.getId());
ruleVariableService.deleteByRule(ruleInDb);
LOGGER.info("Succeed to delete all rule_variable. rule_id: {}", ruleInDb.getId());
ruleDataSourceService.deleteByRule(ruleInDb);
LOGGER.info("Succeed to delete all rule_dataSources. rule_id: {}", ruleInDb.getId());
// Update rule count of datasource
ruleDataSourceService.updateRuleDataSourceCount(ruleInDb, -1);
Rule savedRule = ruleDao.saveRule(ruleInDb);
LOGGER.info("Succeed to save rule. rule_id: {}", savedRule.getId());
// For repeat fps table name when concurrent task is running.
addUuid(request.getDatasource());
// Save alarm_config,ruleVariable和ruleDataSource
List<RuleVariable> ruleVariables = autoAdaptArgumentAndGetRuleVariable(templateInDb, request.getDatasource(), request.getTemplateArgumentRequests(), savedRule);
List<RuleVariable> savedRuleVariables = ruleVariableService.saveRuleVariable(ruleVariables);
LOGGER.info("Succeed to save rule_variable, rule_variable: {}", savedRuleVariables);
List<AlarmConfig> savedAlarmConfigs = new ArrayList<>();
if (request.getAlarm()) {
savedAlarmConfigs = alarmConfigService.checkAndSaveAlarmVariable(request.getAlarmVariable(), savedRule);
LOGGER.info("Succeed to save alarm_configs, alarm_configs: {}", savedAlarmConfigs);
}
List<RuleDataSource> savedRuleDataSource = ruleDataSourceService.checkAndSaveRuleDataSource(request.getDatasource(), savedRule, cs, loginUser);
LOGGER.info("Succeed to save rule_dataSources, rule_dataSources: {}", savedRuleDataSource);
savedRule.setRuleVariables(new HashSet<>(savedRuleVariables));
savedRule.setAlarmConfigs(new HashSet<>(savedAlarmConfigs));
savedRule.setRuleDataSources(new HashSet<>(savedRuleDataSource));
// Update rule count of datasource
ruleDataSourceService.updateRuleDataSourceCount(ruleInDb, 1);
RuleResponse response = new RuleResponse(savedRule);
LOGGER.info("Succeed to modify rule. response: {}", response);
// projectEventService.record(request.getProjectId(), loginUser, "modify", "rule[name= " + savedRule.getName() + "].", EventTypeEnum.MODIFY_PROJECT.getCode());
return new GeneralResponse<>("200", "{&MODIFY_RULE_SUCCESSFULLY}", response);
}
Aggregations