From cc60338e3d2d93014a64bbee33648818acabb92c Mon Sep 17 00:00:00 2001 From: DoolinMa <564121522@qq.com> Date: Tue, 29 Mar 2022 17:09:12 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1=E3=80=81=E8=B0=83=E5=BA=A6=E4=B8=AD?= =?UTF-8?q?=E5=BF=83restfulapi=E5=9C=B0=E5=9D=80=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E4=B8=AD=E5=BA=94=E8=AF=A5=E5=B8=A6=E6=9C=89/api=202=E3=80=81?= =?UTF-8?q?=E6=A1=A3=E4=B8=AD=E2=80=9C=E8=B7=9F=E2=80=9D=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E6=96=87=E5=AD=97=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/XXL-JOB官方文档.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index 467798ae..6be128b2 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -776,7 +776,7 @@ docker run -e PARAMS="--spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xxl_jo 执行器配置,配置内容说明: - ### 调度中心部署跟地址 [选填]:如调度中心集群部署存在多个地址则用逗号分隔。执行器将会使用该地址进行"执行器心跳注册"和"任务结果回调";为空则关闭自动注册; + ### 调度中心部署根地址 [选填]:如调度中心集群部署存在多个地址则用逗号分隔。执行器将会使用该地址进行"执行器心跳注册"和"任务结果回调";为空则关闭自动注册; xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin ### 执行器通讯TOKEN [选填]:非空时启用; @@ -1514,7 +1514,7 @@ API服务请求参考代码:com.xxl.job.adminbiz.AdminBizTest ------ -地址格式:{调度中心跟地址}/callback +地址格式:{调度中心根地址}/api/callback Header: XXL-JOB-ACCESS-TOKEN : {请求令牌} @@ -1542,7 +1542,7 @@ Header: ------ -地址格式:{调度中心跟地址}/registry +地址格式:{调度中心根地址}/api/registry Header: XXL-JOB-ACCESS-TOKEN : {请求令牌} @@ -1567,7 +1567,7 @@ Header: ------ -地址格式:{调度中心跟地址}/registryRemove +地址格式:{调度中心根地址}/api/registryRemove Header: XXL-JOB-ACCESS-TOKEN : {请求令牌} @@ -1597,7 +1597,7 @@ API服务请求参考代码:com.xxl.job.executorbiz.ExecutorBizTest ------ -地址格式:{执行器内嵌服务跟地址}/beat +地址格式:{执行器内嵌服务根地址}/beat Header: XXL-JOB-ACCESS-TOKEN : {请求令牌} @@ -1617,7 +1617,7 @@ Header: ------ -地址格式:{执行器内嵌服务跟地址}/idleBeat +地址格式:{执行器内嵌服务根地址}/idleBeat Header: XXL-JOB-ACCESS-TOKEN : {请求令牌} @@ -1640,7 +1640,7 @@ Header: ------ -地址格式:{执行器内嵌服务跟地址}/run +地址格式:{执行器内嵌服务根地址}/run Header: XXL-JOB-ACCESS-TOKEN : {请求令牌} @@ -1674,7 +1674,7 @@ Header: ------ -地址格式:{执行器内嵌服务跟地址}/kill +地址格式:{执行器内嵌服务根地址}/kill Header: XXL-JOB-ACCESS-TOKEN : {请求令牌} @@ -1698,7 +1698,7 @@ Header: ------ -地址格式:{执行器内嵌服务跟地址}/log +地址格式:{执行器内嵌服务根地址}/log Header: XXL-JOB-ACCESS-TOKEN : {请求令牌} From d55068a5bf04310558ef093e89257dc1964cd886 Mon Sep 17 00:00:00 2001 From: cszxyang Date: Wed, 20 Apr 2022 00:14:01 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= =?UTF-8?q?=E3=80=81=E6=97=A5=E5=BF=97=E5=A4=84=E7=90=86=E5=8F=8A=E9=83=A8?= =?UTF-8?q?=E5=88=86=E4=BB=A3=E7=A0=81=E7=AE=80=E5=8D=95=E7=BE=8E=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xxl/job/core/executor/XxlJobExecutor.java | 8 ++- .../com/xxl/job/core/server/EmbedServer.java | 64 ++++++++----------- 2 files changed, 32 insertions(+), 40 deletions(-) diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java b/xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java index 70a2dad9..4719b7b7 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java @@ -83,6 +83,7 @@ public class XxlJobExecutor { // init executor-server initEmbedServer(address, ip, port, appname, accessToken); } + public void destroy(){ // destroy executor-server stopEmbedServer(); @@ -131,6 +132,7 @@ public class XxlJobExecutor { } } } + public static List getAdminBizList(){ return adminBizList; } @@ -251,6 +253,7 @@ public class XxlJobExecutor { return newJobThread; } + public static JobThread removeJobThread(int jobId, String removeOldReason){ JobThread oldJobThread = jobThreadRepository.remove(jobId); if (oldJobThread != null) { @@ -261,9 +264,8 @@ public class XxlJobExecutor { } return null; } + public static JobThread loadJobThread(int jobId){ - JobThread jobThread = jobThreadRepository.get(jobId); - return jobThread; + return jobThreadRepository.get(jobId); } - } diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/server/EmbedServer.java b/xxl-job-core/src/main/java/com/xxl/job/core/server/EmbedServer.java index 242d6b63..540e0ea2 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/server/EmbedServer.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/server/EmbedServer.java @@ -36,10 +36,8 @@ public class EmbedServer { public void start(final String address, final int port, final String appname, final String accessToken) { executorBiz = new ExecutorBizImpl(); thread = new Thread(new Runnable() { - @Override public void run() { - // param EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); @@ -61,8 +59,6 @@ public class EmbedServer { throw new RuntimeException("xxl-job, EmbedServer bizThreadPool is EXHAUSTED!"); } }); - - try { // start server ServerBootstrap bootstrap = new ServerBootstrap(); @@ -92,11 +88,9 @@ public class EmbedServer { future.channel().closeFuture().sync(); } catch (InterruptedException e) { - if (e instanceof InterruptedException) { - logger.info(">>>>>>>>>>> xxl-job remoting server stop."); - } else { - logger.error(">>>>>>>>>>> xxl-job remoting server error.", e); - } + logger.info(">>>>>>>>>>> xxl-job remoting server stop."); + } catch (Exception e) { + logger.error(">>>>>>>>>>> xxl-job remoting server error.", e); } finally { // stop try { @@ -106,17 +100,15 @@ public class EmbedServer { logger.error(e.getMessage(), e); } } - } - }); - thread.setDaemon(true); // daemon, service jvm, user thread leave >>> daemon leave >>> jvm leave + thread.setDaemon(true); // daemon, service jvm, user thread leave >>> daemon leave >>> jvm leave thread.start(); } public void stop() throws Exception { // destroy server thread - if (thread!=null && thread.isAlive()) { + if (thread != null && thread.isAlive()) { thread.interrupt(); } @@ -130,7 +122,7 @@ public class EmbedServer { /** * netty_http - * + *

