diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSAccessStrategy.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSAccessStrategy.java index 4ce9b261f..d3de304fb 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSAccessStrategy.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSAccessStrategy.java @@ -42,7 +42,7 @@ boolean handleStorageException( String command, String queryId, SnowflakeGCSClient gcsClient) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException; + throws SnowflakeSQLException; void shutdown(); } diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSAccessStrategyAwsSdk.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSAccessStrategyAwsSdk.java index 15c4b7c3b..d1be06b7a 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSAccessStrategyAwsSdk.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSAccessStrategyAwsSdk.java @@ -39,8 +39,7 @@ class GCSAccessStrategyAwsSdk implements GCSAccessStrategy { private static final SFLogger logger = SFLoggerFactory.getLogger(GCSAccessStrategyAwsSdk.class); private final AmazonS3 amazonClient; - GCSAccessStrategyAwsSdk(StageInfo stage) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + GCSAccessStrategyAwsSdk(StageInfo stage) throws SnowflakeSQLException { String accessToken = (String) stage.getCredentials().get("GCS_ACCESS_TOKEN"); Optional oEndpoint = stage.gcsCustomEndpoint(); @@ -223,7 +222,7 @@ public boolean handleStorageException( String command, String queryId, SnowflakeGCSClient gcsClient) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { if (ex instanceof AmazonClientException) { logger.debug("GCSAccessStrategyAwsSdk: " + ex.getMessage()); diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSDefaultAccessStrategy.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSDefaultAccessStrategy.java index c710a1ead..2e08910b6 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSDefaultAccessStrategy.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSDefaultAccessStrategy.java @@ -178,7 +178,7 @@ public boolean handleStorageException( String command, String queryId, SnowflakeGCSClient gcsClient) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { if (ex instanceof StorageException) { // NOTE: this code path only handle Access token based operation, // presigned URL is not covered. Presigned Url do not raise diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeAzureClient.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeAzureClient.java index 6e83c25c6..e424dab64 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeAzureClient.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeAzureClient.java @@ -10,8 +10,8 @@ */ package net.snowflake.ingest.streaming.internal.fileTransferAgent; -import static net.snowflake.client.core.HttpUtil.setSessionlessProxyForAzure; import static net.snowflake.ingest.streaming.internal.fileTransferAgent.ErrorCode.CLOUD_STORAGE_CREDENTIALS_EXPIRED; +import static net.snowflake.ingest.streaming.internal.fileTransferAgent.StorageClientUtil.setSessionlessProxyForAzure; import static net.snowflake.ingest.streaming.internal.fileTransferAgent.StorageClientUtil.systemGetProperty; import com.fasterxml.jackson.core.JsonFactory; @@ -80,8 +80,7 @@ private SnowflakeAzureClient() {} * required to decrypt/encrypt content in stage */ public static SnowflakeAzureClient createSnowflakeAzureClient( - StageInfo stage, RemoteStoreFileEncryptionMaterial encMat) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + StageInfo stage, RemoteStoreFileEncryptionMaterial encMat) throws SnowflakeSQLException { logger.debug( "Initializing Snowflake Azure client with encryption: {}", encMat != null ? "true" : "false"); @@ -102,9 +101,7 @@ public static SnowflakeAzureClient createSnowflakeAzureClient( * @throws IllegalArgumentException when invalid credentials are used */ private void setupAzureClient(StageInfo stage, RemoteStoreFileEncryptionMaterial encMat) - throws IllegalArgumentException, - SnowflakeSQLException, - net.snowflake.client.jdbc.SnowflakeSQLException { + throws IllegalArgumentException, SnowflakeSQLException { // Save the client creation parameters so that we can reuse them, // to reset the Azure client. this.stageInfo = stage; @@ -189,8 +186,7 @@ public int getEncryptionKeySize() { * @throws SnowflakeSQLException failure to renew the client */ @Override - public void renew(Map stageCredentials) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + public void renew(Map stageCredentials) throws SnowflakeSQLException { logger.debug("Renewing the Azure client"); stageInfo.setCredentials(stageCredentials); setupAzureClient(stageInfo, encMat); @@ -302,7 +298,7 @@ public void download( String stageRegion, String presignedUrl, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { Stopwatch stopwatch = new Stopwatch(); stopwatch.start(); String localFilePath = localLocation + localFileSep + destFileName; @@ -416,7 +412,7 @@ public InputStream downloadToStream( String stageRegion, String presignedUrl, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { logger.debug( "Staring download of file from Azure stage path: {} to input stream", stageFilePath); Stopwatch stopwatch = new Stopwatch(); @@ -528,7 +524,7 @@ public void upload( String stageRegion, String presignedUrl, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { logger.info( StorageHelper.getStartUploadLog( "Azure", uploadFromStream, inputStream, fileBackedOutputStream, srcFile, destFileName)); @@ -649,7 +645,7 @@ public void upload( @Override public void handleStorageException( Exception ex, int retryCount, String operation, String command, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { handleAzureException(ex, retryCount, operation, command, this, queryId); } @@ -755,7 +751,7 @@ private static void handleAzureException( String command, SnowflakeAzureClient azClient, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { // no need to retry if it is invalid key exception if (ex.getCause() instanceof InvalidKeyException) { diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeGCSClient.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeGCSClient.java index 64dcb73ba..340587025 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeGCSClient.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeGCSClient.java @@ -81,8 +81,7 @@ private SnowflakeGCSClient() {} * required to decrypt/encrypt content in stage */ public static SnowflakeGCSClient createSnowflakeGCSClient( - StageInfo stage, RemoteStoreFileEncryptionMaterial encMat) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + StageInfo stage, RemoteStoreFileEncryptionMaterial encMat) throws SnowflakeSQLException { logger.debug( "Initializing Snowflake GCS client with encryption: {}", encMat != null ? "true" : "false"); SnowflakeGCSClient sfGcsClient = new SnowflakeGCSClient(); @@ -137,8 +136,7 @@ public boolean requirePresignedUrl() { } @Override - public void renew(Map stageCredentials) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + public void renew(Map stageCredentials) throws SnowflakeSQLException { logger.debug("Renewing the Snowflake GCS client"); stageInfo.setCredentials(stageCredentials); setupGCSClient(stageInfo, encMat); @@ -196,7 +194,7 @@ public void download( String stageRegion, String presignedUrl, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { String localFilePath = localLocation + localFileSep + destFileName; logger.debug( "Staring download of file from GCS stage path: {} to {}", stageFilePath, localFilePath); @@ -364,7 +362,7 @@ public InputStream downloadToStream( String stageRegion, String presignedUrl, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { logger.debug("Staring download of file from GCS stage path: {} to input stream", stageFilePath); int retryCount = 0; Stopwatch stopwatch = new Stopwatch(); @@ -531,7 +529,7 @@ public void uploadWithPresignedUrlWithoutConnection( String stageRegion, String presignedUrl, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { logger.info( StorageHelper.getStartUploadLog( "GCS", uploadFromStream, inputStream, fileBackedOutputStream, srcFile, destFileName)); @@ -632,7 +630,7 @@ public void upload( String stageRegion, String presignedUrl, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { logger.info( StorageHelper.getStartUploadLog( "GCS", uploadFromStream, inputStream, fileBackedOutputStream, srcFile, destFileName)); @@ -783,7 +781,7 @@ private void uploadWithDownScopedToken( long contentLength, InputStream content, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { logger.debug("Uploading file {} to bucket {}", destFileName, remoteStorageLocation); try { this.gcsAccessStrategy.uploadWithDownScopedToken( @@ -834,7 +832,7 @@ private void uploadWithPresignedUrl( String presignedUrl, net.snowflake.client.core.HttpClientSettingsKey ocspAndProxyKey, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { try { URIBuilder uriBuilder = new URIBuilder(presignedUrl); @@ -991,7 +989,7 @@ private SFPair createUploadStream( @Override public void handleStorageException( Exception ex, int retryCount, String operation, String command, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { // no need to retry if it is invalid key exception if (ex.getCause() instanceof InvalidKeyException) { // Most likely cause is that the unlimited strength policy files are not installed @@ -1126,9 +1124,7 @@ public String getDigestMetadata(StorageObjectMetadata meta) { * @throws IllegalArgumentException when invalid credentials are used */ private void setupGCSClient(StageInfo stage, RemoteStoreFileEncryptionMaterial encMat) - throws IllegalArgumentException, - SnowflakeSQLException, - net.snowflake.client.jdbc.SnowflakeSQLException { + throws IllegalArgumentException, SnowflakeSQLException { // Save the client creation parameters so that we can reuse them, // to reset the GCS client. this.stageInfo = stage; diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeS3Client.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeS3Client.java index 4bede51dd..dec49b0fd 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeS3Client.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeS3Client.java @@ -110,7 +110,7 @@ public SnowflakeS3Client( String stageEndPoint, boolean isClientSideEncrypted, boolean useS3RegionalUrl) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { logger.debug( "Initializing Snowflake S3 client with encryption: {}, client side encrypted: {}", encMat != null, @@ -134,7 +134,7 @@ private void setupSnowflakeS3Client( String stageRegion, String stageEndPoint, boolean isClientSideEncrypted) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { // Save the client creation parameters so that we can reuse them, // to reset the AWS client. We won't save the awsCredentials since // we will be refreshing that, every time we reset the AWS client @@ -263,8 +263,7 @@ public int getEncryptionKeySize() { * @throws SnowflakeSQLException if any error occurs */ @Override - public void renew(Map stageCredentials) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + public void renew(Map stageCredentials) throws SnowflakeSQLException { logger.debug("Renewing the Snowflake S3 client"); // We renew the client with fresh credentials and with its original parameters setupSnowflakeS3Client( @@ -324,7 +323,7 @@ public void download( String stageRegion, String presignedUrl, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { Stopwatch stopwatch = new Stopwatch(); stopwatch.start(); String localFilePath = localLocation + localFileSep + destFileName; @@ -445,7 +444,7 @@ public InputStream downloadToStream( String stageRegion, String presignedUrl, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { logger.debug("Staring download of file from S3 stage path: {} to input stream", stageFilePath); Stopwatch stopwatch = new Stopwatch(); stopwatch.start(); @@ -542,7 +541,7 @@ public void upload( String stageRegion, String presignedUrl, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { logger.info( StorageHelper.getStartUploadLog( "S3", uploadFromStream, inputStream, fileBackedOutputStream, srcFile, destFileName)); @@ -763,7 +762,7 @@ private SFPair createUploadStream( @Override public void handleStorageException( Exception ex, int retryCount, String operation, String command, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { handleS3Exception(ex, retryCount, operation, command, this, queryId); } @@ -774,7 +773,7 @@ private static void handleS3Exception( String command, SnowflakeS3Client s3Client, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { // no need to retry if it is invalid key exception if (ex.getCause() instanceof InvalidKeyException) { // Most likely cause is that the unlimited strength policy files are not installed diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeStorageClient.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeStorageClient.java index e50355f00..45da628fe 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeStorageClient.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeStorageClient.java @@ -58,8 +58,7 @@ default boolean requirePresignedUrl() { * @param stageCredentials a Map (as returned by GS) which contains the new credential properties * @throws SnowflakeSQLException failure to renew the storage client */ - void renew(Map stageCredentials) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException; + void renew(Map stageCredentials) throws SnowflakeSQLException; /** shuts down the client */ void shutdown(); @@ -103,7 +102,7 @@ default void download( String stageFilePath, String stageRegion, String presignedUrl) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { download( command, localLocation, @@ -140,7 +139,7 @@ void download( String stageRegion, String presignedUrl, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException; + throws SnowflakeSQLException; /** * @deprecated @@ -153,7 +152,7 @@ default InputStream downloadToStream( String stageFilePath, String stageRegion, String presignedUrl) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { return downloadToStream( command, parallelism, @@ -185,7 +184,7 @@ InputStream downloadToStream( String stageRegion, String presignedUrl, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException; + throws SnowflakeSQLException; /** * @deprecated @@ -203,7 +202,7 @@ default void upload( StorageObjectMetadata meta, String stageRegion, String presignedUrl) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { upload( command, parallelism, @@ -249,7 +248,7 @@ void upload( String stageRegion, String presignedUrl, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException; + throws SnowflakeSQLException; /** * @deprecated @@ -268,7 +267,7 @@ default void uploadWithPresignedUrlWithoutConnection( StorageObjectMetadata meta, String stageRegion, String presignedUrl) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { uploadWithPresignedUrlWithoutConnection( networkTimeoutInMilli, ocspModeAndProxyKey, @@ -304,7 +303,7 @@ default void uploadWithPresignedUrlWithoutConnection( String stageRegion, String presignedUrl, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { if (!requirePresignedUrl()) { throw new SnowflakeSQLLoggedException( queryId, @@ -322,8 +321,7 @@ default void uploadWithPresignedUrlWithoutConnection( */ @Deprecated default void handleStorageException( - Exception ex, int retryCount, String operation, String command) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + Exception ex, int retryCount, String operation, String command) throws SnowflakeSQLException { handleStorageException(ex, retryCount, operation, command, null); } @@ -340,7 +338,7 @@ default void handleStorageException( */ void handleStorageException( Exception ex, int retryCount, String operation, String command, String queryId) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException; + throws SnowflakeSQLException; /** * Returns the material descriptor key diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/StorageClientFactory.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/StorageClientFactory.java index e1c540297..728133c0f 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/StorageClientFactory.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/StorageClientFactory.java @@ -52,7 +52,7 @@ public static StorageClientFactory getFactory() { */ public SnowflakeStorageClient createClient( StageInfo stage, int parallel, RemoteStoreFileEncryptionMaterial encMat) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { logger.debug("Creating storage client. Client type: {}", stage.getStageType().name()); switch (stage.getStageType()) { @@ -106,7 +106,7 @@ private SnowflakeS3Client createS3Client( String stageEndPoint, boolean isClientSideEncrypted, boolean useS3RegionalUrl) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { final int S3_TRANSFER_MAX_RETRIES = 3; logger.debug("Creating S3 client with encryption: {}", (encMat == null ? "no" : "yes")); @@ -188,8 +188,7 @@ public StorageObjectMetadata createStorageMetadataObj(StageInfo.StageType stageT * @return the SnowflakeS3Client instance created */ private SnowflakeAzureClient createAzureClient( - StageInfo stage, RemoteStoreFileEncryptionMaterial encMat) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + StageInfo stage, RemoteStoreFileEncryptionMaterial encMat) throws SnowflakeSQLException { logger.debug("Creating Azure client with encryption: {}", (encMat == null ? "no" : "yes")); SnowflakeAzureClient azureClient; @@ -213,8 +212,7 @@ private SnowflakeAzureClient createAzureClient( * @return the SnowflakeGCSClient instance created */ private SnowflakeGCSClient createGCSClient( - StageInfo stage, RemoteStoreFileEncryptionMaterial encMat) - throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException { + StageInfo stage, RemoteStoreFileEncryptionMaterial encMat) throws SnowflakeSQLException { logger.debug("Creating GCS client with encryption: {}", (encMat == null ? "no" : "yes")); SnowflakeGCSClient gcsClient; diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/StorageClientUtil.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/StorageClientUtil.java index 5ef4c408e..0d93fcd90 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/StorageClientUtil.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/StorageClientUtil.java @@ -11,8 +11,11 @@ import static java.util.Arrays.stream; +import com.microsoft.azure.storage.OperationContext; import java.io.File; import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.Proxy; import java.nio.file.Paths; import java.time.Instant; import java.util.Map; @@ -116,7 +119,7 @@ static boolean isWindows() { * SnowflakeSQLException here temporarily until Step 5 replaces it. */ static HttpClientSettingsKey convertProxyPropertiesToHttpClientKey(OCSPMode mode, Properties info) - throws net.snowflake.client.jdbc.SnowflakeSQLException { + throws SnowflakeSQLException { if (info != null && info.size() > 0 && info.getProperty(SFSessionProperty.USE_PROXY.getPropertyKey()) != null) { @@ -129,9 +132,8 @@ static HttpClientSettingsKey convertProxyPropertiesToHttpClientKey(OCSPMode mode proxyPort = Integer.parseInt(info.getProperty(SFSessionProperty.PROXY_PORT.getPropertyKey())); } catch (NumberFormatException | NullPointerException e) { - throw new net.snowflake.client.jdbc.SnowflakeSQLException( - net.snowflake.client.jdbc.ErrorCode.INVALID_PROXY_PROPERTIES, - "Could not parse port number"); + throw new SnowflakeSQLException( + ErrorCode.INVALID_PROXY_PROPERTIES, "Could not parse port number"); } String proxyUser = info.getProperty(SFSessionProperty.PROXY_USER.getPropertyKey()); String proxyPassword = info.getProperty(SFSessionProperty.PROXY_PASSWORD.getPropertyKey()); @@ -304,4 +306,39 @@ static long getEpochTimeInMicroSeconds() { + TimeUnit.NANOSECONDS.toMicros(timestamp.getNano()); return micros; } + + /** + * Replicated from HttpUtil.setSessionlessProxyForAzure. Source: + * https://github.com/snowflakedb/snowflake-jdbc/blob/v3.25.1/src/main/java/net/snowflake/client/core/HttpUtil.java + */ + static void setSessionlessProxyForAzure(Properties proxyProperties, OperationContext opContext) + throws SnowflakeSQLException { + if (proxyProperties != null + && proxyProperties.size() > 0 + && proxyProperties.getProperty(SFSessionProperty.USE_PROXY.getPropertyKey()) != null) { + Boolean useProxy = + Boolean.valueOf( + proxyProperties.getProperty(SFSessionProperty.USE_PROXY.getPropertyKey())); + if (useProxy) { + String proxyHost = + proxyProperties.getProperty(SFSessionProperty.PROXY_HOST.getPropertyKey()); + int proxyPort; + try { + proxyPort = + Integer.parseInt( + proxyProperties.getProperty(SFSessionProperty.PROXY_PORT.getPropertyKey())); + } catch (NumberFormatException | NullPointerException e) { + throw new SnowflakeSQLException( + ErrorCode.INVALID_PROXY_PROPERTIES, "Could not parse port number"); + } + Proxy azProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)); + logger.debug("Setting sessionless Azure proxy. Host: {}, port: {}", proxyHost, proxyPort); + opContext.setProxy(azProxy); + } else { + logger.debug("Omitting sessionless Azure proxy setup as proxy is disabled"); + } + } else { + logger.debug("Omitting sessionless Azure proxy setup"); + } + } }