|
|
@@ -1,11 +1,20 @@
|
|
|
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.app.AppConfigQuery;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.config.AppOrchestration;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.config.build.CompilerConfig;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.config.build.PackerConfig;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.config.build.RepoAuthConfig;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.config.AppOrchestrationRepository;
|
|
|
+import cn.reghao.autodop.dmaster.app.repository.config.build.CompilerConfigRepository;
|
|
|
+import cn.reghao.autodop.dmaster.app.repository.config.build.PackerConfigRepository;
|
|
|
+import cn.reghao.autodop.dmaster.app.repository.config.build.RepoAuthConfigRepository;
|
|
|
import cn.reghao.autodop.dmaster.app.validator.AppOrchestrationValidator;
|
|
|
-import cn.reghao.autodop.dmaster.auth.entity.User;
|
|
|
+import cn.reghao.autodop.dmaster.machine.entity.MachineInfo;
|
|
|
+import cn.reghao.autodop.dmaster.machine.entity.NetworkInfo;
|
|
|
+import cn.reghao.autodop.dmaster.machine.repository.MachineInfoRepository;
|
|
|
import cn.reghao.autodop.dmaster.utils.WebBody;
|
|
|
import cn.reghao.autodop.dmaster.utils.db.PageList;
|
|
|
import cn.reghao.autodop.dmaster.utils.db.PageSort;
|
|
|
@@ -22,9 +31,8 @@ import org.springframework.ui.Model;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author reghao
|
|
|
@@ -37,10 +45,23 @@ import java.util.Map;
|
|
|
public class AppConfigPageController {
|
|
|
private AppConfigQuery appConfigQuery;
|
|
|
private AppOrchestrationRepository appRepository;
|
|
|
-
|
|
|
- public AppConfigPageController(AppConfigQuery appConfigQuery, AppOrchestrationRepository appRepository) {
|
|
|
+ private RepoAuthConfigRepository repoAuthRepository;
|
|
|
+ private CompilerConfigRepository compilerRepository;
|
|
|
+ private PackerConfigRepository packerRepository;
|
|
|
+ private MachineInfoRepository machineRepository;
|
|
|
+
|
|
|
+ public AppConfigPageController(AppConfigQuery appConfigQuery,
|
|
|
+ AppOrchestrationRepository appRepository,
|
|
|
+ RepoAuthConfigRepository repoAuthRepository,
|
|
|
+ CompilerConfigRepository compilerRepository,
|
|
|
+ PackerConfigRepository packerRepository,
|
|
|
+ MachineInfoRepository machineRepository) {
|
|
|
this.appConfigQuery = appConfigQuery;
|
|
|
this.appRepository = appRepository;
|
|
|
+ this.repoAuthRepository = repoAuthRepository;
|
|
|
+ this.compilerRepository = compilerRepository;
|
|
|
+ this.packerRepository = packerRepository;
|
|
|
+ this.machineRepository = machineRepository;
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "应用配置页面")
|
|
|
@@ -76,18 +97,62 @@ public class AppConfigPageController {
|
|
|
}
|
|
|
|
|
|
@PostMapping(value = "/app", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
- public String appConfigPage(@Validated AppOrchestrationValidator appOrchestrationValidator,
|
|
|
+ public String appConfigPage(/*@Validated AppOrchestrationValidator appOrchestrationValidator,*/
|
|
|
AppOrchestration appOrchestration) {
|
|
|
return WebBody.success();
|
|
|
}
|
|
|
|
|
|
@GetMapping("/app/add")
|
|
|
- public String addAppConfigPage() {
|
|
|
+ public String addAppConfigPage(Model model) {
|
|
|
+ setModel(model);
|
|
|
return "/app/config/app/add";
|
|
|
}
|
|
|
|
|
|
+ private void setModel(Model model) {
|
|
|
+ List<String> environments = new ArrayList<>();
|
|
|
+ for (EnvType envType : EnvType.values()) {
|
|
|
+ environments.add(envType.name());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> appTypes = new ArrayList<>();
|
|
|
+ for (AppType appType : AppType.values()) {
|
|
|
+ appTypes.add(appType.name());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> repoAuths = repoAuthRepository.findAllByIsDeleteFalse().stream()
|
|
|
+ .map(RepoAuthConfig::getName)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<String> compilers = compilerRepository.findAllByIsDeleteFalse().stream()
|
|
|
+ .map(CompilerConfig::getName)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<String> packers = packerRepository.findAllByIsDeleteFalse().stream()
|
|
|
+ .map(PackerConfig::getName)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<MachineInfo> machines = machineRepository.findAllByIsDeleteFalse();
|
|
|
+ List<String> machineIpv4s = machines.stream()
|
|
|
+ .map(machineInfo -> {
|
|
|
+ List<NetworkInfo> networkInfos = machineInfo.getNetworkInfo();
|
|
|
+ if (!networkInfos.isEmpty()) {
|
|
|
+ return networkInfos.get(0).getIpv4();
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ })
|
|
|
+ .filter(Objects::isNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ model.addAttribute("environments", environments);
|
|
|
+ model.addAttribute("appTypes", appTypes);
|
|
|
+ model.addAttribute("repoAuths", repoAuths);
|
|
|
+ model.addAttribute("compilers", compilers);
|
|
|
+ model.addAttribute("packers", packers);
|
|
|
+ model.addAttribute("machines", machineIpv4s);
|
|
|
+ }
|
|
|
+
|
|
|
@GetMapping("/app/edit/{id}")
|
|
|
public String editAppConfigPage(@PathVariable("id") AppOrchestration app, Model model) {
|
|
|
+ setModel(model);
|
|
|
model.addAttribute("app", app);
|
|
|
return "/app/config/app/add";
|
|
|
}
|