Search in sources :

Example 11 with PutObjectRequest

use of com.amazonaws.services.s3.model.PutObjectRequest in project airpal by airbnb.

the class S3FilePersistor method persist.

@Override
public URI persist(JobOutputBuilder outputBuilder, Job job) {
    File file = checkNotNull(outputBuilder.build(), "output builder resulting file was null");
    val objectMetaData = new ObjectMetadata();
    objectMetaData.setContentLength(file.length());
    objectMetaData.setContentType(MediaType.CSV_UTF_8.toString());
    if (compressedOutput) {
        objectMetaData.setContentEncoding("gzip");
    }
    val putRequest = new PutObjectRequest(outputBucket, getOutputKey(file.getName()), file).withMetadata(objectMetaData);
    try {
        s3Client.putObject(putRequest);
        return UriBuilder.fromPath("/api/s3/{filename}").build(file.getName());
    } catch (AmazonClientException e) {
        throw new ExecutionClient.ExecutionFailureException(job, "Could not upload CSV to S3", e);
    } finally {
        outputBuilder.delete();
    }
}
Also used : lombok.val(lombok.val) AmazonClientException(com.amazonaws.AmazonClientException) ExecutionClient(com.airbnb.airpal.core.execution.ExecutionClient) File(java.io.File) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 12 with PutObjectRequest

use of com.amazonaws.services.s3.model.PutObjectRequest in project exhibitor by soabase.

the class S3PseudoLock method createFile.

@Override
protected void createFile(String key, byte[] contents) throws Exception {
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentLength(contents.length);
    PutObjectRequest request = new PutObjectRequest(bucket, key, new ByteArrayInputStream(contents), metadata);
    client.putObject(request);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 13 with PutObjectRequest

use of com.amazonaws.services.s3.model.PutObjectRequest in project exhibitor by soabase.

the class TestS3BackupProviderBase method testDownload.

@Test
public void testDownload() throws Exception {
    InputStream in = null;
    OutputStream out = null;
    File tempFile = File.createTempFile("test", ".test");
    try {
        in = new FileInputStream(sourceFile);
        PutObjectRequest dummyRequest = new PutObjectRequest("bucket", "exhibitor-backup" + S3BackupProvider.SEPARATOR + "test" + S3BackupProvider.SEPARATOR + 1, in, null);
        MockS3Client s3Client = new MockS3Client(null, null);
        s3Client.putObject(dummyRequest);
        S3BackupProvider provider = new S3BackupProvider(new MockS3ClientFactory(s3Client), new PropertyBasedS3Credential(new Properties()), new PropertyBasedS3ClientConfig(new Properties()), null);
        out = new FileOutputStream(tempFile);
        provider.downloadBackup(null, new BackupMetaData("test", 1), out, Maps.<String, String>newHashMap());
        Assert.assertEquals(Files.toByteArray(sourceFile), Files.toByteArray(tempFile));
    } finally {
        CloseableUtils.closeQuietly(in);
        CloseableUtils.closeQuietly(out);
        //noinspection ResultOfMethodCallIgnored
        tempFile.delete();
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BackupMetaData(com.netflix.exhibitor.core.backup.BackupMetaData) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) PropertyBasedS3ClientConfig(com.netflix.exhibitor.core.s3.PropertyBasedS3ClientConfig) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) PropertyBasedS3Credential(com.netflix.exhibitor.core.s3.PropertyBasedS3Credential) File(java.io.File) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) Test(org.testng.annotations.Test)

Example 14 with PutObjectRequest

use of com.amazonaws.services.s3.model.PutObjectRequest in project gradle by gradle.

the class S3Client method put.

public void put(InputStream inputStream, Long contentLength, URI destination) {
    checkRequiredJigsawModuleIsOnPath();
    try {
        S3RegionalResource s3RegionalResource = new S3RegionalResource(destination);
        String bucketName = s3RegionalResource.getBucketName();
        String s3BucketKey = s3RegionalResource.getKey();
        configureClient(s3RegionalResource);
        ObjectMetadata objectMetadata = new ObjectMetadata();
        objectMetadata.setContentLength(contentLength);
        PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, s3BucketKey, inputStream, objectMetadata);
        LOGGER.debug("Attempting to put resource:[{}] into s3 bucket [{}]", s3BucketKey, bucketName);
        amazonS3Client.putObject(putObjectRequest);
    } catch (AmazonClientException e) {
        throw ResourceExceptions.putFailed(destination, e);
    }
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 15 with PutObjectRequest

use of com.amazonaws.services.s3.model.PutObjectRequest in project alluxio by Alluxio.

the class S3AUnderFileSystem method createEmptyObject.

@Override
protected boolean createEmptyObject(String key) {
    try {
        ObjectMetadata meta = new ObjectMetadata();
        meta.setContentLength(0);
        meta.setContentMD5(DIR_HASH);
        meta.setContentType(Mimetypes.MIMETYPE_OCTET_STREAM);
        mClient.putObject(new PutObjectRequest(mBucketName, key, new ByteArrayInputStream(new byte[0]), meta));
        return true;
    } catch (AmazonClientException e) {
        LOG.error("Failed to create object: {}", key, e);
        return false;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AmazonClientException(com.amazonaws.AmazonClientException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Aggregations

PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)33 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)21 Upload (com.amazonaws.services.s3.transfer.Upload)11 AmazonClientException (com.amazonaws.AmazonClientException)10 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)8 Exchange (org.apache.camel.Exchange)8 Processor (org.apache.camel.Processor)8 Test (org.junit.Test)8 InputStream (java.io.InputStream)7 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)7 File (java.io.File)6 IOException (java.io.IOException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 AmazonServiceException (com.amazonaws.AmazonServiceException)4 S3Object (com.amazonaws.services.s3.model.S3Object)4 Date (java.util.Date)4 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)3 Copy (com.amazonaws.services.s3.transfer.Copy)3 FileInputStream (java.io.FileInputStream)3 HashMap (java.util.HashMap)3