Skip to content

Commit

Permalink
Merge pull request #42378 from gsmet/reorganize-search-management-config
Browse files Browse the repository at this point in the history
Reorganize Hibernate Search management config
  • Loading branch information
gsmet authored Aug 8, 2024
2 parents 495d945 + 27290ae commit 4cad699
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import io.quarkus.hibernate.search.orm.elasticsearch.runtime.HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit.ElasticsearchIndexBuildTimeConfig;
import io.quarkus.hibernate.search.orm.elasticsearch.runtime.HibernateSearchElasticsearchRecorder;
import io.quarkus.hibernate.search.orm.elasticsearch.runtime.HibernateSearchElasticsearchRuntimeConfig;
import io.quarkus.hibernate.search.orm.elasticsearch.runtime.management.HibernateSearchManagementConfig;
import io.quarkus.runtime.configuration.ConfigUtils;
import io.quarkus.runtime.configuration.ConfigurationException;
import io.quarkus.vertx.http.deployment.spi.RouteBuildItem;
Expand Down Expand Up @@ -441,10 +440,12 @@ void devServicesDropAndCreateAndDropByDefault(
@BuildStep(onlyIf = HibernateSearchManagementEnabled.class)
void createManagementRoutes(BuildProducer<RouteBuildItem> routes,
HibernateSearchElasticsearchRecorder recorder,
HibernateSearchManagementConfig managementConfig) {
HibernateSearchElasticsearchBuildTimeConfig hibernateSearchElasticsearchBuildTimeConfig) {

String managementRootPath = hibernateSearchElasticsearchBuildTimeConfig.management().rootPath();

routes.produce(RouteBuildItem.newManagementRoute(
managementConfig.rootPath() + (managementConfig.rootPath().endsWith("/") ? "" : "/") + "reindex")
managementRootPath + (managementRootPath.endsWith("/") ? "" : "/") + "reindex")
.withRoutePathConfigKey("quarkus.hibernate-search-orm.management.root-path")
.withRequestHandler(recorder.managementHandler())
.displayOnNotFoundPage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public class HibernateSearchEnabled implements BooleanSupplier {

private final HibernateSearchElasticsearchBuildTimeConfig config;
protected final HibernateSearchElasticsearchBuildTimeConfig config;

HibernateSearchEnabled(HibernateSearchElasticsearchBuildTimeConfig config) {
this.config = config;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
package io.quarkus.hibernate.search.orm.elasticsearch.deployment;

import io.quarkus.hibernate.search.orm.elasticsearch.runtime.HibernateSearchElasticsearchBuildTimeConfig;
import io.quarkus.hibernate.search.orm.elasticsearch.runtime.management.HibernateSearchManagementConfig;

/**
* Supplier that can be used to only run build steps
* if the Hibernate Search extension and its management is enabled.
*/
public class HibernateSearchManagementEnabled extends HibernateSearchEnabled {

private final HibernateSearchManagementConfig config;

HibernateSearchManagementEnabled(HibernateSearchElasticsearchBuildTimeConfig config,
HibernateSearchManagementConfig managementConfig) {
HibernateSearchManagementEnabled(HibernateSearchElasticsearchBuildTimeConfig config) {
super(config);
this.config = managementConfig;
}

@Override
public boolean getAsBoolean() {
return super.getAsBoolean() && config.enabled();
return super.getAsBoolean() && config.management().enabled();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import io.quarkus.hibernate.orm.runtime.PersistenceUnitUtil;
import io.quarkus.runtime.annotations.ConfigDocMapKey;
import io.quarkus.runtime.annotations.ConfigDocSection;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
Expand Down Expand Up @@ -35,4 +36,9 @@ public interface HibernateSearchElasticsearchBuildTimeConfig {
@ConfigDocMapKey("persistence-unit-name")
Map<String, HibernateSearchElasticsearchBuildTimeConfigPersistenceUnit> persistenceUnits();

/**
* Management interface.
*/
@ConfigDocSection
HibernateSearchElasticsearchBuildTimeConfigManagement management();
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package io.quarkus.hibernate.search.orm.elasticsearch.runtime.management;
package io.quarkus.hibernate.search.orm.elasticsearch.runtime;

import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.quarkus.runtime.annotations.ConfigGroup;
import io.smallrye.config.WithDefault;

@ConfigMapping(prefix = "quarkus.hibernate-search-orm.management")
@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
public interface HibernateSearchManagementConfig {
@ConfigGroup
public interface HibernateSearchElasticsearchBuildTimeConfigManagement {

/**
* Root path for reindexing endpoints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public class HibernateSearchStandaloneEnabled implements BooleanSupplier {

private final HibernateSearchStandaloneBuildTimeConfig config;
protected final HibernateSearchStandaloneBuildTimeConfig config;

HibernateSearchStandaloneEnabled(HibernateSearchStandaloneBuildTimeConfig config) {
this.config = config;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
package io.quarkus.hibernate.search.standalone.elasticsearch.deployment;

import io.quarkus.hibernate.search.standalone.elasticsearch.runtime.HibernateSearchStandaloneBuildTimeConfig;
import io.quarkus.hibernate.search.standalone.elasticsearch.runtime.management.HibernateSearchStandaloneManagementConfig;

/**
* Supplier that can be used to only run build steps
* if the Hibernate Search extension and its management is enabled.
*/
public class HibernateSearchStandaloneManagementEnabled extends HibernateSearchStandaloneEnabled {

private final HibernateSearchStandaloneManagementConfig config;

HibernateSearchStandaloneManagementEnabled(HibernateSearchStandaloneBuildTimeConfig config,
HibernateSearchStandaloneManagementConfig managementConfig) {
HibernateSearchStandaloneManagementEnabled(HibernateSearchStandaloneBuildTimeConfig config) {
super(config);
this.config = managementConfig;
}

@Override
public boolean getAsBoolean() {
return super.getAsBoolean() && config.enabled();
return super.getAsBoolean() && config.management().enabled();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import io.quarkus.hibernate.search.standalone.elasticsearch.runtime.HibernateSearchStandaloneBuildTimeConfig.ElasticsearchIndexBuildTimeConfig;
import io.quarkus.hibernate.search.standalone.elasticsearch.runtime.HibernateSearchStandaloneRecorder;
import io.quarkus.hibernate.search.standalone.elasticsearch.runtime.HibernateSearchStandaloneRuntimeConfig;
import io.quarkus.hibernate.search.standalone.elasticsearch.runtime.management.HibernateSearchStandaloneManagementConfig;
import io.quarkus.runtime.configuration.ConfigUtils;
import io.quarkus.runtime.configuration.ConfigurationException;
import io.quarkus.vertx.http.deployment.spi.RouteBuildItem;
Expand Down Expand Up @@ -370,10 +369,12 @@ void devServices(Optional<HibernateSearchStandaloneEnabledBuildItem> enabled,
@BuildStep(onlyIf = HibernateSearchStandaloneManagementEnabled.class)
void createManagementRoutes(BuildProducer<RouteBuildItem> routes,
HibernateSearchStandaloneRecorder recorder,
HibernateSearchStandaloneManagementConfig managementConfig) {
HibernateSearchStandaloneBuildTimeConfig hibernateSearchStandaloneBuildTimeConfig) {

String managementRootPath = hibernateSearchStandaloneBuildTimeConfig.management().rootPath();

routes.produce(RouteBuildItem.newManagementRoute(
managementConfig.rootPath() + (managementConfig.rootPath().endsWith("/") ? "" : "/") + "reindex")
managementRootPath + (managementRootPath.endsWith("/") ? "" : "/") + "reindex")
.withRoutePathConfigKey("quarkus.hibernate-search-standalone.management.root-path")
.withRequestHandler(recorder.managementHandler())
.displayOnNotFoundPage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ public interface HibernateSearchStandaloneBuildTimeConfig {
*/
Optional<String> backgroundFailureHandler();

/**
* Management interface.
*/
@ConfigDocSection
HibernateSearchStandaloneBuildTimeConfigManagement management();

/**
* Configuration related to the mapping.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package io.quarkus.hibernate.search.standalone.elasticsearch.runtime.management;
package io.quarkus.hibernate.search.standalone.elasticsearch.runtime;

import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.quarkus.runtime.annotations.ConfigGroup;
import io.smallrye.config.WithDefault;

@ConfigMapping(prefix = "quarkus.hibernate-search-standalone.management")
@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
public interface HibernateSearchStandaloneManagementConfig {
@ConfigGroup
public interface HibernateSearchStandaloneBuildTimeConfigManagement {

/**
* Root path for reindexing endpoints.
Expand Down

0 comments on commit 4cad699

Please sign in to comment.