Skip to content

Commit 6c85db0

Browse files
committed
Fix bucket creation issue for GCS Copy/Move Plugins
1 parent ba75120 commit 6c85db0

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/main/java/io/cdap/plugin/gcp/gcs/StorageClient.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,17 @@ public void mapMetaDataForAllBlobs(String path, Consumer<Map<String, String>> fu
115115
* @param cmekKeyName the name of the cmek key
116116
*/
117117
public void createBucketIfNotExists(GCSPath path, @Nullable String location, @Nullable CryptoKeyName cmekKeyName) {
118-
Bucket bucket = null;
119118
try {
120-
bucket = storage.get(path.getBucket());
119+
GCPUtils.createBucket(storage, path.getBucket(), location, cmekKeyName);
120+
LOG.info("Bucket {} has been created successfully", path.getBucket());
121121
} catch (StorageException e) {
122-
throw new RuntimeException(
123-
String.format("Unable to access bucket %s. ", path.getBucket())
122+
// Don't throw error if bucket already exists
123+
// https://cloud.google.com/storage/docs/xml-api/reference-status#409%E2%80%94conflict
124+
if (e.getCode() != 409) {
125+
throw new RuntimeException(
126+
String.format("Unable to create bucket %s. ", path.getBucket())
124127
+ "Ensure you entered the correct bucket path and have permissions for it.", e);
125-
}
126-
if (bucket == null) {
127-
GCPUtils.createBucket(storage, path.getBucket(), location, cmekKeyName);
128+
}
128129
}
129130
}
130131

0 commit comments

Comments
 (0)