EnvironmentController.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package cn.seecoder.paas.web.controller.api;
  2. import cn.seecoder.paas.service.EnvironmentService;
  3. import cn.seecoder.paas.service.model.vo.EnvironmentVO;
  4. import cn.seecoder.paas.util.ServiceException;
  5. import cn.seecoder.paas.web.model.Response;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.web.bind.annotation.*;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.validation.Valid;
  10. @RestController
  11. @RequestMapping("/api/environment")
  12. public class EnvironmentController {
  13. private final EnvironmentService environmentService;
  14. @Autowired
  15. public EnvironmentController(EnvironmentService environmentService) {
  16. this.environmentService = environmentService;
  17. }
  18. @PostMapping("")
  19. public Response create(@Valid @RequestBody EnvironmentVO environmentVO) throws ServiceException {
  20. return Response.buildSuccess(environmentService.createOrUpdate(environmentVO));
  21. }
  22. @PutMapping("")
  23. public Response update(@Valid @RequestBody EnvironmentVO environmentVO) throws ServiceException {
  24. return Response.buildSuccess(environmentService.createOrUpdate(environmentVO));
  25. }
  26. @GetMapping("")
  27. public Response getAll(@RequestParam Integer appId) {
  28. return Response.buildSuccess(environmentService.getListByAppId(appId));
  29. }
  30. @GetMapping("/{id}")
  31. public Response get(@PathVariable("id") Integer id, HttpServletRequest request) throws ServiceException {
  32. Boolean fetchAll = Boolean.valueOf(request.getParameter("fetchAll"));
  33. return Response.buildSuccess(environmentService.get(id, fetchAll == null ? false : fetchAll));
  34. }
  35. @DeleteMapping("/{id}")
  36. public Response delete(@PathVariable("id") Integer id) throws ServiceException {
  37. environmentService.delete(id);
  38. return Response.buildSuccess(null);
  39. }
  40. @GetMapping("/log")
  41. public Response getLog(@RequestParam Integer id, @RequestParam String podName) throws ServiceException {
  42. return Response.buildSuccess(
  43. environmentService.getLog(id, podName));
  44. }
  45. @PostMapping("/deploy")
  46. public Response deploy(@RequestParam Integer id, @RequestParam(required = false, defaultValue = "false") Boolean useCache) throws ServiceException {
  47. return Response.buildSuccess(
  48. environmentService.deploy(id,useCache));
  49. }
  50. @PostMapping("/restart")
  51. public Response deploy(@RequestParam Integer id, @RequestParam String podName) throws ServiceException {
  52. return Response.buildSuccess(
  53. environmentService.restart(id, podName));
  54. }
  55. }