Skip to content

Commit

Permalink
Merge pull request #229 from cloudsufi/Multi_upload_Policy
Browse files Browse the repository at this point in the history
Functionality added for GCS multipart upload policy.
  • Loading branch information
samdgupi authored Nov 28, 2023
2 parents 67246c2 + 51422f5 commit 44f61d8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,20 @@ the License.-->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>2.1.3</version>
<version>2.8.0</version>
</dependency>

<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-bigquery</artifactId>
<version>2.1.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.apis/google-api-services-storage -->
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-storage</artifactId>
<version>v1-rev20220604-1.32.1</version>
</dependency>

</dependencies>

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/io/cdap/e2e/utils/StorageClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

}

0 comments on commit 44f61d8

Please sign in to comment.