From 51422f58116419b544da8ace238dfd0d970ffeb0 Mon Sep 17 00:00:00 2001 From: neerajsinghal Date: Thu, 9 Nov 2023 21:25:16 +0530 Subject: [PATCH] Functionality added for GCS multipart upload policy. --- pom.xml | 8 +++++++- .../java/io/cdap/e2e/utils/StorageClient.java | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f9e8ab6b7..f7dfea65f 100644 --- a/pom.xml +++ b/pom.xml @@ -360,7 +360,7 @@ the License.--> com.google.cloud google-cloud-storage - 2.1.3 + 2.8.0 @@ -368,6 +368,12 @@ the License.--> google-cloud-bigquery 2.1.8 + + + com.google.apis + google-api-services-storage + v1-rev20220604-1.32.1 + diff --git a/src/main/java/io/cdap/e2e/utils/StorageClient.java b/src/main/java/io/cdap/e2e/utils/StorageClient.java index 638538b98..c5571461d 100644 --- a/src/main/java/io/cdap/e2e/utils/StorageClient.java +++ b/src/main/java/io/cdap/e2e/utils/StorageClient.java @@ -22,10 +22,15 @@ import com.google.cloud.storage.BlobInfo; import com.google.cloud.storage.Bucket; import com.google.cloud.storage.BucketInfo; +import com.google.cloud.storage.BucketInfo.LifecycleRule; +import com.google.cloud.storage.BucketInfo.LifecycleRule.LifecycleAction; +import com.google.cloud.storage.BucketInfo.LifecycleRule.LifecycleCondition; import com.google.cloud.storage.Storage; +import com.google.cloud.storage.Storage.BucketField; import com.google.cloud.storage.StorageException; import com.google.cloud.storage.StorageOptions; +import com.google.common.collect.ImmutableList; import java.io.IOException; import java.net.URISyntaxException; import java.nio.file.Files; @@ -93,4 +98,18 @@ public static Blob uploadObject(String bucketName, String objectName, String fil Files.readAllBytes(Paths.get(StorageClient.class.getResource("/" + filePath).toURI()))); } + /** + * @param bucketName , required random Bucket name to create in GCS. + * @param ageInDays Age has to be pass in days. + */ + public static Bucket createBucketwithLifeCycle(String bucketName, int ageInDays) throws IOException { + return getStorageService().create(BucketInfo.of(bucketName)).toBuilder() + .setLifecycleRules( + ImmutableList.of( + new LifecycleRule( + LifecycleAction.newAbortIncompleteMPUploadAction(), + LifecycleCondition.newBuilder().setAge(ageInDays).build()))).build().update(); + } + } +