Skip to content

Commit

Permalink
add ut
Browse files Browse the repository at this point in the history
  • Loading branch information
goldenxinxing committed Jul 21, 2023
1 parent 288a0a1 commit d3e54b1
Show file tree
Hide file tree
Showing 8 changed files with 465 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import ai.starwhale.mlops.domain.evaluation.mapper.ViewConfigMapper;
import ai.starwhale.mlops.domain.evaluation.po.ViewConfigEntity;
import ai.starwhale.mlops.domain.job.JobDao;
import ai.starwhale.mlops.domain.job.bo.Job;
import ai.starwhale.mlops.domain.job.converter.JobConverter;
import ai.starwhale.mlops.domain.job.po.JobEntity;
import ai.starwhale.mlops.domain.job.status.JobStatusMachine;
import ai.starwhale.mlops.domain.project.ProjectService;
import ai.starwhale.mlops.domain.user.UserService;
Expand Down Expand Up @@ -114,12 +114,12 @@ public PageInfo<SummaryVo> listEvaluationSummary(String projectUrl,
SummaryFilter summaryFilter, PageParams pageParams) {
Long projectId = projectService.getProjectId(projectUrl);
PageHelper.startPage(pageParams.getPageNum(), pageParams.getPageSize());
List<Job> jobs = jobDao.listJobs(projectId, null);
var jobs = jobDao.listJobs(projectId, null);
return PageUtil.toPageInfo(jobs, this::toSummary);
}


private SummaryVo toSummary(Job job) {
private SummaryVo toSummary(JobEntity job) {
if (summaryCache.containsKey(job.getId())) {
return summaryCache.get(job.getId());
}
Expand All @@ -129,7 +129,7 @@ private SummaryVo toSummary(Job job) {
.id(jobVo.getId())
.uuid(jobVo.getUuid())
.projectId(idConvertor.convert(job.getProject().getId()))
.projectName(job.getProject().getName())
.projectName(job.getProject().getProjectName())
.modelName(jobVo.getModelName())
.modelVersion(jobVo.getModelVersion())
.datasets(StrUtil.join(",", jobVo.getDatasets()))
Expand All @@ -145,7 +145,7 @@ private SummaryVo toSummary(Job job) {
.build();

// only cache the jobs which have the final status
if (jobStatusMachine.isFinal(job.getStatus())) {
if (jobStatusMachine.isFinal(job.getJobStatus())) {
summaryCache.put(job.getId(), summaryVo);
}
return summaryVo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,8 @@ private JobEntity convertFromFlatten(JobFlattenEntity flattenEntity) {
}


public List<Job> listJobs(Long projectId, Long modelId) {
return jobMapper.listJobs(projectId, modelId)
.stream()
.map(jobBoConverter::fromEntity)
.collect(Collectors.toList());
public List<JobEntity> listJobs(Long projectId, Long modelId) {
return jobMapper.listJobs(projectId, modelId);
}

public List<Job> findJobByStatusIn(List<JobStatus> jobStatuses) {
Expand Down Expand Up @@ -177,6 +174,14 @@ public Job findJob(String jobUrl) {
}
}

public JobEntity findJobEntity(String jobUrl) {
if (idConvertor.isId(jobUrl)) {
return jobMapper.findJobById(idConvertor.revert(jobUrl));
} else {
return jobMapper.findJobByUuid(jobUrl);
}
}

public boolean updateJobPinStatus(String jobUrl, boolean pinned) {
Date pinnedTime = pinned ? Date.from(Instant.now()) : null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public JobService(
public PageInfo<JobVo> listJobs(String projectUrl, Long modelId, PageParams pageParams) {
Long projectId = projectService.getProjectId(projectUrl);
PageHelper.startPage(pageParams.getPageNum(), pageParams.getPageSize());
List<Job> jobEntities = jobDao.listJobs(projectId, modelId);
var jobEntities = jobDao.listJobs(projectId, modelId);
return PageUtil.toPageInfo(jobEntities, jobConvertor::convert);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public interface StepMapper {
+ " values (#{step.uuid}, #{step.name}, #{step.jobId}, #{step.lastStepId}, #{step.status}, "
+ " #{step.concurrency}, #{step.taskNum}, #{step.poolInfo})")
@Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
void save(@Param("step") StepEntity stepEntity);
int save(@Param("step") StepEntity stepEntity);

@Select("select id, step_uuid as uuid, step_name as name, job_id, last_step_id, step_status as status,"
+ " finished_time, started_time, created_time, modified_time, concurrency, task_num, pool_info from step"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import ai.starwhale.mlops.api.protocol.task.TaskVo;
import ai.starwhale.mlops.common.IdConverter;
import ai.starwhale.mlops.common.PageParams;
import ai.starwhale.mlops.common.util.PageUtil;
import ai.starwhale.mlops.domain.job.JobDao;
import ai.starwhale.mlops.domain.job.bo.Job;
import ai.starwhale.mlops.domain.task.bo.ResultPath;
import ai.starwhale.mlops.domain.task.converter.TaskConverter;
import ai.starwhale.mlops.domain.task.mapper.TaskMapper;
Expand Down Expand Up @@ -63,16 +63,16 @@ public TaskService(TaskConverter taskConvertor, TaskMapper taskMapper,
}

public PageInfo<TaskVo> listTasks(String jobUrl, PageParams pageParams) {
Job job = jobDao.findJob(jobUrl);
var job = jobDao.findJobEntity(jobUrl);
PageHelper.startPage(pageParams.getPageNum(), pageParams.getPageSize());
List<TaskVo> tasks = taskMapper.listTasks(job.getId()).stream().map(taskConvertor::convert)
.peek(taskVo -> {
if (!StringUtils.hasText(taskVo.getResourcePool())) {
taskVo.setResourcePool(job.getResourcePool().getName());
}
})
.collect(Collectors.toList());
return PageInfo.of(tasks);
var entities = taskMapper.listTasks(job.getId());
return PageUtil.toPageInfo(entities, entity -> {
var vo = taskConvertor.convert(entity);
if (!StringUtils.hasText(vo.getResourcePool())) {
vo.setResourcePool(job.getResourcePool());
}
return vo;
});

}

Expand Down
Loading

0 comments on commit d3e54b1

Please sign in to comment.