Skip to content

Commit

Permalink
Connect to server specified in serverless bundle
Browse files Browse the repository at this point in the history
Before this change, the driver, when connecting to a serverless cluster,
would try to resolve host-id.* domains as a proxy IP for each node.

This commit aligns the behavior with scylladb/python-driver#177 and
scylladb/gocql#106. Now, the "Server" field of bundle is the single
hostname/IP the driver will use for proxy connection.

This simplifies the setup we had in integration tests, removing the
necessity of hacks caused by previous behavior (driver trying to
resolve host-id.* domains).

Fixes scylladb#164
Fixes scylladb#167
Fixes scylladb#169
  • Loading branch information
avelanarius committed Nov 15, 2022
1 parent cef684a commit 5fe8b3b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ protected Builder withScyllaCloudConnectionConfig(ScyllaCloudConnectionConfig co
Builder builder =
withEndPointFactory(
new ScyllaCloudSniEndPointFactory(
currentDatacenter.getNodeDomain(), proxyAddress.getPort()))
proxyAddress, currentDatacenter.getNodeDomain()))
.withSSL(
(config.getCurrentAuthInfo().isInsecureSkipTlsVerify()
? config.createBundle().getInsecureSSLOptions()
Expand All @@ -1423,7 +1423,7 @@ protected Builder withScyllaCloudConnectionConfig(ScyllaCloudConnectionConfig co
throw new IllegalStateException(
"Can't use withCloudSecureConnectBundle if you've already called addContactPoint(s)");
}
builder.addContactPoint(new SniEndPoint(proxyAddress, proxyAddress.getHostName()));
builder.addContactPoint(new SniEndPoint(proxyAddress, currentDatacenter.getNodeDomain()));

return builder;
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@

class ScyllaCloudSniEndPointFactory implements EndPointFactory {
private final String nodeDomain;
private final int port;

public ScyllaCloudSniEndPointFactory(String nodeDomain, int port) {
private final InetSocketAddress proxy;

public ScyllaCloudSniEndPointFactory(InetSocketAddress proxy, String nodeDomain) {
this.proxy = proxy;
this.nodeDomain = nodeDomain;
this.port = port;
}

@Override
Expand All @@ -39,7 +40,6 @@ public void init(Cluster cluster) {}
public EndPoint create(Row row) {
UUID host_id = row.getUUID("host_id");
String sni = host_id.toString() + "." + nodeDomain;
InetSocketAddress proxy = InetSocketAddress.createUnresolved(sni, port);
return new SniEndPoint(proxy, sni);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import static com.datastax.driver.core.CreateCCM.TestMode.PER_CLASS;
import static com.datastax.driver.core.CreateCCM.TestMode.PER_METHOD;
import static com.datastax.driver.core.TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT;
import static com.datastax.driver.core.TestUtils.addressOfNode;
import static com.datastax.driver.core.TestUtils.executeNoFail;
import static com.datastax.driver.core.TestUtils.ipOfNode;
import static org.assertj.core.api.Assertions.fail;
Expand All @@ -40,7 +39,6 @@
import com.google.common.util.concurrent.Uninterruptibles;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
Expand Down Expand Up @@ -778,26 +776,7 @@ public Cluster.Builder createClusterBuilderScyllaCloud() throws IOException {
File clusterFile = new File(ccmdir, ccm.getClusterName());
File yamlFile = new File(clusterFile, "config_data.yaml");

final ScyllaCloudConnectionConfig cloudConfig =
ScyllaCloudConnectionConfig.fromInputStream(new FileInputStream(yamlFile));

builder.withScyllaCloudConnectionConfig(cloudConfig);
builder.withEndPointFactory(
new MockSniEndPointFactory(
InetSocketAddress.createUnresolved(
addressOfNode(1).getHostAddress(),
cloudConfig.getCurrentDatacenter().getServer().getPort()),
builder.getConfiguration().getPolicies().getEndPointFactory()));
builder.addContactPoint(
new SniEndPoint(
InetSocketAddress.createUnresolved(
addressOfNode(1).getHostAddress(),
cloudConfig.getCurrentDatacenter().getServer().getPort()),
cloudConfig.getCurrentDatacenter().getServer().getHostName()));

builder
.withCodecRegistry(new CodecRegistry())
.withPort(cloudConfig.getCurrentDatacenter().getServer().getPort());
builder.withScyllaCloudConnectionConfig(yamlFile);
return builder;
}

Expand Down

This file was deleted.

0 comments on commit 5fe8b3b

Please sign in to comment.