/** * {@inheritDoc} */ @Override public BlobContainer blobContainer(BlobPath path) { try { return new URLBlobContainer(this, path, buildPath(path)); } catch (MalformedURLException ex) { throw new BlobStoreException("malformed URL " + path, ex); } }
/** * {@inheritDoc} */ @Override public BlobContainer blobContainer(BlobPath path) { try { return new URLBlobContainer(this, path, buildPath(path)); } catch (MalformedURLException ex) { throw new BlobStoreException("malformed URL " + path, ex); } }
@Override public boolean blobExists(String blobName) { try { blobStore.client().getObjectMetadata(blobStore.bucket(), buildKey(blobName)); return true; } catch (AmazonS3Exception e) { return false; } catch (Throwable e) { throw new BlobStoreException("failed to check if blob exists", e); } }
@Override public InputStream openInput(String blobName) throws IOException { int retry = 0; while (retry <= blobStore.numberOfRetries()) { try { S3Object s3Object = blobStore.client().getObject(blobStore.bucket(), buildKey(blobName)); return s3Object.getObjectContent(); } catch (AmazonClientException e) { if (blobStore.shouldRetry(e) && (retry < blobStore.numberOfRetries())) { retry++; } else { if (e instanceof AmazonS3Exception) { if (404 == ((AmazonS3Exception) e).getStatusCode()) { throw new FileNotFoundException("Blob object [" + blobName + "] not found: " + e.getMessage()); } } throw e; } } } throw new BlobStoreException("retries exhausted while attempting to access blob object [name:" + blobName + ", bucket:" + blobStore.bucket() +"]"); }
public S3BlobStore(Settings settings, AmazonS3 client, String bucket, @Nullable String region, boolean serverSideEncryption, ByteSizeValue bufferSize, int maxRetries) { super(settings); this.client = client; this.bucket = bucket; this.region = region; this.serverSideEncryption = serverSideEncryption; this.bufferSize = (bufferSize != null) ? bufferSize : MIN_BUFFER_SIZE; if (this.bufferSize.getBytes() < MIN_BUFFER_SIZE.getBytes()) { throw new BlobStoreException("Detected a buffer_size for the S3 storage lower than [" + MIN_BUFFER_SIZE + "]"); } this.numberOfRetries = maxRetries; if (!client.doesBucketExist(bucket)) { if (region != null) { client.createBucket(bucket, region); } else { client.createBucket(bucket); } } }