Skip to content

Commit 5c0f246

Browse files
committed
---
yaml --- r: 5961 b: refs/heads/tswast-patch-1 c: be58a4c h: refs/heads/master i: 5959: 58faa98
1 parent a80bbc9 commit 5c0f246

4 files changed

Lines changed: 34 additions & 9 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: 075fc6c56115c00d19aa7f3f7f883533eba7a7de
60+
refs/heads/tswast-patch-1: be58a4c85f2cf300ac902f1d362b6163e9709284
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

branches/tswast-patch-1/src/main/java/com/google/gcloud/spi/StorageRpc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.gcloud.spi;import com.google.api.services.storage.model.Bucket;import com.google.api.services.storage.model.StorageObject;import com.google.gcloud.storage.BlobReadChannel;import com.google.gcloud.storage.BlobWriteChannel;import com.google.gcloud.storage.StorageServiceException;import java.util.Map;public interface StorageRpc { enum Option { PREDEFINED_ACL("predefinedAcl"), PREDEFINED_DEFAULT_OBJECT_ACL("predefinedDefaultObjectAcl"), IF_METAGENERATION_MATCH("ifMetagenerationMatch"), IF_METAGENERATION_NOT_MATCH("ifMetagenerationNotMatch"), IF_GENERATION_NOT_MATCH("ifGenerationMatch"), IF_GENERATION_MATCH("ifGenerationNotMatch"), IF_SOURCE_METAGENERATION_MATCH("ifSourceMetagenerationMatch"), IF_SOURCE_METAGENERATION_NOT_MATCH("ifSourceMetagenerationNotMatch"), IF_SOURCE_GENERATION_MATCH("ifSourceGenerationMatch"), IF_SOURCE_GENERATION_NOT_MATCH("ifSourceGenerationNotMatch"), PREFIX("prefix"), MAX_RESULTS("maxResults"), PAGE_TOKEN("pageToken"), DELIMITER("delimiter"), VERSIONS("versions"); private final String value; Option(String value) { this.value = value; } public String value() { return value; } @SuppressWarnings("unchecked") <T> T get(Map<Option, ?> options) { return (T) options.get(this); } String getString(Map<Option, ?> options) { return get(options); } Long getLong(Map<Option, ?> options) { return get(options); } Boolean getBoolean(Map<Option, ?> options) { return get(options); } } class Tuple<X, Y> { private final X x; private final Y y; private Tuple(X x, Y y) { this.x = x; this.y = y; } public static <X, Y> Tuple<X, Y> of(X x, Y y) { return new Tuple<>(x, y); } public X x() { return x; } public Y y() { return y; } } Bucket create(Bucket bucket, Map<Option, ?> options) throws StorageServiceException; StorageObject create(StorageObject object, byte[] content, Map<Option, ?> options) throws StorageServiceException; Tuple<String, Iterable<Bucket>> list(Map<Option, ?> options) throws StorageServiceException; Tuple<String, Iterable<StorageObject>> list(String bucket, Map<Option, ?> options) throws StorageServiceException; Bucket get(Bucket bucket, Map<Option, ?> options) throws StorageServiceException; StorageObject get(StorageObject object, Map<Option, ?> options) throws StorageServiceException; Bucket patch(Bucket bucket, Map<Option, ?> options) throws StorageServiceException; StorageObject patch(StorageObject storageObject, Map<Option, ?> options) throws StorageServiceException; boolean delete(Bucket bucket, Map<Option, ?> options) throws StorageServiceException; boolean delete(StorageObject object, Map<Option, ?> options) throws StorageServiceException; void batch(Iterable<Tuple<StorageObject, Map<Option, ?>>> toDelete) throws StorageServiceException; StorageObject compose(Iterable<StorageObject> sources, StorageObject target, Map<Option, ?> targetOptions) throws StorageServiceException; StorageObject copy(StorageObject source, Map<Option, ?> sourceOptions, StorageObject target, Map<Option, ?> targetOptions) throws StorageServiceException; byte[] load(StorageObject storageObject, Map<Option, ?> options) throws StorageServiceException; BlobReadChannel reader(StorageObject from, Map<Option, ?> options) throws StorageServiceException; BlobWriteChannel writer(StorageObject to, Map<Option, ?> options) throws StorageServiceException;}
1+
/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.gcloud.spi;import com.google.api.services.storage.model.Bucket;import com.google.api.services.storage.model.StorageObject;import com.google.common.collect.ImmutableList;import com.google.common.collect.ImmutableMap;import com.google.gcloud.storage.BlobReadChannel;import com.google.gcloud.storage.BlobWriteChannel;import com.google.gcloud.storage.StorageServiceException;import java.util.List;import java.util.Map;public interface StorageRpc { enum Option { PREDEFINED_ACL("predefinedAcl"), PREDEFINED_DEFAULT_OBJECT_ACL("predefinedDefaultObjectAcl"), IF_METAGENERATION_MATCH("ifMetagenerationMatch"), IF_METAGENERATION_NOT_MATCH("ifMetagenerationNotMatch"), IF_GENERATION_NOT_MATCH("ifGenerationMatch"), IF_GENERATION_MATCH("ifGenerationNotMatch"), IF_SOURCE_METAGENERATION_MATCH("ifSourceMetagenerationMatch"), IF_SOURCE_METAGENERATION_NOT_MATCH("ifSourceMetagenerationNotMatch"), IF_SOURCE_GENERATION_MATCH("ifSourceGenerationMatch"), IF_SOURCE_GENERATION_NOT_MATCH("ifSourceGenerationNotMatch"), PREFIX("prefix"), MAX_RESULTS("maxResults"), PAGE_TOKEN("pageToken"), DELIMITER("delimiter"), VERSIONS("versions"); private final String value; Option(String value) { this.value = value; } public String value() { return value; } @SuppressWarnings("unchecked") <T> T get(Map<Option, ?> options) { return (T) options.get(this); } String getString(Map<Option, ?> options) { return get(options); } Long getLong(Map<Option, ?> options) { return get(options); } Boolean getBoolean(Map<Option, ?> options) { return get(options); } } class Tuple<X, Y> { private final X x; private final Y y; private Tuple(X x, Y y) { this.x = x; this.y = y; } public static <X, Y> Tuple<X, Y> of(X x, Y y) { return new Tuple<>(x, y); } public X x() { return x; } public Y y() { return y; } } class BatchRequest { public final List<Tuple<StorageObject, Map<Option, ?>>> toDelete; public final List<Tuple<StorageObject, Map<Option, ?>>> toUpdate; public final List<Tuple<StorageObject, Map<Option, ?>>> toGet; public BatchRequest(Iterable<Tuple<StorageObject, Map<Option, ?>>> toDelete, Iterable<Tuple<StorageObject, Map<Option, ?>>> toUpdate, Iterable<Tuple<StorageObject, Map<Option, ?>>> toGet) { this.toDelete = ImmutableList.copyOf(toDelete); this.toUpdate = ImmutableList.copyOf(toUpdate); this.toGet = ImmutableList.copyOf(toGet); } } class BatchResponse { public final Map<StorageObject, Tuple<Boolean, StorageServiceException>> deletes; public final Map<StorageObject, Tuple<StorageObject, StorageServiceException>> updates; public final Map<StorageObject, Tuple<StorageObject, StorageServiceException>> gets; public BatchResponse(Map<StorageObject, Tuple<Boolean, StorageServiceException>> deletes, Map<StorageObject, Tuple<StorageObject, StorageServiceException>> updates, Map<StorageObject, Tuple<StorageObject, StorageServiceException>> gets) { this.deletes = ImmutableMap.copyOf(deletes); this.updates = ImmutableMap.copyOf(updates); this.gets = ImmutableMap.copyOf(gets); } } Bucket create(Bucket bucket, Map<Option, ?> options) throws StorageServiceException; StorageObject create(StorageObject object, byte[] content, Map<Option, ?> options) throws StorageServiceException; Tuple<String, Iterable<Bucket>> list(Map<Option, ?> options) throws StorageServiceException; Tuple<String, Iterable<StorageObject>> list(String bucket, Map<Option, ?> options) throws StorageServiceException; Bucket get(Bucket bucket, Map<Option, ?> options) throws StorageServiceException; StorageObject get(StorageObject object, Map<Option, ?> options) throws StorageServiceException; Bucket patch(Bucket bucket, Map<Option, ?> options) throws StorageServiceException; StorageObject patch(StorageObject storageObject, Map<Option, ?> options) throws StorageServiceException; boolean delete(Bucket bucket, Map<Option, ?> options) throws StorageServiceException; boolean delete(StorageObject object, Map<Option, ?> options) throws StorageServiceException; BatchResponse batch(BatchRequest request) throws StorageServiceException; StorageObject compose(Iterable<StorageObject> sources, StorageObject target, Map<Option, ?> targetOptions) throws StorageServiceException; StorageObject copy(StorageObject source, Map<Option, ?> sourceOptions, StorageObject target, Map<Option, ?> targetOptions) throws StorageServiceException; byte[] load(StorageObject storageObject, Map<Option, ?> options) throws StorageServiceException; BlobReadChannel reader(StorageObject from, Map<Option, ?> options) throws StorageServiceException; BlobWriteChannel writer(StorageObject to, Map<Option, ?> options) throws StorageServiceException;}

