Skip to content

Commit 802c684

Browse files
committed
vipshop#452 增加空集合的判空;修复第一次获取作业状态后导致后面的作业都不会更新
状态
1 parent 52f6df1 commit 802c684

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

saturn-console-api/src/main/java/com/vip/saturn/job/console/controller/gui/JobOverviewController.java

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.slf4j.Logger;
1717
import org.slf4j.LoggerFactory;
1818
import org.springframework.data.domain.Pageable;
19+
import org.springframework.util.CollectionUtils;
1920
import org.springframework.web.bind.annotation.*;
2021
import org.springframework.web.multipart.MultipartFile;
2122

@@ -91,18 +92,20 @@ public SuccessResponseEntity getJobNames(@PathVariable String namespace) throws
9192
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
9293
@GetMapping(value = "/sharding/status")
9394
public SuccessResponseEntity getJobsShardingStatus(@PathVariable String namespace,
94-
@RequestParam List<String> jobNames) throws SaturnJobConsoleException {
95+
@RequestParam(required = false) List<String> jobNames) throws SaturnJobConsoleException {
9596
Map<String, String> jobShardingMap = new HashMap<>();
96-
for (String jobName : jobNames) {
97-
JobStatus jobStatus = jobService.getJobStatus(namespace, jobName);
98-
boolean isAllocated = !JobStatus.STOPPED.equals(jobStatus)
99-
&& jobService.isJobShardingAllocatedExecutor(namespace, jobName);
100-
if (isAllocated) {
101-
jobShardingMap.put(jobName, "已分配");
102-
} else {
103-
jobShardingMap.put(jobName, "未分配");
104-
}
105-
}
97+
if (!CollectionUtils.isEmpty(jobNames)) {
98+
for (String jobName : jobNames) {
99+
JobStatus jobStatus = jobService.getJobStatus(namespace, jobName);
100+
boolean isAllocated = !JobStatus.STOPPED.equals(jobStatus)
101+
&& jobService.isJobShardingAllocatedExecutor(namespace, jobName);
102+
if (isAllocated) {
103+
jobShardingMap.put(jobName, "已分配");
104+
} else {
105+
jobShardingMap.put(jobName, "未分配");
106+
}
107+
}
108+
}
106109
return new SuccessResponseEntity(jobShardingMap);
107110
}
108111

@@ -192,9 +195,10 @@ private List<JobOverviewJobVo> updateJobOverviewDetail(String namespace, List<Jo
192195
}
193196

194197
if (jobStatus == null) {
195-
jobStatus = jobService.getJobStatus(namespace, jobConfig);
198+
jobOverviewJobVo.setStatus(jobService.getJobStatus(namespace, jobConfig));
199+
} else {
200+
jobOverviewJobVo.setStatus(jobStatus);
196201
}
197-
jobOverviewJobVo.setStatus(jobStatus);
198202
result.add(jobOverviewJobVo);
199203
} catch (Exception e) {
200204
log.error("list job " + jobConfig.getJobName() + " error", e);
@@ -216,14 +220,6 @@ private void updateJobTypesInOverview(JobConfig jobConfig, JobOverviewJobVo jobO
216220
}
217221
}
218222

219-
private void updateShardingListInOverview(String namespace, JobConfig jobConfig, JobOverviewJobVo jobOverviewJobVo)
220-
throws SaturnJobConsoleException {
221-
boolean isAllocated = jobService.isJobShardingAllocatedExecutor(namespace, jobConfig.getJobName());
222-
if (isAllocated) {
223-
jobOverviewJobVo.setShardingList("已分配分片");
224-
}
225-
}
226-
227223
public JobOverviewVo countJobOverviewVo(String namespace) throws SaturnJobConsoleException{
228224
JobOverviewVo jobOverviewVo = new JobOverviewVo();
229225
jobOverviewVo.setTotalNumber(jobService.countUnSystemJobsWithCondition(namespace,

0 commit comments

Comments
 (0)