use of com.microsoft.azure.storage.blob.models.BlobGetPropertiesResponse in project geowebcache by GeoWebCache.
the class AzureBlobStore method put.
@Override
public void put(TileObject obj) throws StorageException {
final Resource blob = obj.getBlob();
checkNotNull(blob);
checkNotNull(obj.getBlobFormat());
final String key = keyBuilder.forTile(obj);
BlockBlobURL blobURL = client.getBlockBlobURL(key);
// if there are listeners, gather first the old size with a "head" request
Long oldSize = null;
boolean existed = false;
if (!listeners.isEmpty()) {
try {
BlobGetPropertiesResponse properties = blobURL.getProperties().blockingGet();
oldSize = properties.headers().contentLength();
existed = true;
} catch (RestException e) {
if (e.response().statusCode() != HttpStatus.NOT_FOUND.value()) {
throw new StorageException("Failed to check if the container exists", e);
}
}
}
// then upload
try (InputStream is = blob.getInputStream()) {
byte[] bytes = IOUtils.toByteArray(is);
ByteBuffer buffer = ByteBuffer.wrap(bytes);
String mimeType = MimeType.createFromFormat(obj.getBlobFormat()).getMimeType();
BlobHTTPHeaders headers = new BlobHTTPHeaders().withBlobContentType(mimeType);
int status = blobURL.upload(Flowable.just(buffer), bytes.length, headers, null, null, null).blockingGet().statusCode();
if (!HttpStatus.valueOf(status).is2xxSuccessful()) {
throw new StorageException("Failed to upload tile to Azure on container " + client.getContainerName() + " and key " + key + " got HTTP status " + status);
}
} catch (RestException | IOException | MimeException e) {
throw new StorageException("Failed to upload tile to Azure on container " + client.getContainerName() + " and key " + key, e);
}
// along with the metadata
putParametersMetadata(obj.getLayerName(), obj.getParametersId(), obj.getParameters());
// This is important because listeners may be tracking tile existence
if (!listeners.isEmpty()) {
if (existed) {
listeners.sendTileUpdated(obj, oldSize);
} else {
listeners.sendTileStored(obj);
}
}
}
use of com.microsoft.azure.storage.blob.models.BlobGetPropertiesResponse in project geowebcache by GeoWebCache.
the class AzureBlobStore method delete.
@Override
public boolean delete(TileObject obj) throws StorageException {
final String key = keyBuilder.forTile(obj);
BlockBlobURL blob = client.getBlockBlobURL(key);
// don't bother for the extra call if there are no listeners
if (listeners.isEmpty()) {
try {
int statusCode = blob.delete().blockingGet().statusCode();
return HttpStatus.valueOf(statusCode).is2xxSuccessful();
} catch (RestException e) {
return false;
}
}
try {
// if there are listeners, gather extra information
BlobGetPropertiesResponse properties = blob.getProperties().blockingGet();
Long oldSize = properties.headers().contentLength();
int statusCode = blob.delete().blockingGet().statusCode();
if (!HttpStatus.valueOf(statusCode).is2xxSuccessful()) {
return false;
}
if (oldSize != null) {
obj.setBlobSize(oldSize.intValue());
}
} catch (RestException e) {
if (e.response().statusCode() != 404) {
throw new StorageException("Failed to delete tile ", e);
}
return false;
}
listeners.sendTileDeleted(obj);
return true;
}
Aggregations