Skip to content

Commit f5fc83d

Browse files
committed
Connect to server specified in serverless bundle
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 to work around previous behavior (driver trying to resolve host-id.* domains). Fixes #164 Fixes #167 Fixes #169
1 parent e7efe74 commit f5fc83d

File tree

4 files changed

+7
-67
lines changed

4 files changed

+7
-67
lines changed

driver-core/src/main/java/com/datastax/driver/core/Cluster.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ protected Builder withScyllaCloudConnectionConfig(ScyllaCloudConnectionConfig co
14061406
Builder builder =
14071407
withEndPointFactory(
14081408
new ScyllaCloudSniEndPointFactory(
1409-
currentDatacenter.getNodeDomain(), proxyAddress.getPort()))
1409+
proxyAddress, currentDatacenter.getNodeDomain()))
14101410
.withSSL(
14111411
(config.getCurrentAuthInfo().isInsecureSkipTlsVerify()
14121412
? config.createBundle().getInsecureSSLOptions()
@@ -1423,7 +1423,7 @@ protected Builder withScyllaCloudConnectionConfig(ScyllaCloudConnectionConfig co
14231423
throw new IllegalStateException(
14241424
"Can't use withCloudSecureConnectBundle if you've already called addContactPoint(s)");
14251425
}
1426-
builder.addContactPoint(new SniEndPoint(proxyAddress, proxyAddress.getHostName()));
1426+
builder.addContactPoint(new SniEndPoint(proxyAddress, currentDatacenter.getNodeDomain()));
14271427

14281428
return builder;
14291429
} catch (IOException e) {

driver-core/src/main/java/com/datastax/driver/core/ScyllaCloudSniEndPointFactory.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525

2626
class ScyllaCloudSniEndPointFactory implements EndPointFactory {
2727
private final String nodeDomain;
28-
private final int port;
2928

30-
public ScyllaCloudSniEndPointFactory(String nodeDomain, int port) {
29+
private final InetSocketAddress proxy;
30+
31+
public ScyllaCloudSniEndPointFactory(InetSocketAddress proxy, String nodeDomain) {
32+
this.proxy = proxy;
3133
this.nodeDomain = nodeDomain;
32-
this.port = port;
3334
}
3435

3536
@Override
@@ -39,7 +40,6 @@ public void init(Cluster cluster) {}
3940
public EndPoint create(Row row) {
4041
UUID host_id = row.getUUID("host_id");
4142
String sni = host_id.toString() + "." + nodeDomain;
42-
InetSocketAddress proxy = InetSocketAddress.createUnresolved(sni, port);
4343
return new SniEndPoint(proxy, sni);
4444
}
4545
}

driver-core/src/test/java/com/datastax/driver/core/CCMTestsSupport.java

+1-22
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import static com.datastax.driver.core.CreateCCM.TestMode.PER_CLASS;
2525
import static com.datastax.driver.core.CreateCCM.TestMode.PER_METHOD;
2626
import static com.datastax.driver.core.TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT;
27-
import static com.datastax.driver.core.TestUtils.addressOfNode;
2827
import static com.datastax.driver.core.TestUtils.executeNoFail;
2928
import static com.datastax.driver.core.TestUtils.ipOfNode;
3029
import static org.assertj.core.api.Assertions.fail;
@@ -40,7 +39,6 @@
4039
import com.google.common.util.concurrent.Uninterruptibles;
4140
import java.io.Closeable;
4241
import java.io.File;
43-
import java.io.FileInputStream;
4442
import java.io.IOException;
4543
import java.lang.annotation.Annotation;
4644
import java.lang.reflect.Constructor;
@@ -778,26 +776,7 @@ public Cluster.Builder createClusterBuilderScyllaCloud() throws IOException {
778776
File clusterFile = new File(ccmdir, ccm.getClusterName());
779777
File yamlFile = new File(clusterFile, "config_data.yaml");
780778

781-
final ScyllaCloudConnectionConfig cloudConfig =
782-
ScyllaCloudConnectionConfig.fromInputStream(new FileInputStream(yamlFile));
783-
784-
builder.withScyllaCloudConnectionConfig(cloudConfig);
785-
builder.withEndPointFactory(
786-
new MockSniEndPointFactory(
787-
InetSocketAddress.createUnresolved(
788-
addressOfNode(1).getHostAddress(),
789-
cloudConfig.getCurrentDatacenter().getServer().getPort()),
790-
builder.getConfiguration().getPolicies().getEndPointFactory()));
791-
builder.addContactPoint(
792-
new SniEndPoint(
793-
InetSocketAddress.createUnresolved(
794-
addressOfNode(1).getHostAddress(),
795-
cloudConfig.getCurrentDatacenter().getServer().getPort()),
796-
cloudConfig.getCurrentDatacenter().getServer().getHostName()));
797-
798-
builder
799-
.withCodecRegistry(new CodecRegistry())
800-
.withPort(cloudConfig.getCurrentDatacenter().getServer().getPort());
779+
builder.withScyllaCloudConnectionConfig(yamlFile);
801780
return builder;
802781
}
803782

driver-core/src/test/java/com/datastax/driver/core/MockSniEndPointFactory.java

-39
This file was deleted.

0 commit comments

Comments
 (0)