Skip to content

Commit adbb11d

Browse files
authored
Fix gcs endpoint pipeline option wiring (#39435)
1 parent f1d9c3e commit adbb11d

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

  • sdks/java/extensions/google-cloud-platform-core/src

sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/GcsUtilV1.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,18 @@ public boolean shouldRetry(IOException e) {
261261
this.credentials = credentials;
262262
this.maxBytesRewrittenPerCall = null;
263263
this.numRewriteTokensUsed = null;
264-
googleCloudStorageOptions =
264+
GoogleCloudStorageOptions.Builder optionsBuilder =
265265
GoogleCloudStorageOptions.builder()
266266
.setAppName("Beam")
267267
.setReadChannelOptions(gcsReadOptions)
268-
.setGrpcEnabled(shouldUseGrpc)
269-
.build();
268+
.setGrpcEnabled(shouldUseGrpc);
269+
if (storageClient.getRootUrl() != null) {
270+
optionsBuilder.setStorageRootUrl(storageClient.getRootUrl());
271+
}
272+
if (storageClient.getServicePath() != null) {
273+
optionsBuilder.setStorageServicePath(storageClient.getServicePath());
274+
}
275+
googleCloudStorageOptions = optionsBuilder.build();
270276
try {
271277
googleCloudStorage =
272278
createGoogleCloudStorage(googleCloudStorageOptions, storageClient, credentials);
@@ -495,6 +501,11 @@ private Long toFileSize(StorageObjectOrIOException storageObjectOrIOException)
495501
}
496502
}
497503

504+
@VisibleForTesting
505+
GoogleCloudStorage getGoogleCloudStorage() {
506+
return googleCloudStorage;
507+
}
508+
498509
@VisibleForTesting
499510
void setCloudStorageImpl(GoogleCloudStorage g) {
500511
googleCloudStorage = g;

sdks/java/extensions/google-cloud-platform-core/src/test/java/org/apache/beam/sdk/extensions/gcp/util/GcsUtilTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import com.google.auth.Credentials;
6464
import com.google.cloud.hadoop.gcsio.CreateObjectOptions;
6565
import com.google.cloud.hadoop.gcsio.GoogleCloudStorage;
66+
import com.google.cloud.hadoop.gcsio.GoogleCloudStorageImpl;
6667
import com.google.cloud.hadoop.gcsio.GoogleCloudStorageOptions;
6768
import com.google.cloud.hadoop.gcsio.GoogleCloudStorageReadOptions;
6869
import com.google.cloud.hadoop.gcsio.StorageResourceId;
@@ -1866,6 +1867,18 @@ public void testReadMetricsAreNotCollectedWhenNotEnabledOpenWithOptions() throws
18661867
testReadMetrics(false, GoogleCloudStorageReadOptions.DEFAULT);
18671868
}
18681869

1870+
@Test
1871+
public void testGcsEndpoint() throws IOException {
1872+
GcsOptions pipelineOptions = PipelineOptionsFactory.as(GcsOptions.class);
1873+
pipelineOptions.setGcsEndpoint("http://localhost:4443/storage/v1/");
1874+
1875+
GcsUtil gcsUtil = pipelineOptions.getGcsUtil();
1876+
GoogleCloudStorageImpl gcsImpl =
1877+
(GoogleCloudStorageImpl) gcsUtil.delegate.getGoogleCloudStorage();
1878+
assertEquals("http://localhost:4443/", gcsImpl.getOptions().getStorageRootUrl());
1879+
assertEquals("storage/v1/", gcsImpl.getOptions().getStorageServicePath());
1880+
}
1881+
18691882
/** A helper to wrap a {@link GenericJson} object in a content stream. */
18701883
private static InputStream toStream(String content) throws IOException {
18711884
return new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));

0 commit comments

Comments
 (0)