1717package io .cdap .plugin .gcp .gcs .actions ;
1818
1919import com .google .cloud .kms .v1 .CryptoKeyName ;
20- import com .google .cloud .storage .Bucket ;
21- import com .google .cloud .storage .Storage ;
22- import com .google .cloud .storage .StorageException ;
23- import com .google .common .base .Strings ;
2420import io .cdap .cdap .api .annotation .Description ;
2521import io .cdap .cdap .api .annotation .Macro ;
2622import io .cdap .cdap .api .annotation .Name ;
3026import io .cdap .cdap .etl .api .action .Action ;
3127import io .cdap .cdap .etl .api .action .ActionContext ;
3228import io .cdap .plugin .gcp .common .CmekUtils ;
33- import io .cdap .plugin .gcp .common .GCPUtils ;
3429import io .cdap .plugin .gcp .gcs .GCSPath ;
3530import io .cdap .plugin .gcp .gcs .StorageClient ;
3631
3732import java .io .IOException ;
3833import java .util .ArrayList ;
39- import java .util .Collections ;
4034import java .util .List ;
4135import javax .annotation .Nullable ;
4236
@@ -57,7 +51,7 @@ public void configurePipeline(PipelineConfigurer pipelineConfigurer) {
5751 }
5852
5953 @ Override
60- public void run (ActionContext context ) throws IOException {
54+ public void run (ActionContext context ) {
6155 FailureCollector collector = context .getFailureCollector ();
6256 config .validate (collector , context .getArguments ().asMap ());
6357
@@ -68,8 +62,16 @@ public void run(ActionContext context) throws IOException {
6862 collector .getOrThrowException ();
6963 return ;
7064 }
71- StorageClient storageClient = StorageClient .create (config .getProject (), config .getServiceAccount (),
72- isServiceAccountFilePath , config .readTimeout );
65+ StorageClient storageClient = null ;
66+ try {
67+ storageClient = StorageClient .create (config .getProject (), config .getServiceAccount (), isServiceAccountFilePath ,
68+ config .readTimeout );
69+ } catch (IOException e ) {
70+ String errorReason = "Failed to create storage client, unable to load service account credentials." ;
71+ collector .addFailure (String .format ("%s %s" , errorReason , e .getMessage ()), null )
72+ .withStacktrace (e .getStackTrace ());
73+ collector .getOrThrowException ();
74+ }
7375
7476 GCSPath destPath = config .getDestPath ();
7577 CryptoKeyName cmekKeyName = CmekUtils .getCmekKey (config .cmekKey , context .getArguments ().asMap (), collector );
0 commit comments