From ab462660248e8a5909d68f77ded8e38bec3677ed Mon Sep 17 00:00:00 2001 From: Dinu John <86094133+dinujoh@users.noreply.github.com> Date: Wed, 24 Apr 2024 11:17:53 -0500 Subject: [PATCH] Revert DocumentDB source hosts array to host string Signed-off-by: Dinu John <86094133+dinujoh@users.noreply.github.com> --- .../plugins/mongo/client/MongoDBConnection.java | 6 +++--- .../mongo/configuration/MongoDBSourceConfig.java | 12 ++++-------- .../plugins/mongo/client/MongoDBConnectionTest.java | 6 +++--- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/data-prepper-plugins/mongodb/src/main/java/org/opensearch/dataprepper/plugins/mongo/client/MongoDBConnection.java b/data-prepper-plugins/mongodb/src/main/java/org/opensearch/dataprepper/plugins/mongo/client/MongoDBConnection.java index a44c6bfa35..224d8b0f54 100644 --- a/data-prepper-plugins/mongodb/src/main/java/org/opensearch/dataprepper/plugins/mongo/client/MongoDBConnection.java +++ b/data-prepper-plugins/mongodb/src/main/java/org/opensearch/dataprepper/plugins/mongo/client/MongoDBConnection.java @@ -54,12 +54,12 @@ private static String getConnectionString(final MongoDBSourceConfig sourceConfig throw new RuntimeException("Unsupported characters in password."); } - if (sourceConfig.getHosts() == null || sourceConfig.getHosts().length == 0) { - throw new RuntimeException("The hosts array should at least have one host."); + if (sourceConfig.getHost() == null || sourceConfig.getHost().isBlank()) { + throw new RuntimeException("The host should not be null or empty."); } // Support for only single host - final String hostname = sourceConfig.getHosts()[0]; + final String hostname = sourceConfig.getHost(); final int port = sourceConfig.getPort(); final String tls = sourceConfig.getTls().toString(); final String invalidHostAllowed = sourceConfig.getSslInsecureDisableVerification().toString(); diff --git a/data-prepper-plugins/mongodb/src/main/java/org/opensearch/dataprepper/plugins/mongo/configuration/MongoDBSourceConfig.java b/data-prepper-plugins/mongodb/src/main/java/org/opensearch/dataprepper/plugins/mongo/configuration/MongoDBSourceConfig.java index d250c4b0c5..e1abc1116d 100644 --- a/data-prepper-plugins/mongodb/src/main/java/org/opensearch/dataprepper/plugins/mongo/configuration/MongoDBSourceConfig.java +++ b/data-prepper-plugins/mongodb/src/main/java/org/opensearch/dataprepper/plugins/mongo/configuration/MongoDBSourceConfig.java @@ -12,12 +12,11 @@ public class MongoDBSourceConfig { private static final int DEFAULT_PORT = 27017; private static final Boolean DEFAULT_INSECURE = false; private static final Boolean DEFAULT_INSECURE_DISABLE_VERIFICATION = false; - private static final String DEFAULT_SNAPSHOT_FETCH_SIZE = "1000"; private static final String DEFAULT_READ_PREFERENCE = "primaryPreferred"; private static final Boolean DEFAULT_DIRECT_CONNECT = true; private static final Duration DEFAULT_ACKNOWLEDGEMENT_SET_TIMEOUT = Duration.ofHours(2); - @JsonProperty("hosts") - private @NotNull String[] hosts; + @JsonProperty("host") + private @NotNull String host; @JsonProperty("port") private int port = DEFAULT_PORT; @JsonProperty("trust_store_file_path") @@ -27,8 +26,6 @@ public class MongoDBSourceConfig { @JsonProperty("authentication") private AuthenticationConfig authenticationConfig; - @JsonProperty("snapshot_fetch_size") - private String snapshotFetchSize; @JsonProperty("read_preference") private String readPreference; @JsonProperty("collections") @@ -61,7 +58,6 @@ public class MongoDBSourceConfig { private AwsConfig awsConfig; public MongoDBSourceConfig() { - this.snapshotFetchSize = DEFAULT_SNAPSHOT_FETCH_SIZE; this.readPreference = DEFAULT_READ_PREFERENCE; this.collections = new ArrayList<>(); this.insecure = DEFAULT_INSECURE; @@ -74,8 +70,8 @@ public AuthenticationConfig getAuthenticationConfig() { return this.authenticationConfig; } - public String[] getHosts() { - return this.hosts; + public String getHost() { + return this.host; } public int getPort() { diff --git a/data-prepper-plugins/mongodb/src/test/java/org/opensearch/dataprepper/plugins/mongo/client/MongoDBConnectionTest.java b/data-prepper-plugins/mongodb/src/test/java/org/opensearch/dataprepper/plugins/mongo/client/MongoDBConnectionTest.java index 1a427e0ee5..30bc721c49 100644 --- a/data-prepper-plugins/mongodb/src/test/java/org/opensearch/dataprepper/plugins/mongo/client/MongoDBConnectionTest.java +++ b/data-prepper-plugins/mongodb/src/test/java/org/opensearch/dataprepper/plugins/mongo/client/MongoDBConnectionTest.java @@ -36,7 +36,7 @@ void setUp() { when(mongoDBSourceConfig.getAuthenticationConfig()).thenReturn(authenticationConfig); when(authenticationConfig.getUsername()).thenReturn("\uD800\uD800" + UUID.randomUUID()); when(authenticationConfig.getPassword()).thenReturn("aЯ ⾀sd?q=%%l€0£.lo" + UUID.randomUUID()); - when(mongoDBSourceConfig.getHosts()).thenReturn(new String[] { UUID.randomUUID().toString() }); + when(mongoDBSourceConfig.getHost()).thenReturn(UUID.randomUUID().toString()); when(mongoDBSourceConfig.getPort()).thenReturn(getRandomInteger()); when(mongoDBSourceConfig.getTls()).thenReturn(getRandomBoolean()); when(mongoDBSourceConfig.getSslInsecureDisableVerification()).thenReturn(getRandomBoolean()); @@ -71,7 +71,7 @@ public void getMongoClientNullHost() { when(mongoDBSourceConfig.getAuthenticationConfig()).thenReturn(authenticationConfig); when(authenticationConfig.getUsername()).thenReturn("\uD800\uD800" + UUID.randomUUID()); when(authenticationConfig.getPassword()).thenReturn("aЯ ⾀sd?q=%%l€0£.lo" + UUID.randomUUID()); - when(mongoDBSourceConfig.getHosts()).thenReturn(null); + when(mongoDBSourceConfig.getHost()).thenReturn(null); assertThrows(RuntimeException.class, () -> MongoDBConnection.getMongoClient(mongoDBSourceConfig)); } @@ -80,7 +80,7 @@ public void getMongoClientEmptyHost() { when(mongoDBSourceConfig.getAuthenticationConfig()).thenReturn(authenticationConfig); when(authenticationConfig.getUsername()).thenReturn("\uD800\uD800" + UUID.randomUUID()); when(authenticationConfig.getPassword()).thenReturn("aЯ ⾀sd?q=%%l€0£.lo" + UUID.randomUUID()); - when(mongoDBSourceConfig.getHosts()).thenReturn(new String[]{}); + when(mongoDBSourceConfig.getHost()).thenReturn(" "); assertThrows(RuntimeException.class, () -> MongoDBConnection.getMongoClient(mongoDBSourceConfig)); }