Skip to content

Commit 1c4a6ab

Browse files
committed
Remove deprecated Mongo configuration and use mapping object
1 parent 9cda99b commit 1c4a6ab

File tree

4 files changed

+18
-115
lines changed

4 files changed

+18
-115
lines changed

extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongoConfigSourceInterceptor.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongodbConfig.java

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@
2020
public interface MongodbConfig {
2121
String CONFIG_NAME = "mongodb";
2222
String DEFAULT_CLIENT_NAME = "<default>";
23-
@Deprecated
24-
String NATIVE_DNS_LOG_ACTIVITY = "native.dns.log-activity";
25-
String DNS_LOG_ACTIVITY = "dns.log-activity";
26-
@Deprecated
27-
String NATIVE_DNS_SERVER_HOST = "native.dns.server-host";
28-
String DNS_SERVER_HOST = "dns.server-host";
29-
@Deprecated
30-
String NATIVE_DNS_SERVER_PORT = "native.dns.server-port";
31-
String DNS_SERVER_PORT = "dns.server-port";
32-
@Deprecated
33-
String NATIVE_DNS_LOOKUP_TIMEOUT = "native.dns.lookup-timeout";
34-
String DNS_LOOKUP_TIMEOUT = "dns.lookup-timeout";
3523

3624
/**
3725
* Configures the Mongo clients.
@@ -92,75 +80,33 @@ public interface MongodbConfig {
9280
@WithDefault("false")
9381
boolean useVertxDnsResolverInNativeMode();
9482

95-
/**
96-
* If {@code native.dns.use-vertx-dns-resolver} is set to {@code true}, this property configures the DNS server.
97-
* If the server is not set, it tries to read the first {@code nameserver} from {@code /etc/resolv.conf} (if the
98-
* file exists), otherwise fallback to the default.
99-
*
100-
* @deprecated this property has been deprecated in favor of {@link #dnsServer}
101-
*/
102-
@Deprecated
103-
@WithName(NATIVE_DNS_SERVER_HOST)
104-
Optional<String> dnsServerInNativeMode();
105-
10683
/**
10784
* This property configures the DNS server. If the server is not set, it tries to read the first {@code nameserver} from
10885
* {@code /etc /resolv.conf} (if the file exists), otherwise fallback to the default.
10986
*/
110-
@WithName(DNS_SERVER_HOST)
87+
@WithName("dns.server-host")
11188
Optional<String> dnsServer();
11289

113-
/**
114-
* If {@code native.dns.use-vertx-dns-resolver} is set to {@code true}, this property configures the DNS server port.
115-
*
116-
* @deprecated this property has been deprecated in favor of {@link #dnsServerPort}
117-
*/
118-
@Deprecated
119-
@WithName(NATIVE_DNS_SERVER_PORT)
120-
OptionalInt dnsServerPortInNativeMode();
121-
12290
/**
12391
* This property configures the DNS server port.
12492
*/
125-
@WithName(DNS_SERVER_PORT)
93+
@WithName("dns.server-port")
12694
OptionalInt dnsServerPort();
12795

128-
/**
129-
* If {@code native.dns.use-vertx-dns-resolver} is set to {@code true}, this property configures the DNS lookup timeout
130-
* duration.
131-
*
132-
* @deprecated this property has been deprecated in favor of {@link #dnsLookupTimeout}
133-
*/
134-
@Deprecated
135-
@WithName(NATIVE_DNS_LOOKUP_TIMEOUT)
136-
@WithDefault("5s")
137-
Duration dnsLookupTimeoutInNativeMode();
138-
13996
/**
14097
* If {@code native.dns.use-vertx-dns-resolver} is set to {@code true}, this property configures the DNS lookup timeout
14198
* duration.
14299
*/
143-
@WithName(DNS_LOOKUP_TIMEOUT)
100+
@WithName("dns.lookup-timeout")
144101
@WithDefault("5s")
145102
Duration dnsLookupTimeout();
146103

147-
/**
148-
* If {@code native.dns.use-vertx-dns-resolver} is set to {@code true}, this property enables the logging ot the
149-
* DNS lookup. It can be useful to understand why the lookup fails.
150-
*
151-
* @deprecated this property has been deprecated in favor of {@link #dnsLookupLogActivity}
152-
*/
153-
@Deprecated
154-
@WithDefault("false")
155-
@WithName(NATIVE_DNS_LOG_ACTIVITY)
156-
Optional<Boolean> dnsLookupLogActivityInNativeMode();
157-
158104
/**
159105
* This property enables the logging ot the DNS lookup. It can be useful to understand why the lookup fails.
160106
*/
161107
@WithDefault("false")
162-
@WithName(DNS_LOG_ACTIVITY)
163-
Optional<Boolean> dnsLookupLogActivity();
108+
@WithName("dns.log-activity")
109+
boolean dnsLookupLogActivity();
164110

165111
static boolean isDefaultClient(final String name) {
166112
return DEFAULT_CLIENT_NAME.equalsIgnoreCase(name);

extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/dns/MongoDnsClient.java

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.quarkus.mongodb.runtime.dns;
22

33
import static java.lang.String.format;
4+
import static org.eclipse.microprofile.config.ConfigProvider.getConfig;
45

56
import java.io.IOException;
67
import java.nio.file.Files;
@@ -17,8 +18,6 @@
1718
import java.util.stream.Collectors;
1819
import java.util.stream.Stream;
1920

20-
import org.eclipse.microprofile.config.Config;
21-
import org.eclipse.microprofile.config.ConfigProvider;
2221
import org.jboss.logging.Logger;
2322

2423
import com.mongodb.MongoConfigurationException;
@@ -27,61 +26,47 @@
2726

2827
import io.quarkus.mongodb.runtime.MongodbConfig;
2928
import io.quarkus.runtime.annotations.RegisterForReflection;
29+
import io.smallrye.config.SmallRyeConfig;
3030
import io.smallrye.mutiny.Uni;
3131
import io.vertx.core.dns.DnsClientOptions;
3232
import io.vertx.mutiny.core.Vertx;
3333
import io.vertx.mutiny.core.dns.SrvRecord;
3434

3535
@RegisterForReflection
3636
public class MongoDnsClient implements DnsClient {
37-
private static final String BASE_CONFIG_NAME = "quarkus." + MongodbConfig.CONFIG_NAME + ".";
38-
39-
public static final String DNS_LOOKUP_TIMEOUT = BASE_CONFIG_NAME + MongodbConfig.DNS_LOOKUP_TIMEOUT;
40-
public static final String NATIVE_DNS_LOOKUP_TIMEOUT = BASE_CONFIG_NAME + MongodbConfig.NATIVE_DNS_LOOKUP_TIMEOUT;
41-
42-
public static final String DNS_LOG_ACTIVITY = BASE_CONFIG_NAME + MongodbConfig.DNS_LOG_ACTIVITY;
43-
public static final String NATIVE_DNS_LOG_ACTIVITY = BASE_CONFIG_NAME + MongodbConfig.NATIVE_DNS_LOG_ACTIVITY;
44-
45-
public static final String DNS_SERVER = BASE_CONFIG_NAME + MongodbConfig.DNS_SERVER_HOST;
46-
public static final String NATIVE_DNS_SERVER = BASE_CONFIG_NAME + MongodbConfig.NATIVE_DNS_SERVER_HOST;
47-
public static final String DNS_SERVER_PORT = BASE_CONFIG_NAME + MongodbConfig.DNS_SERVER_PORT;
48-
public static final String NATIVE_DNS_SERVER_PORT = BASE_CONFIG_NAME + MongodbConfig.NATIVE_DNS_SERVER_PORT;
49-
50-
private final Config config = ConfigProvider.getConfig();
51-
52-
private final io.vertx.mutiny.core.dns.DnsClient dnsClient;
37+
private static final Logger log = Logger.getLogger(MongoDnsClient.class);
5338

5439
// the static fields are used in order to hold DNS resolution result that has been performed on the main thread
5540
// at application startup
5641
// the reason we need this is to ensure that no blocking of event loop threads will occur due to DNS resolution
5742
private static final Map<String, List<SrvRecord>> SRV_CACHE = new ConcurrentHashMap<>();
5843
private static final Map<String, List<String>> TXT_CACHE = new ConcurrentHashMap<>();
5944

60-
private static final Logger log = Logger.getLogger(MongoDnsClient.class);
45+
private final io.vertx.mutiny.core.dns.DnsClient dnsClient;
46+
private final MongodbConfig mongoConfig;
6147

6248
MongoDnsClient(io.vertx.core.Vertx vertx) {
49+
this.mongoConfig = getConfig().unwrap(SmallRyeConfig.class).getConfigMapping(MongodbConfig.class);
6350
Vertx mutinyVertx = new io.vertx.mutiny.core.Vertx(vertx);
6451

65-
boolean activity = config.getOptionalValue(DNS_LOG_ACTIVITY, Boolean.class).orElse(false);
66-
6752
// If the server is not set, we attempt to read the /etc/resolv.conf. If it does not exist, we use the default
6853
// configuration.
69-
String server = config.getOptionalValue(DNS_SERVER, String.class).orElseGet(() -> {
54+
String server = mongoConfig.dnsServer().orElseGet(() -> {
7055
List<String> list = nameServers();
7156
if (!list.isEmpty()) {
7257
return list.get(0);
7358
}
7459
return null;
7560
});
7661
DnsClientOptions dnsClientOptions = new DnsClientOptions()
77-
.setLogActivity(activity);
62+
.setLogActivity(mongoConfig.dnsLookupLogActivity());
7863
if (server != null) {
7964
dnsClientOptions.setHost(server);
80-
if (config.getOptionalValue(DNS_SERVER_PORT, Integer.class).isPresent()) {
81-
dnsClientOptions.setPort(config.getOptionalValue(DNS_SERVER_PORT, Integer.class).orElseThrow());
65+
if (mongoConfig.dnsServerPort().isPresent()) {
66+
dnsClientOptions.setPort(mongoConfig.dnsServerPort().orElseThrow());
8267
}
8368
}
84-
dnsClientOptions.setQueryTimeout(config.getValue(DNS_LOOKUP_TIMEOUT, Duration.class).toMillis());
69+
dnsClientOptions.setQueryTimeout(mongoConfig.dnsLookupTimeout().toMillis());
8570

8671
if (log.isDebugEnabled()) {
8772
log.debugf("DNS client options: %s", dnsClientOptions.toJson());
@@ -128,8 +113,7 @@ public List<String> getResourceRecordData(String name, String type) throws DnsEx
128113
*/
129114
private List<String> resolveSrvRequest(final String srvHost) {
130115
List<String> hosts = new ArrayList<>();
131-
Duration timeout = config.getOptionalValue(DNS_LOOKUP_TIMEOUT, Duration.class)
132-
.orElse(Duration.ofSeconds(5));
116+
Duration timeout = mongoConfig.dnsLookupTimeout();
133117

134118
try {
135119
List<SrvRecord> srvRecords;
@@ -184,9 +168,7 @@ public List<String> resolveTxtRequest(final String host) {
184168
return TXT_CACHE.get(host);
185169
}
186170
try {
187-
Duration timeout = config.getOptionalValue(DNS_LOOKUP_TIMEOUT, Duration.class)
188-
.orElse(Duration.ofSeconds(5));
189-
171+
Duration timeout = mongoConfig.dnsLookupTimeout();
190172
return Uni.createFrom().<List<String>> deferred(
191173
new Supplier<>() {
192174
@Override

extensions/mongodb-client/runtime/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)