clairemcginty commented on code in PR #33368:
URL: https://github.com/apache/beam/pull/33368#discussion_r1915192473
##########
sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/GcsUtil.java:
##########
@@ -739,7 +741,47 @@ public WritableByteChannel create(GcsPath path,
CreateOptions options) throws IO
GoogleCloudStorage createGoogleCloudStorage(
GoogleCloudStorageOptions options, Storage storage, Credentials
credentials) {
- return new GoogleCloudStorageImpl(options, storage, credentials);
+ try {
+ return new GoogleCloudStorageImpl(options, storage, credentials);
+ } catch (NoSuchMethodError e) {
+ // gcs-connector 3.x drops the direct constructor and exclusively uses
Builder
+ // TODO eliminate reflection once Beam drops Java 8 support and upgrades
to gcsio 3.x
+ try {
+ final Method builderMethod =
GoogleCloudStorageImpl.class.getMethod("builder");
+ Object builder = builderMethod.invoke(null);
+ final Class<?> builderClass =
+ Class.forName(
+
"com.google.cloud.hadoop.gcsio.AutoBuilder_GoogleCloudStorageImpl_Builder");
+
+ final Method setOptionsMethod =
+ builderClass.getMethod("setOptions",
GoogleCloudStorageOptions.class);
+ setOptionsMethod.setAccessible(true);
+ builder = setOptionsMethod.invoke(builder, options);
+
+ final Method setHttpTransportMethod =
+ builderClass.getMethod("setHttpTransport", HttpTransport.class);
+ setHttpTransportMethod.setAccessible(true);
+ builder =
+ setHttpTransportMethod.invoke(builder,
storage.getRequestFactory().getTransport());
+
+ final Method setCredentialsMethod =
+ builderClass.getMethod("setCredentials", Credentials.class);
+ setCredentialsMethod.setAccessible(true);
+ builder = setCredentialsMethod.invoke(builder, credentials);
+
+ final Method setHttpRequestInitializerMethod =
+ builderClass.getMethod("setHttpRequestInitializer",
HttpRequestInitializer.class);
+ setHttpRequestInitializerMethod.setAccessible(true);
+ builder = setHttpRequestInitializerMethod.invoke(builder,
httpRequestInitializer);
+
+ final Method buildMethod = builderClass.getMethod("build");
+ buildMethod.setAccessible(true);
+ return (GoogleCloudStorage) buildMethod.invoke(builder);
+ } catch (Exception reflectionError) {
+ throw new RuntimeException(
+ "Failed to construct GoogleCloudStorageImpl from gcsio 3.x
Builder", e);
Review Comment:
Thanks for spotting that! Fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]