From b7b6bd73af4a5d678126debf0f3dca8eb18b432a Mon Sep 17 00:00:00 2001 From: itsankit-google Date: Thu, 16 Jan 2025 06:52:30 +0000 Subject: [PATCH] remove try-block from GCPUtils#getStorage --- .../gcp/bigquery/sink/AbstractBigQuerySink.java | 10 +--------- .../plugin/gcp/bigquery/source/BigQuerySource.java | 10 +--------- .../io/cdap/plugin/gcp/gcs/sink/GCSBatchSink.java | 12 +----------- .../cdap/plugin/gcp/gcs/sink/GCSMultiBatchSink.java | 12 +----------- .../io/cdap/plugin/gcp/gcs/source/GCSSource.java | 12 +----------- 5 files changed, 5 insertions(+), 51 deletions(-) diff --git a/src/main/java/io/cdap/plugin/gcp/bigquery/sink/AbstractBigQuerySink.java b/src/main/java/io/cdap/plugin/gcp/bigquery/sink/AbstractBigQuerySink.java index 9cc580ed5..8ef8505d0 100644 --- a/src/main/java/io/cdap/plugin/gcp/bigquery/sink/AbstractBigQuerySink.java +++ b/src/main/java/io/cdap/plugin/gcp/bigquery/sink/AbstractBigQuerySink.java @@ -46,7 +46,6 @@ import io.cdap.plugin.gcp.bigquery.util.BigQueryUtil; import io.cdap.plugin.gcp.common.CmekUtils; import io.cdap.plugin.gcp.common.GCPUtils; -import io.cdap.plugin.gcp.gcs.GCSErrorDetailsProvider; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.io.NullWritable; import org.slf4j.Logger; @@ -112,14 +111,7 @@ public final void prepareRun(BatchSinkContext context) throws Exception { } // Get the required bucket name and bucket instance (if it exists) - Storage storage; - try { - storage = GCPUtils.getStorage(project, credentials);; - } catch (Exception e) { - ProgramFailureException ex = new GCSErrorDetailsProvider().getExceptionDetails(e, - new ErrorContext(ErrorPhase.WRITING)); - throw ex == null ? e : ex; - } + Storage storage = GCPUtils.getStorage(project, credentials);; String bucketName = BigQueryUtil.getStagingBucketName(context.getArguments().asMap(), config.getLocation(), dataset, config.getBucket()); bucketName = BigQuerySinkUtils.configureBucket(baseConfiguration, bucketName, runUUID.toString()); diff --git a/src/main/java/io/cdap/plugin/gcp/bigquery/source/BigQuerySource.java b/src/main/java/io/cdap/plugin/gcp/bigquery/source/BigQuerySource.java index a115b642f..7b9521d29 100644 --- a/src/main/java/io/cdap/plugin/gcp/bigquery/source/BigQuerySource.java +++ b/src/main/java/io/cdap/plugin/gcp/bigquery/source/BigQuerySource.java @@ -63,7 +63,6 @@ import io.cdap.plugin.gcp.bigquery.util.BigQueryUtil; import io.cdap.plugin.gcp.common.CmekUtils; import io.cdap.plugin.gcp.common.GCPUtils; -import io.cdap.plugin.gcp.gcs.GCSErrorDetailsProvider; import org.apache.avro.generic.GenericData; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.io.LongWritable; @@ -180,14 +179,7 @@ public void prepareRun(BatchSourceContext context) throws Exception { dataset, config.getBucket()); // Configure GCS Bucket to use - Storage storage; - try { - storage = GCPUtils.getStorage(config.getProject(), credentials);; - } catch (Exception e) { - ProgramFailureException ex = new GCSErrorDetailsProvider().getExceptionDetails(e, - new ErrorContext(ErrorPhase.READING)); - throw ex == null ? e : ex; - } + Storage storage = GCPUtils.getStorage(config.getProject(), credentials);; String bucket = null; try { bucket = BigQuerySourceUtils.getOrCreateBucket(configuration, storage, bucketName, dataset, diff --git a/src/main/java/io/cdap/plugin/gcp/gcs/sink/GCSBatchSink.java b/src/main/java/io/cdap/plugin/gcp/gcs/sink/GCSBatchSink.java index 998f31c1e..96b555e4a 100644 --- a/src/main/java/io/cdap/plugin/gcp/gcs/sink/GCSBatchSink.java +++ b/src/main/java/io/cdap/plugin/gcp/gcs/sink/GCSBatchSink.java @@ -32,7 +32,6 @@ import io.cdap.cdap.api.annotation.Name; import io.cdap.cdap.api.annotation.Plugin; import io.cdap.cdap.api.data.schema.Schema; -import io.cdap.cdap.api.exception.ProgramFailureException; import io.cdap.cdap.api.plugin.PluginConfig; import io.cdap.cdap.etl.api.FailureCollector; import io.cdap.cdap.etl.api.PipelineConfigurer; @@ -40,9 +39,7 @@ import io.cdap.cdap.etl.api.batch.BatchSink; import io.cdap.cdap.etl.api.batch.BatchSinkContext; import io.cdap.cdap.etl.api.connector.Connector; -import io.cdap.cdap.etl.api.exception.ErrorContext; import io.cdap.cdap.etl.api.exception.ErrorDetailsProviderSpec; -import io.cdap.cdap.etl.api.exception.ErrorPhase; import io.cdap.cdap.etl.api.validation.ValidatingOutputFormat; import io.cdap.plugin.common.Asset; import io.cdap.plugin.common.ConfigUtil; @@ -141,14 +138,7 @@ public void prepareRun(BatchSinkContext context) throws Exception { } String bucketName = config.getBucket(collector); - Storage storage; - try { - storage = GCPUtils.getStorage(config.connection.getProject(), credentials); - } catch (Exception e) { - ProgramFailureException ex = new GCSErrorDetailsProvider().getExceptionDetails(e, - new ErrorContext(ErrorPhase.READING)); - throw ex == null ? e : ex; - } + Storage storage = GCPUtils.getStorage(config.connection.getProject(), credentials); Bucket bucket; String location = null; try { diff --git a/src/main/java/io/cdap/plugin/gcp/gcs/sink/GCSMultiBatchSink.java b/src/main/java/io/cdap/plugin/gcp/gcs/sink/GCSMultiBatchSink.java index ee7bfabc3..030f7c24f 100644 --- a/src/main/java/io/cdap/plugin/gcp/gcs/sink/GCSMultiBatchSink.java +++ b/src/main/java/io/cdap/plugin/gcp/gcs/sink/GCSMultiBatchSink.java @@ -32,7 +32,6 @@ import io.cdap.cdap.api.data.format.StructuredRecord; import io.cdap.cdap.api.data.schema.Schema; import io.cdap.cdap.api.dataset.lib.KeyValue; -import io.cdap.cdap.api.exception.ProgramFailureException; import io.cdap.cdap.api.plugin.InvalidPluginConfigException; import io.cdap.cdap.api.plugin.InvalidPluginProperty; import io.cdap.cdap.api.plugin.PluginProperties; @@ -42,9 +41,7 @@ import io.cdap.cdap.etl.api.batch.BatchSink; import io.cdap.cdap.etl.api.batch.BatchSinkContext; import io.cdap.cdap.etl.api.connector.Connector; -import io.cdap.cdap.etl.api.exception.ErrorContext; import io.cdap.cdap.etl.api.exception.ErrorDetailsProviderSpec; -import io.cdap.cdap.etl.api.exception.ErrorPhase; import io.cdap.cdap.etl.api.validation.ValidatingOutputFormat; import io.cdap.plugin.common.batch.sink.SinkOutputFormatProvider; import io.cdap.plugin.format.FileFormat; @@ -159,14 +156,7 @@ public void prepareRun(BatchSinkContext context) throws Exception { } String bucketName = config.getBucket(collector); - Storage storage; - try { - storage = GCPUtils.getStorage(config.connection.getProject(), credentials); - } catch (Exception e) { - ProgramFailureException ex = new GCSErrorDetailsProvider().getExceptionDetails(e, - new ErrorContext(ErrorPhase.READING)); - throw ex == null ? e : ex; - } + Storage storage = GCPUtils.getStorage(config.connection.getProject(), credentials); try { if (storage.get(bucketName) == null) { GCPUtils.createBucket(storage, bucketName, config.getLocation(), cmekKeyName); diff --git a/src/main/java/io/cdap/plugin/gcp/gcs/source/GCSSource.java b/src/main/java/io/cdap/plugin/gcp/gcs/source/GCSSource.java index 8a805e646..4287b2a69 100644 --- a/src/main/java/io/cdap/plugin/gcp/gcs/source/GCSSource.java +++ b/src/main/java/io/cdap/plugin/gcp/gcs/source/GCSSource.java @@ -28,15 +28,12 @@ import io.cdap.cdap.api.annotation.MetadataProperty; import io.cdap.cdap.api.annotation.Name; import io.cdap.cdap.api.annotation.Plugin; -import io.cdap.cdap.api.exception.ProgramFailureException; import io.cdap.cdap.etl.api.FailureCollector; import io.cdap.cdap.etl.api.PipelineConfigurer; import io.cdap.cdap.etl.api.batch.BatchSource; import io.cdap.cdap.etl.api.batch.BatchSourceContext; import io.cdap.cdap.etl.api.connector.Connector; -import io.cdap.cdap.etl.api.exception.ErrorContext; import io.cdap.cdap.etl.api.exception.ErrorDetailsProviderSpec; -import io.cdap.cdap.etl.api.exception.ErrorPhase; import io.cdap.plugin.common.Asset; import io.cdap.plugin.common.ConfigUtil; import io.cdap.plugin.common.LineageRecorder; @@ -121,14 +118,7 @@ public void prepareRun(BatchSourceContext context) throws Exception { collector.getOrThrowException(); } - Storage storage; - try { - storage = GCPUtils.getStorage(config.connection.getProject(), credentials); - } catch (Exception e) { - ProgramFailureException ex = new GCSErrorDetailsProvider().getExceptionDetails(e, - new ErrorContext(ErrorPhase.READING)); - throw ex == null ? e : ex; - } + Storage storage = GCPUtils.getStorage(config.connection.getProject(), credentials); String location = null; try { // Get location of the source for lineage