Search in sources :

Example 6 with ObjectMetadata

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

the class TestS3AGetFileStatus method testFakeDirectory.

@Test
public void testFakeDirectory() throws Exception {
    Path path = new Path("/dir");
    String key = path.toUri().getPath().substring(1);
    when(s3.getObjectMetadata(argThat(correctGetMetadataRequest(BUCKET, key)))).thenThrow(NOT_FOUND);
    ObjectMetadata meta = new ObjectMetadata();
    meta.setContentLength(0L);
    when(s3.getObjectMetadata(argThat(correctGetMetadataRequest(BUCKET, key + "/")))).thenReturn(meta);
    FileStatus stat = fs.getFileStatus(path);
    assertNotNull(stat);
    assertEquals(fs.makeQualified(path), stat.getPath());
    assertTrue(stat.isDirectory());
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Test(org.junit.Test)

Example 7 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project elasticsearch by elastic.

the class TestAmazonS3 method putObject.

@Override
public PutObjectResult putObject(String bucketName, String key, InputStream input, ObjectMetadata metadata) throws AmazonClientException, AmazonServiceException {
    if (shouldFail(bucketName, key, writeFailureRate)) {
        long length = metadata.getContentLength();
        long partToRead = (long) (length * randomDouble());
        byte[] buffer = new byte[1024];
        for (long cur = 0; cur < partToRead; cur += buffer.length) {
            try {
                input.read(buffer, 0, (int) (partToRead - cur > buffer.length ? buffer.length : partToRead - cur));
            } catch (IOException ex) {
                throw new ElasticsearchException("cannot read input stream", ex);
            }
        }
        logger.info("--> random write failure on putObject method: throwing an exception for [bucket={}, key={}]", bucketName, key);
        AmazonS3Exception ex = new AmazonS3Exception("Random S3 exception");
        ex.setStatusCode(400);
        ex.setErrorCode("RequestTimeout");
        throw ex;
    } else {
        return super.putObject(bucketName, key, input, metadata);
    }
}
Also used : IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception)

Example 8 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project elasticsearch by elastic.

the class DefaultS3OutputStream method doUpload.

protected void doUpload(S3BlobStore blobStore, String bucketName, String blobName, InputStream is, int length, boolean serverSideEncryption) throws AmazonS3Exception {
    ObjectMetadata md = new ObjectMetadata();
    if (serverSideEncryption) {
        md.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
    }
    md.setContentLength(length);
    InputStream inputStream = is;
    // We try to compute a MD5 while reading it
    MessageDigest messageDigest;
    try {
        messageDigest = MessageDigest.getInstance("MD5");
        inputStream = new DigestInputStream(is, messageDigest);
    } catch (NoSuchAlgorithmException impossible) {
        // Every implementation of the Java platform is required to support MD5 (see MessageDigest)
        throw new RuntimeException(impossible);
    }
    PutObjectRequest putRequest = new PutObjectRequest(bucketName, blobName, inputStream, md).withStorageClass(blobStore.getStorageClass()).withCannedAcl(blobStore.getCannedACL());
    PutObjectResult putObjectResult = blobStore.client().putObject(putRequest);
    String localMd5 = Base64.encodeAsString(messageDigest.digest());
    String remoteMd5 = putObjectResult.getContentMd5();
    if (!localMd5.equals(remoteMd5)) {
        logger.debug("MD5 local [{}], remote [{}] are not equal...", localMd5, remoteMd5);
        throw new AmazonS3Exception("MD5 local [" + localMd5 + "], remote [" + remoteMd5 + "] are not equal...");
    }
}
Also used : DigestInputStream(java.security.DigestInputStream) PutObjectResult(com.amazonaws.services.s3.model.PutObjectResult) ByteArrayInputStream(java.io.ByteArrayInputStream) DigestInputStream(java.security.DigestInputStream) InputStream(java.io.InputStream) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) MessageDigest(java.security.MessageDigest) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 9 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project elasticsearch by elastic.

the class S3BlobContainer method move.

@Override
public void move(String sourceBlobName, String targetBlobName) throws IOException {
    try {
        CopyObjectRequest request = new CopyObjectRequest(blobStore.bucket(), buildKey(sourceBlobName), blobStore.bucket(), buildKey(targetBlobName));
        if (blobStore.serverSideEncryption()) {
            ObjectMetadata objectMetadata = new ObjectMetadata();
            objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
            request.setNewObjectMetadata(objectMetadata);
        }
        SocketAccess.doPrivilegedVoid(() -> {
            blobStore.client().copyObject(request);
            blobStore.client().deleteObject(blobStore.bucket(), buildKey(sourceBlobName));
        });
    } catch (AmazonS3Exception e) {
        throw new IOException(e);
    }
}
Also used : CopyObjectRequest(com.amazonaws.services.s3.model.CopyObjectRequest) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) IOException(java.io.IOException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 10 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project ice by Netflix.

the class BillingFileProcessor method updateLastMillis.

private void updateLastMillis(long millis, String filename) {
    AmazonS3Client s3Client = AwsUtils.getAmazonS3Client();
    s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + filename, IOUtils.toInputStream(millis + ""), new ObjectMetadata());
}
Also used : AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Aggregations

ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)64 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)20 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)18 AmazonServiceException (com.amazonaws.AmazonServiceException)17 AmazonClientException (com.amazonaws.AmazonClientException)15 IOException (java.io.IOException)13 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)10 Copy (com.amazonaws.services.s3.transfer.Copy)8 Upload (com.amazonaws.services.s3.transfer.Upload)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 InputStream (java.io.InputStream)8 Date (java.util.Date)6 File (java.io.File)5 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)4 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)4 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)3 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)3 S3Object (com.amazonaws.services.s3.model.S3Object)3 InterruptedIOException (java.io.InterruptedIOException)3 ProgressEvent (com.amazonaws.event.ProgressEvent)2