Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check dataset permissions when submit job && add the relationship of job and dataset #18

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions wedpr-adm/db/wedpr_ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ create table if not exists `wedpr_job_table`(
index status_index(`status`(128))
)ENGINE=InnoDB default charset=utf8mb4 default collate=utf8mb4_bin ROW_FORMAT=DYNAMIC;

-- job dataset relationship table
create table if not exists `wedpr_job_dataset_relation`(
`job_id` varchar(64) not null comment "任务ID",
`dataset_id` varchar(64) not null comment "数据集ID",
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP comment "任务创建时间",
index job_id_index(`job_id`),
index dataset_id_index(`dataset_id`)
)ENGINE=InnoDB default charset=utf8mb4 default collate=utf8mb4_bin ROW_FORMAT=DYNAMIC;

-- the algorithm_setting template
create table if not exists `wedpr_setting_template`(
`id` varchar(64) not null comment "配置模板ID",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand Down Expand Up @@ -140,6 +142,23 @@ public WeDPRResponse queryJobByCondition(
}
}

// query job by condition
@GetMapping("/queryJobsByDatasetID")
public WeDPRResponse queryJobsByDatasetID(
HttpServletRequest request,
@RequestParam(value = "datasetID", required = true) String datasetID,
@RequestParam(value = "pageNum", required = false) Integer pageNum,
@RequestParam(value = "pageSize", required = false) Integer pageSize) {
try {
return projectService.queryJobsByDatasetID(
TokenUtils.getLoginUser(request).getUsername(), datasetID, pageNum, pageSize);
} catch (Exception e) {
logger.warn("queryJobsByDatasetID exception, condition: {}, error: ", null, e);
return new WeDPRResponse(
Constant.WEDPR_FAILED, "queryJobsByDatasetID failed for " + e.getMessage());
}
}

