public void clear() throws StorageException { throw new StorageException("Not implemented yet!"); }
private LiveStore defaultStore() throws StorageException { LiveStore store = blobStores.get(CompositeBlobStore.DEFAULT_STORE_DEFAULT_ID); if (store == null) { throw new StorageException("No default BlobStore has been defined"); } return store; }
@Nullable public byte[] getBytes(String key) throws StorageException { S3Object object = getObject(key); if (object == null) { return null; } try (S3ObjectInputStream in = object.getObjectContent()) { byte[] bytes = IOUtils.toByteArray(in); return bytes; } catch (IOException e) { throw new StorageException("Error getting " + key, e); } }
@Nullable public byte[] getBytes(String key) throws StorageException { S3Object object = getObject(key); if (object == null) { return null; } try (S3ObjectInputStream in = object.getObjectContent()) { byte[] bytes = IOUtils.toByteArray(in); return bytes; } catch (IOException e) { throw new StorageException("Error getting " + key, e); } }
private void closeObject(S3Object object) throws StorageException { try { object.close(); } catch (IOException e) { throw new StorageException( "Error closing connection to " + object.getKey() + ": " + e.getMessage(), e); } }
private void closeObject(S3Object object) throws StorageException { try { object.close(); } catch (IOException e) { throw new StorageException( "Error closing connection to " + object.getKey() + ": " + e.getMessage(), e); } }
public void putObject(PutObjectRequest putObjectRequest) throws StorageException { try { conn.putObject(putObjectRequest); } catch (RuntimeException e) { throw new StorageException("Error storing " + putObjectRequest.getKey(), e); } }
public void putObject(PutObjectRequest putObjectRequest) throws StorageException { try { conn.putObject(putObjectRequest); } catch (RuntimeException e) { throw new StorageException("Error storing " + putObjectRequest.getKey(), e); } }
private BlobStore store(String layerId) throws StorageException { LiveStore store; try { store = forLayer(layerId); } catch (GeoWebCacheException e) { throw new StorageException(e.getMessage(), e); } if (!store.config.isEnabled()) { throw new StorageException( "Attempted to use a blob store that's disabled: " + store.config.getName()); } return store.liveInstance; }
private ByteArrayInputStream toByteArray(final Resource blob) throws StorageException { final byte[] bytes; if (blob instanceof ByteArrayResource) { bytes = ((ByteArrayResource) blob).getContents(); } else { ByteArrayOutputStream out = new ByteArrayOutputStream((int) blob.getSize()); WritableByteChannel channel = Channels.newChannel(out); try { blob.transferTo(channel); } catch (IOException e) { throw new StorageException("Error copying blob contents", e); } bytes = out.toByteArray(); } ByteArrayInputStream input = new ByteArrayInputStream(bytes); return input; }
@Nullable public ObjectMetadata getObjectMetadata(String key) throws StorageException { ObjectMetadata obj = null; try { obj = conn.getObjectMetadata(bucketName, key); } catch (AmazonS3Exception e) { if (404 != e.getStatusCode()) { // 404 == not found throw new StorageException( "Error checking existence of " + key + ": " + e.getMessage(), e); } } return obj; }
@Nullable public ObjectMetadata getObjectMetadata(String key) throws StorageException { ObjectMetadata obj = null; try { obj = conn.getObjectMetadata(bucketName, key); } catch (AmazonS3Exception e) { if (404 != e.getStatusCode()) { // 404 == not found throw new StorageException( "Error checking existence of " + key + ": " + e.getMessage(), e); } } return obj; }
@Nullable public S3Object getObject(String key) throws StorageException { final S3Object object; try { object = conn.getObject(bucketName, key); } catch (AmazonS3Exception e) { if (404 == e.getStatusCode()) { // 404 == not found return null; } throw new StorageException("Error fetching " + key + ": " + e.getMessage(), e); } if (isPendingDelete(object)) { closeObject(object); return null; } return object; }
@Nullable public S3Object getObject(String key) throws StorageException { final S3Object object; try { object = conn.getObject(bucketName, key); } catch (AmazonS3Exception e) { if (404 == e.getStatusCode()) { // 404 == not found return null; } throw new StorageException("Error fetching " + key + ": " + e.getMessage(), e); } if (isPendingDelete(object)) { closeObject(object); return null; } return object; }
public BlobStore setup() throws Exception { File fh = new File(StorageBrokerTest.findTempDir() + File.separator + TEST_BLOB_DIR_NAME); if (!fh.exists()) { Files.createDirectory(fh.toPath()); if (!fh.exists()) { System.out.println( "Unable to create " + org.geowebcache.util.FileUtils.printFileTree(fh)); throw new StorageException("Unable to create " + fh.getAbsolutePath()); } } return new FileBlobStore( StorageBrokerTest.findTempDir() + File.separator + TEST_BLOB_DIR_NAME); }
@Override public boolean get(TileObject obj) throws StorageException { final String key = keyBuilder.forTile(obj); final S3Object object = s3Ops.getObject(key); if (object == null) { return false; } try (S3ObjectInputStream in = object.getObjectContent()) { byte[] bytes = ByteStreams.toByteArray(in); obj.setBlobSize(bytes.length); obj.setBlob(new ByteArrayResource(bytes)); obj.setCreated(object.getObjectMetadata().getLastModified().getTime()); } catch (IOException e) { throw new StorageException("Error getting " + key, e); } return true; }
@Override public boolean get(TileObject obj) throws StorageException { final String key = keyBuilder.forTile(obj); final S3Object object = s3Ops.getObject(key); if (object == null) { return false; } try (S3ObjectInputStream in = object.getObjectContent()) { byte[] bytes = ByteStreams.toByteArray(in); obj.setBlobSize(bytes.length); obj.setBlob(new ByteArrayResource(bytes)); obj.setCreated(object.getObjectMetadata().getLastModified().getTime()); } catch (IOException e) { throw new StorageException("Error getting " + key, e); } return true; }
public void testLayerRenamed() throws Exception { mediator.layerRenamed("old", "new"); verify(storageBroker, times(1)).rename(eq("old"), eq("new")); doThrow(new StorageException("target directory already exists")).when(storageBroker) .rename(eq("old"), eq("new")); try { mediator.layerRenamed("old", "new"); fail("Expected RTE"); } catch (RuntimeException e) { assertTrue(e.getCause() instanceof StorageException); } }
public void testDeleteCacheByGridSetId() throws Exception { when(storageBroker.deleteByGridSetId(eq("layer"), eq("gset1"))).thenThrow( new StorageException("fake")); try { mediator.deleteCacheByGridSetId("layer", "gset1"); fail(); } catch (RuntimeException e) { assertTrue(true); } mediator.deleteCacheByGridSetId("layer", "gset2"); verify(storageBroker, times(1)).deleteByGridSetId(eq("layer"), eq("gset2")); }
public void testLayerRemoved() throws Exception { mediator.layerRemoved("someLayer"); verify(storageBroker, times(1)).delete(eq("someLayer")); doThrow(new StorageException("fake")).when(storageBroker).delete(eq("anotherLayer")); try { mediator.layerRemoved("anotherLayer"); fail("Expected RTE"); } catch (RuntimeException e) { assertTrue(e.getCause() instanceof StorageException); } }