|
|
@@ -4,8 +4,10 @@ import cn.reghao.autodop.common.http.DefaultWebRequest;
|
|
|
import cn.reghao.autodop.common.http.WebRequest;
|
|
|
import cn.reghao.autodop.dmaster.machine.db.crud.MachineStatusCrudService;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.AppRunningRepository;
|
|
|
-import cn.reghao.autodop.dmaster.monitor.service.job.AppHealthCheckJob;
|
|
|
-import cn.reghao.autodop.dmaster.monitor.service.job.MachineStatusMonitorJob;
|
|
|
+import cn.reghao.autodop.dmaster.monitor.entity.MachineMonitor;
|
|
|
+import cn.reghao.autodop.dmaster.monitor.repository.MachineMonitorRepository;
|
|
|
+import cn.reghao.autodop.dmaster.monitor.service.job.MachineHeartbeatMonitorJob;
|
|
|
+import cn.reghao.autodop.dmaster.notification.entity.NotifyGroup;
|
|
|
import cn.reghao.autodop.dmaster.notification.service.NotifyService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.quartz.*;
|
|
|
@@ -13,6 +15,7 @@ import org.quartz.impl.StdSchedulerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 监控使用的定时任务调度器
|
|
|
@@ -28,46 +31,54 @@ public class MonitorScheduler {
|
|
|
private AppRunningRepository runningRepository;
|
|
|
private MachineStatusCrudService statusCrudService;
|
|
|
private WebRequest webRequest;
|
|
|
+ private MachineMonitorRepository machineMonitorRepository;
|
|
|
|
|
|
- public MonitorScheduler(NotifyService notifyService, AppRunningRepository runningRepository,
|
|
|
- MachineStatusCrudService statusCrudService) throws SchedulerException {
|
|
|
+ public MonitorScheduler(NotifyService notifyService,
|
|
|
+ AppRunningRepository runningRepository,
|
|
|
+ MachineStatusCrudService statusCrudService,
|
|
|
+ MachineMonitorRepository machineMonitorRepository) throws SchedulerException {
|
|
|
this.scheduler = StdSchedulerFactory.getDefaultScheduler();
|
|
|
this.notifyService = notifyService;
|
|
|
this.runningRepository = runningRepository;
|
|
|
this.statusCrudService = statusCrudService;
|
|
|
this.webRequest = new DefaultWebRequest();
|
|
|
+ this.machineMonitorRepository = machineMonitorRepository;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ * @date 2021-06-24 上午10:22
|
|
|
+ */
|
|
|
@PostConstruct
|
|
|
public void startScheduler() throws SchedulerException {
|
|
|
- scheduler.start();
|
|
|
+ for (MachineMonitor machineMonitor : machineMonitorRepository.findAll()) {
|
|
|
+ addMachineStatusMonitorJob(machineMonitor);
|
|
|
+ }
|
|
|
+ // TODO 系统启动时启用所有存在的任务
|
|
|
+ //scheduler.start();
|
|
|
}
|
|
|
|
|
|
- public void pause() throws SchedulerException {
|
|
|
+ public void pauseScheduler() throws SchedulerException {
|
|
|
if (!scheduler.isShutdown()) {
|
|
|
scheduler.pauseAll();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void addAppHealthCheckJob(String jobId, String cronExp) throws SchedulerException {
|
|
|
- JobDataMap jobDataMap = new JobDataMap();
|
|
|
- jobDataMap.put("notifyService", notifyService);
|
|
|
- jobDataMap.put("appId", "");
|
|
|
- jobDataMap.put("machineId", "");
|
|
|
- jobDataMap.put("webRequest", webRequest);
|
|
|
- jobDataMap.put("runningRepository", runningRepository);
|
|
|
- add(AppHealthCheckJob.class, jobId, cronExp, jobDataMap);
|
|
|
- }
|
|
|
+ public void addMachineStatusMonitorJob(MachineMonitor machineMonitor) throws SchedulerException {
|
|
|
+ String jobId = machineMonitor.getJobId();
|
|
|
+ String cronExp = machineMonitor.getCronExp();
|
|
|
+ List<NotifyGroup> notifyGroups = machineMonitor.getNotifyGroups();
|
|
|
|
|
|
- public void addMachineStatusMonitorJob(String jobId, String cronExp) throws SchedulerException {
|
|
|
JobDataMap jobDataMap = new JobDataMap();
|
|
|
jobDataMap.put("notifyService", notifyService);
|
|
|
- jobDataMap.put("machineId", "");
|
|
|
+ jobDataMap.put("notifyGroups", notifyGroups);
|
|
|
+ jobDataMap.put("machineId", machineMonitor.getMachineId());
|
|
|
jobDataMap.put("statusCrudService", statusCrudService);
|
|
|
- add(MachineStatusMonitorJob.class, jobId, cronExp, jobDataMap);
|
|
|
+ addAndStart(MachineHeartbeatMonitorJob.class, jobId, cronExp, jobDataMap);
|
|
|
}
|
|
|
|
|
|
- private void add(Class<? extends Job> clazz, String jobId, String cronExp, JobDataMap jobDataMap)
|
|
|
+ private void addAndStart(Class<? extends Job> clazz, String jobId, String cronExp, JobDataMap jobDataMap)
|
|
|
throws SchedulerException {
|
|
|
JobDetail jobDetail = JobBuilder.newJob(clazz)
|
|
|
.withIdentity(jobId)
|
|
|
@@ -86,6 +97,14 @@ public class MonitorScheduler {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void remove() {
|
|
|
+ public void pause(String jobId) throws SchedulerException {
|
|
|
+ scheduler.pauseJob(JobKey.jobKey(jobId));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void resume(String jobId) throws SchedulerException {
|
|
|
+ scheduler.resumeJob(JobKey.jobKey(jobId));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void remove(String jobId) {
|
|
|
}
|
|
|
}
|