/** * @param bucketName the name of the bucket to check * @return whether requester pays is enabled for that bucket */ public boolean requesterPays(String bucketName) { initStorage(); try { // instead of true/false, this method returns true/null. Boolean isRP = storage.get(bucketName).requesterPays(); return isRP != null && isRP.booleanValue(); } catch (StorageException ex) { if (ex.getCode() == 400 && ex.getMessage().contains("Bucket is requester pays")) { return true; } throw ex; } }
private void assertIsRequesterPaysException(String message, StorageException ex) { Assert.assertEquals(message, ex.getCode(), 400); Assert.assertTrue( message, ex.getMessage().contains("Bucket is requester pays bucket but no user project provided")); }
private IOException asIoException(StorageException oops) { // RPC API can only throw StorageException, but CloudStorageFileSystemProvider // can only throw IOException. Square peg, round hole. // TODO(#810): Research if other codes should be translated similarly. if (oops.getCode() == 404) { return new NoSuchFileException(oops.getReason()); } Throwable cause = oops.getCause(); try { if (cause instanceof FileAlreadyExistsException) { throw new FileAlreadyExistsException(((FileAlreadyExistsException) cause).getReason()); } // fallback if (cause != null && cause instanceof IOException) { return (IOException) cause; } } catch (IOException okEx) { return okEx; } return new IOException(oops.getMessage(), oops); } }
@Test public void testReadGenerationChanged() throws IOException { BlobId blobId = BlobId.of(BUCKET_NAME, BLOB_NAME); reader = new BlobReadChannel(options, blobId, EMPTY_RPC_OPTIONS); byte[] firstResult = randomByteArray(DEFAULT_CHUNK_SIZE); byte[] secondResult = randomByteArray(DEFAULT_CHUNK_SIZE); ByteBuffer firstReadBuffer = ByteBuffer.allocate(DEFAULT_CHUNK_SIZE); ByteBuffer secondReadBuffer = ByteBuffer.allocate(DEFAULT_CHUNK_SIZE); expect(storageRpcMock.read(blobId.toPb(), EMPTY_RPC_OPTIONS, 0, DEFAULT_CHUNK_SIZE)) .andReturn(Tuple.of("etag1", firstResult)); expect( storageRpcMock.read( blobId.toPb(), EMPTY_RPC_OPTIONS, DEFAULT_CHUNK_SIZE, DEFAULT_CHUNK_SIZE)) .andReturn(Tuple.of("etag2", secondResult)); replay(storageRpcMock); reader.read(firstReadBuffer); try { reader.read(secondReadBuffer); fail("Expected ReadChannel read to throw StorageException"); } catch (StorageException ex) { StringBuilder messageBuilder = new StringBuilder(); messageBuilder.append("Blob ").append(blobId).append(" was updated while reading"); assertEquals(messageBuilder.toString(), ex.getMessage()); } }
new Object[]{ffFilename, bucket, key, e.getMessage()}, e); throw (e);
getLogger().error(e.getMessage(), e); flowFile = session.penalize(flowFile); session.transfer(flowFile, REL_FAILURE);
StringBuilder messageBuilder = new StringBuilder(); messageBuilder.append("Blob ").append(blob.getBlobId()).append(" was updated while reading"); assertEquals(messageBuilder.toString(), ex.getMessage());
@Test public void testDeleteBlobNonExistingGeneration() { String blobName = "test-delete-blob-non-existing-generation"; BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).build(); assertNotNull(storage.create(blob)); try { assertFalse(storage.delete(BlobId.of(BUCKET, blobName, -1L))); fail("Expected an 'Invalid argument' exception"); } catch (StorageException e) { assertThat(e.getMessage()).contains("Invalid argument"); } }
@Test public void testGetBlobFailNonExistingGeneration() { String blobName = "test-get-blob-fail-non-existing-generation"; BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).build(); Blob remoteBlob = storage.create(blob); assertNotNull(remoteBlob); BlobId wrongGenerationBlob = BlobId.of(BUCKET, blobName, -1L); try { assertNull(storage.get(wrongGenerationBlob)); fail("Expected an 'Invalid argument' exception"); } catch (StorageException e) { assertThat(e.getMessage()).contains("Invalid argument"); } }
fail("Expected bad user project error."); } catch (StorageException e) { assertTrue(e.getMessage().contains("User project specified in the request is invalid"));
fail("Expected an 'Invalid argument' exception"); } catch (StorageException e) { assertThat(e.getMessage()).contains("Invalid argument"); fail("Expected an 'Invalid argument' exception"); } catch (StorageException e) { assertThat(e.getMessage()).contains("Invalid argument");
fail("Expected an 'Invalid argument' exception"); } catch (StorageException e) { assertThat(e.getMessage()).contains("Invalid argument"); fail("Expected an 'Invalid argument' exception"); } catch (StorageException e) { assertThat(e.getMessage()).contains("Invalid argument");
StorageException exception = new StorageException(500, "message"); assertEquals(500, exception.getCode()); assertEquals("message", exception.getMessage()); assertNull(exception.getReason()); assertTrue(exception.isRetryable()); assertEquals("message", exception.getMessage()); assertNull(exception.getReason()); assertTrue(exception.isRetryable()); assertEquals("message", exception.getMessage()); assertNull(exception.getReason()); assertTrue(exception.isRetryable()); assertEquals("message", exception.getMessage()); assertNull(exception.getReason()); assertTrue(exception.isRetryable()); assertEquals("message", exception.getMessage()); assertNull(exception.getReason()); assertTrue(exception.isRetryable()); assertEquals("message", exception.getMessage()); assertNull(exception.getReason()); assertTrue(exception.isRetryable()); assertEquals("message", exception.getMessage()); assertNull(exception.getReason()); assertFalse(exception.isRetryable());
return true; } catch (StorageException se) { LOG.warn("{} Couldn't upload {} due to {}", logIdentifier, file, se.getMessage(), se); throw se; } catch (Exception e) {
private IOException asIoException(StorageException oops) { // RPC API can only throw StorageException, but CloudStorageFileSystemProvider // can only throw IOException. Square peg, round hole. // TODO(#810): Research if other codes should be translated similarly. if (oops.getCode() == 404) { return new NoSuchFileException(oops.getReason()); } Throwable cause = oops.getCause(); try { if (cause instanceof FileAlreadyExistsException) { throw new FileAlreadyExistsException(((FileAlreadyExistsException) cause).getReason()); } // fallback Throwables.propagateIfInstanceOf(oops.getCause(), IOException.class); } catch (IOException okEx) { return okEx; } return new IOException(oops.getMessage(), oops); } }
log.warn( "StorageException when performing GCS bucket list operation, with message: " + se.getMessage());
log.warn( "StorageException when performing GCS blob list operation, with message: " + se.getMessage()); }); return;