* Copy from : https://github.com/xuxueli/xxl-rpc * * @author xuxueli 2015-11-24 22:25:15 @@ -141,6 +133,7 @@ public class EmbedServer { private ExecutorBiz executorBiz; private String accessToken; private ThreadPoolExecutor bizThreadPool; + public EmbedHttpServerHandler(ExecutorBiz executorBiz, String accessToken, ThreadPoolExecutor bizThreadPool) { this.executorBiz = executorBiz; this.accessToken = accessToken; @@ -149,7 +142,6 @@ public class EmbedServer { @Override protected void channelRead0(final ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception { - // request parse //final byte[] requestBytes = ByteBufUtil.getBytes(msg.content()); // byteBuf.toString(io.netty.util.CharsetUtil.UTF_8); String requestData = msg.content().toString(CharsetUtil.UTF_8); @@ -175,38 +167,38 @@ public class EmbedServer { } private Object process(HttpMethod httpMethod, String uri, String requestData, String accessTokenReq) { - // valid if (HttpMethod.POST != httpMethod) { return new ReturnT(ReturnT.FAIL_CODE, "invalid request, HttpMethod not support."); } - if (uri==null || uri.trim().length()==0) { + if (uri == null || uri.trim().length() == 0) { return new ReturnT(ReturnT.FAIL_CODE, "invalid request, uri-mapping empty."); } - if (accessToken!=null - && accessToken.trim().length()>0 + if (accessToken != null + && accessToken.trim().length() > 0 && !accessToken.equals(accessTokenReq)) { return new ReturnT(ReturnT.FAIL_CODE, "The access token is wrong."); } // services mapping try { - if ("/beat".equals(uri)) { - return executorBiz.beat(); - } else if ("/idleBeat".equals(uri)) { - IdleBeatParam idleBeatParam = GsonTool.fromJson(requestData, IdleBeatParam.class); - return executorBiz.idleBeat(idleBeatParam); - } else if ("/run".equals(uri)) { - TriggerParam triggerParam = GsonTool.fromJson(requestData, TriggerParam.class); - return executorBiz.run(triggerParam); - } else if ("/kill".equals(uri)) { - KillParam killParam = GsonTool.fromJson(requestData, KillParam.class); - return executorBiz.kill(killParam); - } else if ("/log".equals(uri)) { - LogParam logParam = GsonTool.fromJson(requestData, LogParam.class); - return executorBiz.log(logParam); - } else { - return new ReturnT(ReturnT.FAIL_CODE, "invalid request, uri-mapping("+ uri +") not found."); + switch (uri) { + case "/beat": + return executorBiz.beat(); + case "/idleBeat": + IdleBeatParam idleBeatParam = GsonTool.fromJson(requestData, IdleBeatParam.class); + return executorBiz.idleBeat(idleBeatParam); + case "/run": + TriggerParam triggerParam = GsonTool.fromJson(requestData, TriggerParam.class); + return executorBiz.run(triggerParam); + case "/kill": + KillParam killParam = GsonTool.fromJson(requestData, KillParam.class); + return executorBiz.kill(killParam); + case "/log": + LogParam logParam = GsonTool.fromJson(requestData, LogParam.class); + return executorBiz.log(logParam); + default: + return new ReturnT(ReturnT.FAIL_CODE, "invalid request, uri-mapping(" + uri + ") not found."); } } catch (Exception e) { logger.error(e.getMessage(), e); @@ -261,6 +253,4 @@ public class EmbedServer { // stop registry ExecutorRegistryThread.getInstance().toStop(); } - - }