From be64a842fcc573165aeb77c1f0bb1d7118c29199 Mon Sep 17 00:00:00 2001 From: dragonHead1001001 Date: Sun, 11 Aug 2024 15:22:39 +0530 Subject: [PATCH 1/2] [Task]: Replace JacksonFactory references with GsonFactory #32130 --- gradle/wrapper/gradle-wrapper.properties | 5 ++--- .../apache/beam/sdk/extensions/gcp/util/Transport.java | 3 ++- .../beam/sdk/extensions/gcp/util/GcsUtilTest.java | 10 +++++----- .../LatencyRecordingHttpRequestInitializerTest.java | 4 ++-- .../gcp/util/RetryHttpRequestInitializerTest.java | 4 ++-- .../sdk/io/gcp/healthcare/HttpHealthcareApiClient.java | 3 +-- .../sdk/io/gcp/bigquery/BigQueryServicesImplTest.java | 6 +++--- .../beam/sdk/io/gcp/healthcare/FhirIOTestUtil.java | 4 ++-- 8 files changed, 19 insertions(+), 20 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3fa8f862f753..086e52fca019 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,6 @@ +#Sat Aug 10 17:06:24 IST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip -networkTimeout=10000 -validateDistributionUrl=true +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/Transport.java b/sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/Transport.java index ac6d825e125d..180f32c3228f 100644 --- a/sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/Transport.java +++ b/sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/Transport.java @@ -23,6 +23,7 @@ import com.google.api.client.http.HttpRequestInitializer; import com.google.api.client.http.HttpTransport; import com.google.api.client.json.JsonFactory; +import com.google.api.client.json.gson.GsonFactory; import com.google.api.client.json.jackson2.JacksonFactory; import com.google.api.services.storage.Storage; import com.google.auth.Credentials; @@ -53,7 +54,7 @@ private static class SingletonHelper { static { try { - JSON_FACTORY = JacksonFactory.getDefaultInstance(); + JSON_FACTORY = GsonFactory.getDefaultInstance(); HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); } catch (GeneralSecurityException | IOException e) { throw new RuntimeException(e); diff --git a/sdks/java/extensions/google-cloud-platform-core/src/test/java/org/apache/beam/sdk/extensions/gcp/util/GcsUtilTest.java b/sdks/java/extensions/google-cloud-platform-core/src/test/java/org/apache/beam/sdk/extensions/gcp/util/GcsUtilTest.java index 1d35cb0d04d4..bd7f46ec8951 100644 --- a/sdks/java/extensions/google-cloud-platform-core/src/test/java/org/apache/beam/sdk/extensions/gcp/util/GcsUtilTest.java +++ b/sdks/java/extensions/google-cloud-platform-core/src/test/java/org/apache/beam/sdk/extensions/gcp/util/GcsUtilTest.java @@ -49,7 +49,7 @@ import com.google.api.client.json.GenericJson; import com.google.api.client.json.Json; import com.google.api.client.json.JsonFactory; -import com.google.api.client.json.jackson2.JacksonFactory; +import com.google.api.client.json.gson.GsonFactory; import com.google.api.client.testing.http.HttpTesting; import com.google.api.client.testing.http.MockHttpTransport; import com.google.api.client.testing.http.MockLowLevelHttpRequest; @@ -474,7 +474,7 @@ public void testRetryFileSizeNonBatch() throws IOException { @Test public void testGetSizeBytesWhenFileNotFoundBatch() throws Exception { - JsonFactory jsonFactory = new JacksonFactory(); + JsonFactory jsonFactory = new GsonFactory(); String contentBoundary = "batch_foobarbaz"; String contentBoundaryLine = "--" + contentBoundary; @@ -545,7 +545,7 @@ public void testGetSizeBytesWhenFileNotFoundNoBatch() throws Exception { @Test public void testGetSizeBytesWhenFileNotFoundBatchRetry() throws Exception { - JsonFactory jsonFactory = new JacksonFactory(); + JsonFactory jsonFactory = new GsonFactory(); String contentBoundary = "batch_foobarbaz"; String contentBoundaryLine = "--" + contentBoundary; @@ -657,7 +657,7 @@ public LowLevelHttpResponse execute() throws IOException { @Test public void testRemoveWhenFileNotFound() throws Exception { - JsonFactory jsonFactory = new JacksonFactory(); + JsonFactory jsonFactory = new GsonFactory(); String contentBoundary = "batch_foobarbaz"; String contentBoundaryLine = "--" + contentBoundary; @@ -1045,7 +1045,7 @@ private void verifyMetricWasSet( /** Builds a fake GoogleJsonResponseException for testing API error handling. */ private static GoogleJsonResponseException googleJsonResponseException( final int status, final String reason, final String message) throws IOException { - final JsonFactory jsonFactory = new JacksonFactory(); + final JsonFactory jsonFactory = new GsonFactory(); HttpTransport transport = new MockHttpTransport() { @Override diff --git a/sdks/java/extensions/google-cloud-platform-core/src/test/java/org/apache/beam/sdk/extensions/gcp/util/LatencyRecordingHttpRequestInitializerTest.java b/sdks/java/extensions/google-cloud-platform-core/src/test/java/org/apache/beam/sdk/extensions/gcp/util/LatencyRecordingHttpRequestInitializerTest.java index 6e0b45df141d..c2f3d063f4c9 100644 --- a/sdks/java/extensions/google-cloud-platform-core/src/test/java/org/apache/beam/sdk/extensions/gcp/util/LatencyRecordingHttpRequestInitializerTest.java +++ b/sdks/java/extensions/google-cloud-platform-core/src/test/java/org/apache/beam/sdk/extensions/gcp/util/LatencyRecordingHttpRequestInitializerTest.java @@ -34,7 +34,7 @@ import com.google.api.client.http.LowLevelHttpRequest; import com.google.api.client.http.LowLevelHttpResponse; import com.google.api.client.json.JsonFactory; -import com.google.api.client.json.jackson2.JacksonFactory; +import com.google.api.client.json.gson.GsonFactory; import com.google.api.services.storage.Storage; import java.io.IOException; import org.apache.beam.sdk.metrics.Histogram; @@ -61,7 +61,7 @@ public class LatencyRecordingHttpRequestInitializerTest { @Mock private LowLevelHttpResponse mockLowLevelResponse; @Mock private Histogram mockHistogram; - private final JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); + private final JsonFactory jsonFactory = GsonFactory.getDefaultInstance(); private Storage storage; @Before diff --git a/sdks/java/extensions/google-cloud-platform-core/src/test/java/org/apache/beam/sdk/extensions/gcp/util/RetryHttpRequestInitializerTest.java b/sdks/java/extensions/google-cloud-platform-core/src/test/java/org/apache/beam/sdk/extensions/gcp/util/RetryHttpRequestInitializerTest.java index a604b97cd35a..46929d1b6e7a 100644 --- a/sdks/java/extensions/google-cloud-platform-core/src/test/java/org/apache/beam/sdk/extensions/gcp/util/RetryHttpRequestInitializerTest.java +++ b/sdks/java/extensions/google-cloud-platform-core/src/test/java/org/apache/beam/sdk/extensions/gcp/util/RetryHttpRequestInitializerTest.java @@ -39,7 +39,7 @@ import com.google.api.client.http.LowLevelHttpRequest; import com.google.api.client.http.LowLevelHttpResponse; import com.google.api.client.json.JsonFactory; -import com.google.api.client.json.jackson2.JacksonFactory; +import com.google.api.client.json.gson.GsonFactory; import com.google.api.client.testing.http.MockHttpTransport; import com.google.api.client.testing.http.MockLowLevelHttpRequest; import com.google.api.client.testing.http.MockLowLevelHttpResponse; @@ -79,7 +79,7 @@ public class RetryHttpRequestInitializerTest { @Mock private LowLevelHttpResponse mockLowLevelResponse; @Mock private HttpResponseInterceptor mockHttpResponseInterceptor; - private final JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); + private final JsonFactory jsonFactory = GsonFactory.getDefaultInstance(); private Storage storage; // Used to test retrying a request more than the default 10 times. diff --git a/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java index 9a2a16bd949c..7d99043cde73 100644 --- a/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java +++ b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java @@ -24,7 +24,6 @@ import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.client.json.JsonFactory; import com.google.api.client.json.gson.GsonFactory; -import com.google.api.client.json.jackson2.JacksonFactory; import com.google.api.services.healthcare.v1.CloudHealthcare; import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.FhirStores.Fhir.PatientEverything; import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores.Messages; @@ -736,7 +735,7 @@ private void initClient() throws IOException { client = new CloudHealthcare.Builder( - new NetHttpTransport(), new JacksonFactory(), requestInitializer) + new NetHttpTransport(), new GsonFactory(), requestInitializer) .setApplicationName("apache-beam-hl7v2-io") .build(); httpClient = diff --git a/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryServicesImplTest.java b/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryServicesImplTest.java index 5fac8f1a1b4e..4da9d4eb6a70 100644 --- a/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryServicesImplTest.java +++ b/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryServicesImplTest.java @@ -45,7 +45,7 @@ import com.google.api.client.http.LowLevelHttpResponse; import com.google.api.client.json.GenericJson; import com.google.api.client.json.Json; -import com.google.api.client.json.jackson2.JacksonFactory; +import com.google.api.client.json.gson.GsonFactory; import com.google.api.client.testing.http.MockHttpTransport; import com.google.api.client.testing.http.MockLowLevelHttpRequest; import com.google.api.client.testing.util.MockSleeper; @@ -1597,12 +1597,12 @@ public void testSkipInvalidRowsIgnoreUnknownIgnoreInsertIdsValuesStreaming() /** A helper to convert a string response back to a {@link GenericJson} subclass. */ private static T fromString(String content, Class clazz) throws IOException { - return JacksonFactory.getDefaultInstance().fromString(content, clazz); + return GsonFactory.getDefaultInstance().fromString(content, clazz); } /** A helper to wrap a {@link GenericJson} object in a content stream. */ private static InputStream toStream(GenericJson content) throws IOException { - return new ByteArrayInputStream(JacksonFactory.getDefaultInstance().toByteArray(content)); + return new ByteArrayInputStream(GsonFactory.getDefaultInstance().toByteArray(content)); } /** A helper that generates the error JSON payload that Google APIs produce. */ diff --git a/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/healthcare/FhirIOTestUtil.java b/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/healthcare/FhirIOTestUtil.java index 6bc0fbbbd7c9..90c2a647cd45 100644 --- a/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/healthcare/FhirIOTestUtil.java +++ b/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/healthcare/FhirIOTestUtil.java @@ -20,7 +20,7 @@ import com.google.api.client.http.HttpHeaders; import com.google.api.client.http.HttpRequestInitializer; import com.google.api.client.http.javanet.NetHttpTransport; -import com.google.api.client.json.jackson2.JacksonFactory; +import com.google.api.client.json.gson.GsonFactory; import com.google.api.services.healthcare.v1.model.HttpBody; import com.google.api.services.storage.Storage; import com.google.api.services.storage.model.StorageObject; @@ -136,7 +136,7 @@ public static void tearDownTempBucket() throws IOException { request.setReadTimeout(60000); // 1 minute read timeout }; Storage storage = - new Storage.Builder(new NetHttpTransport(), new JacksonFactory(), requestInitializer) + new Storage.Builder(new NetHttpTransport(), new GsonFactory(), requestInitializer) .build(); List blobs = storage.objects().list(DEFAULT_TEMP_BUCKET).execute().getItems(); if (blobs != null) { From dd3fa04c90df95dd9998264f007f7b84bb18fe34 Mon Sep 17 00:00:00 2001 From: dragonHead1001001 Date: Mon, 12 Aug 2024 00:27:09 +0530 Subject: [PATCH 2/2] Replacing Jackson Factory with Gson Factory in Transport.java --- gradle/wrapper/gradle-wrapper.properties | 4 +++- .../org/apache/beam/sdk/extensions/gcp/util/Transport.java | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 086e52fca019..b9d2b1b60ee8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,8 @@ #Sat Aug 10 17:06:24 IST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/Transport.java b/sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/Transport.java index 180f32c3228f..df9049a8fab2 100644 --- a/sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/Transport.java +++ b/sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/Transport.java @@ -24,7 +24,6 @@ import com.google.api.client.http.HttpTransport; import com.google.api.client.json.JsonFactory; import com.google.api.client.json.gson.GsonFactory; -import com.google.api.client.json.jackson2.JacksonFactory; import com.google.api.services.storage.Storage; import com.google.auth.Credentials; import com.google.auth.http.HttpCredentialsAdapter;