Skip to content

Commit

Permalink
add default port and support dbname for uri, 19530 by default, 443 fo…
Browse files Browse the repository at this point in the history
…r serverless (#1191) (#1192)

Signed-off-by: Nian Liu <[email protected]>
Co-authored-by: Nian Liu <[email protected]>
  • Loading branch information
yhmo and nianliuu authored Nov 21, 2024
1 parent d41ca0a commit 3092178
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main/java/io/milvus/v2/client/ConnectConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand All @@ -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;
Expand Down

0 comments on commit 3092178

Please sign in to comment.