Skip to content

Commit

Permalink
Merge pull request WeBankFinTech#280 from one-beauty/dev-1.0.0
Browse files Browse the repository at this point in the history
LGTM
  • Loading branch information
FinalTarget authored Apr 26, 2022
2 parents e424013 + f9716ad commit 89ab6e7
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
import com.webank.wedatasphere.exchangis.job.server.service.impl.DefaultJobExecuteService;
import com.webank.wedatasphere.exchangis.job.server.service.impl.ProjectImportServerImpl;
import com.webank.wedatasphere.exchangis.job.vo.ExchangisJobVo;
import com.webank.wedatasphere.exchangis.project.server.entity.ExchangisProject;
import com.webank.wedatasphere.exchangis.project.server.mapper.ProjectMapper;
import org.apache.commons.lang.StringUtils;
import org.apache.linkis.server.Message;
import org.apache.linkis.server.security.SecurityFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -48,6 +51,10 @@ public class ExchangisJobDssAppConnRestfulApi {

@Resource
private ProjectImportServerImpl projectImportServer;

@Autowired
private ProjectMapper projectMapper;

/**
* Create job
* @param request http request
Expand Down Expand Up @@ -145,7 +152,8 @@ else if (!hasAuthority(userName, jobInfoService.getJob(id , true))){
* @return message
*/
@RequestMapping( value = "/execute/{id}", method = RequestMethod.POST)
public Message executeJob(@PathVariable("id") Long id, HttpServletRequest request) {
public Message executeJob(@PathVariable("id") Long id, HttpServletRequest request, @RequestBody Map<String, Object> params) {
String submitUser = params.get("submitUser").toString();
String loginUser = SecurityFilter.getLoginUsername(request);
Message result = Message.ok();
ExchangisJobInfo jobInfo = null;
Expand All @@ -157,15 +165,22 @@ public Message executeJob(@PathVariable("id") Long id, HttpServletRequest reques
}
// Convert to the job info
jobInfo = new ExchangisJobInfo(jobVo);
if (!hasAuthority(loginUser, jobVo)){
return Message.error("You have no permission to execute job (没有执行DSS任务权限) [" + loginUser +"]" + "[" + jobVo.getCreateUser() + "]");
jobInfo.setName(jobVo.getJobName());
jobInfo.setId(jobVo.getId());
LOG.info("jobInfo: name{},executerUser{},createUser{},id{}",jobInfo.getName(),jobInfo.getExecuteUser(),jobInfo.getCreateUser(),jobInfo.getId());
LOG.info("loginUser: {}, jobVo:{}",loginUser,jobVo);
//find project info
ExchangisProject project = projectMapper.getDetailById(jobVo.getProjectId());
LOG.info("project: {}, getProjectId:{}",project,jobVo.getProjectId());
//find project user authority
if (!hasExecuteAuthority(submitUser, project)){
return Message.error("You have no permission to execute job (没有执行DSS任务权限)");
}
// Send to execute service
String jobExecutionId = executeService.executeJob(jobInfo, StringUtils.isNotBlank(jobInfo.getExecuteUser()) ?
jobInfo.getExecuteUser() : loginUser);
result.data("jobExecutionId", jobExecutionId);

LOG.info("Prepare to get job status");
while (true) {
TaskStatus jobStatus = executeService.getJobStatus(jobExecutionId).getStatus();
LOG.info("Taskstatus is: {}", jobStatus.name());
Expand Down Expand Up @@ -229,6 +244,7 @@ public Message exportJob(@Context HttpServletRequest request, @RequestBody Map<S
//return jobInfoService.exportProject(params, userName, request);

}

/**
* TODO complete the authority strategy
* @param username username
Expand All @@ -238,4 +254,16 @@ public Message exportJob(@Context HttpServletRequest request, @RequestBody Map<S
private boolean hasAuthority(String username, ExchangisJobVo job){
return Objects.nonNull(job) && username.equals(job.getCreateUser());
}

/**
* @param username username
* @param project project
* @return
*/
private boolean hasExecuteAuthority(String username, ExchangisProject project){
if(project.getEditUsers().contains(username)||project.getExecUsers().contains(username)){
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public void deleteJob(Long id) {
public ExchangisJobVo getJob(Long id, boolean basic) {
ExchangisJobEntity exchangisJob = basic ? this.jobEntityDao.getBasicInfo(id) : this.jobEntityDao.getDetail(id);
ExchangisJobVo jobVo = new ExchangisJobVo(exchangisJob);
jobVo.setProjectId(exchangisJob.getProjectId());
if (exchangisJob != null && StringUtils.isNotBlank(exchangisJob.getJobContent())) {
jobVo.setContent(exchangisJob.getJobContent());
jobVo.setSource(Objects.nonNull(exchangisJob.getSource())?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.webank.wedatasphere.exchangis.dss.appconn.request.entity.ProjectReqEntity;
import com.webank.wedatasphere.exchangis.dss.appconn.utils.AppConnUtils;
import com.webank.wedatasphere.exchangis.dss.appconn.utils.JsonExtension;
import org.apache.commons.lang.StringUtils;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -30,8 +31,10 @@ public AbstractExchangisProjectOperation(){
protected ProjectReqEntity getProjectEntity(ProjectRequestRef projectRequestRef){
// Build project request entity
Map<String, Object> source = new HashMap<>();
String owner = projectRequestRef.getCreateBy();
ProjectReqEntity projectReqEntity = new ProjectReqEntity(owner,
String editUsers= StringUtils.join( projectRequestRef.getEditUsers(),",");
String viewUsers = StringUtils.join( projectRequestRef.getAccessUsers(),",");
String execUsers = StringUtils.join( projectRequestRef.getReleaseUsers(),",");
ProjectReqEntity projectReqEntity = new ProjectReqEntity(editUsers,viewUsers,execUsers,
projectRequestRef.getName(), projectRequestRef.getDescription(), source);
projectReqEntity.setLabels(AppConnUtils.serializeDssLabel(projectRequestRef.getDSSLabels()));
// Try to set the project request ref into the source map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,16 @@ public ExchangisRefExecutionOperation(DevelopmentService service) {
@Override
public ResponseRef execute(ExecutionRequestRef executionRequestRef) throws ExternalOperationFailedException {
AsyncExecutionRequestRef nodeRequestRef = (AsyncExecutionRequestRef) executionRequestRef;

LOG.info("execute job request => jobcontent: {}", nodeRequestRef.getJobContent());
LOG.info("executionRequestRef => executionRequestRef: {}", executionRequestRef);
try {
nodeRequestRef.getExecutionRequestRefContext().getRuntimeMap().get("wds.dss.workflow.submit.user").toString();
LOG.info("getExecutionRequestRefContext User: {}", nodeRequestRef.getExecutionRequestRefContext().getRuntimeMap().get("wds.dss.workflow.submit.user").toString());
} catch (Exception e) {
LOG.error("parser request error", e);
}
Long id = AppConnUtils.resolveParam(nodeRequestRef.getJobContent(), Constraints.REF_JOB_ID, Double.class).longValue();
LOG.info("execute job request => id: {}, name: {}, user: {}, jobContent: {}",
id, nodeRequestRef.getName(), nodeRequestRef.getExecutionRequestRefContext().getRuntimeMap().get("wds.dss.workflow.submit.user").toString(),
nodeRequestRef.getJobContent().toString());
String url = requestURL("/appJob/execute/" + id);
String submitUser = nodeRequestRef.getExecutionRequestRefContext().getRuntimeMap().get("wds.dss.workflow.submit.user").toString();
ExchangisEntityRespResult.BasicMessageEntity<Map<String, Object>> entity = requestToGetEntity(url, nodeRequestRef.getWorkspace(), nodeRequestRef,
(requestRef) -> {
// Build ref execution action
return new ExchangisEntityPostAction<>(null,
nodeRequestRef.getExecutionRequestRefContext().getRuntimeMap().get("wds.dss.workflow.submit.user").toString());
ExchangisEntityPostAction exchangisEntityPostAction = new ExchangisEntityPostAction();
exchangisEntityPostAction.addRequestPayload("submitUser",submitUser);
return exchangisEntityPostAction;
}, Map.class);
if (Objects.isNull(entity)){
throw new ExternalOperationFailedException(31020, "The response entity cannot be empty", null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ public ProjectReqEntity(String owner, String projectName, String description, Ma
setViewUsers(owner);
setExecUsers(owner);
}

public ProjectReqEntity(String editUsers, String viewUsers, String execUsers, String projectName, String description, Map<String, Object> source){
this.projectName = projectName;
this.description = description;
this.source = source;
setEditUsers(editUsers);
setViewUsers(viewUsers);
setExecUsers(execUsers);
}

public String getProjectName() {
return projectName;
}
Expand Down

0 comments on commit 89ab6e7

Please sign in to comment.