use of com.webank.wedatasphere.qualitis.request.RuleListExecutionRequest in project Qualitis by WeBankFinTech.
the class OuterExecutionServiceImpl method ruleListExecution.
@Override
public GeneralResponse<?> ruleListExecution(RuleListExecutionRequest request, Integer invokeCode) throws UnExpectedRequestException, PermissionDeniedRequestException {
LOGGER.info("Execute application by rules. rule_ids: {}", request.getRuleList());
// Check Arguments.
RuleListExecutionRequest.checkRequest(request);
String loginUser = getLoginUser(httpServletRequest, request.getCreateUser(), request.getAsync());
// Check the existence of rule.
List<Rule> rules = ruleDao.findByIds(request.getRuleList());
if (CollectionUtils.isEmpty(rules)) {
throw new UnExpectedRequestException("{&NO_RULE_CAN_BE_EXECUTED}");
}
List<Long> ruleIds = rules.stream().map(Rule::getId).distinct().collect(Collectors.toList());
// Check rule exists on the request.
List<Long> notExistRules = request.getRuleList().stream().filter(ruleId -> !ruleIds.contains(ruleId)).collect(Collectors.toList());
if (!notExistRules.isEmpty()) {
throw new UnExpectedRequestException("The ids of rule: " + notExistRules.toString() + " {&DOES_NOT_EXIST}");
}
LOGGER.info("Succeed to find all rules.");
checkPermissionCreateUserProxyExecuteUser(request.getCreateUser(), request.getExecutionUser());
StringBuffer runDate = new StringBuffer();
StringBuffer partition = new StringBuffer();
Map<String, String> execParamMap = new HashMap<>(5);
parseExecParams(partition, runDate, request.getExecutionParam(), execParamMap);
ApplicationProjectResponse applicationProjectResponse = new ApplicationProjectResponse();
List<ApplicationSubmitRequest> applicationSubmitRequests = new ArrayList<>(rules.size());
List<Project> projects = rules.stream().map(Rule::getProject).distinct().collect(Collectors.toList());
GeneralResponse<ApplicationTaskSimpleResponse> generalResponse;
// Check permissions of projects.
for (Project projectInDb : projects) {
List<Integer> permissions = new ArrayList<>();
permissions.add(ProjectUserPermissionEnum.OPERATOR.getCode());
projectService.checkProjectPermission(projectInDb, loginUser, permissions);
List<Rule> currentRules = rules.stream().filter(rule -> rule.getProject().getId().equals(projectInDb.getId())).collect(Collectors.toList());
List<RuleGroup> currentRuleGroups = currentRules.stream().map(Rule::getRuleGroup).distinct().collect(Collectors.toList());
for (RuleGroup ruleGroup : currentRuleGroups) {
List<Rule> currentRulesOfGroup = currentRules.stream().filter(rule -> rule.getRuleGroup().getRuleGroupName().equals(ruleGroup.getRuleGroupName())).distinct().collect(Collectors.toList());
List<Long> currentRuleIds = currentRulesOfGroup.stream().map(Rule::getId).distinct().collect(Collectors.toList());
// Dynamic partition.
try {
submitRulesWithDynamicPartition(applicationSubmitRequests, projectInDb.getId(), ruleGroup.getId(), currentRulesOfGroup, currentRuleIds, request.getExecutionUser(), request.getDyNamicPartition(), request.getClusterName(), partition, request.getDyNamicPartitionPrefix());
if (CollectionUtils.isEmpty(currentRuleIds)) {
continue;
}
} catch (ResourceAccessException e) {
// Record submit failed applicatoin.
generateAbnormalApplicationInfo(projectInDb.getId(), ruleGroup.getId(), request.getCreateUser(), request.getExecutionUser(), new Date(), invokeCode, partition.toString(), request.getStartupParamName(), request.getExecutionParam(), e, ApplicationCommentEnum.METADATA_ISSUES.getCode(), ApplicationStatusEnum.TASK_SUBMIT_FAILED.getCode(), rules);
LOGGER.error("One group execution[id={}] of the rule list execution start failed!", ruleGroup.getId());
} catch (NoPartitionException e) {
// Record submit failed applicatoin.
generateAbnormalApplicationInfo(projectInDb.getId(), ruleGroup.getId(), request.getCreateUser(), request.getExecutionUser(), new Date(), invokeCode, partition.toString(), request.getStartupParamName(), request.getExecutionParam(), e, ApplicationCommentEnum.METADATA_ISSUES.getCode(), ApplicationStatusEnum.TASK_SUBMIT_FAILED.getCode(), rules);
LOGGER.error("One group execution[id={}] of the rule list execution start failed!", ruleGroup.getId());
} catch (Exception e) {
// Record submit failed applicatoin.
generateAbnormalApplicationInfo(projectInDb.getId(), ruleGroup.getId(), request.getCreateUser(), request.getExecutionUser(), new Date(), invokeCode, partition.toString(), request.getStartupParamName(), request.getExecutionParam(), e, ApplicationCommentEnum.METADATA_ISSUES.getCode(), ApplicationStatusEnum.TASK_SUBMIT_FAILED.getCode(), rules);
LOGGER.error("One group execution[id={}] of the rule list execution start failed!", ruleGroup.getId());
}
applicationSubmitRequests.add(new ApplicationSubmitRequest(projectInDb.getId(), ruleGroup.getId(), currentRuleIds, partition));
}
projectEventService.record(projectInDb.getId(), loginUser, "submit rule list execution", "rule name[" + Arrays.toString(currentRules.toArray()) + "].", EventTypeEnum.SUBMIT_PROJECT.getCode());
}
for (ApplicationSubmitRequest applicationSubmitRequest : applicationSubmitRequests) {
generalResponse = (GeneralResponse<ApplicationTaskSimpleResponse>) outerExecutionService.submitRules(applicationSubmitRequest.getRuleIds(), applicationSubmitRequest.getPartition(), loginUser, request.getExecutionUser(), DEFAULT_NODE_NAME, applicationSubmitRequest.getProjectId(), applicationSubmitRequest.getRuleGroupId(), request.getStartupParamName(), request.getClusterName(), request.getSetFlag(), execParamMap, request.getExecutionParam(), runDate, invokeCode);
applicationProjectResponse.getApplicationTaskSimpleResponses().add(generalResponse.getData());
}
return new GeneralResponse<>("200", "{&SUCCEED_TO_DISPATCH_TASK}", applicationProjectResponse);
}
use of com.webank.wedatasphere.qualitis.request.RuleListExecutionRequest in project Qualitis by WeBankFinTech.
the class OuterExecutionServiceImpl method generalExecution.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> generalExecution(GeneralExecutionRequest request) throws UnExpectedRequestException, PermissionDeniedRequestException {
// Generator application information
GeneralExecutionRequest.checkRequest(request);
if (request.getDyNamicPartitionPrefix() == null) {
request.setDyNamicPartitionPrefix("");
}
if (request.getProjectId() != null) {
ProjectExecutionRequest projectExecutionRequest = new ProjectExecutionRequest();
BeanUtils.copyProperties(request, projectExecutionRequest);
return projectExecution(projectExecutionRequest, InvokeTypeEnum.BDP_CLIENT_API_INVOKE.getCode());
} else if (CollectionUtils.isNotEmpty(request.getRuleList())) {
RuleListExecutionRequest ruleListExecutionRequest = new RuleListExecutionRequest();
BeanUtils.copyProperties(request, ruleListExecutionRequest);
return ruleListExecution(ruleListExecutionRequest, InvokeTypeEnum.BDP_CLIENT_API_INVOKE.getCode());
} else if (request.getGroupId() != null) {
GroupExecutionRequest groupExecutionRequest = new GroupExecutionRequest();
BeanUtils.copyProperties(request, groupExecutionRequest);
return groupExecution(groupExecutionRequest, InvokeTypeEnum.FLOW_API_INVOKE.getCode());
} else if (StringUtils.isNotBlank(request.getProjectName())) {
Project projectInDb = projectDao.findByNameAndCreateUser(request.getProjectName(), request.getCreateUser());
if (projectInDb == null) {
List<Integer> permissions = new ArrayList<>();
permissions.add(ProjectUserPermissionEnum.CREATOR.getCode());
permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
List<Project> projects = projectUserDao.findByUsernameAndPermission(request.getExecutionUser(), permissions);
if (CollectionUtils.isEmpty(projects)) {
throw new UnExpectedRequestException("Pick project has no permissions.");
}
List<Project> execProject = projects.stream().filter(project -> project.getName().equals(request.getProjectName())).collect(Collectors.toList());
if (CollectionUtils.isEmpty(execProject)) {
throw new UnExpectedRequestException("Pick project has no permissions.");
} else if (execProject.size() > 1) {
throw new UnExpectedRequestException("Pick project has dubplicate names.");
}
projectInDb = execProject.iterator().next();
}
if (CollectionUtils.isNotEmpty(request.getRuleNameList())) {
List<Long> ruleIds = new ArrayList<>(request.getRuleNameList().size());
for (String ruleName : request.getRuleNameList()) {
Rule rule = ruleDao.findByProjectAndRuleName(projectInDb, ruleName);
ruleIds.add(rule.getId());
}
request.setRuleList(ruleIds);
RuleListExecutionRequest ruleListExecutionRequest = new RuleListExecutionRequest();
BeanUtils.copyProperties(request, ruleListExecutionRequest);
return ruleListExecution(ruleListExecutionRequest, InvokeTypeEnum.BDP_CLIENT_API_INVOKE.getCode());
} else {
request.setProjectId(projectInDb.getId());
ProjectExecutionRequest projectExecutionRequest = new ProjectExecutionRequest();
BeanUtils.copyProperties(request, projectExecutionRequest);
return projectExecution(projectExecutionRequest, InvokeTypeEnum.BDP_CLIENT_API_INVOKE.getCode());
}
} else if (StringUtils.isNotBlank(request.getCluster())) {
DataSourceExecutionRequest dataSourceExecutionRequest = new DataSourceExecutionRequest();
BeanUtils.copyProperties(request, dataSourceExecutionRequest);
return dataSourceExecution(dataSourceExecutionRequest);
} else {
LOGGER.error("Can not resolve the request: " + request);
throw new UnExpectedRequestException("{&CAN_NOT_RESOLVE_THE_REQUEST}");
}
}
Aggregations