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();
}
}
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();
}
}
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;
}
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());
}
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);
}
Aggregations