Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify gRPC configuration parameters in Config class #236

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/main/java/io/weaviate/client/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public class Config {
private int proxyPort;
@Getter
private String proxyScheme;
@Setter
private boolean useGRPC;
@Getter @Setter
private String grpcAddress;
private boolean gRPCSecured;
@Getter @Setter
private String gRPCHost;

public Config(String scheme, String host) {
this(scheme, host, null, DEFAULT_TIMEOUT_SECONDS, DEFAULT_TIMEOUT_SECONDS, DEFAULT_TIMEOUT_SECONDS);
Expand All @@ -49,15 +49,16 @@ public Config(String scheme, String host, Map<String, String> headers, int conne
this.socketTimeout = socketTimeout;
}

public Config(String scheme, String host, Map<String, String> headers, int timeout, boolean useGRPC) {
public Config(String scheme, String host, Map<String, String> headers, int timeout, boolean gRPCSecured, String gRPCHost) {
this.scheme = scheme;
this.host = host;
this.version = "v1";
this.headers = headers;
this.connectionTimeout = timeout;
this.connectionRequestTimeout = timeout;
this.socketTimeout = timeout;
this.useGRPC = useGRPC;
this.gRPCSecured = gRPCSecured;
this.gRPCHost = gRPCHost;
}

public String getBaseURL() {
Expand All @@ -71,6 +72,6 @@ public void setProxy(String proxyHost, int proxyPort, String proxyScheme) {
}

public boolean useGRPC() {
return this.useGRPC;
return this.gRPCHost != null && !this.gRPCHost.trim().isEmpty();
}
}
16 changes: 8 additions & 8 deletions src/main/java/io/weaviate/client/base/grpc/GrpcClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static WeaviateGrpc.WeaviateBlockingStub create(Config config) {
}
}
ManagedChannelBuilder<?> channelBuilder = ManagedChannelBuilder.forTarget(getAddress(config));
if (config.getScheme().equals("https")) {
if (config.isGRPCSecured()) {
channelBuilder = channelBuilder.useTransportSecurity();
} else {
channelBuilder.usePlaintext();
Expand All @@ -29,16 +29,16 @@ public static WeaviateGrpc.WeaviateBlockingStub create(Config config) {
}

private static String getAddress(Config config) {
if (config.getGrpcAddress() != null) {
return config.getGrpcAddress();
}
String host = config.getHost();
if (!host.contains(":")) {
if (config.getScheme() != null && config.getScheme().equals("https")) {
if (config.getGRPCHost() != null) {
String host = config.getGRPCHost();
if (host.contains(":")) {
return host;
}
if (config.isGRPCSecured()) {
return String.format("%s:443", host);
}
return String.format("%s:80", host);
}
return host;
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,10 @@ private void testCreateBatchWithNestedAndNestArrayObject(Boolean useGRPC) {

private WeaviateClient createClient(Boolean useGRPC) {
Config config = new Config("http", host + ":" + port);
config.setUseGRPC(useGRPC);
config.setGrpcAddress(grpcHost + ":" + grpcPort);
if (useGRPC) {
config.setGRPCSecured(false);
config.setGRPCHost(grpcHost + ":" + grpcPort);
}
return new WeaviateClient(config);
}

Expand Down