diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index 486a4c54..85c2ac5e 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -903,6 +903,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 - 4、执行器集群地址列表进行自然排序; - 5、调度中心,DAO层代码精简优化并且新增测试用例覆盖; - 6、调度中心API服务改为自研RPC形式,统一底层通讯模型; +- 7、新增调度中心API服务测试Demo,方便在调度中心API扩展和测试; #### TODO LIST - 1、任务权限管理:执行器为粒度分配权限,核心操作校验权限; diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobApiController.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobApiController.java index d86fa4c3..a31bb293 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobApiController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobApiController.java @@ -1,6 +1,7 @@ package com.xxl.job.admin.controller; import com.xxl.job.admin.controller.annotation.PermessionLimit; +import com.xxl.job.core.biz.AdminBiz; import com.xxl.job.core.rpc.codec.RpcRequest; import com.xxl.job.core.rpc.codec.RpcResponse; import com.xxl.job.core.rpc.netcom.NetComServerFactory; @@ -46,7 +47,7 @@ public class JobApiController { } } - @RequestMapping("/api") + @RequestMapping(AdminBiz.MAPPING) @PermessionLimit(limit=false) public void api(HttpServletRequest request, HttpServletResponse response) throws IOException { diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java index 4a961ef2..be0b6a4d 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java @@ -12,6 +12,8 @@ import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.rpc.netcom.NetComClientProxy; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.DateUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; @@ -32,6 +34,7 @@ import java.util.Map; @Controller @RequestMapping("/joblog") public class JobLogController { + private static Logger logger = LoggerFactory.getLogger(JobLogController.class); @Resource private XxlJobGroupDao xxlJobGroupDao; @@ -129,7 +132,7 @@ public class JobLogController { return logResult; } catch (Exception e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); return new ReturnT(ReturnT.FAIL_CODE, e.getMessage()); } } @@ -148,14 +151,14 @@ public class JobLogController { } // request of kill - ExecutorBiz executorBiz = null; + ReturnT runResult = null; try { - executorBiz = (ExecutorBiz) new NetComClientProxy(ExecutorBiz.class, log.getExecutorAddress()).getObject(); + ExecutorBiz executorBiz = (ExecutorBiz) new NetComClientProxy(ExecutorBiz.class, log.getExecutorAddress()).getObject(); + runResult = executorBiz.kill(jobInfo.getId()); } catch (Exception e) { - e.printStackTrace(); - return new ReturnT(500, e.getMessage()); + logger.error(e.getMessage(), e); + runResult = new ReturnT(500, e.getMessage()); } - ReturnT runResult = executorBiz.kill(jobInfo.getId()); if (ReturnT.SUCCESS_CODE == runResult.getCode()) { log.setHandleCode(ReturnT.FAIL_CODE); diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/ExecutorRouter.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/ExecutorRouter.java index d762de3e..06342122 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/ExecutorRouter.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/ExecutorRouter.java @@ -36,7 +36,7 @@ public abstract class ExecutorRouter { ExecutorBiz executorBiz = (ExecutorBiz) new NetComClientProxy(ExecutorBiz.class, address).getObject(); runResult = executorBiz.run(triggerParam); } catch (Exception e) { - logger.error("", e); + logger.error(e.getMessage(), e); runResult = new ReturnT(ReturnT.FAIL_CODE, ""+e ); } diff --git a/xxl-job-admin/src/test/java/com/xxl/job/dao/impl/AdminBizTest.java b/xxl-job-admin/src/test/java/com/xxl/job/dao/impl/AdminBizTest.java new file mode 100644 index 00000000..ea577b33 --- /dev/null +++ b/xxl-job-admin/src/test/java/com/xxl/job/dao/impl/AdminBizTest.java @@ -0,0 +1,31 @@ +package com.xxl.job.dao.impl; + +import com.xxl.job.core.biz.AdminBiz; +import com.xxl.job.core.biz.model.RegistryParam; +import com.xxl.job.core.biz.model.ReturnT; +import com.xxl.job.core.enums.RegistryConfig; +import com.xxl.job.core.rpc.netcom.NetComClientProxy; +import org.junit.Assert; +import org.junit.Test; + +/** + * admin-api client, test + * @author xuxueli 2017-07-28 22:14:52 + */ +public class AdminBizTest { + + @Test + public void registryTest() throws Exception { + + // admin-client + String addressUrl = "http://127.0.0.1:8080/xxl-job-admin".concat(AdminBiz.MAPPING); + AdminBiz adminBiz = (AdminBiz) new NetComClientProxy(AdminBiz.class, addressUrl).getObject(); + + // test executor registry + RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999"); + ReturnT returnT = adminBiz.registry(registryParam); + Assert.assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE); + + } + +} diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/biz/AdminBiz.java b/xxl-job-core/src/main/java/com/xxl/job/core/biz/AdminBiz.java index 1e4b8313..fcb4f101 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/biz/AdminBiz.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/biz/AdminBiz.java @@ -11,6 +11,8 @@ import java.util.List; */ public interface AdminBiz { + public static final String MAPPING = "/api"; + /** * callback * 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 4f80b48b..88dda0c9 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 @@ -58,7 +58,7 @@ public class XxlJobExecutor implements ApplicationContextAware, ApplicationListe if (adminAddresses!=null && adminAddresses.trim().length()>0) { for (String address: adminAddresses.trim().split(",")) { if (address!=null && address.trim().length()>0) { - String addressUrl = address.concat("/api"); + String addressUrl = address.concat(AdminBiz.MAPPING); AdminBiz adminBiz = (AdminBiz) new NetComClientProxy(AdminBiz.class, addressUrl).getObject(); if (adminBizList == null) { adminBizList = new ArrayList(); diff --git a/xxl-job-executor-example/src/test/java/com/xxl/executor/test/DemoJobHandlerTest.java b/xxl-job-executor-example/src/test/java/com/xxl/executor/test/DemoJobHandlerTest.java index d1325f73..301e83d5 100644 --- a/xxl-job-executor-example/src/test/java/com/xxl/executor/test/DemoJobHandlerTest.java +++ b/xxl-job-executor-example/src/test/java/com/xxl/executor/test/DemoJobHandlerTest.java @@ -8,6 +8,8 @@ import com.xxl.job.core.glue.GlueTypeEnum; import com.xxl.job.core.rpc.netcom.NetComClientProxy; /** + * executor-api client, test + * * Created by xuxueli on 17/5/12. */ public class DemoJobHandlerTest {