From 1b7cefb00b1c956f448de1678f58deb1b8884ea5 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Thu, 30 Mar 2023 17:59:49 +0200 Subject: [PATCH 1/5] Add @ConfigDocDefault to override default value doc for @ConfigMapping --- .../annotation/processor/Constants.java | 1 + .../generate_doc/ConfigDocItemFinder.java | 16 ++++++------ .../runtime/annotations/ConfigDocDefault.java | 25 +++++++++++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 core/runtime/src/main/java/io/quarkus/runtime/annotations/ConfigDocDefault.java diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/Constants.java b/core/processor/src/main/java/io/quarkus/annotation/processor/Constants.java index 776c1eebf8879..5dd32bc4c85dc 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/Constants.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/Constants.java @@ -61,6 +61,7 @@ final public class Constants { public static final String ANNOTATION_CONFIG_DOC_MAP_KEY = "io.quarkus.runtime.annotations.ConfigDocMapKey"; public static final String ANNOTATION_CONFIG_DOC_SECTION = "io.quarkus.runtime.annotations.ConfigDocSection"; public static final String ANNOTATION_CONFIG_DOC_ENUM_VALUE = "io.quarkus.runtime.annotations.ConfigDocEnumValue"; + public static final String ANNOTATION_CONFIG_DOC_DEFAULT = "io.quarkus.runtime.annotations.ConfigDocDefault"; public static final String ANNOTATION_CONFIG_WITH_NAME = "io.smallrye.config.WithName"; public static final String ANNOTATION_CONFIG_WITH_DEFAULT = "io.smallrye.config.WithDefault"; diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java b/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java index d4c86ede61c9a..ee5374595e209 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java @@ -1,5 +1,6 @@ package io.quarkus.annotation.processor.generate_doc; +import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_DOC_DEFAULT; import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_DOC_ENUM_VALUE; import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_DOC_MAP_KEY; import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_DOC_SECTION; @@ -223,14 +224,13 @@ private List recursivelyFindConfigItems(Element element, String r } // Mappings - for (Map.Entry entry : annotationMirror - .getElementValues().entrySet()) { - Object value = entry.getValue().getValue(); - if (annotationName.equals(ANNOTATION_CONFIG_WITH_NAME)) { - name = parentName + DOT + value; - } else if (annotationName.equals(ANNOTATION_CONFIG_WITH_DEFAULT)) { - defaultValue = value.toString(); - } + if (annotationName.equals(ANNOTATION_CONFIG_WITH_NAME)) { + name = parentName + DOT + annotationMirror.getElementValues().values().iterator().next().getValue(); + } else if (annotationName.equals(ANNOTATION_CONFIG_DOC_DEFAULT)) { + defaultValue = annotationMirror.getElementValues().values().iterator().next().getValue().toString(); + } else if (annotationName.equals(ANNOTATION_CONFIG_WITH_DEFAULT) + && defaultValue == null) { + defaultValue = annotationMirror.getElementValues().values().iterator().next().getValue().toString(); } } diff --git a/core/runtime/src/main/java/io/quarkus/runtime/annotations/ConfigDocDefault.java b/core/runtime/src/main/java/io/quarkus/runtime/annotations/ConfigDocDefault.java new file mode 100644 index 0000000000000..b96723d2bbc47 --- /dev/null +++ b/core/runtime/src/main/java/io/quarkus/runtime/annotations/ConfigDocDefault.java @@ -0,0 +1,25 @@ +package io.quarkus.runtime.annotations; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.SOURCE; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import io.smallrye.config.ConfigMapping; + +/** + * Specifies a default value for the documentation. + *

+ * Replaces defaultValueForDocumentation for the {@link ConfigMapping} approach. + */ +@Documented +@Retention(SOURCE) +@Target({ FIELD, PARAMETER, METHOD }) +public @interface ConfigDocDefault { + + String value(); +} From 42aa4e63115ace6342ae1cca5d077f8368faa0c2 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Thu, 30 Mar 2023 18:00:22 +0200 Subject: [PATCH 2/5] Switch Hibernate Search extension to @ConfigMapping --- ...HibernateSearchOutboxPollingProcessor.java | 2 +- ...HibernateSearchElasticsearchProcessor.java | 26 +-- .../deployment/HibernateSearchEnabled.java | 2 +- ...ateSearchElasticsearchBuildTimeConfig.java | 45 ++++- ...csearchBuildTimeConfigPersistenceUnit.java | 81 ++++---- .../HibernateSearchElasticsearchRecorder.java | 91 +++++---- ...rnateSearchElasticsearchRuntimeConfig.java | 24 ++- ...ticsearchRuntimeConfigPersistenceUnit.java | 188 +++++++++--------- ...bernateSearchElasticsearchDevRecorder.java | 2 +- 9 files changed, 236 insertions(+), 225 deletions(-) diff --git a/extensions/hibernate-search-orm-coordination-outbox-polling/deployment/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/deployment/HibernateSearchOutboxPollingProcessor.java b/extensions/hibernate-search-orm-coordination-outbox-polling/deployment/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/deployment/HibernateSearchOutboxPollingProcessor.java index d26cf83fb8ffc..c98d6c8d0ea19 100644 --- a/extensions/hibernate-search-orm-coordination-outbox-polling/deployment/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/deployment/HibernateSearchOutboxPollingProcessor.java +++ b/extensions/hibernate-search-orm-coordination-outbox-polling/deployment/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/deployment/HibernateSearchOutboxPollingProcessor.java @@ -80,7 +80,7 @@ private boolean isUsingOutboxPolling(HibernateSearchElasticsearchPersistenceUnit if (puConfig == null) { return false; } - Optional configuredStrategy = puConfig.coordination.strategy; + Optional configuredStrategy = puConfig.coordination().strategy(); return configuredStrategy.isPresent() && configuredStrategy.get().equals(HibernateOrmMapperOutboxPollingSettings.COORDINATION_STRATEGY_NAME); } diff --git a/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/deployment/HibernateSearchElasticsearchProcessor.java b/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/deployment/HibernateSearchElasticsearchProcessor.java index c18a01e14144a..1c1a1a7012959 100644 --- a/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/deployment/HibernateSearchElasticsearchProcessor.java +++ b/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/deployment/HibernateSearchElasticsearchProcessor.java @@ -68,12 +68,11 @@ class HibernateSearchElasticsearchProcessor { private static final Logger LOG = Logger.getLogger(HibernateSearchElasticsearchProcessor.class); - HibernateSearchElasticsearchBuildTimeConfig buildTimeConfig; - @BuildStep @Record(ExecutionTime.STATIC_INIT) public void build(HibernateSearchElasticsearchRecorder recorder, CombinedIndexBuildItem combinedIndexBuildItem, + HibernateSearchElasticsearchBuildTimeConfig buildTimeConfig, List persistenceUnitDescriptorBuildItems, BuildProducer reflectiveClass, BuildProducer configuredPersistenceUnits, @@ -176,6 +175,7 @@ void registerBeans(List integrationStaticConfigBuildItems, List configuredPersistenceUnits, + HibernateSearchElasticsearchBuildTimeConfig buildTimeConfig, BuildProducer staticConfigured) { // Make it possible to record the settings as bytecode: recorderContext.registerSubstitution(ElasticsearchVersion.class, @@ -199,7 +199,8 @@ void setStaticConfig(RecorderContext recorderContext, HibernateSearchElasticsear staticConfigured.produce( new HibernateOrmIntegrationStaticConfiguredBuildItem(HIBERNATE_SEARCH_ELASTICSEARCH, puName) .setInitListener( - recorder.createStaticInitListener(puName, configuredPersistenceUnit.getBuildTimeConfig(), + // we cannot pass a config group to a recorder so passing the whole config + recorder.createStaticInitListener(puName, buildTimeConfig, configuredPersistenceUnit.getBackendAndIndexNamesForSearchExtensions(), integrationStaticInitListeners)) .setXmlMappingRequired(xmlMappingRequired)); @@ -265,7 +266,7 @@ private void processPersistenceUnitBuildTimeConfig( for (String backendName : allBackendNames) { ElasticsearchBackendBuildTimeConfig backendConfig = backends.get(backendName); // ... we validate that the backend is configured and the version is present - if (backendConfig == null || backendConfig.version.isEmpty()) { + if (backendConfig == null || backendConfig.version().isEmpty()) { propertyKeysWithNoVersion.add(elasticsearchVersionPropertyKey(persistenceUnitName, backendName)); } // ... we register files referenced from backends configuration @@ -287,9 +288,9 @@ private static void registerClasspathFileFromBackendConfig(String persistenceUni ApplicationArchivesBuildItem applicationArchivesBuildItem, BuildProducer nativeImageResources, BuildProducer hotDeploymentWatchedFiles) { - registerClasspathFileFromIndexConfig(persistenceUnitName, backendName, null, backendConfig.indexDefaults, + registerClasspathFileFromIndexConfig(persistenceUnitName, backendName, null, backendConfig.indexDefaults(), applicationArchivesBuildItem, nativeImageResources, hotDeploymentWatchedFiles); - for (Entry entry : backendConfig.indexes.entrySet()) { + for (Entry entry : backendConfig.indexes().entrySet()) { String indexName = entry.getKey(); ElasticsearchIndexBuildTimeConfig indexConfig = entry.getValue(); registerClasspathFileFromIndexConfig(persistenceUnitName, backendName, indexName, indexConfig, @@ -303,10 +304,10 @@ private static void registerClasspathFileFromIndexConfig(String persistenceUnitN BuildProducer nativeImageResources, BuildProducer hotDeploymentWatchedFiles) { registerClasspathFileFromConfig(persistenceUnitName, backendName, indexName, "schema-management.settings-file", - indexConfig.schemaManagement.settingsFile, + indexConfig.schemaManagement().settingsFile(), applicationArchivesBuildItem, nativeImageResources, hotDeploymentWatchedFiles); registerClasspathFileFromConfig(persistenceUnitName, backendName, indexName, "schema-management.mapping-file", - indexConfig.schemaManagement.mappingFile, + indexConfig.schemaManagement().mappingFile(), applicationArchivesBuildItem, nativeImageResources, hotDeploymentWatchedFiles); } @@ -342,10 +343,11 @@ private void registerReflectionForGson(BuildProducer r @BuildStep DevservicesElasticsearchBuildItem devServices(HibernateSearchElasticsearchBuildTimeConfig buildTimeConfig) { - if (buildTimeConfig.defaultPersistenceUnit != null && buildTimeConfig.defaultPersistenceUnit.defaultBackend != null - // If the version is not set, the default backend is not in use. - && buildTimeConfig.defaultPersistenceUnit.defaultBackend.version.isPresent()) { - ElasticsearchVersion version = buildTimeConfig.defaultPersistenceUnit.defaultBackend.version.get(); + if (buildTimeConfig.defaultPersistenceUnit() != null + && buildTimeConfig.defaultPersistenceUnit().defaultBackend() != null + // If the version is not set, the default backend is not in use. + && buildTimeConfig.defaultPersistenceUnit().defaultBackend().version().isPresent()) { + ElasticsearchVersion version = buildTimeConfig.defaultPersistenceUnit().defaultBackend().version().get(); String hostsPropertyKey = backendPropertyKey(PersistenceUnitUtil.DEFAULT_PERSISTENCE_UNIT_NAME, null, null, "hosts"); return new DevservicesElasticsearchBuildItem(hostsPropertyKey, diff --git a/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/deployment/HibernateSearchEnabled.java b/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/deployment/HibernateSearchEnabled.java index a979855b48bc4..a1e71566699aa 100644 --- a/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/deployment/HibernateSearchEnabled.java +++ b/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/deployment/HibernateSearchEnabled.java @@ -18,7 +18,7 @@ public class HibernateSearchEnabled implements BooleanSupplier { @Override public boolean getAsBoolean() { - return config.enabled; + return config.enabled(); } } diff --git a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchBuildTimeConfig.java b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchBuildTimeConfig.java index d81b1b5383dc8..62f58be4453c1 100644 --- a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchBuildTimeConfig.java +++ b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchBuildTimeConfig.java @@ -6,12 +6,15 @@ import io.quarkus.hibernate.orm.runtime.PersistenceUnitUtil; 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.WithParentName; -@ConfigRoot(name = "hibernate-search-orm", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) -public class HibernateSearchElasticsearchBuildTimeConfig { +@ConfigMapping(prefix = "quarkus.hibernate-search-orm") +@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) +public interface HibernateSearchElasticsearchBuildTimeConfig { /** * Whether Hibernate Search is enabled **during the build**. @@ -22,30 +25,50 @@ public class HibernateSearchElasticsearchBuildTimeConfig { * * @asciidoclet */ - @ConfigItem(defaultValue = "true") - public boolean enabled; + @WithDefault("true") + boolean enabled(); /** * Configuration for the default persistence unit. */ - @ConfigItem(name = ConfigItem.PARENT) - public HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit defaultPersistenceUnit; + @WithParentName + HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit defaultPersistenceUnit(); /** * Configuration for additional named persistence units. */ @ConfigDocSection @ConfigDocMapKey("persistence-unit-name") - @ConfigItem(name = ConfigItem.PARENT) - Map persistenceUnits; + @WithParentName + Map persistenceUnits(); - public Map getAllPersistenceUnitConfigsAsMap() { + default Map getAllPersistenceUnitConfigsAsMap() { Map map = new TreeMap<>(); + HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit defaultPersistenceUnit = defaultPersistenceUnit(); + if (defaultPersistenceUnit != null) { map.put(PersistenceUnitUtil.DEFAULT_PERSISTENCE_UNIT_NAME, defaultPersistenceUnit); } - map.putAll(persistenceUnits); + map.putAll(persistenceUnits()); return map; } + default HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit getPersistenceUnitConfig(String persistenceUnitName) { + if (persistenceUnitName == null) { + throw new IllegalArgumentException("Persistence unit name may not be null"); + } + + if (PersistenceUnitUtil.DEFAULT_PERSISTENCE_UNIT_NAME.equals(persistenceUnitName)) { + return defaultPersistenceUnit(); + } + + HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit persistenceUnitConfig = persistenceUnits() + .get(persistenceUnitName); + + if (persistenceUnitConfig == null) { + throw new IllegalStateException("No persistence unit config exists for name " + persistenceUnitName); + } + + return persistenceUnitConfig; + } } diff --git a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit.java b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit.java index 02e9a819ec340..e869201715bd9 100644 --- a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit.java +++ b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit.java @@ -9,24 +9,26 @@ import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigDocSection; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.WithDefault; +import io.smallrye.config.WithName; +import io.smallrye.config.WithParentName; @ConfigGroup -public class HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit { +public interface HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit { /** * Default backend */ - @ConfigItem(name = "elasticsearch") @ConfigDocSection - public ElasticsearchBackendBuildTimeConfig defaultBackend; + @WithName("elasticsearch") + ElasticsearchBackendBuildTimeConfig defaultBackend(); /** * Named backends */ - @ConfigItem(name = "elasticsearch") @ConfigDocSection - ElasticsearchNamedBackendsBuildTimeConfig namedBackends; + @WithName("elasticsearch") + ElasticsearchNamedBackendsBuildTimeConfig namedBackends(); /** * A xref:hibernate-search-orm-elasticsearch.adoc#bean-reference-note-anchor[bean reference] to a component @@ -45,39 +47,37 @@ public class HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit { * * @asciidoclet */ - @ConfigItem - public Optional backgroundFailureHandler; + Optional backgroundFailureHandler(); /** * Configuration for coordination between threads or application instances. */ - @ConfigItem - public CoordinationConfig coordination; + CoordinationConfig coordination(); - public Map getAllBackendConfigsAsMap() { + default Map getAllBackendConfigsAsMap() { Map map = new LinkedHashMap<>(); - if (defaultBackend != null) { - map.put(null, defaultBackend); + if (defaultBackend() != null) { + map.put(null, defaultBackend()); } - if (namedBackends != null) { - map.putAll(namedBackends.backends); + if (namedBackends() != null) { + map.putAll(namedBackends().backends()); } return map; } @ConfigGroup - public static class ElasticsearchNamedBackendsBuildTimeConfig { + public interface ElasticsearchNamedBackendsBuildTimeConfig { /** * Named backends */ @ConfigDocMapKey("backend-name") - public Map backends; + public Map backends(); } @ConfigGroup - public static class ElasticsearchBackendBuildTimeConfig { + public interface ElasticsearchBackendBuildTimeConfig { /** * The version of Elasticsearch used in the cluster. * @@ -92,47 +92,42 @@ public static class ElasticsearchBackendBuildTimeConfig { * * @asciidoclet */ - @ConfigItem - public Optional version; + Optional version(); /** * Configuration for the index layout. */ - @ConfigItem - public LayoutConfig layout; + LayoutConfig layout(); /** * The default configuration for the Elasticsearch indexes. */ - @ConfigItem(name = ConfigItem.PARENT) - public ElasticsearchIndexBuildTimeConfig indexDefaults; + @WithParentName + ElasticsearchIndexBuildTimeConfig indexDefaults(); /** * Per-index specific configuration. */ - @ConfigItem @ConfigDocMapKey("index-name") - public Map indexes; + Map indexes(); } @ConfigGroup - public static class ElasticsearchIndexBuildTimeConfig { + public interface ElasticsearchIndexBuildTimeConfig { /** * Configuration for automatic creation and validation of the Elasticsearch schema: * indexes, their mapping, their settings. */ - @ConfigItem - public SchemaManagementConfig schemaManagement; + SchemaManagementConfig schemaManagement(); /** * Configuration for full-text analysis. */ - @ConfigItem - public AnalysisConfig analysis; + AnalysisConfig analysis(); } @ConfigGroup - public static class SchemaManagementConfig { + public interface SchemaManagementConfig { // @formatter:off /** @@ -149,8 +144,7 @@ public static class SchemaManagementConfig { * @asciidoclet */ // @formatter:on - @ConfigItem - public Optional settingsFile; + Optional settingsFile(); // @formatter:off /** @@ -166,13 +160,12 @@ public static class SchemaManagementConfig { * @asciidoclet */ // @formatter:on - @ConfigItem - public Optional mappingFile; + Optional mappingFile(); } @ConfigGroup - public static class AnalysisConfig { + public interface AnalysisConfig { /** * A xref:hibernate-search-orm-elasticsearch.adoc#bean-reference-note-anchor[bean reference] to the component * used to configure full text analysis (e.g. analyzers, normalizers). @@ -192,12 +185,11 @@ public static class AnalysisConfig { * * @asciidoclet */ - @ConfigItem - public Optional configurer; + Optional configurer(); } @ConfigGroup - public static class LayoutConfig { + public interface LayoutConfig { /** * A xref:hibernate-search-orm-elasticsearch.adoc#bean-reference-note-anchor[bean reference] to the component * used to configure layout (e.g. index names, index aliases). @@ -229,12 +221,11 @@ public static class LayoutConfig { * * @asciidoclet */ - @ConfigItem - public Optional strategy; + Optional strategy(); } @ConfigGroup - public static class CoordinationConfig { + public interface CoordinationConfig { /** * The strategy to use for coordinating between threads or even separate instances of the application, @@ -244,8 +235,8 @@ public static class CoordinationConfig { * * @asciidoclet */ - @ConfigItem(defaultValue = "none") - public Optional strategy; + @WithDefault("none") + Optional strategy(); } } diff --git a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRecorder.java b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRecorder.java index 994e9caa7dc5f..bccae5d686b7c 100644 --- a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRecorder.java +++ b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRecorder.java @@ -54,10 +54,11 @@ public class HibernateSearchElasticsearchRecorder { public HibernateOrmIntegrationStaticInitListener createStaticInitListener( - String persistenceUnitName, HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit buildTimeConfig, + String persistenceUnitName, HibernateSearchElasticsearchBuildTimeConfig buildTimeConfig, Map> backendAndIndexNamesForSearchExtensions, List integrationStaticInitListeners) { - return new HibernateSearchIntegrationStaticInitListener(persistenceUnitName, buildTimeConfig, + return new HibernateSearchIntegrationStaticInitListener(persistenceUnitName, + buildTimeConfig.getPersistenceUnitConfig(persistenceUnitName), backendAndIndexNamesForSearchExtensions, integrationStaticInitListeners); } @@ -78,7 +79,7 @@ public HibernateOrmIntegrationRuntimeInitListener createRuntimeInitListener( public void checkNoExplicitActiveTrue(HibernateSearchElasticsearchRuntimeConfig runtimeConfig) { for (var entry : runtimeConfig.getAllPersistenceUnitConfigsAsMap().entrySet()) { var config = entry.getValue(); - if (config.active.orElse(false)) { + if (config.active().orElse(false)) { var puName = entry.getKey(); String enabledPropertyKey = HibernateSearchElasticsearchRuntimeConfig.extensionPropertyKey("enabled"); String activePropertyKey = HibernateSearchElasticsearchRuntimeConfig.mapperPropertyKey(puName, "active"); @@ -107,7 +108,7 @@ public Supplier searchMappingSupplier(HibernateSearchElasticsearc public SearchMapping get() { HibernateSearchElasticsearchRuntimeConfigPersistenceUnit puRuntimeConfig = runtimeConfig .getAllPersistenceUnitConfigsAsMap().get(persistenceUnitName); - if (puRuntimeConfig != null && !puRuntimeConfig.active.orElse(true)) { + if (puRuntimeConfig != null && !puRuntimeConfig.active().orElse(true)) { throw new IllegalStateException( "Cannot retrieve the SearchMapping for persistence unit " + persistenceUnitName + ": Hibernate Search was deactivated through configuration properties"); @@ -131,7 +132,7 @@ public Supplier searchSessionSupplier(HibernateSearchElasticsearc public SearchSession get() { HibernateSearchElasticsearchRuntimeConfigPersistenceUnit puRuntimeConfig = runtimeConfig .getAllPersistenceUnitConfigsAsMap().get(persistenceUnitName); - if (puRuntimeConfig != null && !puRuntimeConfig.active.orElse(true)) { + if (puRuntimeConfig != null && !puRuntimeConfig.active().orElse(true)) { throw new IllegalStateException( "Cannot retrieve the SearchSession for persistence unit " + persistenceUnitName + ": Hibernate Search was deactivated through configuration properties"); @@ -187,13 +188,13 @@ public void contributeBootProperties(BiConsumer propertyCollecto addConfig(propertyCollector, EngineSettings.BACKGROUND_FAILURE_HANDLER, HibernateSearchBeanUtil.singleExtensionBeanReferenceFor( - buildTimeConfig == null ? Optional.empty() : buildTimeConfig.backgroundFailureHandler, + buildTimeConfig == null ? Optional.empty() : buildTimeConfig.backgroundFailureHandler(), FailureHandler.class, persistenceUnitName, null, null)); addConfig(propertyCollector, HibernateOrmMapperSettings.COORDINATION_STRATEGY, HibernateSearchBeanUtil.singleExtensionBeanReferenceFor( - buildTimeConfig == null ? Optional.empty() : buildTimeConfig.coordination.strategy, + buildTimeConfig == null ? Optional.empty() : buildTimeConfig.coordination().strategy(), CoordinationStrategy.class, persistenceUnitName, null, null)); // We need this weird collecting of names from both @SearchExtension and the configuration properties @@ -206,7 +207,7 @@ public void contributeBootProperties(BiConsumer propertyCollecto Map> backendAndIndexNames = new LinkedHashMap<>(); mergeInto(backendAndIndexNames, backendAndIndexNamesForSearchExtensions); for (Entry entry : backendConfigs.entrySet()) { - mergeInto(backendAndIndexNames, entry.getKey(), entry.getValue().indexes.keySet()); + mergeInto(backendAndIndexNames, entry.getKey(), entry.getValue().indexes().keySet()); } for (Entry> entry : backendAndIndexNames.entrySet()) { @@ -242,24 +243,25 @@ private void contributeBackendBuildTimeProperties(BiConsumer pro ElasticsearchBackendSettings.TYPE_NAME); if (elasticsearchBackendConfig != null) { addBackendConfig(propertyCollector, backendName, ElasticsearchBackendSettings.VERSION, - elasticsearchBackendConfig.version); + elasticsearchBackendConfig.version()); } // Settings that may default to a @SearchExtension-annotated-bean addBackendConfig(propertyCollector, backendName, ElasticsearchBackendSettings.LAYOUT_STRATEGY, HibernateSearchBeanUtil.singleExtensionBeanReferenceFor( - elasticsearchBackendConfig == null ? Optional.empty() : elasticsearchBackendConfig.layout.strategy, + elasticsearchBackendConfig == null ? Optional.empty() + : elasticsearchBackendConfig.layout().strategy(), IndexLayoutStrategy.class, persistenceUnitName, backendName, null)); // Index defaults at the backend level contributeBackendIndexBuildTimeProperties(propertyCollector, backendName, null, - elasticsearchBackendConfig == null ? null : elasticsearchBackendConfig.indexDefaults); + elasticsearchBackendConfig == null ? null : elasticsearchBackendConfig.indexDefaults()); // Per-index properties for (String indexName : indexNames) { ElasticsearchIndexBuildTimeConfig indexConfig = elasticsearchBackendConfig == null ? null - : elasticsearchBackendConfig.indexes.get(indexName); + : elasticsearchBackendConfig.indexes().get(indexName); contributeBackendIndexBuildTimeProperties(propertyCollector, backendName, indexName, indexConfig); } } @@ -269,17 +271,17 @@ private void contributeBackendIndexBuildTimeProperties(BiConsumer propertyCollector) { if (runtimeConfig != null) { - if (!runtimeConfig.active.orElse(true)) { + if (!runtimeConfig.active().orElse(true)) { addConfig(propertyCollector, HibernateOrmMapperSettings.ENABLED, false); // Do not process other properties: Hibernate Search is disabled anyway. return; @@ -335,25 +337,26 @@ public void contributeRuntimeProperties(BiConsumer propertyColle addConfig(propertyCollector, HibernateOrmMapperSettings.SCHEMA_MANAGEMENT_STRATEGY, - runtimeConfig.schemaManagement.strategy); + runtimeConfig.schemaManagement().strategy()); addConfig(propertyCollector, HibernateOrmMapperSettings.AUTOMATIC_INDEXING_ENABLE_DIRTY_CHECK, - runtimeConfig.automaticIndexing.enableDirtyCheck); + runtimeConfig.automaticIndexing().enableDirtyCheck()); addConfig(propertyCollector, HibernateOrmMapperSettings.QUERY_LOADING_CACHE_LOOKUP_STRATEGY, - runtimeConfig.queryLoading.cacheLookup.strategy); + runtimeConfig.queryLoading().cacheLookup().strategy()); addConfig(propertyCollector, HibernateOrmMapperSettings.QUERY_LOADING_FETCH_SIZE, - runtimeConfig.queryLoading.fetchSize); + runtimeConfig.queryLoading().fetchSize()); addConfig(propertyCollector, HibernateOrmMapperSettings.MULTI_TENANCY_TENANT_IDS, - runtimeConfig.multiTenancy.tenantIds); + runtimeConfig.multiTenancy().tenantIds()); } addConfig(propertyCollector, HibernateOrmMapperSettings.AUTOMATIC_INDEXING_SYNCHRONIZATION_STRATEGY, HibernateSearchBeanUtil.singleExtensionBeanReferenceFor( - runtimeConfig == null ? Optional.empty() : runtimeConfig.automaticIndexing.synchronization.strategy, + runtimeConfig == null ? Optional.empty() + : runtimeConfig.automaticIndexing().synchronization().strategy(), AutomaticIndexingSynchronizationStrategy.class, persistenceUnitName, null, null)); // We need this weird collecting of names from both @SearchExtension and the configuration properties @@ -366,7 +369,7 @@ public void contributeRuntimeProperties(BiConsumer propertyColle Map> backendAndIndexNames = new LinkedHashMap<>(); mergeInto(backendAndIndexNames, backendAndIndexNamesForSearchExtensions); for (Entry entry : backendConfigs.entrySet()) { - mergeInto(backendAndIndexNames, entry.getKey(), entry.getValue().indexes.keySet()); + mergeInto(backendAndIndexNames, entry.getKey(), entry.getValue().indexes().keySet()); } for (Entry> entry : backendAndIndexNames.entrySet()) { @@ -385,33 +388,33 @@ private void contributeBackendRuntimeProperties(BiConsumer prope Set indexNames, ElasticsearchBackendRuntimeConfig elasticsearchBackendConfig) { if (elasticsearchBackendConfig != null) { addBackendConfig(propertyCollector, backendName, ElasticsearchBackendSettings.HOSTS, - elasticsearchBackendConfig.hosts); + elasticsearchBackendConfig.hosts()); addBackendConfig(propertyCollector, backendName, ElasticsearchBackendSettings.PROTOCOL, - elasticsearchBackendConfig.protocol.getHibernateSearchString()); + elasticsearchBackendConfig.protocol().getHibernateSearchString()); addBackendConfig(propertyCollector, backendName, ElasticsearchBackendSettings.USERNAME, - elasticsearchBackendConfig.username); + elasticsearchBackendConfig.username()); addBackendConfig(propertyCollector, backendName, ElasticsearchBackendSettings.PASSWORD, - elasticsearchBackendConfig.password); + elasticsearchBackendConfig.password()); addBackendConfig(propertyCollector, backendName, ElasticsearchBackendSettings.CONNECTION_TIMEOUT, - elasticsearchBackendConfig.connectionTimeout.toMillis()); + elasticsearchBackendConfig.connectionTimeout().toMillis()); addBackendConfig(propertyCollector, backendName, ElasticsearchBackendSettings.READ_TIMEOUT, - elasticsearchBackendConfig.readTimeout.toMillis()); + elasticsearchBackendConfig.readTimeout().toMillis()); addBackendConfig(propertyCollector, backendName, ElasticsearchBackendSettings.REQUEST_TIMEOUT, - elasticsearchBackendConfig.requestTimeout, Optional::isPresent, d -> d.get().toMillis()); + elasticsearchBackendConfig.requestTimeout(), Optional::isPresent, d -> d.get().toMillis()); addBackendConfig(propertyCollector, backendName, ElasticsearchBackendSettings.MAX_CONNECTIONS, - elasticsearchBackendConfig.maxConnections); + elasticsearchBackendConfig.maxConnections()); addBackendConfig(propertyCollector, backendName, ElasticsearchBackendSettings.MAX_CONNECTIONS_PER_ROUTE, - elasticsearchBackendConfig.maxConnectionsPerRoute); + elasticsearchBackendConfig.maxConnectionsPerRoute()); addBackendConfig(propertyCollector, backendName, ElasticsearchBackendSettings.THREAD_POOL_SIZE, - elasticsearchBackendConfig.threadPool.size); + elasticsearchBackendConfig.threadPool().size()); addBackendConfig(propertyCollector, backendName, ElasticsearchBackendSettings.VERSION_CHECK_ENABLED, - elasticsearchBackendConfig.versionCheck); + elasticsearchBackendConfig.versionCheck()); addBackendConfig(propertyCollector, backendName, ElasticsearchBackendSettings.DISCOVERY_ENABLED, - elasticsearchBackendConfig.discovery.enabled); - if (elasticsearchBackendConfig.discovery.enabled) { + elasticsearchBackendConfig.discovery().enabled()); + if (elasticsearchBackendConfig.discovery().enabled()) { addBackendConfig(propertyCollector, backendName, ElasticsearchBackendSettings.DISCOVERY_REFRESH_INTERVAL, - elasticsearchBackendConfig.discovery.refreshInterval.getSeconds()); + elasticsearchBackendConfig.discovery().refreshInterval().getSeconds()); } } @@ -420,12 +423,12 @@ private void contributeBackendRuntimeProperties(BiConsumer prope // Index defaults at the backend level contributeBackendIndexRuntimeProperties(propertyCollector, backendName, null, - elasticsearchBackendConfig == null ? null : elasticsearchBackendConfig.indexDefaults); + elasticsearchBackendConfig == null ? null : elasticsearchBackendConfig.indexDefaults()); // Per-index properties for (String indexName : indexNames) { ElasticsearchIndexRuntimeConfig indexConfig = elasticsearchBackendConfig == null ? null - : elasticsearchBackendConfig.indexes.get(indexName); + : elasticsearchBackendConfig.indexes().get(indexName); contributeBackendIndexRuntimeProperties(propertyCollector, backendName, indexName, indexConfig); } } @@ -435,20 +438,20 @@ private void contributeBackendIndexRuntimeProperties(BiConsumer if (indexConfig != null) { addBackendIndexConfig(propertyCollector, backendName, indexName, ElasticsearchIndexSettings.SCHEMA_MANAGEMENT_MINIMAL_REQUIRED_STATUS, - indexConfig.schemaManagement.requiredStatus); + indexConfig.schemaManagement().requiredStatus()); addBackendIndexConfig(propertyCollector, backendName, indexName, ElasticsearchIndexSettings.SCHEMA_MANAGEMENT_MINIMAL_REQUIRED_STATUS_WAIT_TIMEOUT, - indexConfig.schemaManagement.requiredStatusWaitTimeout, Optional::isPresent, + indexConfig.schemaManagement().requiredStatusWaitTimeout(), Optional::isPresent, d -> d.get().toMillis()); addBackendIndexConfig(propertyCollector, backendName, indexName, ElasticsearchIndexSettings.INDEXING_QUEUE_COUNT, - indexConfig.indexing.queueCount); + indexConfig.indexing().queueCount()); addBackendIndexConfig(propertyCollector, backendName, indexName, ElasticsearchIndexSettings.INDEXING_QUEUE_SIZE, - indexConfig.indexing.queueSize); + indexConfig.indexing().queueSize()); addBackendIndexConfig(propertyCollector, backendName, indexName, ElasticsearchIndexSettings.INDEXING_MAX_BULK_SIZE, - indexConfig.indexing.maxBulkSize); + indexConfig.indexing().maxBulkSize()); } // Settings that may default to a @SearchExtension-annotated-bean diff --git a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRuntimeConfig.java b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRuntimeConfig.java index 361c6eb7092f5..10cc3e5073f35 100644 --- a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRuntimeConfig.java +++ b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRuntimeConfig.java @@ -7,33 +7,35 @@ import io.quarkus.hibernate.orm.runtime.PersistenceUnitUtil; 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.WithParentName; -@ConfigRoot(name = "hibernate-search-orm", phase = ConfigPhase.RUN_TIME) -public class HibernateSearchElasticsearchRuntimeConfig { +@ConfigMapping(prefix = "quarkus.hibernate-search-orm") +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +public interface HibernateSearchElasticsearchRuntimeConfig { /** * Configuration for the default persistence unit. */ - @ConfigItem(name = ConfigItem.PARENT) - public HibernateSearchElasticsearchRuntimeConfigPersistenceUnit defaultPersistenceUnit; + @WithParentName + HibernateSearchElasticsearchRuntimeConfigPersistenceUnit defaultPersistenceUnit(); /** * Configuration for additional named persistence units. */ @ConfigDocSection @ConfigDocMapKey("persistence-unit-name") - @ConfigItem(name = ConfigItem.PARENT) - public Map persistenceUnits; + @WithParentName + Map persistenceUnits(); - public Map getAllPersistenceUnitConfigsAsMap() { + default Map getAllPersistenceUnitConfigsAsMap() { Map map = new TreeMap<>(); - if (defaultPersistenceUnit != null) { - map.put(PersistenceUnitUtil.DEFAULT_PERSISTENCE_UNIT_NAME, defaultPersistenceUnit); + if (defaultPersistenceUnit() != null) { + map.put(PersistenceUnitUtil.DEFAULT_PERSISTENCE_UNIT_NAME, defaultPersistenceUnit()); } - map.putAll(persistenceUnits); + map.putAll(persistenceUnits()); return map; } diff --git a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRuntimeConfigPersistenceUnit.java b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRuntimeConfigPersistenceUnit.java index b84373de6cb15..a0c0744352bd7 100644 --- a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRuntimeConfigPersistenceUnit.java +++ b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRuntimeConfigPersistenceUnit.java @@ -14,13 +14,16 @@ import org.hibernate.search.mapper.orm.search.loading.EntityLoadingCacheLookupStrategy; import org.hibernate.search.util.common.SearchException; +import io.quarkus.runtime.annotations.ConfigDocDefault; import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigDocSection; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.WithDefault; +import io.smallrye.config.WithName; +import io.smallrye.config.WithParentName; @ConfigGroup -public class HibernateSearchElasticsearchRuntimeConfigPersistenceUnit { +public interface HibernateSearchElasticsearchRuntimeConfigPersistenceUnit { /** * Whether Hibernate Search should be active for this persistence unit at runtime. @@ -34,108 +37,103 @@ public class HibernateSearchElasticsearchRuntimeConfigPersistenceUnit { * * @asciidoclet */ - @ConfigItem(defaultValueDocumentation = "'true' if Hibernate Search is enabled; 'false' otherwise") - public Optional active; + @ConfigDocDefault("'true' if Hibernate Search is enabled; 'false' otherwise") + Optional active(); /** * Default backend */ - @ConfigItem(name = "elasticsearch") + @WithName("elasticsearch") @ConfigDocSection - ElasticsearchBackendRuntimeConfig defaultBackend; + ElasticsearchBackendRuntimeConfig defaultBackend(); /** * Named backends */ - @ConfigItem(name = "elasticsearch") + @WithName("elasticsearch") @ConfigDocSection - ElasticsearchNamedBackendsRuntimeConfig namedBackends; + ElasticsearchNamedBackendsRuntimeConfig namedBackends(); /** * Configuration for automatic creation and validation of the Elasticsearch schema: * indexes, their mapping, their settings. */ - @ConfigItem - SchemaManagementConfig schemaManagement; + SchemaManagementConfig schemaManagement(); /** * Configuration for how entities are loaded by a search query. */ - @ConfigItem(name = "query.loading") - SearchQueryLoadingConfig queryLoading; + @WithName("query.loading") + SearchQueryLoadingConfig queryLoading(); /** * Configuration for the automatic indexing. */ - @ConfigItem - AutomaticIndexingConfig automaticIndexing; + AutomaticIndexingConfig automaticIndexing(); /** * Configuration for multi-tenancy. */ - @ConfigItem - MultiTenancyConfig multiTenancy; + MultiTenancyConfig multiTenancy(); - Map getAllBackendConfigsAsMap() { + default Map getAllBackendConfigsAsMap() { Map map = new LinkedHashMap<>(); - if (defaultBackend != null) { - map.put(null, defaultBackend); + if (defaultBackend() != null) { + map.put(null, defaultBackend()); } - if (namedBackends != null) { - map.putAll(namedBackends.backends); + if (namedBackends() != null) { + map.putAll(namedBackends().backends()); } return map; } @ConfigGroup - public static class ElasticsearchNamedBackendsRuntimeConfig { + public interface ElasticsearchNamedBackendsRuntimeConfig { /** * Named backends */ @ConfigDocMapKey("backend-name") - public Map backends; + Map backends(); } @ConfigGroup - public static class ElasticsearchBackendRuntimeConfig { + public interface ElasticsearchBackendRuntimeConfig { /** * The list of hosts of the Elasticsearch servers. */ - @ConfigItem(defaultValue = "localhost:9200") - List hosts; + @WithDefault("localhost:9200") + List hosts(); /** * The protocol to use when contacting Elasticsearch servers. * Set to "https" to enable SSL/TLS. */ - @ConfigItem(defaultValue = "http") - ElasticsearchClientProtocol protocol; + @WithDefault("http") + ElasticsearchClientProtocol protocol(); /** * The username used for authentication. */ - @ConfigItem - Optional username; + Optional username(); /** * The password used for authentication. */ - @ConfigItem - Optional password; + Optional password(); /** * The timeout when establishing a connection to an Elasticsearch server. */ - @ConfigItem(defaultValue = "1S") - Duration connectionTimeout; + @WithDefault("1S") + Duration connectionTimeout(); /** * The timeout when reading responses from an Elasticsearch server. */ - @ConfigItem(defaultValue = "30S") - Duration readTimeout; + @WithDefault("30S") + Duration readTimeout(); /** * The timeout when executing a request to an Elasticsearch server. @@ -145,32 +143,29 @@ public static class ElasticsearchBackendRuntimeConfig { * * @asciidoclet */ - @ConfigItem - Optional requestTimeout; + Optional requestTimeout(); /** * The maximum number of connections to all the Elasticsearch servers. */ - @ConfigItem(defaultValue = "20") - int maxConnections; + @WithDefault("20") + int maxConnections(); /** * The maximum number of connections per Elasticsearch server. */ - @ConfigItem(defaultValue = "10") - int maxConnectionsPerRoute; + @WithDefault("10") + int maxConnectionsPerRoute(); /** * Configuration for the automatic discovery of new Elasticsearch nodes. */ - @ConfigItem - DiscoveryConfig discovery; + DiscoveryConfig discovery(); /** * Configuration for the thread pool assigned to the backend. */ - @ConfigItem - ThreadPoolConfig threadPool; + ThreadPoolConfig threadPool(); /** * Whether Hibernate Search should check the version of the Elasticsearch cluster on startup. @@ -179,21 +174,21 @@ public static class ElasticsearchBackendRuntimeConfig { * * @asciidoclet */ - @ConfigItem(name = "version-check.enabled", defaultValue = "true") - public boolean versionCheck; + @WithName("version-check.enabled") + @WithDefault("true") + boolean versionCheck(); /** * The default configuration for the Elasticsearch indexes. */ - @ConfigItem(name = ConfigItem.PARENT) - ElasticsearchIndexRuntimeConfig indexDefaults; + @WithParentName + ElasticsearchIndexRuntimeConfig indexDefaults(); /** * Per-index specific configuration. */ - @ConfigItem @ConfigDocMapKey("index-name") - Map indexes; + Map indexes(); } public enum ElasticsearchClientProtocol { @@ -231,45 +226,42 @@ public String getHibernateSearchString() { } @ConfigGroup - public static class ElasticsearchIndexRuntimeConfig { + public interface ElasticsearchIndexRuntimeConfig { /** * Configuration for the schema management of the indexes. */ - @ConfigItem - ElasticsearchIndexSchemaManagementConfig schemaManagement; + ElasticsearchIndexSchemaManagementConfig schemaManagement(); /** * Configuration for the indexing process that creates, updates and deletes documents. */ - @ConfigItem - ElasticsearchIndexIndexingConfig indexing; + ElasticsearchIndexIndexingConfig indexing(); } @ConfigGroup - public static class DiscoveryConfig { + public interface DiscoveryConfig { /** * Defines if automatic discovery is enabled. */ - @ConfigItem - boolean enabled; + @WithDefault("false") + Boolean enabled(); /** * Refresh interval of the node list. */ - @ConfigItem(defaultValue = "10S") - Duration refreshInterval; + @WithDefault("10S") + Duration refreshInterval(); } @ConfigGroup - public static class AutomaticIndexingConfig { + public interface AutomaticIndexingConfig { /** * Configuration for synchronization with the index when indexing automatically. */ - @ConfigItem - AutomaticIndexingSynchronizationConfig synchronization; + AutomaticIndexingSynchronizationConfig synchronization(); /** * Whether to check if dirty properties are relevant to indexing before actually reindexing an entity. @@ -279,12 +271,12 @@ public static class AutomaticIndexingConfig { * * @asciidoclet */ - @ConfigItem(defaultValue = "true") - boolean enableDirtyCheck; + @WithDefault("true") + boolean enableDirtyCheck(); } @ConfigGroup - public static class AutomaticIndexingSynchronizationConfig { + public interface AutomaticIndexingSynchronizationConfig { // @formatter:off /** @@ -357,38 +349,37 @@ public static class AutomaticIndexingSynchronizationConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValueDocumentation = "write-sync") - Optional strategy; + @ConfigDocDefault("write-sync") + Optional strategy(); } @ConfigGroup - public static class SearchQueryLoadingConfig { + public interface SearchQueryLoadingConfig { /** * Configuration for cache lookup when loading entities during the execution of a search query. */ - @ConfigItem - SearchQueryLoadingCacheLookupConfig cacheLookup; + SearchQueryLoadingCacheLookupConfig cacheLookup(); /** * The fetch size to use when loading entities during the execution of a search query. */ - @ConfigItem(defaultValue = "100") - int fetchSize; + @WithDefault("100") + int fetchSize(); } @ConfigGroup - public static class SearchQueryLoadingCacheLookupConfig { + interface SearchQueryLoadingCacheLookupConfig { /** * The strategy to use when loading entities during the execution of a search query. */ - @ConfigItem(defaultValue = "skip") - EntityLoadingCacheLookupStrategy strategy; + @WithDefault("skip") + EntityLoadingCacheLookupStrategy strategy(); } @ConfigGroup - public static class SchemaManagementConfig { + public interface SchemaManagementConfig { // @formatter:off /** @@ -451,13 +442,14 @@ public static class SchemaManagementConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValue = "create-or-validate", defaultValueDocumentation = "drop-and-create-and-drop when using Dev Services; create-or-validate otherwise") - SchemaManagementStrategyName strategy; + @WithDefault("create-or-validate") + @ConfigDocDefault("drop-and-create-and-drop when using Dev Services; create-or-validate otherwise") + SchemaManagementStrategyName strategy(); } @ConfigGroup - public static class ThreadPoolConfig { + public interface ThreadPoolConfig { /** * The size of the thread pool assigned to the backend. * @@ -477,14 +469,13 @@ public static class ThreadPoolConfig { * @asciidoclet */ // We can't set an actual default value here: see comment on this class. - @ConfigItem - OptionalInt size; + OptionalInt size(); } // We can't set actual default values in this section, // otherwise "quarkus.hibernate-search-orm.elasticsearch.index-defaults" will be ignored. @ConfigGroup - public static class ElasticsearchIndexSchemaManagementConfig { + public interface ElasticsearchIndexSchemaManagementConfig { /** * The minimal https://www.elastic.co/guide/en/elasticsearch/reference/7.17/cluster-health.html[Elasticsearch cluster * status] required on startup. @@ -492,21 +483,21 @@ public static class ElasticsearchIndexSchemaManagementConfig { * @asciidoclet */ // We can't set an actual default value here: see comment on this class. - @ConfigItem(defaultValueDocumentation = "yellow") - Optional requiredStatus; + @ConfigDocDefault("yellow") + Optional requiredStatus(); /** * How long we should wait for the status before failing the bootstrap. */ // We can't set an actual default value here: see comment on this class. - @ConfigItem(defaultValueDocumentation = "10S") - Optional requiredStatusWaitTimeout; + @ConfigDocDefault("10S") + Optional requiredStatusWaitTimeout(); } // We can't set actual default values in this section, // otherwise "quarkus.hibernate-search-orm.elasticsearch.index-defaults" will be ignored. @ConfigGroup - public static class ElasticsearchIndexIndexingConfig { + public interface ElasticsearchIndexIndexingConfig { /** * The number of indexing queues assigned to each index. * @@ -520,8 +511,8 @@ public static class ElasticsearchIndexIndexingConfig { * @asciidoclet */ // We can't set an actual default value here: see comment on this class. - @ConfigItem(defaultValueDocumentation = "10") - OptionalInt queueCount; + @ConfigDocDefault("10") + OptionalInt queueCount(); /** * The size of indexing queues. @@ -534,8 +525,8 @@ public static class ElasticsearchIndexIndexingConfig { * @asciidoclet */ // We can't set an actual default value here: see comment on this class. - @ConfigItem(defaultValueDocumentation = "1000") - OptionalInt queueSize; + @ConfigDocDefault("1000") + OptionalInt queueSize(); /** * The maximum size of bulk requests created when processing indexing queues. @@ -553,12 +544,12 @@ public static class ElasticsearchIndexIndexingConfig { * @asciidoclet */ // We can't set an actual default value here: see comment on this class. - @ConfigItem(defaultValueDocumentation = "100") - OptionalInt maxBulkSize; + @ConfigDocDefault("100") + OptionalInt maxBulkSize(); } @ConfigGroup - public static class MultiTenancyConfig { + public interface MultiTenancyConfig { /** * An exhaustive list of all tenant identifiers that may be used by the application when multi-tenancy is enabled. @@ -568,8 +559,7 @@ public static class MultiTenancyConfig { * * @asciidoclet */ - @ConfigItem - Optional> tenantIds; + Optional> tenantIds(); } } diff --git a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/dev/HibernateSearchElasticsearchDevRecorder.java b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/dev/HibernateSearchElasticsearchDevRecorder.java index 7f55d54f6bd98..fd21fc9dff909 100644 --- a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/dev/HibernateSearchElasticsearchDevRecorder.java +++ b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/dev/HibernateSearchElasticsearchDevRecorder.java @@ -29,7 +29,7 @@ public void initController( Set activePersistenceUnitNames = persistenceUnitNames.stream() .filter(name -> { var puConfig = puConfigs.get(name); - return puConfig == null || puConfig.active.orElse(true); + return puConfig == null || puConfig.active().orElse(true); }) .collect(Collectors.toCollection(LinkedHashSet::new)); HibernateSearchElasticsearchDevController.get().setActivePersistenceUnitNames(activePersistenceUnitNames); From 6669a0d960d3a349ac3549379d296d4fda2193c4 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Wed, 5 Apr 2023 19:26:17 +0200 Subject: [PATCH 3/5] Fix various issues in doc generation related to @ConfigMapping --- .../annotation/processor/Constants.java | 1 + .../generate_doc/ConfigDocItemFinder.java | 41 +++++++++++-------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/Constants.java b/core/processor/src/main/java/io/quarkus/annotation/processor/Constants.java index 5dd32bc4c85dc..c664e4e5228bc 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/Constants.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/Constants.java @@ -64,6 +64,7 @@ final public class Constants { public static final String ANNOTATION_CONFIG_DOC_DEFAULT = "io.quarkus.runtime.annotations.ConfigDocDefault"; public static final String ANNOTATION_CONFIG_WITH_NAME = "io.smallrye.config.WithName"; + public static final String ANNOTATION_CONFIG_WITH_PARENT_NAME = "io.smallrye.config.WithParentName"; public static final String ANNOTATION_CONFIG_WITH_DEFAULT = "io.smallrye.config.WithDefault"; public static final Set SUPPORTED_ANNOTATIONS_TYPES = Set.of(ANNOTATION_BUILD_STEP, ANNOTATION_CONFIG_GROUP, diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java b/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java index ee5374595e209..26035efd27f36 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java @@ -7,6 +7,7 @@ import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_ITEM; import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_WITH_DEFAULT; import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_WITH_NAME; +import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_WITH_PARENT_NAME; import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONVERT_WITH; import static io.quarkus.annotation.processor.Constants.ANNOTATION_DEFAULT_CONVERTER; import static io.quarkus.annotation.processor.Constants.DOT; @@ -226,10 +227,11 @@ private List recursivelyFindConfigItems(Element element, String r // Mappings if (annotationName.equals(ANNOTATION_CONFIG_WITH_NAME)) { name = parentName + DOT + annotationMirror.getElementValues().values().iterator().next().getValue(); + } else if (annotationName.equals(ANNOTATION_CONFIG_WITH_PARENT_NAME)) { + name = parentName; } else if (annotationName.equals(ANNOTATION_CONFIG_DOC_DEFAULT)) { - defaultValue = annotationMirror.getElementValues().values().iterator().next().getValue().toString(); - } else if (annotationName.equals(ANNOTATION_CONFIG_WITH_DEFAULT) - && defaultValue == null) { + defaultValueDoc = annotationMirror.getElementValues().values().iterator().next().getValue().toString(); + } else if (annotationName.equals(ANNOTATION_CONFIG_WITH_DEFAULT)) { defaultValue = annotationMirror.getElementValues().values().iterator().next().getValue().toString(); } } @@ -244,13 +246,9 @@ private List recursivelyFindConfigItems(Element element, String r if (name == null) { name = parentName + DOT + hyphenatedFieldName; } - if (NO_DEFAULT.equals(defaultValue)) { defaultValue = EMPTY; } - if (EMPTY.equals(defaultValue)) { - defaultValue = defaultValueDoc; - } if (isConfigGroup(type)) { List groupConfigItems = readConfigGroupItems(configPhase, rootName, name, type, @@ -321,10 +319,14 @@ private List recursivelyFindConfigItems(Element element, String r type = simpleTypeToString(realTypeMirror); if (isEnumType(realTypeMirror)) { - if (useHyphenateEnumValue) { - defaultValue = Arrays.stream(defaultValue.split(COMMA)) - .map(defaultEnumValue -> hyphenateEnumValue(defaultEnumValue.trim())) - .collect(Collectors.joining(COMMA)); + if (defaultValueDoc.isBlank()) { + if (useHyphenateEnumValue) { + defaultValue = Arrays.stream(defaultValue.split(COMMA)) + .map(defaultEnumValue -> hyphenateEnumValue(defaultEnumValue.trim())) + .collect(Collectors.joining(COMMA)); + } + } else { + defaultValue = defaultValueDoc; } acceptedValues = extractEnumValues(realTypeMirror, useHyphenateEnumValue, clazz.getQualifiedName().toString()); @@ -333,15 +335,18 @@ private List recursivelyFindConfigItems(Element element, String r } } else { type = simpleTypeToString(declaredType); - if (isEnumType(declaredType)) { - if (useHyphenateEnumValue) { + + if (defaultValueDoc.isBlank()) { + if (isEnumType(declaredType)) { defaultValue = hyphenateEnumValue(defaultValue); + acceptedValues = extractEnumValues(declaredType, useHyphenateEnumValue, + clazz.getQualifiedName().toString()); + configDocKey.setEnum(true); + } else if (isDurationType(declaredType) && !defaultValue.isEmpty()) { + defaultValue = DocGeneratorUtil.normalizeDurationValue(defaultValue); } - acceptedValues = extractEnumValues(declaredType, useHyphenateEnumValue, - clazz.getQualifiedName().toString()); - configDocKey.setEnum(true); - } else if (isDurationType(declaredType) && !defaultValue.isEmpty()) { - defaultValue = DocGeneratorUtil.normalizeDurationValue(defaultValue); + } else { + defaultValue = defaultValueDoc; } } } From abdfeeeac6fb841af40e833f5bb421009e9fd5f7 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Thu, 6 Apr 2023 16:38:16 +0200 Subject: [PATCH 4/5] Switch Hibernate Search Outbox Polling extension to @ConfigMapping --- .../HibernateSearchOutboxPollingRecorder.java | 32 ++++---- ...rnateSearchOutboxPollingRuntimeConfig.java | 16 ++-- ...oxPollingRuntimeConfigPersistenceUnit.java | 78 +++++++++---------- 3 files changed, 61 insertions(+), 65 deletions(-) diff --git a/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRecorder.java b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRecorder.java index 6c7e36d341f28..c65a8566d72e5 100644 --- a/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRecorder.java +++ b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRecorder.java @@ -20,8 +20,8 @@ public HibernateOrmIntegrationRuntimeInitListener createRuntimeInitListener( HibernateSearchOutboxPollingRuntimeConfig runtimeConfig, String persistenceUnitName) { HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit puConfig = PersistenceUnitUtil .isDefaultPersistenceUnit(persistenceUnitName) - ? runtimeConfig.defaultPersistenceUnit - : runtimeConfig.persistenceUnits.get(persistenceUnitName); + ? runtimeConfig.defaultPersistenceUnit() + : runtimeConfig.persistenceUnits().get(persistenceUnitName); return new RuntimeInitListener(puConfig); } @@ -40,9 +40,9 @@ public void contributeRuntimeProperties(BiConsumer propertyColle return; } - contributeCoordinationRuntimeProperties(propertyCollector, null, runtimeConfig.coordination.defaults); + contributeCoordinationRuntimeProperties(propertyCollector, null, runtimeConfig.coordination().defaults()); - for (Entry tenantEntry : runtimeConfig.coordination.tenants.entrySet()) { + for (Entry tenantEntry : runtimeConfig.coordination().tenants().entrySet()) { contributeCoordinationRuntimeProperties(propertyCollector, tenantEntry.getKey(), tenantEntry.getValue()); } } @@ -51,41 +51,41 @@ private void contributeCoordinationRuntimeProperties(BiConsumer AgentsConfig agentsConfig) { addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_ENABLED, - agentsConfig.eventProcessor.enabled); + agentsConfig.eventProcessor().enabled()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_SHARDS_TOTAL_COUNT, - agentsConfig.eventProcessor.shards.totalCount); + agentsConfig.eventProcessor().shards().totalCount()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_SHARDS_ASSIGNED, - agentsConfig.eventProcessor.shards.assigned); + agentsConfig.eventProcessor().shards().assigned()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_POLLING_INTERVAL, - agentsConfig.eventProcessor.pollingInterval.toMillis()); + agentsConfig.eventProcessor().pollingInterval().toMillis()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_PULSE_INTERVAL, - agentsConfig.eventProcessor.pulseInterval.toMillis()); + agentsConfig.eventProcessor().pulseInterval().toMillis()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_PULSE_EXPIRATION, - agentsConfig.eventProcessor.pulseExpiration.toMillis()); + agentsConfig.eventProcessor().pulseExpiration().toMillis()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_BATCH_SIZE, - agentsConfig.eventProcessor.batchSize); + agentsConfig.eventProcessor().batchSize()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_TRANSACTION_TIMEOUT, - agentsConfig.eventProcessor.transactionTimeout, Optional::isPresent, d -> d.get().toSeconds()); + agentsConfig.eventProcessor().transactionTimeout(), Optional::isPresent, d -> d.get().toSeconds()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.EVENT_PROCESSOR_RETRY_DELAY, - agentsConfig.eventProcessor.retryDelay.toSeconds()); + agentsConfig.eventProcessor().retryDelay().toSeconds()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.MASS_INDEXER_POLLING_INTERVAL, - agentsConfig.massIndexer.pollingInterval.toMillis()); + agentsConfig.massIndexer().pollingInterval().toMillis()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.MASS_INDEXER_PULSE_INTERVAL, - agentsConfig.massIndexer.pulseInterval.toMillis()); + agentsConfig.massIndexer().pulseInterval().toMillis()); addCoordinationConfig(propertyCollector, tenantId, HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.MASS_INDEXER_PULSE_EXPIRATION, - agentsConfig.massIndexer.pulseExpiration.toMillis()); + agentsConfig.massIndexer().pulseExpiration().toMillis()); } } diff --git a/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRuntimeConfig.java b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRuntimeConfig.java index cd420a78fcbcf..1fbf4e7108ff5 100644 --- a/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRuntimeConfig.java +++ b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRuntimeConfig.java @@ -4,25 +4,27 @@ 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.WithParentName; -@ConfigRoot(name = "hibernate-search-orm", phase = ConfigPhase.RUN_TIME) -public class HibernateSearchOutboxPollingRuntimeConfig { +@ConfigMapping(prefix = "quarkus.hibernate-search-orm") +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +public interface HibernateSearchOutboxPollingRuntimeConfig { /** * Configuration for the default persistence unit. */ - @ConfigItem(name = ConfigItem.PARENT) - public HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit defaultPersistenceUnit; + @WithParentName + HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit defaultPersistenceUnit(); /** * Configuration for additional named persistence units. */ @ConfigDocSection @ConfigDocMapKey("persistence-unit-name") - @ConfigItem(name = ConfigItem.PARENT) - public Map persistenceUnits; + @WithParentName + Map persistenceUnits(); } diff --git a/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit.java b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit.java index d59783942c898..413c1e8834c08 100644 --- a/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit.java +++ b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit.java @@ -9,55 +9,53 @@ import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigDocSection; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.WithDefault; +import io.smallrye.config.WithParentName; @ConfigGroup -class HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit { +public interface HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit { /** * Configuration for coordination between threads or application instances. */ - @ConfigItem - CoordinationConfig coordination; + CoordinationConfig coordination(); @ConfigGroup - static class CoordinationConfig { + public interface CoordinationConfig { /** * Default config */ @ConfigDocSection - @ConfigItem(name = ConfigItem.PARENT) - AgentsConfig defaults; + @WithParentName + AgentsConfig defaults(); /** * Per-tenant config */ @ConfigDocSection @ConfigDocMapKey("tenant-id") - Map tenants; + Map tenants(); } @ConfigGroup - static class AgentsConfig { + public interface AgentsConfig { /** * Configuration for the event processor agent. */ - @ConfigItem - EventProcessorConfig eventProcessor; + EventProcessorConfig eventProcessor(); /** * Configuration for the mass indexer agent. */ - @ConfigItem - MassIndexerConfig massIndexer; + MassIndexerConfig massIndexer(); } @ConfigGroup - static class EventProcessorConfig { + public interface EventProcessorConfig { // @formatter:off /** @@ -74,14 +72,13 @@ static class EventProcessorConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValue = "true") - boolean enabled; + @WithDefault("true") + boolean enabled(); /** * Configuration related to shards. */ - @ConfigItem - EventProcessorShardsConfig shards; + EventProcessorShardsConfig shards(); // @formatter:off /** @@ -97,8 +94,8 @@ static class EventProcessorConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValue = "0.100S") - Duration pollingInterval; + @WithDefault("0.100S") + Duration pollingInterval(); // @formatter:off /** @@ -127,8 +124,8 @@ static class EventProcessorConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValue = "2S") - Duration pulseInterval; + @WithDefault("2S") + Duration pulseInterval(); // @formatter:off /** @@ -154,8 +151,8 @@ static class EventProcessorConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValue = "30S") - Duration pulseExpiration; + @WithDefault("30S") + Duration pulseExpiration(); // @formatter:off /** @@ -172,8 +169,8 @@ static class EventProcessorConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValue = "50") - int batchSize; + @WithDefault("50") + int batchSize(); // @formatter:off /** @@ -191,8 +188,7 @@ static class EventProcessorConfig { * @asciidoclet */ // @formatter:on - @ConfigItem - Optional transactionTimeout; + Optional transactionTimeout(); // @formatter:off /** @@ -207,13 +203,13 @@ static class EventProcessorConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValue = "30S") - Duration retryDelay; + @WithDefault("30S") + Duration retryDelay(); } @ConfigGroup - static class EventProcessorShardsConfig { + public interface EventProcessorShardsConfig { // @formatter:off /** @@ -232,8 +228,7 @@ static class EventProcessorShardsConfig { * @asciidoclet */ // @formatter:on - @ConfigItem - OptionalInt totalCount; + OptionalInt totalCount(); // @formatter:off /** @@ -257,13 +252,12 @@ static class EventProcessorShardsConfig { * @asciidoclet */ // @formatter:on - @ConfigItem - Optional> assigned; + Optional> assigned(); } @ConfigGroup - static class MassIndexerConfig { + public interface MassIndexerConfig { // @formatter:off /** @@ -285,8 +279,8 @@ static class MassIndexerConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValue = "0.100S") - Duration pollingInterval; + @WithDefault("0.100S") + Duration pollingInterval(); // @formatter:off /** @@ -313,8 +307,8 @@ static class MassIndexerConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValue = "2S") - Duration pulseInterval; + @WithDefault("2S") + Duration pulseInterval(); // @formatter:off /** @@ -340,8 +334,8 @@ static class MassIndexerConfig { * @asciidoclet */ // @formatter:on - @ConfigItem(defaultValue = "30S") - Duration pulseExpiration; + @WithDefault("30S") + Duration pulseExpiration(); } From dc3f4cfe408ce2f542c15ef9b66efa4074af48c4 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Thu, 6 Apr 2023 16:41:43 +0200 Subject: [PATCH 5/5] Fix default annotation of strategy() in CoordinationConfig --- ...nateSearchElasticsearchBuildTimeConfigPersistenceUnit.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit.java b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit.java index e869201715bd9..5dabad2197f33 100644 --- a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit.java +++ b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit.java @@ -6,10 +6,10 @@ import org.hibernate.search.backend.elasticsearch.ElasticsearchVersion; +import io.quarkus.runtime.annotations.ConfigDocDefault; import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigDocSection; import io.quarkus.runtime.annotations.ConfigGroup; -import io.smallrye.config.WithDefault; import io.smallrye.config.WithName; import io.smallrye.config.WithParentName; @@ -235,7 +235,7 @@ public interface CoordinationConfig { * * @asciidoclet */ - @WithDefault("none") + @ConfigDocDefault("none") Optional strategy(); }