Search in sources :

Example 11 with ObjectMetadata

use of 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 12 with ObjectMetadata

use of 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 13 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project presto by prestodb.

the class MockAmazonS3 method getObjectMetadata.

@Override
public ObjectMetadata getObjectMetadata(String bucketName, String key) throws AmazonClientException {
    if (getObjectMetadataHttpCode != SC_OK) {
        AmazonS3Exception exception = new AmazonS3Exception("Failing getObjectMetadata call with " + getObjectMetadataHttpCode);
        exception.setStatusCode(getObjectMetadataHttpCode);
        throw exception;
    }
    return null;
}
Also used : AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception)

Example 14 with ObjectMetadata

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

the class S3ConfigProvider method storeConfig.

@Override
public LoadedInstanceConfig storeConfig(ConfigCollection config, long compareVersion) throws Exception {
    {
        ObjectMetadata metadata = getConfigMetadata();
        if (metadata != null) {
            Date lastModified = metadata.getLastModified();
            if (lastModified.getTime() != compareVersion) {
                // apparently there's no atomic way to do this with S3 so this will have to do
                return null;
            }
        }
    }
    PropertyBasedInstanceConfig propertyBasedInstanceConfig = new PropertyBasedInstanceConfig(config);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    propertyBasedInstanceConfig.getProperties().store(out, "Auto-generated by Exhibitor " + hostname);
    byte[] bytes = out.toByteArray();
    ObjectMetadata metadata = S3Utils.simpleUploadFile(s3Client, bytes, arguments.getBucket(), arguments.getKey());
    return new LoadedInstanceConfig(propertyBasedInstanceConfig, metadata.getLastModified().getTime());
}
Also used : PropertyBasedInstanceConfig(com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Date(java.util.Date) LoadedInstanceConfig(com.netflix.exhibitor.core.config.LoadedInstanceConfig)

Example 15 with ObjectMetadata

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

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