diff --git a/README.en.md b/README.en.md index 3542efa89..3e5640a99 100644 --- a/README.en.md +++ b/README.en.md @@ -96,7 +96,7 @@ disjob # Main project① - [Start the Worker Spring-boot application](disjob-samples/disjob-samples-springboot-worker/src/main/java/cn/ponfee/disjob/samples/worker/WorkerApplication.java) - [Start the Supervisor+Worker Spring-boot application](disjob-samples/disjob-samples-springboot-merged/src/main/java/cn/ponfee/disjob/samples/merged/MergedApplication.java) - [Start the Supervisor Spring-boot application](disjob-samples/disjob-samples-springboot-supervisor/src/main/java/cn/ponfee/disjob/samples/supervisor/SupervisorApplication.java) -- [Start the Admin Spring-boot application](disjob-admin/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java) +- [Start the Admin Spring-boot application](disjob-admin/ruoyi-admin/src/main/java/com/ruoyi/DisjobAdminApplication.java) 3. Login to the Admin @@ -149,7 +149,7 @@ disjob # Main project① ```yaml disjob.registry.consul: - namespace: consul_namespace + namespace: disjob_registry host: localhost port: 8500 token: diff --git a/README.md b/README.md index 4167f61c6..516b307f9 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ disjob # 主项目① - [启动Worker单独部署的普通Java-main应用](disjob-samples/disjob-samples-frameless-worker/src/main/java/cn/ponfee/disjob/samples/worker/WorkerFramelessMain.java) - [启动Supervisor+Worker合并部署的Spring-boot应用](disjob-samples/disjob-samples-springboot-merged/src/main/java/cn/ponfee/disjob/samples/merged/MergedApplication.java) - [启动Supervisor单独部署的Spring-boot应用](disjob-samples/disjob-samples-springboot-supervisor/src/main/java/cn/ponfee/disjob/samples/supervisor/SupervisorApplication.java) -- [启动Admin管理后台的Spring-boot应用](disjob-admin/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java) +- [启动Admin管理后台的Spring-boot应用](disjob-admin/ruoyi-admin/src/main/java/com/ruoyi/DisjobAdminApplication.java) 3. 登录管理后台 @@ -168,7 +168,7 @@ disjob # 主项目① ```yaml disjob.registry.consul: - namespace: consul_namespace + namespace: disjob_registry host: localhost port: 8500 token: diff --git a/disjob-admin/ruoyi-admin/src/main/resources/templates/main.html b/disjob-admin/ruoyi-admin/src/main/resources/templates/main.html index 11c50a0ac..537315568 100644 --- a/disjob-admin/ruoyi-admin/src/main/resources/templates/main.html +++ b/disjob-admin/ruoyi-admin/src/main/resources/templates/main.html @@ -303,7 +303,7 @@

