diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/JobController.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/JobController.java index f1f59be74dca655afa20ac66ef91f54d7daf97f7..c4bd8430a55a1de6853a06d17961fd8f7a1ff92b 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/JobController.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/JobController.java @@ -26,6 +26,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import org.apache.bigtop.manager.server.model.vo.JobVO; +import org.apache.bigtop.manager.server.model.vo.PageVO; import org.apache.bigtop.manager.server.service.JobService; import org.apache.bigtop.manager.server.utils.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -33,8 +34,6 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.List; - @Tag(name = "Job Controller") @RestController @RequestMapping("/clusters/{clusterId}/jobs") @@ -51,7 +50,7 @@ public class JobController { @Parameter(in = ParameterIn.QUERY, name = "sort", description = "asc/desc", schema = @Schema(type = "string", defaultValue = "asc")) }) @GetMapping - public ResponseEntity> list(@PathVariable Long clusterId) { + public ResponseEntity> list(@PathVariable Long clusterId) { return ResponseEntity.success(jobService.list(clusterId)); } diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/JobService.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/JobService.java index 396390c4e8e27fa14077f5dc51e97879c8c97a04..117292fb3fb4dfe4406f7d42d2d661e7daa5491b 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/JobService.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/JobService.java @@ -19,12 +19,11 @@ package org.apache.bigtop.manager.server.service; import org.apache.bigtop.manager.server.model.vo.JobVO; - -import java.util.List; +import org.apache.bigtop.manager.server.model.vo.PageVO; public interface JobService { - List list(Long clusterId); + PageVO list(Long clusterId); JobVO get(Long id); } diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/JobServiceImpl.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/JobServiceImpl.java index ba67210b1e51e6bd32360297ce8ab7df933b6513..e22ceb5c92de4f4b0bb525356f29e01ac2427ce6 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/JobServiceImpl.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/JobServiceImpl.java @@ -22,12 +22,17 @@ import jakarta.annotation.Resource; import org.apache.bigtop.manager.dao.entity.Job; import org.apache.bigtop.manager.dao.repository.JobRepository; import org.apache.bigtop.manager.server.model.mapper.JobMapper; +import org.apache.bigtop.manager.server.model.query.PageQuery; import org.apache.bigtop.manager.server.model.vo.JobVO; +import org.apache.bigtop.manager.server.model.vo.PageVO; import org.apache.bigtop.manager.server.service.JobService; +import org.apache.bigtop.manager.server.utils.ClusterUtils; +import org.apache.bigtop.manager.server.utils.PageUtils; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; -import java.util.List; - @Service public class JobServiceImpl implements JobService { @@ -35,20 +40,17 @@ public class JobServiceImpl implements JobService { private JobRepository jobRepository; @Override - public List list(Long clusterId) { -// PageQuery pageQuery = PageUtils.getPageQuery(); -// Pageable pageable = PageRequest.of(pageQuery.getPageNum(), pageQuery.getPageSize(), pageQuery.getSort()); -// Page page; -// if (ClusterUtils.isNoneCluster(clusterId)) { -// page = jobRepository.findAllByClusterIsNull(pageable); -// } else { -// page = jobRepository.findAllByClusterId(clusterId, pageable); -// } -// -// return PageVO.of(page); - List jobs = jobRepository.findAllByClusterId(clusterId); + public PageVO list(Long clusterId) { + PageQuery pageQuery = PageUtils.getPageQuery(); + Pageable pageable = PageRequest.of(pageQuery.getPageNum(), pageQuery.getPageSize(), pageQuery.getSort()); + Page page; + if (ClusterUtils.isNoneCluster(clusterId)) { + page = jobRepository.findAllByClusterIsNull(pageable); + } else { + page = jobRepository.findAllByClusterId(clusterId, pageable); + } - return JobMapper.INSTANCE.fromEntity2VO(jobs); + return PageVO.of(page); } @Override