Skip to content

Commit 86a1429

Browse files
committed
---
yaml --- r: 1959 b: refs/heads/pubsub-alpha c: 87e4bac h: refs/heads/master i: 1957: bc58d83 1955: cfec8a2 1951: d3ecfdb
1 parent 62c021b commit 86a1429

10 files changed

Lines changed: 54 additions & 65 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ refs/heads/master: 689bbb466df4b2d5d2483d6edb8ac5c7c7f7c6fa
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
6-
refs/heads/pubsub-alpha: a4c42736e359a52c0c43c46cb88a1d8860e2c297
6+
refs/heads/pubsub-alpha: 87e4bac0dff3ef1f36f67e6a119072edd0d3509c
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
88
refs/heads/update-datastore: 482954f2c5055231e5b3122ea91d2ba00ce8187c
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import static com.google.gcloud.spi.StorageRpc.Option.PREDEFINED_DEFAULT_OBJECT_ACL;
3131
import static com.google.gcloud.spi.StorageRpc.Option.PREFIX;
3232
import static com.google.gcloud.spi.StorageRpc.Option.VERSIONS;
33-
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
3433

3534
import com.google.api.client.googleapis.batch.json.JsonBatchCallback;
3635
import com.google.api.client.googleapis.json.GoogleJsonError;
@@ -95,8 +94,7 @@ public DefaultStorageRpc(StorageOptions options) {
9594

9695
private static StorageException translate(IOException exception) {
9796
StorageException translated;
98-
if (exception instanceof GoogleJsonResponseException
99-
&& ((GoogleJsonResponseException) exception).getDetails() != null) {
97+
if (exception instanceof GoogleJsonResponseException) {
10098
translated = translate(((GoogleJsonResponseException) exception).getDetails());
10199
} else {
102100
translated = new StorageException(0, exception.getMessage(), false);
@@ -193,11 +191,7 @@ public Bucket get(Bucket bucket, Map<Option, ?> options) {
193191
.setFields(FIELDS.getString(options))
194192
.execute();
195193
} catch (IOException ex) {
196-
StorageException serviceException = translate(ex);
197-
if (serviceException.code() == HTTP_NOT_FOUND) {
198-
return null;
199-
}
200-
throw serviceException;
194+
throw translate(ex);
201195
}
202196
}
203197

@@ -206,11 +200,7 @@ public StorageObject get(StorageObject object, Map<Option, ?> options) {
206200
try {
207201
return getRequest(object, options).execute();
208202
} catch (IOException ex) {
209-
StorageException serviceException = translate(ex);
210-
if (serviceException.code() == HTTP_NOT_FOUND) {
211-
return null;
212-
}
213-
throw serviceException;
203+
throw translate(ex);
214204
}
215205
}
216206

@@ -275,7 +265,7 @@ public boolean delete(Bucket bucket, Map<Option, ?> options) {
275265
return true;
276266
} catch (IOException ex) {
277267
StorageException serviceException = translate(ex);
278-
if (serviceException.code() == HTTP_NOT_FOUND) {
268+
if (serviceException.code() == 404) {
279269
return false;
280270
}
281271
throw serviceException;
@@ -289,7 +279,7 @@ public boolean delete(StorageObject blob, Map<Option, ?> options) {
289279
return true;
290280
} catch (IOException ex) {
291281
StorageException serviceException = translate(ex);
292-
if (serviceException.code() == HTTP_NOT_FOUND) {
282+
if (serviceException.code() == 404) {
293283
return false;
294284
}
295285
throw serviceException;
@@ -378,11 +368,7 @@ public void onSuccess(Void ignore, HttpHeaders responseHeaders) {
378368

379369
@Override
380370
public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
381-
if (e.getCode() == HTTP_NOT_FOUND) {
382-
deletes.put(tuple.x(), Tuple.<Boolean, StorageException>of(Boolean.FALSE, null));
383-
} else {
384-
deletes.put(tuple.x(), Tuple.<Boolean, StorageException>of(null, translate(e)));
385-
}
371+
deletes.put(tuple.x(), Tuple.<Boolean, StorageException>of(null, translate(e)));
386372
}
387373
});
388374
}
@@ -411,13 +397,8 @@ public void onSuccess(StorageObject storageObject, HttpHeaders responseHeaders)
411397

412398
@Override
413399
public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
414-
if (e.getCode() == HTTP_NOT_FOUND) {
415-
gets.put(tuple.x(),
416-
Tuple.<StorageObject, StorageException>of(null, null));
417-
} else {
418-
gets.put(tuple.x(),
419-
Tuple.<StorageObject, StorageException>of(null, translate(e)));
420-
}
400+
gets.put(tuple.x(),
401+
Tuple.<StorageObject, StorageException>of(null, translate(e)));
421402
}
422403
});
423404
}

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,18 +227,8 @@ StorageObject create(StorageObject object, InputStream content, Map<Option, ?> o
227227
Tuple<String, Iterable<StorageObject>> list(String bucket, Map<Option, ?> options)
228228
throws StorageException;
229229

230-
/**
231-
* Returns the requested bucket or {@code null} if not found.
232-
*
233-
* @throws StorageException upon failure
234-
*/
235230
Bucket get(Bucket bucket, Map<Option, ?> options) throws StorageException;
236231

237-
/**
238-
* Returns the requested storage object or {@code null} if not found.
239-
*
240-
* @throws StorageException upon failure
241-
*/
242232
StorageObject get(StorageObject object, Map<Option, ?> options)
243233
throws StorageException;
244234

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public CopyWriter copyTo(BlobId targetBlob, BlobSourceOption... options) {
281281
* Deletes this blob.
282282
*
283283
* @param options blob delete options
284-
* @return {@code true} if blob was deleted, {@code false} if it was not found
284+
* @return true if blob was deleted
285285
* @throws StorageException upon failure
286286
*/
287287
public boolean delete(BlobSourceOption... options) {
@@ -422,8 +422,8 @@ public Blob apply(BlobInfo f) {
422422
* @param storage the storage service used to issue the request
423423
* @param blobs the blobs to delete
424424
* @return an immutable list of booleans. If a blob has been deleted the corresponding item in the
425-
* list is {@code true}. If a blob was not found, deletion failed or access to the resource
426-
* was denied the corresponding item is {@code false}.
425+
* list is {@code true}. If deletion failed or access to the resource was denied the item is
426+
* {@code false}.
427427
* @throws StorageException upon failure
428428
*/
429429
public static List<Boolean> delete(Storage storage, BlobId... blobs) {

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobReadChannel.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626
/**
2727
* A channel for reading data from a Google Cloud Storage object.
2828
*
29-
* Implementations of this class may buffer data internally to reduce remote calls.
30-
*
31-
* This class is @{link Serializable}, which allows incremental reads.
29+
* Implementations of this class may buffer data internally to reduce remote calls. This interface
30+
* implements {@link Restorable} to allow saving the reader's state to continue reading afterwards.
3231
*/
3332
public interface BlobReadChannel extends ReadableByteChannel, Closeable,
3433
Restorable<BlobReadChannel> {

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriteChannel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
* A channel for writing data to a Google Cloud Storage object.
2727
*
2828
* Implementations of this class may further buffer data internally to reduce remote calls. Written
29-
* data will only be visible after calling {@link #close()}. This class is serializable, to allow
30-
* incremental writes.
29+
* data will only be visible after calling {@link #close()}. This interface implements
30+
* {@link Restorable} to allow saving the writer's state to continue writing afterwards.
3131
*/
3232
public interface BlobWriteChannel extends WritableByteChannel, Closeable,
3333
Restorable<BlobWriteChannel> {

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public Bucket update(BucketInfo bucketInfo, BucketTargetOption... options) {
271271
* Deletes this bucket.
272272
*
273273
* @param options bucket delete options
274-
* @return {@code true} if bucket was deleted, {@code false} if it was not found
274+
* @return true if bucket was deleted
275275
* @throws StorageException upon failure
276276
*/
277277
public boolean delete(BucketSourceOption... options) {

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,31 +1316,31 @@ private static void checkContentType(BlobInfo blobInfo) throws IllegalArgumentEx
13161316
/**
13171317
* Delete the requested bucket.
13181318
*
1319-
* @return {@code true} if bucket was deleted, {@code false} if it was not found
1319+
* @return true if bucket was deleted
13201320
* @throws StorageException upon failure
13211321
*/
13221322
boolean delete(String bucket, BucketSourceOption... options);
13231323

13241324
/**
13251325
* Delete the requested blob.
13261326
*
1327-
* @return {@code true} if blob was deleted, {@code false} if it was not found
1327+
* @return true if blob was deleted
13281328
* @throws StorageException upon failure
13291329
*/
13301330
boolean delete(String bucket, String blob, BlobSourceOption... options);
13311331

13321332
/**
13331333
* Delete the requested blob.
13341334
*
1335-
* @return {@code true} if blob was deleted, {@code false} if it was not found
1335+
* @return true if blob was deleted
13361336
* @throws StorageException upon failure
13371337
*/
13381338
boolean delete(BlobId blob, BlobSourceOption... options);
13391339

13401340
/**
13411341
* Delete the requested blob.
13421342
*
1343-
* @return {@code true} if blob was deleted, {@code false} if it was not found
1343+
* @return true if blob was deleted
13441344
* @throws StorageException upon failure
13451345
*/
13461346
boolean delete(BlobId blob);
@@ -1478,8 +1478,8 @@ private static void checkContentType(BlobInfo blobInfo) throws IllegalArgumentEx
14781478
*
14791479
* @param blobIds blobs to delete
14801480
* @return an immutable list of booleans. If a blob has been deleted the corresponding item in the
1481-
* list is {@code true}. If a blob was not found, deletion failed or access to the resource
1482-
* was denied the corresponding item is {@code false}.
1481+
* list is {@code true}. If deletion failed or access to the resource was denied the item is
1482+
* {@code false}.
14831483
* @throws StorageException upon failure
14841484
*/
14851485
List<Boolean> delete(BlobId... blobIds);

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static com.google.gcloud.spi.StorageRpc.Option.IF_SOURCE_GENERATION_NOT_MATCH;
2929
import static com.google.gcloud.spi.StorageRpc.Option.IF_SOURCE_METAGENERATION_MATCH;
3030
import static com.google.gcloud.spi.StorageRpc.Option.IF_SOURCE_METAGENERATION_NOT_MATCH;
31+
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
3132
import static java.nio.charset.StandardCharsets.UTF_8;
3233

3334
import com.google.api.services.storage.model.StorageObject;
@@ -176,7 +177,14 @@ public BucketInfo get(String bucket, BucketGetOption... options) {
176177
new Callable<com.google.api.services.storage.model.Bucket>() {
177178
@Override
178179
public com.google.api.services.storage.model.Bucket call() {
179-
return storageRpc.get(bucketPb, optionsMap);
180+
try {
181+
return storageRpc.get(bucketPb, optionsMap);
182+
} catch (StorageException ex) {
183+
if (ex.code() == HTTP_NOT_FOUND) {
184+
return null;
185+
}
186+
throw ex;
187+
}
180188
}
181189
}, options().retryParams(), EXCEPTION_HANDLER);
182190
return answer == null ? null : BucketInfo.fromPb(answer);
@@ -198,7 +206,14 @@ public BlobInfo get(BlobId blob, BlobGetOption... options) {
198206
StorageObject storageObject = runWithRetries(new Callable<StorageObject>() {
199207
@Override
200208
public StorageObject call() {
201-
return storageRpc.get(storedObject, optionsMap);
209+
try {
210+
return storageRpc.get(storedObject, optionsMap);
211+
} catch (StorageException ex) {
212+
if (ex.code() == HTTP_NOT_FOUND) {
213+
return null;
214+
}
215+
throw ex;
216+
}
202217
}
203218
}, options().retryParams(), EXCEPTION_HANDLER);
204219
return storageObject == null ? null : BlobInfo.fromPb(storageObject);
@@ -510,23 +525,28 @@ public BatchResponse apply(BatchRequest batchRequest) {
510525
List<BatchResponse.Result<BlobInfo>> updates = transformBatchResult(
511526
toUpdate, response.updates, BlobInfo.FROM_PB_FUNCTION);
512527
List<BatchResponse.Result<BlobInfo>> gets = transformBatchResult(
513-
toGet, response.gets, BlobInfo.FROM_PB_FUNCTION);
528+
toGet, response.gets, BlobInfo.FROM_PB_FUNCTION, HTTP_NOT_FOUND);
514529
return new BatchResponse(deletes, updates, gets);
515530
}
516531

517532
private <I, O extends Serializable> List<BatchResponse.Result<O>> transformBatchResult(
518533
Iterable<Tuple<StorageObject, Map<StorageRpc.Option, ?>>> request,
519-
Map<StorageObject, Tuple<I, StorageException>> results, Function<I, O> transform) {
534+
Map<StorageObject, Tuple<I, StorageException>> results, Function<I, O> transform,
535+
int... nullOnErrorCodes) {
536+
Set nullOnErrorCodesSet = Sets.newHashSet(Ints.asList(nullOnErrorCodes));
520537
List<BatchResponse.Result<O>> response = Lists.newArrayListWithCapacity(results.size());
521538
for (Tuple<StorageObject, ?> tuple : request) {
522539
Tuple<I, StorageException> result = results.get(tuple.x());
523-
I object = result.x();
524-
StorageException exception = result.y();
525-
if (exception != null) {
526-
response.add(new BatchResponse.Result<O>(exception));
540+
if (result.x() != null) {
541+
response.add(BatchResponse.Result.of(transform.apply(result.x())));
527542
} else {
528-
response.add(object != null ?
529-
BatchResponse.Result.of(transform.apply(object)) : BatchResponse.Result.<O>empty());
543+
StorageException exception = result.y();
544+
if (nullOnErrorCodesSet.contains(exception.code())) {
545+
//noinspection unchecked
546+
response.add(BatchResponse.Result.<O>empty());
547+
} else {
548+
response.add(new BatchResponse.Result<O>(exception));
549+
}
530550
}
531551
}
532552
return response;

branches/pubsub-alpha/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,7 @@ public void testBatchRequestFail() {
644644
assertFalse(batchResponse.gets().get(1).failed());
645645
assertNull(batchResponse.gets().get(1).get());
646646
assertTrue(batchResponse.deletes().get(0).failed());
647-
assertFalse(batchResponse.deletes().get(1).failed());
648-
assertFalse(batchResponse.deletes().get(1).get());
647+
assertTrue(batchResponse.deletes().get(1).failed());
649648
assertTrue(storage.delete(BUCKET, blobName));
650649
}
651650

0 commit comments

Comments
 (0)