// query jobOverview
@PostMapping("/queryJobOverview")
public WeDPRResponse queryJobOverview(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,20 @@ public boolean hasPermission(int permissionType) {
|| ((permissionType == DatasetPermissionType.WRITABLE.getType()) && writable)
|| ((permissionType == DatasetPermissionType.READABLE.getType()) && readable);
}

public boolean isReadable() {
return hasPermission(DatasetPermissionType.READABLE.getType());
}

public boolean isVisible() {
return hasPermission(DatasetPermissionType.VISIBLE.getType());
}

public boolean isUsable() {
return hasPermission(DatasetPermissionType.USABLE.getType());
}

public boolean isWritable() {
return hasPermission(DatasetPermissionType.WRITABLE.getType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,30 @@ public class DatasetUserPermissionValidator {

private DatasetUserPermissionValidator() {}

/**
* confirm user’s dataset permissions
*
* @param datasetId
* @param userName
* @param agencyName
* @param datasetPermissionMapper
* @param isTx
* @return
* @throws DatasetException
*/
public static DatasetUserPermissions confirmUserDatasetPermissions(
String datasetId,
String userName,
String agencyName,
DatasetPermissionMapper datasetPermissionMapper,
boolean isTx)
throws DatasetException {

UserInfo userInfo =
UserInfo.builder().user(userName).agency(agencyName).groupInfos(null).build();
return confirmUserDatasetPermissions(datasetId, userInfo, datasetPermissionMapper, isTx);
}

/**
* confirm user’s dataset permissions
*
Expand Down
1 change: 1 addition & 0 deletions wedpr-components/meta/project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies{
compile project(":wedpr-core-protocol")
compile project(":wedpr-components-uuid")
compile project(":wedpr-components-resource-follower")
compile project(":wedpr-components-dataset")
}
googleJavaFormat {
//toolVersion = '1.7'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ public String toString() {
@JsonIgnore private transient Object jobRequest;
private String status;
@JsonIgnore private String result;
private List<String> datasetList;

@JsonProperty("jobStatusInfo")
private JobResult jobResult = new JobResult();
Expand Down Expand Up @@ -452,6 +453,15 @@ public Boolean isJobParty(String agency) {
return Boolean.FALSE;
}

// TODO: verify dataset
public boolean isJobDataset(String datasetId) {
if (datasetList == null) {
return false;
}

return datasetList.contains(datasetId);
}

public Object getJobRequest() {
return jobRequest;
}
Expand Down Expand Up @@ -499,6 +509,14 @@ public boolean equals(Object o) {
&& Objects.equals(status, jobDO.status);
}

public List<String> getDatasetList() {
return datasetList;
}

public void setDatasetList(List<String> datasetList) {
this.datasetList = datasetList;
}

@Override
public int hashCode() {
return Objects.hash(id, name, parties, jobType, owner, ownerAgency, projectName, status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public long queryFollowerJobCount(

public int batchUpdateJobInfo(@Param("jobDOList") List<JobDO> jobDOList);

public int batchInsertJobDatasetRelationInfo(
@Param("jobID") String jobID, @Param("datasetIDs") List<String> datasetIDs);

public List<JobDO> queryJobs(
@Param("onlyMeta") Boolean onlyMeta,
@Param("condition") JobDO condition,
Expand All @@ -57,4 +60,6 @@ public List<JobDO> queryFollowerJobByCondition(
@Param("followerUser") String followerUser,
@Param("followerAgency") String followerAgency,
@Param("condition") JobDO condition);

public List<JobDO> queryJobsByDatasetID(@Param("datasetID") String datasetID);
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,26 @@ public void recordJobStatus(JobDO jobDO) {

@Transactional(rollbackFor = Exception.class)
public void insertJob(JobDO jobDO) {
String id = jobDO.getId();

logger.info(" => insert job, jobID: {}", id);

this.projectMapper.insertJobInfo(jobDO);

int insertC = -1;
List<String> datasetList = jobDO.getDatasetList();
if (datasetList != null && !datasetList.isEmpty()) {
insertC = this.projectMapper.batchInsertJobDatasetRelationInfo(id, datasetList);
}

if (logger.isDebugEnabled()) {
logger.debug(
"batch insert job datasets relation, jobID: {}, datasetIDs: {}, insertCount: {}",
id,
datasetList,
insertC);
}

if (jobDO.getTaskParties() == null || jobDO.getTaskParties().isEmpty()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
public class JobRequest extends PageRequest {
private JobDO job = new JobDO(true);
private List<FollowerDO> taskParties;
private List<String> datasetList;

public JobRequest() {}

Expand Down Expand Up @@ -63,8 +64,23 @@ private void checkAndConfigTaskParities(List<FollowerDO> taskParties) {
}
}

public List<String> getDatasetList() {
return datasetList;
}

public void setDatasetList(List<String> datasetList) {
this.datasetList = datasetList;
}

@Override
public String toString() {
return "JobRequest{" + "job=" + job + ", taskParties=" + taskParties + '}';
return "JobRequest{"
+ "job="
+ job
+ ", taskParties="
+ taskParties
+ ", datasetList="
+ datasetList
+ '}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.webank.wedpr.components.project.model;

import com.webank.wedpr.components.project.dao.JobDO;
import java.util.List;
import lombok.Builder;
import lombok.Data;

@Builder
@Data
public class QueryJobsByDatasetIDResponse {
long totalCount;
boolean isLast;
List<JobDO> content;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public abstract Object queryJobOverview(String user, JobOverviewRequest jobOverv
public abstract WeDPRResponse submitJob(String user, JobRequest request);
// query job by condition
public abstract WeDPRResponse queryJobByCondition(String user, JobRequest request);
// query job list by dataset id
public abstract WeDPRResponse queryJobsByDatasetID(
String user, String datasetID, Integer pageNum, Integer pageSize);

public abstract WeDPRResponse queryFollowerJobByCondition(String user, JobRequest request);

Expand Down
Loading
Loading