|
|
@@ -3,7 +3,7 @@ package cn.reghao.autodop.dmaster.monitor.service;
|
|
|
import cn.reghao.autodop.common.http.DefaultWebRequest;
|
|
|
import cn.reghao.autodop.common.http.WebRequest;
|
|
|
import cn.reghao.autodop.dmaster.DmasterApplication;
|
|
|
-import cn.reghao.autodop.dmaster.machine.db.crud.MachineStatusCrudService;
|
|
|
+import cn.reghao.autodop.dmaster.machine.db.crud.MachineStatCrudService;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.AppRunningRepository;
|
|
|
import cn.reghao.autodop.dmaster.monitor.entity.AppMonitor;
|
|
|
import cn.reghao.autodop.dmaster.monitor.entity.MachineMonitor;
|
|
|
@@ -34,15 +34,15 @@ public class MonitorScheduler {
|
|
|
private Scheduler scheduler;
|
|
|
private NotifyService notifyService;
|
|
|
private AppRunningRepository runningRepository;
|
|
|
- private MachineStatusCrudService statusCrudService;
|
|
|
+ private MachineStatCrudService statusCrudService;
|
|
|
private WebRequest webRequest;
|
|
|
private MachineMonitorRepository machineMonitorRepository;
|
|
|
private AppMonitorRepository appMonitorRepository;
|
|
|
- private PackageScanner packageScanner = new PackageScanner();
|
|
|
+ private PackageScanner packageScanner;
|
|
|
|
|
|
public MonitorScheduler(NotifyService notifyService,
|
|
|
AppRunningRepository runningRepository,
|
|
|
- MachineStatusCrudService statusCrudService,
|
|
|
+ MachineStatCrudService statusCrudService,
|
|
|
MachineMonitorRepository machineMonitorRepository,
|
|
|
AppMonitorRepository appMonitorRepository) throws SchedulerException {
|
|
|
this.scheduler = StdSchedulerFactory.getDefaultScheduler();
|
|
|
@@ -52,9 +52,12 @@ public class MonitorScheduler {
|
|
|
this.webRequest = new DefaultWebRequest();
|
|
|
this.machineMonitorRepository = machineMonitorRepository;
|
|
|
this.appMonitorRepository = appMonitorRepository;
|
|
|
+ this.packageScanner = new PackageScanner();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * TODO 系统启动时启用所有存在的任务
|
|
|
+ *
|
|
|
* @param
|
|
|
* @return
|
|
|
* @date 2021-06-24 上午10:22
|
|
|
@@ -78,14 +81,12 @@ public class MonitorScheduler {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // TODO 系统启动时启用所有存在的任务
|
|
|
scheduler.start();
|
|
|
}
|
|
|
|
|
|
- public void pauseScheduler() throws SchedulerException {
|
|
|
- if (!scheduler.isShutdown()) {
|
|
|
- scheduler.pauseAll();
|
|
|
- }
|
|
|
+ public void updateNotifyGroup(String jobId, List<NotifyGroup> notifyGroups) throws SchedulerException {
|
|
|
+ JobDetail jobDetail = scheduler.getJobDetail(JobKey.jobKey(jobId));
|
|
|
+ JobDataMap jobDataMap = jobDetail.getJobDataMap();
|
|
|
}
|
|
|
|
|
|
public void addMachineMonitorJob(MachineMonitor machineMonitor, String jobId)
|
|
|
@@ -100,7 +101,7 @@ public class MonitorScheduler {
|
|
|
jobDataMap.put("notifyGroups", notifyGroups);
|
|
|
jobDataMap.put("machineId", machineMonitor.getMachineId());
|
|
|
jobDataMap.put("statusCrudService", statusCrudService);
|
|
|
- addAndStart(jobClass, jobId, cronExp, jobDataMap);
|
|
|
+ addJob(jobId, cronExp, jobClass, jobDataMap);
|
|
|
}
|
|
|
|
|
|
private void addMachineMonitorJob(MachineMonitor machineMonitor, MonitorJob monitorJob)
|
|
|
@@ -114,41 +115,24 @@ public class MonitorScheduler {
|
|
|
jobDataMap.put("notifyGroups", notifyGroups);
|
|
|
jobDataMap.put("machineId", machineMonitor.getMachineId());
|
|
|
jobDataMap.put("statusCrudService", statusCrudService);
|
|
|
- addAndStart(jobClass, monitorJob.getJobId(), cronExp, jobDataMap);
|
|
|
- }
|
|
|
-
|
|
|
- public void addAppMonitorJob(AppMonitor appMonitor, String jobId) throws SchedulerException, IOException {
|
|
|
- MonitorJob monitorJob = appMonitor.getJobMap().get(jobId);
|
|
|
- List<NotifyGroup> notifyGroups = appMonitor.getNotifyGroups();
|
|
|
- String cronExp = monitorJob.getCronExp();
|
|
|
- Class jobClass = findClassBySimpleName(monitorJob.getJobClassName());
|
|
|
-
|
|
|
- JobDataMap jobDataMap = new JobDataMap();
|
|
|
- jobDataMap.put("notifyService", notifyService);
|
|
|
- jobDataMap.put("notifyGroups", notifyGroups);
|
|
|
- jobDataMap.put("webRequest", webRequest);
|
|
|
- jobDataMap.put("appId", appMonitor.getAppId());
|
|
|
- jobDataMap.put("machineId", appMonitor.getMachineId());
|
|
|
- jobDataMap.put("runningRepository", runningRepository);
|
|
|
- addAndStart(jobClass, jobId, cronExp, jobDataMap);
|
|
|
+ addJob(monitorJob.getJobId(), cronExp, jobClass, jobDataMap);
|
|
|
}
|
|
|
|
|
|
private void addAppMonitorJob(AppMonitor appMonitor, MonitorJob monitorJob) throws SchedulerException, IOException {
|
|
|
- List<NotifyGroup> notifyGroups = appMonitor.getNotifyGroups();
|
|
|
String cronExp = monitorJob.getCronExp();
|
|
|
Class jobClass = findClassBySimpleName(monitorJob.getJobClassName());
|
|
|
|
|
|
JobDataMap jobDataMap = new JobDataMap();
|
|
|
jobDataMap.put("notifyService", notifyService);
|
|
|
- jobDataMap.put("notifyGroups", notifyGroups);
|
|
|
+ jobDataMap.put("notifyGroups", appMonitor.getNotifyGroups());
|
|
|
jobDataMap.put("webRequest", webRequest);
|
|
|
jobDataMap.put("appId", appMonitor.getAppId());
|
|
|
jobDataMap.put("machineId", appMonitor.getMachineId());
|
|
|
jobDataMap.put("runningRepository", runningRepository);
|
|
|
- addAndStart(jobClass, monitorJob.getJobId(), cronExp, jobDataMap);
|
|
|
+ addJob(monitorJob.getJobId(), cronExp, jobClass, jobDataMap);
|
|
|
}
|
|
|
|
|
|
- private void addAndStart(Class<? extends Job> clazz, String jobId, String cronExp, JobDataMap jobDataMap)
|
|
|
+ private void addJob(String jobId, String cronExp, Class<? extends Job> clazz, JobDataMap jobDataMap)
|
|
|
throws SchedulerException {
|
|
|
JobDetail jobDetail = JobBuilder.newJob(clazz)
|
|
|
.withIdentity(jobId)
|
|
|
@@ -168,39 +152,28 @@ public class MonitorScheduler {
|
|
|
}
|
|
|
|
|
|
public void modifyJob(String jobId, String cronExp) throws SchedulerException {
|
|
|
- Trigger trigger = scheduler.getTrigger(TriggerKey.triggerKey(jobId));
|
|
|
- JobDetail jobDetail = scheduler.getJobDetail(JobKey.jobKey(jobId));
|
|
|
- JobDataMap jobDataMap = jobDetail.getJobDataMap();
|
|
|
-
|
|
|
+ TriggerKey triggerKey = TriggerKey.triggerKey(jobId);
|
|
|
CronTrigger cronTrigger = TriggerBuilder.newTrigger()
|
|
|
.withIdentity(jobId)
|
|
|
.withSchedule(CronScheduleBuilder.cronSchedule(cronExp))
|
|
|
.build();
|
|
|
-
|
|
|
- //scheduler.rescheduleJob()
|
|
|
- }
|
|
|
-
|
|
|
- public void updateNotifyGroup(String jobId, List<NotifyGroup> notifyGroups) {
|
|
|
-
|
|
|
+ scheduler.rescheduleJob(triggerKey, cronTrigger);
|
|
|
}
|
|
|
|
|
|
- public void delete(String jobId) throws SchedulerException {
|
|
|
+ public void deleteJob(String jobId) throws SchedulerException {
|
|
|
scheduler.deleteJob(JobKey.jobKey(jobId));
|
|
|
}
|
|
|
|
|
|
- public void pause(String jobId) throws SchedulerException {
|
|
|
+ public void pauseJob(String jobId) throws SchedulerException {
|
|
|
scheduler.pauseJob(JobKey.jobKey(jobId));
|
|
|
}
|
|
|
|
|
|
- public boolean isJobExist(String jobId) throws SchedulerException {
|
|
|
- return scheduler.checkExists(JobKey.jobKey(jobId));
|
|
|
- }
|
|
|
-
|
|
|
- public void resume(String jobId) throws SchedulerException {
|
|
|
+ public void resumeJob(String jobId) throws SchedulerException {
|
|
|
scheduler.resumeJob(JobKey.jobKey(jobId));
|
|
|
}
|
|
|
|
|
|
- public void remove(String jobId) {
|
|
|
+ public boolean isJobExist(String jobId) throws SchedulerException {
|
|
|
+ return scheduler.checkExists(JobKey.jobKey(jobId));
|
|
|
}
|
|
|
|
|
|
private Class findClassBySimpleName(String simpleName) throws IOException {
|