44
44
import com .datastax .oss .driver .api .core .type .codec .registry .MutableCodecRegistry ;
45
45
import com .datastax .oss .driver .api .core .uuid .Uuids ;
46
46
import com .datastax .oss .driver .internal .core .ContactPoints ;
47
- import com .datastax .oss .driver .internal .core .config .cloud . CloudConfig ;
48
- import com .datastax .oss .driver .internal .core .config .cloud . CloudConfigFactory ;
47
+ import com .datastax .oss .driver .internal .core .config .scyllacloud . ConfigurationBundle ;
48
+ import com .datastax .oss .driver .internal .core .config .scyllacloud . ScyllaCloudConnectionConfig ;
49
49
import com .datastax .oss .driver .internal .core .config .typesafe .DefaultDriverConfigLoader ;
50
50
import com .datastax .oss .driver .internal .core .context .DefaultDriverContext ;
51
51
import com .datastax .oss .driver .internal .core .context .InternalDriverContext ;
52
52
import com .datastax .oss .driver .internal .core .metadata .DefaultEndPoint ;
53
+ import com .datastax .oss .driver .internal .core .metadata .SniEndPoint ;
53
54
import com .datastax .oss .driver .internal .core .session .DefaultSession ;
54
55
import com .datastax .oss .driver .internal .core .util .concurrent .BlockingOperation ;
55
56
import com .datastax .oss .driver .internal .core .util .concurrent .CompletableFutures ;
57
+ import com .datastax .oss .driver .shaded .guava .common .collect .ImmutableList ;
56
58
import edu .umd .cs .findbugs .annotations .NonNull ;
57
59
import edu .umd .cs .findbugs .annotations .Nullable ;
58
60
import java .io .InputStream ;
59
61
import java .net .InetSocketAddress ;
60
62
import java .net .MalformedURLException ;
61
63
import java .net .URL ;
62
64
import java .nio .file .Path ;
63
- import java .nio .file .Paths ;
64
65
import java .util .Collection ;
65
66
import java .util .Collections ;
66
67
import java .util .HashSet ;
@@ -96,6 +97,7 @@ public abstract class SessionBuilder<SelfT extends SessionBuilder, SessionT> {
96
97
protected Set <EndPoint > programmaticContactPoints = new HashSet <>();
97
98
protected CqlIdentifier keyspace ;
98
99
protected Callable <InputStream > cloudConfigInputStream ;
100
+ protected Callable <InputStream > scyllaCloudConfigInputStream ;
99
101
100
102
protected ProgrammaticArguments .Builder programmaticArgumentsBuilder =
101
103
ProgrammaticArguments .builder ();
@@ -655,6 +657,17 @@ public SelfT withCloudSecureConnectBundle(@NonNull Path cloudConfigPath) {
655
657
return self ;
656
658
}
657
659
660
+ @ NonNull
661
+ public SelfT withScyllaCloudSecureConnectBundle (@ NonNull Path cloudConfigPath ) {
662
+ try {
663
+ URL cloudConfigUrl = cloudConfigPath .toAbsolutePath ().normalize ().toUri ().toURL ();
664
+ this .scyllaCloudConfigInputStream = cloudConfigUrl ::openStream ;
665
+ } catch (MalformedURLException e ) {
666
+ throw new IllegalArgumentException ("Incorrect format of cloudConfigPath" , e );
667
+ }
668
+ return self ;
669
+ }
670
+
658
671
/**
659
672
* Registers a CodecRegistry to use for the session.
660
673
*
@@ -687,6 +700,12 @@ public SelfT withCloudSecureConnectBundle(@NonNull URL cloudConfigUrl) {
687
700
return self ;
688
701
}
689
702
703
+ @ NonNull
704
+ public SelfT withScyllaCloudSecureConnectBundle (@ NonNull URL cloudConfigUrl ) {
705
+ this .scyllaCloudConfigInputStream = cloudConfigUrl ::openStream ;
706
+ return self ;
707
+ }
708
+
690
709
/**
691
710
* Configures this SessionBuilder for Cloud deployments by retrieving connection information from
692
711
* the provided {@link InputStream}.
@@ -711,6 +730,12 @@ public SelfT withCloudSecureConnectBundle(@NonNull InputStream cloudConfigInputS
711
730
return self ;
712
731
}
713
732
733
+ @ NonNull
734
+ public SelfT withScyllaCloudSecureConnectBundle (@ NonNull InputStream cloudConfigInputStream ) {
735
+ this .scyllaCloudConfigInputStream = () -> cloudConfigInputStream ;
736
+ return self ;
737
+ }
738
+
714
739
/**
715
740
* Configures this SessionBuilder to use the provided Cloud proxy endpoint.
716
741
*
@@ -733,6 +758,13 @@ public SelfT withCloudProxyAddress(@Nullable InetSocketAddress cloudProxyAddress
733
758
return self ;
734
759
}
735
760
761
+ @ NonNull
762
+ public SelfT withScyllaCloudProxyAddress (
763
+ @ Nullable InetSocketAddress cloudProxyAddress , String nodeDomain ) {
764
+ this .programmaticArgumentsBuilder .withScyllaCloudProxyAddress (cloudProxyAddress , nodeDomain );
765
+ return self ;
766
+ }
767
+
736
768
/**
737
769
* A unique identifier for the created session.
738
770
*
@@ -857,16 +889,9 @@ protected final CompletionStage<CqlSession> buildDefaultSessionAsync() {
857
889
: defaultConfigLoader (programmaticArguments .getClassLoader ());
858
890
859
891
DriverExecutionProfile defaultConfig = configLoader .getInitialConfig ().getDefaultProfile ();
860
- if (cloudConfigInputStream == null ) {
861
- String configUrlString =
862
- defaultConfig .getString (DefaultDriverOption .CLOUD_SECURE_CONNECT_BUNDLE , null );
863
- if (configUrlString != null ) {
864
- cloudConfigInputStream = () -> getURL (configUrlString ).openStream ();
865
- }
866
- }
867
892
List <String > configContactPoints =
868
893
defaultConfig .getStringList (DefaultDriverOption .CONTACT_POINTS , Collections .emptyList ());
869
- if (cloudConfigInputStream != null ) {
894
+ if (scyllaCloudConfigInputStream != null ) {
870
895
if (!programmaticContactPoints .isEmpty () || !configContactPoints .isEmpty ()) {
871
896
LOG .info (
872
897
"Both a secure connect bundle and contact points were provided. These are mutually exclusive. The contact points from the secure bundle will have priority." );
@@ -880,20 +905,27 @@ protected final CompletionStage<CqlSession> buildDefaultSessionAsync() {
880
905
LOG .info (
881
906
"Both a secure connect bundle and SSL options were provided. They are mutually exclusive. The SSL options from the secure bundle will have priority." );
882
907
}
883
- CloudConfig cloudConfig =
884
- new CloudConfigFactory ().createCloudConfig (cloudConfigInputStream .call ());
885
- addContactEndPoints (cloudConfig .getEndPoints ());
908
+ ScyllaCloudConnectionConfig cloudConfig =
909
+ ScyllaCloudConnectionConfig .fromInputStream (scyllaCloudConfigInputStream .call ());
910
+ InetSocketAddress proxyAddress = cloudConfig .getCurrentDatacenter ().getServer ();
911
+ addContactEndPoints (
912
+ ImmutableList .of (
913
+ new SniEndPoint (proxyAddress , cloudConfig .getCurrentDatacenter ().getNodeDomain ())));
886
914
887
915
boolean localDataCenterDefined =
888
916
anyProfileHasDatacenterDefined (configLoader .getInitialConfig ());
889
917
if (programmaticLocalDatacenter || localDataCenterDefined ) {
890
918
LOG .info (
891
- "Both a secure connect bundle and a local datacenter were provided. They are mutually exclusive. The local datacenter from the secure bundle will have priority." );
919
+ "Both a secure connect bundle and a local datacenter were provided. They are mutually exclusive. The currentContext datacenter name from the secure bundle will be ignored." );
920
+ } else {
892
921
programmaticArgumentsBuilder .clearDatacenters ();
922
+ withLocalDatacenter (cloudConfig .getCurrentContext ().getDatacenterName ());
893
923
}
894
- withLocalDatacenter (cloudConfig .getLocalDatacenter ());
895
- withSslEngineFactory (cloudConfig .getSslEngineFactory ());
896
- withCloudProxyAddress (cloudConfig .getProxyAddress ());
924
+ ConfigurationBundle bundle = cloudConfig .createBundle ();
925
+ withSslEngineFactory (bundle .getSSLEngineFactory ());
926
+ withScyllaCloudProxyAddress (
927
+ proxyAddress , cloudConfig .getCurrentDatacenter ().getNodeDomain ());
928
+
897
929
programmaticArguments = programmaticArgumentsBuilder .build ();
898
930
}
899
931
@@ -912,7 +944,6 @@ protected final CompletionStage<CqlSession> buildDefaultSessionAsync() {
912
944
(InternalDriverContext ) buildContext (configLoader , programmaticArguments ),
913
945
contactPoints ,
914
946
keyspace );
915
-
916
947
} catch (Throwable t ) {
917
948
// We construct the session synchronously (until the init() call), but async clients expect a
918
949
// failed future if anything goes wrong. So wrap any error from that synchronous part.
@@ -929,27 +960,6 @@ private boolean anyProfileHasDatacenterDefined(DriverConfig driverConfig) {
929
960
return false ;
930
961
}
931
962
932
- /**
933
- * Returns URL based on the configUrl setting. If the configUrl has no protocol provided, the
934
- * method will fallback to file:// protocol and return URL that has file protocol specified.
935
- *
936
- * @param configUrl url to config secure bundle
937
- * @return URL with file protocol if there was not explicit protocol provided in the configUrl
938
- * setting
939
- */
940
- private URL getURL (String configUrl ) throws MalformedURLException {
941
- try {
942
- return new URL (configUrl );
943
- } catch (MalformedURLException e1 ) {
944
- try {
945
- return Paths .get (configUrl ).toAbsolutePath ().normalize ().toUri ().toURL ();
946
- } catch (MalformedURLException e2 ) {
947
- e2 .addSuppressed (e1 );
948
- throw e2 ;
949
- }
950
- }
951
- }
952
-
953
963
/**
954
964
* This <b>must</b> return an instance of {@code InternalDriverContext} (it's not expressed
955
965
* directly in the signature to avoid leaking that type through the protected API).
0 commit comments