Skip to content

Commit 153dca4

Browse files
sfc-gh-ggengclaude
andcommitted
[SNOW-3249917] JDBC removal Step 11a (part 2): Replicate HttpUtil, swap callers, clean up FQN refs
Replicate JDBC's HttpUtil as JdbcHttpUtil (renamed to avoid collision with ingest's utils.HttpUtil). Swap all callers to use replicated REST infrastructure. Clean up all FQN JDBC references. New files: - JdbcHttpUtil.java — verbatim replication of JDBC's HttpUtil - SnowflakeMutableProxyRoutePlanner.java — proxy routing for HttpUtil - AttributeEnhancingHttpRequestRetryHandler.java — headers customizer - AwsSdkGCPSigner.java — GCS virtual-style access signer Changes: - RestRequest: swap HttpUtil FQN → JdbcHttpUtil - TelemetryClient: swap HttpUtil → JdbcHttpUtil - SnowflakeGCSClient: swap HttpUtil/RestRequest → JdbcHttpUtil/RestRequest - SnowflakeAzureClient: swap setSessionlessProxyForAzure → JdbcHttpUtil - StorageClientUtil: fix convertProxy exception type, fix throwNoSpaceLeft - Remove all FQN SnowflakeSQLException from throws (~47 occurrences) - Remove all FQN HttpClientSettingsKey/HttpProtocol/OCSPMode - Swap AwsSdkGCPSigner to ingest version Result: ZERO net.snowflake.client references in production code (only comments documenting source URLs remain). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 13967ca commit 153dca4

13 files changed

+123
-88
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Replicated from snowflake-jdbc (v3.25.1)
3+
* Source: https://github.com/snowflakedb/snowflake-jdbc/blob/v3.25.1/src/main/java/net/snowflake/client/jdbc/cloud/storage/AwsSdkGCPSigner.java
4+
*
5+
* Permitted differences: package. @SnowflakeJdbcInternalApi removed.
6+
*/
7+
package net.snowflake.ingest.streaming.internal.fileTransferAgent;
8+
9+
import com.amazonaws.SignableRequest;
10+
import com.amazonaws.auth.AWS4Signer;
11+
import com.amazonaws.auth.AWSCredentials;
12+
import com.amazonaws.http.HttpMethodName;
13+
import java.util.HashMap;
14+
import java.util.Map;
15+
import java.util.stream.Collectors;
16+
17+
public class AwsSdkGCPSigner extends AWS4Signer {
18+
private static final Map<String, String> headerMap =
19+
new HashMap<String, String>() {
20+
{
21+
put("x-amz-storage-class", "x-goog-storage-class");
22+
put("x-amz-acl", "x-goog-acl");
23+
put("x-amz-date", "x-goog-date");
24+
put("x-amz-copy-source", "x-goog-copy-source");
25+
put("x-amz-metadata-directive", "x-goog-metadata-directive");
26+
put("x-amz-copy-source-if-match", "x-goog-copy-source-if-match");
27+
put("x-amz-copy-source-if-none-match", "x-goog-copy-source-if-none-match");
28+
put("x-amz-copy-source-if-unmodified-since", "x-goog-copy-source-if-unmodified-since");
29+
put("x-amz-copy-source-if-modified-since", "x-goog-copy-source-if-modified-since");
30+
}
31+
};
32+
33+
@Override
34+
public void sign(SignableRequest<?> request, AWSCredentials credentials) {
35+
if (credentials.getAWSAccessKeyId() != null && !"".equals(credentials.getAWSAccessKeyId())) {
36+
request.addHeader("Authorization", "Bearer " + credentials.getAWSAccessKeyId());
37+
}
38+
39+
if (request.getHttpMethod() == HttpMethodName.GET) {
40+
request.addHeader("Accept-Encoding", "gzip,deflate");
41+
}
42+
43+
Map<String, String> headerCopy =
44+
request.getHeaders().entrySet().stream()
45+
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
46+
47+
for (Map.Entry<String, String> entry : headerCopy.entrySet()) {
48+
String entryKey = entry.getKey().toLowerCase();
49+
if (headerMap.containsKey(entryKey)) {
50+
request.addHeader(headerMap.get(entryKey), entry.getValue());
51+
} else if (entryKey.startsWith("x-amz-meta-")) {
52+
request.addHeader(entryKey.replace("x-amz-meta-", "x-goog-meta-"), entry.getValue());
53+
}
54+
}
55+
}
56+
}