branches/tswast-patch-1/src/main/java/com/google/gcloud/storage/StorageServiceImpl.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,19 +259,44 @@ public byte[] call() {
259259

260260
@Override
261261
public BatchResponse apply(BatchRequest batchRequest) {
262-
List<BatchResponse.Result<Boolean>> deletes = new LinkedList<>();
263-
List<BatchResponse.Result<Blob>> updates = new LinkedList<>();
264-
List<BatchResponse.Result<Blob>> gets = new LinkedList<>();
265-
List<Tuple<StorageObject, Map<StorageRpc.Option, ?>>> request =
262+
List<Tuple<StorageObject, Map<StorageRpc.Option, ?>>> toDelete =
266263
Lists.newArrayListWithCapacity(batchRequest.toDelete().size());
267264
for (Map.Entry<Blob, BlobSourceOption[]> entry : batchRequest.toDelete().entrySet()) {
268265
Blob blob = entry.getKey();
269266
Map<StorageRpc.Option, ?> optionsMap = optionMap(blob, entry.getValue());
270-
request.add(Tuple.<StorageObject, Map<StorageRpc.Option, ?>>of(blob.toPb(), optionsMap));
267+
toDelete.add(Tuple.<StorageObject, Map<StorageRpc.Option, ?>>of(blob.toPb(), optionsMap));
268+
}
269+
List<Tuple<StorageObject, Map<StorageRpc.Option, ?>>> toUpdate =
270+
Lists.newArrayListWithCapacity(batchRequest.toUpdate().size());
271+
for (Map.Entry<Blob, BlobTargetOption[]> entry : batchRequest.toUpdate().entrySet()) {
272+
Blob blob = entry.getKey();
273+
Map<StorageRpc.Option, ?> optionsMap = optionMap(blob, entry.getValue());
274+
toUpdate.add(Tuple.<StorageObject, Map<StorageRpc.Option, ?>>of(blob.toPb(), optionsMap));
275+
}
276+
List<Tuple<StorageObject, Map<StorageRpc.Option, ?>>> toGet =
277+
Lists.newArrayListWithCapacity(batchRequest.toGet().size());
278+
for (Map.Entry<Blob, BlobSourceOption[]> entry : batchRequest.toGet().entrySet()) {
279+
Blob blob = entry.getKey();
280+
Map<StorageRpc.Option, ?> optionsMap = optionMap(blob, entry.getValue());
281+
toGet.add(Tuple.<StorageObject, Map<StorageRpc.Option, ?>>of(blob.toPb(), optionsMap));
271282
}
272283
// todo: populate deletes, updates and gets (the latter 2 needs to be sent to RPC)
273284
// todo: change example to use multi-update and multi-get
274-
storageRpc.batch(request);
285+
StorageRpc.BatchResponse response =
286+
storageRpc.batch(new StorageRpc.BatchRequest(toDelete, toUpdate, toGet));
287+
List<BatchResponse.Result<Boolean>> deletes = new LinkedList<>();
288+
for (Blob blob : batchRequest.toDelete().keySet()) {
289+
Tuple<Boolean, StorageServiceException> result = response.deletes.get(blob);
290+
if (result.x() != null) {
291+
deletes.add(new BatchResponse.Result<>(false));
292+
} else {
293+
deletes.add(new BatchResponse.Result<Boolean>(result.y()));
294+
}
295+
}
296+
297+
List<BatchResponse.Result<Blob>> updates = new LinkedList<>();
298+
List<BatchResponse.Result<Blob>> gets = new LinkedList<>();
299+
275300
return new BatchResponse(deletes, updates, gets);
276301
}
277302

0 commit comments

Comments
 (0)