|
@@ -1,6 +1,8 @@
|
|
|
package cn.reghao.autodop.dmaster.monitor.controller;
|
|
package cn.reghao.autodop.dmaster.monitor.controller;
|
|
|
|
|
|
|
|
|
|
+import cn.reghao.autodop.dmaster.monitor.entity.AppMonitor;
|
|
|
import cn.reghao.autodop.dmaster.monitor.entity.MachineMonitor;
|
|
import cn.reghao.autodop.dmaster.monitor.entity.MachineMonitor;
|
|
|
|
|
+import cn.reghao.autodop.dmaster.monitor.entity.MonitorJob;
|
|
|
import cn.reghao.autodop.dmaster.monitor.repository.AppMonitorRepository;
|
|
import cn.reghao.autodop.dmaster.monitor.repository.AppMonitorRepository;
|
|
|
import cn.reghao.autodop.dmaster.monitor.repository.MachineMonitorRepository;
|
|
import cn.reghao.autodop.dmaster.monitor.repository.MachineMonitorRepository;
|
|
|
import cn.reghao.autodop.dmaster.monitor.service.MonitorScheduler;
|
|
import cn.reghao.autodop.dmaster.monitor.service.MonitorScheduler;
|
|
@@ -14,6 +16,7 @@ import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
+import javax.validation.Valid;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -39,30 +42,26 @@ public class MonitorController {
|
|
|
|
|
|
|
|
@ApiOperation(value = "设置机器状态监控任务")
|
|
@ApiOperation(value = "设置机器状态监控任务")
|
|
|
@PostMapping(value = "/machine/job/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
@PostMapping(value = "/machine/job/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
- public ResponseEntity<String> machineStatusMonitor(@PathVariable("id") MachineMonitor machineMonitor,
|
|
|
|
|
- @RequestParam("cronExp") String cronExp) throws SchedulerException {
|
|
|
|
|
- String jobId = machineMonitor.getJobId();
|
|
|
|
|
- if (jobId == null) {
|
|
|
|
|
- jobId = machineMonitor.getMachineId() + "-heartbeat";
|
|
|
|
|
- machineMonitor.setJobId(jobId);
|
|
|
|
|
- }
|
|
|
|
|
- // TODO 验证 cronExp 是否有效
|
|
|
|
|
- machineMonitor.setCronExp(cronExp);
|
|
|
|
|
- machineMonitor.setEnable(true);
|
|
|
|
|
|
|
+ public ResponseEntity<String> machineMonitorJob(@PathVariable("id") MachineMonitor machineMonitor,
|
|
|
|
|
+ @Valid MonitorJob monitorJob) throws SchedulerException {
|
|
|
|
|
+ String jobId = machineMonitor.getMachineId() + "-heartbeat";
|
|
|
|
|
+ monitorJob.setJobId(jobId);
|
|
|
|
|
+ monitorJob.setEnable(true);
|
|
|
|
|
|
|
|
|
|
+ List<MonitorJob> monitorJobs = machineMonitor.getMonitorJobs();
|
|
|
|
|
+ monitorJobs.add(monitorJob);
|
|
|
// 这两个操作应该在一个事务中
|
|
// 这两个操作应该在一个事务中
|
|
|
- monitorScheduler.addMachineStatusMonitorJob(machineMonitor);
|
|
|
|
|
|
|
+ //monitorScheduler.addMachineHeartbeatCheckJob(machineMonitor);
|
|
|
machineMonitorRepository.save(machineMonitor);
|
|
machineMonitorRepository.save(machineMonitor);
|
|
|
-
|
|
|
|
|
return ResponseEntity.ok().body(WebBody.success());
|
|
return ResponseEntity.ok().body(WebBody.success());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @ApiOperation(value = "是否开始监控")
|
|
|
|
|
|
|
+ @ApiOperation(value = "是否开始监控机器状态")
|
|
|
@PostMapping(value = "/machine/{status}/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
@PostMapping(value = "/machine/{status}/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
- public ResponseEntity<String> disableMachineMonitor(@PathVariable("status") String status,
|
|
|
|
|
|
|
+ public ResponseEntity<String> machineMonitorStatus(@PathVariable("status") String status,
|
|
|
@PathVariable("id") MachineMonitor machineMonitor)
|
|
@PathVariable("id") MachineMonitor machineMonitor)
|
|
|
throws SchedulerException {
|
|
throws SchedulerException {
|
|
|
- Boolean enable = machineMonitor.getEnable();
|
|
|
|
|
|
|
+ /*Boolean enable = machineMonitor.getEnable();
|
|
|
if ("enable".equals(status)) {
|
|
if ("enable".equals(status)) {
|
|
|
if (enable) {
|
|
if (enable) {
|
|
|
return ResponseEntity.ok().body(WebBody.successMsg("当前正在监控中"));
|
|
return ResponseEntity.ok().body(WebBody.successMsg("当前正在监控中"));
|
|
@@ -90,7 +89,9 @@ public class MonitorController {
|
|
|
machineMonitorRepository.save(machineMonitor);
|
|
machineMonitorRepository.save(machineMonitor);
|
|
|
|
|
|
|
|
return ResponseEntity.ok().body(WebBody.successMsg("监控已停止"));
|
|
return ResponseEntity.ok().body(WebBody.successMsg("监控已停止"));
|
|
|
- }
|
|
|
|
|
|
|
+ }*/
|
|
|
|
|
+
|
|
|
|
|
+ return ResponseEntity.ok().body(WebBody.successMsg("监控已停止"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation(value = "设置机器状态监控通知")
|
|
@ApiOperation(value = "设置机器状态监控通知")
|
|
@@ -101,4 +102,71 @@ public class MonitorController {
|
|
|
machineMonitorRepository.save(machineMonitor);
|
|
machineMonitorRepository.save(machineMonitor);
|
|
|
return ResponseEntity.ok().body(WebBody.success());
|
|
return ResponseEntity.ok().body(WebBody.success());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation(value = "设置应用健康检查监控任务")
|
|
|
|
|
+ @PostMapping(value = "/app/job/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
|
+ public ResponseEntity<String> appMonitorJob(@PathVariable("id") AppMonitor appMonitor,
|
|
|
|
|
+ @RequestParam("cronExp") String cronExp) throws SchedulerException {
|
|
|
|
|
+ /*String jobId = appMonitor.getJobId();
|
|
|
|
|
+ if (jobId == null) {
|
|
|
|
|
+ jobId = String.format("%s-%s-healthcheck", appMonitor.getAppId(), appMonitor.getMachineId());
|
|
|
|
|
+ appMonitor.setJobId(jobId);
|
|
|
|
|
+ }
|
|
|
|
|
+ // TODO 验证 cronExp 是否有效
|
|
|
|
|
+ appMonitor.setCronExp(cronExp);
|
|
|
|
|
+ appMonitor.setEnable(true);
|
|
|
|
|
+
|
|
|
|
|
+ // TODO 这两个操作应该在一个事务中
|
|
|
|
|
+ monitorScheduler.addAppHealthCheckJob(appMonitor);
|
|
|
|
|
+ appMonitorRepository.save(appMonitor);*/
|
|
|
|
|
+
|
|
|
|
|
+ return ResponseEntity.ok().body(WebBody.success());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation(value = "是否开始应用健康检查监控")
|
|
|
|
|
+ @PostMapping(value = "/app/{status}/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
|
+ public ResponseEntity<String> appMonitorStatus(@PathVariable("status") String status,
|
|
|
|
|
+ @PathVariable("id") AppMonitor appMonitor)
|
|
|
|
|
+ throws SchedulerException {
|
|
|
|
|
+ /*Boolean enable = appMonitor.getEnable();
|
|
|
|
|
+ if ("enable".equals(status)) {
|
|
|
|
|
+ if (enable) {
|
|
|
|
|
+ return ResponseEntity.ok().body(WebBody.successMsg("当前正在监控中"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String jobId = appMonitor.getJobId();
|
|
|
|
|
+ if (jobId == null) {
|
|
|
|
|
+ return ResponseEntity.ok().body(WebBody.failWithMsg("请先设置监控任务"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // TODO 应该在一个事务中
|
|
|
|
|
+ appMonitor.setEnable(true);
|
|
|
|
|
+ monitorScheduler.resume(appMonitor.getJobId());
|
|
|
|
|
+ appMonitorRepository.save(appMonitor);
|
|
|
|
|
+
|
|
|
|
|
+ return ResponseEntity.ok().body(WebBody.successMsg("监控已开启"));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (!enable) {
|
|
|
|
|
+ return ResponseEntity.ok().body(WebBody.successMsg("当前没有监控"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // TODO 应该在一个事务中
|
|
|
|
|
+ appMonitor.setEnable(false);
|
|
|
|
|
+ monitorScheduler.pause(appMonitor.getJobId());
|
|
|
|
|
+ appMonitorRepository.save(appMonitor);
|
|
|
|
|
+
|
|
|
|
|
+ return ResponseEntity.ok().body(WebBody.successMsg("监控已停止"));
|
|
|
|
|
+ }*/
|
|
|
|
|
+
|
|
|
|
|
+ return ResponseEntity.ok().body(WebBody.successMsg("监控已停止"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation(value = "设置机器状态监控通知")
|
|
|
|
|
+ @PostMapping(value = "/app/notify", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
|
+ public ResponseEntity<String> appMonitorNotify(@RequestParam("id") AppMonitor appMonitor,
|
|
|
|
|
+ @RequestParam("groupId") List<NotifyGroup> notifyGroups) {
|
|
|
|
|
+ appMonitor.setNotifyGroups(notifyGroups);
|
|
|
|
|
+ appMonitorRepository.save(appMonitor);
|
|
|
|
|
+ return ResponseEntity.ok().body(WebBody.success());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|