From edda14ad6c53f6016cf4ad0db994cd29ca39edff Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Wed, 24 May 2023 17:17:39 +0200 Subject: [PATCH] Switch Redis extension to @ConfigMapping --- .../client/deployment/DevServicesConfig.java | 42 ++--- .../deployment/DevServicesRedisProcessor.java | 16 +- .../deployment/RedisBuildTimeConfig.java | 53 +++--- .../RedisClientBuildTimeConfig.java | 22 +-- .../deployment/RedisClientProcessor.java | 20 +-- .../RedisConfigClientNamesTest.java | 155 +++++++++++------- .../runtime/client/RedisClientRecorder.java | 8 +- .../client/VertxRedisClientFactory.java | 124 +++++++------- .../runtime/client/config/NetConfig.java | 73 +++------ .../runtime/client/config/ProxyConfig.java | 21 +-- .../client/config/RedisClientConfig.java | 118 +++++++------ .../runtime/client/config/RedisConfig.java | 23 +-- .../runtime/client/config/TlsConfig.java | 34 ++-- .../client/health/RedisHealthCheck.java | 4 +- 14 files changed, 337 insertions(+), 376 deletions(-) diff --git a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesConfig.java b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesConfig.java index 53764787caf1f6..ea16fd0de08b74 100644 --- a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesConfig.java +++ b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesConfig.java @@ -1,14 +1,13 @@ package io.quarkus.redis.client.deployment; -import java.util.Objects; import java.util.Optional; import java.util.OptionalInt; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.WithDefault; @ConfigGroup -public class DevServicesConfig { +public interface DevServicesConfig { /** * If DevServices has been explicitly enabled or disabled. DevServices is generally enabled @@ -17,24 +16,22 @@ public class DevServicesConfig { * When DevServices is enabled Quarkus will attempt to automatically configure and start * a database when running in Dev or Test mode and when Docker is running. */ - @ConfigItem(defaultValue = "true") - public boolean enabled; + @WithDefault("true") + boolean enabled(); /** * The container image name to use, for container based DevServices providers. * If you want to use Redis Stack modules (bloom, graph, search...), use: * {@code redis/redis-stack-server:latest}. */ - @ConfigItem - public Optional imageName; + Optional imageName(); /** * Optional fixed port the dev service will listen to. *

* If not defined, the port will be chosen randomly. */ - @ConfigItem - public OptionalInt port; + OptionalInt port(); /** * Indicates if the Redis server managed by Quarkus Dev Services is shared. @@ -47,8 +44,8 @@ public class DevServicesConfig { *

* Container sharing is only used in dev mode. */ - @ConfigItem(defaultValue = "true") - public boolean shared; + @WithDefault("true") + boolean shared(); /** * The value of the {@code quarkus-dev-service-redis} label attached to the started container. @@ -60,25 +57,6 @@ public class DevServicesConfig { *

* This property is used when you need multiple shared Redis servers. */ - @ConfigItem(defaultValue = "redis") - public String serviceName; - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - DevServicesConfig that = (DevServicesConfig) o; - return enabled == that.enabled && - Objects.equals(imageName, that.imageName) && - Objects.equals(port, that.port) && - Objects.equals(shared, that.shared) && - Objects.equals(serviceName, that.serviceName); - } - - @Override - public int hashCode() { - return Objects.hash(enabled, imageName, port, shared, serviceName); - } + @WithDefault("redis") + String serviceName(); } diff --git a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesRedisProcessor.java b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesRedisProcessor.java index f189bacacbeac8..86f31b4e7f7603 100644 --- a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesRedisProcessor.java +++ b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesRedisProcessor.java @@ -70,8 +70,8 @@ public List startRedisContainers(LaunchModeBuildItem LoggingSetupBuildItem loggingSetupBuildItem, GlobalDevServicesConfig devServicesConfig) { - Map currentDevServicesConfiguration = new HashMap<>(config.additionalDevServices); - currentDevServicesConfiguration.put(RedisConfig.DEFAULT_CLIENT_NAME, config.defaultDevService); + Map currentDevServicesConfiguration = new HashMap<>(config.additionalDevServices()); + currentDevServicesConfiguration.put(RedisConfig.DEFAULT_CLIENT_NAME, config.defaultDevService()); // figure out if we need to shut down and restart existing redis containers // if not and the redis containers have already started we just return @@ -101,7 +101,7 @@ public List startRedisContainers(LaunchModeBuildItem for (Entry entry : currentDevServicesConfiguration.entrySet()) { String connectionName = entry.getKey(); RunningDevService devService = startContainer(dockerStatusBuildItem, connectionName, - entry.getValue().devservices, + entry.getValue().devservices(), launchMode.getLaunchMode(), !devServicesSharedNetworkBuildItem.isEmpty(), devServicesConfig.timeout); if (devService == null) { @@ -148,7 +148,7 @@ public List startRedisContainers(LaunchModeBuildItem private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuildItem, String name, DevServicesConfig devServicesConfig, LaunchMode launchMode, boolean useSharedNetwork, Optional timeout) { - if (!devServicesConfig.enabled) { + if (!devServicesConfig.enabled()) { // explicitly disabled log.debug("Not starting devservices for " + (RedisConfig.isDefaultClient(name) ? "default redis client" : name) + " as it has been disabled in the config"); @@ -171,12 +171,12 @@ private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuild return null; } - DockerImageName dockerImageName = DockerImageName.parse(devServicesConfig.imageName.orElse(REDIS_7_ALPINE)) + DockerImageName dockerImageName = DockerImageName.parse(devServicesConfig.imageName().orElse(REDIS_7_ALPINE)) .asCompatibleSubstituteFor(REDIS_7_ALPINE); Supplier defaultRedisServerSupplier = () -> { - QuarkusPortRedisContainer redisContainer = new QuarkusPortRedisContainer(dockerImageName, devServicesConfig.port, - launchMode == DEVELOPMENT ? devServicesConfig.serviceName : null, useSharedNetwork); + QuarkusPortRedisContainer redisContainer = new QuarkusPortRedisContainer(dockerImageName, devServicesConfig.port(), + launchMode == DEVELOPMENT ? devServicesConfig.serviceName() : null, useSharedNetwork); timeout.ifPresent(redisContainer::withStartupTimeout); redisContainer.start(); String redisHost = REDIS_SCHEME + redisContainer.getHost() + ":" + redisContainer.getPort(); @@ -184,7 +184,7 @@ private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuild redisContainer::close, configPrefix + RedisConfig.HOSTS_CONFIG_NAME, redisHost); }; - return redisContainerLocator.locateContainer(devServicesConfig.serviceName, devServicesConfig.shared, launchMode) + return redisContainerLocator.locateContainer(devServicesConfig.serviceName(), devServicesConfig.shared(), launchMode) .map(containerAddress -> { String redisUrl = REDIS_SCHEME + containerAddress.getUrl(); return new RunningDevService(Feature.REDIS_CLIENT.getName(), containerAddress.getId(), diff --git a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisBuildTimeConfig.java b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisBuildTimeConfig.java index a6bac1a32ee56e..155c6d3cb8b60b 100644 --- a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisBuildTimeConfig.java +++ b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisBuildTimeConfig.java @@ -1,21 +1,25 @@ package io.quarkus.redis.client.deployment; import java.util.Map; -import java.util.Objects; import io.quarkus.runtime.annotations.ConfigDocMapKey; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; +import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefault; +import io.smallrye.config.WithName; +import io.smallrye.config.WithParentName; -@ConfigRoot -public class RedisBuildTimeConfig { +@ConfigMapping(prefix = "quarkus.redis") +@ConfigRoot(phase = ConfigPhase.BUILD_TIME) +public interface RedisBuildTimeConfig { /** * The default redis client */ - @ConfigItem(name = ConfigItem.PARENT) - public RedisClientBuildTimeConfig defaultRedisClient; + @WithParentName + RedisClientBuildTimeConfig defaultRedisClient(); /** * Configures additional (named) Redis clients. @@ -44,52 +48,37 @@ public class RedisBuildTimeConfig { * } * */ - @ConfigItem(name = ConfigItem.PARENT) + @WithParentName @ConfigDocMapKey("redis-client-name") - public Map namedRedisClients; + Map namedRedisClients(); /** * Whether a health check is published in case the smallrye-health extension is present. */ - @ConfigItem(name = "health.enabled", defaultValue = "true") - public boolean healthEnabled; + @WithName("health.enabled") + @WithDefault("true") + boolean healthEnabled(); /** * Default Dev services configuration. */ - @ConfigItem(name = ConfigItem.PARENT) - public DevServiceConfiguration defaultDevService; + @WithParentName + DevServiceConfiguration defaultDevService(); /** * Additional dev services configurations */ - @ConfigItem(name = ConfigItem.PARENT) + @WithParentName @ConfigDocMapKey("additional-redis-clients") - public Map additionalDevServices; + Map additionalDevServices(); @ConfigGroup - public static class DevServiceConfiguration { + public interface DevServiceConfiguration { /** * Configuration for DevServices *

* DevServices allows Quarkus to automatically start Redis in dev and test mode. */ - @ConfigItem - public DevServicesConfig devservices; - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - DevServiceConfiguration that = (DevServiceConfiguration) o; - return Objects.equals(devservices, that.devservices); - } - - @Override - public int hashCode() { - return Objects.hash(devservices); - } + DevServicesConfig devservices(); } } diff --git a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisClientBuildTimeConfig.java b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisClientBuildTimeConfig.java index 35881a5a397a38..b3e48cd264520d 100644 --- a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisClientBuildTimeConfig.java +++ b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisClientBuildTimeConfig.java @@ -3,14 +3,14 @@ import java.util.List; import java.util.Optional; +import io.quarkus.runtime.annotations.ConfigDocDefault; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; -import io.quarkus.runtime.annotations.ConvertWith; import io.quarkus.runtime.configuration.TrimmedStringConverter; +import io.smallrye.config.WithConverter; +import io.smallrye.config.WithDefault; -@SuppressWarnings("OptionalUsedAsFieldOrParameterType") @ConfigGroup -public class RedisClientBuildTimeConfig { +public interface RedisClientBuildTimeConfig { /** * A list of files allowing to pre-load data into the Redis server. @@ -23,20 +23,20 @@ public class RedisClientBuildTimeConfig { *

  • Parameters including double-quotes must be wrapped into single-quotes
  • * */ - @ConfigItem(defaultValueDocumentation = "import.redis in DEV, TEST ; no-file otherwise") - @ConvertWith(TrimmedStringConverter.class) - public Optional> loadScript; + @ConfigDocDefault("import.redis in DEV, TEST ; no-file otherwise") + @WithConverter(TrimmedStringConverter.class) + Optional> loadScript(); /** * When using {@code redisLoadScript}, indicates if the Redis database must be flushed (erased) before importing. */ - @ConfigItem(defaultValue = "true") - public boolean flushBeforeLoad; + @WithDefault("true") + boolean flushBeforeLoad(); /** * When using {@code redisLoadScript}, indicates if the import should only happen if the database is empty (no keys). */ - @ConfigItem(defaultValue = "true") - public boolean loadOnlyIfEmpty; + @WithDefault("true") + boolean loadOnlyIfEmpty(); } diff --git a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisClientProcessor.java b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisClientProcessor.java index f745b7079eb880..385a55f168cfc6 100644 --- a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisClientProcessor.java +++ b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisClientProcessor.java @@ -182,12 +182,12 @@ public void init( recorder.cleanup(shutdown); // Handle data import - preloadRedisData(DEFAULT_CLIENT_NAME, buildTimeConfig.defaultRedisClient, applicationArchivesBuildItem, + preloadRedisData(DEFAULT_CLIENT_NAME, buildTimeConfig.defaultRedisClient(), applicationArchivesBuildItem, launchMode.getLaunchMode(), nativeImageResources, hotDeploymentWatchedFiles, recorder); - if (buildTimeConfig.namedRedisClients != null) { - for (Map.Entry entry : buildTimeConfig.namedRedisClients.entrySet()) { + if (buildTimeConfig.namedRedisClients() != null) { + for (Map.Entry entry : buildTimeConfig.namedRedisClients().entrySet()) { preloadRedisData(entry.getKey(), entry.getValue(), applicationArchivesBuildItem, launchMode.getLaunchMode(), nativeImageResources, hotDeploymentWatchedFiles, recorder); } @@ -197,10 +197,10 @@ public void init( static Set configuredClientNames(RedisBuildTimeConfig buildTimeConfig, Config config) { Set names = new HashSet<>(); // redis client names from dev services - if (buildTimeConfig.defaultDevService.devservices.enabled) { + if (buildTimeConfig.defaultDevService().devservices().enabled()) { names.add(DEFAULT_CLIENT_NAME); } - names.addAll(buildTimeConfig.additionalDevServices.keySet()); + names.addAll(buildTimeConfig.additionalDevServices().keySet()); // redis client names declared in config for (String propertyName : config.getPropertyNames()) { if (propertyName.equals("quarkus.redis.hosts")) { @@ -255,12 +255,12 @@ private void preloadRedisData(String name, RedisClientBuildTimeConfig clientConf if (loadScriptPath != null && !Files.isDirectory(loadScriptPath)) { // enlist resource if present nativeImageResources.produce(new NativeImageResourceBuildItem(importFile)); - } else if (clientConfig != null && clientConfig.loadScript.isPresent()) { + } else if (clientConfig != null && clientConfig.loadScript().isPresent()) { //raise exception if explicit file is not present (i.e. not the default) throw new ConfigurationException( "Unable to find file referenced in '" + RedisConfig.propertyKey(name, "redis-load-script") + "=" - + String.join(", ", clientConfig.loadScript.get()) + + String.join(", ", clientConfig.loadScript().get()) + "'. Remove property or add file to your path."); } // in dev mode we want to make sure that we watch for changes to file even if it doesn't currently exist @@ -274,7 +274,7 @@ private void preloadRedisData(String name, RedisClientBuildTimeConfig clientConf if (!paths.isEmpty()) { if (clientConfig != null) { - recorder.preload(name, paths, clientConfig.flushBeforeLoad, clientConfig.loadOnlyIfEmpty); + recorder.preload(name, paths, clientConfig.flushBeforeLoad(), clientConfig.loadOnlyIfEmpty()); } else { recorder.preload(name, paths, true, true); } @@ -285,7 +285,7 @@ private void preloadRedisData(String name, RedisClientBuildTimeConfig clientConf @BuildStep HealthBuildItem addHealthCheck(RedisBuildTimeConfig buildTimeConfig) { return new HealthBuildItem("io.quarkus.redis.runtime.client.health.RedisHealthCheck", - buildTimeConfig.healthEnabled); + buildTimeConfig.healthEnabled()); } public static final String NO_REDIS_SCRIPT_FILE = "no-file"; @@ -294,7 +294,7 @@ private static List getRedisLoadScript(RedisClientBuildTimeConfig config if (config == null) { return List.of("import.redis"); } - var scripts = config.loadScript; + var scripts = config.loadScript(); if (scripts.isPresent()) { return scripts.get().stream() .filter(s -> !NO_REDIS_SCRIPT_FILE.equalsIgnoreCase(s)) diff --git a/extensions/redis-client/deployment/src/test/java/io/quarkus/redis/client/deployment/RedisConfigClientNamesTest.java b/extensions/redis-client/deployment/src/test/java/io/quarkus/redis/client/deployment/RedisConfigClientNamesTest.java index 96e88d108df4bd..4aff1f9b04f273 100644 --- a/extensions/redis-client/deployment/src/test/java/io/quarkus/redis/client/deployment/RedisConfigClientNamesTest.java +++ b/extensions/redis-client/deployment/src/test/java/io/quarkus/redis/client/deployment/RedisConfigClientNamesTest.java @@ -3,12 +3,15 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.Map; +import java.util.Optional; +import java.util.OptionalInt; import java.util.Set; import org.eclipse.microprofile.config.spi.ConfigProviderResolver; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; +import io.quarkus.redis.client.deployment.RedisBuildTimeConfig.DevServiceConfiguration; import io.smallrye.config.SmallRyeConfig; import io.smallrye.config.SmallRyeConfigBuilder; import io.smallrye.config.common.MapBackedConfigSource; @@ -34,14 +37,10 @@ private void createConfig(Map configMap) { @Test void testWithEmptyConfig() { createConfig(Map.of()); - DevServicesConfig devservices = new DevServicesConfig(); - RedisBuildTimeConfig.DevServiceConfiguration devService = new RedisBuildTimeConfig.DevServiceConfiguration(); - devService.devservices = devservices; - - RedisBuildTimeConfig redisBuildTimeConfig = new RedisBuildTimeConfig(); - redisBuildTimeConfig.defaultDevService = devService; - redisBuildTimeConfig.additionalDevServices = Map.of(); + RedisBuildTimeConfig redisBuildTimeConfig = createRedisBuildTimeConfig( + createDevServiceConfiguration(false), + Map.of()); Set names = RedisClientProcessor.configuredClientNames(redisBuildTimeConfig, config); assertThat(names).isEmpty(); @@ -50,15 +49,10 @@ void testWithEmptyConfig() { @Test void testWithDefaultConfig() { createConfig(Map.of()); - DevServicesConfig devservices = new DevServicesConfig(); - devservices.enabled = true; - - RedisBuildTimeConfig.DevServiceConfiguration devService = new RedisBuildTimeConfig.DevServiceConfiguration(); - devService.devservices = devservices; - RedisBuildTimeConfig redisBuildTimeConfig = new RedisBuildTimeConfig(); - redisBuildTimeConfig.defaultDevService = devService; - redisBuildTimeConfig.additionalDevServices = Map.of(); + RedisBuildTimeConfig redisBuildTimeConfig = createRedisBuildTimeConfig( + createDevServiceConfiguration(true), + Map.of()); Set names = RedisClientProcessor.configuredClientNames(redisBuildTimeConfig, config); assertThat(names).containsOnly(""); @@ -67,21 +61,10 @@ void testWithDefaultConfig() { @Test void testWithAdditionalDevServices() { createConfig(Map.of()); - DevServicesConfig devservicesCfg = new DevServicesConfig(); - devservicesCfg.enabled = true; - - RedisBuildTimeConfig.DevServiceConfiguration devService = new RedisBuildTimeConfig.DevServiceConfiguration(); - devService.devservices = devservicesCfg; - RedisBuildTimeConfig redisBuildTimeConfig = new RedisBuildTimeConfig(); - redisBuildTimeConfig.defaultDevService = devService; - - DevServicesConfig additionalDevService = new DevServicesConfig(); - additionalDevService.enabled = true; - - RedisBuildTimeConfig.DevServiceConfiguration additional = new RedisBuildTimeConfig.DevServiceConfiguration(); - additional.devservices = additionalDevService; - redisBuildTimeConfig.additionalDevServices = Map.of("additional", additional); + RedisBuildTimeConfig redisBuildTimeConfig = createRedisBuildTimeConfig( + createDevServiceConfiguration(true), + Map.of("additional", createDevServiceConfiguration(true))); Set names = RedisClientProcessor.configuredClientNames(redisBuildTimeConfig, config); assertThat(names).containsOnly("", "additional"); @@ -90,21 +73,10 @@ void testWithAdditionalDevServices() { @Test void testWithDisabledDefaultDevServiceConfig() { createConfig(Map.of()); - DevServicesConfig devservicesCfg = new DevServicesConfig(); - devservicesCfg.enabled = false; - - RedisBuildTimeConfig.DevServiceConfiguration devService = new RedisBuildTimeConfig.DevServiceConfiguration(); - devService.devservices = devservicesCfg; - RedisBuildTimeConfig redisBuildTimeConfig = new RedisBuildTimeConfig(); - redisBuildTimeConfig.defaultDevService = devService; - - DevServicesConfig additionalDevService = new DevServicesConfig(); - additionalDevService.enabled = true; - - RedisBuildTimeConfig.DevServiceConfiguration additional = new RedisBuildTimeConfig.DevServiceConfiguration(); - additional.devservices = additionalDevService; - redisBuildTimeConfig.additionalDevServices = Map.of("additional", additional); + RedisBuildTimeConfig redisBuildTimeConfig = createRedisBuildTimeConfig( + createDevServiceConfiguration(false), + Map.of("additional", createDevServiceConfiguration(true))); Set names = RedisClientProcessor.configuredClientNames(redisBuildTimeConfig, config); assertThat(names).containsOnly("additional"); @@ -113,16 +85,10 @@ void testWithDisabledDefaultDevServiceConfig() { @Test void testWithDisabledDefaultDevServiceWithHostsConfig() { createConfig(Map.of("quarkus.redis.hosts", "redis://localhost:1234")); - DevServicesConfig devservicesCfg = new DevServicesConfig(); - devservicesCfg.enabled = false; - - RedisBuildTimeConfig.DevServiceConfiguration devService = new RedisBuildTimeConfig.DevServiceConfiguration(); - devService.devservices = devservicesCfg; - RedisBuildTimeConfig redisBuildTimeConfig = new RedisBuildTimeConfig(); - redisBuildTimeConfig.defaultDevService = devService; - - redisBuildTimeConfig.additionalDevServices = Map.of(); + RedisBuildTimeConfig redisBuildTimeConfig = createRedisBuildTimeConfig( + createDevServiceConfiguration(false), + Map.of()); Set names = RedisClientProcessor.configuredClientNames(redisBuildTimeConfig, config); assertThat(names).containsOnly(""); @@ -132,18 +98,85 @@ void testWithDisabledDefaultDevServiceWithHostsConfig() { void testWithDisabledDefaultDevServiceWithAdditionalHostsConfig() { createConfig(Map.of("quarkus.redis.my-redis.hosts", "redis://localhost:5678", "quarkus.redis.my-redis-2.hosts-provider-name", "my-redis-2-provider")); - DevServicesConfig devservicesCfg = new DevServicesConfig(); - devservicesCfg.enabled = false; - - RedisBuildTimeConfig.DevServiceConfiguration devService = new RedisBuildTimeConfig.DevServiceConfiguration(); - devService.devservices = devservicesCfg; - - RedisBuildTimeConfig redisBuildTimeConfig = new RedisBuildTimeConfig(); - redisBuildTimeConfig.defaultDevService = devService; - redisBuildTimeConfig.additionalDevServices = Map.of(); + RedisBuildTimeConfig redisBuildTimeConfig = createRedisBuildTimeConfig( + createDevServiceConfiguration(false), + Map.of()); Set names = RedisClientProcessor.configuredClientNames(redisBuildTimeConfig, config); assertThat(names).containsOnly("my-redis", "my-redis-2"); } + + private static RedisBuildTimeConfig createRedisBuildTimeConfig(DevServiceConfiguration defaultDevService, + Map additionalDevServices) { + RedisBuildTimeConfig redisBuildTimeConfig = new RedisBuildTimeConfig() { + + @Override + public RedisClientBuildTimeConfig defaultRedisClient() { + return null; + } + + @Override + public Map namedRedisClients() { + return Map.of(); + } + + @Override + public boolean healthEnabled() { + return false; + } + + @Override + public DevServiceConfiguration defaultDevService() { + return defaultDevService; + } + + @Override + public Map additionalDevServices() { + return additionalDevServices; + } + }; + + return redisBuildTimeConfig; + } + + private static DevServiceConfiguration createDevServiceConfiguration(boolean enabled) { + DevServicesConfig devServicesConfig = new DevServicesConfig() { + + @Override + public boolean enabled() { + return enabled; + } + + @Override + public Optional imageName() { + return Optional.empty(); + } + + @Override + public OptionalInt port() { + return OptionalInt.empty(); + } + + @Override + public boolean shared() { + return false; + } + + @Override + public String serviceName() { + return null; + } + }; + + DevServiceConfiguration devServiceConfiguration = new DevServiceConfiguration() { + + @Override + public DevServicesConfig devservices() { + return devServicesConfig; + } + }; + + return devServiceConfiguration; + } } diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/RedisClientRecorder.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/RedisClientRecorder.java index a649952c0f322b..be8647c2707f36 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/RedisClientRecorder.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/RedisClientRecorder.java @@ -91,10 +91,10 @@ public ConfigurationException get() { static Optional getConfigForName(RedisConfig cfg, String name) { if (RedisConfig.isDefaultClient(name)) { - return Optional.ofNullable(cfg.defaultRedisClient); + return Optional.ofNullable(cfg.defaultRedisClient()); } - for (Map.Entry entry : cfg.namedRedisClients.entrySet()) { + for (Map.Entry entry : cfg.namedRedisClients().entrySet()) { if (entry.getKey().equalsIgnoreCase(name)) { return Optional.of(entry.getValue()); } @@ -180,9 +180,9 @@ public RedisClient get() { private Duration getTimeoutForClient(String name) { Duration timeout; if (RedisConfig.isDefaultClient(name)) { - timeout = config.defaultRedisClient.timeout; + timeout = config.defaultRedisClient().timeout(); } else { - timeout = config.namedRedisClients.get(name).timeout; + timeout = config.namedRedisClients().get(name).timeout(); } return timeout; } diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/VertxRedisClientFactory.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/VertxRedisClientFactory.java index 9cf4ec222e5d29..9892d47af009be 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/VertxRedisClientFactory.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/VertxRedisClientFactory.java @@ -44,13 +44,13 @@ public static Redis create(String name, Vertx vertx, RedisClientConfig config) { RedisOptions options = new RedisOptions(); List hosts = new ArrayList<>(); - if (config.hosts.isPresent()) { - hosts.addAll(config.hosts.get()); - for (URI uri : config.hosts.get()) { + if (config.hosts().isPresent()) { + hosts.addAll(config.hosts().get()); + for (URI uri : config.hosts().get()) { options.addConnectionString(uri.toString().trim()); } - } else if (config.hostsProviderName.isPresent()) { - RedisHostsProvider hostsProvider = findProvider(config.hostsProviderName.get()); + } else if (config.hostsProviderName().isPresent()) { + RedisHostsProvider hostsProvider = findProvider(config.hostsProviderName().get()); hosts.addAll(hostsProvider.getHosts()); for (URI uri : hostsProvider.getHosts()) { options.addConnectionString(uri.toString()); @@ -60,26 +60,26 @@ public static Redis create(String name, Vertx vertx, RedisClientConfig config) { " 'quarkus.redis.host-provider-name' and have a bean providing the hosts programmatically."); } - if (RedisClientType.STANDALONE == config.clientType) { + if (RedisClientType.STANDALONE == config.clientType()) { if (hosts.size() > 1) { throw new ConfigurationException("Multiple Redis hosts supplied for non-clustered configuration"); } } - config.masterName.ifPresent(options::setMasterName); - options.setMaxNestedArrays(config.maxNestedArrays); - options.setMaxPoolSize(config.maxPoolSize); - options.setMaxPoolWaiting(config.maxPoolWaiting); - options.setMaxWaitingHandlers(config.maxWaitingHandlers); + config.masterName().ifPresent(options::setMasterName); + options.setMaxNestedArrays(config.maxNestedArrays()); + options.setMaxPoolSize(config.maxPoolSize()); + options.setMaxPoolWaiting(config.maxPoolWaiting()); + options.setMaxWaitingHandlers(config.maxWaitingHandlers()); - options.setProtocolNegotiation(config.protocolNegotiation); - options.setPassword(config.password.orElse(null)); - config.poolCleanerInterval.ifPresent(d -> options.setPoolCleanerInterval((int) d.toMillis())); - options.setPoolRecycleTimeout((int) config.poolRecycleTimeout.toMillis()); + options.setProtocolNegotiation(config.protocolNegotiation()); + options.setPassword(config.password().orElse(null)); + config.poolCleanerInterval().ifPresent(d -> options.setPoolCleanerInterval((int) d.toMillis())); + options.setPoolRecycleTimeout((int) config.poolRecycleTimeout().toMillis()); - config.role.ifPresent(options::setRole); - options.setType(config.clientType); - config.replicas.ifPresent(options::setUseReplicas); + config.role().ifPresent(options::setRole); + options.setType(config.clientType()); + config.replicas().ifPresent(options::setUseReplicas); options.setNetClientOptions(toNetClientOptions(config)); @@ -105,61 +105,61 @@ private static void customize(String name, RedisOptions options) { } private static NetClientOptions toNetClientOptions(RedisClientConfig config) { - NetConfig tcp = config.tcp; - TlsConfig tls = config.tls; + NetConfig tcp = config.tcp(); + TlsConfig tls = config.tls(); NetClientOptions net = new NetClientOptions(); - tcp.alpn.ifPresent(net::setUseAlpn); - tcp.applicationLayerProtocols.ifPresent(net::setApplicationLayerProtocols); - tcp.connectionTimeout.ifPresent(d -> net.setConnectTimeout((int) d.toMillis())); - tls.hostnameVerificationAlgorithm.ifPresent(net::setHostnameVerificationAlgorithm); - tcp.idleTimeout.ifPresent(d -> net.setIdleTimeout((int) d.toSeconds())); + tcp.alpn().ifPresent(net::setUseAlpn); + tcp.applicationLayerProtocols().ifPresent(net::setApplicationLayerProtocols); + tcp.connectionTimeout().ifPresent(d -> net.setConnectTimeout((int) d.toMillis())); + tls.hostnameVerificationAlgorithm().ifPresent(net::setHostnameVerificationAlgorithm); + tcp.idleTimeout().ifPresent(d -> net.setIdleTimeout((int) d.toSeconds())); - tcp.keepAlive.ifPresent(b -> net.setTcpKeepAlive(true)); - tcp.noDelay.ifPresent(b -> net.setTcpNoDelay(true)); + tcp.keepAlive().ifPresent(b -> net.setTcpKeepAlive(true)); + tcp.noDelay().ifPresent(b -> net.setTcpNoDelay(true)); - net.setSsl(tls.enabled).setTrustAll(tls.trustAll); + net.setSsl(tls.enabled()).setTrustAll(tls.trustAll()); - configurePemTrustOptions(net, tls.trustCertificatePem); - configureJksTrustOptions(net, tls.trustCertificateJks); - configurePfxTrustOptions(net, tls.trustCertificatePfx); + configurePemTrustOptions(net, tls.trustCertificatePem()); + configureJksTrustOptions(net, tls.trustCertificateJks()); + configurePfxTrustOptions(net, tls.trustCertificatePfx()); - configurePemKeyCertOptions(net, tls.keyCertificatePem); - configureJksKeyCertOptions(net, tls.keyCertificateJks); - configurePfxKeyCertOptions(net, tls.keyCertificatePfx); + configurePemKeyCertOptions(net, tls.keyCertificatePem()); + configureJksKeyCertOptions(net, tls.keyCertificateJks()); + configurePfxKeyCertOptions(net, tls.keyCertificatePfx()); - net.setReconnectAttempts(config.reconnectAttempts); - net.setReconnectInterval(config.reconnectInterval.toMillis()); + net.setReconnectAttempts(config.reconnectAttempts()); + net.setReconnectInterval(config.reconnectInterval().toMillis()); - tcp.localAddress.ifPresent(net::setLocalAddress); - tcp.nonProxyHosts.ifPresent(net::setNonProxyHosts); - tcp.proxyOptions.ifPresent(s -> { + tcp.localAddress().ifPresent(net::setLocalAddress); + tcp.nonProxyHosts().ifPresent(net::setNonProxyHosts); + tcp.proxyOptions().ifPresent(s -> { ProxyOptions po = new ProxyOptions(); - po.setHost(s.host); - po.setType(s.type); - po.setPort(s.port); - s.username.ifPresent(po::setUsername); - s.password.ifPresent(po::setPassword); + s.host().ifPresent(po::setHost); + po.setType(s.type()); + po.setPort(s.port()); + s.username().ifPresent(po::setUsername); + s.password().ifPresent(po::setPassword); net.setProxyOptions(po); }); - tcp.readIdleTimeout.ifPresent(d -> net.setReadIdleTimeout((int) d.toSeconds())); - tcp.reconnectAttempts.ifPresent(net::setReconnectAttempts); - tcp.reconnectInterval.ifPresent(v -> net.setReconnectInterval(v.toMillis())); - tcp.reuseAddress.ifPresent(net::setReuseAddress); - tcp.reusePort.ifPresent(net::setReusePort); - tcp.receiveBufferSize.ifPresent(net::setReceiveBufferSize); - tcp.sendBufferSize.ifPresent(net::setSendBufferSize); - tcp.soLinger.ifPresent(d -> net.setSoLinger((int) d.toMillis())); - tcp.secureTransportProtocols.ifPresent(net::setEnabledSecureTransportProtocols); - tcp.trafficClass.ifPresent(net::setTrafficClass); - tcp.noDelay.ifPresent(net::setTcpNoDelay); - tcp.cork.ifPresent(net::setTcpCork); - tcp.keepAlive.ifPresent(net::setTcpKeepAlive); - tcp.fastOpen.ifPresent(net::setTcpFastOpen); - tcp.quickAck.ifPresent(net::setTcpQuickAck); - tcp.writeIdleTimeout.ifPresent(d -> net.setWriteIdleTimeout((int) d.toSeconds())); - - tls.hostnameVerificationAlgorithm.ifPresent(net::setHostnameVerificationAlgorithm); + tcp.readIdleTimeout().ifPresent(d -> net.setReadIdleTimeout((int) d.toSeconds())); + tcp.reconnectAttempts().ifPresent(net::setReconnectAttempts); + tcp.reconnectInterval().ifPresent(v -> net.setReconnectInterval(v.toMillis())); + tcp.reuseAddress().ifPresent(net::setReuseAddress); + tcp.reusePort().ifPresent(net::setReusePort); + tcp.receiveBufferSize().ifPresent(net::setReceiveBufferSize); + tcp.sendBufferSize().ifPresent(net::setSendBufferSize); + tcp.soLinger().ifPresent(d -> net.setSoLinger((int) d.toMillis())); + tcp.secureTransportProtocols().ifPresent(net::setEnabledSecureTransportProtocols); + tcp.trafficClass().ifPresent(net::setTrafficClass); + tcp.noDelay().ifPresent(net::setTcpNoDelay); + tcp.cork().ifPresent(net::setTcpCork); + tcp.keepAlive().ifPresent(net::setTcpKeepAlive); + tcp.fastOpen().ifPresent(net::setTcpFastOpen); + tcp.quickAck().ifPresent(net::setTcpQuickAck); + tcp.writeIdleTimeout().ifPresent(d -> net.setWriteIdleTimeout((int) d.toSeconds())); + + tls.hostnameVerificationAlgorithm().ifPresent(net::setHostnameVerificationAlgorithm); return net; } diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/NetConfig.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/NetConfig.java index 842332498f43bd..da29b69e8d51be 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/NetConfig.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/NetConfig.java @@ -7,149 +7,124 @@ import java.util.Set; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; -@SuppressWarnings("OptionalUsedAsFieldOrParameterType") @ConfigGroup -public class NetConfig { +public interface NetConfig { /** * Set the ALPN usage. */ - @ConfigItem - public Optional alpn; + Optional alpn(); /** * Sets the list of application-layer protocols to provide to the server during the * {@code Application-Layer Protocol Negotiation}. */ - @ConfigItem - public Optional> applicationLayerProtocols; + Optional> applicationLayerProtocols(); /** * Sets the list of enabled SSL/TLS protocols. */ - @ConfigItem - public Optional> secureTransportProtocols; + Optional> secureTransportProtocols(); /** * Set the idle timeout. */ - @ConfigItem - public Optional idleTimeout; + Optional idleTimeout(); /** * Set the connect timeout. */ - @ConfigItem - public Optional connectionTimeout; + Optional connectionTimeout(); /** * Set a list of remote hosts that are not proxied when the client is configured to use a proxy. */ - @ConfigItem - public Optional> nonProxyHosts; + Optional> nonProxyHosts(); /** * Set proxy options for connections via CONNECT proxy */ - @ConfigItem - public Optional proxyOptions; + Optional proxyOptions(); /** * Set the read idle timeout. */ - @ConfigItem - public Optional readIdleTimeout; + Optional readIdleTimeout(); /** * Set the TCP receive buffer size. */ - @ConfigItem - public OptionalInt receiveBufferSize; + OptionalInt receiveBufferSize(); /** * Set the value of reconnect attempts. */ - @ConfigItem - public OptionalInt reconnectAttempts; + OptionalInt reconnectAttempts(); /** * Set the reconnect interval. */ - @ConfigItem - public Optional reconnectInterval; + Optional reconnectInterval(); /** * Whether to reuse the address. */ - @ConfigItem - public Optional reuseAddress; + Optional reuseAddress(); /** * Whether to reuse the port. */ - @ConfigItem - public Optional reusePort; + Optional reusePort(); /** * Set the TCP send buffer size. */ - @ConfigItem - public OptionalInt sendBufferSize; + OptionalInt sendBufferSize(); /** * Set the {@code SO_linger} keep alive duration. */ - @ConfigItem - public Optional soLinger; + Optional soLinger(); /** * Enable the {@code TCP_CORK} option - only with linux native transport. */ - @ConfigItem - public Optional cork; + Optional cork(); /** * Enable the {@code TCP_FASTOPEN} option - only with linux native transport. */ - @ConfigItem - public Optional fastOpen; + Optional fastOpen(); /** * Set whether keep alive is enabled */ - @ConfigItem - public Optional keepAlive; + Optional keepAlive(); /** * Set whether no delay is enabled */ - @ConfigItem - public Optional noDelay; + Optional noDelay(); /** * Enable the {@code TCP_QUICKACK} option - only with linux native transport. */ - @ConfigItem - public Optional quickAck; + Optional quickAck(); /** * Set the value of traffic class. */ - @ConfigItem - public OptionalInt trafficClass; + OptionalInt trafficClass(); /** * Set the write idle timeout. */ - @ConfigItem - public Optional writeIdleTimeout; + Optional writeIdleTimeout(); /** * Set the local interface to bind for network connections. * When the local address is null, it will pick any local address, the default local address is null. */ - @ConfigItem - public Optional localAddress; + Optional localAddress(); } diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/ProxyConfig.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/ProxyConfig.java index bb6fb3b040b813..aff77e22892b3a 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/ProxyConfig.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/ProxyConfig.java @@ -3,41 +3,38 @@ import java.util.Optional; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; +import io.smallrye.config.WithDefault; import io.vertx.core.net.ProxyType; @ConfigGroup -public class ProxyConfig { +public interface ProxyConfig { /** * Set proxy username. */ - @ConfigItem - public Optional username; + Optional username(); /** * Set proxy password. */ - @ConfigItem - public Optional password; + Optional password(); /** * Set proxy port. Defaults to 3128. */ - @ConfigItem(defaultValue = "3128") - public int port; + @WithDefault("3128") + int port(); /** * Set proxy host. */ - @ConfigItem - public String host; + Optional host(); /** * Set proxy type. * Accepted values are: {@code HTTP} (default), {@code SOCKS4} and {@code SOCKS5}. */ - @ConfigItem(defaultValue = "http") - public ProxyType type; + @WithDefault("http") + ProxyType type(); } diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/RedisClientConfig.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/RedisClientConfig.java index 7a193cd474a06f..5fcd5069be44f9 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/RedisClientConfig.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/RedisClientConfig.java @@ -5,16 +5,17 @@ import java.util.Optional; import java.util.Set; +import io.quarkus.runtime.annotations.ConfigDocDefault; 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.vertx.redis.client.RedisClientType; import io.vertx.redis.client.RedisReplicas; import io.vertx.redis.client.RedisRole; -@SuppressWarnings("OptionalUsedAsFieldOrParameterType") @ConfigGroup -public class RedisClientConfig { +public interface RedisClientConfig { + /** * The redis hosts to use while connecting to the redis server. Only the cluster and sentinel modes will consider more than * 1 element. @@ -25,8 +26,7 @@ public class RedisClientConfig { * * @see Redis scheme on www.iana.org */ - @ConfigItem(name = RedisConfig.HOSTS_CONFIG_NAME) - public Optional> hosts; + Optional> hosts(); /** * The hosts provider bean name. @@ -37,75 +37,72 @@ public class RedisClientConfig { *

    * Used when `quarkus.redis.hosts` is not set. */ - @ConfigItem - public Optional hostsProviderName; + Optional hostsProviderName(); /** * The maximum delay to wait before a blocking command to redis server times out */ - @ConfigItem(defaultValue = "10s") - public Duration timeout; + @WithDefault("10s") + Duration timeout(); /** * The redis client type. * Accepted values are: {@code STANDALONE} (default), {@code CLUSTER}, {@code REPLICATION}, {@code SENTINEL}. */ - @ConfigItem(defaultValue = "standalone") - public RedisClientType clientType; + @WithDefault("standalone") + RedisClientType clientType(); /** * The master name (only considered in HA mode). */ - @ConfigItem(defaultValueDocumentation = "my-master") - public Optional masterName; + @ConfigDocDefault("my-master") + Optional masterName(); /** * The role name (only considered in Sentinel / HA mode). * Accepted values are: {@code MASTER}, {@code REPLICA}, {@code SENTINEL}. */ - @ConfigItem(defaultValueDocumentation = "master") - public Optional role; + @ConfigDocDefault("master") + Optional role(); /** * Whether to use replicas nodes (only considered in Cluster mode). * Accepted values are: {@code ALWAYS}, {@code NEVER}, {@code SHARE}. */ - @ConfigItem(defaultValueDocumentation = "never") - public Optional replicas; + @ConfigDocDefault("never") + Optional replicas(); /** * The default password for cluster/sentinel connections. *

    * If not set it will try to extract the value from the current default {@code #hosts}. */ - @ConfigItem - public Optional password; + Optional password(); /** * The maximum size of the connection pool. When working with cluster or sentinel. *

    * This value should be at least the total number of cluster member (or number of sentinels + 1) */ - @ConfigItem(defaultValue = "6") - public int maxPoolSize; + @WithDefault("6") + int maxPoolSize(); /** * The maximum waiting requests for a connection from the pool. */ - @ConfigItem(defaultValue = "24") - public int maxPoolWaiting; + @WithDefault("24") + int maxPoolWaiting(); /** * The duration indicating how often should the connection pool cleaner executes. */ - @ConfigItem - public Optional poolCleanerInterval; + Optional poolCleanerInterval(); /** * The timeout for a connection recycling. */ - @ConfigItem(defaultValue = "15") - public Duration poolRecycleTimeout; + @WithDefault("15") + Duration poolRecycleTimeout(); /** * Sets how many handlers is the client willing to queue. @@ -113,69 +110,66 @@ public class RedisClientConfig { * The client will always work on pipeline mode, this means that messages can start queueing. * Using this configuration option, you can control how much backlog you're willing to accept. */ - @ConfigItem(defaultValue = "2048") - public int maxWaitingHandlers; + @WithDefault("2048") + int maxWaitingHandlers(); /** * Tune how much nested arrays are allowed on a redis response. This affects the parser performance. */ - @ConfigItem(defaultValue = "32") - public int maxNestedArrays; + @WithDefault("32") + int maxNestedArrays(); /** * The number of reconnection attempts when a pooled connection cannot be established on first try. */ - @ConfigItem(defaultValue = "0") - public int reconnectAttempts; + @WithDefault("0") + int reconnectAttempts(); /** * The interval between reconnection attempts when a pooled connection cannot be established on first try. */ - @ConfigItem(defaultValue = "1") - public Duration reconnectInterval; + @WithDefault("1") + Duration reconnectInterval(); /** * Should the client perform {@code RESP protocol negotiation during the connection handshake. */ - @ConfigItem(defaultValue = "true") - public boolean protocolNegotiation; + @WithDefault("true") + boolean protocolNegotiation(); /** * TCP config. */ - @ConfigItem @ConfigDocSection - public NetConfig tcp; + NetConfig tcp(); /** * SSL/TLS config. */ - @ConfigItem @ConfigDocSection - public TlsConfig tls; + TlsConfig tls(); - @Override - public String toString() { + default String toDebugString() { return "RedisClientConfig{" + - "hosts=" + hosts + - ", hostsProviderName=" + hostsProviderName + - ", timeout=" + timeout + - ", clientType=" + clientType + - ", masterName=" + masterName + - ", role=" + role + - ", replicas=" + replicas + - ", password=" + password + - ", maxPoolSize=" + maxPoolSize + - ", maxPoolWaiting=" + maxPoolWaiting + - ", poolCleanerInterval=" + poolCleanerInterval + - ", poolRecycleTimeout=" + poolRecycleTimeout + - ", maxWaitingHandlers=" + maxWaitingHandlers + - ", maxNestedArrays=" + maxNestedArrays + - ", reconnectAttempts=" + reconnectAttempts + - ", reconnectInterval=" + reconnectInterval + - ", protocolNegotiation=" + protocolNegotiation + - ", tcp=" + tcp + - ", tls=" + tls + + "hosts=" + hosts() + + ", hostsProviderName=" + hostsProviderName() + + ", timeout=" + timeout() + + ", clientType=" + clientType() + + ", masterName=" + masterName() + + ", role=" + role() + + ", replicas=" + replicas() + + ", password=" + password() + + ", maxPoolSize=" + maxPoolSize() + + ", maxPoolWaiting=" + maxPoolWaiting() + + ", poolCleanerInterval=" + poolCleanerInterval() + + ", poolRecycleTimeout=" + poolRecycleTimeout() + + ", maxWaitingHandlers=" + maxWaitingHandlers() + + ", maxNestedArrays=" + maxNestedArrays() + + ", reconnectAttempts=" + reconnectAttempts() + + ", reconnectInterval=" + reconnectInterval() + + ", protocolNegotiation=" + protocolNegotiation() + + ", tcp=" + tcp() + + ", tls=" + tls() + '}'; } diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/RedisConfig.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/RedisConfig.java index a393329ab8fd7c..ac13188c6338b4 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/RedisConfig.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/RedisConfig.java @@ -3,20 +3,24 @@ import java.util.Map; 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; + +@ConfigMapping(prefix = "quarkus.redis") +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +public interface RedisConfig { -@ConfigRoot(phase = ConfigPhase.RUN_TIME, name = RedisConfig.REDIS_CONFIG_ROOT_NAME) -public class RedisConfig { public final static String REDIS_CONFIG_ROOT_NAME = "redis"; public final static String HOSTS_CONFIG_NAME = "hosts"; public static final String DEFAULT_CLIENT_NAME = ""; + /** * The default redis client */ - @ConfigItem(name = ConfigItem.PARENT) - public RedisClientConfig defaultRedisClient; + @WithParentName + RedisClientConfig defaultRedisClient(); /** * Configures additional (named) Redis clients. @@ -45,19 +49,18 @@ public class RedisConfig { * } * */ - @ConfigItem(name = ConfigItem.PARENT) + @WithParentName @ConfigDocMapKey("redis-client-name") - public Map namedRedisClients; + Map namedRedisClients(); - public static boolean isDefaultClient(String name) { + static boolean isDefaultClient(String name) { return DEFAULT_CLIENT_NAME.equalsIgnoreCase(name); } - public static String propertyKey(String name, String radical) { + static String propertyKey(String name, String radical) { String prefix = DEFAULT_CLIENT_NAME.equals(name) ? "quarkus.redis." : "quarkus.redis.\"" + name + "\"."; return prefix + radical; } - } diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/TlsConfig.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/TlsConfig.java index 52ec32b7189b30..44a4126b527527 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/TlsConfig.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/config/TlsConfig.java @@ -3,81 +3,73 @@ import java.util.Optional; import io.quarkus.runtime.annotations.ConfigGroup; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.vertx.core.runtime.config.JksConfiguration; import io.quarkus.vertx.core.runtime.config.PemKeyCertConfiguration; import io.quarkus.vertx.core.runtime.config.PemTrustCertConfiguration; import io.quarkus.vertx.core.runtime.config.PfxConfiguration; +import io.smallrye.config.WithDefault; -@SuppressWarnings("OptionalUsedAsFieldOrParameterType") @ConfigGroup -public class TlsConfig { +public interface TlsConfig { /** * Whether SSL/TLS is enabled. */ - @ConfigItem(defaultValue = "false") - public boolean enabled; + @WithDefault("false") + boolean enabled(); /** * Enable trusting all certificates. Disabled by default. */ - @ConfigItem(defaultValue = "false") - public boolean trustAll; + @WithDefault("false") + boolean trustAll(); /** * Trust configuration in the PEM format. *

    * When enabled, {@code #trust-certificate-jks} and {@code #trust-certificate-pfx} must be disabled. */ - @ConfigItem - public PemTrustCertConfiguration trustCertificatePem; + PemTrustCertConfiguration trustCertificatePem(); /** * Trust configuration in the JKS format. *

    * When enabled, {@code #trust-certificate-pem} and {@code #trust-certificate-pfx} must be disabled. */ - @ConfigItem - public JksConfiguration trustCertificateJks; + JksConfiguration trustCertificateJks(); /** * Trust configuration in the PFX format. *

    * When enabled, {@code #trust-certificate-jks} and {@code #trust-certificate-pem} must be disabled. */ - @ConfigItem - public PfxConfiguration trustCertificatePfx; + PfxConfiguration trustCertificatePfx(); /** * Key/cert configuration in the PEM format. *

    * When enabled, {@code key-certificate-jks} and {@code #key-certificate-pfx} must be disabled. */ - @ConfigItem - public PemKeyCertConfiguration keyCertificatePem; + PemKeyCertConfiguration keyCertificatePem(); /** * Key/cert configuration in the JKS format. *

    * When enabled, {@code #key-certificate-pem} and {@code #key-certificate-pfx} must be disabled. */ - @ConfigItem - public JksConfiguration keyCertificateJks; + JksConfiguration keyCertificateJks(); /** * Key/cert configuration in the PFX format. *

    * When enabled, {@code key-certificate-jks} and {@code #key-certificate-pem} must be disabled. */ - @ConfigItem - public PfxConfiguration keyCertificatePfx; + PfxConfiguration keyCertificatePfx(); /** * The hostname verification algorithm to use in case the server's identity should be checked. * Should be HTTPS, LDAPS or an empty string. */ - @ConfigItem - public Optional hostnameVerificationAlgorithm; + Optional hostnameVerificationAlgorithm(); } diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/health/RedisHealthCheck.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/health/RedisHealthCheck.java index 2a986c6aa8a6ad..d30c2068ef7049 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/health/RedisHealthCheck.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/health/RedisHealthCheck.java @@ -72,9 +72,9 @@ private String getClientName(Bean bean) { private Duration getTimeout(String name) { if (RedisConfig.isDefaultClient(name)) { - return config.defaultRedisClient.timeout; + return config.defaultRedisClient().timeout(); } else { - return config.namedRedisClients.get(name).timeout; + return config.namedRedisClients().get(name).timeout(); } }