Skip to content

Commit

Permalink
🦉 Updates from OwlBot post-processor
Browse files Browse the repository at this point in the history
  • Loading branch information
gcf-owl-bot[bot] committed Apr 13, 2024
1 parent 9d7fcc7 commit 4d90381
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 82 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file:
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage-control</artifactId>
</dependency>

```

Expand All @@ -44,13 +48,18 @@ If you are using Maven without the BOM, add this to your dependencies:
<artifactId>google-cloud-storage</artifactId>
<version>2.36.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage-control</artifactId>
<version>2.36.0-alpha</version><!-- {x-version-update:google-cloud-storage:current} -->
</dependency>

```

If you are using Gradle 5.x or later, add this to your dependencies:

```Groovy
implementation platform('com.google.cloud:libraries-bom:26.35.0')
implementation platform('com.google.cloud:libraries-bom:26.37.0')
implementation 'com.google.cloud:google-cloud-storage'
```
Expand Down Expand Up @@ -233,6 +242,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-storage/tree/
| Quickstart Grpc Dp Sample | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/QuickstartGrpcDpSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/QuickstartGrpcDpSample.java) |
| Quickstart Grpc Sample | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/QuickstartGrpcSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/QuickstartGrpcSample.java) |
| Quickstart Sample | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/QuickstartSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/QuickstartSample.java) |
| Quickstart Storage Control Sample | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/QuickstartStorageControlSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/QuickstartStorageControlSample.java) |
| Add Bucket Default Owner | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/AddBucketDefaultOwner.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/AddBucketDefaultOwner.java) |
| Add Bucket Iam Conditional Binding | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/AddBucketIamConditionalBinding.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/AddBucketIamConditionalBinding.java) |
| Add Bucket Iam Member | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/AddBucketIamMember.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/AddBucketIamMember.java) |
Expand Down Expand Up @@ -337,6 +347,10 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-storage/tree/
| Upload Kms Encrypted Object | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/UploadKmsEncryptedObject.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/UploadKmsEncryptedObject.java) |
| Upload Object | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/UploadObject.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/UploadObject.java) |
| Upload Object From Memory | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/UploadObjectFromMemory.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/UploadObjectFromMemory.java) |
| Download Bucket | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/transfermanager/DownloadBucket.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/transfermanager/DownloadBucket.java) |
| Download Many | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/transfermanager/DownloadMany.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/transfermanager/DownloadMany.java) |
| Upload Directory | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/transfermanager/UploadDirectory.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/transfermanager/UploadDirectory.java) |
| Upload Many | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/transfermanager/UploadMany.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/transfermanager/UploadMany.java) |



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ public static void main(String... args) throws Exception {

// Instantiates a client in a try-with-resource to automatically cleanup underlying resources
try (StorageControlClient storageControlClient = StorageControlClient.create()) {
GetStorageLayoutRequest request = GetStorageLayoutRequest.newBuilder()
// Set project to "_" to signify global bucket
.setName(StorageLayoutName.format("_", bucketName))
.build();
GetStorageLayoutRequest request =
GetStorageLayoutRequest.newBuilder()
// Set project to "_" to signify global bucket
.setName(StorageLayoutName.format("_", bucketName))
.build();
StorageLayout response = storageControlClient.getStorageLayout(request);
System.out.printf("Performed getStorageLayout request for %s", response.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,32 @@

class DownloadBucket {

public static void downloadBucketContents(String projectId,
String bucketName, Path destinationDirectory) {
public static void downloadBucketContents(
String projectId, String bucketName, Path destinationDirectory) {
Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
List<BlobInfo> blobs = storage
.list(bucketName)
.streamAll()
.map(blob -> blob.asBlobInfo())
.collect(Collectors.toList());
List<BlobInfo> blobs =
storage
.list(bucketName)
.streamAll()
.map(blob -> blob.asBlobInfo())
.collect(Collectors.toList());
TransferManager transferManager = TransferManagerConfig.newBuilder().build().getService();
ParallelDownloadConfig parallelDownloadConfig = ParallelDownloadConfig.newBuilder()
.setBucketName(bucketName)
.setDownloadDirectory(destinationDirectory)
.build();
ParallelDownloadConfig parallelDownloadConfig =
ParallelDownloadConfig.newBuilder()
.setBucketName(bucketName)
.setDownloadDirectory(destinationDirectory)
.build();

List<DownloadResult> results = transferManager
.downloadBlobs(blobs, parallelDownloadConfig)
.getDownloadResults();
List<DownloadResult> results =
transferManager.downloadBlobs(blobs, parallelDownloadConfig).getDownloadResults();

for (DownloadResult result : results) {
System.out.println("Download of " + result.getInput().getName()
+ " completed with status "
+ result.getStatus());
System.out.println(
"Download of "
+ result.getInput().getName()
+ " completed with status "
+ result.getStatus());
}

}

}
// [END storage_transfer_manager_download_bucket]
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,26 @@

class DownloadMany {

public static void downloadManyBlobs(String bucketName,
List<BlobInfo> blobs, Path destinationDirectory) {
public static void downloadManyBlobs(
String bucketName, List<BlobInfo> blobs, Path destinationDirectory) {

TransferManager transferManager = TransferManagerConfig.newBuilder().build().getService();
ParallelDownloadConfig parallelDownloadConfig = ParallelDownloadConfig.newBuilder()
.setBucketName(bucketName)
.setDownloadDirectory(destinationDirectory)
.build();
ParallelDownloadConfig parallelDownloadConfig =
ParallelDownloadConfig.newBuilder()
.setBucketName(bucketName)
.setDownloadDirectory(destinationDirectory)
.build();

List<DownloadResult> results = transferManager
.downloadBlobs(blobs, parallelDownloadConfig)
.getDownloadResults();
List<DownloadResult> results =
transferManager.downloadBlobs(blobs, parallelDownloadConfig).getDownloadResults();

for (DownloadResult result : results) {
System.out.println("Download of " + result.getInput().getName()
+ " completed with status " + result.getStatus());
System.out.println(
"Download of "
+ result.getInput().getName()
+ " completed with status "
+ result.getStatus());
}

}

}
// [END storage_transfer_manager_download_many]
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,25 @@ class UploadDirectory {
public static void uploadDirectoryContents(String bucketName, Path sourceDirectory)
throws IOException {
TransferManager transferManager = TransferManagerConfig.newBuilder().build().getService();
ParallelUploadConfig parallelUploadConfig = ParallelUploadConfig
.newBuilder()
.setBucketName(bucketName)
.build();
ParallelUploadConfig parallelUploadConfig =
ParallelUploadConfig.newBuilder().setBucketName(bucketName).build();

// Create a list to store the file paths
List<Path> filePaths = new ArrayList<>();
// Get all files in the directory
// try-with-resource to ensure pathStream is closed
try (Stream<Path> pathStream = Files.walk(sourceDirectory)) {
pathStream.filter(Files::isRegularFile)
.forEach(filePaths::add);
pathStream.filter(Files::isRegularFile).forEach(filePaths::add);
}
List<UploadResult> results = transferManager
.uploadFiles(filePaths, parallelUploadConfig)
.getUploadResults();
List<UploadResult> results =
transferManager.uploadFiles(filePaths, parallelUploadConfig).getUploadResults();
for (UploadResult result : results) {
System.out.println("Upload for " + result.getInput().getName()
+ " completed with status " + result.getStatus());
System.out.println(
"Upload for "
+ result.getInput().getName()
+ " completed with status "
+ result.getStatus());
}
}

}
// [END storage_transfer_manager_upload_directory]
// [END storage_transfer_manager_upload_directory]
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,18 @@

class UploadMany {

public static void uploadManyFiles(String bucketName, List<Path> files)
throws IOException {
public static void uploadManyFiles(String bucketName, List<Path> files) throws IOException {
TransferManager transferManager = TransferManagerConfig.newBuilder().build().getService();
ParallelUploadConfig parallelUploadConfig = ParallelUploadConfig
.newBuilder()
.setBucketName(bucketName)
.build();
List<UploadResult> results = transferManager
.uploadFiles(files, parallelUploadConfig)
.getUploadResults();
ParallelUploadConfig parallelUploadConfig =
ParallelUploadConfig.newBuilder().setBucketName(bucketName).build();
List<UploadResult> results =
transferManager.uploadFiles(files, parallelUploadConfig).getUploadResults();
for (UploadResult result : results) {
System.out.println("Upload for " + result.getInput().getName()
+ " completed with status " + result.getStatus());
System.out.println(
"Upload for "
+ result.getInput().getName()
+ " completed with status "
+ result.getStatus());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ public void testQuickstartStorageControl() throws Exception {
QuickstartStorageControlSample.main(bucketName);
String got = stdOutCaptureRule.getCapturedOutputAsUtf8String();
assertThat(got)
.contains(String.format("Performed getStorageLayout request for %s",
StorageLayoutName.format("_", bucketName)));
.contains(
String.format(
"Performed getStorageLayout request for %s",
StorageLayoutName.format("_", bucketName)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import static com.google.common.truth.Truth.assertThat;

import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.BlobInfo;
import com.google.cloud.storage.BucketInfo;
import com.google.cloud.storage.Storage;
Expand All @@ -29,22 +28,19 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;


public class ITTransferManagerSamples {
private static final String BUCKET = RemoteStorageHelper.generateBucketName();
private static Storage storage;
private static List<BlobInfo> blobs;
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
@Rule
public final StdOutCaptureRule stdOutCaptureRule = new StdOutCaptureRule();
@Rule public final StdOutCaptureRule stdOutCaptureRule = new StdOutCaptureRule();
@Rule public final TemporaryFolder tmp = new TemporaryFolder();
@Rule public final TemporaryFolder tmpDirectory = new TemporaryFolder();

Expand All @@ -53,22 +49,22 @@ public static void beforeClass() {
RemoteStorageHelper helper = RemoteStorageHelper.create();
storage = helper.getOptions().getService();
storage.create(BucketInfo.of(BUCKET));
blobs = Arrays.asList(BlobInfo.newBuilder(BUCKET, "blob1").build(),
BlobInfo.newBuilder(BUCKET, "blob2").build(),
BlobInfo.newBuilder(BUCKET, "blob3").build());
blobs =
Arrays.asList(
BlobInfo.newBuilder(BUCKET, "blob1").build(),
BlobInfo.newBuilder(BUCKET, "blob2").build(),
BlobInfo.newBuilder(BUCKET, "blob3").build());
for (BlobInfo blob : blobs) {
storage.create(blob);
}

}

@Test
public void uploadFiles() throws Exception {
File tmpFile = File.createTempFile("file", ".txt");
File tmpFile2 = File.createTempFile("file2", ".txt");
File tmpFile3 = File.createTempFile("file3", ".txt");
List<Path> files =
ImmutableList.of(tmpFile.toPath(), tmpFile2.toPath(), tmpFile3.toPath());
List<Path> files = ImmutableList.of(tmpFile.toPath(), tmpFile2.toPath(), tmpFile3.toPath());
UploadMany.uploadManyFiles(BUCKET, files);
String snippetOutput = stdOutCaptureRule.getCapturedOutputAsUtf8String();
assertThat(snippetOutput.contains("file")).isTrue();
Expand All @@ -92,15 +88,16 @@ public void uploadDirectory() throws IOException {
public void downloadBucket() {
String downloadFullBucketName = RemoteStorageHelper.generateBucketName();
storage.create(BucketInfo.of(downloadFullBucketName));
List<BlobInfo> bucketBlobs = Arrays.asList(
BlobInfo.newBuilder(downloadFullBucketName, "bucketb1").build(),
BlobInfo.newBuilder(downloadFullBucketName, "bucketb2").build(),
BlobInfo.newBuilder(downloadFullBucketName, "bucketb3").build());
List<BlobInfo> bucketBlobs =
Arrays.asList(
BlobInfo.newBuilder(downloadFullBucketName, "bucketb1").build(),
BlobInfo.newBuilder(downloadFullBucketName, "bucketb2").build(),
BlobInfo.newBuilder(downloadFullBucketName, "bucketb3").build());
for (BlobInfo blob : bucketBlobs) {
storage.create(blob);
}
DownloadBucket
.downloadBucketContents(PROJECT_ID, downloadFullBucketName, tmp.getRoot().toPath());
DownloadBucket.downloadBucketContents(
PROJECT_ID, downloadFullBucketName, tmp.getRoot().toPath());
String snippetOutput = stdOutCaptureRule.getCapturedOutputAsUtf8String();
assertThat(snippetOutput.contains("bucketb1")).isTrue();
assertThat(snippetOutput.contains("bucketb2")).isTrue();
Expand All @@ -115,5 +112,4 @@ public void downloadFiles() {
assertThat(snippetOutput.contains("blob2")).isTrue();
assertThat(snippetOutput.contains("blob3")).isTrue();
}

}

0 comments on commit 4d90381

Please sign in to comment.