use of com.webank.wedatasphere.qualitis.request.DataSourceExecutionRequest in project Qualitis by WeBankFinTech.
the class OuterExecutionServiceImpl method dataSourceExecution.
@Override
public GeneralResponse<?> dataSourceExecution(DataSourceExecutionRequest request) throws UnExpectedRequestException, PermissionDeniedRequestException {
LOGGER.info("Execute application by datasource. cluster: {}, database: {}, table: {}", request.getCluster(), request.getDatabase(), request.getTable());
// Check Arguments.
DataSourceExecutionRequest.checkRequest(request);
String loginUser = getLoginUser(httpServletRequest, request.getCreateUser(), request.getAsync());
// Find all rule datasources by user.
List<RuleDataSource> ruleDataSources = new ArrayList<>();
ruleDataSources.addAll(ruleDataSourceDao.findDatasourcesByUser(loginUser, request.getCluster(), request.getDatabase(), request.getTable()));
List<Rule> rules = ruleDataSources.stream().filter(r -> r.getClusterName().equals(request.getCluster()) && r.getDbName().equals(request.getDatabase()) && r.getTableName().equals(request.getTable())).map(RuleDataSource::getRule).distinct().filter(rule -> {
if (!request.getCrossTable()) {
return rule.getRuleDataSources().size() == 1;
}
return true;
}).collect(Collectors.toList());
if (CollectionUtils.isEmpty(rules)) {
throw new UnExpectedRequestException("{&NO_RULE_CAN_BE_EXECUTED}");
}
checkPermissionCreateUserProxyExecuteUser(request.getCreateUser(), request.getExecutionUser());
ApplicationProjectResponse applicationProjectResponse = new ApplicationProjectResponse();
List<ApplicationSubmitRequest> applicationSubmitRequests = new ArrayList<>();
StringBuffer partition = new StringBuffer();
StringBuffer runDate = new StringBuffer();
Map<String, String> execParamMap = new HashMap<>(5);
parseExecParams(partition, runDate, request.getExecutionParam(), execParamMap);
List<Project> projects = rules.stream().map(Rule::getProject).distinct().collect(Collectors.toList());
for (Project projectInDb : projects) {
// Check permissions of project
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());
LOGGER.info("Succeed to find current rules of one group with datasource. rule_id: {}", currentRuleIds);
// Dynamic partition.
try {
submitRulesWithDynamicPartition(applicationSubmitRequests, projectInDb.getId(), ruleGroup.getId(), rules, currentRuleIds, request.getExecutionUser(), request.getDyNamicPartition(), request.getClusterName(), partition, request.getDyNamicPartitionPrefix());
} catch (ResourceAccessException e) {
// Record submit failed applicatoin.
generateAbnormalApplicationInfo(projectInDb.getId(), ruleGroup.getId(), request.getCreateUser(), request.getExecutionUser(), new Date(), InvokeTypeEnum.BDP_CLIENT_API_INVOKE.getCode(), 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 datasource execution start failed!", ruleGroup.getId());
} catch (NoPartitionException e) {
// Record submit failed applicatoin.
generateAbnormalApplicationInfo(projectInDb.getId(), ruleGroup.getId(), request.getCreateUser(), request.getExecutionUser(), new Date(), InvokeTypeEnum.BDP_CLIENT_API_INVOKE.getCode(), 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 datasource execution start failed!", ruleGroup.getId());
} catch (Exception e) {
// Record submit failed applicatoin.
generateAbnormalApplicationInfo(projectInDb.getId(), ruleGroup.getId(), request.getCreateUser(), request.getExecutionUser(), new Date(), InvokeTypeEnum.BDP_CLIENT_API_INVOKE.getCode(), partition.toString(), request.getStartupParamName(), request.getExecutionParam(), e, ApplicationCommentEnum.UNKNOWN_ERROR_ISSUES.getCode(), ApplicationStatusEnum.TASK_SUBMIT_FAILED.getCode(), rules);
LOGGER.error("One group execution[id={}] of the datasource execution start failed!", ruleGroup.getId());
}
if (CollectionUtils.isNotEmpty(currentRuleIds)) {
applicationSubmitRequests.add(new ApplicationSubmitRequest(request.getJobId(), projectInDb.getId(), ruleGroup.getId(), currentRuleIds, partition));
}
}
projectEventService.record(projectInDb.getId(), loginUser, "submit datasource execution", "rule name[" + Arrays.toString(rules.stream().filter(rule -> rule.getProject().getId().equals(projectInDb.getId())).toArray()) + "].", EventTypeEnum.SUBMIT_PROJECT.getCode());
}
GeneralResponse<ApplicationTaskSimpleResponse> generalResponse;
for (ApplicationSubmitRequest applicationSubmitRequest : applicationSubmitRequests) {
if (StringUtils.isNotBlank(request.getJobId())) {
applicationSubmitRequest.setJobId(request.getJobId());
}
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, InvokeTypeEnum.BDP_CLIENT_API_INVOKE.getCode());
applicationProjectResponse.getApplicationTaskSimpleResponses().add(generalResponse.getData());
}
return new GeneralResponse<>("200", "{&SUCCEED_TO_DISPATCH_TASK}", applicationProjectResponse);
}
use of com.webank.wedatasphere.qualitis.request.DataSourceExecutionRequest 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