src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSAccessStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ boolean handleStorageException(
4242
String command,
4343
String queryId,
4444
SnowflakeGCSClient gcsClient)
45-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException;
45+
throws SnowflakeSQLException;
4646

4747
void shutdown();
4848
}

src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSAccessStrategyAwsSdk.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ class GCSAccessStrategyAwsSdk implements GCSAccessStrategy {
3939
private static final SFLogger logger = SFLoggerFactory.getLogger(GCSAccessStrategyAwsSdk.class);
4040
private final AmazonS3 amazonClient;
4141

42-
GCSAccessStrategyAwsSdk(StageInfo stage)
43-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
42+
GCSAccessStrategyAwsSdk(StageInfo stage) throws SnowflakeSQLException {
4443
String accessToken = (String) stage.getCredentials().get("GCS_ACCESS_TOKEN");
4544

4645
Optional<String> oEndpoint = stage.gcsCustomEndpoint();
@@ -64,9 +63,10 @@ class GCSAccessStrategyAwsSdk implements GCSAccessStrategy {
6463
ClientConfiguration clientConfig = new ClientConfiguration();
6564

6665
SignerFactory.registerSigner(
67-
"net.snowflake.client.jdbc.cloud.storage.AwsSdkGCPSigner",
68-
net.snowflake.client.jdbc.cloud.storage.AwsSdkGCPSigner.class);
69-
clientConfig.setSignerOverride("net.snowflake.client.jdbc.cloud.storage.AwsSdkGCPSigner");
66+
"net.snowflake.ingest.streaming.internal.fileTransferAgent.AwsSdkGCPSigner",
67+
net.snowflake.ingest.streaming.internal.fileTransferAgent.AwsSdkGCPSigner.class);
68+
clientConfig.setSignerOverride(
69+
"net.snowflake.ingest.streaming.internal.fileTransferAgent.AwsSdkGCPSigner");
7070

7171
clientConfig
7272
.getApacheHttpClientConfig()
@@ -223,7 +223,7 @@ public boolean handleStorageException(
223223
String command,
224224
String queryId,
225225
SnowflakeGCSClient gcsClient)
226-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
226+
throws SnowflakeSQLException {
227227
if (ex instanceof AmazonClientException) {
228228
logger.debug("GCSAccessStrategyAwsSdk: " + ex.getMessage());
229229

src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSDefaultAccessStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public boolean handleStorageException(
178178
String command,
179179
String queryId,
180180
SnowflakeGCSClient gcsClient)
181-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
181+
throws SnowflakeSQLException {
182182
if (ex instanceof StorageException) {
183183
// NOTE: this code path only handle Access token based operation,
184184
// presigned URL is not covered. Presigned Url do not raise

src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/HttpClientSettingsKey.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Replicated from snowflake-jdbc: net.snowflake.client.core.HttpClientSettingsKey
2+
* Replicated from snowflake-jdbc: HttpClientSettingsKey
33
* Tag: v3.25.1
44
* Source: https://github.com/snowflakedb/snowflake-jdbc/blob/v3.25.1/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java
55
*

src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/S3HttpUtil.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,10 @@ public class S3HttpUtil {
3232
*/
3333
// Parameter uses JDBC's HttpClientSettingsKey because session.getHttpClientKey() returns it.
3434
// This path is only used when session != null (never from streaming ingest).
35-
public static void setProxyForS3(
36-
net.snowflake.client.core.HttpClientSettingsKey key, ClientConfiguration clientConfig) {
35+
public static void setProxyForS3(HttpClientSettingsKey key, ClientConfiguration clientConfig) {
3736
if (key != null && key.usesProxy()) {
3837
clientConfig.setProxyProtocol(
39-
key.getProxyHttpProtocol() == net.snowflake.client.core.HttpProtocol.HTTPS
40-
? Protocol.HTTPS
41-
: Protocol.HTTP);
38+
key.getProxyHttpProtocol() == HttpProtocol.HTTPS ? Protocol.HTTPS : Protocol.HTTP);
4239
clientConfig.setProxyHost(key.getProxyHost());
4340
clientConfig.setProxyPort(key.getProxyPort());
4441
clientConfig.setNonProxyHosts(key.getNonProxyHosts());

src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeAzureClient.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ private SnowflakeAzureClient() {}
8080
* required to decrypt/encrypt content in stage
8181
*/
8282
public static SnowflakeAzureClient createSnowflakeAzureClient(
83-
StageInfo stage, RemoteStoreFileEncryptionMaterial encMat)
84-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
83+
StageInfo stage, RemoteStoreFileEncryptionMaterial encMat) throws SnowflakeSQLException {
8584
logger.debug(
8685
"Initializing Snowflake Azure client with encryption: {}",
8786
encMat != null ? "true" : "false");
@@ -102,9 +101,7 @@ public static SnowflakeAzureClient createSnowflakeAzureClient(
102101
* @throws IllegalArgumentException when invalid credentials are used
103102
*/
104103
private void setupAzureClient(StageInfo stage, RemoteStoreFileEncryptionMaterial encMat)
105-
throws IllegalArgumentException,
106-
SnowflakeSQLException,
107-
net.snowflake.client.jdbc.SnowflakeSQLException {
104+
throws IllegalArgumentException, SnowflakeSQLException, SnowflakeSQLException {
108105
// Save the client creation parameters so that we can reuse them,
109106
// to reset the Azure client.
110107
this.stageInfo = stage;
@@ -189,8 +186,7 @@ public int getEncryptionKeySize() {
189186
* @throws SnowflakeSQLException failure to renew the client
190187
*/
191188
@Override
192-
public void renew(Map<?, ?> stageCredentials)
193-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
189+
public void renew(Map<?, ?> stageCredentials) throws SnowflakeSQLException {
194190
logger.debug("Renewing the Azure client");
195191
stageInfo.setCredentials(stageCredentials);
196192
setupAzureClient(stageInfo, encMat);
@@ -302,7 +298,7 @@ public void download(
302298
String stageRegion,
303299
String presignedUrl,
304300
String queryId)
305-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
301+
throws SnowflakeSQLException {
306302
Stopwatch stopwatch = new Stopwatch();
307303
stopwatch.start();
308304
String localFilePath = localLocation + localFileSep + destFileName;
@@ -416,7 +412,7 @@ public InputStream downloadToStream(
416412
String stageRegion,
417413
String presignedUrl,
418414
String queryId)
419-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
415+
throws SnowflakeSQLException {
420416
logger.debug(
421417
"Staring download of file from Azure stage path: {} to input stream", stageFilePath);
422418
Stopwatch stopwatch = new Stopwatch();
@@ -528,7 +524,7 @@ public void upload(
528524
String stageRegion,
529525
String presignedUrl,
530526
String queryId)
531-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
527+
throws SnowflakeSQLException {
532528
logger.info(
533529
StorageHelper.getStartUploadLog(
534530
"Azure", uploadFromStream, inputStream, fileBackedOutputStream, srcFile, destFileName));
@@ -649,7 +645,7 @@ public void upload(
649645
@Override
650646
public void handleStorageException(
651647
Exception ex, int retryCount, String operation, String command, String queryId)
652-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
648+
throws SnowflakeSQLException {
653649
handleAzureException(ex, retryCount, operation, command, this, queryId);
654650
}
655651

@@ -755,7 +751,7 @@ private static void handleAzureException(
755751
String command,
756752
SnowflakeAzureClient azClient,
757753
String queryId)
758-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
754+
throws SnowflakeSQLException {
759755

760756
// no need to retry if it is invalid key exception
761757
if (ex.getCause() instanceof InvalidKeyException) {

src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeFileTransferAgent.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,9 @@ public static void uploadWithoutConnection(SnowflakeFileTransferConfig config) t
638638
String streamingIngestClientKey = config.getStreamingIngestClientKey();
639639

640640
// Create HttpClient key
641-
net.snowflake.client.core.HttpClientSettingsKey key =
642-
net.snowflake.client.jdbc.SnowflakeUtil.convertProxyPropertiesToHttpClientKey(
643-
net.snowflake.client.core.OCSPMode.FAIL_OPEN, proxyProperties);
641+
HttpClientSettingsKey key =
642+
StorageClientUtil.convertProxyPropertiesToHttpClientKey(
643+
net.snowflake.ingest.utils.OCSPMode.FAIL_OPEN, proxyProperties);
644644

645645
StageInfo stageInfo = metadata.getStageInfo();
646646
stageInfo.setProxyProperties(proxyProperties);
@@ -860,7 +860,7 @@ private static void pushFileToRemoteStoreWithPresignedUrl(
860860
FileCompressionType compressionType,
861861
SnowflakeStorageClient initialClient,
862862
int networkTimeoutInMilli,
863-
net.snowflake.client.core.HttpClientSettingsKey ocspModeAndProxyKey,
863+
HttpClientSettingsKey ocspModeAndProxyKey,
864864
int parallel,
865865
File srcFile,
866866
boolean uploadFromStream,

src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeGCSClient.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ private SnowflakeGCSClient() {}
8181
* required to decrypt/encrypt content in stage
8282
*/
8383
public static SnowflakeGCSClient createSnowflakeGCSClient(
84-
StageInfo stage, RemoteStoreFileEncryptionMaterial encMat)
85-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
84+
StageInfo stage, RemoteStoreFileEncryptionMaterial encMat) throws SnowflakeSQLException {
8685
logger.debug(
8786
"Initializing Snowflake GCS client with encryption: {}", encMat != null ? "true" : "false");
8887
SnowflakeGCSClient sfGcsClient = new SnowflakeGCSClient();
@@ -137,8 +136,7 @@ public boolean requirePresignedUrl() {
137136
}
138137

139138
@Override
140-
public void renew(Map<?, ?> stageCredentials)
141-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
139+
public void renew(Map<?, ?> stageCredentials) throws SnowflakeSQLException {
142140
logger.debug("Renewing the Snowflake GCS client");
143141
stageInfo.setCredentials(stageCredentials);
144142
setupGCSClient(stageInfo, encMat);
@@ -196,7 +194,7 @@ public void download(
196194
String stageRegion,
197195
String presignedUrl,
198196
String queryId)
199-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
197+
throws SnowflakeSQLException {
200198
String localFilePath = localLocation + localFileSep + destFileName;
201199
logger.debug(
202200
"Staring download of file from GCS stage path: {} to {}", stageFilePath, localFilePath);
@@ -379,7 +377,7 @@ public InputStream downloadToStream(
379377
String stageRegion,
380378
String presignedUrl,
381379
String queryId)
382-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
380+
throws SnowflakeSQLException {
383381
logger.debug("Staring download of file from GCS stage path: {} to input stream", stageFilePath);
384382
int retryCount = 0;
385383
Stopwatch stopwatch = new Stopwatch();
@@ -549,7 +547,7 @@ public InputStream downloadToStream(
549547
@Override
550548
public void uploadWithPresignedUrlWithoutConnection(
551549
int networkTimeoutInMilli,
552-
net.snowflake.client.core.HttpClientSettingsKey ocspModeAndProxyKey,
550+
HttpClientSettingsKey ocspModeAndProxyKey,
553551
int parallelism,
554552
boolean uploadFromStream,
555553
String remoteStorageLocation,
@@ -561,7 +559,7 @@ public void uploadWithPresignedUrlWithoutConnection(
561559
String stageRegion,
562560
String presignedUrl,
563561
String queryId)
564-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
562+
throws SnowflakeSQLException {
565563
logger.info(
566564
StorageHelper.getStartUploadLog(
567565
"GCS", uploadFromStream, inputStream, fileBackedOutputStream, srcFile, destFileName));
@@ -662,7 +660,7 @@ public void upload(
662660
String stageRegion,
663661
String presignedUrl,
664662
String queryId)
665-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
663+
throws SnowflakeSQLException {
666664
logger.info(
667665
StorageHelper.getStartUploadLog(
668666
"GCS", uploadFromStream, inputStream, fileBackedOutputStream, srcFile, destFileName));
@@ -813,7 +811,7 @@ private void uploadWithDownScopedToken(
813811
long contentLength,
814812
InputStream content,
815813
String queryId)
816-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
814+
throws SnowflakeSQLException {
817815
logger.debug("Uploading file {} to bucket {}", destFileName, remoteStorageLocation);
818816
try {
819817
this.gcsAccessStrategy.uploadWithDownScopedToken(
@@ -862,9 +860,9 @@ private void uploadWithPresignedUrl(
862860
Map<String, String> metadata,
863861
InputStream content,
864862
String presignedUrl,
865-
net.snowflake.client.core.HttpClientSettingsKey ocspAndProxyKey,
863+
HttpClientSettingsKey ocspAndProxyKey,
866864
String queryId)
867-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
865+
throws SnowflakeSQLException {
868866
try {
869867
URIBuilder uriBuilder = new URIBuilder(presignedUrl);
870868

@@ -1037,7 +1035,7 @@ private SFPair<InputStream, Boolean> createUploadStream(
10371035
@Override
10381036
public void handleStorageException(
10391037
Exception ex, int retryCount, String operation, String command, String queryId)
1040-
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
1038+
throws SnowflakeSQLException {
10411039
// no need to retry if it is invalid key exception
10421040
if (ex.getCause() instanceof InvalidKeyException) {
10431041
// Most likely cause is that the unlimited strength policy files are not installed
@@ -1172,9 +1170,7 @@ public String getDigestMetadata(StorageObjectMetadata meta) {
11721170
* @throws IllegalArgumentException when invalid credentials are used
11731171
*/
11741172
private void setupGCSClient(StageInfo stage, RemoteStoreFileEncryptionMaterial encMat)
1175-
throws IllegalArgumentException,
1176-
SnowflakeSQLException,
1177-
net.snowflake.client.jdbc.SnowflakeSQLException {
1173+
throws IllegalArgumentException, SnowflakeSQLException, SnowflakeSQLException {
11781174
// Save the client creation parameters so that we can reuse them,
11791175
// to reset the GCS client.
11801176
this.stageInfo = stage;
@@ -1244,8 +1240,7 @@ public String getStreamingIngestClientKey(StorageObjectMetadata meta) {
12441240
* use JDBC's HttpClientSettingsKey type. Will be removed once the full storage stack import swap
12451241
* is complete.
12461242
*/
1247-
private static HttpClientSettingsKey toIngestKey(
1248-
net.snowflake.client.core.HttpClientSettingsKey jdbcKey) {
1243+
private static HttpClientSettingsKey toIngestKey(HttpClientSettingsKey jdbcKey) {
12491244
if (jdbcKey == null) {
12501245
return null;
12511246
}

0 commit comments

Comments
 (0)