Search in sources :

Example 56 with ObjectMetadata

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);
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) Resource(org.trellisldp.api.Resource) S3Object(com.amazonaws.services.s3.model.S3Object) IOException(java.io.IOException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) Test(org.junit.jupiter.api.Test)

Example 57 with ObjectMetadata

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);
}
Also used : Path(java.nio.file.Path) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) GzipCompressorInputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) LZ4FrameInputStream(net.jpountz.lz4.LZ4FrameInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) GetObjectMetadataRequest(com.amazonaws.services.s3.model.GetObjectMetadataRequest) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Download(com.amazonaws.services.s3.transfer.Download) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest)

Example 58 with ObjectMetadata

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 59 with 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;
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 60 with ObjectMetadata

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Aggregations

ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)566 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)191 ByteArrayInputStream (java.io.ByteArrayInputStream)157 Test (org.junit.Test)143 IOException (java.io.IOException)101 InputStream (java.io.InputStream)80 File (java.io.File)62 AmazonClientException (com.amazonaws.AmazonClientException)61 AmazonServiceException (com.amazonaws.AmazonServiceException)61 S3Object (com.amazonaws.services.s3.model.S3Object)59 AmazonS3 (com.amazonaws.services.s3.AmazonS3)54 Date (java.util.Date)46 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)34 GetObjectMetadataRequest (com.amazonaws.services.s3.model.GetObjectMetadataRequest)33 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)32 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)30 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)29 Upload (com.amazonaws.services.s3.transfer.Upload)26 SdkClientException (com.amazonaws.SdkClientException)24 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)24