Skip to content

Commit

Permalink
changes as per the review
Browse files Browse the repository at this point in the history
  • Loading branch information
neerajsinghal05 committed Nov 14, 2023
1 parent f12721c commit dc1d1f6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
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
21 changes: 18 additions & 3 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 All @@ -40,7 +45,7 @@ public class StorageClient {

private static Storage getStorageService() throws IOException {
return (null == storageService) ? StorageOptions.newBuilder().setProjectId(
PluginPropertyUtils.pluginProp(ConstantsUtil.PROJECT_ID)).build().getService() : storageService;
PluginPropertyUtils.pluginProp(ConstantsUtil.PROJECT_ID)).build().getService() : storageService;
}

public static Page<Bucket> listBuckets() throws IOException {
Expand Down Expand Up @@ -89,8 +94,18 @@ public static Bucket createBucket(String bucketName) throws IOException {
public static Blob uploadObject(String bucketName, String objectName, String filePath)
throws IOException, URISyntaxException {
return getStorageService().create(
BlobInfo.newBuilder(BlobId.of(bucketName, objectName)).build(),
Files.readAllBytes(Paths.get(StorageClient.class.getResource("/" + filePath).toURI())));
BlobInfo.newBuilder(BlobId.of(bucketName, objectName)).build(),
Files.readAllBytes(Paths.get(StorageClient.class.getResource("/" + filePath).toURI())));
}

public static Bucket createBucketwithLifeCycle(String bucketName, int age) throws IOException {
return getStorageService().create(BucketInfo.of(bucketName)).toBuilder()
.setLifecycleRules(
ImmutableList.of(
new LifecycleRule(
LifecycleAction.newAbortIncompleteMPUploadAction(),
LifecycleCondition.newBuilder().setAge(age).build()))).build().update();
}

}

0 comments on commit dc1d1f6

Please sign in to comment.