32
32
import static com .google .cloud .spanner .connection .ConnectionProperties .ENABLE_EXTENDED_TRACING ;
33
33
import static com .google .cloud .spanner .connection .ConnectionProperties .ENCODED_CREDENTIALS ;
34
34
import static com .google .cloud .spanner .connection .ConnectionProperties .ENDPOINT ;
35
+ import static com .google .cloud .spanner .connection .ConnectionProperties .IS_EXPERIMENTAL_HOST ;
35
36
import static com .google .cloud .spanner .connection .ConnectionProperties .LENIENT ;
36
37
import static com .google .cloud .spanner .connection .ConnectionProperties .MAX_COMMIT_DELAY ;
37
38
import static com .google .cloud .spanner .connection .ConnectionProperties .MAX_PARTITIONED_PARALLELISM ;
@@ -221,6 +222,7 @@ public String[] getValidValues() {
221
222
private static final LocalConnectionChecker LOCAL_CONNECTION_CHECKER =
222
223
new LocalConnectionChecker ();
223
224
static final boolean DEFAULT_USE_PLAIN_TEXT = false ;
225
+ static final boolean DEFAULT_IS_EXPERIMENTAL_HOST = false ;
224
226
static final boolean DEFAULT_AUTOCOMMIT = true ;
225
227
static final boolean DEFAULT_READONLY = false ;
226
228
static final boolean DEFAULT_RETRY_ABORTS_INTERNALLY = true ;
@@ -260,6 +262,8 @@ public String[] getValidValues() {
260
262
static final boolean DEFAULT_AUTO_BATCH_DML = false ;
261
263
static final long DEFAULT_AUTO_BATCH_DML_UPDATE_COUNT = 1L ;
262
264
static final boolean DEFAULT_AUTO_BATCH_DML_UPDATE_COUNT_VERIFICATION = true ;
265
+ private static final String EXPERIMENTAL_HOST_PROJECT_ID = "default" ;
266
+ private static final String DEFAULT_EXPERIMENTAL_HOST_INSTANCE_ID = "default" ;
263
267
264
268
private static final String PLAIN_TEXT_PROTOCOL = "http:" ;
265
269
private static final String HOST_PROTOCOL = "https:" ;
@@ -268,6 +272,8 @@ public String[] getValidValues() {
268
272
private static final String DEFAULT_EMULATOR_HOST = "http://localhost:9010" ;
269
273
/** Use plain text is only for local testing purposes. */
270
274
static final String USE_PLAIN_TEXT_PROPERTY_NAME = "usePlainText" ;
275
+ /** Connect to a Experimental Host * */
276
+ static final String IS_EXPERIMENTAL_HOST_PROPERTY_NAME = "isExperimentalHost" ;
271
277
/** Client certificate path to establish mTLS */
272
278
static final String CLIENT_CERTIFICATE_PROPERTY_NAME = "clientCertificate" ;
273
279
/** Client key path to establish mTLS */
@@ -444,6 +450,10 @@ static boolean isEnableTransactionalConnectionStateForPostgreSQL() {
444
450
USE_PLAIN_TEXT_PROPERTY_NAME ,
445
451
"Use a plain text communication channel (i.e. non-TLS) for communicating with the server (true/false). Set this value to true for communication with the Cloud Spanner emulator." ,
446
452
DEFAULT_USE_PLAIN_TEXT ),
453
+ ConnectionProperty .createBooleanProperty (
454
+ IS_EXPERIMENTAL_HOST_PROPERTY_NAME ,
455
+ "Set this value to true for communication with an Experimental Host." ,
456
+ DEFAULT_IS_EXPERIMENTAL_HOST ),
447
457
ConnectionProperty .createStringProperty (
448
458
CLIENT_CERTIFICATE_PROPERTY_NAME ,
449
459
"Specifies the file path to the client certificate required for establishing an mTLS connection." ),
@@ -664,7 +674,7 @@ private boolean isValidUri(String uri) {
664
674
return SPANNER_URI_PATTERN .matcher (uri ).matches ();
665
675
}
666
676
667
- private boolean isValidExternalHostUri (String uri ) {
677
+ private boolean isValidExperimentalHostUri (String uri ) {
668
678
return EXTERNAL_HOST_PATTERN .matcher (uri ).matches ();
669
679
}
670
680
@@ -725,7 +735,7 @@ private boolean isValidExternalHostUri(String uri) {
725
735
* @return this builder
726
736
*/
727
737
public Builder setUri (String uri ) {
728
- if (!isValidExternalHostUri (uri )) {
738
+ if (!isValidExperimentalHostUri (uri )) {
729
739
Preconditions .checkArgument (
730
740
isValidUri (uri ),
731
741
"The specified URI is not a valid Cloud Spanner connection URI. Please specify a URI in the format \" cloudspanner:[//host[:port]]/projects/project-id[/instances/instance-id[/databases/database-name]][\\ ?property-name=property-value[;property-name=property-value]*]?\" " );
@@ -857,10 +867,10 @@ public static Builder newBuilder() {
857
867
858
868
private ConnectionOptions (Builder builder ) {
859
869
Matcher matcher ;
860
- boolean isExternalHost = false ;
861
- if (builder .isValidExternalHostUri (builder .uri )) {
870
+ boolean isExperimentalHostPattern = false ;
871
+ if (builder .isValidExperimentalHostUri (builder .uri )) {
862
872
matcher = Builder .EXTERNAL_HOST_PATTERN .matcher (builder .uri );
863
- isExternalHost = true ;
873
+ isExperimentalHostPattern = true ;
864
874
} else {
865
875
matcher = Builder .SPANNER_URI_PATTERN .matcher (builder .uri );
866
876
}
@@ -923,8 +933,8 @@ private ConnectionOptions(Builder builder) {
923
933
getInitialConnectionPropertyValue (AUTO_CONFIG_EMULATOR ),
924
934
usePlainText ,
925
935
System .getenv ());
926
- GoogleCredentials defaultExternalHostCredentials =
927
- SpannerOptions .getDefaultExternalHostCredentialsFromSysEnv ();
936
+ GoogleCredentials defaultExperimentalHostCredentials =
937
+ SpannerOptions .getDefaultExperimentalCredentialsFromSysEnv ();
928
938
// Using credentials on a plain text connection is not allowed, so if the user has not specified
929
939
// any credentials and is using a plain text connection, we should not try to get the
930
940
// credentials from the environment, but default to NoCredentials.
@@ -939,8 +949,9 @@ && getInitialConnectionPropertyValue(OAUTH_TOKEN) == null
939
949
this .credentials =
940
950
new GoogleCredentials (
941
951
new AccessToken (getInitialConnectionPropertyValue (OAUTH_TOKEN ), null ));
942
- } else if (isExternalHost && defaultExternalHostCredentials != null ) {
943
- this .credentials = defaultExternalHostCredentials ;
952
+ } else if ((isExperimentalHostPattern || isExperimentalHost ())
953
+ && defaultExperimentalHostCredentials != null ) {
954
+ this .credentials = defaultExperimentalHostCredentials ;
944
955
} else if (getInitialConnectionPropertyValue (CREDENTIALS_PROVIDER ) != null ) {
945
956
try {
946
957
this .credentials = getInitialConnectionPropertyValue (CREDENTIALS_PROVIDER ).getCredentials ();
@@ -981,16 +992,19 @@ && getInitialConnectionPropertyValue(OAUTH_TOKEN) == null
981
992
this .sessionPoolOptions = sessionPoolOptionsBuilder .build ();
982
993
} else if (builder .sessionPoolOptions != null ) {
983
994
this .sessionPoolOptions = builder .sessionPoolOptions ;
995
+ } else if (isExperimentalHostPattern || isExperimentalHost ()) {
996
+ this .sessionPoolOptions =
997
+ SessionPoolOptions .newBuilder ().setExperimentalHost ().setAutoDetectDialect (true ).build ();
984
998
} else {
985
999
this .sessionPoolOptions = SessionPoolOptions .newBuilder ().setAutoDetectDialect (true ).build ();
986
1000
}
987
1001
988
- String projectId = "default" ;
1002
+ String projectId = EXPERIMENTAL_HOST_PROJECT_ID ;
989
1003
String instanceId = matcher .group (Builder .INSTANCE_GROUP );
990
- if (!isExternalHost ) {
1004
+ if (!isExperimentalHost () && ! isExperimentalHostPattern ) {
991
1005
projectId = matcher .group (Builder .PROJECT_GROUP );
992
- } else if (instanceId == null ) {
993
- instanceId = "default" ;
1006
+ } else if (instanceId == null && isExperimentalHost () ) {
1007
+ instanceId = DEFAULT_EXPERIMENTAL_HOST_INSTANCE_ID ;
994
1008
}
995
1009
if (Builder .DEFAULT_PROJECT_ID_PLACEHOLDER .equalsIgnoreCase (projectId )) {
996
1010
projectId = getDefaultProjectId (this .credentials );
@@ -1311,6 +1325,10 @@ boolean isUsePlainText() {
1311
1325
|| getInitialConnectionPropertyValue (USE_PLAIN_TEXT );
1312
1326
}
1313
1327
1328
+ boolean isExperimentalHost () {
1329
+ return getInitialConnectionPropertyValue (IS_EXPERIMENTAL_HOST );
1330
+ }
1331
+
1314
1332
String getClientCertificate () {
1315
1333
return getInitialConnectionPropertyValue (CLIENT_CERTIFICATE );
1316
1334
}
0 commit comments