Skip to content

Commit

Permalink
Merge pull request #160 from yrodiere/configmapping
Browse files Browse the repository at this point in the history
Upgrade to quarkus-amazon-services 2.4.2 and migrate to @ConfigMapping
  • Loading branch information
yrodiere authored Aug 1, 2023
2 parents 8688ebe + 1d62b8c commit d70edf3
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 916 deletions.
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/includes/attributes.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
:quarkus-version: 3.2.0.Final
:quarkus-version: 3.2.2.Final
:quarkus-hibernate-search-extras-version: 2.0.3

:quarkus-org-url: https://github.com/quarkusio
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.hibernate.search.backend.elasticsearch.aws.cfg.ElasticsearchAwsBackendSettings;
import org.hibernate.search.backend.elasticsearch.aws.spi.ElasticsearcAwsCredentialsProvider;

import io.quarkus.hibernate.orm.runtime.PersistenceUnitUtil;
import io.quarkus.hibernate.orm.runtime.integration.HibernateOrmIntegrationRuntimeInitListener;
import io.quarkus.hibernate.search.orm.elasticsearch.aws.runtime.HibernateSearchOrmElasticsearchAwsRuntimeConfigPersistenceUnit.ElasticsearchBackendRuntimeConfig;
import io.quarkus.runtime.annotations.Recorder;
Expand All @@ -19,10 +18,8 @@ public class HibernateSearchOrmElasticsearchAwsRecorder {

public HibernateOrmIntegrationRuntimeInitListener createRuntimeInitListener(
HibernateSearchOrmElasticsearchAwsRuntimeConfig runtimeConfig, String persistenceUnitName) {
HibernateSearchOrmElasticsearchAwsRuntimeConfigPersistenceUnit puConfig = PersistenceUnitUtil
.isDefaultPersistenceUnit(persistenceUnitName)
? runtimeConfig.defaultPersistenceUnit
: runtimeConfig.persistenceUnits.get(persistenceUnitName);
HibernateSearchOrmElasticsearchAwsRuntimeConfigPersistenceUnit puConfig = runtimeConfig.persistenceUnits()
.get(persistenceUnitName);
if (puConfig == null) {
return null;
}
Expand All @@ -41,19 +38,16 @@ private RuntimeInitListener(

@Override
public void contributeRuntimeProperties(BiConsumer<String, Object> propertyCollector) {
contributeBackendRuntimeProperties(propertyCollector, null,
runtimeConfig.defaultBackend);

for (Entry<String, ElasticsearchBackendRuntimeConfig> backendEntry : runtimeConfig.namedBackends.backends
.entrySet()) {
for (Entry<String, ElasticsearchBackendRuntimeConfig> backendEntry : runtimeConfig.backends().entrySet()) {
contributeBackendRuntimeProperties(propertyCollector, backendEntry.getKey(), backendEntry.getValue());
}
}

private void contributeBackendRuntimeProperties(BiConsumer<String, Object> propertyCollector, String backendName,
ElasticsearchBackendRuntimeConfig elasticsearchBackendConfig) {
HibernateSearchOrmElasticsearchAwsRuntimeConfigPersistenceUnit.ElasticsearchBackendAwsConfig aws = elasticsearchBackendConfig.aws;
if (aws == null || !aws.signingEnabled) {
HibernateSearchOrmElasticsearchAwsRuntimeConfigPersistenceUnit.ElasticsearchBackendAwsConfig aws = elasticsearchBackendConfig
.aws();
if (aws == null || !aws.signing().enabled()) {
return;
}

Expand All @@ -64,16 +58,16 @@ private void contributeBackendRuntimeProperties(BiConsumer<String, Object> prope
? "quarkus.hibernate-search-orm.elasticsearch"
: "quarkus.hibernate-search-orm.elasticsearch.backends." + backendName;

if (!aws.region.isPresent()) {
if (aws.region().isEmpty()) {
String propertyKey = configKeyRoot + ".aws.region";
throw new RuntimeException(
"When AWS request signing is enabled, the AWS region needs to be defined via property '"
+ propertyKey + "'.");
}
addBackendConfig(propertyCollector, backendName, ElasticsearchAwsBackendSettings.REGION,
aws.region.get().id());
aws.region().get().id());

AwsCredentialsProvider credentialProvider = aws.credentials.type.create(aws.credentials, configKeyRoot);
AwsCredentialsProvider credentialProvider = aws.credentials().type().create(aws.credentials(), configKeyRoot);
addBackendConfig(propertyCollector, backendName, ElasticsearchAwsBackendSettings.CREDENTIALS_TYPE,
(ElasticsearcAwsCredentialsProvider) configurationPropertySource -> credentialProvider);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@

import java.util.Map;

import io.quarkus.hibernate.orm.runtime.PersistenceUnitUtil;
import io.quarkus.runtime.annotations.ConfigDocMapKey;
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;
import io.smallrye.config.WithUnnamedKey;

@ConfigRoot(name = "hibernate-search-orm", phase = ConfigPhase.RUN_TIME)
public class HibernateSearchOrmElasticsearchAwsRuntimeConfig {
@ConfigMapping(prefix = "quarkus.hibernate-search-orm")
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public interface HibernateSearchOrmElasticsearchAwsRuntimeConfig {

/**
* Configuration for the default persistence unit.
*/
@ConfigItem(name = ConfigItem.PARENT)
public HibernateSearchOrmElasticsearchAwsRuntimeConfigPersistenceUnit defaultPersistenceUnit;

/**
* Configuration for additional named persistence units.
* Configuration for persistence units.
*/
@WithParentName
@WithUnnamedKey(PersistenceUnitUtil.DEFAULT_PERSISTENCE_UNIT_NAME)
@ConfigDocMapKey("persistence-unit-name")
@ConfigItem(name = ConfigItem.PARENT)
public Map<String, HibernateSearchOrmElasticsearchAwsRuntimeConfigPersistenceUnit> persistenceUnits;
Map<String, HibernateSearchOrmElasticsearchAwsRuntimeConfigPersistenceUnit> persistenceUnits();

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,38 @@
import io.quarkus.amazon.common.runtime.AwsCredentialsProviderConfig;
import io.quarkus.runtime.annotations.ConfigDocMapKey;
import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.smallrye.config.WithName;
import io.smallrye.config.WithUnnamedKey;
import software.amazon.awssdk.regions.Region;

@ConfigGroup
public class HibernateSearchOrmElasticsearchAwsRuntimeConfigPersistenceUnit {
public interface HibernateSearchOrmElasticsearchAwsRuntimeConfigPersistenceUnit {

/**
* Default backend
* Configuration for backends.
*/
@ConfigItem(name = "elasticsearch")
ElasticsearchBackendRuntimeConfig defaultBackend;

/**
* Named backends
*/
@ConfigItem(name = "elasticsearch")
public ElasticsearchNamedBackendsRuntimeConfig namedBackends;

@ConfigGroup
public static class ElasticsearchNamedBackendsRuntimeConfig {

/**
* Named backends
*/
@ConfigDocMapKey("backend-name")
public Map<String, ElasticsearchBackendRuntimeConfig> backends;

}
@WithName("elasticsearch")
@WithUnnamedKey // The default backend has the null key
@ConfigDocMapKey("backend-name")
Map<String, ElasticsearchBackendRuntimeConfig> backends();

@ConfigGroup
public static class ElasticsearchBackendRuntimeConfig {
interface ElasticsearchBackendRuntimeConfig {

/**
* AWS services configurations
*/
@ConfigItem
ElasticsearchBackendAwsConfig aws;
ElasticsearchBackendAwsConfig aws();

}

@ConfigGroup
public static class ElasticsearchBackendAwsConfig {
interface ElasticsearchBackendAwsConfig {

/**
* Whether requests should be signed using the AWS credentials.
* Configuration for signing.
*/
@ConfigItem(name = "signing.enabled")
boolean signingEnabled;
ElasticsearchBackendAwsSigningConfig signing();

// @formatter:off
/**
Expand All @@ -66,14 +50,22 @@ public static class ElasticsearchBackendAwsConfig {
* @asciidoclet
*/
// @formatter:on
@ConfigItem
Optional<Region> region;
Optional<Region> region();

/**
* Defines the credentials provider.
*/
@ConfigItem
AwsCredentialsProviderConfig credentials;
AwsCredentialsProviderConfig credentials();

}

@ConfigGroup
interface ElasticsearchBackendAwsSigningConfig {

/**
* Whether requests should be signed using the AWS credentials.
*/
boolean enabled();

}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.version>3.2.2.Final</quarkus.version>
<maven-processor-plugin.version>4.5</maven-processor-plugin.version>
<quarkus-amazon-services.version>2.4.0</quarkus-amazon-services.version>
<quarkus-amazon-services.version>2.4.2</quarkus-amazon-services.version>
<!-- Unfortunately we cannot use a BOM for Maven plugin dependencies -->
<awssdk.version.for-annotation-processor>2.20.98</awssdk.version.for-annotation-processor>
<assertj.version>3.24.2</assertj.version>
Expand Down

0 comments on commit d70edf3

Please sign in to comment.