mirror of
https://gitee.com/wangkang/udf.git
synced 2026-10-29 16:03:44 +00:00
添加job的链式调用
This commit is contained in:
-25
@@ -1,25 +0,0 @@
|
||||
/**
|
||||
* IExecutor.java
|
||||
* Created at 2017-06-11
|
||||
* Created by Administrator
|
||||
* Copyright (C) 2016 itkk.org, All rights reserved.
|
||||
*/
|
||||
package org.itkk.udf.scheduler.client;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 描述 : IExecutor
|
||||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
public interface IExecutor { //NOSONAR
|
||||
|
||||
/**
|
||||
* 描述 : 执行方法
|
||||
*
|
||||
* @param jobDataMap jobDataMap
|
||||
*/
|
||||
void handle(Map<String, Object> jobDataMap);
|
||||
|
||||
}
|
||||
+10
-15
@@ -6,11 +6,14 @@
|
||||
*/
|
||||
package org.itkk.udf.scheduler.client;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.itkk.udf.core.RestResponse;
|
||||
import org.itkk.udf.rms.Rms;
|
||||
import org.itkk.udf.scheduler.client.domain.RmsJobParam;
|
||||
import org.itkk.udf.scheduler.client.domain.RmsJobResult;
|
||||
import org.itkk.udf.scheduler.client.executor.AbstractExecutor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -22,8 +25,6 @@ import org.springframework.retry.annotation.Retryable;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 描述 : SchClientService
|
||||
*
|
||||
@@ -50,20 +51,14 @@ public class SchClientHandle implements ApplicationContextAware {
|
||||
|
||||
/**
|
||||
* 描述 : 异步执行
|
||||
*
|
||||
* @param receiveTime 接收时间
|
||||
* @param param 参数
|
||||
*
|
||||
* @param param 参数
|
||||
* @param result 结果
|
||||
*/
|
||||
@Async
|
||||
public void asyncHandle(Date receiveTime, RmsJobParam param) {
|
||||
//定义返回值
|
||||
RmsJobResult result = new RmsJobResult();
|
||||
result.setParam(param);
|
||||
result.setClientReceiveTime(receiveTime);
|
||||
result.setId(param.getId());
|
||||
//执行(并且记录开始和结束时间)
|
||||
result.setClientStartExecuteTime(new Date());
|
||||
public void asyncHandle(RmsJobParam param, RmsJobResult result) {
|
||||
try {
|
||||
//执行
|
||||
this.handle(param);
|
||||
result.setClientEndExecuteTime(new Date());
|
||||
result.setStats(RmsJobStats.COMPLETE.value());
|
||||
@@ -93,9 +88,9 @@ public class SchClientHandle implements ApplicationContextAware {
|
||||
throw new SchException(param.getBeanName() + " not definition");
|
||||
}
|
||||
//获得bean
|
||||
IExecutor bean = applicationContext.getBean(param.getBeanName(), IExecutor.class);
|
||||
AbstractExecutor bean = applicationContext.getBean(param.getBeanName(), AbstractExecutor.class);
|
||||
//执行
|
||||
bean.handle(param.getJobDataMap());
|
||||
bean.handle(param);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* TriggerDataMapKey.java
|
||||
* Created at 2016-09-27
|
||||
* Created by wangkang
|
||||
* Copyright (C) 2016 itkk.org, All rights reserved.
|
||||
*/
|
||||
package org.itkk.udf.scheduler.client;
|
||||
|
||||
/**
|
||||
* 描述 : TriggerDataMapKey
|
||||
*
|
||||
* @author wangkang
|
||||
*/
|
||||
public enum TriggerDataMapKey {
|
||||
/**
|
||||
* 描述 : 父触发ID
|
||||
*/
|
||||
PARENT_TRIGGER_ID("parentTriggerId"),
|
||||
/**
|
||||
* 描述 : 触发ID
|
||||
*/
|
||||
TRIGGER_ID("triggerId"),
|
||||
/**
|
||||
* 描述 : 触发类型
|
||||
*/
|
||||
TRIGGER_TYPE("triggerType"),
|
||||
/**
|
||||
* 描述 : 服务代码
|
||||
*/
|
||||
SERVICE_CODE("serviceCode"),
|
||||
/**
|
||||
* 描述 : bean名称
|
||||
*/
|
||||
BEAN_NAME("beanName"),
|
||||
/**
|
||||
* 描述 : 是否异步
|
||||
*/
|
||||
ASYNC("async");
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Field value: 参数值
|
||||
* </p>
|
||||
*/
|
||||
private String value = null;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Description: 构造函数
|
||||
* </p>
|
||||
*
|
||||
* @param value 构造函数
|
||||
*/
|
||||
TriggerDataMapKey(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Description: 放回int值
|
||||
* </p>
|
||||
*
|
||||
* @return value 放回int值
|
||||
*/
|
||||
public String value() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -19,7 +19,11 @@ public enum TriggerType {
|
||||
/**
|
||||
* 描述 : 触发器触发
|
||||
*/
|
||||
TRIGGER("trigger");
|
||||
TRIGGER("trigger"),
|
||||
/**
|
||||
* 描述 : 触发链
|
||||
*/
|
||||
CALL_CHAIN("callChain");
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
||||
+24
@@ -31,6 +31,12 @@ public class RmsJobParam implements Serializable {
|
||||
@ApiModelProperty(value = "主键ID", required = true, dataType = "string")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 父ID
|
||||
*/
|
||||
@ApiModelProperty(value = "父ID", required = false, dataType = "string")
|
||||
private String parentId;
|
||||
|
||||
/**
|
||||
* 描述 : 触发实例ID
|
||||
*/
|
||||
@@ -61,6 +67,24 @@ public class RmsJobParam implements Serializable {
|
||||
@ApiModelProperty(value = "作业参数", required = true, dataType = "object")
|
||||
private Map<String, Object> jobDataMap; //NOSONAR
|
||||
|
||||
/**
|
||||
* 描述 : 获取parentId
|
||||
*
|
||||
* @return the parentId
|
||||
*/
|
||||
public String getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 设置parentId
|
||||
*
|
||||
* @param parentId the parentId to set
|
||||
*/
|
||||
public void setParentId(String parentId) {
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 获取triggerType
|
||||
*
|
||||
|
||||
+4
-28
@@ -6,12 +6,12 @@
|
||||
*/
|
||||
package org.itkk.udf.scheduler.client.domain;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* 描述 : RmsJobResult
|
||||
*
|
||||
@@ -31,12 +31,6 @@ public class RmsJobResult implements Serializable {
|
||||
@ApiModelProperty(value = "主键ID", required = true, dataType = "string")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 描述 : 参数
|
||||
*/
|
||||
@ApiModelProperty(value = "参数", required = true, dataType = "object")
|
||||
private RmsJobParam param;
|
||||
|
||||
/**
|
||||
* 描述 : 客户端接收时间
|
||||
*/
|
||||
@@ -52,7 +46,7 @@ public class RmsJobResult implements Serializable {
|
||||
/**
|
||||
* 描述 : 客户端结束时间
|
||||
*/
|
||||
@ApiModelProperty(value = "客户端结束时间", required = true, dataType = "long")
|
||||
@ApiModelProperty(value = "客户端结束时间", required = false, dataType = "long")
|
||||
private Date clientEndExecuteTime;
|
||||
|
||||
/**
|
||||
@@ -67,24 +61,6 @@ public class RmsJobResult implements Serializable {
|
||||
@ApiModelProperty(value = "错误信息", required = true, dataType = "string")
|
||||
private String errorMsg;
|
||||
|
||||
/**
|
||||
* 描述 : 获取param
|
||||
*
|
||||
* @return the param
|
||||
*/
|
||||
public RmsJobParam getParam() {
|
||||
return param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 设置param
|
||||
*
|
||||
* @param param the param to set
|
||||
*/
|
||||
public void setParam(RmsJobParam param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 获取errorMsg
|
||||
*
|
||||
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* AbstractExecutor.java
|
||||
* Created at 2017-08-09
|
||||
* Created by Administrator
|
||||
* Copyright (C) 2016 egridcloud.com, All rights reserved.
|
||||
*/
|
||||
package org.itkk.udf.scheduler.client.executor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.itkk.udf.scheduler.client.TriggerDataMapKey;
|
||||
import org.itkk.udf.scheduler.client.TriggerType;
|
||||
import org.itkk.udf.scheduler.client.domain.RmsJobParam;
|
||||
import org.itkk.udf.scheduler.client.service.SchClientService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* 描述 : AbstractExecutor
|
||||
*
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractExecutor {
|
||||
|
||||
/**
|
||||
* schClientService
|
||||
*/
|
||||
@Autowired
|
||||
private SchClientService schClientService;
|
||||
|
||||
/**
|
||||
* 执行方法 描述 : 执行方法
|
||||
*
|
||||
* @param param param
|
||||
*/
|
||||
public void handle(RmsJobParam param) {
|
||||
this.handle(param.getId(), param.getJobDataMap());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 描述 : 调用链 (允许并发,异步调用)
|
||||
*
|
||||
* @param parentId 父ID
|
||||
* @param serviceCode 服务代码
|
||||
* @param beanName bean名称
|
||||
* @param param 业务参数
|
||||
* @return 结果
|
||||
*/
|
||||
protected String chain(String parentId, String serviceCode, String beanName, Map<String, String> param) {
|
||||
return this.chain(true, parentId, serviceCode, beanName, true, param);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 描述 : 调用链
|
||||
*
|
||||
* @param isConcurrent 是否并发(true:允许并发,false:禁止并发)
|
||||
* @param parentId 父ID
|
||||
* @param serviceCode 服务代码
|
||||
* @param beanName bean名称
|
||||
* @param async 是否异步
|
||||
* @param param 业务参数
|
||||
* @return 结果
|
||||
*/
|
||||
protected String chain(boolean isConcurrent, String parentId, String serviceCode, String beanName, boolean async, Map<String, String> param) {
|
||||
//构建jobDataMap
|
||||
Map<String, String> jdm = new HashMap<>();
|
||||
jdm.put(TriggerDataMapKey.PARENT_TRIGGER_ID.value(), parentId);
|
||||
jdm.put(TriggerDataMapKey.TRIGGER_TYPE.value(), TriggerType.CALL_CHAIN.value());
|
||||
jdm.put(TriggerDataMapKey.SERVICE_CODE.value(), serviceCode);
|
||||
jdm.put(TriggerDataMapKey.BEAN_NAME.value(), beanName);
|
||||
jdm.put(TriggerDataMapKey.ASYNC.value(), Boolean.toString(async));
|
||||
jdm.putAll(param);
|
||||
// 调用 & 返回
|
||||
String jobCode = isConcurrent ? "rmsJob" : "rmsJobDisallowConcurrent";
|
||||
return this.schClientService.trigger(jobCode, jdm);
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 执行方法
|
||||
*
|
||||
* @param id id
|
||||
* @param jobDataMap jobDataMap
|
||||
*/
|
||||
protected abstract void handle(String id, Map<String, Object> jobDataMap);
|
||||
|
||||
}
|
||||
+3
-4
@@ -34,7 +34,7 @@ public class SchClientService {
|
||||
* 描述 : 触发作业
|
||||
*
|
||||
* @param jobCode 作业代码
|
||||
* @param param 参数
|
||||
* @param param 参数
|
||||
* @return id
|
||||
*/
|
||||
public String trigger(String jobCode, Map<String, String> param) {
|
||||
@@ -44,9 +44,8 @@ public class SchClientService {
|
||||
Map<String, String> uriVariables = new HashMap<>();
|
||||
uriVariables.put("jobCode", jobCode);
|
||||
//请求
|
||||
ResponseEntity<RestResponse<String>> result =
|
||||
rms.call(serviceCode, param, null, new ParameterizedTypeReference<RestResponse<String>>() {
|
||||
}, uriVariables);
|
||||
ResponseEntity<RestResponse<String>> result = rms.call(serviceCode, param, null, new ParameterizedTypeReference<RestResponse<String>>() {
|
||||
}, uriVariables);
|
||||
//返回
|
||||
return result.getBody().getResult();
|
||||
}
|
||||
|
||||
+4
-5
@@ -6,6 +6,8 @@
|
||||
*/
|
||||
package org.itkk.udf.scheduler.client.web;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.itkk.udf.core.RestResponse;
|
||||
import org.itkk.udf.scheduler.client.RmsJobStats;
|
||||
import org.itkk.udf.scheduler.client.SchClientHandle;
|
||||
@@ -15,8 +17,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 描述 : SchClientController
|
||||
*
|
||||
@@ -37,15 +37,14 @@ public class SchClientController implements ISchClientController {
|
||||
Date receiveTime = new Date();
|
||||
//定义返回值
|
||||
RmsJobResult result = new RmsJobResult();
|
||||
result.setParam(param);
|
||||
result.setClientReceiveTime(receiveTime);
|
||||
result.setId(param.getId());
|
||||
result.setClientStartExecuteTime(new Date());
|
||||
//执行(区分同步跟异步)
|
||||
if (param.getAsync()) {
|
||||
schClientHandle.asyncHandle(receiveTime, param);
|
||||
schClientHandle.asyncHandle(param, result);
|
||||
result.setStats(RmsJobStats.EXECUTING.value());
|
||||
} else {
|
||||
result.setClientStartExecuteTime(new Date());
|
||||
schClientHandle.handle(param);
|
||||
result.setClientEndExecuteTime(new Date());
|
||||
result.setStats(RmsJobStats.COMPLETE.value());
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
package org.itkk.udf.scheduler;
|
||||
|
||||
import org.itkk.udf.scheduler.client.domain.RmsJobParam;
|
||||
import org.itkk.udf.scheduler.client.domain.RmsJobResult;
|
||||
|
||||
/**
|
||||
@@ -16,11 +17,13 @@ import org.itkk.udf.scheduler.client.domain.RmsJobResult;
|
||||
public interface IRmsJobLog {
|
||||
|
||||
/**
|
||||
*
|
||||
* 描述 : save
|
||||
*
|
||||
* @param param param
|
||||
* @param result result
|
||||
*/
|
||||
void save(RmsJobResult result);
|
||||
void save(RmsJobParam param, RmsJobResult result);
|
||||
|
||||
/**
|
||||
* 描述 : delete
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
*/
|
||||
package org.itkk.udf.scheduler.job;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
@@ -14,6 +16,7 @@ import org.itkk.udf.rms.Rms;
|
||||
import org.itkk.udf.scheduler.IRmsJobLog;
|
||||
import org.itkk.udf.scheduler.client.RmsJobStats;
|
||||
import org.itkk.udf.scheduler.client.SchException;
|
||||
import org.itkk.udf.scheduler.client.TriggerDataMapKey;
|
||||
import org.itkk.udf.scheduler.client.TriggerType;
|
||||
import org.itkk.udf.scheduler.client.domain.RmsJobParam;
|
||||
import org.itkk.udf.scheduler.client.domain.RmsJobResult;
|
||||
@@ -26,8 +29,6 @@ import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 描述 : RmsJob
|
||||
*
|
||||
@@ -45,16 +46,18 @@ public class RmsJob extends AbstractBaseJob {
|
||||
//从trigger中获得jobDataMap
|
||||
JobDataMap jobDataMap = jobExecutionContext.getTrigger().getJobDataMap();
|
||||
//获得必要字段
|
||||
String triggerId = jobDataMap.getString("triggerId");
|
||||
String triggerId = jobDataMap.getString(TriggerDataMapKey.TRIGGER_ID.value());
|
||||
triggerId = StringUtils.isBlank(triggerId) ? UUID.randomUUID().toString() : triggerId;
|
||||
String triggerType = jobDataMap.getString("triggerType");
|
||||
String parentTriggerId = jobDataMap.getString(TriggerDataMapKey.PARENT_TRIGGER_ID.value());
|
||||
String triggerType = jobDataMap.getString(TriggerDataMapKey.TRIGGER_TYPE.value());
|
||||
triggerType = StringUtils.isBlank(triggerType) ? TriggerType.TRIGGER.value() : triggerType;
|
||||
String serviceCode = jobDataMap.getString("serviceCode");
|
||||
String beanName = jobDataMap.getString("beanName");
|
||||
Boolean async = jobDataMap.getBoolean("async");
|
||||
String serviceCode = jobDataMap.getString(TriggerDataMapKey.SERVICE_CODE.value());
|
||||
String beanName = jobDataMap.getString(TriggerDataMapKey.BEAN_NAME.value());
|
||||
Boolean async = jobDataMap.getBoolean(TriggerDataMapKey.ASYNC.value());
|
||||
//封装请求参数
|
||||
RmsJobParam rmsJobParam = new RmsJobParam();
|
||||
rmsJobParam.setId(triggerId);
|
||||
rmsJobParam.setParentId(parentTriggerId);
|
||||
rmsJobParam.setTriggerType(triggerType);
|
||||
rmsJobParam.setFireInstanceId(jobExecutionContext.getFireInstanceId());
|
||||
rmsJobParam.setBeanName(beanName);
|
||||
@@ -71,25 +74,23 @@ public class RmsJob extends AbstractBaseJob {
|
||||
//获得RMS
|
||||
Rms rms = this.getApplicationContext().getBean(Rms.class);
|
||||
//请求
|
||||
ResponseEntity<RestResponse<RmsJobResult>> result = rms.call(serviceCode, rmsJobParam, null,
|
||||
new ParameterizedTypeReference<RestResponse<RmsJobResult>>() {
|
||||
}, null);
|
||||
ResponseEntity<RestResponse<RmsJobResult>> result = rms.call(serviceCode, rmsJobParam, null, new ParameterizedTypeReference<RestResponse<RmsJobResult>>() {
|
||||
}, null);
|
||||
//判断http状态
|
||||
if (result.getStatusCode() != HttpStatus.OK) {
|
||||
//抛出异常
|
||||
throw new SchException("http状态:" + result.getStatusCode().toString());
|
||||
}
|
||||
//记录
|
||||
saveRmsJobResult(result.getBody().getResult());
|
||||
saveRmsJobLog(rmsJobParam, result.getBody().getResult());
|
||||
} catch (Exception e) {
|
||||
//定义返回值
|
||||
RmsJobResult result = new RmsJobResult();
|
||||
result.setParam(rmsJobParam);
|
||||
result.setId(rmsJobParam.getId());
|
||||
result.setStats(RmsJobStats.ERROR.value());
|
||||
result.setErrorMsg(ExceptionUtils.getStackTrace(e));
|
||||
//记录
|
||||
saveRmsJobResult(result);
|
||||
saveRmsJobLog(rmsJobParam, result);
|
||||
//抛出异常
|
||||
LOGGER.error("RmsJob error:", e);
|
||||
throw new JobExecutionException(e);
|
||||
@@ -97,15 +98,16 @@ public class RmsJob extends AbstractBaseJob {
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 保存
|
||||
* 保存
|
||||
*
|
||||
* @param param param
|
||||
* @param result result
|
||||
*/
|
||||
private void saveRmsJobResult(RmsJobResult result) {
|
||||
private void saveRmsJobLog(RmsJobParam param, RmsJobResult result) {
|
||||
String[] beanNames = this.getApplicationContext().getBeanNamesForType(IRmsJobLog.class);
|
||||
if (ArrayUtils.isNotEmpty(beanNames)) {
|
||||
IRmsJobLog rmsJobLog = this.getApplicationContext().getBean(IRmsJobLog.class);
|
||||
rmsJobLog.save(result);
|
||||
rmsJobLog.save(param, result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+20
-27
@@ -34,15 +34,13 @@ public interface IJobController {
|
||||
* @param jobCode 作业代码
|
||||
* @return 操作结果
|
||||
* @throws ClassNotFoundException ClassNotFoundException
|
||||
* @throws SchedulerException SchedulerException
|
||||
* @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")
|
||||
})
|
||||
@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.POST)
|
||||
RestResponse<String> save(@PathVariable String jobCode) throws ClassNotFoundException, SchedulerException; //NOSONAR
|
||||
|
||||
@@ -52,15 +50,13 @@ public interface IJobController {
|
||||
* @param jobCode 作业代码
|
||||
* @return 操作结果
|
||||
* @throws ClassNotFoundException ClassNotFoundException
|
||||
* @throws SchedulerException SchedulerException
|
||||
* @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")
|
||||
})
|
||||
@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)
|
||||
RestResponse<String> saveCover(@PathVariable String jobCode) throws ClassNotFoundException, SchedulerException; //NOSONAR
|
||||
|
||||
@@ -72,30 +68,27 @@ public interface IJobController {
|
||||
* @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")
|
||||
})
|
||||
@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)
|
||||
RestResponse<String> remove(@PathVariable String jobCode) throws SchedulerException; //NOSONAR
|
||||
|
||||
/**
|
||||
* 描述 : 触发作业
|
||||
*
|
||||
* @param jobCode 作业代码
|
||||
* @param jobCode 作业代码
|
||||
* @param jobDataMap jobDataMap
|
||||
* @return 操作结果
|
||||
* @throws SchedulerException SchedulerException
|
||||
*/
|
||||
@ApiOperation(value = "SCHEDULER_JOB_4", 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")})
|
||||
@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 = "trigger/{jobCode}", method = RequestMethod.POST)
|
||||
RestResponse<String> trigger(@PathVariable String jobCode, @RequestBody Map<String, Object> jobDataMap) throws SchedulerException;
|
||||
RestResponse<String> trigger(@PathVariable String jobCode, @RequestBody Map<String, String> jobDataMap) throws SchedulerException;
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.itkk.udf.scheduler.web;
|
||||
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.itkk.udf.core.RestResponse;
|
||||
import org.itkk.udf.scheduler.client.TriggerDataMapKey;
|
||||
import org.itkk.udf.scheduler.client.TriggerType;
|
||||
import org.itkk.udf.scheduler.service.JobService;
|
||||
import org.quartz.JobDataMap;
|
||||
@@ -35,15 +36,13 @@ public class JobController implements IJobController {
|
||||
private JobService jobService;
|
||||
|
||||
@Override
|
||||
public RestResponse<String> save(@PathVariable String jobCode)
|
||||
throws ClassNotFoundException, SchedulerException {
|
||||
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 {
|
||||
public RestResponse<String> saveCover(@PathVariable String jobCode) throws ClassNotFoundException, SchedulerException {
|
||||
jobService.save(jobCode, true);
|
||||
return new RestResponse<>();
|
||||
}
|
||||
@@ -55,8 +54,7 @@ public class JobController implements IJobController {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestResponse<String> trigger(@PathVariable String jobCode,
|
||||
@RequestBody Map<String, Object> jobDataMap) throws SchedulerException {
|
||||
public RestResponse<String> trigger(@PathVariable String jobCode, @RequestBody Map<String, String> jobDataMap) throws SchedulerException {
|
||||
//生成id
|
||||
String triggerId = UUID.randomUUID().toString();
|
||||
//生成jobDataMap
|
||||
@@ -68,8 +66,10 @@ public class JobController implements IJobController {
|
||||
jdm = new JobDataMap(jobDataMap);
|
||||
}
|
||||
//添加参数
|
||||
jdm.put("triggerId", triggerId);
|
||||
jdm.put("triggerType", TriggerType.MANUAL.value());
|
||||
jdm.put(TriggerDataMapKey.TRIGGER_ID.value(), triggerId);
|
||||
if (!jobDataMap.containsKey(TriggerDataMapKey.TRIGGER_TYPE.value())) {
|
||||
jdm.put(TriggerDataMapKey.TRIGGER_TYPE.value(), TriggerType.MANUAL.value());
|
||||
}
|
||||
//触发
|
||||
jobService.trigger(jobCode, jdm);
|
||||
//返回
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ public class SchClientCallbackController implements ISchClientCallbackController
|
||||
@Override
|
||||
public RestResponse<String> callback(@RequestBody RmsJobResult result) {
|
||||
if (rmsJobLog != null) {
|
||||
rmsJobLog.save(result);
|
||||
rmsJobLog.save(null, result);
|
||||
}
|
||||
return new RestResponse<>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user