-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Hibernate Search Elasticsearch backend to a dedicated extension
- Loading branch information
Showing
37 changed files
with
1,554 additions
and
1,626 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
extensions/hibernate-search-backend-elasticsearch/deployment/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>quarkus-hibernate-search-backend-elasticsearch-parent</artifactId> | ||
<groupId>io.quarkus</groupId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>quarkus-hibernate-search-backend-elasticsearch-deployment</artifactId> | ||
<name>Quarkus - Hibernate Search - Elasticsearch - Deployment</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-core-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-elasticsearch-rest-client-common-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-hibernate-search-backend-elasticsearch</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-processor</artifactId> | ||
<version>${project.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
28 changes: 28 additions & 0 deletions
28
...backend/elasticsearch/deployment/HibernateSearchBackendElasticsearchEnabledBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.quarkus.hibernate.search.backend.elasticsearch.deployment; | ||
|
||
import java.util.Map; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
import io.quarkus.hibernate.search.backend.elasticsearch.runtime.HibernateSearchBackendElasticsearchBuildTimeConfig; | ||
import io.quarkus.hibernate.search.backend.elasticsearch.runtime.MapperContext; | ||
|
||
public final class HibernateSearchBackendElasticsearchEnabledBuildItem extends MultiBuildItem { | ||
|
||
private final MapperContext mapperContext; | ||
private final Map<String, HibernateSearchBackendElasticsearchBuildTimeConfig> buildTimeConfig; | ||
|
||
public HibernateSearchBackendElasticsearchEnabledBuildItem(MapperContext mapperContext, | ||
Map<String, HibernateSearchBackendElasticsearchBuildTimeConfig> buildTimeConfig) { | ||
this.mapperContext = mapperContext; | ||
this.buildTimeConfig = buildTimeConfig; | ||
} | ||
|
||
public MapperContext getMapperContext() { | ||
return mapperContext; | ||
} | ||
|
||
public Map<String, HibernateSearchBackendElasticsearchBuildTimeConfig> getBuildTimeConfig() { | ||
return buildTimeConfig; | ||
} | ||
|
||
} |
151 changes: 151 additions & 0 deletions
151
...search/backend/elasticsearch/deployment/HibernateSearchBackendElasticsearchProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package io.quarkus.hibernate.search.backend.elasticsearch.deployment; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Map.Entry; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import org.hibernate.search.backend.elasticsearch.analysis.ElasticsearchAnalysisConfigurer; | ||
import org.hibernate.search.backend.elasticsearch.gson.spi.GsonClasses; | ||
import org.hibernate.search.backend.elasticsearch.index.layout.IndexLayoutStrategy; | ||
|
||
import io.quarkus.arc.deployment.UnremovableBeanBuildItem; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.annotations.BuildSteps; | ||
import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem; | ||
import io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; | ||
import io.quarkus.hibernate.search.backend.elasticsearch.runtime.HibernateSearchBackendElasticsearchBuildTimeConfig; | ||
import io.quarkus.hibernate.search.backend.elasticsearch.runtime.MapperContext; | ||
import io.quarkus.runtime.configuration.ConfigurationException; | ||
|
||
@BuildSteps | ||
class HibernateSearchBackendElasticsearchProcessor { | ||
|
||
@BuildStep | ||
void registerBeans(List<HibernateSearchBackendElasticsearchEnabledBuildItem> searchEnabledPUs, | ||
BuildProducer<UnremovableBeanBuildItem> unremovableBean) { | ||
if (searchEnabledPUs.isEmpty()) { | ||
return; | ||
} | ||
// Some user-injectable beans are retrieved programmatically and shouldn't be removed | ||
unremovableBean.produce(UnremovableBeanBuildItem.beanTypes(ElasticsearchAnalysisConfigurer.class, | ||
IndexLayoutStrategy.class)); | ||
} | ||
|
||
@BuildStep | ||
void registerReflectionForGson(List<HibernateSearchBackendElasticsearchEnabledBuildItem> enabled, | ||
BuildProducer<ReflectiveClassBuildItem> reflectiveClass) { | ||
if (enabled.isEmpty()) { | ||
return; | ||
} | ||
String[] reflectiveClasses = GsonClasses.typesRequiringReflection().toArray(String[]::new); | ||
reflectiveClass.produce(ReflectiveClassBuildItem.builder(reflectiveClasses).methods().fields().build()); | ||
} | ||
|
||
@BuildStep | ||
void processBuildTimeConfig(List<HibernateSearchBackendElasticsearchEnabledBuildItem> enabled, | ||
ApplicationArchivesBuildItem applicationArchivesBuildItem, | ||
BuildProducer<NativeImageResourceBuildItem> nativeImageResources, | ||
BuildProducer<HotDeploymentWatchedFileBuildItem> hotDeploymentWatchedFiles) { | ||
if (enabled.isEmpty()) { | ||
return; | ||
} | ||
for (HibernateSearchBackendElasticsearchEnabledBuildItem enabledItem : enabled) { | ||
processBuildTimeConfig(enabledItem, applicationArchivesBuildItem, nativeImageResources, | ||
hotDeploymentWatchedFiles); | ||
} | ||
} | ||
|
||
private void processBuildTimeConfig(HibernateSearchBackendElasticsearchEnabledBuildItem enabledItem, | ||
ApplicationArchivesBuildItem applicationArchivesBuildItem, | ||
BuildProducer<NativeImageResourceBuildItem> nativeImageResources, | ||
BuildProducer<HotDeploymentWatchedFileBuildItem> hotDeploymentWatchedFiles) { | ||
Set<String> propertyKeysWithNoVersion = new LinkedHashSet<>(); | ||
var buildTimeConfig = enabledItem.getBuildTimeConfig(); | ||
|
||
var mapperContext = enabledItem.getMapperContext(); | ||
Set<String> allBackendNames = new LinkedHashSet<>(mapperContext.backendNamesForIndexedEntities()); | ||
allBackendNames.addAll(buildTimeConfig.keySet()); | ||
// For all backends referenced either through @Indexed(backend = ...) or configuration... | ||
for (String backendName : allBackendNames) { | ||
HibernateSearchBackendElasticsearchBuildTimeConfig backendConfig = buildTimeConfig.get(backendName); | ||
// ... we validate that the backend is configured and the version is present | ||
if (backendConfig == null || backendConfig.version().isEmpty()) { | ||
propertyKeysWithNoVersion.add(mapperContext.backendPropertyKey(backendName, null, "version")); | ||
} | ||
if (backendConfig == null) { | ||
continue; | ||
} | ||
// ... we register files referenced from backends configuration | ||
registerClasspathFilesFromBackendConfig(mapperContext, backendName, backendConfig, | ||
applicationArchivesBuildItem, nativeImageResources, hotDeploymentWatchedFiles); | ||
} | ||
if (!propertyKeysWithNoVersion.isEmpty()) { | ||
throw new ConfigurationException( | ||
"The Elasticsearch version needs to be defined via properties: " | ||
+ String.join(", ", propertyKeysWithNoVersion) + ".", | ||
propertyKeysWithNoVersion); | ||
} | ||
} | ||
|
||
private static void registerClasspathFilesFromBackendConfig(MapperContext mapperContext, String backendName, | ||
HibernateSearchBackendElasticsearchBuildTimeConfig backendConfig, | ||
ApplicationArchivesBuildItem applicationArchivesBuildItem, | ||
BuildProducer<NativeImageResourceBuildItem> nativeImageResources, | ||
BuildProducer<HotDeploymentWatchedFileBuildItem> hotDeploymentWatchedFiles) { | ||
registerClasspathFilesFromIndexConfig(mapperContext, backendName, null, backendConfig.indexDefaults(), | ||
applicationArchivesBuildItem, nativeImageResources, hotDeploymentWatchedFiles); | ||
for (Entry<String, HibernateSearchBackendElasticsearchBuildTimeConfig.IndexConfig> entry : backendConfig.indexes() | ||
.entrySet()) { | ||
String indexName = entry.getKey(); | ||
HibernateSearchBackendElasticsearchBuildTimeConfig.IndexConfig indexConfig = entry.getValue(); | ||
registerClasspathFilesFromIndexConfig(mapperContext, backendName, indexName, indexConfig, | ||
applicationArchivesBuildItem, nativeImageResources, hotDeploymentWatchedFiles); | ||
} | ||
} | ||
|
||
private static void registerClasspathFilesFromIndexConfig(MapperContext mapperContext, String backendName, String indexName, | ||
HibernateSearchBackendElasticsearchBuildTimeConfig.IndexConfig indexConfig, | ||
ApplicationArchivesBuildItem applicationArchivesBuildItem, | ||
BuildProducer<NativeImageResourceBuildItem> nativeImageResources, | ||
BuildProducer<HotDeploymentWatchedFileBuildItem> hotDeploymentWatchedFiles) { | ||
registerClasspathFileFromConfig(mapperContext, backendName, indexName, "schema-management.settings-file", | ||
indexConfig.schemaManagement().settingsFile(), | ||
applicationArchivesBuildItem, nativeImageResources, hotDeploymentWatchedFiles); | ||
registerClasspathFileFromConfig(mapperContext, backendName, indexName, "schema-management.mapping-file", | ||
indexConfig.schemaManagement().mappingFile(), | ||
applicationArchivesBuildItem, nativeImageResources, hotDeploymentWatchedFiles); | ||
} | ||
|
||
private static void registerClasspathFileFromConfig(MapperContext mapperContext, String backendName, String indexName, | ||
String propertyKeyRadical, | ||
Optional<String> classpathFileOptional, | ||
ApplicationArchivesBuildItem applicationArchivesBuildItem, | ||
BuildProducer<NativeImageResourceBuildItem> nativeImageResources, | ||
BuildProducer<HotDeploymentWatchedFileBuildItem> hotDeploymentWatchedFiles) { | ||
if (!classpathFileOptional.isPresent()) { | ||
return; | ||
} | ||
String classpathFile = classpathFileOptional.get(); | ||
|
||
Path existingPath = applicationArchivesBuildItem.getRootArchive().getChildPath(classpathFile); | ||
|
||
if (existingPath == null || Files.isDirectory(existingPath)) { | ||
//raise exception if explicit file is not present (i.e. not the default) | ||
throw new ConfigurationException( | ||
"Unable to find file referenced in '" | ||
+ mapperContext.backendPropertyKey(backendName, indexName, propertyKeyRadical) + "=" | ||
+ classpathFile | ||
+ "'. Remove property or add file to your path."); | ||
} | ||
nativeImageResources.produce(new NativeImageResourceBuildItem(classpathFile)); | ||
hotDeploymentWatchedFiles.produce(new HotDeploymentWatchedFileBuildItem(classpathFile)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>quarkus-extensions-parent</artifactId> | ||
<groupId>io.quarkus</groupId> | ||
<version>999-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>quarkus-hibernate-search-backend-elasticsearch-parent</artifactId> | ||
<name>Quarkus - Hibernate Search - Elasticsearch</name> | ||
<packaging>pom</packaging> | ||
<modules> | ||
<module>deployment</module> | ||
<module>runtime</module> | ||
</modules> | ||
</project> |
55 changes: 55 additions & 0 deletions
55
extensions/hibernate-search-backend-elasticsearch/runtime/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>quarkus-hibernate-search-backend-elasticsearch-parent</artifactId> | ||
<groupId>io.quarkus</groupId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>quarkus-hibernate-search-backend-elasticsearch</artifactId> | ||
<name>Quarkus - Hibernate Search - Elasticsearch - Runtime</name> | ||
<description>Elasticsearch/OpenSearch backend for use in other Hibernate Search extensions</description> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-elasticsearch-rest-client-common</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hibernate.search</groupId> | ||
<artifactId>hibernate-search-backend-elasticsearch</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.graalvm.sdk</groupId> | ||
<artifactId>graal-sdk</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-processor</artifactId> | ||
<version>${project.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
2 changes: 1 addition & 1 deletion
2
...ime/ElasticsearchVersionSubstitution.java → ...ime/ElasticsearchVersionSubstitution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.