|
|
@@ -1,83 +1,42 @@
|
|
|
package cn.reghao.autodop.dmaster.app.controller;
|
|
|
|
|
|
-import cn.reghao.autodop.common.deploy.AppStatus;
|
|
|
import cn.reghao.autodop.common.dockerc.exception.DockerException;
|
|
|
-import cn.reghao.autodop.dmaster.app.constant.EnvType;
|
|
|
-import cn.reghao.autodop.dmaster.app.service.LogManager;
|
|
|
-import cn.reghao.autodop.dmaster.app.service.StatusManager;
|
|
|
-import cn.reghao.autodop.dmaster.app.vo.LogFile;
|
|
|
-import cn.reghao.autodop.dmaster.common.db.PageList;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.AppStatusService;
|
|
|
import cn.reghao.autodop.common.result.WebResult;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.data.domain.PageRequest;
|
|
|
-import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
/**
|
|
|
* @author reghao
|
|
|
* @date 2020-02-28 11:33:23
|
|
|
*/
|
|
|
@Slf4j
|
|
|
-@Api(tags = "应用管理接口")
|
|
|
+@Api(tags = "应用状态管理接口")
|
|
|
@RestController
|
|
|
-@RequestMapping("/api/app/manage")
|
|
|
-public class ManageController {
|
|
|
- private StatusManager statusManager;
|
|
|
- private LogManager logManager;
|
|
|
+@RequestMapping("/api/app/status")
|
|
|
+public class StatusController {
|
|
|
+ private AppStatusService statusService;
|
|
|
|
|
|
- public ManageController(StatusManager statusManager, LogManager logManager) {
|
|
|
- this.statusManager = statusManager;
|
|
|
- this.logManager = logManager;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "启动应用")
|
|
|
- @PostMapping("/start/{appId}")
|
|
|
- public ResponseEntity<String> start(@PathVariable("appId") String appId) throws DockerException {
|
|
|
- statusManager.start(appId);
|
|
|
- return ResponseEntity.ok().body("ok");
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "停止应用")
|
|
|
- @PostMapping("/stop/{appId}")
|
|
|
- public ResponseEntity<String> stop(@PathVariable("appId") String appId) throws DockerException {
|
|
|
- statusManager.stop(appId);
|
|
|
- return ResponseEntity.ok().body("ok");
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "重启应用")
|
|
|
- @PostMapping("/restart/{appId}")
|
|
|
- public ResponseEntity<String> restart(@PathVariable("appId") String appId) throws DockerException {
|
|
|
- statusManager.restart(appId);
|
|
|
- return ResponseEntity.ok().body("ok");
|
|
|
+ public StatusController(AppStatusService statusService) {
|
|
|
+ this.statusService = statusService;
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "获取所有已部署应用的运行状态")
|
|
|
+ @ApiOperation(value = "获取已部署应用的运行状态")
|
|
|
@GetMapping("/status")
|
|
|
public ResponseEntity<String> status(@RequestParam("env") String env,
|
|
|
@RequestParam("page") int page,
|
|
|
@RequestParam("size") int size) throws DockerException {
|
|
|
- String env1 = EnvType.valueOf(env).name();
|
|
|
- PageRequest pageRequest =
|
|
|
- PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC, "updateTime"));
|
|
|
- List<AppStatus> statusList = statusManager.status(env1, pageRequest);
|
|
|
-
|
|
|
- PageList<AppStatus> pageList = new PageList<>();
|
|
|
- pageList.setList(statusList);
|
|
|
- pageList.setTotalSize(statusList.size());
|
|
|
- return ResponseEntity.ok().body(WebResult.success(pageList));
|
|
|
+ return ResponseEntity.ok().body(WebResult.success("pageList"));
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "获取指定主机上应用的所有日志文件")
|
|
|
@GetMapping("/logs")
|
|
|
public ResponseEntity<String> appLogs(@RequestParam("appId") String appId,
|
|
|
@RequestParam("host") String host) throws Exception {
|
|
|
- List<LogFile> list = logManager.logFiles(appId, host);
|
|
|
- return ResponseEntity.ok().body(WebResult.success(list));
|
|
|
+ return ResponseEntity.ok().body("WebResult.success(logs)");
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "获取应用日志内容")
|
|
|
@@ -86,7 +45,27 @@ public class ManageController {
|
|
|
@RequestParam("logType") String logType,
|
|
|
@RequestParam("logLevel") String logLevel,
|
|
|
@RequestParam("logName") String logName) throws Exception {
|
|
|
- List<String> logs = logManager.logContent(appId, logType, logLevel, logName);
|
|
|
- return ResponseEntity.ok().body(WebResult.success(logs));
|
|
|
+ return ResponseEntity.ok().body("WebResult.success(logs)");
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "重启应用")
|
|
|
+ @PostMapping("/restart/{appId}")
|
|
|
+ public ResponseEntity<String> restart(@PathVariable("appId") String appId) throws DockerException {
|
|
|
+ statusService.restart(appId);
|
|
|
+ return ResponseEntity.ok().body("ok");
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "停止应用")
|
|
|
+ @PostMapping("/stop/{appId}")
|
|
|
+ public ResponseEntity<String> stop(@PathVariable("appId") String appId) throws DockerException {
|
|
|
+ statusService.stop(appId);
|
|
|
+ return ResponseEntity.ok().body("ok");
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "启动应用")
|
|
|
+ @PostMapping("/start/{appId}")
|
|
|
+ public ResponseEntity<String> start(@PathVariable("appId") String appId) throws DockerException {
|
|
|
+ statusService.start(appId);
|
|
|
+ return ResponseEntity.ok().body("ok");
|
|
|
}
|
|
|
}
|