|
@@ -1,15 +1,20 @@
|
|
|
package cn.reghao.autodop.dmaster.machine.controller;
|
|
package cn.reghao.autodop.dmaster.machine.controller;
|
|
|
|
|
|
|
|
|
|
+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.MachineHostCrudService;
|
|
|
import cn.reghao.autodop.dmaster.machine.db.crud.MachineInfoCrudService;
|
|
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.crud.MachineStatCrudService;
|
|
|
|
|
+import cn.reghao.autodop.dmaster.machine.db.query.MachineHostQuery;
|
|
|
import cn.reghao.autodop.dmaster.machine.entity.SshConnData;
|
|
import cn.reghao.autodop.dmaster.machine.entity.SshConnData;
|
|
|
import cn.reghao.autodop.dmaster.machine.entity.po.MachineHost;
|
|
import cn.reghao.autodop.dmaster.machine.entity.po.MachineHost;
|
|
|
import cn.reghao.autodop.dmaster.machine.entity.po.MachineStat;
|
|
import cn.reghao.autodop.dmaster.machine.entity.po.MachineStat;
|
|
|
import cn.reghao.autodop.dmaster.machine.entity.po.SshAuth;
|
|
import cn.reghao.autodop.dmaster.machine.entity.po.SshAuth;
|
|
|
import cn.reghao.autodop.dmaster.machine.entity.po.info.MachineInfo;
|
|
import cn.reghao.autodop.dmaster.machine.entity.po.info.MachineInfo;
|
|
|
-import cn.reghao.autodop.dmaster.machine.service.MachineService;
|
|
|
|
|
import cn.reghao.autodop.dmaster.machine.entity.vo.HostInfo;
|
|
import cn.reghao.autodop.dmaster.machine.entity.vo.HostInfo;
|
|
|
|
|
+import cn.reghao.autodop.dmaster.machine.service.ssh.Keys;
|
|
|
|
|
+import cn.reghao.autodop.dmaster.notification.entity.NotifyGroup;
|
|
|
|
|
+import cn.reghao.autodop.dmaster.notification.repository.NotifyGroupRepository;
|
|
|
import cn.reghao.autodop.dmaster.utils.db.PageList;
|
|
import cn.reghao.autodop.dmaster.utils.db.PageList;
|
|
|
import cn.reghao.autodop.dmaster.utils.db.PageSort;
|
|
import cn.reghao.autodop.dmaster.utils.db.PageSort;
|
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
@@ -24,6 +29,11 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.HashSet;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Set;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @author reghao
|
|
* @author reghao
|
|
|
* @date 2019-08-30 18:49:15
|
|
* @date 2019-08-30 18:49:15
|
|
@@ -35,17 +45,20 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
public class MachinePageController {
|
|
public class MachinePageController {
|
|
|
private MachineInfoCrudService infoCrudService;
|
|
private MachineInfoCrudService infoCrudService;
|
|
|
private MachineHostCrudService hostCrudService;
|
|
private MachineHostCrudService hostCrudService;
|
|
|
|
|
+ private MachineHostQuery hostQuery;
|
|
|
private MachineStatCrudService statCrudService;
|
|
private MachineStatCrudService statCrudService;
|
|
|
- private MachineService machineService;
|
|
|
|
|
|
|
+ private NotifyGroupRepository receiverRepository;
|
|
|
|
|
|
|
|
public MachinePageController(MachineInfoCrudService infoCrudService,
|
|
public MachinePageController(MachineInfoCrudService infoCrudService,
|
|
|
MachineHostCrudService hostCrudService,
|
|
MachineHostCrudService hostCrudService,
|
|
|
|
|
+ MachineHostQuery hostQuery,
|
|
|
MachineStatCrudService statCrudService,
|
|
MachineStatCrudService statCrudService,
|
|
|
- MachineService machineService) {
|
|
|
|
|
|
|
+ NotifyGroupRepository receiverRepository) {
|
|
|
this.infoCrudService = infoCrudService;
|
|
this.infoCrudService = infoCrudService;
|
|
|
this.hostCrudService = hostCrudService;
|
|
this.hostCrudService = hostCrudService;
|
|
|
|
|
+ this.hostQuery = hostQuery;
|
|
|
this.statCrudService = statCrudService;
|
|
this.statCrudService = statCrudService;
|
|
|
- this.machineService = machineService;
|
|
|
|
|
|
|
+ this.receiverRepository = receiverRepository;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation(value = "机器列表页面")
|
|
@ApiOperation(value = "机器列表页面")
|
|
@@ -64,9 +77,63 @@ public class MachinePageController {
|
|
|
return "/machine/host";
|
|
return "/machine/host";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @ApiOperation(value = "机器编辑页面")
|
|
|
|
|
|
|
+ @ApiOperation(value = "机器通知设置页面")
|
|
|
|
|
+ @GetMapping("/notify/{machineId}")
|
|
|
|
|
+ public String machineNotifyPage(@PathVariable("machineId") String machineId, Model model) {
|
|
|
|
|
+ MachineHost machineHost = hostQuery.query(machineId);
|
|
|
|
|
+ Set<NotifyGroup> currentSet = new HashSet<>(machineHost.getNotifyGroups());
|
|
|
|
|
+ List<NotifyGroup> list = receiverRepository.findAll();
|
|
|
|
|
+
|
|
|
|
|
+ model.addAttribute("machineId", machineId);
|
|
|
|
|
+ model.addAttribute("currentSet", currentSet);
|
|
|
|
|
+ model.addAttribute("list", list);
|
|
|
|
|
+ return "/machine/machinenotify";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation(value = "SSH 认证设置页面")
|
|
|
|
|
+ @GetMapping("/sshauth/{machineId}")
|
|
|
|
|
+ public String sshAuthPage(@PathVariable("machineId") String machineId, Model model) {
|
|
|
|
|
+ MachineHost machineHost = hostQuery.query(machineId);
|
|
|
|
|
+ SshAuth sshAuth = machineHost.getSshAuth();
|
|
|
|
|
+
|
|
|
|
|
+ model.addAttribute("machineId", machineId);
|
|
|
|
|
+ model.addAttribute("sshAuth", sshAuth);
|
|
|
|
|
+ return "/machine/sshauth";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation(value = "SSH 控制台页面")
|
|
|
|
|
+ @GetMapping("/webssh/{machineId}")
|
|
|
|
|
+ public String webSshPage(@PathVariable("machineId") String machineId, Model model) {
|
|
|
|
|
+ MachineHost machineHost = hostQuery.query(machineId);
|
|
|
|
|
+ String machineIpv4 = machineHost.getMachineInfo().machineIpv4();
|
|
|
|
|
+ SshAuth sshAuth = machineHost.getSshAuth();
|
|
|
|
|
+ if (sshAuth == null) {
|
|
|
|
|
+ return "先设置 SSH 认证";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ SshConnData sshConnData = new SshConnData();
|
|
|
|
|
+ sshConnData.setOps(Keys.OPS_CONNECT);
|
|
|
|
|
+ sshConnData.setHost(machineIpv4);
|
|
|
|
|
+ sshConnData.setPort(sshAuth.getPort());
|
|
|
|
|
+ sshConnData.setUsername(sshAuth.getUsername());
|
|
|
|
|
+ sshConnData.setPassword(sshAuth.getPassword());
|
|
|
|
|
+
|
|
|
|
|
+ model.addAttribute("sshConnData", sshConnData);
|
|
|
|
|
+ return "/machine/webssh";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation(value = "机器额外信息编辑页面")
|
|
|
@GetMapping("/host/edit/{machineId}")
|
|
@GetMapping("/host/edit/{machineId}")
|
|
|
public String hostEditPage(@PathVariable("machineId") String machineId, Model model) {
|
|
public String hostEditPage(@PathVariable("machineId") String machineId, Model model) {
|
|
|
|
|
+ List<KeyValue> envs = new ArrayList<>();
|
|
|
|
|
+ for (EnvType envType : EnvType.values()) {
|
|
|
|
|
+ envs.add(new KeyValue(envType.name(), envType.name()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ MachineHost machineHost = hostQuery.query(machineId);
|
|
|
|
|
+ model.addAttribute("machineId", machineId);
|
|
|
|
|
+ model.addAttribute("environments", envs);
|
|
|
|
|
+ model.addAttribute("env", machineHost.getEnv());
|
|
|
return "/machine/edit";
|
|
return "/machine/edit";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -78,32 +145,6 @@ public class MachinePageController {
|
|
|
return "/machine/detail";
|
|
return "/machine/detail";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @ApiOperation(value = "机器状态详情页面")
|
|
|
|
|
- @GetMapping("/host/status/{machineId}")
|
|
|
|
|
- public String hostStatusPage(@PathVariable("machineId") String machineId, Model model) {
|
|
|
|
|
- return "/machine/status";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @ApiOperation(value = "内存使用详情页面")
|
|
|
|
|
- @GetMapping("/host/status/mem/{machineId}")
|
|
|
|
|
- public String memUsagePage(@PathVariable("machineId") String machineId, Model model) {
|
|
|
|
|
- MachineStat machineStat = statCrudService.selectByUk(machineId);
|
|
|
|
|
- if (machineStat != null) {
|
|
|
|
|
- model.addAttribute("memoryUsage", machineStat.getMemoryUsage());
|
|
|
|
|
- }
|
|
|
|
|
- return "/machine/memusage";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @ApiOperation(value = "磁盘使用详情页面")
|
|
|
|
|
- @GetMapping("/host/status/disk/{machineId}")
|
|
|
|
|
- public String diskUsagePage(@PathVariable("machineId") String machineId, Model model) {
|
|
|
|
|
- MachineStat machineStat = statCrudService.selectByUk(machineId);
|
|
|
|
|
- if (machineStat != null) {
|
|
|
|
|
- model.addAttribute("diskUsages", machineStat.getDiskUsages());
|
|
|
|
|
- }
|
|
|
|
|
- return "/machine/diskusage";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
@ApiOperation(value = "机器状态列表页面")
|
|
@ApiOperation(value = "机器状态列表页面")
|
|
|
@GetMapping("/status")
|
|
@GetMapping("/status")
|
|
|
public String statusPage(@RequestParam(value = "env", required = false) String env,
|
|
public String statusPage(@RequestParam(value = "env", required = false) String env,
|
|
@@ -120,27 +161,49 @@ public class MachinePageController {
|
|
|
return "/machine/status";
|
|
return "/machine/status";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @ApiOperation(value = "机器通知设置页面")
|
|
|
|
|
- @GetMapping("/notify/{machineId}")
|
|
|
|
|
- public String machineNotifyPage(@PathVariable("machineId") String machineId, Model model) {
|
|
|
|
|
- return "/machine/machinenotify";
|
|
|
|
|
|
|
+ @ApiOperation(value = "机器系统负载页面")
|
|
|
|
|
+ @GetMapping("/status/sys/{machineId}")
|
|
|
|
|
+ public String hostStatusPage(@PathVariable("machineId") String machineId, Model model) {
|
|
|
|
|
+ return "/machine/sysload";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @ApiOperation(value = "SSH 认证设置页面")
|
|
|
|
|
- @GetMapping("/sshauth/{machineId}")
|
|
|
|
|
- public String sshAuthPage(@PathVariable("machineId") String machineId, Model model) {
|
|
|
|
|
- SshAuth sshAuth = new SshAuth();
|
|
|
|
|
|
|
+ @ApiOperation(value = "网络状态页面")
|
|
|
|
|
+ @GetMapping("/status/network/{machineId}")
|
|
|
|
|
+ public String networkStatusPage(@PathVariable("machineId") String machineId, Model model) {
|
|
|
|
|
+ MachineStat machineStat = statCrudService.selectByUk(machineId);
|
|
|
|
|
+ if (machineStat != null) {
|
|
|
|
|
+ model.addAttribute("memoryUsage", machineStat.getMemoryUsage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return "/machine/networkstatus";
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- model.addAttribute("machineId", machineId);
|
|
|
|
|
- model.addAttribute("sshAuth", sshAuth);
|
|
|
|
|
- return "/machine/sshauth";
|
|
|
|
|
|
|
+ @ApiOperation(value = "CPU 使用率页面")
|
|
|
|
|
+ @GetMapping("/status/cpu/{machineId}")
|
|
|
|
|
+ public String cpuUsagePage(@PathVariable("machineId") String machineId, Model model) {
|
|
|
|
|
+ MachineStat machineStat = statCrudService.selectByUk(machineId);
|
|
|
|
|
+ if (machineStat != null) {
|
|
|
|
|
+ model.addAttribute("memoryUsage", machineStat.getMemoryUsage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return "/machine/cpuusage";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @ApiOperation(value = "SSH 控制台页面")
|
|
|
|
|
- @GetMapping("/webssh/{machineId}")
|
|
|
|
|
- public String webSshPage(@PathVariable("machineId") String machineId, Model model) {
|
|
|
|
|
- SshConnData sshConnData = new SshConnData();
|
|
|
|
|
- model.addAttribute("sshConnData", sshConnData);
|
|
|
|
|
- return "/machine/webssh";
|
|
|
|
|
|
|
+ @ApiOperation(value = "内存详情页面")
|
|
|
|
|
+ @GetMapping("/status/mem/{machineId}")
|
|
|
|
|
+ public String memUsagePage(@PathVariable("machineId") String machineId, Model model) {
|
|
|
|
|
+ MachineStat machineStat = statCrudService.selectByUk(machineId);
|
|
|
|
|
+ if (machineStat != null) {
|
|
|
|
|
+ model.addAttribute("memoryUsage", machineStat.getMemoryUsage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return "/machine/memusage";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation(value = "磁盘详情页面")
|
|
|
|
|
+ @GetMapping("/status/disk/{machineId}")
|
|
|
|
|
+ public String diskUsagePage(@PathVariable("machineId") String machineId, Model model) {
|
|
|
|
|
+ MachineStat machineStat = statCrudService.selectByUk(machineId);
|
|
|
|
|
+ if (machineStat != null) {
|
|
|
|
|
+ model.addAttribute("diskUsages", machineStat.getDiskUsages());
|
|
|
|
|
+ }
|
|
|
|
|
+ return "/machine/diskusage";
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|