2323import co .cask .cdap .etl .api .action .Action ;
2424import co .cask .cdap .etl .api .action .ActionContext ;
2525import co .cask .gcp .common .GCPConfig ;
26+ import co .cask .gcp .gcs .GCSConfigHelper ;
2627import org .apache .hadoop .conf .Configuration ;
2728import org .apache .hadoop .fs .FileSystem ;
2829import org .apache .hadoop .fs .Path ;
3132
3233import java .io .IOException ;
3334import java .util .ArrayList ;
35+ import java .util .Arrays ;
3436import java .util .List ;
37+ import java .util .stream .Collectors ;
3538
3639
3740/**
@@ -58,18 +61,12 @@ public void run(ActionContext context) throws Exception {
5861 String projectId = config .getProject ();
5962 configuration .set ("fs.gs.project.id" , projectId );
6063
61- configuration .set ("fs.gs.system.bucket" , config .bucket );
6264 configuration .setBoolean ("fs.gs.impl.disable.cache" , true );
6365 configuration .setBoolean ("fs.gs.metadata.cache.enable" , false );
6466
65- String [] paths = config .paths .split ("," );
6667 List <Path > gcsPaths = new ArrayList <>();
67- for (String path : paths ) {
68- String gcsPath = String .format ("gs://%s/%s" , config .bucket , path );
69- if (path .startsWith ("/" )) {
70- gcsPath = String .format ("gs://%s%s" , config .bucket , path );
71- }
72- gcsPaths .add (new Path (gcsPath ));
68+ for (String path : config .getPaths ()) {
69+ gcsPaths .add (new Path (GCSConfigHelper .getPath (path )));
7370 }
7471
7572 FileSystem fs ;
@@ -97,10 +94,10 @@ public void run(ActionContext context) throws Exception {
9794 throw e ;
9895 }
9996 } else {
100- if (config .failIfExists . equalsIgnoreCase ( "yes" )) {
97+ if (config .getFailIfExists ( )) {
10198 rollback = true ;
10299 throw new Exception (
103- String .format ("Object %s already exists" )
100+ String .format ("Object %s already exists" , gcsPath )
104101 );
105102 }
106103 }
@@ -126,20 +123,22 @@ public void run(ActionContext context) throws Exception {
126123 * Config for the plugin.
127124 */
128125 public final class Config extends GCPConfig {
129-
130- @ Name ("bucket" )
131- @ Description ("Name of the bucket." )
132- @ Macro
133- public String bucket ;
134-
135126 @ Name ("paths" )
136- @ Description ("List of objects to be created within a bucket " )
127+ @ Description ("Comma separated list of objects to be created. " )
137128 @ Macro
138- public String paths ;
129+ private String paths ;
139130
140131 @ Name ("failIfExists" )
141132 @ Description ("Fail if path exists." )
142133 @ Macro
143- public String failIfExists ;
134+ private boolean failIfExists ;
135+
136+ public List <String > getPaths () {
137+ return Arrays .stream (paths .split ("," )).map (String ::trim ).collect (Collectors .toList ());
138+ }
139+
140+ public boolean getFailIfExists () {
141+ return failIfExists ;
142+ }
144143 }
145144}
0 commit comments