From 309217811e9a06d8bbd2af4baa86fd7bdb25b9b4 Mon Sep 17 00:00:00 2001 From: groot Date: Thu, 21 Nov 2024 16:32:26 +0800 Subject: [PATCH] add default port and support dbname for uri, 19530 by default, 443 for serverless (#1191) (#1192) Signed-off-by: Nian Liu Co-authored-by: Nian Liu --- .../io/milvus/v2/client/ConnectConfig.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/milvus/v2/client/ConnectConfig.java b/src/main/java/io/milvus/v2/client/ConnectConfig.java index e101ccca2..9e401c1f9 100644 --- a/src/main/java/io/milvus/v2/client/ConnectConfig.java +++ b/src/main/java/io/milvus/v2/client/ConnectConfig.java @@ -19,14 +19,17 @@ package io.milvus.v2.client; +import static io.milvus.common.constant.MilvusClientConstant.MilvusConsts.CLOUD_SERVERLESS_URI_REGEX; import lombok.Builder; import lombok.Data; import lombok.NonNull; import lombok.experimental.SuperBuilder; +import org.apache.commons.lang3.StringUtils; import javax.net.ssl.SSLContext; import java.net.URI; import java.util.concurrent.TimeUnit; +import java.util.regex.Pattern; @Data @SuperBuilder @@ -61,13 +64,17 @@ public class ConnectConfig { private SSLContext sslContext; public String getHost() { - URI uri = URI.create(this.uri); - return uri.getHost(); + io.milvus.utils.URLParser urlParser = new io.milvus.utils.URLParser(this.uri); + return urlParser.getHostname(); } public int getPort() { - URI uri = URI.create(this.uri); - return uri.getPort(); + io.milvus.utils.URLParser urlParser = new io.milvus.utils.URLParser(this.uri); + int port = urlParser.getPort(); + if (Pattern.matches(CLOUD_SERVERLESS_URI_REGEX, this.uri)) { + port = 443; + } + return port; } public String getAuthorization() { @@ -79,6 +86,11 @@ public String getAuthorization() { return null; } + public String getDbName() { + io.milvus.utils.URLParser urlParser = new io.milvus.utils.URLParser(this.uri); + return StringUtils.isNotEmpty(urlParser.getDatabase()) ? urlParser.getDatabase() : this.dbName; + } + public Boolean isSecure() { if(uri.startsWith("https")) { return true;