提交 c511a945 authored 作者: xuxueli's avatar xuxueli

调度中心与执行器通讯规范为双向restful,方便跨语言,以及第三方执行器实现;通讯组件xxl-rpc方案调整为Jetty+Gson方案;

上级 bb62887f
差异被折叠。
package com.xxl.job.executor; package com.xxl.job.executorbiz;
import com.xxl.job.core.biz.ExecutorBiz; import com.xxl.job.core.biz.ExecutorBiz;
import com.xxl.job.core.biz.client.ExecutorBizClient; import com.xxl.job.core.biz.client.ExecutorBizClient;
...@@ -12,7 +12,7 @@ import org.junit.Assert; ...@@ -12,7 +12,7 @@ import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
/** /**
* executor-api client, test * executor api test
* *
* Created by xuxueli on 17/5/12. * Created by xuxueli on 17/5/12.
*/ */
...@@ -51,6 +51,29 @@ public class ExecutorBizTest { ...@@ -51,6 +51,29 @@ public class ExecutorBizTest {
Assert.assertEquals("job thread is running or has trigger queue.", retval.getMsg()); Assert.assertEquals("job thread is running or has trigger queue.", retval.getMsg());
} }
@Test
public void run(){
ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken);
// trigger data
final TriggerParam triggerParam = new TriggerParam();
triggerParam.setJobId(1);
triggerParam.setExecutorHandler("demoJobHandler");
triggerParam.setExecutorParams(null);
triggerParam.setExecutorBlockStrategy(ExecutorBlockStrategyEnum.COVER_EARLY.name());
triggerParam.setGlueType(GlueTypeEnum.BEAN.name());
triggerParam.setGlueSource(null);
triggerParam.setGlueUpdatetime(System.currentTimeMillis());
triggerParam.setLogId(1);
triggerParam.setLogDateTime(System.currentTimeMillis());
// Act
final ReturnT<String> retval = executorBiz.run(triggerParam);
// Assert result
Assert.assertNotNull(retval);
}
@Test @Test
public void kill(){ public void kill(){
ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken); ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken);
...@@ -82,27 +105,4 @@ public class ExecutorBizTest { ...@@ -82,27 +105,4 @@ public class ExecutorBizTest {
Assert.assertNotNull(retval); Assert.assertNotNull(retval);
} }
@Test
public void run(){
ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken);
// trigger data
final TriggerParam triggerParam = new TriggerParam();
triggerParam.setJobId(1);
triggerParam.setExecutorHandler("demoJobHandler");
triggerParam.setExecutorParams(null);
triggerParam.setExecutorBlockStrategy(ExecutorBlockStrategyEnum.COVER_EARLY.name());
triggerParam.setGlueType(GlueTypeEnum.BEAN.name());
triggerParam.setGlueSource(null);
triggerParam.setGlueUpdatetime(System.currentTimeMillis());
triggerParam.setLogId(1);
triggerParam.setLogDateTime(System.currentTimeMillis());
// Act
final ReturnT<String> retval = executorBiz.run(triggerParam);
// Assert result
Assert.assertNotNull(retval);
}
} }
...@@ -24,6 +24,13 @@ public interface ExecutorBiz { ...@@ -24,6 +24,13 @@ public interface ExecutorBiz {
*/ */
public ReturnT<String> idleBeat(int jobId); public ReturnT<String> idleBeat(int jobId);
/**
* run
* @param triggerParam
* @return
*/
public ReturnT<String> run(TriggerParam triggerParam);
/** /**
* kill * kill
* @param jobId * @param jobId
...@@ -38,11 +45,4 @@ public interface ExecutorBiz { ...@@ -38,11 +45,4 @@ public interface ExecutorBiz {
*/ */
public ReturnT<LogResult> log(LogParam logParam); public ReturnT<LogResult> log(LogParam logParam);
/**
* run
* @param triggerParam
* @return
*/
public ReturnT<String> run(TriggerParam triggerParam);
} }
...@@ -36,10 +36,16 @@ public class ExecutorBizClient implements ExecutorBiz { ...@@ -36,10 +36,16 @@ public class ExecutorBizClient implements ExecutorBiz {
return XxlJobRemotingUtil.postBody(addressUrl+"beat", accessToken, timeout, null, String.class); return XxlJobRemotingUtil.postBody(addressUrl+"beat", accessToken, timeout, null, String.class);
} }
@Override
public ReturnT<String> idleBeat(int jobId){ public ReturnT<String> idleBeat(int jobId){
return XxlJobRemotingUtil.postBody(addressUrl+"idleBeat", accessToken, timeout, jobId, String.class); return XxlJobRemotingUtil.postBody(addressUrl+"idleBeat", accessToken, timeout, jobId, String.class);
} }
@Override
public ReturnT<String> run(TriggerParam triggerParam) {
return XxlJobRemotingUtil.postBody(addressUrl + "run", accessToken, timeout, triggerParam, String.class);
}
@Override @Override
public ReturnT<String> kill(int jobId) { public ReturnT<String> kill(int jobId) {
return XxlJobRemotingUtil.postBody(addressUrl + "kill", accessToken, timeout, jobId, String.class); return XxlJobRemotingUtil.postBody(addressUrl + "kill", accessToken, timeout, jobId, String.class);
...@@ -50,8 +56,4 @@ public class ExecutorBizClient implements ExecutorBiz { ...@@ -50,8 +56,4 @@ public class ExecutorBizClient implements ExecutorBiz {
return XxlJobRemotingUtil.postBody(addressUrl + "log", accessToken, timeout, logParam, LogResult.class); return XxlJobRemotingUtil.postBody(addressUrl + "log", accessToken, timeout, logParam, LogResult.class);
} }
public ReturnT<String> run(TriggerParam triggerParam) {
return XxlJobRemotingUtil.postBody(addressUrl + "run", accessToken, timeout, triggerParam, String.class);
}
} }
...@@ -46,27 +46,6 @@ public class ExecutorBizImpl implements ExecutorBiz { ...@@ -46,27 +46,6 @@ public class ExecutorBizImpl implements ExecutorBiz {
return ReturnT.SUCCESS; return ReturnT.SUCCESS;
} }
@Override
public ReturnT<String> kill(int jobId) {
// kill handlerThread, and create new one
JobThread jobThread = XxlJobExecutor.loadJobThread(jobId);
if (jobThread != null) {
XxlJobExecutor.removeJobThread(jobId, "scheduling center kill job.");
return ReturnT.SUCCESS;
}
return new ReturnT<String>(ReturnT.SUCCESS_CODE, "job thread already killed.");
}
@Override
public ReturnT<LogResult> log(LogParam logParam) {
// log filename: logPath/yyyy-MM-dd/9999.log
String logFileName = XxlJobFileAppender.makeLogFileName(new Date(logParam.getLogDateTim()), logParam.getLogId());
LogResult logResult = XxlJobFileAppender.readLog(logFileName, logParam.getFromLineNum());
return new ReturnT<LogResult>(logResult);
}
@Override @Override
public ReturnT<String> run(TriggerParam triggerParam) { public ReturnT<String> run(TriggerParam triggerParam) {
// load old:jobHandler + jobThread // load old:jobHandler + jobThread
...@@ -172,4 +151,25 @@ public class ExecutorBizImpl implements ExecutorBiz { ...@@ -172,4 +151,25 @@ public class ExecutorBizImpl implements ExecutorBiz {
return pushResult; return pushResult;
} }
@Override
public ReturnT<String> kill(int jobId) {
// kill handlerThread, and create new one
JobThread jobThread = XxlJobExecutor.loadJobThread(jobId);
if (jobThread != null) {
XxlJobExecutor.removeJobThread(jobId, "scheduling center kill job.");
return ReturnT.SUCCESS;
}
return new ReturnT<String>(ReturnT.SUCCESS_CODE, "job thread already killed.");
}
@Override
public ReturnT<LogResult> log(LogParam logParam) {
// log filename: logPath/yyyy-MM-dd/9999.log
String logFileName = XxlJobFileAppender.makeLogFileName(new Date(logParam.getLogDateTim()), logParam.getLogId());
LogResult logResult = XxlJobFileAppender.readLog(logFileName, logParam.getFromLineNum());
return new ReturnT<LogResult>(logResult);
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论