|
|
@@ -5,6 +5,7 @@ import cn.reghao.autodop.dmaster.app.vo.KeyValue;
|
|
|
import cn.reghao.autodop.dmaster.monitor.entity.AppMonitor;
|
|
|
import cn.reghao.autodop.dmaster.monitor.entity.MachineMonitor;
|
|
|
import cn.reghao.autodop.dmaster.monitor.entity.MonitorJob;
|
|
|
+import cn.reghao.autodop.dmaster.monitor.entity.MonitorType;
|
|
|
import cn.reghao.autodop.dmaster.monitor.repository.AppMonitorRepository;
|
|
|
import cn.reghao.autodop.dmaster.monitor.repository.MachineMonitorRepository;
|
|
|
import cn.reghao.autodop.dmaster.notification.entity.NotifyGroup;
|
|
|
@@ -19,22 +20,18 @@ import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author reghao
|
|
|
* @date 2019-08-30 18:49:15
|
|
|
*/
|
|
|
@Slf4j
|
|
|
-@Api(tags = "监控页面接口")
|
|
|
+@Api(tags = "机器监控页面")
|
|
|
@Controller
|
|
|
@RequestMapping("/monitor")
|
|
|
public class MonitorPageController {
|
|
|
@@ -50,106 +47,188 @@ public class MonitorPageController {
|
|
|
this.receiverRepository = receiverRepository;
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "机器监控页面")
|
|
|
- @GetMapping("/machine")
|
|
|
- public String machineMonitorPage(Model model) {
|
|
|
+ @ApiOperation(value = "监控页面")
|
|
|
+ @GetMapping("/{monitorType}")
|
|
|
+ public String machineMonitorPage(@PathVariable("monitorType") String monitorType, Model model) {
|
|
|
PageRequest pageRequest = PageSort.pageRequest();
|
|
|
- Page<MachineMonitor> page = machineMonitorRepository.findAll(pageRequest);
|
|
|
- PageList<MachineMonitor> pageList = PageList.pageList(page);
|
|
|
+ switch (MonitorType.valueOf(monitorType)) {
|
|
|
+ case machine:
|
|
|
+ Page<MachineMonitor> page = machineMonitorRepository.findAll(pageRequest);
|
|
|
+ PageList<MachineMonitor> pageList = PageList.pageList(page);
|
|
|
+
|
|
|
+ model.addAttribute("page", page);
|
|
|
+ model.addAttribute("list", pageList.getList());
|
|
|
+ return "/monitor/machinemonitor";
|
|
|
+ case app:
|
|
|
+ Page<MachineMonitor> page1 = machineMonitorRepository.findAll(pageRequest);
|
|
|
+ PageList<MachineMonitor> pageList1 = PageList.pageList(page1);
|
|
|
+
|
|
|
+ model.addAttribute("page", page1);
|
|
|
+ model.addAttribute("list", pageList1.getList());
|
|
|
+ return "/monitor/appmonitor";
|
|
|
+ default:
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "监控通知设置页面")
|
|
|
+ @GetMapping("/{monitorType}/notify/{id}")
|
|
|
+ public String monitorNotifyPage(@PathVariable("monitorType") String monitorType,
|
|
|
+ @PathVariable("id") Integer id,
|
|
|
+ Model model) {
|
|
|
+ String notifyApi;
|
|
|
+ Set<NotifyGroup> currentSet;
|
|
|
+ List<NotifyGroup> list;
|
|
|
+ switch (MonitorType.valueOf(monitorType)) {
|
|
|
+ case machine:
|
|
|
+ notifyApi = "/api/monitor/machine/notify/" + id;
|
|
|
+ MachineMonitor machineMonitor = machineMonitorRepository.findById(id).orElse(null);
|
|
|
+ currentSet = new HashSet<>(machineMonitor.getNotifyGroups());
|
|
|
+ list = receiverRepository.findAll();
|
|
|
+ break;
|
|
|
+ case app:
|
|
|
+ notifyApi = "/api/monitor/app/notify/" + id;
|
|
|
+ AppMonitor appMonitor = appMonitorRepository.findById(id).orElse(null);
|
|
|
+ currentSet = new HashSet<>(appMonitor.getNotifyGroups());
|
|
|
+ list = receiverRepository.findAll();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ notifyApi = null;
|
|
|
+ currentSet = Collections.emptySet();
|
|
|
+ list = Collections.emptyList();
|
|
|
+ }
|
|
|
|
|
|
- model.addAttribute("page", page);
|
|
|
- model.addAttribute("list", pageList.getList());
|
|
|
- return "/monitor/machine";
|
|
|
+ model.addAttribute("notifyApi", notifyApi);
|
|
|
+ model.addAttribute("currentSet", currentSet);
|
|
|
+ model.addAttribute("list", list);
|
|
|
+ return "/monitor/monitornotify";
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "机器监控任务列表页面")
|
|
|
- @GetMapping("/machine/jobs/{id}")
|
|
|
- public String monitorAddPage(@PathVariable("id") MachineMonitor machineMonitor, Model model) {
|
|
|
- List<MonitorJob> list = machineMonitor.getMonitorJobs();
|
|
|
- model.addAttribute("machineMonitorId", machineMonitor.getId());
|
|
|
+ @ApiOperation(value = "监控任务列表页面")
|
|
|
+ @GetMapping("/{monitorType}/jobs/{id}")
|
|
|
+ public String monitorAddPage(@PathVariable("monitorType") String monitorType,
|
|
|
+ @PathVariable("id") Integer id,
|
|
|
+ Model model) {
|
|
|
+
|
|
|
+ String addJobUrl;
|
|
|
+ String editJobUrl;
|
|
|
+ String jobStatusApi;
|
|
|
+ List<MonitorJob> list;
|
|
|
+ switch (MonitorType.valueOf(monitorType)) {
|
|
|
+ case machine:
|
|
|
+ addJobUrl = String.format("/monitor/machine/jobs/add/%s", id);
|
|
|
+ editJobUrl = String.format("/monitor/machine/jobs/edit/%s", id);
|
|
|
+ jobStatusApi = String.format("/api/monitor/machine/job/%s", id);
|
|
|
+ MachineMonitor machineMonitor = machineMonitorRepository.findById(id).orElse(null);
|
|
|
+ list = new ArrayList<>(machineMonitor.getJobMap().values());
|
|
|
+ break;
|
|
|
+ case app:
|
|
|
+ addJobUrl = String.format("/monitor/app/jobs/add/%s", id);
|
|
|
+ editJobUrl = String.format("/monitor/app/jobs/edit/%s", id);
|
|
|
+ jobStatusApi = String.format("/api/monitor/app/job/%s", id);
|
|
|
+ AppMonitor appMonitor = appMonitorRepository.findById(id).orElse(null);
|
|
|
+ list = new ArrayList<>(appMonitor.getJobMap().values());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ addJobUrl = null;
|
|
|
+ editJobUrl = null;
|
|
|
+ jobStatusApi = null;
|
|
|
+ list = Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ model.addAttribute("addJobUrl", addJobUrl);
|
|
|
+ model.addAttribute("editJobUrl", editJobUrl);
|
|
|
+ model.addAttribute("jobStatusApi", jobStatusApi);
|
|
|
model.addAttribute("list", list);
|
|
|
- return "/monitor/machinejobs";
|
|
|
+ return "/monitor/monitorjobs";
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "机器监控任务添加页面")
|
|
|
- @GetMapping("/machine/jobs/add/{id}")
|
|
|
- public String monitorJobAddPage(@PathVariable("id") MachineMonitor machineMonitor, Model model)
|
|
|
- throws IOException {
|
|
|
+ @ApiOperation(value = "监控任务添加页面")
|
|
|
+ @GetMapping("/{monitorType}/jobs/add/{id}")
|
|
|
+ public String monitorJobAddPage(@PathVariable("monitorType") String monitorType,
|
|
|
+ @PathVariable("id") Integer id,
|
|
|
+ Model model) throws IOException {
|
|
|
+
|
|
|
+ String addJobApi;
|
|
|
+ String jobPkg;
|
|
|
+ Set<String> exclude;
|
|
|
+ switch (MonitorType.valueOf(monitorType)) {
|
|
|
+ case machine:
|
|
|
+ MachineMonitor machineMonitor = machineMonitorRepository.findById(id).orElse(null);
|
|
|
+ exclude = machineMonitor.getJobMap().values().stream()
|
|
|
+ .map(MonitorJob::getJobClassName)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ addJobApi = String.format("/api/monitor/machine/job/%s", id);
|
|
|
+ jobPkg = "cn.reghao.autodop.dmaster.monitor.service.job.machine";
|
|
|
+ break;
|
|
|
+ case app:
|
|
|
+ AppMonitor appMonitor = appMonitorRepository.findById(id).orElse(null);
|
|
|
+ exclude = appMonitor.getJobMap().values().stream()
|
|
|
+ .map(MonitorJob::getJobClassName)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ addJobApi = String.format("/api/monitor/app/job/%s", id);
|
|
|
+ jobPkg = "cn.reghao.autodop.dmaster.monitor.service.job.app";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ addJobApi = null;
|
|
|
+ jobPkg = null;
|
|
|
+ exclude = Collections.emptySet();
|
|
|
+ }
|
|
|
|
|
|
- setJobNames(model);
|
|
|
- model.addAttribute("machineMonitorId", machineMonitor.getId());
|
|
|
- return "/monitor/machinejob";
|
|
|
+ model.addAttribute("addJobApi", addJobApi);
|
|
|
+ setJobNames(model, jobPkg, exclude);
|
|
|
+ return "/monitor/monitorjob";
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "机器监控任务编辑页面")
|
|
|
- @GetMapping("/machine/jobs/edit/{id}")
|
|
|
- public String monitorJobEditPage(@PathVariable("id") MonitorJob monitorJob, Model model) throws IOException {
|
|
|
- setJobNames(model);
|
|
|
+ @ApiOperation(value = "监控任务编辑页面")
|
|
|
+ @GetMapping("/{monitorType}/jobs/edit/{id}/{jobId}")
|
|
|
+ public String monitorJobEditPage(@PathVariable("monitorType") String monitorType,
|
|
|
+ @PathVariable("id") Integer id,
|
|
|
+ @PathVariable("jobId") String jobId,
|
|
|
+ Model model) {
|
|
|
+
|
|
|
+ String addJobApi;
|
|
|
+ List<KeyValue> jobNames;
|
|
|
+ MonitorJob monitorJob;
|
|
|
+ switch (MonitorType.valueOf(monitorType)) {
|
|
|
+ case machine:
|
|
|
+ addJobApi = String.format("/api/monitor/machine/job/%s", id);
|
|
|
+ MachineMonitor machineMonitor = machineMonitorRepository.findById(id).orElse(null);
|
|
|
+ monitorJob = machineMonitor.getJobMap().get(jobId);
|
|
|
+ jobNames = new ArrayList<>();
|
|
|
+ jobNames.add(new KeyValue(monitorJob.getJobClassName(), monitorJob.getJobClassName()));
|
|
|
+ break;
|
|
|
+ case app:
|
|
|
+ addJobApi = String.format("/api/monitor/app/job/%s", id);
|
|
|
+ AppMonitor appMonitor = appMonitorRepository.findById(id).orElse(null);
|
|
|
+ monitorJob = appMonitor.getJobMap().get(jobId);
|
|
|
+ jobNames = new ArrayList<>();
|
|
|
+ jobNames.add(new KeyValue(monitorJob.getJobClassName(), monitorJob.getJobClassName()));
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ addJobApi = null;
|
|
|
+ jobNames = Collections.emptyList();
|
|
|
+ monitorJob = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ model.addAttribute("addJobApi", addJobApi);
|
|
|
+ model.addAttribute("jobNames", jobNames);
|
|
|
model.addAttribute("monitorJob", monitorJob);
|
|
|
- return "/monitor/machinejob";
|
|
|
+ return "/monitor/monitorjob";
|
|
|
}
|
|
|
|
|
|
- private void setJobNames(Model model) throws IOException {
|
|
|
+ private void setJobNames(Model model, String jobPkg, Set<String> exclude) throws IOException {
|
|
|
PackageScanner packageScanner = new PackageScanner();
|
|
|
- String pkg = "cn.reghao.autodop.dmaster.monitor.service.job.machine";
|
|
|
- List<Class<?>> classList = packageScanner.doScan(DmasterApplication.class, pkg);
|
|
|
+ List<Class<?>> classList = packageScanner.doScan(DmasterApplication.class, jobPkg);
|
|
|
|
|
|
List<KeyValue> jobNames = new ArrayList<>();
|
|
|
jobNames.add(new KeyValue("请选择任务", ""));
|
|
|
for (Class<?> clazz : classList) {
|
|
|
- jobNames.add(new KeyValue(clazz.getSimpleName(), clazz.getSimpleName()));
|
|
|
+ String simpleName = clazz.getSimpleName();
|
|
|
+ if (!exclude.contains(simpleName)) {
|
|
|
+ jobNames.add(new KeyValue(simpleName, simpleName));
|
|
|
+ }
|
|
|
}
|
|
|
model.addAttribute("jobNames", jobNames);
|
|
|
}
|
|
|
-
|
|
|
- @ApiOperation(value = "机器监控通知页面")
|
|
|
- @GetMapping("/machine/notify/{id}")
|
|
|
- public String monitorNotifyPage(@PathVariable("id") MachineMonitor machineMonitor, Model model) {
|
|
|
- Set<NotifyGroup> currentSet = new HashSet<>(machineMonitor.getNotifyGroups());
|
|
|
- List<NotifyGroup> list = receiverRepository.findAll();
|
|
|
-
|
|
|
- model.addAttribute("id", machineMonitor.getId());
|
|
|
- model.addAttribute("currentSet", currentSet);
|
|
|
- model.addAttribute("list", list);
|
|
|
- return "/monitor/machinenotify";
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "应用监控页面")
|
|
|
- @GetMapping("/app")
|
|
|
- public String appMonitorPage(Model model) {
|
|
|
- PageRequest pageRequest = PageSort.pageRequest();
|
|
|
- Page<AppMonitor> page = appMonitorRepository.findAll(pageRequest);
|
|
|
- PageList<AppMonitor> pageList = PageList.pageList(page);
|
|
|
-
|
|
|
- model.addAttribute("page", page);
|
|
|
- model.addAttribute("list", pageList.getList());
|
|
|
- return "/monitor/app";
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "应用监控任务页面")
|
|
|
- @GetMapping("/app/job/{id}")
|
|
|
- public String appJobPage(@PathVariable("id") AppMonitor appMonitor, Model model) {
|
|
|
- model.addAttribute("id", appMonitor.getId());
|
|
|
- model.addAttribute("jobId", "appMonitor.getJobId()");
|
|
|
- model.addAttribute("cronExp", "appMonitor.getCronExp()");
|
|
|
- return "/monitor/appjob";
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "应用监控通知页面")
|
|
|
- @GetMapping("/app/notify/{id}")
|
|
|
- public String appNotifyPage(@PathVariable("id") AppMonitor appMonitor, Model model) {
|
|
|
- Set<NotifyGroup> currentSet = new HashSet<>(appMonitor.getNotifyGroups());
|
|
|
- List<NotifyGroup> list = receiverRepository.findAll();
|
|
|
-
|
|
|
- model.addAttribute("id", appMonitor.getId());
|
|
|
- model.addAttribute("currentSet", currentSet);
|
|
|
- model.addAttribute("list", list);
|
|
|
- return "/monitor/appnotify";
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "第三方应用监控页面")
|
|
|
- @GetMapping("/app3")
|
|
|
- public String app3MonitorPage(Model model) {
|
|
|
- return "/monitor/app3";
|
|
|
- }
|
|
|
}
|