Search in sources :

Example 76 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project hadoop by apache.

the class TestS3AGetFileStatus method testFile.

@Test
public void testFile() throws Exception {
    Path path = new Path("/file");
    String key = path.toUri().getPath().substring(1);
    ObjectMetadata meta = new ObjectMetadata();
    meta.setContentLength(1L);
    meta.setLastModified(new Date(2L));
    when(s3.getObjectMetadata(argThat(correctGetMetadataRequest(BUCKET, key)))).thenReturn(meta);
    FileStatus stat = fs.getFileStatus(path);
    assertNotNull(stat);
    assertEquals(fs.makeQualified(path), stat.getPath());
    assertTrue(stat.isFile());
    assertEquals(meta.getContentLength(), stat.getLen());
    assertEquals(meta.getLastModified().getTime(), stat.getModificationTime());
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Date(java.util.Date) Test(org.junit.Test)

Example 77 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project hadoop by apache.

the class S3AFileSystem method newObjectMetadata.

/**
   * Create a new object metadata instance.
   * Any standard metadata headers are added here, for example:
   * encryption.
   * @return a new metadata instance
   */
public ObjectMetadata newObjectMetadata() {
    final ObjectMetadata om = new ObjectMetadata();
    setOptionalObjectMetadata(om);
    return om;
}
Also used : ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 78 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project ignite by apache.

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)

Example 79 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project stocator by SparkTC.

the class COSBlockOutputStream method putObject.

/**
 * Upload the current block as a single PUT request; if the buffer is empty a
 * 0-byte PUT will be invoked, as it is needed to create an entry at the far
 * end.
 *
 * @throws IOException any problem
 */
private void putObject() throws IOException {
    LOG.debug("Executing regular upload for {}", writeOperationHelper);
    final COSDataBlocks.DataBlock block = getActiveBlock();
    int size = block.dataSize();
    final COSDataBlocks.BlockUploadData uploadData = block.startUpload();
    final PutObjectRequest putObjectRequest = uploadData.hasFile() ? writeOperationHelper.newPutRequest(uploadData.getFile()) : writeOperationHelper.newPutRequest(uploadData.getUploadStream(), size);
    final ObjectMetadata om = new ObjectMetadata();
    om.setUserMetadata(mMetadata);
    if (contentType != null && !contentType.isEmpty()) {
        om.setContentType(contentType);
    } else {
        om.setContentType("application/octet-stream");
    }
    putObjectRequest.setMetadata(om);
    ListenableFuture<PutObjectResult> putObjectResult = executorService.submit(new Callable<PutObjectResult>() {

        @Override
        public PutObjectResult call() throws Exception {
            PutObjectResult result;
            try {
                // the putObject call automatically closes the input
                // stream afterwards.
                result = writeOperationHelper.putObject(putObjectRequest);
            } finally {
                closeAll(LOG, uploadData, block);
            }
            return result;
        }
    });
    clearActiveBlock();
    // wait for completion
    try {
        putObjectResult.get();
    } catch (InterruptedException ie) {
        LOG.warn("Interrupted object upload", ie);
        Thread.currentThread().interrupt();
    } catch (ExecutionException ee) {
        throw extractException("regular upload", key, ee);
    }
}
Also used : PutObjectResult(com.amazonaws.services.s3.model.PutObjectResult) COSUtils.extractException(com.ibm.stocator.fs.cos.COSUtils.extractException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) COSUtils.translateException(com.ibm.stocator.fs.cos.COSUtils.translateException) AmazonClientException(com.amazonaws.AmazonClientException) ExecutionException(java.util.concurrent.ExecutionException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 80 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project hippo by NHS-digital-website.

the class S3ObjectMetadataImplTest method shouldReturnMetadata.

@Test
public void shouldReturnMetadata() {
    String bucketName = "test.bucket";
    String objectKey = "A3/C814DE/test.pdf";
    String contentType = "test/type";
    long size = 123456;
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentType(contentType);
    metadata.setContentLength(size);
    S3ObjectMetadata actual = new S3ObjectMetadataImpl(metadata, bucketName, objectKey);
    assertThat("file name is correct", actual.getFileName(), equalTo("test.pdf"));
    assertThat("reference is correct", actual.getReference(), equalTo(objectKey));
    assertThat("content type is correct", actual.getMimeType(), equalTo(contentType));
    assertThat("url is correct", actual.getUrl(), equalTo("https://" + bucketName + "/" + objectKey));
    assertThat("size is correct", actual.getSize(), equalTo(size));
}
Also used : ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Test(org.junit.Test)

Aggregations

ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)75 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)26 IOException (java.io.IOException)19 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)18 AmazonClientException (com.amazonaws.AmazonClientException)17 AmazonServiceException (com.amazonaws.AmazonServiceException)17 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)10 Upload (com.amazonaws.services.s3.transfer.Upload)10 ByteArrayInputStream (java.io.ByteArrayInputStream)10 InputStream (java.io.InputStream)9 Copy (com.amazonaws.services.s3.transfer.Copy)8 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)7 File (java.io.File)5 InterruptedIOException (java.io.InterruptedIOException)5 Date (java.util.Date)5 Path (org.apache.hadoop.fs.Path)5 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)4 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)3 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)3 InitiateMultipartUploadRequest (com.amazonaws.services.s3.model.InitiateMultipartUploadRequest)3