Skip to content

Commit

Permalink
#452 修复根据状态获取作业列表时,截取列表会导致数组越界的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
leewcc committed Jul 20, 2018
1 parent 2952f96 commit c6b1fdd
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private JobOverviewVo getJobOverviewByStatusAndPage(String namespace, JobStatus
List<JobConfig> unSystemJobs = jobService.getUnSystemJobsWithCondition(namespace, condition, page, size);
Pageable pageable = PageableUtil.generatePageble(page, size);

List<JobConfig> targetJobs = unSystemJobs.subList(pageable.getOffset(), pageable.getPageSize());
List<JobConfig> targetJobs = getJobSubListByPage(unSystemJobs, pageable);
List<JobOverviewJobVo> jobOverviewList = updateJobOverviewDetail(namespace, targetJobs, jobStatus);

jobOverviewVo.setJobs(jobOverviewList);
Expand Down Expand Up @@ -220,6 +220,18 @@ private void updateJobTypesInOverview(JobConfig jobConfig, JobOverviewJobVo jobO
}
}

private List<JobConfig> getJobSubListByPage(List<JobConfig> unSystemJobs, Pageable pageable) {
int totalCount = unSystemJobs.size();
int offset = pageable.getOffset();
int end = offset + pageable.getPageSize();
int fromIndex = totalCount >= offset ? offset : -1;
int toIndex = totalCount >= end ? end : totalCount;
if (fromIndex == -1 || fromIndex > toIndex) {
return Lists.newArrayList();
}
return unSystemJobs.subList(fromIndex, toIndex);
}

public JobOverviewVo countJobOverviewVo(String namespace) throws SaturnJobConsoleException{
JobOverviewVo jobOverviewVo = new JobOverviewVo();
jobOverviewVo.setTotalNumber(jobService.countUnSystemJobsWithCondition(namespace,
Expand Down

0 comments on commit c6b1fdd

Please sign in to comment.