|
|
@@ -3,10 +3,8 @@ package cn.reghao.autodop.dmaster.machine.controller;
|
|
|
import cn.reghao.autodop.common.utils.DateTimeConverter;
|
|
|
import cn.reghao.autodop.dmaster.app.constant.EnvType;
|
|
|
import cn.reghao.autodop.dmaster.app.vo.KeyValue;
|
|
|
-import cn.reghao.autodop.dmaster.machine.db.crud.MachineHostCrudService;
|
|
|
import cn.reghao.autodop.dmaster.machine.db.crud.MachineInfoCrudService;
|
|
|
-import cn.reghao.autodop.dmaster.machine.db.crud.MachineStatCrudService;
|
|
|
-import cn.reghao.autodop.dmaster.machine.db.query.MachineHostQuery;
|
|
|
+import cn.reghao.autodop.dmaster.machine.db.query.MachineQuery;
|
|
|
import cn.reghao.autodop.dmaster.machine.db.query.MachineStatQuery;
|
|
|
import cn.reghao.autodop.dmaster.machine.entity.SshConnData;
|
|
|
import cn.reghao.autodop.dmaster.machine.entity.po.MachineHost;
|
|
|
@@ -23,6 +21,7 @@ import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
|
@@ -32,38 +31,29 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author reghao
|
|
|
* @date 2019-08-30 18:49:15
|
|
|
*/
|
|
|
@Slf4j
|
|
|
-@Api(tags = "机器页面接口")
|
|
|
+@Api(tags = "机器模块页面")
|
|
|
@Controller
|
|
|
@RequestMapping("/machine")
|
|
|
public class MachinePageController {
|
|
|
private MachineInfoCrudService infoCrudService;
|
|
|
- private MachineHostCrudService hostCrudService;
|
|
|
- private MachineHostQuery hostQuery;
|
|
|
+ private MachineQuery machineQuery;
|
|
|
private MachineStatQuery statQuery;
|
|
|
- private MachineStatCrudService statCrudService;
|
|
|
private NotifyGroupRepository receiverRepository;
|
|
|
|
|
|
public MachinePageController(MachineInfoCrudService infoCrudService,
|
|
|
- MachineHostCrudService hostCrudService,
|
|
|
- MachineHostQuery hostQuery,
|
|
|
+ MachineQuery machineQuery,
|
|
|
MachineStatQuery statQuery,
|
|
|
- MachineStatCrudService statCrudService,
|
|
|
NotifyGroupRepository receiverRepository) {
|
|
|
this.infoCrudService = infoCrudService;
|
|
|
- this.hostCrudService = hostCrudService;
|
|
|
- this.hostQuery = hostQuery;
|
|
|
+ this.machineQuery = machineQuery;
|
|
|
this.statQuery = statQuery;
|
|
|
- this.statCrudService = statCrudService;
|
|
|
this.receiverRepository = receiverRepository;
|
|
|
}
|
|
|
|
|
|
@@ -72,21 +62,43 @@ public class MachinePageController {
|
|
|
public String hostPage(@RequestParam(value = "env", required = false) String env,
|
|
|
@RequestParam(value = "machineIpv4", required = false) String machineIpv4,
|
|
|
Model model) {
|
|
|
+ if (env == null) {
|
|
|
+ env = EnvType.test.name();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (machineIpv4 != null) {
|
|
|
+ searchByMachineIpv4(env, machineIpv4, model);
|
|
|
+ return "/machine/host";
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, String> queryMap = new HashMap<>();
|
|
|
+ queryMap.put("env", env);
|
|
|
PageRequest pageRequest = PageSort.pageRequest();
|
|
|
- Page<MachineHost> page = hostCrudService.selectByPage(pageRequest);
|
|
|
+ Page<MachineHost> page = machineQuery.queryByMatchAll(queryMap, pageRequest);
|
|
|
Page<HostInfo> hostInfos = page.map(HostInfo::new);
|
|
|
PageList<HostInfo> pageList = PageList.pageList(hostInfos);
|
|
|
|
|
|
- //model.addAttribute("env", env);
|
|
|
+ model.addAttribute("env", env);
|
|
|
model.addAttribute("page", page);
|
|
|
model.addAttribute("list", pageList.getList());
|
|
|
return "/machine/host";
|
|
|
}
|
|
|
|
|
|
+ private void searchByMachineIpv4(String env, String machineIpv4, Model model) {
|
|
|
+ List<MachineHost> list = machineQuery.queryByMachineIpv4(machineIpv4);
|
|
|
+ Page<MachineHost> page = new PageImpl<>(list);
|
|
|
+ Page<HostInfo> hostInfos = page.map(HostInfo::new);
|
|
|
+ PageList<HostInfo> pageList = PageList.pageList(hostInfos);
|
|
|
+
|
|
|
+ model.addAttribute("env", env);
|
|
|
+ model.addAttribute("page", page);
|
|
|
+ model.addAttribute("list", pageList.getList());
|
|
|
+ }
|
|
|
+
|
|
|
@ApiOperation(value = "机器通知设置页面")
|
|
|
@GetMapping("/notify/{machineId}")
|
|
|
public String machineNotifyPage(@PathVariable("machineId") String machineId, Model model) {
|
|
|
- MachineHost machineHost = hostQuery.query(machineId);
|
|
|
+ MachineHost machineHost = machineQuery.query(machineId);
|
|
|
Set<NotifyGroup> currentSet = new HashSet<>(machineHost.getNotifyGroups());
|
|
|
List<NotifyGroup> list = receiverRepository.findAll();
|
|
|
|
|
|
@@ -99,7 +111,7 @@ public class MachinePageController {
|
|
|
@ApiOperation(value = "SSH 认证设置页面")
|
|
|
@GetMapping("/sshauth/{machineId}")
|
|
|
public String sshAuthPage(@PathVariable("machineId") String machineId, Model model) {
|
|
|
- MachineHost machineHost = hostQuery.query(machineId);
|
|
|
+ MachineHost machineHost = machineQuery.query(machineId);
|
|
|
SshAuth sshAuth = machineHost.getSshAuth();
|
|
|
|
|
|
model.addAttribute("machineId", machineId);
|
|
|
@@ -110,7 +122,7 @@ public class MachinePageController {
|
|
|
@ApiOperation(value = "SSH 控制台页面")
|
|
|
@GetMapping("/webssh/{machineId}")
|
|
|
public String webSshPage(@PathVariable("machineId") String machineId, Model model) {
|
|
|
- MachineHost machineHost = hostQuery.query(machineId);
|
|
|
+ MachineHost machineHost = machineQuery.query(machineId);
|
|
|
String machineIpv4 = machineHost.getMachineInfo().machineIpv4();
|
|
|
SshAuth sshAuth = machineHost.getSshAuth();
|
|
|
if (sshAuth == null) {
|
|
|
@@ -136,7 +148,7 @@ public class MachinePageController {
|
|
|
envs.add(new KeyValue(envType.name(), envType.name()));
|
|
|
}
|
|
|
|
|
|
- MachineHost machineHost = hostQuery.query(machineId);
|
|
|
+ MachineHost machineHost = machineQuery.query(machineId);
|
|
|
model.addAttribute("machineId", machineId);
|
|
|
model.addAttribute("environments", envs);
|
|
|
model.addAttribute("env", machineHost.getEnv());
|
|
|
@@ -156,18 +168,29 @@ public class MachinePageController {
|
|
|
public String statusPage(@RequestParam(value = "env", required = false) String env,
|
|
|
@RequestParam(value = "machineIpv4", required = false) String machineIpv4,
|
|
|
Model model) {
|
|
|
+ if (env == null) {
|
|
|
+ env = EnvType.test.name();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (machineIpv4 != null) {
|
|
|
+ searchByMachineIpv4(env, machineIpv4, model);
|
|
|
+ return "/machine/status";
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, String> queryMap = new HashMap<>();
|
|
|
+ queryMap.put("env", env);
|
|
|
PageRequest pageRequest = PageSort.pageRequest();
|
|
|
- Page<MachineHost> page = hostCrudService.selectByPage(pageRequest);
|
|
|
+ Page<MachineHost> page = machineQuery.queryByMatchAll(queryMap, pageRequest);
|
|
|
Page<HostInfo> hostInfos = page.map(HostInfo::new);
|
|
|
PageList<HostInfo> pageList = PageList.pageList(hostInfos);
|
|
|
|
|
|
- //model.addAttribute("env", env);
|
|
|
+ model.addAttribute("env", env);
|
|
|
model.addAttribute("page", page);
|
|
|
model.addAttribute("list", pageList.getList());
|
|
|
return "/machine/status";
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "机器系统负载页面")
|
|
|
+ @ApiOperation(value = "系统负载页面")
|
|
|
@GetMapping("/status/sys/{machineId}")
|
|
|
public String hostStatusPage(@PathVariable("machineId") String machineId, Model model) {
|
|
|
MachineStat machineStat = statQuery.query(machineId);
|