|
|
@@ -1,27 +1,22 @@
|
|
|
package cn.reghao.autodop.dmaster.monitor.controller;
|
|
|
|
|
|
-import cn.reghao.autodop.common.result.Result;
|
|
|
-import cn.reghao.autodop.common.result.ResultStatus;
|
|
|
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.monitor.service.MonitorScheduler;
|
|
|
import cn.reghao.autodop.dmaster.monitor.service.MonitorService;
|
|
|
import cn.reghao.autodop.dmaster.notification.entity.NotifyGroup;
|
|
|
import cn.reghao.autodop.dmaster.utils.WebBody;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.quartz.SchedulerException;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
-import java.io.IOException;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -35,63 +30,74 @@ import java.util.List;
|
|
|
public class MonitorController {
|
|
|
private MonitorService<MachineMonitor> machineMonitorService;
|
|
|
private MonitorService<AppMonitor> appMonitorService;
|
|
|
-
|
|
|
- private MonitorScheduler monitorScheduler;
|
|
|
private MachineMonitorRepository machineMonitorRepository;
|
|
|
private AppMonitorRepository appMonitorRepository;
|
|
|
|
|
|
public MonitorController(MonitorService<MachineMonitor> machineMonitorService,
|
|
|
MonitorService<AppMonitor> appMonitorService,
|
|
|
- MonitorScheduler monitorScheduler,
|
|
|
MachineMonitorRepository machineMonitorRepository,
|
|
|
AppMonitorRepository appMonitorRepository) {
|
|
|
this.machineMonitorService = machineMonitorService;
|
|
|
this.appMonitorService = appMonitorService;
|
|
|
- this.monitorScheduler = monitorScheduler;
|
|
|
this.machineMonitorRepository = machineMonitorRepository;
|
|
|
this.appMonitorRepository = appMonitorRepository;
|
|
|
}
|
|
|
|
|
|
- // TODO 任务启用或禁用时设置都立即生效
|
|
|
@ApiOperation(value = "设置机器监控通知")
|
|
|
@PostMapping(value = "/{monitorType}/notify/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
@ResponseBody
|
|
|
public ResponseEntity<String> machineMonitorNotify(@PathVariable("monitorType") String monitorType,
|
|
|
@PathVariable("id") Integer id,
|
|
|
@RequestParam("groupId") List<NotifyGroup> notifyGroups) {
|
|
|
-
|
|
|
switch (MonitorType.valueOf(monitorType)) {
|
|
|
case machine:
|
|
|
MachineMonitor machineMonitor = machineMonitorRepository.findById(id).orElse(null);
|
|
|
- notifyGroups.forEach(notifyGroup ->
|
|
|
- machineMonitorService.setMonitorNotify(machineMonitor, notifyGroup));
|
|
|
+ notifyGroups.forEach(notifyGroup -> machineMonitorService.setNotify(machineMonitor, notifyGroup));
|
|
|
break;
|
|
|
case app:
|
|
|
AppMonitor appMonitor = appMonitorRepository.findById(id).orElse(null);
|
|
|
- notifyGroups.forEach(notifyGroup -> appMonitorService.setMonitorNotify(appMonitor, notifyGroup));
|
|
|
+ notifyGroups.forEach(notifyGroup -> appMonitorService.setNotify(appMonitor, notifyGroup));
|
|
|
break;
|
|
|
default:
|
|
|
}
|
|
|
return ResponseEntity.ok().body(WebBody.success());
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "设置机器监控任务")
|
|
|
+ @ApiOperation(value = "添加/编辑机器监控任务")
|
|
|
@PostMapping(value = "/{monitorType}/job/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
public ResponseEntity<String> machineMonitorJob(@PathVariable("monitorType") String monitorType,
|
|
|
@PathVariable("id") Integer id,
|
|
|
- @Valid MonitorJob monitorJob) throws SchedulerException, IOException {
|
|
|
+ @Valid MonitorJob monitorJob) {
|
|
|
switch (MonitorType.valueOf(monitorType)) {
|
|
|
case machine:
|
|
|
MachineMonitor machineMonitor = machineMonitorRepository.findById(id).orElse(null);
|
|
|
- machineMonitorService.addMonitorJob(machineMonitor, monitorJob);
|
|
|
+ machineMonitorService.addJob(machineMonitor, monitorJob);
|
|
|
break;
|
|
|
case app:
|
|
|
AppMonitor appMonitor = appMonitorRepository.findById(id).orElse(null);
|
|
|
- appMonitorService.addMonitorJob(appMonitor, monitorJob);
|
|
|
+ appMonitorService.addJob(appMonitor, monitorJob);
|
|
|
break;
|
|
|
default:
|
|
|
}
|
|
|
+ return ResponseEntity.ok().body(WebBody.success());
|
|
|
+ }
|
|
|
|
|
|
+ @ApiOperation(value = "删除机器监控任务")
|
|
|
+ @DeleteMapping(value = "/{monitorType}/job/{id}/{jobId}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public ResponseEntity<String> deleteMachineMonitorJob(@PathVariable("monitorType") String monitorType,
|
|
|
+ @PathVariable("id") Integer id,
|
|
|
+ @PathVariable("jobId") String jobId) {
|
|
|
+ switch (MonitorType.valueOf(monitorType)) {
|
|
|
+ case machine:
|
|
|
+ MachineMonitor machineMonitor = machineMonitorRepository.findById(id).orElse(null);
|
|
|
+ machineMonitorService.deleteJob(machineMonitor, jobId);
|
|
|
+ break;
|
|
|
+ case app:
|
|
|
+ AppMonitor appMonitor = appMonitorRepository.findById(id).orElse(null);
|
|
|
+ appMonitorService.deleteJob(appMonitor, jobId);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ }
|
|
|
return ResponseEntity.ok().body(WebBody.success());
|
|
|
}
|
|
|
|
|
|
@@ -100,22 +106,26 @@ public class MonitorController {
|
|
|
public ResponseEntity<String> machineJobStatus(@PathVariable("monitorType") String monitorType,
|
|
|
@PathVariable("id") Integer id,
|
|
|
@PathVariable("jobId") String jobId,
|
|
|
- @PathVariable("enable") Boolean enable) throws SchedulerException {
|
|
|
- Result result;
|
|
|
+ @PathVariable("enable") Boolean enable) {
|
|
|
switch (MonitorType.valueOf(monitorType)) {
|
|
|
case machine:
|
|
|
MachineMonitor machineMonitor = machineMonitorRepository.findById(id).orElse(null);
|
|
|
- machineMonitorService.startOrPause(machineMonitor, jobId, enable);
|
|
|
+ if (enable) {
|
|
|
+ machineMonitorService.startJob(machineMonitor, jobId);
|
|
|
+ } else {
|
|
|
+ machineMonitorService.pauseJob(machineMonitor, jobId);
|
|
|
+ }
|
|
|
break;
|
|
|
case app:
|
|
|
AppMonitor appMonitor = appMonitorRepository.findById(id).orElse(null);
|
|
|
- appMonitorService.startOrPause(appMonitor, jobId, enable);
|
|
|
- appMonitorRepository.save(appMonitor);
|
|
|
+ if (enable) {
|
|
|
+ appMonitorService.startJob(appMonitor, jobId);
|
|
|
+ } else {
|
|
|
+ appMonitorService.pauseJob(appMonitor, jobId);
|
|
|
+ }
|
|
|
break;
|
|
|
default:
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
return ResponseEntity.ok().body(WebBody.success());
|
|
|
}
|
|
|
}
|