启动Worker单独部署的普通Java-main应用
  • 启动Supervisor+Worker合并部署的Spring-boot应用
  • 启动Supervisor单独部署的Spring-boot应用
  • -
  • 启动Admin管理后台的Spring-boot应用
  • +
  • 启动Admin管理后台的Spring-boot应用
    1. 登录管理后台
    2. @@ -380,11 +380,11 @@

      例如:若使用Consul做配置中心时,可加如下配置

      disjob.registry.consul:
      -  namespace: consul_namespace
      +  namespace: disjob_registry
         host: localhost
         port: 8500
         token:
      diff --git a/disjob-admin/ruoyi-disjob/src/main/java/cn/ponfee/disjob/admin/DisjobAdminConfiguration.java b/disjob-admin/ruoyi-disjob/src/main/java/cn/ponfee/disjob/admin/DisjobAdminConfiguration.java index 555a4bb97..631d9ea95 100644 --- a/disjob-admin/ruoyi-disjob/src/main/java/cn/ponfee/disjob/admin/DisjobAdminConfiguration.java +++ b/disjob-admin/ruoyi-disjob/src/main/java/cn/ponfee/disjob/admin/DisjobAdminConfiguration.java @@ -31,7 +31,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.core.JdbcTemplate; -import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.JDBC_TEMPLATE_SPRING_BEAN_NAME; +import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.SPRING_BEAN_NAME_JDBC_TEMPLATE; /** * Disjob admin configuration @@ -42,11 +42,11 @@ @ComponentScan("cn.ponfee.disjob.test.handler") // 加载一些测试的JobHandler,只用于demo演示使用(开发时建议删掉这行) @EnableJacksonDateConfigurer // 解决日期反序列化报错的问题 @EnableSupervisor // disjob-admin必须启用Supervisor角色,即:必须加@EnableSupervisor注解 -@EnableWorker // 若要取消worker角色可去掉@EnableWorker注解(生产建议Supervisor与Worker分开部署) +@EnableWorker // 若要取消worker角色可去掉@EnableWorker注解(生产建议Supervisor与Worker分开部署,即去掉@EnableWorker注解) public class DisjobAdminConfiguration { @Bean - public IdGenerator idGenerator(@Qualifier(JDBC_TEMPLATE_SPRING_BEAN_NAME) JdbcTemplate jdbcTemplate, + public IdGenerator idGenerator(@Qualifier(SPRING_BEAN_NAME_JDBC_TEMPLATE) JdbcTemplate jdbcTemplate, @Value("${" + JobConstants.SPRING_WEB_SERVER_PORT + "}") int port, @Value("${" + JobConstants.DISJOB_BOUND_SERVER_HOST + ":}") String boundHost) { // serverTag = host:port diff --git a/disjob-common/src/main/java/cn/ponfee/disjob/common/base/RetryTemplate.java b/disjob-common/src/main/java/cn/ponfee/disjob/common/base/RetryTemplate.java index 41def2cd2..7a7db573e 100644 --- a/disjob-common/src/main/java/cn/ponfee/disjob/common/base/RetryTemplate.java +++ b/disjob-common/src/main/java/cn/ponfee/disjob/common/base/RetryTemplate.java @@ -48,7 +48,6 @@ public static T execute(ThrowingSupplier action, int retryMaxC return action.get(); } catch (InterruptedException e) { LOG.error("Thread interrupted, skip retry."); - Thread.currentThread().interrupt(); throw e; } catch (Throwable e) { ex = e; diff --git a/disjob-common/src/main/java/cn/ponfee/disjob/common/concurrent/ThreadPoolExecutors.java b/disjob-common/src/main/java/cn/ponfee/disjob/common/concurrent/ThreadPoolExecutors.java index 364c0d32a..29c43e8df 100644 --- a/disjob-common/src/main/java/cn/ponfee/disjob/common/concurrent/ThreadPoolExecutors.java +++ b/disjob-common/src/main/java/cn/ponfee/disjob/common/concurrent/ThreadPoolExecutors.java @@ -97,7 +97,6 @@ public final class ThreadPoolExecutors { try { executor.getQueue().put(task); } catch (InterruptedException e) { - Thread.currentThread().interrupt(); ExceptionUtils.rethrow(e); } }; diff --git a/disjob-common/src/main/java/cn/ponfee/disjob/common/lock/RedisLock.java b/disjob-common/src/main/java/cn/ponfee/disjob/common/lock/RedisLock.java index 7b88a0697..0bdb0daf1 100644 --- a/disjob-common/src/main/java/cn/ponfee/disjob/common/lock/RedisLock.java +++ b/disjob-common/src/main/java/cn/ponfee/disjob/common/lock/RedisLock.java @@ -211,7 +211,6 @@ public void lock() { Thread.sleep(computeSleepMillis(round)); } catch (InterruptedException e) { LOG.error("Redis lock sleep occur interrupted exception.", e); - Thread.currentThread().interrupt(); ExceptionUtils.rethrow(e); } } diff --git a/disjob-common/src/main/java/cn/ponfee/disjob/common/tree/TreeNode.java b/disjob-common/src/main/java/cn/ponfee/disjob/common/tree/TreeNode.java index e9151ed61..479cc4ccd 100644 --- a/disjob-common/src/main/java/cn/ponfee/disjob/common/tree/TreeNode.java +++ b/disjob-common/src/main/java/cn/ponfee/disjob/common/tree/TreeNode.java @@ -477,7 +477,7 @@ private List buildPath(List parentPath, T nid) { return null; } - // already check duplicated, so cannot happen has circular dependencies state + // already check duplicated, so cannot happen exists circular dependencies /* if (IterableUtils.matchesAny(parentPath, nid::equals)) { // 节点路径中已经包含了此节点,则视为环状 @@ -502,7 +502,8 @@ private > void convert(Function, E> List list = new LinkedList<>(); for (TreeNode child : children) { - if (child.available || containsUnavailable) { // filter unavailable + // filter unavailable + if (child.available || containsUnavailable) { E node = convert.apply(child); child.convert(convert, node, containsUnavailable); list.add(node); diff --git a/disjob-common/src/main/java/cn/ponfee/disjob/common/util/NetUtils.java b/disjob-common/src/main/java/cn/ponfee/disjob/common/util/NetUtils.java index f278fa552..6f9245590 100644 --- a/disjob-common/src/main/java/cn/ponfee/disjob/common/util/NetUtils.java +++ b/disjob-common/src/main/java/cn/ponfee/disjob/common/util/NetUtils.java @@ -154,8 +154,10 @@ public static boolean isReachableHost(String host) { // ignored } + // https://stackoverflow.com/questions/11506321/how-to-ping-an-ip-address + boolean isWindows = org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS; try { - Process process = Runtime.getRuntime().exec("ping -c 1 " + host); + Process process = Runtime.getRuntime().exec(String.format("ping -%s 1 %s", isWindows ? "n" : "c", host)); boolean exited = process.waitFor(PING_TIMEOUT, TimeUnit.MILLISECONDS); return exited && process.exitValue() == 0; } catch (Exception ignored) { diff --git a/disjob-common/src/test/java/cn/ponfee/disjob/common/date/DateFormatTest.java b/disjob-common/src/test/java/cn/ponfee/disjob/common/date/DateFormatTest.java index cb515e3a2..1ea362867 100644 --- a/disjob-common/src/test/java/cn/ponfee/disjob/common/date/DateFormatTest.java +++ b/disjob-common/src/test/java/cn/ponfee/disjob/common/date/DateFormatTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2022-2024 Ponfee (http://www.ponfee.cn/) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package cn.ponfee.disjob.common.date; import com.google.common.collect.Lists; @@ -14,6 +30,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; +/** + * DateFormat Test + * + * @author Ponfee + */ public class DateFormatTest { @Test diff --git a/disjob-common/src/test/java/cn/ponfee/disjob/common/date/DatePeriodsTest.java b/disjob-common/src/test/java/cn/ponfee/disjob/common/date/DatePeriodsTest.java index d4aa3de8c..d37556b71 100644 --- a/disjob-common/src/test/java/cn/ponfee/disjob/common/date/DatePeriodsTest.java +++ b/disjob-common/src/test/java/cn/ponfee/disjob/common/date/DatePeriodsTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2022-2024 Ponfee (http://www.ponfee.cn/) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package cn.ponfee.disjob.common.date; import cn.ponfee.disjob.common.util.Bytes; @@ -9,6 +25,11 @@ import java.text.ParseException; import java.util.Date; +/** + * DatePeriods Test + * + * @author Ponfee + */ public class DatePeriodsTest { @Test diff --git a/disjob-common/src/test/java/cn/ponfee/disjob/common/util/CopyrightTest.java b/disjob-common/src/test/java/cn/ponfee/disjob/common/util/CopyrightTest.java index 3a52fc402..e6b6ffbdb 100644 --- a/disjob-common/src/test/java/cn/ponfee/disjob/common/util/CopyrightTest.java +++ b/disjob-common/src/test/java/cn/ponfee/disjob/common/util/CopyrightTest.java @@ -40,6 +40,7 @@ @Disabled public class CopyrightTest { + public static final String CURRENT_FILE_CLASS = "\npublic class " + CopyrightTest.class.getSimpleName() + " {\n"; private static final String OLD_COPYRIGHT_KEYWORD = "\n * Copyright 2022-2023 Ponfee (http://www.ponfee.cn/)\n"; private static final String NEW_COPYRIGHT_KEYWORD = "\n * Copyright 2022-2024 Ponfee (http://www.ponfee.cn/)\n"; @@ -115,11 +116,11 @@ private static void handleFile(Consumer consumer) { } private boolean isOwnerCode(String sourceCode) { - if (sourceCode.contains("public class " + getClass().getSimpleName() + " {\n")) { + if (sourceCode.contains(CURRENT_FILE_CLASS)) { // is current file: CopyrightTest.java return true; } - return sourceCode.contains(" * @author Ponfee\n") && StringUtils.countMatches(sourceCode, " @author ") == 1; + return sourceCode.contains("\n * @author Ponfee\n") && StringUtils.countMatches(sourceCode, " @author ") == 1; } } diff --git a/disjob-common/src/test/java/cn/ponfee/disjob/common/util/NetUtilsTest.java b/disjob-common/src/test/java/cn/ponfee/disjob/common/util/NetUtilsTest.java index 1a1d0183a..a27620f86 100644 --- a/disjob-common/src/test/java/cn/ponfee/disjob/common/util/NetUtilsTest.java +++ b/disjob-common/src/test/java/cn/ponfee/disjob/common/util/NetUtilsTest.java @@ -88,8 +88,9 @@ void testIsReachableHost() { @Test @Disabled void testIsConnectable() { - assertTrue(NetUtils.isConnectableHostPort("www.baidu.com", 80, 100)); - assertFalse(NetUtils.isConnectableHostPort("www.unknownhostname.com", 80, 100)); + assertTrue(NetUtils.isConnectableHostPort("www.baidu.com", 80, 300)); + assertTrue(NetUtils.isConnectableHostPort("www.ponfee.cn", 80, 300)); + assertFalse(NetUtils.isConnectableHostPort("www.unknownhostnamexxxxxxx.com", 80, 300)); } @Test @@ -205,6 +206,12 @@ void testIgnoreGivenPrefixInterfaceName() { } } + @Test + void testFormat() { + assertEquals("ping -n 1 localhost", String.format("ping -%s 1 %s", "n", "localhost")); + assertEquals("ping -c 1 localhost", String.format("ping -%s 1 %s", "c", "localhost")); + } + private String getIgnoredInterfaces() { return System.getProperty(NetUtils.IGNORED_NETWORK_INTERFACE); } diff --git a/disjob-samples/disjob-samples-springboot-common/src/main/resources/application-registry_database.yml b/disjob-samples/disjob-samples-springboot-common/src/main/resources/application-registry_database.yml index f236cf2f2..118afa5f1 100644 --- a/disjob-samples/disjob-samples-springboot-common/src/main/resources/application-registry_database.yml +++ b/disjob-samples/disjob-samples-springboot-common/src/main/resources/application-registry_database.yml @@ -1,6 +1,6 @@ # 当使用database作为注册中心时使用该配置,同时需要在“application.yml”配置文件的“spring.profiles.include”项中增加“registry_database”,即“spring.profiles.include: xxx,registry_database” disjob.registry.database: - namespace: mysql_namespace + namespace: disjob_registry session-timeout-ms: 30000 datasource: driver-class-name: com.mysql.cj.jdbc.Driver diff --git a/disjob-samples/disjob-samples-springboot-merged/src/main/java/cn/ponfee/disjob/samples/merged/MergedApplication.java b/disjob-samples/disjob-samples-springboot-merged/src/main/java/cn/ponfee/disjob/samples/merged/MergedApplication.java index 43fef6aca..31f326034 100644 --- a/disjob-samples/disjob-samples-springboot-merged/src/main/java/cn/ponfee/disjob/samples/merged/MergedApplication.java +++ b/disjob-samples/disjob-samples-springboot-merged/src/main/java/cn/ponfee/disjob/samples/merged/MergedApplication.java @@ -31,7 +31,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.jdbc.core.JdbcTemplate; -import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.JDBC_TEMPLATE_SPRING_BEAN_NAME; +import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.SPRING_BEAN_NAME_JDBC_TEMPLATE; /** * Disjob application based spring boot @@ -53,7 +53,7 @@ public static void main(String[] args) { } @Bean - public IdGenerator idGenerator(@Qualifier(JDBC_TEMPLATE_SPRING_BEAN_NAME) JdbcTemplate jdbcTemplate, + public IdGenerator idGenerator(@Qualifier(SPRING_BEAN_NAME_JDBC_TEMPLATE) JdbcTemplate jdbcTemplate, @Value("${" + JobConstants.SPRING_WEB_SERVER_PORT + "}") int port, @Value("${" + JobConstants.DISJOB_BOUND_SERVER_HOST + ":}") String boundHost) { return new DbDistributedSnowflake(jdbcTemplate, JobConstants.DISJOB_KEY_PREFIX, JobUtils.getLocalHost(boundHost) + Char.COLON + port); diff --git a/disjob-samples/disjob-samples-springboot-supervisor/src/main/java/cn/ponfee/disjob/samples/supervisor/SupervisorApplication.java b/disjob-samples/disjob-samples-springboot-supervisor/src/main/java/cn/ponfee/disjob/samples/supervisor/SupervisorApplication.java index b3efead3a..7553a0210 100644 --- a/disjob-samples/disjob-samples-springboot-supervisor/src/main/java/cn/ponfee/disjob/samples/supervisor/SupervisorApplication.java +++ b/disjob-samples/disjob-samples-springboot-supervisor/src/main/java/cn/ponfee/disjob/samples/supervisor/SupervisorApplication.java @@ -29,7 +29,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.jdbc.core.JdbcTemplate; -import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.JDBC_TEMPLATE_SPRING_BEAN_NAME; +import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.SPRING_BEAN_NAME_JDBC_TEMPLATE; /** * Supervisor application based spring boot @@ -49,7 +49,7 @@ public static void main(String[] args) { } @Bean - public IdGenerator idGenerator(@Qualifier(JDBC_TEMPLATE_SPRING_BEAN_NAME) JdbcTemplate jdbcTemplate, + public IdGenerator idGenerator(@Qualifier(SPRING_BEAN_NAME_JDBC_TEMPLATE) JdbcTemplate jdbcTemplate, @Value("${" + JobConstants.SPRING_WEB_SERVER_PORT + "}") int port, @Value("${" + JobConstants.DISJOB_BOUND_SERVER_HOST + ":}") String boundHost) { return new DbDistributedSnowflake(jdbcTemplate, JobConstants.DISJOB_KEY_PREFIX, JobUtils.getLocalHost(boundHost) + Char.COLON + port); diff --git a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/application/EventSubscribeService.java b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/application/EventSubscribeService.java index b41bb22b5..832d5119e 100644 --- a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/application/EventSubscribeService.java +++ b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/application/EventSubscribeService.java @@ -16,6 +16,7 @@ package cn.ponfee.disjob.supervisor.application; +import cn.ponfee.disjob.common.base.SingletonClassConstraint; import cn.ponfee.disjob.common.concurrent.ThreadPoolExecutors; import cn.ponfee.disjob.common.exception.Throwables.ThrowingRunnable; import cn.ponfee.disjob.core.param.supervisor.EventParam; @@ -37,7 +38,7 @@ * @author Ponfee */ @Service -public class EventSubscribeService { +public class EventSubscribeService extends SingletonClassConstraint { private static final Logger LOG = LoggerFactory.getLogger(EventSubscribeService.class); private static final ConcurrentMap MAP = new ConcurrentHashMap<>(); diff --git a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/application/OpenapiService.java b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/application/OpenapiService.java index 40c7751bb..e41557df7 100644 --- a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/application/OpenapiService.java +++ b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/application/OpenapiService.java @@ -16,6 +16,7 @@ package cn.ponfee.disjob.supervisor.application; +import cn.ponfee.disjob.common.base.SingletonClassConstraint; import cn.ponfee.disjob.common.model.PageResponse; import cn.ponfee.disjob.core.base.JobCodeMsg; import cn.ponfee.disjob.core.enums.ExecuteState; @@ -51,7 +52,7 @@ * @author Ponfee */ @Service -public class OpenapiService { +public class OpenapiService extends SingletonClassConstraint { private static final Logger LOG = LoggerFactory.getLogger(OpenapiService.class); diff --git a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/component/AbstractJobManager.java b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/component/AbstractJobManager.java index c574c112c..ad678d5ed 100644 --- a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/component/AbstractJobManager.java +++ b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/component/AbstractJobManager.java @@ -53,7 +53,7 @@ import static cn.ponfee.disjob.common.spring.TransactionUtils.assertOneAffectedRow; import static cn.ponfee.disjob.common.spring.TransactionUtils.isOneAffectedRow; -import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.TX_MANAGER_SPRING_BEAN_NAME; +import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.SPRING_BEAN_NAME_TX_MANAGER; /** * Abstract job manager @@ -99,7 +99,7 @@ public boolean updateJobNextScanTime(SchedJob schedJob) { // ------------------------------------------------------------------database operation within spring transactional - @Transactional(transactionManager = TX_MANAGER_SPRING_BEAN_NAME, rollbackFor = Exception.class) + @Transactional(transactionManager = SPRING_BEAN_NAME_TX_MANAGER, rollbackFor = Exception.class) public Long addJob(SchedJob job) throws JobException { if (jobMapper.exists(job.getGroup(), job.getJobName())) { throw new KeyExistsException("[" + job.getGroup() + "] already exists job name: " + job.getJobName()); @@ -115,7 +115,7 @@ public Long addJob(SchedJob job) throws JobException { return job.getJobId(); } - @Transactional(transactionManager = TX_MANAGER_SPRING_BEAN_NAME, rollbackFor = Exception.class) + @Transactional(transactionManager = SPRING_BEAN_NAME_TX_MANAGER, rollbackFor = Exception.class) public void updateJob(SchedJob job) throws JobException { job.verifyBeforeUpdate(); job.checkAndDefaultSetting(); @@ -143,7 +143,7 @@ public void updateJob(SchedJob job) throws JobException { assertOneAffectedRow(jobMapper.update(job), "Update sched job fail or conflict."); } - @Transactional(transactionManager = TX_MANAGER_SPRING_BEAN_NAME, rollbackFor = Exception.class) + @Transactional(transactionManager = SPRING_BEAN_NAME_TX_MANAGER, rollbackFor = Exception.class) public void deleteJob(long jobId) { SchedJob job = jobMapper.get(jobId); Assert.notNull(job, "Job id not found: " + jobId); diff --git a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/component/DistributedJobManager.java b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/component/DistributedJobManager.java index 0555ea26c..c8ce0d073 100644 --- a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/component/DistributedJobManager.java +++ b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/component/DistributedJobManager.java @@ -68,8 +68,8 @@ import static cn.ponfee.disjob.common.spring.TransactionUtils.*; import static cn.ponfee.disjob.core.base.JobConstants.PROCESS_BATCH_SIZE; -import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.TX_MANAGER_SPRING_BEAN_NAME; -import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.TX_TEMPLATE_SPRING_BEAN_NAME; +import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.SPRING_BEAN_NAME_TX_MANAGER; +import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.SPRING_BEAN_NAME_TX_TEMPLATE; /** * Manage distributed schedule job. @@ -108,7 +108,7 @@ public DistributedJobManager(SchedJobMapper jobMapper, SupervisorRegistry discoveryWorker, TaskDispatcher taskDispatcher, GroupedServerInvoker workerRpcServiceClient, - @Qualifier(TX_TEMPLATE_SPRING_BEAN_NAME) TransactionTemplate transactionTemplate) { + @Qualifier(SPRING_BEAN_NAME_TX_TEMPLATE) TransactionTemplate transactionTemplate) { super(jobMapper, dependMapper, idGenerator, discoveryWorker, taskDispatcher, workerRpcServiceClient); this.taskDispatchFailedCountThreshold = supervisorProperties.getTaskDispatchFailedCountThreshold(); this.transactionTemplate = transactionTemplate; @@ -157,7 +157,7 @@ public void savepoint(long taskId, String executeSnapshot) { * @param jobId the job id * @throws JobException if occur error */ - @Transactional(transactionManager = TX_MANAGER_SPRING_BEAN_NAME, rollbackFor = Exception.class) + @Transactional(transactionManager = SPRING_BEAN_NAME_TX_MANAGER, rollbackFor = Exception.class) public void triggerJob(long jobId) throws JobException { SchedJob job = jobMapper.get(jobId); Assert.notNull(job, () -> "Sched job not found: " + jobId); @@ -175,7 +175,7 @@ public void triggerJob(long jobId) throws JobException { * @param triggerInstance the trigger instance * @return {@code true} if operated success */ - @Transactional(transactionManager = TX_MANAGER_SPRING_BEAN_NAME, rollbackFor = Exception.class) + @Transactional(transactionManager = SPRING_BEAN_NAME_TX_MANAGER, rollbackFor = Exception.class) public boolean createInstance(SchedJob job, TriggerInstance triggerInstance) { if (jobMapper.updateNextTriggerTime(job) == 0) { // operation conflicted @@ -190,7 +190,7 @@ public boolean createInstance(SchedJob job, TriggerInstance triggerInstance) { * * @param list the update task worker list */ - @Transactional(transactionManager = TX_MANAGER_SPRING_BEAN_NAME, rollbackFor = Exception.class) + @Transactional(transactionManager = SPRING_BEAN_NAME_TX_MANAGER, rollbackFor = Exception.class) public void updateTaskWorker(List list) { if (CollectionUtils.isNotEmpty(list)) { // Sort for prevent sql deadlock: Deadlock found when trying to get lock; try restarting transaction @@ -205,7 +205,7 @@ public void updateTaskWorker(List list) { * @param param the start task param * @return {@code true} if start successfully */ - @Transactional(transactionManager = TX_MANAGER_SPRING_BEAN_NAME, rollbackFor = Exception.class) + @Transactional(transactionManager = SPRING_BEAN_NAME_TX_MANAGER, rollbackFor = Exception.class) public boolean startTask(StartTaskParam param) { SchedInstance instance = instanceMapper.get(param.getInstanceId()); Assert.notNull(instance, () -> "Sched instance not found: " + param); diff --git a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/configuration/EnableSupervisor.java b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/configuration/EnableSupervisor.java index f3f57b26a..41db88cfb 100644 --- a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/configuration/EnableSupervisor.java +++ b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/configuration/EnableSupervisor.java @@ -54,7 +54,7 @@ import java.lang.annotation.*; import java.util.function.UnaryOperator; -import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.JDBC_TEMPLATE_SPRING_BEAN_NAME; +import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.SPRING_BEAN_NAME_JDBC_TEMPLATE; /** * Enable supervisor role @@ -162,19 +162,19 @@ class EnableScanLockerConfiguration { @ConditionalOnMissingBean(name = SupervisorConstants.SPRING_BEAN_NAME_SCAN_TRIGGERING_JOB_LOCKER) @Bean(SupervisorConstants.SPRING_BEAN_NAME_SCAN_TRIGGERING_JOB_LOCKER) - public DoInLocked scanTriggeringJobLocker(@Qualifier(JDBC_TEMPLATE_SPRING_BEAN_NAME) JdbcTemplate jdbcTemplate) { + public DoInLocked scanTriggeringJobLocker(@Qualifier(SPRING_BEAN_NAME_JDBC_TEMPLATE) JdbcTemplate jdbcTemplate) { return new DoInDatabaseLocked(jdbcTemplate, SupervisorConstants.LOCK_SCAN_TRIGGERING_JOB); } @ConditionalOnMissingBean(name = SupervisorConstants.SPRING_BEAN_NAME_SCAN_WAITING_INSTANCE_LOCKER) @Bean(SupervisorConstants.SPRING_BEAN_NAME_SCAN_WAITING_INSTANCE_LOCKER) - public DoInLocked scanWaitingInstanceLocker(@Qualifier(JDBC_TEMPLATE_SPRING_BEAN_NAME) JdbcTemplate jdbcTemplate) { + public DoInLocked scanWaitingInstanceLocker(@Qualifier(SPRING_BEAN_NAME_JDBC_TEMPLATE) JdbcTemplate jdbcTemplate) { return new DoInDatabaseLocked(jdbcTemplate, SupervisorConstants.LOCK_SCAN_WAITING_INSTANCE); } @ConditionalOnMissingBean(name = SupervisorConstants.SPRING_BEAN_NAME_SCAN_RUNNING_INSTANCE_LOCKER) @Bean(SupervisorConstants.SPRING_BEAN_NAME_SCAN_RUNNING_INSTANCE_LOCKER) - public DoInLocked scanRunningInstanceLocker(@Qualifier(JDBC_TEMPLATE_SPRING_BEAN_NAME) JdbcTemplate jdbcTemplate) { + public DoInLocked scanRunningInstanceLocker(@Qualifier(SPRING_BEAN_NAME_JDBC_TEMPLATE) JdbcTemplate jdbcTemplate) { return new DoInDatabaseLocked(jdbcTemplate, SupervisorConstants.LOCK_SCAN_RUNNING_INSTANCE); } } diff --git a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/dao/SupervisorDataSourceConfig.java b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/dao/SupervisorDataSourceConfig.java index e01ab7fc8..5cf371506 100644 --- a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/dao/SupervisorDataSourceConfig.java +++ b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/dao/SupervisorDataSourceConfig.java @@ -51,7 +51,7 @@ @Configuration @MapperScan( basePackages = SupervisorDataSourceConfig.BASE_PACKAGE + ".mapper", - sqlSessionTemplateRef = SupervisorDataSourceConfig.SQL_SESSION_TEMPLATE_SPRING_BEAN_NAME + sqlSessionTemplateRef = SupervisorDataSourceConfig.SPRING_BEAN_NAME_SQL_SESSION_TEMPLATE ) public class SupervisorDataSourceConfig extends AbstractDataSourceConfig { @@ -74,31 +74,36 @@ public class SupervisorDataSourceConfig extends AbstractDataSourceConfig { private static final String DB_NAME = "disjob"; /** - * Transaction manager spring bean name + * Spring bean name datasource */ - public static final String TX_MANAGER_SPRING_BEAN_NAME = DB_NAME + TX_MANAGER_NAME_SUFFIX; + public static final String SPRING_BEAN_NAME_DATASOURCE = DB_NAME + DATA_SOURCE_NAME_SUFFIX; /** - * Transaction template spring bean name + * Spring bean name transaction manager */ - public static final String TX_TEMPLATE_SPRING_BEAN_NAME = DB_NAME + TX_TEMPLATE_NAME_SUFFIX; + public static final String SPRING_BEAN_NAME_TX_MANAGER = DB_NAME + TX_MANAGER_NAME_SUFFIX; /** - * JDBC template spring bean name + * Spring bean name transaction template */ - public static final String JDBC_TEMPLATE_SPRING_BEAN_NAME = DB_NAME + JDBC_TEMPLATE_NAME_SUFFIX; + public static final String SPRING_BEAN_NAME_TX_TEMPLATE = DB_NAME + TX_TEMPLATE_NAME_SUFFIX; /** - * Mybatis sql session factory spring bean name + * Spring bean name JDBC template */ - public static final String SQL_SESSION_FACTORY_SPRING_BEAN_NAME = DB_NAME + SQL_SESSION_FACTORY_NAME_SUFFIX; + public static final String SPRING_BEAN_NAME_JDBC_TEMPLATE = DB_NAME + JDBC_TEMPLATE_NAME_SUFFIX; /** - * Mybatis sql session template spring bean name + * Spring bean name mybatis sql session factory */ - public static final String SQL_SESSION_TEMPLATE_SPRING_BEAN_NAME = DB_NAME + SQL_SESSION_TEMPLATE_NAME_SUFFIX; + public static final String SPRING_BEAN_NAME_SQL_SESSION_FACTORY = DB_NAME + SQL_SESSION_FACTORY_NAME_SUFFIX; - @Bean(name = DB_NAME + DATA_SOURCE_NAME_SUFFIX) + /** + * Spring bean name mybatis sql session template + */ + public static final String SPRING_BEAN_NAME_SQL_SESSION_TEMPLATE = DB_NAME + SQL_SESSION_TEMPLATE_NAME_SUFFIX; + + @Bean(name = SPRING_BEAN_NAME_DATASOURCE) @ConfigurationProperties(prefix = DB_NAME + ".datasource") @Override public DataSource dataSource() { @@ -107,27 +112,27 @@ public DataSource dataSource() { .build(); } - @Bean(name = SQL_SESSION_FACTORY_SPRING_BEAN_NAME) + @Bean(name = SPRING_BEAN_NAME_SQL_SESSION_FACTORY) public SqlSessionFactory sqlSessionFactory() throws Exception { return super.createSqlSessionFactory(); } - @Bean(name = SQL_SESSION_TEMPLATE_SPRING_BEAN_NAME) + @Bean(name = SPRING_BEAN_NAME_SQL_SESSION_TEMPLATE) public SqlSessionTemplate sqlSessionTemplate() throws Exception { return new SqlSessionTemplate(sqlSessionFactory()); } - @Bean(name = TX_MANAGER_SPRING_BEAN_NAME) + @Bean(name = SPRING_BEAN_NAME_TX_MANAGER) public DataSourceTransactionManager transactionManager() { return new DataSourceTransactionManager(dataSource()); } - @Bean(name = TX_TEMPLATE_SPRING_BEAN_NAME) + @Bean(name = SPRING_BEAN_NAME_TX_TEMPLATE) public TransactionTemplate transactionTemplate() { return new TransactionTemplate(transactionManager()); } - @Bean(name = JDBC_TEMPLATE_SPRING_BEAN_NAME) + @Bean(name = SPRING_BEAN_NAME_JDBC_TEMPLATE) public JdbcTemplate jdbcTemplate() { return new JdbcTemplate(dataSource()); } diff --git a/disjob-supervisor/src/test/java/cn/ponfee/disjob/supervisor/config/DisjobConfiguration.java b/disjob-supervisor/src/test/java/cn/ponfee/disjob/supervisor/config/DisjobConfiguration.java index fbda33c13..58d016835 100644 --- a/disjob-supervisor/src/test/java/cn/ponfee/disjob/supervisor/config/DisjobConfiguration.java +++ b/disjob-supervisor/src/test/java/cn/ponfee/disjob/supervisor/config/DisjobConfiguration.java @@ -27,7 +27,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.core.JdbcTemplate; -import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.JDBC_TEMPLATE_SPRING_BEAN_NAME; +import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.SPRING_BEAN_NAME_JDBC_TEMPLATE; /** * Job supervisor configuration. @@ -38,7 +38,7 @@ public class DisjobConfiguration { @Bean - public IdGenerator idGenerator(@Qualifier(JDBC_TEMPLATE_SPRING_BEAN_NAME) JdbcTemplate jdbcTemplate, + public IdGenerator idGenerator(@Qualifier(SPRING_BEAN_NAME_JDBC_TEMPLATE) JdbcTemplate jdbcTemplate, @Value("${" + JobConstants.SPRING_WEB_SERVER_PORT + "}") int port, @Value("${" + JobConstants.DISJOB_BOUND_SERVER_HOST + ":}") String boundHost) { return new DbDistributedSnowflake(jdbcTemplate, JobConstants.DISJOB_KEY_PREFIX, JobUtils.getLocalHost(boundHost) + Char.COLON + port); diff --git a/disjob-supervisor/src/test/java/cn/ponfee/disjob/supervisor/transaction/JobTxManagerTestService.java b/disjob-supervisor/src/test/java/cn/ponfee/disjob/supervisor/transaction/JobTxManagerTestService.java index e404ad8cd..0e574bfbf 100644 --- a/disjob-supervisor/src/test/java/cn/ponfee/disjob/supervisor/transaction/JobTxManagerTestService.java +++ b/disjob-supervisor/src/test/java/cn/ponfee/disjob/supervisor/transaction/JobTxManagerTestService.java @@ -26,8 +26,8 @@ import java.util.Arrays; -import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.TX_MANAGER_SPRING_BEAN_NAME; -import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.TX_TEMPLATE_SPRING_BEAN_NAME; +import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.SPRING_BEAN_NAME_TX_MANAGER; +import static cn.ponfee.disjob.supervisor.dao.SupervisorDataSourceConfig.SPRING_BEAN_NAME_TX_TEMPLATE; /** * test db_order_base @@ -38,7 +38,7 @@ public class JobTxManagerTestService extends AbstractTxManagerTestService { public JobTxManagerTestService(SchedJobMapper mapper, - @Qualifier(TX_TEMPLATE_SPRING_BEAN_NAME) TransactionTemplate transactionTemplate) { + @Qualifier(SPRING_BEAN_NAME_TX_TEMPLATE) TransactionTemplate transactionTemplate) { super( transactionTemplate, (id1, id2) -> mapper.testFindByJobIds(Arrays.asList(id1, id2)), @@ -47,13 +47,13 @@ public JobTxManagerTestService(SchedJobMapper mapper, ); } - @Transactional(value = TX_MANAGER_SPRING_BEAN_NAME, rollbackFor = Exception.class) + @Transactional(value = SPRING_BEAN_NAME_TX_MANAGER, rollbackFor = Exception.class) @Override public void testWithAnnotationTxHasError(Long id1, Long id2) { super.testWithAnnotationTxHasError(id1, id2); } - @Transactional(value = TX_MANAGER_SPRING_BEAN_NAME, rollbackFor = Exception.class) + @Transactional(value = SPRING_BEAN_NAME_TX_MANAGER, rollbackFor = Exception.class) @Override public void testWithAnnotationTxNoneError(Long id1, Long id2) { super.testWithAnnotationTxNoneError(id1, id2); diff --git a/disjob-worker/src/main/java/cn/ponfee/disjob/worker/base/WorkerThreadPool.java b/disjob-worker/src/main/java/cn/ponfee/disjob/worker/base/WorkerThreadPool.java index 05b79fa82..7113d19e6 100644 --- a/disjob-worker/src/main/java/cn/ponfee/disjob/worker/base/WorkerThreadPool.java +++ b/disjob-worker/src/main/java/cn/ponfee/disjob/worker/base/WorkerThreadPool.java @@ -364,8 +364,8 @@ private boolean returnWorkerThread(WorkerThread workerThread) { return true; } catch (InterruptedException e) { LOG.error("Return thread to idle pool interrupted.", e); - Thread.currentThread().interrupt(); stopWorkerThread(workerThread, false); + Thread.currentThread().interrupt(); return false; } }