From af37fb3c05dd486862d25a3aaa012307da535a22 Mon Sep 17 00:00:00 2001 From: "Jonathan Hess (he/him)" <103529393+hessjcg@users.noreply.github.com> Date: Mon, 30 Oct 2023 15:03:24 -0600 Subject: [PATCH] chore: Extract internal connector registry implementation (#1645) Move the connector registry implementation out of CoreSocketFactory and into InternalConnectorRegistry. CoreSocketFactory is deprecated and contains only the static public methods used informally by other projects. It delegates to the InternalConnectorRegistry. --- .../cloud/sql/core/CoreSocketFactory.java | 337 +---------------- .../sql/core/InternalConnectorRegistry.java | 358 ++++++++++++++++++ .../google/cloud/sql/core/package-info.java | 6 +- ...ultConnectionInfoCacheConcurrencyTest.java | 2 +- ...ava => InternalConnectorRegistryTest.java} | 95 ++--- .../cloud/sql/mariadb/SocketFactory.java | 8 +- .../google/cloud/sql/mysql/SocketFactory.java | 8 +- .../cloud/sql/postgres/SocketFactory.java | 8 +- .../cloud/sql/sqlserver/SocketFactory.java | 8 +- .../sql/core/CloudSqlConnectionFactory.java | 4 +- .../core/GcpConnectionFactoryProvider.java | 4 +- .../GcpConnectionFactoryProviderTest.java | 10 +- .../GcpConnectionFactoryProviderMysql.java | 2 +- .../GcpConnectionFactoryProviderPostgres.java | 2 +- .../GcpConnectionFactoryProviderMssql.java | 2 +- 15 files changed, 448 insertions(+), 406 deletions(-) create mode 100644 core/src/main/java/com/google/cloud/sql/core/InternalConnectorRegistry.java rename core/src/test/java/com/google/cloud/sql/core/{CoreSocketFactoryTest.java => InternalConnectorRegistryTest.java} (82%) diff --git a/core/src/main/java/com/google/cloud/sql/core/CoreSocketFactory.java b/core/src/main/java/com/google/cloud/sql/core/CoreSocketFactory.java index 96800a8ba..9a594cb8d 100644 --- a/core/src/main/java/com/google/cloud/sql/core/CoreSocketFactory.java +++ b/core/src/main/java/com/google/cloud/sql/core/CoreSocketFactory.java @@ -16,42 +16,15 @@ package com.google.cloud.sql.core; -import com.google.api.client.http.HttpRequestInitializer; import com.google.cloud.sql.ConnectionConfig; -import com.google.cloud.sql.CredentialFactory; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningScheduledExecutorService; -import com.google.common.util.concurrent.MoreExecutors; -import java.io.File; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.logging.Logger; -import javax.net.ssl.SSLSocket; -import jnr.unixsocket.UnixSocketAddress; -import jnr.unixsocket.UnixSocketChannel; /** - * Factory responsible for obtaining an ephemeral certificate, if necessary, and establishing a - * secure connecting to a Cloud SQL instance. + * Implementation of informally used Java API to preserve compatibility with older code that uses + * CoreSocketFactory. * - *
This class should not be used directly, but only through the JDBC driver specific {@code - * SocketFactory} implementations. - * - *
The API of this class is subject to change without notice.
+ * @deprecated This will soon be replaced.
*/
+@Deprecated
public final class CoreSocketFactory {
/**
@@ -98,303 +71,11 @@ public final class CoreSocketFactory {
* @deprecated Use {@link #setApplicationName(String)} to set the application name
* programmatically.
*/
- @Deprecated public static final String USER_TOKEN_PROPERTY_NAME = "_CLOUD_SQL_USER_TOKEN";
-
- static final long DEFAULT_MAX_REFRESH_MS = 30000;
- private static final Logger logger = Logger.getLogger(CoreSocketFactory.class.getName());
-
- private static final int DEFAULT_SERVER_PROXY_PORT = 3307;
- private static final int RSA_KEY_SIZE = 2048;
- private static final List Depending on the given properties, it may return either a SSL Socket or a Unix Socket.
- *
- * @param props Properties used to configure the connection.
- * @param unixPathSuffix suffix to add the the Unix socket path. Unused if null.
- * @return the newly created Socket.
- * @throws IOException if error occurs during socket creation.
- */
- public static Socket connect(Properties props, String unixPathSuffix)
- throws IOException, InterruptedException {
- // Gather parameters
-
- ConnectionConfig config = ConnectionConfig.fromConnectionProperties(props);
-
- // Validate parameters
- Preconditions.checkArgument(
- config.getCloudSqlInstance() != null,
- "cloudSqlInstance property not set. Please specify this property in the JDBC URL or the "
- + "connection Properties with value in form \"project:region:instance\"");
-
- // Connect using the specified Unix socket
- String unixSocket = getUnixSocketArg(config);
- if (unixSocket != null) {
- // Verify it ends with the correct suffix
- if (unixPathSuffix != null && !unixSocket.endsWith(unixPathSuffix)) {
- unixSocket = unixSocket + unixPathSuffix;
- }
- logger.info(
- String.format(
- "Connecting to Cloud SQL instance [%s] via unix socket at %s.",
- config.getCloudSqlInstance(), unixSocket));
- UnixSocketAddress socketAddress = new UnixSocketAddress(new File(unixSocket));
- return UnixSocketChannel.open(socketAddress).socket();
- }
-
- return getInstance().createSslSocket(config);
- }
-
- /** Returns data that can be used to establish Cloud SQL SSL connection. */
- public static SslData getSslData(ConnectionConfig config) throws IOException {
- CoreSocketFactory instance = getInstance();
- return instance.getConnectionInfoCache(config).getSslData(instance.refreshTimeoutMs);
- }
-
- /** Returns preferred ip address that can be used to establish Cloud SQL connection. */
- public static String getHostIp(ConnectionConfig config) throws IOException {
- CoreSocketFactory instance = getInstance();
- return instance
- .getConnectionInfoCache(config)
- .getPreferredIp(config.getIpTypes(), instance.refreshTimeoutMs);
- }
-
- private static KeyPair generateRsaKeyPair() {
- KeyPairGenerator generator;
- try {
- generator = KeyPairGenerator.getInstance("RSA");
- } catch (NoSuchAlgorithmException err) {
- throw new RuntimeException(
- "Unable to initialize Cloud SQL socket factory because no RSA implementation is "
- + "available.");
- }
- generator.initialize(RSA_KEY_SIZE);
- return generator.generateKeyPair();
- }
-
- private static String getVersion() {
- try {
- Properties packageInfo = new Properties();
- packageInfo.load(
- CoreSocketFactory.class
- .getClassLoader()
- .getResourceAsStream("com.google.cloud.sql/project.properties"));
- return packageInfo.getProperty("version", "unknown");
- } catch (IOException e) {
- return "unknown";
- }
- }
-
- /**
- * Internal use only: Sets the default string which is appended to the SQLAdmin API client
- * User-Agent header.
- *
- * This is used by the specific database connector socket factory implementations to append
- * their database name to the user agent.
- */
- public static void addArtifactId(String artifactId) {
- String userAgent = artifactId + "/" + version;
- if (!userAgents.contains(userAgent)) {
- userAgents.add(userAgent);
- }
- }
-
- /** Resets the values of User Agent fields for unit tests. */
- @VisibleForTesting
- static void resetUserAgent() {
- coreSocketFactory = null;
- userAgents.clear();
- setApplicationName("");
- }
-
- /** Returns the default string which is appended to the SQLAdmin API client User-Agent header. */
- static String getUserAgents() {
- String ua = String.join(" ", userAgents);
- String appName = getApplicationName();
- if (!Strings.isNullOrEmpty(appName)) {
- ua = ua + " " + appName;
- }
- return ua;
- }
-
- /** Returns the current User-Agent header set for the underlying SQLAdmin API client. */
- private static String getApplicationName() {
- return System.getProperty(USER_TOKEN_PROPERTY_NAME, "");
- }
-
- /**
- * Adds an external application name to the user agent string for tracking. This is known to be
- * used by the spring-cloud-gcp project.
- *
- * @throws IllegalStateException if the SQLAdmin client has already been initialized
- */
- public static void setApplicationName(String applicationName) {
- if (coreSocketFactory != null) {
- throw new IllegalStateException(
- "Unable to set ApplicationName - SQLAdmin client already initialized.");
- }
- System.setProperty(USER_TOKEN_PROPERTY_NAME, applicationName);
- }
-
- /**
- * Creates a secure socket representing a connection to a Cloud SQL instance.
- *
- * @return the newly created Socket.
- * @throws IOException if error occurs during socket creation.
- */
- // TODO(berezv): separate creating socket and performing connection to make it easier to test
- @VisibleForTesting
- Socket createSslSocket(ConnectionConfig config) throws IOException, InterruptedException {
- DefaultConnectionInfoCache connectionInfoCache = getConnectionInfoCache(config);
-
- try {
- SSLSocket socket = connectionInfoCache.createSslSocket(this.refreshTimeoutMs);
-
- // TODO(kvg): Support all socket related options listed here:
- // https://dev.mysql.com/doc/connector-j/en/connector-j-reference-configuration-properties.html
- socket.setKeepAlive(true);
- socket.setTcpNoDelay(true);
-
- String instanceIp = connectionInfoCache.getPreferredIp(config.getIpTypes(), refreshTimeoutMs);
-
- socket.connect(new InetSocketAddress(instanceIp, serverProxyPort));
- socket.startHandshake();
-
- return socket;
- } catch (Exception ex) {
- // TODO(kvg): Let user know about the rate limit
- connectionInfoCache.forceRefresh();
- throw ex;
- }
- }
-
- DefaultConnectionInfoCache getConnectionInfoCache(ConnectionConfig config) {
- return connectionInfoCaches.computeIfAbsent(
- config.getCloudSqlInstance(), k -> newConnectionInfoCache(config));
- }
-
- private DefaultConnectionInfoCache newConnectionInfoCache(ConnectionConfig config) {
-
- final CredentialFactory instanceCredentialFactory;
- if (config.getTargetPrincipal() != null && !config.getTargetPrincipal().isEmpty()) {
- instanceCredentialFactory =
- new ServiceAccountImpersonatingCredentialFactory(
- credentialFactory, config.getTargetPrincipal(), config.getDelegates());
- } else {
- if (config.getDelegates() != null && !config.getDelegates().isEmpty()) {
- throw new IllegalArgumentException(
- String.format(
- "Connection property %s must be when %s is set.",
- ConnectionConfig.CLOUD_SQL_TARGET_PRINCIPAL_PROPERTY,
- ConnectionConfig.CLOUD_SQL_DELEGATES_PROPERTY));
- }
- instanceCredentialFactory = credentialFactory;
- }
-
- HttpRequestInitializer credential = instanceCredentialFactory.create();
- DefaultConnectionInfoRepository adminApi =
- connectionInfoRepositoryFactory.create(credential, config);
+ @Deprecated
+ public static final String USER_TOKEN_PROPERTY_NAME =
+ InternalConnectorRegistry.USER_TOKEN_PROPERTY_NAME;
- return new DefaultConnectionInfoCache(
- config.getCloudSqlInstance(),
- adminApi,
- config.getAuthType(),
- instanceCredentialFactory,
- executor,
- localKeyPair,
- MIN_REFRESH_DELAY_MS);
+ static void setApplicationName(String artifactId) {
+ InternalConnectorRegistry.setApplicationName(artifactId);
}
}
diff --git a/core/src/main/java/com/google/cloud/sql/core/InternalConnectorRegistry.java b/core/src/main/java/com/google/cloud/sql/core/InternalConnectorRegistry.java
new file mode 100644
index 000000000..dc251a387
--- /dev/null
+++ b/core/src/main/java/com/google/cloud/sql/core/InternalConnectorRegistry.java
@@ -0,0 +1,358 @@
+/*
+ * Copyright 2023 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.cloud.sql.core;
+
+import com.google.api.client.http.HttpRequestInitializer;
+import com.google.cloud.sql.ConnectionConfig;
+import com.google.cloud.sql.CredentialFactory;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListeningScheduledExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
+import java.io.File;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.logging.Logger;
+import javax.net.ssl.SSLSocket;
+import jnr.unixsocket.UnixSocketAddress;
+import jnr.unixsocket.UnixSocketChannel;
+
+/**
+ * InternalConnectorRegistry keeps track of connectors. This class should not be used directly, but
+ * only through the JDBC driver specific {@code SocketFactory} implementations.
+ *
+ * WARNING: This is an internal class. The API is subject to change without notice.
+ */
+public final class InternalConnectorRegistry {
+ static final long DEFAULT_MAX_REFRESH_MS = 30000;
+ private static final Logger logger = Logger.getLogger(InternalConnectorRegistry.class.getName());
+
+ private static final int DEFAULT_SERVER_PROXY_PORT = 3307;
+ private static final int RSA_KEY_SIZE = 2048;
+ private static final List Depending on the given properties, it may return either a SSL Socket or a Unix Socket.
+ *
+ * @param props Properties used to configure the connection.
+ * @param unixPathSuffix suffix to add the the Unix socket path. Unused if null.
+ * @return the newly created Socket.
+ * @throws IOException if error occurs during socket creation.
+ */
+ public static Socket connect(Properties props, String unixPathSuffix)
+ throws IOException, InterruptedException {
+ // Gather parameters
+
+ ConnectionConfig config = ConnectionConfig.fromConnectionProperties(props);
+
+ // Validate parameters
+ Preconditions.checkArgument(
+ config.getCloudSqlInstance() != null,
+ "cloudSqlInstance property not set. Please specify this property in the JDBC URL or the "
+ + "connection Properties with value in form \"project:region:instance\"");
+
+ // Connect using the specified Unix socket
+ String unixSocket = getUnixSocketArg(config);
+ if (unixSocket != null) {
+ // Verify it ends with the correct suffix
+ if (unixPathSuffix != null && !unixSocket.endsWith(unixPathSuffix)) {
+ unixSocket = unixSocket + unixPathSuffix;
+ }
+ logger.info(
+ String.format(
+ "Connecting to Cloud SQL instance [%s] via unix socket at %s.",
+ config.getCloudSqlInstance(), unixSocket));
+ UnixSocketAddress socketAddress = new UnixSocketAddress(new File(unixSocket));
+ return UnixSocketChannel.open(socketAddress).socket();
+ }
+
+ return getInstance().createSslSocket(config);
+ }
+
+ /** Returns data that can be used to establish Cloud SQL SSL connection. */
+ public static SslData getSslData(ConnectionConfig config) throws IOException {
+ InternalConnectorRegistry instance = getInstance();
+ return instance.getConnectionInfoCache(config).getSslData(instance.refreshTimeoutMs);
+ }
+
+ /** Returns preferred ip address that can be used to establish Cloud SQL connection. */
+ public static String getHostIp(ConnectionConfig config) throws IOException {
+ InternalConnectorRegistry instance = getInstance();
+ return instance
+ .getConnectionInfoCache(config)
+ .getPreferredIp(config.getIpTypes(), instance.refreshTimeoutMs);
+ }
+
+ private static KeyPair generateRsaKeyPair() {
+ KeyPairGenerator generator;
+ try {
+ generator = KeyPairGenerator.getInstance("RSA");
+ } catch (NoSuchAlgorithmException err) {
+ throw new RuntimeException(
+ "Unable to initialize Cloud SQL socket factory because no RSA implementation is "
+ + "available.");
+ }
+ generator.initialize(RSA_KEY_SIZE);
+ return generator.generateKeyPair();
+ }
+
+ private static String getVersion() {
+ try {
+ Properties packageInfo = new Properties();
+ packageInfo.load(
+ InternalConnectorRegistry.class
+ .getClassLoader()
+ .getResourceAsStream("com.google.cloud.sql/project.properties"));
+ return packageInfo.getProperty("version", "unknown");
+ } catch (IOException e) {
+ return "unknown";
+ }
+ }
+
+ /**
+ * Internal use only: Sets the default string which is appended to the SQLAdmin API client
+ * User-Agent header.
+ *
+ * This is used by the specific database connector socket factory implementations to append
+ * their database name to the user agent.
+ */
+ public static void addArtifactId(String artifactId) {
+ String userAgent = artifactId + "/" + version;
+ if (!userAgents.contains(userAgent)) {
+ userAgents.add(userAgent);
+ }
+ }
+
+ /** Resets the values of User Agent fields for unit tests. */
+ @VisibleForTesting
+ static void resetUserAgent() {
+ internalConnectorRegistry = null;
+ userAgents.clear();
+ setApplicationName("");
+ }
+
+ /** Returns the default string which is appended to the SQLAdmin API client User-Agent header. */
+ static String getUserAgents() {
+ String ua = String.join(" ", userAgents);
+ String appName = getApplicationName();
+ if (!Strings.isNullOrEmpty(appName)) {
+ ua = ua + " " + appName;
+ }
+ return ua;
+ }
+
+ /** Returns the current User-Agent header set for the underlying SQLAdmin API client. */
+ private static String getApplicationName() {
+ return System.getProperty(USER_TOKEN_PROPERTY_NAME, "");
+ }
+
+ /**
+ * Adds an external application name to the user agent string for tracking. This is known to be
+ * used by the spring-cloud-gcp project.
+ *
+ * @throws IllegalStateException if the SQLAdmin client has already been initialized
+ */
+ public static void setApplicationName(String applicationName) {
+ if (internalConnectorRegistry != null) {
+ throw new IllegalStateException(
+ "Unable to set ApplicationName - SQLAdmin client already initialized.");
+ }
+ System.setProperty(USER_TOKEN_PROPERTY_NAME, applicationName);
+ }
+
+ /**
+ * Creates a secure socket representing a connection to a Cloud SQL instance.
+ *
+ * @return the newly created Socket.
+ * @throws IOException if error occurs during socket creation.
+ */
+ // TODO(berezv): separate creating socket and performing connection to make it easier to test
+ @VisibleForTesting
+ Socket createSslSocket(ConnectionConfig config) throws IOException, InterruptedException {
+ DefaultConnectionInfoCache connectionInfoCache = getConnectionInfoCache(config);
+
+ try {
+ SSLSocket socket = connectionInfoCache.createSslSocket(this.refreshTimeoutMs);
+
+ // TODO(kvg): Support all socket related options listed here:
+ // https://dev.mysql.com/doc/connector-j/en/connector-j-reference-configuration-properties.html
+ socket.setKeepAlive(true);
+ socket.setTcpNoDelay(true);
+
+ String instanceIp = connectionInfoCache.getPreferredIp(config.getIpTypes(), refreshTimeoutMs);
+
+ socket.connect(new InetSocketAddress(instanceIp, serverProxyPort));
+ socket.startHandshake();
+
+ return socket;
+ } catch (Exception ex) {
+ // TODO(kvg): Let user know about the rate limit
+ connectionInfoCache.forceRefresh();
+ throw ex;
+ }
+ }
+
+ DefaultConnectionInfoCache getConnectionInfoCache(ConnectionConfig config) {
+ return connectionInfoCaches.computeIfAbsent(
+ config.getCloudSqlInstance(), k -> apiFetcher(config));
+ }
+
+ private DefaultConnectionInfoCache apiFetcher(ConnectionConfig config) {
+
+ final CredentialFactory instanceCredentialFactory;
+ if (config.getTargetPrincipal() != null && !config.getTargetPrincipal().isEmpty()) {
+ instanceCredentialFactory =
+ new ServiceAccountImpersonatingCredentialFactory(
+ credentialFactory, config.getTargetPrincipal(), config.getDelegates());
+ } else {
+ if (config.getDelegates() != null && !config.getDelegates().isEmpty()) {
+ throw new IllegalArgumentException(
+ String.format(
+ "Connection property %s must be when %s is set.",
+ ConnectionConfig.CLOUD_SQL_TARGET_PRINCIPAL_PROPERTY,
+ ConnectionConfig.CLOUD_SQL_DELEGATES_PROPERTY));
+ }
+ instanceCredentialFactory = credentialFactory;
+ }
+
+ HttpRequestInitializer credential = instanceCredentialFactory.create();
+ DefaultConnectionInfoRepository adminApi =
+ connectionInfoRepositoryFactory.create(credential, config);
+
+ return new DefaultConnectionInfoCache(
+ config.getCloudSqlInstance(),
+ adminApi,
+ config.getAuthType(),
+ instanceCredentialFactory,
+ executor,
+ localKeyPair,
+ MIN_REFRESH_DELAY_MS);
+ }
+}
diff --git a/core/src/main/java/com/google/cloud/sql/core/package-info.java b/core/src/main/java/com/google/cloud/sql/core/package-info.java
index 8643db86f..f483c6271 100644
--- a/core/src/main/java/com/google/cloud/sql/core/package-info.java
+++ b/core/src/main/java/com/google/cloud/sql/core/package-info.java
@@ -15,8 +15,10 @@
*/
/**
- * Package com.google.cloud.sql.core holds internal shared packages that implement logic to create a
- * socket to a Cloud SQL database. Classes in this package are considered internal and subject to
+ * WARNING: This package does not contain any stable, public Java API. The class definitions may
* change without notice.
+ *
+ * Package com.google.cloud.sql.core holds internal shared packages that implement logic to
+ * create a socket to a Cloud SQL database.
*/
package com.google.cloud.sql.core;
diff --git a/core/src/test/java/com/google/cloud/sql/core/DefaultConnectionInfoCacheConcurrencyTest.java b/core/src/test/java/com/google/cloud/sql/core/DefaultConnectionInfoCacheConcurrencyTest.java
index 05a3baa43..1f966c351 100644
--- a/core/src/test/java/com/google/cloud/sql/core/DefaultConnectionInfoCacheConcurrencyTest.java
+++ b/core/src/test/java/com/google/cloud/sql/core/DefaultConnectionInfoCacheConcurrencyTest.java
@@ -59,7 +59,7 @@ public void testForceRefreshDoesNotCauseADeadlockOrBrokenRefreshLoop() throws Ex
MockAdminApi mockAdminApi = new MockAdminApi();
ListenableFuture The heavy lifting is done by the singleton {@link CoreSocketFactory} class.
+ * The heavy lifting is done by the singleton {@link InternalConnectorRegistry} class.
*/
public class SocketFactory extends ConfigurableSocketFactory {
static {
- CoreSocketFactory.addArtifactId("mariadb-socket-factory");
+ InternalConnectorRegistry.addArtifactId("mariadb-socket-factory");
}
private Configuration conf;
@@ -48,7 +48,7 @@ public void setConfiguration(Configuration conf, String host) {
@Override
public Socket createSocket() throws IOException {
try {
- return CoreSocketFactory.connect(conf.nonMappedOptions());
+ return InternalConnectorRegistry.connect(conf.nonMappedOptions());
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
diff --git a/jdbc/mysql-j-8/src/main/java/com/google/cloud/sql/mysql/SocketFactory.java b/jdbc/mysql-j-8/src/main/java/com/google/cloud/sql/mysql/SocketFactory.java
index 623d13dc3..05e52c4bb 100644
--- a/jdbc/mysql-j-8/src/main/java/com/google/cloud/sql/mysql/SocketFactory.java
+++ b/jdbc/mysql-j-8/src/main/java/com/google/cloud/sql/mysql/SocketFactory.java
@@ -16,7 +16,7 @@
package com.google.cloud.sql.mysql;
-import com.google.cloud.sql.core.CoreSocketFactory;
+import com.google.cloud.sql.core.InternalConnectorRegistry;
import com.mysql.cj.conf.PropertySet;
import com.mysql.cj.protocol.ServerSession;
import com.mysql.cj.protocol.SocketConnection;
@@ -28,12 +28,12 @@
* A MySQL {@link SocketFactory} that establishes a secure connection to a Cloud SQL instance using
* ephemeral certificates.
*
- * The heavy lifting is done by the singleton {@link CoreSocketFactory} class.
+ * The heavy lifting is done by the singleton {@link InternalConnectorRegistry} class.
*/
public class SocketFactory implements com.mysql.cj.protocol.SocketFactory {
static {
- CoreSocketFactory.addArtifactId("mysql-socket-factory-connector-j-8");
+ InternalConnectorRegistry.addArtifactId("mysql-socket-factory-connector-j-8");
}
@Override
@@ -56,7 +56,7 @@ public The heavy lifting is done by the singleton {@link CoreSocketFactory} class.
+ * The heavy lifting is done by the singleton {@link InternalConnectorRegistry} class.
*/
public class SocketFactory extends javax.net.SocketFactory {
@@ -40,7 +40,7 @@ public class SocketFactory extends javax.net.SocketFactory {
private final Properties props;
static {
- CoreSocketFactory.addArtifactId("postgres-socket-factory");
+ InternalConnectorRegistry.addArtifactId("postgres-socket-factory");
}
/**
@@ -75,7 +75,7 @@ private static Properties createDefaultProperties(String instanceName) {
@Override
public Socket createSocket() throws IOException {
try {
- return CoreSocketFactory.connect(props, POSTGRES_SUFFIX);
+ return InternalConnectorRegistry.connect(props, POSTGRES_SUFFIX);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
diff --git a/jdbc/sqlserver/src/main/java/com/google/cloud/sql/sqlserver/SocketFactory.java b/jdbc/sqlserver/src/main/java/com/google/cloud/sql/sqlserver/SocketFactory.java
index 0bcb6aa9f..4e0617db4 100644
--- a/jdbc/sqlserver/src/main/java/com/google/cloud/sql/sqlserver/SocketFactory.java
+++ b/jdbc/sqlserver/src/main/java/com/google/cloud/sql/sqlserver/SocketFactory.java
@@ -17,7 +17,7 @@
package com.google.cloud.sql.sqlserver;
import com.google.cloud.sql.ConnectionConfig;
-import com.google.cloud.sql.core.CoreSocketFactory;
+import com.google.cloud.sql.core.InternalConnectorRegistry;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Splitter;
import java.io.IOException;
@@ -33,12 +33,12 @@
* A Microsoft SQL Server {@link SocketFactory} that establishes a secure connection to a Cloud SQL
* instance using ephemeral certificates.
*
- * The heavy lifting is done by the singleton {@link CoreSocketFactory} class.
+ * The heavy lifting is done by the singleton {@link InternalConnectorRegistry} class.
*/
public class SocketFactory extends javax.net.SocketFactory {
static {
- CoreSocketFactory.addArtifactId("cloud-sql-connector-jdbc-sqlserver");
+ InternalConnectorRegistry.addArtifactId("cloud-sql-connector-jdbc-sqlserver");
}
// props are protected, not private, so that they can be accessed from unit tests
@@ -74,7 +74,7 @@ public SocketFactory(String socketFactoryConstructorArg) throws UnsupportedEncod
@Override
public Socket createSocket() throws IOException {
try {
- return CoreSocketFactory.connect(props);
+ return InternalConnectorRegistry.connect(props);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
diff --git a/r2dbc/core/src/main/java/com/google/cloud/sql/core/CloudSqlConnectionFactory.java b/r2dbc/core/src/main/java/com/google/cloud/sql/core/CloudSqlConnectionFactory.java
index 2b4d52966..e51eb1e06 100644
--- a/r2dbc/core/src/main/java/com/google/cloud/sql/core/CloudSqlConnectionFactory.java
+++ b/r2dbc/core/src/main/java/com/google/cloud/sql/core/CloudSqlConnectionFactory.java
@@ -52,7 +52,7 @@ public CloudSqlConnectionFactory(
@NonNull
public Publisher extends Connection> create() {
try {
- String hostIp = CoreSocketFactory.getHostIp(config);
+ String hostIp = InternalConnectorRegistry.getHostIp(config);
builder.option(HOST, hostIp).option(PORT, SERVER_PROXY_PORT);
return supplier.get().create(builder.build()).create();
} catch (IOException e) {
@@ -64,7 +64,7 @@ public Publisher extends Connection> create() {
@NonNull
public ConnectionFactoryMetadata getMetadata() {
try {
- String hostIp = CoreSocketFactory.getHostIp(config);
+ String hostIp = InternalConnectorRegistry.getHostIp(config);
builder.option(HOST, hostIp).option(PORT, SERVER_PROXY_PORT);
return supplier.get().create(builder.build()).getMetadata();
} catch (IOException e) {
diff --git a/r2dbc/core/src/main/java/com/google/cloud/sql/core/GcpConnectionFactoryProvider.java b/r2dbc/core/src/main/java/com/google/cloud/sql/core/GcpConnectionFactoryProvider.java
index 1c32bab96..b0047fdb2 100644
--- a/r2dbc/core/src/main/java/com/google/cloud/sql/core/GcpConnectionFactoryProvider.java
+++ b/r2dbc/core/src/main/java/com/google/cloud/sql/core/GcpConnectionFactoryProvider.java
@@ -122,7 +122,7 @@ public ConnectionFactory create(ConnectionFactoryOptions connectionFactoryOption
try {
// Precompute SSL Data to trigger the initial refresh to happen immediately,
// and ensure enableIAMAuth is set correctly.
- CoreSocketFactory.getSslData(config);
+ InternalConnectorRegistry.getSslData(config);
String socket = (String) connectionFactoryOptions.getValue(UNIX_SOCKET);
if (socket != null) {
@@ -136,7 +136,7 @@ public ConnectionFactory create(ConnectionFactoryOptions connectionFactoryOption
Mono.fromSupplier(
() -> {
try {
- return CoreSocketFactory.getSslData(config);
+ return InternalConnectorRegistry.getSslData(config);
} catch (IOException e) {
throw new RuntimeException(e);
}
diff --git a/r2dbc/core/src/test/java/com/google/cloud/sql/core/GcpConnectionFactoryProviderTest.java b/r2dbc/core/src/test/java/com/google/cloud/sql/core/GcpConnectionFactoryProviderTest.java
index 3099bf623..a9f82e9a0 100644
--- a/r2dbc/core/src/test/java/com/google/cloud/sql/core/GcpConnectionFactoryProviderTest.java
+++ b/r2dbc/core/src/test/java/com/google/cloud/sql/core/GcpConnectionFactoryProviderTest.java
@@ -66,7 +66,7 @@ public class GcpConnectionFactoryProviderTest {
private final CredentialFactory credentialFactory = new StubCredentialFactory();
ListeningScheduledExecutorService defaultExecutor;
ListenableFuture