|
|
@@ -1,17 +1,23 @@
|
|
|
package cn.reghao.autodop.dmaster.app.controller.view;
|
|
|
|
|
|
+import cn.reghao.autodop.dmaster.app.constant.AppType;
|
|
|
import cn.reghao.autodop.dmaster.app.constant.EnvType;
|
|
|
import cn.reghao.autodop.dmaster.app.db.query.AppBuildingQuery;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.AppDeploying;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.AppRunning;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.config.AppOrchestration;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.config.deploy.DeployConfig;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.log.BuildLog;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.AppBuildingRepository;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.AppDeployingRepository;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.AppRunningRepository;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.AppBuilding;
|
|
|
+import cn.reghao.autodop.dmaster.app.repository.config.AppOrchestrationRepository;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.log.BuildLogRepository;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.log.DeployLogRepository;
|
|
|
-import cn.reghao.autodop.dmaster.utils.WebBody;
|
|
|
+import cn.reghao.autodop.dmaster.auth.UserContext;
|
|
|
+import cn.reghao.autodop.dmaster.auth.entity.RoleType;
|
|
|
+import cn.reghao.autodop.dmaster.auth.entity.User;
|
|
|
import cn.reghao.autodop.dmaster.utils.db.PageList;
|
|
|
import cn.reghao.autodop.dmaster.utils.db.PageSort;
|
|
|
import io.swagger.annotations.Api;
|
|
|
@@ -22,9 +28,7 @@ import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author reghao
|
|
|
@@ -35,24 +39,21 @@ import java.util.Map;
|
|
|
@Controller
|
|
|
@RequestMapping("/app")
|
|
|
public class AppPageController {
|
|
|
- private AppBuildingRepository appBuildingRepository;
|
|
|
- private AppDeployingRepository appDeployingRepository;
|
|
|
- private AppRunningRepository appRunningRepository;
|
|
|
+ private AppOrchestrationRepository appRepository;
|
|
|
+ private AppBuildingRepository buildingRepository;
|
|
|
+ private AppDeployingRepository deployingRepository;
|
|
|
+ private AppRunningRepository runningRepository;
|
|
|
private AppBuildingQuery buildingQuery;
|
|
|
- private BuildLogRepository buildLogRepository;
|
|
|
- private DeployLogRepository deployLogRepository;
|
|
|
-
|
|
|
- public AppPageController(AppBuildingRepository appBuildingRepository,
|
|
|
- AppDeployingRepository appDeployingRepository,
|
|
|
- AppRunningRepository appRunningRepository,
|
|
|
- BuildLogRepository buildLogRepository,
|
|
|
- DeployLogRepository deployLogRepository,
|
|
|
+
|
|
|
+ public AppPageController(AppOrchestrationRepository appRepository,
|
|
|
+ AppBuildingRepository buildingRepository,
|
|
|
+ AppDeployingRepository deployingRepository,
|
|
|
+ AppRunningRepository runningRepository,
|
|
|
AppBuildingQuery buildingQuery) {
|
|
|
- this.appBuildingRepository = appBuildingRepository;
|
|
|
- this.appDeployingRepository = appDeployingRepository;
|
|
|
- this.appRunningRepository = appRunningRepository;
|
|
|
- this.buildLogRepository = buildLogRepository;
|
|
|
- this.deployLogRepository = deployLogRepository;
|
|
|
+ this.appRepository = appRepository;
|
|
|
+ this.buildingRepository = buildingRepository;
|
|
|
+ this.deployingRepository = deployingRepository;
|
|
|
+ this.runningRepository = runningRepository;
|
|
|
this.buildingQuery = buildingQuery;
|
|
|
}
|
|
|
|
|
|
@@ -78,10 +79,29 @@ public class AppPageController {
|
|
|
return "/app/build";
|
|
|
}
|
|
|
|
|
|
+ Set<String> set = new HashSet<>();
|
|
|
+ UserContext.currentUser().getAuthorities().forEach(auth -> {
|
|
|
+ set.add(auth.getAuthority());
|
|
|
+ });
|
|
|
+
|
|
|
+ String appType;
|
|
|
+ if (set.contains(RoleType.ROLE_BACKEND.name())) {
|
|
|
+ appType = AppType.dotnetCore.name();
|
|
|
+ } else if (set.contains(RoleType.ROLE_FRONTEND.name())) {
|
|
|
+ appType = AppType.npm.name();
|
|
|
+ } else {
|
|
|
+ appType = AppType.maven.name();
|
|
|
+ }
|
|
|
+
|
|
|
PageRequest pageRequest = PageSort.pageRequest();
|
|
|
- Page<AppBuilding> appBuildings = appBuildingRepository.findAllByEnv(env, pageRequest);
|
|
|
- PageList<AppBuilding> pageList = PageList.pageList(appBuildings);
|
|
|
+ Page<AppBuilding> appBuildings;
|
|
|
+ if (set.contains(RoleType.ROLE_ADMIN.name())) {
|
|
|
+ appBuildings = buildingRepository.findAllByEnv(env, pageRequest);
|
|
|
+ } else {
|
|
|
+ appBuildings = buildingRepository.findAllByEnvAndAppType(env, appType, pageRequest);
|
|
|
+ }
|
|
|
|
|
|
+ PageList<AppBuilding> pageList = PageList.pageList(appBuildings);
|
|
|
model.addAttribute("env", env);
|
|
|
model.addAttribute("page", appBuildings);
|
|
|
model.addAttribute("list", pageList.getList());
|
|
|
@@ -89,9 +109,16 @@ public class AppPageController {
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "部署页面")
|
|
|
- @GetMapping("/deploy/{buildLogId}")
|
|
|
- public String deployPage(@PathVariable("buildLogId") String buildLogId, Model model) {
|
|
|
- List<AppDeploying> list = appDeployingRepository.findByBuildLogId(buildLogId);
|
|
|
+ @GetMapping("/deploy/{appId}")
|
|
|
+ public String deployPage(@PathVariable("appId") String appId, Model model) {
|
|
|
+ AppOrchestration app = appRepository.findByIsDeleteFalseAndAppId(appId);
|
|
|
+ List<DeployConfig> deployConfigs = app.getDeployConfigs();
|
|
|
+ List<AppDeploying> list = new ArrayList<>();
|
|
|
+ for (DeployConfig deployConfig : deployConfigs) {
|
|
|
+ AppDeploying deploying = deployingRepository.findByAppIdAndMachineId(appId, deployConfig.getMachineId());
|
|
|
+ list.add(deploying);
|
|
|
+ }
|
|
|
+
|
|
|
model.addAttribute("list", list);
|
|
|
return "/app/deploy";
|
|
|
}
|
|
|
@@ -107,15 +134,32 @@ public class AppPageController {
|
|
|
|
|
|
@ApiOperation(value = "运行状态页面")
|
|
|
@GetMapping("/status")
|
|
|
- public String statusPage(Model model) {
|
|
|
- int page = 1;
|
|
|
- int size = 10;
|
|
|
- PageRequest pageRequest =
|
|
|
- PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC, "updateTime"));
|
|
|
- Page<AppRunning> appRunningPage = appRunningRepository.findAll(pageRequest);
|
|
|
- PageList<AppRunning> pageList = PageList.pageList(appRunningPage);
|
|
|
+ public String statusPage(@RequestParam(value = "env", required = false) String env,
|
|
|
+ @RequestParam(value = "appName", required = false) String appName,
|
|
|
+ Model model) {
|
|
|
+ if (env == null) {
|
|
|
+ env = EnvType.test.name();
|
|
|
+ }
|
|
|
|
|
|
- model.addAttribute("page", appRunningPage);
|
|
|
+ if (appName != null) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("appName", appName);
|
|
|
+ List<AppRunning> list = buildingQuery.queryAppRunning(map);
|
|
|
+ Page<AppRunning> page = new PageImpl<>(list);
|
|
|
+ PageList<AppRunning> pageList = PageList.pageList(page);
|
|
|
+
|
|
|
+ model.addAttribute("env", env);
|
|
|
+ model.addAttribute("page", page);
|
|
|
+ model.addAttribute("list", pageList.getList());
|
|
|
+ return "/app/status";
|
|
|
+ }
|
|
|
+
|
|
|
+ PageRequest pageRequest = PageSort.pageRequest();
|
|
|
+ Page<AppRunning> appRunnings = runningRepository.findAllByEnv(env, pageRequest);
|
|
|
+ PageList<AppRunning> pageList = PageList.pageList(appRunnings);
|
|
|
+
|
|
|
+ model.addAttribute("env", env);
|
|
|
+ model.addAttribute("page", appRunnings);
|
|
|
model.addAttribute("list", pageList.getList());
|
|
|
return "/app/status";
|
|
|
}
|
|
|
@@ -129,7 +173,7 @@ public class AppPageController {
|
|
|
PageRequest pageRequest =
|
|
|
PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC, "updateTime"));
|
|
|
|
|
|
- Page<AppBuilding> appBuildings = appBuildingRepository.findAllByEnv(env, pageRequest);
|
|
|
+ Page<AppBuilding> appBuildings = buildingRepository.findAllByEnv(env, pageRequest);
|
|
|
PageList<AppBuilding> pageList = PageList.pageList(appBuildings);
|
|
|
|
|
|
model.addAttribute("page", appBuildings);
|