This commit is contained in:
Administrator
2017-07-29 10:18:36 +08:00
committed by wangkang
parent a1cc0346fe
commit b712ff0cde
8 changed files with 395 additions and 18 deletions
@@ -42,11 +42,12 @@ public class SchClientController implements ISchClientController, ApplicationCon
GeneralJobResult result = new GeneralJobResult();
result.setFireInstanceId(param.getFireInstanceId());
result.setParam(param);
//获得bean
IExecute bean = applicationContext.getBean(IExecute.class, param.getBeanName());
if (bean == null) {
//判断bean是否存在
if (!applicationContext.containsBean(param.getBeanName())) {
throw new SchException(param.getBeanName() + " not definition");
}
//获得bean
IExecute bean = applicationContext.getBean(param.getBeanName(), IExecute.class);
//客户端开始时间
Date clientStartExecuteTime = new Date();
//执行
@@ -6,7 +6,9 @@
*/
package com.egridcloud.udf.scheduler.job;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
@@ -27,6 +29,7 @@ import com.egridcloud.udf.scheduler.client.domain.GeneralJobResult;
* @author Administrator
*
*/
@DisallowConcurrentExecution
public class GeneralJob extends AbstractBaseJob {
@Override
@@ -64,14 +67,15 @@ public class GeneralJob extends AbstractBaseJob {
}
/**
* 描述 : 保存
* 描述 : 保存(会吃掉注入IGeneralJobResult实现类的异常)
*
* @param result result
*/
private void saveGeneralJobResult(GeneralJobResult result) {
IGeneralJobResult generalJobResultService =
this.getApplicationContext().getBean(IGeneralJobResult.class);
if (generalJobResultService != null) {
String[] beanNames = this.getApplicationContext().getBeanNamesForType(IGeneralJobResult.class);
if (ArrayUtils.isNotEmpty(beanNames)) {
IGeneralJobResult generalJobResultService =
this.getApplicationContext().getBean(IGeneralJobResult.class);
generalJobResultService.save(result);
}
}
@@ -106,7 +106,7 @@ public class JobService {
+ jobDetailMeta.getGroup() + " already exist!");
}
// 获得jobDataMap
JobDataMap jobDataMap = null;
JobDataMap jobDataMap = new JobDataMap();
if (MapUtils.isNotEmpty(jobDetailMeta.getDataMap())) {
jobDataMap = new JobDataMap(jobDetailMeta.getDataMap());
}
@@ -133,7 +133,7 @@ public class JobService {
// 设置jobkey
JobKey jobKey = getJobKey(jobDetailMeta);
// 删除
this.s.getScheduler().triggerJob(jobKey);
this.s.getScheduler().deleteJob(jobKey);
}
/**
@@ -245,6 +245,10 @@ public class JobService {
* @return 作业元数据
*/
protected JobDetailMeta getJobDetailMeta(String jobCode) {
//判空
if (MapUtils.isEmpty(schedulerProperties.getJobDetail())) {
throw new SchException("JobDetail not defined!");
}
//获得作业定义
JobDetailMeta jobDetailMeta = schedulerProperties.getJobDetail().get(jobCode);
//判断作业是否存在
@@ -164,7 +164,7 @@ public class TriggerService {
// 获得jobkey
JobKey jobKey = jobService.getJobKey(jobDetailMeta);
// 获得jobDataMap
JobDataMap jobDataMap = null;
JobDataMap jobDataMap = new JobDataMap();
if (MapUtils.isNotEmpty(triggerMeta.getDataMap())) {
jobDataMap = new JobDataMap(triggerMeta.getDataMap());
}
@@ -246,7 +246,7 @@ public class TriggerService {
// 获得jobkey
JobKey jobKey = jobService.getJobKey(jobDetailMeta);
// 获得jobDataMap
JobDataMap jobDataMap = null;
JobDataMap jobDataMap = new JobDataMap();
if (MapUtils.isNotEmpty(triggerMeta.getDataMap())) {
jobDataMap = new JobDataMap(triggerMeta.getDataMap());
}
@@ -390,14 +390,23 @@ public class TriggerService {
* @return 触发器元数据
*/
protected TriggerMeta getTriggerMeta(String triggerCode) {
TriggerMeta triggerMeta = getCronTriggerMeta(triggerCode);
if (triggerMeta == null) {
triggerMeta = getSimpleTriggerMeta(triggerCode);
if (triggerMeta == null) {
throw new SchException("triggerCode : " + triggerCode + " not defined!"); //NOSONAR
}
TriggerMeta cornTriggerMeta = null;
TriggerMeta simpleTriggerMeta = null;
if (MapUtils.isNotEmpty(schedulerProperties.getCronTrigger())) {
cornTriggerMeta = schedulerProperties.getCronTrigger().get(triggerCode);
}
if (MapUtils.isNotEmpty(schedulerProperties.getSimpleTrigger())) {
simpleTriggerMeta = schedulerProperties.getSimpleTrigger().get(triggerCode);
}
if (cornTriggerMeta == null && simpleTriggerMeta == null) {
throw new SchException("triggerCode : " + triggerCode + " not defined!"); //NOSONAR
} else if (simpleTriggerMeta == null) {
return cornTriggerMeta;
} else if (cornTriggerMeta == null) {
return simpleTriggerMeta;
} else {
throw new SchException("triggerCode : " + triggerCode + " Definition repeats ");
}
return triggerMeta;
}
/**
@@ -407,6 +416,10 @@ public class TriggerService {
* @return simple触发器元数据
*/
protected CronTriggerMeta getCronTriggerMeta(String cronTriggerCode) {
//判空
if (MapUtils.isEmpty(schedulerProperties.getCronTrigger())) {
throw new SchException("cronTrigger not defined!");
}
//获得触发器定义
CronTriggerMeta cronTriggerMeta = schedulerProperties.getCronTrigger().get(cronTriggerCode);
//判断触发器是否存在
@@ -430,6 +443,10 @@ public class TriggerService {
* @return simple触发器元数据
*/
protected SimpleTriggerMeta getSimpleTriggerMeta(String simpleTriggerCode) {
//判空
if (MapUtils.isEmpty(schedulerProperties.getSimpleTrigger())) {
throw new SchException("simpleTrigger not defined!");
}
//获得触发器定义
SimpleTriggerMeta simpleTriggerMeta =
schedulerProperties.getSimpleTrigger().get(simpleTriggerCode);
@@ -0,0 +1,97 @@
/**
* IJobController.java
* Created at 2017-06-11
* Created by Administrator
* Copyright (C) 2016 egridcloud.com, All rights reserved.
*/
package com.egridcloud.udf.scheduler.web;
import org.quartz.SchedulerException;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.egridcloud.udf.core.RestResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
/**
* 描述 : IJobController
*
* @author Administrator
*
*/
@Api(value = "作业服务", consumes = "application/json", produces = "application/json",
protocols = "http")
@RequestMapping(value = "/service/scheduler/job")
public interface IJobController {
/**
* 描述 : 保存作业
*
* @param jobCode 作业代码
* @return 操作结果
* @throws ClassNotFoundException ClassNotFoundException
* @throws SchedulerException SchedulerException
*/
@ApiOperation(value = "SCHEDULER_JOB_1", notes = "保存作业")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "header", name = "rmsApplicationName", value = "rms应用名称",
required = true, dataType = "string"),
@ApiImplicitParam(paramType = "header", name = "rmsSign", value = "rms认证秘钥", required = true,
dataType = "string"),
@ApiImplicitParam(paramType = "header", name = "rmsServiceCode", value = "rms接口编号",
required = true, dataType = "string"),
@ApiImplicitParam(paramType = "path", name = "jobCode", value = "作业代码", required = true,
dataType = "string") })
@RequestMapping(value = "{jobCode}", method = RequestMethod.PUT)
public RestResponse<String> save(@PathVariable String jobCode) //NOSONAR
throws ClassNotFoundException, SchedulerException;
/**
* 描述 : 保存作业(覆盖)
*
* @param jobCode 作业代码
* @return 操作结果
* @throws ClassNotFoundException ClassNotFoundException
* @throws SchedulerException SchedulerException
*/
@ApiOperation(value = "SCHEDULER_JOB_2", notes = "保存作业(覆盖)")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "header", name = "rmsApplicationName", value = "rms应用名称",
required = true, dataType = "string"),
@ApiImplicitParam(paramType = "header", name = "rmsSign", value = "rms认证秘钥", required = true,
dataType = "string"),
@ApiImplicitParam(paramType = "header", name = "rmsServiceCode", value = "rms接口编号",
required = true, dataType = "string"),
@ApiImplicitParam(paramType = "path", name = "jobCode", value = "作业代码", required = true,
dataType = "string") })
@RequestMapping(value = "{jobCode}/cover", method = RequestMethod.PUT)
public RestResponse<String> saveCover(@PathVariable String jobCode) //NOSONAR
throws ClassNotFoundException, SchedulerException;
/**
* 描述 : 移除作业
*
* @param jobCode 作业代码
* @return 操作结果
* @throws SchedulerException SchedulerException
*/
@ApiOperation(value = "SCHEDULER_JOB_3", notes = "移除作业")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "header", name = "rmsApplicationName", value = "rms应用名称",
required = true, dataType = "string"),
@ApiImplicitParam(paramType = "header", name = "rmsSign", value = "rms认证秘钥", required = true,
dataType = "string"),
@ApiImplicitParam(paramType = "header", name = "rmsServiceCode", value = "rms接口编号",
required = true, dataType = "string"),
@ApiImplicitParam(paramType = "path", name = "jobCode", value = "作业代码", required = true,
dataType = "string") })
@RequestMapping(value = "{jobCode}", method = RequestMethod.DELETE)
public RestResponse<String> remove(@PathVariable String jobCode) //NOSONAR
throws SchedulerException;
}
@@ -0,0 +1,137 @@
/**
* ITriggerController.java
* Created at 2017-06-11
* Created by Administrator
* Copyright (C) 2016 egridcloud.com, All rights reserved.
*/
package com.egridcloud.udf.scheduler.web;
import org.quartz.SchedulerException;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.egridcloud.udf.core.RestResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
/**
* 描述 : ITriggerController
*
* @author Administrator
*
*/
@Api(value = "触发器服务", consumes = "application/json", produces = "application/json",
protocols = "http")
@RequestMapping(value = "/service/scheduler/trigger")
public interface ITriggerController {
/**
* 描述 : 保存简单触发器
*
* @param triggerCode 触发器代码
* @return 操作结果
* @throws SchedulerException SchedulerException
*/
@ApiOperation(value = "SCHEDULER_TRIGGER_1", notes = "保存简单触发器")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "header", name = "rmsApplicationName", value = "rms应用名称",
required = true, dataType = "string"),
@ApiImplicitParam(paramType = "header", name = "rmsSign", value = "rms认证秘钥", required = true,
dataType = "string"),
@ApiImplicitParam(paramType = "header", name = "rmsServiceCode", value = "rms接口编号",
required = true, dataType = "string"),
@ApiImplicitParam(paramType = "path", name = "triggerCode", value = "触发器代码", required = true,
dataType = "string") })
@RequestMapping(value = "simple/{triggerCode}", method = RequestMethod.PUT)
public RestResponse<String> saveSimple(@PathVariable String triggerCode) //NOSONAR
throws SchedulerException;
/**
* 描述 : 保存简单触发器(覆盖)
*
* @param triggerCode 触发器代码
* @return 操作结果
* @throws SchedulerException SchedulerException
*/
@ApiOperation(value = "SCHEDULER_TRIGGER_1", notes = "保存简单触发器(覆盖)")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "header", name = "rmsApplicationName", value = "rms应用名称",
required = true, dataType = "string"),
@ApiImplicitParam(paramType = "header", name = "rmsSign", value = "rms认证秘钥", required = true,
dataType = "string"),
@ApiImplicitParam(paramType = "header", name = "rmsServiceCode", value = "rms接口编号",
required = true, dataType = "string"),
@ApiImplicitParam(paramType = "path", name = "triggerCode", value = "触发器代码", required = true,
dataType = "string") })
@RequestMapping(value = "simple/{triggerCode}/cover", method = RequestMethod.PUT)
public RestResponse<String> saveSimpleCover(@PathVariable String triggerCode) //NOSONAR
throws SchedulerException;
/**
* 描述 : 保存CRON触发器
*
* @param triggerCode 触发器代码
* @return 操作结果
* @throws SchedulerException SchedulerException
*/
@ApiOperation(value = "SCHEDULER_TRIGGER_3", notes = "保存CRON触发器")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "header", name = "rmsApplicationName", value = "rms应用名称",
required = true, dataType = "string"),
@ApiImplicitParam(paramType = "header", name = "rmsSign", value = "rms认证秘钥", required = true,
dataType = "string"),
@ApiImplicitParam(paramType = "header", name = "rmsServiceCode", value = "rms接口编号",
required = true, dataType = "string"),
@ApiImplicitParam(paramType = "path", name = "triggerCode", value = "触发器代码", required = true,
dataType = "string") })
@RequestMapping(value = "cron/{triggerCode}", method = RequestMethod.PUT)
public RestResponse<String> saveCron(@PathVariable String triggerCode) //NOSONAR
throws SchedulerException;
/**
* 描述 : 保存CRON触发器(覆盖)
*
* @param triggerCode 触发器代码
* @return 操作结果
* @throws SchedulerException SchedulerException
*/
@ApiOperation(value = "SCHEDULER_TRIGGER_4", notes = "保存CRON触发器(覆盖)")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "header", name = "rmsApplicationName", value = "rms应用名称",
required = true, dataType = "string"),
@ApiImplicitParam(paramType = "header", name = "rmsSign", value = "rms认证秘钥", required = true,
dataType = "string"),
@ApiImplicitParam(paramType = "header", name = "rmsServiceCode", value = "rms接口编号",
required = true, dataType = "string"),
@ApiImplicitParam(paramType = "path", name = "triggerCode", value = "触发器代码", required = true,
dataType = "string") })
@RequestMapping(value = "cron/{triggerCode}/cover", method = RequestMethod.PUT)
public RestResponse<String> saveCronCover(@PathVariable String triggerCode) //NOSONAR
throws SchedulerException;
/**
* 描述 : 删除触发器
*
* @param triggerCode 触发器代码
* @return 操作结果
* @throws SchedulerException SchedulerException
*/
@ApiOperation(value = "SCHEDULER_TRIGGER_5", notes = "删除触发器")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "header", name = "rmsApplicationName", value = "rms应用名称",
required = true, dataType = "string"),
@ApiImplicitParam(paramType = "header", name = "rmsSign", value = "rms认证秘钥", required = true,
dataType = "string"),
@ApiImplicitParam(paramType = "header", name = "rmsServiceCode", value = "rms接口编号",
required = true, dataType = "string"),
@ApiImplicitParam(paramType = "path", name = "triggerCode", value = "触发器代码", required = true,
dataType = "string") })
@RequestMapping(value = "{triggerCode}", method = RequestMethod.DELETE)
public RestResponse<String> remove(@PathVariable String triggerCode) //NOSONAR
throws SchedulerException;
}
@@ -0,0 +1,52 @@
/**
* JobController.java
* Created at 2017-05-26
* Created by Administrator
* Copyright (C) 2016 egridcloud.com, All rights reserved.
*/
package com.egridcloud.udf.scheduler.web;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import com.egridcloud.udf.core.RestResponse;
import com.egridcloud.udf.scheduler.service.JobService;
/**
* 描述 : JobController
*
* @author Administrator
*
*/
@RestController
public class JobController implements IJobController {
/**
* 描述 : jobService
*/
@Autowired
private JobService jobService;
@Override
public RestResponse<String> save(@PathVariable String jobCode)
throws ClassNotFoundException, SchedulerException {
jobService.save(jobCode, false);
return new RestResponse<>();
}
@Override
public RestResponse<String> saveCover(@PathVariable String jobCode)
throws ClassNotFoundException, SchedulerException {
jobService.save(jobCode, true);
return new RestResponse<>();
}
@Override
public RestResponse<String> remove(@PathVariable String jobCode) throws SchedulerException {
jobService.remove(jobCode);
return new RestResponse<>();
}
}
@@ -0,0 +1,65 @@
/**
* TriggerController.java
* Created at 2017-05-26
* Created by Administrator
* Copyright (C) 2016 egridcloud.com, All rights reserved.
*/
package com.egridcloud.udf.scheduler.web;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import com.egridcloud.udf.core.RestResponse;
import com.egridcloud.udf.scheduler.service.TriggerService;
/**
* 描述 : TriggerController
*
* @author Administrator
*
*/
@RestController
public class TriggerController implements ITriggerController {
/**
* 描述 : triggerService
*/
@Autowired
private TriggerService triggerService;
@Override
public RestResponse<String> saveSimple(@PathVariable String triggerCode)
throws SchedulerException {
triggerService.saveSimpleTirgger(triggerCode, false);
return new RestResponse<>();
}
@Override
public RestResponse<String> saveSimpleCover(@PathVariable String triggerCode)
throws SchedulerException {
triggerService.saveSimpleTirgger(triggerCode, true);
return new RestResponse<>();
}
@Override
public RestResponse<String> saveCron(@PathVariable String triggerCode) throws SchedulerException {
triggerService.saveCronTrigger(triggerCode, false);
return new RestResponse<>();
}
@Override
public RestResponse<String> saveCronCover(@PathVariable String triggerCode)
throws SchedulerException {
triggerService.saveCronTrigger(triggerCode, true);
return new RestResponse<>();
}
@Override
public RestResponse<String> remove(@PathVariable String triggerCode) throws SchedulerException {
triggerService.remove(triggerCode);
return new RestResponse<>();
}
}