Search in sources :

Example 6 with ObjectMetadata

use of com.talend.shaded.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.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata 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 8 with ObjectMetadata

use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project airpal by airbnb.

the class ResultsPreviewResource method getS3Preview.

private Response getS3Preview(URI fileURI, int numLines) {
    val filename = getFilename(fileURI);
    val outputKey = getOutputKey(filename);
    // download ~100 kb (depending on your definition) of the file
    val request = new GetObjectRequest(outputBucket, outputKey).withRange(0, 100 * 1024);
    val object = s3Client.getObject(request);
    ObjectMetadata objectMetadata = object.getObjectMetadata();
    boolean gzip = "gzip".equalsIgnoreCase(objectMetadata.getContentEncoding());
    try (InputStream input = object.getObjectContent()) {
        InputStreamReader reader;
        if (gzip) {
            reader = new InputStreamReader(new GZIPInputStream(input));
        } else {
            reader = new InputStreamReader(input);
        }
        return getPreviewFromCSV(new CSVReader(reader), numLines);
    } catch (IOException e) {
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : lombok.val(lombok.val) GZIPInputStream(java.util.zip.GZIPInputStream) InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 9 with ObjectMetadata

use of com.talend.shaded.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)

Example 10 with ObjectMetadata

use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata 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

ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)163 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)76 ByteArrayInputStream (java.io.ByteArrayInputStream)52 Test (org.junit.Test)47 IOException (java.io.IOException)33 File (java.io.File)27 AmazonClientException (com.amazonaws.AmazonClientException)25 AmazonServiceException (com.amazonaws.AmazonServiceException)22 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)21 InputStream (java.io.InputStream)20 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)18 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)15 Upload (com.amazonaws.services.s3.transfer.Upload)15 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)11 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)10 Date (java.util.Date)9 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)9 Copy (com.amazonaws.services.s3.transfer.Copy)8 S3Object (com.amazonaws.services.s3.model.S3Object)7 InterruptedIOException (java.io.InterruptedIOException)7