From 5b7fd337b87f6bb8cd75e94deacb3c78b2c94edf Mon Sep 17 00:00:00 2001 From: Mark Allen <3417310+maallen@users.noreply.github.com> Date: Fri, 25 Aug 2023 14:13:04 +0100 Subject: [PATCH] Code review updates --- docker/docker-compose-api-worker.yml | 193 +++++++++--------- .../box/l10n/mojito/quartz/QuartzConfig.java | 2 + .../box/l10n/mojito/quartz/QuartzJobInfo.java | 14 ++ .../quartz/QuartzPollableTaskScheduler.java | 16 +- .../mojito/quartz/QuartzSchedulerManager.java | 2 +- ...y.java => QuartzMultiSchedulerConfig.java} | 10 +- .../QuartzMultiSchedulerConfigProperties.java | 61 ------ ...MultiSchedulerConfigurationProperties.java | 74 +++++++ .../multi/QuartzMultiSchedulerManager.java | 15 +- .../mojito/quartz/multi/SchedulerConfig.java | 27 --- .../box/l10n/mojito/rest/asset/AssetWS.java | 5 +- .../MachineTranslationWS.java | 5 +- .../mojito/service/asset/AssetService.java | 5 +- .../AssetExtractionService.java | 5 +- .../mojito/service/branch/BranchService.java | 5 +- .../branch/BranchStatisticService.java | 5 +- .../BranchNotificationService.java | 5 +- .../BranchNotificationServiceLegacy.java | 5 +- .../RepositoryStatisticsJobScheduler.java | 5 +- .../box/l10n/mojito/service/tm/TMService.java | 5 +- ...iSchedulerConfigurationPropertiesTest.java | 73 +++++++ .../QuartzMultiSchedulerManagerTest.java | 23 +-- 22 files changed, 322 insertions(+), 238 deletions(-) rename webapp/src/main/java/com/box/l10n/mojito/quartz/multi/{QuartzMultiSchedulerFactory.java => QuartzMultiSchedulerConfig.java} (89%) delete mode 100644 webapp/src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerConfigProperties.java create mode 100644 webapp/src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerConfigurationProperties.java delete mode 100644 webapp/src/main/java/com/box/l10n/mojito/quartz/multi/SchedulerConfig.java create mode 100644 webapp/src/test/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerConfigurationPropertiesTest.java diff --git a/docker/docker-compose-api-worker.yml b/docker/docker-compose-api-worker.yml index a8fceb88c6..d22a9a1f68 100644 --- a/docker/docker-compose-api-worker.yml +++ b/docker/docker-compose-api-worker.yml @@ -19,10 +19,10 @@ services: - --collation-server=utf8mb4_bin - --max-connections=1000 - --log_error_verbosity=2 - worker: + api: deploy: mode: replicated - replicas: 2 + replicas: 1 endpoint_mode: vip resources: limits: @@ -39,62 +39,65 @@ services: depends_on: db: condition: service_healthy - api: - condition: service_healthy build: dockerfile: docker/Dockerfile-bk8 context: ../ + image: mojito:latest + pull_policy: never links: - db + ports: + - "8080:8080" restart: always environment: SPRING_APPLICATION_JSON: '{ - "spring.flyway.enabled": "true", - "l10n.flyway.clean" : "false", - "spring.jpa.database-platform" : "org.hibernate.dialect.MySQLDialect", - "spring.jpa.hibernate.ddl-auto" : "none", - "spring.datasource.url" : "jdbc:mysql://db:3306/mojito?characterEncoding=UTF-8&useUnicode=true", - "spring.datasource.username" : "mojito", - "spring.datasource.password" : "ChangeMe", - "spring.datasource.driverClassName" : "com.mysql.cj.jdbc.Driver", - "spring.jpa.defer-datasource-initialization" : "false", - "l10n.org.quartz.scheduler.enabled" : "true", - "l10n.org.multi-quartz.enabled" : "true", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.jobStore.useProperties" : "true", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.scheduler.instanceId" : "AUTO", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.jobStore.isClustered" : "true", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.threadPool.threadCount" : 10, - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.jobStore.class" : "org.quartz.impl.jdbcjobstore.JobStoreTX", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.jobStore.driverDelegateClass" : "org.quartz.impl.jdbcjobstore.StdJDBCDelegate", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.jobStore.dataSource" : "myDS", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.dataSource.myDS.provider" : "hikaricp", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.dataSource.myDS.driver" : "com.mysql.jdbc.Driver", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.dataSource.myDS.URL" : "jdbc:mysql://db:3306/mojito?characterEncoding=UTF-8&useUnicode=true", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.dataSource.myDS.user" : "mojito", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.dataSource.myDS.password" : "ChangeMe", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.dataSource.myDS.maxConnections" : 12, - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.dataSource.myDS.validationQuery" : "select 1", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.jobStore.useProperties" : "true", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.scheduler.instanceId" : "AUTO", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.jobStore.isClustered" : "true", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.threadPool.threadCount" : 5, - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.jobStore.class" : "org.quartz.impl.jdbcjobstore.JobStoreTX", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.jobStore.driverDelegateClass" : "org.quartz.impl.jdbcjobstore.StdJDBCDelegate", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.jobStore.dataSource" : "myDS", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.dataSource.myDS.provider" : "hikaricp", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.dataSource.myDS.driver" : "com.mysql.jdbc.Driver", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.dataSource.myDS.URL" : "jdbc:mysql://db:3306/mojito?characterEncoding=UTF-8&useUnicode=true", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.dataSource.myDS.user" : "mojito", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.dataSource.myDS.password" : "ChangeMe", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.dataSource.myDS.maxConnections" : 12, - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.dataSource.myDS.validationQuery" : "select 1", - "l10n.assetExtraction.quartz.schedulerName" : "lowPriority", - "logging.level.com.box.l10n.mojito.quartz.QuartzPollableTaskScheduler" : "DEBUG" - }' - api: + "spring.flyway.enabled": "true", + "l10n.flyway.clean" : "false", + "spring.jpa.database-platform" : "org.hibernate.dialect.MySQLDialect", + "spring.jpa.hibernate.ddl-auto" : "none", + "spring.datasource.url" : "jdbc:mysql://db:3306/mojito?characterEncoding=UTF-8&useUnicode=true", + "spring.datasource.username" : "mojito", + "spring.datasource.password" : "ChangeMe", + "spring.datasource.driverClassName" : "com.mysql.cj.jdbc.Driver", + "spring.jpa.defer-datasource-initialization" : "false", + "l10n.org.quartz.scheduler.enabled" : "false", + "l10n.org.multi-quartz.enabled" : "true", + "l10n.org.multi-quartz.schedulers.default.quartz.jobStore.useProperties" : "true", + "l10n.org.multi-quartz.schedulers.default.quartz.scheduler.instanceId" : "AUTO", + "l10n.org.multi-quartz.schedulers.default.quartz.jobStore.isClustered" : "true", + "l10n.org.multi-quartz.schedulers.default.quartz.threadPool.threadCount" : 10, + "l10n.org.multi-quartz.schedulers.default.quartz.jobStore.class" : "org.quartz.impl.jdbcjobstore.JobStoreTX", + "l10n.org.multi-quartz.schedulers.default.quartz.jobStore.driverDelegateClass" : "org.quartz.impl.jdbcjobstore.StdJDBCDelegate", + "l10n.org.multi-quartz.schedulers.default.quartz.jobStore.dataSource" : "myDS", + "l10n.org.multi-quartz.schedulers.default.quartz.dataSource.myDS.provider" : "hikaricp", + "l10n.org.multi-quartz.schedulers.default.quartz.dataSource.myDS.driver" : "com.mysql.jdbc.Driver", + "l10n.org.multi-quartz.schedulers.default.quartz.dataSource.myDS.URL" : "jdbc:mysql://db:3306/mojito?characterEncoding=UTF-8&useUnicode=true", + "l10n.org.multi-quartz.schedulers.default.quartz.dataSource.myDS.user" : "mojito", + "l10n.org.multi-quartz.schedulers.default.quartz.dataSource.myDS.password" : "ChangeMe", + "l10n.org.multi-quartz.schedulers.default.quartz.dataSource.myDS.maxConnections" : 12, + "l10n.org.multi-quartz.schedulers.default.quartz.dataSource.myDS.validationQuery" : "select 1", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.jobStore.useProperties" : "true", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.scheduler.instanceId" : "AUTO", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.jobStore.isClustered" : "true", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.threadPool.threadCount" : 5, + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.jobStore.class" : "org.quartz.impl.jdbcjobstore.JobStoreTX", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.jobStore.driverDelegateClass" : "org.quartz.impl.jdbcjobstore.StdJDBCDelegate", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.jobStore.dataSource" : "myDS", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.dataSource.myDS.provider" : "hikaricp", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.dataSource.myDS.driver" : "com.mysql.jdbc.Driver", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.dataSource.myDS.URL" : "jdbc:mysql://db:3306/mojito?characterEncoding=UTF-8&useUnicode=true", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.dataSource.myDS.user" : "mojito", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.dataSource.myDS.password" : "ChangeMe", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.dataSource.myDS.maxConnections" : 12, + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.dataSource.myDS.validationQuery" : "select 1", + "l10n.assetExtraction.quartz.schedulerName" : "lowPriority", + "logging.level.com.box.l10n.mojito.quartz.QuartzPollableTaskScheduler" : "DEBUG", + "logging.level.com.box.l10n.mojito.service.repository.statistics.RepositoryStatisticsJob" : "DEBUG" + }' + worker: deploy: mode: replicated - replicas: 1 + replicas: 2 endpoint_mode: vip resources: limits: @@ -111,55 +114,55 @@ services: depends_on: db: condition: service_healthy - build: - dockerfile: docker/Dockerfile-bk8 - context: ../ + api: + condition: service_healthy + image: mojito:latest + pull_policy: never links: - db - ports: - - "8080:8080" restart: always environment: SPRING_APPLICATION_JSON: '{ - "spring.flyway.enabled": "true", - "l10n.flyway.clean" : "false", - "spring.jpa.database-platform" : "org.hibernate.dialect.MySQLDialect", - "spring.jpa.hibernate.ddl-auto" : "none", - "spring.datasource.url" : "jdbc:mysql://db:3306/mojito?characterEncoding=UTF-8&useUnicode=true", - "spring.datasource.username" : "mojito", - "spring.datasource.password" : "ChangeMe", - "spring.datasource.driverClassName" : "com.mysql.cj.jdbc.Driver", - "spring.jpa.defer-datasource-initialization" : "false", - "l10n.org.quartz.scheduler.enabled" : "false", - "l10n.org.multi-quartz.enabled" : "true", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.jobStore.useProperties" : "true", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.scheduler.instanceId" : "AUTO", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.jobStore.isClustered" : "true", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.threadPool.threadCount" : 10, - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.jobStore.class" : "org.quartz.impl.jdbcjobstore.JobStoreTX", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.jobStore.driverDelegateClass" : "org.quartz.impl.jdbcjobstore.StdJDBCDelegate", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.jobStore.dataSource" : "myDS", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.dataSource.myDS.provider" : "hikaricp", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.dataSource.myDS.driver" : "com.mysql.jdbc.Driver", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.dataSource.myDS.URL" : "jdbc:mysql://db:3306/mojito?characterEncoding=UTF-8&useUnicode=true", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.dataSource.myDS.user" : "mojito", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.dataSource.myDS.password" : "ChangeMe", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.dataSource.myDS.maxConnections" : 12, - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.dataSource.myDS.validationQuery" : "select 1", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.jobStore.useProperties" : "true", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.scheduler.instanceId" : "AUTO", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.jobStore.isClustered" : "true", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.threadPool.threadCount" : 5, - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.jobStore.class" : "org.quartz.impl.jdbcjobstore.JobStoreTX", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.jobStore.driverDelegateClass" : "org.quartz.impl.jdbcjobstore.StdJDBCDelegate", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.jobStore.dataSource" : "myDS", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.dataSource.myDS.provider" : "hikaricp", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.dataSource.myDS.driver" : "com.mysql.jdbc.Driver", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.dataSource.myDS.URL" : "jdbc:mysql://db:3306/mojito?characterEncoding=UTF-8&useUnicode=true", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.dataSource.myDS.user" : "mojito", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.dataSource.myDS.password" : "ChangeMe", - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.dataSource.myDS.maxConnections" : 12, - "l10n.org.multi-quartz.scheduler.lowPriority.quartz.dataSource.myDS.validationQuery" : "select 1", - "l10n.assetExtraction.quartz.schedulerName" : "lowPriority", - "logging.level.com.box.l10n.mojito.quartz.QuartzPollableTaskScheduler" : "DEBUG" - }' \ No newline at end of file + "spring.flyway.enabled": "true", + "l10n.flyway.clean" : "false", + "spring.jpa.database-platform" : "org.hibernate.dialect.MySQLDialect", + "spring.jpa.hibernate.ddl-auto" : "none", + "spring.datasource.url" : "jdbc:mysql://db:3306/mojito?characterEncoding=UTF-8&useUnicode=true", + "spring.datasource.username" : "mojito", + "spring.datasource.password" : "ChangeMe", + "spring.datasource.driverClassName" : "com.mysql.cj.jdbc.Driver", + "spring.jpa.defer-datasource-initialization" : "false", + "l10n.org.quartz.scheduler.enabled" : "true", + "l10n.org.multi-quartz.enabled" : "true", + "l10n.org.multi-quartz.schedulers.default.quartz.jobStore.useProperties" : "true", + "l10n.org.multi-quartz.schedulers.default.quartz.scheduler.instanceId" : "AUTO", + "l10n.org.multi-quartz.schedulers.default.quartz.jobStore.isClustered" : "true", + "l10n.org.multi-quartz.schedulers.default.quartz.threadPool.threadCount" : 10, + "l10n.org.multi-quartz.schedulers.default.quartz.jobStore.class" : "org.quartz.impl.jdbcjobstore.JobStoreTX", + "l10n.org.multi-quartz.schedulers.default.quartz.jobStore.driverDelegateClass" : "org.quartz.impl.jdbcjobstore.StdJDBCDelegate", + "l10n.org.multi-quartz.schedulers.default.quartz.jobStore.dataSource" : "myDS", + "l10n.org.multi-quartz.schedulers.default.quartz.dataSource.myDS.provider" : "hikaricp", + "l10n.org.multi-quartz.schedulers.default.quartz.dataSource.myDS.driver" : "com.mysql.jdbc.Driver", + "l10n.org.multi-quartz.schedulers.default.quartz.dataSource.myDS.URL" : "jdbc:mysql://db:3306/mojito?characterEncoding=UTF-8&useUnicode=true", + "l10n.org.multi-quartz.schedulers.default.quartz.dataSource.myDS.user" : "mojito", + "l10n.org.multi-quartz.schedulers.default.quartz.dataSource.myDS.password" : "ChangeMe", + "l10n.org.multi-quartz.schedulers.default.quartz.dataSource.myDS.maxConnections" : 12, + "l10n.org.multi-quartz.schedulers.default.quartz.dataSource.myDS.validationQuery" : "select 1", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.jobStore.useProperties" : "true", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.scheduler.instanceId" : "AUTO", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.jobStore.isClustered" : "true", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.threadPool.threadCount" : 5, + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.jobStore.class" : "org.quartz.impl.jdbcjobstore.JobStoreTX", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.jobStore.driverDelegateClass" : "org.quartz.impl.jdbcjobstore.StdJDBCDelegate", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.jobStore.dataSource" : "myDS", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.dataSource.myDS.provider" : "hikaricp", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.dataSource.myDS.driver" : "com.mysql.jdbc.Driver", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.dataSource.myDS.URL" : "jdbc:mysql://db:3306/mojito?characterEncoding=UTF-8&useUnicode=true", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.dataSource.myDS.user" : "mojito", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.dataSource.myDS.password" : "ChangeMe", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.dataSource.myDS.maxConnections" : 12, + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.dataSource.myDS.validationQuery" : "select 1", + "l10n.assetExtraction.quartz.schedulerName" : "lowPriority", + "logging.level.com.box.l10n.mojito.quartz.QuartzPollableTaskScheduler" : "DEBUG", + "logging.level.com.box.l10n.mojito.service.repository.statistics.RepositoryStatisticsJob" : "DEBUG" + }' \ No newline at end of file diff --git a/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzConfig.java b/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzConfig.java index 0a1d7a678e..a1be0eefba 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzConfig.java +++ b/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzConfig.java @@ -51,6 +51,8 @@ void startSchedulers() throws SchedulerException { for (Scheduler scheduler : schedulerManager.getSchedulers()) { logger.info("Starting scheduler: {}", scheduler.getSchedulerName()); scheduler.startDelayed(delay); + // Increment the delay to avoid lock exceptions being thrown as both schedulers try to start + // concurrently delay++; } } diff --git a/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzJobInfo.java b/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzJobInfo.java index 4e957ffbd3..7a1b5d71f6 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzJobInfo.java +++ b/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzJobInfo.java @@ -1,5 +1,7 @@ package com.box.l10n.mojito.quartz; +import static com.box.l10n.mojito.quartz.QuartzSchedulerManager.DEFAULT_SCHEDULER_NAME; + import java.util.Date; import org.quartz.JobBuilder; @@ -14,6 +16,7 @@ public class QuartzJobInfo { boolean inlineInput; long timeout; boolean requestRecovery; + String scheduler; private QuartzJobInfo(Builder builder) { clazz = builder.clazz; @@ -26,6 +29,7 @@ private QuartzJobInfo(Builder builder) { inlineInput = builder.inlineInput; timeout = builder.timeout; requestRecovery = builder.requestRecovery; + scheduler = builder.scheduler; } public Class> getClazz() { @@ -68,6 +72,10 @@ public boolean getRequestRecovery() { return requestRecovery; } + public String getScheduler() { + return scheduler; + } + public static Builder newBuilder(Class> clazz) { Builder builder = new Builder(); builder.clazz = clazz; @@ -85,6 +93,7 @@ public static final class Builder { private boolean inlineInput = true; private long timeout = 3600; private boolean requestRecovery = false; + private String scheduler = DEFAULT_SCHEDULER_NAME; private Builder() {} @@ -128,6 +137,11 @@ public Builder withTimeout(long val) { return this; } + public Builder withScheduler(String val) { + scheduler = val; + return this; + } + /** As defined in {@link JobBuilder#requestRecovery(boolean)} */ public Builder withRequestRecovery(boolean requestRecovery) { this.requestRecovery = requestRecovery; diff --git a/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzPollableTaskScheduler.java b/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzPollableTaskScheduler.java index d7a3c624e8..0042395849 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzPollableTaskScheduler.java +++ b/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzPollableTaskScheduler.java @@ -1,7 +1,6 @@ package com.box.l10n.mojito.quartz; import static com.box.l10n.mojito.quartz.QuartzConfig.DYNAMIC_GROUP_NAME; -import static com.box.l10n.mojito.quartz.QuartzSchedulerManager.DEFAULT_SCHEDULER_NAME; import com.box.l10n.mojito.entity.PollableTask; import com.box.l10n.mojito.json.ObjectMapper; @@ -42,7 +41,7 @@ public PollableFuture scheduleJob( Class> clazz, I input) { QuartzJobInfo quartzJobInfo = QuartzJobInfo.newBuilder(clazz).withInput(input).withMessage(clazz.getSimpleName()).build(); - return scheduleJob(quartzJobInfo, DEFAULT_SCHEDULER_NAME); + return scheduleJob(quartzJobInfo); } public PollableFuture scheduleJobWithCustomTimeout( @@ -54,11 +53,7 @@ public PollableFuture scheduleJobWithCustomTimeout( .withMessage(clazz.getSimpleName()) .build(); - return scheduleJob(quartzJobInfo, DEFAULT_SCHEDULER_NAME); - } - - public PollableFuture scheduleJob(QuartzJobInfo quartzJobInfo) { - return scheduleJob(quartzJobInfo, DEFAULT_SCHEDULER_NAME); + return scheduleJob(quartzJobInfo); } /** @@ -79,12 +74,11 @@ public PollableFuture scheduleJob(QuartzJobInfo quartzJobInfo) { * @param * @return */ - public PollableFuture scheduleJob( - QuartzJobInfo quartzJobInfo, String schedulerName) { + public PollableFuture scheduleJob(QuartzJobInfo quartzJobInfo) { - Scheduler scheduler = schedulerManager.getScheduler(schedulerName); + logger.debug("Scheduling job on queue: {}", quartzJobInfo.getScheduler()); - logger.debug("Scheduling job on queue: {}", schedulerName); + Scheduler scheduler = schedulerManager.getScheduler(quartzJobInfo.getScheduler()); String pollableTaskName = getPollableTaskName(quartzJobInfo.getClazz()); diff --git a/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzSchedulerManager.java b/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzSchedulerManager.java index 6f11701bec..9a8641e187 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzSchedulerManager.java +++ b/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzSchedulerManager.java @@ -5,7 +5,7 @@ public interface QuartzSchedulerManager { - String DEFAULT_SCHEDULER_NAME = "defaultScheduler"; + String DEFAULT_SCHEDULER_NAME = "default"; Scheduler getScheduler(String schedulerName); diff --git a/webapp/src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerFactory.java b/webapp/src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerConfig.java similarity index 89% rename from webapp/src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerFactory.java rename to webapp/src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerConfig.java index d6cdc58d63..4f6116473d 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerFactory.java +++ b/webapp/src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerConfig.java @@ -22,13 +22,14 @@ @Component @ConditionalOnProperty(name = "l10n.org.multi-quartz.enabled", havingValue = "true") -public class QuartzMultiSchedulerFactory { +public class QuartzMultiSchedulerConfig { - Logger logger = LoggerFactory.getLogger(QuartzMultiSchedulerFactory.class); + Logger logger = LoggerFactory.getLogger(QuartzMultiSchedulerConfig.class); @Autowired ApplicationContext applicationContext; - @Autowired QuartzMultiSchedulerConfigProperties quartzMultiSchedulerConfigProperties; + @Autowired + QuartzMultiSchedulerConfigurationProperties quartzMultiSchedulerConfigurationProperties; @Autowired(required = false) QuartzMetricsReportingJobListener quartzMetricsReportingJobListener; @@ -39,7 +40,8 @@ public class QuartzMultiSchedulerFactory { @PostConstruct public void createSchedulers() { - for (SchedulerConfig config : quartzMultiSchedulerConfigProperties.getSchedulerConfigs()) { + for (SchedulerConfigurationProperties config : + quartzMultiSchedulerConfigurationProperties.getSchedulerConfigurationProperties()) { Map quartzProps = config.getQuartz(); Properties properties = new Properties(); diff --git a/webapp/src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerConfigProperties.java b/webapp/src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerConfigProperties.java deleted file mode 100644 index 1b74fe641b..0000000000 --- a/webapp/src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerConfigProperties.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.box.l10n.mojito.quartz.multi; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.annotation.PostConstruct; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ConfigurationProperties("l10n.org.multi-quartz") -@ConditionalOnProperty(name = "l10n.org.multi-quartz.enabled", havingValue = "true") -public class QuartzMultiSchedulerConfigProperties { - - Map scheduler; - - List schedulerConfigs = new ArrayList<>(); - - public Map getScheduler() { - return scheduler; - } - - public void setScheduler(Map scheduler) { - this.scheduler = scheduler; - } - - public List getSchedulerConfigs() { - return schedulerConfigs; - } - - @PostConstruct - public void init() { - schedulerConfigs.addAll(extractSchedulerConfigs()); - } - - private Collection extractSchedulerConfigs() { - Map configs = new HashMap<>(); - - for (Map.Entry entry : scheduler.entrySet()) { - String schedulerName = entry.getKey().substring(0, entry.getKey().indexOf(".")); - SchedulerConfig schedulerConfig = configs.getOrDefault(schedulerName, new SchedulerConfig()); - schedulerConfig.setName(schedulerName); - if (schedulerConfig.getQuartz() == null) { - schedulerConfig.setQuartz(new HashMap<>()); - } - String propertyName = entry.getKey().substring(entry.getKey().indexOf(".") + 1); - schedulerConfig - .getQuartz() - .put( - propertyName.startsWith("quartz.") - ? propertyName.substring(propertyName.indexOf(".") + 1) - : propertyName, - entry.getValue()); - configs.put(schedulerName, schedulerConfig); - } - return configs.values(); - } -} diff --git a/webapp/src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerConfigurationProperties.java b/webapp/src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerConfigurationProperties.java new file mode 100644 index 0000000000..d3c7c27637 --- /dev/null +++ b/webapp/src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerConfigurationProperties.java @@ -0,0 +1,74 @@ +package com.box.l10n.mojito.quartz.multi; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.PostConstruct; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ConfigurationProperties("l10n.org.multi-quartz") +@ConditionalOnProperty(name = "l10n.org.multi-quartz.enabled", havingValue = "true") +public class QuartzMultiSchedulerConfigurationProperties { + + Map> schedulers; + + List schedulerConfigurationProperties = new ArrayList<>(); + + public Map> getSchedulers() { + return schedulers; + } + + public void setSchedulers(Map> schedulers) { + this.schedulers = schedulers; + } + + public List getSchedulerConfigurationProperties() { + return schedulerConfigurationProperties; + } + + @PostConstruct + public void init() { + schedulerConfigurationProperties.addAll(extractSchedulerConfigs()); + } + + private List extractSchedulerConfigs() { + List schedulerProperties = new ArrayList<>(); + + for (Map.Entry> entry : schedulers.entrySet()) { + SchedulerConfigurationProperties config = new SchedulerConfigurationProperties(); + config.setName(entry.getKey()); + for (Map.Entry quartzEntry : entry.getValue().entrySet()) { + config.getQuartz().put(quartzEntry.getKey().replace("quartz.", ""), quartzEntry.getValue()); + } + schedulerProperties.add(config); + } + return schedulerProperties; + } +} + +class SchedulerConfigurationProperties { + + private String name; + + private Map quartz = new HashMap<>(); + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Map getQuartz() { + return quartz; + } + + public void setQuartz(Map quartz) { + this.quartz = quartz; + } +} diff --git a/webapp/src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerManager.java b/webapp/src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerManager.java index d216305560..e9acbfb6f1 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerManager.java +++ b/webapp/src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerManager.java @@ -1,6 +1,7 @@ package com.box.l10n.mojito.quartz.multi; import com.box.l10n.mojito.quartz.QuartzSchedulerManager; +import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.PostConstruct; @@ -15,28 +16,28 @@ @Component @ConditionalOnProperty(name = "l10n.org.multi-quartz.enabled", havingValue = "true") -@DependsOn("quartzMultiSchedulerFactory") +@DependsOn("quartzMultiSchedulerConfig") public class QuartzMultiSchedulerManager implements QuartzSchedulerManager { Logger logger = LoggerFactory.getLogger(QuartzMultiSchedulerManager.class); @Autowired List schedulers; - Map schedulerMap = new java.util.HashMap<>(); + Map schedulerByName = new HashMap<>(); @PostConstruct public void init() throws SchedulerException { for (Scheduler scheduler : schedulers) { - if (schedulerMap.containsKey(scheduler.getSchedulerName())) { + if (schedulerByName.containsKey(scheduler.getSchedulerName())) { throw new QuartzMultiSchedulerException( "Scheduler with name '" + scheduler.getSchedulerName() + "' already exists. Please configure a unique name for each scheduler"); } - schedulerMap.put(scheduler.getSchedulerName(), scheduler); + schedulerByName.put(scheduler.getSchedulerName(), scheduler); } - if (!schedulerMap.containsKey(DEFAULT_SCHEDULER_NAME)) { + if (!schedulerByName.containsKey(DEFAULT_SCHEDULER_NAME)) { throw new QuartzMultiSchedulerException( "No default scheduler found. Please configure a scheduler with name '" + DEFAULT_SCHEDULER_NAME @@ -47,13 +48,13 @@ public void init() throws SchedulerException { @Override public Scheduler getScheduler(String schedulerName) { - if (!schedulerMap.containsKey(schedulerName)) { + if (!schedulerByName.containsKey(schedulerName)) { logger.warn( "Scheduler with name '{}' not found, scheduling job on default scheduler", schedulerName); schedulerName = DEFAULT_SCHEDULER_NAME; } - return schedulerMap.get(schedulerName); + return schedulerByName.get(schedulerName); } @Override diff --git a/webapp/src/main/java/com/box/l10n/mojito/quartz/multi/SchedulerConfig.java b/webapp/src/main/java/com/box/l10n/mojito/quartz/multi/SchedulerConfig.java deleted file mode 100644 index 4dc1669d4b..0000000000 --- a/webapp/src/main/java/com/box/l10n/mojito/quartz/multi/SchedulerConfig.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.box.l10n.mojito.quartz.multi; - -import java.util.HashMap; -import java.util.Map; - -public class SchedulerConfig { - - private String name; - - private Map quartz = new HashMap<>(); - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Map getQuartz() { - return quartz; - } - - public void setQuartz(Map quartz) { - this.quartz = quartz; - } -} diff --git a/webapp/src/main/java/com/box/l10n/mojito/rest/asset/AssetWS.java b/webapp/src/main/java/com/box/l10n/mojito/rest/asset/AssetWS.java index 5204b28069..0f564a8c76 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/rest/asset/AssetWS.java +++ b/webapp/src/main/java/com/box/l10n/mojito/rest/asset/AssetWS.java @@ -75,7 +75,7 @@ public class AssetWS { @Autowired MeterRegistry meterRegistry; @Value("${l10n.assetWS.quartz.schedulerName:" + DEFAULT_SCHEDULER_NAME + "}") - String jobSchedulerName; + String schedulerName; /** * Gets the list of {@link Asset} for a given {@link Repository} and other optional filters @@ -236,9 +236,10 @@ public PollableTask getLocalizedAssetForContentAsync( QuartzJobInfo.newBuilder(GenerateLocalizedAssetJob.class) .withInlineInput(false) .withInput(localizedAssetBody) + .withScheduler(schedulerName) .build(); PollableFuture localizedAssetBodyPollableFuture = - quartzPollableTaskScheduler.scheduleJob(quartzJobInfo, jobSchedulerName); + quartzPollableTaskScheduler.scheduleJob(quartzJobInfo); return localizedAssetBodyPollableFuture.getPollableTask(); } diff --git a/webapp/src/main/java/com/box/l10n/mojito/rest/machinetranslation/MachineTranslationWS.java b/webapp/src/main/java/com/box/l10n/mojito/rest/machinetranslation/MachineTranslationWS.java index ab177077ae..17de093e5e 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/rest/machinetranslation/MachineTranslationWS.java +++ b/webapp/src/main/java/com/box/l10n/mojito/rest/machinetranslation/MachineTranslationWS.java @@ -43,7 +43,7 @@ public class MachineTranslationWS { @Autowired RepositoryMachineTranslationService repositoryMachineTranslationService; @Value("${l10n.machineTranslation.quartz.schedulerName:" + DEFAULT_SCHEDULER_NAME + "}") - String jobSchedulerName; + String schedulerName; @RequestMapping(method = RequestMethod.POST, value = "/api/machine-translation-batch") @ResponseStatus(HttpStatus.OK) @@ -53,9 +53,10 @@ public PollableTask getTranslations(@RequestBody BatchTranslationRequestDTO tran QuartzJobInfo.newBuilder(BatchMachineTranslationJob.class) .withInlineInput(false) .withInput(translationRequest) + .withScheduler(schedulerName) .build(); PollableFuture localizedAssetBodyPollableFuture = - quartzPollableTaskScheduler.scheduleJob(quartzJobInfo, jobSchedulerName); + quartzPollableTaskScheduler.scheduleJob(quartzJobInfo); return localizedAssetBodyPollableFuture.getPollableTask(); } diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/asset/AssetService.java b/webapp/src/main/java/com/box/l10n/mojito/service/asset/AssetService.java index dfe71b3035..8ba18fb1ed 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/asset/AssetService.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/asset/AssetService.java @@ -92,7 +92,7 @@ public class AssetService { @Autowired QuartzPollableTaskScheduler quartzPollableTaskScheduler; @Value("${l10n.assetService.quartz.schedulerName:" + DEFAULT_SCHEDULER_NAME + "}") - String jobSchedulerName; + String schedulerName; /** * Adds an {@link Asset} to a {@link Repository}. @@ -391,8 +391,9 @@ public PollableFuture asyncDeleteAssetsOfBranch(Set assetIds, Long b QuartzJobInfo.newBuilder(DeleteAssetsOfBranchJob.class) .withInput(deleteAssetsOfBranchJobInput) .withMessage(pollableMessage) + .withScheduler(schedulerName) .build(); - return quartzPollableTaskScheduler.scheduleJob(quartzJobInfo, jobSchedulerName); + return quartzPollableTaskScheduler.scheduleJob(quartzJobInfo); } public void deleteAssetsOfBranch(Set assetIds, Long branchId) { diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/assetExtraction/AssetExtractionService.java b/webapp/src/main/java/com/box/l10n/mojito/service/assetExtraction/AssetExtractionService.java index ff7470aa50..e1a6c58edb 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/assetExtraction/AssetExtractionService.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/assetExtraction/AssetExtractionService.java @@ -165,7 +165,7 @@ public class AssetExtractionService { @Autowired LocalBranchToEntityBranchConverter localBranchToEntityBranchConverter; @Value("${l10n.assetExtraction.quartz.schedulerName:" + DEFAULT_SCHEDULER_NAME + "}") - String jobSchedulerName; + String quartzSchedulerName; /** * If the asset type is supported, starts the text units extraction for the given asset. @@ -1161,9 +1161,10 @@ public PollableFuture processAssetAsync( .withMessage(pollableMessage) .withParentId(parentTaskId) .withExpectedSubTaskNumber(5) + .withScheduler(quartzSchedulerName) .build(); - return quartzPollableTaskScheduler.scheduleJob(quartzJobInfo, jobSchedulerName); + return quartzPollableTaskScheduler.scheduleJob(quartzJobInfo); } /** diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/branch/BranchService.java b/webapp/src/main/java/com/box/l10n/mojito/service/branch/BranchService.java index 8b41489df2..521827c9b0 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/branch/BranchService.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/branch/BranchService.java @@ -34,7 +34,7 @@ public class BranchService { @Autowired QuartzPollableTaskScheduler quartzPollableTaskScheduler; @Value("${l10n.branchService.quartz.schedulerName:" + DEFAULT_SCHEDULER_NAME + "}") - String jobSchedulerName; + String schedulerName; public Branch createBranch( Repository repository, String branchName, User createdByUser, Set branchNotifierIds) { @@ -83,7 +83,8 @@ public PollableFuture asyncDeleteBranch(Long repositoryId, Long branchId) QuartzJobInfo.newBuilder(DeleteBranchJob.class) .withInput(deleteBranchJobInput) .withMessage(pollableMessage) + .withScheduler(schedulerName) .build(); - return quartzPollableTaskScheduler.scheduleJob(quartzJobInfo, jobSchedulerName); + return quartzPollableTaskScheduler.scheduleJob(quartzJobInfo); } } diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/branch/BranchStatisticService.java b/webapp/src/main/java/com/box/l10n/mojito/service/branch/BranchStatisticService.java index b661fa9e80..9fe3cf0899 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/branch/BranchStatisticService.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/branch/BranchStatisticService.java @@ -80,7 +80,7 @@ public class BranchStatisticService { @Autowired EntityManager entityManager; @Value("${l10n.branchStatistic.quartz.schedulerName:" + DEFAULT_SCHEDULER_NAME + "}") - String jobSchedulerName; + String schedulerName; /** * Compute statistics for all branches that are not deleted in a given repository. @@ -416,8 +416,9 @@ void scheduleBranchNotification(Branch branch) { QuartzJobInfo.newBuilder(BranchNotificationJob.class) .withUniqueId(String.valueOf(branch.getId())) .withInput(branchNotificationJobInput) + .withScheduler(schedulerName) .build(); - quartzPollableTaskScheduler.scheduleJob(quartzJobInfo, jobSchedulerName); + quartzPollableTaskScheduler.scheduleJob(quartzJobInfo); } /** diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/branch/notification/BranchNotificationService.java b/webapp/src/main/java/com/box/l10n/mojito/service/branch/notification/BranchNotificationService.java index b05453bb02..ca5196e678 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/branch/notification/BranchNotificationService.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/branch/notification/BranchNotificationService.java @@ -56,7 +56,7 @@ public class BranchNotificationService { @Autowired BranchNotificationServiceLegacy branchNotificationServiceLegacy; @Value("${l10n.branchNotification.quartz.schedulerName:" + DEFAULT_SCHEDULER_NAME + "}") - String jobSchedulerName; + String schedulerName; /** * When the state of branch changes, notifications must be sent (new, updated, translated). This @@ -185,8 +185,9 @@ void scheduleMissingScreenshotNotificationsForBranch(Branch branch, String notif .withInput(branchNotificationMissingScreenshotsJobInput) .withTriggerStartDate(date) .withUniqueId(notifierId + "_" + branch.getId()) + .withScheduler(schedulerName) .build(); - quartzPollableTaskScheduler.scheduleJob(quartzJobInfo, jobSchedulerName); + quartzPollableTaskScheduler.scheduleJob(quartzJobInfo); } void sendMissingScreenshotNotificationsForBranch( diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/branch/notificationlegacy/BranchNotificationServiceLegacy.java b/webapp/src/main/java/com/box/l10n/mojito/service/branch/notificationlegacy/BranchNotificationServiceLegacy.java index 69969510f5..a46e5fb81d 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/branch/notificationlegacy/BranchNotificationServiceLegacy.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/branch/notificationlegacy/BranchNotificationServiceLegacy.java @@ -49,7 +49,7 @@ public class BranchNotificationServiceLegacy { @Autowired BranchTextUnitStatisticRepository branchTextUnitStatisticRepository; @Value("${l10n.branchNotificationsLegacy.quartz.schedulerName:" + DEFAULT_SCHEDULER_NAME + "}") - String jobSchedulerName; + String schedulerName; /** * 'required = false' needed here to allow a successful Spring Boot startup as if no {@link @@ -166,8 +166,9 @@ void scheduleMissingScreenshotNotificationsForBranch(Branch branch, String sende .withInput(branchNotificationMissingScreenshotsJobInput) .withTriggerStartDate(date) .withUniqueId(senderType + "_" + branch.getId()) + .withScheduler(schedulerName) .build(); - quartzPollableTaskScheduler.scheduleJob(quartzJobInfo, jobSchedulerName); + quartzPollableTaskScheduler.scheduleJob(quartzJobInfo); } void sendMissingScreenshotNotificationsForBranch( diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/repository/statistics/RepositoryStatisticsJobScheduler.java b/webapp/src/main/java/com/box/l10n/mojito/service/repository/statistics/RepositoryStatisticsJobScheduler.java index 26d0c1a31b..3ead21906d 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/repository/statistics/RepositoryStatisticsJobScheduler.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/repository/statistics/RepositoryStatisticsJobScheduler.java @@ -15,7 +15,7 @@ public class RepositoryStatisticsJobScheduler { @Autowired QuartzPollableTaskScheduler quartzPollableTaskScheduler; @Value("${l10n.repositoryStatistics.quartz.schedulerName:" + DEFAULT_SCHEDULER_NAME + "}") - String jobSchedulerName; + String quartzSchedulerName; public void schedule(Long repositoryId) { Preconditions.checkNotNull(repositoryId); @@ -26,8 +26,9 @@ public void schedule(Long repositoryId) { QuartzJobInfo.Builder quartzInfo = QuartzJobInfo.newBuilder(RepositoryStatisticsJob.class) .withUniqueId(String.valueOf(repositoryId)) + .withScheduler(quartzSchedulerName) .withInput(repositoryStatisticsJobInput); - quartzPollableTaskScheduler.scheduleJob(quartzInfo.build(), jobSchedulerName); + quartzPollableTaskScheduler.scheduleJob(quartzInfo.build()); } } diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/tm/TMService.java b/webapp/src/main/java/com/box/l10n/mojito/service/tm/TMService.java index 08d3576139..b0b30d6d8b 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/tm/TMService.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/tm/TMService.java @@ -145,7 +145,7 @@ public class TMService { @Autowired PullRunAssetService pullRunAssetService; @Value("${l10n.tmService.quartz.schedulerName:" + DEFAULT_SCHEDULER_NAME + "}") - String jobSchedulerName; + String schedulerName; /** * Adds a {@link TMTextUnit} in a {@link TM}. @@ -1200,9 +1200,10 @@ public PollableFuture importLocalizedAssetAsync( QuartzJobInfo.newBuilder(ImportLocalizedAssetJob.class) .withInlineInput(false) .withInput(importLocalizedAssetJobInput) + .withScheduler(schedulerName) .build(); - return quartzPollableTaskScheduler.scheduleJob(quartzJobInfo, jobSchedulerName); + return quartzPollableTaskScheduler.scheduleJob(quartzJobInfo); } public void importLocalizedAsset( diff --git a/webapp/src/test/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerConfigurationPropertiesTest.java b/webapp/src/test/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerConfigurationPropertiesTest.java new file mode 100644 index 0000000000..afd1af70f8 --- /dev/null +++ b/webapp/src/test/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerConfigurationPropertiesTest.java @@ -0,0 +1,73 @@ +package com.box.l10n.mojito.quartz.multi; + +import static org.junit.Assert.assertTrue; + +import com.box.l10n.mojito.quartz.QuartzSchedulerManager; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.quartz.Scheduler; +import org.quartz.SchedulerException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest( + classes = { + QuartzMultiSchedulerConfigurationProperties.class, + QuartzMultiSchedulerConfig.class, + QuartzMultiSchedulerManager.class, + QuartzMultiSchedulerConfigurationPropertiesTest.class + }, + properties = { + "l10n.org.multi-quartz.enabled=true", + "l10n.org.multi-quartz.schedulers.default.quartz.threadPool.threadCount=10", + "l10n.org.multi-quartz.schedulers.lowPriority.quartz.threadPool.threadCount=5" + }) +@EnableConfigurationProperties(QuartzMultiSchedulerConfigurationProperties.class) +public class QuartzMultiSchedulerConfigurationPropertiesTest { + + @Autowired + QuartzMultiSchedulerConfigurationProperties quartzMultiSchedulerConfigurationProperties; + + @Autowired QuartzSchedulerManager schedulerManager; + + @Test + public void testSchedulersConfig() { + List schedulerConfigurationProperties = + quartzMultiSchedulerConfigurationProperties.getSchedulerConfigurationProperties(); + assertTrue(schedulerConfigurationProperties.size() == 2); + assertTrue(schedulerManager.getSchedulers().size() == 2); + + assertTrue( + schedulerManager.getSchedulers().stream() + .filter(scheduler -> isSchedulerName(scheduler, "default")) + .findFirst() + .isPresent()); + + assertTrue( + schedulerManager.getSchedulers().stream() + .filter(scheduler -> isSchedulerName(scheduler, "lowPriority")) + .findFirst() + .isPresent()); + } + + @Test + public void testQuartzPropsAssignedToScheduler() throws SchedulerException { + Scheduler defaultScheduler = schedulerManager.getScheduler("default"); + Scheduler lowPriorityScheduler = schedulerManager.getScheduler("lowPriority"); + Assert.assertEquals(10, defaultScheduler.getMetaData().getThreadPoolSize()); + Assert.assertEquals(5, lowPriorityScheduler.getMetaData().getThreadPoolSize()); + } + + private static boolean isSchedulerName(Scheduler scheduler, String schedulerName) { + try { + return scheduler.getSchedulerName().equals(schedulerName); + } catch (SchedulerException e) { + throw new RuntimeException(e); + } + } +} diff --git a/webapp/src/test/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerManagerTest.java b/webapp/src/test/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerManagerTest.java index 64264d23d1..62e8ccb672 100644 --- a/webapp/src/test/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerManagerTest.java +++ b/webapp/src/test/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerManagerTest.java @@ -26,28 +26,28 @@ @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest( classes = { - QuartzMultiSchedulerConfigProperties.class, - QuartzMultiSchedulerFactory.class, + QuartzMultiSchedulerConfigurationProperties.class, + QuartzMultiSchedulerConfig.class, QuartzMultiSchedulerManager.class, QuartzConfig.class, QuartzMultiSchedulerManagerTest.class }, properties = { "l10n.org.multi-quartz.enabled=true", - "l10n.org.multi-quartz.scheduler.defaultScheduler.quartz.threadPool.threadCount=10", - "l10n.org.multi-quartz.scheduler.scheduler2.quartz.threadPool.threadCount=5" + "l10n.org.multi-quartz.schedulers.default.quartz.threadPool.threadCount=10", + "l10n.org.multi-quartz.schedulers.scheduler2.quartz.threadPool.threadCount=5" }) -@EnableConfigurationProperties(QuartzMultiSchedulerConfigProperties.class) +@EnableConfigurationProperties(QuartzMultiSchedulerConfigurationProperties.class) public class QuartzMultiSchedulerManagerTest { @Autowired QuartzMultiSchedulerManager quartzMultiSchedulerManager; @Test public void testSchedulerGeneratedFromProperties() throws SchedulerException { - Scheduler defaultScheduler = quartzMultiSchedulerManager.getScheduler("defaultScheduler"); + Scheduler defaultScheduler = quartzMultiSchedulerManager.getScheduler("default"); Scheduler scheduler2 = quartzMultiSchedulerManager.getScheduler("scheduler2"); - Assert.assertEquals("defaultScheduler", defaultScheduler.getSchedulerName()); + Assert.assertEquals("default", defaultScheduler.getSchedulerName()); Assert.assertEquals(10, defaultScheduler.getMetaData().getThreadPoolSize()); Assert.assertEquals("scheduler2", scheduler2.getSchedulerName()); Assert.assertEquals(5, scheduler2.getMetaData().getThreadPoolSize()); @@ -86,14 +86,13 @@ public void testExceptionThrownIfDuplicateSchedulerConfigured() throws Scheduler @Test public void testDefaultSchedulerReturnedIfRequestedDoesntExist() throws SchedulerException { Assert.assertEquals( - "defaultScheduler", + "default", quartzMultiSchedulerManager.getScheduler("schedulerNotExist").getSchedulerName()); } @Test - public void testScheduleJobOnSeparateSchedulers() - throws SchedulerException, InterruptedException { - Scheduler defaultScheduler = quartzMultiSchedulerManager.getScheduler("defaultScheduler"); + public void testScheduleJobOnSeparateSchedulers() throws SchedulerException { + Scheduler defaultScheduler = quartzMultiSchedulerManager.getScheduler("default"); Scheduler scheduler2 = quartzMultiSchedulerManager.getScheduler("scheduler2"); await() @@ -112,7 +111,7 @@ public void testScheduleJobOnSeparateSchedulers() await() .atMost(Duration.of(10, ChronoUnit.SECONDS)) .until(() -> jobDetail.getJobDataMap() != null); - Assert.assertEquals("defaultScheduler", TestJob.getExecutingScheduler()); + Assert.assertEquals("default", TestJob.getExecutingScheduler()); JobDetail jobDetail2 = JobBuilder.newJob(TestJob.class).withIdentity("job2", "DYNAMIC").build(); Trigger trigger2 =