use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project trellis-extensions by trellis-ldp.
the class S3MementoServiceTest method testResourceError.
@Test
void testResourceError() {
final AmazonS3 mockClient = mock(AmazonS3.class);
final ObjectMetadata mockMetadata = mock(ObjectMetadata.class);
final GetObjectRequest mockRequest = mock(GetObjectRequest.class);
final S3Object mockObject = mock(S3Object.class);
when(mockClient.getObject(eq(mockRequest))).thenReturn(mockObject);
when(mockObject.getObjectContent()).thenAnswer(inv -> {
throw new IOException("Expected");
});
final Resource testResource = new S3Resource(mockMetadata, mockClient, mockRequest, "");
assertThrows(TrellisRuntimeException.class, testResource::stream);
}
use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project nrtsearch by Yelp.
the class ContentDownloaderImpl method getVersionContent.
@Override
public void getVersionContent(final String serviceName, final String resource, final String hash, final Path destDirectory) throws IOException {
final String absoluteResourcePath = String.format("%s/%s/%s", serviceName, resource, hash);
final Path parentDirectory = destDirectory.getParent();
final Path tmpFile = parentDirectory.resolve(getTmpName());
final InputStream s3InputStream;
if (downloadAsStream) {
// Stream the file download from s3 instead of writing to a file first
GetObjectMetadataRequest metadataRequest = new GetObjectMetadataRequest(bucketName, absoluteResourcePath);
ObjectMetadata fullMetadata = transferManager.getAmazonS3Client().getObjectMetadata(metadataRequest);
logger.debug("Full object size: " + fullMetadata.getContentLength());
// get metadata for the 1st file part, needed to find the total number of parts
ObjectMetadata partMetadata = transferManager.getAmazonS3Client().getObjectMetadata(metadataRequest.withPartNumber(1));
int numParts = partMetadata.getPartCount() != null ? partMetadata.getPartCount() : 1;
logger.debug("Object parts: " + numParts);
s3InputStream = getObjectStream(absoluteResourcePath, numParts);
logger.debug("Object streaming started...");
} else {
Download download = transferManager.download(new GetObjectRequest(bucketName, absoluteResourcePath), tmpFile.toFile(), new ContentDownloaderImpl.S3ProgressListenerImpl(serviceName, resource, "download"));
try {
download.waitForCompletion();
logger.debug("S3 Download complete");
} catch (InterruptedException e) {
throw new IOException("S3 Download failed", e);
}
s3InputStream = new FileInputStream(tmpFile.toFile());
}
wrapInputStream(destDirectory, parentDirectory, tmpFile, s3InputStream, hash);
}
use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project nrtsearch by Yelp.
the class TarEntry method uploadToS3.
public static void uploadToS3(AmazonS3 s3, String bucketName, List<TarEntry> tarEntries, String key) throws IOException {
byte[] tarContent = getTarFile(tarEntries);
final ObjectMetadata objectMetadata = new ObjectMetadata();
try (final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(tarContent)) {
s3.putObject(bucketName, key, byteArrayInputStream, objectMetadata);
}
}
use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project nuxeo-coldstorage by nuxeo.
the class S3TestHelper method isBlobContentBeingRetrieved.
/**
* Checks if the document's S3 blob is being retrieved.
*
* @param document the document
* @return {@code true} if the blob's document is being retrieved from {@code Glacier} storage, {@code false}
* otherwise
*/
public boolean isBlobContentBeingRetrieved(DocumentModel document) {
boolean restoreFlag = false;
AmazonS3 amazonS3 = getAmazonS3("glacier");
String blobKey = getBlobKey(document, ColdStorageConstants.COLD_STORAGE_CONTENT_PROPERTY);
log.info("ColdStorage Blob key {}", blobKey);
if (amazonS3.doesObjectExist(glacierBucket, blobKey)) {
ObjectMetadata response = amazonS3.getObjectMetadata(glacierBucket, blobKey);
restoreFlag = response.getOngoingRestore();
} else {
log.info("ColdStorage Blob key {} doesn't exist", blobKey);
}
return restoreFlag;
}
use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project gridgain by gridgain.
the class S3CheckpointSpi method write.
/**
* Writes given checkpoint data to a given S3 bucket. Data is serialized to
* the binary stream and saved to the S3.
*
* @param data Checkpoint data.
* @throws IgniteCheckedException Thrown if an error occurs while marshalling.
* @throws AmazonClientException If an error occurs while querying Amazon S3.
*/
private void write(S3CheckpointData data) throws IgniteCheckedException, AmazonClientException {
assert data != null;
if (log.isDebugEnabled())
log.debug("Writing data to S3 [bucket=" + bucketName + ", key=" + data.getKey() + ']');
byte[] buf = data.toBytes();
ObjectMetadata meta = new ObjectMetadata();
meta.setContentLength(buf.length);
if (!F.isEmpty(sseAlg))
meta.setSSEAlgorithm(sseAlg);
s3.putObject(bucketName, data.getKey(), new ByteArrayInputStream(buf), meta);
}
Aggregations