Skip to content

Commit 8d190e8

Browse files
committed
Adjust API for UI needs
1 parent eae667c commit 8d190e8

File tree

11 files changed

+114
-15
lines changed

11 files changed

+114
-15
lines changed

bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/HostController.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import io.swagger.v3.oas.annotations.tags.Tag;
4747

4848
import jakarta.annotation.Resource;
49+
import java.util.ArrayList;
4950
import java.util.List;
5051

5152
@Tag(name = "Host Controller")
@@ -107,9 +108,10 @@ public ResponseEntity<Boolean> checkConnection(@RequestBody @Validated HostReq h
107108

108109
@Operation(summary = "Install dependencies", description = "Install dependencies on a host")
109110
@PostMapping("/install-dependencies")
110-
public ResponseEntity<Boolean> installDependencies(@RequestBody @Validated HostReq hostReq) {
111-
HostDTO hostDTO = HostConverter.INSTANCE.fromReq2DTO(hostReq);
112-
return ResponseEntity.success(hostService.installDependencies(hostDTO));
111+
public ResponseEntity<Boolean> installDependencies(@RequestBody @Validated List<HostReq> hostReqs) {
112+
List<HostDTO> hostDTOList = new ArrayList<>();
113+
hostReqs.forEach(hostReq -> hostDTOList.add(HostConverter.INSTANCE.fromReq2DTO(hostReq)));
114+
return ResponseEntity.success(hostService.installDependencies(hostDTOList));
113115
}
114116

115117
@Operation(summary = "Installed status", description = "Install status for a host")

bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/JobController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ public ResponseEntity<PageVO<JobVO>> jobs(@PathVariable Long clusterId) {
7171
return ResponseEntity.success(jobService.jobs(clusterId));
7272
}
7373

74+
@Operation(summary = "job details", description = "Get job details")
75+
@GetMapping("/{jobId}")
76+
public ResponseEntity<JobVO> jobDetails(@PathVariable Long clusterId, @PathVariable Long jobId) {
77+
return ResponseEntity.success(jobService.jobDetails(clusterId, jobId));
78+
}
79+
7480
@Operation(summary = "stages", description = "List stages")
7581
@Parameters({
7682
@Parameter(in = ParameterIn.QUERY, name = "pageNum", schema = @Schema(type = "integer", defaultValue = "1")),

bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/StackController.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
*/
1919
package org.apache.bigtop.manager.server.controller;
2020

21+
import org.apache.bigtop.manager.server.model.vo.ClusterVO;
2122
import org.apache.bigtop.manager.server.model.vo.StackVO;
2223
import org.apache.bigtop.manager.server.service.StackService;
2324
import org.apache.bigtop.manager.server.utils.ResponseEntity;
2425

2526
import org.springframework.web.bind.annotation.GetMapping;
27+
import org.springframework.web.bind.annotation.PathVariable;
2628
import org.springframework.web.bind.annotation.RequestMapping;
2729
import org.springframework.web.bind.annotation.RestController;
2830

@@ -45,4 +47,10 @@ public class StackController {
4547
public ResponseEntity<List<StackVO>> list() {
4648
return ResponseEntity.success(stackService.list());
4749
}
50+
51+
@Operation(summary = "service clusters", description = "Get service clusters")
52+
@GetMapping("/services/{serviceName}/clusters")
53+
public ResponseEntity<List<ClusterVO>> serviceClusters(@PathVariable String serviceName) {
54+
return ResponseEntity.success(stackService.serviceClusters(serviceName));
55+
}
4856
}

bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/vo/JobVO.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import lombok.Data;
2222

23+
import java.util.List;
24+
2325
@Data
2426
public class JobVO {
2527

@@ -32,4 +34,6 @@ public class JobVO {
3234
private String createTime;
3335

3436
private String updateTime;
37+
38+
private List<StageVO> stages;
3539
}

bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/vo/StageVO.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import lombok.Data;
2222

23+
import java.util.List;
24+
2325
@Data
2426
public class StageVO {
2527

@@ -34,4 +36,6 @@ public class StageVO {
3436
private String createTime;
3537

3638
private String updateTime;
39+
40+
private List<TaskVO> tasks;
3741
}

bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/HostService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ public interface HostService {
7676
/**
7777
* Install dependencies
7878
*
79-
* @param hostDTO host infos
79+
* @param hostDTOList host infos
8080
* @return true if all dependencies are installed
8181
*/
82-
Boolean installDependencies(HostDTO hostDTO);
82+
Boolean installDependencies(List<HostDTO> hostDTOList);
8383

8484
/**
8585
* Get dependency installed status

bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/JobService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public interface JobService {
2727

2828
PageVO<JobVO> jobs(Long clusterId);
2929

30+
JobVO jobDetails(Long clusterId, Long jobId);
31+
3032
PageVO<StageVO> stages(Long jobId);
3133

3234
PageVO<TaskVO> tasks(Long stageId);

bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/StackService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.apache.bigtop.manager.server.service;
2020

21+
import org.apache.bigtop.manager.server.model.vo.ClusterVO;
2122
import org.apache.bigtop.manager.server.model.vo.StackVO;
2223

2324
import java.util.List;
@@ -30,4 +31,12 @@ public interface StackService {
3031
* @return Stacks
3132
*/
3233
List<StackVO> list();
34+
35+
/**
36+
* Get service clusters.
37+
*
38+
* @param serviceName Service name
39+
* @return Clusters
40+
*/
41+
List<ClusterVO> serviceClusters(String serviceName);
3342
}

bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/HostServiceImpl.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public Boolean checkConnection(HostDTO hostDTO) {
173173
}
174174

175175
@Override
176-
public Boolean installDependencies(HostDTO hostDTO) {
176+
public Boolean installDependencies(List<HostDTO> hostDTOList) {
177177
List<RepoPO> repoPOList = repoDao.findAll();
178178
Map<String, RepoPO> archRepoMap = repoPOList.stream()
179179
.filter(repoPO -> repoPO.getType() == 2)
@@ -182,14 +182,24 @@ public Boolean installDependencies(HostDTO hostDTO) {
182182
// Clear cache list
183183
installedStatus.clear();
184184

185-
for (String hostname : hostDTO.getHostnames()) {
186-
InstalledStatusVO installedStatusVO = new InstalledStatusVO();
187-
installedStatusVO.setHostname(hostname);
188-
installedStatusVO.setStatus(InstalledStatusEnum.INSTALLING);
189-
installedStatus.add(installedStatusVO);
190-
191-
// Async install dependencies
192-
executorService.submit(() -> installDependencies(archRepoMap, hostDTO, hostname, installedStatusVO));
185+
for (HostDTO hostDTO : hostDTOList) {
186+
for (String hostname : hostDTO.getHostnames()) {
187+
InstalledStatusVO installedStatusVO = new InstalledStatusVO();
188+
installedStatusVO.setHostname(hostname);
189+
installedStatusVO.setStatus(InstalledStatusEnum.INSTALLING);
190+
installedStatus.add(installedStatusVO);
191+
192+
// Async install dependencies
193+
executorService.submit(() -> {
194+
try {
195+
installDependencies(archRepoMap, hostDTO, hostname, installedStatusVO);
196+
} catch (Exception e) {
197+
log.error("Unable to install dependencies on host, hostname: {}", hostname, e);
198+
installedStatusVO.setStatus(InstalledStatusEnum.FAILED);
199+
installedStatusVO.setMessage(e.getMessage());
200+
}
201+
});
202+
}
193203
}
194204

195205
return true;
@@ -290,7 +300,7 @@ private ShellResult execCommandOnRemoteHost(HostDTO hostDTO, String hostname, St
290300
};
291301
} catch (Exception e) {
292302
log.error("Unable to exec command on host, hostname: {}, command: {}", hostname, command, e);
293-
throw new ApiException(ApiExceptionEnum.HOST_UNABLE_TO_EXEC_COMMAND, hostname);
303+
throw new RuntimeException(e);
294304
}
295305
}
296306
}

bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/JobServiceImpl.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import org.apache.bigtop.manager.server.enums.ApiExceptionEnum;
3838
import org.apache.bigtop.manager.server.exception.ApiException;
3939
import org.apache.bigtop.manager.server.model.converter.JobConverter;
40+
import org.apache.bigtop.manager.server.model.converter.StageConverter;
41+
import org.apache.bigtop.manager.server.model.converter.TaskConverter;
4042
import org.apache.bigtop.manager.server.model.query.PageQuery;
4143
import org.apache.bigtop.manager.server.model.vo.JobVO;
4244
import org.apache.bigtop.manager.server.model.vo.PageVO;
@@ -52,6 +54,7 @@
5254
import com.github.pagehelper.PageInfo;
5355

5456
import jakarta.annotation.Resource;
57+
import java.util.ArrayList;
5558
import java.util.List;
5659

5760
@Service
@@ -82,6 +85,29 @@ public PageVO<JobVO> jobs(Long clusterId) {
8285
}
8386
}
8487

88+
@Override
89+
public JobVO jobDetails(Long clusterId, Long jobId) {
90+
JobPO jobPO = jobDao.findById(jobId);
91+
List<StageVO> stages = new ArrayList<>();
92+
List<StagePO> stagePOList = stageDao.findByJobId(jobId);
93+
for (int i = 0; i < stagePOList.size(); i++) {
94+
StagePO stagePO = findCorrectStagePO(stagePOList, i + 1);
95+
if (stagePO == null) {
96+
throw new ApiException(ApiExceptionEnum.JOB_NOT_FOUND);
97+
}
98+
99+
StageVO stageVO = StageConverter.INSTANCE.fromPO2VO(stagePO);
100+
List<TaskPO> taskPOList = taskDao.findByStageId(stagePO.getId());
101+
List<TaskVO> taskVOList = TaskConverter.INSTANCE.fromPO2VO(taskPOList);
102+
stageVO.setTasks(taskVOList);
103+
stages.add(stageVO);
104+
}
105+
106+
JobVO jobVO = JobConverter.INSTANCE.fromPO2VO(jobPO);
107+
jobVO.setStages(stages);
108+
return jobVO;
109+
}
110+
85111
@Override
86112
public PageVO<StageVO> stages(Long jobId) {
87113
PageQuery pageQuery = PageUtils.getPageQuery();

0 commit comments

Comments
 (0)