Skip to content

Commit

Permalink
Merge pull request quarkusio#45425 from manofthepeace/scheduler_quart…
Browse files Browse the repository at this point in the history
…z_configmapping

Move scheduler and quartz extensions to ConfigMapping
  • Loading branch information
geoand authored Jan 8, 2025
2 parents 2ade871 + bbb111a commit 2822a90
Show file tree
Hide file tree
Showing 14 changed files with 187 additions and 198 deletions.
3 changes: 0 additions & 3 deletions extensions/quartz/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ AutoAddScopeBuildItem addScope() {

@BuildStep
NativeImageProxyDefinitionBuildItem connectionProxy(QuartzBuildTimeConfig config) {
if (config.storeType.isDbStore()) {
if (config.storeType().isDbStore()) {
return new NativeImageProxyDefinitionBuildItem(Connection.class.getName());
}
return null;
Expand All @@ -118,8 +118,8 @@ NativeImageProxyDefinitionBuildItem connectionProxy(QuartzBuildTimeConfig config
@BuildStep
QuartzJDBCDriverDialectBuildItem driver(List<JdbcDataSourceBuildItem> jdbcDataSourceBuildItems,
QuartzBuildTimeConfig config, Capabilities capabilities, CombinedIndexBuildItem indexBuildItem) {
if (!config.storeType.isDbStore()) {
if (config.clustered) {
if (!config.storeType().isDbStore()) {
if (config.clustered()) {
throw new ConfigurationException("Clustered jobs configured with unsupported job store option");
}

Expand All @@ -131,7 +131,7 @@ QuartzJDBCDriverDialectBuildItem driver(List<JdbcDataSourceBuildItem> jdbcDataSo
"The Agroal extension is missing and it is required when a Quartz JDBC store is used.");
}

Optional<String> driverDelegate = config.driverDelegate;
Optional<String> driverDelegate = config.driverDelegate();
if (driverDelegate.isPresent()) {
// user-specified custom delegate
IndexView indexView = indexBuildItem.getIndex();
Expand Down Expand Up @@ -164,14 +164,14 @@ QuartzJDBCDriverDialectBuildItem driver(List<JdbcDataSourceBuildItem> jdbcDataSo
}
} else {
Optional<JdbcDataSourceBuildItem> selectedJdbcDataSourceBuildItem = jdbcDataSourceBuildItems.stream()
.filter(i -> config.dataSourceName.isPresent() ? config.dataSourceName.get().equals(i.getName())
.filter(i -> config.dataSourceName().isPresent() ? config.dataSourceName().get().equals(i.getName())
: i.isDefault())
.findFirst();

if (!selectedJdbcDataSourceBuildItem.isPresent()) {
String message = String.format(
"JDBC Store configured but the '%s' datasource is not configured properly. You can configure your datasource by following the guide available at: https://quarkus.io/guides/datasource",
config.dataSourceName.isPresent() ? config.dataSourceName.get() : "default");
config.dataSourceName().isPresent() ? config.dataSourceName().get() : "default");
throw new ConfigurationException(message);
}
driverDelegate = Optional.of(guessDriver(selectedJdbcDataSourceBuildItem));
Expand Down Expand Up @@ -206,7 +206,7 @@ List<ReflectiveClassBuildItem> reflectiveClasses(QuartzBuildTimeConfig config,
QuartzJDBCDriverDialectBuildItem driverDialect) {
List<ReflectiveClassBuildItem> reflectiveClasses = new ArrayList<>();

if (config.serializeJobData.orElse(false)) {
if (config.serializeJobData().orElse(false)) {
reflectiveClasses.add(ReflectiveClassBuildItem.builder(
String.class,
JobDataMap.class,
Expand All @@ -219,13 +219,13 @@ List<ReflectiveClassBuildItem> reflectiveClasses(QuartzBuildTimeConfig config,

Class<?> threadPoolClass;
try {
threadPoolClass = Class.forName(config.threadPoolClass, false, Thread.currentThread().getContextClassLoader());
threadPoolClass = Class.forName(config.threadPoolClass(), false, Thread.currentThread().getContextClassLoader());
if (!ThreadPool.class.isAssignableFrom(threadPoolClass)) {
throw new ConfigurationException(
"Thread pool class does not implement ThreadPool interface spi: " + config.threadPoolClass);
"Thread pool class does not implement ThreadPool interface spi: " + config.threadPoolClass());
}
} catch (ClassNotFoundException e) {
throw new ConfigurationException("Thread pool class not found: " + config.threadPoolClass);
throw new ConfigurationException("Thread pool class not found: " + config.threadPoolClass());
}

reflectiveClasses.add(ReflectiveClassBuildItem.builder(threadPoolClass, SimpleInstanceIdGenerator.class)
Expand All @@ -235,11 +235,11 @@ List<ReflectiveClassBuildItem> reflectiveClasses(QuartzBuildTimeConfig config,
.add(ReflectiveClassBuildItem.builder(CascadingClassLoadHelper.class, InitThreadContextClassLoadHelper.class)
.reason(getClass().getName())
.build());
reflectiveClasses.add(ReflectiveClassBuildItem.builder(config.storeType.clazz)
reflectiveClasses.add(ReflectiveClassBuildItem.builder(config.storeType().clazz)
.reason(getClass().getName())
.methods().fields().build());

if (config.storeType.isDbStore()) {
if (config.storeType().isDbStore()) {
reflectiveClasses.add(ReflectiveClassBuildItem.builder(
JobStoreSupport.class,
AbstractTrigger.class,
Expand All @@ -259,10 +259,10 @@ List<ReflectiveClassBuildItem> reflectiveClasses(QuartzBuildTimeConfig config,
}

reflectiveClasses
.addAll(getAdditionalConfigurationReflectiveClasses(config.instanceIdGenerators, InstanceIdGenerator.class));
reflectiveClasses.addAll(getAdditionalConfigurationReflectiveClasses(config.triggerListeners, TriggerListener.class));
reflectiveClasses.addAll(getAdditionalConfigurationReflectiveClasses(config.jobListeners, JobListener.class));
reflectiveClasses.addAll(getAdditionalConfigurationReflectiveClasses(config.plugins, SchedulerPlugin.class));
.addAll(getAdditionalConfigurationReflectiveClasses(config.instanceIdGenerators(), InstanceIdGenerator.class));
reflectiveClasses.addAll(getAdditionalConfigurationReflectiveClasses(config.triggerListeners(), TriggerListener.class));
reflectiveClasses.addAll(getAdditionalConfigurationReflectiveClasses(config.jobListeners(), JobListener.class));
reflectiveClasses.addAll(getAdditionalConfigurationReflectiveClasses(config.plugins(), SchedulerPlugin.class));

return reflectiveClasses;
}
Expand All @@ -273,13 +273,14 @@ private List<ReflectiveClassBuildItem> getAdditionalConfigurationReflectiveClass
for (QuartzExtensionPointConfig props : config.values()) {
try {
if (!clazz
.isAssignableFrom(Class.forName(props.clazz, false, Thread.currentThread().getContextClassLoader()))) {
throw new IllegalArgumentException(String.format("%s does not implements %s", props.clazz, clazz));
.isAssignableFrom(
Class.forName(props.clazz(), false, Thread.currentThread().getContextClassLoader()))) {
throw new IllegalArgumentException(String.format("%s does not implements %s", props.clazz(), clazz));
}
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException(e);
}
reflectiveClasses.add(ReflectiveClassBuildItem.builder(props.clazz)
reflectiveClasses.add(ReflectiveClassBuildItem.builder(props.clazz())
.reason(getClass().getName())
.methods().build());
}
Expand All @@ -302,7 +303,7 @@ public List<LogCleanupFilterBuildItem> logCleanup(QuartzBuildTimeConfig config)
"Scheduler meta-data:",
"Scheduler "));

logCleanUps.add(new LogCleanupFilterBuildItem(config.storeType.clazz, config.storeType.simpleName
logCleanUps.add(new LogCleanupFilterBuildItem(config.storeType().clazz, config.storeType().simpleName
+ " initialized.", "Handling", "Using db table-based data access locking",
"JDBCJobStore threads will inherit ContextClassLoader of thread",
"Couldn't rollback jdbc connection", "Database connection shutdown unsuccessful"));
Expand Down
3 changes: 0 additions & 3 deletions extensions/quartz/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,30 @@

import io.quarkus.runtime.annotations.ConfigDocMapKey;
import io.quarkus.runtime.annotations.ConfigDocSection;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;
import io.smallrye.config.WithName;

@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
public class QuartzBuildTimeConfig {
@ConfigMapping(prefix = "quarkus.quartz")
public interface QuartzBuildTimeConfig {
/**
* Enable cluster mode or not.
* <p>
* If enabled make sure to set the appropriate cluster properties.
*/
@ConfigItem
public boolean clustered;
@WithDefault("false")
boolean clustered();

/**
* The frequency (in milliseconds) at which the scheduler instance checks-in with other instances of the cluster.
* <p>
* Ignored if using a `ram` store i.e {@link StoreType#RAM}.
*/
@ConfigItem(defaultValue = "15000")
public long clusterCheckinInterval;
@WithDefault("15000")
long clusterCheckinInterval();

/**
* The type of store to use.
Expand All @@ -39,17 +42,17 @@ public class QuartzBuildTimeConfig {
* "https://github.com/quartz-scheduler/quartz/blob/master/quartz-core/src/main/resources/org/quartz/impl/jdbcjobstore">Quartz
* repository</a>.
*/
@ConfigItem(defaultValue = "ram")
public StoreType storeType;
@WithDefault("ram")
StoreType storeType();

/**
* The class name of the thread pool implementation to use.
* <p>
* It's important to bear in mind that Quartz threads are not used to execute scheduled methods, instead the regular Quarkus
* thread pool is used by default. See also {@code quarkus.quartz.run-blocking-scheduled-method-on-quartz-thread}.
*/
@ConfigItem(defaultValue = "org.quartz.simpl.SimpleThreadPool")
public String threadPoolClass;
@WithDefault("org.quartz.simpl.SimpleThreadPool")
String threadPoolClass();

/**
* The name of the datasource to use.
Expand All @@ -59,16 +62,16 @@ public class QuartzBuildTimeConfig {
* Optionally needed when using the `jdbc-tx` or `jdbc-cmt` store types.
* If not specified, defaults to using the default datasource.
*/
@ConfigItem(name = "datasource")
public Optional<String> dataSourceName;
@WithName("datasource")
Optional<String> dataSourceName();

/**
* The prefix for quartz job store tables.
* <p>
* Ignored if using a `ram` store i.e {@link StoreType#RAM}
*/
@ConfigItem(defaultValue = "QRTZ_")
public String tablePrefix;
@WithDefault("QRTZ_")
String tablePrefix();

/**
* The SQL string that selects a row in the "LOCKS" table and places a lock on the row.
Expand All @@ -80,8 +83,7 @@ public class QuartzBuildTimeConfig {
* <p>
* An example SQL string `SELECT * FROM {0}LOCKS WHERE SCHED_NAME = {1} AND LOCK_NAME = ? FOR UPDATE`
*/
@ConfigItem
public Optional<String> selectWithLockSql;
Optional<String> selectWithLockSql();

/**
* Allows users to specify fully qualified class name for a custom JDBC driver delegate.
Expand All @@ -93,8 +95,7 @@ public class QuartzBuildTimeConfig {
* {@link io.quarkus.quartz.runtime.jdbc.QuarkusPostgreSQLDelegate} or
* {@link io.quarkus.quartz.runtime.jdbc.QuarkusMSSQLDelegate}
*/
@ConfigItem
public Optional<String> driverDelegate;
Optional<String> driverDelegate();

/**
* Instructs JDBCJobStore to serialize JobDataMaps in the BLOB column.
Expand All @@ -113,36 +114,34 @@ public class QuartzBuildTimeConfig {
* a BLOB.
* This is equivalent of setting `org.quartz.jobStore.useProperties` to `true`.
*/
@ConfigItem(defaultValue = "false")
public Optional<Boolean> serializeJobData;
@WithDefault("false")
Optional<Boolean> serializeJobData();

/**
* Instance ID generators.
*/
@ConfigItem
@ConfigDocMapKey("generator-name")
@ConfigDocSection
public Map<String, QuartzExtensionPointConfig> instanceIdGenerators;
Map<String, QuartzExtensionPointConfig> instanceIdGenerators();

/**
* Trigger listeners.
*/
@ConfigItem
@ConfigDocMapKey("listener-name")
@ConfigDocSection
public Map<String, QuartzExtensionPointConfig> triggerListeners;
Map<String, QuartzExtensionPointConfig> triggerListeners();

/**
* Job listeners.
*/
@ConfigItem
@ConfigDocMapKey("listener-name")
@ConfigDocSection
public Map<String, QuartzExtensionPointConfig> jobListeners;
Map<String, QuartzExtensionPointConfig> jobListeners();

/**
* Plugins.
*/
@ConfigItem
@ConfigDocMapKey("plugin-name")
@ConfigDocSection
public Map<String, QuartzExtensionPointConfig> plugins;
Map<String, QuartzExtensionPointConfig> plugins();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
import java.util.Map;

import io.quarkus.runtime.annotations.ConfigDocMapKey;
import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithName;

@ConfigGroup
public class QuartzExtensionPointConfig {
@ConfigMapping
public interface QuartzExtensionPointConfig {
/**
* Class name for the configuration.
*/
@ConfigItem(name = "class")
public String clazz;
@WithName("class")
String clazz();

/**
* The properties passed to the class.
*/
@ConfigItem
@ConfigDocMapKey("property-key")
public Map<String, String> properties;
Map<String, String> properties();
}
Loading

0 comments on commit 2822a90

Please sign in to comment.