use of org.jets3t.service.model.S3Object in project druid by druid-io.
the class S3TimestampVersionedDataFinderTest method testMissing.
@Test
public void testMissing() throws S3ServiceException {
String bucket = "bucket";
String keyPrefix = "prefix/dir/0";
RestS3Service s3Client = EasyMock.createStrictMock(RestS3Service.class);
S3Object object0 = new S3Object(), object1 = new S3Object();
object0.setBucketName(bucket);
object0.setKey(keyPrefix + "/renames-0.gz");
object0.setLastModifiedDate(new Date(0));
object1.setBucketName(bucket);
object1.setKey(keyPrefix + "/renames-1.gz");
object1.setLastModifiedDate(new Date(1));
EasyMock.expect(s3Client.listObjects(EasyMock.eq(bucket), EasyMock.anyString(), EasyMock.<String>isNull())).andReturn(null).once();
S3TimestampVersionedDataFinder finder = new S3TimestampVersionedDataFinder(s3Client);
Pattern pattern = Pattern.compile("renames-[0-9]*\\.gz");
EasyMock.replay(s3Client);
URI latest = finder.getLatestVersion(URI.create(String.format("s3://%s/%s", bucket, keyPrefix)), pattern);
EasyMock.verify(s3Client);
Assert.assertEquals(null, latest);
}
use of org.jets3t.service.model.S3Object in project druid by druid-io.
the class S3TimestampVersionedDataFinderTest method testFindSelf.
@Test
public void testFindSelf() throws S3ServiceException {
String bucket = "bucket";
String keyPrefix = "prefix/dir/0";
RestS3Service s3Client = EasyMock.createStrictMock(RestS3Service.class);
S3Object object0 = new S3Object();
object0.setBucketName(bucket);
object0.setKey(keyPrefix + "/renames-0.gz");
object0.setLastModifiedDate(new Date(0));
EasyMock.expect(s3Client.listObjects(EasyMock.eq(bucket), EasyMock.anyString(), EasyMock.<String>isNull())).andReturn(new S3Object[] { object0 }).once();
S3TimestampVersionedDataFinder finder = new S3TimestampVersionedDataFinder(s3Client);
Pattern pattern = Pattern.compile("renames-[0-9]*\\.gz");
EasyMock.replay(s3Client);
URI latest = finder.getLatestVersion(URI.create(String.format("s3://%s/%s", bucket, keyPrefix)), pattern);
EasyMock.verify(s3Client);
URI expected = URI.create(String.format("s3://%s/%s", bucket, object0.getKey()));
Assert.assertEquals(expected, latest);
}
use of org.jets3t.service.model.S3Object in project hadoop by apache.
the class Jets3tNativeFileSystemStore method copy.
@Override
public void copy(String srcKey, String dstKey) throws IOException {
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Copying srcKey: " + srcKey + "to dstKey: " + dstKey + "in bucket: " + bucket.getName());
}
if (multipartEnabled) {
S3Object object = s3Service.getObjectDetails(bucket, srcKey, null, null, null, null);
if (multipartCopyBlockSize > 0 && object.getContentLength() > multipartCopyBlockSize) {
copyLargeFile(object, dstKey);
return;
}
}
S3Object dstObject = new S3Object(dstKey);
dstObject.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm);
s3Service.copyObject(bucket.getName(), srcKey, bucket.getName(), dstObject, false);
} catch (ServiceException e) {
handleException(e, srcKey);
}
}
use of org.jets3t.service.model.S3Object in project hadoop by apache.
the class Jets3tNativeFileSystemStore method storeLargeFile.
public void storeLargeFile(String key, File file, byte[] md5Hash) throws IOException {
S3Object object = new S3Object(key);
object.setDataInputFile(file);
object.setContentType("binary/octet-stream");
object.setContentLength(file.length());
object.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm);
if (md5Hash != null) {
object.setMd5Hash(md5Hash);
}
List<StorageObject> objectsToUploadAsMultipart = new ArrayList<StorageObject>();
objectsToUploadAsMultipart.add(object);
MultipartUtils mpUtils = new MultipartUtils(multipartBlockSize);
try {
mpUtils.uploadObjects(bucket.getName(), s3Service, objectsToUploadAsMultipart, null);
} catch (Exception e) {
handleException(e, key);
}
}
use of org.jets3t.service.model.S3Object in project hadoop by apache.
the class Jets3tNativeFileSystemStore method retrieve.
/**
* @param key
* The key is the object name that is being retrieved from the S3 bucket
* @return
* This method returns null if the key is not found
* @throws IOException
*/
@Override
public InputStream retrieve(String key) throws IOException {
try {
LOG.debug("Getting key: {} from bucket: {}", key, bucket.getName());
S3Object object = s3Service.getObject(bucket.getName(), key);
return object.getDataInputStream();
} catch (ServiceException e) {
handleException(e, key);
//return null if key not found
return null;
}
}
Aggregations